Coverage Report

Created: 2026-08-13 06:31

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
391k
#define IA_ENHAACPDEC_NUM_MEMTABS (4)
122
123
0
#define NUM_AAC_TABLES 8
124
125
961k
#define LD_OBJ -2
126
127
#define SCR_BASE_SCR_8K_SIZE \
128
294k
  (IXHEAAC_GET_SIZE_ALIGNED((2 * CHANNELS * MAX_BINS_LONG * sizeof(WORD32)), BYTE_ALIGN_8))
129
#define SCR_EXTRA_SCR_4K_0_SIZE                                                           \
130
458k
  (2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_channel_info_struct), sizeof(WORD32)) + \
131
458k
   2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_sfb_code_book_struct), sizeof(WORD32)) +    \
132
458k
   IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_pns_stereo_data_struct), sizeof(WORD32)))
133
#define SCR_EXTRA_SCR_4K_2_SIZE \
134
458k
  (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8))
135
#define SCR_EXTRA_SCR_4K_3_SIZE \
136
163k
  (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8))
137
#define SCR_OUT_DATA_SIZE \
138
117k
  (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8))
139
#define SCR_IN_DATA_SIZE                                                                \
140
117k
  (2 * IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), \
141
117k
                                BYTE_ALIGN_8))
142
#define SCR_INTER_SCR_SIZE                                                          \
143
275k
  (MAX_CHANNEL_COUNT *                                                              \
144
275k
   IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD16)), \
145
275k
                            BYTE_ALIGN_8))
146
#define SCR_COUP_CH_OUT_SIZE                                                        \
147
261k
  (MAX_CHANNEL_COUNT *                                                              \
148
261k
   IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD16)), \
149
261k
                            BYTE_ALIGN_8))
150
151
#define P_IND_CH_INFO_OFFSET \
152
204
  (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
296k
#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
330k
                                  WORD32 i_cmd, WORD32 i_idx, VOID *pv_value) {
171
330k
  pUWORD32 pui_value = pv_value;
172
173
330k
  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
330k
  if (i_cmd == IA_API_CMD_SET_MEM_PTR) {
178
82.5k
    if (pv_value == 0) {
179
0
      return (IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC);
180
0
    }
181
82.5k
    if (((SIZE_T)pv_value %
182
82.5k
         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
82.5k
    p_obj_exhaacplus_dec->pp_mem_aac[i_idx] = pv_value;
186
82.5k
    memset(p_obj_exhaacplus_dec->pp_mem_aac[i_idx], 0,
187
82.5k
           p_obj_exhaacplus_dec->p_mem_info_aac[i_idx].ui_size);
188
189
82.5k
    if (i_idx == IA_ENHAACPLUS_DEC_PERSIST_IDX) {
190
20.6k
      pUWORD8 p_temp = pv_value;
191
20.6k
      UWORD32 *meminfo =
192
20.6k
          (UWORD32 *)p_obj_exhaacplus_dec->p_mem_info_aac + i_idx;
193
20.6k
      UWORD32 pers_size = meminfo[0];
194
20.6k
      p_temp = p_temp + pers_size -
195
20.6k
               (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) +
196
20.6k
                IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8) +
197
20.6k
                IXHEAAC_GET_SIZE_ALIGNED(MAX_HEADER_BUF_SIZE, BYTE_ALIGN_8));
198
20.6k
      p_obj_exhaacplus_dec->p_state_aac = pv_value;
199
20.6k
      memset(p_obj_exhaacplus_dec->p_state_aac, 0,
200
20.6k
             IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8));
201
20.6k
      p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data = p_temp;
202
20.6k
      p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config =
203
20.6k
          p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8);
204
20.6k
      p_obj_exhaacplus_dec->p_state_aac->header_ptr =
205
20.6k
          p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) +
206
20.6k
          IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8);
207
20.6k
    }
208
209
247k
  } else {
210
247k
    UWORD32 *meminfo =
211
247k
        (UWORD32 *)(p_obj_exhaacplus_dec->p_mem_info_aac + i_idx);
212
247k
    *pui_value = *(meminfo + (i_cmd - IA_API_CMD_GET_MEM_INFO_SIZE));
213
247k
  }
214
215
330k
  return IA_NO_ERROR;
216
330k
}
217
218
static PLATFORM_INLINE VOID
219
20.6k
ixheaacd_init_sbr_tables(ia_sbr_tables_struct *ptr_sbr_tables) {
220
20.6k
  ptr_sbr_tables->env_calc_tables_ptr =
221
20.6k
      (ia_env_calc_tables_struct *)&ixheaacd_aac_dec_env_calc_tables;
222
20.6k
  ptr_sbr_tables->qmf_dec_tables_ptr =
223
20.6k
      (ia_qmf_dec_tables_struct *)&ixheaacd_aac_qmf_dec_tables;
224
20.6k
  ptr_sbr_tables->env_extr_tables_ptr =
225
20.6k
      (ia_env_extr_tables_struct *)&ixheaacd_aac_dec_env_extr_tables;
226
20.6k
  ptr_sbr_tables->ps_tables_ptr =
227
20.6k
      (ia_ps_tables_struct *)&ixheaacd_aac_dec_ps_tables;
228
20.6k
}
229
230
VOID ixheaacd_updatebytesconsumed(
231
    ia_aac_dec_state_struct *p_state_enhaacplus_dec,
232
264k
    struct ia_bit_buf_struct *it_bit_buff) {
233
264k
  p_state_enhaacplus_dec->i_bytes_consumed =
234
264k
      (WORD32)(it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base);
235
264k
  if ((p_state_enhaacplus_dec->i_bytes_consumed == 0) &&
236
2.50k
      (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
264k
  if (it_bit_buff->cnt_bits < 0) {
241
171
    p_state_enhaacplus_dec->i_bytes_consumed = 0;
242
171
    p_state_enhaacplus_dec->ui_out_bytes = 0;
243
171
    p_state_enhaacplus_dec->ui_mps_out_bytes = 0;
244
171
    p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
245
171
  }
246
264k
}
247
248
static VOID copy_qmf_to_ldmps(ia_mps_dec_state_struct *mps_dec_handle,
249
12.0k
                              VOID *sbr_persistent_mem_v) {
250
12.0k
  ia_sbr_pers_struct *sbr_persistent_mem =
251
12.0k
      (ia_sbr_pers_struct *)sbr_persistent_mem_v;
252
12.0k
  memcpy(&mps_dec_handle->str_mps_qmf_bank,
253
12.0k
         &sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[0]
254
12.0k
              ->str_sbr_dec.str_codec_qmf_bank,
255
12.0k
         sizeof(ia_sbr_qmf_filter_bank_struct));
256
257
12.0k
  mps_dec_handle->sbr_tables_ptr =
258
12.0k
      sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables;
259
12.0k
  mps_dec_handle->qmf_dec_tables_ptr =
260
12.0k
      sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables->qmf_dec_tables_ptr;
261
12.0k
  mps_dec_handle->str_sbr_scale_fact =
262
12.0k
      &sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[0]
263
12.0k
           ->str_sbr_dec.str_sbr_scale_fact;
264
12.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
48.1k
                           ia_adts_header_struct *adts) {
269
48.1k
  WORD error;
270
271
48.1k
  if ((error = ixheaacd_find_syncword(adts, it_bit_buff)) != 0) {
272
1.19k
    ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
273
1.19k
    return IA_XHEAAC_DEC_EXE_NONFATAL_ADTS_SYNC_LOST;
274
1.19k
  }
275
46.9k
  if ((error = ixheaacd_check_if_adts(
276
46.9k
           adts, it_bit_buff,
277
46.9k
           p_state_enhaacplus_dec->p_config->ui_max_channels)) != 0) {
278
229
    p_state_enhaacplus_dec->i_bytes_consumed = 1;
279
280
229
    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
229
    return IA_XHEAAC_DEC_EXE_NONFATAL_ADTS_SYNC_LOST;
288
229
  }
289
46.6k
  p_state_enhaacplus_dec->b_n_raw_data_blk =
290
46.6k
      (WORD8)(adts->no_raw_data_blocks + 1);
291
46.6k
  return 0;
292
46.9k
}
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
294k
    WORD32 audio_object_type) {
298
294k
  WORD32 scratch_used = 0;
299
294k
  aac_scratch_struct->base_scr_8k = base_scratch_ptr;
300
294k
  aac_scratch_struct->extra_scr_4k[1] = (WORD8 *)base_scratch_ptr;
301
294k
  scratch_used += SCR_BASE_SCR_8K_SIZE;
302
294k
  if (channel == 1) {
303
239k
    aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used;
304
239k
    scratch_used += SCR_EXTRA_SCR_4K_0_SIZE;
305
239k
    aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used;
306
239k
    scratch_used += SCR_EXTRA_SCR_4K_2_SIZE;
307
239k
  } else {
308
55.3k
    aac_scratch_struct->extra_scr_4k[0] = output_ptr;
309
310
55.3k
    if (max_channel > 2) {
311
55.3k
      aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used;
312
55.3k
      scratch_used += SCR_EXTRA_SCR_4K_0_SIZE;
313
55.3k
    }
314
55.3k
    aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used;
315
55.3k
    scratch_used += SCR_EXTRA_SCR_4K_2_SIZE;
316
55.3k
  }
317
318
294k
  if (audio_object_type == AOT_ER_AAC_ELD || audio_object_type == AOT_ER_AAC_LD) {
319
163k
    aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used;
320
163k
    scratch_used += SCR_EXTRA_SCR_4K_0_SIZE;
321
322
163k
    aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used;
323
163k
    scratch_used += SCR_EXTRA_SCR_4K_2_SIZE;
324
325
163k
    aac_scratch_struct->extra_scr_4k[3] = (WORD8 *)base_scratch_ptr + scratch_used;
326
163k
    scratch_used += SCR_EXTRA_SCR_4K_3_SIZE;
327
163k
  }
328
294k
  if ((audio_object_type == AOT_ER_AAC_LD) || (audio_object_type == AOT_AAC_LTP)) {
329
117k
    aac_scratch_struct->out_data = (WORD32 *)((WORD8 *)base_scratch_ptr + scratch_used);
330
117k
    scratch_used += SCR_OUT_DATA_SIZE;
331
332
117k
    aac_scratch_struct->in_data = (WORD32 *)((WORD8 *)base_scratch_ptr + scratch_used);
333
117k
    scratch_used += SCR_IN_DATA_SIZE;
334
117k
  }
335
294k
}
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
277k
                               UWORD8 slot_pos, UWORD8 num_ch) {
340
277k
  WORD32 j, i;
341
277k
  sbr_scratch_struct->ptr_work_buf_core = base_scratch_ptr;
342
343
277k
  if (p_qshift_arr != NULL && *p_qshift_arr != LD_OBJ) {
344
43.8k
    WORD32 *tmp_buf = (WORD32 *)output_ptr;
345
346
66.0k
    for (j = 1; j < num_ch; j++) {
347
22.1k
      if ((*p_qshift_arr + j) == 0)
348
0
        *(p_qshift_arr + j) = *(p_qshift_arr + j - 1);
349
22.1k
    }
350
351
43.8k
    if (total_channels > 2) {
352
333
      for (j = 0; j < num_ch; j++) {
353
188k
        for (i = 0; i < 1024; i++) {
354
188k
          *((WORD16 *)tmp_buf + slot_pos + total_channels * i + j) =
355
188k
              ixheaac_round16(ixheaac_shl32_sat(
356
188k
                  *(tmp_buf + slot_pos + total_channels * i + j),
357
188k
                  *(p_qshift_arr + j)));
358
188k
        }
359
184
      }
360
43.7k
    } else {
361
109k
      for (j = 0; j < num_ch; j++) {
362
67.5M
        for (i = 0; i < 1024; i++) {
363
67.4M
          *((WORD16 *)tmp_buf + total_channels * i + j) =
364
67.4M
              ixheaac_round16(ixheaac_shl32_sat(
365
67.4M
                  *(tmp_buf + total_channels * i + j), *(p_qshift_arr + j)));
366
67.4M
        }
367
65.8k
      }
368
43.7k
    }
369
43.8k
  }
370
277k
}
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
4.64M
                              WORD32 i_idx, pVOID pv_value) {
383
4.64M
  ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec = p_ia_xheaac_dec_obj;
384
4.64M
  pUWORD32 pui_value = pv_value;
385
4.64M
  pWORD32 pui_value_signed = pv_value;
386
4.64M
  pWORD8 pb_value = pv_value;
387
4.64M
  pVOID *pp_value = (pVOID *)pv_value;
388
4.64M
  float *pf_value = pv_value;
389
390
4.64M
  if ((i_cmd != IA_API_CMD_GET_API_SIZE) &&
391
4.62M
      (i_cmd != IA_API_CMD_GET_LIB_ID_STRINGS)) {
392
4.62M
    if (p_ia_xheaac_dec_obj == 0) {
393
0
      return (IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC);
394
0
    }
395
4.62M
    if (((SIZE_T)p_ia_xheaac_dec_obj & 3) != 0) {
396
0
      return (IA_XHEAAC_DEC_API_FATAL_MEM_ALIGN);
397
0
    }
398
4.62M
  }
399
400
4.64M
  switch (i_cmd) {
401
82.5k
    case IA_API_CMD_GET_MEM_INFO_SIZE:
402
165k
    case IA_API_CMD_GET_MEM_INFO_ALIGNMENT:
403
247k
    case IA_API_CMD_GET_MEM_INFO_TYPE:
404
330k
    case IA_API_CMD_SET_MEM_PTR: {
405
330k
      return ixheaacd_dec_mem_api(p_ia_xheaac_dec_obj, i_cmd, i_idx,
406
330k
                                  pv_value);
407
247k
    }
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
4.64M
  };
417
418
4.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
20.6k
    case IA_API_CMD_GET_API_SIZE: {
443
20.6k
      *pui_value = sizeof(ia_exhaacplus_dec_api_struct);
444
20.6k
      break;
445
0
    }
446
108k
    case IA_API_CMD_INIT: {
447
108k
      switch (i_idx) {
448
20.6k
        case IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS: {
449
20.6k
          memset(p_obj_exhaacplus_dec, 0, sizeof(*p_obj_exhaacplus_dec));
450
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16;
451
20.6k
          p_obj_exhaacplus_dec->aac_config.flag_downmix = 0;
452
20.6k
          p_obj_exhaacplus_dec->aac_config.flag_08khz_out = 0;
453
20.6k
          p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0;
454
20.6k
          p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 0;
455
20.6k
          p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0;
456
20.6k
          p_obj_exhaacplus_dec->aac_config.header_dec_done = 0;
457
20.6k
          p_obj_exhaacplus_dec->aac_config.frame_status = 1;
458
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 0;
459
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0;
460
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 1;
461
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_samp_freq = 0;
462
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_frame_size = 0;
463
464
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_n_channels = 2;
465
20.6k
          p_obj_exhaacplus_dec->aac_config.i_channel_mask = 3;
466
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 3;
467
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0;
468
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_effect_type = 0;
469
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_target_loudness = -24;
470
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_loud_norm_flag = 0;
471
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_hq_esbr = 0;
472
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_enh_sbr = 1;
473
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps = 0;
474
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr = 0;
475
20.6k
          p_obj_exhaacplus_dec->aac_config.loas_present = 0;
476
20.6k
          p_obj_exhaacplus_dec->aac_config.ld_decoder = 0;
477
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 100;
478
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 100;
479
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_mode_cut = 0;
480
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_mode_boost = 0;
481
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108;
482
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 0;
483
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 0;
484
20.6k
          p_obj_exhaacplus_dec->aac_config.output_level = -1;
485
20.6k
#ifdef LOUDNESS_LEVELING_SUPPORT
486
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = 1;
487
20.6k
#endif
488
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_max_channels = 6;
489
490
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 0;
491
20.6k
          p_obj_exhaacplus_dec->aac_config.downmix = 0;
492
493
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_err_conceal = 0;
494
495
20.6k
          {
496
20.6k
            ia_aac_dec_tables_struct *pstr_aac_tables =
497
20.6k
                &p_obj_exhaacplus_dec->aac_tables;
498
20.6k
            pstr_aac_tables->pstr_huffmann_tables =
499
20.6k
                (ia_aac_dec_huffman_tables_struct
500
20.6k
                     *)&ixheaacd_aac_huffmann_tables;
501
20.6k
            pstr_aac_tables->pstr_block_tables =
502
20.6k
                (ia_aac_dec_block_tables_struct *)&ixheaacd_aac_block_tables;
503
20.6k
            pstr_aac_tables->pstr_imdct_tables =
504
20.6k
                (ia_aac_dec_imdct_tables_struct *)&ixheaacd_imdct_tables;
505
506
20.6k
            ixheaacd_huff_tables_create(pstr_aac_tables);
507
20.6k
          }
508
20.6k
          ixheaacd_init_sbr_tables(&p_obj_exhaacplus_dec->str_sbr_tables);
509
20.6k
          p_obj_exhaacplus_dec->common_tables =
510
20.6k
              (ixheaacd_misc_tables *)&ixheaacd_str_fft_n_transcendent_tables;
511
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_qmf_bands = 64;
512
513
20.6k
          break;
514
0
        }
515
20.6k
        case IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS: {
516
20.6k
          ixheaacd_fill_aac_mem_tables(p_obj_exhaacplus_dec);
517
20.6k
          break;
518
0
        }
519
33.3k
        case IA_CMD_TYPE_INIT_PROCESS: {
520
33.3k
          WORD32 err_code = 0;
521
33.3k
          if (p_obj_exhaacplus_dec->p_state_aac->fatal_err_present) {
522
457
            err_code = IA_FATAL_ERROR;
523
32.9k
          } else {
524
32.9k
            err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec);
525
32.9k
            if (err_code && p_obj_exhaacplus_dec->p_state_aac->s_adts_hdr_present) {
526
441
              p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0;
527
441
            }
528
32.9k
            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
32.9k
          }
536
33.3k
          if (err_code != 0) {
537
1.59k
            if (err_code < 0)
538
1.04k
              p_obj_exhaacplus_dec->p_state_aac->fatal_err_present = 1;
539
1.59k
            p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
540
1.59k
                p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
541
1.59k
          }
542
33.3k
          return err_code;
543
0
          break;
544
0
        }
545
33.3k
        case IA_CMD_TYPE_INIT_DONE_QUERY: {
546
33.3k
          if (p_obj_exhaacplus_dec->p_state_aac->ui_init_done == 1) {
547
18.1k
            *pui_value = 1;
548
18.1k
          } else {
549
15.2k
            *pui_value = 0;
550
15.2k
          }
551
33.3k
          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
108k
      };
568
74.6k
      break;
569
108k
    }
570
165k
    case IA_API_CMD_SET_CONFIG_PARAM: {
571
165k
      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
20.6k
        case IA_XHEAAC_DEC_CONFIG_PARAM_MP4FLAG: {
622
20.6k
          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
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = *pui_value;
627
20.6k
          break;
628
20.6k
        }
629
20.6k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_CUT: {
630
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1;
631
20.6k
          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
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_mode_cut = 1;
637
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_cut =
638
20.6k
              (WORD32)((*pf_value) * 100);
639
20.6k
          break;
640
20.6k
        }
641
642
20.6k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_BOOST: {
643
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1;
644
20.6k
          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
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_mode_boost = 1;
650
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_boost =
651
20.6k
              (WORD32)((*pf_value) * 100);
652
20.6k
          break;
653
20.6k
        }
654
655
20.6k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL: {
656
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1;
657
20.6k
          p_obj_exhaacplus_dec->aac_config.i_loud_ref_level = *pui_value_signed;
658
20.6k
          if (*pui_value > 127) {
659
8.32k
            p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108;
660
8.32k
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRC_TARGET);
661
8.32k
          }
662
12.2k
          p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = *pui_value;
663
12.2k
          break;
664
20.6k
        }
665
20.6k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_HEAVY_COMP: {
666
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1;
667
20.6k
          if ((*pui_value != 1) && (*pui_value != 0)) {
668
15.6k
            p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp = 0;
669
15.6k
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRCFLAG);
670
15.6k
          }
671
4.98k
          p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp = *pui_value;
672
4.98k
          break;
673
20.6k
        }
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
20.6k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE: {
743
20.6k
          if (((*pui_value_signed) > 8) || ((*pui_value_signed) < -1)) {
744
16.7k
            p_obj_exhaacplus_dec->aac_config.ui_effect_type = -1;
745
16.7k
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_EFFECT_TYPE);
746
16.7k
          }
747
3.91k
          p_obj_exhaacplus_dec->aac_config.ui_effect_type = *pui_value_signed;
748
3.91k
          break;
749
20.6k
        }
750
20.6k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS: {
751
20.6k
          if (*pui_value_signed >= 0) {
752
20.6k
            p_obj_exhaacplus_dec->aac_config.ui_loud_norm_flag = 1;
753
20.6k
          }
754
20.6k
          *pui_value_signed = -(*pui_value_signed >> 2);
755
20.6k
          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
20.6k
          p_obj_exhaacplus_dec->aac_config.ui_target_loudness =
760
20.6k
              *pui_value_signed;
761
20.6k
          break;
762
20.6k
        }
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
20.6k
        case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUDNESS_LEVELING: {
805
20.6k
          if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) {
806
17.2k
            p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = 1;
807
17.2k
            return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_LOUDNESS_LEVELING_FLAG);
808
17.2k
          }
809
3.34k
          p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = *pui_value_signed;
810
3.34k
          break;
811
20.6k
        }
812
0
#endif
813
0
        default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_CONFIG_PARAM; }
814
165k
      }
815
107k
      break;
816
165k
    }
817
818
1.29M
    case IA_API_CMD_GET_CONFIG_PARAM: {
819
1.29M
      UWORD32 i;
820
1.29M
      WORD32 *pvalue =
821
1.29M
          (WORD32 *)(&p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz);
822
1.29M
      if (IA_XHEAAC_DEC_CONFIG_PARAM_NUM_CHANNELS == i_idx) {
823
18.1k
        if (p_obj_exhaacplus_dec->p_state_aac != NULL &&
824
18.1k
            p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle
825
18.1k
                    .heaac_mps_present == 1) {
826
4.52k
          *pui_value = p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle
827
4.52k
                           .num_output_channels_at;
828
13.6k
        } else {
829
13.6k
          *pui_value = pvalue[i_idx];
830
13.6k
        }
831
1.27M
      } else if (IA_XHEAAC_DEC_CONFIG_PARAM_CHANNEL_MASK == i_idx) {
832
18.1k
        if (p_obj_exhaacplus_dec->p_state_aac != NULL &&
833
18.1k
            p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle
834
18.1k
                    .heaac_mps_present == 1) {
835
4.52k
          *pui_value = p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle
836
4.52k
                           .bs_config.ui_channel_mask;
837
13.6k
        } else {
838
13.6k
          *pui_value = pvalue[i_idx];
839
13.6k
        }
840
18.1k
      } else
841
1.25M
      if (i_idx >= 0 && i_idx <= 8) {
842
145k
        *pui_value = pvalue[i_idx];
843
1.11M
      } 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
1.11M
      } else if (IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR == i_idx) {
858
18.1k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
859
18.1k
            ((ia_audio_specific_config_struct *)
860
18.1k
                p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
861
862
26.7k
        for (i = 0; i < ptr_audio_specific_config->str_usac_config
863
26.7k
                            .str_usac_dec_config.num_config_extensions;
864
18.1k
             i++) {
865
8.57k
          pp_value[i] = ptr_audio_specific_config->str_usac_config
866
8.57k
                            .str_usac_dec_config.usac_cfg_ext_info_buf[i];
867
8.57k
        }
868
869
34.6k
        for (i = 0; i < ptr_audio_specific_config->str_usac_config
870
34.6k
                            .str_usac_dec_config.num_elements;
871
18.1k
             i++) {
872
16.5k
          if (ptr_audio_specific_config->str_usac_config.str_usac_dec_config
873
16.5k
                  .usac_ext_ele_payload_present[i]) {
874
1.57k
            pp_value[i + 16] =
875
1.57k
                ptr_audio_specific_config->str_usac_config.str_usac_dec_config
876
1.57k
                    .usac_ext_ele_payload_buf[i];
877
1.57k
          }
878
16.5k
        }
879
1.09M
      } else if (IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES == i_idx) {
880
18.1k
        WORD32 *ptri_value = (WORD32 *)pv_value;
881
18.1k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
882
18.1k
            ((ia_audio_specific_config_struct *)
883
18.1k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
884
26.7k
        for (i = 0; i < ptr_audio_specific_config->str_usac_config
885
26.7k
                            .str_usac_dec_config.num_config_extensions;
886
18.1k
             i++) {
887
8.57k
          ptri_value[i] = ptr_audio_specific_config->str_usac_config
888
8.57k
                              .str_usac_dec_config.usac_cfg_ext_info_len[i];
889
8.57k
        }
890
34.6k
        for (i = 0; i < ptr_audio_specific_config->str_usac_config
891
34.6k
                            .str_usac_dec_config.num_elements;
892
18.1k
             i++) {
893
16.5k
          ptri_value[i + 16] =
894
16.5k
              ptr_audio_specific_config->str_usac_config.str_usac_dec_config
895
16.5k
                  .usac_ext_ele_payload_len[i];
896
16.5k
        }
897
898
1.07M
      } 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
1.07M
      } else if (IA_ENHAACPLUS_DEC_DRC_APPLY_CROSSFADE == i_idx) {
901
0
        *pui_value = p_obj_exhaacplus_dec->p_state_aac->apply_crossfade;
902
1.07M
      } else if (IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE == i_idx) {
903
18.1k
        UWORD32 *ptri_value = (UWORD32 *)pv_value;
904
18.1k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
905
18.1k
            ((ia_audio_specific_config_struct *)
906
18.1k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
907
18.1k
        *ptri_value = ptr_audio_specific_config->str_usac_config
908
18.1k
                          .str_usac_dec_config.num_elements;
909
910
1.05M
      } else if (IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT == i_idx) {
911
18.1k
        UWORD32 *ptri_value = (UWORD32 *)pv_value;
912
18.1k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
913
18.1k
            ((ia_audio_specific_config_struct *)
914
18.1k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
915
18.1k
        *ptri_value = ptr_audio_specific_config->str_usac_config
916
18.1k
                          .str_usac_dec_config.num_config_extensions;
917
1.04M
      } else if (IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN == i_idx) {
918
520k
        UWORD32 *ptri_value = (UWORD32 *)pv_value;
919
520k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
920
520k
            ((ia_audio_specific_config_struct *)
921
520k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
922
520k
        WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config
923
520k
                                     .str_usac_dec_config.preroll_counter;
924
520k
        *ptri_value =
925
520k
            ptr_audio_specific_config->str_usac_config.str_usac_dec_config
926
520k
                .usac_ext_gain_payload_len[preroll_counter];
927
520k
      } else if (IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF == i_idx) {
928
520k
        WORD32 payload_buffer_offeset = 0;
929
520k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
930
520k
            ((ia_audio_specific_config_struct *)
931
520k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
932
520k
        WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config
933
520k
                                     .str_usac_dec_config.preroll_counter;
934
523k
        for (i = 0; i < (UWORD32)preroll_counter; i++)
935
3.52k
          payload_buffer_offeset +=
936
3.52k
              ptr_audio_specific_config->str_usac_config.str_usac_dec_config
937
3.52k
                  .usac_ext_gain_payload_len[i] *
938
3.52k
              sizeof(WORD8);
939
520k
        *pp_value = ptr_audio_specific_config->str_usac_config
940
520k
                        .str_usac_dec_config.usac_ext_gain_payload_buf +
941
520k
                    payload_buffer_offeset;
942
520k
      } 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
1.29M
      break;
980
1.29M
    }
981
982
1.29M
    case IA_API_CMD_GET_MEMTABS_SIZE: {
983
20.6k
      *pui_value = (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) *
984
20.6k
                   (IA_ENHAACPDEC_NUM_MEMTABS);
985
20.6k
      break;
986
1.29M
    }
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
1.29M
    }
991
20.6k
    case IA_API_CMD_SET_MEMTABS_PTR: {
992
20.6k
      if (pv_value == NULL) return IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC;
993
20.6k
      memset(pv_value, 0, (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) *
994
20.6k
                              (IA_ENHAACPDEC_NUM_MEMTABS));
995
996
20.6k
      p_obj_exhaacplus_dec->p_mem_info_aac = pv_value;
997
20.6k
      p_obj_exhaacplus_dec->pp_mem_aac =
998
20.6k
          (pVOID *)((WORD8 *)pv_value +
999
20.6k
                    sizeof(ia_mem_info_struct) * IA_ENHAACPDEC_NUM_MEMTABS);
1000
1001
20.6k
      break;
1002
20.6k
    }
1003
0
    case IA_API_CMD_GET_N_MEMTABS: {
1004
0
      *pui_value = IA_ENHAACPDEC_NUM_MEMTABS;
1005
0
      break;
1006
20.6k
    }
1007
1008
0
    case IA_API_CMD_GET_N_TABLES: {
1009
0
      *pui_value = NUM_AAC_TABLES + NUM_MPS_TABLES;
1010
0
      break;
1011
20.6k
    }
1012
1.04M
    case IA_API_CMD_EXECUTE: {
1013
1.04M
      switch (i_idx) {
1014
520k
        case IA_CMD_TYPE_DO_EXECUTE: {
1015
520k
          WORD32 err_code = 0;
1016
520k
          if (!p_obj_exhaacplus_dec->p_state_aac->ui_init_done ||
1017
518k
              p_obj_exhaacplus_dec->p_state_aac->fatal_err_present) {
1018
3.21k
            err_code = IA_FATAL_ERROR;
1019
516k
          } else {
1020
516k
            memset(p_obj_exhaacplus_dec->p_state_aac->qshift_adj, 0,
1021
516k
                   sizeof(p_obj_exhaacplus_dec->p_state_aac->qshift_adj));
1022
516k
            p_obj_exhaacplus_dec->p_state_aac->qshift_cnt = 0;
1023
516k
            err_code = ixheaacd_dec_execute(p_obj_exhaacplus_dec);
1024
516k
          }
1025
520k
          if (err_code != IA_NO_ERROR) {
1026
18.7k
            if (err_code < 0) {
1027
6.69k
              p_obj_exhaacplus_dec->p_state_aac->fatal_err_present = 1;
1028
6.69k
            }
1029
18.7k
            p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
1030
18.7k
                p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
1031
18.7k
          }
1032
520k
          return err_code;
1033
0
          break;
1034
0
        }
1035
520k
        case IA_CMD_TYPE_DONE_QUERY: {
1036
520k
          if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 1) {
1037
0
            *pui_value = 1;
1038
520k
          } else {
1039
520k
            *pui_value = 0;
1040
520k
          }
1041
1042
520k
          break;
1043
0
        }
1044
0
        default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_EXECUTE_TYPE; }
1045
1.04M
      };
1046
520k
      break;
1047
1.04M
    }
1048
553k
    case IA_API_CMD_GET_CURIDX_INPUT_BUF: {
1049
553k
      *pui_value = p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed;
1050
553k
      break;
1051
1.04M
    }
1052
553k
    case IA_API_CMD_SET_INPUT_BYTES: {
1053
553k
      p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes = *pui_value;
1054
553k
      break;
1055
1.04M
    }
1056
520k
    case IA_API_CMD_GET_OUTPUT_BYTES: {
1057
520k
      if (1 == i_idx) {
1058
0
        *pui_value = p_obj_exhaacplus_dec->p_state_aac->ui_mps_out_bytes;
1059
520k
      } else {
1060
520k
        *pui_value = p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes;
1061
520k
      }
1062
520k
      if (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_USAC) {
1063
246k
        ia_audio_specific_config_struct *ptr_audio_specific_config =
1064
246k
            ((ia_audio_specific_config_struct *)
1065
246k
                 p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
1066
1067
246k
        WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config
1068
246k
                                     .str_usac_dec_config.preroll_counter;
1069
1070
246k
        *pui_value = ptr_audio_specific_config->str_usac_config
1071
246k
                         .str_usac_dec_config.preroll_bytes[preroll_counter];
1072
1073
246k
        preroll_counter++;
1074
246k
        if (preroll_counter > (MAX_AUDIO_PREROLLS + 1)) return IA_FATAL_ERROR;
1075
245k
        ptr_audio_specific_config->str_usac_config.str_usac_dec_config
1076
245k
            .preroll_counter = preroll_counter;
1077
245k
      }
1078
519k
      break;
1079
520k
    }
1080
519k
    case IA_API_CMD_INPUT_OVER: {
1081
20.6k
      p_obj_exhaacplus_dec->p_state_aac->ui_input_over = 1;
1082
20.6k
      break;
1083
520k
    }
1084
0
    default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_CMD; }
1085
4.31M
  };
1086
3.70M
  return IA_NO_ERROR;
1087
4.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
20.6k
ixheaacd_persistent_buffer_sizes(WORD32 num_channel) {
1257
20.6k
  WORD32 size_buffers = 0;
1258
1259
20.6k
  WORD32 temp;
1260
20.6k
  WORD32 max_channels;
1261
1262
20.6k
  size_buffers += IXHEAAC_GET_SIZE_ALIGNED(4 * 512 * num_channel * sizeof(WORD32), BYTE_ALIGN_8);
1263
1264
20.6k
  size_buffers +=
1265
20.6k
      num_channel * IXHEAAC_GET_SIZE_ALIGNED(ltp_buffer_size * sizeof(WORD16), BYTE_ALIGN_8);
1266
1267
20.6k
  size_buffers +=
1268
20.6k
      num_channel * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_channel_info), BYTE_ALIGN_8);
1269
1270
20.6k
  if (num_channel > 2) {
1271
20.6k
    max_channels = MAX_BS_ELEMENT;
1272
20.6k
  } else {
1273
0
    max_channels = 2;
1274
0
  }
1275
20.6k
  size_buffers += (max_channels)*2 *
1276
20.6k
                  IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), BYTE_ALIGN_8);
1277
1278
20.6k
  size_buffers +=
1279
20.6k
      num_channel * IXHEAAC_GET_SIZE_ALIGNED(MAXSBRBYTES * sizeof(WORD8), BYTE_ALIGN_8);
1280
1281
20.6k
  size_buffers +=
1282
20.6k
      num_channel * IXHEAAC_GET_SIZE_ALIGNED(MAXSBRBYTES * sizeof(WORD8), BYTE_ALIGN_8);
1283
1284
20.6k
  size_buffers +=
1285
20.6k
      2 * num_channel *
1286
20.6k
      IXHEAAC_GET_SIZE_ALIGNED(
1287
20.6k
          (QMF_FILTER_STATE_ANA_SIZE + 2 * NO_ANALYSIS_CHANNELS) * sizeof(WORD16), BYTE_ALIGN_8);
1288
1289
20.6k
  size_buffers +=
1290
20.6k
      2 * num_channel *
1291
20.6k
      IXHEAAC_GET_SIZE_ALIGNED(
1292
20.6k
          (QMF_FILTER_STATE_ANA_SIZE + 2 * NO_ANALYSIS_CHANNELS) * sizeof(WORD32), BYTE_ALIGN_8);
1293
1294
20.6k
  size_buffers +=
1295
20.6k
      2 * num_channel *
1296
20.6k
      IXHEAAC_GET_SIZE_ALIGNED(
1297
20.6k
          (QMF_FILTER_STATE_SYN_SIZE + 2 * NO_SYNTHESIS_CHANNELS) * sizeof(WORD16), BYTE_ALIGN_8);
1298
1299
20.6k
  size_buffers +=
1300
20.6k
      2 * num_channel *
1301
20.6k
      IXHEAAC_GET_SIZE_ALIGNED(
1302
20.6k
          (QMF_FILTER_STATE_SYN_SIZE + 2 * NO_SYNTHESIS_CHANNELS) * sizeof(WORD32), BYTE_ALIGN_8);
1303
1304
20.6k
  size_buffers += num_channel * 2 *
1305
20.6k
                  IXHEAAC_GET_SIZE_ALIGNED(MAX_OV_COLS * NO_SYNTHESIS_CHANNELS * sizeof(WORD32),
1306
20.6k
                                           BYTE_ALIGN_8);
1307
1308
20.6k
  size_buffers += 2 * LPC_ORDER * num_channel *
1309
20.6k
                  IXHEAAC_GET_SIZE_ALIGNED(NO_ANALYSIS_CHANNELS * sizeof(WORD32), BYTE_ALIGN_8);
1310
1311
20.6k
  size_buffers += 2 * IXHEAAC_GET_SIZE_ALIGNED(LPC_ORDER * sizeof(WORD32 *), BYTE_ALIGN_8);
1312
1313
20.6k
  size_buffers += 2 * LPC_ORDER * num_channel *
1314
20.6k
                  IXHEAAC_GET_SIZE_ALIGNED(NO_ANALYSIS_CHANNELS * sizeof(WORD32), BYTE_ALIGN_8);
1315
1316
20.6k
  size_buffers += 2 * num_channel * 3 *
1317
20.6k
                  IXHEAAC_GET_SIZE_ALIGNED(MAX_FREQ_COEFFS * sizeof(WORD16), BYTE_ALIGN_8);
1318
1319
20.6k
  temp = IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_freq_band_data_struct), BYTE_ALIGN_8) +
1320
20.6k
         IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_prev_frame_data_struct), BYTE_ALIGN_8) +
1321
20.6k
         IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_channel_struct), BYTE_ALIGN_8) +
1322
20.6k
         IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_header_data_struct), BYTE_ALIGN_8);
1323
20.6k
  size_buffers += 2 * num_channel * temp;
1324
1325
20.6k
  size_buffers += MAX_BS_ELEMENT *
1326
20.6k
                  IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaac_drc_bs_data_struct *), BYTE_ALIGN_8);
1327
1328
20.6k
  size_buffers += num_channel * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_ps_dec_struct), BYTE_ALIGN_8);
1329
1330
20.6k
  {
1331
20.6k
    WORD32 temp_size = 0;
1332
20.6k
    size_buffers += (num_channel * 2 *
1333
20.6k
                     IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_frame_info_data_struct) +
1334
20.6k
                                                  MAX_FREQ_COEFFS * sizeof(WORD32) * 2 + 8,
1335
20.6k
                                              BYTE_ALIGN_8));
1336
20.6k
    temp_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_pvc_data_struct), BYTE_ALIGN_8);
1337
20.6k
    temp_size += 2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_esbr_hbe_txposer_struct), BYTE_ALIGN_8);
1338
20.6k
    temp_size += 2 * IXHEAAC_GET_SIZE_ALIGNED(MAX_HBE_PERSISTENT_SIZE, BYTE_ALIGN_8);
1339
20.6k
    temp_size +=
1340
20.6k
        2 * 2 * IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(FLOAT32 *), BYTE_ALIGN_8);
1341
20.6k
    temp_size += 2 * 2 * MAX_QMF_BUF_LEN *
1342
20.6k
                 IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(FLOAT32), BYTE_ALIGN_8);
1343
20.6k
    temp_size += 2 * 2 * MAX_ENV_COLS *
1344
20.6k
                 IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(WORD32), BYTE_ALIGN_8);
1345
20.6k
    size_buffers += num_channel * temp_size;
1346
20.6k
  }
1347
1348
20.6k
  return (size_buffers);
1349
20.6k
}
1350
1351
VOID ixheaacd_fill_aac_mem_tables(
1352
20.6k
    ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
1353
20.6k
  ia_mem_info_struct *p_mem_info_aac;
1354
1355
20.6k
  WORD32 num_channels;
1356
20.6k
  WORD32 channels;
1357
20.6k
  WORD32 buffer_size;
1358
1359
20.6k
  if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
1360
20.6k
    num_channels = (p_obj_exhaacplus_dec->aac_config.ui_max_channels + 1);
1361
20.6k
  } else
1362
1363
0
  {
1364
0
    num_channels = p_obj_exhaacplus_dec->aac_config.ui_max_channels;
1365
0
  }
1366
1367
20.6k
  channels = num_channels;
1368
20.6k
  buffer_size = ixheaacd_persistent_buffer_sizes(num_channels);
1369
1370
20.6k
  {
1371
20.6k
    p_mem_info_aac =
1372
20.6k
        &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX];
1373
20.6k
    p_mem_info_aac->ui_size =
1374
20.6k
        IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8) +
1375
20.6k
        channels *
1376
20.6k
            IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ia_aac_persistent_struct), BYTE_ALIGN_8) +
1377
20.6k
        buffer_size + channels * ixheaacd_getsize_sbr_persistent() + channels * 16 +
1378
20.6k
        ixheaacd_mps_persistent_buffer_sizes();
1379
20.6k
    p_mem_info_aac->ui_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8);
1380
20.6k
    p_mem_info_aac->ui_size +=
1381
20.6k
        IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8);
1382
20.6k
    p_mem_info_aac->ui_size += IXHEAAC_GET_SIZE_ALIGNED(MAX_HEADER_BUF_SIZE, BYTE_ALIGN_8);
1383
20.6k
    p_mem_info_aac->ui_alignment = 16;
1384
20.6k
    p_mem_info_aac->ui_type = IA_MEMTYPE_PERSIST;
1385
20.6k
  }
1386
1387
20.6k
  {
1388
20.6k
    p_mem_info_aac =
1389
20.6k
        &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX];
1390
1391
20.6k
    p_mem_info_aac->ui_size = MAX_SCR_SIZE;
1392
1393
20.6k
    p_mem_info_aac->ui_alignment = 8;
1394
20.6k
    p_mem_info_aac->ui_type = IA_MEMTYPE_SCRATCH;
1395
20.6k
  }
1396
20.6k
  {
1397
20.6k
    p_mem_info_aac =
1398
20.6k
        &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_INPUT_IDX];
1399
1400
20.6k
    p_mem_info_aac->ui_size = IA_MAX_INP_BUFFER_SIZE;
1401
1402
20.6k
    p_mem_info_aac->ui_alignment = 8;
1403
20.6k
    p_mem_info_aac->ui_type = IA_MEMTYPE_INPUT;
1404
20.6k
  }
1405
20.6k
  {
1406
20.6k
    p_mem_info_aac =
1407
20.6k
        &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX];
1408
20.6k
    p_mem_info_aac->ui_size = IA_ENHAACPLUS_DEC_OUT_BUF_SIZE;
1409
20.6k
    p_mem_info_aac->ui_alignment = 8;
1410
20.6k
    p_mem_info_aac->ui_type = IA_MEMTYPE_OUTPUT;
1411
20.6k
  }
1412
20.6k
  return;
1413
20.6k
}
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
5.56k
                          ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
1511
5.56k
  struct ia_bit_buf_struct local_bit_buff;
1512
5.56k
  struct ia_bit_buf_struct *it_bit_buff;
1513
5.56k
  if (self->ptr_mps_data != NULL) {
1514
3.98k
    ixheaacd_create_init_bit_buf(&local_bit_buff, (UWORD8 *)self->ptr_mps_data,
1515
3.98k
                                 (self->left_mps_bits >> 3) + 1);
1516
3.98k
  }
1517
1518
5.56k
  local_bit_buff.xaac_jmp_buf =
1519
5.56k
      &p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf;
1520
1521
5.56k
  it_bit_buff = &local_bit_buff;
1522
1523
5.56k
  it_bit_buff->bit_pos = self->mps_bits_pos;
1524
5.56k
  it_bit_buff->cnt_bits = self->left_mps_bits;
1525
1526
13.6k
  while (self->left_mps_bits >= 8) {
1527
8.08k
    ixheaacd_extension_payload(
1528
8.08k
        it_bit_buff, &self->left_mps_bits,
1529
8.08k
        &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle);
1530
8.08k
  }
1531
5.56k
}
1532
1533
IA_ERRORCODE ixheaacd_dec_init(
1534
32.9k
    ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
1535
32.9k
  FLAG frame_status = 1;
1536
32.9k
  WORD32 frame_size_1;
1537
32.9k
  WORD32 sample_rate_1;
1538
32.9k
  WORD16 num_channels_1;
1539
32.9k
  WORD32 ps_detected = 0;
1540
32.9k
  UWORD8 *in_buffer;
1541
32.9k
  WORD16 *time_data;
1542
32.9k
  WORD ch_idx;
1543
32.9k
  WORD sbr_present_flag = 0;
1544
32.9k
  UWORD8 *mps_buffer;
1545
32.9k
  ia_aac_dec_state_struct *p_state_enhaacplus_dec;
1546
1547
32.9k
  WORD32 error_code = IA_NO_ERROR;
1548
32.9k
  WORD32 persistent_used = 0;
1549
32.9k
  IA_ERRORCODE err_code = IA_NO_ERROR;
1550
32.9k
  struct ia_aac_persistent_struct *aac_persistent_mem;
1551
32.9k
  struct ia_sbr_pers_struct *sbr_persistent_mem;
1552
32.9k
  WORD32 ret_val;
1553
1554
32.9k
  p_obj_exhaacplus_dec->p_state_aac =
1555
32.9k
      p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX];
1556
1557
32.9k
  if (p_obj_exhaacplus_dec->p_state_aac->ui_init_done)
1558
0
  {
1559
0
    return IA_NO_ERROR;
1560
0
  }
1561
1562
32.9k
  p_obj_exhaacplus_dec->p_state_aac->preroll_config_present = 0;
1563
1564
32.9k
  if (p_obj_exhaacplus_dec->p_state_aac != NULL) {
1565
32.9k
    ret_val = setjmp(p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf);
1566
32.9k
    if (ret_val != 0) {
1567
1.24k
      p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
1568
1.24k
          p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
1569
1.24k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
1570
1.24k
      return IA_NO_ERROR;
1571
1.24k
    }
1572
32.9k
  }
1573
1574
31.6k
  time_data = (WORD16 *)(p_obj_exhaacplus_dec
1575
31.6k
                             ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]);
1576
1577
32.9k
  if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) {
1578
32.9k
    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
31.6k
  p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac;
1584
1585
31.6k
  p_state_enhaacplus_dec->aac_scratch_mem_v =
1586
31.6k
      p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX];
1587
31.6k
  p_obj_exhaacplus_dec->p_state_aac->huffman_code_book_scl =
1588
31.6k
      p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables
1589
31.6k
          ->huffman_code_book_scl;
1590
31.6k
  mps_buffer = p_obj_exhaacplus_dec->p_state_aac->mps_buffer;
1591
31.6k
  p_state_enhaacplus_dec->mps_header = -1;
1592
31.6k
  p_obj_exhaacplus_dec->p_state_aac->huffman_code_book_scl_index =
1593
31.6k
      p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables
1594
31.6k
          ->huffman_code_book_scl_index;
1595
1596
31.6k
  p_state_enhaacplus_dec->pstr_aac_tables = &p_obj_exhaacplus_dec->aac_tables;
1597
31.6k
  if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 0)
1598
20.6k
  {
1599
20.6k
    p_obj_exhaacplus_dec->aac_config.header_dec_done = 0;
1600
20.6k
    p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.ldmps_present_flag = 0;
1601
20.6k
  }
1602
31.6k
  if (p_obj_exhaacplus_dec->aac_config.header_dec_done == 0) {
1603
20.6k
    WORD32 channels;
1604
20.6k
    UWORD32 total_persistent_used = 0;
1605
1606
20.6k
    p_obj_exhaacplus_dec->p_state_aac->p_config =
1607
20.6k
        &p_obj_exhaacplus_dec->aac_config;
1608
1609
20.6k
    p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr =
1610
20.6k
        (pVOID)((pWORD8)p_obj_exhaacplus_dec->p_state_aac +
1611
20.6k
                IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8));
1612
20.6k
    if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
1613
20.6k
      p_state_enhaacplus_dec->aac_persistent_mem_v =
1614
20.6k
          (pVOID)((pWORD8)p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr +
1615
20.6k
                  (MAX_BS_ELEMENT)*2 *
1616
20.6k
                      IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct),
1617
20.6k
                                               BYTE_ALIGN_8));
1618
1619
20.6k
      memset(p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr, 0,
1620
20.6k
             (MAX_BS_ELEMENT)*2 *
1621
20.6k
                 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), BYTE_ALIGN_8));
1622
20.6k
    } 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
20.6k
    if (1 == p_obj_exhaacplus_dec->aac_config.ui_max_channels)
1634
0
      channels = 1;
1635
20.6k
    else
1636
20.6k
      channels = 2;
1637
1638
20.6k
    persistent_used = ixheaacd_set_aac_persistent_buffers(
1639
20.6k
        p_state_enhaacplus_dec->aac_persistent_mem_v, channels);
1640
1641
20.6k
    p_state_enhaacplus_dec->sbr_persistent_mem_v =
1642
20.6k
        (pVOID)((pWORD8)p_state_enhaacplus_dec->aac_persistent_mem_v +
1643
20.6k
                IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8));
1644
20.6k
    total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8);
1645
1646
20.6k
    persistent_used = ixheaacd_getsize_sbr_persistent();
1647
20.6k
    ixheaacd_set_sbr_persistent_buffers(
1648
20.6k
        p_state_enhaacplus_dec->sbr_persistent_mem_v, &persistent_used,
1649
20.6k
        channels, 1);
1650
1651
20.6k
    p_state_enhaacplus_dec->heaac_mps_handle.mps_persistent_mem_v =
1652
20.6k
        (pVOID)((pWORD8)p_state_enhaacplus_dec->sbr_persistent_mem_v +
1653
20.6k
                IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8));
1654
20.6k
    total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8);
1655
1656
20.6k
    persistent_used = ixheaacd_getsize_mps_persistent();
1657
1658
20.6k
    ixheaacd_set_mps_persistent_buffers(
1659
20.6k
        &p_state_enhaacplus_dec->heaac_mps_handle, &persistent_used, channels,
1660
20.6k
        p_state_enhaacplus_dec->heaac_mps_handle.mps_persistent_mem_v);
1661
20.6k
    total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8);
1662
1663
20.6k
    if (total_persistent_used >
1664
20.6k
        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
20.6k
    aac_persistent_mem = (struct ia_aac_persistent_struct *)
1669
20.6k
                             p_state_enhaacplus_dec->aac_persistent_mem_v;
1670
20.6k
    if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
1671
20.6k
        p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD)
1672
2
      p_state_enhaacplus_dec->frame_len_flag =
1673
2
          p_obj_exhaacplus_dec->aac_config.framesize_480;
1674
1675
20.6k
    p_state_enhaacplus_dec->ptr_overlap_buf =
1676
20.6k
        aac_persistent_mem->overlap_buffer;
1677
1678
20.6k
    p_state_enhaacplus_dec->bit_count = 0;
1679
20.6k
    p_state_enhaacplus_dec->ec_enable = p_obj_exhaacplus_dec->aac_config.ui_err_conceal;
1680
20.6k
    p_state_enhaacplus_dec->sync_status = 0;
1681
20.6k
    p_state_enhaacplus_dec->bs_format = ADTS_BSFORMAT;
1682
20.6k
    p_state_enhaacplus_dec->latm_initialized = 0;
1683
20.6k
    p_state_enhaacplus_dec->frame_size = 0;
1684
20.6k
    memset(&p_state_enhaacplus_dec->latm_struct_element, 0,
1685
20.6k
           sizeof(ixheaacd_latm_struct));
1686
20.6k
    memset(&p_state_enhaacplus_dec->b_n_raw_data_blk, 0,
1687
20.6k
           sizeof(WORD32) * (9 + MAX_BS_ELEMENT));
1688
1689
20.6k
    p_state_enhaacplus_dec->sbr_present_flag = 0;
1690
1691
227k
    for (ch_idx = 0; ch_idx < MAX_BS_ELEMENT; ch_idx++) {
1692
206k
      p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0;
1693
206k
    }
1694
1695
20.6k
    memset(&p_state_enhaacplus_dec->ind_cc_info, 0,
1696
20.6k
           sizeof(ia_enhaacplus_dec_ind_cc));
1697
1698
20.6k
    p_state_enhaacplus_dec->last_frame_ok = 1;
1699
20.6k
    p_obj_exhaacplus_dec->aac_config.header_dec_done = 1;
1700
1701
20.6k
    aac_persistent_mem->str_aac_decoder.pstr_aac_tables =
1702
20.6k
        &p_obj_exhaacplus_dec->aac_tables;
1703
20.6k
    aac_persistent_mem->str_aac_decoder.pstr_common_tables =
1704
20.6k
        p_obj_exhaacplus_dec->common_tables;
1705
1706
20.6k
    p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_u =
1707
20.6k
        p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_v;
1708
1709
20.6k
    p_obj_exhaacplus_dec->p_state_aac->sbr_scratch_mem_u =
1710
20.6k
        p_obj_exhaacplus_dec->p_state_aac->aac_scratch_mem_v;
1711
1712
20.6k
    ixheaacd_set_sbr_persistent_table_pointer(
1713
20.6k
        p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_v,
1714
20.6k
        &p_obj_exhaacplus_dec->str_sbr_tables,
1715
20.6k
        p_obj_exhaacplus_dec->common_tables);
1716
20.6k
    ixheaacd_set_scratch_buffers(
1717
20.6k
        &p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle,
1718
20.6k
        p_state_enhaacplus_dec->aac_scratch_mem_v);
1719
20.6k
  }
1720
1721
31.6k
  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
31.6k
  if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 0) {
1726
20.6k
    if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
1727
20.6k
        p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD)
1728
2
      p_state_enhaacplus_dec->frame_len_flag =
1729
2
          p_obj_exhaacplus_dec->aac_config.framesize_480;
1730
1731
20.6k
    aac_persistent_mem = (struct ia_aac_persistent_struct *)
1732
20.6k
                             p_state_enhaacplus_dec->aac_persistent_mem_v;
1733
20.6k
    sbr_persistent_mem = (struct ia_sbr_pers_struct *)
1734
20.6k
                             p_state_enhaacplus_dec->sbr_persistent_mem_v;
1735
20.6k
    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
20.6k
    if (p_obj_exhaacplus_dec->aac_config.ui_samp_freq == 0) {
1740
20.6k
      WORD32 header_bytes_consumed, return_val;
1741
1742
20.6k
      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
20.6k
      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
20.6k
      } else {
1751
20.6k
        p_state_enhaacplus_dec->frame_len_flag = 0;
1752
20.6k
        p_state_enhaacplus_dec->frame_length = 1024;
1753
20.6k
      }
1754
1755
20.6k
      p_state_enhaacplus_dec->ui_init_done = 0;
1756
20.6k
      memset(&(p_state_enhaacplus_dec->eld_specific_config), 0,
1757
20.6k
             sizeof(ia_eld_specific_config_struct));
1758
20.6k
      return_val = ixheaacd_aac_headerdecode(
1759
20.6k
          p_obj_exhaacplus_dec, (UWORD8 *)in_buffer, &header_bytes_consumed,
1760
20.6k
          aac_persistent_mem->str_aac_decoder.pstr_aac_tables
1761
20.6k
              ->pstr_huffmann_tables);
1762
20.6k
      if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
1763
18.7k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD ||
1764
15.9k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) {
1765
5.48k
        *sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[0] =
1766
5.48k
            p_obj_exhaacplus_dec->p_state_aac->str_sbr_config;
1767
5.48k
        *sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[1] =
1768
5.48k
            p_obj_exhaacplus_dec->p_state_aac->str_sbr_config;
1769
15.1k
      } else {
1770
15.1k
        memset(&(p_state_enhaacplus_dec->eld_specific_config), 0,
1771
15.1k
               sizeof(ia_eld_specific_config_struct));
1772
15.1k
      }
1773
1774
20.6k
      if (return_val < 0) {
1775
398
        if (return_val ==
1776
398
            (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
393
        p_state_enhaacplus_dec->i_bytes_consumed = 1;
1781
1782
393
        return return_val;
1783
398
      }
1784
1785
20.2k
      if (return_val ==
1786
20.2k
          IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES) {
1787
33
        p_state_enhaacplus_dec->i_bytes_consumed = header_bytes_consumed;
1788
33
        return return_val;
1789
33
      }
1790
1791
20.2k
      p_state_enhaacplus_dec->i_bytes_consumed = header_bytes_consumed;
1792
1793
20.2k
      if ((return_val == 0) &&
1794
19.8k
          (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_USAC)) {
1795
7.46k
        {
1796
7.46k
          WORD32 pcm_size = p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz;
1797
7.46k
          WORD8 *inbuffer =
1798
7.46k
              p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX];
1799
7.46k
          WORD8 *outbuffer =
1800
7.46k
              p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX];
1801
7.46k
          WORD32 out_bytes = 0;
1802
7.46k
          WORD32 frames_done = p_obj_exhaacplus_dec->p_state_aac->frame_counter;
1803
7.46k
          p_obj_exhaacplus_dec->p_state_aac->decode_create_done = 0;
1804
1805
7.46k
          if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 0) {
1806
7.46k
            error_code = ixheaacd_dec_main(
1807
7.46k
                p_obj_exhaacplus_dec, inbuffer, outbuffer, &out_bytes,
1808
7.46k
                frames_done, pcm_size,
1809
7.46k
                &p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch);
1810
7.46k
            if (error_code) return error_code;
1811
7.44k
            p_obj_exhaacplus_dec->p_state_aac->frame_counter++;
1812
7.44k
          } else {
1813
0
            out_bytes = 0;
1814
0
          }
1815
1816
7.44k
          p_obj_exhaacplus_dec->aac_config.ui_n_channels =
1817
7.44k
              p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch;
1818
7.44k
        }
1819
7.44k
        if (return_val == 0)
1820
7.44k
          p_obj_exhaacplus_dec->p_state_aac->ui_init_done = 1;
1821
7.44k
        return return_val;
1822
7.46k
      }
1823
1824
12.7k
      if (return_val == 0) {
1825
12.3k
        p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 1;
1826
12.3k
        if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) {
1827
12.3k
          memcpy(p_state_enhaacplus_dec->header_ptr, in_buffer,
1828
12.3k
                 header_bytes_consumed * sizeof(UWORD8));
1829
12.3k
          p_state_enhaacplus_dec->header_length = header_bytes_consumed;
1830
12.3k
        }
1831
12.3k
      }
1832
1833
12.7k
      if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done != 1)
1834
17
        return IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START;
1835
1836
12.7k
      if (p_state_enhaacplus_dec->dwnsmp_signal == 1 &&
1837
1.60k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD)
1838
1.60k
        p_obj_exhaacplus_dec->aac_config.down_sample_flag = 1;
1839
1840
12.7k
      if (p_state_enhaacplus_dec->sampling_rate ==
1841
12.7k
          p_state_enhaacplus_dec->extension_samp_rate) {
1842
5
        p_obj_exhaacplus_dec->aac_config.down_sample_flag = 1;
1843
5
      }
1844
1845
12.7k
    } else {
1846
3
      p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 1;
1847
3
      p_state_enhaacplus_dec->i_bytes_consumed = 0;
1848
1849
3
      p_state_enhaacplus_dec->sampling_rate =
1850
3
          p_obj_exhaacplus_dec->aac_config.ui_samp_freq;
1851
1852
3
      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
3
      } else {
1856
3
        p_state_enhaacplus_dec->frame_len_flag = 0;
1857
3
        p_state_enhaacplus_dec->frame_length = 1024;
1858
3
      }
1859
3
    }
1860
1861
12.7k
    p_state_enhaacplus_dec->pstr_bit_buf = ixheaacd_create_bit_buf(
1862
12.7k
        &p_state_enhaacplus_dec->str_bit_buf, (UWORD8 *)in_buffer,
1863
12.7k
        p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]
1864
12.7k
            .ui_size);
1865
12.7k
    p_state_enhaacplus_dec->pstr_bit_buf->xaac_jmp_buf =
1866
12.7k
        &(p_state_enhaacplus_dec->xaac_jmp_buf);
1867
1868
12.7k
    p_state_enhaacplus_dec->ptr_bit_stream =
1869
12.7k
        p_state_enhaacplus_dec->pstr_bit_buf;
1870
1871
12.7k
    if (p_state_enhaacplus_dec->s_adts_hdr_present) {
1872
6.43k
      if (p_obj_exhaacplus_dec->aac_config.ld_decoder == 1)
1873
0
        p_state_enhaacplus_dec->audio_object_type = 23;
1874
6.43k
    }
1875
1876
12.7k
    if ((p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) ||
1877
9.65k
        (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD))
1878
4.27k
      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
12.7k
    {
1895
136k
      for (ch_idx = 0; ch_idx < MAX_BS_ELEMENT; ch_idx++) {
1896
123k
        WORD32 channels;
1897
123k
        channels = 2;
1898
1899
123k
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] =
1900
123k
            ixheaacd_aac_decoder_init(
1901
123k
                p_state_enhaacplus_dec,
1902
1903
123k
                p_state_enhaacplus_dec->pstr_stream_sbr[0], channels,
1904
123k
                p_state_enhaacplus_dec->aac_persistent_mem_v,
1905
123k
                p_state_enhaacplus_dec->frame_length);
1906
1907
123k
        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
123k
      }
1912
1913
12.7k
      {
1914
12.7k
        p_state_enhaacplus_dec->pstr_drc_dec =
1915
12.7k
            &p_state_enhaacplus_dec->str_drc_dec_info;
1916
12.7k
        ixheaacd_drc_dec_create(p_state_enhaacplus_dec->pstr_drc_dec, 127, 127);
1917
12.7k
      }
1918
12.7k
      p_state_enhaacplus_dec->pstr_drc_dec->cut_factor =
1919
12.7k
          p_obj_exhaacplus_dec->aac_config.ui_drc_cut;
1920
12.7k
      p_state_enhaacplus_dec->pstr_drc_dec->boost_factor =
1921
12.7k
          p_obj_exhaacplus_dec->aac_config.ui_drc_boost;
1922
12.7k
      p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level =
1923
12.7k
          p_obj_exhaacplus_dec->aac_config.ui_drc_target_level;
1924
12.7k
      p_state_enhaacplus_dec->pstr_drc_dec->prog_ref_level =
1925
12.7k
          p_obj_exhaacplus_dec->aac_config.ui_drc_target_level;
1926
1927
12.7k
      if (1 == p_obj_exhaacplus_dec->aac_config.ui_drc_set) {
1928
12.3k
        if (p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp == 1) {
1929
214
          p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 1;
1930
214
          p_state_enhaacplus_dec->pstr_drc_dec->heavy_mode = 1;
1931
12.1k
        } else {
1932
12.1k
          p_state_enhaacplus_dec->pstr_drc_dec->heavy_mode = 0;
1933
12.1k
          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
12.1k
          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
12.1k
          } else {
1944
12.1k
            p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 1;
1945
12.1k
            p_state_enhaacplus_dec->pstr_drc_dec->drc_dig_norm = 1;
1946
12.1k
          }
1947
12.1k
        }
1948
12.3k
      }
1949
12.7k
    }
1950
12.7k
  } else {
1951
11.0k
    struct ia_bit_buf_struct temp_bit_buff = {0};
1952
11.0k
    ia_adts_header_struct adts;
1953
11.0k
    struct ia_bit_buf_struct *it_bit_buff;
1954
1955
11.0k
    WORD16 frame_size_2 = 0;
1956
11.0k
    WORD32 sample_rate_2 = 0;
1957
11.0k
    WORD32 sample_rate = 0;
1958
11.0k
    WORD type, i;
1959
11.0k
    WORD elements_number;
1960
1961
11.0k
    if (p_state_enhaacplus_dec->audio_object_type == AOT_USAC)
1962
0
      return IA_FATAL_ERROR;
1963
1964
11.0k
    memset(&adts, 0, sizeof(ia_adts_header_struct));
1965
1966
146k
    for (i = 0; i < MAX_BS_ELEMENT + 1; i++) {
1967
135k
      p_obj_exhaacplus_dec->aac_config.element_type[i] = -1;
1968
135k
    }
1969
1970
11.0k
    it_bit_buff = p_state_enhaacplus_dec->pstr_bit_buf;
1971
1972
11.0k
    p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0;
1973
11.0k
    p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
1974
11.0k
    p_state_enhaacplus_dec->ui_mps_out_bytes = 0;
1975
11.0k
    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
11.0k
    if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
1981
10.7k
        p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) {
1982
4.23k
      if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag)
1983
27
        p_state_enhaacplus_dec->frame_size =
1984
27
            p_state_enhaacplus_dec->ui_in_bytes;
1985
4.23k
    }
1986
1987
11.0k
    ixheaacd_create_init_bit_buf(it_bit_buff, in_buffer,
1988
11.0k
                                 p_state_enhaacplus_dec->ui_in_bytes);
1989
11.0k
    p_state_enhaacplus_dec->pstr_bit_buf->xaac_jmp_buf =
1990
11.0k
        &(p_state_enhaacplus_dec->xaac_jmp_buf);
1991
1992
11.0k
    it_bit_buff->adts_header_present =
1993
11.0k
        p_state_enhaacplus_dec->s_adts_hdr_present;
1994
11.0k
    it_bit_buff->no_raw_data_blocks =
1995
11.0k
        (WORD8)p_state_enhaacplus_dec->b_n_raw_data_blk;
1996
11.0k
    it_bit_buff->protection_absent = p_state_enhaacplus_dec->protection_absent;
1997
1998
11.0k
    memcpy(&temp_bit_buff, it_bit_buff, sizeof(struct ia_bit_buf_struct));
1999
2000
11.0k
    if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2)
2001
12.3k
      elements_number = MAX_BS_ELEMENT;
2002
18.4E
    else
2003
18.4E
      elements_number = 2;
2004
2005
134k
    for (i = 0; i < elements_number; i++)
2006
123k
      p_state_enhaacplus_dec->pstr_stream_sbr[i][0].no_elements = 0;
2007
2008
11.0k
    { it_bit_buff->initial_cnt_bits = it_bit_buff->cnt_bits; }
2009
2010
11.0k
    ixheaacd_byte_align(
2011
11.0k
        p_state_enhaacplus_dec->ptr_bit_stream,
2012
11.0k
        &p_state_enhaacplus_dec->pstr_aac_dec_info[0]->byte_align_bits);
2013
2014
11.0k
    if (p_state_enhaacplus_dec->s_adts_hdr_present) {
2015
6.43k
      WORD32 error;
2016
2017
6.43k
      if (p_state_enhaacplus_dec->b_n_raw_data_blk == 0) {
2018
6.43k
        error = ixheaacd_readifadts(p_state_enhaacplus_dec, it_bit_buff, &adts);
2019
2020
6.43k
        if (error) return error;
2021
2022
6.43k
        p_state_enhaacplus_dec->protection_absent = adts.protection_absent;
2023
2024
6.43k
        if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
2025
6.43k
            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
6.43k
      }
2033
6.43k
    }
2034
2035
11.0k
    if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
2036
5.78k
      WORD32 result;
2037
5.78k
      WORD32 sync;
2038
5.78k
      WORD32 cnt_bits;
2039
2040
5.78k
      sync = ixheaacd_read_bits_buf(it_bit_buff, 11);
2041
5.78k
      cnt_bits = it_bit_buff->cnt_bits;
2042
5.78k
      if (it_bit_buff->cnt_bits <= 24) {
2043
0
        return IA_XHEAAC_DEC_INIT_NONFATAL_INSUFFICIENT_INPUT_BYTES;
2044
0
      }
2045
2046
5.78k
      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
5.78k
      it_bit_buff->audio_mux_align = it_bit_buff->cnt_bits - 13;
2057
2058
5.78k
      if (sync == 0x2b7) {
2059
5.78k
        result = ixheaacd_latm_audio_mux_element(
2060
5.78k
            it_bit_buff, &p_state_enhaacplus_dec->latm_struct_element,
2061
5.78k
            p_state_enhaacplus_dec,
2062
5.78k
            (ia_sampling_rate_info_struct *)&p_obj_exhaacplus_dec->aac_tables
2063
5.78k
                .pstr_huffmann_tables->str_sample_rate_info[0]);
2064
5.78k
        if (result < 0) {
2065
3
          return result;
2066
3
        }
2067
5.78k
      }
2068
5.78k
    }
2069
2070
11.0k
    p_state_enhaacplus_dec->pstr_aac_dec_info[0]->byte_align_bits =
2071
11.0k
        it_bit_buff->cnt_bits;
2072
2073
11.0k
    type = -1;
2074
11.0k
    ch_idx = 0;
2075
2076
20.4k
    while ((type != 7)) {
2077
14.9k
      ia_aac_dec_scratch_struct aac_scratch_struct;
2078
14.9k
      memset(&aac_scratch_struct, 0, sizeof(aac_scratch_struct));
2079
2080
14.9k
      if (ch_idx >= elements_number) {
2081
14
        p_state_enhaacplus_dec->i_bytes_consumed = 1;
2082
2083
14
        return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX;
2084
14
      }
2085
2086
14.9k
      ixheaacd_allocate_aac_scr(
2087
14.9k
          &aac_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v,
2088
14.9k
          time_data, 1, p_obj_exhaacplus_dec->aac_config.ui_max_channels,
2089
14.9k
          p_state_enhaacplus_dec->audio_object_type);
2090
2091
14.9k
      p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info =
2092
14.9k
          &p_state_enhaacplus_dec->ind_cc_info;
2093
14.9k
      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
14.9k
      error_code = ixheaacd_aacdec_decodeframe(
2098
14.9k
          p_obj_exhaacplus_dec, &aac_scratch_struct, time_data, frame_status, &type, &ch_idx, 1,
2099
14.9k
          2, p_obj_exhaacplus_dec->aac_config.element_instance_order, 0, 1, 0,
2100
14.9k
          p_obj_exhaacplus_dec->aac_config.ui_max_channels, 2,
2101
14.9k
          p_obj_exhaacplus_dec->p_state_aac->frame_length,
2102
14.9k
          p_obj_exhaacplus_dec->p_state_aac->frame_size, p_state_enhaacplus_dec->pstr_drc_dec,
2103
14.9k
          p_state_enhaacplus_dec->audio_object_type, p_state_enhaacplus_dec->ch_config,
2104
14.9k
          p_state_enhaacplus_dec->eld_specific_config, p_state_enhaacplus_dec->s_adts_hdr_present,
2105
14.9k
          &p_state_enhaacplus_dec->drc_dummy, p_state_enhaacplus_dec->ldmps_present,
2106
14.9k
          &p_state_enhaacplus_dec->slot_pos, mps_buffer, &p_state_enhaacplus_dec->mps_header,
2107
14.9k
          &p_state_enhaacplus_dec->ui_mps_out_bytes, 1,
2108
14.9k
          p_obj_exhaacplus_dec->aac_config.first_frame);
2109
2110
14.9k
      if (p_state_enhaacplus_dec->pstr_drc_dec->drc_element_found == 1) {
2111
569
        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
569
        } else {
2115
569
          p_obj_exhaacplus_dec->aac_config.output_level =
2116
569
              p_obj_exhaacplus_dec->aac_config.i_loud_ref_level;
2117
569
        }
2118
569
      }
2119
2120
14.9k
      memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx]
2121
14.9k
                   ->pstr_aac_dec_ch_info[0]
2122
14.9k
                   ->str_ics_info.ltp),
2123
14.9k
             0, sizeof(ltp_info));
2124
14.9k
      memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx]
2125
14.9k
                   ->pstr_aac_dec_ch_info[0]
2126
14.9k
                   ->str_ics_info.ltp2),
2127
14.9k
             0, sizeof(ltp_info));
2128
14.9k
      memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx]
2129
14.9k
                   ->pstr_aac_dec_ch_info[1]
2130
14.9k
                   ->str_ics_info.ltp),
2131
14.9k
             0, sizeof(ltp_info));
2132
14.9k
      memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx]
2133
14.9k
                   ->pstr_aac_dec_ch_info[1]
2134
14.9k
                   ->str_ics_info.ltp2),
2135
14.9k
             0, sizeof(ltp_info));
2136
2137
14.9k
      {
2138
2139
14.9k
        frame_size_1 = p_state_enhaacplus_dec->frame_length;
2140
14.9k
        sample_rate_1 =
2141
14.9k
            p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->sampling_rate;
2142
14.9k
        num_channels_1 =
2143
14.9k
            p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->channels;
2144
14.9k
      }
2145
2146
14.9k
      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
14.9k
      if (p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
2153
2.61k
        sbr_present_flag = 1;
2154
2.61k
        p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 1;
2155
2.61k
      }
2156
2157
14.9k
      if (error_code) {
2158
502
        if (p_state_enhaacplus_dec->ui_input_over) {
2159
0
          return IA_XHEAAC_DEC_INIT_FATAL_EO_INPUT_REACHED;
2160
0
        }
2161
2162
502
        ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
2163
502
        return error_code;
2164
502
      }
2165
2166
14.4k
      if (p_state_enhaacplus_dec->s_adts_hdr_present) {
2167
7.20k
        if (adts.no_raw_data_blocks != 0) {
2168
4.03k
          if (adts.protection_absent == 0 && it_bit_buff->cnt_bits >= 16) {
2169
57
            adts.crc_check = ixheaacd_read_bits_buf(it_bit_buff, 16);
2170
57
          }
2171
4.03k
        }
2172
7.20k
        p_state_enhaacplus_dec->b_n_raw_data_blk--;
2173
7.20k
      }
2174
2175
14.4k
      sample_rate_2 = sample_rate_1;
2176
14.4k
      frame_size_2 = frame_size_1;
2177
2178
14.4k
      if (!p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] &&
2179
13.6k
          p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
2180
2.61k
        WORD32 harmonic_sbr_flag = 0;
2181
2.61k
        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.61k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr(
2187
2.61k
            sample_rate_1, frame_size_1,
2188
2.61k
            (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag,
2189
2.61k
            p_state_enhaacplus_dec->sbr_persistent_mem_v,
2190
2.61k
            p_state_enhaacplus_dec->ptr_overlap_buf, MAXNRSBRCHANNELS, (WORD)1,
2191
2.61k
            1, frame_size_1 * 2, &harmonic_sbr_flag, NULL,
2192
2.61k
            p_state_enhaacplus_dec->str_sbr_config,
2193
2.61k
            p_state_enhaacplus_dec->audio_object_type,
2194
2.61k
            p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2195
2.61k
                .ldmps_present_flag,
2196
2.61k
            p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2197
2.61k
                .no_ldsbr_present);
2198
2.61k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
2199
2.60k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
2200
2.60k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
2201
2.60k
        }
2202
11.8k
      } else {
2203
11.8k
      }
2204
2205
14.4k
      if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] &&
2206
2.60k
          p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
2207
2.60k
        ia_sbr_scr_struct sbr_scratch_struct;
2208
2.60k
        WORD16 num_channels_1_t = num_channels_1;
2209
2.60k
        ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v,
2210
2.60k
                                  time_data, 0, NULL, 0, 0);
2211
2.60k
        {
2212
2.60k
          WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type;
2213
2214
2.60k
          if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) {
2215
518
            WORD32 i = 0;
2216
518
            ia_dec_data_struct *pstr_dec_data =
2217
518
                (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data;
2218
518
            if (num_channels_1 == 1) {
2219
469k
              for (; i < 1024; i++) {
2220
468k
                pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
2221
468k
                    ((FLOAT32)time_data[i]);
2222
468k
              }
2223
458
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
2224
458
                  &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
2225
2226
458
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
2227
458
                  &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
2228
458
            } else if (num_channels_1 == 2) {
2229
61.5k
              for (; i < 1024; i++) {
2230
61.4k
                pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
2231
61.4k
                    ((FLOAT32)time_data[2 * i + 0]);
2232
61.4k
                pstr_dec_data->str_usac_data.time_sample_vector[1][i] =
2233
61.4k
                    ((FLOAT32)time_data[2 * i + 1]);
2234
61.4k
              }
2235
60
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
2236
60
                  &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
2237
2238
60
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
2239
60
                  &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
2240
60
            }
2241
518
          }
2242
2.60k
        }
2243
2.60k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->ec_flag =
2244
2.60k
            p_obj_exhaacplus_dec->aac_config.ui_err_conceal;
2245
2.60k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->esbr_hq =
2246
2.60k
            p_obj_exhaacplus_dec->aac_config.ui_hq_esbr;
2247
2.60k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr =
2248
2.60k
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr;
2249
2.60k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr_ps =
2250
2.60k
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps;
2251
2252
2.60k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
2253
2.60k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
2254
2.60k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
2255
2.60k
        }
2256
2257
2.60k
        if (ixheaacd_applysbr(p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx],
2258
2.60k
                              &p_state_enhaacplus_dec->pstr_stream_sbr[0][0], time_data,
2259
2.60k
                              &num_channels_1, frame_status,
2260
2.60k
                              p_obj_exhaacplus_dec->aac_config.down_sample_flag, 0,
2261
2.60k
                              &sbr_scratch_struct, 1, 1, 0, NULL, NULL,
2262
2.60k
                              p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present,
2263
2.60k
                              p_state_enhaacplus_dec->audio_object_type, 1,
2264
2.60k
                              p_state_enhaacplus_dec->ldmps_present, frame_size_1,
2265
2.60k
                              p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present,
2266
2.60k
                              p_obj_exhaacplus_dec->aac_config.ui_err_conceal,
2267
2.60k
                              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.58k
        } else {
2271
2.58k
          if (!p_obj_exhaacplus_dec->aac_config.down_sample_flag) {
2272
1.23k
            sample_rate_1 *= 2;
2273
1.23k
          }
2274
2.58k
          if (p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present == 1) {
2275
2.00k
            p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.pre_mix_req = 1;
2276
2.00k
            ixheaacd_mps_payload(
2277
2.00k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx],
2278
2.00k
              p_obj_exhaacplus_dec);
2279
2.00k
          }
2280
2.58k
        }
2281
2.58k
        {
2282
2.58k
          WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type;
2283
2284
2.58k
          if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) {
2285
518
            WORD32 out_bytes = 0;
2286
518
            ia_dec_data_struct *pstr_dec_data =
2287
518
                (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data;
2288
518
            ixheaacd_samples_sat((WORD8 *)time_data, 2048, 16,
2289
518
                                 pstr_dec_data->str_usac_data.time_sample_vector, &out_bytes, 1);
2290
518
          }
2291
2.58k
        }
2292
2.58k
        if (p_obj_exhaacplus_dec->aac_config.flag_downmix) {
2293
0
          num_channels_1 = 1;
2294
0
        }
2295
2.58k
        if (num_channels_1_t == 1 && num_channels_1 == 2) ps_detected = 1;
2296
11.8k
      } else {
2297
11.8k
        p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present = 1;
2298
11.8k
      }
2299
2300
14.4k
      p_state_enhaacplus_dec->i_bytes_consumed = 0;
2301
14.4k
      p_state_enhaacplus_dec->pstr_bit_buf = it_bit_buff;
2302
2303
14.4k
      {
2304
14.4k
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] =
2305
14.4k
            ixheaacd_aac_decoder_init(
2306
14.4k
                p_state_enhaacplus_dec,
2307
14.4k
                p_state_enhaacplus_dec->pstr_stream_sbr[0], 2,
2308
14.4k
                p_state_enhaacplus_dec->aac_persistent_mem_v,
2309
14.4k
                p_state_enhaacplus_dec->frame_length);
2310
2311
14.4k
        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
14.4k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
2317
2.48k
          WORD32 harmonic_sbr_flag = 0;
2318
2.48k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr(
2319
2.48k
              sample_rate_2, frame_size_2,
2320
2.48k
              (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag,
2321
2.48k
              p_state_enhaacplus_dec->sbr_persistent_mem_v,
2322
2.48k
              p_state_enhaacplus_dec->ptr_overlap_buf, MAXNRSBRCHANNELS, 1, 1,
2323
2.48k
              frame_size_2 * 2, &harmonic_sbr_flag, NULL,
2324
2.48k
              p_state_enhaacplus_dec->str_sbr_config,
2325
2.48k
              p_state_enhaacplus_dec->audio_object_type,
2326
2.48k
              p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2327
2.48k
                .ldmps_present_flag,
2328
2.48k
              p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2329
2.48k
                .no_ldsbr_present);
2330
2.48k
        }
2331
14.4k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
2332
2.48k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
2333
2.48k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
2334
2.48k
        }
2335
14.4k
      }
2336
2337
14.4k
      if (sample_rate < sample_rate_1) sample_rate = sample_rate_1;
2338
2339
14.4k
      ch_idx++;
2340
2341
14.4k
      if (p_state_enhaacplus_dec->audio_object_type >= ER_OBJECT_START &&
2342
5.05k
          (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD ||
2343
2.52k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
2344
1.04k
          p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC))
2345
5.00k
        break;
2346
14.4k
    }
2347
2348
10.5k
    {
2349
10.5k
      ia_adts_crc_info_struct *ptr_adts_crc_info =
2350
10.5k
          p_state_enhaacplus_dec->ptr_bit_stream->pstr_adts_crc_info;
2351
10.5k
      if (ptr_adts_crc_info->crc_active == 1) {
2352
37
        if ((error_code = ixheaacd_adts_crc_check_crc(ptr_adts_crc_info))) {
2353
37
          return error_code;
2354
37
        }
2355
37
      }
2356
10.5k
    }
2357
2358
10.4k
    {
2359
10.4k
      VOID *temp;
2360
10.4k
      WORD prev_persistent_used_t;
2361
10.4k
      WORD prev_sbrpersistent_used_t;
2362
10.4k
      WORD ps_enable;
2363
10.4k
      WORD ch_idx_err = 0;
2364
10.4k
      WORD persistent_used_t = 0;
2365
10.4k
      WORD channel_check = 0;
2366
10.4k
      WORD cc_channel_check = 0;
2367
10.4k
      WORD max_ch_num = p_obj_exhaacplus_dec->aac_config.ui_max_channels;
2368
10.4k
      WORD32 harmonic_sbr_flag = 0;
2369
10.4k
      i = 0;
2370
2371
10.4k
      p_obj_exhaacplus_dec->aac_config.ui_n_channels = ch_idx;
2372
22.7k
      while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx_err] <= 3 &&
2373
23.0k
             p_obj_exhaacplus_dec->aac_config.element_type[ch_idx_err] >= 0) {
2374
12.2k
        ch_idx_err++;
2375
12.2k
      }
2376
2377
10.4k
      if (ch_idx_err == 0) {
2378
14
        p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0;
2379
14
        p_state_enhaacplus_dec->i_bytes_consumed = (WORD32)(
2380
14
            it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base);
2381
14
        return IA_XHEAAC_DEC_INIT_NONFATAL_DECODE_FRAME_ERROR;
2382
14
      }
2383
2384
10.4k
      if (ch_idx_err == 1)
2385
10.2k
        ps_enable = 1;
2386
213
      else
2387
213
        ps_enable = 0;
2388
2389
18.0k
      while (p_obj_exhaacplus_dec->aac_config.element_type[i] >= 0 &&
2390
12.2k
             p_obj_exhaacplus_dec->aac_config.element_type[i] <= 3) {
2391
12.2k
        WORD32 channel = 0;
2392
12.2k
        switch (p_obj_exhaacplus_dec->aac_config.element_type[i]) {
2393
8.06k
          case 0:
2394
9.81k
          case 3:
2395
9.81k
            channel = 1;
2396
9.81k
            break;
2397
2.12k
          case 1:
2398
2.12k
            channel = 2;
2399
2.12k
            break;
2400
296
          case 2:
2401
296
            if (max_ch_num > 2) {
2402
296
              if (p_obj_exhaacplus_dec->aac_config.element_instance_order[i] !=
2403
296
                  p_obj_exhaacplus_dec->aac_config.ui_coupling_channel) {
2404
172
                i++;
2405
172
                continue;
2406
172
              }
2407
124
              channel = 1;
2408
124
            } else {
2409
0
              i++;
2410
0
              continue;
2411
0
            }
2412
124
            cc_channel_check++;
2413
124
            break;
2414
0
          default:
2415
0
            return -1;
2416
12.2k
        }
2417
2418
12.0k
        if (cc_channel_check > MAX_CC_CHANNEL_NUM)
2419
1
          return IA_XHEAAC_DEC_EXE_FATAL_UNIMPLEMENTED_CCE;
2420
12.0k
        if (ps_enable == 1) {
2421
10.2k
          channel = 2;
2422
10.2k
        }
2423
2424
12.0k
        if (p_obj_exhaacplus_dec->aac_config.element_type[i] != 2) {
2425
11.9k
          channel_check += channel;
2426
11.9k
        }
2427
2428
12.0k
        if (channel_check > max_ch_num) {
2429
4
          p_state_enhaacplus_dec->i_bytes_consumed = 1;
2430
4
          return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX;
2431
4
        }
2432
2433
12.0k
        temp = p_state_enhaacplus_dec->aac_persistent_mem_v;
2434
2435
12.0k
        prev_persistent_used_t = persistent_used_t;
2436
2437
12.0k
        ixheaacd_allocate_mem_persistent(
2438
12.0k
            p_obj_exhaacplus_dec, p_state_enhaacplus_dec, channel,
2439
12.0k
            &persistent_used_t, &prev_sbrpersistent_used_t, ps_enable);
2440
2441
12.0k
        p_state_enhaacplus_dec->aac_persistent_mem_v = temp;
2442
12.0k
        p_state_enhaacplus_dec->last_frame_ok = 1;
2443
2444
12.0k
        p_state_enhaacplus_dec->num_channel_last = 0;
2445
12.0k
        p_state_enhaacplus_dec->ui_init_done = 0;
2446
12.0k
        p_state_enhaacplus_dec->ui_input_over = 0;
2447
12.0k
        p_state_enhaacplus_dec->ptr_bit_stream =
2448
12.0k
            p_state_enhaacplus_dec->pstr_bit_buf;
2449
2450
12.0k
        p_state_enhaacplus_dec->pstr_aac_dec_info[i] = 0;
2451
2452
12.0k
        p_state_enhaacplus_dec->pstr_aac_dec_info[i] =
2453
12.0k
            ixheaacd_aac_decoder_init(
2454
12.0k
                p_state_enhaacplus_dec,
2455
12.0k
                p_state_enhaacplus_dec->pstr_stream_sbr[i], channel,
2456
12.0k
                (WORD8 *)p_state_enhaacplus_dec->aac_persistent_mem_v +
2457
12.0k
                    prev_persistent_used_t,
2458
12.0k
                p_state_enhaacplus_dec->frame_length);
2459
2460
12.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
12.0k
        p_state_enhaacplus_dec->str_sbr_dec_info[i] = ixheaacd_init_sbr(
2466
12.0k
            sample_rate_2, frame_size_2,
2467
12.0k
            (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag,
2468
12.0k
            p_state_enhaacplus_dec->sbr_persistent_mem_v,
2469
12.0k
            p_state_enhaacplus_dec->ptr_overlap_buf, channel, ps_enable, 1,
2470
12.0k
            frame_size_2 * 2, &harmonic_sbr_flag, NULL,
2471
12.0k
            p_state_enhaacplus_dec->str_sbr_config,
2472
12.0k
            p_state_enhaacplus_dec->audio_object_type,
2473
12.0k
            p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2474
12.0k
                .ldmps_present_flag,
2475
12.0k
            p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2476
12.0k
                .no_ldsbr_present);
2477
12.0k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[i]) {
2478
11.9k
          p_state_enhaacplus_dec->str_sbr_dec_info[i]->xaac_jmp_buf =
2479
11.9k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
2480
11.9k
        }
2481
12.0k
        if ((sbr_present_flag &&
2482
2.51k
            ((p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
2483
2.51k
              AOT_AAC_LC) ||
2484
2.02k
             (p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
2485
2.02k
              AOT_SBR) ||
2486
2.02k
             (p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
2487
2.02k
               AOT_PS))) ||
2488
11.5k
            ((p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
2489
11.5k
                  .ldmps_present_flag == 1) &&
2490
385
             (p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
2491
385
              AOT_ER_AAC_ELD)))
2492
882
          p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 1;
2493
12.0k
        copy_qmf_to_ldmps(&p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle,
2494
12.0k
                          p_state_enhaacplus_dec->sbr_persistent_mem_v);
2495
12.0k
        if (p_state_enhaacplus_dec->audio_object_type == AOT_AAC_LC &&
2496
6.21k
            p_state_enhaacplus_dec->ui_mps_out_bytes != 0) {
2497
4.63k
          p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present = 1;
2498
4.63k
          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
4.63k
          error_code =
2502
4.63k
              ixheaacd_aac_mps_init(p_obj_exhaacplus_dec, mps_buffer,
2503
4.63k
                                    p_state_enhaacplus_dec->ui_mps_out_bytes, sample_rate_1);
2504
4.63k
          if (error_code) return error_code;
2505
4.55k
          p_obj_exhaacplus_dec->aac_config.ui_n_channels =
2506
4.55k
              p_state_enhaacplus_dec->heaac_mps_handle.num_output_channels_at;
2507
4.55k
          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
4.55k
          if (p_obj_exhaacplus_dec->aac_config.element_type[i + 1] >= 0 &&
2511
1
              p_obj_exhaacplus_dec->aac_config.element_type[i + 1] <= 3) {
2512
1
            return IA_FATAL_ERROR;
2513
1
          }
2514
4.55k
          break;
2515
4.55k
        }
2516
7.42k
        i++;
2517
7.42k
      }
2518
10.3k
      p_state_enhaacplus_dec->pers_mem_ptr =
2519
10.3k
          (WORD8 *)p_state_enhaacplus_dec->aac_persistent_mem_v +
2520
10.3k
          persistent_used_t;
2521
2522
10.3k
      p_obj_exhaacplus_dec->aac_config.i_channel_mask =
2523
10.3k
          ixheaacd_get_channel_mask(p_obj_exhaacplus_dec);
2524
2525
10.3k
      {
2526
10.3k
        num_channels_1 = 0;
2527
10.3k
        ch_idx = 0;
2528
22.4k
        while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] >= 0 &&
2529
12.0k
               p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] <= 3) {
2530
12.0k
          if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 0 ||
2531
4.15k
              p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 3)
2532
9.67k
            num_channels_1 += 1;
2533
12.0k
          if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 1)
2534
2.11k
            num_channels_1 += 2;
2535
12.0k
          ch_idx++;
2536
12.0k
        }
2537
2538
10.3k
        if (ch_idx == 2 && num_channels_1 == 2) {
2539
189
          p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 2;
2540
189
        }
2541
10.3k
        if (ch_idx == 1) {
2542
10.1k
          if (num_channels_1 == 1)
2543
8.17k
            p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 0;
2544
10.1k
          if (num_channels_1 == 2)
2545
1.92k
            p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 1;
2546
10.1k
        }
2547
2548
10.3k
        if (ps_detected == 1 && num_channels_1 == 1) num_channels_1 = 2;
2549
10.3k
      }
2550
10.3k
    }
2551
10.3k
    if (1 == p_obj_exhaacplus_dec->aac_config.downmix) num_channels_1 = 2;
2552
2553
10.3k
    if (p_obj_exhaacplus_dec->aac_config.flag_downmix == 1) {
2554
0
      num_channels_1 = 1;
2555
0
    }
2556
2557
10.3k
    if ((p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1) &&
2558
788
        (ch_idx == 1 || num_channels_1 <= 2)) {
2559
751
      num_channels_1 = 2;
2560
751
    }
2561
2562
10.3k
    p_obj_exhaacplus_dec->aac_config.ui_n_channels = num_channels_1;
2563
10.3k
    p_obj_exhaacplus_dec->aac_config.ui_samp_freq = sample_rate;
2564
10.3k
    p_state_enhaacplus_dec->ui_init_done = 1;
2565
2566
10.3k
    memcpy(it_bit_buff, &temp_bit_buff, sizeof(struct ia_bit_buf_struct));
2567
2568
10.3k
    p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
2569
2570
10.7k
    if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 1) {
2571
10.7k
      p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0;
2572
10.7k
    }
2573
10.3k
  }
2574
23.1k
  return err_code;
2575
31.6k
}
2576
2577
VOID ixheaacd_fill_slot_order(ia_aac_dec_state_struct *p_state_enhaacplus_dec,
2578
                              WORD32 ch, WORD8 *ptr_is_cpe,
2579
12.0k
                              WORD8 *ptr_tag_select, WORD32 *ptr_idx_no) {
2580
12.0k
  WORD32 i;
2581
12.0k
  WORD32 idx_no = *ptr_idx_no;
2582
12.0k
  WORD *p_slot_element = p_state_enhaacplus_dec->p_config->slot_element;
2583
12.0k
  WORD *p_element_type = p_state_enhaacplus_dec->p_config->element_type;
2584
12.0k
  WORD *p_element_instance_order =
2585
12.0k
      p_state_enhaacplus_dec->p_config->element_instance_order;
2586
2587
18.4k
  for (i = 0; i < ch; i++) {
2588
6.43k
    if (ptr_is_cpe[i] == 0) {
2589
2.98k
      *p_slot_element++ = idx_no++;
2590
2.98k
      *p_element_type++ = 0;
2591
2.98k
      *p_element_instance_order++ = ptr_tag_select[i];
2592
2.98k
    }
2593
6.43k
  }
2594
12.0k
  *ptr_idx_no = idx_no;
2595
12.0k
}
2596
2597
VOID ixheaacd_fill_prog_config_slots(
2598
4.01k
    ia_aac_dec_state_struct *p_state_enhaacplus_dec) {
2599
4.01k
  WORD32 idx_no = 0;
2600
2601
4.01k
  ixheaacd_fill_slot_order(
2602
4.01k
      p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config
2603
4.01k
                                  .num_front_channel_elements,
2604
4.01k
      p_state_enhaacplus_dec->p_config->str_prog_config.front_element_is_cpe,
2605
4.01k
      p_state_enhaacplus_dec->p_config->str_prog_config
2606
4.01k
          .front_element_tag_select,
2607
4.01k
      &idx_no);
2608
2609
4.01k
  ixheaacd_fill_slot_order(
2610
4.01k
      p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config
2611
4.01k
                                  .num_side_channel_elements,
2612
4.01k
      p_state_enhaacplus_dec->p_config->str_prog_config.side_element_is_cpe,
2613
4.01k
      p_state_enhaacplus_dec->p_config->str_prog_config.side_element_tag_select,
2614
4.01k
      &idx_no);
2615
2616
4.01k
  ixheaacd_fill_slot_order(
2617
4.01k
      p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config
2618
4.01k
                                  .num_back_channel_elements,
2619
4.01k
      p_state_enhaacplus_dec->p_config->str_prog_config.back_element_is_cpe,
2620
4.01k
      p_state_enhaacplus_dec->p_config->str_prog_config.back_element_tag_select,
2621
4.01k
      &idx_no);
2622
4.01k
}
2623
2624
IA_ERRORCODE ixheaacd_dec_execute(
2625
516k
    ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) {
2626
516k
  ia_adts_header_struct adts = {0};
2627
516k
  ia_aac_dec_state_struct *p_state_enhaacplus_dec;
2628
2629
516k
  UWORD8 *in_buffer;
2630
516k
  WORD16 *time_data;
2631
516k
  WORD16 num_of_out_samples = 0;
2632
516k
  WORD16 frame_size = 0;
2633
516k
  WORD32 sample_rate_dec = 0;
2634
516k
  WORD32 sample_rate = 0;
2635
516k
  WORD16 num_ch = 0;
2636
516k
  struct ia_bit_buf_struct *it_bit_buff;
2637
516k
  UWORD8 *mps_buffer;
2638
516k
  WORD32 error_code = IA_NO_ERROR;
2639
516k
  WORD ch_idx1;
2640
516k
  WORD type;
2641
516k
  WORD total_channels = 0;
2642
516k
  WORD total_elements = 0;
2643
516k
  WORD16 *actual_out_buffer = NULL;
2644
516k
  WORD ps_enable;
2645
516k
  WORD esbr_mono_downmix = 0;
2646
516k
  WORD8 element_used[MAX_BS_ELEMENT];
2647
516k
  WORD32 channel_coupling_flag = 0;
2648
2649
516k
  SIZE_T bytes_for_sync;
2650
516k
  WORD32 audio_mux_length_bytes_last = 0;
2651
516k
  WORD32 ret_val;
2652
516k
  WORD32 mps_out_samples;
2653
2654
516k
  p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0;
2655
516k
  p_obj_exhaacplus_dec->aac_config.frame_status = 1;
2656
2657
516k
  if (p_obj_exhaacplus_dec->p_state_aac != NULL) {
2658
516k
    ret_val = setjmp(p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf);
2659
516k
    if (ret_val != 0) {
2660
5.48k
      p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
2661
5.48k
          p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
2662
5.48k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
2663
5.48k
      p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2664
5.48k
      return IA_NO_ERROR;
2665
5.48k
    }
2666
516k
  }
2667
2668
511k
  time_data = (WORD16 *)(p_obj_exhaacplus_dec
2669
511k
                             ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]);
2670
511k
  in_buffer = p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX];
2671
511k
  p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac;
2672
511k
  p_state_enhaacplus_dec->aac_scratch_mem_v =
2673
511k
      p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX];
2674
511k
  p_state_enhaacplus_dec->mps_header = -1;
2675
511k
  mps_buffer = p_state_enhaacplus_dec->mps_buffer;
2676
511k
  it_bit_buff = p_state_enhaacplus_dec->pstr_bit_buf;
2677
2678
511k
  ch_idx1 = 0;
2679
511k
  p_state_enhaacplus_dec->i_bytes_consumed = 0;
2680
2681
511k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_USAC) {
2682
245k
    WORD32 pcm_size = p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz;
2683
245k
    WORD8 *inbuffer = (WORD8 *)(p_obj_exhaacplus_dec
2684
245k
                                    ->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]);
2685
245k
    WORD8 *outbuffer =
2686
245k
        (WORD8 *)(p_obj_exhaacplus_dec
2687
245k
                      ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]);
2688
245k
    WORD32 out_bytes = 0;
2689
2690
245k
    WORD32 frames_done = p_obj_exhaacplus_dec->p_state_aac->frame_counter;
2691
2692
245k
    ia_dec_data_struct *pstr_dec_data =
2693
245k
        (ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac
2694
245k
                                   ->pstr_dec_data);
2695
2696
245k
    if (pstr_dec_data->str_usac_data.down_samp_sbr != 0) return IA_FATAL_ERROR;
2697
2698
245k
    if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 0) {
2699
245k
      ia_audio_specific_config_struct *ptr_audio_specific_config =
2700
245k
          ((ia_audio_specific_config_struct *)
2701
245k
               p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config);
2702
2703
245k
      ptr_audio_specific_config->str_usac_config.str_usac_dec_config
2704
245k
          .preroll_counter = 0;
2705
245k
      {
2706
245k
        WORD32 iii = 0;
2707
1.22M
        for (iii = 0; iii < (MAX_AUDIO_PREROLLS + 1); iii++) {
2708
980k
          ((ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac
2709
980k
                                      ->pstr_dec_data))
2710
980k
              ->str_frame_data.str_audio_specific_config.str_usac_config
2711
980k
              .str_usac_dec_config.usac_ext_gain_payload_len[iii] = 0;
2712
980k
          ptr_audio_specific_config->str_usac_config.str_usac_dec_config
2713
980k
              .usac_ext_gain_payload_len[iii] =
2714
980k
              0;  // reinitilize the payload len buff
2715
980k
          ptr_audio_specific_config->str_usac_config.str_usac_dec_config
2716
980k
              .preroll_bytes[iii] = 0;
2717
980k
        }
2718
245k
      }
2719
2720
245k
      ((ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data))
2721
245k
          ->str_frame_data.str_audio_specific_config.str_usac_config
2722
245k
          .str_usac_dec_config.preroll_counter = 0;
2723
245k
      error_code = ixheaacd_dec_main(
2724
245k
          p_obj_exhaacplus_dec, inbuffer, outbuffer, &out_bytes, frames_done,
2725
245k
          pcm_size, &p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch);
2726
245k
      if (error_code) {
2727
1.64k
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2728
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2729
1.64k
        } else {
2730
1.64k
          return error_code;
2731
1.64k
        }
2732
1.64k
      }
2733
243k
      p_obj_exhaacplus_dec->p_state_aac->frame_counter++;
2734
243k
    } else {
2735
0
      out_bytes = 0;
2736
0
    }
2737
2738
243k
    if (pstr_dec_data->str_usac_data.ec_flag == 0) {
2739
240k
      if (p_state_enhaacplus_dec->bs_format != LOAS_BSFORMAT) {
2740
1.20k
        p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed =
2741
1.20k
            p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes;
2742
1.20k
      }
2743
240k
    } else {
2744
2.78k
      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.78k
    }
2767
2768
243k
    p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = out_bytes;
2769
243k
    p_obj_exhaacplus_dec->aac_config.ui_n_channels =
2770
243k
        p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch;
2771
243k
    pstr_dec_data->str_usac_data.sbr_parse_err_flag = 0;
2772
2773
243k
    return 0;
2774
245k
  }
2775
2776
560k
  while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] <= 3 &&
2777
566k
         p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] >= 0) {
2778
294k
    if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 0 ||
2779
235k
        p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 3) {
2780
235k
      total_channels += 1;
2781
235k
      total_elements += 1;
2782
235k
    }
2783
294k
    if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 1) {
2784
57.7k
      total_elements += 1;
2785
57.7k
      total_channels += 2;
2786
57.7k
    }
2787
294k
    if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 2) {
2788
1.46k
      total_elements += 1;
2789
1.46k
    }
2790
2791
294k
    ch_idx1++;
2792
294k
    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
294k
  }
2799
2800
266k
  if (ch_idx1 != 1) {
2801
13.7k
    ps_enable = 0;
2802
13.7k
    if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
2803
13.7k
      WORD32 scratch_pointer;
2804
2805
13.7k
      scratch_pointer = (MAX_SCR_SIZE - SCR_INTER_SCR_SIZE);
2806
2807
13.7k
      p_state_enhaacplus_dec->coup_ch_output =
2808
13.7k
          (WORD32 *)((WORD8 *)
2809
13.7k
                         p_obj_exhaacplus_dec->p_state_aac->aac_scratch_mem_v +
2810
13.7k
                     scratch_pointer);
2811
13.7k
    }
2812
2813
13.7k
  }
2814
2815
252k
  else {
2816
252k
    if (total_channels < (WORD)p_obj_exhaacplus_dec->aac_config.ui_n_channels)
2817
28.9k
      total_channels = p_obj_exhaacplus_dec->aac_config.ui_n_channels;
2818
252k
    ps_enable = 1;
2819
252k
  }
2820
2821
266k
  p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0;
2822
266k
  p_obj_exhaacplus_dec->p_state_aac->ui_mps_out_bytes = 0;
2823
266k
  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
266k
  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
266k
  if (total_channels > (WORD)p_obj_exhaacplus_dec->aac_config.ui_max_channels) {
2883
18
    p_state_enhaacplus_dec->i_bytes_consumed = 1;
2884
18
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2885
0
      p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2886
18
    } else {
2887
18
      return IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MAX_CHANNEL;
2888
18
    }
2889
18
  }
2890
2891
266k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD ||
2892
181k
      p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) {
2893
162k
    if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag)
2894
383
      p_state_enhaacplus_dec->frame_size = p_state_enhaacplus_dec->ui_in_bytes;
2895
162k
  }
2896
2897
266k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) {
2898
52.8k
    if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag)
2899
69
      p_state_enhaacplus_dec->frame_size = 1024;
2900
52.8k
  }
2901
2902
266k
  {
2903
266k
    ixheaacd_create_init_bit_buf(it_bit_buff, in_buffer,
2904
266k
                                 p_state_enhaacplus_dec->ui_in_bytes);
2905
266k
    it_bit_buff->xaac_jmp_buf = &(p_state_enhaacplus_dec->xaac_jmp_buf);
2906
2907
266k
    it_bit_buff->adts_header_present =
2908
266k
        p_state_enhaacplus_dec->s_adts_hdr_present;
2909
266k
    it_bit_buff->no_raw_data_blocks =
2910
266k
        (WORD8)p_state_enhaacplus_dec->b_n_raw_data_blk;
2911
266k
    it_bit_buff->protection_absent = p_state_enhaacplus_dec->protection_absent;
2912
2913
266k
    if (p_state_enhaacplus_dec->s_adts_hdr_present) {
2914
43.6k
      if (p_state_enhaacplus_dec->b_n_raw_data_blk == 0) {
2915
41.6k
        WORD32 error;
2916
2917
41.6k
        error = ixheaacd_readifadts(p_state_enhaacplus_dec, it_bit_buff, &adts);
2918
41.6k
        if (error) {
2919
1.42k
          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.42k
          } else {
2925
1.42k
            return error;
2926
1.42k
          }
2927
1.42k
        }
2928
2929
40.2k
        if ((WORD32)p_state_enhaacplus_dec->sampling_rate !=
2930
40.2k
            (WORD32)((p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables
2931
40.2k
                          ->str_sample_rate_info[adts.samp_freq_index]
2932
40.2k
                          .sampling_frequency))) {
2933
29
          p_state_enhaacplus_dec->i_bytes_consumed = 0;
2934
29
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2935
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2936
29
          } else {
2937
29
            return IA_XHEAAC_DEC_EXE_NONFATAL_CHANGED_ADTS_SF;
2938
29
          }
2939
29
        }
2940
40.2k
      }
2941
43.6k
    }
2942
2943
264k
    bytes_for_sync = (SIZE_T)it_bit_buff->ptr_read_next;
2944
2945
264k
    if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) {
2946
226k
      WORD32 result, audio_mux_len_bytes_last;
2947
226k
      WORD32 cnt_bits = it_bit_buff->cnt_bits;
2948
226k
      WORD32 sync = ixheaacd_read_bits_buf(it_bit_buff, 11);
2949
226k
      UWORD32 curr_samp_rate = 0;
2950
2951
226k
      if (p_state_enhaacplus_dec->latm_initialized)
2952
221k
        curr_samp_rate =
2953
221k
            p_state_enhaacplus_dec->latm_struct_element.layer_info[0][0]
2954
221k
                .asc.sampling_freq;
2955
2956
148M
      while (sync != 0x2b7) {
2957
148M
        sync = ((sync & 0x3ff) << 1) | ixheaacd_read_bits_buf(it_bit_buff, 1);
2958
148M
        if (it_bit_buff->cnt_bits < 13) {
2959
1.39k
          ixheaacd_read_bidirection(it_bit_buff, -11);
2960
1.39k
          p_state_enhaacplus_dec->i_bytes_consumed =
2961
1.39k
              (cnt_bits - it_bit_buff->cnt_bits) / 8;
2962
2963
1.39k
          if (p_state_enhaacplus_dec->i_bytes_consumed == 0)
2964
42
            p_state_enhaacplus_dec->i_bytes_consumed = 1;
2965
1.39k
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2966
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2967
1.39k
          } else {
2968
1.39k
            return (IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START);
2969
1.39k
          }
2970
1.39k
        }
2971
148M
      }
2972
2973
224k
      it_bit_buff->audio_mux_align = it_bit_buff->cnt_bits - 13;
2974
2975
224k
      audio_mux_len_bytes_last = ixheaacd_read_bits_buf(it_bit_buff, 13);
2976
2977
224k
      audio_mux_length_bytes_last = audio_mux_len_bytes_last;
2978
2979
224k
      bytes_for_sync = (SIZE_T)it_bit_buff->ptr_read_next - bytes_for_sync;
2980
2981
224k
      if (it_bit_buff->cnt_bits < (audio_mux_len_bytes_last << 3)) {
2982
995
        ixheaacd_read_bidirection(it_bit_buff, -(13 + 11));
2983
995
        p_state_enhaacplus_dec->i_bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8;
2984
995
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
2985
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
2986
995
        } else {
2987
995
          return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
2988
995
        }
2989
223k
      } else {
2990
223k
        ixheaacd_read_bidirection(it_bit_buff, -(13));
2991
223k
      }
2992
2993
223k
      if (sync == 0x2b7) {
2994
223k
        result = ixheaacd_latm_audio_mux_element(
2995
223k
            it_bit_buff, &p_state_enhaacplus_dec->latm_struct_element,
2996
223k
            p_state_enhaacplus_dec,
2997
223k
            (ia_sampling_rate_info_struct *)&p_obj_exhaacplus_dec->aac_tables
2998
223k
                .pstr_huffmann_tables->str_sample_rate_info[0]);
2999
223k
        if (result < 0) {
3000
565
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3001
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3002
565
          } else {
3003
565
            return result;
3004
565
          }
3005
565
        }
3006
223k
        if (!p_state_enhaacplus_dec->latm_initialized) {
3007
5.23k
          p_state_enhaacplus_dec->sampling_rate =
3008
5.23k
              p_state_enhaacplus_dec->latm_struct_element.layer_info[0][0].asc.sampling_freq;
3009
5.23k
          p_state_enhaacplus_dec->latm_initialized = 1;
3010
218k
        } else {
3011
218k
          if (p_state_enhaacplus_dec->sampling_rate != curr_samp_rate) {
3012
123
            p_state_enhaacplus_dec->i_bytes_consumed = 0;
3013
123
            if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3014
0
              p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3015
123
            } else {
3016
123
              return IA_XHEAAC_DEC_EXE_NONFATAL_CHANGED_ADTS_SF;
3017
123
            }
3018
123
          }
3019
218k
        }
3020
223k
      }
3021
223k
    }
3022
264k
  }
3023
3024
261k
  if (total_elements == 2 && total_channels == 2 &&
3025
8.77k
      (p_state_enhaacplus_dec->p_config->ui_pce_found_in_hdr == 1 ||
3026
7.15k
       p_state_enhaacplus_dec->p_config->ui_pce_found_in_hdr == 3)) {
3027
3.26k
    ixheaacd_fill_prog_config_slots(p_state_enhaacplus_dec);
3028
3.26k
  }
3029
3030
261k
  memset(element_used, 0, sizeof(WORD8) * MAX_BS_ELEMENT);
3031
3032
261k
  if (it_bit_buff->cnt_bits <= 0) {
3033
17
    it_bit_buff->cnt_bits = -1;
3034
17
    ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
3035
17
    if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3036
0
      p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3037
17
    } else {
3038
17
      return (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
3039
17
    }
3040
17
  }
3041
3042
261k
  { it_bit_buff->initial_cnt_bits = it_bit_buff->cnt_bits; }
3043
3044
261k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD) {
3045
88.5k
    if (p_state_enhaacplus_dec->s_adts_hdr_present)
3046
0
      p_state_enhaacplus_dec->frame_size = adts.aac_frame_length;
3047
88.5k
  }
3048
3049
261k
  if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) {
3050
52.3k
    if (p_state_enhaacplus_dec->s_adts_hdr_present)
3051
0
      p_state_enhaacplus_dec->frame_size = 1024;
3052
52.3k
  }
3053
3054
266k
  if (p_state_enhaacplus_dec->pstr_drc_dec) {
3055
266k
    p_state_enhaacplus_dec->pstr_drc_dec->num_drc_elements = 0;
3056
3057
266k
    p_state_enhaacplus_dec->pstr_drc_dec->state = 1;
3058
266k
  }
3059
261k
  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
261k
  WORD16 *intermediate_scr = (WORD16 *)(WORD8 *)p_state_enhaacplus_dec->aac_scratch_mem_v +
3066
261k
                             (MAX_SCR_SIZE - SCR_INTER_SCR_SIZE - SCR_COUP_CH_OUT_SIZE);
3067
3068
535k
  for (ch_idx1 = 0; ch_idx1 < total_elements; ch_idx1++) {
3069
282k
    WORD32 skip_full_decode = 0;
3070
282k
    WORD32 ch_idx = ch_idx1;
3071
282k
    WORD32 channel = 0;
3072
282k
    WORD ch_fac, slot_ele;
3073
3074
282k
    if (p_state_enhaacplus_dec->audio_object_type < ER_OBJECT_START ||
3075
211k
        (p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LD &&
3076
123k
         p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_ELD &&
3077
70.9k
         p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LC)) {
3078
70.9k
      jmp_buf local;
3079
3080
70.9k
      if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal == 1) {
3081
0
        ret_val = setjmp(local);
3082
0
      }
3083
70.9k
      if (ret_val == 0) {
3084
70.9k
        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
70.9k
        error_code = ixheaacd_get_element_index_tag(
3088
70.9k
            p_obj_exhaacplus_dec, ch_idx1, &ch_idx, &channel,
3089
70.9k
            p_obj_exhaacplus_dec->aac_config.element_instance_order, total_elements, element_used,
3090
70.9k
            total_channels, p_state_enhaacplus_dec->pstr_drc_dec,
3091
70.9k
            &p_state_enhaacplus_dec->drc_dummy, mps_buffer, &p_state_enhaacplus_dec->mps_header,
3092
70.9k
            &p_state_enhaacplus_dec->ui_mps_out_bytes);
3093
70.9k
      }
3094
3095
70.9k
      if (error_code || ret_val) {
3096
2.77k
        ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
3097
2.77k
        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.77k
        p_state_enhaacplus_dec->i_bytes_consumed = 1;
3103
2.77k
        p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
3104
2.77k
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3105
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3106
2.77k
        } else {
3107
2.77k
          return error_code;
3108
2.77k
        }
3109
2.77k
      }
3110
68.1k
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == ID_CPE)
3111
1.38k
      {
3112
1.38k
        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.38k
      }
3125
66.7k
      else
3126
66.7k
      {
3127
66.7k
        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
66.7k
      }
3140
211k
    } else {
3141
211k
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == ID_SCE)
3142
157k
        channel = 1;
3143
53.9k
      else
3144
53.9k
        channel = 2;
3145
211k
    }
3146
3147
279k
    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
279k
    ch_fac = total_channels;
3177
279k
    slot_ele = p_obj_exhaacplus_dec->aac_config.slot_element[ch_idx];
3178
279k
    actual_out_buffer = time_data;
3179
279k
    if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 2) {
3180
510
      p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info =
3181
510
          &p_state_enhaacplus_dec->ind_cc_info;
3182
510
      if (p_obj_exhaacplus_dec->aac_config.element_instance_order[ch_idx] !=
3183
510
          p_obj_exhaacplus_dec->aac_config.ui_coupling_channel) {
3184
204
        skip_full_decode = 1;
3185
204
        ixheaacd_set_aac_persistent_buffers(
3186
204
            p_state_enhaacplus_dec->pers_mem_ptr, channel);
3187
3188
204
        {
3189
204
          struct ia_aac_persistent_struct *aac_persistent_mem =
3190
204
              (struct ia_aac_persistent_struct *)
3191
204
                  p_state_enhaacplus_dec->pers_mem_ptr;
3192
204
          aac_persistent_mem->str_aac_decoder.pstr_aac_tables =
3193
204
              &p_obj_exhaacplus_dec->aac_tables;
3194
204
          aac_persistent_mem->str_aac_decoder.pstr_common_tables =
3195
204
              p_obj_exhaacplus_dec->common_tables;
3196
204
        }
3197
3198
204
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] = 0;
3199
3200
204
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0;
3201
3202
204
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] =
3203
204
            ixheaacd_aac_decoder_init(
3204
204
                p_state_enhaacplus_dec,
3205
3206
204
                p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx],
3207
3208
204
                channel, p_state_enhaacplus_dec->pers_mem_ptr,
3209
204
                p_state_enhaacplus_dec->frame_length
3210
3211
204
                );
3212
204
        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
204
        p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info =
3221
204
            (WORD8 *)p_state_enhaacplus_dec->aac_scratch_mem_v + (P_IND_CH_INFO_OFFSET);
3222
204
      }
3223
510
      if (p_obj_exhaacplus_dec->aac_config.element_type[1] < 3 &&
3224
413
          p_obj_exhaacplus_dec->aac_config.element_type[1] > 0 &&
3225
107
          p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) {
3226
107
        actual_out_buffer =
3227
107
            (WORD16 *)(VOID *)p_state_enhaacplus_dec->coup_ch_output;
3228
107
      }
3229
510
      ch_fac = 1;
3230
510
      slot_ele = 0;
3231
510
    }
3232
3233
279k
    type = -1;
3234
279k
    p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements = 0;
3235
3236
279k
    {
3237
279k
      WORD element_index_order1[MAX_BS_ELEMENT];
3238
279k
      ia_aac_dec_scratch_struct aac_scratch_struct;
3239
279k
      memset(&aac_scratch_struct, 0, sizeof(aac_scratch_struct));
3240
3241
279k
      ixheaacd_allocate_aac_scr(
3242
279k
          &aac_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v,
3243
279k
          time_data, channel, p_obj_exhaacplus_dec->aac_config.ui_max_channels,
3244
279k
          p_state_enhaacplus_dec->audio_object_type);
3245
3246
279k
      if (p_state_enhaacplus_dec->ch_config == 2 && channel == 1) {
3247
77
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3248
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3249
77
        } else {
3250
77
          return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR;
3251
77
        }
3252
77
      }
3253
3254
279k
      error_code = ixheaacd_aacdec_decodeframe(
3255
279k
          p_obj_exhaacplus_dec, &aac_scratch_struct, actual_out_buffer,
3256
279k
          p_obj_exhaacplus_dec->aac_config.frame_status, &type, &ch_idx, 0, channel,
3257
279k
          element_index_order1, skip_full_decode, ch_fac, slot_ele,
3258
279k
          p_obj_exhaacplus_dec->aac_config.ui_max_channels, total_channels,
3259
279k
          p_obj_exhaacplus_dec->p_state_aac->frame_length,
3260
279k
          p_obj_exhaacplus_dec->p_state_aac->frame_size, p_state_enhaacplus_dec->pstr_drc_dec,
3261
279k
          p_state_enhaacplus_dec->audio_object_type, p_state_enhaacplus_dec->ch_config,
3262
279k
          p_state_enhaacplus_dec->eld_specific_config, p_state_enhaacplus_dec->s_adts_hdr_present,
3263
279k
          &p_state_enhaacplus_dec->drc_dummy, p_state_enhaacplus_dec->ldmps_present,
3264
279k
          &p_state_enhaacplus_dec->slot_pos, mps_buffer, &p_state_enhaacplus_dec->mps_header,
3265
279k
          &p_state_enhaacplus_dec->ui_mps_out_bytes, 0,
3266
279k
          p_obj_exhaacplus_dec->aac_config.first_frame);
3267
3268
279k
      p_state_enhaacplus_dec->slot_pos -= (channel - 1);
3269
279k
      p_state_enhaacplus_dec->sbr_present = 0;
3270
3271
279k
      if (p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ &&
3272
211k
          p_state_enhaacplus_dec->frame_counter == 0) {
3273
8.84k
        ixheaacd_peak_limiter_init(
3274
8.84k
            &p_state_enhaacplus_dec->peak_limiter, total_channels,
3275
8.84k
            p_obj_exhaacplus_dec->p_state_aac->p_config->ui_samp_freq,
3276
8.84k
            &p_state_enhaacplus_dec->peak_limiter.buffer[0],
3277
8.84k
            &p_obj_exhaacplus_dec->p_state_aac->delay_in_samples);
3278
8.84k
        p_obj_exhaacplus_dec->p_state_aac->peak_lim_init = 1;
3279
8.84k
      }
3280
3281
279k
      if (p_state_enhaacplus_dec->audio_object_type < ER_OBJECT_START ||
3282
210k
          (p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LD &&
3283
122k
           p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_ELD &&
3284
67.6k
           p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LC)) {
3285
67.6k
        if ((error_code == 0) && ((ch_idx1 + 1) == total_elements) &&
3286
50.8k
            (type != ID_END)) {
3287
819
          {
3288
819
            p_state_enhaacplus_dec->i_bytes_consumed = (WORD32)(
3289
819
                it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base);
3290
819
            p_state_enhaacplus_dec->b_n_raw_data_blk = 0;
3291
819
            if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3292
0
              p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3293
819
            } else {
3294
819
            return IA_XHEAAC_DEC_EXE_NONFATAL_ELE_INSTANCE_TAG_NOT_FOUND;
3295
819
          }
3296
819
          }
3297
819
        }
3298
67.6k
      }
3299
3300
278k
      num_ch = p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->channels;
3301
278k
      if (skip_full_decode == 0) {
3302
277k
        if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD ||
3303
206k
            p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD)
3304
158k
          frame_size = p_state_enhaacplus_dec->frame_length;
3305
118k
        else {
3306
118k
          frame_size = p_state_enhaacplus_dec->frame_length;
3307
118k
        }
3308
3309
277k
        sample_rate_dec =
3310
277k
            p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->sampling_rate;
3311
277k
      }
3312
278k
    }
3313
3314
278k
    if (skip_full_decode == 1) {
3315
194
      p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements = 0;
3316
194
    }
3317
3318
278k
    if (p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements != 0) {
3319
55.3k
      p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 1;
3320
55.3k
    }
3321
3322
278k
    if (error_code) {
3323
4.35k
      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
4.35k
      ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
3331
4.35k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes +=
3332
4.35k
          p_state_enhaacplus_dec->num_of_out_samples * num_ch * sizeof(WORD16);
3333
4.35k
      if (error_code) {
3334
4.35k
        if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3335
0
          p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3336
4.35k
        } else {
3337
4.35k
          return error_code;
3338
4.35k
        }
3339
4.35k
      }
3340
4.35k
    }
3341
3342
274k
    error_code = IA_NO_ERROR;
3343
3344
274k
    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
274k
    if ((!p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) &&
3352
3.10k
        p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements) {
3353
33
      WORD32 harmonic_sbr_flag = 0;
3354
33
      error_code = IA_XHEAAC_DEC_EXE_NONFATAL_SBR_TURNED_ON;
3355
33
      p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr(
3356
33
          sample_rate_dec, frame_size,
3357
33
          (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag,
3358
33
          p_state_enhaacplus_dec->sbr_persistent_mem_v,
3359
33
          p_state_enhaacplus_dec->ptr_overlap_buf, ps_enable ? 2 : channel,
3360
33
          ps_enable, 1, frame_size * 2, &harmonic_sbr_flag, NULL,
3361
33
          p_state_enhaacplus_dec->str_sbr_config,
3362
33
          p_state_enhaacplus_dec->audio_object_type,
3363
33
          p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
3364
33
              .ldmps_present_flag,
3365
33
          p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present);
3366
33
      if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
3367
5
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
3368
5
            &(p_state_enhaacplus_dec->xaac_jmp_buf);
3369
5
      }
3370
33
    }
3371
3372
274k
    {
3373
274k
      if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] &&
3374
270k
          p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) {
3375
55.1k
        ia_sbr_scr_struct sbr_scratch_struct;
3376
55.1k
        ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v,
3377
55.1k
                                  time_data, total_channels,
3378
55.1k
                                  p_obj_exhaacplus_dec->p_state_aac->qshift_adj,
3379
55.1k
                                  p_state_enhaacplus_dec->slot_pos, channel);
3380
3381
55.1k
        p_state_enhaacplus_dec->sbr_present = 1;
3382
55.1k
        p_state_enhaacplus_dec->peak_lim_init = 0;
3383
3384
55.1k
        if (p_obj_exhaacplus_dec->aac_config.ui_enh_sbr)
3385
55.1k
        {
3386
55.1k
          WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type;
3387
3388
55.1k
          if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) {
3389
21.8k
            WORD32 i = 0;
3390
21.8k
            ia_dec_data_struct* pstr_dec_data =
3391
21.8k
                (ia_dec_data_struct*)p_state_enhaacplus_dec->pstr_dec_data;
3392
21.8k
            if (ch_fac == 1) {
3393
1.74M
              for (; i < 1024; i++) {
3394
1.74M
                pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
3395
1.74M
                    (FLOAT32)time_data[i];
3396
1.74M
              }
3397
1.70k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
3398
1.70k
                  &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
3399
3400
1.70k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
3401
1.70k
                  &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
3402
20.1k
            } else if (ch_fac == 2) {
3403
20.4M
              for (; i < 1024; i++) {
3404
20.4M
                pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
3405
20.4M
                    (FLOAT32)time_data[2 * i + 0];
3406
20.4M
                pstr_dec_data->str_usac_data.time_sample_vector[1][i] =
3407
20.4M
                    (FLOAT32)time_data[2 * i + 1];
3408
20.4M
              }
3409
19.9k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
3410
19.9k
                  &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
3411
3412
19.9k
              p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
3413
19.9k
                  &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
3414
19.9k
            } else if (ch_fac > 2) {
3415
148
              if (channel == 1) {
3416
115k
                for (; i < 1024; i++) {
3417
115k
                  pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
3418
115k
                      (FLOAT32)(time_data + slot_ele)[i* ch_fac];
3419
115k
                }
3420
113
                p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
3421
113
                    &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
3422
113
              } else if (channel == 2) {
3423
35.8k
                for (; i < 1024; i++) {
3424
35.8k
                  pstr_dec_data->str_usac_data.time_sample_vector[0][i] =
3425
35.8k
                      (FLOAT32)(time_data + slot_ele)[ch_fac * i + 0];
3426
35.8k
                  pstr_dec_data->str_usac_data.time_sample_vector[1][i] =
3427
35.8k
                      (FLOAT32)(time_data + slot_ele)[ch_fac * i + 1];
3428
35.8k
                }
3429
35
                p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] =
3430
35
                    &pstr_dec_data->str_usac_data.time_sample_vector[0][0];
3431
3432
35
                p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] =
3433
35
                    &pstr_dec_data->str_usac_data.time_sample_vector[1][0];
3434
35
              }
3435
148
            }
3436
21.8k
          }
3437
55.1k
        }
3438
55.1k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->esbr_hq =
3439
55.1k
            p_obj_exhaacplus_dec->aac_config.ui_hq_esbr;
3440
55.1k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr =
3441
55.1k
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr;
3442
55.1k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr_ps =
3443
55.1k
            p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps;
3444
3445
55.1k
        if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
3446
55.1k
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf =
3447
55.1k
              &(p_state_enhaacplus_dec->xaac_jmp_buf);
3448
55.1k
        }
3449
3450
55.1k
        if (ixheaacd_applysbr(p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx],
3451
55.1k
                              &p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0],
3452
55.1k
                              actual_out_buffer, &num_ch,
3453
55.1k
                              p_obj_exhaacplus_dec->aac_config.frame_status,
3454
55.1k
                              p_obj_exhaacplus_dec->aac_config.down_sample_flag,
3455
55.1k
                              esbr_mono_downmix, &sbr_scratch_struct, ps_enable, ch_fac, slot_ele,
3456
55.1k
                              NULL, &p_state_enhaacplus_dec->str_drc_dec_info,
3457
55.1k
                              p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present,
3458
55.1k
                              p_state_enhaacplus_dec->audio_object_type, 0,
3459
55.1k
                              p_state_enhaacplus_dec->ldmps_present, frame_size,
3460
55.1k
                              p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present,
3461
55.1k
                              p_obj_exhaacplus_dec->aac_config.ui_err_conceal,
3462
55.1k
                              p_obj_exhaacplus_dec->aac_config.first_frame) != SBRDEC_OK) {
3463
245
          p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0;
3464
245
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3465
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3466
245
          } else {
3467
245
            return -1;
3468
245
          }
3469
54.8k
        } else {
3470
54.8k
          if (!p_obj_exhaacplus_dec->aac_config.down_sample_flag) {
3471
34.6k
            frame_size = (WORD16)(frame_size * 2);
3472
34.6k
            sample_rate_dec *= 2;
3473
34.6k
          }
3474
54.8k
          if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
3475
54.8k
                  .ldmps_present_flag == 1) {
3476
3.55k
            ixheaacd_mps_payload(
3477
3.55k
                p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx],
3478
3.55k
                p_obj_exhaacplus_dec);
3479
3.55k
          }
3480
54.8k
        }
3481
3482
54.8k
        if (p_obj_exhaacplus_dec->aac_config.ui_enh_sbr)
3483
54.4k
        {
3484
54.4k
          WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type;
3485
3486
54.4k
          if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) {
3487
21.7k
            WORD32 out_bytes = 0;
3488
21.7k
            ia_dec_data_struct *pstr_dec_data =
3489
21.7k
                (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data;
3490
21.7k
            if (ch_fac <= 2) {
3491
21.6k
              ixheaacd_samples_sat((WORD8*)time_data, 2048, 16,
3492
21.6k
                                   pstr_dec_data->str_usac_data.time_sample_vector,
3493
21.6k
                                   &out_bytes, ch_fac);
3494
21.6k
            } else {
3495
147
              ixheaacd_samples_sat_mc((WORD8*)(time_data + slot_ele), 2048,
3496
147
                                      pstr_dec_data->str_usac_data.time_sample_vector,
3497
147
                                      &out_bytes, channel, ch_fac);
3498
147
            }
3499
21.7k
          }
3500
54.4k
        }
3501
54.8k
        p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present =
3502
54.8k
            0;
3503
54.8k
        if (p_state_enhaacplus_dec->ui_mps_out_bytes > 0) {
3504
381
          p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present = 1;
3505
381
        }
3506
219k
      } else {
3507
219k
        p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present = 1;
3508
219k
      }
3509
274k
    }
3510
3511
274k
    if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
3512
274k
                .ldmps_present_flag == 1 &&
3513
18.3k
         p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] &&
3514
17.3k
         p_state_enhaacplus_dec->mps_dec_handle.mps_init_done == 1) {
3515
3.64k
      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
3.64k
      } else {
3521
3.64k
        error_code = ixheaacd_ld_mps_apply(p_obj_exhaacplus_dec, actual_out_buffer);
3522
3523
3.64k
        if (error_code)
3524
88
          return error_code;
3525
3.64k
      }
3526
3.64k
    }
3527
274k
    if (sample_rate < sample_rate_dec) {
3528
257k
      sample_rate = sample_rate_dec;
3529
257k
    }
3530
3531
274k
    if (p_state_enhaacplus_dec->sbr_present ||
3532
218k
        p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] == LD_OBJ) {
3533
110k
      num_of_out_samples = frame_size;
3534
3535
163k
    } else {
3536
163k
      num_of_out_samples =
3537
163k
          frame_size -
3538
163k
          MIN((WORD16)p_obj_exhaacplus_dec->p_state_aac->delay_in_samples, frame_size);
3539
163k
    }
3540
3541
274k
    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
274k
    p_obj_exhaacplus_dec->aac_config.ui_samp_freq = sample_rate;
3549
3550
274k
    p_state_enhaacplus_dec->num_channel_last = num_ch;
3551
274k
    p_state_enhaacplus_dec->num_of_out_samples = num_of_out_samples;
3552
3553
274k
    if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
3554
274k
            .ldmps_present_flag == 1 &&
3555
18.2k
        p_state_enhaacplus_dec->mps_dec_handle.mps_init_done == 1 &&
3556
3.56k
        p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) {
3557
3.56k
      if (p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.output_buffer) {
3558
3.56k
        ixheaacd_samples_sat((WORD8 *)actual_out_buffer, num_of_out_samples,
3559
3.56k
                             p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz,
3560
3.56k
                             p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.output_buffer,
3561
3.56k
                             &mps_out_samples, 2);
3562
3.56k
        p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = mps_out_samples;
3563
3.56k
      }
3564
3.56k
      num_ch = p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.out_ch_count;
3565
3.56k
      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
270k
    } else {
3572
270k
      if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] != 2) {
3573
268k
        if (p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1 &&
3574
20.2k
          channel == 1 && total_elements == 1 && num_ch == 1) {
3575
5.87k
        num_ch = 2;
3576
5.87k
        p_obj_exhaacplus_dec->aac_config.dup_stereo_flag = 1;
3577
3578
262k
      } else {
3579
262k
        p_obj_exhaacplus_dec->aac_config.dup_stereo_flag = 0;
3580
262k
      }
3581
3582
268k
      p_obj_exhaacplus_dec->aac_config.ui_n_channels = 2;
3583
3584
268k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes +=
3585
268k
          p_state_enhaacplus_dec->num_of_out_samples * num_ch * sizeof(WORD16);
3586
3587
268k
    } else {
3588
2.09k
      channel_coupling_flag = 1;
3589
2.09k
    }
3590
270k
  }
3591
3592
274k
    if (p_state_enhaacplus_dec->sbr_present && total_channels > 2) {
3593
331
      for (WORD32 j = 0; j < channel; j++) {
3594
317k
        for (WORD32 i = 0; i < frame_size; i++) {
3595
317k
          intermediate_scr[total_channels * i + j +
3596
317k
                           p_state_enhaacplus_dec->slot_pos] =
3597
317k
              actual_out_buffer[total_channels * i + j +
3598
317k
                                p_state_enhaacplus_dec->slot_pos];
3599
317k
        }
3600
183
      }
3601
148
    }
3602
274k
  }
3603
3604
253k
  if (p_state_enhaacplus_dec->sbr_present && total_channels > 2) {
3605
46
    memcpy(time_data, intermediate_scr,
3606
46
           sizeof(WORD16) * frame_size * total_channels);
3607
46
  }
3608
3609
253k
  {
3610
253k
    ia_adts_crc_info_struct *ptr_adts_crc_info =
3611
253k
        p_state_enhaacplus_dec->ptr_bit_stream->pstr_adts_crc_info;
3612
253k
    if (ptr_adts_crc_info->crc_active == 1) {
3613
23
      if ((error_code = ixheaacd_adts_crc_check_crc(ptr_adts_crc_info))) {
3614
23
        if (error_code) {
3615
23
          if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) {
3616
0
            p_obj_exhaacplus_dec->aac_config.frame_status = 0;
3617
23
          } else {
3618
23
            return error_code;
3619
23
          }
3620
23
        }
3621
23
      }
3622
23
    }
3623
253k
  }
3624
3625
253k
  p_obj_exhaacplus_dec->aac_config.ui_n_channels = total_channels;
3626
3627
253k
  p_state_enhaacplus_dec->frame_counter++;
3628
3629
253k
  WORD32 i, j;
3630
3631
253k
  if (channel_coupling_flag) {
3632
354
    error_code = ixheaacd_dec_ind_coupling(p_obj_exhaacplus_dec,
3633
354
                                           p_state_enhaacplus_dec->coup_ch_output,
3634
354
                                           num_of_out_samples, total_channels, time_data);
3635
354
    if (error_code)
3636
10
      return error_code;
3637
354
  }
3638
3639
604k
  for (i = 0; i < total_channels; i++) {
3640
351k
    if (p_obj_exhaacplus_dec->p_state_aac->qshift_adj[i + 1] == 0)
3641
311k
      p_obj_exhaacplus_dec->p_state_aac->qshift_adj[i + 1] =
3642
311k
          p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0];
3643
351k
  }
3644
3645
253k
  if (p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1 &&
3646
23.6k
      total_elements == 1 && num_ch == 2 &&
3647
23.6k
      p_obj_exhaacplus_dec->aac_config.dup_stereo_flag == 1) {
3648
5.87k
    WORD i;
3649
3650
5.87k
    if (!p_state_enhaacplus_dec->sbr_present &&
3651
140
        p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ) {
3652
142k
      for (i = 0; i < frame_size; i++) {
3653
142k
        *((WORD32 *)actual_out_buffer + 2 * i + 1) =
3654
142k
            *((WORD32 *)actual_out_buffer + 2 * i);
3655
142k
      }
3656
5.74k
    } else {
3657
11.7M
      for (i = 0; i < frame_size; i++) {
3658
11.7M
        *(actual_out_buffer + 2 * i + 1) = *(actual_out_buffer + 2 * i);
3659
11.7M
      }
3660
5.74k
    }
3661
5.87k
  }
3662
3663
253k
  if (!p_state_enhaacplus_dec->sbr_present &&
3664
202k
      p_obj_exhaacplus_dec->p_state_aac->peak_lim_init == 1 &&
3665
128k
      p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ) {
3666
117k
    if (!p_obj_exhaacplus_dec->aac_config.peak_limiter_off) {
3667
117k
      ixheaacd_peak_limiter_process(
3668
117k
          &p_state_enhaacplus_dec->peak_limiter, time_data, frame_size,
3669
117k
          p_obj_exhaacplus_dec->p_state_aac->qshift_adj);
3670
117k
    } 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
198M
    for (i = 0; i < frame_size * 2; i++) {
3677
444M
      for (j = 0; j < total_channels; j++) {
3678
246M
        *((WORD16 *)time_data + total_channels * i + j) =
3679
246M
            ixheaac_round16(*((WORD32 *)time_data + total_channels * i + j));
3680
246M
      }
3681
198M
    }
3682
3683
117k
    memmove(
3684
117k
        time_data,
3685
117k
        (time_data +
3686
117k
         total_channels * p_obj_exhaacplus_dec->p_state_aac->delay_in_samples),
3687
117k
        sizeof(WORD16) * num_of_out_samples * total_channels);
3688
3689
117k
    p_obj_exhaacplus_dec->p_state_aac->delay_in_samples =
3690
117k
        p_obj_exhaacplus_dec->p_state_aac->delay_in_samples -
3691
117k
        MIN(p_obj_exhaacplus_dec->p_state_aac->delay_in_samples, (UWORD16)frame_size);
3692
117k
  }
3693
253k
  if (p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present == 1) {
3694
18.3k
    ia_heaac_mps_state_struct *pstr_mps_state =
3695
18.3k
        &p_state_enhaacplus_dec->heaac_mps_handle;
3696
18.3k
    if (p_state_enhaacplus_dec->sbr_present == 0) {
3697
17.6k
      p_state_enhaacplus_dec->heaac_mps_handle.mps_decode = 1;
3698
17.6k
    } else {
3699
695
      p_state_enhaacplus_dec->heaac_mps_handle.mps_with_sbr = 1;
3700
695
    }
3701
18.3k
    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
18.3k
    if (p_state_enhaacplus_dec->heaac_mps_handle.mps_init_done == 1) {
3706
18.0k
      p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.frame_ok =
3707
18.0k
          p_obj_exhaacplus_dec->aac_config.frame_status;
3708
18.0k
      p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.ec_flag =
3709
18.0k
          p_obj_exhaacplus_dec->aac_config.ui_err_conceal;
3710
3711
18.0k
      error_code = ixheaacd_heaac_mps_apply(p_obj_exhaacplus_dec, actual_out_buffer, mps_buffer,
3712
18.0k
                                            p_state_enhaacplus_dec->ui_mps_out_bytes);
3713
3714
18.0k
      if (error_code != IA_NO_ERROR) {
3715
900
        return error_code;
3716
900
      }
3717
3718
17.1k
      p_state_enhaacplus_dec->heaac_mps_handle.mps_decode = 1;
3719
17.1k
      p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes =
3720
17.1k
          (pstr_mps_state->num_output_channels_at *
3721
17.1k
           pstr_mps_state->frame_length *
3722
17.1k
           (p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz >> 3));
3723
17.1k
      p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.first_frame = 0;
3724
17.1k
    }
3725
18.3k
  }
3726
252k
  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
252k
  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
252k
  if (p_state_enhaacplus_dec->s_adts_hdr_present) {
3761
38.7k
    if (adts.no_raw_data_blocks != 0) {
3762
2.51k
      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.51k
    }
3766
38.7k
    p_state_enhaacplus_dec->b_n_raw_data_blk--;
3767
38.7k
  }
3768
3769
252k
  ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff);
3770
3771
252k
  if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT)
3772
216k
    p_state_enhaacplus_dec->i_bytes_consumed =
3773
216k
        (WORD32)(audio_mux_length_bytes_last + bytes_for_sync);
3774
3775
252k
  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
252k
  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
252k
  } else {
3786
252k
    return error_code;
3787
252k
  }
3788
252k
}