Mercurial > audlegacy-plugins
annotate src/aac/src/libmp4.c @ 700:27a557e80e15 trunk
[svn] - fix a ringbuffering error. found by purify.
author | nenolod |
---|---|
date | Wed, 21 Feb 2007 02:02:10 -0800 |
parents | 74a762a3592e |
children | eecd54a11610 |
rev | line source |
---|---|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
1 #include <glib.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
2 #include <gtk/gtk.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
3 #include <string.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
4 #include <stdlib.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
5 #include "faad.h" |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
6 #include "mp4ff.h" |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
7 #include "tagging.h" |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
8 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
9 #include <audacious/plugin.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
10 #include <audacious/output.h> |
4
0ad4849f6219
[svn] - the first pass missed some libaudacious references, this fixes them
nenolod
parents:
0
diff
changeset
|
11 #include <audacious/util.h> |
0ad4849f6219
[svn] - the first pass missed some libaudacious references, this fixes them
nenolod
parents:
0
diff
changeset
|
12 #include <audacious/titlestring.h> |
0ad4849f6219
[svn] - the first pass missed some libaudacious references, this fixes them
nenolod
parents:
0
diff
changeset
|
13 #include <audacious/vfs.h> |
527
d124034ebea3
[svn] - glib/gi18n.h -> audacious/i18n.h for automatic dgettext support
nenolod
parents:
393
diff
changeset
|
14 #include <audacious/i18n.h> |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
15 |
583 | 16 #define MP4_VERSION VERSION |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
17 |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
18 #define SBR_DEC |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
19 |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
20 /* |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
21 * BUFFER_SIZE is the highest amount of memory that can be pulled. |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
22 * We use this for sanity checks, among other things, as mp4ff needs |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
23 * a labotomy sometimes. |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
24 */ |
583 | 25 #define BUFFER_SIZE FAAD_MIN_STREAMSIZE*64 |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
26 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
27 /* |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
28 * AAC_MAGIC is the pattern that marks the beginning of an MP4 container. |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
29 */ |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
30 #define AAC_MAGIC (unsigned char [4]) { 0xFF, 0xF9, 0x5C, 0x80 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
31 |
583 | 32 static void mp4_init(void); |
33 static void mp4_about(void); | |
34 static int mp4_is_our_file(char *); | |
35 static void mp4_play(InputPlayback *); | |
36 static void mp4_stop(InputPlayback *); | |
37 static void mp4_pause(InputPlayback *, short); | |
38 static void mp4_seek(InputPlayback *, int); | |
39 static int mp4_get_time(InputPlayback *); | |
40 static void mp4_cleanup(void); | |
41 static void mp4_get_song_title_len(char *filename, char **, int *); | |
42 static TitleInput* mp4_get_song_tuple(char *); | |
43 static int mp4_is_our_fd(char *, VFSFile *); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
44 |
374 | 45 gchar *mp4_fmts[] = { "m4a", "mp4", "aac", NULL }; |
46 | |
583 | 47 static void * mp4_decode(void *); |
48 static gchar * mp4_get_song_title(char *filename); | |
49 static void audmp4_file_info_box(gchar *); | |
50 gboolean buffer_playing; | |
51 | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
52 InputPlugin mp4_ip = |
583 | 53 { |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
54 NULL, // handle |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
55 NULL, // filename |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
56 "MP4 Audio Plugin", |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
57 mp4_init, |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
58 mp4_about, |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
59 NULL, // configuration |
583 | 60 mp4_is_our_file, |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
61 NULL, //scandir |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
62 mp4_play, |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
63 mp4_stop, |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
64 mp4_pause, |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
65 mp4_seek, |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
66 NULL, // set equalizer |
583 | 67 mp4_get_time, |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
68 NULL, // get volume |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
69 NULL, |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
70 mp4_cleanup, |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
71 NULL, // obsolete |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
72 NULL, // send visualisation data |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
73 NULL, // set player window info |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
74 NULL, // set song title text |
583 | 75 mp4_get_song_title_len, // get song title text |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
76 NULL, // info box |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
77 NULL, // to output plugin |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
78 mp4_get_song_tuple, |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
79 NULL, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
80 NULL, |
583 | 81 mp4_is_our_fd, |
374 | 82 mp4_fmts, |
583 | 83 }; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
84 |
583 | 85 typedef struct _mp4cfg |
86 { | |
87 #define FILE_UNKNOWN 0 | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
88 #define FILE_MP4 1 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
89 #define FILE_AAC 2 |
583 | 90 gshort file_type; |
91 } Mp4Config; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
92 |
583 | 93 static Mp4Config mp4cfg; |
94 static GThread *decodeThread; | |
95 GStaticMutex mutex = G_STATIC_MUTEX_INIT; | |
96 static int seekPosition = -1; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
97 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
98 void getMP4info(char*); |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
99 int getAACTrack(mp4ff_t *); |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
100 |
583 | 101 static guint32 mp4_read_callback(void *data, void *buffer, guint32 len) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
102 { |
583 | 103 if (data == NULL || buffer == NULL) |
104 return -1; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
105 |
583 | 106 return vfs_fread(buffer, 1, len, (VFSFile *) data); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
107 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
108 |
583 | 109 static guint32 mp4_seek_callback(void *data, guint64 pos) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
110 { |
583 | 111 if (data == NULL) |
112 return -1; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
113 |
583 | 114 return vfs_fseek((VFSFile *) data, pos, SEEK_SET); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
115 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
116 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
117 static gchar * |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
118 extname(const char *filename) |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
119 { |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
120 gchar *ext = strrchr(filename, '.'); |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
121 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
122 if (ext != NULL) |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
123 ++ext; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
124 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
125 return ext; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
126 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
127 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
128 InputPlugin *get_iplugin_info(void) |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
129 { |
583 | 130 return(&mp4_ip); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
131 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
132 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
133 static void mp4_init(void) |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
134 { |
583 | 135 mp4cfg.file_type = FILE_UNKNOWN; |
136 seekPosition = -1; | |
137 return; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
138 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
139 |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
140 static void mp4_play(InputPlayback *playback) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
141 { |
583 | 142 buffer_playing = TRUE; |
143 decodeThread = g_thread_create((GThreadFunc)mp4_decode, playback, TRUE, NULL); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
144 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
145 |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
146 static void mp4_stop(InputPlayback *playback) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
147 { |
583 | 148 if (buffer_playing) |
149 { | |
150 buffer_playing = FALSE; | |
151 g_thread_join(decodeThread); | |
152 playback->output->close_audio(); | |
153 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
154 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
155 |
678
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
156 /* |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
157 * These routines are derived from MPlayer. |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
158 */ |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
159 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
160 /// \param srate (out) sample rate |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
161 /// \param num (out) number of audio frames in this ADTS frame |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
162 /// \return size of the ADTS frame in bytes |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
163 /// aac_parse_frames needs a buffer at least 8 bytes long |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
164 int aac_parse_frame(guchar *buf, int *srate, int *num) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
165 { |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
166 int i = 0, sr, fl = 0, id; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
167 static int srates[] = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 0, 0, 0}; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
168 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
169 if((buf[i] != 0xFF) || ((buf[i+1] & 0xF6) != 0xF0)) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
170 return 0; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
171 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
172 id = (buf[i+1] >> 3) & 0x01; //id=1 mpeg2, 0: mpeg4 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
173 sr = (buf[i+2] >> 2) & 0x0F; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
174 if(sr > 11) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
175 return 0; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
176 *srate = srates[sr]; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
177 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
178 fl = ((buf[i+3] & 0x03) << 11) | (buf[i+4] << 3) | ((buf[i+5] >> 5) & 0x07); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
179 *num = (buf[i+6] & 0x02) + 1; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
180 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
181 return fl; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
182 } |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
183 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
184 static gboolean parse_aac_stream(VFSFile *stream) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
185 { |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
186 int cnt = 0, c, len, srate, num; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
187 off_t init, probed; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
188 static guchar buf[8]; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
189 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
190 init = probed = vfs_ftell(stream); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
191 while(probed-init <= 32768 && cnt < 8) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
192 { |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
193 c = 0; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
194 while(probed-init <= 32768 && c != 0xFF) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
195 { |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
196 c = vfs_getc(stream); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
197 if(c < 0) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
198 return FALSE; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
199 probed = vfs_ftell(stream); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
200 } |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
201 buf[0] = 0xFF; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
202 if(vfs_fread(&(buf[1]), 1, 7, stream) < 7) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
203 return FALSE; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
204 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
205 len = aac_parse_frame(buf, &srate, &num); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
206 if(len > 0) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
207 { |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
208 cnt++; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
209 vfs_fseek(stream, len - 8, SEEK_CUR); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
210 } |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
211 probed = vfs_ftell(stream); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
212 } |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
213 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
214 if(cnt < 8) |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
215 return FALSE; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
216 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
217 return TRUE; |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
218 } |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
219 |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
220 static int aac_probe(unsigned char *buffer, int len) |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
221 { |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
222 int i = 0, pos = 0; |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
223 #ifdef DEBUG |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
224 g_print("\nAAC_PROBE: %d bytes\n", len); |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
225 #endif |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
226 while(i <= len-4) { |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
227 if( |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
228 ((buffer[i] == 0xff) && ((buffer[i+1] & 0xf6) == 0xf0)) || |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
229 (buffer[i] == 'A' && buffer[i+1] == 'D' && buffer[i+2] == 'I' && buffer[i+3] == 'F') |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
230 ) { |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
231 pos = i; |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
232 break; |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
233 } |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
234 #ifdef DEBUG |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
235 g_print("AUDIO PAYLOAD: %x %x %x %x\n", |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
236 buffer[i], buffer[i+1], buffer[i+2], buffer[i+3]); |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
237 #endif |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
238 i++; |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
239 } |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
240 #ifdef DEBUG |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
241 g_print("\nAAC_PROBE: ret %d\n", pos); |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
242 #endif |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
243 return pos; |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
244 } |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
245 |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
246 static int mp4_is_our_file(char *filename) |
262
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
247 { |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
248 VFSFile *file; |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
249 gchar* extension; |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
250 gchar magic[8]; |
393 | 251 |
252 memset(magic, '\0', 8); | |
253 | |
262
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
254 extension = strrchr(filename, '.'); |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
255 if ((file = vfs_fopen(filename, "rb"))) { |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
256 vfs_fread(magic, 1, 8, file); |
678
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
257 vfs_rewind(file); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
258 if (parse_aac_stream(file) == TRUE) { |
262
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
259 vfs_fclose(file); |
678
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
260 return TRUE; |
262
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
261 } |
583 | 262 if (!memcmp(magic, "ID3", 3)) { // ID3 tag bolted to the front, obfuscated magic bytes |
262
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
263 vfs_fclose(file); |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
264 if (extension &&( |
583 | 265 !strcasecmp(extension, ".mp4") || // official extension |
266 !strcasecmp(extension, ".m4a") || // Apple mp4 extension | |
267 !strcasecmp(extension, ".aac") // old MPEG2/4-AAC extension | |
268 )) | |
269 return 1; | |
270 else | |
271 return 0; | |
262
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
272 } |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
273 if (!memcmp(&magic[4], "ftyp", 4)) { |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
274 vfs_fclose(file); |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
275 return 1; |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
276 } |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
277 vfs_fclose(file); |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
278 } |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
279 return 0; |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
280 } |
f653f1219db2
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
255
diff
changeset
|
281 |
583 | 282 static int mp4_is_our_fd(char *filename, VFSFile* file) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
283 { |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
284 gchar* extension; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
285 gchar magic[8]; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
286 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
287 extension = strrchr(filename, '.'); |
255 | 288 vfs_fread(magic, 1, 8, file); |
678
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
289 vfs_rewind(file); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
290 if (parse_aac_stream(file) == TRUE) |
255 | 291 return 1; |
292 if (!memcmp(&magic[4], "ftyp", 4)) | |
293 return 1; | |
583 | 294 if (!memcmp(magic, "ID3", 3)) { // ID3 tag bolted to the front, obfuscated magic bytes |
255 | 295 if (extension &&( |
583 | 296 !strcasecmp(extension, ".mp4") || // official extension |
297 !strcasecmp(extension, ".m4a") || // Apple mp4 extension | |
298 !strcasecmp(extension, ".aac") // old MPEG2/4-AAC extension | |
255 | 299 )) |
300 return 1; | |
301 else | |
302 return 0; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
303 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
304 return 0; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
305 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
306 |
583 | 307 static void mp4_about(void) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
308 { |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
309 static GtkWidget *aboutbox = NULL; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
310 aboutbox = xmms_show_message("About MP4 AAC player plugin", |
583 | 311 "Using libfaad2-" FAAD2_VERSION " for decoding.\n" |
680
3a06665a810e
[svn] - satisfy Nero AG attribution requirement for FAAD 2.5 code import
nenolod
parents:
679
diff
changeset
|
312 "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com\n" |
583 | 313 "Copyright (c) 2005-2006 Audacious team", |
314 "Ok", FALSE, NULL, NULL); | |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
315 g_signal_connect(G_OBJECT(aboutbox), "destroy", |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
316 G_CALLBACK(gtk_widget_destroyed), |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
317 &aboutbox); |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
318 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
319 |
583 | 320 static void mp4_pause(InputPlayback *playback, short flag) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
321 { |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
322 playback->output->pause(flag); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
323 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
324 |
583 | 325 static void mp4_seek(InputPlayback *data, int time) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
326 { |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
327 seekPosition = time; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
328 while(buffer_playing && seekPosition != -1) |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
329 xmms_usleep(10000); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
330 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
331 |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
332 static int mp4_get_time(InputPlayback *playback) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
333 { |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
334 if(!buffer_playing) |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
335 return (-1); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
336 else |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
337 return (playback->output->output_time()); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
338 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
339 |
583 | 340 static void mp4_cleanup(void) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
341 { |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
342 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
343 |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
344 static TitleInput *mp4_get_song_tuple(char *fn) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
345 { |
583 | 346 mp4ff_callback_t *mp4cb = g_malloc0(sizeof(mp4ff_callback_t)); |
347 VFSFile *mp4fh; | |
348 mp4ff_t *mp4file; | |
349 TitleInput *input = NULL; | |
350 gchar *filename = g_strdup(fn); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
351 |
583 | 352 mp4fh = vfs_fopen(filename, "rb"); |
353 mp4cb->read = mp4_read_callback; | |
354 mp4cb->seek = mp4_seek_callback; | |
355 mp4cb->user_data = mp4fh; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
356 |
583 | 357 if (!(mp4file = mp4ff_open_read(mp4cb))) { |
358 g_free(mp4cb); | |
359 vfs_fclose(mp4fh); | |
360 } else { | |
361 gint mp4track= getAACTrack(mp4file); | |
362 gint numSamples = mp4ff_num_samples(mp4file, mp4track); | |
363 guint framesize = 1024; | |
364 gulong samplerate; | |
365 guchar channels; | |
366 gint msDuration; | |
367 mp4AudioSpecificConfig mp4ASC; | |
368 gchar *tmpval; | |
369 guchar *buffer = NULL; | |
370 guint bufferSize = 0; | |
371 faacDecHandle decoder; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
372 |
583 | 373 if (mp4track == -1) |
374 return NULL; | |
375 | |
376 decoder = faacDecOpen(); | |
377 mp4ff_get_decoder_config(mp4file, mp4track, &buffer, &bufferSize); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
378 |
583 | 379 if ( !buffer ) { |
380 faacDecClose(decoder); | |
381 return FALSE; | |
382 } | |
383 if ( faacDecInit2(decoder, buffer, bufferSize, | |
384 &samplerate, &channels) < 0 ) { | |
385 faacDecClose(decoder); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
386 |
583 | 387 return FALSE; |
388 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
389 |
583 | 390 /* Add some hacks for SBR profile */ |
391 if (AudioSpecificConfig(buffer, bufferSize, &mp4ASC) >= 0) { | |
392 if (mp4ASC.frameLengthFlag == 1) framesize = 960; | |
393 if (mp4ASC.sbr_present_flag == 1) framesize *= 2; | |
394 } | |
395 | |
396 g_free(buffer); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
397 |
583 | 398 faacDecClose(decoder); |
399 | |
400 msDuration = ((float)numSamples * (float)(framesize - 1.0)/(float)samplerate) * 1000; | |
401 | |
402 input = bmp_title_input_new(); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
403 |
583 | 404 mp4ff_meta_get_title(mp4file, &input->track_name); |
405 mp4ff_meta_get_album(mp4file, &input->album_name); | |
406 mp4ff_meta_get_artist(mp4file, &input->performer); | |
407 mp4ff_meta_get_date(mp4file, &tmpval); | |
408 mp4ff_meta_get_genre(mp4file, &input->genre); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
409 |
583 | 410 if (tmpval) |
411 { | |
412 input->year = atoi(tmpval); | |
413 free(tmpval); | |
414 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
415 |
583 | 416 input->file_name = g_path_get_basename(filename); |
417 input->file_path = g_path_get_dirname(filename); | |
418 input->file_ext = extname(filename); | |
419 input->length = msDuration; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
420 |
583 | 421 free (mp4cb); |
422 vfs_fclose(mp4fh); | |
423 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
424 |
583 | 425 return input; |
426 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
427 |
583 | 428 static void mp4_get_song_title_len(char *filename, char **title, int *len) |
429 { | |
430 (*title) = mp4_get_song_title(filename); | |
431 (*len) = -1; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
432 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
433 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
434 static gchar *mp4_get_song_title(char *filename) |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
435 { |
583 | 436 mp4ff_callback_t *mp4cb = g_malloc0(sizeof(mp4ff_callback_t)); |
437 VFSFile *mp4fh; | |
438 mp4ff_t *mp4file; | |
439 gchar *title = NULL; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
440 |
583 | 441 mp4fh = vfs_fopen(filename, "rb"); |
442 mp4cb->read = mp4_read_callback; | |
443 mp4cb->seek = mp4_seek_callback; | |
444 mp4cb->user_data = mp4fh; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
445 |
583 | 446 if (!(mp4file = mp4ff_open_read(mp4cb))) { |
447 g_free(mp4cb); | |
448 vfs_fclose(mp4fh); | |
449 } else { | |
450 TitleInput *input; | |
451 gchar *tmpval; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
452 |
583 | 453 input = bmp_title_input_new(); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
454 |
583 | 455 mp4ff_meta_get_title(mp4file, &input->track_name); |
456 mp4ff_meta_get_album(mp4file, &input->album_name); | |
457 mp4ff_meta_get_artist(mp4file, &input->performer); | |
458 mp4ff_meta_get_date(mp4file, &tmpval); | |
459 mp4ff_meta_get_genre(mp4file, &input->genre); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
460 |
583 | 461 if (tmpval) |
462 { | |
463 input->year = atoi(tmpval); | |
464 free(tmpval); | |
465 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
466 |
583 | 467 input->file_name = g_path_get_basename(filename); |
468 input->file_path = g_path_get_dirname(filename); | |
469 input->file_ext = extname(filename); | |
470 | |
471 title = xmms_get_titlestring(xmms_get_gentitle_format(), input); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
472 |
583 | 473 free (input->track_name); |
474 free (input->album_name); | |
475 free (input->performer); | |
476 free (input->genre); | |
477 free (input->file_name); | |
478 free (input->file_path); | |
479 free (input); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
480 |
583 | 481 free (mp4cb); |
482 vfs_fclose(mp4fh); | |
483 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
484 |
583 | 485 if (!title) |
486 { | |
487 title = g_path_get_basename(filename); | |
488 if (extname(title)) | |
489 *(extname(title) - 1) = '\0'; | |
490 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
491 |
583 | 492 return title; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
493 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
494 |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
495 static int my_decode_mp4( InputPlayback *playback, char *filename, mp4ff_t *mp4file ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
496 { |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
497 // We are reading an MP4 file |
583 | 498 gint mp4track= getAACTrack(mp4file); |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
499 faacDecHandle decoder; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
500 mp4AudioSpecificConfig mp4ASC; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
501 guchar *buffer = NULL; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
502 guint bufferSize = 0; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
503 gulong samplerate; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
504 guchar channels; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
505 gulong msDuration; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
506 gulong numSamples; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
507 gulong sampleID = 1; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
508 guint framesize = 1024; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
509 |
694
a429ce72d20e
[svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents:
693
diff
changeset
|
510 if (mp4track < 0) |
a429ce72d20e
[svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents:
693
diff
changeset
|
511 { |
a429ce72d20e
[svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents:
693
diff
changeset
|
512 g_print("Unsupported Audio track type\n"); |
a429ce72d20e
[svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents:
693
diff
changeset
|
513 return TRUE; |
a429ce72d20e
[svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents:
693
diff
changeset
|
514 } |
a429ce72d20e
[svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents:
693
diff
changeset
|
515 |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
516 gchar *xmmstitle = NULL; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
517 xmmstitle = mp4_get_song_title(filename); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
518 if(xmmstitle == NULL) |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
519 xmmstitle = g_strdup(filename); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
520 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
521 decoder = faacDecOpen(); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
522 mp4ff_get_decoder_config(mp4file, mp4track, &buffer, &bufferSize); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
523 if ( !buffer ) { |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
524 faacDecClose(decoder); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
525 return FALSE; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
526 } |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
527 if ( faacDecInit2(decoder, buffer, bufferSize, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
528 &samplerate, &channels) < 0 ) { |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
529 faacDecClose(decoder); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
530 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
531 return FALSE; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
532 } |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
533 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
534 /* Add some hacks for SBR profile */ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
535 if (AudioSpecificConfig(buffer, bufferSize, &mp4ASC) >= 0) { |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
536 if (mp4ASC.frameLengthFlag == 1) framesize = 960; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
537 if (mp4ASC.sbr_present_flag == 1) framesize *= 2; |
583 | 538 } |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
539 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
540 g_free(buffer); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
541 if( !channels ) { |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
542 faacDecClose(decoder); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
543 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
544 return FALSE; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
545 } |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
546 numSamples = mp4ff_num_samples(mp4file, mp4track); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
547 msDuration = ((float)numSamples * (float)(framesize - 1.0)/(float)samplerate) * 1000; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
548 playback->output->open_audio(FMT_S16_NE, samplerate, channels); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
549 playback->output->flush(0); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
550 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
551 mp4_ip.set_info(xmmstitle, msDuration, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
552 mp4ff_get_avg_bitrate( mp4file, mp4track ), |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
553 samplerate,channels); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
554 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
555 while ( buffer_playing ) { |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
556 void* sampleBuffer; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
557 faacDecFrameInfo frameInfo; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
558 gint rc; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
559 |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
560 /* Seek if seek position has changed */ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
561 if ( seekPosition!=-1 ) { |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
562 sampleID = (float)seekPosition*(float)samplerate/(float)(framesize - 1.0); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
563 playback->output->flush(seekPosition*1000); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
564 seekPosition = -1; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
565 } |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
566 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
567 /* Otherwise continue playing */ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
568 buffer=NULL; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
569 bufferSize=0; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
570 |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
571 /* If we've run to the end of the file, we're done. */ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
572 if(sampleID >= numSamples){ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
573 /* Finish playing before we close the |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
574 output. */ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
575 while ( playback->output->buffer_playing() ) { |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
576 xmms_usleep(10000); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
577 } |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
578 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
579 playback->output->flush(seekPosition*1000); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
580 playback->output->close_audio(); |
583 | 581 faacDecClose(decoder); |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
582 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
583 g_static_mutex_lock(&mutex); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
584 buffer_playing = FALSE; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
585 g_static_mutex_unlock(&mutex); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
586 g_thread_exit(NULL); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
587 |
583 | 588 return FALSE; |
589 } | |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
590 rc= mp4ff_read_sample(mp4file, mp4track, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
591 sampleID++, &buffer, &bufferSize); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
592 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
593 /*g_print(":: %d/%d\n", sampleID-1, numSamples);*/ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
594 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
595 /* If we can't read the file, we're done. */ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
596 if((rc == 0) || (buffer== NULL) || (bufferSize == 0) || (bufferSize > BUFFER_SIZE)){ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
597 g_print("MP4: read error\n"); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
598 sampleBuffer = NULL; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
599 sampleID=0; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
600 playback->output->buffer_free(); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
601 playback->output->close_audio(); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
602 |
583 | 603 faacDecClose(decoder); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
604 |
583 | 605 return FALSE; |
606 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
607 |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
608 /* g_print(" :: %d/%d\n", bufferSize, BUFFER_SIZE); */ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
609 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
610 sampleBuffer= faacDecDecode(decoder, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
611 &frameInfo, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
612 buffer, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
613 bufferSize); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
614 |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
615 /* If there was an error decoding, we're done. */ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
616 if(frameInfo.error > 0){ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
617 g_print("MP4: %s\n", |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
618 faacDecGetErrorMessage(frameInfo.error)); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
619 playback->output->close_audio(); |
583 | 620 faacDecClose(decoder); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
621 |
583 | 622 return FALSE; |
623 } | |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
624 if(buffer){ |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
625 g_free(buffer); |
583 | 626 buffer=NULL; |
627 bufferSize=0; | |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
628 } |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
629 if (buffer_playing == FALSE) |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
630 { |
583 | 631 playback->output->close_audio(); |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
632 return FALSE; |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
633 } |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
634 produce_audio(playback->output->written_time(), |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
635 FMT_S16_NE, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
636 channels, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
637 frameInfo.samples<<1, |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
638 sampleBuffer, &buffer_playing); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
639 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
640 |
584
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
641 playback->output->close_audio(); |
5e2b137a24fe
[svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents:
583
diff
changeset
|
642 faacDecClose(decoder); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
643 |
583 | 644 return TRUE; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
645 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
646 |
692
a77e766e332d
[svn] - fix another potential synchronization problem
nenolod
parents:
690
diff
changeset
|
647 static void my_decode_aac( InputPlayback *playback, char *filename, VFSFile *file ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
648 { |
583 | 649 faacDecHandle decoder = 0; |
695
e6b3dddb3c35
[svn] - no idea why we were using a dynamically allocated buffer for raw aac
nenolod
parents:
694
diff
changeset
|
650 guchar buffer[BUFFER_SIZE]; |
583 | 651 gulong bufferconsumed = 0; |
652 gulong samplerate = 0; | |
653 guchar channels; | |
654 gulong buffervalid = 0; | |
655 TitleInput* input; | |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
656 gchar *ttemp = NULL, *stemp = NULL; |
583 | 657 gchar *temp = g_strdup(filename); |
658 gchar *ext = strrchr(temp, '.'); | |
659 gchar *xmmstitle = NULL; | |
660 faacDecConfigurationPtr config; | |
697
74a762a3592e
[svn] - temporarily cheat and disable certain codepaths for local files
nenolod
parents:
695
diff
changeset
|
661 gboolean remote = str_has_prefix_nocase(filename, "http:") || |
74a762a3592e
[svn] - temporarily cheat and disable certain codepaths for local files
nenolod
parents:
695
diff
changeset
|
662 str_has_prefix_nocase(filename, "https:"); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
663 |
692
a77e766e332d
[svn] - fix another potential synchronization problem
nenolod
parents:
690
diff
changeset
|
664 vfs_rewind(file); |
583 | 665 if((decoder = faacDecOpen()) == NULL){ |
666 g_print("AAC: Open Decoder Error\n"); | |
667 vfs_fclose(file); | |
668 buffer_playing = FALSE; | |
669 g_static_mutex_unlock(&mutex); | |
670 g_thread_exit(NULL); | |
671 } | |
672 if((buffervalid = vfs_fread(buffer, 1, BUFFER_SIZE, file))==0){ | |
673 g_print("AAC: Error reading file\n"); | |
674 vfs_fclose(file); | |
675 buffer_playing = FALSE; | |
676 faacDecClose(decoder); | |
677 g_static_mutex_unlock(&mutex); | |
678 g_thread_exit(NULL); | |
679 } | |
680 if(!strncmp((char*)buffer, "ID3", 3)){ | |
681 gint size = 0; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
682 |
583 | 683 vfs_fseek(file, 0, SEEK_SET); |
684 size = (buffer[6]<<21) | (buffer[7]<<14) | (buffer[8]<<7) | buffer[9]; | |
685 size+=10; | |
686 vfs_fread(buffer, 1, size, file); | |
687 buffervalid = vfs_fread(buffer, 1, BUFFER_SIZE, file); | |
688 } | |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
689 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
690 ttemp = vfs_get_metadata(file, "stream-name"); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
691 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
692 if (ttemp != NULL) |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
693 { |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
694 xmmstitle = g_strdup(ttemp); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
695 g_free(ttemp); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
696 } |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
697 else |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
698 xmmstitle = g_strdup(g_basename(temp)); |
679
c8dc00a58f0d
[svn] - remove a bunch of pointless code. we don't do ID3 for raw AAC files at this time.
nenolod
parents:
678
diff
changeset
|
699 |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
700 bufferconsumed = aac_probe(buffer, buffervalid); |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
701 if(bufferconsumed) { |
690
0305b3165a01
[svn] - ringbuffering underrun fixups -- found with purify
nenolod
parents:
689
diff
changeset
|
702 memmove(buffer, &buffer[bufferconsumed], buffervalid); |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
703 buffervalid -= bufferconsumed; |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
704 buffervalid += vfs_fread(&buffer[buffervalid], 1, |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
705 BUFFER_SIZE-buffervalid, file); |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
706 bufferconsumed = 0; |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
707 } |
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
708 |
583 | 709 bufferconsumed = faacDecInit(decoder, |
710 buffer, | |
711 buffervalid, | |
712 &samplerate, | |
713 &channels); | |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
714 #ifdef DEBUG |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
715 g_print("samplerate: %d, channels: %d\n", samplerate, channels); |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
716 #endif |
583 | 717 if(playback->output->open_audio(FMT_S16_NE,samplerate,channels) == FALSE){ |
718 g_print("AAC: Output Error\n"); | |
719 faacDecClose(decoder); | |
720 vfs_fclose(file); | |
721 playback->output->close_audio(); | |
722 g_free(xmmstitle); | |
723 buffer_playing = FALSE; | |
724 g_static_mutex_unlock(&mutex); | |
725 g_thread_exit(NULL); | |
726 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
727 |
583 | 728 mp4_ip.set_info(xmmstitle, -1, -1, samplerate, channels); |
729 playback->output->flush(0); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
730 |
700
27a557e80e15
[svn] - fix a ringbuffering error. found by purify.
nenolod
parents:
697
diff
changeset
|
731 while(buffer_playing && buffervalid > 0 && buffer != NULL) |
27a557e80e15
[svn] - fix a ringbuffering error. found by purify.
nenolod
parents:
697
diff
changeset
|
732 { |
583 | 733 faacDecFrameInfo finfo; |
734 unsigned long samplesdecoded; | |
735 char* sample_buffer = NULL; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
736 |
700
27a557e80e15
[svn] - fix a ringbuffering error. found by purify.
nenolod
parents:
697
diff
changeset
|
737 if(bufferconsumed > 0) |
27a557e80e15
[svn] - fix a ringbuffering error. found by purify.
nenolod
parents:
697
diff
changeset
|
738 { |
690
0305b3165a01
[svn] - ringbuffering underrun fixups -- found with purify
nenolod
parents:
689
diff
changeset
|
739 memmove(buffer, &buffer[bufferconsumed], buffervalid); |
583 | 740 buffervalid -= bufferconsumed; |
741 buffervalid += vfs_fread(&buffer[buffervalid], 1, | |
742 BUFFER_SIZE-buffervalid, file); | |
743 bufferconsumed = 0; | |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
744 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
745 ttemp = vfs_get_metadata(file, "stream-name"); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
746 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
747 if (ttemp != NULL) |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
748 stemp = vfs_get_metadata(file, "track-name"); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
749 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
750 if (stemp != NULL) |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
751 { |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
752 static gchar *ostmp = NULL; |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
753 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
754 if (ostmp == NULL || g_ascii_strcasecmp(stemp, ostmp)) |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
755 { |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
756 if (xmmstitle != NULL) |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
757 g_free(xmmstitle); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
758 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
759 xmmstitle = g_strdup_printf("%s (%s)", stemp, ttemp); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
760 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
761 if (ostmp != NULL) |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
762 g_free(ostmp); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
763 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
764 ostmp = stemp; |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
765 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
766 mp4_ip.set_info(xmmstitle, -1, -1, samplerate, channels); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
767 } |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
768 } |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
769 |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
770 g_free(ttemp); |
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
771 ttemp = NULL; |
583 | 772 } |
688
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
773 |
583 | 774 sample_buffer = faacDecDecode(decoder, &finfo, buffer, buffervalid); |
688
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
775 |
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
776 bufferconsumed += finfo.bytesconsumed; |
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
777 samplesdecoded = finfo.samples; |
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
778 |
700
27a557e80e15
[svn] - fix a ringbuffering error. found by purify.
nenolod
parents:
697
diff
changeset
|
779 if(finfo.error > 0 && remote != FALSE) |
27a557e80e15
[svn] - fix a ringbuffering error. found by purify.
nenolod
parents:
697
diff
changeset
|
780 { |
686 | 781 memmove(buffer, &buffer[1], buffervalid); |
688
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
782 if(buffervalid < BUFFER_SIZE) { |
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
783 buffervalid += |
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
784 vfs_fread(&buffer[buffervalid], 1, BUFFER_SIZE-buffervalid, file); |
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
785 } |
686 | 786 bufferconsumed = aac_probe(buffer, buffervalid); |
787 if(bufferconsumed) { | |
700
27a557e80e15
[svn] - fix a ringbuffering error. found by purify.
nenolod
parents:
697
diff
changeset
|
788 buffervalid -= bufferconsumed; |
689 | 789 memmove(buffer, &buffer[bufferconsumed], buffervalid); |
686 | 790 bufferconsumed = 0; |
583 | 791 } |
686 | 792 continue; |
583 | 793 } |
688
43c77973e494
[svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents:
686
diff
changeset
|
794 |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
795 if((samplesdecoded <= 0) && !sample_buffer){ |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
796 #ifdef DEBUG |
684
c9eaa64b92b3
[svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents:
682
diff
changeset
|
797 g_print("AAC: decoded %d samples!\n", samplesdecoded); |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
798 #endif |
583 | 799 continue; |
800 } | |
693
a7ba9d27c7b5
[svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents:
692
diff
changeset
|
801 |
583 | 802 produce_audio(playback->output->written_time(), |
803 FMT_S16_LE, channels, | |
804 samplesdecoded<<1, sample_buffer, &buffer_playing); | |
805 } | |
806 playback->output->buffer_free(); | |
807 playback->output->close_audio(); | |
808 buffer_playing = FALSE; | |
809 faacDecClose(decoder); | |
810 g_free(xmmstitle); | |
811 vfs_fclose(file); | |
812 seekPosition = -1; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
813 |
583 | 814 buffer_playing = FALSE; |
815 g_static_mutex_unlock(&mutex); | |
816 g_thread_exit(NULL); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
817 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
818 |
583 | 819 static void *mp4_decode( void *args ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
820 { |
583 | 821 mp4ff_callback_t *mp4cb = g_malloc0(sizeof(mp4ff_callback_t)); |
822 VFSFile *mp4fh; | |
823 mp4ff_t *mp4file; | |
678
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
824 gboolean ret; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
825 |
583 | 826 InputPlayback *playback = args; |
827 char *filename = playback->filename; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
828 |
583 | 829 mp4fh = vfs_fopen(filename, "rb"); |
830 mp4cb->read = mp4_read_callback; | |
831 mp4cb->seek = mp4_seek_callback; | |
832 mp4cb->user_data = mp4fh; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
833 |
583 | 834 g_static_mutex_lock(&mutex); |
835 seekPosition= -1; | |
836 buffer_playing= TRUE; | |
837 g_static_mutex_unlock(&mutex); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
838 |
692
a77e766e332d
[svn] - fix another potential synchronization problem
nenolod
parents:
690
diff
changeset
|
839 if (mp4fh == NULL) |
a77e766e332d
[svn] - fix another potential synchronization problem
nenolod
parents:
690
diff
changeset
|
840 g_thread_exit(NULL); |
a77e766e332d
[svn] - fix another potential synchronization problem
nenolod
parents:
690
diff
changeset
|
841 |
678
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
842 ret = parse_aac_stream(mp4fh); |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
843 vfs_rewind(mp4fh); |
583 | 844 mp4file= mp4ff_open_read(mp4cb); |
678
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
845 |
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
846 if( ret == TRUE ) { |
583 | 847 g_free(mp4cb); |
692
a77e766e332d
[svn] - fix another potential synchronization problem
nenolod
parents:
690
diff
changeset
|
848 my_decode_aac( playback, filename, mp4fh ); |
583 | 849 } |
678
9e4145566248
[svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents:
595
diff
changeset
|
850 else |
583 | 851 my_decode_mp4( playback, filename, mp4file ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
852 |
583 | 853 return NULL; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
854 } |