aboutsummaryrefslogtreecommitdiffstats
path: root/src/tag.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-03-21 16:34:06 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-03-21 16:34:06 +0000
commit1bb75913c37b7494871964fd214eacdd6cb78ccb (patch)
treedd7bbc3b1fe2d10a9d57b835a5476f6857ce4486 /src/tag.c
parent9ab67e75817fd38d6dac42783ddae318dd0b7daa (diff)
downloadmpd-1bb75913c37b7494871964fd214eacdd6cb78ccb.tar.gz
mpd-1bb75913c37b7494871964fd214eacdd6cb78ccb.tar.xz
mpd-1bb75913c37b7494871964fd214eacdd6cb78ccb.zip
begin parsing work on AAC info parsing
git-svn-id: https://svn.musicpd.org/mpd/trunk@345 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/tag.c')
-rw-r--r--src/tag.c106
1 files changed, 105 insertions, 1 deletions
diff --git a/src/tag.c b/src/tag.c
index c5b012b79..73821c74e 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -173,7 +173,111 @@ MpdTag * mp3TagDup(char * utf8file) {
#endif
#ifdef HAVE_FAAD
-/* copied from FAAD2 frontend */
+typedef struct {
+ long bytesIntoBuffer;
+ long bytesConsumed;
+ long fileOffset;
+ unsigned char *buffer;
+ int atEof;
+ FILE *infile;
+} AacBuffer;
+
+void fillAacBuffer(AacBuffer *b) {
+ if(b->bytesConsumed > 0) {
+ int bread;
+
+ if(b->bytesIntoBuffer) {
+ memmove((void *)b->buffer,(void*)(b->buffer+
+ b->bytesConsumed),b->bytesIntoBuffer);
+ }
+
+ if(!b->atEof) {
+ bread = fread((void *)(b->buffer+b->bytesIntoBuffer),1,
+ b->bytesConsumed,b->infile);
+ if(bread!=b->bytesConsumed) b->atEof = 1;
+ b->bytesIntoBuffer+=bread;
+ }
+
+ b->bytesConsumed = 0;
+
+ if(b->bytesIntoBuffer > 3) {
+ if(memcmp(b->buffer,"TAG",3)==0) b->bytesIntoBuffer = 0;
+ }
+ if(b->bytesIntoBuffer > 11) {
+ if(memcmp(b->buffer,"LYRICSBEGIN",11)==0) {
+ b->bytesIntoBuffer = 0;
+ }
+ }
+ if(b->bytesIntoBuffer > 8) {
+ if(memcmp(b->buffer,"APETAGEX",8)==0) {
+ b->bytesIntoBuffer = 0;
+ }
+ }
+ }
+}
+
+void advanceAacBuffer(AacBuffer * b, int bytes) {
+ b->fileOffset+=bytes;
+ b->bytesConsumed = bytes;
+ b->bytesIntoBuffer-=bytes;
+}
+
+static int adtsSampleRates[] = {96000,88200,64000,48000,44100,32000,24000,22050,
+ 16000,12000,11025,8000,7350,0,0,0};
+
+int adtsParse(AacBuffer * b, float * length) {
+ int frames, frameLength;
+ int tFrameLength = 0;
+ int sampleRate = 0;
+ float framesPerSec, bytesPerFrame;
+
+ /* Read all frames to ensure correct time and bitrate */
+ for(frames = 0; ;frames++) {
+ fillAacBuffer(b);
+
+ if(b->bytesIntoBuffer > 7) {
+ /* check syncword */
+ if (!((b->buffer[0] == 0xFF) &&
+ ((b->buffer[1] & 0xF6) == 0xF0)))
+ {
+ break;
+ }
+
+ if(frames==0) {
+ sampleRate = adtsSampleRates[
+ (b->buffer[2]&0x3c)>>2];
+ }
+
+ frameLength = ((((unsigned int)b->buffer[3] & 0x3))
+ << 11) | (((unsigned int)b->buffer[4])
+ << 3) | (b->buffer[5] >> 5);
+
+ tFrameLength+=frameLength;
+
+ if(frameLength > b->bytesIntoBuffer) break;
+
+ advanceAacBuffer(b,frameLength);
+ }
+ else break;
+ }
+
+ framesPerSec = (float)sampleRate/1024.0;
+ if(frames!=0) {
+ bytesPerFrame = (float)tFrameLength/(float)(frames*1000);
+ }
+ else bytesPerFrame = 0;
+ if(framesPerSec!=0) *length = (float)frames/framesPerSec;
+ else *length = 1;
+
+ return 1;
+}
+
+MpdTag * aacTagDup(char * utf8file) {
+ MpdTag * ret = NULL;
+
+ return ret;
+}
+
MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
MpdTag * ret = NULL;
FILE * fh;