Coverage Report

Created: 2025-08-26 06:47

/src/libxaac/decoder/ixheaacd_process.c
Line
Count
Source (jump to first uncovered line)
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 <stdio.h>
21
#include <string.h>
22
#include <math.h>
23
#include "ixheaac_constants.h"
24
#include "ixheaac_type_def.h"
25
#include "ixheaacd_memory_standards.h"
26
#include "ixheaacd_sbrdecsettings.h"
27
#include "ixheaacd_env_extr_part.h"
28
#include "ixheaacd_defines.h"
29
#include "ixheaacd_aac_rom.h"
30
#include "ixheaacd_common_rom.h"
31
#include "ixheaacd_sbr_rom.h"
32
#include "ixheaacd_bitbuffer.h"
33
#include "ixheaacd_pulsedata.h"
34
#include "ixheaacd_pns.h"
35
36
#include "ixheaacd_sbr_common.h"
37
#include "ixheaacd_drc_data_struct.h"
38
#include "ixheaacd_drc_dec.h"
39
40
#include "ixheaacd_lt_predict.h"
41
#include "ixheaacd_cnst.h"
42
#include "ixheaacd_ec_defines.h"
43
#include "ixheaacd_ec_struct_def.h"
44
#include "ixheaacd_channelinfo.h"
45
#include "ixheaacd_channel.h"
46
#include "ixheaacd_sbrdecoder.h"
47
#include "ixheaacd_sbr_scale.h"
48
#include "ixheaacd_audioobjtypes.h"
49
#include "ixheaacd_latmdemux.h"
50
#include "ixheaacd_aacdec.h"
51
#include "ixheaacd_sbr_common.h"
52
53
#include "ixheaacd_mps_polyphase.h"
54
#include "ixheaacd_config.h"
55
#include "ixheaacd_hybrid.h"
56
#include "ixheaacd_ps_dec.h"
57
#include "ixheaacd_qmf_dec.h"
58
#include "ixheaacd_mps_macro_def.h"
59
#include "ixheaacd_mps_struct_def.h"
60
#include "ixheaacd_mps_res_rom.h"
61
#include "ixheaacd_mps_aac_struct.h"
62
#include "ixheaacd_mps_dec.h"
63
#include "ixheaacd_mps_interface.h"
64
#include "ixheaacd_struct_def.h"
65
#include "ixheaacd_config.h"
66
#include "ixheaacd_bitbuffer.h"
67
#include "ixheaacd_interface.h"
68
69
#include "ixheaacd_tns_usac.h"
70
#include "ixheaacd_cnst.h"
71
#include "ixheaacd_acelp_info.h"
72
#include "ixheaacd_sbrdecsettings.h"
73
#include "ixheaacd_info.h"
74
#include "ixheaacd_struct.h"
75
76
#include "ixheaacd_sbrdecoder.h"
77
#include "ixheaacd_mps_polyphase.h"
78
#include "ixheaac_sbr_const.h"
79
#include "ixheaacd_main.h"
80
#include "ixheaacd_ec.h"
81
#include "ixheaacd_arith_dec.h"
82
#include "ixheaacd_bit_extract.h"
83
#include "ixheaacd_create.h"
84
85
#include "ixheaacd_func_def.h"
86
#include "ixheaacd_mps_interface.h"
87
#include "ixheaacd_mps_polyphase.h"
88
89
#include "ixheaacd_defines.h"
90
91
#include "ixheaacd_sbr_scale.h"
92
#include "ixheaacd_lpp_tran.h"
93
#include "ixheaacd_hybrid.h"
94
#include "ixheaacd_ps_dec.h"
95
#include "ixheaacd_env_extr.h"
96
#include "ixheaacd_env_calc.h"
97
#include "ixheaacd_qmf_dec.h"
98
99
#include "ixheaacd_pvc_dec.h"
100
#include "ixheaacd_sbr_dec.h"
101
102
#include "ixheaacd_error_codes.h"
103
104
220k
#define MAXNRSBRELEMENTS 6
105
106
VOID ixheaacd_allocate_sbr_scr(ia_sbr_scr_struct *sbr_scratch_struct, VOID *base_scratch_ptr,
107
                               VOID *output_ptr, WORD32 total_channels, WORD8 *p_qshift_arr,
108
                               UWORD8 slot_element, WORD32 channel);
109
110
IA_ERRORCODE ixheaacd_esbr_process(ia_usac_data_struct *usac_data,
111
                                   ia_bit_buf_struct *it_bit_buff,
112
                                   WORD32 stereo_config_idx,
113
                                   WORD16 num_channels,
114
                                   WORD32 audio_object_type,
115
221k
                                   WORD32 heaac_mps_present) {
116
221k
  WORD32 ch;
117
221k
  WORD32 err_code = 0;
118
221k
  ia_aac_dec_sbr_bitstream_struct *esbr_bit_str = &usac_data->esbr_bit_str[0];
119
221k
  ia_handle_sbr_dec_inst_struct self = usac_data->pstr_esbr_dec;
120
121
221k
  ia_sbr_scr_struct sbr_scratch_struct;
122
221k
  ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, usac_data->sbr_scratch_mem_base, NULL, 0, NULL,
123
221k
                            0, 0);
124
125
221k
  self->usac_independency_flag = usac_data->usac_independency_flg;
126
127
221k
  self->time_sample_buf[0] = usac_data->time_sample_vector[0];
128
221k
  self->time_sample_buf[1] = usac_data->time_sample_vector[1];
129
221k
  self->stereo_config_idx = stereo_config_idx;
130
131
221k
  self->sbr_mode = usac_data->sbr_mode;
132
221k
  self->aot_usac_flag = usac_data->usac_flag;
133
221k
  self->esbr_hq = usac_data->esbr_hq;
134
221k
  self->enh_sbr = usac_data->enh_sbr;
135
221k
  self->enh_sbr_ps = usac_data->enh_sbr_ps;
136
221k
  self->ec_flag = usac_data->ec_flag;
137
221k
  self->first_frame = usac_data->first_frame;
138
221k
  self->frame_ok = usac_data->frame_ok;
139
221k
  self->sbr_parse_complete = usac_data->sbr_parse_complete;
140
141
526k
  for (ch = 0; ch < num_channels; ch++) {
142
305k
    if ((self->pstr_sbr_channel[ch]
143
305k
             ->str_sbr_dec.str_synthesis_qmf_bank.qmf_filter_state_size) <
144
305k
        QMF_FILTER_STATE_SYN_SIZE)
145
0
      return IA_FATAL_ERROR;
146
305k
  }
147
148
221k
  err_code = ixheaacd_applysbr(self, esbr_bit_str, NULL, &num_channels, 1, 0, 0,
149
221k
                               &sbr_scratch_struct, 0, 1, 0, it_bit_buff, NULL,
150
221k
                               0, audio_object_type, 0, 0, 1024,
151
221k
                               heaac_mps_present, self->ec_flag, self->first_frame);
152
153
221k
  usac_data->sbr_mode = self->sbr_mode;
154
155
221k
  return err_code;
156
221k
}
157
158
IA_ERRORCODE ixheaacd_esbr_parse(ia_usac_data_struct *usac_data, ia_bit_buf_struct *it_bit_buff,
159
                                 WORD32 stereo_config_idx, WORD16 num_channels,
160
                                 WORD32 audio_object_type)
161
0
{
162
0
  WORD32 err_code = 0;
163
0
  ia_aac_dec_sbr_bitstream_struct *esbr_bit_str = &usac_data->esbr_bit_str[0];
164
0
  ia_handle_sbr_dec_inst_struct self = usac_data->pstr_esbr_dec;
165
166
0
  ia_sbr_scr_struct sbr_scratch_struct;
167
0
  jmp_buf local;
168
0
  ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, usac_data->sbr_scratch_mem_base, NULL, 0, NULL,
169
0
                            0, 0);
170
171
0
  self->usac_independency_flag = usac_data->usac_independency_flg;
172
173
0
  self->time_sample_buf[0] = usac_data->time_sample_vector[0];
174
0
  self->time_sample_buf[1] = usac_data->time_sample_vector[1];
175
0
  self->stereo_config_idx = stereo_config_idx;
176
0
  self->pstr_sbr_channel[0]->str_sbr_dec.time_sample_buf = self->time_sample_buf[0];
177
0
  self->pstr_sbr_channel[1]->str_sbr_dec.time_sample_buf = self->time_sample_buf[1];
178
179
0
  self->sbr_mode = usac_data->sbr_mode;
180
0
  self->aot_usac_flag = usac_data->usac_flag;
181
0
  self->esbr_hq = usac_data->esbr_hq;
182
0
  self->enh_sbr = usac_data->enh_sbr;
183
0
  self->enh_sbr_ps = usac_data->enh_sbr_ps;
184
0
  self->ec_flag = usac_data->ec_flag;
185
0
  self->first_frame = usac_data->first_frame;
186
0
  self->frame_ok = usac_data->frame_ok;
187
0
  self->sbr_parse_err_flag = usac_data->sbr_parse_err_flag;
188
189
0
  if (usac_data->ec_flag) {
190
0
    err_code = setjmp(local);
191
0
  }
192
0
  if (err_code == 0) {
193
0
    if (usac_data->ec_flag) {
194
0
      it_bit_buff->xaac_jmp_buf = &local;
195
0
    }
196
0
    err_code = ixheaacd_parse_sbr(self, esbr_bit_str, &num_channels, self->frame_ok,
197
0
                                  &sbr_scratch_struct, it_bit_buff, audio_object_type);
198
0
  } else {
199
0
    usac_data->frame_ok = 0;
200
0
    self->frame_ok = usac_data->frame_ok;
201
0
  }
202
203
0
  usac_data->sbr_mode = self->sbr_mode;
204
0
  usac_data->sbr_parse_err_flag = self->sbr_parse_err_flag;
205
0
  usac_data->sbr_parse_complete = self->sbr_parse_complete;
206
207
0
  return err_code;
208
0
}
209
210
static VOID ixheaacd_sbr_ext_data_read(ia_bit_buf_struct *it_bit_buff,
211
220k
    ia_aac_dec_sbr_bitstream_struct *esbr_bit_str) {
212
220k
  WORD32 count = 0;
213
220k
  WORD32 read_bits = 0;
214
220k
  WORD32 unaligned_bits = 0;
215
220k
  WORD32 cnt_bits_in;
216
217
220k
  cnt_bits_in = it_bit_buff->cnt_bits;
218
220k
  count = (it_bit_buff->cnt_bits) >> 3;
219
220k
  if (count > 0) {
220
220k
    if ((esbr_bit_str->no_elements < MAXNRSBRELEMENTS)) {
221
220k
      esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].extension_type =
222
220k
          EXT_SBR_DATA;
223
220k
      esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].size_payload = count;
224
225
220k
      read_bits = count << 3;
226
227
220k
      unaligned_bits = (cnt_bits_in - read_bits);
228
220k
      if (unaligned_bits > 0 && unaligned_bits < 8) {
229
201k
        count++;
230
201k
        esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].size_payload =
231
201k
            count;
232
201k
      }
233
220k
      esbr_bit_str->no_elements += 1;
234
220k
    }
235
220k
  }
236
220k
}
237
238
static WORD32 ixheaacd_read_ext_element(UWORD32 usac_ext_element_default_length,
239
                                        UWORD32 usac_ext_element_payload_frag,
240
                                        ia_bit_buf_struct *it_bit_buff
241
                                       ,
242
                                        ia_usac_decoder_config_struct *pstr_usac_dec_config,
243
                                        WORD32 elem_idx,
244
389k
                                        WORD32 *frame_ok) {
245
389k
  UWORD32 usac_ext_element_present;
246
389k
  UWORD32 usac_ext_element_use_dft_length;
247
389k
  UWORD32 pay_load_length;
248
389k
  WORD32 i;
249
389k
  usac_ext_element_present = ixheaacd_read_bits_buf(it_bit_buff, 1);
250
251
389k
  if (usac_ext_element_present) {
252
25.6k
    usac_ext_element_use_dft_length = ixheaacd_read_bits_buf(it_bit_buff, 1);
253
254
25.6k
    if (usac_ext_element_use_dft_length) {
255
10.6k
      pay_load_length = usac_ext_element_default_length;
256
14.9k
    } else {
257
14.9k
      pay_load_length = ixheaacd_read_bits_buf(it_bit_buff, 8);
258
259
14.9k
      if (pay_load_length == 255) {
260
31
        WORD32 val_add = 0;
261
31
        val_add = ixheaacd_read_bits_buf(it_bit_buff, 16);
262
31
        pay_load_length = (UWORD32)((WORD32)pay_load_length + val_add - 2);
263
31
      }
264
14.9k
    }
265
25.6k
    if ((it_bit_buff->cnt_bits >> 3) < (WORD32)pay_load_length) {
266
177
      *frame_ok = 0;
267
177
      longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
268
177
    }
269
25.4k
    if (pay_load_length > 0) {
270
15.7k
      if (usac_ext_element_payload_frag)
271
5.10k
        ixheaacd_read_bits_buf(it_bit_buff, 2);
272
273
15.7k
      if (pstr_usac_dec_config->usac_ext_ele_payload_present[elem_idx]) {
274
3.93k
        WORD32 preroll_counter = pstr_usac_dec_config->preroll_counter;
275
3.93k
        int payload_buffer_offeset = 0;
276
3.93k
        for (i = 0; i < preroll_counter; i++)
277
0
          payload_buffer_offeset +=
278
0
              pstr_usac_dec_config->usac_ext_gain_payload_len[i] *
279
0
              sizeof(WORD8);
280
3.93k
        if ((pay_load_length + payload_buffer_offeset) >
281
3.93k
            (MAX_AUDIO_PREROLLS * 768))
282
1
          return IA_FATAL_ERROR;
283
53.4k
        for (i = 0; i < ((WORD32)pay_load_length); i++) {
284
49.5k
          pstr_usac_dec_config
285
49.5k
              ->usac_ext_gain_payload_buf[i + payload_buffer_offeset] =
286
49.5k
              ixheaacd_read_bits_buf(it_bit_buff, 8);
287
49.5k
        }
288
3.93k
        pstr_usac_dec_config->usac_ext_gain_payload_len[preroll_counter] +=
289
3.93k
            pay_load_length;
290
11.8k
      } else {
291
11.8k
        if (it_bit_buff->cnt_bits < (WORD32)(pay_load_length << 3)) {
292
1
          longjmp(*(it_bit_buff->xaac_jmp_buf),
293
1
                  IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
294
1
        }
295
11.8k
        it_bit_buff->ptr_read_next =
296
11.8k
            it_bit_buff->ptr_read_next + pay_load_length;
297
11.8k
        it_bit_buff->cnt_bits =
298
11.8k
            it_bit_buff->cnt_bits - (WORD32)(pay_load_length << 3);
299
11.8k
      }
300
15.7k
    }
301
25.4k
  }
302
389k
  return 0;
303
389k
}
304
305
static VOID ixheaacd_sbr_ele_type_set(
306
    ia_aac_dec_sbr_bitstream_struct *esbr_bit_str0,
307
    ia_aac_dec_sbr_bitstream_struct *esbr_bit_str1, WORD32 ele_id,
308
259k
    WORD32 st_config_idx) {
309
259k
  if (ele_id == ID_USAC_SCE) {
310
118k
    esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
311
118k
        SBR_ID_SCE;
312
118k
    esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
313
118k
        SBR_ID_SCE;
314
118k
  }
315
259k
  if (ele_id == ID_USAC_CPE) {
316
139k
    if ((st_config_idx == 0) || (st_config_idx == 3)) {
317
91.2k
      esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
318
91.2k
          SBR_ID_CPE;
319
91.2k
      esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
320
91.2k
          SBR_ID_CPE;
321
91.2k
    } else {
322
48.3k
      esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
323
48.3k
          SBR_ID_SCE;
324
48.3k
      esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
325
48.3k
          SBR_ID_SCE;
326
48.3k
    }
327
139k
  }
328
259k
  if (ele_id == ID_USAC_LFE) {
329
1.29k
    esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
330
1.29k
        SBR_ID_SCE;
331
1.29k
    esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
332
1.29k
        SBR_ID_SCE;
333
334
1.29k
    esbr_bit_str0->no_elements++;
335
1.29k
    esbr_bit_str0->str_sbr_ele[0].size_payload = 0;
336
1.29k
  }
337
259k
}
338
339
47.8k
VOID ixheaacd_ms_processing(ia_usac_data_struct *pstr_usac_data) {
340
47.8k
  WORD32 i;
341
342
47.8k
  FLOAT32 tmp, tmp1;
343
47.8k
  FLOAT32 ms_factor = (FLOAT32)0.7071067812;
344
48.9M
  for (i = 0; i < pstr_usac_data->ccfl; i++) {
345
48.9M
    tmp = (FLOAT32)((pstr_usac_data->time_sample_vector[0][i] +
346
48.9M
                     pstr_usac_data->time_sample_vector[1][i]) *
347
48.9M
                    ms_factor);
348
48.9M
    tmp1 = (FLOAT32)((pstr_usac_data->time_sample_vector[0][i] -
349
48.9M
                      pstr_usac_data->time_sample_vector[1][i]) *
350
48.9M
                     ms_factor);
351
48.9M
    pstr_usac_data->time_sample_vector[1][i] = tmp1;
352
48.9M
    pstr_usac_data->time_sample_vector[0][i] = tmp;
353
48.9M
  }
354
47.8k
}
355
356
WORD32 ixheaacd_usac_process(ia_dec_data_struct *pstr_dec_data,
357
231k
                             WORD32 *num_out_channels, VOID *codec_handle) {
358
231k
  WORD32 ele_id = 0;
359
231k
  WORD32 err_code = 0;
360
361
231k
  ia_aac_dec_state_struct *p_state_aac_dec =
362
231k
      (ia_aac_dec_state_struct *)codec_handle;
363
364
231k
  ia_usac_data_struct *pstr_usac_data = &(pstr_dec_data->str_usac_data);
365
231k
  ia_bit_buf_struct *it_bit_buff = &pstr_dec_data->dec_bit_buf;
366
367
231k
  ia_frame_data_struct *fd = &(pstr_dec_data->str_frame_data);
368
369
231k
  ia_usac_config_struct *pstr_usac_config =
370
231k
      &(fd->str_audio_specific_config.str_usac_config);
371
231k
  ia_usac_decoder_config_struct *pstr_usac_dec_config =
372
231k
      &(fd->str_audio_specific_config.str_usac_config.str_usac_dec_config);
373
374
231k
  WORD32 err = 0;
375
231k
  WORD16 nr_core_coder_channels = 0;
376
231k
  WORD32 ch_offset = 0;
377
378
231k
  WORD32 elem_idx = 0;
379
231k
  WORD32 num_ch_out = 0;
380
231k
  WORD32 num_elements = pstr_usac_dec_config->num_elements;
381
231k
  UWORD32 ec_flag = p_state_aac_dec->p_config->ui_err_conceal;
382
383
231k
  if (ec_flag) {
384
0
    if (it_bit_buff->cnt_bits < 16) {
385
0
      pstr_dec_data->str_usac_data.frame_ok = 0;
386
0
    }
387
0
    if (pstr_dec_data->str_usac_data.frame_ok == 1) {
388
0
      pstr_usac_data->usac_independency_flg = ixheaacd_read_bits_buf(it_bit_buff, 1);
389
0
    }
390
231k
  } else {
391
231k
    pstr_usac_data->usac_independency_flg = ixheaacd_read_bits_buf(it_bit_buff, 1);
392
231k
  }
393
394
231k
  if (pstr_usac_data->ec_flag && pstr_dec_data->str_usac_data.frame_ok == 1) {
395
0
    if (!(pstr_usac_data->last_frame_ok) && !(pstr_usac_data->usac_independency_flg)) {
396
0
      pstr_dec_data->str_usac_data.frame_ok = 0;
397
0
    } else {
398
0
      pstr_dec_data->str_usac_data.frame_ok = 1;
399
0
    }
400
0
  }
401
402
879k
  for (elem_idx = 0; elem_idx < num_elements; elem_idx++) {
403
651k
    WORD32 stereo_config_index =
404
651k
        pstr_usac_config->str_usac_dec_config.str_usac_element_config[elem_idx]
405
651k
            .stereo_config_index;
406
651k
    jmp_buf local;
407
651k
    if (ec_flag) {
408
0
      err = setjmp(local);
409
0
    }
410
411
651k
    pstr_usac_data->esbr_bit_str[0].no_elements = 0;
412
651k
    pstr_usac_data->esbr_bit_str[1].no_elements = 0;
413
414
651k
    if (!err) {
415
651k
      if (ec_flag) {
416
0
        it_bit_buff->xaac_jmp_buf = &local;
417
0
      }
418
651k
      switch (ele_id = pstr_usac_dec_config->usac_element_type[elem_idx]) {
419
119k
        case ID_USAC_SCE:
420
119k
          nr_core_coder_channels = 1;
421
119k
          num_ch_out += 1;
422
119k
          goto core_data_extracting;
423
424
140k
        case ID_USAC_CPE:
425
140k
          nr_core_coder_channels = (stereo_config_index == 1) ? 1 : 2;
426
140k
          if (((stereo_config_index > 1) || (stereo_config_index == 0)) &&
427
140k
              (p_state_aac_dec->num_of_output_ch < 2))
428
2
            return -1;
429
140k
          num_ch_out += 2;
430
140k
          goto core_data_extracting;
431
1.33k
        case ID_USAC_LFE:
432
1.33k
          nr_core_coder_channels = 1;
433
1.33k
          num_ch_out += 1;
434
435
261k
        core_data_extracting:
436
261k
          if (!ec_flag) {
437
261k
            if (ch_offset >= MAX_NUM_CHANNELS_USAC_LVL2) return -1;
438
261k
            if (num_ch_out > MAX_NUM_CHANNELS_USAC_LVL2) return -1;
439
261k
          } else {
440
0
            if ((ch_offset >= MAX_NUM_CHANNELS_USAC_LVL2) ||
441
0
                (num_ch_out > MAX_NUM_CHANNELS_USAC_LVL2)) {
442
0
              pstr_usac_data->frame_ok = 0;
443
0
            }
444
0
          }
445
446
261k
          err = ixheaacd_core_coder_data(ele_id, pstr_usac_data, elem_idx, ch_offset, it_bit_buff,
447
261k
                                         nr_core_coder_channels);
448
261k
          if (!ec_flag) {
449
259k
            if (err != 0) return -1;
450
259k
          } else {
451
1.49k
            if (err != 0) pstr_usac_data->frame_ok = 0;
452
1.49k
          }
453
454
260k
          ixheaacd_sbr_ele_type_set(&pstr_usac_data->esbr_bit_str[0],
455
260k
                                    &pstr_usac_data->esbr_bit_str[1], ele_id,
456
260k
                                    stereo_config_index);
457
458
260k
          if (pstr_usac_data->mps_pseudo_lr[elem_idx]) ixheaacd_ms_processing(pstr_usac_data);
459
460
260k
          if (ele_id != ID_USAC_LFE) {
461
257k
            if (pstr_usac_data->sbr_ratio_idx > 0)
462
220k
              ixheaacd_sbr_ext_data_read(it_bit_buff, &pstr_usac_data->esbr_bit_str[0]);
463
257k
          }
464
465
260k
          if ((pstr_usac_data->sbr_ratio_idx > 0) &&
466
260k
              (pstr_usac_data->esbr_bit_str[0].no_elements != 0)) {
467
221k
            if (ec_flag) {
468
0
              pstr_usac_data->first_frame = p_state_aac_dec->first_frame;
469
0
            }
470
221k
            err_code = ixheaacd_esbr_process(
471
221k
                pstr_usac_data, it_bit_buff, stereo_config_index, nr_core_coder_channels,
472
221k
                pstr_dec_data->str_frame_data.str_audio_specific_config.audio_object_type,
473
221k
                p_state_aac_dec->heaac_mps_handle.heaac_mps_present);
474
221k
            if (!ec_flag) {
475
221k
              if (err_code < 0) return err_code;
476
221k
            } else {
477
185
              if (err_code < 0) pstr_usac_data->frame_ok = 0;
478
185
            }
479
221k
          }
480
481
260k
          if (stereo_config_index > 0 && pstr_usac_data->sbr_ratio_idx > 0) {
482
91.2k
            FLOAT32 **ptr_inp[2 * 2];
483
91.2k
            WORD32 ch;
484
485
91.2k
            *num_out_channels = p_state_aac_dec->mps_dec_handle.out_ch_count;
486
487
91.2k
            if (!ec_flag && pstr_usac_data->frame_ok == 1) {
488
91.2k
              if (ec_flag) {
489
0
                it_bit_buff->xaac_jmp_buf = &local;
490
0
              }
491
91.2k
              err =
492
91.2k
                  ixheaacd_mps_frame_parsing(&p_state_aac_dec->mps_dec_handle,
493
91.2k
                                             pstr_usac_data->usac_independency_flg, it_bit_buff);
494
91.2k
              if (err) return err;
495
91.2k
            }
496
497
91.1k
            p_state_aac_dec->mps_dec_handle.band_count[0] =
498
91.1k
                pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[0]->str_sbr_dec.band_count;
499
91.1k
            p_state_aac_dec->mps_dec_handle.band_count[1] =
500
91.1k
                pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]->str_sbr_dec.band_count;
501
502
251k
            for (ch = 0; ch < nr_core_coder_channels; ch++) {
503
159k
              ptr_inp[2 * ch] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]
504
159k
                                    ->str_sbr_dec.pp_qmf_buf_real;
505
159k
              ptr_inp[2 * ch + 1] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]
506
159k
                                        ->str_sbr_dec.pp_qmf_buf_imag;
507
159k
              p_state_aac_dec->mps_dec_handle.p_sbr_dec[ch] =
508
159k
                  (VOID *)(&pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]->str_sbr_dec);
509
159k
              p_state_aac_dec->mps_dec_handle.p_sbr_header[ch] =
510
159k
                  (VOID *)(pstr_usac_data->pstr_esbr_dec->pstr_sbr_header[ch]);
511
159k
              p_state_aac_dec->mps_dec_handle.p_sbr_frame[ch] =
512
159k
                  (VOID *)(pstr_usac_data->pstr_esbr_dec->frame_buffer[ch]);
513
159k
            }
514
91.1k
            if (nr_core_coder_channels == 1) {
515
22.2k
              if (p_state_aac_dec->mps_dec_handle.res_ch_count != 0) {
516
0
                ptr_inp[2] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]
517
0
                                 ->str_sbr_dec.pp_qmf_buf_real;
518
0
                ptr_inp[2 + 1] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]
519
0
                                     ->str_sbr_dec.pp_qmf_buf_imag;
520
0
              }
521
22.2k
              p_state_aac_dec->mps_dec_handle.p_sbr_dec[1] =
522
22.2k
                  (VOID *)(&pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]->str_sbr_dec);
523
22.2k
              p_state_aac_dec->mps_dec_handle.p_sbr_header[1] =
524
22.2k
                  (VOID *)(pstr_usac_data->pstr_esbr_dec->pstr_sbr_header[1]);
525
22.2k
              p_state_aac_dec->mps_dec_handle.p_sbr_frame[1] =
526
22.2k
                  (VOID *)(pstr_usac_data->pstr_esbr_dec->frame_buffer[1]);
527
22.2k
            }
528
91.1k
            if ((!ec_flag || !p_state_aac_dec->first_frame) &&
529
91.1k
                p_state_aac_dec->mps_dec_handle.mps_init_done == 1) {
530
91.0k
              err = ixheaacd_mps_apply(&p_state_aac_dec->mps_dec_handle, ptr_inp,
531
91.0k
                                       pstr_usac_data->time_sample_vector);
532
91.0k
              if (!ec_flag) {
533
91.0k
                if (err) return err;
534
91.0k
              } else {
535
0
                if (err) pstr_usac_data->frame_ok = 0;
536
0
              }
537
91.0k
            }
538
91.0k
            if (ec_flag) {
539
0
              pstr_usac_data->first_frame = p_state_aac_dec->first_frame;
540
0
              err_code = ixheaacd_esbr_parse(
541
0
                  pstr_usac_data, it_bit_buff, stereo_config_index, nr_core_coder_channels,
542
0
                  pstr_dec_data->str_frame_data.str_audio_specific_config.audio_object_type);
543
544
0
              if (err_code < 0) pstr_usac_data->frame_ok = 0;
545
0
              if (ec_flag) {
546
0
                err = setjmp(local);
547
0
              }
548
0
              if (err == 0 && pstr_usac_data->frame_ok == 1) {
549
0
                if (ec_flag) {
550
0
                  it_bit_buff->xaac_jmp_buf = &local;
551
0
                }
552
0
                err = ixheaacd_mps_frame_parsing(&p_state_aac_dec->mps_dec_handle,
553
0
                                                 pstr_usac_data->usac_independency_flg,
554
0
                                                 it_bit_buff);
555
0
                if (err) pstr_usac_data->frame_ok = 0;
556
0
              } else {
557
0
                pstr_usac_data->frame_ok = 0;
558
0
                if (p_state_aac_dec->mps_dec_handle.num_parameter_sets_prev < 1) {
559
0
                  p_state_aac_dec->mps_dec_handle.num_parameter_sets_prev = 1;
560
0
                }
561
0
              }
562
0
            }
563
169k
          } else if ((pstr_usac_data->sbr_ratio_idx > 0) &&
564
169k
                     (pstr_usac_data->esbr_bit_str[0].no_elements != 0) && ec_flag) {
565
0
            pstr_usac_data->first_frame = p_state_aac_dec->first_frame;
566
0
            err_code = ixheaacd_esbr_parse(
567
0
                pstr_usac_data, it_bit_buff, stereo_config_index, nr_core_coder_channels,
568
0
                pstr_dec_data->str_frame_data.str_audio_specific_config.audio_object_type);
569
0
            if (err_code < 0) pstr_usac_data->frame_ok = 0;
570
0
          }
571
260k
          if (ec_flag) {
572
0
            p_state_aac_dec->first_frame = 0;
573
0
          }
574
575
260k
          ch_offset += nr_core_coder_channels;
576
260k
          break;
577
578
389k
        case ID_USAC_EXT: {
579
389k
          ia_usac_dec_element_config_struct *pusac_element_config =
580
389k
              &pstr_usac_dec_config->str_usac_element_config[elem_idx];
581
389k
          if (pstr_usac_data->frame_ok) {
582
389k
            err = ixheaacd_read_ext_element(pusac_element_config->usac_ext_eleme_def_len,
583
389k
                                            pusac_element_config->usac_ext_elem_pld_frag,
584
389k
                                            it_bit_buff, pstr_usac_dec_config, elem_idx,
585
389k
                                            &pstr_usac_data->frame_ok);
586
389k
            if (!ec_flag) {
587
389k
              if (err != 0) return err;
588
389k
            } else {
589
211
              if (err) pstr_usac_data->frame_ok = 0;
590
211
            }
591
389k
          }
592
389k
          break;
593
389k
        }
594
595
389k
        default:
596
597
0
          return -1;
598
599
0
          break;
600
651k
      }
601
651k
    }
602
651k
  }
603
228k
  pstr_usac_data->last_frame_ok = pstr_usac_data->frame_ok;
604
605
228k
  return 0;
606
231k
}