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