Mercurial > audlegacy
annotate Plugins/Input/mpg123/mpg123.c @ 1105:4be4d74db123 trunk
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
author | yaz |
---|---|
date | Sat, 27 May 2006 11:02:08 -0700 |
parents | b5ae09a6c2f1 |
children | c4063c84b797 |
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 |
354
e2775c9b8b13
[svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents:
353
diff
changeset
|
28 #define BUFSIZE_X 2048 |
e2775c9b8b13
[svn] very rudementary http stream detection support for mpg123-clone.
nenolod
parents:
353
diff
changeset
|
29 |
61 | 30 static struct frame fr, temp_fr; |
31 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
32 PlayerInfo *mpgdec_info = NULL; |
61 | 33 static GThread *decode_thread; |
34 | |
35 static gboolean audio_error = FALSE, output_opened = FALSE, dopause = FALSE; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
36 gint mpgdec_bitrate, mpgdec_frequency, mpgdec_length, mpgdec_layer, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
37 mpgdec_lsf; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
38 gchar *mpgdec_title = NULL, *mpgdec_filename = NULL; |
61 | 39 static int disp_bitrate, skip_frames = 0; |
40 static int cpu_fflags, cpu_efflags; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
41 gboolean mpgdec_stereo, mpgdec_mpeg25; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
42 int mpgdec_mode; |
61 | 43 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
44 mpgdec_t *ins; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
45 |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
46 gchar **mpgdec_id3_encoding_list = NULL; |
61 | 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 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
52 const char *mpgdec_id3_genres[GENRE_MAX] = { |
61 | 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 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
99 mpgdec_compute_tpf(struct frame *fr) |
61 | 100 { |
101 const int bs[4] = { 0, 384, 1152, 1152 }; | |
102 double tpf; | |
103 | |
104 tpf = bs[fr->lay]; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
105 tpf /= mpgdec_freqs[fr->sampling_frequency] << (fr->lsf); |
61 | 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] = { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
120 {mpgdec_synth_1to1, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
121 mpgdec_synth_2to1, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
122 mpgdec_synth_4to1}, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
123 {mpgdec_synth_1to1_8bit, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
124 mpgdec_synth_2to1_8bit, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
125 mpgdec_synth_4to1_8bit}, |
61 | 126 }; |
127 | |
128 static func_mono funcs_mono[2][4] = { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
129 {mpgdec_synth_1to1_mono, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
130 mpgdec_synth_2to1_mono, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
131 mpgdec_synth_4to1_mono}, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
132 {mpgdec_synth_1to1_8bit_mono, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
133 mpgdec_synth_2to1_8bit_mono, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
134 mpgdec_synth_4to1_8bit_mono} |
61 | 135 }; |
136 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
137 if (mpgdec_cfg.resolution == 8) |
61 | 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) { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
144 mpgdec_make_conv16to8_table(); |
61 | 145 } |
146 } | |
147 | |
148 static void | |
149 init(void) | |
150 { | |
151 ConfigDb *db; | |
152 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
153 ins = mpgdec_new(); |
61 | 154 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
155 memset(&mpgdec_cfg, 0, sizeof(mpgdec_cfg)); |
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
|
156 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
157 mpgdec_cfg.resolution = 16; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
158 mpgdec_cfg.channels = 2; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
159 mpgdec_cfg.downsample = 0; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
160 mpgdec_cfg.http_buffer_size = 128; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
161 mpgdec_cfg.http_prebuffer = 25; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
162 mpgdec_cfg.proxy_port = 8080; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
163 mpgdec_cfg.proxy_use_auth = FALSE; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
164 mpgdec_cfg.proxy_user = NULL; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
165 mpgdec_cfg.proxy_pass = NULL; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
166 mpgdec_cfg.use_udp_channel = TRUE; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
167 mpgdec_cfg.title_override = FALSE; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
168 mpgdec_cfg.disable_id3v2 = FALSE; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
169 mpgdec_cfg.default_synth = SYNTH_AUTO; |
61 | 170 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
171 mpgdec_cfg.title_encoding_enabled = FALSE; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
172 mpgdec_cfg.title_encoding = NULL; |
61 | 173 |
174 db = bmp_cfg_db_open(); | |
175 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
176 bmp_cfg_db_get_int(db, "MPG123", "resolution", &mpgdec_cfg.resolution); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
177 bmp_cfg_db_get_int(db, "MPG123", "channels", &mpgdec_cfg.channels); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
178 bmp_cfg_db_get_int(db, "MPG123", "downsample", &mpgdec_cfg.downsample); |
61 | 179 bmp_cfg_db_get_int(db, "MPG123", "http_buffer_size", |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
180 &mpgdec_cfg.http_buffer_size); |
61 | 181 bmp_cfg_db_get_int(db, "MPG123", "http_prebuffer", |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
182 &mpgdec_cfg.http_prebuffer); |
61 | 183 bmp_cfg_db_get_bool(db, "MPG123", "save_http_stream", |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
184 &mpgdec_cfg.save_http_stream); |
61 | 185 if (!bmp_cfg_db_get_string |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
186 (db, "MPG123", "save_http_path", &mpgdec_cfg.save_http_path)) |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
187 mpgdec_cfg.save_http_path = g_strdup(g_get_home_dir()); |
61 | 188 |
189 bmp_cfg_db_get_bool(db, "MPG123", "use_udp_channel", | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
190 &mpgdec_cfg.use_udp_channel); |
61 | 191 |
192 bmp_cfg_db_get_bool(db, "MPG123", "title_override", | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
193 &mpgdec_cfg.title_override); |
61 | 194 bmp_cfg_db_get_bool(db, "MPG123", "disable_id3v2", |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
195 &mpgdec_cfg.disable_id3v2); |
61 | 196 if (!bmp_cfg_db_get_string |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
197 (db, "MPG123", "id3_format", &mpgdec_cfg.id3_format)) |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
198 mpgdec_cfg.id3_format = g_strdup("%p - %t"); |
61 | 199 bmp_cfg_db_get_int(db, "MPG123", "default_synth", |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
200 &mpgdec_cfg.default_synth); |
61 | 201 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
202 bmp_cfg_db_get_bool(db, "MPG123", "title_encoding_enabled", &mpgdec_cfg.title_encoding_enabled); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
203 bmp_cfg_db_get_string(db, "MPG123", "title_encoding", &mpgdec_cfg.title_encoding); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
204 if (mpgdec_cfg.title_encoding_enabled) |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
205 mpgdec_id3_encoding_list = g_strsplit_set(mpgdec_cfg.title_encoding, ENCODING_SEPARATOR, 0); |
61 | 206 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
207 bmp_cfg_db_get_bool(db, NULL, "use_proxy", &mpgdec_cfg.use_proxy); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
208 bmp_cfg_db_get_string(db, NULL, "proxy_host", &mpgdec_cfg.proxy_host); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
209 bmp_cfg_db_get_int(db, NULL, "proxy_port", &mpgdec_cfg.proxy_port); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
210 bmp_cfg_db_get_bool(db, NULL, "proxy_use_auth", &mpgdec_cfg.proxy_use_auth); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
211 bmp_cfg_db_get_string(db, NULL, "proxy_user", &mpgdec_cfg.proxy_user); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
212 bmp_cfg_db_get_string(db, NULL, "proxy_pass", &mpgdec_cfg.proxy_pass); |
1071
592ef16386aa
[svn] - use global proxy configuration instead of individual configurations (chainsaw)
nenolod
parents:
997
diff
changeset
|
213 |
61 | 214 bmp_cfg_db_close(db); |
215 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
216 if (mpgdec_cfg.resolution != 16 && mpgdec_cfg.resolution != 8) |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
217 mpgdec_cfg.resolution = 16; |
61 | 218 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
219 mpgdec_cfg.channels = CLAMP(mpgdec_cfg.channels, 0, 2); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
220 mpgdec_cfg.downsample = CLAMP(mpgdec_cfg.downsample, 0, 2); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
221 mpgdec_getcpuflags(&cpu_fflags, &cpu_efflags); |
61 | 222 } |
223 | |
224 static void | |
225 cleanup(void) | |
226 { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
227 g_free(mpgdec_ip.description); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
228 mpgdec_ip.description = NULL; |
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
|
229 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
230 if (mpgdec_cfg.save_http_path) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
231 free(mpgdec_cfg.save_http_path); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
232 mpgdec_cfg.save_http_path = NULL; |
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
|
233 } |
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 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
235 if (mpgdec_cfg.proxy_host) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
236 free(mpgdec_cfg.proxy_host); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
237 mpgdec_cfg.proxy_host = NULL; |
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
|
238 } |
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 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
240 if (mpgdec_cfg.proxy_user) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
241 free(mpgdec_cfg.proxy_user); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
242 mpgdec_cfg.proxy_user = NULL; |
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
|
243 } |
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 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
245 if (mpgdec_cfg.proxy_pass) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
246 free(mpgdec_cfg.proxy_pass); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
247 mpgdec_cfg.proxy_pass = NULL; |
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
|
248 } |
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 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
250 if (mpgdec_cfg.id3_format) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
251 free(mpgdec_cfg.id3_format); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
252 mpgdec_cfg.id3_format = NULL; |
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
|
253 } |
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 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
255 if (mpgdec_cfg.title_encoding) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
256 free(mpgdec_cfg.title_encoding); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
257 mpgdec_cfg.title_encoding = NULL; |
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
|
258 } |
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 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
260 g_strfreev(mpgdec_id3_encoding_list); |
61 | 261 } |
262 | |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
263 static guint32 |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
264 convert_to_header(guint8 * buf) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
265 { |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
266 return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
267 } |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
268 |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
269 |
777 | 270 #if 0 |
61 | 271 #define DET_BUF_SIZE 1024 |
272 | |
273 static gboolean | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
274 mpgdec_detect_by_content(char *filename) |
61 | 275 { |
276 VFSFile *file; | |
277 guchar tmp[4]; | |
278 guint32 head; | |
279 struct frame fr; | |
280 guchar buf[DET_BUF_SIZE]; | |
281 int in_buf, i; | |
282 gboolean ret = FALSE; | |
775 | 283 guint cyc = 0; |
61 | 284 |
285 if ((file = vfs_fopen(filename, "rb")) == NULL) | |
286 return FALSE; | |
287 if (vfs_fread(tmp, 1, 4, file) != 4) | |
288 goto done; | |
289 head = convert_to_header(tmp); | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
290 while (!mpgdec_head_check(head)) { |
61 | 291 /* |
292 * The mpeg-stream can start anywhere in the file, | |
293 * 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
|
294 * |
771 | 295 * 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
|
296 * code for safety's sake. Buffer overflows suck. --nenolod |
61 | 297 */ |
298 /* Optimize this */ | |
299 in_buf = vfs_fread(buf, 1, DET_BUF_SIZE, file); | |
300 if (in_buf == 0) | |
301 goto done; | |
302 | |
303 for (i = 0; i < in_buf; i++) { | |
304 head <<= 8; | |
305 head |= buf[i]; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
306 if (mpgdec_head_check(head)) { |
61 | 307 vfs_fseek(file, i + 1 - in_buf, SEEK_CUR); |
308 break; | |
309 } | |
310 } | |
775 | 311 |
312 if (++cyc > 20) | |
313 goto done; | |
61 | 314 } |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
315 if (mpgdec_decode_header(&fr, head)) { |
61 | 316 /* |
317 * We found something which looks like a MPEG-header. | |
318 * We check the next frame too, to be sure | |
319 */ | |
320 | |
321 if (vfs_fseek(file, fr.framesize, SEEK_CUR) != 0) | |
322 goto done; | |
323 if (vfs_fread(tmp, 1, 4, file) != 4) | |
324 goto done; | |
325 head = convert_to_header(tmp); | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
326 if (mpgdec_head_check(head) && mpgdec_decode_header(&fr, head)) |
61 | 327 ret = TRUE; |
328 } | |
329 | |
330 done: | |
331 vfs_fclose(file); | |
332 return ret; | |
333 } | |
777 | 334 #endif |
61 | 335 |
336 static int | |
337 is_our_file(char *filename) | |
338 { | |
653 | 339 gchar *ext = strrchr(filename, '.'); |
340 | |
761 | 341 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
|
342 return TRUE; |
777 | 343 else if (ext && (!strncasecmp(ext, ".mp3", 4) |
344 || !strncasecmp(ext, ".mp2", 4) | |
345 || !strncasecmp(ext, ".mpg", 4))) | |
346 return TRUE; | |
653 | 347 |
778 | 348 return FALSE; |
61 | 349 } |
350 | |
351 static void | |
352 play_frame(struct frame *fr) | |
353 { | |
354 if (fr->error_protection) { | |
355 bsi.wordpointer += 2; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
356 /* mpgdec_getbits(16); *//* skip crc */ |
61 | 357 } |
358 if (!fr->do_layer(fr)) { | |
359 skip_frames = 2; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
360 mpgdec_info->output_audio = FALSE; |
61 | 361 } |
362 else { | |
363 if (!skip_frames) | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
364 mpgdec_info->output_audio = TRUE; |
61 | 365 else |
366 skip_frames--; | |
367 } | |
368 } | |
369 | |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
370 static const char * |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
371 get_id3_genre(unsigned char genre_code) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
372 { |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
373 if (genre_code < GENRE_MAX) |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
374 return gettext(mpgdec_id3_genres[genre_code]); |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
375 |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
376 return ""; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
377 } |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
378 |
61 | 379 guint |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
380 mpgdec_strip_spaces(char *src, size_t n) |
61 | 381 { |
382 gchar *space = NULL, /* last space in src */ | |
383 *start = src; | |
384 | |
385 while (n--) | |
386 switch (*src++) { | |
387 case '\0': | |
388 n = 0; /* breaks out of while loop */ | |
389 | |
390 src--; | |
391 break; | |
392 case ' ': | |
393 if (space == NULL) | |
394 space = src - 1; | |
395 break; | |
396 default: | |
397 space = NULL; /* don't terminate intermediate spaces */ | |
398 | |
399 break; | |
400 } | |
401 if (space != NULL) { | |
402 src = space; | |
403 *src = '\0'; | |
404 } | |
405 return src - start; | |
406 } | |
407 | |
408 /* | |
409 * Function extname (filename) | |
410 * | |
411 * Return pointer within filename to its extenstion, or NULL if | |
412 * filename has no extension. | |
413 * | |
414 */ | |
415 static gchar * | |
416 extname(const char *filename) | |
417 { | |
418 gchar *ext = strrchr(filename, '.'); | |
419 | |
420 if (ext != NULL) | |
421 ++ext; | |
422 | |
423 return ext; | |
424 } | |
425 | |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
426 /* |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
427 * Function id3v1_to_id3v2 (v1, v2) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
428 * |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
429 * Convert ID3v1 tag `v1' to ID3v2 tag `v2'. |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
430 * |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
431 */ |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
432 void |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
433 mpgdec_id3v1_to_id3v2(struct id3v1tag_t *v1, struct id3tag_t *v2) |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
434 { |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
435 memset(v2, 0, sizeof(struct id3tag_t)); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
436 strncpy(v2->title, v1->title, 30); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
437 strncpy(v2->artist, v1->artist, 30); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
438 strncpy(v2->album, v1->album, 30); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
439 strncpy(v2->comment, v1->u.v1_0.comment, 30); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
440 strncpy(v2->genre, get_id3_genre(v1->genre), sizeof(v2->genre)); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
441 g_strstrip(v2->title); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
442 g_strstrip(v2->artist); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
443 g_strstrip(v2->album); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
444 g_strstrip(v2->comment); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
445 g_strstrip(v2->genre); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
446 { |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
447 char y[5]; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
448 memcpy(y, v1->year, 4); y[4]=0; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
449 v2->year = atoi(y); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
450 } |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
451 |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
452 /* Check for v1.1 tags. */ |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
453 if (v1->u.v1_1.__zero == 0) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
454 v2->track_number = v1->u.v1_1.track_number; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
455 else |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
456 v2->track_number = 0; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
457 } |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
458 |
974 | 459 #define REMOVE_NONEXISTANT_TAG(x) if (!*x) { x = NULL; } |
460 | |
61 | 461 /* |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
462 * Function mpgdec_format_song_title (tag, filename) |
61 | 463 * |
464 * Create song title according to `tag' and/or `filename' and | |
465 * return it. The title must be subsequently freed using g_free(). | |
466 * | |
467 */ | |
468 gchar * | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
469 mpgdec_format_song_title(TagLib_Tag *taglib_tag, gchar * filename) |
61 | 470 { |
471 gchar *title = NULL; | |
472 TitleInput *input; | |
473 | |
474 input = bmp_title_input_new(); | |
475 | |
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
|
476 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
|
477 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
|
478 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
|
479 input->track_name = taglib_tag_title(taglib_tag); |
974 | 480 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
481 mpgdec_strip_spaces(input->performer,strlen(input->performer)); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
482 mpgdec_strip_spaces(input->album_name,strlen(input->album_name)); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
483 mpgdec_strip_spaces(input->track_name,strlen(input->track_name)); |
974 | 484 |
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
|
485 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
|
486 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
|
487 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
|
488 input->comment = taglib_tag_comment(taglib_tag); |
974 | 489 |
490 /* remove any blank tags, fucking taglib */ | |
491 REMOVE_NONEXISTANT_TAG(input->performer); | |
492 REMOVE_NONEXISTANT_TAG(input->album_name); | |
493 REMOVE_NONEXISTANT_TAG(input->track_name); | |
494 REMOVE_NONEXISTANT_TAG(input->genre); | |
495 REMOVE_NONEXISTANT_TAG(input->comment); | |
61 | 496 } |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
497 if(input->performer) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
498 input->performer = str_to_utf8(input->performer); |
61 | 499 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
500 if(input->album_name) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
501 input->album_name = str_to_utf8(input->album_name); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
502 |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
503 if(input->track_name) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
504 input->track_name = str_to_utf8(input->track_name); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
505 |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
506 if(input->comment) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
507 input->comment = str_to_utf8(input->comment); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
508 |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
509 |
61 | 510 input->file_name = g_path_get_basename(filename); |
511 input->file_path = g_path_get_dirname(filename); | |
512 input->file_ext = extname(filename); | |
513 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
514 title = xmms_get_titlestring(mpgdec_cfg.title_override ? |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
515 mpgdec_cfg.id3_format : |
61 | 516 xmms_get_gentitle_format(), input); |
517 | |
974 | 518 if (!title /* || strlen(input->track_name) == 0 */) { |
61 | 519 /* Format according to filename. */ |
520 title = g_path_get_basename(filename); | |
521 if (extname(title)) | |
522 *(extname(title) - 1) = '\0'; /* removes period */ | |
523 } | |
524 | |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
525 if(input->performer) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
526 g_free(input->performer); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
527 if(input->album_name) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
528 g_free(input->album_name); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
529 if(input->track_name) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
530 g_free(input->track_name); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
531 if(input->comment) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
532 g_free(input->comment); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
533 |
61 | 534 g_free(input->file_path); |
535 g_free(input->file_name); | |
536 g_free(input); | |
537 | |
538 return title; | |
539 } | |
540 | |
541 /* | |
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
|
542 * Function get_song_title (filename) |
61 | 543 * |
544 */ | |
545 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
|
546 get_song_title(char *filename) |
61 | 547 { |
548 char *ret = NULL; | |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
549 #ifdef USE_CHARDET |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
550 taglib_set_strings_unicode(FALSE); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1098
diff
changeset
|
551 #endif |
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
|
552 taglib_file = taglib_file_new(filename); |
997
e64eb333b63f
[svn] Properly nullify the tag pointer or we could be passing a stale one.
chainsaw
parents:
994
diff
changeset
|
553 taglib_tag = 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
|
554 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
|
555 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
|
556 taglib_ap = taglib_file_audioproperties(taglib_file); |
61 | 557 } |
558 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
559 ret = mpgdec_format_song_title(taglib_tag, filename); |
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
|
560 |
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
|
561 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
|
562 taglib_tag_free_strings(); |
61 | 563 return ret; |
564 } | |
565 | |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
566 static long |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
567 get_song_length(VFSFile * file) |
61 | 568 { |
569 int len; | |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
570 char tmp[4]; |
61 | 571 |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
572 vfs_fseek(file, 0, SEEK_END); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
573 len = vfs_ftell(file); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
574 vfs_fseek(file, -128, SEEK_END); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
575 vfs_fread(tmp, 1, 3, file); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
576 if (!strncmp(tmp, "TAG", 3)) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
577 len -= 128; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
578 return len; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
579 } |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
580 |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
581 |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
582 static guint |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
583 get_song_time(VFSFile * file) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
584 { |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
585 guint32 head; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
586 guchar tmp[4], *buf; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
587 struct frame frm; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
588 xing_header_t xing_header; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
589 double tpf, bpf; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
590 guint32 len; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
591 |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
592 if (!file) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
593 return -1; |
61 | 594 |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
595 vfs_fseek(file, 0, SEEK_SET); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
596 if (vfs_fread(tmp, 1, 4, file) != 4) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
597 return 0; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
598 head = convert_to_header(tmp); |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
599 while (!mpgdec_head_check(head)) { |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
600 head <<= 8; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
601 if (vfs_fread(tmp, 1, 1, file) != 1) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
602 return 0; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
603 head |= tmp[0]; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
604 } |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
605 if (mpgdec_decode_header(&frm, head)) { |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
606 buf = g_malloc(frm.framesize + 4); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
607 vfs_fseek(file, -4, SEEK_CUR); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
608 vfs_fread(buf, 1, frm.framesize + 4, file); |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
609 tpf = mpgdec_compute_tpf(&frm); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
610 if (mpgdec_get_xing_header(&xing_header, buf)) { |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
611 g_free(buf); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
612 if (xing_header.bytes == 0) |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
613 xing_header.bytes = get_song_length(file); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
614 return (tpf * xing_header.frames * 1000); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
615 } |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
616 g_free(buf); |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
617 bpf = mpgdec_compute_bpf(&frm); |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
618 len = get_song_length(file); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
619 return ((guint) (len / bpf) * tpf * 1000); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
620 } |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
621 return 0; |
61 | 622 } |
623 | |
624 static void | |
625 get_song_info(char *filename, char **title_real, int *len_real) | |
626 { | |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
627 VFSFile *file; |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
628 |
61 | 629 (*len_real) = -1; |
630 (*title_real) = NULL; | |
631 | |
632 /* | |
633 * TODO: Getting song info from http streams. | |
634 */ | |
635 if (!strncasecmp(filename, "http://", 7)) | |
636 return; | |
637 | |
994
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
638 if ((file = vfs_fopen(filename, "rb")) != NULL) { |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
639 (*len_real) = get_song_time(file); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
640 (*title_real) = get_song_title(filename); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
641 vfs_fclose(file); |
3d2984564cb8
[svn] Taglib length determination veto by nenolod, reverting. Leaving fileinfo optimizations in place, though.
chainsaw
parents:
993
diff
changeset
|
642 } |
61 | 643 } |
644 | |
645 static int | |
646 open_output(void) | |
647 { | |
648 int r; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
649 AFormat fmt = mpgdec_cfg.resolution == 16 ? FMT_S16_NE : FMT_U8; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
650 int freq = mpgdec_freqs[fr.sampling_frequency] >> mpgdec_cfg.downsample; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
651 int channels = mpgdec_cfg.channels == 2 ? fr.stereo : 1; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
652 r = mpgdec_ip.output->open_audio(fmt, freq, channels); |
61 | 653 |
654 if (r && dopause) { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
655 mpgdec_ip.output->pause(TRUE); |
61 | 656 dopause = FALSE; |
657 } | |
658 | |
659 return r; | |
660 } | |
661 | |
662 | |
663 static int | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
664 mpgdec_seek(struct frame *fr, xing_header_t * xh, gboolean vbr, int time) |
61 | 665 { |
666 int jumped = -1; | |
667 | |
668 if (xh) { | |
669 int percent = ((double) time * 100.0) / | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
670 (mpgdec_info->num_frames * mpgdec_info->tpf); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
671 int byte = mpgdec_seek_point(xh, percent); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
672 jumped = mpgdec_stream_jump_to_byte(fr, byte); |
61 | 673 } |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
674 else if (vbr && mpgdec_length > 0) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
675 int byte = ((guint64) time * 1000 * mpgdec_info->filesize) / |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
676 mpgdec_length; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
677 jumped = mpgdec_stream_jump_to_byte(fr, byte); |
61 | 678 } |
679 else { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
680 int frame = time / mpgdec_info->tpf; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
681 jumped = mpgdec_stream_jump_to_frame(fr, frame); |
61 | 682 } |
683 | |
684 return jumped; | |
685 } | |
686 | |
687 | |
688 static void * | |
689 decode_loop(void *arg) | |
690 { | |
691 gboolean have_xing_header = FALSE, vbr = FALSE; | |
1096
9b4e9be457f0
[svn] - remove improper sampling rate change condition. Valid MP3s will not do this. Infact, I've never seen an MP3 that does this. Additionally, it doesn't even work with Shoutcast.
nenolod
parents:
1090
diff
changeset
|
692 int disp_count = 0; |
61 | 693 char *filename = arg; |
694 xing_header_t xing_header; | |
695 | |
696 /* This is used by fileinfo on http streams */ | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
697 mpgdec_bitrate = 0; |
61 | 698 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
699 mpgdec_pcm_sample = g_malloc0(32768); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
700 mpgdec_pcm_point = 0; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
701 mpgdec_filename = filename; |
61 | 702 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
703 mpgdec_read_frame_init(); |
61 | 704 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
705 mpgdec_open_stream(filename, -1); |
61 | 706 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
707 if (mpgdec_info->eof || !mpgdec_read_frame(&fr)) |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
708 mpgdec_info->eof = TRUE; |
61 | 709 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
710 if (!mpgdec_info->eof && mpgdec_info->going) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
711 if (mpgdec_cfg.channels == 2) |
61 | 712 fr.single = -1; |
713 else | |
714 fr.single = 3; | |
715 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
716 fr.down_sample = mpgdec_cfg.downsample; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
717 fr.down_sample_sblimit = SBLIMIT >> mpgdec_cfg.downsample; |
61 | 718 set_synth_functions(&fr); |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
719 mpgdec_init_layer3(fr.down_sample_sblimit); |
61 | 720 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
721 mpgdec_info->tpf = mpgdec_compute_tpf(&fr); |
61 | 722 if (strncasecmp(filename, "http://", 7)) { |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
723 if (mpgdec_stream_check_for_xing_header(&fr, &xing_header)) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
724 mpgdec_info->num_frames = xing_header.frames; |
61 | 725 have_xing_header = TRUE; |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
726 mpgdec_read_frame(&fr); |
61 | 727 } |
728 } | |
729 | |
730 for (;;) { | |
731 memcpy(&temp_fr, &fr, sizeof(struct frame)); | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
732 if (!mpgdec_read_frame(&temp_fr)) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
733 mpgdec_info->eof = TRUE; |
61 | 734 break; |
735 } | |
736 if (fr.lay != temp_fr.lay || | |
737 fr.sampling_frequency != temp_fr.sampling_frequency || | |
738 fr.stereo != temp_fr.stereo || fr.lsf != temp_fr.lsf) | |
739 memcpy(&fr, &temp_fr, sizeof(struct frame)); | |
740 else | |
741 break; | |
742 } | |
743 | |
744 if (!have_xing_header && strncasecmp(filename, "http://", 7)) | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
745 mpgdec_info->num_frames = mpgdec_calc_numframes(&fr); |
61 | 746 |
747 memcpy(&fr, &temp_fr, sizeof(struct frame)); | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
748 mpgdec_bitrate = tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index]; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
749 disp_bitrate = mpgdec_bitrate; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
750 mpgdec_frequency = mpgdec_freqs[fr.sampling_frequency]; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
751 mpgdec_stereo = fr.stereo; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
752 mpgdec_layer = fr.lay; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
753 mpgdec_lsf = fr.lsf; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
754 mpgdec_mpeg25 = fr.mpeg25; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
755 mpgdec_mode = fr.mode; |
61 | 756 |
757 if (strncasecmp(filename, "http://", 7)) { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
758 mpgdec_length = mpgdec_info->num_frames * mpgdec_info->tpf * 1000; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
759 if (!mpgdec_title) |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
760 mpgdec_title = get_song_title(filename); |
61 | 761 } |
762 else { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
763 if (!mpgdec_title) |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
764 mpgdec_title = mpgdec_http_get_title(filename); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
765 mpgdec_length = -1; |
61 | 766 } |
767 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
768 mpgdec_ip.set_info(mpgdec_title, mpgdec_length, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
769 mpgdec_bitrate * 1000, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
770 mpgdec_freqs[fr.sampling_frequency], fr.stereo); |
61 | 771 |
772 output_opened = TRUE; | |
773 | |
774 if (!open_output()) { | |
775 audio_error = TRUE; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
776 mpgdec_info->eof = TRUE; |
61 | 777 } |
778 else | |
779 play_frame(&fr); | |
780 } | |
781 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
782 mpgdec_info->first_frame = FALSE; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
783 while (mpgdec_info->going) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
784 if (mpgdec_info->jump_to_time != -1) { |
61 | 785 void *xp = NULL; |
786 if (have_xing_header) | |
787 xp = &xing_header; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
788 if (mpgdec_seek(&fr, xp, vbr, mpgdec_info->jump_to_time) > -1) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
789 mpgdec_ip.output->flush(mpgdec_info->jump_to_time * 1000); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
790 mpgdec_info->eof = FALSE; |
61 | 791 } |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
792 mpgdec_info->jump_to_time = -1; |
61 | 793 } |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
794 if (!mpgdec_info->eof) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
795 if (mpgdec_read_frame(&fr) != 0) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
796 if (fr.lay != mpgdec_layer || fr.lsf != mpgdec_lsf) { |
61 | 797 memcpy(&temp_fr, &fr, sizeof(struct frame)); |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
798 if (mpgdec_read_frame(&temp_fr) != 0) { |
61 | 799 if (fr.lay == temp_fr.lay && fr.lsf == temp_fr.lsf) { |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
800 mpgdec_layer = fr.lay; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
801 mpgdec_lsf = fr.lsf; |
61 | 802 memcpy(&fr, &temp_fr, sizeof(struct frame)); |
803 } | |
804 else { | |
805 memcpy(&fr, &temp_fr, sizeof(struct frame)); | |
806 skip_frames = 2; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
807 mpgdec_info->output_audio = FALSE; |
61 | 808 continue; |
809 } | |
810 | |
811 } | |
812 } | |
813 | |
814 if (tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index] != | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
815 mpgdec_bitrate) |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
816 mpgdec_bitrate = |
61 | 817 tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index]; |
818 | |
819 if (!disp_count) { | |
820 disp_count = 20; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
821 if (mpgdec_bitrate != disp_bitrate) { |
61 | 822 /* FIXME networks streams */ |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
823 disp_bitrate = mpgdec_bitrate; |
61 | 824 if (!have_xing_header |
825 && strncasecmp(filename, "http://", 7)) { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
826 double rel = mpgdec_relative_pos(); |
61 | 827 if (rel) { |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
828 mpgdec_length = |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
829 mpgdec_ip.output->written_time() / rel; |
61 | 830 vbr = TRUE; |
831 } | |
832 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
833 if (rel == 0 || !(mpgdec_length > 0)) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
834 mpgdec_info->num_frames = |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
835 mpgdec_calc_numframes(&fr); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
836 mpgdec_info->tpf = mpgdec_compute_tpf(&fr); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
837 mpgdec_length = |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
838 mpgdec_info->num_frames * |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
839 mpgdec_info->tpf * 1000; |
61 | 840 } |
841 | |
842 | |
843 } | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
844 mpgdec_ip.set_info(mpgdec_title, mpgdec_length, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
845 mpgdec_bitrate * 1000, |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
846 mpgdec_frequency, mpgdec_stereo); |
61 | 847 } |
848 } | |
849 else | |
850 disp_count--; | |
851 play_frame(&fr); | |
852 } | |
853 else { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
854 mpgdec_ip.output->buffer_free(); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
855 mpgdec_ip.output->buffer_free(); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
856 mpgdec_info->eof = TRUE; |
1097 | 857 g_usleep(10000); |
61 | 858 } |
859 } | |
860 else { | |
1097 | 861 g_usleep(10000); |
61 | 862 } |
863 } | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
864 g_free(mpgdec_title); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
865 mpgdec_title = NULL; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
866 mpgdec_stream_close(); |
61 | 867 if (output_opened && !audio_error) |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
868 mpgdec_ip.output->close_audio(); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
869 g_free(mpgdec_pcm_sample); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
870 mpgdec_filename = NULL; |
61 | 871 g_free(filename); |
872 | |
873 return NULL; | |
874 } | |
875 | |
876 static void | |
877 play_file(char *filename) | |
878 { | |
879 memset(&fr, 0, sizeof(struct frame)); | |
880 memset(&temp_fr, 0, sizeof(struct frame)); | |
881 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
882 mpgdec_info = g_malloc0(sizeof(PlayerInfo)); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
883 mpgdec_info->going = 1; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
884 mpgdec_info->first_frame = TRUE; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
885 mpgdec_info->output_audio = TRUE; |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
886 mpgdec_info->jump_to_time = -1; |
61 | 887 skip_frames = 0; |
888 audio_error = FALSE; | |
889 output_opened = FALSE; | |
890 dopause = FALSE; | |
891 | |
892 decode_thread = g_thread_create(decode_loop, g_strdup(filename), TRUE, | |
893 NULL); | |
894 } | |
895 | |
896 static void | |
897 stop(void) | |
898 { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
899 if (mpgdec_info && mpgdec_info->going) { |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
900 mpgdec_info->going = FALSE; |
61 | 901 g_thread_join(decode_thread); |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
902 g_free(mpgdec_info); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
903 mpgdec_info = NULL; |
61 | 904 } |
905 } | |
906 | |
907 static void | |
908 seek(int time) | |
909 { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
910 mpgdec_info->jump_to_time = time; |
61 | 911 |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
912 while (mpgdec_info->jump_to_time != -1) |
1097 | 913 g_usleep(10000); |
61 | 914 } |
915 | |
916 static void | |
917 do_pause(short p) | |
918 { | |
919 if (output_opened) | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
920 mpgdec_ip.output->pause(p); |
61 | 921 else |
922 dopause = p; | |
923 } | |
924 | |
925 static int | |
926 get_time(void) | |
927 { | |
928 if (audio_error) | |
929 return -2; | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
930 if (!mpgdec_info) |
61 | 931 return -1; |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
932 if (!mpgdec_info->going |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
933 || (mpgdec_info->eof && !mpgdec_ip.output->buffer_playing())) |
61 | 934 return -1; |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
935 return mpgdec_ip.output->output_time(); |
61 | 936 } |
937 | |
938 static void | |
939 aboutbox(void) | |
940 { | |
941 static GtkWidget *aboutbox; | |
942 | |
943 if (aboutbox != NULL) | |
944 return; | |
945 | |
946 aboutbox = xmms_show_message(_("About MPEG Audio Plugin"), | |
223
e7e9a86c0c01
[svn] Update credits on here reflecting audacious-decoder changes.
nenolod
parents:
177
diff
changeset
|
947 _("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
|
948 "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
|
949 "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
|
950 "Based on the original XMMS plugin."), |
ce9d4aa5889a
[svn] Update the credits to note the code sync that occured.
nenolod
parents:
61
diff
changeset
|
951 _("Ok"), |
ce9d4aa5889a
[svn] Update the credits to note the code sync that occured.
nenolod
parents:
61
diff
changeset
|
952 FALSE, NULL, NULL); |
61 | 953 |
954 g_signal_connect(G_OBJECT(aboutbox), "destroy", | |
955 G_CALLBACK(gtk_widget_destroyed), &aboutbox); | |
956 } | |
957 | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
958 InputPlugin mpgdec_ip = { |
61 | 959 NULL, |
960 NULL, | |
961 NULL, /* Description */ | |
962 init, | |
963 aboutbox, | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
964 mpgdec_configure, |
61 | 965 is_our_file, |
966 NULL, | |
967 play_file, | |
968 stop, | |
969 do_pause, | |
970 seek, | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
971 mpgdec_set_eq, |
61 | 972 get_time, |
973 NULL, NULL, | |
974 cleanup, | |
975 NULL, | |
976 NULL, NULL, NULL, | |
977 get_song_info, | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
978 mpgdec_file_info_box, /* file_info_box */ |
61 | 979 NULL |
980 }; | |
981 | |
982 InputPlugin * | |
983 get_iplugin_info(void) | |
984 { | |
1098
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
985 mpgdec_ip.description = g_strdup_printf(_("MPEG Audio Plugin")); |
b5ae09a6c2f1
[svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents:
1097
diff
changeset
|
986 return &mpgdec_ip; |
61 | 987 } |