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