/src/libxaac/decoder/ixheaacd_decode_main.c
Line | Count | Source |
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 <stdlib.h> |
21 | | #include <string.h> |
22 | | #include "ixheaac_type_def.h" |
23 | | #include "ixheaac_error_standards.h" |
24 | | #include "ixheaacd_memory_standards.h" |
25 | | #include "ixheaacd_sbrdecsettings.h" |
26 | | #include "ixheaacd_sbr_scale.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 | | #include "ixheaacd_interface.h" |
36 | | #include "ixheaacd_info.h" |
37 | | #include "ixheaacd_lt_predict.h" |
38 | | #include "ixheaacd_cnst.h" |
39 | | #include "ixheaacd_ec_defines.h" |
40 | | #include "ixheaacd_ec_struct_def.h" |
41 | | #include "ixheaacd_channelinfo.h" |
42 | | #include "ixheaacd_sbr_common.h" |
43 | | #include "ixheaacd_drc_data_struct.h" |
44 | | #include "ixheaacd_drc_dec.h" |
45 | | #include "ixheaacd_channel.h" |
46 | | #include "ixheaacd_sbrdecoder.h" |
47 | | #include "ixheaacd_audioobjtypes.h" |
48 | | #include "ixheaacd_latmdemux.h" |
49 | | #include "ixheaacd_aacdec.h" |
50 | | #include "ixheaacd_sbr_common.h" |
51 | | #include "ixheaacd_hybrid.h" |
52 | | #include "ixheaacd_ps_dec.h" |
53 | | #include "ixheaacd_mps_polyphase.h" |
54 | | #include "ixheaacd_config.h" |
55 | | #include "ixheaacd_qmf_dec.h" |
56 | | #include "ixheaacd_mps_macro_def.h" |
57 | | #include "ixheaacd_mps_struct_def.h" |
58 | | #include "ixheaacd_mps_res_rom.h" |
59 | | #include "ixheaacd_mps_aac_struct.h" |
60 | | #include "ixheaac_constants.h" |
61 | | #include "ixheaacd_mps_dec.h" |
62 | | #include "ixheaacd_struct_def.h" |
63 | | #include "ixheaacd_bitbuffer.h" |
64 | | #include "ixheaacd_interface.h" |
65 | | #include "ixheaacd_tns_usac.h" |
66 | | |
67 | | #include "ixheaacd_acelp_info.h" |
68 | | #include "ixheaacd_sbrdecsettings.h" |
69 | | #include "ixheaacd_info.h" |
70 | | #include "ixheaacd_sbrdecoder.h" |
71 | | #include "ixheaacd_mps_polyphase.h" |
72 | | #include "ixheaac_sbr_const.h" |
73 | | #include "ixheaacd_main.h" |
74 | | #include "ixheaacd_arith_dec.h" |
75 | | #include "ixheaacd_config.h" |
76 | | #include "ixheaacd_struct.h" |
77 | | #include "ixheaacd_create.h" |
78 | | #include "ixheaacd_dec_main.h" |
79 | | #include "ixheaac_error_standards.h" |
80 | | #include "ixheaacd_headerdecode.h" |
81 | | #include "ixheaacd_error_codes.h" |
82 | | VOID ixheaacd_samples_sat(WORD8 *outbuffer, WORD32 num_samples_out, |
83 | | WORD32 pcmsize, FLOAT32 (*out_samples)[4096], |
84 | 245k | WORD32 *out_bytes, WORD32 num_channel_out) { |
85 | 245k | WORD32 num; |
86 | 245k | WORD32 i; |
87 | 245k | WORD32 write_local; |
88 | 245k | FLOAT32 write_local_float; |
89 | | |
90 | 245k | WORD16 *out_buf = (WORD16 *)outbuffer; |
91 | | |
92 | 245k | num = num_channel_out * num_samples_out; |
93 | | |
94 | 245k | if (pcmsize == 16) { |
95 | 956M | for (i = 0; i < num; i++) { |
96 | 956M | write_local_float = |
97 | 956M | (out_samples[i % num_channel_out][i / num_channel_out]); |
98 | | |
99 | 956M | if (write_local_float > 32767.0f) { |
100 | 33.3M | write_local_float = 32767.0f; |
101 | 923M | } else if (write_local_float < -32768.0f) { |
102 | 37.5M | write_local_float = -32768.0f; |
103 | 37.5M | } |
104 | 956M | out_buf[i] = (WORD16)write_local_float; |
105 | 956M | } |
106 | | |
107 | 245k | *out_bytes = num * sizeof(WORD16); |
108 | 245k | } else { |
109 | 0 | WORD8 *out_24bit = (WORD8 *)out_buf; |
110 | 0 | for (i = 0; i < num; i++) { |
111 | 0 | write_local_float = |
112 | 0 | (out_samples[i % num_channel_out][i / num_channel_out] * 256); |
113 | |
|
114 | 0 | if (write_local_float > 8388607.0f) { |
115 | 0 | write_local_float = 8388607.0f; |
116 | 0 | } else if (write_local_float < -8388608.0f) { |
117 | 0 | write_local_float = -8388608.0f; |
118 | 0 | } |
119 | 0 | write_local = (WORD32)write_local_float; |
120 | |
|
121 | 0 | *out_24bit++ = (WORD32)write_local & 0xff; |
122 | 0 | *out_24bit++ = ((WORD32)write_local >> 8) & 0xff; |
123 | 0 | *out_24bit++ = ((WORD32)write_local >> 16) & 0xff; |
124 | 0 | } |
125 | |
|
126 | 0 | *out_bytes = num * 3 * sizeof(WORD8); |
127 | 0 | } |
128 | 245k | } |
129 | | |
130 | | VOID ixheaacd_samples_sat_mc(WORD8* outbuffer, WORD32 num_samples_out, |
131 | | FLOAT32(*out_samples)[4096], WORD32* out_bytes, |
132 | 118 | WORD32 num_channel_out, WORD32 ch_fac) { |
133 | 118 | WORD32 num; |
134 | 118 | WORD32 i; |
135 | 118 | FLOAT32 write_local_float; |
136 | | |
137 | 118 | WORD16* out_buf = (WORD16*)outbuffer; |
138 | | |
139 | 118 | num = num_channel_out * num_samples_out; |
140 | 118 | if (num_channel_out == 1) { |
141 | 157k | for (i = 0; i < num; i++) { |
142 | 157k | write_local_float = |
143 | 157k | (out_samples[i % num_channel_out][i / num_channel_out]); |
144 | | |
145 | 157k | if (write_local_float > 32767.0f) { |
146 | 26 | write_local_float = 32767.0f; |
147 | 157k | } else if (write_local_float < -32768.0f) { |
148 | 0 | write_local_float = -32768.0f; |
149 | 0 | } |
150 | 157k | out_buf[i * ch_fac] = (WORD16)write_local_float; |
151 | 157k | } |
152 | 77 | } else if (num_channel_out == 2) { |
153 | 84.0k | for (i = 0; i < num_samples_out; i++) { |
154 | 83.9k | write_local_float = |
155 | 83.9k | (out_samples[(2*i) % num_channel_out][(2 * i) / num_channel_out]); |
156 | | |
157 | 83.9k | if (write_local_float > 32767.0f) { |
158 | 0 | write_local_float = 32767.0f; |
159 | 83.9k | } else if (write_local_float < -32768.0f) { |
160 | 0 | write_local_float = -32768.0f; |
161 | 0 | } |
162 | 83.9k | out_buf[i * ch_fac] = (WORD16)write_local_float; |
163 | | |
164 | 83.9k | write_local_float = |
165 | 83.9k | (out_samples[((2 * i) + 1) % num_channel_out][((2 * i) + 1) / num_channel_out]); |
166 | | |
167 | 83.9k | if (write_local_float > 32767.0f) { |
168 | 0 | write_local_float = 32767.0f; |
169 | 83.9k | } else if (write_local_float < -32768.0f) { |
170 | 0 | write_local_float = -32768.0f; |
171 | 0 | } |
172 | 83.9k | out_buf[i * ch_fac + 1] = (WORD16)write_local_float; |
173 | 83.9k | } |
174 | 41 | } |
175 | 118 | *out_bytes = num * sizeof(WORD16); |
176 | 118 | } |
177 | | |
178 | | /* audio pre roll frame parsing*/ |
179 | | static WORD32 ixheaacd_audio_preroll_parsing( |
180 | | ia_dec_data_struct *pstr_dec_data, UWORD8 *conf_buf, WORD32 *preroll_units, |
181 | | WORD32 *preroll_frame_offset, ia_aac_dec_state_struct *aac_dec_handle, |
182 | 22.6k | WORD32 *config_changed, WORD32 *apply_crossfade) { |
183 | 22.6k | ia_bit_buf_struct *temp_buff = |
184 | 22.6k | (ia_bit_buf_struct *)&(pstr_dec_data->dec_bit_buf); |
185 | | |
186 | 22.6k | WORD32 ext_ele_present = 0; |
187 | 22.6k | WORD32 ext_ele_use_dflt_len = 0; |
188 | 22.6k | WORD32 ext_ele_payload_len = 0; |
189 | 22.6k | WORD32 num_pre_roll_frames = 0; |
190 | | |
191 | 22.6k | WORD32 frame_idx = 0; |
192 | 22.6k | WORD32 temp = 0; |
193 | | |
194 | 22.6k | WORD32 config_len = 0; |
195 | 22.6k | WORD32 loop; |
196 | | |
197 | 22.6k | if (pstr_dec_data->str_frame_data.str_audio_specific_config.str_usac_config |
198 | 22.6k | .str_usac_dec_config.usac_element_type[0] == ID_USAC_EXT) { |
199 | 22.4k | temp = ixheaacd_show_bits_buf(temp_buff, 3); |
200 | 22.4k | ext_ele_present = (temp >> 1) & 0x1; |
201 | | |
202 | 22.4k | if (ext_ele_present) { |
203 | 1.20k | ext_ele_use_dflt_len = temp & 0x1; |
204 | 1.20k | if (ext_ele_use_dflt_len != 0) return 0; |
205 | | |
206 | 353 | ixheaacd_read_bits_buf(temp_buff, 3); |
207 | | |
208 | 353 | ext_ele_payload_len = ixheaacd_read_bits_buf(temp_buff, 8); |
209 | | |
210 | 353 | if (ext_ele_payload_len == 255) { |
211 | 1 | WORD32 val_add = 0; |
212 | 1 | val_add = ixheaacd_read_bits_buf(temp_buff, 16); |
213 | 1 | ext_ele_payload_len = |
214 | 1 | (UWORD32)((WORD32)ext_ele_payload_len + val_add - 2); |
215 | 1 | } |
216 | | |
217 | 353 | config_len = ixheaacd_read_bits_buf(temp_buff, 4); |
218 | 353 | if (config_len == 15) { |
219 | 34 | WORD32 val_add = 0; |
220 | 34 | val_add = ixheaacd_read_bits_buf(temp_buff, 4); |
221 | 34 | config_len += val_add; |
222 | 34 | if (val_add == 15) { |
223 | 3 | WORD32 val_add1 = 0; |
224 | 3 | val_add1 = ixheaacd_read_bits_buf(temp_buff, 8); |
225 | 3 | config_len += val_add1; |
226 | 3 | } |
227 | 34 | } |
228 | | |
229 | 1.62k | for (loop = 0; loop < config_len; loop++) |
230 | 1.27k | conf_buf[loop] = ixheaacd_read_bits_buf(temp_buff, 8); |
231 | | |
232 | 353 | if (aac_dec_handle->preroll_config_present == 1) { |
233 | 219 | if (!(memcmp(aac_dec_handle->preroll_config_prev, conf_buf, |
234 | 219 | sizeof(UWORD8) * config_len))) { |
235 | 183 | config_len = 0; |
236 | 183 | } |
237 | 219 | if (memcmp(aac_dec_handle->preroll_config_prev, conf_buf, |
238 | 219 | sizeof(UWORD8) * config_len) != 0) { |
239 | 36 | *config_changed = 1; |
240 | 183 | } else { |
241 | 183 | *config_changed = 0; |
242 | 183 | } |
243 | 219 | } |
244 | 353 | aac_dec_handle->preroll_config_present = 1; |
245 | 353 | memcpy(aac_dec_handle->preroll_config_prev, conf_buf, |
246 | 353 | sizeof(UWORD8) * config_len); |
247 | | |
248 | 353 | *apply_crossfade = ixheaacd_read_bits_buf(temp_buff, 1); |
249 | 353 | ixheaacd_read_bits_buf(temp_buff, 1); |
250 | | |
251 | 353 | num_pre_roll_frames = ixheaacd_read_bits_buf(temp_buff, 2); |
252 | 353 | if (num_pre_roll_frames == 3) { |
253 | 34 | WORD32 val_add = 0; |
254 | 34 | val_add = ixheaacd_read_bits_buf(temp_buff, 4); |
255 | 34 | num_pre_roll_frames += val_add; |
256 | 34 | } |
257 | | |
258 | 353 | if (num_pre_roll_frames > MAX_AUDIO_PREROLLS) { |
259 | 11 | if (pstr_dec_data->str_usac_data.ec_flag) { |
260 | 0 | num_pre_roll_frames = 0; |
261 | 0 | longjmp(*(pstr_dec_data->xaac_jmp_buf), |
262 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
263 | 11 | } else { |
264 | 11 | return IA_FATAL_ERROR; |
265 | 11 | } |
266 | 11 | } |
267 | | |
268 | 731 | for (frame_idx = 0; frame_idx < num_pre_roll_frames; frame_idx++) { |
269 | 439 | WORD32 au_len = 0; |
270 | 439 | au_len = ixheaacd_read_bits_buf(temp_buff, 16); |
271 | 439 | if (au_len == 65535) { |
272 | 10 | WORD32 val_add = ixheaacd_read_bits_buf(temp_buff, 16); |
273 | 10 | au_len += val_add; |
274 | 10 | } |
275 | 439 | if (config_len != 0) { |
276 | 81 | preroll_frame_offset[frame_idx] = |
277 | 81 | temp_buff->size - temp_buff->cnt_bits; |
278 | 81 | } |
279 | 439 | temp_buff->ptr_read_next += au_len; |
280 | 439 | temp_buff->cnt_bits -= au_len * 8; |
281 | 439 | if (temp_buff->cnt_bits < 0) { |
282 | 50 | if (pstr_dec_data->str_usac_data.ec_flag) { |
283 | 0 | temp_buff->cnt_bits = 0; |
284 | 0 | longjmp(*(pstr_dec_data->xaac_jmp_buf), |
285 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
286 | 50 | } else { |
287 | 50 | return IA_FATAL_ERROR; |
288 | 50 | } |
289 | 50 | } |
290 | 439 | } |
291 | 342 | } |
292 | 22.4k | } |
293 | 21.7k | if (config_len == 0) |
294 | 21.7k | *preroll_units = 0; |
295 | 43 | else |
296 | 43 | *preroll_units = num_pre_roll_frames; |
297 | | |
298 | 21.7k | return config_len; |
299 | 22.6k | } |
300 | | |
301 | | WORD32 ixheaacd_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *outbuffer, |
302 | | WORD32 *out_bytes, WORD32 frames_done, WORD32 pcmsize, |
303 | 232k | WORD32 *num_channel_out) { |
304 | 232k | WORD32 err = 0; |
305 | 232k | ia_exhaacplus_dec_api_struct *handle = |
306 | 232k | (ia_exhaacplus_dec_api_struct *)temp_handle; |
307 | 232k | ia_aac_dec_state_struct *aac_dec_handle = handle->p_state_aac; |
308 | | |
309 | 232k | WORD32 tmp; |
310 | 232k | ia_audio_specific_config_struct *pstr_audio_specific_config = |
311 | 232k | (ia_audio_specific_config_struct *) |
312 | 232k | aac_dec_handle->ia_audio_specific_config; |
313 | 232k | WORD32 suitable_tracks = 1; |
314 | 232k | WORD32 num_samples_out; |
315 | 232k | ia_dec_data_struct *pstr_dec_data; |
316 | 232k | UWORD8 config[MAX_PREROLL_SIZE]; |
317 | 232k | WORD32 config_len; |
318 | 232k | WORD32 delay; |
319 | 232k | WORD preroll_frame_offset[MAX_PREROLL_FRAME_OFFSET] = {0}; |
320 | 232k | WORD preroll_units = -1; |
321 | 232k | WORD32 access_units = 0; |
322 | 232k | WORD32 bits_consumed = 0; |
323 | | |
324 | 232k | if (frames_done == 0) { |
325 | 6.29k | if ((pstr_audio_specific_config->channel_configuration > 2) || |
326 | 6.28k | (pstr_audio_specific_config->channel_configuration == 0)) { |
327 | 4 | return -1; |
328 | 4 | } |
329 | | |
330 | 6.28k | pstr_dec_data = (ia_dec_data_struct *)aac_dec_handle->pstr_dec_data; |
331 | | |
332 | 6.28k | tmp = pstr_audio_specific_config->channel_configuration; |
333 | | |
334 | 6.28k | suitable_tracks = |
335 | 6.28k | ixheaacd_frm_data_init(pstr_audio_specific_config, pstr_dec_data); |
336 | | |
337 | 6.28k | pstr_audio_specific_config->channel_configuration = tmp; |
338 | | |
339 | 6.28k | if (suitable_tracks <= 0) { |
340 | 0 | return -1; |
341 | 0 | } |
342 | 6.28k | } |
343 | | |
344 | 232k | { |
345 | 232k | WORD32 tot_out_bytes = 0; |
346 | 232k | jmp_buf local; |
347 | 232k | pstr_dec_data = (ia_dec_data_struct *)aac_dec_handle->pstr_dec_data; |
348 | 232k | pstr_dec_data->str_usac_data.frame_ok = 1; |
349 | 232k | pstr_dec_data->str_usac_data.ec_flag = aac_dec_handle->p_config->ui_err_conceal; |
350 | 232k | if (pstr_dec_data->str_usac_data.ec_flag) { |
351 | 0 | err = setjmp(local); |
352 | 0 | } |
353 | | |
354 | 232k | if (aac_dec_handle->p_config->ui_err_conceal) { |
355 | 0 | if (err == 0) { |
356 | 0 | if (pstr_dec_data->dec_bit_buf.cnt_bits) { |
357 | 0 | aac_dec_handle->ui_in_bytes += (pstr_dec_data->dec_bit_buf.cnt_bits >> 3); |
358 | 0 | if (aac_dec_handle->ui_in_bytes > IA_MAX_INP_BUFFER_SIZE) { |
359 | 0 | aac_dec_handle->ui_in_bytes = 0; |
360 | 0 | } |
361 | 0 | } |
362 | 0 | } else { |
363 | 0 | pstr_dec_data->str_usac_data.frame_ok = 0; |
364 | 0 | } |
365 | 0 | } |
366 | | |
367 | 232k | if (frames_done == 0) { |
368 | 6.28k | WORD32 delay; |
369 | 6.28k | pstr_dec_data->str_usac_data.first_frame = 1; |
370 | 6.28k | if (aac_dec_handle->decode_create_done == 0) { |
371 | 6.28k | delay = ixheaacd_decode_create( |
372 | 6.28k | handle, pstr_dec_data, |
373 | 6.28k | pstr_dec_data->str_frame_data.scal_out_select + 1); |
374 | 6.28k | if (delay == -1) return -1; |
375 | 6.28k | } |
376 | 6.27k | pstr_dec_data->dec_bit_buf.max_size = |
377 | 6.27k | handle->p_mem_info_aac[IA_MEMTYPE_INPUT].ui_size; |
378 | 6.27k | *num_channel_out = pstr_dec_data->str_frame_data.scal_out_num_channels; |
379 | 6.27k | return 0; |
380 | 6.28k | } |
381 | | |
382 | 225k | pstr_dec_data->dec_bit_buf.ptr_bit_buf_base = (UWORD8 *)inbuffer; |
383 | 225k | pstr_dec_data->dec_bit_buf.size = aac_dec_handle->ui_in_bytes << 3; |
384 | 225k | pstr_dec_data->dec_bit_buf.ptr_bit_buf_end = |
385 | 225k | (UWORD8 *)inbuffer + aac_dec_handle->ui_in_bytes - 1; |
386 | 225k | pstr_dec_data->dec_bit_buf.ptr_read_next = (UWORD8 *)inbuffer; |
387 | 225k | pstr_dec_data->dec_bit_buf.bit_pos = 7; |
388 | 225k | pstr_dec_data->dec_bit_buf.cnt_bits = pstr_dec_data->dec_bit_buf.size; |
389 | 225k | pstr_dec_data->dec_bit_buf.xaac_jmp_buf = &(aac_dec_handle->xaac_jmp_buf); |
390 | 225k | if (pstr_dec_data->str_usac_data.ec_flag) { |
391 | 0 | pstr_dec_data->xaac_jmp_buf = &local; |
392 | 0 | } |
393 | 225k | pstr_dec_data->str_usac_data.usac_flag = aac_dec_handle->usac_flag; |
394 | 225k | pstr_dec_data->str_usac_data.esbr_hq = handle->aac_config.ui_hq_esbr; |
395 | 225k | pstr_dec_data->str_usac_data.enh_sbr = 1; |
396 | 225k | pstr_dec_data->str_usac_data.enh_sbr_ps = handle->aac_config.ui_enh_sbr_ps; |
397 | 225k | if (pstr_dec_data->dec_bit_buf.size > pstr_dec_data->dec_bit_buf.max_size) |
398 | 1.95k | pstr_dec_data->dec_bit_buf.max_size = pstr_dec_data->dec_bit_buf.size; |
399 | | /* audio pre roll frame parsing*/ |
400 | | |
401 | 225k | if (aac_dec_handle->bs_format == LOAS_BSFORMAT && pstr_dec_data->str_usac_data.frame_ok) { |
402 | 223k | WORD32 sync = ixheaacd_read_bits_buf(&pstr_dec_data->dec_bit_buf, 11); |
403 | 223k | if (sync == 0x2b7) { |
404 | 29.9k | WORD32 result = ixheaacd_latm_audio_mux_element( |
405 | 29.9k | &pstr_dec_data->dec_bit_buf, &aac_dec_handle->latm_struct_element, |
406 | 29.9k | aac_dec_handle, |
407 | 29.9k | (ia_sampling_rate_info_struct *)&handle->aac_tables |
408 | 29.9k | .pstr_huffmann_tables->str_sample_rate_info[0]); |
409 | 29.9k | if (result < 0) { |
410 | 84 | if (aac_dec_handle->p_config->ui_err_conceal) |
411 | 0 | pstr_dec_data->str_usac_data.frame_ok = 0; |
412 | 84 | else |
413 | 84 | return result; |
414 | 84 | } |
415 | 29.9k | } |
416 | 223k | bits_consumed = pstr_dec_data->dec_bit_buf.size - pstr_dec_data->dec_bit_buf.cnt_bits; |
417 | 223k | } |
418 | | |
419 | 225k | do { |
420 | 225k | config_len = 0; |
421 | 225k | if (err == 0 || aac_dec_handle->p_config->ui_err_conceal == 0) { |
422 | 225k | if (access_units == 0 && |
423 | 225k | pstr_audio_specific_config->str_usac_config.str_usac_dec_config.preroll_flag) { |
424 | 22.6k | config_len = ixheaacd_audio_preroll_parsing( |
425 | 22.6k | pstr_dec_data, &config[0], &preroll_units, &preroll_frame_offset[0], aac_dec_handle, |
426 | 22.6k | &aac_dec_handle->drc_config_changed, &aac_dec_handle->apply_crossfade); |
427 | | |
428 | 22.6k | if (config_len == IA_FATAL_ERROR) return IA_FATAL_ERROR; |
429 | 22.6k | } |
430 | | |
431 | 225k | if (config_len != 0) { |
432 | 40 | ia_bit_buf_struct config_bit_buf = {0}; |
433 | | |
434 | 40 | config_bit_buf.ptr_bit_buf_base = config; |
435 | 40 | config_bit_buf.size = config_len << 3; |
436 | 40 | config_bit_buf.ptr_read_next = config_bit_buf.ptr_bit_buf_base; |
437 | 40 | config_bit_buf.ptr_bit_buf_end = (UWORD8 *)config + config_len; |
438 | 40 | config_bit_buf.bit_pos = 7; |
439 | 40 | config_bit_buf.cnt_bits = config_bit_buf.size; |
440 | 40 | if (pstr_dec_data->str_usac_data.ec_flag) { |
441 | 0 | config_bit_buf.xaac_jmp_buf = &local; |
442 | 40 | } else { |
443 | 40 | config_bit_buf.xaac_jmp_buf = &(aac_dec_handle->xaac_jmp_buf); |
444 | 40 | } |
445 | | |
446 | 40 | suitable_tracks = ixheaacd_frm_data_init(pstr_audio_specific_config, pstr_dec_data); |
447 | | |
448 | 40 | if (suitable_tracks <= 0) return -1; |
449 | | |
450 | 40 | aac_dec_handle->decode_create_done = 0; |
451 | 40 | if (aac_dec_handle->p_config->ui_err_conceal) { |
452 | 0 | if (pstr_dec_data->str_usac_data.frame_ok == 1 && err == 0) { |
453 | 0 | err = ixheaacd_config( |
454 | 0 | &config_bit_buf, |
455 | 0 | &(pstr_dec_data->str_frame_data.str_audio_specific_config.str_usac_config), |
456 | 0 | &(pstr_audio_specific_config->channel_configuration), |
457 | 0 | aac_dec_handle->p_config->ui_err_conceal); |
458 | 0 | if (err != 0) { |
459 | 0 | if (frames_done == 0) |
460 | 0 | return -1; |
461 | 0 | else |
462 | 0 | pstr_dec_data->str_usac_data.frame_ok = 0; |
463 | 0 | } |
464 | 0 | } |
465 | 40 | } else { |
466 | 40 | err = ixheaacd_config( |
467 | 40 | &config_bit_buf, |
468 | 40 | &(pstr_dec_data->str_frame_data.str_audio_specific_config.str_usac_config), |
469 | 40 | &(pstr_audio_specific_config->channel_configuration), |
470 | 40 | aac_dec_handle->p_config->ui_err_conceal); |
471 | 40 | if (err != 0) { |
472 | 9 | return err; |
473 | 9 | } |
474 | 40 | } |
475 | | |
476 | 31 | pstr_dec_data->str_frame_data.str_audio_specific_config.sampling_frequency = |
477 | 31 | pstr_dec_data->str_frame_data.str_audio_specific_config.str_usac_config |
478 | 31 | .usac_sampling_frequency; |
479 | 31 | delay = ixheaacd_decode_create(handle, pstr_dec_data, |
480 | 31 | pstr_dec_data->str_frame_data.scal_out_select + 1); |
481 | 31 | if (delay == -1) return -1; |
482 | 15 | *num_channel_out = pstr_dec_data->str_frame_data.scal_out_num_channels; |
483 | 15 | } |
484 | 225k | } else { |
485 | 28 | pstr_dec_data->str_usac_data.frame_ok = 0; |
486 | 28 | } |
487 | | |
488 | 225k | pstr_dec_data->dec_bit_buf.ptr_bit_buf_base = (UWORD8 *)inbuffer; |
489 | 225k | pstr_dec_data->dec_bit_buf.size = aac_dec_handle->ui_in_bytes << 3; |
490 | 225k | pstr_dec_data->dec_bit_buf.ptr_bit_buf_end = |
491 | 225k | (UWORD8 *)inbuffer + aac_dec_handle->ui_in_bytes - 1; |
492 | 225k | pstr_dec_data->dec_bit_buf.ptr_read_next = (UWORD8 *)inbuffer; |
493 | 225k | pstr_dec_data->dec_bit_buf.bit_pos = 7; |
494 | 225k | pstr_dec_data->dec_bit_buf.cnt_bits = pstr_dec_data->dec_bit_buf.size; |
495 | 225k | pstr_dec_data->dec_bit_buf.xaac_jmp_buf = &(aac_dec_handle->xaac_jmp_buf); |
496 | | |
497 | 225k | pstr_dec_data->str_usac_data.usac_flag = aac_dec_handle->usac_flag; |
498 | 225k | pstr_dec_data->str_usac_data.esbr_hq = handle->aac_config.ui_hq_esbr; |
499 | 225k | pstr_dec_data->str_usac_data.enh_sbr = 1; |
500 | 225k | pstr_dec_data->str_usac_data.enh_sbr_ps = handle->aac_config.ui_enh_sbr_ps; |
501 | | |
502 | 225k | if (preroll_frame_offset[access_units] && |
503 | 15 | ((pstr_dec_data->str_usac_data.ec_flag && pstr_dec_data->str_usac_data.frame_ok == 1) || |
504 | 15 | pstr_dec_data->str_usac_data.ec_flag == 0)) { |
505 | 15 | pstr_dec_data->dec_bit_buf.cnt_bits = |
506 | 15 | pstr_dec_data->dec_bit_buf.size - |
507 | 15 | preroll_frame_offset[access_units]; |
508 | 15 | pstr_dec_data->dec_bit_buf.bit_pos = |
509 | 15 | 7 - preroll_frame_offset[access_units] % 8; |
510 | 15 | pstr_dec_data->dec_bit_buf.ptr_read_next = |
511 | 15 | pstr_dec_data->dec_bit_buf.ptr_read_next + |
512 | 15 | (preroll_frame_offset[access_units] / 8); |
513 | 225k | } else { |
514 | 225k | pstr_dec_data->dec_bit_buf.cnt_bits = |
515 | 225k | pstr_dec_data->dec_bit_buf.size - |
516 | 225k | (bits_consumed); |
517 | 225k | pstr_dec_data->dec_bit_buf.bit_pos = |
518 | 225k | 7 - (bits_consumed) % 8; |
519 | 225k | pstr_dec_data->dec_bit_buf.ptr_read_next = |
520 | 225k | pstr_dec_data->dec_bit_buf.ptr_read_next + |
521 | 225k | (bits_consumed / 8); |
522 | 225k | } |
523 | | |
524 | 225k | if (pstr_dec_data->str_usac_data.ec_flag) { |
525 | 0 | if (!aac_dec_handle->decode_create_done && pstr_dec_data->str_usac_data.frame_ok == 1 && |
526 | 0 | config_len != 0) |
527 | 0 | return IA_FATAL_ERROR; |
528 | 225k | } else { |
529 | 225k | if (!aac_dec_handle->decode_create_done) return IA_FATAL_ERROR; |
530 | 225k | } |
531 | | |
532 | 225k | err = |
533 | 225k | ixheaacd_usac_process(pstr_dec_data, num_channel_out, aac_dec_handle); |
534 | | |
535 | 225k | switch (pstr_dec_data->str_usac_data.sbr_ratio_idx) { |
536 | 42.4k | case 0: |
537 | 42.4k | handle->aac_config.ui_sbr_mode = 0; |
538 | 42.4k | break; |
539 | 143k | case 1: |
540 | 143k | handle->aac_config.ui_sbr_mode = 1; |
541 | 143k | break; |
542 | 18.3k | case 2: |
543 | 18.3k | handle->aac_config.ui_sbr_mode = 1; |
544 | 18.3k | break; |
545 | 18.9k | case 3: |
546 | 18.9k | handle->aac_config.ui_sbr_mode = 3; |
547 | 18.9k | break; |
548 | | |
549 | 0 | default: |
550 | 0 | handle->aac_config.ui_sbr_mode = 0; |
551 | 225k | } |
552 | | |
553 | 223k | if (err == -1) return err; |
554 | | |
555 | 222k | num_samples_out = pstr_dec_data->str_usac_data.output_samples; |
556 | 222k | if (!handle->aac_config.peak_limiter_off && pstr_dec_data->str_usac_data.ec_flag) { |
557 | 0 | aac_dec_handle->peak_limiter.num_channels = *num_channel_out; |
558 | |
|
559 | 0 | ixheaacd_peak_limiter_process_float(&aac_dec_handle->peak_limiter, |
560 | 0 | pstr_dec_data->str_usac_data.time_sample_vector, |
561 | 0 | num_samples_out); |
562 | 0 | } |
563 | | |
564 | 222k | ixheaacd_samples_sat((WORD8 *)outbuffer + tot_out_bytes, num_samples_out, |
565 | 222k | pcmsize, |
566 | 222k | pstr_dec_data->str_usac_data.time_sample_vector, |
567 | 222k | out_bytes, *num_channel_out); |
568 | 222k | { |
569 | 222k | WORD32 preroll_counter = |
570 | 222k | pstr_dec_data->str_frame_data.str_audio_specific_config |
571 | 222k | .str_usac_config.str_usac_dec_config.preroll_counter; |
572 | | |
573 | 222k | UWORD8 i; // for looping index used for payload calculation |
574 | 222k | WORD32 payload_buffer_offset = 0; |
575 | 222k | WORD32 copy_bytes = |
576 | 222k | pstr_dec_data->str_frame_data.str_audio_specific_config |
577 | 222k | .str_usac_config.str_usac_dec_config |
578 | 222k | .usac_ext_gain_payload_len[preroll_counter] * |
579 | 222k | sizeof(WORD8); |
580 | | |
581 | 222k | pstr_audio_specific_config->str_usac_config.str_usac_dec_config |
582 | 222k | .usac_ext_gain_payload_len[preroll_counter] = |
583 | 222k | pstr_dec_data->str_frame_data.str_audio_specific_config |
584 | 222k | .str_usac_config.str_usac_dec_config |
585 | 222k | .usac_ext_gain_payload_len[preroll_counter]; |
586 | | |
587 | 222k | for (i = 0; i < preroll_counter; i++) |
588 | 13 | payload_buffer_offset += |
589 | 13 | pstr_dec_data->str_frame_data.str_audio_specific_config |
590 | 13 | .str_usac_config.str_usac_dec_config |
591 | 13 | .usac_ext_gain_payload_len[i] * |
592 | 13 | sizeof(WORD8); |
593 | | |
594 | 222k | memcpy(pstr_audio_specific_config->str_usac_config.str_usac_dec_config |
595 | 222k | .usac_ext_gain_payload_buf + |
596 | 222k | payload_buffer_offset, |
597 | 222k | pstr_dec_data->str_frame_data.str_audio_specific_config |
598 | 222k | .str_usac_config.str_usac_dec_config |
599 | 222k | .usac_ext_gain_payload_buf + |
600 | 222k | payload_buffer_offset, |
601 | 222k | copy_bytes); |
602 | | |
603 | 222k | pstr_audio_specific_config->str_usac_config.str_usac_dec_config |
604 | 222k | .preroll_bytes[preroll_counter] = *out_bytes; |
605 | | |
606 | 222k | preroll_counter++; |
607 | | |
608 | 222k | if (preroll_counter > (MAX_AUDIO_PREROLLS + 1)) return IA_FATAL_ERROR; |
609 | | |
610 | 222k | pstr_dec_data->str_frame_data.str_audio_specific_config.str_usac_config |
611 | 222k | .str_usac_dec_config.preroll_counter = preroll_counter; |
612 | | |
613 | 222k | ia_usac_decoder_config_struct *pstr_usac_dec_config_state = |
614 | 222k | &pstr_audio_specific_config->str_usac_config.str_usac_dec_config; |
615 | 222k | ia_usac_decoder_config_struct *pstr_usac_dec_config_dec_data = |
616 | 222k | &pstr_dec_data->str_frame_data.str_audio_specific_config.str_usac_config |
617 | 222k | .str_usac_dec_config; |
618 | 222k | pstr_usac_dec_config_state->num_config_extensions = |
619 | 222k | pstr_usac_dec_config_dec_data->num_config_extensions; |
620 | 222k | pstr_usac_dec_config_state->num_elements = |
621 | 222k | pstr_usac_dec_config_dec_data->num_elements; |
622 | 222k | memcpy(pstr_usac_dec_config_state->usac_cfg_ext_info_buf, |
623 | 222k | pstr_usac_dec_config_dec_data->usac_cfg_ext_info_buf, |
624 | 222k | sizeof(pstr_usac_dec_config_state->usac_cfg_ext_info_buf)); |
625 | 222k | memcpy(pstr_usac_dec_config_state->usac_ext_ele_payload_present, |
626 | 222k | pstr_usac_dec_config_dec_data->usac_ext_ele_payload_present, |
627 | 222k | sizeof(pstr_usac_dec_config_dec_data->usac_ext_ele_payload_present)); |
628 | 222k | memcpy(pstr_usac_dec_config_state->usac_ext_ele_payload_buf, |
629 | 222k | pstr_usac_dec_config_dec_data->usac_ext_ele_payload_buf, |
630 | 222k | sizeof(pstr_usac_dec_config_state->usac_ext_ele_payload_buf)); |
631 | 222k | } |
632 | | |
633 | 0 | access_units++; |
634 | 222k | preroll_units--; |
635 | 222k | tot_out_bytes += (*out_bytes); |
636 | 222k | } while (preroll_units >= 0); |
637 | 222k | *out_bytes = tot_out_bytes; |
638 | 222k | } |
639 | | |
640 | 222k | if (aac_dec_handle->bs_format == LOAS_BSFORMAT) { |
641 | 220k | pstr_dec_data->dec_bit_buf.ptr_bit_buf_base = (UWORD8 *)inbuffer; |
642 | 220k | pstr_dec_data->dec_bit_buf.size = aac_dec_handle->ui_in_bytes << 3; |
643 | 220k | pstr_dec_data->dec_bit_buf.ptr_bit_buf_end = |
644 | 220k | (UWORD8 *)inbuffer + aac_dec_handle->ui_in_bytes - 1; |
645 | 220k | pstr_dec_data->dec_bit_buf.ptr_read_next = (UWORD8 *)inbuffer; |
646 | 220k | pstr_dec_data->dec_bit_buf.bit_pos = 7; |
647 | 220k | pstr_dec_data->dec_bit_buf.cnt_bits = pstr_dec_data->dec_bit_buf.size; |
648 | 220k | pstr_dec_data->dec_bit_buf.xaac_jmp_buf = &(aac_dec_handle->xaac_jmp_buf); |
649 | | |
650 | 220k | ixheaacd_read_bits_buf(&pstr_dec_data->dec_bit_buf, 11); |
651 | 220k | aac_dec_handle->i_bytes_consumed = |
652 | 220k | ixheaacd_read_bits_buf(&pstr_dec_data->dec_bit_buf, 13) + 3; |
653 | 220k | } |
654 | | |
655 | 222k | return err; |
656 | 225k | } |