Mercurial > mplayer.hg
annotate libfaad2/decoder.c @ 19998:b1cebdd78625
Do not compile with -DDEBUG by default.
author | diego |
---|---|
date | Fri, 29 Sep 2006 09:46:06 +0000 |
parents | 59b6fa5b4201 |
children | 645cbba10a57 |
rev | line source |
---|---|
10725 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
12527 | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
4 ** | |
10725 | 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. | |
12527 | 9 ** |
10725 | 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. | |
12527 | 14 ** |
10725 | 15 ** You should have received a copy of the GNU General Public License |
12527 | 16 ** along with this program; if not, write to the Free Software |
10725 | 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 ** | |
18141 | 25 ** $Id: decoder.c,v 1.107 2004/09/08 09:43:11 gcp Exp $ |
10725 | 26 **/ |
27 | |
28 #include "common.h" | |
29 #include "structs.h" | |
30 | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 | |
34 #include "decoder.h" | |
35 #include "mp4.h" | |
36 #include "syntax.h" | |
37 #include "error.h" | |
38 #include "output.h" | |
12527 | 39 #include "filtbank.h" |
40 #include "drc.h" | |
41 #ifdef SBR_DEC | |
42 #include "sbr_dec.h" | |
43 #include "sbr_syntax.h" | |
44 #endif | |
10725 | 45 #ifdef SSR_DEC |
46 #include "ssr.h" | |
47 #endif | |
48 | |
49 #ifdef ANALYSIS | |
50 uint16_t dbg_count; | |
51 #endif | |
52 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
53 /* static function declarations */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
54 static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
55 uint8_t *buffer, uint32_t buffer_size, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
56 void **sample_buffer, uint32_t sample_buffer_size); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
57 static void create_channel_config(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
58 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
59 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
60 char* NEAACDECAPI NeAACDecGetErrorMessage(uint8_t errcode) |
10725 | 61 { |
62 if (errcode >= NUM_ERROR_MESSAGES) | |
63 return NULL; | |
64 return err_msg[errcode]; | |
65 } | |
66 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
67 uint32_t NEAACDECAPI NeAACDecGetCapabilities(void) |
10725 | 68 { |
69 uint32_t cap = 0; | |
70 | |
71 /* can't do without it */ | |
72 cap += LC_DEC_CAP; | |
73 | |
74 #ifdef MAIN_DEC | |
75 cap += MAIN_DEC_CAP; | |
76 #endif | |
77 #ifdef LTP_DEC | |
78 cap += LTP_DEC_CAP; | |
79 #endif | |
80 #ifdef LD_DEC | |
81 cap += LD_DEC_CAP; | |
82 #endif | |
83 #ifdef ERROR_RESILIENCE | |
84 cap += ERROR_RESILIENCE_CAP; | |
85 #endif | |
86 #ifdef FIXED_POINT | |
87 cap += FIXED_POINT_CAP; | |
88 #endif | |
89 | |
90 return cap; | |
91 } | |
92 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
93 NeAACDecHandle NEAACDECAPI NeAACDecOpen(void) |
10725 | 94 { |
95 uint8_t i; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
96 NeAACDecHandle hDecoder = NULL; |
10725 | 97 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
98 if ((hDecoder = (NeAACDecHandle)faad_malloc(sizeof(NeAACDecStruct))) == NULL) |
10725 | 99 return NULL; |
100 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
101 memset(hDecoder, 0, sizeof(NeAACDecStruct)); |
10725 | 102 |
103 hDecoder->config.outputFormat = FAAD_FMT_16BIT; | |
104 hDecoder->config.defObjectType = MAIN; | |
105 hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | |
12527 | 106 hDecoder->config.downMatrix = 0; |
10725 | 107 hDecoder->adts_header_present = 0; |
108 hDecoder->adif_header_present = 0; | |
109 #ifdef ERROR_RESILIENCE | |
110 hDecoder->aacSectionDataResilienceFlag = 0; | |
111 hDecoder->aacScalefactorDataResilienceFlag = 0; | |
112 hDecoder->aacSpectralDataResilienceFlag = 0; | |
113 #endif | |
114 hDecoder->frameLength = 1024; | |
115 | |
116 hDecoder->frame = 0; | |
117 hDecoder->sample_buffer = NULL; | |
118 | |
119 for (i = 0; i < MAX_CHANNELS; i++) | |
120 { | |
121 hDecoder->window_shape_prev[i] = 0; | |
122 hDecoder->time_out[i] = NULL; | |
12527 | 123 hDecoder->fb_intermed[i] = NULL; |
10725 | 124 #ifdef SSR_DEC |
125 hDecoder->ssr_overlap[i] = NULL; | |
126 hDecoder->prev_fmd[i] = NULL; | |
127 #endif | |
128 #ifdef MAIN_DEC | |
129 hDecoder->pred_stat[i] = NULL; | |
130 #endif | |
131 #ifdef LTP_DEC | |
132 hDecoder->ltp_lag[i] = 0; | |
133 hDecoder->lt_pred_stat[i] = NULL; | |
134 #endif | |
135 } | |
136 | |
137 #ifdef SBR_DEC | |
12527 | 138 for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
10725 | 139 { |
140 hDecoder->sbr[i] = NULL; | |
141 } | |
142 #endif | |
143 | |
144 hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | |
145 | |
146 return hDecoder; | |
147 } | |
148 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
149 NeAACDecConfigurationPtr NEAACDECAPI NeAACDecGetCurrentConfiguration(NeAACDecHandle hDecoder) |
10725 | 150 { |
10989 | 151 if (hDecoder) |
152 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
153 NeAACDecConfigurationPtr config = &(hDecoder->config); |
10725 | 154 |
12527 | 155 return config; |
10989 | 156 } |
157 | |
158 return NULL; | |
10725 | 159 } |
160 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
161 uint8_t NEAACDECAPI NeAACDecSetConfiguration(NeAACDecHandle hDecoder, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
162 NeAACDecConfigurationPtr config) |
10725 | 163 { |
10989 | 164 if (hDecoder && config) |
165 { | |
166 /* check if we can decode this object type */ | |
167 if (can_decode_ot(config->defObjectType) < 0) | |
168 return 0; | |
12527 | 169 hDecoder->config.defObjectType = config->defObjectType; |
10989 | 170 |
171 /* samplerate: anything but 0 should be possible */ | |
172 if (config->defSampleRate == 0) | |
173 return 0; | |
12527 | 174 hDecoder->config.defSampleRate = config->defSampleRate; |
10989 | 175 |
176 /* check output format */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
177 #ifdef FIXED_POINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
178 if ((config->outputFormat < 1) || (config->outputFormat > 4)) |
10989 | 179 return 0; |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
180 #else |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
181 if ((config->outputFormat < 1) || (config->outputFormat > 5)) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
182 return 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
183 #endif |
12527 | 184 hDecoder->config.outputFormat = config->outputFormat; |
10989 | 185 |
186 if (config->downMatrix > 1) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
187 return 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
188 hDecoder->config.downMatrix = config->downMatrix; |
10725 | 189 |
12527 | 190 /* OK */ |
191 return 1; | |
10989 | 192 } |
193 | |
194 return 0; | |
10725 | 195 } |
196 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
197 int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
198 uint32_t buffer_size, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
199 uint32_t *samplerate, uint8_t *channels) |
10725 | 200 { |
201 uint32_t bits = 0; | |
202 bitfile ld; | |
203 adif_header adif; | |
204 adts_header adts; | |
205 | |
10989 | 206 if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL)) |
207 return -1; | |
208 | |
10725 | 209 hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate); |
210 hDecoder->object_type = hDecoder->config.defObjectType; | |
10989 | 211 *samplerate = get_sample_rate(hDecoder->sf_index); |
10725 | 212 *channels = 1; |
213 | |
214 if (buffer != NULL) | |
215 { | |
216 faad_initbits(&ld, buffer, buffer_size); | |
217 | |
218 /* Check if an ADIF header is present */ | |
219 if ((buffer[0] == 'A') && (buffer[1] == 'D') && | |
220 (buffer[2] == 'I') && (buffer[3] == 'F')) | |
221 { | |
222 hDecoder->adif_header_present = 1; | |
223 | |
224 get_adif_header(&adif, &ld); | |
225 faad_byte_align(&ld); | |
226 | |
227 hDecoder->sf_index = adif.pce[0].sf_index; | |
10989 | 228 hDecoder->object_type = adif.pce[0].object_type + 1; |
10725 | 229 |
10989 | 230 *samplerate = get_sample_rate(hDecoder->sf_index); |
10725 | 231 *channels = adif.pce[0].channels; |
232 | |
233 memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config)); | |
234 hDecoder->pce_set = 1; | |
235 | |
236 bits = bit2byte(faad_get_processed_bits(&ld)); | |
237 | |
238 /* Check if an ADTS header is present */ | |
239 } else if (faad_showbits(&ld, 12) == 0xfff) { | |
240 hDecoder->adts_header_present = 1; | |
241 | |
10989 | 242 adts.old_format = hDecoder->config.useOldADTSFormat; |
10725 | 243 adts_frame(&adts, &ld); |
244 | |
245 hDecoder->sf_index = adts.sf_index; | |
10989 | 246 hDecoder->object_type = adts.profile + 1; |
10725 | 247 |
10989 | 248 *samplerate = get_sample_rate(hDecoder->sf_index); |
10725 | 249 *channels = (adts.channel_configuration > 6) ? |
250 2 : adts.channel_configuration; | |
251 } | |
252 | |
253 if (ld.error) | |
254 { | |
255 faad_endbits(&ld); | |
256 return -1; | |
257 } | |
258 faad_endbits(&ld); | |
259 } | |
260 hDecoder->channelConfiguration = *channels; | |
261 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
262 #if (defined(PS_DEC) || defined(DRM_PS)) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
263 /* check if we have a mono file */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
264 if (*channels == 1) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
265 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
266 /* upMatrix to 2 channels for implicit signalling of PS */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
267 *channels = 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
268 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
269 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
270 |
10989 | 271 #ifdef SBR_DEC |
272 /* implicit signalling */ | |
12527 | 273 if (*samplerate <= 24000 && !(hDecoder->config.dontUpSampleImplicitSBR)) |
10989 | 274 { |
275 *samplerate *= 2; | |
276 hDecoder->forceUpSampling = 1; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
277 } else if (*samplerate > 24000 && !(hDecoder->config.dontUpSampleImplicitSBR)) { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
278 hDecoder->downSampledSBR = 1; |
10989 | 279 } |
280 #endif | |
281 | |
10725 | 282 /* must be done before frameLength is divided by 2 for LD */ |
283 #ifdef SSR_DEC | |
284 if (hDecoder->object_type == SSR) | |
285 hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); | |
286 else | |
287 #endif | |
288 hDecoder->fb = filter_bank_init(hDecoder->frameLength); | |
289 | |
290 #ifdef LD_DEC | |
291 if (hDecoder->object_type == LD) | |
292 hDecoder->frameLength >>= 1; | |
293 #endif | |
294 | |
295 if (can_decode_ot(hDecoder->object_type) < 0) | |
296 return -1; | |
297 | |
298 return bits; | |
299 } | |
300 | |
301 /* Init the library using a DecoderSpecificInfo */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
302 int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
303 uint32_t SizeOfDecoderSpecificInfo, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
304 uint32_t *samplerate, uint8_t *channels) |
10725 | 305 { |
306 int8_t rc; | |
307 mp4AudioSpecificConfig mp4ASC; | |
308 | |
309 if((hDecoder == NULL) | |
310 || (pBuffer == NULL) | |
311 || (SizeOfDecoderSpecificInfo < 2) | |
312 || (samplerate == NULL) | |
313 || (channels == NULL)) | |
314 { | |
315 return -1; | |
316 } | |
317 | |
10989 | 318 hDecoder->adif_header_present = 0; |
319 hDecoder->adts_header_present = 0; | |
320 | |
10725 | 321 /* decode the audio specific config */ |
322 rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC, | |
323 &(hDecoder->pce)); | |
324 | |
325 /* copy the relevant info to the decoder handle */ | |
326 *samplerate = mp4ASC.samplingFrequency; | |
327 if (mp4ASC.channelsConfiguration) | |
328 { | |
329 *channels = mp4ASC.channelsConfiguration; | |
330 } else { | |
331 *channels = hDecoder->pce.channels; | |
332 hDecoder->pce_set = 1; | |
333 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
334 #if (defined(PS_DEC) || defined(DRM_PS)) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
335 /* check if we have a mono file */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
336 if (*channels == 1) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
337 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
338 /* upMatrix to 2 channels for implicit signalling of PS */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
339 *channels = 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
340 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
341 #endif |
10725 | 342 hDecoder->sf_index = mp4ASC.samplingFrequencyIndex; |
343 hDecoder->object_type = mp4ASC.objectTypeIndex; | |
10989 | 344 #ifdef ERROR_RESILIENCE |
10725 | 345 hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag; |
346 hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag; | |
347 hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag; | |
10989 | 348 #endif |
10725 | 349 #ifdef SBR_DEC |
350 hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
351 hDecoder->downSampledSBR = mp4ASC.downSampledSBR; |
12527 | 352 if (hDecoder->config.dontUpSampleImplicitSBR == 0) |
353 hDecoder->forceUpSampling = mp4ASC.forceUpSampling; | |
354 else | |
355 hDecoder->forceUpSampling = 0; | |
10725 | 356 |
357 /* AAC core decoder samplerate is 2 times as low */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
358 if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1) |
10725 | 359 { |
360 hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2); | |
361 } | |
362 #endif | |
363 | |
364 if (rc != 0) | |
365 { | |
366 return rc; | |
367 } | |
368 hDecoder->channelConfiguration = mp4ASC.channelsConfiguration; | |
369 if (mp4ASC.frameLengthFlag) | |
12527 | 370 #ifdef ALLOW_SMALL_FRAMELENGTH |
10725 | 371 hDecoder->frameLength = 960; |
12527 | 372 #else |
373 return -1; | |
374 #endif | |
10725 | 375 |
376 /* must be done before frameLength is divided by 2 for LD */ | |
377 #ifdef SSR_DEC | |
378 if (hDecoder->object_type == SSR) | |
379 hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); | |
380 else | |
381 #endif | |
382 hDecoder->fb = filter_bank_init(hDecoder->frameLength); | |
383 | |
384 #ifdef LD_DEC | |
385 if (hDecoder->object_type == LD) | |
386 hDecoder->frameLength >>= 1; | |
387 #endif | |
388 | |
389 return 0; | |
390 } | |
391 | |
12527 | 392 #ifdef DRM |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
393 int8_t NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, uint32_t samplerate, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
394 uint8_t channels) |
10725 | 395 { |
12527 | 396 if (hDecoder == NULL) |
397 return 1; /* error */ | |
398 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
399 NeAACDecClose(*hDecoder); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
400 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
401 *hDecoder = NeAACDecOpen(); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
402 |
10725 | 403 /* Special object type defined for DRM */ |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
404 (*hDecoder)->config.defObjectType = DRM_ER_LC; |
10725 | 405 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
406 (*hDecoder)->config.defSampleRate = samplerate; |
10989 | 407 #ifdef ERROR_RESILIENCE // This shoudl always be defined for DRM |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
408 (*hDecoder)->aacSectionDataResilienceFlag = 1; /* VCB11 */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
409 (*hDecoder)->aacScalefactorDataResilienceFlag = 0; /* no RVLC */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
410 (*hDecoder)->aacSpectralDataResilienceFlag = 1; /* HCR */ |
10989 | 411 #endif |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
412 (*hDecoder)->frameLength = 960; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
413 (*hDecoder)->sf_index = get_sr_index((*hDecoder)->config.defSampleRate); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
414 (*hDecoder)->object_type = (*hDecoder)->config.defObjectType; |
10989 | 415 |
416 if ((channels == DRMCH_STEREO) || (channels == DRMCH_SBR_STEREO)) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
417 (*hDecoder)->channelConfiguration = 2; |
10989 | 418 else |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
419 (*hDecoder)->channelConfiguration = 1; |
10989 | 420 |
421 #ifdef SBR_DEC | |
422 if ((channels == DRMCH_MONO) || (channels == DRMCH_STEREO)) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
423 (*hDecoder)->sbr_present_flag = 0; |
10989 | 424 else |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
425 (*hDecoder)->sbr_present_flag = 1; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
426 #endif |
10725 | 427 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
428 (*hDecoder)->fb = filter_bank_init((*hDecoder)->frameLength); |
10725 | 429 |
430 return 0; | |
431 } | |
12527 | 432 #endif |
10725 | 433 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
434 void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder) |
10725 | 435 { |
436 uint8_t i; | |
437 | |
438 if (hDecoder == NULL) | |
439 return; | |
440 | |
12527 | 441 #ifdef PROFILE |
442 printf("AAC decoder total: %I64d cycles\n", hDecoder->cycles); | |
443 printf("requant: %I64d cycles\n", hDecoder->requant_cycles); | |
444 printf("spectral_data: %I64d cycles\n", hDecoder->spectral_cycles); | |
445 printf("scalefactors: %I64d cycles\n", hDecoder->scalefac_cycles); | |
446 printf("output: %I64d cycles\n", hDecoder->output_cycles); | |
447 #endif | |
448 | |
10725 | 449 for (i = 0; i < MAX_CHANNELS; i++) |
450 { | |
12527 | 451 if (hDecoder->time_out[i]) faad_free(hDecoder->time_out[i]); |
452 if (hDecoder->fb_intermed[i]) faad_free(hDecoder->fb_intermed[i]); | |
10725 | 453 #ifdef SSR_DEC |
12527 | 454 if (hDecoder->ssr_overlap[i]) faad_free(hDecoder->ssr_overlap[i]); |
455 if (hDecoder->prev_fmd[i]) faad_free(hDecoder->prev_fmd[i]); | |
10725 | 456 #endif |
457 #ifdef MAIN_DEC | |
12527 | 458 if (hDecoder->pred_stat[i]) faad_free(hDecoder->pred_stat[i]); |
10725 | 459 #endif |
460 #ifdef LTP_DEC | |
12527 | 461 if (hDecoder->lt_pred_stat[i]) faad_free(hDecoder->lt_pred_stat[i]); |
10725 | 462 #endif |
463 } | |
464 | |
465 #ifdef SSR_DEC | |
466 if (hDecoder->object_type == SSR) | |
467 ssr_filter_bank_end(hDecoder->fb); | |
468 else | |
469 #endif | |
470 filter_bank_end(hDecoder->fb); | |
471 | |
472 drc_end(hDecoder->drc); | |
473 | |
12527 | 474 if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer); |
10725 | 475 |
476 #ifdef SBR_DEC | |
12527 | 477 for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
10725 | 478 { |
479 if (hDecoder->sbr[i]) | |
480 sbrDecodeEnd(hDecoder->sbr[i]); | |
481 } | |
482 #endif | |
483 | |
12527 | 484 if (hDecoder) faad_free(hDecoder); |
10725 | 485 } |
486 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
487 void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, int32_t frame) |
10725 | 488 { |
489 if (hDecoder) | |
490 { | |
491 hDecoder->postSeekResetFlag = 1; | |
492 | |
493 if (frame != -1) | |
494 hDecoder->frame = frame; | |
495 } | |
496 } | |
497 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
498 static void create_channel_config(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo) |
10725 | 499 { |
500 hInfo->num_front_channels = 0; | |
501 hInfo->num_side_channels = 0; | |
502 hInfo->num_back_channels = 0; | |
503 hInfo->num_lfe_channels = 0; | |
504 memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | |
505 | |
506 if (hDecoder->downMatrix) | |
507 { | |
508 hInfo->num_front_channels = 2; | |
509 hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | |
510 hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | |
511 return; | |
512 } | |
513 | |
514 /* check if there is a PCE */ | |
515 if (hDecoder->pce_set) | |
516 { | |
517 uint8_t i, chpos = 0; | |
518 uint8_t chdir, back_center = 0; | |
519 | |
520 hInfo->num_front_channels = hDecoder->pce.num_front_channels; | |
521 hInfo->num_side_channels = hDecoder->pce.num_side_channels; | |
522 hInfo->num_back_channels = hDecoder->pce.num_back_channels; | |
523 hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | |
524 | |
525 chdir = hInfo->num_front_channels; | |
526 if (chdir & 1) | |
527 { | |
528 hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | |
529 chdir--; | |
530 } | |
531 for (i = 0; i < chdir; i += 2) | |
532 { | |
533 hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | |
534 hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | |
535 } | |
536 | |
537 for (i = 0; i < hInfo->num_side_channels; i += 2) | |
538 { | |
539 hInfo->channel_position[chpos++] = SIDE_CHANNEL_LEFT; | |
540 hInfo->channel_position[chpos++] = SIDE_CHANNEL_RIGHT; | |
541 } | |
542 | |
543 chdir = hInfo->num_back_channels; | |
544 if (chdir & 1) | |
545 { | |
546 back_center = 1; | |
547 chdir--; | |
548 } | |
549 for (i = 0; i < chdir; i += 2) | |
550 { | |
551 hInfo->channel_position[chpos++] = BACK_CHANNEL_LEFT; | |
552 hInfo->channel_position[chpos++] = BACK_CHANNEL_RIGHT; | |
553 } | |
554 if (back_center) | |
555 { | |
556 hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | |
557 } | |
558 | |
559 for (i = 0; i < hInfo->num_lfe_channels; i++) | |
560 { | |
561 hInfo->channel_position[chpos++] = LFE_CHANNEL; | |
562 } | |
563 | |
564 } else { | |
565 switch (hDecoder->channelConfiguration) | |
566 { | |
567 case 1: | |
568 hInfo->num_front_channels = 1; | |
569 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
570 break; | |
571 case 2: | |
572 hInfo->num_front_channels = 2; | |
573 hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | |
574 hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | |
575 break; | |
576 case 3: | |
577 hInfo->num_front_channels = 3; | |
578 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
579 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
580 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
581 break; | |
582 case 4: | |
583 hInfo->num_front_channels = 3; | |
584 hInfo->num_back_channels = 1; | |
585 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
586 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
587 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
588 hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | |
589 break; | |
590 case 5: | |
591 hInfo->num_front_channels = 3; | |
592 hInfo->num_back_channels = 2; | |
593 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
594 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
595 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
596 hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | |
597 hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | |
598 break; | |
599 case 6: | |
600 hInfo->num_front_channels = 3; | |
601 hInfo->num_back_channels = 2; | |
602 hInfo->num_lfe_channels = 1; | |
603 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
604 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
605 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
606 hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | |
607 hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | |
608 hInfo->channel_position[5] = LFE_CHANNEL; | |
609 break; | |
610 case 7: | |
611 hInfo->num_front_channels = 3; | |
612 hInfo->num_side_channels = 2; | |
613 hInfo->num_back_channels = 2; | |
614 hInfo->num_lfe_channels = 1; | |
615 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
616 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
617 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
618 hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | |
619 hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | |
620 hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | |
621 hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | |
622 hInfo->channel_position[7] = LFE_CHANNEL; | |
623 break; | |
624 default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | |
625 { | |
626 uint8_t i; | |
627 uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | |
628 if (ch & 1) /* there's either a center front or a center back channel */ | |
629 { | |
630 uint8_t ch1 = (ch-1)/2; | |
631 if (hDecoder->first_syn_ele == ID_SCE) | |
632 { | |
633 hInfo->num_front_channels = ch1 + 1; | |
634 hInfo->num_back_channels = ch1; | |
635 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
636 for (i = 1; i <= ch1; i+=2) | |
637 { | |
638 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | |
639 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | |
640 } | |
641 for (i = ch1+1; i < ch; i+=2) | |
642 { | |
643 hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | |
644 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | |
645 } | |
646 } else { | |
647 hInfo->num_front_channels = ch1; | |
648 hInfo->num_back_channels = ch1 + 1; | |
649 for (i = 0; i < ch1; i+=2) | |
650 { | |
651 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | |
652 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | |
653 } | |
654 for (i = ch1; i < ch-1; i+=2) | |
655 { | |
656 hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | |
657 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | |
658 } | |
659 hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | |
660 } | |
661 } else { | |
662 uint8_t ch1 = (ch)/2; | |
663 hInfo->num_front_channels = ch1; | |
664 hInfo->num_back_channels = ch1; | |
665 if (ch1 & 1) | |
666 { | |
667 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
668 for (i = 1; i <= ch1; i+=2) | |
669 { | |
670 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | |
671 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | |
672 } | |
673 for (i = ch1+1; i < ch-1; i+=2) | |
674 { | |
675 hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | |
676 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | |
677 } | |
678 hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | |
679 } else { | |
680 for (i = 0; i < ch1; i+=2) | |
681 { | |
682 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | |
683 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | |
684 } | |
685 for (i = ch1; i < ch; i+=2) | |
686 { | |
687 hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | |
688 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | |
689 } | |
690 } | |
691 } | |
692 hInfo->num_lfe_channels = hDecoder->has_lfe; | |
693 for (i = ch; i < hDecoder->fr_channels; i++) | |
694 { | |
695 hInfo->channel_position[i] = LFE_CHANNEL; | |
696 } | |
697 } | |
698 break; | |
699 } | |
700 } | |
701 } | |
702 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
703 void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
704 NeAACDecFrameInfo *hInfo, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
705 uint8_t *buffer, uint32_t buffer_size) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
706 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
707 return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
708 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
709 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
710 void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
711 NeAACDecFrameInfo *hInfo, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
712 uint8_t *buffer, uint32_t buffer_size, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
713 void **sample_buffer, uint32_t sample_buffer_size) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
714 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
715 if ((sample_buffer == NULL) || (sample_buffer_size == 0)) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
716 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
717 hInfo->error = 27; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
718 return NULL; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
719 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
720 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
721 return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
722 sample_buffer, sample_buffer_size); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
723 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
724 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
725 static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
726 uint8_t *buffer, uint32_t buffer_size, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
727 void **sample_buffer2, uint32_t sample_buffer_size) |
10725 | 728 { |
12527 | 729 uint8_t channels = 0; |
10725 | 730 uint8_t output_channels = 0; |
12527 | 731 bitfile ld; |
10989 | 732 uint32_t bitsconsumed; |
12527 | 733 uint16_t frame_len; |
734 void *sample_buffer; | |
735 | |
736 #ifdef PROFILE | |
737 int64_t count = faad_get_ts(); | |
10989 | 738 #endif |
10725 | 739 |
10989 | 740 /* safety checks */ |
12527 | 741 if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL)) |
10989 | 742 { |
743 return NULL; | |
744 } | |
10725 | 745 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
746 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
747 printf("%d\n", buffer_size*8); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
748 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
749 |
10989 | 750 frame_len = hDecoder->frameLength; |
10725 | 751 |
752 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
753 memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); |
10989 | 754 memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0])); |
10725 | 755 |
756 /* initialize the bitstream */ | |
12527 | 757 faad_initbits(&ld, buffer, buffer_size); |
10725 | 758 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
759 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
760 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
761 int i; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
762 for (i = 0; i < ((buffer_size+3)>>2); i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
763 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
764 uint8_t *buf; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
765 uint32_t temp = 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
766 buf = faad_getbitbuffer(&ld, 32); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
767 //temp = getdword((void*)buf); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
768 temp = *((uint32_t*)buf); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
769 printf("0x%.8X\n", temp); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
770 free(buf); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
771 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
772 faad_endbits(&ld); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
773 faad_initbits(&ld, buffer, buffer_size); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
774 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
775 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
776 |
10725 | 777 #ifdef DRM |
12527 | 778 if (hDecoder->object_type == DRM_ER_LC) |
10725 | 779 { |
12527 | 780 /* We do not support stereo right now */ |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
781 if (0) //(hDecoder->channelConfiguration == 2) |
12527 | 782 { |
783 hInfo->error = 8; // Throw CRC error | |
784 goto error; | |
785 } | |
786 | |
787 faad_getbits(&ld, 8 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
788 DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC")); |
10725 | 789 } |
790 #endif | |
791 | |
792 if (hDecoder->adts_header_present) | |
793 { | |
12527 | 794 adts_header adts; |
795 | |
10989 | 796 adts.old_format = hDecoder->config.useOldADTSFormat; |
12527 | 797 if ((hInfo->error = adts_frame(&adts, &ld)) > 0) |
10725 | 798 goto error; |
799 | |
800 /* MPEG2 does byte_alignment() here, | |
801 * but ADTS header is always multiple of 8 bits in MPEG2 | |
802 * so not needed to actually do it. | |
803 */ | |
804 } | |
805 | |
806 #ifdef ANALYSIS | |
807 dbg_count = 0; | |
808 #endif | |
809 | |
12527 | 810 /* decode the complete bitstream */ |
811 #ifdef SCALABLE_DEC | |
812 if ((hDecoder->object_type == 6) || (hDecoder->object_type == DRM_ER_LC)) | |
813 { | |
814 aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | |
815 } else { | |
816 #endif | |
817 raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | |
818 #ifdef SCALABLE_DEC | |
819 } | |
820 #endif | |
10725 | 821 |
822 channels = hDecoder->fr_channels; | |
823 | |
824 if (hInfo->error > 0) | |
825 goto error; | |
826 | |
12527 | 827 /* safety check */ |
828 if (channels == 0 || channels > MAX_CHANNELS) | |
829 { | |
830 /* invalid number of channels */ | |
831 hInfo->error = 12; | |
832 goto error; | |
833 } | |
10725 | 834 |
835 /* no more bit reading after this */ | |
12527 | 836 bitsconsumed = faad_get_processed_bits(&ld); |
10989 | 837 hInfo->bytesconsumed = bit2byte(bitsconsumed); |
12527 | 838 if (ld.error) |
10725 | 839 { |
840 hInfo->error = 14; | |
841 goto error; | |
842 } | |
12527 | 843 faad_endbits(&ld); |
10989 | 844 |
845 | |
10725 | 846 if (!hDecoder->adts_header_present && !hDecoder->adif_header_present) |
847 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
848 if (hDecoder->channelConfiguration == 0) |
10725 | 849 hDecoder->channelConfiguration = channels; |
850 | |
851 if (channels == 8) /* 7.1 */ | |
852 hDecoder->channelConfiguration = 7; | |
853 if (channels == 7) /* not a standard channelConfiguration */ | |
854 hDecoder->channelConfiguration = 0; | |
855 } | |
856 | |
857 if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix) | |
858 { | |
859 hDecoder->downMatrix = 1; | |
860 output_channels = 2; | |
861 } else { | |
862 output_channels = channels; | |
863 } | |
864 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
865 #if (defined(PS_DEC) || defined(DRM_PS)) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
866 hDecoder->upMatrix = 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
867 /* check if we have a mono file */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
868 if (output_channels == 1) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
869 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
870 /* upMatrix to 2 channels for implicit signalling of PS */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
871 hDecoder->upMatrix = 1; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
872 output_channels = 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
873 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
874 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
875 |
10725 | 876 /* Make a channel configuration based on either a PCE or a channelConfiguration */ |
877 create_channel_config(hDecoder, hInfo); | |
878 | |
879 /* number of samples in this frame */ | |
880 hInfo->samples = frame_len*output_channels; | |
881 /* number of channels in this frame */ | |
882 hInfo->channels = output_channels; | |
883 /* samplerate */ | |
10989 | 884 hInfo->samplerate = get_sample_rate(hDecoder->sf_index); |
885 /* object type */ | |
886 hInfo->object_type = hDecoder->object_type; | |
887 /* sbr */ | |
888 hInfo->sbr = NO_SBR; | |
889 /* header type */ | |
890 hInfo->header_type = RAW; | |
891 if (hDecoder->adif_header_present) | |
892 hInfo->header_type = ADIF; | |
893 if (hDecoder->adts_header_present) | |
894 hInfo->header_type = ADTS; | |
18141 | 895 #if (defined(PS_DEC) || defined(DRM_PS)) |
896 hInfo->ps = hDecoder->ps_used_global; | |
897 #endif | |
10725 | 898 |
899 /* check if frame has channel elements */ | |
900 if (channels == 0) | |
901 { | |
902 hDecoder->frame++; | |
903 return NULL; | |
904 } | |
905 | |
12527 | 906 /* allocate the buffer for the final samples */ |
907 if ((hDecoder->sample_buffer == NULL) || | |
908 (hDecoder->alloced_channels != output_channels)) | |
10725 | 909 { |
12527 | 910 static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), |
911 sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), | |
912 sizeof(int16_t), sizeof(int16_t), 0, 0, 0 | |
913 }; | |
914 uint8_t stride = str[hDecoder->config.outputFormat-1]; | |
10725 | 915 #ifdef SBR_DEC |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
916 if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1)) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
917 { |
12527 | 918 stride = 2 * stride; |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
919 } |
10725 | 920 #endif |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
921 /* check if we want to use internal sample_buffer */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
922 if (sample_buffer_size == 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
923 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
924 if (hDecoder->sample_buffer) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
925 faad_free(hDecoder->sample_buffer); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
926 hDecoder->sample_buffer = NULL; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
927 hDecoder->sample_buffer = faad_malloc(frame_len*output_channels*stride); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
928 } else if (sample_buffer_size < frame_len*output_channels*stride) { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
929 /* provided sample buffer is not big enough */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
930 hInfo->error = 27; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
931 return NULL; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
932 } |
12527 | 933 hDecoder->alloced_channels = output_channels; |
10725 | 934 } |
935 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
936 if (sample_buffer_size == 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
937 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
938 sample_buffer = hDecoder->sample_buffer; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
939 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
940 sample_buffer = *sample_buffer2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
941 } |
10725 | 942 |
943 #ifdef SBR_DEC | |
10989 | 944 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) |
10725 | 945 { |
12527 | 946 uint8_t ele; |
10989 | 947 |
12527 | 948 /* this data is different when SBR is used or when the data is upsampled */ |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
949 if (!hDecoder->downSampledSBR) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
950 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
951 frame_len *= 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
952 hInfo->samples *= 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
953 hInfo->samplerate *= 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
954 } |
12527 | 955 |
956 /* check if every element was provided with SBR data */ | |
957 for (ele = 0; ele < hDecoder->fr_ch_ele; ele++) | |
958 { | |
959 if (hDecoder->sbr[ele] == NULL) | |
960 { | |
961 hInfo->error = 25; | |
962 goto error; | |
963 } | |
964 } | |
965 | |
10989 | 966 /* sbr */ |
967 if (hDecoder->sbr_present_flag == 1) | |
968 { | |
969 hInfo->object_type = HE_AAC; | |
970 hInfo->sbr = SBR_UPSAMPLED; | |
971 } else { | |
972 hInfo->sbr = NO_SBR_UPSAMPLED; | |
973 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
974 if (hDecoder->downSampledSBR) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
975 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
976 hInfo->sbr = SBR_DOWNSAMPLED; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
977 } |
10725 | 978 } |
979 #endif | |
980 | |
12527 | 981 sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, |
982 output_channels, frame_len, hDecoder->config.outputFormat); | |
983 | |
984 | |
10725 | 985 hDecoder->postSeekResetFlag = 0; |
986 | |
987 hDecoder->frame++; | |
988 #ifdef LD_DEC | |
12527 | 989 if (hDecoder->object_type != LD) |
10725 | 990 { |
991 #endif | |
992 if (hDecoder->frame <= 1) | |
993 hInfo->samples = 0; | |
994 #ifdef LD_DEC | |
995 } else { | |
996 /* LD encoders will give lower delay */ | |
997 if (hDecoder->frame <= 0) | |
998 hInfo->samples = 0; | |
999 } | |
1000 #endif | |
1001 | |
1002 /* cleanup */ | |
1003 #ifdef ANALYSIS | |
1004 fflush(stdout); | |
1005 #endif | |
1006 | |
12527 | 1007 #ifdef PROFILE |
1008 count = faad_get_ts() - count; | |
1009 hDecoder->cycles += count; | |
1010 #endif | |
1011 | |
10725 | 1012 return sample_buffer; |
1013 | |
1014 error: | |
12527 | 1015 |
1016 faad_endbits(&ld); | |
10725 | 1017 |
1018 /* cleanup */ | |
1019 #ifdef ANALYSIS | |
1020 fflush(stdout); | |
1021 #endif | |
1022 | |
1023 return NULL; | |
1024 } |