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