Mercurial > mplayer.hg
annotate libfaad2/decoder.c @ 31620:508f24b02449
Remove disabled and pointless code.
author | reimar |
---|---|
date | Sat, 10 Jul 2010 23:18:45 +0000 |
parents | 86888a4c406e |
children |
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, |
31477 | 225 uint32_t *samplerate, uint8_t *channels, int latm_stream) |
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 } |
31477 | 260 else if (latm_stream) { |
261 return -1; | |
262 } | |
25836
bc425ba00960
added code to check and handle the presence of LATM streams in the init() and decode() functions
nicodvb
parents:
25835
diff
changeset
|
263 else |
10725 | 264 /* Check if an ADIF header is present */ |
265 if ((buffer[0] == 'A') && (buffer[1] == 'D') && | |
266 (buffer[2] == 'I') && (buffer[3] == 'F')) | |
267 { | |
268 hDecoder->adif_header_present = 1; | |
269 | |
270 get_adif_header(&adif, &ld); | |
271 faad_byte_align(&ld); | |
272 | |
273 hDecoder->sf_index = adif.pce[0].sf_index; | |
10989 | 274 hDecoder->object_type = adif.pce[0].object_type + 1; |
10725 | 275 |
10989 | 276 *samplerate = get_sample_rate(hDecoder->sf_index); |
10725 | 277 *channels = adif.pce[0].channels; |
278 | |
279 memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config)); | |
280 hDecoder->pce_set = 1; | |
281 | |
282 bits = bit2byte(faad_get_processed_bits(&ld)); | |
283 | |
284 /* Check if an ADTS header is present */ | |
285 } else if (faad_showbits(&ld, 12) == 0xfff) { | |
286 hDecoder->adts_header_present = 1; | |
287 | |
10989 | 288 adts.old_format = hDecoder->config.useOldADTSFormat; |
10725 | 289 adts_frame(&adts, &ld); |
290 | |
291 hDecoder->sf_index = adts.sf_index; | |
10989 | 292 hDecoder->object_type = adts.profile + 1; |
10725 | 293 |
10989 | 294 *samplerate = get_sample_rate(hDecoder->sf_index); |
10725 | 295 *channels = (adts.channel_configuration > 6) ? |
296 2 : adts.channel_configuration; | |
297 } | |
298 | |
299 if (ld.error) | |
300 { | |
301 faad_endbits(&ld); | |
302 return -1; | |
303 } | |
304 faad_endbits(&ld); | |
305 } | |
306 hDecoder->channelConfiguration = *channels; | |
307 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
308 #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
|
309 /* 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
|
310 if (*channels == 1) |
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 /* 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
|
313 *channels = 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
314 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
315 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
316 |
10989 | 317 #ifdef SBR_DEC |
318 /* implicit signalling */ | |
12527 | 319 if (*samplerate <= 24000 && !(hDecoder->config.dontUpSampleImplicitSBR)) |
10989 | 320 { |
321 *samplerate *= 2; | |
322 hDecoder->forceUpSampling = 1; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
323 } 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
|
324 hDecoder->downSampledSBR = 1; |
10989 | 325 } |
326 #endif | |
327 | |
10725 | 328 /* must be done before frameLength is divided by 2 for LD */ |
329 #ifdef SSR_DEC | |
330 if (hDecoder->object_type == SSR) | |
331 hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); | |
332 else | |
333 #endif | |
334 hDecoder->fb = filter_bank_init(hDecoder->frameLength); | |
335 | |
336 #ifdef LD_DEC | |
337 if (hDecoder->object_type == LD) | |
338 hDecoder->frameLength >>= 1; | |
339 #endif | |
340 | |
341 if (can_decode_ot(hDecoder->object_type) < 0) | |
342 return -1; | |
343 | |
344 return bits; | |
345 } | |
346 | |
347 /* 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
|
348 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
|
349 uint32_t SizeOfDecoderSpecificInfo, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
350 uint32_t *samplerate, uint8_t *channels) |
10725 | 351 { |
352 int8_t rc; | |
353 mp4AudioSpecificConfig mp4ASC; | |
354 | |
355 if((hDecoder == NULL) | |
356 || (pBuffer == NULL) | |
357 || (SizeOfDecoderSpecificInfo < 2) | |
358 || (samplerate == NULL) | |
359 || (channels == NULL)) | |
360 { | |
361 return -1; | |
362 } | |
363 | |
10989 | 364 hDecoder->adif_header_present = 0; |
365 hDecoder->adts_header_present = 0; | |
366 | |
10725 | 367 /* decode the audio specific config */ |
368 rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC, | |
25835
645cbba10a57
added AudioSpecificConfigFromBitfile() -that reads from an initizialized
nicodvb
parents:
18141
diff
changeset
|
369 &(hDecoder->pce), hDecoder->latm_header_present); |
10725 | 370 |
371 /* copy the relevant info to the decoder handle */ | |
372 *samplerate = mp4ASC.samplingFrequency; | |
373 if (mp4ASC.channelsConfiguration) | |
374 { | |
375 *channels = mp4ASC.channelsConfiguration; | |
376 } else { | |
377 *channels = hDecoder->pce.channels; | |
378 hDecoder->pce_set = 1; | |
379 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
380 #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
|
381 /* 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
|
382 if (*channels == 1) |
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 /* 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
|
385 *channels = 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
386 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
387 #endif |
10725 | 388 hDecoder->sf_index = mp4ASC.samplingFrequencyIndex; |
389 hDecoder->object_type = mp4ASC.objectTypeIndex; | |
10989 | 390 #ifdef ERROR_RESILIENCE |
10725 | 391 hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag; |
392 hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag; | |
393 hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag; | |
10989 | 394 #endif |
10725 | 395 #ifdef SBR_DEC |
396 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
|
397 hDecoder->downSampledSBR = mp4ASC.downSampledSBR; |
12527 | 398 if (hDecoder->config.dontUpSampleImplicitSBR == 0) |
399 hDecoder->forceUpSampling = mp4ASC.forceUpSampling; | |
400 else | |
401 hDecoder->forceUpSampling = 0; | |
10725 | 402 |
403 /* 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
|
404 if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1) |
10725 | 405 { |
406 hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2); | |
407 } | |
408 #endif | |
409 | |
410 if (rc != 0) | |
411 { | |
412 return rc; | |
413 } | |
414 hDecoder->channelConfiguration = mp4ASC.channelsConfiguration; | |
415 if (mp4ASC.frameLengthFlag) | |
12527 | 416 #ifdef ALLOW_SMALL_FRAMELENGTH |
10725 | 417 hDecoder->frameLength = 960; |
12527 | 418 #else |
419 return -1; | |
420 #endif | |
10725 | 421 |
422 /* must be done before frameLength is divided by 2 for LD */ | |
423 #ifdef SSR_DEC | |
424 if (hDecoder->object_type == SSR) | |
425 hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); | |
426 else | |
427 #endif | |
428 hDecoder->fb = filter_bank_init(hDecoder->frameLength); | |
429 | |
430 #ifdef LD_DEC | |
431 if (hDecoder->object_type == LD) | |
432 hDecoder->frameLength >>= 1; | |
433 #endif | |
434 | |
435 return 0; | |
436 } | |
437 | |
12527 | 438 #ifdef DRM |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
439 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
|
440 uint8_t channels) |
10725 | 441 { |
12527 | 442 if (hDecoder == NULL) |
443 return 1; /* error */ | |
444 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
445 NeAACDecClose(*hDecoder); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
446 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
447 *hDecoder = NeAACDecOpen(); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
448 |
10725 | 449 /* 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
|
450 (*hDecoder)->config.defObjectType = DRM_ER_LC; |
10725 | 451 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
452 (*hDecoder)->config.defSampleRate = samplerate; |
10989 | 453 #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
|
454 (*hDecoder)->aacSectionDataResilienceFlag = 1; /* VCB11 */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
455 (*hDecoder)->aacScalefactorDataResilienceFlag = 0; /* no RVLC */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
456 (*hDecoder)->aacSpectralDataResilienceFlag = 1; /* HCR */ |
10989 | 457 #endif |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
458 (*hDecoder)->frameLength = 960; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
459 (*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
|
460 (*hDecoder)->object_type = (*hDecoder)->config.defObjectType; |
10989 | 461 |
462 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
|
463 (*hDecoder)->channelConfiguration = 2; |
10989 | 464 else |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
465 (*hDecoder)->channelConfiguration = 1; |
10989 | 466 |
467 #ifdef SBR_DEC | |
468 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
|
469 (*hDecoder)->sbr_present_flag = 0; |
10989 | 470 else |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
25836
diff
changeset
|
471 (*hDecoder)->sbr_present_flag = 1; |
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
25836
diff
changeset
|
472 #endif |
10725 | 473 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
474 (*hDecoder)->fb = filter_bank_init((*hDecoder)->frameLength); |
10725 | 475 |
476 return 0; | |
477 } | |
12527 | 478 #endif |
10725 | 479 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
480 void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder) |
10725 | 481 { |
482 uint8_t i; | |
483 | |
484 if (hDecoder == NULL) | |
485 return; | |
486 | |
12527 | 487 #ifdef PROFILE |
488 printf("AAC decoder total: %I64d cycles\n", hDecoder->cycles); | |
489 printf("requant: %I64d cycles\n", hDecoder->requant_cycles); | |
490 printf("spectral_data: %I64d cycles\n", hDecoder->spectral_cycles); | |
491 printf("scalefactors: %I64d cycles\n", hDecoder->scalefac_cycles); | |
492 printf("output: %I64d cycles\n", hDecoder->output_cycles); | |
493 #endif | |
494 | |
10725 | 495 for (i = 0; i < MAX_CHANNELS; i++) |
496 { | |
12527 | 497 if (hDecoder->time_out[i]) faad_free(hDecoder->time_out[i]); |
498 if (hDecoder->fb_intermed[i]) faad_free(hDecoder->fb_intermed[i]); | |
10725 | 499 #ifdef SSR_DEC |
12527 | 500 if (hDecoder->ssr_overlap[i]) faad_free(hDecoder->ssr_overlap[i]); |
501 if (hDecoder->prev_fmd[i]) faad_free(hDecoder->prev_fmd[i]); | |
10725 | 502 #endif |
503 #ifdef MAIN_DEC | |
12527 | 504 if (hDecoder->pred_stat[i]) faad_free(hDecoder->pred_stat[i]); |
10725 | 505 #endif |
506 #ifdef LTP_DEC | |
12527 | 507 if (hDecoder->lt_pred_stat[i]) faad_free(hDecoder->lt_pred_stat[i]); |
10725 | 508 #endif |
509 } | |
510 | |
511 #ifdef SSR_DEC | |
512 if (hDecoder->object_type == SSR) | |
513 ssr_filter_bank_end(hDecoder->fb); | |
514 else | |
515 #endif | |
516 filter_bank_end(hDecoder->fb); | |
517 | |
518 drc_end(hDecoder->drc); | |
519 | |
12527 | 520 if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer); |
10725 | 521 |
522 #ifdef SBR_DEC | |
12527 | 523 for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
10725 | 524 { |
525 if (hDecoder->sbr[i]) | |
526 sbrDecodeEnd(hDecoder->sbr[i]); | |
527 } | |
528 #endif | |
529 | |
12527 | 530 if (hDecoder) faad_free(hDecoder); |
10725 | 531 } |
532 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
533 void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, int32_t frame) |
10725 | 534 { |
535 if (hDecoder) | |
536 { | |
537 hDecoder->postSeekResetFlag = 1; | |
538 | |
539 if (frame != -1) | |
540 hDecoder->frame = frame; | |
541 } | |
542 } | |
543 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
544 static void create_channel_config(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo) |
10725 | 545 { |
546 hInfo->num_front_channels = 0; | |
547 hInfo->num_side_channels = 0; | |
548 hInfo->num_back_channels = 0; | |
549 hInfo->num_lfe_channels = 0; | |
550 memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | |
551 | |
552 if (hDecoder->downMatrix) | |
553 { | |
554 hInfo->num_front_channels = 2; | |
555 hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | |
556 hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | |
557 return; | |
558 } | |
559 | |
560 /* check if there is a PCE */ | |
561 if (hDecoder->pce_set) | |
562 { | |
563 uint8_t i, chpos = 0; | |
564 uint8_t chdir, back_center = 0; | |
565 | |
566 hInfo->num_front_channels = hDecoder->pce.num_front_channels; | |
567 hInfo->num_side_channels = hDecoder->pce.num_side_channels; | |
568 hInfo->num_back_channels = hDecoder->pce.num_back_channels; | |
569 hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | |
570 | |
571 chdir = hInfo->num_front_channels; | |
572 if (chdir & 1) | |
573 { | |
574 hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | |
575 chdir--; | |
576 } | |
577 for (i = 0; i < chdir; i += 2) | |
578 { | |
579 hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | |
580 hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | |
581 } | |
582 | |
583 for (i = 0; i < hInfo->num_side_channels; i += 2) | |
584 { | |
585 hInfo->channel_position[chpos++] = SIDE_CHANNEL_LEFT; | |
586 hInfo->channel_position[chpos++] = SIDE_CHANNEL_RIGHT; | |
587 } | |
588 | |
589 chdir = hInfo->num_back_channels; | |
590 if (chdir & 1) | |
591 { | |
592 back_center = 1; | |
593 chdir--; | |
594 } | |
595 for (i = 0; i < chdir; i += 2) | |
596 { | |
597 hInfo->channel_position[chpos++] = BACK_CHANNEL_LEFT; | |
598 hInfo->channel_position[chpos++] = BACK_CHANNEL_RIGHT; | |
599 } | |
600 if (back_center) | |
601 { | |
602 hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | |
603 } | |
604 | |
605 for (i = 0; i < hInfo->num_lfe_channels; i++) | |
606 { | |
607 hInfo->channel_position[chpos++] = LFE_CHANNEL; | |
608 } | |
609 | |
610 } else { | |
611 switch (hDecoder->channelConfiguration) | |
612 { | |
613 case 1: | |
614 hInfo->num_front_channels = 1; | |
615 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
616 break; | |
617 case 2: | |
618 hInfo->num_front_channels = 2; | |
619 hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | |
620 hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | |
621 break; | |
622 case 3: | |
623 hInfo->num_front_channels = 3; | |
624 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
625 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
626 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
627 break; | |
628 case 4: | |
629 hInfo->num_front_channels = 3; | |
630 hInfo->num_back_channels = 1; | |
631 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
632 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
633 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
634 hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | |
635 break; | |
636 case 5: | |
637 hInfo->num_front_channels = 3; | |
638 hInfo->num_back_channels = 2; | |
639 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
640 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
641 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
642 hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | |
643 hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | |
644 break; | |
645 case 6: | |
646 hInfo->num_front_channels = 3; | |
647 hInfo->num_back_channels = 2; | |
648 hInfo->num_lfe_channels = 1; | |
649 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
650 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
651 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
652 hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | |
653 hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | |
654 hInfo->channel_position[5] = LFE_CHANNEL; | |
655 break; | |
656 case 7: | |
657 hInfo->num_front_channels = 3; | |
658 hInfo->num_side_channels = 2; | |
659 hInfo->num_back_channels = 2; | |
660 hInfo->num_lfe_channels = 1; | |
661 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
662 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | |
663 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | |
664 hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | |
665 hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | |
666 hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | |
667 hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | |
668 hInfo->channel_position[7] = LFE_CHANNEL; | |
669 break; | |
670 default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | |
671 { | |
672 uint8_t i; | |
673 uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | |
674 if (ch & 1) /* there's either a center front or a center back channel */ | |
675 { | |
676 uint8_t ch1 = (ch-1)/2; | |
677 if (hDecoder->first_syn_ele == ID_SCE) | |
678 { | |
679 hInfo->num_front_channels = ch1 + 1; | |
680 hInfo->num_back_channels = ch1; | |
681 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
682 for (i = 1; i <= ch1; i+=2) | |
683 { | |
684 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | |
685 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | |
686 } | |
687 for (i = ch1+1; i < ch; i+=2) | |
688 { | |
689 hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | |
690 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | |
691 } | |
692 } else { | |
693 hInfo->num_front_channels = ch1; | |
694 hInfo->num_back_channels = ch1 + 1; | |
695 for (i = 0; i < ch1; i+=2) | |
696 { | |
697 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | |
698 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | |
699 } | |
700 for (i = ch1; i < ch-1; i+=2) | |
701 { | |
702 hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | |
703 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | |
704 } | |
705 hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | |
706 } | |
707 } else { | |
708 uint8_t ch1 = (ch)/2; | |
709 hInfo->num_front_channels = ch1; | |
710 hInfo->num_back_channels = ch1; | |
711 if (ch1 & 1) | |
712 { | |
713 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | |
714 for (i = 1; i <= ch1; i+=2) | |
715 { | |
716 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | |
717 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | |
718 } | |
719 for (i = ch1+1; i < ch-1; i+=2) | |
720 { | |
721 hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | |
722 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | |
723 } | |
724 hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | |
725 } else { | |
726 for (i = 0; i < ch1; i+=2) | |
727 { | |
728 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | |
729 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | |
730 } | |
731 for (i = ch1; i < ch; i+=2) | |
732 { | |
733 hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | |
734 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | |
735 } | |
736 } | |
737 } | |
738 hInfo->num_lfe_channels = hDecoder->has_lfe; | |
739 for (i = ch; i < hDecoder->fr_channels; i++) | |
740 { | |
741 hInfo->channel_position[i] = LFE_CHANNEL; | |
742 } | |
743 } | |
744 break; | |
745 } | |
746 } | |
747 } | |
748 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
749 void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
750 NeAACDecFrameInfo *hInfo, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
751 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
|
752 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
753 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
|
754 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
755 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
756 void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
757 NeAACDecFrameInfo *hInfo, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
758 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
|
759 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
|
760 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
761 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
|
762 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
763 hInfo->error = 27; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
764 return NULL; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
765 } |
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 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
|
768 sample_buffer, sample_buffer_size); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
769 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
770 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
771 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
|
772 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
|
773 void **sample_buffer2, uint32_t sample_buffer_size) |
10725 | 774 { |
12527 | 775 uint8_t channels = 0; |
10725 | 776 uint8_t output_channels = 0; |
12527 | 777 bitfile ld; |
10989 | 778 uint32_t bitsconsumed; |
12527 | 779 uint16_t frame_len; |
780 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
|
781 uint32_t startbit=0, endbit=0, payload_bits=0; |
12527 | 782 |
783 #ifdef PROFILE | |
784 int64_t count = faad_get_ts(); | |
10989 | 785 #endif |
10725 | 786 |
10989 | 787 /* safety checks */ |
12527 | 788 if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL)) |
10989 | 789 { |
790 return NULL; | |
791 } | |
10725 | 792 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
793 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
794 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
|
795 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
796 |
10989 | 797 frame_len = hDecoder->frameLength; |
10725 | 798 |
799 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
800 memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); |
10989 | 801 memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0])); |
10725 | 802 |
803 /* initialize the bitstream */ | |
12527 | 804 faad_initbits(&ld, buffer, buffer_size); |
10725 | 805 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
806 #if 0 |
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 int i; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
809 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
|
810 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
811 uint8_t *buf; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
812 uint32_t temp = 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
813 buf = faad_getbitbuffer(&ld, 32); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
814 //temp = getdword((void*)buf); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
815 temp = *((uint32_t*)buf); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
816 printf("0x%.8X\n", temp); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
817 free(buf); |
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 faad_endbits(&ld); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
820 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
|
821 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
822 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
823 |
25836
bc425ba00960
added code to check and handle the presence of LATM streams in the init() and decode() functions
nicodvb
parents:
25835
diff
changeset
|
824 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
|
825 { |
bc425ba00960
added code to check and handle the presence of LATM streams in the init() and decode() functions
nicodvb
parents:
25835
diff
changeset
|
826 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
|
827 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
|
828 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
|
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 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
|
831 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
|
832 } |
bc425ba00960
added code to check and handle the presence of LATM streams in the init() and decode() functions
nicodvb
parents:
25835
diff
changeset
|
833 } |
bc425ba00960
added code to check and handle the presence of LATM streams in the init() and decode() functions
nicodvb
parents:
25835
diff
changeset
|
834 |
10725 | 835 #ifdef DRM |
12527 | 836 if (hDecoder->object_type == DRM_ER_LC) |
10725 | 837 { |
12527 | 838 /* 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
|
839 if (0) //(hDecoder->channelConfiguration == 2) |
12527 | 840 { |
841 hInfo->error = 8; // Throw CRC error | |
842 goto error; | |
843 } | |
844 | |
845 faad_getbits(&ld, 8 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
846 DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC")); |
10725 | 847 } |
848 #endif | |
849 | |
850 if (hDecoder->adts_header_present) | |
851 { | |
12527 | 852 adts_header adts; |
853 | |
10989 | 854 adts.old_format = hDecoder->config.useOldADTSFormat; |
12527 | 855 if ((hInfo->error = adts_frame(&adts, &ld)) > 0) |
10725 | 856 goto error; |
857 | |
858 /* MPEG2 does byte_alignment() here, | |
859 * but ADTS header is always multiple of 8 bits in MPEG2 | |
860 * so not needed to actually do it. | |
861 */ | |
862 } | |
863 | |
864 #ifdef ANALYSIS | |
865 dbg_count = 0; | |
866 #endif | |
867 | |
12527 | 868 /* decode the complete bitstream */ |
869 #ifdef SCALABLE_DEC | |
870 if ((hDecoder->object_type == 6) || (hDecoder->object_type == DRM_ER_LC)) | |
871 { | |
872 aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | |
873 } else { | |
874 #endif | |
875 raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | |
876 #ifdef SCALABLE_DEC | |
877 } | |
878 #endif | |
10725 | 879 |
25836
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(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
|
881 { |
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 = 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
|
883 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
|
884 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
|
885 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
|
886 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
|
887 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
|
888 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
|
889 } |
bc425ba00960
added code to check and handle the presence of LATM streams in the init() and decode() functions
nicodvb
parents:
25835
diff
changeset
|
890 |
10725 | 891 channels = hDecoder->fr_channels; |
892 | |
893 if (hInfo->error > 0) | |
894 goto error; | |
895 | |
12527 | 896 /* safety check */ |
897 if (channels == 0 || channels > MAX_CHANNELS) | |
898 { | |
899 /* invalid number of channels */ | |
900 hInfo->error = 12; | |
901 goto error; | |
902 } | |
10725 | 903 |
904 /* no more bit reading after this */ | |
12527 | 905 bitsconsumed = faad_get_processed_bits(&ld); |
10989 | 906 hInfo->bytesconsumed = bit2byte(bitsconsumed); |
12527 | 907 if (ld.error) |
10725 | 908 { |
909 hInfo->error = 14; | |
910 goto error; | |
911 } | |
12527 | 912 faad_endbits(&ld); |
10989 | 913 |
914 | |
25836
bc425ba00960
added code to check and handle the presence of LATM streams in the init() and decode() functions
nicodvb
parents:
25835
diff
changeset
|
915 if (!hDecoder->adts_header_present && !hDecoder->adif_header_present && !hDecoder->latm_header_present) |
10725 | 916 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
917 if (hDecoder->channelConfiguration == 0) |
10725 | 918 hDecoder->channelConfiguration = channels; |
919 | |
920 if (channels == 8) /* 7.1 */ | |
921 hDecoder->channelConfiguration = 7; | |
922 if (channels == 7) /* not a standard channelConfiguration */ | |
923 hDecoder->channelConfiguration = 0; | |
924 } | |
925 | |
926 if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix) | |
927 { | |
928 hDecoder->downMatrix = 1; | |
929 output_channels = 2; | |
930 } else { | |
931 output_channels = channels; | |
932 } | |
933 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
934 #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
|
935 hDecoder->upMatrix = 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
936 /* 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
|
937 if (output_channels == 1) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
938 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
939 /* 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
|
940 hDecoder->upMatrix = 1; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
941 output_channels = 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
942 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
943 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
944 |
10725 | 945 /* Make a channel configuration based on either a PCE or a channelConfiguration */ |
946 create_channel_config(hDecoder, hInfo); | |
947 | |
948 /* number of samples in this frame */ | |
949 hInfo->samples = frame_len*output_channels; | |
950 /* number of channels in this frame */ | |
951 hInfo->channels = output_channels; | |
952 /* samplerate */ | |
10989 | 953 hInfo->samplerate = get_sample_rate(hDecoder->sf_index); |
954 /* object type */ | |
955 hInfo->object_type = hDecoder->object_type; | |
956 /* sbr */ | |
957 hInfo->sbr = NO_SBR; | |
958 /* header type */ | |
959 hInfo->header_type = RAW; | |
960 if (hDecoder->adif_header_present) | |
961 hInfo->header_type = ADIF; | |
962 if (hDecoder->adts_header_present) | |
963 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
|
964 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
|
965 hInfo->header_type = LATM; |
18141 | 966 #if (defined(PS_DEC) || defined(DRM_PS)) |
967 hInfo->ps = hDecoder->ps_used_global; | |
968 #endif | |
10725 | 969 |
970 /* check if frame has channel elements */ | |
971 if (channels == 0) | |
972 { | |
973 hDecoder->frame++; | |
974 return NULL; | |
975 } | |
976 | |
12527 | 977 /* allocate the buffer for the final samples */ |
978 if ((hDecoder->sample_buffer == NULL) || | |
979 (hDecoder->alloced_channels != output_channels)) | |
10725 | 980 { |
12527 | 981 static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), |
982 sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), | |
983 sizeof(int16_t), sizeof(int16_t), 0, 0, 0 | |
984 }; | |
985 uint8_t stride = str[hDecoder->config.outputFormat-1]; | |
10725 | 986 #ifdef SBR_DEC |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
987 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
|
988 { |
12527 | 989 stride = 2 * stride; |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
990 } |
10725 | 991 #endif |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
992 /* 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
|
993 if (sample_buffer_size == 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
994 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
995 if (hDecoder->sample_buffer) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
996 faad_free(hDecoder->sample_buffer); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
997 hDecoder->sample_buffer = NULL; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
998 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
|
999 } 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
|
1000 /* 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
|
1001 hInfo->error = 27; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1002 return NULL; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1003 } |
12527 | 1004 hDecoder->alloced_channels = output_channels; |
10725 | 1005 } |
1006 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1007 if (sample_buffer_size == 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1008 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1009 sample_buffer = hDecoder->sample_buffer; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1010 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1011 sample_buffer = *sample_buffer2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1012 } |
10725 | 1013 |
1014 #ifdef SBR_DEC | |
10989 | 1015 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) |
10725 | 1016 { |
12527 | 1017 uint8_t ele; |
10989 | 1018 |
12527 | 1019 /* 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
|
1020 if (!hDecoder->downSampledSBR) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1021 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1022 frame_len *= 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1023 hInfo->samples *= 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1024 hInfo->samplerate *= 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1025 } |
12527 | 1026 |
1027 /* check if every element was provided with SBR data */ | |
1028 for (ele = 0; ele < hDecoder->fr_ch_ele; ele++) | |
1029 { | |
1030 if (hDecoder->sbr[ele] == NULL) | |
1031 { | |
1032 hInfo->error = 25; | |
1033 goto error; | |
1034 } | |
1035 } | |
1036 | |
10989 | 1037 /* sbr */ |
1038 if (hDecoder->sbr_present_flag == 1) | |
1039 { | |
1040 hInfo->object_type = HE_AAC; | |
1041 hInfo->sbr = SBR_UPSAMPLED; | |
1042 } else { | |
1043 hInfo->sbr = NO_SBR_UPSAMPLED; | |
1044 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1045 if (hDecoder->downSampledSBR) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1046 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1047 hInfo->sbr = SBR_DOWNSAMPLED; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1048 } |
10725 | 1049 } |
1050 #endif | |
1051 | |
12527 | 1052 sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, |
1053 output_channels, frame_len, hDecoder->config.outputFormat); | |
1054 | |
1055 | |
10725 | 1056 hDecoder->postSeekResetFlag = 0; |
1057 | |
1058 hDecoder->frame++; | |
1059 #ifdef LD_DEC | |
12527 | 1060 if (hDecoder->object_type != LD) |
10725 | 1061 { |
1062 #endif | |
1063 if (hDecoder->frame <= 1) | |
1064 hInfo->samples = 0; | |
1065 #ifdef LD_DEC | |
1066 } else { | |
1067 /* LD encoders will give lower delay */ | |
1068 if (hDecoder->frame <= 0) | |
1069 hInfo->samples = 0; | |
1070 } | |
1071 #endif | |
1072 | |
1073 /* cleanup */ | |
1074 #ifdef ANALYSIS | |
1075 fflush(stdout); | |
1076 #endif | |
1077 | |
12527 | 1078 #ifdef PROFILE |
1079 count = faad_get_ts() - count; | |
1080 hDecoder->cycles += count; | |
1081 #endif | |
1082 | |
10725 | 1083 return sample_buffer; |
1084 | |
1085 error: | |
12527 | 1086 |
1087 faad_endbits(&ld); | |
10725 | 1088 |
1089 /* cleanup */ | |
1090 #ifdef ANALYSIS | |
1091 fflush(stdout); | |
1092 #endif | |
1093 | |
1094 return NULL; | |
1095 } |