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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 * MP4/AAC decoder for xmms
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * This decoding source code is completly independent of the faad2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 * package.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 * This package exist for people who don't want to install
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * faad2 and mpeg4ip project files.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 * OPTIONNAL need
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 * --------------
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 * libid3 (3.8.x - www.id3.org)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 #include <gtk/gtk.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 #include "faad.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 #include "mp4.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 #include <audacious/plugin.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 #include <libaudacious/util.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 #include <libaudacious/configfile.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21 #include <libaudacious/titlestring.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 #define MP4_ABOUT "Written by ciberfred"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 #define BUFFER_SIZE FAAD_MIN_STREAMSIZE*64
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 static void mp4_init(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 static void mp4_about(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 static void mp4_play(char *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 static void mp4_stop(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 static void mp4_pause(short);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 static void mp4_seek(int);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 static int mp4_getTime(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 static void mp4_cleanup(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37 static void mp4_getSongInfo(char *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 static int mp4_isFile(char *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 static void* mp4Decode(void *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 InputPlugin mp4_ip =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 0, // handle
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 0, // filename
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 MP4_DESCRIPTION,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 mp4_init,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 mp4_about,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 0, // configuration
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 mp4_isFile,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 0, //scandir
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 mp4_play,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 mp4_stop,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 mp4_pause,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 mp4_seek,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 0, // set equalizer
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 mp4_getTime,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 0, // get volume
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 0,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 mp4_cleanup,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 0, // obsolete
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 0, // send visualisation data
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 0, // set player window info
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 0, // set song title text
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 0, // get song title text
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 mp4_getSongInfo, // info box
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 0, // to output plugin
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 typedef struct _mp4cfg{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 gshort file_type;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 #define FILE_UNKNOW 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 #define FILE_MP4 1
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 #define FILE_AAC 2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 } Mp4Config;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 static Mp4Config mp4cfg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 static int seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 InputPlugin *get_iplugin_info(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 return(&mp4_ip);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 static void mp4_init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 mp4cfg.file_type = FILE_UNKNOW;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 static void mp4_play(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 static void mp4_stop(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 if(bPlaying){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 static int mp4_isFile(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 )){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 return (1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 return(0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 static void mp4_about(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 static GtkWidget *aboutbox;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 if(aboutbox!=NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 aboutbox = xmms_show_message("About MP4 AAC player plugin",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 "libfaad2-" FAAD2_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 "libmp4v2-" LIBMP4V2_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 "plugin version: " MP4_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 MP4_ABOUT,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 "Ok", FALSE, NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 gtk_signal_connect(GTK_OBJECT(aboutbox), "destroy",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 GTK_SIGNAL_FUNC(gtk_widget_destroyed),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 &aboutbox);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 static void mp4_pause(short flag)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150 mp4_ip.output->pause(flag);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 static void mp4_seek(int time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 seekPosition = time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 while(bPlaying && seekPosition!=-1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 static int mp4_getTime(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 if(!bPlaying)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 return (-1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 return (mp4_ip.output->output_time());
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 static void mp4_cleanup(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 static void mp4_getSongInfo(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 if(mp4cfg.file_type == FILE_MP4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 getMP4info(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 else if(mp4cfg.file_type == FILE_AAC)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 ;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 static void *mp4Decode(void *args)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 MP4FileHandle mp4file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 bPlaying = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 if(!(mp4file = MP4Read(args, 0))){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 mp4cfg.file_type = FILE_AAC;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 mp4cfg.file_type = FILE_MP4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 if(mp4cfg.file_type == FILE_MP4){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 // We are reading a MP4 file
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 gint mp4track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 if((mp4track = getAACTrack(mp4file)) < 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 //TODO: check here for others Audio format.....
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 g_print("Unsupported Audio track type\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 faacDecHandle decoder;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 unsigned char *buffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 guint bufferSize = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 gulong samplerate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 MP4Duration duration;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 gulong msDuration;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215 MP4SampleId numSamples;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 MP4SampleId sampleID = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 decoder = faacDecOpen();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 MP4GetTrackESConfiguration(mp4file, mp4track, &buffer, &bufferSize);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 if(!buffer){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 if(faacDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 if(channels == 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 g_print("Number of Channels not supported\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 duration = MP4GetTrackDuration(mp4file, mp4track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 msDuration = MP4ConvertFromTrackDuration(mp4file, mp4track, duration,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248 MP4_MSECS_TIME_SCALE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 numSamples = MP4GetTrackNumberOfSamples(mp4file, mp4track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 mp4_ip.output->open_audio(FMT_S16_NE, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 mp4_ip.output->flush(0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 while(bPlaying){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 void* sampleBuffer;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 faacDecFrameInfo frameInfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 gint rc;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 if(seekPosition!=-1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 duration = MP4ConvertToTrackDuration(mp4file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 mp4track,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 seekPosition*1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 MP4_MSECS_TIME_SCALE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 sampleID = MP4GetSampleIdFromTime(mp4file, mp4track, duration, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 mp4_ip.output->flush(seekPosition*1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269 buffer=NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270 bufferSize=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 if(sampleID > numSamples){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
275 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280 rc = MP4ReadSample(mp4file, mp4track, sampleID++, &buffer, &bufferSize,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281 NULL, NULL, NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 //g_print("%d/%d\n", sampleID-1, numSamples);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283 if((rc==0) || (buffer== NULL)){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284 g_print("MP4: read error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 sampleBuffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 sampleID=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287 mp4_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296 sampleBuffer = faacDecDecode(decoder, &frameInfo, buffer, bufferSize);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 if(frameInfo.error > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298 g_print("MP4: %s\n",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 faacDecGetErrorMessage(frameInfo.error));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308 if(buffer){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309 g_free(buffer); buffer=NULL; bufferSize=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311 while(bPlaying && mp4_ip.output->buffer_free()<frameInfo.samples<<1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312 xmms_usleep(30000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314 mp4_ip.add_vis_pcm(mp4_ip.output->written_time(),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315 FMT_S16_NE,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316 channels,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 frameInfo.samples<<1,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318 sampleBuffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319 mp4_ip.output->write_audio(sampleBuffer, frameInfo.samples<<1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 while(bPlaying && mp4_ip.output->buffer_free()){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 } else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 // WE ARE READING AN AAC FILE
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 FILE *file = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 faacDecHandle decoder = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 guchar *buffer = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 gulong bufferconsumed = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 gulong samplerate = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 guchar channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 gulong buffervalid = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 TitleInput* input;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 gchar *temp = g_strdup(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 gchar *ext = strrchr(temp, '.');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344 gchar *xmmstitle = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 faacDecConfigurationPtr config;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 if((decoder = faacDecOpen()) == NULL){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 g_print("AAC: Open Decoder Error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 config->useOldADTSFormat = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 faacDecSetConfiguration(decoder, config);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 if((buffer = g_malloc(BUFFER_SIZE)) == NULL){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 g_print("AAC: error g_malloc\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371 if((buffervalid = fread(buffer, 1, BUFFER_SIZE, file))==0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372 g_print("AAC: Error reading file\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382 input->file_ext = ext ? ext+1 : NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 input->file_path = temp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384 if(!strncmp(buffer, "ID3", 3)){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 gint size = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387 fseek(file, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 size = (buffer[6]<<21) | (buffer[7]<<14) | (buffer[8]<<7) | buffer[9];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 size+=10;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 fread(buffer, 1, size, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 buffervalid = fread(buffer, 1, BUFFER_SIZE, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393 xmmstitle = xmms_get_titlestring(xmms_get_gentitle_format(), input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 if(xmmstitle == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 xmmstitle = g_strdup(input->file_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 if(temp) g_free(temp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 if(input->performer) g_free(input->performer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 if(input->album_name) g_free(input->album_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 if(input->track_name) g_free(input->track_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 if(input->genre) g_free(input->genre);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 g_free(input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 bufferconsumed = faacDecInit(decoder,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 buffer,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 buffervalid,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 &samplerate,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 &channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407 if(mp4_ip.output->open_audio(FMT_S16_NE,samplerate,channels) == FALSE){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 g_print("AAC: Output Error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409 g_free(buffer); buffer=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414 if(positionTable){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415 g_free(positionTable); positionTable=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 g_free(xmmstitle);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
423 //if(bSeek){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 //mp4_ip.set_info(xmmstitle, lenght*1000, -1, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
425 //}else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 mp4_ip.set_info(xmmstitle, -1, -1, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427 //}
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 mp4_ip.output->flush(0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
429
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430 while(bPlaying && buffervalid > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 faacDecFrameInfo finfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
432 unsigned long samplesdecoded;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 char* sample_buffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 if(bSeek && seekPosition!=-1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436 fseek(file, positionTable[seekPosition], SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 bufferconsumed=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
438 buffervalid = fread(buffer, 1, BUFFER_SIZE, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439 aac_ip.output->flush(seekPosition*1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440 seekPosition=-1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 if(bufferconsumed > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444 memmove(buffer, &buffer[bufferconsumed], buffervalid-bufferconsumed);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445 buffervalid -= bufferconsumed;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 buffervalid += fread(&buffer[buffervalid], 1,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 BUFFER_SIZE-buffervalid, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 bufferconsumed = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450 sample_buffer = faacDecDecode(decoder, &finfo, buffer, buffervalid);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 if(finfo.error){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 if(config->useOldADTSFormat != 1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 decoder = faacDecOpen();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 config->useOldADTSFormat = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
458 faacDecSetConfiguration(decoder, config);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 finfo.bytesconsumed=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 finfo.samples = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461 faacDecInit(decoder,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 buffer,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463 buffervalid,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464 &samplerate,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 &channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
467 g_print("FAAD2 Warning %s\n", faacDecGetErrorMessage(finfo.error));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 buffervalid = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 bufferconsumed += finfo.bytesconsumed;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 samplesdecoded = finfo.samples;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473 if((samplesdecoded<=0) && !sample_buffer){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 g_print("AAC: error sample decoding\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477 while(bPlaying && mp4_ip.output->buffer_free() < (samplesdecoded<<1)){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 mp4_ip.add_vis_pcm(mp4_ip.output->written_time(),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481 FMT_S16_LE, channels,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 samplesdecoded<<1, sample_buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483 mp4_ip.output->write_audio(sample_buffer, samplesdecoded<<1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
484 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
485 while(bPlaying && mp4_ip.output->buffer_playing()){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
487 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
488 mp4_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
491 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
493 g_free(xmmstitle);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
494 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
497 if(positionTable){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498 g_free(positionTable); positionTable=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
500 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
505 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 }