Coverage Report

Created: 2026-02-07 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_api.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 <string.h>
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include "ixheaacd_sbr_common.h"
24
#include "ixheaac_type_def.h"
25
#include "ixheaacd_memory_standards.h"
26
#include "ixheaacd_mps_struct_def.h"
27
#include "ixheaacd_mps_res_rom.h"
28
#include "ixheaacd_mps_aac_struct.h"
29
#include "ixheaac_constants.h"
30
#include "ixheaac_basic_ops32.h"
31
#include "ixheaac_basic_ops16.h"
32
#include "ixheaac_basic_ops40.h"
33
#include "ixheaac_basic_ops.h"
34
35
#include "ixheaac_error_standards.h"
36
#include "ixheaacd_apicmd_standards.h"
37
#include "ixheaacd_aac_config.h"
38
#include "ixheaacd_api_defs.h"
39
40
#include "ixheaacd_definitions.h"
41
#include "ixheaacd_error_codes.h"
42
#include "ixheaacd_bitbuffer.h"
43
44
#include "ixheaacd_audioobjtypes.h"
45
#include "ixheaacd_sbrdecsettings.h"
46
#include "ixheaacd_memory_standards.h"
47
48
#include "ixheaacd_bitbuffer.h"
49
#include "ixheaacd_adts.h"
50
#include "ixheaacd_defines.h"
51
#include "ixheaacd_cnst.h"
52
#include "ixheaacd_aac_rom.h"
53
#include "ixheaacd_ec_defines.h"
54
#include "ixheaacd_ec_struct_def.h"
55
56
#include "ixheaacd_sbr_scale.h"
57
#include "ixheaacd_lpp_tran.h"
58
#include "ixheaacd_env_extr_part.h"
59
#include "ixheaacd_sbr_rom.h"
60
61
#include "ixheaacd_hybrid.h"
62
#include "ixheaacd_ps_dec.h"
63
#include "ixheaacd_ps_bitdec.h"
64
65
#include "ixheaacd_pulsedata.h"
66
67
#include "ixheaacd_pns.h"
68
#include "ixheaacd_drc_data_struct.h"
69
70
#include "ixheaacd_lt_predict.h"
71
72
#include "ixheaacd_channelinfo.h"
73
#include "ixheaacd_drc_dec.h"
74
#include "ixheaac_sbr_const.h"
75
#include "ixheaacd_sbrdecoder.h"
76
#include "ixheaacd_env_extr.h"
77
#include "ixheaacd_common_rom.h"
78
#include "ixheaacd_freq_sca.h"
79
#include "ixheaacd_qmf_dec.h"
80
#include "ixheaacd_env_calc.h"
81
82
#include "ixheaacd_pvc_dec.h"
83
#include "ixheaacd_sbr_dec.h"
84
#include "ixheaacd_block.h"
85
#include "ixheaacd_channel.h"
86
87
#include "ixheaacd_audioobjtypes.h"
88
#include "ixheaacd_latmdemux.h"
89
90
#include "ixheaacd_aacdec.h"
91
#include "ixheaacd_mps_polyphase.h"
92
#include "ixheaacd_config.h"
93
#include "ixheaacd_mps_dec.h"
94
#include "ixheaacd_struct_def.h"
95
#include "ixheaacd_headerdecode.h"
96
#include "ixheaacd_adts_crc_check.h"
97
98
#include "ixheaacd_multichannel.h"
99
#include "ixheaacd_ver_number.h"
100
101
#include "ixheaacd_interface.h"
102
#include "ixheaacd_info.h"
103
104
#include "ixheaacd_config.h"
105
106
#include "ixheaacd_struct.h"
107
#include "ixheaacd_mps_polyphase.h"
108
#include "ixheaacd_tns_usac.h"
109
#include "ixheaacd_acelp_info.h"
110
111
#include "ixheaacd_main.h"
112
#include "ixheaacd_arith_dec.h"
113
#include "ixheaacd_create.h"
114
#include "ixheaacd_function_selector.h"
115
#include "ixheaacd_ld_mps_dec.h"
116
#include "ixheaacd_mps_tables.h"
117
#define MAX_TRACKS_PER_LAYER 50
118
119
#define ALIGN_SIZE64(x) ((((x) + 7) >> 3) << 3)
120
121
325k
#define IA_ENHAACPDEC_NUM_MEMTABS (4)
122
123
0
#define NUM_AAC_TABLES 8
124
125
730k
#define LD_OBJ -2
126
127
#define SCR_BASE_SCR_8K_SIZE \
128
225k
  (IXHEAAC_GET_SIZE_ALIGNED((2 * CHANNELS * MAX_BINS_LONG * sizeof(WORD32)), BYTE_ALIGN_8))
129
#define SCR_EXTRA_SCR_4K_0_SIZE                                                           \
130
349k
  (2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_channel_info_struct), sizeof(WORD32)) + \
131
349k
   2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_sfb_code_book_struct), sizeof(WORD32)) +    \
132
349k
   IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_pns_stereo_data_struct), sizeof(WORD32)))
133
#define SCR_EXTRA_SCR_4K_2_SIZE \
134
349k
  (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8))
135
#define SCR_EXTRA_SCR_4K_3_SIZE \
136
123k
  (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8))
137
#define SCR_OUT_DATA_SIZE \
138
91.6k
  (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8))
139
#define SCR_IN_DATA_SIZE                                                                \
140
91.6k
  (2 * IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), \
141
91.6k
                                BYTE_ALIGN_8))
142
#define SCR_INTER_SCR_SIZE                                                          \
143
210k
  (MAX_CHANNEL_COUNT *                                                              \
144
210k
   IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD16)), \
145
210k
                            BYTE_ALIGN_8))
146
#define SCR_COUP_CH_OUT_SIZE                                                        \
147
197k
  (MAX_CHANNEL_COUNT *                                                              \
148
197k
   IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD16)), \
149
197k
                            BYTE_ALIGN_8))
150
151
#define P_IND_CH_INFO_OFFSET \
152
154
  (SCR_BASE_SCR_8K_SIZE + SCR_EXTRA_SCR_4K_0_SIZE + SCR_EXTRA_SCR_4K_2_SIZE)
153
154
#define HEAACV2_MAX_SIZE                                                          \
155
  (max(SCR_BASE_SCR_8K_SIZE + SCR_EXTRA_SCR_4K_0_SIZE + SCR_EXTRA_SCR_4K_2_SIZE + \
156
           SCR_INTER_SCR_SIZE + SCR_COUP_CH_OUT_SIZE,                             \
157
       MPS_SCRATCH_MEM_SIZE))
158
#define ELDV2_MAX_SIZE                                                            \
159
  (max(SCR_BASE_SCR_8K_SIZE + SCR_EXTRA_SCR_4K_0_SIZE + SCR_EXTRA_SCR_4K_2_SIZE + \
160
           SCR_EXTRA_SCR_4K_3_SIZE + SCR_INTER_SCR_SIZE + SCR_COUP_CH_OUT_SIZE,   \
161
       MPS_SCRATCH_MEM_SIZE))
162
#define LD_MAX_SIZE                                                                          \
163
  (max(SCR_BASE_SCR_8K_SIZE + SCR_EXTRA_SCR_4K_0_SIZE + SCR_EXTRA_SCR_4K_2_SIZE +            \
164
           SCR_OUT_DATA_SIZE + SCR_IN_DATA_SIZE + SCR_INTER_SCR_SIZE + SCR_COUP_CH_OUT_SIZE, \
165
       MPS_SCRATCH_MEM_SIZE))
166
167
227k
#define MAX_SCR_SIZE (max(max(HEAACV2_MAX_SIZE, ELDV2_MAX_SIZE), LD_MAX_SIZE))
168
169
IA_ERRORCODE ixheaacd_dec_mem_api(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec,
170
273k
                                  WORD32 i_cmd, WORD32 i_idx, VOID *pv_value) {
171
273k
  pUWORD32 pui_value = pv_value;
172
173
273k
  if (i_idx < 0 || i_idx >= IA_ENHAACPDEC_NUM_MEMTABS) {
174
0
    return IA_XHEAAC_DEC_API_FATAL_INVALID_MEMTAB_INDEX;
175
0
  }
176
177
273k
  if (i_cmd == IA_API_CMD_SET_MEM_PTR) {
178
68.4k
    if (pv_value == 0) {
179
0
      return (IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC);
180
0
    }
181
68.4k
    if (((SIZE_T)pv_value %
182
68.4k
         p_obj_exhaacplus_dec->p_mem_info_aac[i_idx].ui_alignment) != 0) {
183
0
      return (IA_XHEAAC_DEC_API_FATAL_MEM_ALIGN);
184
0
    }
185
68.4k
    p_obj_exhaacplus_dec->pp_mem_aac[i_idx] = pv_value;
186
68.4k
    memset(p_obj_exhaacplus_dec->pp_mem_aac[i_idx], 0,
187
68.4k
           p_obj_exhaacplus_dec->p_mem_info_aac[i_idx].ui_size);
188
189
68.4k
    if (i_idx == IA_ENHAACPLUS_DEC_PERSIST_IDX) {
190
17.1k
      pUWORD8 p_temp = pv_value;
191
17.1k
      UWORD32 *meminfo =
192
17.1k
          (UWORD32 *)p_obj_exhaacplus_dec->p_mem_info_aac + i_idx;
193
17.1k
      UWORD32 pers_size = meminfo[0];
194
17.1k
      p_temp = p_temp + pers_size -
195
17.1k
               (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) +
196
17.1k
                IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8) +
197
17.1k
                IXHEAAC_GET_SIZE_ALIGNED(MAX_HEADER_BUF_SIZE, BYTE_ALIGN_8));
198
17.1k
      p_obj_exhaacplus_dec->p_state_aac = pv_value;
199
17.1k
      memset(p_obj_exhaacplus_dec->p_state_aac, 0,
200
17.1k
             IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8));
201
17.1k
      p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data = p_temp;
202
17.1k
      p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config =
203
17.1k
          p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8);
204
17.1k
      p_obj_exhaacplus_dec->p_state_aac->header_ptr =
205
17.1k
          p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) +
206
17.1k
          IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8);
207
17.1k
    }
208
209
205k
  } else {
210
205k
    UWORD32 *meminfo =
211
205k
        (UWORD32 *)(p_obj_exhaacplus_dec->p_mem_info_aac + i_idx);
212
205k
    *pui_value = *(meminfo + (i_cmd - IA_API_CMD_GET_MEM_INFO_SIZE));
213
205k
  }
214
215
273k
  return IA_NO_ERROR;
216
273k
}
217
218
static PLATFORM_INLINE VOID
219
17.1k
ixheaacd_init_sbr_tables(ia_sbr_tables_struct *ptr_sbr_tables) {
220
17.1k
  ptr_sbr_tables->env_calc_tables_ptr =
221
17.1k
      (ia_env_calc_tables_struct *)&ixheaacd_aac_dec_env_calc_tables;
222
17.1k
  ptr_sbr_tables->qmf_dec_tables_ptr =
223
17.1k
      (ia_qmf_dec_tables_struct *)&ixheaacd_aac_qmf_dec_tables;
224
17.1k
  ptr_sbr_tables->env_extr_tables_ptr =
225
17.1k
      (ia_env_extr_tables_struct *)&ixheaacd_aac_dec_env_extr_tables;
226
17.1k
  ptr_sbr_tables->ps_tables_ptr =
227
17.1k
      (ia_ps_tables_struct *)&ixheaacd_aac_dec_ps_tables;
228
17.1k
}
229
230
VOID ixheaacd_updatebytesconsumed(
231
    ia_aac_dec_state_struct *p_state_enhaacplus_dec,
232
199k
    struct ia_bit_buf_struct *it_bit_buff) {
233
199k
  p_state_enhaacplus_dec->i_bytes_consumed =
234
199k
      (WORD32)(it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base);
235
199k
  if ((p_state_enhaacplus_dec->i_bytes_consumed == 0) &&
236
2.14k
      (it_bit_buff->cnt_bits == 0)) {
237
0
    p_state_enhaacplus_dec->i_bytes_consumed =
238
0
        p_state_enhaacplus_dec->ui_in_bytes;
239
0
  }
240
199k
  if (it_bit_buff->cnt_bits < 0) {
241
114
    p_state_enhaacplus_dec->i_bytes_consumed = 0;
242
114
    p_state_enhaacplus_dec->ui_out_bytes = 0;
243
114
    p_state_enhaacplus_dec->ui_mps_out_bytes = 0;
244
114
    p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
245
114
  }
246
199k
}
247
248
static VOID copy_qmf_to_ldmps(ia_mps_dec_state_struct *mps_dec_handle,
249
10.0k
                              VOID *sbr_persistent_mem_v) {
250
10.0k
  ia_sbr_pers_struct *sbr_persistent_mem =
251
10.0k
      (ia_sbr_pers_struct *)sbr_persistent_mem_v;
252
10.0k
  memcpy(&mps_dec_handle->str_mps_qmf_bank,
253
10.0k
         &sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[0]
254
10.0k
              ->str_sbr_dec.str_codec_qmf_bank,
255
10.0k
         sizeof(ia_sbr_qmf_filter_bank_struct));
256
257
10.0k
  mps_dec_handle->sbr_tables_ptr =
258
10.0k
      sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables;
259
10.0k
  mps_dec_handle->qmf_dec_tables_ptr =
260
10.0k
      sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables->qmf_dec_tables_ptr;
261
10.0k
  mps_dec_handle->str_sbr_scale_fact =
262
10.0k
      &sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[0]
263
10.0k
           ->str_sbr_dec.str_sbr_scale_fact;
264
10.0k
}
265
266
WORD32 ixheaacd_readifadts(ia_aac_dec_state_struct *p_state_enhaacplus_dec,
267
                           struct ia_bit_buf_struct *it_bit_buff,
268
35.4k
                           ia_adts_header_struct *adts) {
269
35.4k
  WORD error;
270
271
35.4k
  if ((error = ixheaacd_find_syncword(adts, it_bit_buff)) != 0) {
272
832
    ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
273
832
    return IA_XHEAAC_DEC_EXE_NONFATAL_ADTS_SYNC_LOST;
274
832
  }
275
34.5k
  if ((error = ixheaacd_check_if_adts(
276
34.5k
           adts, it_bit_buff,
277
34.5k
           p_state_enhaacplus_dec->p_config->ui_max_channels)) != 0) {
278
185
    p_state_enhaacplus_dec->i_bytes_consumed = 1;
279
280
185
    if (it_bit_buff->cnt_bits < 0) {
281
0
      p_state_enhaacplus_dec->i_bytes_consumed = 0;
282
0
      p_state_enhaacplus_dec->ui_out_bytes = 0;
283
0
      p_state_enhaacplus_dec->ui_mps_out_bytes = 0;
284
0
      error = IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
285
0
      return error;
286
0
    }
287
185
    return IA_XHEAAC_DEC_EXE_NONFATAL_ADTS_SYNC_LOST;
288
185
  }
289
34.3k
  p_state_enhaacplus_dec->b_n_raw_data_blk =
290
34.3k
      (WORD8)(adts->no_raw_data_blocks + 1);
291
34.3k
  return 0;
292
34.5k
}
293
294
static VOID ixheaacd_allocate_aac_scr(
295
    ia_aac_dec_scratch_struct *aac_scratch_struct, VOID *base_scratch_ptr,
296
    VOID *output_ptr, WORD channel, WORD max_channel,
297
225k
    WORD32 audio_object_type) {
298
225k
  WORD32 scratch_used = 0;
299
225k
  aac_scratch_struct->base_scr_8k = base_scratch_ptr;
300
225k
  aac_scratch_struct->extra_scr_4k[1] = (WORD8 *)base_scratch_ptr;
301
225k
  scratch_used += SCR_BASE_SCR_8K_SIZE;
302
225k
  if (channel == 1) {
303
184k
    aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used;
304
184k
    scratch_used += SCR_EXTRA_SCR_4K_0_SIZE;
305
184k
    aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used;
306
184k
    scratch_used += SCR_EXTRA_SCR_4K_2_SIZE;
307
184k
  } else {
308
40.9k
    aac_scratch_struct->extra_scr_4k[0] = output_ptr;
309
310
40.9k
    if (max_channel > 2) {
311
40.9k
      aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used;
312
40.9k
      scratch_used += SCR_EXTRA_SCR_4K_0_SIZE;
313
40.9k
    }
314
40.9k
    aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used;
315
40.9k
    scratch_used += SCR_EXTRA_SCR_4K_2_SIZE;
316
40.9k
  }
317
318
225k
  if (audio_object_type == AOT_ER_AAC_ELD || audio_object_type == AOT_ER_AAC_LD) {
319
123k
    aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used;
320
123k
    scratch_used += SCR_EXTRA_SCR_4K_0_SIZE;
321
322
123k
    aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used;
323
123k
    scratch_used += SCR_EXTRA_SCR_4K_2_SIZE;
324
325
123k
    aac_scratch_struct->extra_scr_4k[3] = (WORD8 *)base_scratch_ptr + scratch_used;
326
123k
    scratch_used += SCR_EXTRA_SCR_4K_3_SIZE;
327
123k
  }
328
225k
  if ((audio_object_type == AOT_ER_AAC_LD) || (audio_object_type == AOT_AAC_LTP)) {
329
91.6k
    aac_scratch_struct->out_data = (WORD32 *)((WORD8 *)base_scratch_ptr + scratch_used);
330
91.6k
    scratch_used += SCR_OUT_DATA_SIZE;
331
332
91.6k
    aac_scratch_struct->in_data = (WORD32 *)((WORD8 *)base_scratch_ptr + scratch_used);
333
91.6k
    scratch_used += SCR_IN_DATA_SIZE;
334
91.6k
  }
335
225k
}
336
337
VOID ixheaacd_allocate_sbr_scr(ia_sbr_scr_struct *sbr_scratch_struct, VOID *base_scratch_ptr,
338
                               VOID *output_ptr, WORD32 total_channels, WORD8 *p_qshift_arr,
339
210k
                               UWORD8 slot_pos, UWORD8 num_ch) {
340
210k
  WORD32 j, i;
341
210k
  sbr_scratch_struct->ptr_work_buf_core = base_scratch_ptr;
342
343
210k
  if (p_qshift_arr != NULL && *p_qshift_arr != LD_OBJ) {
344
30.8k
    WORD32 *tmp_buf = (WORD32 *)output_ptr;
345
346
47.2k
    for (j = 1; j < num_ch; j++) {
347
16.4k
      if ((*p_qshift_arr + j) == 0)
348
0
        *(p_qshift_arr + j) = *(p_qshift_arr + j - 1);
349
16.4k
    }
350
351
30.8k
    if (total_channels > 2) {
352
241
      for (j = 0; j < num_ch; j++) {
353
139k
        for (i = 0; i < 1024; i++) {
354
139k
          *((WORD16 *)tmp_buf + slot_pos + total_channels * i + j) =
355
139k
              ixheaac_round16(ixheaac_shl32_sat(
356
139k
                  *(tmp_buf + slot_pos + total_channels * i + j),
357
139k
                  *(p_qshift_arr + j)));
358
139k
        }
359
136
      }
360
30.6k
    } else {
361
77.8k
      for (j = 0; j < num_ch; j++) {
362
48.3M
        for (i = 0; i < 1024; i++) {
363
48.2M
          *((WORD16 *)tmp_buf + total_channels * i + j) =
364
48.2M
              ixheaac_round16(ixheaac_shl32_sat(
365
48.2M
                  *(tmp_buf + total_channels * i + j), *(p_qshift_arr + j)));
366
48.2M
        }
367
47.1k
      }
368
30.6k
    }
369
30.8k
  }
370
210k
}
371
372
0
VOID ixheaacd_get_lib_id_strings(pVOID pv_output) {
373
0
  ia_lib_info_struct *pstr_lib_info = (ia_lib_info_struct *)pv_output;
374
375
0
  pstr_lib_info->p_lib_name = (WORD8 *)LIBNAME;
376
0
  pstr_lib_info->p_version_num = (WORD8 *)xHE_AAC_DEC_ITTIAM_VER;
377
378
0
  return;
379
0
}
380
381
IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_xheaac_dec_obj, WORD32 i_cmd,
382
3.59M
                              WORD32 i_idx, pVOID pv_value) {
383
3.59M
  ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec = p_ia_xheaac_dec_obj;
384
3.59M
  pUWORD32 pui_value = pv_value;
385
3.59M
  pWORD32 pui_value_signed = pv_value;
386
3.59M
  pWORD8 pb_value = pv_value;
387
3.59M
  pVOID *pp_value = (pVOID *)pv_value;
388
3.59M
  float *pf_value = pv_value;
389
390
3.59M
  if ((i_cmd != IA_API_CMD_GET_API_SIZE) &&
391
3.57M
      (i_cmd != IA_API_CMD_GET_LIB_ID_STRINGS)) {
392
3.57M
    if (p_ia_xheaac_dec_obj == 0) {
393
0
      return (IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC);
394
0
    }
395
3.57M
    if (((SIZE_T)p_ia_xheaac_dec_obj & 3) != 0) {
396
0
      return (IA_XHEAAC_DEC_API_FATAL_MEM_ALIGN);
397
0
    }
398
3.57M
  }
399
400
3.59M
  switch (i_cmd) {
401
68.4k
    case IA_API_CMD_GET_MEM_INFO_SIZE:
402
136k
    case IA_API_CMD_GET_MEM_INFO_ALIGNMENT:
403
205k
    case IA_API_CMD_GET_MEM_INFO_TYPE:
404
273k
    case IA_API_CMD_SET_MEM_PTR: {
405
273k
      return ixheaacd_dec_mem_api(p_ia_xheaac_dec_obj, i_cmd, i_idx,
406
273k
                                  pv_value);
407
205k
    }
408
409
0
    case IA_API_CMD_GET_TABLE_INFO_SIZE:
410
0
    case IA_API_CMD_GET_TABLE_INFO_ALIGNMENT:
411
0
    case IA_API_CMD_SET_TABLE_PTR:
412
0
    case IA_API_CMD_GET_TABLE_PTR: {
413
0
      return ixheaacd_dec_table_api(p_ia_xheaac_dec_obj, i_cmd, i_idx,
414
0
                                    pv_value);
415
0
    }
416
3.59M
  };
417
418
3.31M
  switch (i_cmd) {
419
0
    case IA_API_CMD_GET_LIB_ID_STRINGS: {
420
0
      WORD8 *i1_ver;
421
0
      WORD8 ver_char;
422
423
0
      if (i_idx == IA_CMD_TYPE_LIB_NAME)
424
0
        i1_ver = (WORD8 *)LIBNAME;
425
0
      else if (i_idx == IA_CMD_TYPE_LIB_VERSION)
426
0
        i1_ver = (WORD8 *)xHE_AAC_DEC_ITTIAM_VER;
427
0
      else
428
0
        return IA_XHEAAC_DEC_API_FATAL_INVALID_LIB_ID_STRINGS_IDX;
429
430
0
      ver_char = *i1_ver++;
431
432
0
      for (; ver_char != '\0';) {
433
0
        if (ver_char != '$') {
434
0
          *pb_value++ = ver_char;
435
0
        }
436
0
        ver_char = *i1_ver++;
437
0
      }
438
0
      *pb_value = ver_char;
439
440
0
      break;
441
0
    }
442
17.1k
    case IA_API_CMD_GET_API_SIZE: {
443
17.1k
      *pui_value = sizeof(ia_exhaacplus_dec_api_struct);
444
17.1k
      break;
445
0
    }
446
89.6k
    case IA_API_CMD_INIT: {
447
89.6k
      switch (i_idx) {
448
17.1k
        case IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS: {
449
17.1k
          memset(p_obj_exhaacplus_dec, 0, sizeof(*p_obj_exhaacplus_dec));
450
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16;
451
17.1k
          p_obj_exhaacplus_dec->aac_config.flag_downmix = 0;
452
17.1k
          p_obj_exhaacplus_dec->aac_config.flag_08khz_out = 0;
453
17.1k
          p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0;
454
17.1k
          p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 0;
455
17.1k
          p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0;
456
17.1k
          p_obj_exhaacplus_dec->aac_config.header_dec_done = 0;
457
17.1k
          p_obj_exhaacplus_dec->aac_config.frame_status = 1;
458
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 0;
459
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0;
460
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 1;
461
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_samp_freq = 0;
462
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_frame_size = 0;
463
464
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_n_channels = 2;
465
17.1k
          p_obj_exhaacplus_dec->aac_config.i_channel_mask = 3;
466
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 3;
467
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0;
468
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_effect_type = 0;
469
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_target_loudness = -24;
470
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_loud_norm_flag = 0;
471
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_hq_esbr = 0;
472
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_enh_sbr = 1;
473
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps = 0;
474
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr = 0;
475
17.1k
          p_obj_exhaacplus_dec->aac_config.loas_present = 0;
476
17.1k
          p_obj_exhaacplus_dec->aac_config.ld_decoder = 0;
477
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 100;
478
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 100;
479
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_mode_cut = 0;
480
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_mode_boost = 0;
481
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108;
482
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 0;
483
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 0;
484
17.1k
          p_obj_exhaacplus_dec->aac_config.output_level = -1;
485
17.1k
#ifdef LOUDNESS_LEVELING_SUPPORT
486
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = 1;
487
17.1k
#endif
488
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_max_channels = 6;
489
490
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 0;
491
17.1k
          p_obj_exhaacplus_dec->aac_config.downmix = 0;
492
493
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_err_conceal = 0;
494
495
17.1k
          {
496
17.1k
            ia_aac_dec_tables_struct *pstr_aac_tables =
497
17.1k
                &p_obj_exhaacplus_dec->aac_tables;
498
17.1k
            pstr_aac_tables->pstr_huffmann_tables =
499
17.1k
                (ia_aac_dec_huffman_tables_struct
500
17.1k
                     *)&ixheaacd_aac_huffmann_tables;
501
17.1k
            pstr_aac_tables->pstr_block_tables =
502
17.1k
                (ia_aac_dec_block_tables_struct *)&ixheaacd_aac_block_tables;
503
17.1k
            pstr_aac_tables->pstr_imdct_tables =
504
17.1k
                (ia_aac_dec_imdct_tables_struct *)&ixheaacd_imdct_tables;
505
506
17.1k
            ixheaacd_huff_tables_create(pstr_aac_tables);
507
17.1k
          }
508
17.1k
          ixheaacd_init_sbr_tables(&p_obj_exhaacplus_dec->str_sbr_tables);
509
17.1k
          p_obj_exhaacplus_dec->common_tables =
510
17.1k
              (ixheaacd_misc_tables *)&ixheaacd_str_fft_n_transcendent_tables;
511
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_qmf_bands = 64;
512
513
17.1k
          break;
514
0
        }
515
17.1k
        case IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS: {
516
17.1k
          ixheaacd_fill_aac_mem_tables(p_obj_exhaacplus_dec);
517
17.1k
          break;
518
0
        }
519
27.7k
        case IA_CMD_TYPE_INIT_PROCESS: {
520
27.7k
          WORD32 err_code = 0;
521
27.7k
          if (p_obj_exhaacplus_dec->p_state_aac->fatal_err_present) {
522
293
            err_code = IA_FATAL_ERROR;
523
27.4k
          } else {
524
27.4k
            err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec);
525
27.4k
            if (err_code && p_obj_exhaacplus_dec->p_state_aac->s_adts_hdr_present) {
526
354
              p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0;
527
354
            }
528
27.4k
            if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && err_code) {
529
0
              if (err_code & IA_FATAL_ERROR) {
530
0
                err_code = IA_XHEAAC_DEC_INIT_FATAL_EC_INIT_FAIL;
531
0
              } else {
532
0
                err_code = IA_XHEAAC_DEC_INIT_NONFATAL_EC_INIT_FAIL;
533
0
              }
534
0
            }
535
27.4k
          }
536
27.7k
          if (err_code != 0) {
537
1.27k
            if (err_code < 0)
538
807
              p_obj_exhaacplus_dec->p_state_aac->fatal_err_present = 1;
539
1.27k
            p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
540
1.27k
                p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
541
1.27k
          }
542
27.7k
          return err_code;
543
0
          break;
544
0
        }
545
27.7k
        case IA_CMD_TYPE_INIT_DONE_QUERY: {
546
27.7k
          if (p_obj_exhaacplus_dec->p_state_aac->ui_init_done == 1) {
547
14.9k
            *pui_value = 1;
548
14.9k
          } else {
549
12.7k
            *pui_value = 0;
550
12.7k
          }
551
27.7k
          break;
552
0
        }
553
554
0
        case IA_CMD_TYPE_GA_HDR: {
555
0
          return ixheaacd_decoder_2_ga_hdr(p_obj_exhaacplus_dec);
556
0
          break;
557
0
        }
558
559
0
        case IA_CMD_TYPE_FLUSH_MEM: {
560
0
          return ixheaacd_decoder_flush_api(p_obj_exhaacplus_dec);
561
0
          break;
562
0
        }
563
564
0
        default: {
565
0
          return IA_XHEAAC_DEC_API_NONFATAL_CMD_TYPE_NOT_SUPPORTED;
566
0
        }
567
89.6k
      };
568
61.9k
      break;
569
89.6k
    }
570
136k
    case IA_API_CMD_SET_CONFIG_PARAM: {
571
136k
      switch (i_idx) {
572
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_SAMP_FREQ: {
573
0
          if ((*pui_value < 8000) || (*pui_value > 96000)) {
574
0
            return (IA_XHEAAC_DEC_CONFIG_FATAL_INVALID_SAMPLE_RATE);
575
0
          }
576
0
          p_obj_exhaacplus_dec->aac_config.ui_samp_freq = *pui_value;
577
0
          break;
578
0
        }
579
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_FRAMELENGTH_FLAG: {
580
0
          if ((*pui_value != 1) && (*pui_value != 0)) {
581
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_FRAMELENGTHFLAG);
582
0
          }
583
0
          p_obj_exhaacplus_dec->aac_config.ui_frame_size = *pui_value;
584
0
          break;
585
0
        }
586
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_PCM_WDSZ: {
587
0
          if ((*pui_value != 16) && (*pui_value != 24)) {
588
0
            p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16;
589
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_PCM_WDSZ);
590
0
          }
591
0
          p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = *pui_value;
592
0
          break;
593
0
        }
594
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_DOWNMIX: {
595
0
          if ((*pui_value != 1) && (*pui_value != 0)) {
596
0
            p_obj_exhaacplus_dec->aac_config.flag_downmix = 0;
597
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DOWNMIX);
598
0
          }
599
0
          p_obj_exhaacplus_dec->aac_config.flag_downmix = *pui_value;
600
0
          p_obj_exhaacplus_dec->aac_config.downmix = *pui_value;
601
0
          break;
602
0
        }
603
604
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_TOSTEREO: {
605
0
          if ((*pui_value != 1) && (*pui_value != 0)) {
606
0
            p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 1;
607
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_TOSTEREO);
608
0
          }
609
0
          p_obj_exhaacplus_dec->aac_config.flag_to_stereo = *pui_value;
610
0
          break;
611
0
        }
612
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_DSAMPLE: {
613
0
          if ((*pui_value != 1) && (*pui_value != 0)) {
614
0
            p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0;
615
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DSAMPLE);
616
0
          }
617
0
          p_obj_exhaacplus_dec->aac_config.down_sample_flag = *pui_value;
618
0
          break;
619
0
        }
620
621
17.1k
        case IA_XHEAAC_DEC_CONFIG_PARAM_MP4FLAG: {
622
17.1k
          if ((*pui_value != 1) && (*pui_value != 0)) {
623
0
            p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 0;
624
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MP4FLAG);
625
0
          }
626
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = *pui_value;
627
17.1k
          break;
628
17.1k
        }
629
17.1k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_CUT: {
630
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1;
631
17.1k
          if (*pf_value > 1 || *pf_value < 0) {
632
0
            p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 0;
633
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRC_CUT);
634
0
          }
635
636
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_mode_cut = 1;
637
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_cut =
638
17.1k
              (WORD32)((*pf_value) * 100);
639
17.1k
          break;
640
17.1k
        }
641
642
17.1k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_BOOST: {
643
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1;
644
17.1k
          if (*pf_value > 1 || *pf_value < 0) {
645
0
            p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 0;
646
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRC_BOOST);
647
0
          }
648
649
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_mode_boost = 1;
650
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_boost =
651
17.1k
              (WORD32)((*pf_value) * 100);
652
17.1k
          break;
653
17.1k
        }
654
655
17.1k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL: {
656
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1;
657
17.1k
          p_obj_exhaacplus_dec->aac_config.i_loud_ref_level = *pui_value_signed;
658
17.1k
          if (*pui_value > 127) {
659
7.07k
            p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108;
660
7.07k
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRC_TARGET);
661
7.07k
          }
662
10.0k
          p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = *pui_value;
663
10.0k
          break;
664
17.1k
        }
665
17.1k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_HEAVY_COMP: {
666
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1;
667
17.1k
          if ((*pui_value != 1) && (*pui_value != 0)) {
668
12.6k
            p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp = 0;
669
12.6k
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRCFLAG);
670
12.6k
          }
671
4.43k
          p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp = *pui_value;
672
4.43k
          break;
673
17.1k
        }
674
0
        case IA_XHEAAC_DEC_CONFIG_DISABLE_SYNC: {
675
0
          if ((*pui_value != 1) && (*pui_value != 0)) {
676
0
            p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0;
677
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_SYNCFLAG);
678
0
          }
679
0
          p_obj_exhaacplus_dec->aac_config.ui_disable_sync = *pui_value;
680
0
          break;
681
0
        }
682
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_AUTO_SBR_UPSAMPLE: {
683
0
          if ((*pui_value != 1) && (*pui_value != 0)) {
684
0
            p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 0;
685
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_SBRUPFLAG);
686
0
          }
687
0
          p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = *pui_value;
688
0
          break;
689
0
        }
690
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_MAX_CHANNEL: {
691
0
          if (*pui_value > 8) {
692
0
            p_obj_exhaacplus_dec->aac_config.ui_max_channels = 8;
693
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MAX_CHANNEL);
694
0
          }
695
0
          if (*pui_value < 2) {
696
0
            p_obj_exhaacplus_dec->aac_config.ui_max_channels = 2;
697
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MAX_CHANNEL);
698
0
          }
699
0
          p_obj_exhaacplus_dec->aac_config.ui_max_channels = *pui_value;
700
0
          break;
701
0
        }
702
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_FRAMESIZE: {
703
0
          if (*pui_value == 1) {
704
0
            p_obj_exhaacplus_dec->aac_config.framesize_480 = 1;
705
0
          } else if (*pui_value == 0) {
706
0
            p_obj_exhaacplus_dec->aac_config.framesize_480 = 0;
707
0
          } else {
708
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_FRAMSZ);
709
0
          }
710
0
          break;
711
0
        }
712
713
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_LD_TESTING: {
714
0
          if (*pui_value == 1) {
715
0
            p_obj_exhaacplus_dec->aac_config.ld_decoder = 1;
716
0
          } else if (*pui_value == 0) {
717
0
            p_obj_exhaacplus_dec->aac_config.ld_decoder = 0;
718
0
          } else {
719
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_LD_CONFIG);
720
0
          }
721
0
          break;
722
0
        }
723
724
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_COUP_CHANNEL: {
725
0
          if (*pui_value > 16) {
726
0
            p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 1;
727
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_COUP_CHANNEL);
728
0
          }
729
0
          p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = *pui_value;
730
0
          break;
731
0
        }
732
733
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_DOWNMIX_STEREO: {
734
0
          if ((*pui_value != 1) && (*pui_value != 0)) {
735
0
            p_obj_exhaacplus_dec->aac_config.downmix = 0;
736
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DOWNMIX_STEREO);
737
0
          }
738
0
          p_obj_exhaacplus_dec->aac_config.downmix = *pui_value;
739
0
          break;
740
0
        }
741
742
17.1k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE: {
743
17.1k
          if (((*pui_value_signed) > 8) || ((*pui_value_signed) < -1)) {
744
13.8k
            p_obj_exhaacplus_dec->aac_config.ui_effect_type = -1;
745
13.8k
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_EFFECT_TYPE);
746
13.8k
          }
747
3.22k
          p_obj_exhaacplus_dec->aac_config.ui_effect_type = *pui_value_signed;
748
3.22k
          break;
749
17.1k
        }
750
17.1k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS: {
751
17.1k
          if (*pui_value_signed >= 0) {
752
17.1k
            p_obj_exhaacplus_dec->aac_config.ui_loud_norm_flag = 1;
753
17.1k
          }
754
17.1k
          *pui_value_signed = -(*pui_value_signed >> 2);
755
17.1k
          if (((*pui_value_signed) > 0) || ((*pui_value_signed) < -63)) {
756
0
            p_obj_exhaacplus_dec->aac_config.ui_target_loudness = 0;
757
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_TARGET_LOUDNESS);
758
0
          }
759
17.1k
          p_obj_exhaacplus_dec->aac_config.ui_target_loudness =
760
17.1k
              *pui_value_signed;
761
17.1k
          break;
762
17.1k
        }
763
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_HQ_ESBR: {
764
0
          if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) {
765
0
            p_obj_exhaacplus_dec->aac_config.ui_hq_esbr = 0;
766
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_ESBR_HQ_FLAG);
767
0
          }
768
0
          p_obj_exhaacplus_dec->aac_config.ui_hq_esbr = *pui_value_signed;
769
0
          break;
770
0
        }
771
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_PS_ENABLE: {
772
0
          if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) {
773
0
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps = 0;
774
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_ESBR_PS_FLAG);
775
0
          }
776
0
          p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps = *pui_value_signed;
777
0
          break;
778
0
        }
779
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_PEAK_LIMITER: {
780
0
          if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) {
781
0
            p_obj_exhaacplus_dec->aac_config.peak_limiter_off = 0;
782
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_PEAK_LIM_FLAG_TYPE);
783
0
          }
784
0
          p_obj_exhaacplus_dec->aac_config.peak_limiter_off = *pui_value_signed;
785
0
          break;
786
0
        }
787
0
        case IA_XHEAAC_DEC_CONFIG_ERROR_CONCEALMENT: {
788
0
          if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) {
789
0
            p_obj_exhaacplus_dec->aac_config.ui_err_conceal = 0;
790
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_ERR_CONCEAL_FLAG_TYPE);
791
0
          }
792
0
          p_obj_exhaacplus_dec->aac_config.ui_err_conceal = *pui_value_signed;
793
0
          break;
794
0
        }
795
0
        case IA_XHEAAC_DEC_CONFIG_PARAM_ESBR: {
796
0
          if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) {
797
0
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr = 1;
798
0
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_ESBR_FLAG);
799
0
          }
800
0
          p_obj_exhaacplus_dec->aac_config.ui_enh_sbr = *pui_value_signed;
801
0
          break;
802
0
        }
803
0
#ifdef LOUDNESS_LEVELING_SUPPORT
804
17.1k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUDNESS_LEVELING: {
805
17.1k
          if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) {
806
14.3k
            p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = 1;
807
14.3k
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_LOUDNESS_LEVELING_FLAG);
808
14.3k
          }
809
2.80k
          p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = *pui_value_signed;
810
2.80k
          break;
811
17.1k
        }
812
0
#endif
813
0
        default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_CONFIG_PARAM; }
814
136k
      }
815
88.9k
      break;
816
136k
    }
817
818
996k
    case IA_API_CMD_GET_CONFIG_PARAM: {
819
996k
      UWORD32 i;
820
996k
      WORD32 *pvalue =
821
996k
          (WORD32 *)(&p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz);
822
996k
      if (IA_XHEAAC_DEC_CONFIG_PARAM_NUM_CHANNELS == i_idx) {
823
14.9k
        if (p_obj_exhaacplus_dec->p_state_aac != NULL &&
824
14.9k
            p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle
825
14.9k
                    .heaac_mps_present == 1) {
826
3.85k
          *pui_value = p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle
827
3.85k
                           .num_output_channels_at;
828
11.0k
        } else {
829
11.0k
          *pui_value = pvalue[i_idx];
830
11.0k
        }
831
982k
      } else if (IA_XHEAAC_DEC_CONFIG_PARAM_CHANNEL_MASK == i_idx) {
832
14.9k
        if (p_obj_exhaacplus_dec->p_state_aac != NULL &&
833
14.9k
            p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle
834
14.9k
                    .heaac_mps_present == 1) {
835
3.85k
          *pui_value = p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle
836
3.85k
                           .bs_config.ui_channel_mask;
837
11.0k
        } else {
838
11.0k
          *pui_value = pvalue[i_idx];
839
11.0k
        }
840
14.9k
      } else
841
967k
      if (i_idx >= 0 && i_idx <= 8) {
842
119k
        *pui_value = pvalue[i_idx];
843
847k
      } else if (IA_ENHAACPLUS_DEC_CONFIG_GET_NUM_PRE_ROLL_FRAMES == i_idx) {
844
0
        WORD32 *ptri_value = (WORD32 *)pv_value;
845
0
        ia_audio_specific_config_struct *ptr_audio_specific_config =
846
0
            ((ia_audio_specific_config_struct *)
847
0
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
848
849
0
        for (i = 0; i < MAX_AUDIO_PREROLLS + 1; i++) {
850
0
          if (ptr_audio_specific_config->str_usac_config.str_usac_dec_config
851
0
                  .preroll_bytes[i] == 0) {
852
0
            break;
853
0
          }
854
0
        }
855
856
0
        *ptri_value = i;
857
847k
      } else if (IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR == i_idx) {
858
14.9k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
859
14.9k
            ((ia_audio_specific_config_struct *)
860
14.9k
                p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
861
862
21.4k
        for (i = 0; i < ptr_audio_specific_config->str_usac_config
863
21.4k
                            .str_usac_dec_config.num_config_extensions;
864
14.9k
             i++) {
865
6.51k
          pp_value[i] = ptr_audio_specific_config->str_usac_config
866
6.51k
                            .str_usac_dec_config.usac_cfg_ext_info_buf[i];
867
6.51k
        }
868
869
27.7k
        for (i = 0; i < ptr_audio_specific_config->str_usac_config
870
27.7k
                            .str_usac_dec_config.num_elements;
871
14.9k
             i++) {
872
12.7k
          if (ptr_audio_specific_config->str_usac_config.str_usac_dec_config
873
12.7k
                  .usac_ext_ele_payload_present[i]) {
874
1.24k
            pp_value[i + 16] =
875
1.24k
                ptr_audio_specific_config->str_usac_config.str_usac_dec_config
876
1.24k
                    .usac_ext_ele_payload_buf[i];
877
1.24k
          }
878
12.7k
        }
879
832k
      } else if (IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES == i_idx) {
880
14.9k
        WORD32 *ptri_value = (WORD32 *)pv_value;
881
14.9k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
882
14.9k
            ((ia_audio_specific_config_struct *)
883
14.9k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
884
21.4k
        for (i = 0; i < ptr_audio_specific_config->str_usac_config
885
21.4k
                            .str_usac_dec_config.num_config_extensions;
886
14.9k
             i++) {
887
6.51k
          ptri_value[i] = ptr_audio_specific_config->str_usac_config
888
6.51k
                              .str_usac_dec_config.usac_cfg_ext_info_len[i];
889
6.51k
        }
890
27.7k
        for (i = 0; i < ptr_audio_specific_config->str_usac_config
891
27.7k
                            .str_usac_dec_config.num_elements;
892
14.9k
             i++) {
893
12.7k
          ptri_value[i + 16] =
894
12.7k
              ptr_audio_specific_config->str_usac_config.str_usac_dec_config
895
12.7k
                  .usac_ext_ele_payload_len[i];
896
12.7k
        }
897
898
817k
      } else if (IA_ENHAACPLUS_DEC_DRC_IS_CONFIG_CHANGED == i_idx) {
899
0
        *pui_value = p_obj_exhaacplus_dec->p_state_aac->drc_config_changed;
900
817k
      } else if (IA_ENHAACPLUS_DEC_DRC_APPLY_CROSSFADE == i_idx) {
901
0
        *pui_value = p_obj_exhaacplus_dec->p_state_aac->apply_crossfade;
902
817k
      } else if (IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE == i_idx) {
903
14.9k
        UWORD32 *ptri_value = (UWORD32 *)pv_value;
904
14.9k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
905
14.9k
            ((ia_audio_specific_config_struct *)
906
14.9k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
907
14.9k
        *ptri_value = ptr_audio_specific_config->str_usac_config
908
14.9k
                          .str_usac_dec_config.num_elements;
909
910
802k
      } else if (IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT == i_idx) {
911
14.9k
        UWORD32 *ptri_value = (UWORD32 *)pv_value;
912
14.9k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
913
14.9k
            ((ia_audio_specific_config_struct *)
914
14.9k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
915
14.9k
        *ptri_value = ptr_audio_specific_config->str_usac_config
916
14.9k
                          .str_usac_dec_config.num_config_extensions;
917
787k
      } else if (IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN == i_idx) {
918
393k
        UWORD32 *ptri_value = (UWORD32 *)pv_value;
919
393k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
920
393k
            ((ia_audio_specific_config_struct *)
921
393k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
922
393k
        WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config
923
393k
                                     .str_usac_dec_config.preroll_counter;
924
393k
        *ptri_value =
925
393k
            ptr_audio_specific_config->str_usac_config.str_usac_dec_config
926
393k
                .usac_ext_gain_payload_len[preroll_counter];
927
393k
      } else if (IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF == i_idx) {
928
393k
        WORD32 payload_buffer_offeset = 0;
929
393k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
930
393k
            ((ia_audio_specific_config_struct *)
931
393k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
932
393k
        WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config
933
393k
                                     .str_usac_dec_config.preroll_counter;
934
396k
        for (i = 0; i < (UWORD32)preroll_counter; i++)
935
2.20k
          payload_buffer_offeset +=
936
2.20k
              ptr_audio_specific_config->str_usac_config.str_usac_dec_config
937
2.20k
                  .usac_ext_gain_payload_len[i] *
938
2.20k
              sizeof(WORD8);
939
393k
        *pp_value = ptr_audio_specific_config->str_usac_config
940
393k
                        .str_usac_dec_config.usac_ext_gain_payload_buf +
941
393k
                    payload_buffer_offeset;
942
393k
      } else if (IA_XHEAAC_DEC_CONFIG_PARAM_AOT == i_idx) {
943
0
        if (p_obj_exhaacplus_dec->p_state_aac != NULL) {
944
0
          if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag == 1) {
945
0
            ia_audio_specific_config_struct *ptr_audio_specific_config =
946
0
                ((ia_audio_specific_config_struct *)
947
0
                    p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
948
0
            *pui_value = ptr_audio_specific_config->audio_object_type;
949
0
          } else {
950
0
            *pui_value = p_obj_exhaacplus_dec->p_state_aac->audio_object_type;
951
0
          }
952
0
        } else {
953
0
          *pui_value = AOT_AAC_LC;
954
0
        }
955
0
      }
956
0
#ifdef LOUDNESS_LEVELING_SUPPORT
957
0
      else if (IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUDNESS_LEVELING == i_idx) {
958
0
        WORD32 *ui_value =
959
0
            (WORD32 *)(&p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag);
960
0
        *pui_value = *ui_value;
961
0
      }
962
0
#endif
963
0
      else if (IA_XHEAAC_DEC_CONFIG_PARAM_DRC_CUT == i_idx) {
964
0
        UWORD32 *ui_value = (UWORD32 *)(&p_obj_exhaacplus_dec->aac_config.ui_drc_cut);
965
0
        *pf_value = (*ui_value) / 100.0f;
966
0
      } else if (IA_XHEAAC_DEC_CONFIG_PARAM_DRC_BOOST == i_idx) {
967
0
        UWORD32 *ui_value = (UWORD32 *)(&p_obj_exhaacplus_dec->aac_config.ui_drc_boost);
968
0
        *pf_value = (*ui_value) / 100.0f;
969
0
      } else if (IA_XHEAAC_DEC_CONFIG_PARAM_DRC_MODE_CUT == i_idx) {
970
0
        UWORD8 *ui_value = (&p_obj_exhaacplus_dec->aac_config.ui_drc_mode_cut);
971
0
        *pb_value = (*ui_value);
972
0
      } else if (IA_XHEAAC_DEC_CONFIG_PARAM_DRC_MODE_BOOST == i_idx) {
973
0
        UWORD8 *ui_value = (&p_obj_exhaacplus_dec->aac_config.ui_drc_mode_boost);
974
0
        *pb_value = *ui_value;
975
0
      }
976
0
      else {
977
0
        return IA_XHEAAC_DEC_API_FATAL_INVALID_CONFIG_PARAM;
978
0
      }
979
996k
      break;
980
996k
    }
981
982
996k
    case IA_API_CMD_GET_MEMTABS_SIZE: {
983
17.1k
      *pui_value = (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) *
984
17.1k
                   (IA_ENHAACPDEC_NUM_MEMTABS);
985
17.1k
      break;
986
996k
    }
987
0
    case IA_API_CMD_GET_LOUDNESS_VAL: {
988
0
      *pui_value = p_obj_exhaacplus_dec->aac_config.output_level;
989
0
      break;
990
996k
    }
991
17.1k
    case IA_API_CMD_SET_MEMTABS_PTR: {
992
17.1k
      if (pv_value == NULL) return IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC;
993
17.1k
      memset(pv_value, 0, (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) *
994
17.1k
                              (IA_ENHAACPDEC_NUM_MEMTABS));
995
996
17.1k
      p_obj_exhaacplus_dec->p_mem_info_aac = pv_value;
997
17.1k
      p_obj_exhaacplus_dec->pp_mem_aac =
998
17.1k
          (pVOID *)((WORD8 *)pv_value +
999
17.1k
                    sizeof(ia_mem_info_struct) * IA_ENHAACPDEC_NUM_MEMTABS);
1000
1001
17.1k
      break;
1002
17.1k
    }
1003
0
    case IA_API_CMD_GET_N_MEMTABS: {
1004
0
      *pui_value = IA_ENHAACPDEC_NUM_MEMTABS;
1005
0
      break;
1006
17.1k
    }
1007
1008
0
    case IA_API_CMD_GET_N_TABLES: {
1009
0
      *pui_value = NUM_AAC_TABLES + NUM_MPS_TABLES;
1010
0
      break;
1011
17.1k
    }
1012
787k
    case IA_API_CMD_EXECUTE: {
1013
787k
      switch (i_idx) {
1014
393k
        case IA_CMD_TYPE_DO_EXECUTE: {
1015
393k
          WORD32 err_code = 0;
1016
393k
          if (!p_obj_exhaacplus_dec->p_state_aac->ui_init_done ||
1017
392k
              p_obj_exhaacplus_dec->p_state_aac->fatal_err_present) {
1018
2.51k
            err_code = IA_FATAL_ERROR;
1019
391k
          } else {
1020
391k
            memset(p_obj_exhaacplus_dec->p_state_aac->qshift_adj, 0,
1021
391k
                   sizeof(p_obj_exhaacplus_dec->p_state_aac->qshift_adj));
1022
391k
            p_obj_exhaacplus_dec->p_state_aac->qshift_cnt = 0;
1023
391k
            err_code = ixheaacd_dec_execute(p_obj_exhaacplus_dec);
1024
391k
          }
1025
393k
          if (err_code != IA_NO_ERROR) {
1026
14.8k
            if (err_code < 0) {
1027
5.38k
              p_obj_exhaacplus_dec->p_state_aac->fatal_err_present = 1;
1028
5.38k
            }
1029
14.8k
            p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
1030
14.8k
                p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
1031
14.8k
          }
1032
393k
          return err_code;
1033
0
          break;
1034
0
        }
1035
393k
        case IA_CMD_TYPE_DONE_QUERY: {
1036
393k
          if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 1) {
1037
0
            *pui_value = 1;
1038
393k
          } else {
1039
393k
            *pui_value = 0;
1040
393k
          }
1041
1042
393k
          break;
1043
0
        }
1044
0
        default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_EXECUTE_TYPE; }
1045
787k
      };
1046
393k
      break;
1047
787k
    }
1048
421k
    case IA_API_CMD_GET_CURIDX_INPUT_BUF: {
1049
421k
      *pui_value = p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed;
1050
421k
      break;
1051
787k
    }
1052
421k
    case IA_API_CMD_SET_INPUT_BYTES: {
1053
421k
      p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes = *pui_value;
1054
421k
      break;
1055
787k
    }
1056
393k
    case IA_API_CMD_GET_OUTPUT_BYTES: {
1057
393k
      if (1 == i_idx) {
1058
0
        *pui_value = p_obj_exhaacplus_dec->p_state_aac->ui_mps_out_bytes;
1059
393k
      } else {
1060
393k
        *pui_value = p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes;
1061
393k
      }
1062
393k
      if (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_USAC) {
1063
186k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
1064
186k
            ((ia_audio_specific_config_struct *)
1065
186k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
1066
1067
186k
        WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config
1068
186k
                                     .str_usac_dec_config.preroll_counter;
1069
1070
186k
        *pui_value = ptr_audio_specific_config->str_usac_config
1071
186k
                         .str_usac_dec_config.preroll_bytes[preroll_counter];
1072
1073
186k
        preroll_counter++;
1074
186k
        if (preroll_counter > (MAX_AUDIO_PREROLLS + 1)) return IA_FATAL_ERROR;
1075
186k
        ptr_audio_specific_config->str_usac_config.str_usac_dec_config
1076
186k
            .preroll_counter = preroll_counter;
1077
186k
      }
1078
393k
      break;
1079
393k
    }
1080
393k
    case IA_API_CMD_INPUT_OVER: {
1081
17.1k
      p_obj_exhaacplus_dec->p_state_aac->ui_input_over = 1;
1082
17.1k
      break;
1083
393k
    }
1084
0
    default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_CMD; }
1085
3.31M
  };
1086
2.84M
  return IA_NO_ERROR;
1087
3.31M
}
1088
1089
0
IA_ERRORCODE ixheaacd_decoder_2_ga_hdr(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
1090
0
  IA_ERRORCODE err_code = IA_NO_ERROR;
1091
0
  if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) {
1092
0
    p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16;
1093
0
    p_obj_exhaacplus_dec->aac_config.flag_downmix = 0;
1094
0
    p_obj_exhaacplus_dec->aac_config.flag_08khz_out = 0;
1095
0
    p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0;
1096
0
    p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 0;
1097
0
    p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0;
1098
0
    p_obj_exhaacplus_dec->aac_config.header_dec_done = 0;
1099
0
    p_obj_exhaacplus_dec->aac_config.frame_status = 1;
1100
0
    p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 1;
1101
0
    p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0;
1102
0
    p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 1;
1103
0
    p_obj_exhaacplus_dec->aac_config.ui_samp_freq = 0;
1104
0
    p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 3;
1105
0
    p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 2;
1106
0
    p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr = 0;
1107
0
    p_obj_exhaacplus_dec->aac_config.loas_present = 0;
1108
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 0;
1109
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 0;
1110
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_mode_cut = 0;
1111
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_mode_boost = 0;
1112
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108;
1113
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_set = 0;
1114
0
    p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 1;
1115
1116
0
    p_obj_exhaacplus_dec->aac_config.ui_max_channels = 6;
1117
1118
0
    p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 0;
1119
0
    p_obj_exhaacplus_dec->aac_config.downmix = 0;
1120
1121
0
    {
1122
0
      ia_aac_dec_tables_struct *pstr_aac_tables =
1123
0
          &p_obj_exhaacplus_dec->aac_tables;
1124
0
      pstr_aac_tables->pstr_huffmann_tables =
1125
0
          (ia_aac_dec_huffman_tables_struct *)&ixheaacd_aac_huffmann_tables;
1126
0
      pstr_aac_tables->pstr_block_tables =
1127
0
          (ia_aac_dec_block_tables_struct *)&ixheaacd_aac_block_tables;
1128
0
      pstr_aac_tables->pstr_imdct_tables =
1129
0
          (ia_aac_dec_imdct_tables_struct *)&ixheaacd_imdct_tables;
1130
1131
0
      ixheaacd_huff_tables_create(pstr_aac_tables);
1132
0
    }
1133
0
    ixheaacd_init_sbr_tables(&p_obj_exhaacplus_dec->str_sbr_tables);
1134
0
    p_obj_exhaacplus_dec->common_tables =
1135
0
        (ixheaacd_misc_tables *)&ixheaacd_str_fft_n_transcendent_tables;
1136
0
    p_obj_exhaacplus_dec->aac_config.ui_qmf_bands = 64;
1137
0
    p_obj_exhaacplus_dec->p_state_aac->ui_init_done = 0;
1138
1139
0
    err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec);
1140
0
  } else {
1141
0
    p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 0;
1142
0
    err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec);
1143
0
  }
1144
0
  if (err_code && p_obj_exhaacplus_dec->p_state_aac->s_adts_hdr_present) {
1145
0
    p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0;
1146
0
  }
1147
0
  if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && err_code) {
1148
0
    if (err_code & IA_FATAL_ERROR) {
1149
0
      return IA_XHEAAC_DEC_INIT_FATAL_EC_INIT_FAIL;
1150
0
    } else {
1151
0
      return IA_XHEAAC_DEC_INIT_NONFATAL_EC_INIT_FAIL;
1152
0
    }
1153
0
  } else {
1154
0
    return err_code;
1155
0
  }
1156
0
}
1157
1158
0
IA_ERRORCODE ixheaacd_decoder_flush_api(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
1159
0
  IA_ERRORCODE err_code = IA_NO_ERROR;
1160
0
  UWORD8 *header_temp_ptr;
1161
0
  WORD32 header_length;
1162
0
  if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) {
1163
0
    header_temp_ptr = p_obj_exhaacplus_dec->p_state_aac->header_ptr;
1164
0
    header_length = p_obj_exhaacplus_dec->p_state_aac->header_length;
1165
0
    memset(p_obj_exhaacplus_dec->p_state_aac, 0,
1166
0
           IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8));
1167
0
    {
1168
0
      pUWORD8 p_temp = (pUWORD8)p_obj_exhaacplus_dec->p_state_aac;
1169
0
      UWORD32 *meminfo = (UWORD32 *)p_obj_exhaacplus_dec->p_mem_info_aac;
1170
0
      UWORD32 pers_size = meminfo[0];
1171
0
      p_temp = p_temp + pers_size -
1172
0
               (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) +
1173
0
                IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8) +
1174
0
                IXHEAAC_GET_SIZE_ALIGNED(MAX_HEADER_BUF_SIZE, BYTE_ALIGN_8));
1175
1176
0
      p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data = p_temp;
1177
0
      p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config =
1178
0
          p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8);
1179
0
      p_obj_exhaacplus_dec->p_state_aac->header_ptr =
1180
0
          p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) +
1181
0
          IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8);
1182
0
    }
1183
0
    memset(&(p_obj_exhaacplus_dec->aac_config), 0,
1184
0
           sizeof(ia_aac_dec_config_struct));
1185
1186
0
    p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16;
1187
0
    p_obj_exhaacplus_dec->aac_config.flag_downmix = 0;
1188
0
    p_obj_exhaacplus_dec->aac_config.flag_08khz_out = 0;
1189
0
    p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0;
1190
0
    p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 0;
1191
0
    p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0;
1192
0
    p_obj_exhaacplus_dec->aac_config.header_dec_done = 0;
1193
0
    p_obj_exhaacplus_dec->aac_config.frame_status = 1;
1194
0
    p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 1;
1195
0
    p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0;
1196
0
    p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 1;
1197
0
    p_obj_exhaacplus_dec->aac_config.ui_samp_freq = 0;
1198
0
    p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 3;
1199
0
    p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 2;
1200
0
    p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr = 0;
1201
0
    p_obj_exhaacplus_dec->aac_config.loas_present = 0;
1202
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 0;
1203
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 0;
1204
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_mode_cut = 0;
1205
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_mode_boost = 0;
1206
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108;
1207
0
    p_obj_exhaacplus_dec->aac_config.ui_drc_set = 0;
1208
0
    p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 1;
1209
1210
0
    p_obj_exhaacplus_dec->aac_config.ui_max_channels = 6;
1211
1212
0
    p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 0;
1213
0
    p_obj_exhaacplus_dec->aac_config.downmix = 0;
1214
0
    p_obj_exhaacplus_dec->p_state_aac->peak_lim_init = 0;
1215
1216
0
    {
1217
0
      ia_aac_dec_tables_struct *pstr_aac_tables =
1218
0
          &p_obj_exhaacplus_dec->aac_tables;
1219
0
      pstr_aac_tables->pstr_huffmann_tables =
1220
0
          (ia_aac_dec_huffman_tables_struct *)&ixheaacd_aac_huffmann_tables;
1221
0
      pstr_aac_tables->pstr_block_tables =
1222
0
          (ia_aac_dec_block_tables_struct *)&ixheaacd_aac_block_tables;
1223
0
      pstr_aac_tables->pstr_imdct_tables =
1224
0
          (ia_aac_dec_imdct_tables_struct *)&ixheaacd_imdct_tables;
1225
1226
0
      ixheaacd_huff_tables_create(pstr_aac_tables);
1227
0
    }
1228
0
    ixheaacd_init_sbr_tables(&p_obj_exhaacplus_dec->str_sbr_tables);
1229
0
    p_obj_exhaacplus_dec->common_tables =
1230
0
        (ixheaacd_misc_tables *)&ixheaacd_str_fft_n_transcendent_tables;
1231
0
    p_obj_exhaacplus_dec->aac_config.ui_qmf_bands = 64;
1232
0
    p_obj_exhaacplus_dec->p_state_aac->header_ptr = header_temp_ptr;
1233
0
    p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes = header_length;
1234
0
    p_obj_exhaacplus_dec->p_state_aac->header_length = header_length;
1235
1236
0
    err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec);
1237
0
  } else {
1238
0
    p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 0;
1239
0
    err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec);
1240
0
  }
1241
0
  if (err_code && p_obj_exhaacplus_dec->p_state_aac->s_adts_hdr_present) {
1242
0
    p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0;
1243
0
  }
1244
0
  if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && err_code) {
1245
0
    if (err_code & IA_FATAL_ERROR) {
1246
0
      return IA_XHEAAC_DEC_INIT_FATAL_EC_INIT_FAIL;
1247
0
    } else {
1248
0
      return IA_XHEAAC_DEC_INIT_NONFATAL_EC_INIT_FAIL;
1249
0
    }
1250
0
  } else {
1251
0
    return err_code;
1252
0
  }
1253
0
}
1254
1255
static PLATFORM_INLINE WORD32
1256
17.1k
ixheaacd_persistent_buffer_sizes(WORD32 num_channel) {
1257
17.1k
  WORD32 size_buffers = 0;
1258
1259
17.1k
  WORD32 temp;
1260
17.1k
  WORD32 max_channels;
1261
1262
17.1k
  size_buffers += IXHEAAC_GET_SIZE_ALIGNED(4 * 512 * num_channel * sizeof(WORD32), BYTE_ALIGN_8);
1263
1264
17.1k
  size_buffers +=
1265
17.1k
      num_channel * IXHEAAC_GET_SIZE_ALIGNED(ltp_buffer_size * sizeof(WORD16), BYTE_ALIGN_8);
1266
1267
17.1k
  size_buffers +=
1268
17.1k
      num_channel * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_channel_info), BYTE_ALIGN_8);
1269
1270
17.1k
  if (num_channel > 2) {
1271
17.1k
    max_channels = MAX_BS_ELEMENT;
1272
17.1k
  } else {
1273
0
    max_channels = 2;
1274
0
  }
1275
17.1k
  size_buffers += (max_channels)*2 *
1276
17.1k
                  IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), BYTE_ALIGN_8);
1277
1278
17.1k
  size_buffers +=
1279
17.1k
      num_channel * IXHEAAC_GET_SIZE_ALIGNED(MAXSBRBYTES * sizeof(WORD8), BYTE_ALIGN_8);
1280
1281
17.1k
  size_buffers +=
1282
17.1k
      num_channel * IXHEAAC_GET_SIZE_ALIGNED(MAXSBRBYTES * sizeof(WORD8), BYTE_ALIGN_8);
1283
1284
17.1k
  size_buffers +=
1285
17.1k
      2 * num_channel *
1286
17.1k
      IXHEAAC_GET_SIZE_ALIGNED(
1287
17.1k
          (QMF_FILTER_STATE_ANA_SIZE + 2 * NO_ANALYSIS_CHANNELS) * sizeof(WORD16), BYTE_ALIGN_8);
1288
1289
17.1k
  size_buffers +=
1290
17.1k
      2 * num_channel *
1291
17.1k
      IXHEAAC_GET_SIZE_ALIGNED(
1292
17.1k
          (QMF_FILTER_STATE_ANA_SIZE + 2 * NO_ANALYSIS_CHANNELS) * sizeof(WORD32), BYTE_ALIGN_8);
1293
1294
17.1k
  size_buffers +=
1295
17.1k
      2 * num_channel *
1296
17.1k
      IXHEAAC_GET_SIZE_ALIGNED(
1297
17.1k
          (QMF_FILTER_STATE_SYN_SIZE + 2 * NO_SYNTHESIS_CHANNELS) * sizeof(WORD16), BYTE_ALIGN_8);
1298
1299
17.1k
  size_buffers +=
1300
17.1k
      2 * num_channel *
1301
17.1k
      IXHEAAC_GET_SIZE_ALIGNED(
1302
17.1k
          (QMF_FILTER_STATE_SYN_SIZE + 2 * NO_SYNTHESIS_CHANNELS) * sizeof(WORD32), BYTE_ALIGN_8);
1303
1304
17.1k
  size_buffers += num_channel * 2 *
1305
17.1k
                  IXHEAAC_GET_SIZE_ALIGNED(MAX_OV_COLS * NO_SYNTHESIS_CHANNELS * sizeof(WORD32),
1306
17.1k
                                           BYTE_ALIGN_8);
1307
1308
17.1k
  size_buffers += 2 * LPC_ORDER * num_channel *
1309
17.1k
                  IXHEAAC_GET_SIZE_ALIGNED(NO_ANALYSIS_CHANNELS * sizeof(WORD32), BYTE_ALIGN_8);
1310
1311
17.1k
  size_buffers += 2 * IXHEAAC_GET_SIZE_ALIGNED(LPC_ORDER * sizeof(WORD32 *), BYTE_ALIGN_8);
1312
1313
17.1k
  size_buffers += 2 * LPC_ORDER * num_channel *
1314
17.1k
                  IXHEAAC_GET_SIZE_ALIGNED(NO_ANALYSIS_CHANNELS * sizeof(WORD32), BYTE_ALIGN_8);
1315
1316
17.1k
  size_buffers += 2 * num_channel * 3 *
1317
17.1k
                  IXHEAAC_GET_SIZE_ALIGNED(MAX_FREQ_COEFFS * sizeof(WORD16), BYTE_ALIGN_8);
1318
1319
17.1k
  temp = IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_freq_band_data_struct), BYTE_ALIGN_8) +
1320
17.1k
         IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_prev_frame_data_struct), BYTE_ALIGN_8) +
1321
17.1k
         IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_channel_struct), BYTE_ALIGN_8) +
1322
17.1k
         IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_header_data_struct), BYTE_ALIGN_8);
1323
17.1k
  size_buffers += 2 * num_channel * temp;
1324
1325
17.1k
  size_buffers += MAX_BS_ELEMENT *
1326
17.1k
                  IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaac_drc_bs_data_struct *), BYTE_ALIGN_8);
1327
1328
17.1k
  size_buffers += num_channel * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_ps_dec_struct), BYTE_ALIGN_8);
1329
1330
17.1k
  {
1331
17.1k
    WORD32 temp_size = 0;
1332
17.1k
    size_buffers += (num_channel * 2 *
1333
17.1k
                     IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_frame_info_data_struct) +
1334
17.1k
                                                  MAX_FREQ_COEFFS * sizeof(WORD32) * 2 + 8,
1335
17.1k
                                              BYTE_ALIGN_8));
1336
17.1k
    temp_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_pvc_data_struct), BYTE_ALIGN_8);
1337
17.1k
    temp_size += 2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_esbr_hbe_txposer_struct), BYTE_ALIGN_8);
1338
17.1k
    temp_size += 2 * IXHEAAC_GET_SIZE_ALIGNED(MAX_HBE_PERSISTENT_SIZE, BYTE_ALIGN_8);
1339
17.1k
    temp_size +=
1340
17.1k
        2 * 2 * IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(FLOAT32 *), BYTE_ALIGN_8);
1341
17.1k
    temp_size += 2 * 2 * MAX_QMF_BUF_LEN *
1342
17.1k
                 IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(FLOAT32), BYTE_ALIGN_8);
1343
17.1k
    temp_size += 2 * 2 * MAX_ENV_COLS *
1344
17.1k
                 IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(WORD32), BYTE_ALIGN_8);
1345
17.1k
    size_buffers += num_channel * temp_size;
1346
17.1k
  }
1347
1348
17.1k
  return (size_buffers);
1349
17.1k
}
1350
1351
VOID ixheaacd_fill_aac_mem_tables(
1352
17.1k
    ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
1353
17.1k
  ia_mem_info_struct *p_mem_info_aac;
1354
1355
17.1k
  WORD32 num_channels;
1356
17.1k
  WORD32 channels;
1357
17.1k
  WORD32 buffer_size;
1358
1359
17.1k
  if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
1360
17.1k
    num_channels = (p_obj_exhaacplus_dec->aac_config.ui_max_channels + 1);
1361
17.1k
  } else
1362
1363
0
  {
1364
0
    num_channels = p_obj_exhaacplus_dec->aac_config.ui_max_channels;
1365
0
  }
1366
1367
17.1k
  channels = num_channels;
1368
17.1k
  buffer_size = ixheaacd_persistent_buffer_sizes(num_channels);
1369
1370
17.1k
  {
1371
17.1k
    p_mem_info_aac =
1372
17.1k
        &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX];
1373
17.1k
    p_mem_info_aac->ui_size =
1374
17.1k
        IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8) +
1375
17.1k
        channels *
1376
17.1k
            IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ia_aac_persistent_struct), BYTE_ALIGN_8) +
1377
17.1k
        buffer_size + channels * ixheaacd_getsize_sbr_persistent() + channels * 16 +
1378
17.1k
        ixheaacd_mps_persistent_buffer_sizes();
1379
17.1k
    p_mem_info_aac->ui_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8);
1380
17.1k
    p_mem_info_aac->ui_size +=
1381
17.1k
        IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8);
1382
17.1k
    p_mem_info_aac->ui_size += IXHEAAC_GET_SIZE_ALIGNED(MAX_HEADER_BUF_SIZE, BYTE_ALIGN_8);
1383
17.1k
    p_mem_info_aac->ui_alignment = 16;
1384
17.1k
    p_mem_info_aac->ui_type = IA_MEMTYPE_PERSIST;
1385
17.1k
  }
1386
1387
17.1k
  {
1388
17.1k
    p_mem_info_aac =
1389
17.1k
        &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX];
1390
1391
17.1k
    p_mem_info_aac->ui_size = MAX_SCR_SIZE;
1392
1393
17.1k
    p_mem_info_aac->ui_alignment = 8;
1394
17.1k
    p_mem_info_aac->ui_type = IA_MEMTYPE_SCRATCH;
1395
17.1k
  }
1396
17.1k
  {
1397
17.1k
    p_mem_info_aac =
1398
17.1k
        &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_INPUT_IDX];
1399
1400
17.1k
    p_mem_info_aac->ui_size = IA_MAX_INP_BUFFER_SIZE;
1401
1402
17.1k
    p_mem_info_aac->ui_alignment = 8;
1403
17.1k
    p_mem_info_aac->ui_type = IA_MEMTYPE_INPUT;
1404
17.1k
  }
1405
17.1k
  {
1406
17.1k
    p_mem_info_aac =
1407
17.1k
        &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX];
1408
17.1k
    p_mem_info_aac->ui_size = IA_ENHAACPLUS_DEC_OUT_BUF_SIZE;
1409
17.1k
    p_mem_info_aac->ui_alignment = 8;
1410
17.1k
    p_mem_info_aac->ui_type = IA_MEMTYPE_OUTPUT;
1411
17.1k
  }
1412
17.1k
  return;
1413
17.1k
}
1414
1415
IA_ERRORCODE ixheaacd_dec_table_api(
1416
    ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, WORD32 i_cmd,
1417
0
    WORD32 i_idx, pVOID pv_value) {
1418
0
  ia_heaac_mps_state_struct *pstr_mps_state =
1419
0
      &p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle;
1420
0
  pUWORD32 pui_value = pv_value;
1421
0
  pUWORD32 *p_pui_value = pv_value;
1422
0
  SIZE_T ui_get_vals[5];
1423
1424
0
  pVOID *table_ptrs[8 + NUM_MPS_TABLES];
1425
0
  UWORD32 table_sizes[8 + NUM_MPS_TABLES] = {
1426
0
      sizeof(ixheaacd_aac_huffmann_tables),
1427
0
      sizeof(ixheaacd_aac_block_tables),
1428
0
      sizeof(ixheaacd_imdct_tables),
1429
0
      sizeof(ixheaacd_str_fft_n_transcendent_tables),
1430
0
      sizeof(ixheaacd_aac_dec_env_calc_tables),
1431
0
      sizeof(ixheaacd_aac_qmf_dec_tables),
1432
0
      sizeof(ixheaacd_aac_dec_env_extr_tables),
1433
0
      sizeof(ixheaacd_aac_dec_ps_tables),
1434
0
      sizeof(ixheaacd_mps_dec_qmf_tables),
1435
0
      sizeof(ixheaacd_mps_dec_common_tables),
1436
0
      sizeof(ixheaacd_mps_dec_hybrid_tables),
1437
0
      sizeof(ixheaacd_mps_dec_m1_m2_tables),
1438
0
      sizeof(ixheaacd_mps_dec_decorr_tables),
1439
0
      sizeof(ixheaacd_mps_dec_tp_process_tables),
1440
0
      sizeof(ixheaacd_mps_dec_mdct2qmf_table),
1441
0
      sizeof(ixheaacd_mps_dec_tonality_tables),
1442
0
      sizeof(ixheaacd_mps_dec_bitdec_tables),
1443
0
      sizeof(ixheaacd_mps_dec_blind_tables),
1444
0
      sizeof(ixheaacd_mps_dec_mdct2qmf_tables),
1445
0
      sizeof(ia_mps_dec_mdct2qmf_cos_table_struct),
1446
0
      sizeof(ia_mps_dec_residual_aac_tables_struct)};
1447
0
  table_ptrs[0] =
1448
0
      (pVOID *)&(p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables);
1449
0
  table_ptrs[1] =
1450
0
      (pVOID *)&(p_obj_exhaacplus_dec->aac_tables.pstr_block_tables);
1451
0
  table_ptrs[2] =
1452
0
      (pVOID *)&(p_obj_exhaacplus_dec->aac_tables.pstr_imdct_tables);
1453
0
  table_ptrs[3] = (pVOID *)&(p_obj_exhaacplus_dec->common_tables);
1454
0
  table_ptrs[4] =
1455
0
      (pVOID *)&p_obj_exhaacplus_dec->str_sbr_tables.env_calc_tables_ptr;
1456
0
  table_ptrs[5] =
1457
0
      (pVOID *)&p_obj_exhaacplus_dec->str_sbr_tables.qmf_dec_tables_ptr;
1458
0
  table_ptrs[6] =
1459
0
      (pVOID *)&p_obj_exhaacplus_dec->str_sbr_tables.env_extr_tables_ptr;
1460
0
  table_ptrs[7] = (pVOID *)&p_obj_exhaacplus_dec->str_sbr_tables.ps_tables_ptr;
1461
0
  table_ptrs[8] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.qmf_table_ptr);
1462
0
  table_ptrs[9] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr);
1463
0
  table_ptrs[10] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.hybrid_table_ptr);
1464
0
  table_ptrs[11] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr);
1465
0
  table_ptrs[12] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.decor_table_ptr);
1466
0
  table_ptrs[13] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.tp_process_table_ptr);
1467
0
  table_ptrs[14] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.mdct2qmf_table_ptr);
1468
0
  table_ptrs[15] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.tonality_table_ptr);
1469
0
  table_ptrs[16] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr);
1470
0
  table_ptrs[17] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.blind_table_ptr);
1471
0
  table_ptrs[18] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.mdct2qmfcos_table_ptr);
1472
0
  table_ptrs[19] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.mdct2qmfcos_tab_ptr);
1473
0
  table_ptrs[20] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.aac_tab);
1474
1475
0
  if (i_idx < 0 || i_idx >= (NUM_AAC_TABLES + NUM_MPS_TABLES)) {
1476
0
    return IA_XHEAAC_DEC_API_FATAL_INVALID_MEMTAB_INDEX;
1477
0
  }
1478
1479
0
  ui_get_vals[0] = table_sizes[i_idx];
1480
0
  ui_get_vals[1] = 4;
1481
0
  ui_get_vals[4] = (SIZE_T)(*table_ptrs[i_idx]);
1482
1483
0
  if (i_cmd == IA_API_CMD_SET_TABLE_PTR) {
1484
0
    if (pv_value == 0) {
1485
0
      return (IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC);
1486
0
    }
1487
0
    if (((SIZE_T)pv_value) & 3) {
1488
0
      return IA_XHEAAC_DEC_API_FATAL_MEM_ALIGN;
1489
0
    }
1490
1491
0
    *table_ptrs[i_idx] = pv_value;
1492
1493
0
    if (i_idx == 0) {
1494
0
      ixheaacd_huff_tables_create(&p_obj_exhaacplus_dec->aac_tables);
1495
0
    }
1496
1497
0
  }
1498
1499
0
  else if (i_cmd == IA_API_CMD_GET_TABLE_PTR) {
1500
0
    *p_pui_value = (UWORD32 *)((SIZE_T)(
1501
0
        ui_get_vals[i_cmd - IA_API_CMD_GET_TABLE_INFO_SIZE]));
1502
0
  } else {
1503
0
    *pui_value = (WORD32)(ui_get_vals[i_cmd - IA_API_CMD_GET_TABLE_INFO_SIZE]);
1504
0
  }
1505
1506
0
  return IA_NO_ERROR;
1507
0
}
1508
1509
VOID ixheaacd_mps_payload(ia_handle_sbr_dec_inst_struct self,
1510
3.71k
                          ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
1511
3.71k
  struct ia_bit_buf_struct local_bit_buff;
1512
3.71k
  struct ia_bit_buf_struct *it_bit_buff;
1513
3.71k
  if (self->ptr_mps_data != NULL) {
1514
2.42k
    ixheaacd_create_init_bit_buf(&local_bit_buff, (UWORD8 *)self->ptr_mps_data,
1515
2.42k
                                 (self->left_mps_bits >> 3) + 1);
1516
2.42k
  }
1517
1518
3.71k
  local_bit_buff.xaac_jmp_buf =
1519
3.71k
      &p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf;
1520
1521
3.71k
  it_bit_buff = &local_bit_buff;
1522
1523
3.71k
  it_bit_buff->bit_pos = self->mps_bits_pos;
1524
3.71k
  it_bit_buff->cnt_bits = self->left_mps_bits;
1525
1526
8.52k
  while (self->left_mps_bits >= 8) {
1527
4.81k
    ixheaacd_extension_payload(
1528
4.81k
        it_bit_buff, &self->left_mps_bits,
1529
4.81k
        &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle);
1530
4.81k
  }
1531
3.71k
}
1532
1533
IA_ERRORCODE ixheaacd_dec_init(
1534
27.4k
    ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
1535
27.4k
  FLAG frame_status = 1;
1536
27.4k
  WORD32 frame_size_1;
1537
27.4k
  WORD32 sample_rate_1;
1538
27.4k
  WORD16 num_channels_1;
1539
27.4k
  WORD32 ps_detected = 0;
1540
27.4k
  UWORD8 *in_buffer;
1541
27.4k
  WORD16 *time_data;
1542
27.4k
  WORD ch_idx;
1543
27.4k
  WORD sbr_present_flag = 0;
1544
27.4k
  UWORD8 *mps_buffer;
1545
27.4k
  ia_aac_dec_state_struct *p_state_enhaacplus_dec;
1546
1547
27.4k
  WORD32 error_code = IA_NO_ERROR;
1548
27.4k
  WORD32 persistent_used = 0;
1549
27.4k
  IA_ERRORCODE err_code = IA_NO_ERROR;
1550
27.4k
  struct ia_aac_persistent_struct *aac_persistent_mem;
1551
27.4k
  struct ia_sbr_pers_struct *sbr_persistent_mem;
1552
27.4k
  WORD32 ret_val;
1553
1554
27.4k
  p_obj_exhaacplus_dec->p_state_aac =
1555
27.4k
      p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX];
1556
1557
27.4k
  if (p_obj_exhaacplus_dec->p_state_aac->ui_init_done)
1558
0
  {
1559
0
    return IA_NO_ERROR;
1560
0
  }
1561
1562
27.4k
  p_obj_exhaacplus_dec->p_state_aac->preroll_config_present = 0;
1563
1564
27.4k
  if (p_obj_exhaacplus_dec->p_state_aac != NULL) {
1565
27.4k
    ret_val = setjmp(p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf);
1566
27.4k
    if (ret_val != 0) {
1567
1.14k
      p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
1568
1.14k
          p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
1569
1.14k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
1570
1.14k
      return IA_NO_ERROR;
1571
1.14k
    }
1572
27.4k
  }
1573
1574
26.2k
  time_data = (WORD16 *)(p_obj_exhaacplus_dec
1575
26.2k
                             ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]);
1576
1577
27.4k
  if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) {
1578
27.4k
    in_buffer = p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX];
1579
18.4E
  } else {
1580
18.4E
    in_buffer = p_obj_exhaacplus_dec->p_state_aac->header_ptr;
1581
18.4E
  }
1582
1583
26.2k
  p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac;
1584
1585
26.2k
  p_state_enhaacplus_dec->aac_scratch_mem_v =
1586
26.2k
      p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX];
1587
26.2k
  p_obj_exhaacplus_dec->p_state_aac->huffman_code_book_scl =
1588
26.2k
      p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables
1589
26.2k
          ->huffman_code_book_scl;
1590
26.2k
  mps_buffer = p_obj_exhaacplus_dec->p_state_aac->mps_buffer;
1591
26.2k
  p_state_enhaacplus_dec->mps_header = -1;
1592
26.2k
  p_obj_exhaacplus_dec->p_state_aac->huffman_code_book_scl_index =
1593
26.2k
      p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables
1594
26.2k
          ->huffman_code_book_scl_index;
1595
1596
26.2k
  p_state_enhaacplus_dec->pstr_aac_tables = &p_obj_exhaacplus_dec->aac_tables;
1597
26.2k
  if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 0)
1598
17.1k
  {
1599
17.1k
    p_obj_exhaacplus_dec->aac_config.header_dec_done = 0;
1600
17.1k
    p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.ldmps_present_flag = 0;
1601
17.1k
  }
1602
26.2k
  if (p_obj_exhaacplus_dec->aac_config.header_dec_done == 0) {
1603
17.1k
    WORD32 channels;
1604
17.1k
    UWORD32 total_persistent_used = 0;
1605
1606
17.1k
    p_obj_exhaacplus_dec->p_state_aac->p_config =
1607
17.1k
        &p_obj_exhaacplus_dec->aac_config;
1608
1609
17.1k
    p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr =
1610
17.1k
        (pVOID)((pWORD8)p_obj_exhaacplus_dec->p_state_aac +
1611
17.1k
                IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8));
1612
17.1k
    if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
1613
17.1k
      p_state_enhaacplus_dec->aac_persistent_mem_v =
1614
17.1k
          (pVOID)((pWORD8)p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr +
1615
17.1k
                  (MAX_BS_ELEMENT)*2 *
1616
17.1k
                      IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct),
1617
17.1k
                                               BYTE_ALIGN_8));
1618
1619
17.1k
      memset(p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr, 0,
1620
17.1k
             (MAX_BS_ELEMENT)*2 *
1621
17.1k
                 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), BYTE_ALIGN_8));
1622
17.1k
    } else {
1623
0
      p_state_enhaacplus_dec->aac_persistent_mem_v =
1624
0
          (pVOID)((pWORD8)p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr +
1625
0
                  (2) * 2 *
1626
0
                      IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct),
1627
0
                                               BYTE_ALIGN_8));
1628
1629
0
      memset(p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr, 0,
1630
0
             (2) * 2 *
1631
0
                 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), BYTE_ALIGN_8));
1632
0
    }
1633
17.1k
    if (1 == p_obj_exhaacplus_dec->aac_config.ui_max_channels)
1634
0
      channels = 1;
1635
17.1k
    else
1636
17.1k
      channels = 2;
1637
1638
17.1k
    persistent_used = ixheaacd_set_aac_persistent_buffers(
1639
17.1k
        p_state_enhaacplus_dec->aac_persistent_mem_v, channels);
1640
1641
17.1k
    p_state_enhaacplus_dec->sbr_persistent_mem_v =
1642
17.1k
        (pVOID)((pWORD8)p_state_enhaacplus_dec->aac_persistent_mem_v +
1643
17.1k
                IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8));
1644
17.1k
    total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8);
1645
1646
17.1k
    persistent_used = ixheaacd_getsize_sbr_persistent();
1647
17.1k
    ixheaacd_set_sbr_persistent_buffers(
1648
17.1k
        p_state_enhaacplus_dec->sbr_persistent_mem_v, &persistent_used,
1649
17.1k
        channels, 1);
1650
1651
17.1k
    p_state_enhaacplus_dec->heaac_mps_handle.mps_persistent_mem_v =
1652
17.1k
        (pVOID)((pWORD8)p_state_enhaacplus_dec->sbr_persistent_mem_v +
1653
17.1k
                IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8));
1654
17.1k
    total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8);
1655
1656
17.1k
    persistent_used = ixheaacd_getsize_mps_persistent();
1657
1658
17.1k
    ixheaacd_set_mps_persistent_buffers(
1659
17.1k
        &p_state_enhaacplus_dec->heaac_mps_handle, &persistent_used, channels,
1660
17.1k
        p_state_enhaacplus_dec->heaac_mps_handle.mps_persistent_mem_v);
1661
17.1k
    total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8);
1662
1663
17.1k
    if (total_persistent_used >
1664
17.1k
        p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX].ui_size) {
1665
0
      return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL;
1666
0
    }
1667
1668
17.1k
    aac_persistent_mem = (struct ia_aac_persistent_struct *)
1669
17.1k
                             p_state_enhaacplus_dec->aac_persistent_mem_v;
1670
17.1k
    if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
1671
17.1k
        p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD)
1672
1
      p_state_enhaacplus_dec->frame_len_flag =
1673
1
          p_obj_exhaacplus_dec->aac_config.framesize_480;
1674
1675
17.1k
    p_state_enhaacplus_dec->ptr_overlap_buf =
1676
17.1k
        aac_persistent_mem->overlap_buffer;
1677
1678
17.1k
    p_state_enhaacplus_dec->bit_count = 0;
1679
17.1k
    p_state_enhaacplus_dec->ec_enable = p_obj_exhaacplus_dec->aac_config.ui_err_conceal;
1680
17.1k
    p_state_enhaacplus_dec->sync_status = 0;
1681
17.1k
    p_state_enhaacplus_dec->bs_format = ADTS_BSFORMAT;
1682
17.1k
    p_state_enhaacplus_dec->latm_initialized = 0;
1683
17.1k
    p_state_enhaacplus_dec->frame_size = 0;
1684
17.1k
    memset(&p_state_enhaacplus_dec->latm_struct_element, 0,
1685
17.1k
           sizeof(ixheaacd_latm_struct));
1686
17.1k
    memset(&p_state_enhaacplus_dec->b_n_raw_data_blk, 0,
1687
17.1k
           sizeof(WORD32) * (9 + MAX_BS_ELEMENT));
1688
1689
17.1k
    p_state_enhaacplus_dec->sbr_present_flag = 0;
1690
1691
188k
    for (ch_idx = 0; ch_idx < MAX_BS_ELEMENT; ch_idx++) {
1692
171k
      p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0;
1693
171k
    }
1694
1695
17.1k
    memset(&p_state_enhaacplus_dec->ind_cc_info, 0,
1696
17.1k
           sizeof(ia_enhaacplus_dec_ind_cc));
1697
1698
17.1k
    p_state_enhaacplus_dec->last_frame_ok = 1;
1699
17.1k
    p_obj_exhaacplus_dec->aac_config.header_dec_done = 1;
1700
1701
17.1k
    aac_persistent_mem->str_aac_decoder.pstr_aac_tables =
1702
17.1k
        &p_obj_exhaacplus_dec->aac_tables;
1703
17.1k
    aac_persistent_mem->str_aac_decoder.pstr_common_tables =
1704
17.1k
        p_obj_exhaacplus_dec->common_tables;
1705
1706
17.1k
    p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_u =
1707
17.1k
        p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_v;
1708
1709
17.1k
    p_obj_exhaacplus_dec->p_state_aac->sbr_scratch_mem_u =
1710
17.1k
        p_obj_exhaacplus_dec->p_state_aac->aac_scratch_mem_v;
1711
1712
17.1k
    ixheaacd_set_sbr_persistent_table_pointer(
1713
17.1k
        p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_v,
1714
17.1k
        &p_obj_exhaacplus_dec->str_sbr_tables,
1715
17.1k
        p_obj_exhaacplus_dec->common_tables);
1716
17.1k
    ixheaacd_set_scratch_buffers(
1717
17.1k
        &p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle,
1718
17.1k
        p_state_enhaacplus_dec->aac_scratch_mem_v);
1719
17.1k
  }
1720
1721
26.2k
  if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 1) {
1722
0
    return IA_XHEAAC_DEC_INIT_FATAL_EO_INPUT_REACHED;
1723
0
  }
1724
1725
26.2k
  if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 0) {
1726
17.1k
    if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
1727
17.1k
        p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD)
1728
1
      p_state_enhaacplus_dec->frame_len_flag =
1729
1
          p_obj_exhaacplus_dec->aac_config.framesize_480;
1730
1731
17.1k
    aac_persistent_mem = (struct ia_aac_persistent_struct *)
1732
17.1k
                             p_state_enhaacplus_dec->aac_persistent_mem_v;
1733
17.1k
    sbr_persistent_mem = (struct ia_sbr_pers_struct *)
1734
17.1k
                             p_state_enhaacplus_dec->sbr_persistent_mem_v;
1735
17.1k
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
1736
0
      p_obj_exhaacplus_dec->p_state_aac->first_frame = 1;
1737
0
    }
1738
1739
17.1k
    if (p_obj_exhaacplus_dec->aac_config.ui_samp_freq == 0) {
1740
17.1k
      WORD32 header_bytes_consumed, return_val;
1741
1742
17.1k
      if (p_state_enhaacplus_dec->ui_in_bytes == 0) {
1743
0
        p_state_enhaacplus_dec->i_bytes_consumed = 0;
1744
0
        return IA_NO_ERROR;
1745
0
      }
1746
1747
17.1k
      if (1 == p_obj_exhaacplus_dec->aac_config.ui_frame_size) {
1748
0
        p_state_enhaacplus_dec->frame_len_flag = 1;
1749
0
        p_state_enhaacplus_dec->frame_length = 960;
1750
17.1k
      } else {
1751
17.1k
        p_state_enhaacplus_dec->frame_len_flag = 0;
1752
17.1k
        p_state_enhaacplus_dec->frame_length = 1024;
1753
17.1k
      }
1754
1755
17.1k
      p_state_enhaacplus_dec->ui_init_done = 0;
1756
17.1k
      memset(&(p_state_enhaacplus_dec->eld_specific_config), 0,
1757
17.1k
             sizeof(ia_eld_specific_config_struct));
1758
17.1k
      return_val = ixheaacd_aac_headerdecode(
1759
17.1k
          p_obj_exhaacplus_dec, (UWORD8 *)in_buffer, &header_bytes_consumed,
1760
17.1k
          aac_persistent_mem->str_aac_decoder.pstr_aac_tables
1761
17.1k
              ->pstr_huffmann_tables);
1762
17.1k
      if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
1763
15.5k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD ||
1764
13.3k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) {
1765
4.40k
        *sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[0] =
1766
4.40k
            p_obj_exhaacplus_dec->p_state_aac->str_sbr_config;
1767
4.40k
        *sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[1] =
1768
4.40k
            p_obj_exhaacplus_dec->p_state_aac->str_sbr_config;
1769
12.7k
      } else {
1770
12.7k
        memset(&(p_state_enhaacplus_dec->eld_specific_config), 0,
1771
12.7k
               sizeof(ia_eld_specific_config_struct));
1772
12.7k
      }
1773
1774
17.1k
      if (return_val < 0) {
1775
373
        if (return_val ==
1776
373
            (WORD32)IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX) {
1777
5
          p_state_enhaacplus_dec->i_bytes_consumed = header_bytes_consumed;
1778
5
          return return_val;
1779
5
        }
1780
368
        p_state_enhaacplus_dec->i_bytes_consumed = 1;
1781
1782
368
        return return_val;
1783
373
      }
1784
1785
16.7k
      if (return_val ==
1786
16.7k
          IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES) {
1787
25
        p_state_enhaacplus_dec->i_bytes_consumed = header_bytes_consumed;
1788
25
        return return_val;
1789
25
      }
1790
1791
16.7k
      p_state_enhaacplus_dec->i_bytes_consumed = header_bytes_consumed;
1792
1793
16.7k
      if ((return_val == 0) &&
1794
16.4k
          (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_USAC)) {
1795
6.03k
        {
1796
6.03k
          WORD32 pcm_size = p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz;
1797
6.03k
          WORD8 *inbuffer =
1798
6.03k
              p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX];
1799
6.03k
          WORD8 *outbuffer =
1800
6.03k
              p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX];
1801
6.03k
          WORD32 out_bytes = 0;
1802
6.03k
          WORD32 frames_done = p_obj_exhaacplus_dec->p_state_aac->frame_counter;
1803
6.03k
          p_obj_exhaacplus_dec->p_state_aac->decode_create_done = 0;
1804
1805
6.03k
          if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 0) {
1806
6.03k
            error_code = ixheaacd_dec_main(
1807
6.03k
                p_obj_exhaacplus_dec, inbuffer, outbuffer, &out_bytes,
1808
6.03k
                frames_done, pcm_size,
1809
6.03k
                &p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch);
1810
6.03k
            if (error_code) return error_code;
1811
6.01k
            p_obj_exhaacplus_dec->p_state_aac->frame_counter++;
1812
6.01k
          } else {
1813
0
            out_bytes = 0;
1814
0
          }
1815
1816
6.01k
          p_obj_exhaacplus_dec->aac_config.ui_n_channels =
1817
6.01k
              p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch;
1818
6.01k
        }
1819
6.01k
        if (return_val == 0)
1820
6.01k
          p_obj_exhaacplus_dec->p_state_aac->ui_init_done = 1;
1821
6.01k
        return return_val;
1822
6.03k
      }
1823
1824
10.6k
      if (return_val == 0) {
1825
10.3k
        p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 1;
1826
10.3k
        if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) {
1827
10.3k
          memcpy(p_state_enhaacplus_dec->header_ptr, in_buffer,
1828
10.3k
                 header_bytes_consumed * sizeof(UWORD8));
1829
10.3k
          p_state_enhaacplus_dec->header_length = header_bytes_consumed;
1830
10.3k
        }
1831
10.3k
      }
1832
1833
10.6k
      if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done != 1)
1834
12
        return IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START;
1835
1836
10.6k
      if (p_state_enhaacplus_dec->dwnsmp_signal == 1 &&
1837
1.31k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD)
1838
1.31k
        p_obj_exhaacplus_dec->aac_config.down_sample_flag = 1;
1839
1840
10.6k
      if (p_state_enhaacplus_dec->sampling_rate ==
1841
10.6k
          p_state_enhaacplus_dec->extension_samp_rate) {
1842
4
        p_obj_exhaacplus_dec->aac_config.down_sample_flag = 1;
1843
4
      }
1844
1845
10.6k
    } else {
1846
1
      p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 1;
1847
1
      p_state_enhaacplus_dec->i_bytes_consumed = 0;
1848
1849
1
      p_state_enhaacplus_dec->sampling_rate =
1850
1
          p_obj_exhaacplus_dec->aac_config.ui_samp_freq;
1851
1852
1
      if (1 == p_obj_exhaacplus_dec->aac_config.ui_frame_size) {
1853
0
        p_state_enhaacplus_dec->frame_len_flag = 1;
1854
0
        p_state_enhaacplus_dec->frame_length = 960;
1855
1
      } else {
1856
1
        p_state_enhaacplus_dec->frame_len_flag = 0;
1857
1
        p_state_enhaacplus_dec->frame_length = 1024;
1858
1
      }
1859
1
    }
1860
1861
10.6k
    p_state_enhaacplus_dec->pstr_bit_buf = ixheaacd_create_bit_buf(
1862
10.6k
        &p_state_enhaacplus_dec->str_bit_buf, (UWORD8 *)in_buffer,
1863
10.6k
        p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]
1864
10.6k
            .ui_size);
1865
10.6k
    p_state_enhaacplus_dec->pstr_bit_buf->xaac_jmp_buf =
1866
10.6k
        &(p_state_enhaacplus_dec->xaac_jmp_buf);
1867
1868
10.6k
    p_state_enhaacplus_dec->ptr_bit_stream =
1869
10.6k
        p_state_enhaacplus_dec->pstr_bit_buf;
1870
1871
10.6k
    if (p_state_enhaacplus_dec->s_adts_hdr_present) {
1872
5.60k
      if (p_obj_exhaacplus_dec->aac_config.ld_decoder == 1)
1873
0
        p_state_enhaacplus_dec->audio_object_type = 23;
1874
5.60k
    }
1875
1876
10.6k
    if ((p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) ||
1877
8.21k
        (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD))
1878
3.39k
      if (p_state_enhaacplus_dec->s_adts_hdr_present) {
1879
0
        if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) {
1880
0
          p_state_enhaacplus_dec->eld_specific_config.ld_sbr_samp_rate = 1;
1881
0
          p_state_enhaacplus_dec->eld_specific_config.ld_sbr_crc_flag = 0;
1882
0
          p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present = 0;
1883
1884
0
          if (p_obj_exhaacplus_dec->aac_config.eld_sbr_present == 1) {
1885
0
            p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present = 1;
1886
0
          }
1887
0
        }
1888
0
        if (p_obj_exhaacplus_dec->aac_config.framesize_480)
1889
0
          p_state_enhaacplus_dec->frame_length = 480;
1890
0
        else
1891
0
          p_state_enhaacplus_dec->frame_length = 512;
1892
0
      }
1893
1894
10.6k
    {
1895
114k
      for (ch_idx = 0; ch_idx < MAX_BS_ELEMENT; ch_idx++) {
1896
103k
        WORD32 channels;
1897
103k
        channels = 2;
1898
1899
103k
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] =
1900
103k
            ixheaacd_aac_decoder_init(
1901
103k
                p_state_enhaacplus_dec,
1902
1903
103k
                p_state_enhaacplus_dec->pstr_stream_sbr[0], channels,
1904
103k
                p_state_enhaacplus_dec->aac_persistent_mem_v,
1905
103k
                p_state_enhaacplus_dec->frame_length);
1906
1907
103k
        if (!p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]) {
1908
0
          p_state_enhaacplus_dec->i_bytes_consumed = 1;
1909
0
          return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL;
1910
0
        }
1911
103k
      }
1912
1913
10.6k
      {
1914
10.6k
        p_state_enhaacplus_dec->pstr_drc_dec =
1915
10.6k
            &p_state_enhaacplus_dec->str_drc_dec_info;
1916
10.6k
        ixheaacd_drc_dec_create(p_state_enhaacplus_dec->pstr_drc_dec, 127, 127);
1917
10.6k
      }
1918
10.6k
      p_state_enhaacplus_dec->pstr_drc_dec->cut_factor =
1919
10.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_cut;
1920
10.6k
      p_state_enhaacplus_dec->pstr_drc_dec->boost_factor =
1921
10.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_boost;
1922
10.6k
      p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level =
1923
10.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_target_level;
1924
10.6k
      p_state_enhaacplus_dec->pstr_drc_dec->prog_ref_level =
1925
10.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_target_level;
1926
1927
10.6k
      if (1 == p_obj_exhaacplus_dec->aac_config.ui_drc_set) {
1928
10.3k
        if (p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp == 1) {
1929
345
          p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 1;
1930
345
          p_state_enhaacplus_dec->pstr_drc_dec->heavy_mode = 1;
1931
10.0k
        } else {
1932
10.0k
          p_state_enhaacplus_dec->pstr_drc_dec->heavy_mode = 0;
1933
10.0k
          if (p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level > 127)
1934
0
            p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level = 127;
1935
10.0k
          if (p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level < 0) {
1936
0
            if (p_state_enhaacplus_dec->pstr_drc_dec->cut_factor > 0 ||
1937
0
                p_state_enhaacplus_dec->pstr_drc_dec->boost_factor > 0)
1938
0
              p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 1;
1939
0
            else
1940
0
              p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 0;
1941
0
            p_state_enhaacplus_dec->pstr_drc_dec->drc_dig_norm = 0;
1942
0
            p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level = 108;
1943
10.0k
          } else {
1944
10.0k
            p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 1;
1945
10.0k
            p_state_enhaacplus_dec->pstr_drc_dec->drc_dig_norm = 1;
1946
10.0k
          }
1947
10.0k
        }
1948
10.3k
      }
1949
10.6k
    }
1950
10.6k
  } else {
1951
9.15k
    struct ia_bit_buf_struct temp_bit_buff = {0};
1952
9.15k
    ia_adts_header_struct adts;
1953
9.15k
    struct ia_bit_buf_struct *it_bit_buff;
1954
1955
9.15k
    WORD16 frame_size_2 = 0;
1956
9.15k
    WORD32 sample_rate_2 = 0;
1957
9.15k
    WORD32 sample_rate = 0;
1958
9.15k
    WORD type, i;
1959
9.15k
    WORD elements_number;
1960
1961
9.15k
    if (p_state_enhaacplus_dec->audio_object_type == AOT_USAC)
1962
0
      return IA_FATAL_ERROR;
1963
1964
9.15k
    memset(&adts, 0, sizeof(ia_adts_header_struct));
1965
1966
122k
    for (i = 0; i < MAX_BS_ELEMENT + 1; i++) {
1967
113k
      p_obj_exhaacplus_dec->aac_config.element_type[i] = -1;
1968
113k
    }
1969
1970
9.15k
    it_bit_buff = p_state_enhaacplus_dec->pstr_bit_buf;
1971
1972
9.15k
    p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0;
1973
9.15k
    p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
1974
9.15k
    p_state_enhaacplus_dec->ui_mps_out_bytes = 0;
1975
9.15k
    if (p_state_enhaacplus_dec->ui_in_bytes == 0) {
1976
0
      p_state_enhaacplus_dec->i_bytes_consumed = 0;
1977
0
      return IA_NO_ERROR;
1978
0
    }
1979
1980
9.15k
    if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
1981
9.07k
        p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) {
1982
3.36k
      if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag)
1983
30
        p_state_enhaacplus_dec->frame_size =
1984
30
            p_state_enhaacplus_dec->ui_in_bytes;
1985
3.36k
    }
1986
1987
9.15k
    ixheaacd_create_init_bit_buf(it_bit_buff, in_buffer,
1988
9.15k
                                 p_state_enhaacplus_dec->ui_in_bytes);
1989
9.15k
    p_state_enhaacplus_dec->pstr_bit_buf->xaac_jmp_buf =
1990
9.15k
        &(p_state_enhaacplus_dec->xaac_jmp_buf);
1991
1992
9.15k
    it_bit_buff->adts_header_present =
1993
9.15k
        p_state_enhaacplus_dec->s_adts_hdr_present;
1994
9.15k
    it_bit_buff->no_raw_data_blocks =
1995
9.15k
        (WORD8)p_state_enhaacplus_dec->b_n_raw_data_blk;
1996
9.15k
    it_bit_buff->protection_absent = p_state_enhaacplus_dec->protection_absent;
1997
1998
9.15k
    memcpy(&temp_bit_buff, it_bit_buff, sizeof(struct ia_bit_buf_struct));
1999
2000
9.15k
    if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2)
2001
10.3k
      elements_number = MAX_BS_ELEMENT;
2002
18.4E
    else
2003
18.4E
      elements_number = 2;
2004
2005
112k
    for (i = 0; i < elements_number; i++)
2006
103k
      p_state_enhaacplus_dec->pstr_stream_sbr[i][0].no_elements = 0;
2007
2008
9.15k
    { it_bit_buff->initial_cnt_bits = it_bit_buff->cnt_bits; }
2009
2010
9.15k
    ixheaacd_byte_align(
2011
9.15k
        p_state_enhaacplus_dec->ptr_bit_stream,
2012
9.15k
        &p_state_enhaacplus_dec->pstr_aac_dec_info[0]->byte_align_bits);
2013
2014
9.15k
    if (p_state_enhaacplus_dec->s_adts_hdr_present) {
2015
5.60k
      WORD32 error;
2016
2017
5.60k
      if (p_state_enhaacplus_dec->b_n_raw_data_blk == 0) {
2018
5.60k
        error = ixheaacd_readifadts(p_state_enhaacplus_dec, it_bit_buff, &adts);
2019
2020
5.60k
        if (error) return error;
2021
2022
5.60k
        p_state_enhaacplus_dec->protection_absent = adts.protection_absent;
2023
2024
5.60k
        if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
2025
5.60k
            p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) {
2026
0
          p_state_enhaacplus_dec->frame_size = adts.aac_frame_length;
2027
0
          if (p_obj_exhaacplus_dec->aac_config.framesize_480)
2028
0
            p_state_enhaacplus_dec->frame_length = 480;
2029
0
          else
2030
0
            p_state_enhaacplus_dec->frame_length = 512;
2031
0
        }
2032
5.60k
      }
2033
5.60k
    }
2034
2035
9.15k
    if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
2036
4.61k
      WORD32 result;
2037
4.61k
      WORD32 sync;
2038
4.61k
      WORD32 cnt_bits;
2039
2040
4.61k
      sync = ixheaacd_read_bits_buf(it_bit_buff, 11);
2041
4.61k
      cnt_bits = it_bit_buff->cnt_bits;
2042
4.61k
      if (it_bit_buff->cnt_bits <= 24) {
2043
0
        return IA_XHEAAC_DEC_INIT_NONFATAL_INSUFFICIENT_INPUT_BYTES;
2044
0
      }
2045
2046
4.61k
      while (sync != 0x2b7) {
2047
0
        sync = ((sync & 0x3ff) << 1) | ixheaacd_read_bits_buf(it_bit_buff, 1);
2048
0
        if (it_bit_buff->cnt_bits < 11) {
2049
0
          ixheaacd_read_bidirection(it_bit_buff, -11);
2050
0
          p_state_enhaacplus_dec->i_bytes_consumed =
2051
0
              (cnt_bits - it_bit_buff->cnt_bits) / 8;
2052
0
          return (IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START);
2053
0
        }
2054
0
      }
2055
2056
4.61k
      it_bit_buff->audio_mux_align = it_bit_buff->cnt_bits - 13;
2057
2058
4.61k
      if (sync == 0x2b7) {
2059
4.61k
        result = ixheaacd_latm_audio_mux_element(
2060
4.61k
            it_bit_buff, &p_state_enhaacplus_dec->latm_struct_element,
2061
4.61k
            p_state_enhaacplus_dec,
2062
4.61k
            (ia_sampling_rate_info_struct *)&p_obj_exhaacplus_dec->aac_tables
2063
4.61k
                .pstr_huffmann_tables->str_sample_rate_info[0]);
2064
4.61k
        if (result < 0) {
2065
3
          return result;
2066
3
        }
2067
4.61k
      }
2068
4.61k
    }
2069
2070
9.15k
    p_state_enhaacplus_dec->pstr_aac_dec_info[0]->byte_align_bits =
2071
9.15k
        it_bit_buff->cnt_bits;
2072
2073
9.15k
    type = -1;
2074
9.15k
    ch_idx = 0;
2075
2076
17.3k
    while ((type != 7)) {
2077
12.6k
      ia_aac_dec_scratch_struct aac_scratch_struct;
2078
12.6k
      memset(&aac_scratch_struct, 0, sizeof(aac_scratch_struct));
2079
2080
12.6k
      if (ch_idx >= elements_number) {
2081
12
        p_state_enhaacplus_dec->i_bytes_consumed = 1;
2082
2083
12
        return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX;
2084
12
      }
2085
2086
12.5k
      ixheaacd_allocate_aac_scr(
2087
12.5k
          &aac_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v,
2088
12.5k
          time_data, 1, p_obj_exhaacplus_dec->aac_config.ui_max_channels,
2089
12.5k
          p_state_enhaacplus_dec->audio_object_type);
2090
2091
12.5k
      p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info =
2092
12.5k
          &p_state_enhaacplus_dec->ind_cc_info;
2093
12.5k
      if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2094
0
        p_obj_exhaacplus_dec->aac_config.first_frame = 1;
2095
0
      }
2096
2097
12.5k
      error_code = ixheaacd_aacdec_decodeframe(
2098
12.5k
          p_obj_exhaacplus_dec, &aac_scratch_struct, time_data, frame_status, &type, &ch_idx, 1,
2099
12.5k
          2, p_obj_exhaacplus_dec->aac_config.element_instance_order, 0, 1, 0,
2100
12.5k
          p_obj_exhaacplus_dec->aac_config.ui_max_channels, 2,
2101
12.5k
          p_obj_exhaacplus_dec->p_state_aac->frame_length,
2102
12.5k
          p_obj_exhaacplus_dec->p_state_aac->frame_size, p_state_enhaacplus_dec->pstr_drc_dec,
2103
12.5k
          p_state_enhaacplus_dec->audio_object_type, p_state_enhaacplus_dec->ch_config,
2104
12.5k
          p_state_enhaacplus_dec->eld_specific_config, p_state_enhaacplus_dec->s_adts_hdr_present,
2105
12.5k
          &p_state_enhaacplus_dec->drc_dummy, p_state_enhaacplus_dec->ldmps_present,
2106
12.5k
          &p_state_enhaacplus_dec->slot_pos, mps_buffer, &p_state_enhaacplus_dec->mps_header,
2107
12.5k
          &p_state_enhaacplus_dec->ui_mps_out_bytes, 1,
2108
12.5k
          p_obj_exhaacplus_dec->aac_config.first_frame);
2109
2110
12.5k
      if (p_state_enhaacplus_dec->pstr_drc_dec->drc_element_found == 1) {
2111
415
        if (p_obj_exhaacplus_dec->aac_config.i_loud_ref_level < 0) {
2112
0
          p_obj_exhaacplus_dec->aac_config.output_level =
2113
0
              p_state_enhaacplus_dec->pstr_drc_dec->prog_ref_level;
2114
415
        } else {
2115
415
          p_obj_exhaacplus_dec->aac_config.output_level =
2116
415
              p_obj_exhaacplus_dec->aac_config.i_loud_ref_level;
2117
415
        }
2118
415
      }
2119
2120
12.5k
      memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx]
2121
12.5k
                   ->pstr_aac_dec_ch_info[0]
2122
12.5k
                   ->str_ics_info.ltp),
2123
12.5k
             0, sizeof(ltp_info));
2124
12.5k
      memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx]
2125
12.5k
                   ->pstr_aac_dec_ch_info[0]
2126
12.5k
                   ->str_ics_info.ltp2),
2127
12.5k
             0, sizeof(ltp_info));
2128
12.5k
      memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx]
2129
12.5k
                   ->pstr_aac_dec_ch_info[1]
2130
12.5k
                   ->str_ics_info.ltp),
2131
12.5k
             0, sizeof(ltp_info));
2132
12.5k
      memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx]
2133
12.5k
                   ->pstr_aac_dec_ch_info[1]
2134
12.5k
                   ->str_ics_info.ltp2),
2135
12.5k
             0, sizeof(ltp_info));
2136
2137
12.5k
      {
2138
2139
12.5k
        frame_size_1 = p_state_enhaacplus_dec->frame_length;
2140
12.5k
        sample_rate_1 =
2141
12.5k
            p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->sampling_rate;
2142
12.5k
        num_channels_1 =
2143
12.5k
            p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->channels;
2144
12.5k
      }
2145
2146
12.5k
      if ((p_obj_exhaacplus_dec->aac_config.ui_max_channels <= 2) &&
2147
0
          (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 2)) {
2148
0
        p_state_enhaacplus_dec->i_bytes_consumed = 1;
2149
0
        return IA_XHEAAC_DEC_INIT_FATAL_UNIMPLEMENTED_CCE;
2150
0
      }
2151
2152
12.5k
      if (p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
2153
2.09k
        sbr_present_flag = 1;
2154
2.09k
        p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 1;
2155
2.09k
      }
2156
2157
12.5k
      if (error_code) {
2158
412
        if (p_state_enhaacplus_dec->ui_input_over) {
2159
0
          return IA_XHEAAC_DEC_INIT_FATAL_EO_INPUT_REACHED;
2160
0
        }
2161
2162
412
        ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
2163
412
        return error_code;
2164
412
      }
2165
2166
12.1k
      if (p_state_enhaacplus_dec->s_adts_hdr_present) {
2167
6.35k
        if (adts.no_raw_data_blocks != 0) {
2168
3.49k
          if (adts.protection_absent == 0 && it_bit_buff->cnt_bits >= 16) {
2169
56
            adts.crc_check = ixheaacd_read_bits_buf(it_bit_buff, 16);
2170
56
          }
2171
3.49k
        }
2172
6.35k
        p_state_enhaacplus_dec->b_n_raw_data_blk--;
2173
6.35k
      }
2174
2175
12.1k
      sample_rate_2 = sample_rate_1;
2176
12.1k
      frame_size_2 = frame_size_1;
2177
2178
12.1k
      if (!p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] &&
2179
11.4k
          p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
2180
2.09k
        WORD32 harmonic_sbr_flag = 0;
2181
2.09k
        if ((p_obj_exhaacplus_dec->aac_config.flag_16khz_out == 1) &&
2182
0
            (sample_rate_1 == 8000)) {
2183
0
          p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0;
2184
0
        }
2185
2186
2.09k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr(
2187
2.09k
            sample_rate_1, frame_size_1,
2188
2.09k
            (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag,
2189
2.09k
            p_state_enhaacplus_dec->sbr_persistent_mem_v,
2190
2.09k
            p_state_enhaacplus_dec->ptr_overlap_buf, MAXNRSBRCHANNELS, (WORD)1,
2191
2.09k
            1, frame_size_1 * 2, &harmonic_sbr_flag, NULL,
2192
2.09k
            p_state_enhaacplus_dec->str_sbr_config,
2193
2.09k
            p_state_enhaacplus_dec->audio_object_type,
2194
2.09k
            p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2195
2.09k
                .ldmps_present_flag,
2196
2.09k
            p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2197
2.09k
                .no_ldsbr_present);
2198
2.09k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
2199
2.07k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
2200
2.07k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
2201
2.07k
        }
2202
10.0k
      } else {
2203
10.0k
      }
2204
2205
12.1k
      if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] &&
2206
2.07k
          p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
2207
2.07k
        ia_sbr_scr_struct sbr_scratch_struct;
2208
2.07k
        WORD16 num_channels_1_t = num_channels_1;
2209
2.07k
        ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v,
2210
2.07k
                                  time_data, 0, NULL, 0, 0);
2211
2.07k
        {
2212
2.07k
          WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type;
2213
2214
2.07k
          if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) {
2215
441
            WORD32 i = 0;
2216
441
            ia_dec_data_struct *pstr_dec_data =
2217
441
                (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data;
2218
441
            if (num_channels_1 == 1) {
2219
381k
              for (; i < 1024; i++) {
2220
380k
                pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
2221
380k
                    ((FLOAT32)time_data[i]);
2222
380k
              }
2223
372
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
2224
372
                  &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
2225
2226
372
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
2227
372
                  &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
2228
372
            } else if (num_channels_1 == 2) {
2229
70.7k
              for (; i < 1024; i++) {
2230
70.6k
                pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
2231
70.6k
                    ((FLOAT32)time_data[2 * i + 0]);
2232
70.6k
                pstr_dec_data->str_usac_data.time_sample_vector[1][i] =
2233
70.6k
                    ((FLOAT32)time_data[2 * i + 1]);
2234
70.6k
              }
2235
69
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
2236
69
                  &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
2237
2238
69
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
2239
69
                  &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
2240
69
            }
2241
441
          }
2242
2.07k
        }
2243
2.07k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->ec_flag =
2244
2.07k
            p_obj_exhaacplus_dec->aac_config.ui_err_conceal;
2245
2.07k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->esbr_hq =
2246
2.07k
            p_obj_exhaacplus_dec->aac_config.ui_hq_esbr;
2247
2.07k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr =
2248
2.07k
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr;
2249
2.07k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr_ps =
2250
2.07k
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps;
2251
2252
2.07k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
2253
2.07k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
2254
2.07k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
2255
2.07k
        }
2256
2257
2.07k
        if (ixheaacd_applysbr(p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx],
2258
2.07k
                              &p_state_enhaacplus_dec->pstr_stream_sbr[0][0], time_data,
2259
2.07k
                              &num_channels_1, frame_status,
2260
2.07k
                              p_obj_exhaacplus_dec->aac_config.down_sample_flag, 0,
2261
2.07k
                              &sbr_scratch_struct, 1, 1, 0, NULL, NULL,
2262
2.07k
                              p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present,
2263
2.07k
                              p_state_enhaacplus_dec->audio_object_type, 1,
2264
2.07k
                              p_state_enhaacplus_dec->ldmps_present, frame_size_1,
2265
2.07k
                              p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present,
2266
2.07k
                              p_obj_exhaacplus_dec->aac_config.ui_err_conceal,
2267
2.07k
                              p_obj_exhaacplus_dec->aac_config.first_frame) != SBRDEC_OK) {
2268
21
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0;
2269
21
          return -1;
2270
2.05k
        } else {
2271
2.05k
          if (!p_obj_exhaacplus_dec->aac_config.down_sample_flag) {
2272
924
            sample_rate_1 *= 2;
2273
924
          }
2274
2.05k
          if (p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present == 1) {
2275
1.57k
            p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.pre_mix_req = 1;
2276
1.57k
            ixheaacd_mps_payload(
2277
1.57k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx],
2278
1.57k
              p_obj_exhaacplus_dec);
2279
1.57k
          }
2280
2.05k
        }
2281
2.05k
        {
2282
2.05k
          WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type;
2283
2284
2.05k
          if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) {
2285
441
            WORD32 out_bytes = 0;
2286
441
            ia_dec_data_struct *pstr_dec_data =
2287
441
                (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data;
2288
441
            ixheaacd_samples_sat((WORD8 *)time_data, 2048, 16,
2289
441
                                 pstr_dec_data->str_usac_data.time_sample_vector, &out_bytes, 1);
2290
441
          }
2291
2.05k
        }
2292
2.05k
        if (p_obj_exhaacplus_dec->aac_config.flag_downmix) {
2293
0
          num_channels_1 = 1;
2294
0
        }
2295
2.05k
        if (num_channels_1_t == 1 && num_channels_1 == 2) ps_detected = 1;
2296
10.1k
      } else {
2297
10.1k
        p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present = 1;
2298
10.1k
      }
2299
2300
12.1k
      p_state_enhaacplus_dec->i_bytes_consumed = 0;
2301
12.1k
      p_state_enhaacplus_dec->pstr_bit_buf = it_bit_buff;
2302
2303
12.1k
      {
2304
12.1k
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] =
2305
12.1k
            ixheaacd_aac_decoder_init(
2306
12.1k
                p_state_enhaacplus_dec,
2307
12.1k
                p_state_enhaacplus_dec->pstr_stream_sbr[0], 2,
2308
12.1k
                p_state_enhaacplus_dec->aac_persistent_mem_v,
2309
12.1k
                p_state_enhaacplus_dec->frame_length);
2310
2311
12.1k
        if (!p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]) {
2312
0
          p_state_enhaacplus_dec->i_bytes_consumed = 1;
2313
0
          return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL;
2314
0
        }
2315
2316
12.1k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
2317
1.98k
          WORD32 harmonic_sbr_flag = 0;
2318
1.98k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr(
2319
1.98k
              sample_rate_2, frame_size_2,
2320
1.98k
              (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag,
2321
1.98k
              p_state_enhaacplus_dec->sbr_persistent_mem_v,
2322
1.98k
              p_state_enhaacplus_dec->ptr_overlap_buf, MAXNRSBRCHANNELS, 1, 1,
2323
1.98k
              frame_size_2 * 2, &harmonic_sbr_flag, NULL,
2324
1.98k
              p_state_enhaacplus_dec->str_sbr_config,
2325
1.98k
              p_state_enhaacplus_dec->audio_object_type,
2326
1.98k
              p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2327
1.98k
                .ldmps_present_flag,
2328
1.98k
              p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2329
1.98k
                .no_ldsbr_present);
2330
1.98k
        }
2331
12.1k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
2332
1.98k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
2333
1.98k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
2334
1.98k
        }
2335
12.1k
      }
2336
2337
12.1k
      if (sample_rate < sample_rate_1) sample_rate = sample_rate_1;
2338
2339
12.1k
      ch_idx++;
2340
2341
12.1k
      if (p_state_enhaacplus_dec->audio_object_type >= ER_OBJECT_START &&
2342
4.01k
          (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD ||
2343
2.01k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
2344
819
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC))
2345
3.99k
        break;
2346
12.1k
    }
2347
2348
8.71k
    {
2349
8.71k
      ia_adts_crc_info_struct *ptr_adts_crc_info =
2350
8.71k
          p_state_enhaacplus_dec->ptr_bit_stream->pstr_adts_crc_info;
2351
8.71k
      if (ptr_adts_crc_info->crc_active == 1) {
2352
41
        if ((error_code = ixheaacd_adts_crc_check_crc(ptr_adts_crc_info))) {
2353
41
          return error_code;
2354
41
        }
2355
41
      }
2356
8.71k
    }
2357
2358
8.66k
    {
2359
8.66k
      VOID *temp;
2360
8.66k
      WORD prev_persistent_used_t;
2361
8.66k
      WORD prev_sbrpersistent_used_t;
2362
8.66k
      WORD ps_enable;
2363
8.66k
      WORD ch_idx_err = 0;
2364
8.66k
      WORD persistent_used_t = 0;
2365
8.66k
      WORD channel_check = 0;
2366
8.66k
      WORD cc_channel_check = 0;
2367
8.66k
      WORD max_ch_num = p_obj_exhaacplus_dec->aac_config.ui_max_channels;
2368
8.66k
      WORD32 harmonic_sbr_flag = 0;
2369
8.66k
      i = 0;
2370
2371
8.66k
      p_obj_exhaacplus_dec->aac_config.ui_n_channels = ch_idx;
2372
18.9k
      while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx_err] <= 3 &&
2373
19.2k
             p_obj_exhaacplus_dec->aac_config.element_type[ch_idx_err] >= 0) {
2374
10.2k
        ch_idx_err++;
2375
10.2k
      }
2376
2377
8.66k
      if (ch_idx_err == 0) {
2378
12
        p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0;
2379
12
        p_state_enhaacplus_dec->i_bytes_consumed = (WORD32)(
2380
12
            it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base);
2381
12
        return IA_XHEAAC_DEC_INIT_NONFATAL_DECODE_FRAME_ERROR;
2382
12
      }
2383
2384
8.65k
      if (ch_idx_err == 1)
2385
8.47k
        ps_enable = 1;
2386
186
      else
2387
186
        ps_enable = 0;
2388
2389
14.9k
      while (p_obj_exhaacplus_dec->aac_config.element_type[i] >= 0 &&
2390
10.2k
             p_obj_exhaacplus_dec->aac_config.element_type[i] <= 3) {
2391
10.2k
        WORD32 channel = 0;
2392
10.2k
        switch (p_obj_exhaacplus_dec->aac_config.element_type[i]) {
2393
6.67k
          case 0:
2394
8.17k
          case 3:
2395
8.17k
            channel = 1;
2396
8.17k
            break;
2397
1.77k
          case 1:
2398
1.77k
            channel = 2;
2399
1.77k
            break;
2400
279
          case 2:
2401
279
            if (max_ch_num > 2) {
2402
279
              if (p_obj_exhaacplus_dec->aac_config.element_instance_order[i] !=
2403
279
                  p_obj_exhaacplus_dec->aac_config.ui_coupling_channel) {
2404
168
                i++;
2405
168
                continue;
2406
168
              }
2407
111
              channel = 1;
2408
111
            } else {
2409
0
              i++;
2410
0
              continue;
2411
0
            }
2412
111
            cc_channel_check++;
2413
111
            break;
2414
0
          default:
2415
0
            return -1;
2416
10.2k
        }
2417
2418
10.0k
        if (cc_channel_check > MAX_CC_CHANNEL_NUM)
2419
1
          return IA_XHEAAC_DEC_EXE_FATAL_UNIMPLEMENTED_CCE;
2420
10.0k
        if (ps_enable == 1) {
2421
8.45k
          channel = 2;
2422
8.45k
        }
2423
2424
10.0k
        if (p_obj_exhaacplus_dec->aac_config.element_type[i] != 2) {
2425
9.94k
          channel_check += channel;
2426
9.94k
        }
2427
2428
10.0k
        if (channel_check > max_ch_num) {
2429
2
          p_state_enhaacplus_dec->i_bytes_consumed = 1;
2430
2
          return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX;
2431
2
        }
2432
2433
10.0k
        temp = p_state_enhaacplus_dec->aac_persistent_mem_v;
2434
2435
10.0k
        prev_persistent_used_t = persistent_used_t;
2436
2437
10.0k
        ixheaacd_allocate_mem_persistent(
2438
10.0k
            p_obj_exhaacplus_dec, p_state_enhaacplus_dec, channel,
2439
10.0k
            &persistent_used_t, &prev_sbrpersistent_used_t, ps_enable);
2440
2441
10.0k
        p_state_enhaacplus_dec->aac_persistent_mem_v = temp;
2442
10.0k
        p_state_enhaacplus_dec->last_frame_ok = 1;
2443
2444
10.0k
        p_state_enhaacplus_dec->num_channel_last = 0;
2445
10.0k
        p_state_enhaacplus_dec->ui_init_done = 0;
2446
10.0k
        p_state_enhaacplus_dec->ui_input_over = 0;
2447
10.0k
        p_state_enhaacplus_dec->ptr_bit_stream =
2448
10.0k
            p_state_enhaacplus_dec->pstr_bit_buf;
2449
2450
10.0k
        p_state_enhaacplus_dec->pstr_aac_dec_info[i] = 0;
2451
2452
10.0k
        p_state_enhaacplus_dec->pstr_aac_dec_info[i] =
2453
10.0k
            ixheaacd_aac_decoder_init(
2454
10.0k
                p_state_enhaacplus_dec,
2455
10.0k
                p_state_enhaacplus_dec->pstr_stream_sbr[i], channel,
2456
10.0k
                (WORD8 *)p_state_enhaacplus_dec->aac_persistent_mem_v +
2457
10.0k
                    prev_persistent_used_t,
2458
10.0k
                p_state_enhaacplus_dec->frame_length);
2459
2460
10.0k
        if (!p_state_enhaacplus_dec->pstr_aac_dec_info[i]) {
2461
0
          p_state_enhaacplus_dec->i_bytes_consumed = 1;
2462
0
          return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL;
2463
0
        }
2464
2465
10.0k
        p_state_enhaacplus_dec->str_sbr_dec_info[i] = ixheaacd_init_sbr(
2466
10.0k
            sample_rate_2, frame_size_2,
2467
10.0k
            (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag,
2468
10.0k
            p_state_enhaacplus_dec->sbr_persistent_mem_v,
2469
10.0k
            p_state_enhaacplus_dec->ptr_overlap_buf, channel, ps_enable, 1,
2470
10.0k
            frame_size_2 * 2, &harmonic_sbr_flag, NULL,
2471
10.0k
            p_state_enhaacplus_dec->str_sbr_config,
2472
10.0k
            p_state_enhaacplus_dec->audio_object_type,
2473
10.0k
            p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2474
10.0k
                .ldmps_present_flag,
2475
10.0k
            p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2476
10.0k
                .no_ldsbr_present);
2477
10.0k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[i]) {
2478
9.99k
          p_state_enhaacplus_dec->str_sbr_dec_info[i]->xaac_jmp_buf =
2479
9.99k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
2480
9.99k
        }
2481
10.0k
        if ((sbr_present_flag &&
2482
2.00k
            ((p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
2483
2.00k
              AOT_AAC_LC) ||
2484
1.59k
             (p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
2485
1.59k
              AOT_SBR) ||
2486
1.59k
             (p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
2487
1.59k
               AOT_PS))) ||
2488
9.65k
            ((p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2489
9.65k
                  .ldmps_present_flag == 1) &&
2490
266
             (p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
2491
266
              AOT_ER_AAC_ELD)))
2492
671
          p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 1;
2493
10.0k
        copy_qmf_to_ldmps(&p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle,
2494
10.0k
                          p_state_enhaacplus_dec->sbr_persistent_mem_v);
2495
10.0k
        if (p_state_enhaacplus_dec->audio_object_type == AOT_AAC_LC &&
2496
5.41k
            p_state_enhaacplus_dec->ui_mps_out_bytes != 0) {
2497
3.93k
          p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present = 1;
2498
3.93k
          if (p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
2499
0
            p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.mps_with_sbr = 1;
2500
0
          }
2501
3.93k
          error_code =
2502
3.93k
              ixheaacd_aac_mps_init(p_obj_exhaacplus_dec, mps_buffer,
2503
3.93k
                                    p_state_enhaacplus_dec->ui_mps_out_bytes, sample_rate_1);
2504
3.93k
          if (error_code) return error_code;
2505
3.88k
          p_obj_exhaacplus_dec->aac_config.ui_n_channels =
2506
3.88k
              p_state_enhaacplus_dec->heaac_mps_handle.num_output_channels_at;
2507
3.88k
          if (p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.mps_with_sbr == 1) {
2508
0
            p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 1;
2509
0
          }
2510
3.88k
          if (p_obj_exhaacplus_dec->aac_config.element_type[i + 1] >= 0 &&
2511
0
              p_obj_exhaacplus_dec->aac_config.element_type[i + 1] <= 3) {
2512
0
            return IA_FATAL_ERROR;
2513
0
          }
2514
3.88k
          break;
2515
3.88k
        }
2516
6.12k
        i++;
2517
6.12k
      }
2518
8.60k
      p_state_enhaacplus_dec->pers_mem_ptr =
2519
8.60k
          (WORD8 *)p_state_enhaacplus_dec->aac_persistent_mem_v +
2520
8.60k
          persistent_used_t;
2521
2522
8.60k
      p_obj_exhaacplus_dec->aac_config.i_channel_mask =
2523
8.60k
          ixheaacd_get_channel_mask(p_obj_exhaacplus_dec);
2524
2525
8.60k
      {
2526
8.60k
        num_channels_1 = 0;
2527
8.60k
        ch_idx = 0;
2528
18.7k
        while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] >= 0 &&
2529
10.1k
               p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] <= 3) {
2530
10.1k
          if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 0 ||
2531
3.54k
              p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 3)
2532
8.07k
            num_channels_1 += 1;
2533
10.1k
          if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 1)
2534
1.77k
            num_channels_1 += 2;
2535
10.1k
          ch_idx++;
2536
10.1k
        }
2537
2538
8.60k
        if (ch_idx == 2 && num_channels_1 == 2) {
2539
185
          p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 2;
2540
185
        }
2541
8.60k
        if (ch_idx == 1) {
2542
8.38k
          if (num_channels_1 == 1)
2543
6.79k
            p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 0;
2544
8.38k
          if (num_channels_1 == 2)
2545
1.57k
            p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 1;
2546
8.38k
        }
2547
2548
8.60k
        if (ps_detected == 1 && num_channels_1 == 1) num_channels_1 = 2;
2549
8.60k
      }
2550
8.60k
    }
2551
8.60k
    if (1 == p_obj_exhaacplus_dec->aac_config.downmix) num_channels_1 = 2;
2552
2553
8.60k
    if (p_obj_exhaacplus_dec->aac_config.flag_downmix == 1) {
2554
0
      num_channels_1 = 1;
2555
0
    }
2556
2557
8.60k
    if ((p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1) &&
2558
609
        (ch_idx == 1 || num_channels_1 <= 2)) {
2559
583
      num_channels_1 = 2;
2560
583
    }
2561
2562
8.60k
    p_obj_exhaacplus_dec->aac_config.ui_n_channels = num_channels_1;
2563
8.60k
    p_obj_exhaacplus_dec->aac_config.ui_samp_freq = sample_rate;
2564
8.60k
    p_state_enhaacplus_dec->ui_init_done = 1;
2565
2566
8.60k
    memcpy(it_bit_buff, &temp_bit_buff, sizeof(struct ia_bit_buf_struct));
2567
2568
8.60k
    p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
2569
2570
8.91k
    if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 1) {
2571
8.91k
      p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0;
2572
8.91k
    }
2573
8.60k
  }
2574
19.2k
  return err_code;
2575
26.2k
}
2576
2577
VOID ixheaacd_fill_slot_order(ia_aac_dec_state_struct *p_state_enhaacplus_dec,
2578
                              WORD32 ch, WORD8 *ptr_is_cpe,
2579
19.0k
                              WORD8 *ptr_tag_select, WORD32 *ptr_idx_no) {
2580
19.0k
  WORD32 i;
2581
19.0k
  WORD32 idx_no = *ptr_idx_no;
2582
19.0k
  WORD *p_slot_element = p_state_enhaacplus_dec->p_config->slot_element;
2583
19.0k
  WORD *p_element_type = p_state_enhaacplus_dec->p_config->element_type;
2584
19.0k
  WORD *p_element_instance_order =
2585
19.0k
      p_state_enhaacplus_dec->p_config->element_instance_order;
2586
2587
25.6k
  for (i = 0; i < ch; i++) {
2588
6.54k
    if (ptr_is_cpe[i] == 0) {
2589
4.15k
      *p_slot_element++ = idx_no++;
2590
4.15k
      *p_element_type++ = 0;
2591
4.15k
      *p_element_instance_order++ = ptr_tag_select[i];
2592
4.15k
    }
2593
6.54k
  }
2594
19.0k
  *ptr_idx_no = idx_no;
2595
19.0k
}
2596
2597
VOID ixheaacd_fill_prog_config_slots(
2598
6.36k
    ia_aac_dec_state_struct *p_state_enhaacplus_dec) {
2599
6.36k
  WORD32 idx_no = 0;
2600
2601
6.36k
  ixheaacd_fill_slot_order(
2602
6.36k
      p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config
2603
6.36k
                                  .num_front_channel_elements,
2604
6.36k
      p_state_enhaacplus_dec->p_config->str_prog_config.front_element_is_cpe,
2605
6.36k
      p_state_enhaacplus_dec->p_config->str_prog_config
2606
6.36k
          .front_element_tag_select,
2607
6.36k
      &idx_no);
2608
2609
6.36k
  ixheaacd_fill_slot_order(
2610
6.36k
      p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config
2611
6.36k
                                  .num_side_channel_elements,
2612
6.36k
      p_state_enhaacplus_dec->p_config->str_prog_config.side_element_is_cpe,
2613
6.36k
      p_state_enhaacplus_dec->p_config->str_prog_config.side_element_tag_select,
2614
6.36k
      &idx_no);
2615
2616
6.36k
  ixheaacd_fill_slot_order(
2617
6.36k
      p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config
2618
6.36k
                                  .num_back_channel_elements,
2619
6.36k
      p_state_enhaacplus_dec->p_config->str_prog_config.back_element_is_cpe,
2620
6.36k
      p_state_enhaacplus_dec->p_config->str_prog_config.back_element_tag_select,
2621
6.36k
      &idx_no);
2622
6.36k
}
2623
2624
IA_ERRORCODE ixheaacd_dec_execute(
2625
391k
    ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
2626
391k
  ia_adts_header_struct adts = {0};
2627
391k
  ia_aac_dec_state_struct *p_state_enhaacplus_dec;
2628
2629
391k
  UWORD8 *in_buffer;
2630
391k
  WORD16 *time_data;
2631
391k
  WORD16 num_of_out_samples = 0;
2632
391k
  WORD16 frame_size = 0;
2633
391k
  WORD32 sample_rate_dec = 0;
2634
391k
  WORD32 sample_rate = 0;
2635
391k
  WORD16 num_ch = 0;
2636
391k
  struct ia_bit_buf_struct *it_bit_buff;
2637
391k
  UWORD8 *mps_buffer;
2638
391k
  WORD32 error_code = IA_NO_ERROR;
2639
391k
  WORD ch_idx1;
2640
391k
  WORD type;
2641
391k
  WORD total_channels = 0;
2642
391k
  WORD total_elements = 0;
2643
391k
  WORD16 *actual_out_buffer = NULL;
2644
391k
  WORD ps_enable;
2645
391k
  WORD esbr_mono_downmix = 0;
2646
391k
  WORD8 element_used[MAX_BS_ELEMENT];
2647
391k
  WORD32 channel_coupling_flag = 0;
2648
2649
391k
  SIZE_T bytes_for_sync;
2650
391k
  WORD32 audio_mux_length_bytes_last = 0;
2651
391k
  WORD32 ret_val;
2652
391k
  WORD32 mps_out_samples;
2653
2654
391k
  p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0;
2655
391k
  p_obj_exhaacplus_dec->aac_config.frame_status = 1;
2656
2657
391k
  if (p_obj_exhaacplus_dec->p_state_aac != NULL) {
2658
391k
    ret_val = setjmp(p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf);
2659
391k
    if (ret_val != 0) {
2660
4.04k
      p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
2661
4.04k
          p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
2662
4.04k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
2663
4.04k
      p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2664
4.04k
      return IA_NO_ERROR;
2665
4.04k
    }
2666
391k
  }
2667
2668
387k
  time_data = (WORD16 *)(p_obj_exhaacplus_dec
2669
387k
                             ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]);
2670
387k
  in_buffer = p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX];
2671
387k
  p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac;
2672
387k
  p_state_enhaacplus_dec->aac_scratch_mem_v =
2673
387k
      p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX];
2674
387k
  p_state_enhaacplus_dec->mps_header = -1;
2675
387k
  mps_buffer = p_state_enhaacplus_dec->mps_buffer;
2676
387k
  it_bit_buff = p_state_enhaacplus_dec->pstr_bit_buf;
2677
2678
387k
  ch_idx1 = 0;
2679
387k
  p_state_enhaacplus_dec->i_bytes_consumed = 0;
2680
2681
387k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_USAC) {
2682
186k
    WORD32 pcm_size = p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz;
2683
186k
    WORD8 *inbuffer = (WORD8 *)(p_obj_exhaacplus_dec
2684
186k
                                    ->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]);
2685
186k
    WORD8 *outbuffer =
2686
186k
        (WORD8 *)(p_obj_exhaacplus_dec
2687
186k
                      ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]);
2688
186k
    WORD32 out_bytes = 0;
2689
2690
186k
    WORD32 frames_done = p_obj_exhaacplus_dec->p_state_aac->frame_counter;
2691
2692
186k
    ia_dec_data_struct *pstr_dec_data =
2693
186k
        (ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac
2694
186k
                                   ->pstr_dec_data);
2695
2696
186k
    if (pstr_dec_data->str_usac_data.down_samp_sbr != 0) return IA_FATAL_ERROR;
2697
2698
186k
    if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 0) {
2699
186k
      ia_audio_specific_config_struct *ptr_audio_specific_config =
2700
186k
          ((ia_audio_specific_config_struct *)
2701
186k
               p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
2702
2703
186k
      ptr_audio_specific_config->str_usac_config.str_usac_dec_config
2704
186k
          .preroll_counter = 0;
2705
186k
      {
2706
186k
        WORD32 iii = 0;
2707
930k
        for (iii = 0; iii < (MAX_AUDIO_PREROLLS + 1); iii++) {
2708
744k
          ((ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac
2709
744k
                                      ->pstr_dec_data))
2710
744k
              ->str_frame_data.str_audio_specific_config.str_usac_config
2711
744k
              .str_usac_dec_config.usac_ext_gain_payload_len[iii] = 0;
2712
744k
          ptr_audio_specific_config->str_usac_config.str_usac_dec_config
2713
744k
              .usac_ext_gain_payload_len[iii] =
2714
744k
              0;  // reinitilize the payload len buff
2715
744k
          ptr_audio_specific_config->str_usac_config.str_usac_dec_config
2716
744k
              .preroll_bytes[iii] = 0;
2717
744k
        }
2718
186k
      }
2719
2720
186k
      ((ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data))
2721
186k
          ->str_frame_data.str_audio_specific_config.str_usac_config
2722
186k
          .str_usac_dec_config.preroll_counter = 0;
2723
186k
      error_code = ixheaacd_dec_main(
2724
186k
          p_obj_exhaacplus_dec, inbuffer, outbuffer, &out_bytes, frames_done,
2725
186k
          pcm_size, &p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch);
2726
186k
      if (error_code) {
2727
1.29k
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2728
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2729
1.29k
        } else {
2730
1.29k
          return error_code;
2731
1.29k
        }
2732
1.29k
      }
2733
184k
      p_obj_exhaacplus_dec->p_state_aac->frame_counter++;
2734
184k
    } else {
2735
0
      out_bytes = 0;
2736
0
    }
2737
2738
184k
    if (pstr_dec_data->str_usac_data.ec_flag == 0) {
2739
182k
      if (p_state_enhaacplus_dec->bs_format != LOAS_BSFORMAT) {
2740
1.29k
        p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
2741
1.29k
            p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
2742
1.29k
      }
2743
182k
    } else {
2744
2.10k
      if (p_state_enhaacplus_dec->bs_format != LOAS_BSFORMAT) {
2745
0
        if (pstr_dec_data->str_usac_data.frame_ok == 0) {
2746
0
          p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
2747
0
              p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
2748
0
          pstr_dec_data->dec_bit_buf.cnt_bits = 0;
2749
0
        } else {
2750
0
          ia_dec_data_struct *pstr_dec_data =
2751
0
              (ia_dec_data_struct *)p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data;
2752
2753
0
          if (pstr_dec_data->dec_bit_buf.cnt_bits & 7) {
2754
0
            pstr_dec_data->dec_bit_buf.cnt_bits -= (pstr_dec_data->dec_bit_buf.cnt_bits & 7);
2755
0
          }
2756
0
          if (pstr_dec_data->dec_bit_buf.cnt_bits == 0) {
2757
0
            p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
2758
0
                p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
2759
0
          } else {
2760
0
            p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
2761
0
                p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes -
2762
0
                (pstr_dec_data->dec_bit_buf.cnt_bits >> 3);
2763
0
          }
2764
0
        }
2765
0
      }
2766
2.10k
    }
2767
2768
184k
    p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = out_bytes;
2769
184k
    p_obj_exhaacplus_dec->aac_config.ui_n_channels =
2770
184k
        p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch;
2771
184k
    pstr_dec_data->str_usac_data.sbr_parse_err_flag = 0;
2772
2773
184k
    return 0;
2774
186k
  }
2775
2776
425k
  while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] <= 3 &&
2777
429k
         p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] >= 0) {
2778
224k
    if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 0 ||
2779
180k
        p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 3) {
2780
180k
      total_channels += 1;
2781
180k
      total_elements += 1;
2782
180k
    }
2783
224k
    if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 1) {
2784
43.1k
      total_elements += 1;
2785
43.1k
      total_channels += 2;
2786
43.1k
    }
2787
224k
    if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 2) {
2788
1.01k
      total_elements += 1;
2789
1.01k
    }
2790
2791
224k
    ch_idx1++;
2792
224k
    if (ch_idx1 > MAX_BS_ELEMENT) {
2793
0
      if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal)
2794
0
        break;
2795
0
      else
2796
0
        return IA_FATAL_ERROR;
2797
0
    }
2798
224k
  }
2799
2800
201k
  if (ch_idx1 != 1) {
2801
12.6k
    ps_enable = 0;
2802
12.6k
    if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
2803
12.6k
      WORD32 scratch_pointer;
2804
2805
12.6k
      scratch_pointer = (MAX_SCR_SIZE - SCR_INTER_SCR_SIZE);
2806
2807
12.6k
      p_state_enhaacplus_dec->coup_ch_output =
2808
12.6k
          (WORD32 *)((WORD8 *)
2809
12.6k
                         p_obj_exhaacplus_dec->p_state_aac->aac_scratch_mem_v +
2810
12.6k
                     scratch_pointer);
2811
12.6k
    }
2812
2813
12.6k
  }
2814
2815
188k
  else {
2816
188k
    if (total_channels < (WORD)p_obj_exhaacplus_dec->aac_config.ui_n_channels)
2817
16.8k
      total_channels = p_obj_exhaacplus_dec->aac_config.ui_n_channels;
2818
188k
    ps_enable = 1;
2819
188k
  }
2820
2821
201k
  p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
2822
201k
  p_obj_exhaacplus_dec->p_state_aac->ui_mps_out_bytes = 0;
2823
201k
  if (p_state_enhaacplus_dec->ui_in_bytes == 0) {
2824
0
    UWORD32 i;
2825
0
    WORD32 j;
2826
0
    if (p_state_enhaacplus_dec->peak_lim_init == 1) {
2827
0
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes =
2828
0
          (p_state_enhaacplus_dec->peak_limiter.attack_time_samples) *
2829
0
          total_channels * sizeof(WORD16);
2830
2831
0
      for (j = 0; j < total_channels; j++) {
2832
0
        for (i = 0;
2833
0
             i < (p_state_enhaacplus_dec->peak_limiter.attack_time_samples -
2834
0
                  p_state_enhaacplus_dec->peak_limiter.delayed_input_index);
2835
0
             i++) {
2836
0
          *(time_data + total_channels * i + j) = ixheaac_round16(
2837
0
              (WORD32)*(p_state_enhaacplus_dec->peak_limiter.delayed_input +
2838
0
                (p_state_enhaacplus_dec->peak_limiter.delayed_input_index) *
2839
0
                    total_channels +
2840
0
                total_channels * i + j));
2841
0
        }
2842
0
      }
2843
2844
0
      for (j = 0; j < total_channels; j++) {
2845
0
        for (i = 0;
2846
0
             i < p_state_enhaacplus_dec->peak_limiter.delayed_input_index;
2847
0
             i++) {
2848
0
          *(time_data +
2849
0
            (p_state_enhaacplus_dec->peak_limiter.attack_time_samples -
2850
0
             p_state_enhaacplus_dec->peak_limiter.delayed_input_index) *
2851
0
                total_channels +
2852
0
            total_channels * i + j) =
2853
0
              ixheaac_round16(
2854
0
                  (WORD32)*(p_state_enhaacplus_dec->peak_limiter.delayed_input +
2855
0
                   total_channels * i + j));
2856
0
        }
2857
0
      }
2858
2859
0
      if (p_obj_exhaacplus_dec->aac_config.dup_stereo_flag) {
2860
0
        for (i = 0;
2861
0
             i < (p_state_enhaacplus_dec->peak_limiter.attack_time_samples);
2862
0
             i++) {
2863
0
          time_data[2 * i + 1] = time_data[2 * i + 0];
2864
0
        }
2865
0
      }
2866
0
    } else {
2867
0
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
2868
0
    }
2869
2870
0
    p_state_enhaacplus_dec->i_bytes_consumed = 0;
2871
0
    return IA_NO_ERROR;
2872
0
  }
2873
2874
201k
  if (ch_idx1 == 0) {
2875
0
    p_state_enhaacplus_dec->i_bytes_consumed = 1;
2876
0
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2877
0
      p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2878
0
    } else {
2879
0
      return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR;
2880
0
    }
2881
0
  }
2882
201k
  if (total_channels > (WORD)p_obj_exhaacplus_dec->aac_config.ui_max_channels) {
2883
77
    p_state_enhaacplus_dec->i_bytes_consumed = 1;
2884
77
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2885
0
      p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2886
77
    } else {
2887
77
      return IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MAX_CHANNEL;
2888
77
    }
2889
77
  }
2890
2891
201k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
2892
138k
      p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) {
2893
122k
    if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag)
2894
568
      p_state_enhaacplus_dec->frame_size = p_state_enhaacplus_dec->ui_in_bytes;
2895
122k
  }
2896
2897
201k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) {
2898
39.2k
    if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag)
2899
66
      p_state_enhaacplus_dec->frame_size = 1024;
2900
39.2k
  }
2901
2902
201k
  {
2903
201k
    ixheaacd_create_init_bit_buf(it_bit_buff, in_buffer,
2904
201k
                                 p_state_enhaacplus_dec->ui_in_bytes);
2905
201k
    it_bit_buff->xaac_jmp_buf = &(p_state_enhaacplus_dec->xaac_jmp_buf);
2906
2907
201k
    it_bit_buff->adts_header_present =
2908
201k
        p_state_enhaacplus_dec->s_adts_hdr_present;
2909
201k
    it_bit_buff->no_raw_data_blocks =
2910
201k
        (WORD8)p_state_enhaacplus_dec->b_n_raw_data_blk;
2911
201k
    it_bit_buff->protection_absent = p_state_enhaacplus_dec->protection_absent;
2912
2913
201k
    if (p_state_enhaacplus_dec->s_adts_hdr_present) {
2914
31.5k
      if (p_state_enhaacplus_dec->b_n_raw_data_blk == 0) {
2915
29.8k
        WORD32 error;
2916
2917
29.8k
        error = ixheaacd_readifadts(p_state_enhaacplus_dec, it_bit_buff, &adts);
2918
29.8k
        if (error) {
2919
1.01k
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2920
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2921
0
            if (adts.samp_freq_index > 11) {
2922
0
              adts.samp_freq_index = 11;
2923
0
            }
2924
1.01k
          } else {
2925
1.01k
            return error;
2926
1.01k
          }
2927
1.01k
        }
2928
2929
28.7k
        if ((WORD32)p_state_enhaacplus_dec->sampling_rate !=
2930
28.7k
            (WORD32)((p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables
2931
28.7k
                          ->str_sample_rate_info[adts.samp_freq_index]
2932
28.7k
                          .sampling_frequency))) {
2933
16
          p_state_enhaacplus_dec->i_bytes_consumed = 0;
2934
16
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2935
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2936
16
          } else {
2937
16
            return IA_XHEAAC_DEC_EXE_NONFATAL_CHANGED_ADTS_SF;
2938
16
          }
2939
16
        }
2940
28.7k
      }
2941
31.5k
    }
2942
2943
200k
    bytes_for_sync = (SIZE_T)it_bit_buff->ptr_read_next;
2944
2945
200k
    if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
2946
172k
      WORD32 result, audio_mux_len_bytes_last;
2947
172k
      WORD32 cnt_bits = it_bit_buff->cnt_bits;
2948
172k
      WORD32 sync = ixheaacd_read_bits_buf(it_bit_buff, 11);
2949
172k
      UWORD32 curr_samp_rate = 0;
2950
2951
172k
      if (p_state_enhaacplus_dec->latm_initialized)
2952
168k
        curr_samp_rate =
2953
168k
            p_state_enhaacplus_dec->latm_struct_element.layer_info[0][0]
2954
168k
                .asc.sampling_freq;
2955
2956
122M
      while (sync != 0x2b7) {
2957
122M
        sync = ((sync & 0x3ff) << 1) | ixheaacd_read_bits_buf(it_bit_buff, 1);
2958
122M
        if (it_bit_buff->cnt_bits < 13) {
2959
1.22k
          ixheaacd_read_bidirection(it_bit_buff, -11);
2960
1.22k
          p_state_enhaacplus_dec->i_bytes_consumed =
2961
1.22k
              (cnt_bits - it_bit_buff->cnt_bits) / 8;
2962
2963
1.22k
          if (p_state_enhaacplus_dec->i_bytes_consumed == 0)
2964
25
            p_state_enhaacplus_dec->i_bytes_consumed = 1;
2965
1.22k
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2966
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2967
1.22k
          } else {
2968
1.22k
            return (IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START);
2969
1.22k
          }
2970
1.22k
        }
2971
122M
      }
2972
2973
171k
      it_bit_buff->audio_mux_align = it_bit_buff->cnt_bits - 13;
2974
2975
171k
      audio_mux_len_bytes_last = ixheaacd_read_bits_buf(it_bit_buff, 13);
2976
2977
171k
      audio_mux_length_bytes_last = audio_mux_len_bytes_last;
2978
2979
171k
      bytes_for_sync = (SIZE_T)it_bit_buff->ptr_read_next - bytes_for_sync;
2980
2981
171k
      if (it_bit_buff->cnt_bits < (audio_mux_len_bytes_last << 3)) {
2982
743
        ixheaacd_read_bidirection(it_bit_buff, -(13 + 11));
2983
743
        p_state_enhaacplus_dec->i_bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8;
2984
743
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2985
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2986
743
        } else {
2987
743
          return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
2988
743
        }
2989
170k
      } else {
2990
170k
        ixheaacd_read_bidirection(it_bit_buff, -(13));
2991
170k
      }
2992
2993
170k
      if (sync == 0x2b7) {
2994
170k
        result = ixheaacd_latm_audio_mux_element(
2995
170k
            it_bit_buff, &p_state_enhaacplus_dec->latm_struct_element,
2996
170k
            p_state_enhaacplus_dec,
2997
170k
            (ia_sampling_rate_info_struct *)&p_obj_exhaacplus_dec->aac_tables
2998
170k
                .pstr_huffmann_tables->str_sample_rate_info[0]);
2999
170k
        if (result < 0) {
3000
442
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3001
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3002
442
          } else {
3003
442
            return result;
3004
442
          }
3005
442
        }
3006
169k
        if (!p_state_enhaacplus_dec->latm_initialized) {
3007
4.16k
          p_state_enhaacplus_dec->sampling_rate =
3008
4.16k
              p_state_enhaacplus_dec->latm_struct_element.layer_info[0][0].asc.sampling_freq;
3009
4.16k
          p_state_enhaacplus_dec->latm_initialized = 1;
3010
165k
        } else {
3011
165k
          if (p_state_enhaacplus_dec->sampling_rate != curr_samp_rate) {
3012
71
            p_state_enhaacplus_dec->i_bytes_consumed = 0;
3013
71
            if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3014
0
              p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3015
71
            } else {
3016
71
              return IA_XHEAAC_DEC_EXE_NONFATAL_CHANGED_ADTS_SF;
3017
71
            }
3018
71
          }
3019
165k
        }
3020
169k
      }
3021
170k
    }
3022
200k
  }
3023
3024
197k
  if (total_elements == 2 && total_channels == 2 &&
3025
9.19k
      (p_state_enhaacplus_dec->p_config->ui_pce_found_in_hdr == 1 ||
3026
6.05k
       p_state_enhaacplus_dec->p_config->ui_pce_found_in_hdr == 3)) {
3027
6.05k
    ixheaacd_fill_prog_config_slots(p_state_enhaacplus_dec);
3028
6.05k
  }
3029
3030
197k
  memset(element_used, 0, sizeof(WORD8) * MAX_BS_ELEMENT);
3031
3032
197k
  if (it_bit_buff->cnt_bits <= 0) {
3033
12
    it_bit_buff->cnt_bits = -1;
3034
12
    ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
3035
12
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3036
0
      p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3037
12
    } else {
3038
12
      return (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
3039
12
    }
3040
12
  }
3041
3042
197k
  { it_bit_buff->initial_cnt_bits = it_bit_buff->cnt_bits; }
3043
3044
197k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD) {
3045
65.6k
    if (p_state_enhaacplus_dec->s_adts_hdr_present)
3046
0
      p_state_enhaacplus_dec->frame_size = adts.aac_frame_length;
3047
65.6k
  }
3048
3049
197k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) {
3050
38.7k
    if (p_state_enhaacplus_dec->s_adts_hdr_present)
3051
0
      p_state_enhaacplus_dec->frame_size = 1024;
3052
38.7k
  }
3053
3054
201k
  if (p_state_enhaacplus_dec->pstr_drc_dec) {
3055
201k
    p_state_enhaacplus_dec->pstr_drc_dec->num_drc_elements = 0;
3056
3057
201k
    p_state_enhaacplus_dec->pstr_drc_dec->state = 1;
3058
201k
  }
3059
197k
  if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3060
0
    if (total_elements > MAX_BS_ELEMENT) {
3061
0
      total_elements = MAX_BS_ELEMENT;
3062
0
    }
3063
0
  }
3064
3065
197k
  WORD16 *intermediate_scr = (WORD16 *)(WORD8 *)p_state_enhaacplus_dec->aac_scratch_mem_v +
3066
197k
                             (MAX_SCR_SIZE - SCR_INTER_SCR_SIZE - SCR_COUP_CH_OUT_SIZE);
3067
3068
406k
  for (ch_idx1 = 0; ch_idx1 < total_elements; ch_idx1++) {
3069
215k
    WORD32 skip_full_decode = 0;
3070
215k
    WORD32 ch_idx = ch_idx1;
3071
215k
    WORD32 channel = 0;
3072
215k
    WORD ch_fac, slot_ele;
3073
3074
215k
    if (p_state_enhaacplus_dec->audio_object_type < ER_OBJECT_START ||
3075
159k
        (p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LD &&
3076
93.7k
         p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_ELD &&
3077
56.3k
         p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LC)) {
3078
56.3k
      jmp_buf local;
3079
3080
56.3k
      if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal == 1) {
3081
0
        ret_val = setjmp(local);
3082
0
      }
3083
56.3k
      if (ret_val == 0) {
3084
56.3k
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal == 1) {
3085
0
          p_obj_exhaacplus_dec->p_state_aac->ptr_bit_stream->xaac_jmp_buf = &local;
3086
0
        }
3087
56.3k
        error_code = ixheaacd_get_element_index_tag(
3088
56.3k
            p_obj_exhaacplus_dec, ch_idx1, &ch_idx, &channel,
3089
56.3k
            p_obj_exhaacplus_dec->aac_config.element_instance_order, total_elements, element_used,
3090
56.3k
            total_channels, p_state_enhaacplus_dec->pstr_drc_dec,
3091
56.3k
            &p_state_enhaacplus_dec->drc_dummy, mps_buffer, &p_state_enhaacplus_dec->mps_header,
3092
56.3k
            &p_state_enhaacplus_dec->ui_mps_out_bytes);
3093
56.3k
      }
3094
3095
56.3k
      if (error_code || ret_val) {
3096
2.38k
        ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
3097
2.38k
        if (it_bit_buff->cnt_bits < 0) {
3098
10
          p_state_enhaacplus_dec->ui_out_bytes = 0;
3099
10
          p_state_enhaacplus_dec->ui_mps_out_bytes = 0;
3100
10
          p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
3101
10
        }
3102
2.38k
        p_state_enhaacplus_dec->i_bytes_consumed = 1;
3103
2.38k
        p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
3104
2.38k
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3105
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3106
2.38k
        } else {
3107
2.38k
          return error_code;
3108
2.38k
        }
3109
2.38k
      }
3110
53.9k
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == ID_CPE)
3111
1.14k
      {
3112
1.14k
        if (channel != 2)
3113
0
        {
3114
0
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal)
3115
0
          {
3116
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3117
0
            channel = 2;
3118
0
          }
3119
0
          else
3120
0
          {
3121
0
            return IA_FATAL_ERROR;
3122
0
          }
3123
0
        }
3124
1.14k
      }
3125
52.8k
      else
3126
52.8k
      {
3127
52.8k
        if (channel != 1)
3128
0
        {
3129
0
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal)
3130
0
          {
3131
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3132
0
            channel = 1;
3133
0
          }
3134
0
          else
3135
0
          {
3136
0
            return IA_FATAL_ERROR;
3137
0
          }
3138
0
        }
3139
52.8k
      }
3140
159k
    } else {
3141
159k
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == ID_SCE)
3142
119k
        channel = 1;
3143
39.8k
      else
3144
39.8k
        channel = 2;
3145
159k
    }
3146
3147
213k
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && (error_code || ret_val)) {
3148
0
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 0 ||
3149
0
          p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 3) {
3150
0
        if (channel > 1) {
3151
0
          channel = 1;
3152
0
        }
3153
0
      }
3154
0
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 1) {
3155
0
        if (channel > 2) {
3156
0
          channel = 2;
3157
0
        }
3158
0
      }
3159
0
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 2) {
3160
0
        if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
3161
0
          if (!(p_obj_exhaacplus_dec->aac_config.element_instance_order[ch_idx] !=
3162
0
                p_obj_exhaacplus_dec->aac_config.ui_coupling_channel)) {
3163
0
            if (channel > 1) {
3164
0
              channel = 1;
3165
0
            }
3166
0
          }
3167
0
        }
3168
0
      }
3169
0
      if (ps_enable == 1) {
3170
0
        if (channel > 2) {
3171
0
          channel = 2;
3172
0
        }
3173
0
      }
3174
0
    }
3175
3176
213k
    ch_fac = total_channels;
3177
213k
    slot_ele = p_obj_exhaacplus_dec->aac_config.slot_element[ch_idx];
3178
213k
    actual_out_buffer = time_data;
3179
213k
    if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 2) {
3180
487
      p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info =
3181
487
          &p_state_enhaacplus_dec->ind_cc_info;
3182
487
      if (p_obj_exhaacplus_dec->aac_config.element_instance_order[ch_idx] !=
3183
487
          p_obj_exhaacplus_dec->aac_config.ui_coupling_channel) {
3184
154
        skip_full_decode = 1;
3185
154
        ixheaacd_set_aac_persistent_buffers(
3186
154
            p_state_enhaacplus_dec->pers_mem_ptr, channel);
3187
3188
154
        {
3189
154
          struct ia_aac_persistent_struct *aac_persistent_mem =
3190
154
              (struct ia_aac_persistent_struct *)
3191
154
                  p_state_enhaacplus_dec->pers_mem_ptr;
3192
154
          aac_persistent_mem->str_aac_decoder.pstr_aac_tables =
3193
154
              &p_obj_exhaacplus_dec->aac_tables;
3194
154
          aac_persistent_mem->str_aac_decoder.pstr_common_tables =
3195
154
              p_obj_exhaacplus_dec->common_tables;
3196
154
        }
3197
3198
154
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] = 0;
3199
3200
154
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0;
3201
3202
154
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] =
3203
154
            ixheaacd_aac_decoder_init(
3204
154
                p_state_enhaacplus_dec,
3205
3206
154
                p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx],
3207
3208
154
                channel, p_state_enhaacplus_dec->pers_mem_ptr,
3209
154
                p_state_enhaacplus_dec->frame_length
3210
3211
154
                );
3212
154
        if (!p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]) {
3213
0
          p_state_enhaacplus_dec->i_bytes_consumed = 1;
3214
0
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3215
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3216
0
          } else {
3217
0
            return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL;
3218
0
          }
3219
0
        }
3220
154
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info =
3221
154
            (WORD8 *)p_state_enhaacplus_dec->aac_scratch_mem_v + (P_IND_CH_INFO_OFFSET);
3222
154
      }
3223
487
      if (p_obj_exhaacplus_dec->aac_config.element_type[1] < 3 &&
3224
462
          p_obj_exhaacplus_dec->aac_config.element_type[1] > 0 &&
3225
116
          p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
3226
116
        actual_out_buffer =
3227
116
            (WORD16 *)(VOID *)p_state_enhaacplus_dec->coup_ch_output;
3228
116
      }
3229
487
      ch_fac = 1;
3230
487
      slot_ele = 0;
3231
487
    }
3232
3233
213k
    type = -1;
3234
213k
    p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements = 0;
3235
3236
213k
    {
3237
213k
      WORD element_index_order1[MAX_BS_ELEMENT];
3238
213k
      ia_aac_dec_scratch_struct aac_scratch_struct;
3239
213k
      memset(&aac_scratch_struct, 0, sizeof(aac_scratch_struct));
3240
3241
213k
      ixheaacd_allocate_aac_scr(
3242
213k
          &aac_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v,
3243
213k
          time_data, channel, p_obj_exhaacplus_dec->aac_config.ui_max_channels,
3244
213k
          p_state_enhaacplus_dec->audio_object_type);
3245
3246
213k
      if (p_state_enhaacplus_dec->ch_config == 2 && channel == 1) {
3247
81
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3248
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3249
81
        } else {
3250
81
          return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR;
3251
81
        }
3252
81
      }
3253
3254
213k
      error_code = ixheaacd_aacdec_decodeframe(
3255
213k
          p_obj_exhaacplus_dec, &aac_scratch_struct, actual_out_buffer,
3256
213k
          p_obj_exhaacplus_dec->aac_config.frame_status, &type, &ch_idx, 0, channel,
3257
213k
          element_index_order1, skip_full_decode, ch_fac, slot_ele,
3258
213k
          p_obj_exhaacplus_dec->aac_config.ui_max_channels, total_channels,
3259
213k
          p_obj_exhaacplus_dec->p_state_aac->frame_length,
3260
213k
          p_obj_exhaacplus_dec->p_state_aac->frame_size, p_state_enhaacplus_dec->pstr_drc_dec,
3261
213k
          p_state_enhaacplus_dec->audio_object_type, p_state_enhaacplus_dec->ch_config,
3262
213k
          p_state_enhaacplus_dec->eld_specific_config, p_state_enhaacplus_dec->s_adts_hdr_present,
3263
213k
          &p_state_enhaacplus_dec->drc_dummy, p_state_enhaacplus_dec->ldmps_present,
3264
213k
          &p_state_enhaacplus_dec->slot_pos, mps_buffer, &p_state_enhaacplus_dec->mps_header,
3265
213k
          &p_state_enhaacplus_dec->ui_mps_out_bytes, 0,
3266
213k
          p_obj_exhaacplus_dec->aac_config.first_frame);
3267
3268
213k
      p_state_enhaacplus_dec->slot_pos -= (channel - 1);
3269
213k
      p_state_enhaacplus_dec->sbr_present = 0;
3270
3271
213k
      if (p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ &&
3272
160k
          p_state_enhaacplus_dec->frame_counter == 0) {
3273
7.51k
        ixheaacd_peak_limiter_init(
3274
7.51k
            &p_state_enhaacplus_dec->peak_limiter, total_channels,
3275
7.51k
            p_obj_exhaacplus_dec->p_state_aac->p_config->ui_samp_freq,
3276
7.51k
            &p_state_enhaacplus_dec->peak_limiter.buffer[0],
3277
7.51k
            &p_obj_exhaacplus_dec->p_state_aac->delay_in_samples);
3278
7.51k
        p_obj_exhaacplus_dec->p_state_aac->peak_lim_init = 1;
3279
7.51k
      }
3280
3281
213k
      if (p_state_enhaacplus_dec->audio_object_type < ER_OBJECT_START ||
3282
158k
          (p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LD &&
3283
93.3k
           p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_ELD &&
3284
53.5k
           p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LC)) {
3285
53.5k
        if ((error_code == 0) && ((ch_idx1 + 1) == total_elements) &&
3286
38.8k
            (type != ID_END)) {
3287
801
          {
3288
801
            p_state_enhaacplus_dec->i_bytes_consumed = (WORD32)(
3289
801
                it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base);
3290
801
            p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
3291
801
            if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3292
0
              p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3293
801
            } else {
3294
801
            return IA_XHEAAC_DEC_EXE_NONFATAL_ELE_INSTANCE_TAG_NOT_FOUND;
3295
801
          }
3296
801
          }
3297
801
        }
3298
53.5k
      }
3299
3300
212k
      num_ch = p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->channels;
3301
212k
      if (skip_full_decode == 0) {
3302
211k
        if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD ||
3303
156k
            p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD)
3304
120k
          frame_size = p_state_enhaacplus_dec->frame_length;
3305
91.0k
        else {
3306
91.0k
          frame_size = p_state_enhaacplus_dec->frame_length;
3307
91.0k
        }
3308
3309
211k
        sample_rate_dec =
3310
211k
            p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->sampling_rate;
3311
211k
      }
3312
212k
    }
3313
3314
212k
    if (skip_full_decode == 1) {
3315
140
      p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements = 0;
3316
140
    }
3317
3318
212k
    if (p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements != 0) {
3319
39.9k
      p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 1;
3320
39.9k
    }
3321
3322
212k
    if (error_code) {
3323
3.01k
      if (p_state_enhaacplus_dec->ui_input_over) {
3324
0
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3325
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3326
0
        } else {
3327
0
          return IA_XHEAAC_DEC_INIT_FATAL_EO_INPUT_REACHED;
3328
0
        }
3329
0
      }
3330
3.01k
      ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
3331
3.01k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes +=
3332
3.01k
          p_state_enhaacplus_dec->num_of_out_samples * num_ch * sizeof(WORD16);
3333
3.01k
      if (error_code) {
3334
3.01k
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3335
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3336
3.01k
        } else {
3337
3.01k
          return error_code;
3338
3.01k
        }
3339
3.01k
      }
3340
3.01k
    }
3341
3342
209k
    error_code = IA_NO_ERROR;
3343
3344
209k
    if (p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample == 0) {
3345
0
      if (p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements == 0 &&
3346
0
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
3347
0
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0;
3348
0
        error_code = IA_XHEAAC_DEC_EXE_NONFATAL_SBR_TURNED_OFF;
3349
0
      }
3350
0
    }
3351
209k
    if ((!p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) &&
3352
1.18k
        p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements) {
3353
31
      WORD32 harmonic_sbr_flag = 0;
3354
31
      error_code = IA_XHEAAC_DEC_EXE_NONFATAL_SBR_TURNED_ON;
3355
31
      p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr(
3356
31
          sample_rate_dec, frame_size,
3357
31
          (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag,
3358
31
          p_state_enhaacplus_dec->sbr_persistent_mem_v,
3359
31
          p_state_enhaacplus_dec->ptr_overlap_buf, ps_enable ? 2 : channel,
3360
31
          ps_enable, 1, frame_size * 2, &harmonic_sbr_flag, NULL,
3361
31
          p_state_enhaacplus_dec->str_sbr_config,
3362
31
          p_state_enhaacplus_dec->audio_object_type,
3363
31
          p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
3364
31
              .ldmps_present_flag,
3365
31
          p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present);
3366
31
      if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
3367
1
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
3368
1
            &(p_state_enhaacplus_dec->xaac_jmp_buf);
3369
1
      }
3370
31
    }
3371
3372
209k
    {
3373
209k
      if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] &&
3374
207k
          p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
3375
39.6k
        ia_sbr_scr_struct sbr_scratch_struct;
3376
39.6k
        ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v,
3377
39.6k
                                  time_data, total_channels,
3378
39.6k
                                  p_obj_exhaacplus_dec->p_state_aac->qshift_adj,
3379
39.6k
                                  p_state_enhaacplus_dec->slot_pos, channel);
3380
3381
39.6k
        p_state_enhaacplus_dec->sbr_present = 1;
3382
39.6k
        p_state_enhaacplus_dec->peak_lim_init = 0;
3383
3384
39.6k
        if (p_obj_exhaacplus_dec->aac_config.ui_enh_sbr)
3385
39.6k
        {
3386
39.6k
          WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type;
3387
3388
39.6k
          if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) {
3389
14.4k
            WORD32 i = 0;
3390
14.4k
            ia_dec_data_struct* pstr_dec_data =
3391
14.4k
                (ia_dec_data_struct*)p_state_enhaacplus_dec->pstr_dec_data;
3392
14.4k
            if (ch_fac == 1) {
3393
2.04M
              for (; i < 1024; i++) {
3394
2.04M
                pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
3395
2.04M
                    (FLOAT32)time_data[i];
3396
2.04M
              }
3397
1.99k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
3398
1.99k
                  &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
3399
3400
1.99k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
3401
1.99k
                  &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
3402
12.4k
            } else if (ch_fac == 2) {
3403
12.6M
              for (; i < 1024; i++) {
3404
12.6M
                pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
3405
12.6M
                    (FLOAT32)time_data[2 * i + 0];
3406
12.6M
                pstr_dec_data->str_usac_data.time_sample_vector[1][i] =
3407
12.6M
                    (FLOAT32)time_data[2 * i + 1];
3408
12.6M
              }
3409
12.3k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
3410
12.3k
                  &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
3411
3412
12.3k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
3413
12.3k
                  &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
3414
12.3k
            } else if (ch_fac > 2) {
3415
104
              if (channel == 1) {
3416
74.8k
                for (; i < 1024; i++) {
3417
74.7k
                  pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
3418
74.7k
                      (FLOAT32)(time_data + slot_ele)[i* ch_fac];
3419
74.7k
                }
3420
73
                p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
3421
73
                    &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
3422
73
              } else if (channel == 2) {
3423
31.7k
                for (; i < 1024; i++) {
3424
31.7k
                  pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
3425
31.7k
                      (FLOAT32)(time_data + slot_ele)[ch_fac * i + 0];
3426
31.7k
                  pstr_dec_data->str_usac_data.time_sample_vector[1][i] =
3427
31.7k
                      (FLOAT32)(time_data + slot_ele)[ch_fac * i + 1];
3428
31.7k
                }
3429
31
                p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
3430
31
                    &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
3431
3432
31
                p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
3433
31
                    &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
3434
31
              }
3435
104
            }
3436
14.4k
          }
3437
39.6k
        }
3438
39.6k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->esbr_hq =
3439
39.6k
            p_obj_exhaacplus_dec->aac_config.ui_hq_esbr;
3440
39.6k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr =
3441
39.6k
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr;
3442
39.6k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr_ps =
3443
39.6k
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps;
3444
3445
39.6k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
3446
39.6k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
3447
39.6k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
3448
39.6k
        }
3449
3450
39.6k
        if (ixheaacd_applysbr(p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx],
3451
39.6k
                              &p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0],
3452
39.6k
                              actual_out_buffer, &num_ch,
3453
39.6k
                              p_obj_exhaacplus_dec->aac_config.frame_status,
3454
39.6k
                              p_obj_exhaacplus_dec->aac_config.down_sample_flag,
3455
39.6k
                              esbr_mono_downmix, &sbr_scratch_struct, ps_enable, ch_fac, slot_ele,
3456
39.6k
                              NULL, &p_state_enhaacplus_dec->str_drc_dec_info,
3457
39.6k
                              p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present,
3458
39.6k
                              p_state_enhaacplus_dec->audio_object_type, 0,
3459
39.6k
                              p_state_enhaacplus_dec->ldmps_present, frame_size,
3460
39.6k
                              p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present,
3461
39.6k
                              p_obj_exhaacplus_dec->aac_config.ui_err_conceal,
3462
39.6k
                              p_obj_exhaacplus_dec->aac_config.first_frame) != SBRDEC_OK) {
3463
204
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0;
3464
204
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3465
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3466
204
          } else {
3467
204
            return -1;
3468
204
          }
3469
39.4k
        } else {
3470
39.4k
          if (!p_obj_exhaacplus_dec->aac_config.down_sample_flag) {
3471
22.0k
            frame_size = (WORD16)(frame_size * 2);
3472
22.0k
            sample_rate_dec *= 2;
3473
22.0k
          }
3474
39.4k
          if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
3475
39.4k
                  .ldmps_present_flag == 1) {
3476
2.13k
            ixheaacd_mps_payload(
3477
2.13k
                p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx],
3478
2.13k
                p_obj_exhaacplus_dec);
3479
2.13k
          }
3480
39.4k
        }
3481
3482
39.4k
        if (p_obj_exhaacplus_dec->aac_config.ui_enh_sbr)
3483
39.0k
        {
3484
39.0k
          WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type;
3485
3486
39.0k
          if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) {
3487
14.4k
            WORD32 out_bytes = 0;
3488
14.4k
            ia_dec_data_struct *pstr_dec_data =
3489
14.4k
                (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data;
3490
14.4k
            if (ch_fac <= 2) {
3491
14.2k
              ixheaacd_samples_sat((WORD8*)time_data, 2048, 16,
3492
14.2k
                                   pstr_dec_data->str_usac_data.time_sample_vector,
3493
14.2k
                                   &out_bytes, ch_fac);
3494
14.2k
            } else {
3495
104
              ixheaacd_samples_sat_mc((WORD8*)(time_data + slot_ele), 2048,
3496
104
                                      pstr_dec_data->str_usac_data.time_sample_vector,
3497
104
                                      &out_bytes, channel, ch_fac);
3498
104
            }
3499
14.4k
          }
3500
39.0k
        }
3501
39.4k
        p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present =
3502
39.4k
            0;
3503
39.4k
        if (p_state_enhaacplus_dec->ui_mps_out_bytes > 0) {
3504
379
          p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present = 1;
3505
379
        }
3506
169k
      } else {
3507
169k
        p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present = 1;
3508
169k
      }
3509
209k
    }
3510
3511
209k
    if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
3512
209k
                .ldmps_present_flag == 1 &&
3513
11.7k
         p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] &&
3514
11.4k
         p_state_enhaacplus_dec->mps_dec_handle.mps_init_done == 1) {
3515
2.23k
      if (p_state_enhaacplus_dec->ec_enable) {
3516
0
        if (!p_obj_exhaacplus_dec->aac_config.first_frame) {
3517
0
          error_code = ixheaacd_ld_mps_apply(p_obj_exhaacplus_dec, actual_out_buffer);
3518
0
          if (error_code) p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3519
0
        }
3520
2.23k
      } else {
3521
2.23k
        error_code = ixheaacd_ld_mps_apply(p_obj_exhaacplus_dec, actual_out_buffer);
3522
3523
2.23k
        if (error_code)
3524
62
          return error_code;
3525
2.23k
      }
3526
2.23k
    }
3527
209k
    if (sample_rate < sample_rate_dec) {
3528
194k
      sample_rate = sample_rate_dec;
3529
194k
    }
3530
3531
209k
    if (p_state_enhaacplus_dec->sbr_present ||
3532
168k
        p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] == LD_OBJ) {
3533
82.0k
      num_of_out_samples = frame_size;
3534
3535
127k
    } else {
3536
127k
      num_of_out_samples =
3537
127k
          frame_size -
3538
127k
          MIN((WORD16)p_obj_exhaacplus_dec->p_state_aac->delay_in_samples, frame_size);
3539
127k
    }
3540
3541
209k
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal &&
3542
0
        p_obj_exhaacplus_dec->aac_config.first_frame &&
3543
0
        (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_ER_AAC_ELD ||
3544
0
         p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_ER_AAC_LD)) {
3545
0
      num_of_out_samples = frame_size;
3546
0
    }
3547
3548
209k
    p_obj_exhaacplus_dec->aac_config.ui_samp_freq = sample_rate;
3549
3550
209k
    p_state_enhaacplus_dec->num_channel_last = num_ch;
3551
209k
    p_state_enhaacplus_dec->num_of_out_samples = num_of_out_samples;
3552
3553
209k
    if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
3554
209k
            .ldmps_present_flag == 1 &&
3555
11.6k
        p_state_enhaacplus_dec->mps_dec_handle.mps_init_done == 1 &&
3556
2.17k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
3557
2.17k
      if (p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.output_buffer) {
3558
2.17k
        ixheaacd_samples_sat((WORD8 *)actual_out_buffer, num_of_out_samples,
3559
2.17k
                             p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz,
3560
2.17k
                             p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.output_buffer,
3561
2.17k
                             &mps_out_samples, 2);
3562
2.17k
        p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = mps_out_samples;
3563
2.17k
      }
3564
2.17k
      num_ch = p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.out_ch_count;
3565
2.17k
      if (p_state_enhaacplus_dec->ec_enable) {
3566
0
        if (p_obj_exhaacplus_dec->aac_config.first_frame) {
3567
0
          p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes =
3568
0
              p_state_enhaacplus_dec->num_of_out_samples * num_ch * sizeof(WORD16);
3569
0
        }
3570
0
      }
3571
206k
    } else {
3572
206k
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] != 2) {
3573
205k
        if (p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1 &&
3574
12.5k
          channel == 1 && total_elements == 1 && num_ch == 1) {
3575
4.12k
        num_ch = 2;
3576
4.12k
        p_obj_exhaacplus_dec->aac_config.dup_stereo_flag = 1;
3577
3578
201k
      } else {
3579
201k
        p_obj_exhaacplus_dec->aac_config.dup_stereo_flag = 0;
3580
201k
      }
3581
3582
205k
      p_obj_exhaacplus_dec->aac_config.ui_n_channels = 2;
3583
3584
205k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes +=
3585
205k
          p_state_enhaacplus_dec->num_of_out_samples * num_ch * sizeof(WORD16);
3586
3587
205k
    } else {
3588
1.71k
      channel_coupling_flag = 1;
3589
1.71k
    }
3590
206k
  }
3591
3592
209k
    if (p_state_enhaacplus_dec->sbr_present && total_channels > 2) {
3593
241
      for (WORD32 j = 0; j < channel; j++) {
3594
213k
        for (WORD32 i = 0; i < frame_size; i++) {
3595
213k
          intermediate_scr[total_channels * i + j +
3596
213k
                           p_state_enhaacplus_dec->slot_pos] =
3597
213k
              actual_out_buffer[total_channels * i + j +
3598
213k
                                p_state_enhaacplus_dec->slot_pos];
3599
213k
        }
3600
136
      }
3601
105
    }
3602
209k
  }
3603
3604
191k
  if (p_state_enhaacplus_dec->sbr_present && total_channels > 2) {
3605
36
    memcpy(time_data, intermediate_scr,
3606
36
           sizeof(WORD16) * frame_size * total_channels);
3607
36
  }
3608
3609
191k
  {
3610
191k
    ia_adts_crc_info_struct *ptr_adts_crc_info =
3611
191k
        p_state_enhaacplus_dec->ptr_bit_stream->pstr_adts_crc_info;
3612
191k
    if (ptr_adts_crc_info->crc_active == 1) {
3613
7
      if ((error_code = ixheaacd_adts_crc_check_crc(ptr_adts_crc_info))) {
3614
7
        if (error_code) {
3615
7
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3616
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3617
7
          } else {
3618
7
            return error_code;
3619
7
          }
3620
7
        }
3621
7
      }
3622
7
    }
3623
191k
  }
3624
3625
191k
  p_obj_exhaacplus_dec->aac_config.ui_n_channels = total_channels;
3626
3627
191k
  p_state_enhaacplus_dec->frame_counter++;
3628
3629
191k
  WORD32 i, j;
3630
3631
191k
  if (channel_coupling_flag) {
3632
319
    error_code = ixheaacd_dec_ind_coupling(p_obj_exhaacplus_dec,
3633
319
                                           p_state_enhaacplus_dec->coup_ch_output,
3634
319
                                           num_of_out_samples, total_channels, time_data);
3635
319
    if (error_code)
3636
14
      return error_code;
3637
319
  }
3638
3639
452k
  for (i = 0; i < total_channels; i++) {
3640
260k
    if (p_obj_exhaacplus_dec->p_state_aac->qshift_adj[i + 1] == 0)
3641
231k
      p_obj_exhaacplus_dec->p_state_aac->qshift_adj[i + 1] =
3642
231k
          p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0];
3643
260k
  }
3644
3645
191k
  if (p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1 &&
3646
14.6k
      total_elements == 1 && num_ch == 2 &&
3647
14.5k
      p_obj_exhaacplus_dec->aac_config.dup_stereo_flag == 1) {
3648
4.12k
    WORD i;
3649
3650
4.12k
    if (!p_state_enhaacplus_dec->sbr_present &&
3651
111
        p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ) {
3652
111k
      for (i = 0; i < frame_size; i++) {
3653
111k
        *((WORD32 *)actual_out_buffer + 2 * i + 1) =
3654
111k
            *((WORD32 *)actual_out_buffer + 2 * i);
3655
111k
      }
3656
4.01k
    } else {
3657
8.20M
      for (i = 0; i < frame_size; i++) {
3658
8.19M
        *(actual_out_buffer + 2 * i + 1) = *(actual_out_buffer + 2 * i);
3659
8.19M
      }
3660
4.01k
    }
3661
4.12k
  }
3662
3663
191k
  if (!p_state_enhaacplus_dec->sbr_present &&
3664
154k
      p_obj_exhaacplus_dec->p_state_aac->peak_lim_init == 1 &&
3665
94.9k
      p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ) {
3666
89.5k
    if (!p_obj_exhaacplus_dec->aac_config.peak_limiter_off) {
3667
89.5k
      ixheaacd_peak_limiter_process(
3668
89.5k
          &p_state_enhaacplus_dec->peak_limiter, time_data, frame_size,
3669
89.5k
          p_obj_exhaacplus_dec->p_state_aac->qshift_adj);
3670
89.5k
    } else {
3671
0
      ixheaacd_scale_adjust(time_data, frame_size,
3672
0
                            p_obj_exhaacplus_dec->p_state_aac->qshift_adj,
3673
0
                            total_channels);
3674
0
    }
3675
3676
152M
    for (i = 0; i < frame_size * 2; i++) {
3677
340M
      for (j = 0; j < total_channels; j++) {
3678
187M
        *((WORD16 *)time_data + total_channels * i + j) =
3679
187M
            ixheaac_round16(*((WORD32 *)time_data + total_channels * i + j));
3680
187M
      }
3681
152M
    }
3682
3683
89.5k
    memmove(
3684
89.5k
        time_data,
3685
89.5k
        (time_data +
3686
89.5k
         total_channels * p_obj_exhaacplus_dec->p_state_aac->delay_in_samples),
3687
89.5k
        sizeof(WORD16) * num_of_out_samples * total_channels);
3688
3689
89.5k
    p_obj_exhaacplus_dec->p_state_aac->delay_in_samples =
3690
89.5k
        p_obj_exhaacplus_dec->p_state_aac->delay_in_samples -
3691
89.5k
        MIN(p_obj_exhaacplus_dec->p_state_aac->delay_in_samples, (UWORD16)frame_size);
3692
89.5k
  }
3693
191k
  if (p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present == 1) {
3694
14.7k
    ia_heaac_mps_state_struct *pstr_mps_state =
3695
14.7k
        &p_state_enhaacplus_dec->heaac_mps_handle;
3696
14.7k
    if (p_state_enhaacplus_dec->sbr_present == 0) {
3697
13.6k
      p_state_enhaacplus_dec->heaac_mps_handle.mps_decode = 1;
3698
13.6k
    } else {
3699
1.00k
      p_state_enhaacplus_dec->heaac_mps_handle.mps_with_sbr = 1;
3700
1.00k
    }
3701
14.7k
    if (!p_obj_exhaacplus_dec->aac_config.ui_enh_sbr)
3702
0
    {
3703
0
      p_state_enhaacplus_dec->heaac_mps_handle.mps_decode = 1;
3704
0
    }
3705
14.7k
    if (p_state_enhaacplus_dec->heaac_mps_handle.mps_init_done == 1) {
3706
14.0k
      p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.frame_ok =
3707
14.0k
          p_obj_exhaacplus_dec->aac_config.frame_status;
3708
14.0k
      p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.ec_flag =
3709
14.0k
          p_obj_exhaacplus_dec->aac_config.ui_err_conceal;
3710
3711
14.0k
      error_code = ixheaacd_heaac_mps_apply(p_obj_exhaacplus_dec, actual_out_buffer, mps_buffer,
3712
14.0k
                                            p_state_enhaacplus_dec->ui_mps_out_bytes);
3713
3714
14.0k
      if (error_code != IA_NO_ERROR) {
3715
833
        return error_code;
3716
833
      }
3717
3718
13.2k
      p_state_enhaacplus_dec->heaac_mps_handle.mps_decode = 1;
3719
13.2k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes =
3720
13.2k
          (pstr_mps_state->num_output_channels_at *
3721
13.2k
           pstr_mps_state->frame_length *
3722
13.2k
           (p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz >> 3));
3723
13.2k
      p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.first_frame = 0;
3724
13.2k
    }
3725
14.7k
  }
3726
190k
  if ((total_channels > 2) && (1 == p_obj_exhaacplus_dec->aac_config.downmix)) {
3727
0
    ixheaacd_dec_downmix_to_stereo(p_obj_exhaacplus_dec, num_of_out_samples,
3728
0
                                   total_elements, time_data, total_channels);
3729
3730
0
    total_channels = 2;
3731
0
    p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes =
3732
0
        p_state_enhaacplus_dec->num_of_out_samples * 2 * sizeof(WORD16);
3733
0
  }
3734
3735
190k
  if (p_obj_exhaacplus_dec->aac_config.flag_downmix && total_channels == 2) {
3736
0
    WORD32 out_ch = 1;
3737
0
    WORD i;
3738
0
    if (p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1) {
3739
0
      out_ch = 2;
3740
0
    }
3741
3742
0
    p_obj_exhaacplus_dec->aac_config.ui_n_channels = out_ch;
3743
0
    p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes =
3744
0
        p_state_enhaacplus_dec->num_of_out_samples * out_ch * sizeof(WORD16);
3745
3746
0
    for (i = 0; i < num_of_out_samples; i++) {
3747
0
      WORD16 temp;
3748
3749
0
      temp = (time_data[2 * i + 0] >> 1) + (time_data[2 * i + 1] >> 1);
3750
3751
0
      if (out_ch == 2) {
3752
0
        time_data[2 * i + 0] = temp;
3753
0
        time_data[2 * i + 1] = time_data[2 * i + 0];
3754
0
      } else {
3755
0
        time_data[i] = temp;
3756
0
      }
3757
0
    }
3758
0
  }
3759
3760
190k
  if (p_state_enhaacplus_dec->s_adts_hdr_present) {
3761
27.4k
    if (adts.no_raw_data_blocks != 0) {
3762
2.14k
      if (adts.protection_absent == 0 && it_bit_buff->cnt_bits >= 16) {
3763
0
        adts.crc_check = ixheaacd_read_bits_buf(it_bit_buff, 16);
3764
0
      }
3765
2.14k
    }
3766
27.4k
    p_state_enhaacplus_dec->b_n_raw_data_blk--;
3767
27.4k
  }
3768
3769
190k
  ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
3770
3771
190k
  if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT)
3772
164k
    p_state_enhaacplus_dec->i_bytes_consumed =
3773
164k
        (WORD32)(audio_mux_length_bytes_last + bytes_for_sync);
3774
3775
190k
  if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal &&
3776
0
      p_obj_exhaacplus_dec->aac_config.first_frame) {
3777
0
    p_obj_exhaacplus_dec->aac_config.first_frame = 0;
3778
0
  }
3779
3780
190k
  if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3781
0
    if (p_obj_exhaacplus_dec->aac_config.frame_status != 1) {
3782
0
      p_state_enhaacplus_dec->i_bytes_consumed = p_state_enhaacplus_dec->ui_in_bytes;
3783
0
    }
3784
0
    return IA_NO_ERROR;
3785
190k
  } else {
3786
190k
    return error_code;
3787
190k
  }
3788
190k
}