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