Coverage Report

Created: 2025-08-11 07:08

/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
227k
#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
227k
                                   WORD32 heaac_mps_present) {
116
227k
  WORD32 ch;
117
227k
  WORD32 err_code = 0;
118
227k
  ia_aac_dec_sbr_bitstream_struct *esbr_bit_str = &usac_data->esbr_bit_str[0];
119
227k
  ia_handle_sbr_dec_inst_struct self = usac_data->pstr_esbr_dec;
120
121
227k
  ia_sbr_scr_struct sbr_scratch_struct;
122
227k
  ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, usac_data->sbr_scratch_mem_base, NULL, 0, NULL,
123
227k
                            0, 0);
124
125
227k
  self->usac_independency_flag = usac_data->usac_independency_flg;
126
127
227k
  self->time_sample_buf[0] = usac_data->time_sample_vector[0];
128
227k
  self->time_sample_buf[1] = usac_data->time_sample_vector[1];
129
227k
  self->stereo_config_idx = stereo_config_idx;
130
131
227k
  self->sbr_mode = usac_data->sbr_mode;
132
227k
  self->aot_usac_flag = usac_data->usac_flag;
133
227k
  self->esbr_hq = usac_data->esbr_hq;
134
227k
  self->enh_sbr = usac_data->enh_sbr;
135
227k
  self->enh_sbr_ps = usac_data->enh_sbr_ps;
136
227k
  self->ec_flag = usac_data->ec_flag;
137
227k
  self->first_frame = usac_data->first_frame;
138
227k
  self->frame_ok = usac_data->frame_ok;
139
227k
  self->sbr_parse_complete = usac_data->sbr_parse_complete;
140
141
540k
  for (ch = 0; ch < num_channels; ch++) {
142
312k
    if ((self->pstr_sbr_channel[ch]
143
312k
             ->str_sbr_dec.str_synthesis_qmf_bank.qmf_filter_state_size) <
144
312k
        QMF_FILTER_STATE_SYN_SIZE)
145
0
      return IA_FATAL_ERROR;
146
312k
  }
147
148
227k
  err_code = ixheaacd_applysbr(self, esbr_bit_str, NULL, &num_channels, 1, 0, 0,
149
227k
                               &sbr_scratch_struct, 0, 1, 0, it_bit_buff, NULL,
150
227k
                               0, audio_object_type, 0, 0, 1024,
151
227k
                               heaac_mps_present, self->ec_flag, self->first_frame);
152
153
227k
  usac_data->sbr_mode = self->sbr_mode;
154
155
227k
  return err_code;
156
227k
}
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
227k
    ia_aac_dec_sbr_bitstream_struct *esbr_bit_str) {
212
227k
  WORD32 count = 0;
213
227k
  WORD32 read_bits = 0;
214
227k
  WORD32 unaligned_bits = 0;
215
227k
  WORD32 cnt_bits_in;
216
217
227k
  cnt_bits_in = it_bit_buff->cnt_bits;
218
227k
  count = (it_bit_buff->cnt_bits) >> 3;
219
227k
  if (count > 0) {
220
227k
    if ((esbr_bit_str->no_elements < MAXNRSBRELEMENTS)) {
221
227k
      esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].extension_type =
222
227k
          EXT_SBR_DATA;
223
227k
      esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].size_payload = count;
224
225
227k
      read_bits = count << 3;
226
227
227k
      unaligned_bits = (cnt_bits_in - read_bits);
228
227k
      if (unaligned_bits > 0 && unaligned_bits < 8) {
229
205k
        count++;
230
205k
        esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].size_payload =
231
205k
            count;
232
205k
      }
233
227k
      esbr_bit_str->no_elements += 1;
234
227k
    }
235
227k
  }
236
227k
}
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
381k
                                        WORD32 *frame_ok) {
245
381k
  UWORD32 usac_ext_element_present;
246
381k
  UWORD32 usac_ext_element_use_dft_length;
247
381k
  UWORD32 pay_load_length;
248
381k
  WORD32 i;
249
381k
  usac_ext_element_present = ixheaacd_read_bits_buf(it_bit_buff, 1);
250
251
381k
  if (usac_ext_element_present) {
252
24.5k
    usac_ext_element_use_dft_length = ixheaacd_read_bits_buf(it_bit_buff, 1);
253
254
24.5k
    if (usac_ext_element_use_dft_length) {
255
10.2k
      pay_load_length = usac_ext_element_default_length;
256
14.2k
    } else {
257
14.2k
      pay_load_length = ixheaacd_read_bits_buf(it_bit_buff, 8);
258
259
14.2k
      if (pay_load_length == 255) {
260
58
        WORD32 val_add = 0;
261
58
        val_add = ixheaacd_read_bits_buf(it_bit_buff, 16);
262
58
        pay_load_length = (UWORD32)((WORD32)pay_load_length + val_add - 2);
263
58
      }
264
14.2k
    }
265
24.5k
    if ((it_bit_buff->cnt_bits >> 3) < (WORD32)pay_load_length) {
266
166
      *frame_ok = 0;
267
166
      longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
268
166
    }
269
24.3k
    if (pay_load_length > 0) {
270
15.1k
      if (usac_ext_element_payload_frag)
271
5.82k
        ixheaacd_read_bits_buf(it_bit_buff, 2);
272
273
15.1k
      if (pstr_usac_dec_config->usac_ext_ele_payload_present[elem_idx]) {
274
2.95k
        WORD32 preroll_counter = pstr_usac_dec_config->preroll_counter;
275
2.95k
        int payload_buffer_offeset = 0;
276
2.95k
        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
2.95k
        if ((pay_load_length + payload_buffer_offeset) >
281
2.95k
            (MAX_AUDIO_PREROLLS * 768))
282
1
          return IA_FATAL_ERROR;
283
74.4k
        for (i = 0; i < ((WORD32)pay_load_length); i++) {
284
71.5k
          pstr_usac_dec_config
285
71.5k
              ->usac_ext_gain_payload_buf[i + payload_buffer_offeset] =
286
71.5k
              ixheaacd_read_bits_buf(it_bit_buff, 8);
287
71.5k
        }
288
2.95k
        pstr_usac_dec_config->usac_ext_gain_payload_len[preroll_counter] +=
289
2.95k
            pay_load_length;
290
12.1k
      } else {
291
12.1k
        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
12.1k
        it_bit_buff->ptr_read_next =
296
12.1k
            it_bit_buff->ptr_read_next + pay_load_length;
297
12.1k
        it_bit_buff->cnt_bits =
298
12.1k
            it_bit_buff->cnt_bits - (WORD32)(pay_load_length << 3);
299
12.1k
      }
300
15.1k
    }
301
24.3k
  }
302
381k
  return 0;
303
381k
}
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
269k
    WORD32 st_config_idx) {
309
269k
  if (ele_id == ID_USAC_SCE) {
310
122k
    esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
311
122k
        SBR_ID_SCE;
312
122k
    esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
313
122k
        SBR_ID_SCE;
314
122k
  }
315
269k
  if (ele_id == ID_USAC_CPE) {
316
145k
    if ((st_config_idx == 0) || (st_config_idx == 3)) {
317
95.3k
      esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
318
95.3k
          SBR_ID_CPE;
319
95.3k
      esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
320
95.3k
          SBR_ID_CPE;
321
95.3k
    } else {
322
50.1k
      esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
323
50.1k
          SBR_ID_SCE;
324
50.1k
      esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
325
50.1k
          SBR_ID_SCE;
326
50.1k
    }
327
145k
  }
328
269k
  if (ele_id == ID_USAC_LFE) {
329
914
    esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
330
914
        SBR_ID_SCE;
331
914
    esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
332
914
        SBR_ID_SCE;
333
334
914
    esbr_bit_str0->no_elements++;
335
914
    esbr_bit_str0->str_sbr_ele[0].size_payload = 0;
336
914
  }
337
269k
}
338
339
48.7k
VOID ixheaacd_ms_processing(ia_usac_data_struct *pstr_usac_data) {
340
48.7k
  WORD32 i;
341
342
48.7k
  FLOAT32 tmp, tmp1;
343
48.7k
  FLOAT32 ms_factor = (FLOAT32)0.7071067812;
344
49.9M
  for (i = 0; i < pstr_usac_data->ccfl; i++) {
345
49.9M
    tmp = (FLOAT32)((pstr_usac_data->time_sample_vector[0][i] +
346
49.9M
                     pstr_usac_data->time_sample_vector[1][i]) *
347
49.9M
                    ms_factor);
348
49.9M
    tmp1 = (FLOAT32)((pstr_usac_data->time_sample_vector[0][i] -
349
49.9M
                      pstr_usac_data->time_sample_vector[1][i]) *
350
49.9M
                     ms_factor);
351
49.9M
    pstr_usac_data->time_sample_vector[1][i] = tmp1;
352
49.9M
    pstr_usac_data->time_sample_vector[0][i] = tmp;
353
49.9M
  }
354
48.7k
}
355
356
WORD32 ixheaacd_usac_process(ia_dec_data_struct *pstr_dec_data,
357
238k
                             WORD32 *num_out_channels, VOID *codec_handle) {
358
238k
  WORD32 ele_id = 0;
359
238k
  WORD32 err_code = 0;
360
361
238k
  ia_aac_dec_state_struct *p_state_aac_dec =
362
238k
      (ia_aac_dec_state_struct *)codec_handle;
363
364
238k
  ia_usac_data_struct *pstr_usac_data = &(pstr_dec_data->str_usac_data);
365
238k
  ia_bit_buf_struct *it_bit_buff = &pstr_dec_data->dec_bit_buf;
366
367
238k
  ia_frame_data_struct *fd = &(pstr_dec_data->str_frame_data);
368
369
238k
  ia_usac_config_struct *pstr_usac_config =
370
238k
      &(fd->str_audio_specific_config.str_usac_config);
371
238k
  ia_usac_decoder_config_struct *pstr_usac_dec_config =
372
238k
      &(fd->str_audio_specific_config.str_usac_config.str_usac_dec_config);
373
374
238k
  WORD32 err = 0;
375
238k
  WORD16 nr_core_coder_channels = 0;
376
238k
  WORD32 ch_offset = 0;
377
378
238k
  WORD32 elem_idx = 0;
379
238k
  WORD32 num_ch_out = 0;
380
238k
  WORD32 num_elements = pstr_usac_dec_config->num_elements;
381
238k
  UWORD32 ec_flag = p_state_aac_dec->p_config->ui_err_conceal;
382
383
238k
  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
238k
  } else {
391
238k
    pstr_usac_data->usac_independency_flg = ixheaacd_read_bits_buf(it_bit_buff, 1);
392
238k
  }
393
394
238k
  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
888k
  for (elem_idx = 0; elem_idx < num_elements; elem_idx++) {
403
653k
    WORD32 stereo_config_index =
404
653k
        pstr_usac_config->str_usac_dec_config.str_usac_element_config[elem_idx]
405
653k
            .stereo_config_index;
406
653k
    jmp_buf local;
407
653k
    if (ec_flag) {
408
0
      err = setjmp(local);
409
0
    }
410
411
653k
    pstr_usac_data->esbr_bit_str[0].no_elements = 0;
412
653k
    pstr_usac_data->esbr_bit_str[1].no_elements = 0;
413
414
653k
    if (!err) {
415
653k
      if (ec_flag) {
416
0
        it_bit_buff->xaac_jmp_buf = &local;
417
0
      }
418
653k
      switch (ele_id = pstr_usac_dec_config->usac_element_type[elem_idx]) {
419
123k
        case ID_USAC_SCE:
420
123k
          nr_core_coder_channels = 1;
421
123k
          num_ch_out += 1;
422
123k
          goto core_data_extracting;
423
424
147k
        case ID_USAC_CPE:
425
147k
          nr_core_coder_channels = (stereo_config_index == 1) ? 1 : 2;
426
147k
          if (((stereo_config_index > 1) || (stereo_config_index == 0)) &&
427
147k
              (p_state_aac_dec->num_of_output_ch < 2))
428
1
            return -1;
429
147k
          num_ch_out += 2;
430
147k
          goto core_data_extracting;
431
943
        case ID_USAC_LFE:
432
943
          nr_core_coder_channels = 1;
433
943
          num_ch_out += 1;
434
435
271k
        core_data_extracting:
436
271k
          if (!ec_flag) {
437
271k
            if (ch_offset >= MAX_NUM_CHANNELS_USAC_LVL2) return -1;
438
271k
            if (num_ch_out > MAX_NUM_CHANNELS_USAC_LVL2) return -1;
439
271k
          } 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
271k
          err = ixheaacd_core_coder_data(ele_id, pstr_usac_data, elem_idx, ch_offset, it_bit_buff,
447
271k
                                         nr_core_coder_channels);
448
271k
          if (!ec_flag) {
449
269k
            if (err != 0) return -1;
450
269k
          } else {
451
1.74k
            if (err != 0) pstr_usac_data->frame_ok = 0;
452
1.74k
          }
453
454
271k
          ixheaacd_sbr_ele_type_set(&pstr_usac_data->esbr_bit_str[0],
455
271k
                                    &pstr_usac_data->esbr_bit_str[1], ele_id,
456
271k
                                    stereo_config_index);
457
458
271k
          if (pstr_usac_data->mps_pseudo_lr[elem_idx]) ixheaacd_ms_processing(pstr_usac_data);
459
460
271k
          if (ele_id != ID_USAC_LFE) {
461
268k
            if (pstr_usac_data->sbr_ratio_idx > 0)
462
227k
              ixheaacd_sbr_ext_data_read(it_bit_buff, &pstr_usac_data->esbr_bit_str[0]);
463
268k
          }
464
465
271k
          if ((pstr_usac_data->sbr_ratio_idx > 0) &&
466
271k
              (pstr_usac_data->esbr_bit_str[0].no_elements != 0)) {
467
227k
            if (ec_flag) {
468
0
              pstr_usac_data->first_frame = p_state_aac_dec->first_frame;
469
0
            }
470
227k
            err_code = ixheaacd_esbr_process(
471
227k
                pstr_usac_data, it_bit_buff, stereo_config_index, nr_core_coder_channels,
472
227k
                pstr_dec_data->str_frame_data.str_audio_specific_config.audio_object_type,
473
227k
                p_state_aac_dec->heaac_mps_handle.heaac_mps_present);
474
227k
            if (!ec_flag) {
475
227k
              if (err_code < 0) return err_code;
476
227k
            } else {
477
179
              if (err_code < 0) pstr_usac_data->frame_ok = 0;
478
179
            }
479
227k
          }
480
481
270k
          if (stereo_config_index > 0 && pstr_usac_data->sbr_ratio_idx > 0) {
482
90.2k
            FLOAT32 **ptr_inp[2 * 2];
483
90.2k
            WORD32 ch;
484
485
90.2k
            *num_out_channels = p_state_aac_dec->mps_dec_handle.out_ch_count;
486
487
90.2k
            if (!ec_flag && pstr_usac_data->frame_ok == 1) {
488
90.2k
              if (ec_flag) {
489
0
                it_bit_buff->xaac_jmp_buf = &local;
490
0
              }
491
90.2k
              err =
492
90.2k
                  ixheaacd_mps_frame_parsing(&p_state_aac_dec->mps_dec_handle,
493
90.2k
                                             pstr_usac_data->usac_independency_flg, it_bit_buff);
494
90.2k
              if (err) return err;
495
90.2k
            }
496
497
90.2k
            p_state_aac_dec->mps_dec_handle.band_count[0] =
498
90.2k
                pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[0]->str_sbr_dec.band_count;
499
90.2k
            p_state_aac_dec->mps_dec_handle.band_count[1] =
500
90.2k
                pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]->str_sbr_dec.band_count;
501
502
247k
            for (ch = 0; ch < nr_core_coder_channels; ch++) {
503
157k
              ptr_inp[2 * ch] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]
504
157k
                                    ->str_sbr_dec.pp_qmf_buf_real;
505
157k
              ptr_inp[2 * ch + 1] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]
506
157k
                                        ->str_sbr_dec.pp_qmf_buf_imag;
507
157k
              p_state_aac_dec->mps_dec_handle.p_sbr_dec[ch] =
508
157k
                  (VOID *)(&pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]->str_sbr_dec);
509
157k
              p_state_aac_dec->mps_dec_handle.p_sbr_header[ch] =
510
157k
                  (VOID *)(pstr_usac_data->pstr_esbr_dec->pstr_sbr_header[ch]);
511
157k
              p_state_aac_dec->mps_dec_handle.p_sbr_frame[ch] =
512
157k
                  (VOID *)(pstr_usac_data->pstr_esbr_dec->frame_buffer[ch]);
513
157k
            }
514
90.2k
            if (nr_core_coder_channels == 1) {
515
22.8k
              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.8k
              p_state_aac_dec->mps_dec_handle.p_sbr_dec[1] =
522
22.8k
                  (VOID *)(&pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]->str_sbr_dec);
523
22.8k
              p_state_aac_dec->mps_dec_handle.p_sbr_header[1] =
524
22.8k
                  (VOID *)(pstr_usac_data->pstr_esbr_dec->pstr_sbr_header[1]);
525
22.8k
              p_state_aac_dec->mps_dec_handle.p_sbr_frame[1] =
526
22.8k
                  (VOID *)(pstr_usac_data->pstr_esbr_dec->frame_buffer[1]);
527
22.8k
            }
528
90.2k
            if ((!ec_flag || !p_state_aac_dec->first_frame) &&
529
90.2k
                p_state_aac_dec->mps_dec_handle.mps_init_done == 1) {
530
90.0k
              err = ixheaacd_mps_apply(&p_state_aac_dec->mps_dec_handle, ptr_inp,
531
90.0k
                                       pstr_usac_data->time_sample_vector);
532
90.0k
              if (!ec_flag) {
533
90.0k
                if (err) return err;
534
90.0k
              } else {
535
0
                if (err) pstr_usac_data->frame_ok = 0;
536
0
              }
537
90.0k
            }
538
90.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
180k
          } else if ((pstr_usac_data->sbr_ratio_idx > 0) &&
564
180k
                     (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
270k
          if (ec_flag) {
572
0
            p_state_aac_dec->first_frame = 0;
573
0
          }
574
575
270k
          ch_offset += nr_core_coder_channels;
576
270k
          break;
577
578
381k
        case ID_USAC_EXT: {
579
381k
          ia_usac_dec_element_config_struct *pusac_element_config =
580
381k
              &pstr_usac_dec_config->str_usac_element_config[elem_idx];
581
381k
          if (pstr_usac_data->frame_ok) {
582
381k
            err = ixheaacd_read_ext_element(pusac_element_config->usac_ext_eleme_def_len,
583
381k
                                            pusac_element_config->usac_ext_elem_pld_frag,
584
381k
                                            it_bit_buff, pstr_usac_dec_config, elem_idx,
585
381k
                                            &pstr_usac_data->frame_ok);
586
381k
            if (!ec_flag) {
587
381k
              if (err != 0) return err;
588
381k
            } else {
589
210
              if (err) pstr_usac_data->frame_ok = 0;
590
210
            }
591
381k
          }
592
381k
          break;
593
381k
        }
594
595
381k
        default:
596
597
0
          return -1;
598
599
0
          break;
600
653k
      }
601
653k
    }
602
653k
  }
603
235k
  pstr_usac_data->last_frame_ok = pstr_usac_data->frame_ok;
604
605
235k
  return 0;
606
238k
}