Coverage Report

Created: 2026-09-01 06:32

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