Coverage Report

Created: 2025-11-24 06:48

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