• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ixheaacd_constants.h"
24 #include "ixheaacd_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 "ixheaacd_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 #define MAXNRSBRELEMENTS 6
105 
106 VOID ixheaacd_allocate_sbr_scr(ia_sbr_scr_struct *sbr_scratch_struct,
107                                VOID *base_scratch_ptr, VOID *output_ptr,
108                                WORD total_elements, WORD ch_fac,
109                                WORD32 object_type, WORD32 total_channels,
110                                WORD8 *p_qshift_arr, UWORD8 slot_element,
111                                WORD32 channel);
112 
ixheaacd_esbr_process(ia_usac_data_struct * usac_data,ia_bit_buf_struct * it_bit_buff,WORD32 stereo_config_idx,WORD16 num_channels,WORD32 audio_object_type,WORD32 heaac_mps_present)113 IA_ERRORCODE ixheaacd_esbr_process(ia_usac_data_struct *usac_data,
114                                    ia_bit_buf_struct *it_bit_buff,
115                                    WORD32 stereo_config_idx,
116                                    WORD16 num_channels,
117                                    WORD32 audio_object_type,
118                                    WORD32 heaac_mps_present) {
119   WORD32 ch;
120   WORD32 err_code = 0;
121   ia_aac_dec_sbr_bitstream_struct *esbr_bit_str = &usac_data->esbr_bit_str[0];
122   ia_handle_sbr_dec_inst_struct self = usac_data->pstr_esbr_dec;
123 
124   ia_sbr_scr_struct sbr_scratch_struct;
125   ixheaacd_allocate_sbr_scr(&sbr_scratch_struct,
126                             usac_data->sbr_scratch_mem_base, NULL, 2, 1,
127                             audio_object_type, 0, NULL, 0, 0);
128 
129   self->usac_independency_flag = usac_data->usac_independency_flg;
130 
131   self->time_sample_buf[0] = usac_data->time_sample_vector[0];
132   self->time_sample_buf[1] = usac_data->time_sample_vector[1];
133   self->stereo_config_idx = stereo_config_idx;
134 
135   self->sbr_mode = usac_data->sbr_mode;
136   self->aot_usac_flag = usac_data->usac_flag;
137   self->esbr_hq = usac_data->esbr_hq;
138   self->enh_sbr = usac_data->enh_sbr;
139   self->enh_sbr_ps = usac_data->enh_sbr_ps;
140   self->ec_flag = usac_data->ec_flag;
141   self->first_frame = usac_data->first_frame;
142   self->frame_ok = usac_data->frame_ok;
143   self->sbr_parse_complete = usac_data->sbr_parse_complete;
144 
145   for (ch = 0; ch < num_channels; ch++) {
146     if ((self->pstr_sbr_channel[ch]
147              ->str_sbr_dec.str_synthesis_qmf_bank.qmf_filter_state_size) <
148         QMF_FILTER_STATE_SYN_SIZE)
149       return IA_FATAL_ERROR;
150   }
151 
152   err_code = ixheaacd_applysbr(self, esbr_bit_str, NULL, &num_channels, 1, 0, 0,
153                                &sbr_scratch_struct, 0, 1, 0, it_bit_buff, NULL,
154                                0, audio_object_type, 0, 0, 1024,
155                                heaac_mps_present, self->ec_flag, self->first_frame);
156 
157   usac_data->sbr_mode = self->sbr_mode;
158 
159   return err_code;
160 }
161 
ixheaacd_esbr_parse(ia_usac_data_struct * usac_data,ia_bit_buf_struct * it_bit_buff,WORD32 stereo_config_idx,WORD16 num_channels,WORD32 audio_object_type)162 IA_ERRORCODE ixheaacd_esbr_parse(ia_usac_data_struct *usac_data, ia_bit_buf_struct *it_bit_buff,
163                                  WORD32 stereo_config_idx, WORD16 num_channels,
164                                  WORD32 audio_object_type)
165 {
166   WORD32 err_code = 0;
167   ia_aac_dec_sbr_bitstream_struct *esbr_bit_str = &usac_data->esbr_bit_str[0];
168   ia_handle_sbr_dec_inst_struct self = usac_data->pstr_esbr_dec;
169 
170   ia_sbr_scr_struct sbr_scratch_struct;
171   jmp_buf local;
172   ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, usac_data->sbr_scratch_mem_base, NULL, 2, 1,
173                             audio_object_type, 0, NULL, 0, 0);
174 
175   self->usac_independency_flag = usac_data->usac_independency_flg;
176 
177   self->time_sample_buf[0] = usac_data->time_sample_vector[0];
178   self->time_sample_buf[1] = usac_data->time_sample_vector[1];
179   self->stereo_config_idx = stereo_config_idx;
180   self->pstr_sbr_channel[0]->str_sbr_dec.time_sample_buf = self->time_sample_buf[0];
181   self->pstr_sbr_channel[1]->str_sbr_dec.time_sample_buf = self->time_sample_buf[1];
182 
183   self->sbr_mode = usac_data->sbr_mode;
184   self->aot_usac_flag = usac_data->usac_flag;
185   self->esbr_hq = usac_data->esbr_hq;
186   self->enh_sbr = usac_data->enh_sbr;
187   self->enh_sbr_ps = usac_data->enh_sbr_ps;
188   self->ec_flag = usac_data->ec_flag;
189   self->first_frame = usac_data->first_frame;
190   self->frame_ok = usac_data->frame_ok;
191   self->sbr_parse_err_flag = usac_data->sbr_parse_err_flag;
192 
193   if (usac_data->ec_flag) {
194     err_code = setjmp(local);
195   }
196   if (err_code == 0) {
197     if (usac_data->ec_flag) {
198       it_bit_buff->xaac_jmp_buf = &local;
199     }
200     err_code = ixheaacd_parse_sbr(self, esbr_bit_str, &num_channels, self->frame_ok,
201                                   &sbr_scratch_struct, it_bit_buff, audio_object_type);
202   } else {
203     usac_data->frame_ok = 0;
204     self->frame_ok = usac_data->frame_ok;
205   }
206 
207   usac_data->sbr_mode = self->sbr_mode;
208   usac_data->sbr_parse_err_flag = self->sbr_parse_err_flag;
209   usac_data->sbr_parse_complete = self->sbr_parse_complete;
210 
211   return err_code;
212 }
213 
ixheaacd_sbr_ext_data_read(ia_bit_buf_struct * it_bit_buff,ia_aac_dec_sbr_bitstream_struct * esbr_bit_str)214 static VOID ixheaacd_sbr_ext_data_read(ia_bit_buf_struct *it_bit_buff,
215     ia_aac_dec_sbr_bitstream_struct *esbr_bit_str) {
216   WORD32 count = 0;
217   WORD32 read_bits = 0;
218   WORD32 unaligned_bits = 0;
219   WORD32 cnt_bits_in;
220 
221   cnt_bits_in = it_bit_buff->cnt_bits;
222   count = (it_bit_buff->cnt_bits) >> 3;
223   if (count > 0) {
224     if ((esbr_bit_str->no_elements < MAXNRSBRELEMENTS)) {
225       esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].extension_type =
226           EXT_SBR_DATA;
227       esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].size_payload = count;
228 
229       read_bits = count << 3;
230 
231       unaligned_bits = (cnt_bits_in - read_bits);
232       if (unaligned_bits > 0 && unaligned_bits < 8) {
233         count++;
234         esbr_bit_str->str_sbr_ele[esbr_bit_str->no_elements].size_payload =
235             count;
236       }
237       esbr_bit_str->no_elements += 1;
238     }
239   }
240 }
241 
ixheaacd_read_ext_element(UWORD32 usac_ext_element_default_length,UWORD32 usac_ext_element_payload_frag,ia_bit_buf_struct * it_bit_buff,ia_usac_decoder_config_struct * pstr_usac_dec_config,WORD32 elem_idx,WORD32 * frame_ok)242 static WORD32 ixheaacd_read_ext_element(UWORD32 usac_ext_element_default_length,
243                                         UWORD32 usac_ext_element_payload_frag,
244                                         ia_bit_buf_struct *it_bit_buff
245                                        ,
246                                         ia_usac_decoder_config_struct *pstr_usac_dec_config,
247                                         WORD32 elem_idx,
248                                         WORD32 *frame_ok) {
249   UWORD32 usac_ext_element_present;
250   UWORD32 usac_ext_element_use_dft_length;
251   UWORD32 pay_load_length;
252   WORD32 i;
253   usac_ext_element_present = ixheaacd_read_bits_buf(it_bit_buff, 1);
254 
255   if (usac_ext_element_present) {
256     usac_ext_element_use_dft_length = ixheaacd_read_bits_buf(it_bit_buff, 1);
257 
258     if (usac_ext_element_use_dft_length) {
259       pay_load_length = usac_ext_element_default_length;
260     } else {
261       pay_load_length = ixheaacd_read_bits_buf(it_bit_buff, 8);
262 
263       if (pay_load_length == 255) {
264         WORD32 val_add = 0;
265         val_add = ixheaacd_read_bits_buf(it_bit_buff, 16);
266         pay_load_length = (UWORD32)((WORD32)pay_load_length + val_add - 2);
267       }
268     }
269     if ((it_bit_buff->cnt_bits >> 3) < (WORD32)pay_load_length) {
270       *frame_ok = 0;
271       longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
272     }
273     if (pay_load_length > 0) {
274       if (usac_ext_element_payload_frag)
275         ixheaacd_read_bits_buf(it_bit_buff, 2);
276 
277       if (pstr_usac_dec_config->usac_ext_ele_payload_present[elem_idx]) {
278         WORD32 preroll_counter = pstr_usac_dec_config->preroll_counter;
279         int payload_buffer_offeset = 0;
280         for (i = 0; i < preroll_counter; i++)
281           payload_buffer_offeset +=
282               pstr_usac_dec_config->usac_ext_gain_payload_len[i] *
283               sizeof(WORD8);
284         if ((pay_load_length + payload_buffer_offeset) >
285             (MAX_AUDIO_PREROLLS * 768))
286           return IA_FATAL_ERROR;
287         for (i = 0; i < ((WORD32)pay_load_length); i++) {
288           pstr_usac_dec_config
289               ->usac_ext_gain_payload_buf[i + payload_buffer_offeset] =
290               ixheaacd_read_bits_buf(it_bit_buff, 8);
291         }
292         pstr_usac_dec_config->usac_ext_gain_payload_len[preroll_counter] +=
293             pay_load_length;
294       } else {
295         if (it_bit_buff->cnt_bits < (WORD32)(pay_load_length << 3)) {
296           longjmp(*(it_bit_buff->xaac_jmp_buf),
297                   IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
298         }
299         it_bit_buff->ptr_read_next =
300             it_bit_buff->ptr_read_next + pay_load_length;
301         it_bit_buff->cnt_bits =
302             it_bit_buff->cnt_bits - (WORD32)(pay_load_length << 3);
303       }
304     }
305   }
306   return 0;
307 }
308 
ixheaacd_sbr_ele_type_set(ia_aac_dec_sbr_bitstream_struct * esbr_bit_str0,ia_aac_dec_sbr_bitstream_struct * esbr_bit_str1,WORD32 ele_id,WORD32 st_config_idx)309 static VOID ixheaacd_sbr_ele_type_set(
310     ia_aac_dec_sbr_bitstream_struct *esbr_bit_str0,
311     ia_aac_dec_sbr_bitstream_struct *esbr_bit_str1, WORD32 ele_id,
312     WORD32 st_config_idx) {
313   if (ele_id == ID_USAC_SCE) {
314     esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
315         SBR_ID_SCE;
316     esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
317         SBR_ID_SCE;
318   }
319   if (ele_id == ID_USAC_CPE) {
320     if ((st_config_idx == 0) || (st_config_idx == 3)) {
321       esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
322           SBR_ID_CPE;
323       esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
324           SBR_ID_CPE;
325     } else {
326       esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
327           SBR_ID_SCE;
328       esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
329           SBR_ID_SCE;
330     }
331   }
332   if (ele_id == ID_USAC_LFE) {
333     esbr_bit_str0->str_sbr_ele[esbr_bit_str0->no_elements].sbr_ele_id =
334         SBR_ID_SCE;
335     esbr_bit_str1->str_sbr_ele[esbr_bit_str1->no_elements].sbr_ele_id =
336         SBR_ID_SCE;
337 
338     esbr_bit_str0->no_elements++;
339     esbr_bit_str0->str_sbr_ele[0].size_payload = 0;
340   }
341 }
342 
ixheaacd_ms_processing(ia_usac_data_struct * pstr_usac_data)343 VOID ixheaacd_ms_processing(ia_usac_data_struct *pstr_usac_data) {
344   WORD32 i;
345 
346   FLOAT32 tmp, tmp1;
347   FLOAT32 ms_factor = (FLOAT32)0.7071067812;
348   for (i = 0; i < pstr_usac_data->ccfl; i++) {
349     tmp = (FLOAT32)((pstr_usac_data->time_sample_vector[0][i] +
350                      pstr_usac_data->time_sample_vector[1][i]) *
351                     ms_factor);
352     tmp1 = (FLOAT32)((pstr_usac_data->time_sample_vector[0][i] -
353                       pstr_usac_data->time_sample_vector[1][i]) *
354                      ms_factor);
355     pstr_usac_data->time_sample_vector[1][i] = tmp1;
356     pstr_usac_data->time_sample_vector[0][i] = tmp;
357   }
358 }
359 
ixheaacd_usac_process(ia_dec_data_struct * pstr_dec_data,WORD32 * num_out_channels,VOID * codec_handle)360 WORD32 ixheaacd_usac_process(ia_dec_data_struct *pstr_dec_data,
361                              WORD32 *num_out_channels, VOID *codec_handle) {
362   WORD32 ele_id = 0;
363   WORD32 err_code = 0;
364 
365   ia_aac_dec_state_struct *p_state_aac_dec =
366       (ia_aac_dec_state_struct *)codec_handle;
367 
368   ia_usac_data_struct *pstr_usac_data = &(pstr_dec_data->str_usac_data);
369   ia_bit_buf_struct *it_bit_buff = &pstr_dec_data->dec_bit_buf;
370 
371   ia_frame_data_struct *fd = &(pstr_dec_data->str_frame_data);
372 
373   ia_usac_config_struct *pstr_usac_config =
374       &(fd->str_audio_specific_config.str_usac_config);
375   ia_usac_decoder_config_struct *pstr_usac_dec_config =
376       &(fd->str_audio_specific_config.str_usac_config.str_usac_dec_config);
377 
378   WORD32 err = 0;
379   WORD16 nr_core_coder_channels = 0;
380   WORD32 ch_offset = 0;
381 
382   WORD32 elem_idx = 0;
383   WORD32 num_ch_out = 0;
384   WORD32 num_elements = pstr_usac_dec_config->num_elements;
385   UWORD32 ec_flag = p_state_aac_dec->p_config->ui_err_conceal;
386 
387   if (ec_flag) {
388     if (it_bit_buff->cnt_bits < 16) {
389       pstr_dec_data->str_usac_data.frame_ok = 0;
390     }
391     if (pstr_dec_data->str_usac_data.frame_ok == 1) {
392       pstr_usac_data->usac_independency_flg = ixheaacd_read_bits_buf(it_bit_buff, 1);
393     }
394   } else {
395     pstr_usac_data->usac_independency_flg = ixheaacd_read_bits_buf(it_bit_buff, 1);
396   }
397 
398   if (pstr_usac_data->ec_flag && pstr_dec_data->str_usac_data.frame_ok == 1) {
399     if (!(pstr_usac_data->last_frame_ok) && !(pstr_usac_data->usac_independency_flg)) {
400       pstr_dec_data->str_usac_data.frame_ok = 0;
401     } else {
402       pstr_dec_data->str_usac_data.frame_ok = 1;
403     }
404   }
405 
406   for (elem_idx = 0; elem_idx < num_elements; elem_idx++) {
407     WORD32 stereo_config_index =
408         pstr_usac_config->str_usac_dec_config.str_usac_element_config[elem_idx]
409             .stereo_config_index;
410     jmp_buf local;
411     if (ec_flag) {
412       err = setjmp(local);
413     }
414 
415     pstr_usac_data->esbr_bit_str[0].no_elements = 0;
416     pstr_usac_data->esbr_bit_str[1].no_elements = 0;
417 
418     if (!err) {
419       if (ec_flag) {
420         it_bit_buff->xaac_jmp_buf = &local;
421       }
422       switch (ele_id = pstr_usac_dec_config->usac_element_type[elem_idx]) {
423         case ID_USAC_SCE:
424           nr_core_coder_channels = 1;
425           num_ch_out += 1;
426           goto core_data_extracting;
427 
428         case ID_USAC_CPE:
429           nr_core_coder_channels = (stereo_config_index == 1) ? 1 : 2;
430           if (((stereo_config_index > 1) || (stereo_config_index == 0)) &&
431               (p_state_aac_dec->num_of_output_ch < 2))
432             return -1;
433           num_ch_out += 2;
434           goto core_data_extracting;
435         case ID_USAC_LFE:
436           nr_core_coder_channels = 1;
437           num_ch_out += 1;
438 
439         core_data_extracting:
440           if (!ec_flag) {
441             if (ch_offset >= MAX_NUM_CHANNELS_USAC_LVL2) return -1;
442             if (num_ch_out > MAX_NUM_CHANNELS_USAC_LVL2) return -1;
443           } else {
444             if ((ch_offset >= MAX_NUM_CHANNELS_USAC_LVL2) ||
445                 (num_ch_out > MAX_NUM_CHANNELS_USAC_LVL2)) {
446               pstr_usac_data->frame_ok = 0;
447             }
448           }
449 
450           err = ixheaacd_core_coder_data(ele_id, pstr_usac_data, elem_idx, ch_offset, it_bit_buff,
451                                          nr_core_coder_channels);
452           if (!ec_flag) {
453             if (err != 0) return -1;
454           } else {
455             if (err != 0) pstr_usac_data->frame_ok = 0;
456           }
457 
458           ixheaacd_sbr_ele_type_set(&pstr_usac_data->esbr_bit_str[0],
459                                     &pstr_usac_data->esbr_bit_str[1], ele_id,
460                                     stereo_config_index);
461 
462           if (pstr_usac_data->mps_pseudo_lr[elem_idx]) ixheaacd_ms_processing(pstr_usac_data);
463 
464           if (ele_id != ID_USAC_LFE) {
465             if (pstr_usac_data->sbr_ratio_idx > 0)
466               ixheaacd_sbr_ext_data_read(it_bit_buff, &pstr_usac_data->esbr_bit_str[0]);
467           }
468 
469           if ((pstr_usac_data->sbr_ratio_idx > 0) &&
470               (pstr_usac_data->esbr_bit_str[0].no_elements != 0)) {
471             if (ec_flag) {
472               pstr_usac_data->first_frame = p_state_aac_dec->first_frame;
473             }
474             err_code = ixheaacd_esbr_process(
475                 pstr_usac_data, it_bit_buff, stereo_config_index, nr_core_coder_channels,
476                 pstr_dec_data->str_frame_data.str_audio_specific_config.audio_object_type,
477                 p_state_aac_dec->heaac_mps_handle.heaac_mps_present);
478             if (!ec_flag) {
479               if (err_code < 0) return err_code;
480             } else {
481               if (err_code < 0) pstr_usac_data->frame_ok = 0;
482             }
483           }
484 
485           if (stereo_config_index > 0 && pstr_usac_data->sbr_ratio_idx > 0) {
486             FLOAT32 **ptr_inp[2 * 2];
487             WORD32 ch;
488 
489             *num_out_channels = p_state_aac_dec->mps_dec_handle.out_ch_count;
490 
491             if (!ec_flag && pstr_usac_data->frame_ok == 1) {
492               if (ec_flag) {
493                 it_bit_buff->xaac_jmp_buf = &local;
494               }
495               err =
496                   ixheaacd_mps_frame_parsing(&p_state_aac_dec->mps_dec_handle,
497                                              pstr_usac_data->usac_independency_flg, it_bit_buff);
498               if (err) return err;
499             }
500 
501             p_state_aac_dec->mps_dec_handle.band_count[0] =
502                 pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[0]->str_sbr_dec.band_count;
503             p_state_aac_dec->mps_dec_handle.band_count[1] =
504                 pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]->str_sbr_dec.band_count;
505 
506             for (ch = 0; ch < nr_core_coder_channels; ch++) {
507               ptr_inp[2 * ch] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]
508                                     ->str_sbr_dec.pp_qmf_buf_real;
509               ptr_inp[2 * ch + 1] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]
510                                         ->str_sbr_dec.pp_qmf_buf_imag;
511               p_state_aac_dec->mps_dec_handle.p_sbr_dec[ch] =
512                   (VOID *)(&pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[ch]->str_sbr_dec);
513               p_state_aac_dec->mps_dec_handle.p_sbr_header[ch] =
514                   (VOID *)(pstr_usac_data->pstr_esbr_dec->pstr_sbr_header[ch]);
515               p_state_aac_dec->mps_dec_handle.p_sbr_frame[ch] =
516                   (VOID *)(pstr_usac_data->pstr_esbr_dec->frame_buffer[ch]);
517             }
518             if (nr_core_coder_channels == 1) {
519               if (p_state_aac_dec->mps_dec_handle.res_ch_count != 0) {
520                 ptr_inp[2] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]
521                                  ->str_sbr_dec.pp_qmf_buf_real;
522                 ptr_inp[2 + 1] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]
523                                      ->str_sbr_dec.pp_qmf_buf_imag;
524               }
525               p_state_aac_dec->mps_dec_handle.p_sbr_dec[1] =
526                   (VOID *)(&pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1]->str_sbr_dec);
527               p_state_aac_dec->mps_dec_handle.p_sbr_header[1] =
528                   (VOID *)(pstr_usac_data->pstr_esbr_dec->pstr_sbr_header[1]);
529               p_state_aac_dec->mps_dec_handle.p_sbr_frame[1] =
530                   (VOID *)(pstr_usac_data->pstr_esbr_dec->frame_buffer[1]);
531             }
532             if ((!ec_flag || !p_state_aac_dec->first_frame) &&
533                 p_state_aac_dec->mps_dec_handle.mps_init_done == 1) {
534               err = ixheaacd_mps_apply(&p_state_aac_dec->mps_dec_handle, ptr_inp,
535                                        pstr_usac_data->time_sample_vector);
536               if (!ec_flag) {
537                 if (err) return err;
538               } else {
539                 if (err) pstr_usac_data->frame_ok = 0;
540               }
541             }
542             if (ec_flag) {
543               pstr_usac_data->first_frame = p_state_aac_dec->first_frame;
544               err_code = ixheaacd_esbr_parse(
545                   pstr_usac_data, it_bit_buff, stereo_config_index, nr_core_coder_channels,
546                   pstr_dec_data->str_frame_data.str_audio_specific_config.audio_object_type);
547 
548               if (err_code < 0) pstr_usac_data->frame_ok = 0;
549               if (ec_flag) {
550                 err = setjmp(local);
551               }
552               if (err == 0 && pstr_usac_data->frame_ok == 1) {
553                 if (ec_flag) {
554                   it_bit_buff->xaac_jmp_buf = &local;
555                 }
556                 err = ixheaacd_mps_frame_parsing(&p_state_aac_dec->mps_dec_handle,
557                                                  pstr_usac_data->usac_independency_flg,
558                                                  it_bit_buff);
559                 if (err) pstr_usac_data->frame_ok = 0;
560               } else {
561                 pstr_usac_data->frame_ok = 0;
562                 if (p_state_aac_dec->mps_dec_handle.num_parameter_sets_prev < 1) {
563                   p_state_aac_dec->mps_dec_handle.num_parameter_sets_prev = 1;
564                 }
565               }
566             }
567           } else if ((pstr_usac_data->sbr_ratio_idx > 0) &&
568                      (pstr_usac_data->esbr_bit_str[0].no_elements != 0) && ec_flag) {
569             pstr_usac_data->first_frame = p_state_aac_dec->first_frame;
570             err_code = ixheaacd_esbr_parse(
571                 pstr_usac_data, it_bit_buff, stereo_config_index, nr_core_coder_channels,
572                 pstr_dec_data->str_frame_data.str_audio_specific_config.audio_object_type);
573             if (err_code < 0) pstr_usac_data->frame_ok = 0;
574           }
575           if (ec_flag) {
576             p_state_aac_dec->first_frame = 0;
577           }
578 
579           ch_offset += nr_core_coder_channels;
580           break;
581 
582         case ID_USAC_EXT: {
583           ia_usac_dec_element_config_struct *pusac_element_config =
584               &pstr_usac_dec_config->str_usac_element_config[elem_idx];
585           if (pstr_usac_data->frame_ok) {
586             err = ixheaacd_read_ext_element(pusac_element_config->usac_ext_eleme_def_len,
587                                             pusac_element_config->usac_ext_elem_pld_frag,
588                                             it_bit_buff, pstr_usac_dec_config, elem_idx,
589                                             &pstr_usac_data->frame_ok);
590             if (!ec_flag) {
591               if (err != 0) return err;
592             } else {
593               if (err) pstr_usac_data->frame_ok = 0;
594             }
595           }
596           break;
597         }
598 
599         default:
600 
601           return -1;
602 
603           break;
604       }
605     }
606   }
607   pstr_usac_data->last_frame_ok = pstr_usac_data->frame_ok;
608 
609   return 0;
610 }
611