annotate Plugins/Input/mpg123/mpg123.c @ 801:ec9ba0ad38a8 trunk

[svn] - use OBJECTIVE_DATA instead of a kludge in the posthook here
author nenolod
date Sat, 04 Mar 2006 14:34:04 -0800
parents 69d3bb31aa49
children c8cf439179b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 #include "mpg123.h"
354
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
2 #include "common.h"
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 #include <glib/gi18n.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 #include <gtk/gtk.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 #include <string.h>
354
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
9 #include <unistd.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
10
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
11 #include <fcntl.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
12 #include <unistd.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
13 #include <errno.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
14 #include <sys/types.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
15 #include <sys/socket.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
16 #include <sys/time.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
17 #include <netinet/in.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
18 #include <arpa/inet.h>
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
19 #include <netdb.h>
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21 #include <libaudacious/util.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22 #include <libaudacious/configdb.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 #include <libaudacious/vfs.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 #include <libaudacious/titlestring.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 #include "audacious/util.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 static const long outscale = 32768;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29
354
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
30 #define BUFSIZE_X 2048
e2775c9b8b13 [svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents: 353
diff changeset
31
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 static struct frame fr, temp_fr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 PlayerInfo *mpg123_info = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 static GThread *decode_thread;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37 static gboolean audio_error = FALSE, output_opened = FALSE, dopause = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 gint mpg123_bitrate, mpg123_frequency, mpg123_length, mpg123_layer,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 mpg123_lsf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 gchar *mpg123_title = NULL, *mpg123_filename = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 static int disp_bitrate, skip_frames = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 static int cpu_fflags, cpu_efflags;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 gboolean mpg123_stereo, mpg123_mpeg25;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 int mpg123_mode;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 gchar **mpg123_id3_encoding_list = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 const char *mpg123_id3_genres[GENRE_MAX] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 N_("Blues"), N_("Classic Rock"), N_("Country"), N_("Dance"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 N_("Disco"), N_("Funk"), N_("Grunge"), N_("Hip-Hop"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 N_("Jazz"), N_("Metal"), N_("New Age"), N_("Oldies"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 N_("Other"), N_("Pop"), N_("R&B"), N_("Rap"), N_("Reggae"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 N_("Rock"), N_("Techno"), N_("Industrial"), N_("Alternative"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 N_("Ska"), N_("Death Metal"), N_("Pranks"), N_("Soundtrack"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 N_("Euro-Techno"), N_("Ambient"), N_("Trip-Hop"), N_("Vocal"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 N_("Jazz+Funk"), N_("Fusion"), N_("Trance"), N_("Classical"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 N_("Instrumental"), N_("Acid"), N_("House"), N_("Game"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 N_("Sound Clip"), N_("Gospel"), N_("Noise"), N_("AlternRock"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 N_("Bass"), N_("Soul"), N_("Punk"), N_("Space"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 N_("Meditative"), N_("Instrumental Pop"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 N_("Instrumental Rock"), N_("Ethnic"), N_("Gothic"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 N_("Darkwave"), N_("Techno-Industrial"), N_("Electronic"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 N_("Pop-Folk"), N_("Eurodance"), N_("Dream"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 N_("Southern Rock"), N_("Comedy"), N_("Cult"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 N_("Gangsta Rap"), N_("Top 40"), N_("Christian Rap"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 N_("Pop/Funk"), N_("Jungle"), N_("Native American"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 N_("Cabaret"), N_("New Wave"), N_("Psychedelic"), N_("Rave"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 N_("Showtunes"), N_("Trailer"), N_("Lo-Fi"), N_("Tribal"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 N_("Acid Punk"), N_("Acid Jazz"), N_("Polka"), N_("Retro"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 N_("Musical"), N_("Rock & Roll"), N_("Hard Rock"), N_("Folk"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 N_("Folk/Rock"), N_("National Folk"), N_("Swing"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 N_("Fast-Fusion"), N_("Bebob"), N_("Latin"), N_("Revival"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 N_("Celtic"), N_("Bluegrass"), N_("Avantgarde"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 N_("Gothic Rock"), N_("Progressive Rock"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 N_("Psychedelic Rock"), N_("Symphonic Rock"), N_("Slow Rock"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 N_("Big Band"), N_("Chorus"), N_("Easy Listening"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 N_("Acoustic"), N_("Humour"), N_("Speech"), N_("Chanson"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 N_("Opera"), N_("Chamber Music"), N_("Sonata"), N_("Symphony"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 N_("Booty Bass"), N_("Primus"), N_("Porn Groove"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 N_("Satire"), N_("Slow Jam"), N_("Club"), N_("Tango"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 N_("Samba"), N_("Folklore"), N_("Ballad"), N_("Power Ballad"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 N_("Rhythmic Soul"), N_("Freestyle"), N_("Duet"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 N_("Punk Rock"), N_("Drum Solo"), N_("A Cappella"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 N_("Euro-House"), N_("Dance Hall"), N_("Goa"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 N_("Drum & Bass"), N_("Club-House"), N_("Hardcore"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 N_("Terror"), N_("Indie"), N_("BritPop"), N_("Negerpunk"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 N_("Polsk Punk"), N_("Beat"), N_("Christian Gangsta Rap"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 N_("Heavy Metal"), N_("Black Metal"), N_("Crossover"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 N_("Contemporary Christian"), N_("Christian Rock"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 N_("Merengue"), N_("Salsa"), N_("Thrash Metal"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 N_("Anime"), N_("JPop"), N_("Synthpop")
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 double
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 mpg123_compute_tpf(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 const int bs[4] = { 0, 384, 1152, 1152 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 double tpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 tpf = bs[fr->lay];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 tpf /= mpg123_freqs[fr->sampling_frequency] << (fr->lsf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 return tpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 set_synth_functions(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 typedef int (*func) (real *, int, unsigned char *, int *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 typedef int (*func_mono) (real *, unsigned char *, int *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 typedef void (*func_dct36) (real *, real *, real *, real *, real *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 int ds = fr->down_sample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 int p8 = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 static func funcs[][3] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 {mpg123_synth_1to1,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 mpg123_synth_2to1,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 mpg123_synth_4to1},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 {mpg123_synth_1to1_8bit,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 mpg123_synth_2to1_8bit,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121 mpg123_synth_4to1_8bit},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 static func_mono funcs_mono[2][4] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 {mpg123_synth_1to1_mono,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 mpg123_synth_2to1_mono,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 mpg123_synth_4to1_mono},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 {mpg123_synth_1to1_8bit_mono,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 mpg123_synth_2to1_8bit_mono,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 mpg123_synth_4to1_8bit_mono}
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 if (mpg123_cfg.resolution == 8)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 p8 = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 fr->synth = funcs[p8][ds];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 fr->synth_mono = funcs_mono[p8][ds];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 fr->synth_type = SYNTH_FPU;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 if (p8) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 mpg123_make_conv16to8_table();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 ConfigDb *db;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 mpg123_make_decode_tables(outscale);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 mpg123_cfg.resolution = 16;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 mpg123_cfg.channels = 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 mpg123_cfg.downsample = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 mpg123_cfg.http_buffer_size = 128;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 mpg123_cfg.http_prebuffer = 25;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 mpg123_cfg.proxy_port = 8080;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 mpg123_cfg.proxy_use_auth = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 mpg123_cfg.proxy_user = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 mpg123_cfg.proxy_pass = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 mpg123_cfg.use_udp_channel = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 mpg123_cfg.title_override = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 mpg123_cfg.disable_id3v2 = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 mpg123_cfg.default_synth = SYNTH_AUTO;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 mpg123_cfg.title_encoding_enabled = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 mpg123_cfg.title_encoding = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 db = bmp_cfg_db_open();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 bmp_cfg_db_get_int(db, "MPG123", "resolution", &mpg123_cfg.resolution);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 bmp_cfg_db_get_int(db, "MPG123", "channels", &mpg123_cfg.channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 bmp_cfg_db_get_int(db, "MPG123", "downsample", &mpg123_cfg.downsample);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 bmp_cfg_db_get_int(db, "MPG123", "http_buffer_size",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 &mpg123_cfg.http_buffer_size);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 bmp_cfg_db_get_int(db, "MPG123", "http_prebuffer",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 &mpg123_cfg.http_prebuffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 bmp_cfg_db_get_bool(db, "MPG123", "save_http_stream",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 &mpg123_cfg.save_http_stream);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 if (!bmp_cfg_db_get_string
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 (db, "MPG123", "save_http_path", &mpg123_cfg.save_http_path))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 mpg123_cfg.save_http_path = g_strdup(g_get_home_dir());
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 bmp_cfg_db_get_bool(db, "MPG123", "use_udp_channel",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 &mpg123_cfg.use_udp_channel);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 bmp_cfg_db_get_bool(db, "MPG123", "use_proxy", &mpg123_cfg.use_proxy);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 if (!bmp_cfg_db_get_string
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 (db, "MPG123", "proxy_host", &mpg123_cfg.proxy_host))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 mpg123_cfg.proxy_host = g_strdup("localhost");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 bmp_cfg_db_get_int(db, "MPG123", "proxy_port", &mpg123_cfg.proxy_port);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 bmp_cfg_db_get_bool(db, "MPG123", "proxy_use_auth",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 &mpg123_cfg.proxy_use_auth);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 bmp_cfg_db_get_string(db, "MPG123", "proxy_user", &mpg123_cfg.proxy_user);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 bmp_cfg_db_get_string(db, "MPG123", "proxy_pass", &mpg123_cfg.proxy_pass);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 bmp_cfg_db_get_bool(db, "MPG123", "title_override",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 &mpg123_cfg.title_override);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 bmp_cfg_db_get_bool(db, "MPG123", "disable_id3v2",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 &mpg123_cfg.disable_id3v2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 if (!bmp_cfg_db_get_string
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 (db, "MPG123", "id3_format", &mpg123_cfg.id3_format))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 mpg123_cfg.id3_format = g_strdup("%p - %t");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203 bmp_cfg_db_get_int(db, "MPG123", "default_synth",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204 &mpg123_cfg.default_synth);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 bmp_cfg_db_get_bool(db, "MPG123", "title_encoding_enabled", &mpg123_cfg.title_encoding_enabled);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 bmp_cfg_db_get_string(db, "MPG123", "title_encoding", &mpg123_cfg.title_encoding);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 if (mpg123_cfg.title_encoding_enabled)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 mpg123_id3_encoding_list = g_strsplit_set(mpg123_cfg.title_encoding, ENCODING_SEPARATOR, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 bmp_cfg_db_close(db);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 if (mpg123_cfg.resolution != 16 && mpg123_cfg.resolution != 8)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 mpg123_cfg.resolution = 16;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 mpg123_cfg.channels = CLAMP(mpg123_cfg.channels, 0, 2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 mpg123_cfg.downsample = CLAMP(mpg123_cfg.downsample, 0, 2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 mpg123_getcpuflags(&cpu_fflags, &cpu_efflags);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 cleanup(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 g_strfreev(mpg123_id3_encoding_list);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 static guint32
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 convert_to_header(guint8 * buf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233
777
f3ee3610ca26 [svn] - do not use type/magic detection here
nenolod
parents: 776
diff changeset
234 #if 0
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 #define DET_BUF_SIZE 1024
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 mpg123_detect_by_content(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 VFSFile *file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 guchar tmp[4];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 guint32 head;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 struct frame fr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 guchar buf[DET_BUF_SIZE];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 int in_buf, i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 gboolean ret = FALSE;
775
d8e406227b9a [svn] - reinstate cyc-based checks intelligently
nenolod
parents: 773
diff changeset
247 guint cyc = 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 if ((file = vfs_fopen(filename, "rb")) == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 if (vfs_fread(tmp, 1, 4, file) != 4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 goto done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 head = convert_to_header(tmp);
773
f3d15ea6e56b [svn] - remove cyc based breaking
nenolod
parents: 771
diff changeset
254 while (!mpg123_head_check(head)) {
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 * The mpeg-stream can start anywhere in the file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 * so we check the entire file
762
a22aa7bfa108 [svn] - try to avoid a buffer overflow when detecting an MPEG stream
nenolod
parents: 761
diff changeset
258 *
771
0f0659a2d5fb [svn] ten iterations?
nenolod
parents: 766
diff changeset
259 * Incorrect! We give up past ten iterations of this
762
a22aa7bfa108 [svn] - try to avoid a buffer overflow when detecting an MPEG stream
nenolod
parents: 761
diff changeset
260 * code for safety's sake. Buffer overflows suck. --nenolod
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 /* Optimize this */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 in_buf = vfs_fread(buf, 1, DET_BUF_SIZE, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 if (in_buf == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 goto done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 for (i = 0; i < in_buf; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 head <<= 8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269 head |= buf[i];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270 if (mpg123_head_check(head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 vfs_fseek(file, i + 1 - in_buf, SEEK_CUR);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274 }
775
d8e406227b9a [svn] - reinstate cyc-based checks intelligently
nenolod
parents: 773
diff changeset
275
d8e406227b9a [svn] - reinstate cyc-based checks intelligently
nenolod
parents: 773
diff changeset
276 if (++cyc > 20)
d8e406227b9a [svn] - reinstate cyc-based checks intelligently
nenolod
parents: 773
diff changeset
277 goto done;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 if (mpg123_decode_header(&fr, head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281 * We found something which looks like a MPEG-header.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 * We check the next frame too, to be sure
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 if (vfs_fseek(file, fr.framesize, SEEK_CUR) != 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 goto done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287 if (vfs_fread(tmp, 1, 4, file) != 4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 goto done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 head = convert_to_header(tmp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290 if (mpg123_head_check(head) && mpg123_decode_header(&fr, head))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 ret = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294 done:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 }
777
f3ee3610ca26 [svn] - do not use type/magic detection here
nenolod
parents: 776
diff changeset
298 #endif
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 is_our_file(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 {
653
97113126c7f9 [svn] - Fix mp3 detection properly.
nenolod
parents: 651
diff changeset
303 gchar *ext = strrchr(filename, '.');
97113126c7f9 [svn] - Fix mp3 detection properly.
nenolod
parents: 651
diff changeset
304
761
363f8644bce7 [svn] - sanity checks here
nenolod
parents: 685
diff changeset
305 if (!strncasecmp(filename, "http://", 7) && (ext && strncasecmp(ext, ".ogg", 4)))
684
d991052592f6 [svn] - Roll back broken HTTP-based stream detection code.
nenolod
parents: 653
diff changeset
306 return TRUE;
777
f3ee3610ca26 [svn] - do not use type/magic detection here
nenolod
parents: 776
diff changeset
307 else if (ext && (!strncasecmp(ext, ".mp3", 4)
f3ee3610ca26 [svn] - do not use type/magic detection here
nenolod
parents: 776
diff changeset
308 || !strncasecmp(ext, ".mp2", 4)
f3ee3610ca26 [svn] - do not use type/magic detection here
nenolod
parents: 776
diff changeset
309 || !strncasecmp(ext, ".mpg", 4)))
f3ee3610ca26 [svn] - do not use type/magic detection here
nenolod
parents: 776
diff changeset
310 return TRUE;
653
97113126c7f9 [svn] - Fix mp3 detection properly.
nenolod
parents: 651
diff changeset
311
778
69d3bb31aa49 [svn] lalala
nenolod
parents: 777
diff changeset
312 return FALSE;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316 play_frame(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318 if (fr->error_protection) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319 bsi.wordpointer += 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 /* mpg123_getbits(16); *//* skip crc */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 if (!fr->do_layer(fr)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 skip_frames = 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 mpg123_info->output_audio = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 if (!skip_frames)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 mpg123_info->output_audio = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330 skip_frames--;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 static const char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 get_id3_genre(unsigned char genre_code)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 if (genre_code < GENRE_MAX)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 return gettext(mpg123_id3_genres[genre_code]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 return "";
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 guint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344 mpg123_strip_spaces(char *src, size_t n)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 gchar *space = NULL, /* last space in src */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 *start = src;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 while (n--)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 switch (*src++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351 case '\0':
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 n = 0; /* breaks out of while loop */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 src--;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 case ' ':
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357 if (space == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 space = src - 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 default:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 space = NULL; /* don't terminate intermediate spaces */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 if (space != NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366 src = space;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 *src = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369 return src - start;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373 * Function extname (filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 * Return pointer within filename to its extenstion, or NULL if
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376 * filename has no extension.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 static gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380 extname(const char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382 gchar *ext = strrchr(filename, '.');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384 if (ext != NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 ++ext;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387 return ext;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 * Function id3v1_to_id3v2 (v1, v2)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393 * Convert ID3v1 tag `v1' to ID3v2 tag `v2'.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 mpg123_id3v1_to_id3v2(struct id3v1tag_t *v1, struct id3tag_t *v2)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 memset(v2, 0, sizeof(struct id3tag_t));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 strncpy(v2->title, v1->title, 30);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 strncpy(v2->artist, v1->artist, 30);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 strncpy(v2->album, v1->album, 30);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 strncpy(v2->comment, v1->u.v1_0.comment, 30);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 strncpy(v2->genre, get_id3_genre(v1->genre), sizeof(v2->genre));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 g_strstrip(v2->title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 g_strstrip(v2->artist);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407 g_strstrip(v2->album);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 g_strstrip(v2->comment);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409 g_strstrip(v2->genre);
636
aa6914ee37ab [svn] id3v1 tag stuffs.
nenolod
parents: 625
diff changeset
410 {
aa6914ee37ab [svn] id3v1 tag stuffs.
nenolod
parents: 625
diff changeset
411 char y[5];
aa6914ee37ab [svn] id3v1 tag stuffs.
nenolod
parents: 625
diff changeset
412 memcpy(y, v1->year, 4); y[4]=0;
aa6914ee37ab [svn] id3v1 tag stuffs.
nenolod
parents: 625
diff changeset
413 v2->year = atoi(y);
aa6914ee37ab [svn] id3v1 tag stuffs.
nenolod
parents: 625
diff changeset
414 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416 /* Check for v1.1 tags. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 if (v1->u.v1_1.__zero == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 v2->track_number = v1->u.v1_1.track_number;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
419 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420 v2->track_number = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
421 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
423 static char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 mpg123_getstr(char *str)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
425 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 if (str && strlen(str) > 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427 return str;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
429 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 static gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
432 convert_id3_title(gchar * title)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 gchar **encoding = mpg123_id3_encoding_list;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 gchar *new_title = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 if (g_utf8_validate(title, -1, NULL))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
438 return title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440 while (*encoding && !new_title) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441 new_title = g_convert(title, strlen(title), "UTF-8", *encoding++,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 NULL, NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445 if (new_title) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 g_free(title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 return new_title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450 /* FIXME: We're relying on BMP core to provide fallback
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 * conversion */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 return title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 * Function mpg123_format_song_title (tag, filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
458 * Create song title according to `tag' and/or `filename' and
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 * return it. The title must be subsequently freed using g_free().
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463 mpg123_format_song_title(struct id3tag_t * tag, gchar * filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 gchar *title = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 TitleInput *input;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
467
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 input = bmp_title_input_new();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 if (tag) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 input->performer = mpg123_getstr(tag->artist);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 input->album_name = mpg123_getstr(tag->album);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473 input->track_name = mpg123_getstr(tag->title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 input->year = tag->year;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 input->track_number = tag->track_number;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 input->genre = mpg123_getstr(tag->genre);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477 input->comment = mpg123_getstr(tag->comment);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 input->file_name = g_path_get_basename(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481 input->file_path = g_path_get_dirname(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 input->file_ext = extname(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
484 title = xmms_get_titlestring(mpg123_cfg.title_override ?
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
485 mpg123_cfg.id3_format :
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 xmms_get_gentitle_format(), input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
487
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
488 if (!title) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 /* Format according to filename. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490 title = g_path_get_basename(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
491 if (extname(title))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 *(extname(title) - 1) = '\0'; /* removes period */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
493 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
494
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495 g_free(input->file_path);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496 g_free(input->file_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
497 g_free(input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 if (mpg123_cfg.title_encoding_enabled)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
500 title = convert_id3_title(title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
501
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
502 return title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
503 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
504
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
505 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 * Function mpg123_get_id3v2 (id3d, tag)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508 * Get desired contents from the indicated id3tag and store it in
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
509 * `tag'.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
510 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
511 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
512 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
513 mpg123_get_id3v2(struct id3_tag *id3d, struct id3tag_t *tag)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
514 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
515 struct id3_frame *id3frm;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
516 gchar *txt;
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 575
diff changeset
517 gsize tlen;
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 575
diff changeset
518 gint num;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
519
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
520 #define ID3_SET(_tid,_fld) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
521 { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
522 id3frm = id3_get_frame( id3d, _tid, 1 ); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
523 if (id3frm) { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
524 txt = _tid == ID3_TCON ? id3_get_content(id3frm) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
525 : id3_get_text(id3frm); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
526 if(txt) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
527 { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
528 tlen = strlen(txt); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
529 if ( tlen >= sizeof(tag->_fld) ) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
530 tlen = sizeof(tag->_fld)-1; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
531 strncpy( tag->_fld, txt, tlen ); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
532 tag->_fld[tlen] = 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
533 g_free(txt); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
534 } \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
535 else \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
536 tag->_fld[0] = 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
537 } else { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
538 tag->_fld[0] = 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
539 } \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
540 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
541
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
542 #define ID3_SET_NUM(_tid,_fld) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
543 { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
544 id3frm = id3_get_frame(id3d, _tid, 1); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
545 if (id3frm) { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
546 num = id3_get_text_number(id3frm); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
547 tag->_fld = num >= 0 ? num : 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
548 } else \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
549 tag->_fld = 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
550 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
551
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
552 ID3_SET(ID3_TIT2, title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
553 ID3_SET(ID3_TPE1, artist);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
554 if (strlen(tag->artist) == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
555 ID3_SET(ID3_TPE2, artist);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
556 ID3_SET(ID3_TALB, album);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
557 ID3_SET_NUM(ID3_TYER, year);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
558 ID3_SET_NUM(ID3_TRCK, track_number);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
559 ID3_SET(ID3_COMM, comment);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
560 ID3_SET(ID3_TCON, genre);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
561 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
562
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
563
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
564 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
565 * Function get_song_title (fd, filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
566 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
567 * Get song title of file. File position of `fd' will be
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
568 * clobbered. `fd' may be NULL, in which case `filename' is opened
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
569 * separately. The returned song title must be subsequently freed
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
570 * using g_free().
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
571 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
572 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
573 static gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
574 get_song_title(VFSFile * fd, char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
575 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
576 VFSFile *file = fd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
577 char *ret = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
578 struct id3v1tag_t id3v1tag;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
579 struct id3tag_t id3tag;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
580
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
581 if (file || (file = vfs_fopen(filename, "rb")) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
582 struct id3_tag *id3 = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
583
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
584 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
585 * Try reading ID3v2 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
586 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
587 if (!mpg123_cfg.disable_id3v2) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
588 vfs_fseek(file, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
589 id3 = id3_open_fp(file, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
590 if (id3) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
591 mpg123_get_id3v2(id3, &id3tag);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
592 ret = mpg123_format_song_title(&id3tag, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
593 id3_close(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
594 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
595 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
596
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
597 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
598 * Try reading ID3v1 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
599 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
600 if (!id3 && (vfs_fseek(file, -1 * sizeof(id3v1tag), SEEK_END) == 0) &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
601 (vfs_fread(&id3v1tag, 1, sizeof(id3v1tag), file) ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
602 sizeof(id3v1tag)) && (strncmp(id3v1tag.tag, "TAG", 3) == 0)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
603 mpg123_id3v1_to_id3v2(&id3v1tag, &id3tag);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
604 ret = mpg123_format_song_title(&id3tag, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
605 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
606
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
607 if (!fd)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
608 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
609 * File was opened in this function.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
610 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
611 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
612 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
613
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
614 if (ret == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
615 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
616 * Unable to get ID3 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
617 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
618 ret = mpg123_format_song_title(NULL, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
619
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
620 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
621 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
622
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
623 static long
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
624 get_song_length(VFSFile * file)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
625 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
626 int len;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
627 char tmp[4];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
628
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
629 vfs_fseek(file, 0, SEEK_END);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
630 len = vfs_ftell(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
631 vfs_fseek(file, -128, SEEK_END);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
632 vfs_fread(tmp, 1, 3, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
633 if (!strncmp(tmp, "TAG", 3))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
634 len -= 128;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
635 return len;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
636 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
637
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
638
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
639 static guint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
640 get_song_time(VFSFile * file)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
641 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
642 guint32 head;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
643 guchar tmp[4], *buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
644 struct frame frm;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
645 xing_header_t xing_header;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
646 double tpf, bpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
647 guint32 len;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
648
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
649 if (!file)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
650 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
651
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
652 vfs_fseek(file, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
653 if (vfs_fread(tmp, 1, 4, file) != 4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
654 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
655 head = convert_to_header(tmp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
656 while (!mpg123_head_check(head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
657 head <<= 8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
658 if (vfs_fread(tmp, 1, 1, file) != 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
659 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
660 head |= tmp[0];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
661 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
662 if (mpg123_decode_header(&frm, head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
663 buf = g_malloc(frm.framesize + 4);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
664 vfs_fseek(file, -4, SEEK_CUR);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
665 vfs_fread(buf, 1, frm.framesize + 4, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
666 tpf = mpg123_compute_tpf(&frm);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
667 if (mpg123_get_xing_header(&xing_header, buf)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
668 g_free(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
669 if (xing_header.bytes == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
670 xing_header.bytes = get_song_length(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
671 return (tpf * xing_header.frames * 1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
672 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
673 g_free(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
674 bpf = mpg123_compute_bpf(&frm);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
675 len = get_song_length(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
676 return ((guint) (len / bpf) * tpf * 1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
677 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
678 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
679 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
680
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
681 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
682 get_song_info(char *filename, char **title_real, int *len_real)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
683 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
684 VFSFile *file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
685
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
686 (*len_real) = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
687 (*title_real) = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
688
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
689 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
690 * TODO: Getting song info from http streams.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
691 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
692 if (!strncasecmp(filename, "http://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
693 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
694
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
695 if ((file = vfs_fopen(filename, "rb")) != NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
696 (*len_real) = get_song_time(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
697 (*title_real) = get_song_title(file, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
698 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
699 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
700 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
701
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
702 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
703 open_output(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
704 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
705 int r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
706 AFormat fmt = mpg123_cfg.resolution == 16 ? FMT_S16_NE : FMT_U8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
707 int freq = mpg123_freqs[fr.sampling_frequency] >> mpg123_cfg.downsample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
708 int channels = mpg123_cfg.channels == 2 ? fr.stereo : 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
709 r = mpg123_ip.output->open_audio(fmt, freq, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
710
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
711 if (r && dopause) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
712 mpg123_ip.output->pause(TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
713 dopause = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
714 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
715
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
716 return r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
717 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
718
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
719
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
720 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
721 mpg123_seek(struct frame *fr, xing_header_t * xh, gboolean vbr, int time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
722 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
723 int jumped = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
724
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
725 if (xh) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
726 int percent = ((double) time * 100.0) /
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
727 (mpg123_info->num_frames * mpg123_info->tpf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
728 int byte = mpg123_seek_point(xh, percent);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
729 jumped = mpg123_stream_jump_to_byte(fr, byte);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
730 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
731 else if (vbr && mpg123_length > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
732 int byte = ((guint64) time * 1000 * mpg123_info->filesize) /
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
733 mpg123_length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
734 jumped = mpg123_stream_jump_to_byte(fr, byte);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
735 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
736 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
737 int frame = time / mpg123_info->tpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
738 jumped = mpg123_stream_jump_to_frame(fr, frame);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
739 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
740
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
741 return jumped;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
742 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
743
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
744
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
745 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
746 decode_loop(void *arg)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
747 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
748 gboolean have_xing_header = FALSE, vbr = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
749 int disp_count = 0, temp_time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
750 char *filename = arg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
751 xing_header_t xing_header;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
752
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
753 /* This is used by fileinfo on http streams */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
754 mpg123_bitrate = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
755
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
756 mpg123_pcm_sample = g_malloc0(32768);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
757 mpg123_pcm_point = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
758 mpg123_filename = filename;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
759
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
760 mpg123_read_frame_init();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
761
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
762 mpg123_open_stream(filename, -1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
763
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
764 if (mpg123_info->eof || !mpg123_read_frame(&fr))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
765 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
766
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
767 if (!mpg123_info->eof && mpg123_info->going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
768 if (mpg123_cfg.channels == 2)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
769 fr.single = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
770 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
771 fr.single = 3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
772
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
773 fr.down_sample = mpg123_cfg.downsample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
774 fr.down_sample_sblimit = SBLIMIT >> mpg123_cfg.downsample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
775 set_synth_functions(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
776 mpg123_init_layer3(fr.down_sample_sblimit);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
777
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
778 mpg123_info->tpf = mpg123_compute_tpf(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
779 if (strncasecmp(filename, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
780 if (mpg123_stream_check_for_xing_header(&fr, &xing_header)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
781 mpg123_info->num_frames = xing_header.frames;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
782 have_xing_header = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
783 mpg123_read_frame(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
784 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
785 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
786
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
787 for (;;) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
788 memcpy(&temp_fr, &fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
789 if (!mpg123_read_frame(&temp_fr)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
790 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
791 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
792 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
793 if (fr.lay != temp_fr.lay ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
794 fr.sampling_frequency != temp_fr.sampling_frequency ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
795 fr.stereo != temp_fr.stereo || fr.lsf != temp_fr.lsf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
796 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
797 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
798 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
799 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
800
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
801 if (!have_xing_header && strncasecmp(filename, "http://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
802 mpg123_info->num_frames = mpg123_calc_numframes(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
803
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
804 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
805 mpg123_bitrate = tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
806 disp_bitrate = mpg123_bitrate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
807 mpg123_frequency = mpg123_freqs[fr.sampling_frequency];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
808 mpg123_stereo = fr.stereo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
809 mpg123_layer = fr.lay;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
810 mpg123_lsf = fr.lsf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
811 mpg123_mpeg25 = fr.mpeg25;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
812 mpg123_mode = fr.mode;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
813
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
814 if (strncasecmp(filename, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
815 mpg123_length = mpg123_info->num_frames * mpg123_info->tpf * 1000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
816 if (!mpg123_title)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
817 mpg123_title = get_song_title(NULL, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
818 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
819 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
820 if (!mpg123_title)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
821 mpg123_title = mpg123_http_get_title(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
822 mpg123_length = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
823 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
824
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
825 mpg123_ip.set_info(mpg123_title, mpg123_length,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
826 mpg123_bitrate * 1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
827 mpg123_freqs[fr.sampling_frequency], fr.stereo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
828
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
829 output_opened = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
830
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
831 if (!open_output()) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
832 audio_error = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
833 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
834 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
835 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
836 play_frame(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
837 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
838
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
839 mpg123_info->first_frame = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
840 while (mpg123_info->going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
841 if (mpg123_info->jump_to_time != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
842 void *xp = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
843 if (have_xing_header)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
844 xp = &xing_header;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
845 if (mpg123_seek(&fr, xp, vbr, mpg123_info->jump_to_time) > -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
846 mpg123_ip.output->flush(mpg123_info->jump_to_time * 1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
847 mpg123_info->eof = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
848 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
849 mpg123_info->jump_to_time = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
850 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
851 if (!mpg123_info->eof) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
852 if (mpg123_read_frame(&fr) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
853 if (fr.lay != mpg123_layer || fr.lsf != mpg123_lsf) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
854 memcpy(&temp_fr, &fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
855 if (mpg123_read_frame(&temp_fr) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
856 if (fr.lay == temp_fr.lay && fr.lsf == temp_fr.lsf) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
857 mpg123_layer = fr.lay;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
858 mpg123_lsf = fr.lsf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
859 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
860 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
861 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
862 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
863 skip_frames = 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
864 mpg123_info->output_audio = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
865 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
866 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
867
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
868 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
869 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
870 if (mpg123_freqs[fr.sampling_frequency] != mpg123_frequency
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
871 || mpg123_stereo != fr.stereo) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
872 memcpy(&temp_fr, &fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
873 if (mpg123_read_frame(&temp_fr) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
874 if (fr.sampling_frequency ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
875 temp_fr.sampling_frequency
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
876 && temp_fr.stereo == fr.stereo) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
877 mpg123_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
878 mpg123_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
879 while (mpg123_ip.output->buffer_playing()
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
880 && mpg123_info->going
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
881 && mpg123_info->jump_to_time == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
882 xmms_usleep(20000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
883 if (!mpg123_info->going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
884 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
885 temp_time = mpg123_ip.output->output_time();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
886 mpg123_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
887 mpg123_frequency =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
888 mpg123_freqs[fr.sampling_frequency];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
889 mpg123_stereo = fr.stereo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
890 if (!mpg123_ip.output->
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
891 open_audio(mpg123_cfg.resolution ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
892 16 ? FMT_S16_NE : FMT_U8,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
893 mpg123_freqs[fr.sampling_frequency]
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
894 >> mpg123_cfg.downsample,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
895 mpg123_cfg.channels ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
896 2 ? fr.stereo : 1)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
897 audio_error = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
898 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
899 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
900 mpg123_ip.output->flush(temp_time);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
901 mpg123_ip.set_info(mpg123_title, mpg123_length,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
902 mpg123_bitrate * 1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
903 mpg123_frequency,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
904 mpg123_stereo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
905 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
906 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
907 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
908 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
909 skip_frames = 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
910 mpg123_info->output_audio = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
911 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
912 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
913 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
914 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
915
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
916 if (tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index] !=
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
917 mpg123_bitrate)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
918 mpg123_bitrate =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
919 tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
920
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
921 if (!disp_count) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
922 disp_count = 20;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
923 if (mpg123_bitrate != disp_bitrate) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
924 /* FIXME networks streams */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
925 disp_bitrate = mpg123_bitrate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
926 if (!have_xing_header
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
927 && strncasecmp(filename, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
928 double rel = mpg123_relative_pos();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
929 if (rel) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
930 mpg123_length =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
931 mpg123_ip.output->written_time() / rel;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
932 vbr = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
933 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
934
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
935 if (rel == 0 || !(mpg123_length > 0)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
936 mpg123_info->num_frames =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
937 mpg123_calc_numframes(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
938 mpg123_info->tpf = mpg123_compute_tpf(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
939 mpg123_length =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
940 mpg123_info->num_frames *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
941 mpg123_info->tpf * 1000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
942 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
943
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
944
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
945 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
946 mpg123_ip.set_info(mpg123_title, mpg123_length,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
947 mpg123_bitrate * 1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
948 mpg123_frequency, mpg123_stereo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
949 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
950 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
951 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
952 disp_count--;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
953 play_frame(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
954 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
955 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
956 mpg123_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
957 mpg123_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
958 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
959 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
960 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
961 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
962 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
963 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
964 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
965 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
966 g_free(mpg123_title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
967 mpg123_title = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
968 mpg123_stream_close();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
969 if (output_opened && !audio_error)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
970 mpg123_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
971 g_free(mpg123_pcm_sample);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
972 mpg123_filename = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
973 g_free(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
974
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
975 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
976 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
977
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
978 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
979 play_file(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
980 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
981 memset(&fr, 0, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
982 memset(&temp_fr, 0, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
983
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
984 mpg123_info = g_malloc0(sizeof(PlayerInfo));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
985 mpg123_info->going = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
986 mpg123_info->first_frame = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
987 mpg123_info->output_audio = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
988 mpg123_info->jump_to_time = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
989 skip_frames = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
990 audio_error = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
991 output_opened = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
992 dopause = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
993
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
994 decode_thread = g_thread_create(decode_loop, g_strdup(filename), TRUE,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
995 NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
996 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
997
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
998 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
999 stop(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1000 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1001 if (mpg123_info && mpg123_info->going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1002 mpg123_info->going = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1003 g_thread_join(decode_thread);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1004 g_free(mpg123_info);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1005 mpg123_info = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1006 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1007 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1008
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1009 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1010 seek(int time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1011 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1012 mpg123_info->jump_to_time = time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1013
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1014 while (mpg123_info->jump_to_time != -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1015 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1016 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1017
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1018 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1019 do_pause(short p)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1020 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1021 if (output_opened)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1022 mpg123_ip.output->pause(p);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1023 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1024 dopause = p;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1025 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1026
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1027 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1028 get_time(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1029 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1030 if (audio_error)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1031 return -2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1032 if (!mpg123_info)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1033 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1034 if (!mpg123_info->going
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1035 || (mpg123_info->eof && !mpg123_ip.output->buffer_playing()))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1036 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1037 return mpg123_ip.output->output_time();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1038 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1039
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1040 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1041 aboutbox(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1042 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1043 static GtkWidget *aboutbox;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1044
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1045 if (aboutbox != NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1046 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1047
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1048 aboutbox = xmms_show_message(_("About MPEG Audio Plugin"),
223
e7e9a86c0c01 [svn] Update credits on here reflecting audacious-decoder changes.
nenolod
parents: 177
diff changeset
1049 _("Audacious decoding engine by William Pitcock <nenolod@nenolod.net>, derived from:\n"
e7e9a86c0c01 [svn] Update credits on here reflecting audacious-decoder changes.
nenolod
parents: 177
diff changeset
1050 "mpg123 decoding engine by Michael Hipp <mh@mpg123.de>\n"
e7e9a86c0c01 [svn] Update credits on here reflecting audacious-decoder changes.
nenolod
parents: 177
diff changeset
1051 "Derived partially from mpg123 0.59s.mc3 as well.\n"
129
ce9d4aa5889a [svn] Update the credits to note the code sync that occured.
nenolod
parents: 61
diff changeset
1052 "Based on the original XMMS plugin."),
ce9d4aa5889a [svn] Update the credits to note the code sync that occured.
nenolod
parents: 61
diff changeset
1053 _("Ok"),
ce9d4aa5889a [svn] Update the credits to note the code sync that occured.
nenolod
parents: 61
diff changeset
1054 FALSE, NULL, NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1055
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1056 g_signal_connect(G_OBJECT(aboutbox), "destroy",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1057 G_CALLBACK(gtk_widget_destroyed), &aboutbox);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1058 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1059
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1060 InputPlugin mpg123_ip = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1061 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1062 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1063 NULL, /* Description */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1064 init,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1065 aboutbox,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1066 mpg123_configure,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1067 is_our_file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1068 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1069 play_file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1070 stop,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1071 do_pause,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1072 seek,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1073 mpg123_set_eq,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1074 get_time,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1075 NULL, NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1076 cleanup,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1077 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1078 NULL, NULL, NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1079 get_song_info,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1080 mpg123_file_info_box, /* file_info_box */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1081 NULL
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1082 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1083
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1084 InputPlugin *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1085 get_iplugin_info(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1086 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1087 mpg123_ip.description = g_strdup_printf(_("MPEG Audio Plugin"));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1088 return &mpg123_ip;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1089 }