Coverage Report

Created: 2024-05-20 06:52

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