annotate Plugins/Input/aac/src/libmp4.c @ 842:3b2b0d68960c trunk

[svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
author chainsaw
date Sat, 18 Mar 2006 08:56:03 -0800
parents d2db0feae0ca
children cfa2d55986fd
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>
842
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
27 #include <libaudacious/vfs.h>
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28
199
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
29 #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
30 #define LIBMP4V2_VERSION "1.2.0"
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 #define MP4_ABOUT "Written by ciberfred"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 #define BUFFER_SIZE FAAD_MIN_STREAMSIZE*64
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33
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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
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
842
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
80 #define AAC_MAGIC (unsigned char [4]) { 0xFF, 0xF9, 0x5C, 0x80 }
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
81
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 static void mp4_init(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 static void mp4_about(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 static void mp4_play(char *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 static void mp4_stop(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 static void mp4_pause(short);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 static void mp4_seek(int);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 static int mp4_getTime(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 static void mp4_cleanup(void);
842
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
90 static int mp4_IsOurFile(char *);
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
91 static void mp4_getSongTitle(char *filename, char **, int *);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 static void* mp4Decode(void *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93
346
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
94 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
95
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 InputPlugin mp4_ip =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 0, // handle
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 0, // filename
344
a98a7f2dfc84 [svn] Display the MP4/AAC+ bitrate, instead of "VBR".
nenolod
parents: 342
diff changeset
100 "MP4 Audio Plugin",
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 mp4_init,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 mp4_about,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 0, // configuration
842
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
104 mp4_IsOurFile,
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 0, //scandir
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 mp4_play,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 mp4_stop,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 mp4_pause,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 mp4_seek,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 0, // set equalizer
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 mp4_getTime,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 0, // get volume
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 0,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 mp4_cleanup,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 0, // obsolete
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 0, // send visualisation data
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 0, // set player window info
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 0, // set song title text
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
119 mp4_getSongTitle, // get song title text
342
320f0205ad45 [svn] Initial fileinfo box, loosely based around the mpg123-clone one.
nenolod
parents: 340
diff changeset
120 audmp4_file_info_box, // info box
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121 0, // to output plugin
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 typedef struct _mp4cfg{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 gshort file_type;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 #define FILE_UNKNOW 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 #define FILE_MP4 1
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 #define FILE_AAC 2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 } Mp4Config;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 static Mp4Config mp4cfg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 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
133 static GThread *decodeThread;
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
134 GStaticMutex mutex = G_STATIC_MUTEX_INIT;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 static int seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136
199
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
137 void getMP4info(char*);
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
138 int getAACTrack(MP4FileHandle);
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
139
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
140 /*
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
141 * Function extname (filename)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
142 *
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
143 * Return pointer within filename to its extenstion, or NULL if
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
144 * filename has no extension.
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
145 *
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
146 */
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
147 static gchar *
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
148 extname(const char *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 gchar *ext = strrchr(filename, '.');
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
151
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
152 if (ext != NULL)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
153 ++ext;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
154
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
155 return ext;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
156 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 InputPlugin *get_iplugin_info(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 return(&mp4_ip);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 static void mp4_init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 mp4cfg.file_type = FILE_UNKNOW;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 static void mp4_play(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 bPlaying = TRUE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
173 decodeThread = g_thread_create((GThreadFunc)mp4Decode, g_strdup(filename), TRUE, NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 static void mp4_stop(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 if(bPlaying){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
181 g_thread_join(decodeThread);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185
842
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
186 static int mp4_IsOurFile(char *filename)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 {
842
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
188 VFSFile *file;
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
189 gchar* extension;
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
190 gchar magic[4];
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191
842
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
192 extension = strrchr(filename, '.');
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
193 if ((file = vfs_fopen(filename, "rb"))) {
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
194 vfs_fread(magic, 1, 4, file);
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
195 if (!memcmp(magic, AAC_MAGIC, 4)) {
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
196 vfs_fclose(file);
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
197 return 1;
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
198 }
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
199 if (!strncmp(magic, "ID3", 3)) { // ID3 tag bolted to the front, obfuscated magic bytes
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
200 vfs_fclose(file);
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
201 if (extension &&(
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
202 !strcasecmp(extension, ".mp4") || // official extension
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
203 !strcasecmp(extension, ".m4a") || // Apple mp4 extension
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
204 !strcasecmp(extension, ".aac") // old MPEG2/4-AAC extension
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
205 ))
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
206 return 1;
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
207 else
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
208 return 0;
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
209 }
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
210 vfs_fread(magic, 1, 4, file);
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
211 if (!strncasecmp(magic, "ftyp", 6)) {
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
212 vfs_fclose(file);
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
213 return 1;
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
214 }
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
215 vfs_fclose(file);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 }
842
3b2b0d68960c [svn] Use magic bytes to identify AAC and MP4 as the decoder insists on reading the entire file before making a decision. This can be upsetting to users of large playlists, so reduce that to two 4-byte reads. Extension checking still needed for files that have been butchered by bad taggers, sorry.
chainsaw
parents: 832
diff changeset
217 return 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 static void mp4_about(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 static GtkWidget *aboutbox;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 if(aboutbox!=NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 aboutbox = xmms_show_message("About MP4 AAC player plugin",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 "libfaad2-" FAAD2_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 "libmp4v2-" LIBMP4V2_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 "plugin version: " MP4_VERSION "\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 MP4_ABOUT,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 "Ok", FALSE, NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 gtk_signal_connect(GTK_OBJECT(aboutbox), "destroy",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 GTK_SIGNAL_FUNC(gtk_widget_destroyed),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 &aboutbox);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 static void mp4_pause(short flag)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 mp4_ip.output->pause(flag);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 static void mp4_seek(int time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 seekPosition = time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 while(bPlaying && seekPosition!=-1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 static int mp4_getTime(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 if(!bPlaying)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 return (-1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 return (mp4_ip.output->output_time());
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 static void mp4_cleanup(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260
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
261 #if 0
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 static void mp4_getSongInfo(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 if(mp4cfg.file_type == FILE_MP4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 getMP4info(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 else if(mp4cfg.file_type == FILE_AAC)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 ;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 }
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
269 #endif
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
271 static gchar *mp4_get_song_title(char *filename)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
272 {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
273 MP4FileHandle mp4file;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
274 gchar *title = NULL;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
275
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
276 if (!(mp4file = MP4Read(filename, 0))) {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
277 MP4Close(mp4file);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
278 } else {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
279 TitleInput *input;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
280 gchar *tmpval;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
281
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
282 input = bmp_title_input_new();
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
283
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
284 MP4GetMetadataName(mp4file, &input->track_name);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
285 MP4GetMetadataAlbum(mp4file, &input->album_name);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
286 MP4GetMetadataArtist(mp4file, &input->performer);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
287 MP4GetMetadataYear(mp4file, &tmpval);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
288 MP4GetMetadataGenre(mp4file, &input->genre);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
289
340
c7a67ac8e19c [svn] safety fix
nenolod
parents: 339
diff changeset
290 if (tmpval)
793
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
291 {
340
c7a67ac8e19c [svn] safety fix
nenolod
parents: 339
diff changeset
292 input->year = atoi(tmpval);
793
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
293 free(tmpval);
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
294 }
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
295
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
296 input->file_name = g_path_get_basename(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
297 input->file_path = g_path_get_dirname(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
298 input->file_ext = extname(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
299
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
300 title = xmms_get_titlestring(xmms_get_gentitle_format(), input);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
301
793
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
302 free (input->track_name);
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
303 free (input->album_name);
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
304 free (input->performer);
3c4bcd9b8719 [svn] - leak fix
nenolod
parents: 407
diff changeset
305 free (input->genre);
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
306 free (input->file_name);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
307 free (input->file_path);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
308 free (input);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
309 }
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
310
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
311 if (!title)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
312 {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
313 title = g_path_get_basename(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
314 if (extname(title))
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
315 *(extname(title) - 1) = '\0';
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
316 }
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
317
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
318 return title;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
319 }
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
320
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
321 static void mp4_getSongTitle(char *filename, char **title_real, int *len_real)
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
322 {
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
323 (*title_real) = mp4_get_song_title(filename);
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
324 (*len_real) = -1;
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
325 }
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
326
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 static void *mp4Decode(void *args)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 MP4FileHandle mp4file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
331 g_static_mutex_lock(&mutex);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 bPlaying = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 if(!(mp4file = MP4Read(args, 0))){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 mp4cfg.file_type = FILE_AAC;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 mp4cfg.file_type = FILE_MP4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 if(mp4cfg.file_type == FILE_MP4){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 // We are reading a MP4 file
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 gint mp4track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 if((mp4track = getAACTrack(mp4file)) < 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 //TODO: check here for others Audio format.....
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 g_print("Unsupported Audio track type\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
351 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
352 g_thread_exit(NULL);
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
353 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 faacDecHandle decoder;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 unsigned char *buffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357 guint bufferSize = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 gulong samplerate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 guchar channels;
344
a98a7f2dfc84 [svn] Display the MP4/AAC+ bitrate, instead of "VBR".
nenolod
parents: 342
diff changeset
360 guint avgBitrate;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 MP4Duration duration;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 gulong msDuration;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 MP4SampleId numSamples;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 MP4SampleId sampleID = 1;
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
365 gchar *title;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 decoder = faacDecOpen();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368 MP4GetTrackESConfiguration(mp4file, mp4track, &buffer, &bufferSize);
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
369 if(!buffer)
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
370 goto out;
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
371 if(faacDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0)
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
372 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 if(channels == 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 g_print("Number of Channels not supported\n");
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
376 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 duration = MP4GetTrackDuration(mp4file, mp4track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 msDuration = MP4ConvertFromTrackDuration(mp4file, mp4track, duration,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380 MP4_MSECS_TIME_SCALE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 numSamples = MP4GetTrackNumberOfSamples(mp4file, mp4track);
345
9b19994a715c [svn] ditto for samplerate... we should have full plugin compatibility now
nenolod
parents: 344
diff changeset
382 samplerate = MP4GetTrackTimeScale(mp4file, mp4track);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 mp4_ip.output->open_audio(FMT_S16_NE, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384 mp4_ip.output->flush(0);
339
e1630c75175b [svn] MP4 metadata retrieval support.
nenolod
parents: 320
diff changeset
385 title = mp4_get_song_title(args);
344
a98a7f2dfc84 [svn] Display the MP4/AAC+ bitrate, instead of "VBR".
nenolod
parents: 342
diff changeset
386 avgBitrate = MP4GetTrackBitRate(mp4file, mp4track);
345
9b19994a715c [svn] ditto for samplerate... we should have full plugin compatibility now
nenolod
parents: 344
diff changeset
387 mp4_ip.set_info(title, msDuration, avgBitrate, samplerate, channels);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 while(bPlaying){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 void* sampleBuffer;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 faacDecFrameInfo frameInfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 gint rc;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 if(seekPosition!=-1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 duration = MP4ConvertToTrackDuration(mp4file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 mp4track,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 seekPosition*1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 MP4_MSECS_TIME_SCALE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 sampleID = MP4GetSampleIdFromTime(mp4file, mp4track, duration, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 mp4_ip.output->flush(seekPosition*1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 buffer=NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 bufferSize=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 if(sampleID > numSamples){
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
406 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 rc = MP4ReadSample(mp4file, mp4track, sampleID++, &buffer, &bufferSize,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409 NULL, NULL, NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 if((rc==0) || (buffer== NULL)){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 g_print("MP4: read error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 sampleBuffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 sampleID=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414 mp4_ip.output->buffer_free();
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 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 sampleBuffer = faacDecDecode(decoder, &frameInfo, buffer, bufferSize);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 if(frameInfo.error > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
419 g_print("MP4: %s\n",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420 faacDecGetErrorMessage(frameInfo.error));
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
421 goto out;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
423 if(buffer){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 g_free(buffer); buffer=NULL; bufferSize=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
425 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 while(bPlaying && mp4_ip.output->buffer_free()<frameInfo.samples<<1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427 xmms_usleep(30000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 }
346
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
429 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
430 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
431 channels,
430658951e30 [svn] Use produce_audio() to pass the audio through the new audacious filterchain stuff. (EQ support!!!)
nenolod
parents: 345
diff changeset
432 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
433 sampleBuffer, &bPlaying);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 while(bPlaying && mp4_ip.output->buffer_free()){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 }
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
438 out:
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440 g_free(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 MP4Close(mp4file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
444 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
445 g_thread_exit(NULL);
250
b9e6cdce7219 [svn] Reduce code duplication and add a return statement.
chainsaw
parents: 200
diff changeset
446 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 } else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449 // WE ARE READING AN AAC FILE
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450 FILE *file = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 faacDecHandle decoder = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 guchar *buffer = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 gulong bufferconsumed = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 gulong samplerate = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 guchar channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 gulong buffervalid = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 TitleInput* input;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
458 gchar *temp = g_strdup(args);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 gchar *ext = strrchr(temp, '.');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 gchar *xmmstitle = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461 faacDecConfigurationPtr config;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463 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
464 g_print("AAC: can't find file %s\n", (char*)args);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
466 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
467 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 if((decoder = faacDecOpen()) == NULL){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 g_print("AAC: Open Decoder Error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
473 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
474 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477 config->useOldADTSFormat = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478 faacDecSetConfiguration(decoder, config);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479 if((buffer = g_malloc(BUFFER_SIZE)) == NULL){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 g_print("AAC: error g_malloc\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483 faacDecClose(decoder);
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
484 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
485 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
487 if((buffervalid = fread(buffer, 1, BUFFER_SIZE, file))==0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
488 g_print("AAC: Error reading file\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
491 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 faacDecClose(decoder);
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
493 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
494 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496 XMMS_NEW_TITLEINPUT(input);
199
0a2ad94e8607 [svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents: 61
diff changeset
497 input->file_name = (char*)g_basename(temp);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498 input->file_ext = ext ? ext+1 : NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 input->file_path = temp;
407
33823c38e10d [svn] Use glib function for glib types and care about pointer signedness.
chainsaw
parents: 387
diff changeset
500 if(!g_ascii_strncasecmp((gchar*)buffer, "ID3", 3)){
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
501 gint size = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
502
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
503 fseek(file, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
504 size = (buffer[6]<<21) | (buffer[7]<<14) | (buffer[8]<<7) | buffer[9];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
505 size+=10;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 fread(buffer, 1, size, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507 buffervalid = fread(buffer, 1, BUFFER_SIZE, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
509 xmmstitle = xmms_get_titlestring(xmms_get_gentitle_format(), input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
510 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
511 xmmstitle = g_path_get_basename(input->file_name);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
512 if(temp) g_free(temp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
513 if(input->performer) g_free(input->performer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
514 if(input->album_name) g_free(input->album_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
515 if(input->track_name) g_free(input->track_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
516 if(input->genre) g_free(input->genre);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
517 g_free(input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
518 bufferconsumed = faacDecInit(decoder,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
519 buffer,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
520 buffervalid,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
521 &samplerate,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
522 &channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
523 if(mp4_ip.output->open_audio(FMT_S16_NE,samplerate,channels) == FALSE){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
524 g_print("AAC: Output Error\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
525 g_free(buffer); buffer=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
526 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
527 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
528 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
529 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
530 if(positionTable){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
531 g_free(positionTable); positionTable=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
532 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
533 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
534 g_free(xmmstitle);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
535 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
536 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
537 g_thread_exit(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
538 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
539 //if(bSeek){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
540 //mp4_ip.set_info(xmmstitle, lenght*1000, -1, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
541 //}else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
542 mp4_ip.set_info(xmmstitle, -1, -1, samplerate, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
543 //}
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
544 mp4_ip.output->flush(0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
545
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
546 while(bPlaying && buffervalid > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
547 faacDecFrameInfo finfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
548 unsigned long samplesdecoded;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
549 char* sample_buffer = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
550 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
551 if(bSeek && seekPosition!=-1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
552 fseek(file, positionTable[seekPosition], SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
553 bufferconsumed=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
554 buffervalid = fread(buffer, 1, BUFFER_SIZE, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
555 aac_ip.output->flush(seekPosition*1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
556 seekPosition=-1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
557 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
558 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
559 if(bufferconsumed > 0){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
560 memmove(buffer, &buffer[bufferconsumed], buffervalid-bufferconsumed);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
561 buffervalid -= bufferconsumed;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
562 buffervalid += fread(&buffer[buffervalid], 1,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
563 BUFFER_SIZE-buffervalid, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
564 bufferconsumed = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
565 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
566 sample_buffer = faacDecDecode(decoder, &finfo, buffer, buffervalid);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
567 if(finfo.error){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
568 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
569 if(config->useOldADTSFormat != 1){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
570 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
571 decoder = faacDecOpen();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
572 config = faacDecGetCurrentConfiguration(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
573 config->useOldADTSFormat = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
574 faacDecSetConfiguration(decoder, config);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
575 finfo.bytesconsumed=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
576 finfo.samples = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
577 faacDecInit(decoder,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
578 buffer,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
579 buffervalid,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
580 &samplerate,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
581 &channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
582 }else{
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
583 g_print("FAAD2 Warning %s\n", faacDecGetErrorMessage(finfo.error));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
584 buffervalid = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
585 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
586 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
587 bufferconsumed += finfo.bytesconsumed;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
588 samplesdecoded = finfo.samples;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
589 if((samplesdecoded<=0) && !sample_buffer){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
590 g_print("AAC: error sample decoding\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
591 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
592 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
593 while(bPlaying && mp4_ip.output->buffer_free() < (samplesdecoded<<1)){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
594 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
595 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
596 mp4_ip.add_vis_pcm(mp4_ip.output->written_time(),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
597 FMT_S16_LE, channels,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
598 samplesdecoded<<1, sample_buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
599 mp4_ip.output->write_audio(sample_buffer, samplesdecoded<<1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
600 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
601 while(bPlaying && mp4_ip.output->buffer_playing()){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
602 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
603 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
604 mp4_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
605 mp4_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
606 bPlaying = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
607 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
608 faacDecClose(decoder);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
609 g_free(xmmstitle);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
610 fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
611 seekPosition = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
612 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
613 if(positionTable){
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
614 g_free(positionTable); positionTable=0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
615 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
616 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
617 bPlaying = FALSE;
200
094ef8a0a9fd [svn] GThreadify plugin. Adds a return statement and removes a pragma statement to please GCC.
chainsaw
parents: 199
diff changeset
618 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
619 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
620 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
621 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
622 }