• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdio.h>
21 #include <string.h>
22 #include "ixheaacd_sbr_common.h"
23 #include "ixheaacd_type_def.h"
24 
25 #include "ixheaacd_constants.h"
26 #include "ixheaacd_basic_ops32.h"
27 #include "ixheaacd_basic_ops16.h"
28 #include "ixheaacd_basic_ops40.h"
29 #include "ixheaacd_basic_ops.h"
30 #include "ixheaacd_bitbuffer.h"
31 
32 #include "ixheaacd_defines.h"
33 
34 #include "ixheaacd_aac_rom.h"
35 
36 #include "ixheaacd_error_codes.h"
37 
38 #include "ixheaacd_pulsedata.h"
39 
40 #include "ixheaacd_pns.h"
41 #include "ixheaacd_drc_data_struct.h"
42 
43 #include "ixheaacd_interface.h"
44 #include "ixheaacd_info.h"
45 #include "ixheaacd_cnst.h"
46 #include "ixheaacd_sbrdecsettings.h"
47 #include "ixheaacd_sbr_scale.h"
48 #include "ixheaacd_common_rom.h"
49 #include "ixheaacd_env_extr_part.h"
50 #include "ixheaacd_sbr_rom.h"
51 #include "ixheaacd_hybrid.h"
52 #include "ixheaacd_ps_dec.h"
53 #include "ixheaacd_qmf_dec.h"
54 #include "ixheaacd_mps_polyphase.h"
55 #include "ixheaacd_config.h"
56 #include "ixheaacd_mps_struct_def.h"
57 #include "ixheaacd_mps_res_rom.h"
58 #include "ixheaacd_mps_aac_struct.h"
59 #include "ixheaacd_mps_dec.h"
60 #include "ixheaacd_error_standards.h"
61 #include "ixheaacd_sbrdecoder.h"
62 #include "ixheaacd_acelp_info.h"
63 #include "ixheaacd_tns_usac.h"
64 #include "ixheaacd_ec_defines.h"
65 #include "ixheaacd_ec_rom.h"
66 #include "ixheaacd_ec_struct_def.h"
67 #include "ixheaacd_main.h"
68 #include "ixheaacd_channelinfo.h"
69 #include "ixheaacd_ec.h"
70 #include "ixheaacd_drc_dec.h"
71 
72 #include "ixheaacd_block.h"
73 #include "ixheaacd_channel.h"
74 #include "ixheaacd_sbr_payload.h"
75 #include "ixheaacd_stereo.h"
76 #include "ixheaacd_adts.h"
77 #include "ixheaacd_audioobjtypes.h"
78 #include "ixheaacd_memory_standards.h"
79 #include "ixheaacd_latmdemux.h"
80 #include "ixheaacd_aacdec.h"
81 
82 #include "ixheaacd_struct_def.h"
83 #include "ixheaacd_headerdecode.h"
84 #include "ixheaacd_multichannel.h"
85 #include "ixheaacd_adts_crc_check.h"
86 #include "ixheaacd_ld_mps_dec.h"
87 
88 #include "ixheaacd_hcr.h"
89 #include "ixheaacd_struct.h"
90 
91 #define SIZEOF_INT(x) ((sizeof(x) + sizeof(WORD32) - 1) / sizeof(WORD32))
92 
93 #define EXT_FILL_DATA 1
94 #define EXT_FIL 0
95 #define EXT_DATA_LENGTH 3
96 #define EXT_LDSAC_DATA 9
97 
98 #define MIN(x, y) ((x) > (y) ? (y) : (x))
99 
100 extern const ia_usac_samp_rate_info ixheaacd_samp_rate_info[];
101 
ixheaacd_aacdec_decodeframe(ia_exhaacplus_dec_api_struct * p_obj_exhaacplus_dec,ia_aac_dec_scratch_struct * aac_scratch_ptrs,VOID * time_data_tmp,FLAG frame_status,WORD * type,WORD * ch_idx,WORD init_flag,WORD channel,WORD * element_index_order,WORD skip_full_decode,WORD ch_fac,WORD slot_element,WORD max_channels,WORD32 total_channels,WORD32 frame_length,WORD32 frame_size,ia_drc_dec_struct * pstr_drc_dec,WORD32 object_type,WORD32 ch_config,ia_eld_specific_config_struct eld_specific_config,WORD16 adtsheader,ia_drc_dec_struct * drc_dummy,WORD32 ldmps_present,UWORD8 * slot_pos,UWORD8 * mps_buffer,WORD32 * mps_header,WORD32 * mps_bytes,WORD32 is_init,WORD32 first_frame)102 WORD32 ixheaacd_aacdec_decodeframe(
103     ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec,
104     ia_aac_dec_scratch_struct *aac_scratch_ptrs, VOID *time_data_tmp,
105     FLAG frame_status, WORD *type, WORD *ch_idx, WORD init_flag, WORD channel,
106     WORD *element_index_order, WORD skip_full_decode, WORD ch_fac,
107     WORD slot_element, WORD max_channels, WORD32 total_channels,
108     WORD32 frame_length, WORD32 frame_size, ia_drc_dec_struct *pstr_drc_dec,
109     WORD32 object_type, WORD32 ch_config,
110     ia_eld_specific_config_struct eld_specific_config, WORD16 adtsheader,
111     ia_drc_dec_struct *drc_dummy, WORD32 ldmps_present, UWORD8 *slot_pos, UWORD8 *mps_buffer,
112     WORD32 *mps_header, WORD32 *mps_bytes, WORD32 is_init, WORD32 first_frame) {
113   WORD ch, ele_type;
114   ia_aac_dec_state_struct *p_state_enhaacplus_dec;
115   ia_aac_decoder_struct *aac_dec_handle;
116   ia_bit_buf_struct *it_bit_buff;
117   ixheaacd_latm_struct *latm_element;
118 
119   WORD error_code = (WORD)frame_status;
120   WORD previous_element;
121   WORD prev_data_ele_present = 0;
122   WORD new_element;
123   WORD32 num_ch = 0;
124 
125   WORD32 crc_reg = 0;
126   ia_adts_crc_info_struct *ptr_adts_crc_info;
127 
128   WORD32 cnt_bits = 0;
129 
130   WORD32 eld_sbr_flag = eld_specific_config.ld_sbr_flag_present;
131   WORD32 ld_sbr_crc_flag = eld_specific_config.ld_sbr_crc_flag;
132   WORD32 aac_spect_data_resil_flag =
133       eld_specific_config.aac_spect_data_resil_flag;
134 
135   WORD32 ele_ch = 0;
136 
137   ia_aac_sfb_code_book_struct *ptr_aac_sfb_code_book_data[CHANNELS];
138   ia_pns_stereo_data_struct *ptr_pns_stereo_data;
139 
140   WORD32 *work_buffer_core = aac_scratch_ptrs->base_scr_8k;
141   WORD32 *work_buffer_1 = aac_scratch_ptrs->extra_scr_4k[0];
142   WORD32 *work_buffer_2 = aac_scratch_ptrs->extra_scr_4k[2];
143   p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac;
144 
145   WORD32 *time_data = (WORD32 *)time_data_tmp;
146 
147   aac_dec_handle = p_state_enhaacplus_dec->pstr_aac_dec_info[*ch_idx];
148   it_bit_buff = p_state_enhaacplus_dec->ptr_bit_stream;
149 
150   ptr_adts_crc_info = it_bit_buff->pstr_adts_crc_info;
151 
152   latm_element = &p_state_enhaacplus_dec->latm_struct_element;
153 
154   ptr_pns_stereo_data =
155       (ia_pns_stereo_data_struct
156            *)&work_buffer_1[2 * SIZEOF_INT(ia_aac_dec_channel_info_struct) +
157                             2 * SIZEOF_INT(ia_aac_sfb_code_book_struct)];
158 
159   aac_dec_handle->frame_status = 1;
160 
161   for (ch = 0; ch < channel; ch++) {
162     const ia_aac_dec_imdct_tables_struct *pstr_imdct_tables;
163     aac_dec_handle->pstr_aac_dec_ch_info[ch] =
164         (ia_aac_dec_channel_info_struct
165              *)&work_buffer_1[ch * SIZEOF_INT(ia_aac_dec_channel_info_struct)];
166     ptr_aac_sfb_code_book_data[ch] =
167         (ia_aac_sfb_code_book_struct
168              *)&work_buffer_1[2 * SIZEOF_INT(ia_aac_dec_channel_info_struct) +
169                               (ch * SIZEOF_INT(ia_aac_sfb_code_book_struct))];
170 
171     aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_scale_factor =
172         ptr_aac_sfb_code_book_data[ch]->scale_factor;
173     aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_code_book =
174         ptr_aac_sfb_code_book_data[ch]->code_book;
175 
176     aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff =
177         &work_buffer_core[ch * MAX_BINS_LONG];
178 
179     if (object_type == AOT_ER_AAC_ELD) {
180       aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff =
181           &work_buffer_core[2 * ch * MAX_BINS_LONG];
182     }
183 
184     aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_stereo_info =
185         &ptr_pns_stereo_data->str_stereo_info;
186     aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_pns_corr_info =
187         &ptr_pns_stereo_data->str_pns_corr_info;
188     aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_pns_rand_vec_data =
189         aac_dec_handle->pstr_pns_rand_vec_data;
190 
191     pstr_imdct_tables = aac_dec_handle->pstr_aac_tables->pstr_imdct_tables;
192 
193     if (960 != frame_length) {
194       aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
195           pstr_imdct_tables->only_long_window_sine;
196       aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[0] =
197           pstr_imdct_tables->only_short_window_sine;
198       aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
199           pstr_imdct_tables->only_long_window_kbd;
200       aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[1] =
201           pstr_imdct_tables->only_short_window_kbd;
202 
203       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[0] =
204           pstr_imdct_tables->only_long_window_sine;
205       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[0] =
206           pstr_imdct_tables->only_short_window_sine;
207       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[1] =
208           pstr_imdct_tables->only_long_window_kbd;
209       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[1] =
210           pstr_imdct_tables->only_short_window_kbd;
211     } else {
212       aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
213           pstr_imdct_tables->only_long_window_sine_960;
214       aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[0] =
215           pstr_imdct_tables->only_short_window_sine_120;
216       aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
217           pstr_imdct_tables->only_long_window_kbd_960;
218       aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[1] =
219           pstr_imdct_tables->only_short_window_kbd_120;
220 
221       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[0] =
222           pstr_imdct_tables->only_long_window_sine_960;
223       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[0] =
224           pstr_imdct_tables->only_short_window_sine_120;
225       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[1] =
226           pstr_imdct_tables->only_long_window_kbd_960;
227       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[1] =
228           pstr_imdct_tables->only_short_window_kbd_120;
229     }
230 
231     aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.frame_length = frame_length;
232     if (object_type == AOT_ER_AAC_ELD || object_type == AOT_ER_AAC_LD ||
233         object_type == AOT_AAC_LTP) {
234       if (512 == aac_dec_handle->samples_per_frame) {
235         if (object_type != AOT_ER_AAC_ELD) {
236           aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
237               (WORD16 *)pstr_imdct_tables->low_overlap_win;
238           aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
239               (WORD16 *)pstr_imdct_tables->window_sine_512;
240 
241           aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
242               ->ptr_long_window[1] =
243               (WORD16 *)pstr_imdct_tables->low_overlap_win;
244           aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
245               ->ptr_long_window[0] =
246               (WORD16 *)pstr_imdct_tables->window_sine_512;
247         } else {
248           aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
249               (WORD16 *)pstr_imdct_tables->window_sine_512_eld;
250           aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
251               (WORD16 *)pstr_imdct_tables->window_sine_512_eld;
252         }
253       } else if (480 == aac_dec_handle->samples_per_frame) {
254         if (object_type != AOT_ER_AAC_ELD) {
255           aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
256               (WORD16 *)pstr_imdct_tables->low_overlap_win_480;
257           aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
258               (WORD16 *)pstr_imdct_tables->window_sine_480;
259 
260           aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
261               ->ptr_long_window[1] =
262               (WORD16 *)pstr_imdct_tables->low_overlap_win_480;
263           aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
264               ->ptr_long_window[0] =
265               (WORD16 *)pstr_imdct_tables->window_sine_480;
266 
267         } else {
268           aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
269               (WORD16 *)pstr_imdct_tables->window_sine_480_eld;
270           aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
271               (WORD16 *)pstr_imdct_tables->window_sine_480_eld;
272         }
273       }
274     }
275     if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) {
276       if (aac_dec_handle->samples_per_frame <= 512) {
277         aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.lag =
278             aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag;
279       }
280       aac_dec_handle->pstr_aac_dec_ch_info[ch]->ltp_buf =
281           aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_buf;
282       aac_dec_handle->pstr_aac_dec_ch_info[ch]->ltp_lag =
283           aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag;
284     }
285 
286     aac_dec_handle->pstr_aac_dec_ch_info[ch]->scratch_buf_ptr = work_buffer_2;
287     if (object_type == AOT_ER_AAC_ELD) {
288       aac_dec_handle->pstr_aac_dec_ch_info[ch]->pulse_scratch =
289           aac_scratch_ptrs->extra_scr_4k[3];
290     }
291   }
292 
293   if (channel == 2) {
294     if (aac_dec_handle->pstr_aac_dec_ch_info[1]->ptr_spec_coeff ==
295         aac_scratch_ptrs->extra_scr_4k[0]) {
296       aac_dec_handle->pstr_aac_dec_ch_info[1]->ptr_spec_coeff =
297           aac_dec_handle->pstr_aac_dec_ch_info[0]->ptr_spec_coeff;
298     }
299   }
300 
301   for (ch = 0; ch < channel; ch++) {
302     ia_pns_info_struct *ptr_pns_info =
303         &aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_pns_info;
304     memset(ptr_pns_info, 0, sizeof(ia_pns_info_struct));
305   }
306 
307   if (channel > 0) {
308     ia_pns_correlation_info_struct *ptr_corr_info =
309         aac_dec_handle->pstr_aac_dec_ch_info[0]->pstr_pns_corr_info;
310     memset(ptr_corr_info->correlated, 0, sizeof(UWORD8) * PNS_BAND_FLAGS_SIZE);
311   }
312 
313   for (ch = 0; ch < channel; ch++) {
314     memset(&aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_hcr_info, 0,
315            sizeof(ia_hcr_info_struct));
316     ixheaacd_huff_code_reorder_tbl_init(
317         &aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_hcr_info);
318   }
319 
320   for (ch = 0; ch < channel; ch++) {
321     aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.data_present = 0;
322     aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.data_present =
323         0;
324   }
325 
326   for (ch = 0; ch < channel; ch++) {
327     if (object_type == AOT_ER_AAC_ELD || object_type == AOT_ER_AAC_LD)
328       aac_dec_handle->pstr_aac_dec_ch_info[ch]->granule_len =
329           aac_dec_handle->samples_per_frame;
330     if (object_type == AOT_ER_AAC_LC)
331       aac_dec_handle->pstr_aac_dec_ch_info[ch]->granule_len =
332           aac_dec_handle->samples_per_frame / 8;
333   }
334   previous_element = ID_END;
335 
336   aac_dec_handle->pstr_sbr_bitstream->no_elements = 0;
337   new_element = 0;
338   ele_type = *type;
339 
340   cnt_bits = it_bit_buff->cnt_bits;
341 
342   WORD32 err = 0;
343   jmp_buf local;
344 
345   if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
346     err = setjmp(local);
347   }
348 
349   if (!err && frame_status) {
350     if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
351       it_bit_buff->xaac_jmp_buf = &local;
352     }
353 
354     if (((object_type != AOT_ER_AAC_ELD) && (object_type != AOT_ER_AAC_LD) &&
355          (object_type != AOT_ER_AAC_LC)) ||
356         (object_type < ER_OBJECT_START)) {
357       while (ele_type != ID_END && aac_dec_handle->frame_status) {
358         ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3);
359         ixheaacd_read_bidirection(it_bit_buff, -3);
360 
361         if (it_bit_buff->cnt_bits < 3) {
362           it_bit_buff->cnt_bits = -1;
363           error_code = (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
364           break;
365         }
366 
367         if ((ele_type == ID_FIL) || (ele_type == ID_DSE) || (new_element == 0)) {
368           ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3);
369           new_element = 1;
370         } else if ((ele_type != ID_END)) {
371           ele_type = -1;
372           break;
373         } else {
374           ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3);
375         }
376 
377         if (it_bit_buff->cnt_bits < 0) {
378           aac_dec_handle->frame_status = 0;
379         }
380 
381         switch (ele_type) {
382           case ID_SCE:
383           case ID_CPE:
384           case ID_LFE:
385 
386             if (aac_dec_handle->frame_status) {
387               ia_aac_dec_channel_info_struct *pstr_aac_dec_ch_info =
388                   aac_dec_handle->pstr_aac_dec_ch_info[LEFT];
389               ia_ics_info_struct *ptr_ics_info = &pstr_aac_dec_ch_info->str_ics_info;
390               ele_ch = 1;
391               if (ele_type == ID_CPE) {
392                 ele_ch = 2;
393               } else {
394                 ele_ch = 1;
395               }
396 
397               prev_data_ele_present = 1;
398 
399               if (ptr_adts_crc_info->crc_active == 1 && ptr_adts_crc_info->no_reg < 7) {
400                 crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff,
401                                                       CRC_ADTS_RAW_DATA_BLK_LEN);
402               }
403 
404               pstr_aac_dec_ch_info->element_instance_tag =
405                   (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4);
406 
407               element_index_order[*ch_idx] = pstr_aac_dec_ch_info->element_instance_tag;
408               pstr_aac_dec_ch_info->common_window = 0;
409 
410               ptr_ics_info->num_swb_window = 0;
411               ptr_ics_info->sampling_rate_index = aac_dec_handle->sampling_rate_index;
412               if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) {
413                 ptr_ics_info->ltp.data_present = 0;
414                 ptr_ics_info->ltp2.data_present = 0;
415                 ptr_ics_info->predictor_data_present = 0;
416               }
417 
418               if (ele_ch > 1) {
419                 aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.num_swb_window = 0;
420                 aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.sampling_rate_index =
421                     aac_dec_handle->sampling_rate_index;
422 
423                 pstr_aac_dec_ch_info->common_window =
424                     (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 1);
425 
426                 if (pstr_aac_dec_ch_info->common_window) {
427                   error_code = ixheaacd_ics_read(
428                       it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, object_type,
429                       pstr_aac_dec_ch_info->common_window, aac_dec_handle->samples_per_frame);
430                   if (error_code) {
431                     aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info =
432                         aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->str_ics_info;
433                     if (it_bit_buff->cnt_bits < 0) {
434                       error_code =
435                           (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
436                     }
437 
438                     goto _ia_handle_error;
439                   }
440 
441                   aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info =
442                       pstr_aac_dec_ch_info->str_ics_info;
443 
444                   ixheaacd_read_ms_data(it_bit_buff, pstr_aac_dec_ch_info);
445                 }
446               }
447 
448               error_code = ixheaacd_individual_ch_stream(
449                   it_bit_buff, aac_dec_handle, ele_ch, frame_length, total_channels, object_type,
450                   eld_specific_config, ele_type);
451 
452               if (error_code) {
453                 if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
454                   aac_dec_handle->frame_status = 0;
455                 } else {
456                   return error_code;
457                 }
458               }
459 
460               if (ptr_adts_crc_info->crc_active == 1) {
461                 ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg);
462               }
463 
464               if (it_bit_buff->cnt_bits < 0) {
465                 error_code =
466                     (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
467               }
468 
469               if (error_code) {
470                 goto _ia_handle_error;
471               }
472 
473             _ia_handle_error:
474               if (error_code) {
475                 aac_dec_handle->frame_status = 0;
476                 if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) num_ch = num_ch + ele_ch;
477                 break;
478               } else {
479                 error_code = ixheaacd_channel_pair_process(
480                     aac_dec_handle->pstr_aac_dec_ch_info, ele_ch, aac_dec_handle->pstr_aac_tables,
481                     total_channels, object_type, aac_spect_data_resil_flag,
482                     eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data,
483                     aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle);
484                 if (error_code) {
485                   if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
486                     aac_dec_handle->frame_status = 0;
487                   } else {
488                     return error_code;
489                   }
490                 }
491                 num_ch = num_ch + ele_ch;
492               }
493             }
494 
495             break;
496           case ID_CCE:
497             if (max_channels > 2) {
498               prev_data_ele_present = 1;
499               error_code = ixheaacd_dec_coupling_channel_element(
500                   it_bit_buff, aac_dec_handle, aac_dec_handle->sampling_rate_index,
501                   aac_dec_handle->pstr_aac_tables, aac_dec_handle->pstr_common_tables,
502                   &element_index_order[*ch_idx],
503                   (ia_enhaacplus_dec_ind_cc *)aac_dec_handle->p_ind_channel_info, total_channels,
504                   frame_length, object_type, eld_specific_config, ele_type);
505 
506               num_ch = num_ch + 1;
507 
508               if (error_code) {
509                 aac_dec_handle->frame_status = 0;
510                 if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
511                   aac_dec_handle->frame_status = 0;
512                 } else {
513                   return error_code;
514                 }
515               } else {
516                 error_code = ixheaacd_channel_pair_process(
517                     aac_dec_handle->pstr_aac_dec_ch_info, 1, aac_dec_handle->pstr_aac_tables,
518                     total_channels, object_type, aac_spect_data_resil_flag,
519                     eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data,
520                     aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle);
521                 if (error_code) {
522                   if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
523                     aac_dec_handle->frame_status = 0;
524                   } else {
525                     return error_code;
526                   }
527                 }
528               }
529             } else {
530               error_code = (WORD32)((WORD32)IA_XHEAAC_DEC_EXE_FATAL_UNIMPLEMENTED_CCE);
531             }
532             if (it_bit_buff->cnt_bits < 0) {
533               error_code = (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
534               goto _ia_handle_error;
535             }
536             break;
537 
538           case ID_DSE:
539           case ID_PCE:
540           case ID_FIL:
541 
542           {
543             WORD32 flag = 1;
544 
545             if ((ele_type != ID_FIL) && (ptr_adts_crc_info->crc_active == 1) &&
546                 (ptr_adts_crc_info->no_reg < 7)) {
547               crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff, 0);
548             }
549             if (ele_type == ID_DSE) {
550               ixheaacd_read_data_stream_element(it_bit_buff, &aac_dec_handle->byte_align_bits,
551                                                 p_obj_exhaacplus_dec->p_state_aac->pstr_drc_dec);
552             }
553 
554             else if (ele_type == ID_PCE) {
555               error_code = ixheaacd_decode_pce(
556                   it_bit_buff, &p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr,
557                   &p_obj_exhaacplus_dec->aac_config.str_prog_config);
558               if (error_code != 0) {
559                 if (it_bit_buff->cnt_bits < 0) {
560                   error_code =
561                       (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
562                   goto _ia_handle_error;
563                 }
564                 aac_dec_handle->frame_status = 0;
565                 if (error_code > 0) {
566                   if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
567                     aac_dec_handle->frame_status = 0;
568                   } else {
569                     return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR;
570                   }
571                 } else {
572                   if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
573                     aac_dec_handle->frame_status = 0;
574                   } else {
575                     return error_code;
576                   }
577                 }
578               }
579             }
580 
581             else if (ele_type == ID_FIL) {
582               WORD32 bits_decoded = 0;
583               if (object_type == AOT_ER_AAC_ELD) {
584                 bits_decoded = (it_bit_buff->size - it_bit_buff->cnt_bits);
585                 cnt_bits = (frame_size * 8 - bits_decoded);
586                 if (adtsheader == 1) {
587                   if (cnt_bits > it_bit_buff->cnt_bits) {
588                     if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
589                       aac_dec_handle->frame_status = 0;
590                     } else {
591                       return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
592                     }
593                   }
594                 }
595               }
596 
597               if (ixheaacd_check_for_sbr_payload(
598                       it_bit_buff, aac_dec_handle->pstr_sbr_bitstream, (WORD16)previous_element,
599                       pstr_drc_dec, object_type, adtsheader, cnt_bits, ld_sbr_crc_flag, drc_dummy,
600                       mps_buffer, mps_header, mps_bytes, is_init, &aac_dec_handle->is_first,
601                       p_obj_exhaacplus_dec->aac_config.ui_err_conceal)) {
602                 flag = 0;
603               }
604             }
605 
606             if (it_bit_buff->cnt_bits < 0) {
607               error_code = (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
608               goto _ia_handle_error;
609             }
610 
611             if (flag) {
612               if (prev_data_ele_present == 0) {
613                 new_element = 0;
614               }
615             }
616             if ((ele_type != ID_FIL) && (ptr_adts_crc_info->crc_active == 1)) {
617               ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg);
618             }
619 
620             if (ele_type == ID_PCE) {
621               if (ptr_adts_crc_info->str_crc_reg_data[crc_reg].bit_buf_cnt) {
622                 ptr_adts_crc_info->str_crc_reg_data[crc_reg].max_bits =
623                     ptr_adts_crc_info->str_crc_reg_data[crc_reg].bit_buf_cnt;
624               }
625             }
626           }
627 
628           break;
629 
630           case ID_END:
631             error_code = 0;
632             break;
633         }
634 
635         previous_element = ele_type;
636 
637         if (init_flag) {
638           if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) {
639             p_obj_exhaacplus_dec->aac_config.element_type[*ch_idx] = ele_type;
640           }
641         }
642       }
643     } else {
644       {
645         switch (ch_config) {
646           default:
647             if (aac_dec_handle->frame_status) {
648               ia_aac_dec_channel_info_struct *pstr_aac_dec_ch_info =
649                   aac_dec_handle->pstr_aac_dec_ch_info[LEFT];
650               ia_ics_info_struct *ptr_ics_info = &pstr_aac_dec_ch_info->str_ics_info;
651 
652               if (ch_config == 2)
653                 ele_ch = 2, ele_type = 1;
654               else
655                 ele_ch = 1, ele_type = 0;
656 
657               prev_data_ele_present = 1;
658 
659               if ((ptr_adts_crc_info->crc_active == 1) && (ptr_adts_crc_info->no_reg < 7)) {
660                 crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff,
661                                                       CRC_ADTS_RAW_DATA_BLK_LEN);
662               }
663 
664               if (object_type != AOT_ER_AAC_ELD)
665                 pstr_aac_dec_ch_info->element_instance_tag =
666                     (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4);
667 
668               element_index_order[*ch_idx] = pstr_aac_dec_ch_info->element_instance_tag;
669               pstr_aac_dec_ch_info->common_window = 0;
670 
671               ptr_ics_info->num_swb_window = 0;
672               ptr_ics_info->sampling_rate_index = aac_dec_handle->sampling_rate_index;
673 
674               if (object_type == AOT_ER_AAC_LD) {
675                 ptr_ics_info->ltp.data_present = 0;
676                 ptr_ics_info->ltp2.data_present = 0;
677                 ptr_ics_info->predictor_data_present = 0;
678               }
679               if (ele_ch > 1) {
680                 aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.num_swb_window = 0;
681                 aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.sampling_rate_index =
682                     aac_dec_handle->sampling_rate_index;
683 
684                 if (object_type != 39)
685                   pstr_aac_dec_ch_info->common_window =
686                       (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 1);
687                 else
688                   pstr_aac_dec_ch_info->common_window = 1;
689 
690                 if (pstr_aac_dec_ch_info->common_window) {
691                   error_code = ixheaacd_ics_read(
692                       it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, object_type,
693                       pstr_aac_dec_ch_info->common_window, aac_dec_handle->samples_per_frame);
694                   if (error_code) {
695                     aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info =
696                         aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->str_ics_info;
697                     if (it_bit_buff->cnt_bits < 0) {
698                       error_code =
699                           (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
700                     }
701 
702                     goto _ia_handle_error1;
703                   }
704 
705                   aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info =
706                       pstr_aac_dec_ch_info->str_ics_info;
707 
708                   ixheaacd_read_ms_data(it_bit_buff, pstr_aac_dec_ch_info);
709 
710                   {
711                     if (object_type == AOT_ER_AAC_LD) {
712                       IA_ERRORCODE temp =
713                           ixheaacd_ltp_decode(it_bit_buff, ptr_ics_info, object_type,
714                                               aac_dec_handle->samples_per_frame, LEFT);
715 
716                       if (temp != 0) {
717                         if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
718                           p_obj_exhaacplus_dec->aac_config.frame_status = 0;
719                         } else {
720                           return temp;
721                         }
722                       }
723                     }
724                   }
725                 }
726               }
727 
728               error_code = ixheaacd_individual_ch_stream(
729                   it_bit_buff, aac_dec_handle, ele_ch, frame_length, total_channels, object_type,
730                   eld_specific_config, ele_type);
731               if (error_code) {
732                 if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
733                   aac_dec_handle->frame_status = 0;
734                 } else {
735                   return error_code;
736                 }
737               }
738 
739               if (ptr_adts_crc_info->crc_active == 1) {
740                 ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg);
741               }
742 
743               if (it_bit_buff->cnt_bits < 0) {
744                 error_code =
745                     (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
746               }
747 
748               if (error_code) {
749                 goto _ia_handle_error1;
750               }
751 
752             _ia_handle_error1:
753               if (error_code) {
754                 aac_dec_handle->frame_status = 0;
755                 if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) num_ch = num_ch + ele_ch;
756                 break;
757               } else {
758                 error_code = ixheaacd_channel_pair_process(
759                     aac_dec_handle->pstr_aac_dec_ch_info, ele_ch, aac_dec_handle->pstr_aac_tables,
760                     total_channels, object_type, aac_spect_data_resil_flag,
761                     eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data,
762                     aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle);
763                 if (error_code) {
764                   if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
765                     aac_dec_handle->frame_status = 0;
766                   } else {
767                     return error_code;
768                   }
769                 }
770                 num_ch = num_ch + ele_ch;
771               }
772             }
773 
774             p_obj_exhaacplus_dec->aac_config.element_type[*ch_idx] = ele_ch - 1;
775             break;
776         }
777 
778         if ((object_type == AOT_ER_AAC_LC) || (!eld_sbr_flag)) {
779           WORD32 cnt_bits;
780           cnt_bits = it_bit_buff->cnt_bits;
781           p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.ldmps_config.no_ldsbr_present = 1;
782 
783           if (cnt_bits >= 8) {
784             error_code = ixheaacd_extension_payload(
785                 it_bit_buff, &cnt_bits, &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle);
786             if (error_code) {
787               if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
788                 aac_dec_handle->frame_status = 0;
789               } else {
790                 return error_code;
791               }
792             }
793           }
794 
795           if (it_bit_buff->cnt_bits) {
796             WORD32 alignment = it_bit_buff->bit_pos & 0x07;
797             it_bit_buff->cnt_bits = (it_bit_buff->cnt_bits + alignment) & 7;
798             it_bit_buff->bit_pos = 7;
799             it_bit_buff->ptr_read_next++;
800           }
801         }
802 
803         else if ((object_type != AOT_ER_AAC_ELD) || (!eld_sbr_flag)) {
804           WORD32 bits_decoded, cnt_bits;
805           bits_decoded = (it_bit_buff->size - it_bit_buff->cnt_bits);
806 
807           cnt_bits = (frame_size * 8 - bits_decoded);
808 
809           if (object_type == AOT_ER_AAC_LC) cnt_bits = it_bit_buff->cnt_bits;
810 
811           p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.ldmps_config.no_ldsbr_present = 1;
812 
813           if (cnt_bits >= 8) {
814             error_code = ixheaacd_extension_payload(
815                 it_bit_buff, &cnt_bits, &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle);
816             if (error_code) {
817               if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
818                 aac_dec_handle->frame_status = 0;
819               } else {
820                 return error_code;
821               }
822             }
823           }
824 
825           if (((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD)) &&
826               (p_obj_exhaacplus_dec->aac_config.ld_decoder != 1)) {
827             if (it_bit_buff->cnt_bits) {
828               WORD32 alignment = it_bit_buff->bit_pos & 0x07;
829               it_bit_buff->cnt_bits = (it_bit_buff->cnt_bits + alignment) & 7;
830               it_bit_buff->bit_pos = 7;
831               it_bit_buff->ptr_read_next++;
832             }
833           } else {
834             if (it_bit_buff->bit_pos != 7) {
835               WORD32 alignment = it_bit_buff->bit_pos & 0x07;
836               it_bit_buff->cnt_bits -= alignment + 1;
837               it_bit_buff->bit_pos += 7 - alignment;
838               it_bit_buff->ptr_read_next++;
839             }
840           }
841         } else {
842           WORD32 bits_decoded, cnt_bits;
843           bits_decoded = (it_bit_buff->size - it_bit_buff->cnt_bits);
844           cnt_bits = (frame_size * 8 - bits_decoded);
845           if (adtsheader == 1) {
846             if (cnt_bits > it_bit_buff->cnt_bits) {
847               if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
848                 aac_dec_handle->frame_status = 0;
849               } else {
850                 return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
851               }
852             }
853           }
854           ixheaacd_check_for_sbr_payload(
855               it_bit_buff, aac_dec_handle->pstr_sbr_bitstream, (WORD16)(ch_config - 1),
856               pstr_drc_dec, object_type, adtsheader, cnt_bits, ld_sbr_crc_flag, drc_dummy,
857               mps_buffer, mps_header, mps_bytes, is_init, &aac_dec_handle->is_first,
858               p_obj_exhaacplus_dec->aac_config.ui_err_conceal);
859         }
860       }
861     }
862   }
863   if ((err || (aac_dec_handle->frame_status == 0) || (frame_status == 0)) && (!is_init)) {
864     if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
865       aac_dec_handle->frame_status = 0;
866       error_code = 0;
867       num_ch = channel;
868       ele_type = ID_END;
869       p_obj_exhaacplus_dec->aac_config.frame_status = 0;
870       it_bit_buff->cnt_bits = 0;
871     } else {
872       return err;
873     }
874   }
875   if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && aac_dec_handle->conceal_count == 0) {
876     for (ch = 0; ch < channel; ch++) {
877       ixheaacd_aac_ec_init(&aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->str_ec_state);
878     }
879   }
880 
881   if (ele_type == ID_END && p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
882     WORD32 tmp;
883     tmp = ((WORD32)latm_element->layer_info[0][0].frame_len_bits) -
884           (it_bit_buff->initial_cnt_bits - it_bit_buff->cnt_bits);
885 
886     if (tmp > 0) ixheaacd_read_bidirection(it_bit_buff, tmp);
887 
888     if (latm_element->other_data_present) {
889       WORD32 count_bits = (WORD32)latm_element->other_data_length;
890       ixheaacd_read_bidirection(it_bit_buff, count_bits);
891     }
892   }
893 
894   if (object_type == AOT_ER_AAC_LD) {
895     for (ch = 0; ch < channel; ch++) {
896       aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag =
897           aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.lag;
898     }
899   }
900   aac_dec_handle->frame_status = aac_dec_handle->frame_status && frame_status;
901 
902   aac_dec_handle->channels = num_ch;
903 
904   if (error_code == 0)
905     if ((skip_full_decode == 0) || ((skip_full_decode == 1) && error_code)) {
906       ia_ics_info_struct str_ics_info[2];
907       WORD32 *spec_coef[2];
908       WORD32 *scratch[2];
909 
910       for (ch = 0; ch < channel; ch++) {
911         str_ics_info[ch] = aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info;
912         spec_coef[ch] = aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff;
913       }
914 
915       scratch[0] = (WORD32 *)aac_scratch_ptrs->extra_scr_4k[2];
916       scratch[1] = (WORD32 *)aac_scratch_ptrs->extra_scr_4k[1];
917 
918       error_code = ixheaacd_drc_map_channels(
919           pstr_drc_dec, aac_dec_handle->channels,
920           aac_dec_handle->pstr_aac_dec_ch_info[0]->str_ics_info.frame_length);
921       if (error_code) {
922         if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
923           error_code = 0;
924           aac_dec_handle->frame_status = 0;
925         } else {
926           return error_code;
927         }
928       }
929 
930       for (ch = 0; ch < aac_dec_handle->channels; ch++) {
931         WORD32 *overlap1 =
932             aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->overlap_add_data.ptr_overlap_buf;
933         const WORD16 *ptr_long_window_next =
934             aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
935                 ->ptr_long_window[(int)str_ics_info[ch].window_shape];
936         const WORD16 *ptr_short_window_next =
937             aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
938                 ->ptr_short_window[(int)str_ics_info[ch].window_shape];
939         if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
940           ia_aac_dec_channel_info_struct *pstr_aac_dec_channel_info =
941               aac_dec_handle->pstr_aac_dec_ch_info[ch];
942           ia_aac_dec_channel_info *pstr_aac_dec_static_channel_info =
943               aac_dec_handle->ptr_aac_dec_static_channel_info[ch];
944 
945           ia_aac_dec_channel_info_struct **ppstr_aac_dec_channel_info =
946               &pstr_aac_dec_channel_info;
947           ia_aac_dec_channel_info **ppstr_aac_dec_static_channel_info =
948               &pstr_aac_dec_static_channel_info;
949           ia_audio_specific_config_struct *pstr_audio_specific_config;
950           pstr_audio_specific_config = p_state_enhaacplus_dec->ia_audio_specific_config;
951 
952           if (str_ics_info[ch].max_sfb > str_ics_info[ch].num_swb_window) {
953             aac_dec_handle->frame_status = 0;
954           }
955 
956           ixheaacd_aac_apply_ec(
957               &(*ppstr_aac_dec_static_channel_info)->str_ec_state, *ppstr_aac_dec_channel_info,
958               &ixheaacd_samp_rate_info[pstr_audio_specific_config->samp_frequency_index],
959               aac_dec_handle->samples_per_frame, &str_ics_info[ch], aac_dec_handle->frame_status);
960 
961           aac_dec_handle->conceal_count = aac_dec_handle->conceal_count + 1;
962           if (aac_dec_handle->frame_status) {
963             aac_dec_handle->sbr_num_elements = aac_dec_handle->pstr_sbr_bitstream->no_elements;
964           } else {
965             aac_dec_handle->pstr_sbr_bitstream->no_elements = aac_dec_handle->sbr_num_elements;
966           }
967           if (first_frame == 1)
968             skip_full_decode = 1;
969           else
970             skip_full_decode = 0;
971         }
972         if (pstr_drc_dec->drc_on) {
973           ixheaacd_drc_apply(pstr_drc_dec, spec_coef[ch],
974                              str_ics_info[ch].window_sequence, ch,
975                              str_ics_info[ch].frame_length,
976                              object_type);
977         }
978         if (skip_full_decode == 0) {
979           ixheaacd_imdct_process(aac_dec_handle->pstr_aac_dec_overlap_info[ch],
980                                  spec_coef[ch], &str_ics_info[ch],
981                                  time_data + slot_element, ch_fac, scratch[ch],
982                                  aac_dec_handle->pstr_aac_tables, object_type,
983                                  ldmps_present, slot_element);
984 
985           if (slot_pos != NULL) *slot_pos = slot_element;
986           if (p_obj_exhaacplus_dec->p_state_aac->qshift_cnt > 15) {
987             return IA_FATAL_ERROR;
988           }
989 
990           p_obj_exhaacplus_dec->p_state_aac
991               ->qshift_adj[p_obj_exhaacplus_dec->p_state_aac->qshift_cnt++] =
992               str_ics_info[ch].qshift_adj;
993 
994           aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
995               ->overlap_add_data.win_shape = str_ics_info[ch].window_shape;
996           aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
997               ->overlap_add_data.win_seq = str_ics_info[ch].window_sequence;
998           if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) {
999             {
1000               if ((str_ics_info[ch].window_sequence == ONLY_LONG_SEQUENCE) ||
1001                   (str_ics_info[ch].window_sequence == LONG_STOP_SEQUENCE)) {
1002                 ixheaacd_lt_update_state(
1003                     aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
1004                         ->ltp_buf,
1005                     time_data + slot_element, overlap1,
1006                     aac_dec_handle->samples_per_frame, object_type,
1007                     (WORD16)ch_fac, str_ics_info[ch].window_sequence,
1008                     (WORD16 *)ptr_long_window_next, slot_element);
1009               } else {
1010                 ixheaacd_lt_update_state(
1011                     aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
1012                         ->ltp_buf,
1013                     time_data + slot_element, overlap1,
1014                     aac_dec_handle->samples_per_frame, object_type,
1015                     (WORD16)ch_fac, str_ics_info[ch].window_sequence,
1016                     (WORD16 *)ptr_short_window_next, slot_element);
1017               }
1018             }
1019           }
1020           if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
1021             ia_aac_dec_channel_info *pstr_aac_dec_static_channel_info =
1022                 aac_dec_handle->ptr_aac_dec_static_channel_info[ch];
1023             ia_ec_state_str *pstr_ec_state = &pstr_aac_dec_static_channel_info->str_ec_state;
1024             WORD32 k;
1025 
1026             if (pstr_ec_state->fade_idx < MAX_FADE_FRAMES) {
1027               WORD32 fade_fac = ia_ec_fade_factors_fix[pstr_ec_state->fade_idx];
1028               for (k = 0; k < str_ics_info[ch].frame_length; k++) {
1029                 time_data[k] = ixheaacd_mul32_sh(time_data[k], fade_fac, 30);
1030               }
1031             } else {
1032               memset(time_data, 0, str_ics_info[ch].frame_length * sizeof(time_data[0]));
1033             }
1034           }
1035           slot_element++;
1036         }
1037       }
1038     }
1039 
1040   if (ele_type == ID_END) {
1041     if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
1042       if (err && !is_init) {
1043         aac_dec_handle->frame_status = 0;
1044       } else {
1045         ixheaacd_byte_align(it_bit_buff, &aac_dec_handle->byte_align_bits);
1046         if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
1047           ixheaacd_byte_align(it_bit_buff, &it_bit_buff->audio_mux_align);
1048         }
1049       }
1050     } else {
1051       ixheaacd_byte_align(it_bit_buff, &aac_dec_handle->byte_align_bits);
1052       if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
1053         ixheaacd_byte_align(it_bit_buff, &it_bit_buff->audio_mux_align);
1054       }
1055     }
1056   }
1057   *type = ele_type;
1058 
1059   aac_dec_handle->block_number =
1060       ixheaacd_add32(aac_dec_handle->block_number, 1);
1061   if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
1062     p_obj_exhaacplus_dec->aac_config.frame_status = aac_dec_handle->frame_status;
1063     return IA_NO_ERROR;
1064   } else {
1065     return error_code;
1066   }
1067 }
1068 
ixheaacd_extension_payload(ia_bit_buf_struct * it_bit_buff,WORD32 * cnt,ia_mps_dec_state_struct * self)1069 WORD32 ixheaacd_extension_payload(ia_bit_buf_struct *it_bit_buff, WORD32 *cnt,
1070                                   ia_mps_dec_state_struct *self) {
1071   WORD16 extension_type;
1072   WORD32 len, add_len;
1073   WORD32 i;
1074   WORD32 fill_nibble;
1075 
1076   WORD32 err = 0;
1077   extension_type = (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4);
1078   switch (extension_type) {
1079     case EXT_FILL_DATA:
1080 
1081       fill_nibble = ixheaacd_read_bits_buf(it_bit_buff, 4);
1082 
1083       if (fill_nibble == 0) {
1084         for (i = 0; i < (*cnt >> 3) - 1; i++) {
1085           if (it_bit_buff->cnt_bits >= 8)
1086             ixheaacd_read_bits_buf(it_bit_buff, 8);
1087           else
1088             ixheaacd_read_bits_buf(it_bit_buff, it_bit_buff->cnt_bits);
1089         }
1090 
1091       } else
1092           err = -1;
1093       *cnt = it_bit_buff->cnt_bits;
1094       break;
1095 
1096     case EXT_DATA_LENGTH:
1097 
1098       len = ixheaacd_read_bits_buf(it_bit_buff, 4);
1099 
1100       if (len == 15) {
1101         add_len = ixheaacd_read_bits_buf(it_bit_buff, 8);
1102         len += add_len;
1103 
1104         if (add_len == 255) {
1105           len += ixheaacd_read_bits_buf(it_bit_buff, 16);
1106         }
1107       }
1108       len <<= 3;
1109 
1110       ixheaacd_extension_payload(it_bit_buff, cnt, self);
1111       break;
1112 
1113     case EXT_LDSAC_DATA:
1114 
1115       self->parse_nxt_frame = 1;
1116       ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_type*/
1117       ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_start_stop*/
1118 
1119       err = ixheaacd_ld_mps_frame_parsing(self, it_bit_buff);
1120       if (err) return err;
1121 
1122       *cnt = it_bit_buff->cnt_bits;
1123       break;
1124     case EXT_FIL:
1125     default:
1126 
1127       for (i = 0; i < (*cnt) - 4; i++) {
1128          ixheaacd_skip_bits_buf(it_bit_buff, 1);/*discard*/
1129       }
1130 
1131       *cnt = it_bit_buff->cnt_bits;
1132       break;
1133   }
1134 
1135   return err;
1136 }
1137