/src/libxaac/decoder/ixheaacd_init_config.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 <string.h> |
21 | | #include <stdio.h> |
22 | | #include <stdarg.h> |
23 | | #include <assert.h> |
24 | | |
25 | | #include "ixheaac_type_def.h" |
26 | | #include "ixheaac_constants.h" |
27 | | #include "ixheaacd_bitbuffer.h" |
28 | | |
29 | | #include "ixheaacd_defines.h" |
30 | | #include "ixheaacd_memory_standards.h" |
31 | | #include "ixheaacd_sbrdecsettings.h" |
32 | | #include "ixheaacd_sbr_scale.h" |
33 | | #include "ixheaacd_env_extr_part.h" |
34 | | #include "ixheaacd_aac_rom.h" |
35 | | #include "ixheaacd_common_rom.h" |
36 | | #include "ixheaacd_sbr_rom.h" |
37 | | #include "ixheaacd_pulsedata.h" |
38 | | #include "ixheaacd_pns.h" |
39 | | |
40 | | #include "ixheaacd_sbr_common.h" |
41 | | #include "ixheaacd_drc_data_struct.h" |
42 | | #include "ixheaacd_drc_dec.h" |
43 | | |
44 | | #include "ixheaacd_lt_predict.h" |
45 | | #include "ixheaacd_cnst.h" |
46 | | #include "ixheaacd_ec_defines.h" |
47 | | #include "ixheaacd_ec_struct_def.h" |
48 | | #include "ixheaacd_channelinfo.h" |
49 | | #include "ixheaacd_channel.h" |
50 | | #include "ixheaacd_sbrdecoder.h" |
51 | | #include "ixheaacd_audioobjtypes.h" |
52 | | #include "ixheaacd_latmdemux.h" |
53 | | #include "ixheaacd_aacdec.h" |
54 | | #include "ixheaacd_sbr_common.h" |
55 | | |
56 | | #include "ixheaacd_hybrid.h" |
57 | | #include "ixheaacd_ps_dec.h" |
58 | | #include "ixheaacd_qmf_dec.h" |
59 | | #include "ixheaacd_mps_macro_def.h" |
60 | | #include "ixheaacd_mps_struct_def.h" |
61 | | #include "ixheaacd_mps_res_rom.h" |
62 | | #include "ixheaacd_mps_aac_struct.h" |
63 | | #include "ixheaacd_mps_polyphase.h" |
64 | | #include "ixheaacd_config.h" |
65 | | #include "ixheaacd_mps_dec.h" |
66 | | #include "ixheaacd_struct_def.h" |
67 | | |
68 | | #include "ixheaacd_config.h" |
69 | | #include "ixheaacd_interface.h" |
70 | | #include "ixheaacd_info.h" |
71 | | #include "ixheaacd_struct.h" |
72 | | #include "ixheaac_error_standards.h" |
73 | | |
74 | | #include "ixheaacd_error_codes.h" |
75 | | |
76 | | static const WORD32 sampling_rate_tbl[] = { |
77 | | 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, |
78 | | 8000, 7350, 0, 0, 57600, 51200, 40000, 38400, 34150, 28800, 25600, |
79 | | 20000, 19200, 17075, 14400, 12800, 9600, 0, 0, 0}; |
80 | | |
81 | 28.4k | UWORD32 ixheaacd_sbr_ratio(UWORD32 core_sbr_framelength_idx) { |
82 | 28.4k | UWORD32 sbr_ratio_index = 0x0FF; |
83 | | |
84 | 28.4k | switch (core_sbr_framelength_idx) { |
85 | 2.14k | case 0: |
86 | 19.1k | case 1: |
87 | 19.1k | sbr_ratio_index = USAC_SBR_RATIO_NO_SBR; |
88 | 19.1k | break; |
89 | 1.73k | case 2: |
90 | 1.73k | sbr_ratio_index = USAC_SBR_RATIO_INDEX_8_3; |
91 | 1.73k | break; |
92 | 6.82k | case 3: |
93 | 6.82k | sbr_ratio_index = USAC_SBR_RATIO_INDEX_2_1; |
94 | 6.82k | break; |
95 | 777 | case 4: |
96 | 777 | sbr_ratio_index = USAC_SBR_RATIO_INDEX_4_1; |
97 | 777 | break; |
98 | 28.4k | } |
99 | | |
100 | 28.4k | return sbr_ratio_index; |
101 | 28.4k | } |
102 | | |
103 | 7.77k | static WORD32 ixheaacd_get_sample_freq_indx(WORD32 sampling_freq) { |
104 | 7.77k | WORD32 index; |
105 | 7.77k | const WORD32 tbl_size = sizeof(sampling_rate_tbl) / sizeof(WORD32) - 1; |
106 | | |
107 | 142k | for (index = 0; index < tbl_size; index++) { |
108 | 139k | if (sampling_rate_tbl[index] == sampling_freq) break; |
109 | 139k | } |
110 | 7.77k | return index; |
111 | 7.77k | } |
112 | | UWORD32 ixheaacd_sbr_params(UWORD32 core_sbr_framelength_idx, |
113 | | WORD32 *output_framelength, WORD32 *block_size, |
114 | | WORD32 *output_samples, WORD32 *sample_rate_layer, |
115 | 7.77k | UWORD32 *sample_freq_indx) { |
116 | 7.77k | UWORD32 sbr_ratio_index = 0x0FF; |
117 | | |
118 | 7.77k | *output_framelength = -1; |
119 | | |
120 | 7.77k | switch (core_sbr_framelength_idx) { |
121 | 1.39k | case 0: |
122 | 1.39k | sbr_ratio_index = USAC_SBR_RATIO_NO_SBR; |
123 | 1.39k | *output_framelength = USAC_OUT_FRAMELENGTH_768; |
124 | 1.39k | *block_size = 768; |
125 | 1.39k | *output_samples = *block_size; |
126 | 1.39k | break; |
127 | 1.70k | case 1: |
128 | 1.70k | sbr_ratio_index = USAC_SBR_RATIO_NO_SBR; |
129 | 1.70k | *output_framelength = USAC_OUT_FRAMELENGTH_1024; |
130 | 1.70k | *block_size = 1024; |
131 | 1.70k | *output_samples = *block_size; |
132 | 1.70k | break; |
133 | 870 | case 2: |
134 | 870 | sbr_ratio_index = USAC_SBR_RATIO_INDEX_8_3; |
135 | 870 | *output_framelength = USAC_OUT_FRAMELENGTH_2048; |
136 | 870 | *block_size = 768; |
137 | 870 | *output_samples = (*block_size * 8) / 3; |
138 | 870 | *sample_rate_layer = (*sample_rate_layer * 3) >> 3; |
139 | 870 | break; |
140 | 3.37k | case 3: |
141 | 3.37k | sbr_ratio_index = USAC_SBR_RATIO_INDEX_2_1; |
142 | 3.37k | *output_framelength = USAC_OUT_FRAMELENGTH_2048; |
143 | 3.37k | *block_size = 1024; |
144 | 3.37k | *output_samples = *block_size * 2; |
145 | 3.37k | *sample_rate_layer = *sample_rate_layer >> 1; |
146 | 3.37k | break; |
147 | 444 | case 4: |
148 | 444 | sbr_ratio_index = USAC_SBR_RATIO_INDEX_4_1; |
149 | 444 | *output_framelength = USAC_OUT_FRAMELENGTH_4096; |
150 | 444 | *block_size = 1024; |
151 | 444 | *output_samples = *block_size * 4; |
152 | 444 | *sample_rate_layer = *sample_rate_layer >> 2; |
153 | 444 | break; |
154 | 7.77k | } |
155 | | |
156 | 7.77k | *sample_freq_indx = ixheaacd_get_sample_freq_indx(*sample_rate_layer); |
157 | | |
158 | 7.77k | return sbr_ratio_index; |
159 | 7.77k | } |
160 | | |
161 | | VOID ixheaacd_read_escape_value(ia_bit_buf_struct *it_bit_buff, |
162 | | UWORD32 *ext_ele_value, UWORD32 no_bits1, |
163 | 116k | UWORD32 no_bits2, UWORD32 no_bits3) { |
164 | 116k | UWORD32 value = 0; |
165 | 116k | UWORD32 val_add = 0; |
166 | 116k | UWORD32 max_val1 = (1 << no_bits1) - 1; |
167 | 116k | UWORD32 max_val2 = (1 << no_bits2) - 1; |
168 | | |
169 | 116k | value = ixheaacd_read_bits_buf(it_bit_buff, no_bits1); |
170 | | |
171 | 116k | if (value == max_val1) { |
172 | 6.09k | val_add = ixheaacd_read_bits_buf(it_bit_buff, no_bits2); |
173 | | |
174 | 6.09k | value += val_add; |
175 | | |
176 | 6.09k | if (val_add == max_val2) { |
177 | 916 | val_add = ixheaacd_read_bits_buf(it_bit_buff, no_bits3); |
178 | | |
179 | 916 | value += val_add; |
180 | 916 | } |
181 | 6.09k | } |
182 | | |
183 | 116k | *ext_ele_value = value; |
184 | 116k | } |
185 | | |
186 | | static IA_ERRORCODE ixheaacd_get_usac_chan_conf(ia_usac_config_struct *pstr_usac_config, |
187 | | UWORD32 ch_config_index, ia_bit_buf_struct *it_bit_buff, WORD32 ec_flag) |
188 | 21.6k | { |
189 | 21.6k | switch (ch_config_index) { |
190 | 1.07k | case 1: |
191 | 1.07k | pstr_usac_config->num_out_channels = 1; |
192 | 1.07k | pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_C; |
193 | 1.07k | break; |
194 | 18.2k | case 2: |
195 | 18.2k | pstr_usac_config->num_out_channels = 2; |
196 | 18.2k | pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_L; |
197 | 18.2k | pstr_usac_config->output_channel_pos[1] = BS_OUTPUT_CHANNEL_POS_R; |
198 | 18.2k | break; |
199 | 2.27k | case 8: |
200 | 2.27k | pstr_usac_config->num_out_channels = 2; |
201 | 2.27k | pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_NA; |
202 | 2.27k | pstr_usac_config->output_channel_pos[1] = BS_OUTPUT_CHANNEL_POS_NA; |
203 | 2.27k | break; |
204 | | |
205 | 0 | default: |
206 | 0 | if (ec_flag) |
207 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
208 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
209 | 0 | else |
210 | 0 | return IA_FATAL_ERROR; |
211 | 0 | break; |
212 | 21.6k | } |
213 | 21.6k | return IA_NO_ERROR; |
214 | 21.6k | } |
215 | | |
216 | | VOID ixheaacd_sbr_config(ia_bit_buf_struct *it_bit_buff, |
217 | 9.91k | ia_usac_dec_sbr_config_struct *pstr_usac_sbr_config) { |
218 | 9.91k | pstr_usac_sbr_config->harmonic_sbr = ixheaacd_read_bits_buf(it_bit_buff, 1); |
219 | 9.91k | pstr_usac_sbr_config->bs_inter_tes = ixheaacd_read_bits_buf(it_bit_buff, 1); |
220 | 9.91k | pstr_usac_sbr_config->bs_pvc = ixheaacd_read_bits_buf(it_bit_buff, 1); |
221 | 9.91k | pstr_usac_sbr_config->dflt_start_freq = |
222 | 9.91k | ixheaacd_read_bits_buf(it_bit_buff, 4); |
223 | | |
224 | 9.91k | pstr_usac_sbr_config->dflt_stop_freq = ixheaacd_read_bits_buf(it_bit_buff, 4); |
225 | 9.91k | pstr_usac_sbr_config->dflt_header_extra1 = |
226 | 9.91k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
227 | 9.91k | pstr_usac_sbr_config->dflt_header_extra2 = |
228 | 9.91k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
229 | | |
230 | 9.91k | if (pstr_usac_sbr_config->dflt_header_extra1) { |
231 | 4.31k | pstr_usac_sbr_config->dflt_freq_scale = |
232 | 4.31k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
233 | 4.31k | pstr_usac_sbr_config->dflt_alter_scale = |
234 | 4.31k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
235 | 4.31k | pstr_usac_sbr_config->dflt_noise_bands = |
236 | 4.31k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
237 | 4.31k | } |
238 | | |
239 | 9.91k | if (pstr_usac_sbr_config->dflt_header_extra2) { |
240 | 1.57k | pstr_usac_sbr_config->dflt_limiter_bands = |
241 | 1.57k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
242 | 1.57k | pstr_usac_sbr_config->dflt_limiter_gains = |
243 | 1.57k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
244 | 1.57k | pstr_usac_sbr_config->dflt_interpol_freq = |
245 | 1.57k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
246 | 1.57k | pstr_usac_sbr_config->dflt_smoothing_mode = |
247 | 1.57k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
248 | 1.57k | } |
249 | 9.91k | } |
250 | | |
251 | | WORD32 ixheaacd_ext_element_config( |
252 | | ia_bit_buf_struct *it_bit_buff, |
253 | | ia_usac_dec_element_config_struct *pstr_usac_element_config, |
254 | | UWORD8 *ptr_usac_ext_ele_payload, WORD32 *ptr_usac_ext_ele_payload_len, |
255 | 18.4k | WORD32 *preroll_flag) { |
256 | 18.4k | UWORD32 usac_ext_element_type, usac_ext_element_config_length, flag; |
257 | | |
258 | 18.4k | UWORD32 i; |
259 | | |
260 | 18.4k | ixheaacd_read_escape_value(it_bit_buff, &(usac_ext_element_type), 4, 8, 16); |
261 | | |
262 | 18.4k | ixheaacd_read_escape_value(it_bit_buff, &(usac_ext_element_config_length), 4, |
263 | 18.4k | 8, 16); |
264 | 18.4k | if (usac_ext_element_config_length >= 768) return -1; |
265 | | |
266 | 18.4k | flag = ixheaacd_read_bits_buf(it_bit_buff, 1); |
267 | | |
268 | 18.4k | *ptr_usac_ext_ele_payload_len = 0; |
269 | | |
270 | 18.4k | if (flag) { |
271 | 3.63k | ixheaacd_read_escape_value( |
272 | 3.63k | it_bit_buff, |
273 | 3.63k | (UWORD32 *)(&(pstr_usac_element_config->usac_ext_eleme_def_len)), 8, 16, |
274 | 3.63k | 0); |
275 | 3.63k | pstr_usac_element_config->usac_ext_eleme_def_len += 1; |
276 | | |
277 | 14.8k | } else { |
278 | 14.8k | pstr_usac_element_config->usac_ext_eleme_def_len = 0; |
279 | 14.8k | } |
280 | | |
281 | 18.4k | pstr_usac_element_config->usac_ext_elem_pld_frag = |
282 | 18.4k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
283 | | |
284 | 18.4k | switch (usac_ext_element_type) { |
285 | 81 | case ID_EXT_ELE_FILL: |
286 | 81 | break; |
287 | 8.06k | case ID_EXT_ELE_AUDIOPREROLL: |
288 | 8.06k | *preroll_flag = 1; |
289 | 8.06k | break; |
290 | 2.25k | case ID_EXT_ELE_UNI_DRC: |
291 | 54.7k | for (i = 0; i < usac_ext_element_config_length; i++) { |
292 | 52.5k | ptr_usac_ext_ele_payload[i] = ixheaacd_read_bits_buf(it_bit_buff, 8); |
293 | 52.5k | } |
294 | 2.25k | *ptr_usac_ext_ele_payload_len = usac_ext_element_config_length; |
295 | 2.25k | break; |
296 | | |
297 | 8.02k | default: |
298 | 8.02k | if ((it_bit_buff->cnt_bits >> 3) < (WORD32)usac_ext_element_config_length) |
299 | 23 | return -1; |
300 | 8.00k | it_bit_buff->ptr_read_next += usac_ext_element_config_length; |
301 | 8.00k | it_bit_buff->cnt_bits -= (usac_ext_element_config_length << 3); |
302 | | |
303 | 8.00k | break; |
304 | 18.4k | } |
305 | | |
306 | 18.3k | return 0; |
307 | 18.4k | } |
308 | | |
309 | | IA_ERRORCODE ixheaacd_mps212_config( |
310 | | ia_bit_buf_struct *it_bit_buff, |
311 | | ia_usac_dec_mps_config_struct *pstr_usac_mps212_config, |
312 | 4.16k | WORD32 stereo_config_index) { |
313 | 4.16k | pstr_usac_mps212_config->bs_freq_res = ixheaacd_read_bits_buf(it_bit_buff, 3); |
314 | | |
315 | 4.16k | pstr_usac_mps212_config->bs_fixed_gain_dmx = |
316 | 4.16k | ixheaacd_read_bits_buf(it_bit_buff, 3); |
317 | | |
318 | 4.16k | pstr_usac_mps212_config->bs_temp_shape_config = |
319 | 4.16k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
320 | | |
321 | 4.16k | pstr_usac_mps212_config->bs_decorr_config = |
322 | 4.16k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
323 | 4.16k | if (pstr_usac_mps212_config->bs_decorr_config > MAX_DECOR_CONFIG_IDX) |
324 | 3 | return IA_FATAL_ERROR; |
325 | | |
326 | 4.16k | pstr_usac_mps212_config->bs_high_rate_mode = |
327 | 4.16k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
328 | | |
329 | 4.16k | pstr_usac_mps212_config->bs_phase_coding = |
330 | 4.16k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
331 | | |
332 | 4.16k | pstr_usac_mps212_config->bs_ott_bands_phase_present = |
333 | 4.16k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
334 | | |
335 | 4.16k | if (pstr_usac_mps212_config->bs_ott_bands_phase_present) { |
336 | 1.61k | pstr_usac_mps212_config->bs_ott_bands_phase = |
337 | 1.61k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
338 | 1.61k | if (pstr_usac_mps212_config->bs_ott_bands_phase > MAX_PARAMETER_BANDS) |
339 | 1 | return IA_FATAL_ERROR; |
340 | 1.61k | } |
341 | | |
342 | 4.16k | if (stereo_config_index > 1) { |
343 | 2.25k | pstr_usac_mps212_config->bs_residual_bands = |
344 | 2.25k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
345 | | |
346 | 2.25k | if (pstr_usac_mps212_config->bs_residual_bands > MAX_PARAMETER_BANDS) |
347 | 1 | return IA_FATAL_ERROR; |
348 | | |
349 | 2.24k | pstr_usac_mps212_config->bs_ott_bands_phase = |
350 | 2.24k | max(pstr_usac_mps212_config->bs_ott_bands_phase, |
351 | 2.24k | pstr_usac_mps212_config->bs_residual_bands); |
352 | | |
353 | 2.24k | pstr_usac_mps212_config->bs_pseudo_lr = |
354 | 2.24k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
355 | 2.24k | } |
356 | | |
357 | 4.16k | if (pstr_usac_mps212_config->bs_temp_shape_config == 2) |
358 | 990 | pstr_usac_mps212_config->bs_env_quant_mode = |
359 | 990 | ixheaacd_read_bits_buf(it_bit_buff, 1); |
360 | | |
361 | 4.16k | return IA_NO_ERROR; |
362 | 4.16k | } |
363 | | |
364 | | IA_ERRORCODE ixheaacd_cpe_config( |
365 | | ia_bit_buf_struct *it_bit_buff, |
366 | | ia_usac_dec_element_config_struct *pstr_usac_element_config, |
367 | 12.6k | WORD32 sbr_ratio_index) { |
368 | 12.6k | pstr_usac_element_config->tw_mdct = ixheaacd_read_bits_buf(it_bit_buff, 1); |
369 | 12.6k | pstr_usac_element_config->noise_filling = |
370 | 12.6k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
371 | | |
372 | 12.6k | if (sbr_ratio_index > 0) { |
373 | 4.56k | ixheaacd_sbr_config(it_bit_buff, |
374 | 4.56k | &(pstr_usac_element_config->str_usac_sbr_config)); |
375 | 4.56k | pstr_usac_element_config->stereo_config_index = |
376 | 4.56k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
377 | | |
378 | 8.06k | } else { |
379 | 8.06k | pstr_usac_element_config->stereo_config_index = 0; |
380 | 8.06k | } |
381 | | |
382 | 12.6k | if (pstr_usac_element_config->stereo_config_index > 0) |
383 | 4.16k | return ixheaacd_mps212_config( |
384 | 4.16k | it_bit_buff, &(pstr_usac_element_config->str_usac_mps212_config), |
385 | 4.16k | pstr_usac_element_config->stereo_config_index); |
386 | | |
387 | 8.45k | return IA_NO_ERROR; |
388 | 12.6k | } |
389 | | |
390 | | WORD32 ixheaacd_decoder_config( |
391 | | ia_bit_buf_struct *it_bit_buff, |
392 | | ia_usac_decoder_config_struct *pstr_usac_decoder_config, |
393 | 28.4k | WORD32 sbr_ratio_index, UINT32 *chan, WORD32 ec_flag) { |
394 | 28.4k | UWORD32 elem_idx = 0; |
395 | 28.4k | UWORD32 err = 0; |
396 | 28.4k | WORD32 num_channels = 0; |
397 | | |
398 | 28.4k | ixheaacd_read_escape_value( |
399 | 28.4k | it_bit_buff, &(pstr_usac_decoder_config->num_elements), 4, 8, 16); |
400 | 28.4k | pstr_usac_decoder_config->num_elements += 1; |
401 | 28.4k | pstr_usac_decoder_config->preroll_flag = 0; |
402 | | |
403 | 28.4k | if (pstr_usac_decoder_config->num_elements > USAC_MAX_ELEMENTS) { |
404 | 15 | if (ec_flag) { |
405 | 0 | pstr_usac_decoder_config->num_elements = USAC_MAX_ELEMENTS; |
406 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
407 | 15 | } else { |
408 | 15 | return IA_FATAL_ERROR; |
409 | 15 | } |
410 | 15 | } |
411 | | |
412 | 75.5k | for (elem_idx = 0; elem_idx < pstr_usac_decoder_config->num_elements; |
413 | 47.2k | elem_idx++) { |
414 | 47.2k | ia_usac_dec_element_config_struct *pstr_usac_element_config = |
415 | 47.2k | &(pstr_usac_decoder_config->str_usac_element_config[elem_idx]); |
416 | | |
417 | 47.2k | pstr_usac_decoder_config->usac_element_type[elem_idx] = |
418 | 47.2k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
419 | | |
420 | 47.2k | switch (pstr_usac_decoder_config->usac_element_type[elem_idx]) { |
421 | 15.6k | case ID_USAC_SCE: |
422 | 15.6k | num_channels++; |
423 | 15.6k | pstr_usac_element_config->tw_mdct = |
424 | 15.6k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
425 | 15.6k | pstr_usac_element_config->noise_filling = |
426 | 15.6k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
427 | 15.6k | pstr_usac_element_config->stereo_config_index = 0; |
428 | 15.6k | if (sbr_ratio_index > 0) |
429 | 5.35k | ixheaacd_sbr_config(it_bit_buff, |
430 | 5.35k | &(pstr_usac_element_config->str_usac_sbr_config)); |
431 | | |
432 | 15.6k | break; |
433 | | |
434 | 12.6k | case ID_USAC_CPE: |
435 | 12.6k | num_channels += 2; |
436 | 12.6k | if (ixheaacd_cpe_config(it_bit_buff, pstr_usac_element_config, sbr_ratio_index) != |
437 | 12.6k | IA_NO_ERROR) { |
438 | 5 | if (ec_flag) { |
439 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
440 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
441 | 5 | } else { |
442 | 5 | return IA_FATAL_ERROR; |
443 | 5 | } |
444 | 5 | } |
445 | 12.6k | if (pstr_usac_element_config->stereo_config_index > 1 && *chan < 2) { |
446 | 5 | if (ec_flag) { |
447 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
448 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
449 | 5 | } else { |
450 | 5 | return IA_FATAL_ERROR; |
451 | 5 | } |
452 | 5 | } |
453 | 12.6k | break; |
454 | | |
455 | 12.6k | case ID_USAC_LFE: |
456 | 519 | num_channels++; |
457 | 519 | pstr_usac_element_config->tw_mdct = 0; |
458 | 519 | pstr_usac_element_config->noise_filling = 0; |
459 | 519 | pstr_usac_element_config->stereo_config_index = 0; |
460 | 519 | break; |
461 | | |
462 | 18.4k | case ID_USAC_EXT: |
463 | 18.4k | err = ixheaacd_ext_element_config( |
464 | 18.4k | it_bit_buff, pstr_usac_element_config, |
465 | 18.4k | &pstr_usac_decoder_config->usac_ext_ele_payload_buf[elem_idx][0], |
466 | 18.4k | &pstr_usac_decoder_config->usac_ext_ele_payload_len[elem_idx], |
467 | 18.4k | &(pstr_usac_decoder_config->preroll_flag)); |
468 | | |
469 | 18.4k | if (pstr_usac_decoder_config->usac_ext_ele_payload_len[elem_idx] > 0) { |
470 | 2.18k | pstr_usac_decoder_config->usac_ext_ele_payload_present[elem_idx] = 1; |
471 | 16.2k | } else { |
472 | 16.2k | pstr_usac_decoder_config->usac_ext_ele_payload_present[elem_idx] = 0; |
473 | 16.2k | } |
474 | 18.4k | if (err != 0) { |
475 | 30 | if (ec_flag) { |
476 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
477 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
478 | 30 | } else { |
479 | 30 | return IA_FATAL_ERROR; |
480 | 30 | } |
481 | 30 | } |
482 | 18.4k | break; |
483 | 18.4k | default: |
484 | 0 | if (ec_flag) { |
485 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
486 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
487 | 0 | } else { |
488 | 0 | return IA_FATAL_ERROR; |
489 | 0 | } |
490 | 0 | break; |
491 | 47.2k | } |
492 | 47.1k | if (num_channels > 2) { |
493 | 26 | if (ec_flag) { |
494 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
495 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
496 | 26 | } else { |
497 | 26 | return IA_FATAL_ERROR; |
498 | 26 | } |
499 | 26 | } |
500 | 47.1k | } |
501 | 28.2k | return err; |
502 | 28.4k | } |
503 | | |
504 | | WORD32 ixheaacd_config_extension(ia_bit_buf_struct *it_bit_buff, |
505 | 3.88k | ia_usac_decoder_config_struct *pstr_usac_decoder_config, WORD32 ec_flag) { |
506 | 3.88k | UWORD32 i, j; |
507 | 3.88k | UWORD32 num_config_extensions; |
508 | 3.88k | UWORD32 usac_config_ext_type, usac_config_ext_len; |
509 | | |
510 | 3.88k | ixheaacd_read_escape_value(it_bit_buff, &(num_config_extensions), 2, 4, 8); |
511 | 3.88k | num_config_extensions += 1; |
512 | 3.88k | if (USAC_MAX_CONFIG_EXTENSIONS < num_config_extensions) { |
513 | 4 | if (ec_flag) { |
514 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
515 | 4 | } else { |
516 | 4 | return IA_FATAL_ERROR; |
517 | 4 | } |
518 | 4 | } |
519 | | |
520 | 3.87k | pstr_usac_decoder_config->num_config_extensions = num_config_extensions; |
521 | 3.87k | memset(pstr_usac_decoder_config->usac_cfg_ext_info_len, 0, |
522 | 3.87k | USAC_MAX_CONFIG_EXTENSIONS * sizeof(WORD32)); |
523 | 3.87k | memset(pstr_usac_decoder_config->usac_cfg_ext_info_present, 0, |
524 | 3.87k | USAC_MAX_CONFIG_EXTENSIONS * sizeof(WORD32)); |
525 | | |
526 | 22.0k | for (j = 0; j < num_config_extensions; j++) { |
527 | 18.2k | UWORD32 fill_byte_val = 0xa5; |
528 | | |
529 | 18.2k | ixheaacd_read_escape_value(it_bit_buff, &(usac_config_ext_type), 4, 8, 16); |
530 | 18.2k | ixheaacd_read_escape_value(it_bit_buff, &(usac_config_ext_len), 4, 8, 16); |
531 | | |
532 | 18.2k | if (usac_config_ext_len > 768) { |
533 | 5 | if (ec_flag) { |
534 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
535 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
536 | 5 | } else { |
537 | 5 | return IA_FATAL_ERROR; |
538 | 5 | } |
539 | 5 | } |
540 | | |
541 | 18.2k | switch (usac_config_ext_type) { |
542 | 8.18k | case ID_CONFIG_EXT_FILL: |
543 | 8.20k | for (i = 0; i < usac_config_ext_len; i++) { |
544 | 35 | fill_byte_val = ixheaacd_read_bits_buf(it_bit_buff, 8); |
545 | 35 | if (fill_byte_val != 0xa5) { |
546 | 18 | if (ec_flag) { |
547 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
548 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
549 | 18 | } else { |
550 | 18 | return IA_FATAL_ERROR; |
551 | 18 | } |
552 | 18 | } |
553 | 35 | } |
554 | 8.17k | break; |
555 | 10.0k | default: |
556 | 10.0k | if ((WORD32)usac_config_ext_len > (it_bit_buff->cnt_bits >> 3)) { |
557 | 29 | if (ec_flag) { |
558 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
559 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
560 | 29 | } else { |
561 | 29 | return IA_FATAL_ERROR; |
562 | 29 | } |
563 | 29 | } |
564 | 10.0k | if (ID_CONFIG_EXT_LOUDNESS_INFO == usac_config_ext_type) { |
565 | 45.4k | for (i = 0; i < usac_config_ext_len; i++) { |
566 | 43.2k | UWORD8 byte_val = ixheaacd_read_bits_buf(it_bit_buff, 8); |
567 | 43.2k | pstr_usac_decoder_config->usac_cfg_ext_info_buf[j][i] = byte_val; |
568 | 43.2k | } |
569 | 2.22k | pstr_usac_decoder_config->usac_cfg_ext_info_len[j] = |
570 | 2.22k | usac_config_ext_len; |
571 | 2.22k | pstr_usac_decoder_config->usac_cfg_ext_info_present[j] = 1; |
572 | 7.78k | } else { |
573 | 38.5k | for (i = 0; i < usac_config_ext_len; i++) |
574 | 30.8k | ixheaacd_read_bits_buf(it_bit_buff, 8); |
575 | 7.78k | } |
576 | 10.0k | break; |
577 | 18.2k | } |
578 | 18.2k | } |
579 | | |
580 | 3.78k | return 0; |
581 | 3.87k | } |
582 | | |
583 | | WORD32 ixheaacd_config(ia_bit_buf_struct *it_bit_buff, ia_usac_config_struct *pstr_usac_conf, |
584 | 28.5k | UINT32 *chan, WORD32 ec_flag) { |
585 | 28.5k | WORD32 tmp, err; |
586 | 28.5k | err = 0; |
587 | | |
588 | 28.5k | pstr_usac_conf->usac_sampling_frequency_index = |
589 | 28.5k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
590 | | |
591 | 28.5k | if (pstr_usac_conf->usac_sampling_frequency_index == 0x1f) { |
592 | 86 | pstr_usac_conf->usac_sampling_frequency = |
593 | 86 | ixheaacd_read_bits_buf(it_bit_buff, 24); |
594 | | |
595 | 86 | if (pstr_usac_conf->usac_sampling_frequency > USAC_MAX_SAMPLE_RATE) { |
596 | 11 | if (ec_flag) { |
597 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
598 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
599 | 11 | } else { |
600 | 11 | return IA_FATAL_ERROR; |
601 | 11 | } |
602 | 11 | } |
603 | | |
604 | 28.4k | } else { |
605 | 28.4k | pstr_usac_conf->usac_sampling_frequency = |
606 | 28.4k | sampling_rate_tbl[pstr_usac_conf->usac_sampling_frequency_index]; |
607 | 28.4k | } |
608 | | |
609 | 28.5k | if (pstr_usac_conf->usac_sampling_frequency == 0) { |
610 | 3 | if (ec_flag) { |
611 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
612 | 3 | } else { |
613 | 3 | return IA_FATAL_ERROR; |
614 | 3 | } |
615 | 3 | } |
616 | 28.5k | pstr_usac_conf->core_sbr_framelength_index = |
617 | 28.5k | ixheaacd_read_bits_buf(it_bit_buff, 3); |
618 | | |
619 | 28.5k | if (pstr_usac_conf->core_sbr_framelength_index > MAX_CORE_SBR_FRAME_LEN_IDX) { |
620 | 13 | if (ec_flag) { |
621 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
622 | 13 | } else { |
623 | 13 | return IA_FATAL_ERROR; |
624 | 13 | } |
625 | 13 | } |
626 | | |
627 | 28.5k | pstr_usac_conf->channel_configuration_index = |
628 | 28.5k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
629 | 28.5k | if ((pstr_usac_conf->channel_configuration_index >= 3) && |
630 | 28.5k | (pstr_usac_conf->channel_configuration_index != 8)) { |
631 | 21 | if (ec_flag) { |
632 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
633 | 21 | } else { |
634 | 21 | return IA_FATAL_ERROR; |
635 | 21 | } |
636 | 21 | } |
637 | | |
638 | 28.5k | if (pstr_usac_conf->channel_configuration_index == 0) { |
639 | 6.85k | UWORD32 i; |
640 | | |
641 | 6.85k | ixheaacd_read_escape_value(it_bit_buff, |
642 | 6.85k | (UWORD32 *)(&(pstr_usac_conf->num_out_channels)), |
643 | 6.85k | 5, 8, 16); |
644 | 6.85k | if (BS_MAX_NUM_OUT_CHANNELS < pstr_usac_conf->num_out_channels) { |
645 | 12 | return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX; |
646 | 12 | } |
647 | 6.84k | if (pstr_usac_conf->num_out_channels < 1) { |
648 | 8 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
649 | 8 | } |
650 | 499k | for (i = 0; i < pstr_usac_conf->num_out_channels; i++) |
651 | 493k | pstr_usac_conf->output_channel_pos[i] = |
652 | 493k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
653 | | |
654 | 6.83k | if (ec_flag) { |
655 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
656 | 0 | } |
657 | 21.6k | } else { |
658 | 21.6k | err = ixheaacd_get_usac_chan_conf(pstr_usac_conf, pstr_usac_conf->channel_configuration_index, |
659 | 21.6k | it_bit_buff, ec_flag); |
660 | 21.6k | if (err != 0) |
661 | 0 | return err; |
662 | 21.6k | } |
663 | | |
664 | 28.4k | err = ixheaacd_decoder_config( |
665 | 28.4k | it_bit_buff, &(pstr_usac_conf->str_usac_dec_config), |
666 | 28.4k | ixheaacd_sbr_ratio(pstr_usac_conf->core_sbr_framelength_index), chan, ec_flag); |
667 | 28.4k | if (err != 0) return err; |
668 | | |
669 | 28.4k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 1); |
670 | | |
671 | 28.4k | if (tmp) { |
672 | 3.88k | err = ixheaacd_config_extension(it_bit_buff, |
673 | 3.88k | &pstr_usac_conf->str_usac_dec_config, ec_flag); |
674 | 3.88k | if (err != 0) return -1; |
675 | 3.88k | } |
676 | | |
677 | 28.3k | return err; |
678 | 28.4k | } |
679 | | |
680 | 28.5k | VOID ixheaacd_conf_default(ia_usac_config_struct *pstr_usac_conf) { |
681 | 28.5k | WORD32 i; |
682 | | |
683 | 28.5k | pstr_usac_conf->num_out_channels = 0; |
684 | | |
685 | 7.30M | for (i = 0; i < BS_MAX_NUM_OUT_CHANNELS; i++) |
686 | 7.27M | pstr_usac_conf->output_channel_pos[i] = BS_OUTPUT_CHANNEL_POS_NA; |
687 | | |
688 | 28.5k | pstr_usac_conf->str_usac_dec_config.num_elements = 0; |
689 | | |
690 | 484k | for (i = 0; i < USAC_MAX_ELEMENTS; i++) |
691 | 456k | pstr_usac_conf->str_usac_dec_config.usac_element_type[i] = ID_USAC_INVALID; |
692 | | |
693 | 28.5k | return; |
694 | 28.5k | } |