1 /******************************************************************************
2 * *
3 * Copyright (C) 2018 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #include <stdlib.h>
21 #include <ixheaacd_type_def.h>
22 #include "ixheaacd_error_standards.h"
23 #include "ixheaacd_constants.h"
24 #include <ixheaacd_basic_ops32.h>
25 #include <ixheaacd_basic_ops16.h>
26 #include <ixheaacd_basic_ops40.h>
27 #include "ixheaacd_sbr_common.h"
28
29 #include "ixheaacd_bitbuffer.h"
30 #include "ixheaacd_defines.h"
31 #include <ixheaacd_aac_rom.h>
32
33 #include "ixheaacd_sbrdecsettings.h"
34 #include "ixheaacd_sbr_scale.h"
35 #include "ixheaacd_env_extr_part.h"
36 #include <ixheaacd_sbr_rom.h>
37
38 #include "ixheaacd_lpp_tran.h"
39 #include "ixheaacd_hybrid.h"
40 #include "ixheaacd_ps_dec.h"
41
42 #include "ixheaacd_env_extr.h"
43 #include "ixheaacd_common_rom.h"
44
45 #include "ixheaacd_pulsedata.h"
46
47 #include "ixheaacd_pns.h"
48 #include "ixheaacd_drc_data_struct.h"
49
50 #include "ixheaacd_lt_predict.h"
51
52 #include "ixheaacd_channelinfo.h"
53 #include "ixheaacd_drc_dec.h"
54 #include "ixheaacd_sbrdecoder.h"
55 #include "ixheaacd_block.h"
56 #include "ixheaacd_channel.h"
57
58 #include "ixheaacd_adts.h"
59 #include "ixheaacd_audioobjtypes.h"
60 #include "ixheaacd_sbrdecoder.h"
61 #include "ixheaacd_memory_standards.h"
62
63 #include "ixheaacd_latmdemux.h"
64
65 #include "ixheaacd_aacdec.h"
66 #include "ixheaacd_mps_polyphase.h"
67 #include "ixheaacd_config.h"
68 #include "ixheaacd_mps_dec.h"
69
70 #include "ixheaacd_struct_def.h"
71 #include "ixheaacd_error_codes.h"
72 #include "ixheaacd_definitions.h"
73 #include "ixheaacd_adts_crc_check.h"
74
75 #include "ixheaacd_headerdecode.h"
76
77 #include "ixheaacd_interface.h"
78 #include "ixheaacd_info.h"
79
80 #include "ixheaacd_config.h"
81
82 #include "ixheaacd_struct.h"
83 #include "ixheaacd_function_selector.h"
84
85 #include "ixheaacd_error_standards.h"
86
87 #undef ALLOW_SMALL_FRAMELENGTH
88
89 #define ALLOW_SMALL_FRAMELENGTH
90 #ifdef ALLOW_SMALL_FRAMELENGTH
91 #undef FRAME_SIZE_SMALL
92 #define FRAME_SIZE_SMALL 960
93 #endif
94
95 extern const WORD32 ixheaacd_sampl_freq_idx_table[17];
96
97 #define AAC_LC_PROFILE (2)
98
99 #define ADTS_HEADER_LENGTH 7
100
101 #undef ALLOW_SMALL_FRAMELENGTH
102
103 #define ALLOW_SMALL_FRAMELENGTH
104
105 static PLATFORM_INLINE VOID
ixheaacd_aac_bytealign(struct ia_bit_buf_struct * it_bit_buff)106 ixheaacd_aac_bytealign(struct ia_bit_buf_struct *it_bit_buff) {
107 WORD16 num_bit;
108 num_bit = (it_bit_buff->bit_pos + 1);
109 if (num_bit != 8) {
110 it_bit_buff->bit_pos = 7;
111 it_bit_buff->cnt_bits -= num_bit;
112 it_bit_buff->ptr_read_next += 1;
113 }
114 }
115
ixheaacd_read_pce_channel_info(WORD32 ch,WORD8 * ptr_is_cpe,WORD8 * ptr_tag_select,struct ia_bit_buf_struct * it_bit_buff)116 WORD32 ixheaacd_read_pce_channel_info(WORD32 ch, WORD8 *ptr_is_cpe,
117 WORD8 *ptr_tag_select,
118 struct ia_bit_buf_struct *it_bit_buff) {
119 WORD32 num_ch = 0, i, tmp;
120 for (i = 0; i < ch; i++) {
121 tmp = ixheaacd_read_bits_buf(it_bit_buff, 5);
122 ptr_is_cpe[i] = (tmp & 0x10) >> 4;
123
124 if (ptr_is_cpe[i]) {
125 num_ch += 2;
126 } else {
127 num_ch++;
128 }
129
130 ptr_tag_select[i] = (tmp & 0xF);
131 }
132 return num_ch;
133 }
134
ixheaacd_read_pce_mixdown_data(struct ia_bit_buf_struct * it_bit_buff,WORD32 mix_down_present,WORD32 mix_down_element_no)135 VOID ixheaacd_read_pce_mixdown_data(struct ia_bit_buf_struct *it_bit_buff,
136 WORD32 mix_down_present,
137 WORD32 mix_down_element_no) {
138 WORD32 mix_down_flag = ixheaacd_read_bits_buf(it_bit_buff, mix_down_present);
139 if (mix_down_flag == 1) {
140 ixheaacd_read_bits_buf(it_bit_buff, mix_down_element_no);
141 }
142 }
143
ixheaacd_skip_bits(struct ia_bit_buf_struct * it_bit_buff,WORD32 bits,WORD32 num_element)144 VOID ixheaacd_skip_bits(struct ia_bit_buf_struct *it_bit_buff, WORD32 bits,
145 WORD32 num_element) {
146 WORD32 i;
147 for (i = 0; i < num_element; i++) {
148 ixheaacd_read_bits_buf(it_bit_buff, bits);
149 }
150 }
151
ixheaacd_read_prog_config_element(ia_program_config_struct * ptr_config_element,struct ia_bit_buf_struct * it_bit_buff)152 WORD32 ixheaacd_read_prog_config_element(
153 ia_program_config_struct *ptr_config_element,
154 struct ia_bit_buf_struct *it_bit_buff) {
155 WORD32 i, tmp;
156 WORD count = 0, num_ch = 0;
157
158 tmp = ixheaacd_read_bits_buf(it_bit_buff, 6);
159
160 ptr_config_element->element_instance_tag = (tmp >> 2);
161 ptr_config_element->object_type = tmp & 0x3;
162
163 if ((ptr_config_element->object_type + 1) != 2
164
165 && (ptr_config_element->object_type + 1) != 4
166
167 ) {
168 return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL;
169 }
170
171 ptr_config_element->samp_freq_index = ixheaacd_read_bits_buf(it_bit_buff, 4);
172 if (ptr_config_element->samp_freq_index > 11) {
173 return IA_ENHAACPLUS_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR;
174 }
175
176 tmp = ixheaacd_read_bits_buf(it_bit_buff, 21);
177
178 count += ptr_config_element->num_front_channel_elements = (tmp >> 17);
179 count += ptr_config_element->num_side_channel_elements =
180 (tmp & 0x1E000) >> 13;
181 count += ptr_config_element->num_back_channel_elements = (tmp & 0x1E00) >> 9;
182 count += ptr_config_element->num_lfe_channel_elements = (tmp & 0x180) >> 7;
183 ptr_config_element->num_assoc_data_elements = (tmp & 0x70) >> 4;
184 count += ptr_config_element->num_valid_cc_elements = tmp & 0xF;
185
186 if (count > MAX_BS_ELEMENT) {
187 return IA_ENHAACPLUS_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX;
188 }
189
190 ixheaacd_read_pce_mixdown_data(it_bit_buff, 1, 4);
191 ixheaacd_read_pce_mixdown_data(it_bit_buff, 1, 4);
192 ixheaacd_read_pce_mixdown_data(it_bit_buff, 1, 3);
193
194 num_ch += ixheaacd_read_pce_channel_info(
195 ptr_config_element->num_front_channel_elements,
196 ptr_config_element->front_element_is_cpe,
197 ptr_config_element->front_element_tag_select, it_bit_buff);
198
199 num_ch += ixheaacd_read_pce_channel_info(
200 ptr_config_element->num_side_channel_elements,
201 ptr_config_element->side_element_is_cpe,
202 ptr_config_element->side_element_tag_select, it_bit_buff);
203
204 num_ch += ixheaacd_read_pce_channel_info(
205 ptr_config_element->num_back_channel_elements,
206 ptr_config_element->back_element_is_cpe,
207 ptr_config_element->back_element_tag_select, it_bit_buff);
208
209 num_ch += ptr_config_element->num_lfe_channel_elements;
210
211 for (i = 0; i < (ptr_config_element->num_lfe_channel_elements); i++) {
212 ptr_config_element->lfe_element_tag_select[i] =
213 ixheaacd_read_bits_buf(it_bit_buff, 4);
214 }
215
216 ptr_config_element->channels = num_ch;
217
218 for (i = 0; i < (ptr_config_element->num_assoc_data_elements); i++) {
219 ixheaacd_read_bits_buf(it_bit_buff, 4);
220 }
221
222 ixheaacd_skip_bits(it_bit_buff, 5, ptr_config_element->num_valid_cc_elements);
223
224 {
225 WORD32 bits_to_read = ptr_config_element->alignment_bits;
226 if (bits_to_read <= it_bit_buff->bit_pos) {
227 bits_to_read = it_bit_buff->bit_pos - bits_to_read;
228 } else {
229 bits_to_read = 8 - (bits_to_read) + it_bit_buff->bit_pos;
230 }
231 tmp = ixheaacd_read_bits_buf(it_bit_buff, bits_to_read);
232 }
233 tmp = ixheaacd_read_bits_buf(it_bit_buff, 8);
234
235 ixheaacd_skip_bits(it_bit_buff, 8, tmp);
236
237 return 0;
238 }
239
ixheaacd_decode_pce(struct ia_bit_buf_struct * it_bit_buff,UWORD32 * ui_pce_found_in_hdr,ia_program_config_struct * ptr_prog_config)240 WORD ixheaacd_decode_pce(struct ia_bit_buf_struct *it_bit_buff,
241 UWORD32 *ui_pce_found_in_hdr,
242 ia_program_config_struct *ptr_prog_config) {
243 WORD32 error_code = 0;
244
245 if (*ui_pce_found_in_hdr == 1 || *ui_pce_found_in_hdr == 3) {
246 ia_program_config_struct ptr_config_element = {0};
247 ptr_config_element.alignment_bits = ptr_prog_config->alignment_bits;
248 error_code =
249 ixheaacd_read_prog_config_element(&ptr_config_element, it_bit_buff);
250 *ui_pce_found_in_hdr = 3;
251 } else {
252 error_code =
253 ixheaacd_read_prog_config_element(ptr_prog_config, it_bit_buff);
254 *ui_pce_found_in_hdr = 2;
255 }
256 return error_code;
257 }
258
ixheaacd_get_adif_header(ia_adif_header_struct * adif,struct ia_bit_buf_struct * it_bit_buff)259 static PLATFORM_INLINE WORD32 ixheaacd_get_adif_header(
260 ia_adif_header_struct *adif, struct ia_bit_buf_struct *it_bit_buff) {
261 WORD32 i;
262 WORD32 ret_val = 0, tmp;
263
264 ixheaacd_read_bits_buf(it_bit_buff, 16);
265 tmp = ixheaacd_read_bits_buf(it_bit_buff, 17);
266
267 if (tmp & 0x1) {
268 ixheaacd_skip_bits(it_bit_buff, 8, 9);
269 }
270
271 tmp = ixheaacd_read_bits_buf(it_bit_buff, 3);
272
273 adif->bit_stream_type = (tmp & 0x1);
274
275 ixheaacd_read_bits_buf(it_bit_buff, 23);
276
277 tmp = ixheaacd_read_bits_buf(it_bit_buff, 4);
278
279 for (i = 0; i <= tmp; i++) {
280 if (adif->bit_stream_type == 0) {
281 ixheaacd_read_bits_buf(it_bit_buff, 20);
282 }
283
284 adif->prog_config_present = 1;
285 adif->str_prog_config.alignment_bits = 7;
286 ret_val =
287 ixheaacd_read_prog_config_element(&adif->str_prog_config, it_bit_buff);
288 if (ret_val) {
289 return ret_val;
290 }
291 }
292
293 return 0;
294 }
295
ixheaacd_find_syncword(ia_adts_header_struct * adts,struct ia_bit_buf_struct * it_bit_buff)296 WORD32 ixheaacd_find_syncword(ia_adts_header_struct *adts,
297 struct ia_bit_buf_struct *it_bit_buff) {
298 adts->sync_word = (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 12);
299 if (adts->sync_word == 0xFFF) {
300 return 0;
301 }
302
303 while (1) {
304 ixheaacd_read_bidirection(it_bit_buff, -4);
305 if (it_bit_buff->cnt_bits < 12) {
306 return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL;
307 }
308 adts->sync_word = (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 12);
309 if (adts->sync_word == 0xFFF) {
310 ixheaacd_read_bidirection(it_bit_buff, -12);
311 return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL;
312 }
313 }
314 }
315
ixheaacd_adtsframe(ia_adts_header_struct * adts,struct ia_bit_buf_struct * it_bit_buff)316 WORD32 ixheaacd_adtsframe(ia_adts_header_struct *adts,
317 struct ia_bit_buf_struct *it_bit_buff) {
318 WORD32 tmp;
319
320 WORD32 crc_reg;
321 ia_adts_crc_info_struct *ptr_adts_crc_info = it_bit_buff->pstr_adts_crc_info;
322 ptr_adts_crc_info->crc_active = 1;
323 ptr_adts_crc_info->no_reg = 0;
324 ixheaacd_read_bidirection(it_bit_buff, -12);
325 crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff,
326 CRC_ADTS_HEADER_LEN);
327 ixheaacd_find_syncword(adts, it_bit_buff);
328
329 tmp = ixheaacd_read_bits_buf(it_bit_buff, 10);
330
331 adts->id = (tmp & 0x200) >> 9;
332 adts->layer = (tmp & 0x180) >> 7;
333 adts->protection_absent = (tmp & 0x40) >> 6;
334 adts->profile = (tmp & 0x30) >> 4;
335 { adts->profile++; }
336 adts->samp_freq_index = (tmp & 0xF);
337
338 if (((adts->profile != AAC_LC_PROFILE)) || (adts->samp_freq_index > 11))
339
340 {
341 return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL;
342 }
343
344 tmp = ixheaacd_read_bits_buf(it_bit_buff, 21);
345
346 adts->channel_configuration = (WORD32)(tmp & 0xE0000) >> 17;
347
348 adts->aac_frame_length = (tmp & 0x1FFF);
349
350 tmp = ixheaacd_read_bits_buf(it_bit_buff, 13);
351
352 adts->no_raw_data_blocks = (tmp & 0x3);
353
354 ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg);
355
356 if (adts->protection_absent == 0) {
357 ixheaacd_skip_bits(it_bit_buff, 16, adts->no_raw_data_blocks);
358 adts->crc_check = ixheaacd_read_bits_buf(it_bit_buff, 16);
359
360 ptr_adts_crc_info->crc_active = 1;
361 ptr_adts_crc_info->file_value = adts->crc_check;
362 } else
363 ptr_adts_crc_info->crc_active = 0;
364
365 ixheaacd_aac_bytealign(it_bit_buff);
366 return 0;
367 }
368
ixheaacd_get_samp_rate(struct ia_bit_buf_struct * it_bit_buff,ia_sampling_rate_info_struct * pstr_samp_rate_info,ia_audio_specific_config_struct * pstr_audio_specific_config)369 WORD32 ixheaacd_get_samp_rate(
370 struct ia_bit_buf_struct *it_bit_buff,
371 ia_sampling_rate_info_struct *pstr_samp_rate_info,
372 ia_audio_specific_config_struct *pstr_audio_specific_config) {
373 WORD32 index;
374 WORD32 sampling_rate;
375 index = ixheaacd_read_bits_buf(it_bit_buff, 4);
376 pstr_audio_specific_config->samp_frequency_index = index;
377
378 if (index == 0x0F) {
379 sampling_rate = ixheaacd_read_bits_buf(it_bit_buff, 24);
380
381 if (pstr_audio_specific_config->audio_object_type != AOT_USAC) {
382 if (sampling_rate < 9391)
383 sampling_rate = 8000;
384 else if ((sampling_rate >= 9391) && (sampling_rate < 11502))
385 sampling_rate = 11025;
386 else if ((sampling_rate >= 11502) && (sampling_rate < 13856))
387 sampling_rate = 12000;
388 else if ((sampling_rate >= 13856) && (sampling_rate < 18783))
389 sampling_rate = 16000;
390 else if ((sampling_rate >= 18783) && (sampling_rate < 23004))
391 sampling_rate = 22050;
392 else if ((sampling_rate >= 23004) && (sampling_rate < 27713))
393 sampling_rate = 24000;
394 else if ((sampling_rate >= 27713) && (sampling_rate < 37566))
395 sampling_rate = 32000;
396 else if ((sampling_rate >= 37566) && (sampling_rate < 46009))
397 sampling_rate = 44100;
398 else if ((sampling_rate >= 46009) && (sampling_rate < 55426))
399 sampling_rate = 48000;
400 else if ((sampling_rate >= 55426) && (sampling_rate < 75132))
401 sampling_rate = 64000;
402 else if ((sampling_rate >= 75132) && (sampling_rate < 92017))
403 sampling_rate = 88200;
404 else if (sampling_rate >= 92017)
405 sampling_rate = 96000;
406 }
407 return sampling_rate;
408 } else if ((index > 12) && (index < 15)) {
409 return -1;
410 } else {
411 return ((pstr_samp_rate_info[index].sampling_frequency));
412 }
413 }
ixheaacd_get_ld_sbr_header(ia_bit_buf_struct * it_bit_buff,ia_sbr_header_data_struct * sbr_header_data)414 static int ixheaacd_get_ld_sbr_header(
415 ia_bit_buf_struct *it_bit_buff,
416 ia_sbr_header_data_struct *sbr_header_data) {
417 WORD32 header_extra_1, header_extra_2;
418 UWORD32 tmp, bit_cnt = 0;
419
420 tmp = ixheaacd_read_bits_buf(it_bit_buff, 16);
421 bit_cnt += 16;
422
423 sbr_header_data->amp_res = (tmp & 0x8000) >> 15;
424 sbr_header_data->start_freq = (tmp & 0x7800) >> 11;
425 sbr_header_data->stop_freq = (tmp & 0x780) >> 7;
426 sbr_header_data->xover_band = (tmp & 0x70) >> 4;
427 header_extra_1 = (tmp & 0x0002) >> 1;
428 header_extra_2 = (tmp & 0x0001);
429
430 if (header_extra_1) {
431 sbr_header_data->freq_scale = ixheaacd_read_bits_buf(it_bit_buff, 2);
432 sbr_header_data->alter_scale = ixheaacd_read_bits_buf(it_bit_buff, 1);
433 sbr_header_data->noise_bands = ixheaacd_read_bits_buf(it_bit_buff, 2);
434 } else {
435 sbr_header_data->freq_scale = 2;
436 sbr_header_data->alter_scale = 1;
437 sbr_header_data->noise_bands = 2;
438 }
439
440 if (header_extra_2) {
441 sbr_header_data->limiter_bands = ixheaacd_read_bits_buf(it_bit_buff, 2);
442 sbr_header_data->limiter_gains = ixheaacd_read_bits_buf(it_bit_buff, 2);
443 sbr_header_data->interpol_freq = ixheaacd_read_bits_buf(it_bit_buff, 1);
444 sbr_header_data->smoothing_mode = ixheaacd_read_bits_buf(it_bit_buff, 1);
445 } else {
446 sbr_header_data->limiter_bands = 2;
447 sbr_header_data->limiter_gains = 2;
448 sbr_header_data->interpol_freq = 1;
449 sbr_header_data->smoothing_mode = 1;
450 }
451
452 return (bit_cnt);
453 }
454
ixheaacd_eld_sbr_header(ia_bit_buf_struct * it_bit_buff,WORD32 channels,ia_sbr_header_data_struct * pstr_sbr_config)455 WORD32 ixheaacd_eld_sbr_header(ia_bit_buf_struct *it_bit_buff, WORD32 channels,
456 ia_sbr_header_data_struct *pstr_sbr_config) {
457 int num_sbr_header, el, bit_cnt = 0;
458 switch (channels) {
459 default:
460 num_sbr_header = 0;
461 break;
462 case 1:
463 case 2:
464 num_sbr_header = 1;
465 break;
466 case 3:
467 num_sbr_header = 2;
468 break;
469 case 4:
470 case 5:
471 case 6:
472 num_sbr_header = 3;
473 break;
474 case 7:
475 num_sbr_header = 4;
476 break;
477 }
478 for (el = 0; el < num_sbr_header; el++) {
479 bit_cnt = ixheaacd_get_ld_sbr_header(it_bit_buff, pstr_sbr_config);
480 }
481 return (bit_cnt);
482 }
483
ixheaacd_ga_hdr_dec(ia_aac_dec_state_struct * aac_state_struct,WORD32 header_len,WORD32 * bytes_consumed,ia_sampling_rate_info_struct * pstr_samp_rate_info,struct ia_bit_buf_struct * it_bit_buff)484 WORD32 ixheaacd_ga_hdr_dec(ia_aac_dec_state_struct *aac_state_struct,
485 WORD32 header_len, WORD32 *bytes_consumed,
486 ia_sampling_rate_info_struct *pstr_samp_rate_info,
487 struct ia_bit_buf_struct *it_bit_buff) {
488 WORD32 tmp;
489 WORD32 cnt_bits = it_bit_buff->cnt_bits;
490 WORD32 dummy = 0;
491 ia_audio_specific_config_struct *pstr_audio_specific_config;
492
493 memset(aac_state_struct->ia_audio_specific_config, 0,
494 sizeof(ia_audio_specific_config_struct));
495
496 memset(&(aac_state_struct->eld_specific_config), 0,
497 sizeof(ia_eld_specific_config_struct));
498
499 pstr_audio_specific_config = aac_state_struct->ia_audio_specific_config;
500
501 aac_state_struct->p_config->str_prog_config.alignment_bits =
502 it_bit_buff->bit_pos;
503
504 aac_state_struct->audio_object_type = ixheaacd_read_bits_buf(it_bit_buff, 5);
505
506 if (aac_state_struct->audio_object_type == 31) {
507 tmp = ixheaacd_read_bits_buf(it_bit_buff, 6);
508 aac_state_struct->audio_object_type = 32 + tmp;
509 }
510 pstr_audio_specific_config->audio_object_type =
511 aac_state_struct->audio_object_type;
512
513 tmp = ixheaacd_get_samp_rate(it_bit_buff, pstr_samp_rate_info,
514 pstr_audio_specific_config);
515 pstr_audio_specific_config->sampling_frequency = tmp;
516
517 if (tmp == -1) {
518 *bytes_consumed = 1;
519 return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL;
520 } else
521 aac_state_struct->sampling_rate = tmp;
522 aac_state_struct->p_config->ui_samp_freq = tmp;
523
524 aac_state_struct->ch_config = ixheaacd_read_bits_buf(it_bit_buff, 4);
525
526 pstr_audio_specific_config->channel_configuration =
527 aac_state_struct->ch_config;
528
529 if (aac_state_struct->audio_object_type == AOT_SBR ||
530 aac_state_struct->audio_object_type == AOT_PS) {
531 tmp = ixheaacd_get_samp_rate(it_bit_buff, pstr_samp_rate_info,
532 pstr_audio_specific_config);
533 aac_state_struct->sbr_present_flag = 1;
534 if (tmp == -1) {
535 *bytes_consumed = 1;
536 return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL;
537 } else
538 aac_state_struct->extension_samp_rate = tmp;
539
540 aac_state_struct->audio_object_type =
541 ixheaacd_read_bits_buf(it_bit_buff, 5);
542 }
543
544 if (((aac_state_struct->audio_object_type >= AOT_AAC_MAIN &&
545 aac_state_struct->audio_object_type <= AOT_AAC_LTP) ||
546 aac_state_struct->audio_object_type == AOT_AAC_SCAL ||
547 aac_state_struct->audio_object_type == AOT_TWIN_VQ ||
548 aac_state_struct->audio_object_type == AOT_ER_AAC_LD ||
549 aac_state_struct->audio_object_type == AOT_ER_AAC_ELD ||
550 aac_state_struct->audio_object_type == AOT_ER_AAC_LC) &&
551 aac_state_struct->audio_object_type != AOT_USAC)
552
553 {
554 aac_state_struct->usac_flag = 0;
555
556 aac_state_struct->frame_len_flag = ixheaacd_read_bits_buf(it_bit_buff, 1);
557 if (aac_state_struct->audio_object_type != AOT_ER_AAC_ELD) {
558 aac_state_struct->depends_on_core_coder =
559 ixheaacd_read_bits_buf(it_bit_buff, 1);
560 aac_state_struct->extension_flag = ixheaacd_read_bits_buf(it_bit_buff, 1);
561
562 if (aac_state_struct->ch_config == 0) {
563 WORD32 error_code;
564 error_code = ixheaacd_read_prog_config_element(
565 &aac_state_struct->p_config->str_prog_config, it_bit_buff);
566 if (error_code != 0) {
567 *bytes_consumed = 1;
568 return error_code;
569 }
570 aac_state_struct->p_config->ui_pce_found_in_hdr = 1;
571 }
572 }
573 if (aac_state_struct->audio_object_type == AOT_ER_AAC_ELD ||
574 aac_state_struct->audio_object_type == AOT_ER_AAC_LD) {
575 aac_state_struct->eld_specific_config.aac_sect_data_resil_flag = 0;
576 aac_state_struct->eld_specific_config.aac_sf_data_resil_flag = 0;
577 aac_state_struct->eld_specific_config.aac_spect_data_resil_flag = 0;
578 aac_state_struct->eld_specific_config.ep_config = 0;
579 if ((aac_state_struct->extension_flag == 1) ||
580 aac_state_struct->audio_object_type == AOT_ER_AAC_ELD) {
581 if (aac_state_struct->audio_object_type >= ER_OBJECT_START) {
582 aac_state_struct->eld_specific_config.aac_sect_data_resil_flag =
583 ixheaacd_read_bits_buf(it_bit_buff, 1);
584 aac_state_struct->eld_specific_config.aac_sf_data_resil_flag =
585 ixheaacd_read_bits_buf(it_bit_buff, 1);
586 aac_state_struct->eld_specific_config.aac_spect_data_resil_flag =
587 ixheaacd_read_bits_buf(it_bit_buff, 1);
588 if (aac_state_struct->audio_object_type != AOT_ER_AAC_ELD)
589 aac_state_struct->eld_specific_config.ep_config =
590 ixheaacd_read_bits_buf(it_bit_buff, 2);
591 else
592 aac_state_struct->eld_specific_config.ld_sbr_flag_present =
593 ixheaacd_read_bits_buf(it_bit_buff, 1);
594 }
595 }
596 }
597 }
598 if (pstr_audio_specific_config->audio_object_type == AOT_USAC) {
599 {
600 pstr_audio_specific_config->sbr_present_flag = 0;
601 pstr_audio_specific_config->ext_audio_object_type = 0;
602 }
603
604 {{size_t tmp = 0xf;
605 UWORD32 i;
606 WORD32 err = 0;
607
608 aac_state_struct->usac_flag = 1;
609
610 ixheaacd_conf_default(&(pstr_audio_specific_config->str_usac_config));
611 err = ixheaacd_config(it_bit_buff,
612 &(pstr_audio_specific_config->str_usac_config),
613 &(pstr_audio_specific_config->channel_configuration));
614 if (err != 0) return err;
615
616 pstr_audio_specific_config->sampling_frequency =
617 pstr_audio_specific_config->str_usac_config.usac_sampling_frequency;
618
619 if (pstr_audio_specific_config->audio_object_type == AOT_USAC) {
620 pstr_audio_specific_config->sbr_present_flag = 1;
621 pstr_audio_specific_config->ext_audio_object_type = AOT_SBR;
622 pstr_audio_specific_config->ext_sampling_frequency =
623 pstr_audio_specific_config->sampling_frequency;
624 pstr_audio_specific_config->ext_samp_frequency_index =
625 pstr_audio_specific_config->samp_frequency_index;
626
627 for (i = 0; i < sizeof(ixheaacd_sampl_freq_idx_table) /
628 sizeof(ixheaacd_sampl_freq_idx_table[0]);
629 i++) {
630 if (ixheaacd_sampl_freq_idx_table[i] ==
631 (int)(pstr_audio_specific_config->sampling_frequency)) {
632 tmp = i;
633 break;
634 }
635 }
636 pstr_audio_specific_config->samp_frequency_index = (UINT32)tmp;
637 } else {
638 pstr_audio_specific_config->sbr_present_flag = 0;
639 }
640 }
641 }
642
643 {
644 dummy = ixheaacd_skip_bits_buf(it_bit_buff, it_bit_buff->cnt_bits);
645
646 if ((SIZE_T)it_bit_buff->ptr_read_next ==
647 (SIZE_T)it_bit_buff->ptr_bit_buf_base) {
648 *bytes_consumed = ((WORD32)it_bit_buff->size) >> 3;
649 } else {
650 *bytes_consumed = (((((SIZE_T)it_bit_buff->ptr_read_next -
651 (SIZE_T)it_bit_buff->ptr_bit_buf_base))
652 << 3) +
653 7 - it_bit_buff->bit_pos + 7) >>
654 3;
655 }
656 }
657 return 0;
658 }
659
660 aac_state_struct->frame_length = FRAME_SIZE;
661 if (aac_state_struct->frame_len_flag)
662 #ifdef ALLOW_SMALL_FRAMELENGTH
663 aac_state_struct->frame_length = FRAME_SIZE_SMALL;
664 #else
665 return -1;
666 #endif
667
668 if (aac_state_struct->extension_flag)
669 aac_state_struct->extension_flag_3 = ixheaacd_read_bits_buf(it_bit_buff, 1);
670
671 if (aac_state_struct->audio_object_type == AOT_ER_AAC_LD)
672 aac_state_struct->frame_length >>= 1;
673
674 if (aac_state_struct->audio_object_type == AOT_ER_AAC_ELD) {
675 aac_state_struct->frame_length >>= 1;
676 if (aac_state_struct->eld_specific_config.ld_sbr_flag_present) {
677 aac_state_struct->eld_specific_config.ld_sbr_samp_rate =
678 ixheaacd_read_bits_buf(it_bit_buff, 1);
679 aac_state_struct->eld_specific_config.ld_sbr_crc_flag =
680 ixheaacd_read_bits_buf(it_bit_buff, 1);
681
682 ixheaacd_eld_sbr_header(it_bit_buff, aac_state_struct->ch_config,
683 &aac_state_struct->str_sbr_config);
684
685 aac_state_struct->dwnsmp_signal =
686 !aac_state_struct->eld_specific_config.ld_sbr_samp_rate;
687 }
688
689 ixheaacd_read_bits_buf(it_bit_buff, 1);
690 }
691 if (aac_state_struct->audio_object_type == AOT_ER_AAC_ELD) {
692 int ep_config = ixheaacd_read_bits_buf(it_bit_buff, 2);
693 if (ep_config == 2 || ep_config == 3) {
694 }
695 if (ep_config == 3) {
696 int direct_map = ixheaacd_read_bits_buf(it_bit_buff, 1);
697 if (!direct_map) {
698 }
699 }
700 }
701
702 tmp = (header_len * 8) - it_bit_buff->cnt_bits;
703
704 if (aac_state_struct->audio_object_type != AOT_SBR &&
705 (it_bit_buff->cnt_bits >= 16)) {
706 tmp = ixheaacd_read_bits_buf(it_bit_buff, 11);
707
708 if (tmp == 0x2b7) {
709 tmp = ixheaacd_read_bits_buf(it_bit_buff, 5);
710
711 if (tmp == AOT_SBR) {
712 WORD32 sbr_present_flag = ixheaacd_read_bits_buf(it_bit_buff, 1);
713 if (sbr_present_flag) {
714 tmp = ixheaacd_get_samp_rate(it_bit_buff, pstr_samp_rate_info,
715 pstr_audio_specific_config);
716 if (tmp == -1) {
717 *bytes_consumed = 1;
718 return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL;
719 } else
720 aac_state_struct->extension_samp_rate = tmp;
721
722 if (it_bit_buff->cnt_bits >= 12) {
723 tmp = ixheaacd_read_bits_buf(it_bit_buff, 11);
724 if (tmp == 0x548) {
725 tmp = ixheaacd_read_bits_buf(it_bit_buff, 1);
726 }
727 }
728 }
729 }
730 } else if (aac_state_struct->bs_format == LOAS_BSFORMAT) {
731 ixheaacd_read_bidirection(it_bit_buff, -11);
732 }
733 }
734
735 if (aac_state_struct->audio_object_type != AOT_AAC_LC &&
736 aac_state_struct->audio_object_type != AOT_SBR &&
737 aac_state_struct->audio_object_type != AOT_PS &&
738 aac_state_struct->audio_object_type != AOT_ER_AAC_LC &&
739 aac_state_struct->audio_object_type != AOT_ER_AAC_LD &&
740 aac_state_struct->audio_object_type != AOT_ER_AAC_ELD &&
741 aac_state_struct->audio_object_type != AOT_AAC_LTP) {
742 *bytes_consumed = 1;
743 return IA_ENHAACPLUS_DEC_INIT_FATAL_AUDIOOBJECTTYPE_NOT_SUPPORTED;
744 } else {
745 if (aac_state_struct->bs_format == LOAS_BSFORMAT) {
746 *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) >> 3;
747 if (it_bit_buff->bit_pos < 7) *bytes_consumed += 1;
748
749 } else
750 *bytes_consumed = header_len;
751
752 return 0;
753 }
754 }
755
ixheaacd_check_if_adts(ia_adts_header_struct * adts,struct ia_bit_buf_struct * it_bit_buff,WORD32 usr_max_ch)756 WORD32 ixheaacd_check_if_adts(ia_adts_header_struct *adts,
757 struct ia_bit_buf_struct *it_bit_buff,
758 WORD32 usr_max_ch) {
759 WORD32 max_frm_len_per_ch, result = 0;
760
761 result = ixheaacd_adtsframe(adts, it_bit_buff);
762
763 max_frm_len_per_ch = ixheaacd_mult32(768, (adts->no_raw_data_blocks + 1));
764
765 if (adts->channel_configuration != 0)
766 max_frm_len_per_ch =
767 ixheaacd_mult32(max_frm_len_per_ch, adts->channel_configuration);
768 else
769 max_frm_len_per_ch = max_frm_len_per_ch * usr_max_ch;
770
771 return ((result != 0) || (adts->aac_frame_length < 8) || (adts->layer != 0) ||
772 (adts->profile != AAC_LC_PROFILE));
773 }
774
ixheaacd_latm_header_decode(ia_aac_dec_state_struct * aac_state_struct,struct ia_bit_buf_struct * it_bit_buff,WORD32 * bytes_consumed,ia_sampling_rate_info_struct * pstr_samp_rate_info)775 IA_ERRORCODE ixheaacd_latm_header_decode(
776 ia_aac_dec_state_struct *aac_state_struct,
777 struct ia_bit_buf_struct *it_bit_buff, WORD32 *bytes_consumed,
778 ia_sampling_rate_info_struct *pstr_samp_rate_info) {
779 WORD32 sync;
780 IA_ERRORCODE result;
781 WORD32 next_sync, audio_mux_len_bytes_last;
782 WORD32 audio_mux_len_bits_last;
783 WORD32 sync_status = aac_state_struct->sync_status;
784 WORD32 bit_count = aac_state_struct->bit_count;
785 WORD32 cnt_bits = it_bit_buff->cnt_bits;
786
787 *bytes_consumed = 0;
788
789 aac_state_struct->bs_format = LOAS_BSFORMAT;
790
791 if (sync_status == 0) {
792 do {
793 sync = ixheaacd_read_bits_buf(it_bit_buff, 11);
794 bit_count += 11;
795 while (sync != 0x2B7) {
796 sync = ((sync & 0x3ff) << 1) | ixheaacd_read_bits_buf(it_bit_buff, 1);
797 bit_count += 1;
798 if (it_bit_buff->cnt_bits < 13) {
799 ixheaacd_read_bidirection(it_bit_buff, -11);
800 *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8;
801 return (IA_ENHAACPLUS_DEC_INIT_NONFATAL_HEADER_NOT_AT_START);
802 }
803 }
804
805 audio_mux_len_bytes_last = ixheaacd_read_bits_buf(it_bit_buff, 13);
806 bit_count += 13;
807 audio_mux_len_bits_last = audio_mux_len_bytes_last << 3;
808 if (it_bit_buff->cnt_bits >= (audio_mux_len_bits_last + 11)) {
809 ixheaacd_read_bidirection(it_bit_buff, audio_mux_len_bits_last);
810 bit_count += audio_mux_len_bits_last;
811
812 next_sync = ixheaacd_read_bits_buf(it_bit_buff, 11);
813 bit_count += 11;
814
815 if (next_sync == 0x2B7) {
816 ixheaacd_read_bidirection(it_bit_buff,
817 -(11 + audio_mux_len_bits_last + 13 + 11));
818 bit_count -= 11 + audio_mux_len_bits_last + 13 + 11;
819 break;
820 } else {
821 ixheaacd_read_bidirection(it_bit_buff,
822 -(audio_mux_len_bits_last + 24 + 11 - 1));
823 bit_count -= audio_mux_len_bits_last + 24 + 11 - 1;
824 }
825
826 } else {
827 ixheaacd_read_bidirection(it_bit_buff, -(13 + 11));
828 bit_count -= (13 + 11);
829 *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8;
830 return IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
831 }
832 } while (1);
833
834 do {
835 WORD32 audio_mux_len_bytes_last;
836 WORD32 use_same_stream_mux;
837
838 sync = ixheaacd_read_bits_buf(it_bit_buff, 11);
839 bit_count += 11;
840
841 if (sync != 0x2b7) {
842 ixheaacd_read_bidirection(it_bit_buff, -25);
843 bit_count -= 11;
844 *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8;
845 return IA_ENHAACPLUS_DEC_INIT_NONFATAL_HEADER_NOT_AT_START;
846 }
847
848 audio_mux_len_bytes_last = ixheaacd_read_bits_buf(it_bit_buff, 13);
849 bit_count += 13;
850
851 use_same_stream_mux = ixheaacd_read_bits_buf(it_bit_buff, 1);
852 bit_count += 1;
853
854 if (it_bit_buff->cnt_bits - (audio_mux_len_bytes_last * 8 - 1 + 11) < 0) {
855 ixheaacd_read_bidirection(it_bit_buff, -25);
856 bit_count -= 25;
857 aac_state_struct->bit_count = bit_count;
858 *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8;
859 return IA_ENHAACPLUS_DEC_INIT_NONFATAL_HEADER_NOT_AT_START;
860 }
861
862 if (!use_same_stream_mux) {
863 ixheaacd_read_bidirection(it_bit_buff, -25);
864 bit_count -= 25;
865 sync_status = 1;
866 aac_state_struct->sync_status = sync_status;
867 break;
868 }
869
870 ixheaacd_read_bidirection(it_bit_buff, audio_mux_len_bytes_last * 8 - 1);
871 bit_count += audio_mux_len_bytes_last * 8 - 1;
872
873 } while (sync_status == 0);
874
875 *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8;
876 {
877 ixheaacd_latm_struct latm_struct_element;
878 WORD32 sync;
879 memset(&latm_struct_element, 0, sizeof(ixheaacd_latm_struct));
880
881 sync = ixheaacd_read_bits_buf(it_bit_buff, 11);
882 if (sync == 0x2b7) {
883 result = ixheaacd_latm_audio_mux_element(
884 it_bit_buff, &latm_struct_element, aac_state_struct,
885 pstr_samp_rate_info);
886 if (result != 0) {
887 sync_status = 0;
888 aac_state_struct->sync_status = sync_status;
889
890 *bytes_consumed += 1;
891 return result;
892 }
893 }
894 }
895 }
896 return IA_NO_ERROR;
897 }
898
ixheaacd_aac_headerdecode(ia_exhaacplus_dec_api_struct * p_obj_exhaacplus_dec,UWORD8 * buffer,WORD32 * bytes_consumed,const ia_aac_dec_huffman_tables_struct * pstr_huffmann_tables)899 WORD32 ixheaacd_aac_headerdecode(
900 ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, UWORD8 *buffer,
901 WORD32 *bytes_consumed,
902 const ia_aac_dec_huffman_tables_struct *pstr_huffmann_tables) {
903 struct ia_bit_buf_struct it_bit_buff = {0}, *handle_bit_buff;
904 ia_adif_header_struct adif = {0};
905 ia_adts_header_struct adts = {0};
906 WORD32 result;
907 WORD32 header_len;
908 WORD32 sync = 0;
909
910 WORD32 disable_sync = p_obj_exhaacplus_dec->aac_config.ui_disable_sync;
911 WORD32 is_ga_header = p_obj_exhaacplus_dec->aac_config.ui_mp4_flag;
912
913 WORD32 loas_present = p_obj_exhaacplus_dec->aac_config.loas_present;
914
915 ia_aac_dec_state_struct *aac_state_struct =
916 p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX];
917 WORD32 usr_max_ch = aac_state_struct->p_config->ui_max_channels;
918
919 ia_sampling_rate_info_struct *pstr_samp_rate_info =
920 (ia_sampling_rate_info_struct *)&pstr_huffmann_tables
921 ->str_sample_rate_info[0];
922
923 if (buffer == 0) {
924 return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL;
925 }
926
927 header_len = aac_state_struct->ui_in_bytes;
928
929 handle_bit_buff = ixheaacd_create_bit_buf(&it_bit_buff, (UWORD8 *)buffer,
930 (WORD16)header_len);
931 handle_bit_buff->cnt_bits += (header_len << 3);
932 handle_bit_buff->xaac_jmp_buf = &aac_state_struct->xaac_jmp_buf;
933
934 if (is_ga_header == 1) {
935 return ixheaacd_ga_hdr_dec(aac_state_struct, header_len, bytes_consumed,
936 pstr_samp_rate_info, handle_bit_buff);
937 } else if (loas_present) {
938 return ixheaacd_latm_header_decode(aac_state_struct, &it_bit_buff,
939 bytes_consumed, pstr_samp_rate_info);
940 }
941
942 else {
943 WORD32 header_found = 0;
944 WORD32 bytes_taken = -1;
945 WORD32 prev_offset = 0;
946 WORD32 run_once = 1;
947 if (disable_sync == 0) run_once = 0;
948
949 do {
950 bytes_taken++;
951 buffer += (bytes_taken - prev_offset);
952
953 prev_offset = bytes_taken;
954
955 handle_bit_buff = ixheaacd_create_bit_buf(
956 &it_bit_buff, (UWORD8 *)buffer, (WORD16)(header_len - bytes_taken));
957 handle_bit_buff->cnt_bits += (8 * (header_len - bytes_taken));
958
959 handle_bit_buff->pstr_adts_crc_info = &handle_bit_buff->str_adts_crc_info;
960 ixheaacd_adts_crc_open(handle_bit_buff->pstr_adts_crc_info);
961
962 if ((buffer[0] == 'A') && (buffer[1] == 'D') && (buffer[2] == 'I') &&
963 (buffer[3] == 'F')) {
964 adif.prog_config_present = 0;
965 result = ixheaacd_get_adif_header(&adif, handle_bit_buff);
966 if (result == 0) {
967 if (adif.prog_config_present == 1) {
968 aac_state_struct->p_config->ui_pce_found_in_hdr = 1;
969 aac_state_struct->p_config->str_prog_config = adif.str_prog_config;
970 }
971 aac_state_struct->s_adif_hdr_present = 1;
972 aac_state_struct->audio_object_type =
973 adif.str_prog_config.object_type;
974 aac_state_struct->sampling_rate =
975 pstr_samp_rate_info[adif.str_prog_config.samp_freq_index]
976 .sampling_frequency;
977 aac_state_struct->ch_config = adif.str_prog_config.channels;
978 bytes_taken +=
979 ((handle_bit_buff->size - handle_bit_buff->cnt_bits) >> 3);
980
981 header_found = 1;
982 aac_state_struct->frame_length = FRAME_SIZE;
983 if (aac_state_struct->audio_object_type == AOT_ER_AAC_LD)
984 aac_state_struct->frame_length >>= 1;
985 }
986 }
987
988 else if ((sync = ixheaacd_read_bits_buf(&it_bit_buff, 12)) == 0xfff) {
989 result = ixheaacd_check_if_adts(&adts, handle_bit_buff, usr_max_ch);
990 if (result != 0) {
991 continue;
992 }
993
994 if ((adts.aac_frame_length + ADTS_HEADER_LENGTH) <
995 (header_len - bytes_taken)) {
996 ia_adts_header_struct adts_loc = {0};
997
998 handle_bit_buff = ixheaacd_create_init_bit_buf(
999 &it_bit_buff, (UWORD8 *)(buffer + adts.aac_frame_length),
1000 (WORD16)(header_len - adts.aac_frame_length));
1001
1002 adts_loc.sync_word =
1003 (WORD16)ixheaacd_read_bits_buf(handle_bit_buff, 12);
1004
1005 if (adts_loc.sync_word != 0xFFF) {
1006 continue;
1007 }
1008
1009 result =
1010 ixheaacd_check_if_adts(&adts_loc, handle_bit_buff, usr_max_ch);
1011 if ((result != 0) ||
1012 (adts.samp_freq_index != adts_loc.samp_freq_index) ||
1013 (adts.channel_configuration != adts_loc.channel_configuration)) {
1014 continue;
1015 }
1016 }
1017
1018 {
1019 WORD32 obj_type;
1020 obj_type = adts.profile;
1021
1022 aac_state_struct->audio_object_type = obj_type;
1023 aac_state_struct->sampling_rate =
1024 ((pstr_samp_rate_info[adts.samp_freq_index].sampling_frequency));
1025 aac_state_struct->ch_config = adts.channel_configuration;
1026 aac_state_struct->s_adts_hdr_present = 1;
1027 header_found = 1;
1028 aac_state_struct->bs_format = ADTS_BSFORMAT;
1029 aac_state_struct->frame_length = FRAME_SIZE;
1030 if (aac_state_struct->audio_object_type == AOT_ER_AAC_LD)
1031 aac_state_struct->frame_length >>= 1;
1032 }
1033 } else if (0x2b7 == (sync >> 1)) {
1034 ixheaacd_read_bidirection(&it_bit_buff, -12);
1035 result =
1036 ixheaacd_latm_header_decode(aac_state_struct, &it_bit_buff,
1037 bytes_consumed, pstr_samp_rate_info);
1038 if (result != 0) {
1039 if ((result ==
1040 (WORD32)
1041 IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES) ||
1042 (result ==
1043 (WORD32)IA_ENHAACPLUS_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX)) {
1044 bytes_taken += *bytes_consumed;
1045 *bytes_consumed = bytes_taken;
1046 return result;
1047 } else if (result == -1)
1048 return -1;
1049 else if (result == (WORD32)IA_FATAL_ERROR)
1050 return IA_FATAL_ERROR;
1051 else
1052 bytes_taken += *bytes_consumed - 1;
1053 continue;
1054 }
1055 header_found = 1;
1056 aac_state_struct->bs_format = LOAS_BSFORMAT;
1057 bytes_taken += *bytes_consumed;
1058 }
1059
1060 } while ((header_found == 0 && ((bytes_taken + 1) < (header_len - 68))) &&
1061 run_once != 1);
1062
1063 if (header_found == 0 && disable_sync == 1) {
1064 WORD32 err_code;
1065 ixheaacd_read_bidirection(&it_bit_buff, -12);
1066 err_code =
1067 ixheaacd_ga_hdr_dec(aac_state_struct, header_len, bytes_consumed,
1068 pstr_samp_rate_info, handle_bit_buff);
1069
1070 if (err_code == 0) p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 1;
1071 return err_code;
1072 }
1073
1074 switch (aac_state_struct->audio_object_type) {
1075 case AOT_AAC_MAIN:
1076 case AOT_AAC_LC:
1077 case AOT_AAC_SSR:
1078 case AOT_AAC_LTP:
1079 case AOT_AAC_SCAL:
1080 case AOT_TWIN_VQ:
1081 case AOT_ER_AAC_LD:
1082 case AOT_ER_AAC_ELD:
1083 case AOT_ER_AAC_LC:
1084 case AOT_USAC:
1085 break;
1086 default:
1087 return IA_ENHAACPLUS_DEC_INIT_FATAL_AUDIOOBJECTTYPE_NOT_SUPPORTED;
1088 }
1089
1090 if (aac_state_struct->audio_object_type != AOT_USAC)
1091 aac_state_struct->usac_flag = 0;
1092 *bytes_consumed = bytes_taken;
1093
1094 if ((handle_bit_buff->cnt_bits < 0) &&
1095 (handle_bit_buff->size <
1096 (usr_max_ch * (IA_ENHAACPLUS_DEC_INP_BUF_SIZE << 3)))) {
1097 return (WORD16)(
1098 (WORD32)IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
1099 }
1100
1101 if (header_found == 0) {
1102 *bytes_consumed = bytes_taken + 1;
1103 return IA_ENHAACPLUS_DEC_INIT_NONFATAL_HEADER_NOT_AT_START;
1104 } else {
1105 return 0;
1106 }
1107 }
1108 }
1109