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