annotate src/aac/libmp4.c @ 2168:3c9527d25346

fix a crash bug in mp4_is_our_file().
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sat, 17 Nov 2007 03:41:41 +0900
parents 4610f14103e4
children 42a5c9d5830b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1950
2ebeb7816c5e Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents: 1882
diff changeset
9 #include <audacious/plugin.h>
2ebeb7816c5e Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents: 1882
diff changeset
10 #include <audacious/output.h>
2ebeb7816c5e Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents: 1882
diff changeset
11 #include <audacious/util.h>
1952
17a6441c71b6 Some missed #include "" to <> changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
12 #include <audacious/i18n.h>
1950
2ebeb7816c5e Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents: 1882
diff changeset
13 #include <audacious/strings.h>
2ebeb7816c5e Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents: 1882
diff changeset
14 #include <audacious/main.h>
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
16 #define MP4_VERSION VERSION
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
17 #define SBR_DEC
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
18
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 * 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
21 * 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
22 * a labotomy sometimes.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
23 */
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
24 #define BUFFER_SIZE FAAD_MIN_STREAMSIZE*64
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
25
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
26 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27 * 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
28 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
29 #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
30
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
31 static void mp4_init(void);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
32 static void mp4_about(void);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
33 static int mp4_is_our_file(char *);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
34 static void mp4_play(InputPlayback *);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
35 static void mp4_stop(InputPlayback *);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
36 static void mp4_pause(InputPlayback *, short);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
37 static void mp4_seek(InputPlayback *, int);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
38 static void mp4_cleanup(void);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
39 static void mp4_get_song_title_len(char *filename, char **, int *);
1427
138ea47220e8 Conversion of AAC to new tuple API, try one.
Tony Vroon <chainsaw@gentoo.org>
parents: 1395
diff changeset
40 static Tuple* mp4_get_song_tuple(char *);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
41 static int mp4_is_our_fd(char *, VFSFile *);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
42
1073
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
43 static gchar *fmts[] = { "m4a", "mp4", "aac", NULL };
374
7d7d66d0b2c3 [svn] - fix MP4 extension table
nenolod
parents: 372
diff changeset
44
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
45 static void * mp4_decode(void *);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
46 static gchar * mp4_get_song_title(char *filename);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
47 gboolean buffer_playing;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
48
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
49 InputPlugin mp4_ip =
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
50 {
1073
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
51 .description = "MP4 Audio Plugin",
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
52 .init = mp4_init,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
53 .about = mp4_about,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
54 .is_our_file = mp4_is_our_file,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
55 .play_file = mp4_play,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
56 .stop = mp4_stop,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
57 .pause = mp4_pause,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
58 .seek = mp4_seek,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
59 .cleanup = mp4_cleanup,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
60 .get_song_info = mp4_get_song_title_len,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
61 .get_song_tuple = mp4_get_song_tuple,
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
62 .is_our_file_from_vfs = mp4_is_our_fd,
1979
839804c3b3a4 aud_vfs_extensions -> vfs_extensions, some vtable fixes
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
63 .vfs_extensions = fmts,
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
64 };
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
65
1073
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
66 InputPlugin *mp4_iplist[] = { &mp4_ip, NULL };
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
67
1395
761e17b23e0c added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents: 1346
diff changeset
68 DECLARE_PLUGIN(mp4, NULL, NULL, mp4_iplist, NULL, NULL, NULL, NULL, NULL);
1073
c77a0ed314bc [svn] Port to plugin API v2.
chainsaw
parents: 785
diff changeset
69
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
70 typedef struct _mp4cfg
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
71 {
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
72 #define FILE_UNKNOWN 0
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
73 #define FILE_MP4 1
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
74 #define FILE_AAC 2
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
75 gshort file_type;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
76 } Mp4Config;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
77
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
78 static Mp4Config mp4cfg;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
79 static GThread *decodeThread;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
80 GStaticMutex mutex = G_STATIC_MUTEX_INIT;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
81 static int seekPosition = -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
82
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
83 void getMP4info(char*);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
84 int getAACTrack(mp4ff_t *);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
85
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
86 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
87 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
88 if (data == NULL || buffer == NULL)
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
89 return -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
90
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
91 return aud_vfs_fread(buffer, 1, len, (VFSFile *) data);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
92 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
93
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
94 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
95 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
96 if (data == NULL)
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
97 return -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
98
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
99 return aud_vfs_fseek((VFSFile *) data, pos, SEEK_SET);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
100 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
101
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
102 static void mp4_init(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
103 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
104 mp4cfg.file_type = FILE_UNKNOWN;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
105 seekPosition = -1;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
106 return;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
107 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
108
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
109 static void mp4_play(InputPlayback *playback)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
110 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
111 buffer_playing = TRUE;
1163
b5a61440bfe8 [svn] - make aac plugin work again.
yaz
parents: 1075
diff changeset
112 playback->playing = 1; //XXX should acquire lock?
1346
7c5d22f753aa I'm an idiot.
William Pitcock <nenolod@atheme-project.org>
parents: 1345
diff changeset
113 decodeThread = g_thread_self();
1447
195b5657303e updated input plugins to use set_pb_ready to signal to the core that they're ready for playback
Giacomo Lozito <james@develia.org>
parents: 1437
diff changeset
114 playback->set_pb_ready(playback);
1345
76f826e6052d aac: Convert to new threading model.
William Pitcock <nenolod@atheme-project.org>
parents: 1325
diff changeset
115 mp4_decode(playback);
0
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
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
118 static void mp4_stop(InputPlayback *playback)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
119 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
120 if (buffer_playing)
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
121 {
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
122 buffer_playing = FALSE;
1163
b5a61440bfe8 [svn] - make aac plugin work again.
yaz
parents: 1075
diff changeset
123 playback->playing = 0; //XXX should acquire lock?
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
124 g_thread_join(decodeThread);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
125 playback->output->close_audio();
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
126 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
127 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
128
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
129 /*
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
130 * 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
131 */
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
132
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
133 /// \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
134 /// \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
135 /// \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
136 /// 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
137 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
138 {
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
139 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
140 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
141
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
142 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
143 return 0;
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
144
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
145 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
146 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
147 if(sr > 11)
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
148 return 0;
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
149 *srate = srates[sr];
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
150
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
151 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
152 *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
153
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
154 return fl;
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
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
157 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
158 {
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
159 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
160 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
161 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
162
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
163 init = probed = aud_vfs_ftell(stream);
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
164 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
165 {
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
166 c = 0;
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
167 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
168 {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
169 c = aud_vfs_getc(stream);
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
170 if(c < 0)
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
171 return FALSE;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
172 probed = aud_vfs_ftell(stream);
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
173 }
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
174 buf[0] = 0xFF;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
175 if(aud_vfs_fread(&(buf[1]), 1, 7, stream) < 7)
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
176 return FALSE;
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
177
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
178 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
179 if(len > 0)
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
180 {
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
181 cnt++;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
182 aud_vfs_fseek(stream, len - 8, SEEK_CUR);
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
183 }
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
184 probed = aud_vfs_ftell(stream);
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
185 }
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
186
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
187 if(cnt < 8)
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
188 return FALSE;
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
189
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
190 return TRUE;
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
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
193 static int aac_probe(unsigned char *buffer, int len)
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
194 {
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
195 int i = 0, pos = 0;
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
196 #ifdef DEBUG
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
197 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
198 #endif
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
199 while(i <= len-4) {
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
200 if(
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
201 ((buffer[i] == 0xff) && ((buffer[i+1] & 0xf6) == 0xf0)) ||
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
202 (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
203 ) {
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
204 pos = i;
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
205 break;
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
206 }
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
207 #ifdef DEBUG
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
208 g_print("AUDIO PAYLOAD: %x %x %x %x\n",
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
209 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
210 #endif
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
211 i++;
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
212 }
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
213 #ifdef DEBUG
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
214 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
215 #endif
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
216 return pos;
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
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
219 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
220 {
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
221 VFSFile *file;
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
222 gchar* extension;
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
223 gchar magic[8];
393
6987b5334081 [svn] Fix:
nenolod
parents: 374
diff changeset
224
6987b5334081 [svn] Fix:
nenolod
parents: 374
diff changeset
225 memset(magic, '\0', 8);
6987b5334081 [svn] Fix:
nenolod
parents: 374
diff changeset
226
262
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
227 extension = strrchr(filename, '.');
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
228 if ((file = aud_vfs_fopen(filename, "rb"))) {
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
229 aud_vfs_fread(magic, 1, 8, file);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
230 aud_vfs_rewind(file);
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
231 if (parse_aac_stream(file) == TRUE) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
232 aud_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
233 return TRUE;
262
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
234 }
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
235 if (!memcmp(magic, "ID3", 3)) { // ID3 tag bolted to the front, obfuscated magic bytes
2168
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
236 aud_vfs_fclose(file);
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
237 if (extension &&(
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
238 !strcasecmp(extension, ".mp4") || // official extension
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
239 !strcasecmp(extension, ".m4a") || // Apple mp4 extension
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
240 !strcasecmp(extension, ".aac") // old MPEG2/4-AAC extension
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
241 ))
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
242 return 1;
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
243 else {
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
244 return 0;
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
245 }
262
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
246 }
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
247 if (!memcmp(&magic[4], "ftyp", 4)) {
2168
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
248 aud_vfs_fclose(file);
3c9527d25346 fix a crash bug in mp4_is_our_file().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2143
diff changeset
249 return 1;
262
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
250 }
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
251 aud_vfs_fclose(file);
262
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
252 }
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
253 return 0;
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
254 }
f653f1219db2 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 255
diff changeset
255
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
256 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
257 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
258 gchar* extension;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
259 gchar magic[8];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
260
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
261 extension = strrchr(filename, '.');
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
262 aud_vfs_fread(magic, 1, 8, file);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
263 aud_vfs_rewind(file);
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
264 if (parse_aac_stream(file) == TRUE)
255
902605dec467 [svn] Port to NewVFS probe function.
chainsaw
parents: 12
diff changeset
265 return 1;
902605dec467 [svn] Port to NewVFS probe function.
chainsaw
parents: 12
diff changeset
266 if (!memcmp(&magic[4], "ftyp", 4))
902605dec467 [svn] Port to NewVFS probe function.
chainsaw
parents: 12
diff changeset
267 return 1;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
268 if (!memcmp(magic, "ID3", 3)) { // ID3 tag bolted to the front, obfuscated magic bytes
255
902605dec467 [svn] Port to NewVFS probe function.
chainsaw
parents: 12
diff changeset
269 if (extension &&(
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
270 !strcasecmp(extension, ".mp4") || // official extension
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
271 !strcasecmp(extension, ".m4a") || // Apple mp4 extension
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
272 !strcasecmp(extension, ".aac") // old MPEG2/4-AAC extension
255
902605dec467 [svn] Port to NewVFS probe function.
chainsaw
parents: 12
diff changeset
273 ))
902605dec467 [svn] Port to NewVFS probe function.
chainsaw
parents: 12
diff changeset
274 return 1;
902605dec467 [svn] Port to NewVFS probe function.
chainsaw
parents: 12
diff changeset
275 else
902605dec467 [svn] Port to NewVFS probe function.
chainsaw
parents: 12
diff changeset
276 return 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
277 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
278 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
279 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
280
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
281 static void mp4_about(void)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
282 {
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
283 static GtkWidget *aboutbox = NULL;
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
284 gchar *about_text;
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
285
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
286 about_text = g_strjoin ("", _("Using libfaad2-"), FAAD2_VERSION,
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
287 _(" for decoding.\n"
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
288 "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com\n"
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
289 "Copyright (c) 2005-2006 Audacious team"), NULL);
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
290
1677
f6f5603a0954 xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents: 1676
diff changeset
291 aboutbox = audacious_info_dialog(_("About MP4 AAC player plugin"),
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
292 about_text,
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
293 _("Ok"), FALSE, NULL, NULL);
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
294
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
295 g_signal_connect(G_OBJECT(aboutbox), "destroy",
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
296 G_CALLBACK(gtk_widget_destroyed), &aboutbox);
1325
a33da9237bed Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents: 1304
diff changeset
297 g_free(about_text);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
298 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
299
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
300 static void mp4_pause(InputPlayback *playback, short flag)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
301 {
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
302 playback->output->pause(flag);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
303 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
304
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
305 static void mp4_seek(InputPlayback *data, int time)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
306 {
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
307 seekPosition = time;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
308 while(buffer_playing && seekPosition != -1)
1676
aee4ebea943a xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents: 1510
diff changeset
309 g_usleep(10000);
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
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
312 static void mp4_cleanup(void)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
313 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
314 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
315
2050
2ffc6a69fcd1 string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents: 1998
diff changeset
316 static Tuple *mp4_get_song_tuple_base(char *filename, VFSFile *mp4fh)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
317 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
318 mp4ff_callback_t *mp4cb = g_malloc0(sizeof(mp4ff_callback_t));
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
319 mp4ff_t *mp4file;
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
320 Tuple *ti = aud_tuple_new_from_filename(filename);
760
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
321
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
322 /* 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
323 if (parse_aac_stream(mp4fh))
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
324 {
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
325 g_free(mp4cb);
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
326
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
327 aud_tuple_associate_string(ti, FIELD_TITLE, NULL, aud_vfs_get_metadata(mp4fh, "track-name"));
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
328 aud_tuple_associate_string(ti, FIELD_ALBUM, NULL, aud_vfs_get_metadata(mp4fh, "stream-name"));
760
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
329
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
330 aud_tuple_associate_string(ti, FIELD_CODEC, NULL, "Advanced Audio Coding (AAC)");
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
331 aud_tuple_associate_string(ti, FIELD_QUALITY, NULL, "lossy");
760
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
332
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
333 aud_vfs_fclose(mp4fh);
1427
138ea47220e8 Conversion of AAC to new tuple API, try one.
Tony Vroon <chainsaw@gentoo.org>
parents: 1395
diff changeset
334 return ti;
760
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
335 }
6ed8d477ba89 [svn] - add tuple building for ADTS/Shoutcast streams
nenolod
parents: 759
diff changeset
336
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
337 aud_vfs_rewind(mp4fh);
785
e23b8e1472e3 [svn] - don't use a vfs buffered source for local files
nenolod
parents: 760
diff changeset
338
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
339 mp4cb->read = mp4_read_callback;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
340 mp4cb->seek = mp4_seek_callback;
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
341 mp4cb->user_data = mp4fh;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
342
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
343 if (!(mp4file = mp4ff_open_read(mp4cb))) {
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
344 g_free(mp4cb);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
345 aud_vfs_fclose(mp4fh);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
346 } else {
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
347 gint mp4track= getAACTrack(mp4file);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
348 gint numSamples = mp4ff_num_samples(mp4file, mp4track);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
349 guint framesize = 1024;
1188
22a470857579 - fix the bug that aac plugin had failed to get proper playtime length on AMD64.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1167
diff changeset
350 guint samplerate = 0;
22a470857579 - fix the bug that aac plugin had failed to get proper playtime length on AMD64.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1167
diff changeset
351 guchar channels = 0;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
352 gint msDuration;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
353 mp4AudioSpecificConfig mp4ASC;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
354 gchar *tmpval;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
355 guchar *buffer = NULL;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
356 guint bufferSize = 0;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
357 faacDecHandle decoder;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
358
2143
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
359 if (mp4track == -1) {
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
360 // clean up
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
361 g_free(mp4cb);
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
362 aud_vfs_fclose(mp4fh);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
363 return NULL;
2143
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
364 }
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
365
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
366 decoder = faacDecOpen();
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
367 mp4ff_get_decoder_config(mp4file, mp4track, &buffer, &bufferSize);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
368
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
369 if ( !buffer ) {
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
370 faacDecClose(decoder);
2143
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
371 // clean up
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
372 g_free(mp4cb);
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
373 aud_vfs_fclose(mp4fh);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
374 return FALSE;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
375 }
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
376 if ( faacDecInit2(decoder, buffer, bufferSize,
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
377 &samplerate, &channels) < 0 ) {
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
378 faacDecClose(decoder);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
379
2143
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
380 // clean up
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
381 g_free(mp4cb);
4610f14103e4 fixed some memory leaks and dangling file descriptor pointers in the aac/mp4 plugin
Ben Tucker <ben.tucker@gmail.com>
parents: 2055
diff changeset
382 aud_vfs_fclose(mp4fh);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
383 return FALSE;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
384 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
385
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
386 /* Add some hacks for SBR profile */
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
387 if (AudioSpecificConfig(buffer, bufferSize, &mp4ASC) >= 0) {
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
388 if (mp4ASC.frameLengthFlag == 1) framesize = 960;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
389 if (mp4ASC.sbr_present_flag == 1) framesize *= 2;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
390 }
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
391
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
392 g_free(buffer);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
393
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
394 faacDecClose(decoder);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
395
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
396 msDuration = ((float)numSamples * (float)(framesize - 1.0)/(float)samplerate) * 1000;
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
397 aud_tuple_associate_int(ti, FIELD_LENGTH, NULL, msDuration);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
398
1431
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
399 mp4ff_meta_get_title(mp4file, &tmpval);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
400 if (tmpval)
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
401 {
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
402 aud_tuple_associate_string(ti, FIELD_TITLE, NULL, tmpval);
1431
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
403 free(tmpval);
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
404 }
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
405
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
406 mp4ff_meta_get_album(mp4file, &tmpval);
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
407 if (tmpval)
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
408 {
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
409 aud_tuple_associate_string(ti, FIELD_ALBUM, NULL, tmpval);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
410 free(tmpval);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
411 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
412
1431
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
413 mp4ff_meta_get_artist(mp4file, &tmpval);
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
414 if (tmpval)
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
415 {
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
416 aud_tuple_associate_string(ti, FIELD_ARTIST, NULL, tmpval);
1431
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
417 free(tmpval);
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
418 }
1427
138ea47220e8 Conversion of AAC to new tuple API, try one.
Tony Vroon <chainsaw@gentoo.org>
parents: 1395
diff changeset
419
1431
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
420 mp4ff_meta_get_genre(mp4file, &tmpval);
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
421 if (tmpval)
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
422 {
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
423 aud_tuple_associate_string(ti, FIELD_GENRE, NULL, tmpval);
1431
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
424 free(tmpval);
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
425 }
1427
138ea47220e8 Conversion of AAC to new tuple API, try one.
Tony Vroon <chainsaw@gentoo.org>
parents: 1395
diff changeset
426
1431
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
427 mp4ff_meta_get_date(mp4file, &tmpval);
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
428 if (tmpval)
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
429 {
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
430 aud_tuple_associate_int(ti, FIELD_YEAR, NULL, atoi(tmpval));
1431
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
431 free(tmpval);
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
432 }
6b1f888a4c52 Use tuple_new_from_filename in more plugins.
Tony Vroon <chainsaw@gentoo.org>
parents: 1427
diff changeset
433
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
434 aud_tuple_associate_string(ti, FIELD_CODEC, NULL, "Advanced Audio Coding (AAC)");
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
435 aud_tuple_associate_string(ti, FIELD_QUALITY, NULL, "lossy");
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
436
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
437 free (mp4cb);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
438 aud_vfs_fclose(mp4fh);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
439 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
440
1427
138ea47220e8 Conversion of AAC to new tuple API, try one.
Tony Vroon <chainsaw@gentoo.org>
parents: 1395
diff changeset
441 return ti;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
442 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
443
1437
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
444 static Tuple *mp4_get_song_tuple(char *filename)
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
445 {
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
446 Tuple *tuple;
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
447 VFSFile *mp4fh;
2050
2ffc6a69fcd1 string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents: 1998
diff changeset
448 gboolean remote = aud_str_has_prefix_nocase(filename, "http:") ||
2ffc6a69fcd1 string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents: 1998
diff changeset
449 aud_str_has_prefix_nocase(filename, "https:");
1437
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
450
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
451 mp4fh = remote ? aud_vfs_buffered_file_new_from_uri(filename) : aud_vfs_fopen(filename, "rb");
1437
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
452
2050
2ffc6a69fcd1 string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents: 1998
diff changeset
453 tuple = mp4_get_song_tuple_base(filename, mp4fh);
1437
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
454
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
455 return tuple;
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
456 }
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
457
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
458 static void mp4_get_song_title_len(char *filename, char **title, int *len)
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
459 {
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
460 (*title) = mp4_get_song_title(filename);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
461 (*len) = -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
462 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
463
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
464 static gchar *mp4_get_song_title(char *filename)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
465 {
1437
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
466 gchar *title;
7373c4e2657c aac: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1431
diff changeset
467 Tuple *tuple = mp4_get_song_tuple(filename);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
468
2055
2f2ffbc2d04d gentitle changes
William Pitcock <nenolod@atheme.org>
parents: 2050
diff changeset
469 title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
470
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
471 aud_tuple_free(tuple);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
472
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
473 return title;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
474 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
475
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
476 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
477 {
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
478 // We are reading an MP4 file
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
479 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
480 faacDecHandle decoder;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
481 mp4AudioSpecificConfig mp4ASC;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
482 guchar *buffer = NULL;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
483 guint bufferSize = 0;
1188
22a470857579 - fix the bug that aac plugin had failed to get proper playtime length on AMD64.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1167
diff changeset
484 guint samplerate = 0;
22a470857579 - fix the bug that aac plugin had failed to get proper playtime length on AMD64.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1167
diff changeset
485 guchar channels = 0;
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
486 gulong msDuration;
1188
22a470857579 - fix the bug that aac plugin had failed to get proper playtime length on AMD64.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1167
diff changeset
487 guint numSamples;
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
488 gulong sampleID = 1;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
489 guint framesize = 1024;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
490
694
a429ce72d20e [svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents: 693
diff changeset
491 if (mp4track < 0)
a429ce72d20e [svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents: 693
diff changeset
492 {
a429ce72d20e [svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents: 693
diff changeset
493 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
494 return TRUE;
a429ce72d20e [svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents: 693
diff changeset
495 }
a429ce72d20e [svn] - handle a situation where buffer could be NULL (e.g. bail)
nenolod
parents: 693
diff changeset
496
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
497 gchar *xmmstitle = NULL;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
498 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
499 if(xmmstitle == NULL)
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
500 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
501
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
502 decoder = faacDecOpen();
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
503 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
504 if ( !buffer ) {
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
505 faacDecClose(decoder);
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
506 return FALSE;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
507 }
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
508 if ( faacDecInit2(decoder, buffer, bufferSize,
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
509 &samplerate, &channels) < 0 ) {
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
510 faacDecClose(decoder);
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
511
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
512 return FALSE;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
513 }
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
514
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
515 /* 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
516 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
517 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
518 if (mp4ASC.sbr_present_flag == 1) framesize *= 2;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
519 }
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
520
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
521 g_free(buffer);
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
522 if( !channels ) {
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
523 faacDecClose(decoder);
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
524
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
525 return FALSE;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
526 }
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
527 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
528 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
529 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
530 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
531
1984
489e32a8e106 change some places to use set_params() instead of set_info() directly
William Pitcock <nenolod@atheme.org>
parents: 1979
diff changeset
532 playback->set_params(playback, xmmstitle, msDuration,
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
533 mp4ff_get_avg_bitrate( mp4file, mp4track ),
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
534 samplerate,channels);
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
535
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
536 while ( buffer_playing ) {
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
537 void* sampleBuffer;
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
538 faacDecFrameInfo frameInfo;
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
539 gint rc;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
540
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
541 /* 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
542 if ( seekPosition!=-1 ) {
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
543 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
544 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
545 seekPosition = -1;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
546 }
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
547
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
548 /* Otherwise continue playing */
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
549 buffer=NULL;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
550 bufferSize=0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
551
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
552 /* 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
553 if(sampleID >= numSamples){
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
554 /* 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
555 output. */
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
556 while ( playback->output->buffer_playing() ) {
1676
aee4ebea943a xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents: 1510
diff changeset
557 g_usleep(10000);
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
558 }
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
559
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
560 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
561 playback->output->close_audio();
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
562 faacDecClose(decoder);
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
563
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
564 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
565 buffer_playing = FALSE;
1167
f22b4eb572fb [svn] - add playback->playing = 0 where buffer_playing = FALSE is done. without this, playback_get_time() would be confused and playback wouldn't advance in playlist.
yaz
parents: 1163
diff changeset
566 playback->playing = 0;
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
567 g_static_mutex_unlock(&mutex);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
568 return FALSE;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
569 }
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
570 rc= mp4ff_read_sample(mp4file, mp4track,
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
571 sampleID++, &buffer, &bufferSize);
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
572
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
573 /*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
574
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
575 /* 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
576 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
577 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
578 sampleBuffer = NULL;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
579 sampleID=0;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
580 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
581 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
582
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
583 faacDecClose(decoder);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
584
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
585 return FALSE;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
586 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
587
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
588 /* 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
589
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
590 sampleBuffer= faacDecDecode(decoder,
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
591 &frameInfo,
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
592 buffer,
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
593 bufferSize);
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
594
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
595 /* If 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
596 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
597 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
598 faacDecGetErrorMessage(frameInfo.error));
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
599 playback->output->close_audio();
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
600 faacDecClose(decoder);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
601
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
602 return FALSE;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
603 }
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
604 if(buffer){
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
605 g_free(buffer);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
606 buffer=NULL;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
607 bufferSize=0;
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
608 }
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
609 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
610 {
1167
f22b4eb572fb [svn] - add playback->playing = 0 where buffer_playing = FALSE is done. without this, playback_get_time() would be confused and playback wouldn't advance in playlist.
yaz
parents: 1163
diff changeset
611 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
612 return FALSE;
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
613 }
1998
8f3188746b64 chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents: 1984
diff changeset
614 playback->pass_audio(playback,
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
615 FMT_S16_NE,
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
616 channels,
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
617 frameInfo.samples<<1,
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
618 sampleBuffer, &buffer_playing);
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
619 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
620
584
5e2b137a24fe [svn] - Cleaned up AAC plugin a bit more, but still couldn't fix the bug
mf0102
parents: 583
diff changeset
621 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
622 faacDecClose(decoder);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
623
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
624 return TRUE;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
625 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
626
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
627 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
628 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
629 faacDecHandle decoder = 0;
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
630 guchar streambuffer[BUFFER_SIZE];
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
631 gulong bufferconsumed = 0;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
632 gulong samplerate = 0;
1188
22a470857579 - fix the bug that aac plugin had failed to get proper playtime length on AMD64.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1167
diff changeset
633 guchar channels = 0;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
634 gulong buffervalid = 0;
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
635 gchar *ttemp = NULL, *stemp = NULL;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
636 gchar *temp = g_strdup(filename);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
637 gchar *xmmstitle = NULL;
2050
2ffc6a69fcd1 string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents: 1998
diff changeset
638 gboolean remote = aud_str_has_prefix_nocase(filename, "http:") ||
2ffc6a69fcd1 string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents: 1998
diff changeset
639 aud_str_has_prefix_nocase(filename, "https:");
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
640
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
641 aud_vfs_rewind(file);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
642 if((decoder = faacDecOpen()) == NULL){
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
643 g_print("AAC: Open Decoder Error\n");
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
644 aud_vfs_fclose(file);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
645 buffer_playing = FALSE;
1167
f22b4eb572fb [svn] - add playback->playing = 0 where buffer_playing = FALSE is done. without this, playback_get_time() would be confused and playback wouldn't advance in playlist.
yaz
parents: 1163
diff changeset
646 playback->playing = 0;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
647 g_static_mutex_unlock(&mutex);
1345
76f826e6052d aac: Convert to new threading model.
William Pitcock <nenolod@atheme-project.org>
parents: 1325
diff changeset
648 return;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
649 }
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
650 if((buffervalid = aud_vfs_fread(streambuffer, 1, BUFFER_SIZE, file))==0){
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
651 g_print("AAC: Error reading file\n");
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
652 aud_vfs_fclose(file);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
653 buffer_playing = FALSE;
1167
f22b4eb572fb [svn] - add playback->playing = 0 where buffer_playing = FALSE is done. without this, playback_get_time() would be confused and playback wouldn't advance in playlist.
yaz
parents: 1163
diff changeset
654 playback->playing = 0;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
655 faacDecClose(decoder);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
656 g_static_mutex_unlock(&mutex);
1345
76f826e6052d aac: Convert to new threading model.
William Pitcock <nenolod@atheme-project.org>
parents: 1325
diff changeset
657 return;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
658 }
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
659 if(!strncmp((char*)streambuffer, "ID3", 3)){
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
660 gint size = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
661
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
662 aud_vfs_fseek(file, 0, SEEK_SET);
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
663 size = (streambuffer[6]<<21) | (streambuffer[7]<<14) |
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
664 (streambuffer[8]<<7) | streambuffer[9];
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
665 size+=10;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
666 aud_vfs_fread(streambuffer, 1, size, file);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
667 buffervalid = aud_vfs_fread(streambuffer, 1, BUFFER_SIZE, file);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
668 }
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
669
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
670 ttemp = aud_vfs_get_metadata(file, "stream-name");
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
671
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
672 if (ttemp != NULL)
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
673 {
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
674 xmmstitle = g_strdup(ttemp);
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
675 g_free(ttemp);
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
676 }
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
677 else
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
678 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
679
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
680 bufferconsumed = aac_probe(streambuffer, buffervalid);
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
681 if(bufferconsumed) {
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
682 buffervalid -= bufferconsumed;
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
683 memmove(streambuffer, &streambuffer[bufferconsumed], buffervalid);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
684 buffervalid += aud_vfs_fread(&streambuffer[buffervalid], 1,
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
685 BUFFER_SIZE-buffervalid, file);
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
686 bufferconsumed = 0;
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
687 }
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
688
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
689 bufferconsumed = faacDecInit(decoder,
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
690 streambuffer,
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
691 buffervalid,
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
692 &samplerate,
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
693 &channels);
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
694 #ifdef DEBUG
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
695 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
696 #endif
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
697 if(playback->output->open_audio(FMT_S16_NE,samplerate,channels) == FALSE){
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
698 g_print("AAC: Output Error\n");
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
699 faacDecClose(decoder);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
700 aud_vfs_fclose(file);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
701 playback->output->close_audio();
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
702 g_free(xmmstitle);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
703 buffer_playing = FALSE;
1167
f22b4eb572fb [svn] - add playback->playing = 0 where buffer_playing = FALSE is done. without this, playback_get_time() would be confused and playback wouldn't advance in playlist.
yaz
parents: 1163
diff changeset
704 playback->playing = 0;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
705 g_static_mutex_unlock(&mutex);
1345
76f826e6052d aac: Convert to new threading model.
William Pitcock <nenolod@atheme-project.org>
parents: 1325
diff changeset
706 return;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
707 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
708
1984
489e32a8e106 change some places to use set_params() instead of set_info() directly
William Pitcock <nenolod@atheme.org>
parents: 1979
diff changeset
709 playback->set_params(playback, xmmstitle, -1, -1, samplerate, channels);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
710 playback->output->flush(0);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
711
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
712 while(buffer_playing && buffervalid > 0 && streambuffer != NULL)
700
27a557e80e15 [svn] - fix a ringbuffering error. found by purify.
nenolod
parents: 697
diff changeset
713 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
714 faacDecFrameInfo finfo;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
715 unsigned long samplesdecoded;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
716 char* sample_buffer = NULL;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
717
700
27a557e80e15 [svn] - fix a ringbuffering error. found by purify.
nenolod
parents: 697
diff changeset
718 if(bufferconsumed > 0)
27a557e80e15 [svn] - fix a ringbuffering error. found by purify.
nenolod
parents: 697
diff changeset
719 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
720 buffervalid -= bufferconsumed;
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
721 memmove(streambuffer, &streambuffer[bufferconsumed], buffervalid);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
722 buffervalid += aud_vfs_fread(&streambuffer[buffervalid], 1,
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
723 BUFFER_SIZE-buffervalid, file);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
724 bufferconsumed = 0;
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
725
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
726 ttemp = aud_vfs_get_metadata(file, "stream-name");
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
727
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
728 if (ttemp != NULL)
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
729 stemp = aud_vfs_get_metadata(file, "track-name");
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
730
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
731 if (stemp != NULL)
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
732 {
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
733 static gchar *ostmp = NULL;
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
734
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
735 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
736 {
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
737 if (xmmstitle != NULL)
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
738 g_free(xmmstitle);
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
739
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
740 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
741
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
742 if (ostmp != NULL)
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
743 g_free(ostmp);
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
744
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
745 ostmp = stemp;
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
746
1984
489e32a8e106 change some places to use set_params() instead of set_info() directly
William Pitcock <nenolod@atheme.org>
parents: 1979
diff changeset
747 playback->set_params(playback, xmmstitle, -1, -1, samplerate, channels);
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
748 }
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
749 }
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
750
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
751 g_free(ttemp);
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
752 ttemp = NULL;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
753 }
688
43c77973e494 [svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents: 686
diff changeset
754
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
755 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
756
43c77973e494 [svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents: 686
diff changeset
757 bufferconsumed += finfo.bytesconsumed;
43c77973e494 [svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents: 686
diff changeset
758 samplesdecoded = finfo.samples;
43c77973e494 [svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents: 686
diff changeset
759
700
27a557e80e15 [svn] - fix a ringbuffering error. found by purify.
nenolod
parents: 697
diff changeset
760 if(finfo.error > 0 && remote != FALSE)
27a557e80e15 [svn] - fix a ringbuffering error. found by purify.
nenolod
parents: 697
diff changeset
761 {
759
0c18e4b8e840 [svn] - when shifting the ringbuffer to left by one byte to regain alignment,
nenolod
parents: 740
diff changeset
762 buffervalid--;
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
763 memmove(streambuffer, &streambuffer[1], buffervalid);
688
43c77973e494 [svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents: 686
diff changeset
764 if(buffervalid < BUFFER_SIZE) {
43c77973e494 [svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents: 686
diff changeset
765 buffervalid +=
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
766 aud_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
767 }
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
768 bufferconsumed = aac_probe(streambuffer, buffervalid);
686
0d098b87207a [svn] - remove some pointless bloat
nenolod
parents: 684
diff changeset
769 if(bufferconsumed) {
700
27a557e80e15 [svn] - fix a ringbuffering error. found by purify.
nenolod
parents: 697
diff changeset
770 buffervalid -= bufferconsumed;
740
6ae04ca57bc1 [svn] - some ringbuffering issues could cause crashing. a final review has
nenolod
parents: 739
diff changeset
771 memmove(streambuffer, &streambuffer[bufferconsumed], buffervalid);
686
0d098b87207a [svn] - remove some pointless bloat
nenolod
parents: 684
diff changeset
772 bufferconsumed = 0;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
773 }
686
0d098b87207a [svn] - remove some pointless bloat
nenolod
parents: 684
diff changeset
774 continue;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
775 }
688
43c77973e494 [svn] - some ringbuffering fixes -- aac+ shouldn't crash now, but more
nenolod
parents: 686
diff changeset
776
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
777 if((samplesdecoded <= 0) && !sample_buffer){
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
778 #ifdef DEBUG
684
c9eaa64b92b3 [svn] - aacplus shoutcast support. prepare for segfaults.
nenolod
parents: 682
diff changeset
779 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
780 #endif
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
781 continue;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
782 }
693
a7ba9d27c7b5 [svn] - shoutcast title streaming. sucks, could probably be improved upon, but
nenolod
parents: 692
diff changeset
783
1998
8f3188746b64 chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents: 1984
diff changeset
784 playback->pass_audio(playback,
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
785 FMT_S16_LE, channels,
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
786 samplesdecoded<<1, sample_buffer, &buffer_playing);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
787 }
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
788 playback->output->buffer_free();
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
789 playback->output->close_audio();
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
790 buffer_playing = FALSE;
1167
f22b4eb572fb [svn] - add playback->playing = 0 where buffer_playing = FALSE is done. without this, playback_get_time() would be confused and playback wouldn't advance in playlist.
yaz
parents: 1163
diff changeset
791 playback->playing = 0;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
792 faacDecClose(decoder);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
793 g_free(xmmstitle);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
794 aud_vfs_fclose(file);
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
795 seekPosition = -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
796
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
797 buffer_playing = FALSE;
1167
f22b4eb572fb [svn] - add playback->playing = 0 where buffer_playing = FALSE is done. without this, playback_get_time() would be confused and playback wouldn't advance in playlist.
yaz
parents: 1163
diff changeset
798 playback->playing = 0;
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
799 g_static_mutex_unlock(&mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
800 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
801
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
802 static void *mp4_decode( void *args )
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
803 {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
804 mp4ff_callback_t *mp4cb = g_malloc0(sizeof(mp4ff_callback_t));
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
805 VFSFile *mp4fh;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
806 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
807 gboolean ret;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
808
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
809 InputPlayback *playback = args;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
810 char *filename = playback->filename;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
811
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
812 mp4fh = aud_vfs_buffered_file_new_from_uri(filename);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
813
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
814 g_static_mutex_lock(&mutex);
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
815 seekPosition= -1;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
816 buffer_playing= TRUE;
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
817 g_static_mutex_unlock(&mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
818
692
a77e766e332d [svn] - fix another potential synchronization problem
nenolod
parents: 690
diff changeset
819 if (mp4fh == NULL)
1345
76f826e6052d aac: Convert to new threading model.
William Pitcock <nenolod@atheme-project.org>
parents: 1325
diff changeset
820 return NULL;
692
a77e766e332d [svn] - fix another potential synchronization problem
nenolod
parents: 690
diff changeset
821
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
822 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
823
1230
f45a99c8bc0d Updates to the AAC reduced open patch by Christian "Joker" Birchinger.
Tony Vroon <chainsaw@gentoo.org>
parents: 1229
diff changeset
824 if( ret == TRUE )
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
825 aud_vfs_fseek(mp4fh, 0, SEEK_SET);
1230
f45a99c8bc0d Updates to the AAC reduced open patch by Christian "Joker" Birchinger.
Tony Vroon <chainsaw@gentoo.org>
parents: 1229
diff changeset
826 else {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
827 aud_vfs_fclose(mp4fh);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
828 mp4fh = aud_vfs_fopen(filename, "rb");
1230
f45a99c8bc0d Updates to the AAC reduced open patch by Christian "Joker" Birchinger.
Tony Vroon <chainsaw@gentoo.org>
parents: 1229
diff changeset
829 }
1229
c9ff58a0feab An experimental attempt to reduce the number of stream opens for AAC, by Christian @Joker" Birchinger. Tell him if it breaks.
Tony Vroon <chainsaw@gentoo.org>
parents: 1188
diff changeset
830
739
9480fdc511f1 [svn] - do not pass a buffered FD to the decoding thread, just use it for
nenolod
parents: 737
diff changeset
831 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
832 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
833 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
834
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
835 mp4file= mp4ff_open_read(mp4cb);
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1230
diff changeset
836
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
837 if( ret == TRUE ) {
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
838 g_free(mp4cb);
692
a77e766e332d [svn] - fix another potential synchronization problem
nenolod
parents: 690
diff changeset
839 my_decode_aac( playback, filename, mp4fh );
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
840 }
678
9e4145566248 [svn] - allow static AAC files to play. working on AACplus, but this brings us closer.
nenolod
parents: 595
diff changeset
841 else
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
842 my_decode_mp4( playback, filename, mp4file );
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
843
583
dad887da4642 [svn] - Fixed crash at opening AAC files
mf0102
parents: 561
diff changeset
844 return NULL;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
845 }