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