annotate Plugins/Input/aac/src/libmp4.c @ 339:e1630c75175b trunk

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