Mercurial > audlegacy
annotate Plugins/Input/aac/src/libmp4.c @ 340:c7a67ac8e19c trunk
[svn] safety fix
author | nenolod |
---|---|
date | Sun, 25 Dec 2005 23:56:55 -0800 |
parents | e1630c75175b |
children | 320f0205ad45 |
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 | |
340 | 219 if (tmpval) |
220 input->year = atoi(tmpval); | |
339 | 221 |
222 input->file_name = g_path_get_basename(filename); | |
223 input->file_path = g_path_get_dirname(filename); | |
224 input->file_ext = extname(filename); | |
225 | |
226 title = xmms_get_titlestring(xmms_get_gentitle_format(), input); | |
227 | |
228 free (input->file_name); | |
229 free (input->file_path); | |
230 free (input); | |
231 } | |
232 | |
233 if (!title) | |
234 { | |
235 title = g_path_get_basename(filename); | |
236 if (extname(title)) | |
237 *(extname(title) - 1) = '\0'; | |
238 } | |
239 | |
240 return title; | |
241 } | |
242 | |
243 static void mp4_getSongTitle(char *filename, char **title_real, int *len_real) | |
244 { | |
245 (*title_real) = mp4_get_song_title(filename); | |
246 (*len_real) = -1; | |
247 } | |
248 | |
61 | 249 static void *mp4Decode(void *args) |
250 { | |
251 MP4FileHandle mp4file; | |
252 | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
253 g_static_mutex_lock(&mutex); |
61 | 254 seekPosition = -1; |
255 bPlaying = TRUE; | |
256 if(!(mp4file = MP4Read(args, 0))){ | |
257 mp4cfg.file_type = FILE_AAC; | |
258 MP4Close(mp4file); | |
259 }else{ | |
260 mp4cfg.file_type = FILE_MP4; | |
261 } | |
262 | |
263 if(mp4cfg.file_type == FILE_MP4){ | |
264 // We are reading a MP4 file | |
265 gint mp4track; | |
266 | |
267 if((mp4track = getAACTrack(mp4file)) < 0){ | |
268 //TODO: check here for others Audio format..... | |
269 g_print("Unsupported Audio track type\n"); | |
270 g_free(args); | |
271 MP4Close(mp4file); | |
272 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
273 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
|
274 g_thread_exit(NULL); |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
275 return(NULL); |
61 | 276 }else{ |
277 faacDecHandle decoder; | |
278 unsigned char *buffer = NULL; | |
279 guint bufferSize = 0; | |
280 gulong samplerate; | |
281 guchar channels; | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
282 //guint avgBitrate; |
61 | 283 MP4Duration duration; |
284 gulong msDuration; | |
285 MP4SampleId numSamples; | |
286 MP4SampleId sampleID = 1; | |
339 | 287 gchar *title; |
61 | 288 |
289 decoder = faacDecOpen(); | |
290 MP4GetTrackESConfiguration(mp4file, mp4track, &buffer, &bufferSize); | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
291 if(!buffer) |
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
292 goto out; |
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
293 if(faacDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0) |
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
294 goto out; |
61 | 295 g_free(buffer); |
296 if(channels == 0){ | |
297 g_print("Number of Channels not supported\n"); | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
298 goto out; |
61 | 299 } |
300 duration = MP4GetTrackDuration(mp4file, mp4track); | |
301 msDuration = MP4ConvertFromTrackDuration(mp4file, mp4track, duration, | |
302 MP4_MSECS_TIME_SCALE); | |
303 numSamples = MP4GetTrackNumberOfSamples(mp4file, mp4track); | |
304 mp4_ip.output->open_audio(FMT_S16_NE, samplerate, channels); | |
305 mp4_ip.output->flush(0); | |
339 | 306 title = mp4_get_song_title(args); |
307 mp4_ip.set_info(title, msDuration, -1, samplerate/1000, channels); | |
61 | 308 |
309 while(bPlaying){ | |
310 void* sampleBuffer; | |
311 faacDecFrameInfo frameInfo; | |
312 gint rc; | |
313 | |
314 if(seekPosition!=-1){ | |
315 duration = MP4ConvertToTrackDuration(mp4file, | |
316 mp4track, | |
317 seekPosition*1000, | |
318 MP4_MSECS_TIME_SCALE); | |
319 sampleID = MP4GetSampleIdFromTime(mp4file, mp4track, duration, 0); | |
320 mp4_ip.output->flush(seekPosition*1000); | |
321 seekPosition = -1; | |
322 } | |
323 buffer=NULL; | |
324 bufferSize=0; | |
325 if(sampleID > numSamples){ | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
326 goto out; |
61 | 327 } |
328 rc = MP4ReadSample(mp4file, mp4track, sampleID++, &buffer, &bufferSize, | |
329 NULL, NULL, NULL, NULL); | |
330 if((rc==0) || (buffer== NULL)){ | |
331 g_print("MP4: read error\n"); | |
332 sampleBuffer = NULL; | |
333 sampleID=0; | |
334 mp4_ip.output->buffer_free(); | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
335 goto out; |
61 | 336 }else{ |
337 sampleBuffer = faacDecDecode(decoder, &frameInfo, buffer, bufferSize); | |
338 if(frameInfo.error > 0){ | |
339 g_print("MP4: %s\n", | |
340 faacDecGetErrorMessage(frameInfo.error)); | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
341 goto out; |
61 | 342 } |
343 if(buffer){ | |
344 g_free(buffer); buffer=NULL; bufferSize=0; | |
345 } | |
346 while(bPlaying && mp4_ip.output->buffer_free()<frameInfo.samples<<1) | |
347 xmms_usleep(30000); | |
348 } | |
349 mp4_ip.add_vis_pcm(mp4_ip.output->written_time(), | |
350 FMT_S16_NE, | |
351 channels, | |
352 frameInfo.samples<<1, | |
353 sampleBuffer); | |
354 mp4_ip.output->write_audio(sampleBuffer, frameInfo.samples<<1); | |
355 } | |
356 while(bPlaying && mp4_ip.output->buffer_free()){ | |
357 xmms_usleep(10000); | |
358 } | |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
359 out: |
61 | 360 mp4_ip.output->close_audio(); |
361 g_free(args); | |
362 faacDecClose(decoder); | |
363 MP4Close(mp4file); | |
364 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
365 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
|
366 g_thread_exit(NULL); |
250
b9e6cdce7219
[svn] Reduce code duplication and add a return statement.
chainsaw
parents:
200
diff
changeset
|
367 return(NULL); |
61 | 368 } |
369 } else{ | |
370 // WE ARE READING AN AAC FILE | |
371 FILE *file = NULL; | |
372 faacDecHandle decoder = 0; | |
373 guchar *buffer = 0; | |
374 gulong bufferconsumed = 0; | |
375 gulong samplerate = 0; | |
376 guchar channels; | |
377 gulong buffervalid = 0; | |
378 TitleInput* input; | |
379 gchar *temp = g_strdup(args); | |
380 gchar *ext = strrchr(temp, '.'); | |
381 gchar *xmmstitle = NULL; | |
382 faacDecConfigurationPtr config; | |
383 | |
384 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
|
385 g_print("AAC: can't find file %s\n", (char*)args); |
61 | 386 bPlaying = FALSE; |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
387 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
|
388 g_thread_exit(NULL); |
61 | 389 } |
390 if((decoder = faacDecOpen()) == NULL){ | |
391 g_print("AAC: Open Decoder Error\n"); | |
392 fclose(file); | |
393 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
394 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
|
395 g_thread_exit(NULL); |
61 | 396 } |
397 config = faacDecGetCurrentConfiguration(decoder); | |
398 config->useOldADTSFormat = 0; | |
399 faacDecSetConfiguration(decoder, config); | |
400 if((buffer = g_malloc(BUFFER_SIZE)) == NULL){ | |
401 g_print("AAC: error g_malloc\n"); | |
402 fclose(file); | |
403 bPlaying = FALSE; | |
404 faacDecClose(decoder); | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
405 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
|
406 g_thread_exit(NULL); |
61 | 407 } |
408 if((buffervalid = fread(buffer, 1, BUFFER_SIZE, file))==0){ | |
409 g_print("AAC: Error reading file\n"); | |
410 g_free(buffer); | |
411 fclose(file); | |
412 bPlaying = FALSE; | |
413 faacDecClose(decoder); | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
414 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
|
415 g_thread_exit(NULL); |
61 | 416 } |
417 XMMS_NEW_TITLEINPUT(input); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
418 input->file_name = (char*)g_basename(temp); |
61 | 419 input->file_ext = ext ? ext+1 : NULL; |
420 input->file_path = temp; | |
421 if(!strncmp(buffer, "ID3", 3)){ | |
422 gint size = 0; | |
423 | |
424 fseek(file, 0, SEEK_SET); | |
425 size = (buffer[6]<<21) | (buffer[7]<<14) | (buffer[8]<<7) | buffer[9]; | |
426 size+=10; | |
427 fread(buffer, 1, size, file); | |
428 buffervalid = fread(buffer, 1, BUFFER_SIZE, file); | |
429 } | |
430 xmmstitle = xmms_get_titlestring(xmms_get_gentitle_format(), input); | |
431 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
|
432 xmmstitle = g_path_get_basename(input->file_name); |
61 | 433 if(temp) g_free(temp); |
434 if(input->performer) g_free(input->performer); | |
435 if(input->album_name) g_free(input->album_name); | |
436 if(input->track_name) g_free(input->track_name); | |
437 if(input->genre) g_free(input->genre); | |
438 g_free(input); | |
439 bufferconsumed = faacDecInit(decoder, | |
440 buffer, | |
441 buffervalid, | |
442 &samplerate, | |
443 &channels); | |
444 if(mp4_ip.output->open_audio(FMT_S16_NE,samplerate,channels) == FALSE){ | |
445 g_print("AAC: Output Error\n"); | |
446 g_free(buffer); buffer=0; | |
447 faacDecClose(decoder); | |
448 fclose(file); | |
449 mp4_ip.output->close_audio(); | |
450 /* | |
451 if(positionTable){ | |
452 g_free(positionTable); positionTable=0; | |
453 } | |
454 */ | |
455 g_free(xmmstitle); | |
456 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
457 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
|
458 g_thread_exit(NULL); |
61 | 459 } |
460 //if(bSeek){ | |
461 //mp4_ip.set_info(xmmstitle, lenght*1000, -1, samplerate, channels); | |
462 //}else{ | |
463 mp4_ip.set_info(xmmstitle, -1, -1, samplerate, channels); | |
464 //} | |
465 mp4_ip.output->flush(0); | |
466 | |
467 while(bPlaying && buffervalid > 0){ | |
468 faacDecFrameInfo finfo; | |
469 unsigned long samplesdecoded; | |
470 char* sample_buffer = NULL; | |
471 /* | |
472 if(bSeek && seekPosition!=-1){ | |
473 fseek(file, positionTable[seekPosition], SEEK_SET); | |
474 bufferconsumed=0; | |
475 buffervalid = fread(buffer, 1, BUFFER_SIZE, file); | |
476 aac_ip.output->flush(seekPosition*1000); | |
477 seekPosition=-1; | |
478 } | |
479 */ | |
480 if(bufferconsumed > 0){ | |
481 memmove(buffer, &buffer[bufferconsumed], buffervalid-bufferconsumed); | |
482 buffervalid -= bufferconsumed; | |
483 buffervalid += fread(&buffer[buffervalid], 1, | |
484 BUFFER_SIZE-buffervalid, file); | |
485 bufferconsumed = 0; | |
486 } | |
487 sample_buffer = faacDecDecode(decoder, &finfo, buffer, buffervalid); | |
488 if(finfo.error){ | |
489 config = faacDecGetCurrentConfiguration(decoder); | |
490 if(config->useOldADTSFormat != 1){ | |
491 faacDecClose(decoder); | |
492 decoder = faacDecOpen(); | |
493 config = faacDecGetCurrentConfiguration(decoder); | |
494 config->useOldADTSFormat = 1; | |
495 faacDecSetConfiguration(decoder, config); | |
496 finfo.bytesconsumed=0; | |
497 finfo.samples = 0; | |
498 faacDecInit(decoder, | |
499 buffer, | |
500 buffervalid, | |
501 &samplerate, | |
502 &channels); | |
503 }else{ | |
504 g_print("FAAD2 Warning %s\n", faacDecGetErrorMessage(finfo.error)); | |
505 buffervalid = 0; | |
506 } | |
507 } | |
508 bufferconsumed += finfo.bytesconsumed; | |
509 samplesdecoded = finfo.samples; | |
510 if((samplesdecoded<=0) && !sample_buffer){ | |
511 g_print("AAC: error sample decoding\n"); | |
512 continue; | |
513 } | |
514 while(bPlaying && mp4_ip.output->buffer_free() < (samplesdecoded<<1)){ | |
515 xmms_usleep(10000); | |
516 } | |
517 mp4_ip.add_vis_pcm(mp4_ip.output->written_time(), | |
518 FMT_S16_LE, channels, | |
519 samplesdecoded<<1, sample_buffer); | |
520 mp4_ip.output->write_audio(sample_buffer, samplesdecoded<<1); | |
521 } | |
522 while(bPlaying && mp4_ip.output->buffer_playing()){ | |
523 xmms_usleep(10000); | |
524 } | |
525 mp4_ip.output->buffer_free(); | |
526 mp4_ip.output->close_audio(); | |
527 bPlaying = FALSE; | |
528 g_free(buffer); | |
529 faacDecClose(decoder); | |
530 g_free(xmmstitle); | |
531 fclose(file); | |
532 seekPosition = -1; | |
533 /* | |
534 if(positionTable){ | |
535 g_free(positionTable); positionTable=0; | |
536 } | |
537 */ | |
538 bPlaying = FALSE; | |
200
094ef8a0a9fd
[svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents:
199
diff
changeset
|
539 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
|
540 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
|
541 return(NULL); |
61 | 542 } |
543 } |