Coverage Report

Created: 2025-07-18 06:38

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