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