10725
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
|
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
|
|
4 **
|
|
5 ** This program is free software; you can redistribute it and/or modify
|
|
6 ** it under the terms of the GNU General Public License as published by
|
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
|
8 ** (at your option) any later version.
|
|
9 **
|
|
10 ** This program is distributed in the hope that it will be useful,
|
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ** GNU General Public License for more details.
|
|
14 **
|
|
15 ** You should have received a copy of the GNU General Public License
|
|
16 ** along with this program; if not, write to the Free Software
|
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 **
|
|
19 ** Any non-GPL usage of this software or parts of this software is strictly
|
|
20 ** forbidden.
|
|
21 **
|
|
22 ** Commercial non-GPL licensing of this software is possible.
|
|
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
|
|
24 **
|
|
25 ** $Id: mp4.c,v 1.17 2003/07/29 08:20:12 menno Exp $
|
|
26 **/
|
|
27
|
|
28 #include "common.h"
|
|
29 #include "structs.h"
|
|
30
|
|
31 #include <stdlib.h>
|
|
32
|
|
33 #include "bits.h"
|
|
34 #include "mp4.h"
|
|
35 #include "syntax.h"
|
|
36
|
|
37 /* defines if an object type can be decoded by this library or not */
|
|
38 static uint8_t ObjectTypesTable[32] = {
|
|
39 0, /* 0 NULL */
|
|
40 #ifdef MAIN_DEC
|
|
41 1, /* 1 AAC Main */
|
|
42 #else
|
|
43 0, /* 1 AAC Main */
|
|
44 #endif
|
|
45 1, /* 2 AAC LC */
|
|
46 #ifdef SSR_DEC
|
|
47 1, /* 3 AAC SSR */
|
|
48 #else
|
|
49 0, /* 3 AAC SSR */
|
|
50 #endif
|
|
51 #ifdef LTP_DEC
|
|
52 1, /* 4 AAC LTP */
|
|
53 #else
|
|
54 0, /* 4 AAC LTP */
|
|
55 #endif
|
|
56 #ifdef SBR_DEC
|
|
57 1, /* 5 SBR */
|
|
58 #else
|
|
59 0, /* 5 SBR */
|
|
60 #endif
|
|
61 0, /* 6 AAC Scalable */
|
|
62 0, /* 7 TwinVQ */
|
|
63 0, /* 8 CELP */
|
|
64 0, /* 9 HVXC */
|
|
65 0, /* 10 Reserved */
|
|
66 0, /* 11 Reserved */
|
|
67 0, /* 12 TTSI */
|
|
68 0, /* 13 Main synthetic */
|
|
69 0, /* 14 Wavetable synthesis */
|
|
70 0, /* 15 General MIDI */
|
|
71 0, /* 16 Algorithmic Synthesis and Audio FX */
|
|
72
|
|
73 /* MPEG-4 Version 2 */
|
|
74 #ifdef ERROR_RESILIENCE
|
|
75 1, /* 17 ER AAC LC */
|
|
76 0, /* 18 (Reserved) */
|
|
77 #ifdef LTP_DEC
|
|
78 1, /* 19 ER AAC LTP */
|
|
79 #else
|
|
80 0, /* 19 ER AAC LTP */
|
|
81 #endif
|
|
82 0, /* 20 ER AAC scalable */
|
|
83 0, /* 21 ER TwinVQ */
|
|
84 0, /* 22 ER BSAC */
|
|
85 #ifdef LD_DEC
|
|
86 1, /* 23 ER AAC LD */
|
|
87 #else
|
|
88 0, /* 23 ER AAC LD */
|
|
89 #endif
|
|
90 0, /* 24 ER CELP */
|
|
91 0, /* 25 ER HVXC */
|
|
92 0, /* 26 ER HILN */
|
|
93 0, /* 27 ER Parametric */
|
|
94 #else /* No ER defined */
|
|
95 0, /* 17 ER AAC LC */
|
|
96 0, /* 18 (Reserved) */
|
|
97 0, /* 19 ER AAC LTP */
|
|
98 0, /* 20 ER AAC scalable */
|
|
99 0, /* 21 ER TwinVQ */
|
|
100 0, /* 22 ER BSAC */
|
|
101 0, /* 23 ER AAC LD */
|
|
102 0, /* 24 ER CELP */
|
|
103 0, /* 25 ER HVXC */
|
|
104 0, /* 26 ER HILN */
|
|
105 0, /* 27 ER Parametric */
|
|
106 #endif
|
|
107 0, /* 28 (Reserved) */
|
|
108 0, /* 29 (Reserved) */
|
|
109 0, /* 30 (Reserved) */
|
|
110 0 /* 31 (Reserved) */
|
|
111 };
|
|
112
|
|
113 /* Table 1.6.1 */
|
|
114 int8_t FAADAPI AudioSpecificConfig(uint8_t *pBuffer,
|
|
115 uint32_t buffer_size,
|
|
116 mp4AudioSpecificConfig *mp4ASC)
|
|
117 {
|
|
118 return AudioSpecificConfig2(pBuffer, buffer_size, mp4ASC, NULL);
|
|
119 }
|
|
120
|
|
121 int8_t FAADAPI AudioSpecificConfig2(uint8_t *pBuffer,
|
|
122 uint32_t buffer_size,
|
|
123 mp4AudioSpecificConfig *mp4ASC,
|
|
124 program_config *pce)
|
|
125 {
|
|
126 bitfile ld;
|
|
127 int8_t result = 0;
|
|
128 #ifdef SBR_DEC
|
|
129 int8_t bits_to_decode = 0;
|
|
130 #endif
|
|
131
|
|
132 if (pBuffer == NULL)
|
|
133 return -7;
|
|
134 if (mp4ASC == NULL)
|
|
135 return -8;
|
|
136
|
|
137 memset(mp4ASC, 0, sizeof(mp4AudioSpecificConfig));
|
|
138
|
|
139 faad_initbits(&ld, pBuffer, buffer_size);
|
|
140 faad_byte_align(&ld);
|
|
141
|
|
142 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
|
|
143 DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
|
|
144
|
|
145 mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4
|
|
146 DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex"));
|
|
147
|
|
148 mp4ASC->channelsConfiguration = (uint8_t)faad_getbits(&ld, 4
|
|
149 DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration"));
|
|
150
|
|
151 mp4ASC->samplingFrequency = sample_rates[mp4ASC->samplingFrequencyIndex];
|
|
152
|
|
153 if (ObjectTypesTable[mp4ASC->objectTypeIndex] != 1)
|
|
154 {
|
|
155 faad_endbits(&ld);
|
|
156 return -1;
|
|
157 }
|
|
158
|
|
159 if (mp4ASC->samplingFrequency == 0)
|
|
160 {
|
|
161 faad_endbits(&ld);
|
|
162 return -2;
|
|
163 }
|
|
164
|
|
165 if (mp4ASC->channelsConfiguration > 7)
|
|
166 {
|
|
167 faad_endbits(&ld);
|
|
168 return -3;
|
|
169 }
|
|
170
|
|
171 #ifdef SBR_DEC
|
|
172 mp4ASC->sbr_present_flag = -1;
|
|
173 if (mp4ASC->objectTypeIndex == 5)
|
|
174 {
|
|
175 mp4ASC->sbr_present_flag = 1;
|
|
176 mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4
|
|
177 DEBUGVAR(1,5,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
|
|
178 if (mp4ASC->samplingFrequencyIndex == 15)
|
|
179 {
|
|
180 mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24
|
|
181 DEBUGVAR(1,6,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
|
|
182 } else {
|
|
183 mp4ASC->samplingFrequency = sample_rates[mp4ASC->samplingFrequencyIndex];
|
|
184 }
|
|
185 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
|
|
186 DEBUGVAR(1,7,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
|
|
187 }
|
|
188 #endif
|
|
189
|
|
190 /* get GASpecificConfig */
|
|
191 if (mp4ASC->objectTypeIndex == 1 || mp4ASC->objectTypeIndex == 2 ||
|
|
192 mp4ASC->objectTypeIndex == 3 || mp4ASC->objectTypeIndex == 4 ||
|
|
193 mp4ASC->objectTypeIndex == 6 || mp4ASC->objectTypeIndex == 7)
|
|
194 {
|
|
195 result = GASpecificConfig(&ld, mp4ASC, pce);
|
|
196
|
|
197 #ifdef ERROR_RESILIENCE
|
|
198 } else if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) { /* ER */
|
|
199 result = GASpecificConfig(&ld, mp4ASC, pce);
|
|
200 mp4ASC->epConfig = (uint8_t)faad_getbits(&ld, 2
|
|
201 DEBUGVAR(1,143,"parse_audio_decoder_specific_info(): epConfig"));
|
|
202
|
|
203 if (mp4ASC->epConfig != 0)
|
|
204 result = -5;
|
|
205 #endif
|
|
206
|
|
207 } else {
|
|
208 result = -4;
|
|
209 }
|
|
210
|
|
211 #ifdef SSR_DEC
|
|
212 /* shorter frames not allowed for SSR */
|
|
213 if ((mp4ASC->objectTypeIndex == 4) && mp4ASC->frameLengthFlag)
|
|
214 return -6;
|
|
215 #endif
|
|
216
|
|
217
|
|
218 #ifdef SBR_DEC
|
|
219 bits_to_decode = buffer_size*8 - faad_get_processed_bits(&ld);
|
|
220
|
|
221 if ((mp4ASC->objectTypeIndex != 5) && (bits_to_decode >= 16))
|
|
222 {
|
|
223 int16_t syncExtensionType = (int16_t)faad_getbits(&ld, 11
|
|
224 DEBUGVAR(1,9,"parse_audio_decoder_specific_info(): syncExtensionType"));
|
|
225
|
|
226 if (syncExtensionType == 0x2b7)
|
|
227 {
|
|
228 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
|
|
229 DEBUGVAR(1,10,"parse_audio_decoder_specific_info(): extensionAudioObjectType"));
|
|
230
|
|
231 if (mp4ASC->objectTypeIndex == 5)
|
|
232 {
|
|
233 mp4ASC->sbr_present_flag = (uint8_t)faad_get1bit(&ld
|
|
234 DEBUGVAR(1,11,"parse_audio_decoder_specific_info(): sbr_present_flag"));
|
|
235
|
|
236 if (mp4ASC->sbr_present_flag)
|
|
237 {
|
|
238 mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4
|
|
239 DEBUGVAR(1,12,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
|
|
240 if (mp4ASC->samplingFrequencyIndex == 15)
|
|
241 {
|
|
242 mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24
|
|
243 DEBUGVAR(1,13,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
|
|
244 } else {
|
|
245 mp4ASC->samplingFrequency = sample_rates[mp4ASC->samplingFrequencyIndex];
|
|
246 }
|
|
247 }
|
|
248 }
|
|
249 }
|
|
250 }
|
|
251 #endif
|
|
252
|
|
253 faad_endbits(&ld);
|
|
254
|
|
255 return result;
|
|
256 }
|