Coverage Report

Created: 2025-10-27 06:23

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.56M
#define SIZEOF_INT(x) ((sizeof(x) + sizeof(WORD32) - 1) / sizeof(WORD32))
92
93
8.19k
#define EXT_FILL_DATA 1
94
52.2k
#define EXT_FIL 0
95
4.83k
#define EXT_DATA_LENGTH 3
96
8.15k
#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
273k
    WORD32 *mps_header, WORD32 *mps_bytes, WORD32 is_init, WORD32 first_frame) {
111
273k
  WORD ch, ele_type;
112
273k
  ia_aac_dec_state_struct *p_state_enhaacplus_dec;
113
273k
  ia_aac_decoder_struct *aac_dec_handle;
114
273k
  ia_bit_buf_struct *it_bit_buff;
115
273k
  ixheaacd_latm_struct *latm_element;
116
117
273k
  WORD error_code = (WORD)frame_status;
118
273k
  WORD previous_element;
119
273k
  WORD prev_data_ele_present = 0;
120
273k
  WORD new_element;
121
273k
  WORD32 num_ch = 0;
122
123
273k
  WORD32 crc_reg = 0;
124
273k
  ia_adts_crc_info_struct *ptr_adts_crc_info;
125
126
273k
  WORD32 cnt_bits = 0;
127
128
273k
  WORD32 eld_sbr_flag = eld_specific_config.ld_sbr_flag_present;
129
273k
  WORD32 ld_sbr_crc_flag = eld_specific_config.ld_sbr_crc_flag;
130
273k
  WORD32 aac_spect_data_resil_flag =
131
273k
      eld_specific_config.aac_spect_data_resil_flag;
132
133
273k
  WORD32 ele_ch = 0;
134
135
273k
  ia_aac_sfb_code_book_struct *ptr_aac_sfb_code_book_data[CHANNELS];
136
273k
  ia_pns_stereo_data_struct *ptr_pns_stereo_data;
137
138
273k
  WORD32 *work_buffer_core = aac_scratch_ptrs->base_scr_8k;
139
273k
  WORD32 *work_buffer_1 = aac_scratch_ptrs->extra_scr_4k[0];
140
273k
  WORD32 *work_buffer_2 = aac_scratch_ptrs->extra_scr_4k[2];
141
273k
  p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac;
142
143
273k
  WORD32 *time_data = (WORD32 *)time_data_tmp;
144
145
273k
  aac_dec_handle = p_state_enhaacplus_dec->pstr_aac_dec_info[*ch_idx];
146
273k
  it_bit_buff = p_state_enhaacplus_dec->ptr_bit_stream;
147
148
273k
  ptr_adts_crc_info = it_bit_buff->pstr_adts_crc_info;
149
150
273k
  latm_element = &p_state_enhaacplus_dec->latm_struct_element;
151
152
273k
  ptr_pns_stereo_data =
153
273k
      (ia_pns_stereo_data_struct
154
273k
           *)&work_buffer_1[2 * SIZEOF_INT(ia_aac_dec_channel_info_struct) +
155
273k
                            2 * SIZEOF_INT(ia_aac_sfb_code_book_struct)];
156
157
273k
  aac_dec_handle->frame_status = 1;
158
159
612k
  for (ch = 0; ch < channel; ch++) {
160
338k
    const ia_aac_dec_imdct_tables_struct *pstr_imdct_tables;
161
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch] =
162
338k
        (ia_aac_dec_channel_info_struct
163
338k
             *)&work_buffer_1[ch * SIZEOF_INT(ia_aac_dec_channel_info_struct)];
164
338k
    ptr_aac_sfb_code_book_data[ch] =
165
338k
        (ia_aac_sfb_code_book_struct
166
338k
             *)&work_buffer_1[2 * SIZEOF_INT(ia_aac_dec_channel_info_struct) +
167
338k
                              (ch * SIZEOF_INT(ia_aac_sfb_code_book_struct))];
168
169
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_scale_factor =
170
338k
        ptr_aac_sfb_code_book_data[ch]->scale_factor;
171
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_code_book =
172
338k
        ptr_aac_sfb_code_book_data[ch]->code_book;
173
174
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff =
175
338k
        &work_buffer_core[ch * MAX_BINS_LONG];
176
177
338k
    if (object_type == AOT_ER_AAC_ELD) {
178
111k
      aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff =
179
111k
          &work_buffer_core[2 * ch * MAX_BINS_LONG];
180
111k
    }
181
182
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_stereo_info =
183
338k
        &ptr_pns_stereo_data->str_stereo_info;
184
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_pns_corr_info =
185
338k
        &ptr_pns_stereo_data->str_pns_corr_info;
186
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_pns_rand_vec_data =
187
338k
        aac_dec_handle->pstr_pns_rand_vec_data;
188
189
338k
    pstr_imdct_tables = aac_dec_handle->pstr_aac_tables->pstr_imdct_tables;
190
191
338k
    if (960 != frame_length) {
192
273k
      aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
193
273k
          pstr_imdct_tables->only_long_window_sine;
194
273k
      aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[0] =
195
273k
          pstr_imdct_tables->only_short_window_sine;
196
273k
      aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
197
273k
          pstr_imdct_tables->only_long_window_kbd;
198
273k
      aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[1] =
199
273k
          pstr_imdct_tables->only_short_window_kbd;
200
201
273k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[0] =
202
273k
          pstr_imdct_tables->only_long_window_sine;
203
273k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[0] =
204
273k
          pstr_imdct_tables->only_short_window_sine;
205
273k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[1] =
206
273k
          pstr_imdct_tables->only_long_window_kbd;
207
273k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[1] =
208
273k
          pstr_imdct_tables->only_short_window_kbd;
209
273k
    } else {
210
65.0k
      aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
211
65.0k
          pstr_imdct_tables->only_long_window_sine_960;
212
65.0k
      aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[0] =
213
65.0k
          pstr_imdct_tables->only_short_window_sine_120;
214
65.0k
      aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
215
65.0k
          pstr_imdct_tables->only_long_window_kbd_960;
216
65.0k
      aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[1] =
217
65.0k
          pstr_imdct_tables->only_short_window_kbd_120;
218
219
65.0k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[0] =
220
65.0k
          pstr_imdct_tables->only_long_window_sine_960;
221
65.0k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[0] =
222
65.0k
          pstr_imdct_tables->only_short_window_sine_120;
223
65.0k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[1] =
224
65.0k
          pstr_imdct_tables->only_long_window_kbd_960;
225
65.0k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[1] =
226
65.0k
          pstr_imdct_tables->only_short_window_kbd_120;
227
65.0k
    }
228
229
338k
    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
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.frame_length = frame_length;
235
338k
    if (object_type == AOT_ER_AAC_ELD || object_type == AOT_ER_AAC_LD ||
236
226k
        object_type == AOT_AAC_LTP) {
237
226k
      if (512 == aac_dec_handle->samples_per_frame) {
238
134k
        if (object_type != AOT_ER_AAC_ELD) {
239
69.5k
          aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
240
69.5k
              (WORD16 *)pstr_imdct_tables->low_overlap_win;
241
69.5k
          aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
242
69.5k
              (WORD16 *)pstr_imdct_tables->window_sine_512;
243
244
69.5k
          aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
245
69.5k
              ->ptr_long_window[1] =
246
69.5k
              (WORD16 *)pstr_imdct_tables->low_overlap_win;
247
69.5k
          aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
248
69.5k
              ->ptr_long_window[0] =
249
69.5k
              (WORD16 *)pstr_imdct_tables->window_sine_512;
250
69.5k
        } else {
251
64.9k
          aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
252
64.9k
              (WORD16 *)pstr_imdct_tables->window_sine_512_eld;
253
64.9k
          aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
254
64.9k
              (WORD16 *)pstr_imdct_tables->window_sine_512_eld;
255
64.9k
        }
256
134k
      } else if (480 == aac_dec_handle->samples_per_frame) {
257
64.8k
        if (object_type != AOT_ER_AAC_ELD) {
258
17.8k
          aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
259
17.8k
              (WORD16 *)pstr_imdct_tables->low_overlap_win_480;
260
17.8k
          aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
261
17.8k
              (WORD16 *)pstr_imdct_tables->window_sine_480;
262
263
17.8k
          aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
264
17.8k
              ->ptr_long_window[1] =
265
17.8k
              (WORD16 *)pstr_imdct_tables->low_overlap_win_480;
266
17.8k
          aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
267
17.8k
              ->ptr_long_window[0] =
268
17.8k
              (WORD16 *)pstr_imdct_tables->window_sine_480;
269
270
47.0k
        } else {
271
47.0k
          aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] =
272
47.0k
              (WORD16 *)pstr_imdct_tables->window_sine_480_eld;
273
47.0k
          aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] =
274
47.0k
              (WORD16 *)pstr_imdct_tables->window_sine_480_eld;
275
47.0k
        }
276
64.8k
      }
277
226k
    }
278
338k
    if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) {
279
114k
      if (aac_dec_handle->samples_per_frame <= 512) {
280
87.4k
        aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.lag =
281
87.4k
            aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1;
282
87.4k
        aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.lag =
283
87.4k
            aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_2;
284
87.4k
      }
285
114k
      aac_dec_handle->pstr_aac_dec_ch_info[ch]->ltp_buf =
286
114k
          aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_buf;
287
114k
      aac_dec_handle->pstr_aac_dec_ch_info[ch]->ltp_lag =
288
114k
          aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1;
289
114k
    }
290
291
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->scratch_buf_ptr = work_buffer_2;
292
338k
    if (object_type == AOT_ER_AAC_ELD) {
293
111k
      aac_dec_handle->pstr_aac_dec_ch_info[ch]->pulse_scratch =
294
111k
          aac_scratch_ptrs->extra_scr_4k[3];
295
111k
    }
296
338k
  }
297
298
273k
  if (channel == 2) {
299
64.4k
    if (aac_dec_handle->pstr_aac_dec_ch_info[1]->ptr_spec_coeff ==
300
64.4k
        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
64.4k
  }
305
306
612k
  for (ch = 0; ch < channel; ch++) {
307
338k
    ia_pns_info_struct *ptr_pns_info =
308
338k
        &aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_pns_info;
309
338k
    memset(ptr_pns_info, 0, sizeof(ia_pns_info_struct));
310
338k
  }
311
312
273k
  if (channel > 0) {
313
273k
    ia_pns_correlation_info_struct *ptr_corr_info =
314
273k
        aac_dec_handle->pstr_aac_dec_ch_info[0]->pstr_pns_corr_info;
315
273k
    memset(ptr_corr_info->correlated, 0, sizeof(UWORD8) * PNS_BAND_FLAGS_SIZE);
316
273k
  }
317
318
612k
  for (ch = 0; ch < channel; ch++) {
319
338k
    memset(&aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_hcr_info, 0,
320
338k
           sizeof(ia_hcr_info_struct));
321
338k
    ixheaacd_huff_code_reorder_tbl_init(
322
338k
        &aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_hcr_info);
323
338k
  }
324
325
612k
  for (ch = 0; ch < channel; ch++) {
326
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.data_present = 0;
327
338k
    aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.data_present =
328
338k
        0;
329
338k
  }
330
331
612k
  for (ch = 0; ch < channel; ch++) {
332
338k
    if (object_type == AOT_ER_AAC_ELD || object_type == AOT_ER_AAC_LD)
333
199k
      aac_dec_handle->pstr_aac_dec_ch_info[ch]->granule_len =
334
199k
          aac_dec_handle->samples_per_frame;
335
338k
    if (object_type == AOT_ER_AAC_LC)
336
52.3k
      aac_dec_handle->pstr_aac_dec_ch_info[ch]->granule_len =
337
52.3k
          aac_dec_handle->samples_per_frame / 8;
338
338k
  }
339
273k
  previous_element = ID_END;
340
341
273k
  aac_dec_handle->pstr_sbr_bitstream->no_elements = 0;
342
273k
  new_element = 0;
343
273k
  ele_type = *type;
344
345
273k
  cnt_bits = it_bit_buff->cnt_bits;
346
347
273k
  WORD32 err = 0;
348
273k
  jmp_buf local;
349
350
273k
  if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
351
0
    err = setjmp(local);
352
0
  }
353
354
273k
  if (!err && frame_status) {
355
273k
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
356
0
      it_bit_buff->xaac_jmp_buf = &local;
357
0
    }
358
359
273k
    if (((object_type != AOT_ER_AAC_ELD) && (object_type != AOT_ER_AAC_LD) &&
360
124k
         (object_type != AOT_ER_AAC_LC)) ||
361
198k
        (object_type < ER_OBJECT_START)) {
362
255k
      while (ele_type != ID_END && aac_dec_handle->frame_status) {
363
200k
        ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3);
364
200k
        ixheaacd_read_bidirection(it_bit_buff, -3);
365
366
200k
        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
200k
        if ((ele_type == ID_FIL) || (ele_type == ID_DSE) || (new_element == 0)) {
373
127k
          ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3);
374
127k
          new_element = 1;
375
127k
        } else if ((ele_type != ID_END)) {
376
17.9k
          ele_type = -1;
377
17.9k
          break;
378
55.0k
        } else {
379
55.0k
          ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3);
380
55.0k
        }
381
382
182k
        if (it_bit_buff->cnt_bits < 0) {
383
0
          aac_dec_handle->frame_status = 0;
384
0
        }
385
386
182k
        switch (ele_type) {
387
56.3k
          case ID_SCE:
388
59.0k
          case ID_CPE:
389
73.8k
          case ID_LFE:
390
391
73.8k
            if (aac_dec_handle->frame_status) {
392
73.8k
              ia_aac_dec_channel_info_struct *pstr_aac_dec_ch_info =
393
73.8k
                  aac_dec_handle->pstr_aac_dec_ch_info[LEFT];
394
73.8k
              ia_ics_info_struct *ptr_ics_info = &pstr_aac_dec_ch_info->str_ics_info;
395
73.8k
              ele_ch = 1;
396
73.8k
              if (ele_type == ID_CPE) {
397
2.60k
                ele_ch = 2;
398
71.2k
              } else {
399
71.2k
                ele_ch = 1;
400
71.2k
              }
401
402
73.8k
              prev_data_ele_present = 1;
403
404
73.8k
              if (ptr_adts_crc_info->crc_active == 1 && ptr_adts_crc_info->no_reg < 7) {
405
245
                crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff,
406
245
                                                      CRC_ADTS_RAW_DATA_BLK_LEN);
407
245
              }
408
409
73.8k
              pstr_aac_dec_ch_info->element_instance_tag =
410
73.8k
                  (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4);
411
412
73.8k
              element_index_order[*ch_idx] = pstr_aac_dec_ch_info->element_instance_tag;
413
73.8k
              pstr_aac_dec_ch_info->common_window = 0;
414
415
73.8k
              ptr_ics_info->num_swb_window = 0;
416
73.8k
              ptr_ics_info->sampling_rate_index = aac_dec_handle->sampling_rate_index;
417
73.8k
              if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) {
418
23.7k
                ptr_ics_info->ltp.data_present = 0;
419
23.7k
                ptr_ics_info->ltp2.data_present = 0;
420
23.7k
                ptr_ics_info->predictor_data_present = 0;
421
23.7k
              }
422
423
73.8k
              if (ele_ch > 1) {
424
2.59k
                aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.num_swb_window = 0;
425
2.59k
                aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.sampling_rate_index =
426
2.59k
                    aac_dec_handle->sampling_rate_index;
427
428
2.59k
                pstr_aac_dec_ch_info->common_window =
429
2.59k
                    (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 1);
430
431
2.59k
                if (pstr_aac_dec_ch_info->common_window) {
432
1.01k
                  error_code = ixheaacd_ics_read(
433
1.01k
                      it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, object_type,
434
1.01k
                      pstr_aac_dec_ch_info->common_window, aac_dec_handle->samples_per_frame);
435
1.01k
                  if (error_code) {
436
16
                    aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info =
437
16
                        aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->str_ics_info;
438
16
                    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
16
                    goto _ia_handle_error;
444
16
                  }
445
446
1.00k
                  aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info =
447
1.00k
                      pstr_aac_dec_ch_info->str_ics_info;
448
449
1.00k
                  ixheaacd_read_ms_data(it_bit_buff, pstr_aac_dec_ch_info);
450
1.00k
                }
451
2.59k
              }
452
453
73.8k
              error_code = ixheaacd_individual_ch_stream(
454
73.8k
                  it_bit_buff, aac_dec_handle, ele_ch, frame_length, total_channels, object_type,
455
73.8k
                  eld_specific_config, ele_type);
456
457
73.8k
              if (error_code) {
458
1.13k
                if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
459
0
                  aac_dec_handle->frame_status = 0;
460
1.13k
                } else {
461
1.13k
                  return error_code;
462
1.13k
                }
463
1.13k
              }
464
465
72.7k
              if (ptr_adts_crc_info->crc_active == 1) {
466
235
                ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg);
467
235
              }
468
469
72.7k
              if (it_bit_buff->cnt_bits < 0) {
470
18
                error_code =
471
18
                    (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
472
18
              }
473
474
72.7k
              if (error_code) {
475
18
                goto _ia_handle_error;
476
18
              }
477
478
72.7k
            _ia_handle_error:
479
72.1k
              if (error_code) {
480
34
                aac_dec_handle->frame_status = 0;
481
34
                if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) num_ch = num_ch + ele_ch;
482
34
                break;
483
72.1k
              } else {
484
72.1k
                error_code = ixheaacd_channel_pair_process(
485
72.1k
                    aac_dec_handle->pstr_aac_dec_ch_info, ele_ch, aac_dec_handle->pstr_aac_tables,
486
72.1k
                    total_channels, object_type, aac_spect_data_resil_flag,
487
72.1k
                    eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data,
488
72.1k
                    aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle);
489
72.1k
                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
72.1k
                num_ch = num_ch + ele_ch;
497
72.1k
              }
498
72.1k
            }
499
500
72.1k
            break;
501
72.1k
          case ID_CCE:
502
985
            if (max_channels > 2) {
503
985
              prev_data_ele_present = 1;
504
985
              error_code = ixheaacd_dec_coupling_channel_element(
505
985
                  it_bit_buff, aac_dec_handle, aac_dec_handle->sampling_rate_index,
506
985
                  aac_dec_handle->pstr_aac_tables, aac_dec_handle->pstr_common_tables,
507
985
                  &element_index_order[*ch_idx],
508
985
                  (ia_enhaacplus_dec_ind_cc *)aac_dec_handle->p_ind_channel_info, total_channels,
509
985
                  frame_length, object_type, eld_specific_config, ele_type);
510
511
985
              num_ch = num_ch + 1;
512
513
985
              if (error_code) {
514
54
                aac_dec_handle->frame_status = 0;
515
54
                if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
516
0
                  aac_dec_handle->frame_status = 0;
517
54
                } else {
518
54
                  return error_code;
519
54
                }
520
931
              } else {
521
931
                error_code = ixheaacd_channel_pair_process(
522
931
                    aac_dec_handle->pstr_aac_dec_ch_info, 1, aac_dec_handle->pstr_aac_tables,
523
931
                    total_channels, object_type, aac_spect_data_resil_flag,
524
931
                    eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data,
525
931
                    aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle);
526
931
                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
931
              }
534
985
            } else {
535
0
              error_code = (WORD32)((WORD32)IA_XHEAAC_DEC_EXE_FATAL_UNIMPLEMENTED_CCE);
536
0
            }
537
931
            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
931
            break;
542
543
7.45k
          case ID_DSE:
544
7.57k
          case ID_PCE:
545
52.5k
          case ID_FIL:
546
547
52.5k
          {
548
52.5k
            WORD32 flag = 1;
549
550
52.5k
            if ((ele_type != ID_FIL) && (ptr_adts_crc_info->crc_active == 1) &&
551
172
                (ptr_adts_crc_info->no_reg < 7)) {
552
69
              crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff, 0);
553
69
            }
554
52.5k
            if (ele_type == ID_DSE) {
555
7.45k
              ixheaacd_read_data_stream_element(it_bit_buff, &aac_dec_handle->byte_align_bits,
556
7.45k
                                                p_obj_exhaacplus_dec->p_state_aac->pstr_drc_dec);
557
7.45k
            }
558
559
45.0k
            else if (ele_type == ID_PCE) {
560
119
              error_code = ixheaacd_decode_pce(
561
119
                  it_bit_buff, &p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr,
562
119
                  &p_obj_exhaacplus_dec->aac_config.str_prog_config);
563
119
              if (error_code != 0) {
564
37
                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
37
                aac_dec_handle->frame_status = 0;
570
37
                if (error_code > 0) {
571
9
                  if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
572
0
                    aac_dec_handle->frame_status = 0;
573
9
                  } else {
574
9
                    return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR;
575
9
                  }
576
28
                } else {
577
28
                  if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
578
0
                    aac_dec_handle->frame_status = 0;
579
28
                  } else {
580
28
                    return error_code;
581
28
                  }
582
28
                }
583
37
              }
584
119
            }
585
586
44.9k
            else if (ele_type == ID_FIL) {
587
44.9k
              WORD32 bits_decoded = 0;
588
44.9k
              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
44.9k
              if (ixheaacd_check_for_sbr_payload(
603
44.9k
                      it_bit_buff, aac_dec_handle->pstr_sbr_bitstream, (WORD16)previous_element,
604
44.9k
                      pstr_drc_dec, object_type, adtsheader, cnt_bits, ld_sbr_crc_flag, drc_dummy,
605
44.9k
                      mps_buffer, mps_header, mps_bytes, is_init, &aac_dec_handle->is_first,
606
44.9k
                      p_obj_exhaacplus_dec->aac_config.ui_err_conceal)) {
607
24.5k
                flag = 0;
608
24.5k
              }
609
44.9k
            }
610
611
52.5k
            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
52.5k
            if (flag) {
617
27.8k
              if (prev_data_ele_present == 0) {
618
2.12k
                new_element = 0;
619
2.12k
              }
620
27.8k
            }
621
52.5k
            if ((ele_type != ID_FIL) && (ptr_adts_crc_info->crc_active == 1)) {
622
161
              ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg);
623
161
            }
624
625
52.5k
            if (ele_type == ID_PCE) {
626
64
              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
64
            }
631
52.5k
          }
632
633
0
          break;
634
635
54.9k
          case ID_END:
636
54.9k
            error_code = 0;
637
54.9k
            break;
638
182k
        }
639
640
180k
        previous_element = ele_type;
641
642
180k
        if (init_flag) {
643
23.4k
          if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) {
644
8.80k
            p_obj_exhaacplus_dec->aac_config.element_type[*ch_idx] = ele_type;
645
8.80k
          }
646
23.4k
        }
647
180k
      }
648
198k
    } else {
649
198k
      {
650
198k
        switch (ch_config) {
651
198k
          default:
652
198k
            if (aac_dec_handle->frame_status) {
653
198k
              ia_aac_dec_channel_info_struct *pstr_aac_dec_ch_info =
654
198k
                  aac_dec_handle->pstr_aac_dec_ch_info[LEFT];
655
198k
              ia_ics_info_struct *ptr_ics_info = &pstr_aac_dec_ch_info->str_ics_info;
656
657
198k
              if (ch_config == 2)
658
49.1k
                ele_ch = 2, ele_type = 1;
659
149k
              else
660
149k
                ele_ch = 1, ele_type = 0;
661
662
198k
              prev_data_ele_present = 1;
663
664
198k
              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
198k
              if (object_type != AOT_ER_AAC_ELD)
670
127k
                pstr_aac_dec_ch_info->element_instance_tag =
671
127k
                    (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4);
672
673
198k
              element_index_order[*ch_idx] = pstr_aac_dec_ch_info->element_instance_tag;
674
198k
              pstr_aac_dec_ch_info->common_window = 0;
675
676
198k
              ptr_ics_info->num_swb_window = 0;
677
198k
              ptr_ics_info->sampling_rate_index = aac_dec_handle->sampling_rate_index;
678
679
198k
              if (object_type == AOT_ER_AAC_LD) {
680
78.3k
                ptr_ics_info->ltp.data_present = 0;
681
78.3k
                ptr_ics_info->ltp2.data_present = 0;
682
78.3k
                ptr_ics_info->predictor_data_present = 0;
683
78.3k
              }
684
198k
              if (ele_ch > 1) {
685
49.1k
                aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.num_swb_window = 0;
686
49.1k
                aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.sampling_rate_index =
687
49.1k
                    aac_dec_handle->sampling_rate_index;
688
689
49.1k
                if (object_type != 39)
690
9.75k
                  pstr_aac_dec_ch_info->common_window =
691
9.75k
                      (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 1);
692
39.4k
                else
693
39.4k
                  pstr_aac_dec_ch_info->common_window = 1;
694
695
49.1k
                if (pstr_aac_dec_ch_info->common_window) {
696
47.2k
                  error_code = ixheaacd_ics_read(
697
47.2k
                      it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, object_type,
698
47.2k
                      pstr_aac_dec_ch_info->common_window, aac_dec_handle->samples_per_frame);
699
47.2k
                  if (error_code) {
700
26.9k
                    aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info =
701
26.9k
                        aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->str_ics_info;
702
26.9k
                    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
26.9k
                    goto _ia_handle_error1;
708
26.9k
                  }
709
710
20.3k
                  aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info =
711
20.3k
                      pstr_aac_dec_ch_info->str_ics_info;
712
713
20.3k
                  ixheaacd_read_ms_data(it_bit_buff, pstr_aac_dec_ch_info);
714
715
20.3k
                  {
716
20.3k
                    if (object_type == AOT_ER_AAC_LD) {
717
5.78k
                      IA_ERRORCODE temp =
718
5.78k
                          ixheaacd_ltp_decode(it_bit_buff, ptr_ics_info, object_type,
719
5.78k
                                              aac_dec_handle->samples_per_frame, LEFT);
720
721
5.78k
                      if (temp != 0) {
722
2
                        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
723
0
                          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
724
2
                        } else {
725
2
                          return temp;
726
2
                        }
727
2
                      }
728
5.78k
                    }
729
20.3k
                  }
730
20.3k
                }
731
49.1k
              }
732
733
171k
              error_code = ixheaacd_individual_ch_stream(
734
171k
                  it_bit_buff, aac_dec_handle, ele_ch, frame_length, total_channels, object_type,
735
171k
                  eld_specific_config, ele_type);
736
171k
              if (error_code) {
737
3.42k
                if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
738
0
                  aac_dec_handle->frame_status = 0;
739
3.42k
                } else {
740
3.42k
                  return error_code;
741
3.42k
                }
742
3.42k
              }
743
744
168k
              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
168k
              if (it_bit_buff->cnt_bits < 0) {
749
19
                error_code =
750
19
                    (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
751
19
              }
752
753
168k
              if (error_code) {
754
19
                goto _ia_handle_error1;
755
19
              }
756
757
194k
            _ia_handle_error1:
758
194k
              if (error_code) {
759
26.9k
                aac_dec_handle->frame_status = 0;
760
26.9k
                if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) num_ch = num_ch + ele_ch;
761
26.9k
                break;
762
167k
              } else {
763
167k
                error_code = ixheaacd_channel_pair_process(
764
167k
                    aac_dec_handle->pstr_aac_dec_ch_info, ele_ch, aac_dec_handle->pstr_aac_tables,
765
167k
                    total_channels, object_type, aac_spect_data_resil_flag,
766
167k
                    eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data,
767
167k
                    aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle);
768
167k
                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
167k
                num_ch = num_ch + ele_ch;
776
167k
              }
777
194k
            }
778
779
167k
            p_obj_exhaacplus_dec->aac_config.element_type[*ch_idx] = ele_ch - 1;
780
167k
            break;
781
198k
        }
782
783
194k
        if ((object_type == AOT_ER_AAC_LC) || (!eld_sbr_flag)) {
784
128k
          WORD32 cnt_bits;
785
128k
          cnt_bits = it_bit_buff->cnt_bits;
786
128k
          p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.ldmps_config.no_ldsbr_present = 1;
787
788
128k
          if (cnt_bits >= 8) {
789
127k
            error_code = ixheaacd_extension_payload(
790
127k
                it_bit_buff, &cnt_bits, &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle);
791
127k
            if (error_code) {
792
87
              if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) {
793
0
                aac_dec_handle->frame_status = 0;
794
87
              } else {
795
87
                return error_code;
796
87
              }
797
87
            }
798
127k
          }
799
800
128k
          if (it_bit_buff->cnt_bits) {
801
10.5k
            WORD32 alignment = it_bit_buff->bit_pos & 0x07;
802
10.5k
            it_bit_buff->cnt_bits = (it_bit_buff->cnt_bits + alignment) & 7;
803
10.5k
            it_bit_buff->bit_pos = 7;
804
10.5k
            it_bit_buff->ptr_read_next++;
805
10.5k
          }
806
128k
        }
807
808
66.6k
        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
66.6k
        } else {
847
66.6k
          WORD32 bits_decoded, cnt_bits;
848
66.6k
          bits_decoded = (it_bit_buff->size - it_bit_buff->cnt_bits);
849
66.6k
          cnt_bits = (frame_size * 8 - bits_decoded);
850
66.6k
          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
66.6k
          ixheaacd_check_for_sbr_payload(
860
66.6k
              it_bit_buff, aac_dec_handle->pstr_sbr_bitstream, (WORD16)(ch_config - 1),
861
66.6k
              pstr_drc_dec, object_type, adtsheader, cnt_bits, ld_sbr_crc_flag, drc_dummy,
862
66.6k
              mps_buffer, mps_header, mps_bytes, is_init, &aac_dec_handle->is_first,
863
66.6k
              p_obj_exhaacplus_dec->aac_config.ui_err_conceal);
864
66.6k
        }
865
194k
      }
866
194k
    }
867
273k
  }
868
267k
  if ((err || (aac_dec_handle->frame_status == 0) || (frame_status == 0)) && (!is_init)) {
869
26.9k
    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
26.9k
    } else {
878
26.9k
      return err;
879
26.9k
    }
880
26.9k
  }
881
240k
  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
240k
  if (ele_type == ID_END && p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
888
8.78k
    WORD32 tmp;
889
8.78k
    tmp = ((WORD32)latm_element->layer_info[0][0].frame_len_bits) -
890
8.78k
          (it_bit_buff->initial_cnt_bits - it_bit_buff->cnt_bits);
891
892
8.78k
    if (tmp > 0) ixheaacd_read_bidirection(it_bit_buff, tmp);
893
894
8.78k
    if (latm_element->other_data_present) {
895
2.27k
      WORD32 count_bits = (WORD32)latm_element->other_data_length;
896
2.27k
      ixheaacd_read_bidirection(it_bit_buff, count_bits);
897
2.27k
    }
898
8.78k
  }
899
900
240k
  if (object_type == AOT_ER_AAC_LD) {
901
161k
    for (ch = 0; ch < channel; ch++) {
902
85.2k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1 =
903
85.2k
          aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.lag;
904
85.2k
      aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_2 =
905
85.2k
          aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.lag;
906
85.2k
    }
907
76.4k
  }
908
240k
  aac_dec_handle->frame_status = aac_dec_handle->frame_status && frame_status;
909
910
240k
  aac_dec_handle->channels = num_ch;
911
912
240k
  if (error_code == 0)
913
240k
    if ((skip_full_decode == 0) || ((skip_full_decode == 1) && error_code)) {
914
240k
      ia_ics_info_struct str_ics_info[2];
915
240k
      WORD32 *spec_coef[2];
916
240k
      WORD32 *scratch[2];
917
918
515k
      for (ch = 0; ch < channel; ch++) {
919
275k
        str_ics_info[ch] = aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info;
920
275k
        spec_coef[ch] = aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff;
921
275k
      }
922
923
240k
      scratch[0] = (WORD32 *)aac_scratch_ptrs->extra_scr_4k[2];
924
240k
      scratch[1] = (WORD32 *)aac_scratch_ptrs->extra_scr_4k[1];
925
926
240k
      error_code = ixheaacd_drc_map_channels(
927
240k
          pstr_drc_dec, aac_dec_handle->channels,
928
240k
          aac_dec_handle->pstr_aac_dec_ch_info[0]->str_ics_info.frame_length);
929
240k
      if (error_code) {
930
6
        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
6
        } else {
934
6
          return error_code;
935
6
        }
936
6
      }
937
938
503k
      for (ch = 0; ch < aac_dec_handle->channels; ch++) {
939
263k
        WORD32 *overlap1 =
940
263k
            aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->overlap_add_data.ptr_overlap_buf;
941
263k
        const WORD16 *ptr_long_window_next =
942
263k
            aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
943
263k
                ->ptr_long_window[(int)str_ics_info[ch].window_shape];
944
263k
        const WORD16 *ptr_short_window_next =
945
263k
            aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
946
263k
                ->ptr_short_window[(int)str_ics_info[ch].window_shape];
947
263k
        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
263k
        if (pstr_drc_dec->drc_on) {
981
263k
          ixheaacd_drc_apply(pstr_drc_dec, spec_coef[ch],
982
263k
                             str_ics_info[ch].window_sequence, ch,
983
263k
                             str_ics_info[ch].frame_length,
984
263k
                             p_obj_exhaacplus_dec->aac_config.ui_enh_sbr, object_type);
985
263k
        }
986
263k
        if (skip_full_decode == 0) {
987
263k
          ixheaacd_imdct_process(aac_dec_handle->pstr_aac_dec_overlap_info[ch],
988
263k
                                 spec_coef[ch], &str_ics_info[ch],
989
263k
                                 time_data + slot_element, ch_fac, scratch[ch],
990
263k
                                 aac_dec_handle->pstr_aac_tables, object_type,
991
263k
                                 ldmps_present, slot_element);
992
993
263k
          if (slot_pos != NULL) *slot_pos = slot_element;
994
263k
          if (p_obj_exhaacplus_dec->p_state_aac->qshift_cnt > 15) {
995
2
            return IA_FATAL_ERROR;
996
2
          }
997
998
263k
          p_obj_exhaacplus_dec->p_state_aac
999
263k
              ->qshift_adj[p_obj_exhaacplus_dec->p_state_aac->qshift_cnt++] =
1000
263k
              str_ics_info[ch].qshift_adj;
1001
1002
263k
          aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
1003
263k
              ->overlap_add_data.win_shape = str_ics_info[ch].window_shape;
1004
263k
          aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
1005
263k
              ->overlap_add_data.win_seq = str_ics_info[ch].window_sequence;
1006
263k
          if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) {
1007
108k
            {
1008
108k
              if ((str_ics_info[ch].window_sequence == ONLY_LONG_SEQUENCE) ||
1009
71.4k
                  (str_ics_info[ch].window_sequence == LONG_STOP_SEQUENCE)) {
1010
71.4k
                ixheaacd_lt_update_state(
1011
71.4k
                    aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
1012
71.4k
                        ->ltp_buf,
1013
71.4k
                    time_data + slot_element, overlap1,
1014
71.4k
                    aac_dec_handle->samples_per_frame, object_type,
1015
71.4k
                    (WORD16)ch_fac, str_ics_info[ch].window_sequence,
1016
71.4k
                    (WORD16 *)ptr_long_window_next, slot_element);
1017
71.4k
              } else {
1018
36.6k
                ixheaacd_lt_update_state(
1019
36.6k
                    aac_dec_handle->ptr_aac_dec_static_channel_info[ch]
1020
36.6k
                        ->ltp_buf,
1021
36.6k
                    time_data + slot_element, overlap1,
1022
36.6k
                    aac_dec_handle->samples_per_frame, object_type,
1023
36.6k
                    (WORD16)ch_fac, str_ics_info[ch].window_sequence,
1024
36.6k
                    (WORD16 *)ptr_short_window_next, slot_element);
1025
36.6k
              }
1026
108k
            }
1027
108k
          }
1028
263k
          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
263k
          slot_element++;
1044
263k
        }
1045
263k
      }
1046
240k
    }
1047
1048
240k
  if (ele_type == ID_END) {
1049
54.8k
    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
54.8k
    } else {
1059
54.8k
      ixheaacd_byte_align(it_bit_buff, &aac_dec_handle->byte_align_bits);
1060
54.8k
      if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
1061
8.76k
        ixheaacd_byte_align(it_bit_buff, &it_bit_buff->audio_mux_align);
1062
8.76k
      }
1063
54.8k
    }
1064
54.8k
  }
1065
240k
  *type = ele_type;
1066
1067
240k
  aac_dec_handle->block_number =
1068
240k
      ixheaac_add32(aac_dec_handle->block_number, 1);
1069
240k
  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
240k
  } else {
1073
240k
    return error_code;
1074
240k
  }
1075
240k
}
1076
1077
WORD32 ixheaacd_extension_payload(ia_bit_buf_struct *it_bit_buff, WORD32 *cnt,
1078
138k
                                  ia_mps_dec_state_struct *self) {
1079
138k
  WORD16 extension_type;
1080
138k
  WORD32 len, add_len;
1081
138k
  WORD32 i;
1082
138k
  WORD32 fill_nibble;
1083
1084
138k
  WORD32 err = 0;
1085
138k
  extension_type = (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4);
1086
138k
  switch (extension_type) {
1087
8.19k
    case EXT_FILL_DATA:
1088
1089
8.19k
      fill_nibble = ixheaacd_read_bits_buf(it_bit_buff, 4);
1090
1091
8.19k
      if (fill_nibble == 0) {
1092
23.2M
        for (i = 0; i < (*cnt >> 3) - 1; i++) {
1093
23.2M
          if (it_bit_buff->cnt_bits >= 8)
1094
23.2M
            ixheaacd_read_bits_buf(it_bit_buff, 8);
1095
458
          else
1096
458
            ixheaacd_read_bits_buf(it_bit_buff, it_bit_buff->cnt_bits);
1097
23.2M
        }
1098
1099
4.64k
      } else
1100
3.54k
          err = -1;
1101
8.19k
      *cnt = it_bit_buff->cnt_bits;
1102
8.19k
      break;
1103
1104
4.83k
    case EXT_DATA_LENGTH:
1105
1106
4.83k
      len = ixheaacd_read_bits_buf(it_bit_buff, 4);
1107
1108
4.83k
      if (len == 15) {
1109
465
        add_len = ixheaacd_read_bits_buf(it_bit_buff, 8);
1110
465
        len += add_len;
1111
1112
465
        if (add_len == 255) {
1113
137
          len += ixheaacd_read_bits_buf(it_bit_buff, 16);
1114
137
        }
1115
465
      }
1116
4.83k
      len <<= 3;
1117
1118
4.83k
      ixheaacd_extension_payload(it_bit_buff, cnt, self);
1119
4.83k
      break;
1120
1121
8.15k
    case EXT_LDSAC_DATA:
1122
1123
8.15k
      self->parse_nxt_frame = 1;
1124
8.15k
      ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_type*/
1125
8.15k
      ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_start_stop*/
1126
1127
8.15k
      if (self->ldmps_config.ldmps_present_flag == 1) {
1128
2.82k
        err = ixheaacd_ld_mps_frame_parsing(self, it_bit_buff);
1129
2.82k
        if (err) return err;
1130
2.82k
      }
1131
1132
8.11k
      *cnt = it_bit_buff->cnt_bits;
1133
8.11k
      break;
1134
52.2k
    case EXT_FIL:
1135
116k
    default:
1136
1137
5.13G
      for (i = 0; i < (*cnt) - 4; i++) {
1138
5.13G
         ixheaacd_skip_bits_buf(it_bit_buff, 1);/*discard*/
1139
5.13G
      }
1140
1141
116k
      *cnt = it_bit_buff->cnt_bits;
1142
116k
      break;
1143
138k
  }
1144
1145
136k
  return err;
1146
138k
}