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