annotate Plugins/Input/aac/src/libmp4.c @ 832:d2db0feae0ca trunk

[svn] Fix logic error that caused us to lock on to wav.
author chainsaw
date Mon, 13 Mar 2006 14:18:03 -0800
parents f51680f2dab0
children 3b2b0d68960c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 * MP4/AAC decoder for xmms
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * This decoding source code is completly independent of the faad2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 * package.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 * This package exist for people who don't want to install
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * faad2 and mpeg4ip project files.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 * OPTIONNAL need
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 * --------------
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 * libid3 (3.8.x - www.id3.org)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
14 #include <glib.h>
387
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
15 #include <glib/gi18n.h>
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 #include <gtk/gtk.h>
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
17 #include <string.h>
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
18 #include <stdlib.h>
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 #include "faad.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 #include "mp4.h"
387
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
21 #include "tagging.h"
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 #include <audacious/plugin.h>
346
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
24 #include <audacious/output.h>
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 #include <libaudacious/util.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 #include <libaudacious/titlestring.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27
199
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
28 #define MP4_VERSION "ver.- 15 December 2004"
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
29 #define LIBMP4V2_VERSION "1.2.0"
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 #define MP4_ABOUT "Written by ciberfred"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 #define BUFFER_SIZE FAAD_MIN_STREAMSIZE*64
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32
387
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
33 const char *audmp4_id3_genres[GENRE_MAX] = {
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
34 N_("Blues"), N_("Classic Rock"), N_("Country"), N_("Dance"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
35 N_("Disco"), N_("Funk"), N_("Grunge"), N_("Hip-Hop"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
36 N_("Jazz"), N_("Metal"), N_("New Age"), N_("Oldies"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
37 N_("Other"), N_("Pop"), N_("R&B"), N_("Rap"), N_("Reggae"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
38 N_("Rock"), N_("Techno"), N_("Industrial"), N_("Alternative"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
39 N_("Ska"), N_("Death Metal"), N_("Pranks"), N_("Soundtrack"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
40 N_("Euro-Techno"), N_("Ambient"), N_("Trip-Hop"), N_("Vocal"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
41 N_("Jazz+Funk"), N_("Fusion"), N_("Trance"), N_("Classical"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
42 N_("Instrumental"), N_("Acid"), N_("House"), N_("Game"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
43 N_("Sound Clip"), N_("Gospel"), N_("Noise"), N_("AlternRock"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
44 N_("Bass"), N_("Soul"), N_("Punk"), N_("Space"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
45 N_("Meditative"), N_("Instrumental Pop"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
46 N_("Instrumental Rock"), N_("Ethnic"), N_("Gothic"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
47 N_("Darkwave"), N_("Techno-Industrial"), N_("Electronic"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
48 N_("Pop-Folk"), N_("Eurodance"), N_("Dream"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
49 N_("Southern Rock"), N_("Comedy"), N_("Cult"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
50 N_("Gangsta Rap"), N_("Top 40"), N_("Christian Rap"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
51 N_("Pop/Funk"), N_("Jungle"), N_("Native American"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
52 N_("Cabaret"), N_("New Wave"), N_("Psychedelic"), N_("Rave"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
53 N_("Showtunes"), N_("Trailer"), N_("Lo-Fi"), N_("Tribal"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
54 N_("Acid Punk"), N_("Acid Jazz"), N_("Polka"), N_("Retro"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
55 N_("Musical"), N_("Rock & Roll"), N_("Hard Rock"), N_("Folk"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
56 N_("Folk/Rock"), N_("National Folk"), N_("Swing"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
57 N_("Fast-Fusion"), N_("Bebob"), N_("Latin"), N_("Revival"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
58 N_("Celtic"), N_("Bluegrass"), N_("Avantgarde"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
59 N_("Gothic Rock"), N_("Progressive Rock"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
60 N_("Psychedelic Rock"), N_("Symphonic Rock"), N_("Slow Rock"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
61 N_("Big Band"), N_("Chorus"), N_("Easy Listening"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
62 N_("Acoustic"), N_("Humour"), N_("Speech"), N_("Chanson"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
63 N_("Opera"), N_("Chamber Music"), N_("Sonata"), N_("Symphony"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
64 N_("Booty Bass"), N_("Primus"), N_("Porn Groove"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
65 N_("Satire"), N_("Slow Jam"), N_("Club"), N_("Tango"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
66 N_("Samba"), N_("Folklore"), N_("Ballad"), N_("Power Ballad"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
67 N_("Rhythmic Soul"), N_("Freestyle"), N_("Duet"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
68 N_("Punk Rock"), N_("Drum Solo"), N_("A Cappella"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
69 N_("Euro-House"), N_("Dance Hall"), N_("Goa"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
70 N_("Drum & Bass"), N_("Club-House"), N_("Hardcore"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
71 N_("Terror"), N_("Indie"), N_("BritPop"), N_("Negerpunk"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
72 N_("Polsk Punk"), N_("Beat"), N_("Christian Gangsta Rap"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
73 N_("Heavy Metal"), N_("Black Metal"), N_("Crossover"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
74 N_("Contemporary Christian"), N_("Christian Rock"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
75 N_("Merengue"), N_("Salsa"), N_("Thrash Metal"),
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
76 N_("Anime"), N_("JPop"), N_("Synthpop")
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
77 };
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
78
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
79
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 static void mp4_init(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 static void mp4_about(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 static void mp4_play(char *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 static void mp4_stop(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 static void mp4_pause(short);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 static void mp4_seek(int);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 static int mp4_getTime(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 static void mp4_cleanup(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 static int mp4_isFile(char *);
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
89 static void mp4_getSongTitle(char *filename, char **, int *);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 static void* mp4Decode(void *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91
346
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
92 void audmp4_file_info_box(gchar *);
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
93
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 InputPlugin mp4_ip =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 0, // handle
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 0, // filename
344
a98a7f2dfc84 [svn] Display the MP4/AAC+ bitrate, instead of "VBR".
nenolod
parents: 342
diff changeset
98 "MP4 Audio Plugin",
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 mp4_init,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 mp4_about,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 0, // configuration
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 mp4_isFile,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 0, //scandir
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104 mp4_play,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 mp4_stop,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 mp4_pause,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 mp4_seek,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 0, // set equalizer
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 mp4_getTime,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 0, // get volume
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 0,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 mp4_cleanup,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 0, // obsolete
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 0, // send visualisation data
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 0, // set player window info
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 0, // set song title text
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
117 mp4_getSongTitle, // get song title text
342
320f0205ad45 [svn] Initial fileinfo box, loosely based around the mpg123-clone one.
nenolod
parents: 340
diff changeset
118 audmp4_file_info_box, // info box
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 0, // to output plugin
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 typedef struct _mp4cfg{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123 gshort file_type;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 #define FILE_UNKNOW 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 #define FILE_MP4 1
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 #define FILE_AAC 2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 } Mp4Config;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 static Mp4Config mp4cfg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 static gboolean bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
131 static GThread *decodeThread;
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
132 GStaticMutex mutex = G_STATIC_MUTEX_INIT;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 static int seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134
199
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
135 void getMP4info(char*);
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
136 int getAACTrack(MP4FileHandle);
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
137
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
138 /*
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
139 * Function extname (filename)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
140 *
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
141 * Return pointer within filename to its extenstion, or NULL if
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
142 * filename has no extension.
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
143 *
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
144 */
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
145 static gchar *
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
146 extname(const char *filename)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
147 {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
148 gchar *ext = strrchr(filename, '.');
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
149
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
150 if (ext != NULL)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
151 ++ext;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
152
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
153 return ext;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
154 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 InputPlugin *get_iplugin_info(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 return(&mp4_ip);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 static void mp4_init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 mp4cfg.file_type = FILE_UNKNOW;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 static void mp4_play(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 bPlaying = TRUE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
171 decodeThread = g_thread_create((GThreadFunc)mp4Decode, g_strdup(filename), TRUE, NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 static void mp4_stop(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 if(bPlaying){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
179 g_thread_join(decodeThread);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 static int mp4_isFile(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 {
831
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
186 MP4FileHandle mp4file2;
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
187 gint mp4track;
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
188
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
189 if(!filename)
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
190 return 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191
831
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
192 if((mp4file2 = MP4Read(filename, 0))){
832
d2db0feae0ca [svn] Fix logic error that caused us to lock on to wav.
chainsaw
parents: 831
diff changeset
193 if((mp4track = getAACTrack(mp4file2)) > 0){
831
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
194 MP4Close(mp4file2); // This is a valid MP4 file, good to go
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
195 return 1;
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
196 } else {
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
197 MP4Close(mp4file2); // Corrupted MP4 file, will not try to play
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
198 return 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 }
831
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
200 } else { // Not MP4, could be AAC, check extension
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
201 gchar* extension;
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
202 extension = strrchr(filename, '.');
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
203 if (extension &&(
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
204 !strcasecmp(extension, ".mp4") || // official extension
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
205 !strcasecmp(extension, ".m4a") || // Apple mp4 extension
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
206 !strcasecmp(extension, ".aac") // old MPEG2/4-AAC extension
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
207 ))
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
208 return 1;
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
209 else
f51680f2dab0 [svn] Be smarter about spotting MP4 files, only fall back on extension for AAC.
chainsaw
parents: 793
diff changeset
210 return 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 static void mp4_about(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 static GtkWidget *aboutbox;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 if(aboutbox!=NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 aboutbox = xmms_show_message("About MP4 AAC player plugin",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 "libfaad2-" FAAD2_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 "libmp4v2-" LIBMP4V2_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 "plugin version: " MP4_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 MP4_ABOUT,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 "Ok", FALSE, NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 gtk_signal_connect(GTK_OBJECT(aboutbox), "destroy",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 GTK_SIGNAL_FUNC(gtk_widget_destroyed),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 &aboutbox);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 static void mp4_pause(short flag)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 mp4_ip.output->pause(flag);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 static void mp4_seek(int time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 seekPosition = time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 while(bPlaying && seekPosition!=-1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 static int mp4_getTime(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 if(!bPlaying)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 return (-1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248 return (mp4_ip.output->output_time());
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 static void mp4_cleanup(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254
387
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
255 #if 0
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 static void mp4_getSongInfo(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 if(mp4cfg.file_type == FILE_MP4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 getMP4info(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 else if(mp4cfg.file_type == FILE_AAC)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 ;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 }
387
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 346
diff changeset
263 #endif
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
265 static gchar *mp4_get_song_title(char *filename)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
266 {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
267 MP4FileHandle mp4file;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
268 gchar *title = NULL;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
269
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
270 if (!(mp4file = MP4Read(filename, 0))) {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
271 MP4Close(mp4file);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
272 } else {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
273 TitleInput *input;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
274 gchar *tmpval;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
275
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
276 input = bmp_title_input_new();
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
277
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
278 MP4GetMetadataName(mp4file, &input->track_name);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
279 MP4GetMetadataAlbum(mp4file, &input->album_name);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
280 MP4GetMetadataArtist(mp4file, &input->performer);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
281 MP4GetMetadataYear(mp4file, &tmpval);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
282 MP4GetMetadataGenre(mp4file, &input->genre);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
283
340
c7a67ac8e19c [svn] safety fix
nenolod
parents: 339
diff changeset
284 if (tmpval)
793
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
285 {
340
c7a67ac8e19c [svn] safety fix
nenolod
parents: 339
diff changeset
286 input->year = atoi(tmpval);
793
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
287 free(tmpval);
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
288 }
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
289
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
290 input->file_name = g_path_get_basename(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
291 input->file_path = g_path_get_dirname(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
292 input->file_ext = extname(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
293
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
294 title = xmms_get_titlestring(xmms_get_gentitle_format(), input);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
295
793
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
296 free (input->track_name);
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
297 free (input->album_name);
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
298 free (input->performer);
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
299 free (input->genre);
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
300 free (input->file_name);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
301 free (input->file_path);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
302 free (input);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
303 }
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
304
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
305 if (!title)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
306 {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
307 title = g_path_get_basename(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
308 if (extname(title))
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
309 *(extname(title) - 1) = '\0';
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
310 }
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
311
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
312 return title;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
313 }
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
314
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
315 static void mp4_getSongTitle(char *filename, char **title_real, int *len_real)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
316 {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
317 (*title_real) = mp4_get_song_title(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
318 (*len_real) = -1;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
319 }
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
320
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 static void *mp4Decode(void *args)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 MP4FileHandle mp4file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
325 g_static_mutex_lock(&mutex);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 bPlaying = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 if(!(mp4file = MP4Read(args, 0))){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 mp4cfg.file_type = FILE_AAC;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 mp4cfg.file_type = FILE_MP4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 if(mp4cfg.file_type == FILE_MP4){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 // We are reading a MP4 file
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 gint mp4track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 if((mp4track = getAACTrack(mp4file)) < 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 //TODO: check here for others Audio format.....
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 g_print("Unsupported Audio track type\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
345 g_static_mutex_unlock(&mutex);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
346 g_thread_exit(NULL);
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
347 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 faacDecHandle decoder;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 unsigned char *buffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351 guint bufferSize = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 gulong samplerate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 guchar channels;
344
a98a7f2dfc84 [svn] Display the MP4/AAC+ bitrate, instead of "VBR".
nenolod
parents: 342
diff changeset
354 guint avgBitrate;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 MP4Duration duration;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 gulong msDuration;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357 MP4SampleId numSamples;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 MP4SampleId sampleID = 1;
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
359 gchar *title;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 decoder = faacDecOpen();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 MP4GetTrackESConfiguration(mp4file, mp4track, &buffer, &bufferSize);
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
363 if(!buffer)
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
364 goto out;
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
365 if(faacDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0)
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
366 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368 if(channels == 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369 g_print("Number of Channels not supported\n");
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
370 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372 duration = MP4GetTrackDuration(mp4file, mp4track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373 msDuration = MP4ConvertFromTrackDuration(mp4file, mp4track, duration,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 MP4_MSECS_TIME_SCALE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 numSamples = MP4GetTrackNumberOfSamples(mp4file, mp4track);
345
9b19994a715c [svn] ditto for samplerate... we should have full plugin compatibility now
nenolod
parents: 344
diff changeset
376 samplerate = MP4GetTrackTimeScale(mp4file, mp4track);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 mp4_ip.output->open_audio(FMT_S16_NE, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 mp4_ip.output->flush(0);
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
379 title = mp4_get_song_title(args);
344
a98a7f2dfc84 [svn] Display the MP4/AAC+ bitrate, instead of "VBR".
nenolod
parents: 342
diff changeset
380 avgBitrate = MP4GetTrackBitRate(mp4file, mp4track);
345
9b19994a715c [svn] ditto for samplerate... we should have full plugin compatibility now
nenolod
parents: 344
diff changeset
381 mp4_ip.set_info(title, msDuration, avgBitrate, samplerate, channels);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 while(bPlaying){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384 void* sampleBuffer;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 faacDecFrameInfo frameInfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386 gint rc;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 if(seekPosition!=-1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 duration = MP4ConvertToTrackDuration(mp4file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 mp4track,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 seekPosition*1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 MP4_MSECS_TIME_SCALE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393 sampleID = MP4GetSampleIdFromTime(mp4file, mp4track, duration, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 mp4_ip.output->flush(seekPosition*1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 buffer=NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 bufferSize=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 if(sampleID > numSamples){
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
400 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 rc = MP4ReadSample(mp4file, mp4track, sampleID++, &buffer, &bufferSize,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 NULL, NULL, NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 if((rc==0) || (buffer== NULL)){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 g_print("MP4: read error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 sampleBuffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407 sampleID=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 mp4_ip.output->buffer_free();
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
409 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 sampleBuffer = faacDecDecode(decoder, &frameInfo, buffer, bufferSize);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 if(frameInfo.error > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 g_print("MP4: %s\n",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414 faacDecGetErrorMessage(frameInfo.error));
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
415 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 if(buffer){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 g_free(buffer); buffer=NULL; bufferSize=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
419 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420 while(bPlaying && mp4_ip.output->buffer_free()<frameInfo.samples<<1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
421 xmms_usleep(30000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 }
346
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
423 produce_audio(mp4_ip.output->written_time(),
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
424 FMT_S16_NE,
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
425 channels,
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
426 frameInfo.samples<<1,
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
427 sampleBuffer, &bPlaying);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
429 while(bPlaying && mp4_ip.output->buffer_free()){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 }
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
432 out:
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
438 g_static_mutex_unlock(&mutex);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
439 g_thread_exit(NULL);
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
440 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 } else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 // WE ARE READING AN AAC FILE
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444 FILE *file = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445 faacDecHandle decoder = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 guchar *buffer = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 gulong bufferconsumed = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 gulong samplerate = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449 guchar channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450 gulong buffervalid = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 TitleInput* input;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 gchar *temp = g_strdup(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 gchar *ext = strrchr(temp, '.');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 gchar *xmmstitle = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 faacDecConfigurationPtr config;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 if((file = fopen(args, "rb")) == 0){
199
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
458 g_print("AAC: can't find file %s\n", (char*)args);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
460 g_static_mutex_unlock(&mutex);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
461 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463 if((decoder = faacDecOpen()) == NULL){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464 g_print("AAC: Open Decoder Error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
467 g_static_mutex_unlock(&mutex);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
468 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 config->useOldADTSFormat = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 faacDecSetConfiguration(decoder, config);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473 if((buffer = g_malloc(BUFFER_SIZE)) == NULL){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 g_print("AAC: error g_malloc\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477 faacDecClose(decoder);
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
478 g_static_mutex_unlock(&mutex);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
479 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481 if((buffervalid = fread(buffer, 1, BUFFER_SIZE, file))==0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 g_print("AAC: Error reading file\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
484 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
485 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 faacDecClose(decoder);
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
487 g_static_mutex_unlock(&mutex);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
488 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490 XMMS_NEW_TITLEINPUT(input);
199
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
491 input->file_name = (char*)g_basename(temp);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 input->file_ext = ext ? ext+1 : NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
493 input->file_path = temp;
407
33823c38e10d [svn] Use glib function for glib types and care about pointer signedness.
chainsaw
parents: 387
diff changeset
494 if(!g_ascii_strncasecmp((gchar*)buffer, "ID3", 3)){
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495 gint size = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
497 fseek(file, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498 size = (buffer[6]<<21) | (buffer[7]<<14) | (buffer[8]<<7) | buffer[9];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 size+=10;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
500 fread(buffer, 1, size, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
501 buffervalid = fread(buffer, 1, BUFFER_SIZE, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
502 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
503 xmmstitle = xmms_get_titlestring(xmms_get_gentitle_format(), input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
504 if(xmmstitle == NULL)
320
d8889f819081 [svn] Dereferencing type-punned pointer will break strict-aliasing rules squashed by Mark Loeser <halcy0n@gentoo.org>.
chainsaw
parents: 319
diff changeset
505 xmmstitle = g_path_get_basename(input->file_name);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 if(temp) g_free(temp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507 if(input->performer) g_free(input->performer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508 if(input->album_name) g_free(input->album_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
509 if(input->track_name) g_free(input->track_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
510 if(input->genre) g_free(input->genre);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
511 g_free(input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
512 bufferconsumed = faacDecInit(decoder,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
513 buffer,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
514 buffervalid,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
515 &samplerate,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
516 &channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
517 if(mp4_ip.output->open_audio(FMT_S16_NE,samplerate,channels) == FALSE){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
518 g_print("AAC: Output Error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
519 g_free(buffer); buffer=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
520 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
521 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
522 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
523 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
524 if(positionTable){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
525 g_free(positionTable); positionTable=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
526 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
527 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
528 g_free(xmmstitle);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
529 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
530 g_static_mutex_unlock(&mutex);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
531 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
532 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
533 //if(bSeek){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
534 //mp4_ip.set_info(xmmstitle, lenght*1000, -1, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
535 //}else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
536 mp4_ip.set_info(xmmstitle, -1, -1, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
537 //}
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
538 mp4_ip.output->flush(0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
539
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
540 while(bPlaying && buffervalid > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
541 faacDecFrameInfo finfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
542 unsigned long samplesdecoded;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
543 char* sample_buffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
544 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
545 if(bSeek && seekPosition!=-1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
546 fseek(file, positionTable[seekPosition], SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
547 bufferconsumed=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
548 buffervalid = fread(buffer, 1, BUFFER_SIZE, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
549 aac_ip.output->flush(seekPosition*1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
550 seekPosition=-1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
551 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
552 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
553 if(bufferconsumed > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
554 memmove(buffer, &buffer[bufferconsumed], buffervalid-bufferconsumed);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
555 buffervalid -= bufferconsumed;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
556 buffervalid += fread(&buffer[buffervalid], 1,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
557 BUFFER_SIZE-buffervalid, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
558 bufferconsumed = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
559 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
560 sample_buffer = faacDecDecode(decoder, &finfo, buffer, buffervalid);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
561 if(finfo.error){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
562 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
563 if(config->useOldADTSFormat != 1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
564 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
565 decoder = faacDecOpen();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
566 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
567 config->useOldADTSFormat = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
568 faacDecSetConfiguration(decoder, config);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
569 finfo.bytesconsumed=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
570 finfo.samples = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
571 faacDecInit(decoder,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
572 buffer,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
573 buffervalid,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
574 &samplerate,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
575 &channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
576 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
577 g_print("FAAD2 Warning %s\n", faacDecGetErrorMessage(finfo.error));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
578 buffervalid = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
579 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
580 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
581 bufferconsumed += finfo.bytesconsumed;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
582 samplesdecoded = finfo.samples;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
583 if((samplesdecoded<=0) && !sample_buffer){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
584 g_print("AAC: error sample decoding\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
585 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
586 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
587 while(bPlaying && mp4_ip.output->buffer_free() < (samplesdecoded<<1)){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
588 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
589 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
590 mp4_ip.add_vis_pcm(mp4_ip.output->written_time(),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
591 FMT_S16_LE, channels,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
592 samplesdecoded<<1, sample_buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
593 mp4_ip.output->write_audio(sample_buffer, samplesdecoded<<1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
594 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
595 while(bPlaying && mp4_ip.output->buffer_playing()){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
596 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
597 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
598 mp4_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
599 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
600 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
601 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
602 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
603 g_free(xmmstitle);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
604 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
605 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
606 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
607 if(positionTable){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
608 g_free(positionTable); positionTable=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
609 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
610 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
611 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
612 g_static_mutex_unlock(&mutex);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
613 g_thread_exit(NULL);
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
614 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
615 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
616 }