Mercurial > audlegacy
annotate Plugins/Input/aac/src/aac_utils.c @ 927:afd83c152cfd trunk
[svn] Look, you missed a spot.
author | chainsaw |
---|---|
date | Wed, 12 Apr 2006 15:17:39 -0700 |
parents | 7f0e78f42032 |
children |
rev | line source |
---|---|
61 | 1 /* |
2 * | |
3 * utils for AAC informations | |
4 */ | |
5 #include <glib.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 | |
9 | |
10 #define ADTS_HEADER_SIZE 8 | |
11 #define SEEK_TABLE_CHUNK 60 | |
12 #define MPEG4_TYPE 0 | |
13 #define MPEG2_TYPE 1 | |
14 | |
15 // Read ADTS header, the file descriptor must be at | |
16 // the begining of the aac frame not at the id3tag | |
17 | |
18 int getAacInfo(FILE *fd) | |
19 { | |
20 unsigned char header[ADTS_HEADER_SIZE]; | |
21 unsigned int id; | |
22 unsigned long originPosition; | |
23 | |
24 originPosition = ftell(fd); | |
25 if(fread(header, 1, ADTS_HEADER_SIZE, fd) != ADTS_HEADER_SIZE){ | |
26 fseek(fd, originPosition, SEEK_SET); | |
27 return(-1); | |
28 } | |
29 if(!((header[0]==0xFF)&&((header[1]& 0xF6)==0xF0))){ | |
30 printf("Bad header\n"); | |
31 return(-1); | |
32 } | |
33 id = header[1]&0x08; | |
34 if(id==0){//MPEG-4 AAC | |
35 fseek(fd, originPosition, SEEK_SET); | |
36 return(MPEG4_TYPE); | |
37 }else{ | |
38 fseek(fd, originPosition, SEEK_SET); | |
39 return(MPEG2_TYPE); | |
40 } | |
41 fseek(fd, originPosition, SEEK_SET); | |
42 return(-1); | |
43 } | |
44 | |
45 // as AAC is VBR we need to check all ADTS header | |
46 // to enable seeking... | |
47 // there is no other solution | |
48 void checkADTSForSeeking(FILE *fd, | |
49 unsigned long **seekTable, | |
50 unsigned long *seekTableLength) | |
51 { | |
52 unsigned long originPosition; | |
53 unsigned long position; | |
54 unsigned int frameCount, frameLength, frameInsec; | |
55 unsigned int id=0, seconds=0; | |
377 | 56 char header[ADTS_HEADER_SIZE]; |
61 | 57 |
58 originPosition = ftell(fd); | |
59 | |
60 for(frameCount=0,frameInsec=0;; frameCount++,frameInsec++){ | |
61 position = ftell(fd); | |
62 if(fread(header, 1, ADTS_HEADER_SIZE, fd)!=ADTS_HEADER_SIZE){ | |
63 break; | |
64 } | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
65 if(!g_strncasecmp(header, "ID3", 3)){ |
61 | 66 break; |
67 } | |
68 if(!frameCount){ | |
69 id=header[1]&0x08; | |
70 if(((*seekTable) = malloc(SEEK_TABLE_CHUNK * sizeof(unsigned long)))==0){ | |
71 printf("malloc error\n"); | |
72 return; | |
73 } | |
74 (*seekTableLength) = SEEK_TABLE_CHUNK; | |
75 } | |
76 | |
77 //if(id==0){//MPEG-4 | |
78 //frameLength = ((unsigned int)header[4]<<5)|((unsigned int)header[5]>>3); | |
79 //}else{//MPEG-2 | |
80 frameLength = (((unsigned int)header[3]&0x3)<<11)|((unsigned int)header[4]<<3)|(header[5]>>5); | |
81 //} | |
82 if(frameInsec==43){//??? | |
83 frameInsec=0; | |
84 } | |
85 if(frameInsec==0){ | |
86 if(seconds == (*seekTableLength)){ | |
87 (*seekTable) = realloc((*seekTable), (seconds+SEEK_TABLE_CHUNK)*sizeof(unsigned long)); | |
88 (*seekTableLength) = seconds+SEEK_TABLE_CHUNK; | |
89 } | |
90 (*seekTable)[seconds] = position; | |
91 seconds++; | |
92 } | |
93 if(fseek(fd, frameLength-ADTS_HEADER_SIZE, SEEK_CUR)==-1){ | |
94 break; | |
95 } | |
96 } | |
97 (*seekTableLength) = seconds; | |
98 fseek(fd, originPosition, SEEK_SET); | |
99 } |