Coverage Report

Created: 2026-10-31 07:08

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