Coverage Report

Created: 2026-02-26 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_init_config.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 <stdarg.h>
23
#include <assert.h>
24
25
#include "ixheaac_type_def.h"
26
#include "ixheaac_constants.h"
27
#include "ixheaacd_bitbuffer.h"
28
29
#include "ixheaacd_defines.h"
30
#include "ixheaacd_memory_standards.h"
31
#include "ixheaacd_sbrdecsettings.h"
32
#include "ixheaacd_sbr_scale.h"
33
#include "ixheaacd_env_extr_part.h"
34
#include "ixheaacd_aac_rom.h"
35
#include "ixheaacd_common_rom.h"
36
#include "ixheaacd_sbr_rom.h"
37
#include "ixheaacd_pulsedata.h"
38
#include "ixheaacd_pns.h"
39
40
#include "ixheaacd_sbr_common.h"
41
#include "ixheaacd_drc_data_struct.h"
42
#include "ixheaacd_drc_dec.h"
43
44
#include "ixheaacd_lt_predict.h"
45
#include "ixheaacd_cnst.h"
46
#include "ixheaacd_ec_defines.h"
47
#include "ixheaacd_ec_struct_def.h"
48
#include "ixheaacd_channelinfo.h"
49
#include "ixheaacd_channel.h"
50
#include "ixheaacd_sbrdecoder.h"
51
#include "ixheaacd_audioobjtypes.h"
52
#include "ixheaacd_latmdemux.h"
53
#include "ixheaacd_aacdec.h"
54
#include "ixheaacd_sbr_common.h"
55
56
#include "ixheaacd_hybrid.h"
57
#include "ixheaacd_ps_dec.h"
58
#include "ixheaacd_qmf_dec.h"
59
#include "ixheaacd_mps_macro_def.h"
60
#include "ixheaacd_mps_struct_def.h"
61
#include "ixheaacd_mps_res_rom.h"
62
#include "ixheaacd_mps_aac_struct.h"
63
#include "ixheaacd_mps_polyphase.h"
64
#include "ixheaacd_config.h"
65
#include "ixheaacd_mps_dec.h"
66
#include "ixheaacd_struct_def.h"
67
68
#include "ixheaacd_config.h"
69
#include "ixheaacd_interface.h"
70
#include "ixheaacd_info.h"
71
#include "ixheaacd_struct.h"
72
#include "ixheaac_error_standards.h"
73
74
#include "ixheaacd_error_codes.h"
75
76
static const WORD32 sampling_rate_tbl[] = {
77
    96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025,
78
    8000,  7350,  0,     0,     57600, 51200, 40000, 38400, 34150, 28800, 25600,
79
    20000, 19200, 17075, 14400, 12800, 9600,  0,     0,     0};
80
81
19.5k
UWORD32 ixheaacd_sbr_ratio(UWORD32 core_sbr_framelength_idx) {
82
19.5k
  UWORD32 sbr_ratio_index = 0x0FF;
83
84
19.5k
  switch (core_sbr_framelength_idx) {
85
1.39k
    case 0:
86
14.8k
    case 1:
87
14.8k
      sbr_ratio_index = USAC_SBR_RATIO_NO_SBR;
88
14.8k
      break;
89
1.11k
    case 2:
90
1.11k
      sbr_ratio_index = USAC_SBR_RATIO_INDEX_8_3;
91
1.11k
      break;
92
3.24k
    case 3:
93
3.24k
      sbr_ratio_index = USAC_SBR_RATIO_INDEX_2_1;
94
3.24k
      break;
95
393
    case 4:
96
393
      sbr_ratio_index = USAC_SBR_RATIO_INDEX_4_1;
97
393
      break;
98
19.5k
  }
99
100
19.5k
  return sbr_ratio_index;
101
19.5k
}
102
103
4.21k
static WORD32 ixheaacd_get_sample_freq_indx(WORD32 sampling_freq) {
104
4.21k
  WORD32 index;
105
4.21k
  const WORD32 tbl_size = sizeof(sampling_rate_tbl) / sizeof(WORD32) - 1;
106
107
78.0k
  for (index = 0; index < tbl_size; index++) {
108
76.7k
    if (sampling_rate_tbl[index] == sampling_freq) break;
109
76.7k
  }
110
4.21k
  return index;
111
4.21k
}
112
UWORD32 ixheaacd_sbr_params(UWORD32 core_sbr_framelength_idx,
113
                            WORD32 *output_framelength, WORD32 *block_size,
114
                            WORD32 *output_samples, WORD32 *sample_rate_layer,
115
4.21k
                            UWORD32 *sample_freq_indx) {
116
4.21k
  UWORD32 sbr_ratio_index = 0x0FF;
117
118
4.21k
  *output_framelength = -1;
119
120
4.21k
  switch (core_sbr_framelength_idx) {
121
941
    case 0:
122
941
      sbr_ratio_index = USAC_SBR_RATIO_NO_SBR;
123
941
      *output_framelength = USAC_OUT_FRAMELENGTH_768;
124
941
      *block_size = 768;
125
941
      *output_samples = *block_size;
126
941
      break;
127
929
    case 1:
128
929
      sbr_ratio_index = USAC_SBR_RATIO_NO_SBR;
129
929
      *output_framelength = USAC_OUT_FRAMELENGTH_1024;
130
929
      *block_size = 1024;
131
929
      *output_samples = *block_size;
132
929
      break;
133
530
    case 2:
134
530
      sbr_ratio_index = USAC_SBR_RATIO_INDEX_8_3;
135
530
      *output_framelength = USAC_OUT_FRAMELENGTH_2048;
136
530
      *block_size = 768;
137
530
      *output_samples = (*block_size * 8) / 3;
138
530
      *sample_rate_layer = (*sample_rate_layer * 3) >> 3;
139
530
      break;
140
1.58k
    case 3:
141
1.58k
      sbr_ratio_index = USAC_SBR_RATIO_INDEX_2_1;
142
1.58k
      *output_framelength = USAC_OUT_FRAMELENGTH_2048;
143
1.58k
      *block_size = 1024;
144
1.58k
      *output_samples = *block_size * 2;
145
1.58k
      *sample_rate_layer = *sample_rate_layer >> 1;
146
1.58k
      break;
147
229
    case 4:
148
229
      sbr_ratio_index = USAC_SBR_RATIO_INDEX_4_1;
149
229
      *output_framelength = USAC_OUT_FRAMELENGTH_4096;
150
229
      *block_size = 1024;
151
229
      *output_samples = *block_size * 4;
152
229
      *sample_rate_layer = *sample_rate_layer >> 2;
153
229
      break;
154
4.21k
  }
155
156
4.21k
  *sample_freq_indx = ixheaacd_get_sample_freq_indx(*sample_rate_layer);
157
158
4.21k
  return sbr_ratio_index;
159
4.21k
}
160
161
VOID ixheaacd_read_escape_value(ia_bit_buf_struct *it_bit_buff,
162
                                UWORD32 *ext_ele_value, UWORD32 no_bits1,
163
65.4k
                                UWORD32 no_bits2, UWORD32 no_bits3) {
164
65.4k
  UWORD32 value = 0;
165
65.4k
  UWORD32 val_add = 0;
166
65.4k
  UWORD32 max_val1 = (1 << no_bits1) - 1;
167
65.4k
  UWORD32 max_val2 = (1 << no_bits2) - 1;
168
169
65.4k
  value = ixheaacd_read_bits_buf(it_bit_buff, no_bits1);
170
171
65.4k
  if (value == max_val1) {
172
3.29k
    val_add = ixheaacd_read_bits_buf(it_bit_buff, no_bits2);
173
174
3.29k
    value += val_add;
175
176
3.29k
    if (val_add == max_val2) {
177
382
      val_add = ixheaacd_read_bits_buf(it_bit_buff, no_bits3);
178
179
382
      value += val_add;
180
382
    }
181
3.29k
  }
182
183
65.4k
  *ext_ele_value = value;
184
65.4k
}
185
186
static IA_ERRORCODE ixheaacd_get_usac_chan_conf(ia_usac_config_struct *pstr_usac_config,
187
                        UWORD32 ch_config_index, ia_bit_buf_struct *it_bit_buff, WORD32 ec_flag)
188
15.9k
{
189
15.9k
  switch (ch_config_index) {
190
587
    case 1:
191
587
      pstr_usac_config->num_out_channels = 1;
192
587
      pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_C;
193
587
      break;
194
14.3k
    case 2:
195
14.3k
      pstr_usac_config->num_out_channels = 2;
196
14.3k
      pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_L;
197
14.3k
      pstr_usac_config->output_channel_pos[1] = BS_OUTPUT_CHANNEL_POS_R;
198
14.3k
      break;
199
996
    case 8:
200
996
      pstr_usac_config->num_out_channels = 2;
201
996
      pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_NA;
202
996
      pstr_usac_config->output_channel_pos[1] = BS_OUTPUT_CHANNEL_POS_NA;
203
996
      break;
204
205
0
    default:
206
0
      if (ec_flag)
207
0
        longjmp(*(it_bit_buff->xaac_jmp_buf),
208
0
            IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
209
0
      else
210
0
        return IA_FATAL_ERROR;
211
0
      break;
212
15.9k
  }
213
15.9k
  return IA_NO_ERROR;
214
15.9k
}
215
216
VOID ixheaacd_sbr_config(ia_bit_buf_struct *it_bit_buff,
217
4.83k
                         ia_usac_dec_sbr_config_struct *pstr_usac_sbr_config) {
218
4.83k
  pstr_usac_sbr_config->harmonic_sbr = ixheaacd_read_bits_buf(it_bit_buff, 1);
219
4.83k
  pstr_usac_sbr_config->bs_inter_tes = ixheaacd_read_bits_buf(it_bit_buff, 1);
220
4.83k
  pstr_usac_sbr_config->bs_pvc = ixheaacd_read_bits_buf(it_bit_buff, 1);
221
4.83k
  pstr_usac_sbr_config->dflt_start_freq =
222
4.83k
      ixheaacd_read_bits_buf(it_bit_buff, 4);
223
224
4.83k
  pstr_usac_sbr_config->dflt_stop_freq = ixheaacd_read_bits_buf(it_bit_buff, 4);
225
4.83k
  pstr_usac_sbr_config->dflt_header_extra1 =
226
4.83k
      ixheaacd_read_bits_buf(it_bit_buff, 1);
227
4.83k
  pstr_usac_sbr_config->dflt_header_extra2 =
228
4.83k
      ixheaacd_read_bits_buf(it_bit_buff, 1);
229
230
4.83k
  if (pstr_usac_sbr_config->dflt_header_extra1) {
231
2.24k
    pstr_usac_sbr_config->dflt_freq_scale =
232
2.24k
        ixheaacd_read_bits_buf(it_bit_buff, 2);
233
2.24k
    pstr_usac_sbr_config->dflt_alter_scale =
234
2.24k
        ixheaacd_read_bits_buf(it_bit_buff, 1);
235
2.24k
    pstr_usac_sbr_config->dflt_noise_bands =
236
2.24k
        ixheaacd_read_bits_buf(it_bit_buff, 2);
237
2.24k
  }
238
239
4.83k
  if (pstr_usac_sbr_config->dflt_header_extra2) {
240
898
    pstr_usac_sbr_config->dflt_limiter_bands =
241
898
        ixheaacd_read_bits_buf(it_bit_buff, 2);
242
898
    pstr_usac_sbr_config->dflt_limiter_gains =
243
898
        ixheaacd_read_bits_buf(it_bit_buff, 2);
244
898
    pstr_usac_sbr_config->dflt_interpol_freq =
245
898
        ixheaacd_read_bits_buf(it_bit_buff, 1);
246
898
    pstr_usac_sbr_config->dflt_smoothing_mode =
247
898
        ixheaacd_read_bits_buf(it_bit_buff, 1);
248
898
  }
249
4.83k
}
250
251
WORD32 ixheaacd_ext_element_config(
252
    ia_bit_buf_struct *it_bit_buff,
253
    ia_usac_dec_element_config_struct *pstr_usac_element_config,
254
    UWORD8 *ptr_usac_ext_ele_payload, WORD32 *ptr_usac_ext_ele_payload_len,
255
9.91k
    WORD32 *preroll_flag) {
256
9.91k
  UWORD32 usac_ext_element_type, usac_ext_element_config_length, flag;
257
258
9.91k
  UWORD32 i;
259
260
9.91k
  ixheaacd_read_escape_value(it_bit_buff, &(usac_ext_element_type), 4, 8, 16);
261
262
9.91k
  ixheaacd_read_escape_value(it_bit_buff, &(usac_ext_element_config_length), 4,
263
9.91k
                             8, 16);
264
9.91k
  if (usac_ext_element_config_length >= 768) return -1;
265
266
9.91k
  flag = ixheaacd_read_bits_buf(it_bit_buff, 1);
267
268
9.91k
  *ptr_usac_ext_ele_payload_len = 0;
269
270
9.91k
  if (flag) {
271
2.07k
    ixheaacd_read_escape_value(
272
2.07k
        it_bit_buff,
273
2.07k
        (UWORD32 *)(&(pstr_usac_element_config->usac_ext_eleme_def_len)), 8, 16,
274
2.07k
        0);
275
2.07k
    pstr_usac_element_config->usac_ext_eleme_def_len += 1;
276
277
7.83k
  } else {
278
7.83k
    pstr_usac_element_config->usac_ext_eleme_def_len = 0;
279
7.83k
  }
280
281
9.91k
  pstr_usac_element_config->usac_ext_elem_pld_frag =
282
9.91k
      ixheaacd_read_bits_buf(it_bit_buff, 1);
283
284
9.91k
  switch (usac_ext_element_type) {
285
22
    case ID_EXT_ELE_FILL:
286
22
      break;
287
4.29k
    case ID_EXT_ELE_AUDIOPREROLL:
288
4.29k
      *preroll_flag = 1;
289
4.29k
      break;
290
1.33k
    case ID_EXT_ELE_UNI_DRC:
291
35.5k
      for (i = 0; i < usac_ext_element_config_length; i++) {
292
34.1k
        ptr_usac_ext_ele_payload[i] = ixheaacd_read_bits_buf(it_bit_buff, 8);
293
34.1k
      }
294
1.33k
      *ptr_usac_ext_ele_payload_len = usac_ext_element_config_length;
295
1.33k
      break;
296
297
4.25k
    default:
298
4.25k
      if ((it_bit_buff->cnt_bits >> 3) < (WORD32)usac_ext_element_config_length)
299
10
        return -1;
300
4.24k
      it_bit_buff->ptr_read_next += usac_ext_element_config_length;
301
4.24k
      it_bit_buff->cnt_bits -= (usac_ext_element_config_length << 3);
302
303
4.24k
      break;
304
9.91k
  }
305
306
9.89k
  return 0;
307
9.91k
}
308
309
IA_ERRORCODE ixheaacd_mps212_config(
310
    ia_bit_buf_struct *it_bit_buff,
311
    ia_usac_dec_mps_config_struct *pstr_usac_mps212_config,
312
2.11k
    WORD32 stereo_config_index) {
313
2.11k
  pstr_usac_mps212_config->bs_freq_res = ixheaacd_read_bits_buf(it_bit_buff, 3);
314
315
2.11k
  pstr_usac_mps212_config->bs_fixed_gain_dmx =
316
2.11k
      ixheaacd_read_bits_buf(it_bit_buff, 3);
317
318
2.11k
  pstr_usac_mps212_config->bs_temp_shape_config =
319
2.11k
      ixheaacd_read_bits_buf(it_bit_buff, 2);
320
321
2.11k
  pstr_usac_mps212_config->bs_decorr_config =
322
2.11k
      ixheaacd_read_bits_buf(it_bit_buff, 2);
323
2.11k
  if (pstr_usac_mps212_config->bs_decorr_config > MAX_DECOR_CONFIG_IDX)
324
1
    return IA_FATAL_ERROR;
325
326
2.11k
  pstr_usac_mps212_config->bs_high_rate_mode =
327
2.11k
      ixheaacd_read_bits_buf(it_bit_buff, 1);
328
329
2.11k
  pstr_usac_mps212_config->bs_phase_coding =
330
2.11k
      ixheaacd_read_bits_buf(it_bit_buff, 1);
331
332
2.11k
  pstr_usac_mps212_config->bs_ott_bands_phase_present =
333
2.11k
      ixheaacd_read_bits_buf(it_bit_buff, 1);
334
335
2.11k
  if (pstr_usac_mps212_config->bs_ott_bands_phase_present) {
336
787
    pstr_usac_mps212_config->bs_ott_bands_phase =
337
787
        ixheaacd_read_bits_buf(it_bit_buff, 5);
338
787
    if (pstr_usac_mps212_config->bs_ott_bands_phase > MAX_PARAMETER_BANDS)
339
1
      return IA_FATAL_ERROR;
340
787
  }
341
342
2.10k
  if (stereo_config_index > 1) {
343
1.29k
    pstr_usac_mps212_config->bs_residual_bands =
344
1.29k
        ixheaacd_read_bits_buf(it_bit_buff, 5);
345
346
1.29k
    if (pstr_usac_mps212_config->bs_residual_bands > MAX_PARAMETER_BANDS)
347
2
      return IA_FATAL_ERROR;
348
349
1.28k
    pstr_usac_mps212_config->bs_ott_bands_phase =
350
1.28k
        max(pstr_usac_mps212_config->bs_ott_bands_phase,
351
1.28k
            pstr_usac_mps212_config->bs_residual_bands);
352
353
1.28k
    pstr_usac_mps212_config->bs_pseudo_lr =
354
1.28k
        ixheaacd_read_bits_buf(it_bit_buff, 1);
355
1.28k
  }
356
357
2.10k
  if (pstr_usac_mps212_config->bs_temp_shape_config == 2)
358
528
    pstr_usac_mps212_config->bs_env_quant_mode =
359
528
        ixheaacd_read_bits_buf(it_bit_buff, 1);
360
361
2.10k
  return IA_NO_ERROR;
362
2.10k
}
363
364
IA_ERRORCODE ixheaacd_cpe_config(
365
    ia_bit_buf_struct *it_bit_buff,
366
    ia_usac_dec_element_config_struct *pstr_usac_element_config,
367
8.12k
    WORD32 sbr_ratio_index) {
368
8.12k
  pstr_usac_element_config->tw_mdct = ixheaacd_read_bits_buf(it_bit_buff, 1);
369
8.12k
  pstr_usac_element_config->noise_filling =
370
8.12k
      ixheaacd_read_bits_buf(it_bit_buff, 1);
371
372
8.12k
  if (sbr_ratio_index > 0) {
373
2.27k
    ixheaacd_sbr_config(it_bit_buff,
374
2.27k
                        &(pstr_usac_element_config->str_usac_sbr_config));
375
2.27k
    pstr_usac_element_config->stereo_config_index =
376
2.27k
        ixheaacd_read_bits_buf(it_bit_buff, 2);
377
378
5.84k
  } else {
379
5.84k
    pstr_usac_element_config->stereo_config_index = 0;
380
5.84k
  }
381
382
8.12k
  if (pstr_usac_element_config->stereo_config_index > 0)
383
2.11k
    return ixheaacd_mps212_config(
384
2.11k
        it_bit_buff, &(pstr_usac_element_config->str_usac_mps212_config),
385
2.11k
        pstr_usac_element_config->stereo_config_index);
386
387
6.00k
  return IA_NO_ERROR;
388
8.12k
}
389
390
WORD32 ixheaacd_decoder_config(
391
    ia_bit_buf_struct *it_bit_buff,
392
    ia_usac_decoder_config_struct *pstr_usac_decoder_config,
393
19.5k
    WORD32 sbr_ratio_index, UINT32 *chan, WORD32 ec_flag) {
394
19.5k
  UWORD32 elem_idx = 0;
395
19.5k
  UWORD32 err = 0;
396
19.5k
  WORD32 num_channels = 0;
397
398
19.5k
  ixheaacd_read_escape_value(
399
19.5k
      it_bit_buff, &(pstr_usac_decoder_config->num_elements), 4, 8, 16);
400
19.5k
  pstr_usac_decoder_config->num_elements += 1;
401
19.5k
  pstr_usac_decoder_config->preroll_flag = 0;
402
403
19.5k
  if (pstr_usac_decoder_config->num_elements > USAC_MAX_ELEMENTS) {
404
9
    if (ec_flag) {
405
0
      pstr_usac_decoder_config->num_elements = USAC_MAX_ELEMENTS;
406
0
      longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
407
9
    } else {
408
9
      return IA_FATAL_ERROR;
409
9
    }
410
9
  }
411
412
48.7k
  for (elem_idx = 0; elem_idx < pstr_usac_decoder_config->num_elements;
413
29.2k
       elem_idx++) {
414
29.2k
    ia_usac_dec_element_config_struct *pstr_usac_element_config =
415
29.2k
        &(pstr_usac_decoder_config->str_usac_element_config[elem_idx]);
416
417
29.2k
    pstr_usac_decoder_config->usac_element_type[elem_idx] =
418
29.2k
        ixheaacd_read_bits_buf(it_bit_buff, 2);
419
420
29.2k
    switch (pstr_usac_decoder_config->usac_element_type[elem_idx]) {
421
10.9k
      case ID_USAC_SCE:
422
10.9k
        num_channels++;
423
10.9k
        pstr_usac_element_config->tw_mdct =
424
10.9k
            ixheaacd_read_bits_buf(it_bit_buff, 1);
425
10.9k
        pstr_usac_element_config->noise_filling =
426
10.9k
            ixheaacd_read_bits_buf(it_bit_buff, 1);
427
10.9k
        pstr_usac_element_config->stereo_config_index = 0;
428
10.9k
        if (sbr_ratio_index > 0)
429
2.56k
          ixheaacd_sbr_config(it_bit_buff,
430
2.56k
                              &(pstr_usac_element_config->str_usac_sbr_config));
431
432
10.9k
        break;
433
434
8.12k
      case ID_USAC_CPE:
435
8.12k
        num_channels += 2;
436
8.12k
        if (ixheaacd_cpe_config(it_bit_buff, pstr_usac_element_config, sbr_ratio_index) !=
437
8.12k
            IA_NO_ERROR) {
438
4
          if (ec_flag) {
439
0
            longjmp(*(it_bit_buff->xaac_jmp_buf),
440
0
                    IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
441
4
          } else {
442
4
            return IA_FATAL_ERROR;
443
4
          }
444
4
        }
445
8.11k
        if (pstr_usac_element_config->stereo_config_index > 1 && *chan < 2) {
446
2
          if (ec_flag) {
447
0
            longjmp(*(it_bit_buff->xaac_jmp_buf),
448
0
                    IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
449
2
          } else {
450
2
            return IA_FATAL_ERROR;
451
2
          }
452
2
        }
453
8.11k
        break;
454
455
8.11k
      case ID_USAC_LFE:
456
232
        num_channels++;
457
232
        pstr_usac_element_config->tw_mdct = 0;
458
232
        pstr_usac_element_config->noise_filling = 0;
459
232
        pstr_usac_element_config->stereo_config_index = 0;
460
232
        break;
461
462
9.91k
      case ID_USAC_EXT:
463
9.91k
        err = ixheaacd_ext_element_config(
464
9.91k
            it_bit_buff, pstr_usac_element_config,
465
9.91k
            &pstr_usac_decoder_config->usac_ext_ele_payload_buf[elem_idx][0],
466
9.91k
            &pstr_usac_decoder_config->usac_ext_ele_payload_len[elem_idx],
467
9.91k
            &(pstr_usac_decoder_config->preroll_flag));
468
469
9.91k
        if (pstr_usac_decoder_config->usac_ext_ele_payload_len[elem_idx] > 0) {
470
1.28k
          pstr_usac_decoder_config->usac_ext_ele_payload_present[elem_idx] = 1;
471
8.63k
        } else {
472
8.63k
          pstr_usac_decoder_config->usac_ext_ele_payload_present[elem_idx] = 0;
473
8.63k
        }
474
9.91k
        if (err != 0) {
475
11
          if (ec_flag) {
476
0
            longjmp(*(it_bit_buff->xaac_jmp_buf),
477
0
                    IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
478
11
          } else {
479
11
            return IA_FATAL_ERROR;
480
11
          }
481
11
        }
482
9.90k
        break;
483
9.90k
      default:
484
0
        if (ec_flag) {
485
0
          longjmp(*(it_bit_buff->xaac_jmp_buf),
486
0
                  IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
487
0
        } else {
488
0
          return IA_FATAL_ERROR;
489
0
        }
490
0
        break;
491
29.2k
    }
492
29.2k
    if (num_channels > 2) {
493
8
      if (ec_flag) {
494
0
        longjmp(*(it_bit_buff->xaac_jmp_buf),
495
0
                IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
496
8
      } else {
497
8
        return IA_FATAL_ERROR;
498
8
      }
499
8
    }
500
29.2k
  }
501
19.5k
  return err;
502
19.5k
}
503
504
WORD32 ixheaacd_config_extension(ia_bit_buf_struct *it_bit_buff,
505
2.14k
    ia_usac_decoder_config_struct *pstr_usac_decoder_config, WORD32 ec_flag) {
506
2.14k
  UWORD32 i, j;
507
2.14k
  UWORD32 num_config_extensions;
508
2.14k
  UWORD32 usac_config_ext_type, usac_config_ext_len;
509
510
2.14k
  ixheaacd_read_escape_value(it_bit_buff, &(num_config_extensions), 2, 4, 8);
511
2.14k
  num_config_extensions += 1;
512
2.14k
  if (USAC_MAX_CONFIG_EXTENSIONS < num_config_extensions) {
513
3
    if (ec_flag) {
514
0
      longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
515
3
    } else {
516
3
      return IA_FATAL_ERROR;
517
3
    }
518
3
  }
519
520
2.13k
  pstr_usac_decoder_config->num_config_extensions = num_config_extensions;
521
2.13k
  memset(pstr_usac_decoder_config->usac_cfg_ext_info_len, 0,
522
2.13k
         USAC_MAX_CONFIG_EXTENSIONS * sizeof(WORD32));
523
2.13k
  memset(pstr_usac_decoder_config->usac_cfg_ext_info_present, 0,
524
2.13k
         USAC_MAX_CONFIG_EXTENSIONS * sizeof(WORD32));
525
526
11.1k
  for (j = 0; j < num_config_extensions; j++) {
527
9.09k
    UWORD32 fill_byte_val = 0xa5;
528
529
9.09k
    ixheaacd_read_escape_value(it_bit_buff, &(usac_config_ext_type), 4, 8, 16);
530
9.09k
    ixheaacd_read_escape_value(it_bit_buff, &(usac_config_ext_len), 4, 8, 16);
531
532
9.09k
    if (usac_config_ext_len > 768) {
533
4
      if (ec_flag) {
534
0
        longjmp(*(it_bit_buff->xaac_jmp_buf),
535
0
                IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
536
4
      } else {
537
4
        return IA_FATAL_ERROR;
538
4
      }
539
4
    }
540
541
9.09k
    switch (usac_config_ext_type) {
542
4.08k
      case ID_CONFIG_EXT_FILL:
543
4.10k
        for (i = 0; i < usac_config_ext_len; i++) {
544
32
          fill_byte_val = ixheaacd_read_bits_buf(it_bit_buff, 8);
545
32
          if (fill_byte_val != 0xa5) {
546
9
            if (ec_flag) {
547
0
              longjmp(*(it_bit_buff->xaac_jmp_buf),
548
0
                      IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
549
9
            } else {
550
9
              return IA_FATAL_ERROR;
551
9
            }
552
9
          }
553
32
        }
554
4.07k
        break;
555
4.98k
      default:
556
4.98k
        if ((WORD32)usac_config_ext_len > (it_bit_buff->cnt_bits >> 3)) {
557
16
          if (ec_flag) {
558
0
            longjmp(*(it_bit_buff->xaac_jmp_buf),
559
0
                    IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
560
16
          } else {
561
16
            return IA_FATAL_ERROR;
562
16
          }
563
16
        }
564
4.97k
        if (ID_CONFIG_EXT_LOUDNESS_INFO == usac_config_ext_type) {
565
30.1k
          for (i = 0; i < usac_config_ext_len; i++) {
566
29.0k
            UWORD8 byte_val = ixheaacd_read_bits_buf(it_bit_buff, 8);
567
29.0k
            pstr_usac_decoder_config->usac_cfg_ext_info_buf[j][i] = byte_val;
568
29.0k
          }
569
1.07k
          pstr_usac_decoder_config->usac_cfg_ext_info_len[j] =
570
1.07k
              usac_config_ext_len;
571
1.07k
          pstr_usac_decoder_config->usac_cfg_ext_info_present[j] = 1;
572
3.90k
        } else {
573
13.7k
          for (i = 0; i < usac_config_ext_len; i++)
574
9.82k
            ixheaacd_read_bits_buf(it_bit_buff, 8);
575
3.90k
        }
576
4.97k
        break;
577
9.09k
    }
578
9.09k
  }
579
580
2.08k
  return 0;
581
2.13k
}
582
583
WORD32 ixheaacd_config(ia_bit_buf_struct *it_bit_buff, ia_usac_config_struct *pstr_usac_conf,
584
19.6k
                       UINT32 *chan, WORD32 ec_flag) {
585
19.6k
  WORD32 tmp, err;
586
19.6k
  err = 0;
587
588
19.6k
  pstr_usac_conf->usac_sampling_frequency_index =
589
19.6k
      ixheaacd_read_bits_buf(it_bit_buff, 5);
590
591
19.6k
  if (pstr_usac_conf->usac_sampling_frequency_index == 0x1f) {
592
42
    pstr_usac_conf->usac_sampling_frequency =
593
42
        ixheaacd_read_bits_buf(it_bit_buff, 24);
594
595
42
    if (pstr_usac_conf->usac_sampling_frequency > USAC_MAX_SAMPLE_RATE) {
596
4
      if (ec_flag) {
597
0
        longjmp(*(it_bit_buff->xaac_jmp_buf),
598
0
                IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
599
4
      } else {
600
4
        return IA_FATAL_ERROR;
601
4
      }
602
4
    }
603
604
19.5k
  } else {
605
19.5k
    pstr_usac_conf->usac_sampling_frequency =
606
19.5k
        sampling_rate_tbl[pstr_usac_conf->usac_sampling_frequency_index];
607
19.5k
  }
608
609
19.6k
  if (pstr_usac_conf->usac_sampling_frequency == 0) {
610
2
    if (ec_flag) {
611
0
      longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
612
2
    } else {
613
2
      return IA_FATAL_ERROR;
614
2
    }
615
2
  }
616
19.6k
  pstr_usac_conf->core_sbr_framelength_index =
617
19.6k
      ixheaacd_read_bits_buf(it_bit_buff, 3);
618
619
19.6k
  if (pstr_usac_conf->core_sbr_framelength_index > MAX_CORE_SBR_FRAME_LEN_IDX) {
620
5
    if (ec_flag) {
621
0
      longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
622
5
    } else {
623
5
      return IA_FATAL_ERROR;
624
5
    }
625
5
  }
626
627
19.6k
  pstr_usac_conf->channel_configuration_index =
628
19.6k
      ixheaacd_read_bits_buf(it_bit_buff, 5);
629
19.6k
  if ((pstr_usac_conf->channel_configuration_index >= 3) &&
630
1.00k
      (pstr_usac_conf->channel_configuration_index != 8)) {
631
11
    if (ec_flag) {
632
0
      longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
633
11
    } else {
634
11
      return IA_FATAL_ERROR;
635
11
    }
636
11
  }
637
638
19.6k
  if (pstr_usac_conf->channel_configuration_index == 0) {
639
3.66k
    UWORD32 i;
640
641
3.66k
    ixheaacd_read_escape_value(it_bit_buff,
642
3.66k
                               (UWORD32 *)(&(pstr_usac_conf->num_out_channels)),
643
3.66k
                               5, 8, 16);
644
3.66k
    if (BS_MAX_NUM_OUT_CHANNELS < pstr_usac_conf->num_out_channels) {
645
6
      return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX;
646
6
    }
647
3.65k
    if (pstr_usac_conf->num_out_channels < 1) {
648
9
      return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL;
649
9
    }
650
261k
    for (i = 0; i < pstr_usac_conf->num_out_channels; i++)
651
257k
      pstr_usac_conf->output_channel_pos[i] =
652
257k
          ixheaacd_read_bits_buf(it_bit_buff, 5);
653
654
3.64k
    if (ec_flag) {
655
0
      longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
656
0
    }
657
15.9k
  } else {
658
15.9k
    err = ixheaacd_get_usac_chan_conf(pstr_usac_conf, pstr_usac_conf->channel_configuration_index,
659
15.9k
                                      it_bit_buff, ec_flag);
660
15.9k
    if (err != 0)
661
0
      return err;
662
15.9k
  }
663
664
19.6k
  err = ixheaacd_decoder_config(
665
19.6k
      it_bit_buff, &(pstr_usac_conf->str_usac_dec_config),
666
19.6k
      ixheaacd_sbr_ratio(pstr_usac_conf->core_sbr_framelength_index), chan, ec_flag);
667
19.6k
  if (err != 0) return err;
668
669
19.5k
  tmp = ixheaacd_read_bits_buf(it_bit_buff, 1);
670
671
19.5k
  if (tmp) {
672
2.14k
    err = ixheaacd_config_extension(it_bit_buff,
673
2.14k
                                    &pstr_usac_conf->str_usac_dec_config, ec_flag);
674
2.14k
    if (err != 0) return -1;
675
2.14k
  }
676
677
19.5k
  return err;
678
19.5k
}
679
680
19.6k
VOID ixheaacd_conf_default(ia_usac_config_struct *pstr_usac_conf) {
681
19.6k
  WORD32 i;
682
683
19.6k
  pstr_usac_conf->num_out_channels = 0;
684
685
5.02M
  for (i = 0; i < BS_MAX_NUM_OUT_CHANNELS; i++)
686
5.00M
    pstr_usac_conf->output_channel_pos[i] = BS_OUTPUT_CHANNEL_POS_NA;
687
688
19.6k
  pstr_usac_conf->str_usac_dec_config.num_elements = 0;
689
690
333k
  for (i = 0; i < USAC_MAX_ELEMENTS; i++)
691
313k
    pstr_usac_conf->str_usac_dec_config.usac_element_type[i] = ID_USAC_INVALID;
692
693
19.6k
  return;
694
19.6k
}