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