1 //
2 // C++ Implementation: ADM_aacInfo
3 //
4 // Description:
5 // Decode an aac frame an fill the info field
6 // The second is a template to check we do not do bogus frame detection
7 //
8 // Author: mean <fixounet@free.fr>, (C) 2004
9 //
10 // Copyright: See COPYING file that comes with this distribution
11 // THIS FILE IS OBSOLETE, USE ADTS/AAC INSTEAD...
12 //
13 /***************************************************************************
14 * *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
19 * *
20 ***************************************************************************/
21
22
23 #include "ADM_default.h"
24
25 extern "C" {
26 #include "libavcodec/avcodec.h"
27 }
28
29 #include <math.h>
30 #include "ADM_getbits.h"
31 #include "ADM_aacinfo.h"
32
33 static const int aacChannels[8]=
34 {
35 0, //0: Defined in AOT Specifc Config
36 1, //1: 1 channel: front-center
37 2, //2: 2 channels: front-left, front-right
38 3, //3: 3 channels: front-center, front-left, front-right
39 4, //4: 4 channels: front-center, front-left, front-right, back-center
40 5, // 5: 5 channels: front-center, front-left, front-right, back-left, back-right
41 6, // 6: 6 channels: front-center, front-left, front-right, back-left, back-right, LFE-channel
42 8 // 7: 8 channels: front-center, front-left, front-right, side-left, side-right, back-left, back-right, LFE-channel
43 };
44
45 static int aacSampleRate[16]=
46 {
47 96000, 88200, 64000, 48000,
48 44100, 32000, 24000, 22050,
49 16000, 12000, 11025, 8000,
50 7350, 0, 0, 0
51 };
52
53 #define xdebug(...) {}
54
getAudioObjectType(getBits * bit)55 static int getAudioObjectType(getBits *bit)
56 {
57 int type=bit->get(5);
58 if(type==31)
59 type=32+bit->get(6);
60 return type;
61 }
62
getSamplingFrequency(getBits * bit)63 static int getSamplingFrequency(getBits *bit)
64 {
65 int index=bit->get(4);
66 if(index==0xf)
67 return bit->get(24);
68 return aacSampleRate[index];
69 }
70
71 /**
72 \fn ADM_getAacInfoFromConfig
73 */
74
ADM_getAacInfoFromConfig(int size,uint8_t * data,AacAudioInfo & info)75 bool ADM_getAacInfoFromConfig(int size, uint8_t *data, AacAudioInfo &info)
76 {
77 if(size<2)
78 {
79 return false;
80 }
81 int paddedSize=size+AV_INPUT_BUFFER_PADDING_SIZE;
82 uint8_t *padded=new uint8_t[paddedSize];
83 memset(padded,0,paddedSize);
84 memcpy(padded,data,size);
85 getBits bits(size,padded); // get a copy, needed to extract extra data
86 int audioObjectType=getAudioObjectType(&bits);
87 int fq=getSamplingFrequency(&bits);
88 int channelConfiguration=bits.get(4);
89 bool sbrPresent=false;
90 xdebug("ObjectType=%d\n",audioObjectType);
91 #if 0
92 switch(audioObjectType)
93 {
94 case 2: // GASpecificConfig
95 {
96 bits.get(1); // frameLength
97 bool dependsOnCoreCoder=bits.get(1);
98 if(dependsOnCoreCoder) bits.skip(14);
99 bool extensionFlag=bits.get(1);
100 if(!channelConfiguration)
101 {
102 ADM_error("No channel configuraiton\n");
103 return false;
104 }
105 if(extensionFlag)
106 {
107 ADM_error("Extension flag\n");
108 return false;
109 }
110 }
111 break;
112 default:
113 ADM_error("AudoObjecttype =%d not handled\n",audioObjectType);
114 return false;
115 }
116 #endif
117
118 if(audioObjectType==5 || (audioObjectType==29 && !(bits.show(3) & 0x03 && !(bits.show(9) & 0x3f)))) // SBR or PS
119 {
120 sbrPresent=true;
121 fq=getSamplingFrequency(&bits);
122 audioObjectType=getAudioObjectType(&bits);
123 if(audioObjectType==22)
124 channelConfiguration=bits.get(4);
125 }else
126 {
127 int max=size*8-16;
128 while(bits.getConsumedBits()<max)
129 {
130 if(bits.show(11)==0x2b7)
131 {
132 bits.skip(11);
133 if(getAudioObjectType(&bits)==5 && bits.get(1)==1)
134 {
135 int extFq=getSamplingFrequency(&bits);
136 if(extFq && extFq!=fq)
137 {
138 sbrPresent=true;
139 fq=extFq;
140 }
141 }
142 break;
143 }else
144 {
145 bits.skip(1);
146 }
147 }
148 }
149
150 delete [] padded;
151 padded=NULL;
152
153 if(!channelConfiguration)
154 {
155 ADM_error("AOT Specific Config not handled!\n");
156 return false;
157 }
158 info.frequency=fq;
159 info.channels=aacChannels[channelConfiguration];
160 info.sbr=sbrPresent;
161
162 return true;
163 }
164
165 //____________
166
167