Mercurial > audlegacy
annotate Plugins/Input/aac/src/libmp4.c @ 339:e1630c75175b trunk
[svn] MP4 metadata retrieval support.
author | nenolod |
---|---|
date | Sun, 25 Dec 2005 23:22:44 -0800 |
parents | d8889f819081 |
children | c7a67ac8e19c |
rev | line source |
---|---|
61 | 1 /* |
2 * MP4/AAC decoder for xmms | |
3 * | |
4 * This decoding source code is completly independent of the faad2 | |
5 * package. | |
6 * This package exist for people who don't want to install | |
7 * faad2 and mpeg4ip project files. | |
8 * | |
9 * OPTIONNAL need | |
10 * -------------- | |
11 * libid3 (3.8.x - www.id3.org) | |
12 */ | |
13 | |
339 | 14 #include <glib.h> |
61 | 15 #include <gtk/gtk.h> |
339 | 16 #include <string.h> |
17 #include <stdlib.h> | |
61 | 18 #include "faad.h" |
19 #include "mp4.h" | |
20 | |
21 #include <audacious/plugin.h> | |
22 #include <libaudacious/util.h> | |
23 #include <libaudacious/titlestring.h> | |
24 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
25 #define MP4_DESCRIPTION "MP4 & MPEG2/4-AAC for bmp-0.9.7" |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
26 #define MP4_VERSION "ver.- 15 December 2004" |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
27 #define LIBMP4V2_VERSION "1.2.0" |
61 | 28 #define MP4_ABOUT "Written by ciberfred" |
29 #define BUFFER_SIZE FAAD_MIN_STREAMSIZE*64 | |
30 | |
31 static void mp4_init(void); | |
32 static void mp4_about(void); | |
33 static void mp4_play(char *); | |
34 static void mp4_stop(void); | |
35 static void mp4_pause(short); | |
36 static void mp4_seek(int); | |
37 static int mp4_getTime(void); | |
38 static void mp4_cleanup(void); | |
39 static void mp4_getSongInfo(char *); | |
40 static int mp4_isFile(char *); | |
339 | 41 static void mp4_getSongTitle(char *filename, char **, int *); |
61 | 42 static void* mp4Decode(void *); |
43 | |
44 InputPlugin mp4_ip = | |
45 { | |
46 0, // handle | |
47 0, // filename | |
48 MP4_DESCRIPTION, | |
49 mp4_init, | |
50 mp4_about, | |
51 0, // configuration | |
52 mp4_isFile, | |
53 0, //scandir | |
54 mp4_play, | |
55 mp4_stop, | |
56 mp4_pause, | |
57 mp4_seek, | |
58 0, // set equalizer | |
59 mp4_getTime, | |
60 0, // get volume | |
61 0, | |
62 mp4_cleanup, | |
63 0, // obsolete | |
64 0, // send visualisation data | |
65 0, // set player window info | |
66 0, // set song title text | |
339 | 67 mp4_getSongTitle, // get song title text |
61 | 68 mp4_getSongInfo, // info box |
69 0, // to output plugin | |
70 }; | |
71 | |
72 typedef struct _mp4cfg{ | |
73 gshort file_type; | |
74 #define FILE_UNKNOW 0 | |
75 #define FILE_MP4 1 | |
76 #define FILE_AAC 2 | |
77 } Mp4Config; | |
78 | |
79 static Mp4Config mp4cfg; | |
80 static gboolean bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
81 static GThread *decodeThread; |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
82 GStaticMutex mutex = G_STATIC_MUTEX_INIT; |
61 | 83 static int seekPosition = -1; |
84 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
85 void getMP4info(char*); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
86 int getAACTrack(MP4FileHandle); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
87 |
339 | 88 /* |
89 * Function extname (filename) | |
90 * | |
91 * Return pointer within filename to its extenstion, or NULL if | |
92 * filename has no extension. | |
93 * | |
94 */ | |
95 static gchar * | |
96 extname(const char *filename) | |
97 { | |
98 gchar *ext = strrchr(filename, '.'); | |
99 | |
100 if (ext != NULL) | |
101 ++ext; | |
102 | |
103 return ext; | |
104 } | |
61 | 105 |
106 InputPlugin *get_iplugin_info(void) | |
107 { | |
108 return(&mp4_ip); | |
109 } | |
110 | |
111 static void mp4_init(void) | |
112 { | |
113 mp4cfg.file_type = FILE_UNKNOW; | |
114 seekPosition = -1; | |
115 return; | |
116 } | |
117 | |
118 static void mp4_play(char *filename) | |
119 { | |
120 bPlaying = TRUE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
121 decodeThread = g_thread_create((GThreadFunc)mp4Decode, g_strdup(filename), TRUE, NULL); |
61 | 122 return; |
123 } | |
124 | |
125 static void mp4_stop(void) | |
126 { | |
127 if(bPlaying){ | |
128 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
129 g_thread_join(decodeThread); |
61 | 130 mp4_ip.output->close_audio(); |
131 } | |
132 } | |
133 | |
134 static int mp4_isFile(char *filename) | |
135 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
136 if(filename){ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
137 gchar* extention; |
61 | 138 |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
139 extention = strrchr(filename, '.'); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
140 if (extention &&( |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
141 !strcasecmp(extention, ".mp4") || // official extention |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
142 !strcasecmp(extention, ".m4a") || // Apple mp4 extention |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
143 !strcasecmp(extention, ".aac") // old MPEG2/4-AAC extention |
61 | 144 )){ |
145 return (1); | |
146 } | |
147 } | |
148 return(0); | |
149 } | |
150 | |
151 static void mp4_about(void) | |
152 { | |
153 static GtkWidget *aboutbox; | |
154 | |
155 if(aboutbox!=NULL) | |
156 return; | |
157 aboutbox = xmms_show_message("About MP4 AAC player plugin", | |
158 "libfaad2-" FAAD2_VERSION "\n" | |
159 "libmp4v2-" LIBMP4V2_VERSION "\n" | |
160 "plugin version: " MP4_VERSION "\n" | |
161 MP4_ABOUT, | |
162 "Ok", FALSE, NULL, NULL); | |
163 gtk_signal_connect(GTK_OBJECT(aboutbox), "destroy", | |
164 GTK_SIGNAL_FUNC(gtk_widget_destroyed), | |
165 &aboutbox); | |
166 } | |
167 | |
168 static void mp4_pause(short flag) | |
169 { | |
170 mp4_ip.output->pause(flag); | |
171 } | |
172 | |
173 static void mp4_seek(int time) | |
174 { | |
175 seekPosition = time; | |
176 while(bPlaying && seekPosition!=-1) | |
177 xmms_usleep(10000); | |
178 } | |
179 | |
180 static int mp4_getTime(void) | |
181 { | |
182 if(!bPlaying) | |
183 return (-1); | |
184 else | |
185 return (mp4_ip.output->output_time()); | |
186 } | |
187 | |
188 static void mp4_cleanup(void) | |
189 { | |
190 } | |
191 | |
192 static void mp4_getSongInfo(char *filename) | |
193 { | |
194 if(mp4cfg.file_type == FILE_MP4) | |
195 getMP4info(filename); | |
196 else if(mp4cfg.file_type == FILE_AAC) | |
197 ; | |
198 } | |
199 | |
339 | 200 static gchar *mp4_get_song_title(char *filename) |
201 { | |
202 MP4FileHandle mp4file; | |
203 gchar *title = NULL; | |
204 | |
205 if (!(mp4file = MP4Read(filename, 0))) { | |
206 MP4Close(mp4file); | |
207 } else { | |
208 TitleInput *input; | |
209 gchar *tmpval; | |
210 | |
211 input = bmp_title_input_new(); | |
212 | |
213 MP4GetMetadataName(mp4file, &input->track_name); | |
214 MP4GetMetadataAlbum(mp4file, &input->album_name); | |
215 MP4GetMetadataArtist(mp4file, &input->performer); | |
216 MP4GetMetadataYear(mp4file, &tmpval); | |
217 MP4GetMetadataGenre(mp4file, &input->genre); | |
218 | |
219 input->year = atoi(tmpval); | |
220 | |
221 input->file_name = g_path_get_basename(filename); | |
222 input->file_path = g_path_get_dirname(filename); | |
223 input->file_ext = extname(filename); | |
224 | |
225 title = xmms_get_titlestring(xmms_get_gentitle_format(), input); | |
226 | |
227 free (input->file_name); | |
228 free (input->file_path); | |
229 free (input); | |
230 } | |
231 | |
232 if (!title) | |
233 { | |
234 title = g_path_get_basename(filename); | |
235 if (extname(title)) | |
236 *(extname(title) - 1) = '\0'; | |
237 } | |
238 | |
239 return title; | |
240 } | |
241 | |
242 static void mp4_getSongTitle(char *filename, char **title_real, int *len_real) | |
243 { | |
244 (*title_real) = mp4_get_song_title(filename); | |
245 (*len_real) = -1; | |
246 } | |
247 | |
61 | 248 static void *mp4Decode(void *args) |
249 { | |
250 MP4FileHandle mp4file; | |
251 | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
252 g_static_mutex_lock(&mutex); |
61 | 253 seekPosition = -1; |
254 bPlaying = TRUE; | |
255 if(!(mp4file = MP4Read(args, 0))){ | |
256 mp4cfg.file_type = FILE_AAC; | |
257 MP4Close(mp4file); | |
258 }else{ | |
259 mp4cfg.file_type = FILE_MP4; | |
260 } | |
261 | |
262 if(mp4cfg.file_type == FILE_MP4){ | |
263 // We are reading a MP4 file | |
264 gint mp4track; | |
265 | |
266 if((mp4track = getAACTrack(mp4file)) < 0){ | |
267 //TODO: check here for others Audio format..... | |
268 g_print("Unsupported Audio track type\n"); | |
269 g_free(args); | |
270 MP4Close(mp4file); | |
271 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
272 g_static_mutex_unlock(&mutex); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
273 g_thread_exit(NULL); |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
274 return(NULL); |
61 | 275 }else{ |
276 faacDecHandle decoder; | |
277 unsigned char *buffer = NULL; | |
278 guint bufferSize = 0; | |
279 gulong samplerate; | |
280 guchar channels; | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
281 //guint avgBitrate; |
61 | 282 MP4Duration duration; |
283 gulong msDuration; | |
284 MP4SampleId numSamples; | |
285 MP4SampleId sampleID = 1; | |
339 | 286 gchar *title; |
61 | 287 |
288 decoder = faacDecOpen(); | |
289 MP4GetTrackESConfiguration(mp4file, mp4track, &buffer, &bufferSize); | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
290 if(!buffer) |
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
291 goto out; |
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
292 if(faacDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0) |
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
293 goto out; |
61 | 294 g_free(buffer); |
295 if(channels == 0){ | |
296 g_print("Number of Channels not supported\n"); | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
297 goto out; |
61 | 298 } |
299 duration = MP4GetTrackDuration(mp4file, mp4track); | |
300 msDuration = MP4ConvertFromTrackDuration(mp4file, mp4track, duration, | |
301 MP4_MSECS_TIME_SCALE); | |
302 numSamples = MP4GetTrackNumberOfSamples(mp4file, mp4track); | |
303 mp4_ip.output->open_audio(FMT_S16_NE, samplerate, channels); | |
304 mp4_ip.output->flush(0); | |
339 | 305 title = mp4_get_song_title(args); |
306 mp4_ip.set_info(title, msDuration, -1, samplerate/1000, channels); | |
61 | 307 |
308 while(bPlaying){ | |
309 void* sampleBuffer; | |
310 faacDecFrameInfo frameInfo; | |
311 gint rc; | |
312 | |
313 if(seekPosition!=-1){ | |
314 duration = MP4ConvertToTrackDuration(mp4file, | |
315 mp4track, | |
316 seekPosition*1000, | |
317 MP4_MSECS_TIME_SCALE); | |
318 sampleID = MP4GetSampleIdFromTime(mp4file, mp4track, duration, 0); | |
319 mp4_ip.output->flush(seekPosition*1000); | |
320 seekPosition = -1; | |
321 } | |
322 buffer=NULL; | |
323 bufferSize=0; | |
324 if(sampleID > numSamples){ | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
325 goto out; |
61 | 326 } |
327 rc = MP4ReadSample(mp4file, mp4track, sampleID++, &buffer, &bufferSize, | |
328 NULL, NULL, NULL, NULL); | |
329 if((rc==0) || (buffer== NULL)){ | |
330 g_print("MP4: read error\n"); | |
331 sampleBuffer = NULL; | |
332 sampleID=0; | |
333 mp4_ip.output->buffer_free(); | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
334 goto out; |
61 | 335 }else{ |
336 sampleBuffer = faacDecDecode(decoder, &frameInfo, buffer, bufferSize); | |
337 if(frameInfo.error > 0){ | |
338 g_print("MP4: %s\n", | |
339 faacDecGetErrorMessage(frameInfo.error)); | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
340 goto out; |
61 | 341 } |
342 if(buffer){ | |
343 g_free(buffer); buffer=NULL; bufferSize=0; | |
344 } | |
345 while(bPlaying && mp4_ip.output->buffer_free()<frameInfo.samples<<1) | |
346 xmms_usleep(30000); | |
347 } | |
348 mp4_ip.add_vis_pcm(mp4_ip.output->written_time(), | |
349 FMT_S16_NE, | |
350 channels, | |
351 frameInfo.samples<<1, | |
352 sampleBuffer); | |
353 mp4_ip.output->write_audio(sampleBuffer, frameInfo.samples<<1); | |
354 } | |
355 while(bPlaying && mp4_ip.output->buffer_free()){ | |
356 xmms_usleep(10000); | |
357 } | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
358 out: |
61 | 359 mp4_ip.output->close_audio(); |
360 g_free(args); | |
361 faacDecClose(decoder); | |
362 MP4Close(mp4file); | |
363 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
364 g_static_mutex_unlock(&mutex); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
365 g_thread_exit(NULL); |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
366 return(NULL); |
61 | 367 } |
368 } else{ | |
369 // WE ARE READING AN AAC FILE | |
370 FILE *file = NULL; | |
371 faacDecHandle decoder = 0; | |
372 guchar *buffer = 0; | |
373 gulong bufferconsumed = 0; | |
374 gulong samplerate = 0; | |
375 guchar channels; | |
376 gulong buffervalid = 0; | |
377 TitleInput* input; | |
378 gchar *temp = g_strdup(args); | |
379 gchar *ext = strrchr(temp, '.'); | |
380 gchar *xmmstitle = NULL; | |
381 faacDecConfigurationPtr config; | |
382 | |
383 if((file = fopen(args, "rb")) == 0){ | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
384 g_print("AAC: can't find file %s\n", (char*)args); |
61 | 385 bPlaying = FALSE; |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
386 g_static_mutex_unlock(&mutex); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
387 g_thread_exit(NULL); |
61 | 388 } |
389 if((decoder = faacDecOpen()) == NULL){ | |
390 g_print("AAC: Open Decoder Error\n"); | |
391 fclose(file); | |
392 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
393 g_static_mutex_unlock(&mutex); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
394 g_thread_exit(NULL); |
61 | 395 } |
396 config = faacDecGetCurrentConfiguration(decoder); | |
397 config->useOldADTSFormat = 0; | |
398 faacDecSetConfiguration(decoder, config); | |
399 if((buffer = g_malloc(BUFFER_SIZE)) == NULL){ | |
400 g_print("AAC: error g_malloc\n"); | |
401 fclose(file); | |
402 bPlaying = FALSE; | |
403 faacDecClose(decoder); | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
404 g_static_mutex_unlock(&mutex); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
405 g_thread_exit(NULL); |
61 | 406 } |
407 if((buffervalid = fread(buffer, 1, BUFFER_SIZE, file))==0){ | |
408 g_print("AAC: Error reading file\n"); | |
409 g_free(buffer); | |
410 fclose(file); | |
411 bPlaying = FALSE; | |
412 faacDecClose(decoder); | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
413 g_static_mutex_unlock(&mutex); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
414 g_thread_exit(NULL); |
61 | 415 } |
416 XMMS_NEW_TITLEINPUT(input); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
417 input->file_name = (char*)g_basename(temp); |
61 | 418 input->file_ext = ext ? ext+1 : NULL; |
419 input->file_path = temp; | |
420 if(!strncmp(buffer, "ID3", 3)){ | |
421 gint size = 0; | |
422 | |
423 fseek(file, 0, SEEK_SET); | |
424 size = (buffer[6]<<21) | (buffer[7]<<14) | (buffer[8]<<7) | buffer[9]; | |
425 size+=10; | |
426 fread(buffer, 1, size, file); | |
427 buffervalid = fread(buffer, 1, BUFFER_SIZE, file); | |
428 } | |
429 xmmstitle = xmms_get_titlestring(xmms_get_gentitle_format(), input); | |
430 if(xmmstitle == NULL) | |
320
d8889f819081
[svn] Dereferencing type-punned pointer will break strict-aliasing rules squashed by Mark Loeser <halcy0n@gentoo.org>.
chainsaw
parents:
319
diff
changeset
|
431 xmmstitle = g_path_get_basename(input->file_name); |
61 | 432 if(temp) g_free(temp); |
433 if(input->performer) g_free(input->performer); | |
434 if(input->album_name) g_free(input->album_name); | |
435 if(input->track_name) g_free(input->track_name); | |
436 if(input->genre) g_free(input->genre); | |
437 g_free(input); | |
438 bufferconsumed = faacDecInit(decoder, | |
439 buffer, | |
440 buffervalid, | |
441 &samplerate, | |
442 &channels); | |
443 if(mp4_ip.output->open_audio(FMT_S16_NE,samplerate,channels) == FALSE){ | |
444 g_print("AAC: Output Error\n"); | |
445 g_free(buffer); buffer=0; | |
446 faacDecClose(decoder); | |
447 fclose(file); | |
448 mp4_ip.output->close_audio(); | |
449 /* | |
450 if(positionTable){ | |
451 g_free(positionTable); positionTable=0; | |
452 } | |
453 */ | |
454 g_free(xmmstitle); | |
455 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
456 g_static_mutex_unlock(&mutex); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
457 g_thread_exit(NULL); |
61 | 458 } |
459 //if(bSeek){ | |
460 //mp4_ip.set_info(xmmstitle, lenght*1000, -1, samplerate, channels); | |
461 //}else{ | |
462 mp4_ip.set_info(xmmstitle, -1, -1, samplerate, channels); | |
463 //} | |
464 mp4_ip.output->flush(0); | |
465 | |
466 while(bPlaying && buffervalid > 0){ | |
467 faacDecFrameInfo finfo; | |
468 unsigned long samplesdecoded; | |
469 char* sample_buffer = NULL; | |
470 /* | |
471 if(bSeek && seekPosition!=-1){ | |
472 fseek(file, positionTable[seekPosition], SEEK_SET); | |
473 bufferconsumed=0; | |
474 buffervalid = fread(buffer, 1, BUFFER_SIZE, file); | |
475 aac_ip.output->flush(seekPosition*1000); | |
476 seekPosition=-1; | |
477 } | |
478 */ | |
479 if(bufferconsumed > 0){ | |
480 memmove(buffer, &buffer[bufferconsumed], buffervalid-bufferconsumed); | |
481 buffervalid -= bufferconsumed; | |
482 buffervalid += fread(&buffer[buffervalid], 1, | |
483 BUFFER_SIZE-buffervalid, file); | |
484 bufferconsumed = 0; | |
485 } | |
486 sample_buffer = faacDecDecode(decoder, &finfo, buffer, buffervalid); | |
487 if(finfo.error){ | |
488 config = faacDecGetCurrentConfiguration(decoder); | |
489 if(config->useOldADTSFormat != 1){ | |
490 faacDecClose(decoder); | |
491 decoder = faacDecOpen(); | |
492 config = faacDecGetCurrentConfiguration(decoder); | |
493 config->useOldADTSFormat = 1; | |
494 faacDecSetConfiguration(decoder, config); | |
495 finfo.bytesconsumed=0; | |
496 finfo.samples = 0; | |
497 faacDecInit(decoder, | |
498 buffer, | |
499 buffervalid, | |
500 &samplerate, | |
501 &channels); | |
502 }else{ | |
503 g_print("FAAD2 Warning %s\n", faacDecGetErrorMessage(finfo.error)); | |
504 buffervalid = 0; | |
505 } | |
506 } | |
507 bufferconsumed += finfo.bytesconsumed; | |
508 samplesdecoded = finfo.samples; | |
509 if((samplesdecoded<=0) && !sample_buffer){ | |
510 g_print("AAC: error sample decoding\n"); | |
511 continue; | |
512 } | |
513 while(bPlaying && mp4_ip.output->buffer_free() < (samplesdecoded<<1)){ | |
514 xmms_usleep(10000); | |
515 } | |
516 mp4_ip.add_vis_pcm(mp4_ip.output->written_time(), | |
517 FMT_S16_LE, channels, | |
518 samplesdecoded<<1, sample_buffer); | |
519 mp4_ip.output->write_audio(sample_buffer, samplesdecoded<<1); | |
520 } | |
521 while(bPlaying && mp4_ip.output->buffer_playing()){ | |
522 xmms_usleep(10000); | |
523 } | |
524 mp4_ip.output->buffer_free(); | |
525 mp4_ip.output->close_audio(); | |
526 bPlaying = FALSE; | |
527 g_free(buffer); | |
528 faacDecClose(decoder); | |
529 g_free(xmmstitle); | |
530 fclose(file); | |
531 seekPosition = -1; | |
532 /* | |
533 if(positionTable){ | |
534 g_free(positionTable); positionTable=0; | |
535 } | |
536 */ | |
537 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
538 g_static_mutex_unlock(&mutex); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
539 g_thread_exit(NULL); |
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
540 return(NULL); |
61 | 541 } |
542 } |