/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 | 29.4k | UWORD32 ixheaacd_sbr_ratio(UWORD32 core_sbr_framelength_idx) { |
82 | 29.4k | UWORD32 sbr_ratio_index = 0x0FF; |
83 | | |
84 | 29.4k | switch (core_sbr_framelength_idx) { |
85 | 2.53k | case 0: |
86 | 21.2k | case 1: |
87 | 21.2k | sbr_ratio_index = USAC_SBR_RATIO_NO_SBR; |
88 | 21.2k | break; |
89 | 1.28k | case 2: |
90 | 1.28k | sbr_ratio_index = USAC_SBR_RATIO_INDEX_8_3; |
91 | 1.28k | break; |
92 | 6.21k | case 3: |
93 | 6.21k | sbr_ratio_index = USAC_SBR_RATIO_INDEX_2_1; |
94 | 6.21k | break; |
95 | 713 | case 4: |
96 | 713 | sbr_ratio_index = USAC_SBR_RATIO_INDEX_4_1; |
97 | 713 | break; |
98 | 29.4k | } |
99 | | |
100 | 29.4k | return sbr_ratio_index; |
101 | 29.4k | } |
102 | | |
103 | 6.96k | static WORD32 ixheaacd_get_sample_freq_indx(WORD32 sampling_freq) { |
104 | 6.96k | WORD32 index; |
105 | 6.96k | const WORD32 tbl_size = sizeof(sampling_rate_tbl) / sizeof(WORD32) - 1; |
106 | | |
107 | 129k | for (index = 0; index < tbl_size; index++) { |
108 | 126k | if (sampling_rate_tbl[index] == sampling_freq) break; |
109 | 126k | } |
110 | 6.96k | return index; |
111 | 6.96k | } |
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 | 6.96k | UWORD32 *sample_freq_indx) { |
116 | 6.96k | UWORD32 sbr_ratio_index = 0x0FF; |
117 | | |
118 | 6.96k | *output_framelength = -1; |
119 | | |
120 | 6.96k | switch (core_sbr_framelength_idx) { |
121 | 1.49k | case 0: |
122 | 1.49k | sbr_ratio_index = USAC_SBR_RATIO_NO_SBR; |
123 | 1.49k | *output_framelength = USAC_OUT_FRAMELENGTH_768; |
124 | 1.49k | *block_size = 768; |
125 | 1.49k | *output_samples = *block_size; |
126 | 1.49k | break; |
127 | 1.40k | case 1: |
128 | 1.40k | sbr_ratio_index = USAC_SBR_RATIO_NO_SBR; |
129 | 1.40k | *output_framelength = USAC_OUT_FRAMELENGTH_1024; |
130 | 1.40k | *block_size = 1024; |
131 | 1.40k | *output_samples = *block_size; |
132 | 1.40k | break; |
133 | 675 | case 2: |
134 | 675 | sbr_ratio_index = USAC_SBR_RATIO_INDEX_8_3; |
135 | 675 | *output_framelength = USAC_OUT_FRAMELENGTH_2048; |
136 | 675 | *block_size = 768; |
137 | 675 | *output_samples = (*block_size * 8) / 3; |
138 | 675 | *sample_rate_layer = (*sample_rate_layer * 3) >> 3; |
139 | 675 | break; |
140 | 2.99k | case 3: |
141 | 2.99k | sbr_ratio_index = USAC_SBR_RATIO_INDEX_2_1; |
142 | 2.99k | *output_framelength = USAC_OUT_FRAMELENGTH_2048; |
143 | 2.99k | *block_size = 1024; |
144 | 2.99k | *output_samples = *block_size * 2; |
145 | 2.99k | *sample_rate_layer = *sample_rate_layer >> 1; |
146 | 2.99k | break; |
147 | 394 | case 4: |
148 | 394 | sbr_ratio_index = USAC_SBR_RATIO_INDEX_4_1; |
149 | 394 | *output_framelength = USAC_OUT_FRAMELENGTH_4096; |
150 | 394 | *block_size = 1024; |
151 | 394 | *output_samples = *block_size * 4; |
152 | 394 | *sample_rate_layer = *sample_rate_layer >> 2; |
153 | 394 | break; |
154 | 6.96k | } |
155 | | |
156 | 6.96k | *sample_freq_indx = ixheaacd_get_sample_freq_indx(*sample_rate_layer); |
157 | | |
158 | 6.96k | return sbr_ratio_index; |
159 | 6.96k | } |
160 | | |
161 | | VOID ixheaacd_read_escape_value(ia_bit_buf_struct *it_bit_buff, |
162 | | UWORD32 *ext_ele_value, UWORD32 no_bits1, |
163 | 113k | UWORD32 no_bits2, UWORD32 no_bits3) { |
164 | 113k | UWORD32 value = 0; |
165 | 113k | UWORD32 val_add = 0; |
166 | 113k | UWORD32 max_val1 = (1 << no_bits1) - 1; |
167 | 113k | UWORD32 max_val2 = (1 << no_bits2) - 1; |
168 | | |
169 | 113k | value = ixheaacd_read_bits_buf(it_bit_buff, no_bits1); |
170 | | |
171 | 113k | if (value == max_val1) { |
172 | 6.19k | val_add = ixheaacd_read_bits_buf(it_bit_buff, no_bits2); |
173 | | |
174 | 6.19k | value += val_add; |
175 | | |
176 | 6.19k | if (val_add == max_val2) { |
177 | 993 | val_add = ixheaacd_read_bits_buf(it_bit_buff, no_bits3); |
178 | | |
179 | 993 | value += val_add; |
180 | 993 | } |
181 | 6.19k | } |
182 | | |
183 | 113k | *ext_ele_value = value; |
184 | 113k | } |
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 | 23.1k | { |
189 | 23.1k | switch (ch_config_index) { |
190 | 860 | case 1: |
191 | 860 | pstr_usac_config->num_out_channels = 1; |
192 | 860 | pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_C; |
193 | 860 | break; |
194 | 20.3k | case 2: |
195 | 20.3k | pstr_usac_config->num_out_channels = 2; |
196 | 20.3k | pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_L; |
197 | 20.3k | pstr_usac_config->output_channel_pos[1] = BS_OUTPUT_CHANNEL_POS_R; |
198 | 20.3k | break; |
199 | 1.95k | case 8: |
200 | 1.95k | pstr_usac_config->num_out_channels = 2; |
201 | 1.95k | pstr_usac_config->output_channel_pos[0] = BS_OUTPUT_CHANNEL_POS_NA; |
202 | 1.95k | pstr_usac_config->output_channel_pos[1] = BS_OUTPUT_CHANNEL_POS_NA; |
203 | 1.95k | 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 | 23.1k | } |
213 | 23.1k | return IA_NO_ERROR; |
214 | 23.1k | } |
215 | | |
216 | | VOID ixheaacd_sbr_config(ia_bit_buf_struct *it_bit_buff, |
217 | 8.70k | ia_usac_dec_sbr_config_struct *pstr_usac_sbr_config) { |
218 | 8.70k | pstr_usac_sbr_config->harmonic_sbr = ixheaacd_read_bits_buf(it_bit_buff, 1); |
219 | 8.70k | pstr_usac_sbr_config->bs_inter_tes = ixheaacd_read_bits_buf(it_bit_buff, 1); |
220 | 8.70k | pstr_usac_sbr_config->bs_pvc = ixheaacd_read_bits_buf(it_bit_buff, 1); |
221 | 8.70k | pstr_usac_sbr_config->dflt_start_freq = |
222 | 8.70k | ixheaacd_read_bits_buf(it_bit_buff, 4); |
223 | | |
224 | 8.70k | pstr_usac_sbr_config->dflt_stop_freq = ixheaacd_read_bits_buf(it_bit_buff, 4); |
225 | 8.70k | pstr_usac_sbr_config->dflt_header_extra1 = |
226 | 8.70k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
227 | 8.70k | pstr_usac_sbr_config->dflt_header_extra2 = |
228 | 8.70k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
229 | | |
230 | 8.70k | if (pstr_usac_sbr_config->dflt_header_extra1) { |
231 | 3.63k | pstr_usac_sbr_config->dflt_freq_scale = |
232 | 3.63k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
233 | 3.63k | pstr_usac_sbr_config->dflt_alter_scale = |
234 | 3.63k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
235 | 3.63k | pstr_usac_sbr_config->dflt_noise_bands = |
236 | 3.63k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
237 | 3.63k | } |
238 | | |
239 | 8.70k | if (pstr_usac_sbr_config->dflt_header_extra2) { |
240 | 1.51k | pstr_usac_sbr_config->dflt_limiter_bands = |
241 | 1.51k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
242 | 1.51k | pstr_usac_sbr_config->dflt_limiter_gains = |
243 | 1.51k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
244 | 1.51k | pstr_usac_sbr_config->dflt_interpol_freq = |
245 | 1.51k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
246 | 1.51k | pstr_usac_sbr_config->dflt_smoothing_mode = |
247 | 1.51k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
248 | 1.51k | } |
249 | 8.70k | } |
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.2k | WORD32 *preroll_flag) { |
256 | 18.2k | UWORD32 usac_ext_element_type, usac_ext_element_config_length, flag; |
257 | | |
258 | 18.2k | UWORD32 i; |
259 | | |
260 | 18.2k | ixheaacd_read_escape_value(it_bit_buff, &(usac_ext_element_type), 4, 8, 16); |
261 | | |
262 | 18.2k | ixheaacd_read_escape_value(it_bit_buff, &(usac_ext_element_config_length), 4, |
263 | 18.2k | 8, 16); |
264 | 18.2k | if (usac_ext_element_config_length >= 768) return -1; |
265 | | |
266 | 18.2k | flag = ixheaacd_read_bits_buf(it_bit_buff, 1); |
267 | | |
268 | 18.2k | *ptr_usac_ext_ele_payload_len = 0; |
269 | | |
270 | 18.2k | if (flag) { |
271 | 3.65k | ixheaacd_read_escape_value( |
272 | 3.65k | it_bit_buff, |
273 | 3.65k | (UWORD32 *)(&(pstr_usac_element_config->usac_ext_eleme_def_len)), 8, 16, |
274 | 3.65k | 0); |
275 | 3.65k | pstr_usac_element_config->usac_ext_eleme_def_len += 1; |
276 | | |
277 | 14.5k | } else { |
278 | 14.5k | pstr_usac_element_config->usac_ext_eleme_def_len = 0; |
279 | 14.5k | } |
280 | | |
281 | 18.2k | pstr_usac_element_config->usac_ext_elem_pld_frag = |
282 | 18.2k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
283 | | |
284 | 18.2k | switch (usac_ext_element_type) { |
285 | 68 | case ID_EXT_ELE_FILL: |
286 | 68 | break; |
287 | 8.04k | case ID_EXT_ELE_AUDIOPREROLL: |
288 | 8.04k | *preroll_flag = 1; |
289 | 8.04k | break; |
290 | 2.19k | case ID_EXT_ELE_UNI_DRC: |
291 | 47.7k | for (i = 0; i < usac_ext_element_config_length; i++) { |
292 | 45.5k | ptr_usac_ext_ele_payload[i] = ixheaacd_read_bits_buf(it_bit_buff, 8); |
293 | 45.5k | } |
294 | 2.19k | *ptr_usac_ext_ele_payload_len = usac_ext_element_config_length; |
295 | 2.19k | break; |
296 | | |
297 | 7.89k | default: |
298 | 7.89k | if ((it_bit_buff->cnt_bits >> 3) < (WORD32)usac_ext_element_config_length) |
299 | 16 | return -1; |
300 | 7.87k | it_bit_buff->ptr_read_next += usac_ext_element_config_length; |
301 | 7.87k | it_bit_buff->cnt_bits -= (usac_ext_element_config_length << 3); |
302 | | |
303 | 7.87k | break; |
304 | 18.2k | } |
305 | | |
306 | 18.1k | return 0; |
307 | 18.2k | } |
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 | 3.81k | WORD32 stereo_config_index) { |
313 | 3.81k | pstr_usac_mps212_config->bs_freq_res = ixheaacd_read_bits_buf(it_bit_buff, 3); |
314 | | |
315 | 3.81k | pstr_usac_mps212_config->bs_fixed_gain_dmx = |
316 | 3.81k | ixheaacd_read_bits_buf(it_bit_buff, 3); |
317 | | |
318 | 3.81k | pstr_usac_mps212_config->bs_temp_shape_config = |
319 | 3.81k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
320 | | |
321 | 3.81k | pstr_usac_mps212_config->bs_decorr_config = |
322 | 3.81k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
323 | 3.81k | if (pstr_usac_mps212_config->bs_decorr_config > MAX_DECOR_CONFIG_IDX) |
324 | 1 | return IA_FATAL_ERROR; |
325 | | |
326 | 3.81k | pstr_usac_mps212_config->bs_high_rate_mode = |
327 | 3.81k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
328 | | |
329 | 3.81k | pstr_usac_mps212_config->bs_phase_coding = |
330 | 3.81k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
331 | | |
332 | 3.81k | pstr_usac_mps212_config->bs_ott_bands_phase_present = |
333 | 3.81k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
334 | | |
335 | 3.81k | if (pstr_usac_mps212_config->bs_ott_bands_phase_present) { |
336 | 1.41k | pstr_usac_mps212_config->bs_ott_bands_phase = |
337 | 1.41k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
338 | 1.41k | if (pstr_usac_mps212_config->bs_ott_bands_phase > MAX_PARAMETER_BANDS) |
339 | 1 | return IA_FATAL_ERROR; |
340 | 1.41k | } |
341 | | |
342 | 3.81k | if (stereo_config_index > 1) { |
343 | 2.28k | pstr_usac_mps212_config->bs_residual_bands = |
344 | 2.28k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
345 | | |
346 | 2.28k | if (pstr_usac_mps212_config->bs_residual_bands > MAX_PARAMETER_BANDS) |
347 | 2 | return IA_FATAL_ERROR; |
348 | | |
349 | 2.28k | pstr_usac_mps212_config->bs_ott_bands_phase = |
350 | 2.28k | max(pstr_usac_mps212_config->bs_ott_bands_phase, |
351 | 2.28k | pstr_usac_mps212_config->bs_residual_bands); |
352 | | |
353 | 2.28k | pstr_usac_mps212_config->bs_pseudo_lr = |
354 | 2.28k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
355 | 2.28k | } |
356 | | |
357 | 3.81k | if (pstr_usac_mps212_config->bs_temp_shape_config == 2) |
358 | 958 | pstr_usac_mps212_config->bs_env_quant_mode = |
359 | 958 | ixheaacd_read_bits_buf(it_bit_buff, 1); |
360 | | |
361 | 3.81k | return IA_NO_ERROR; |
362 | 3.81k | } |
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 | 13.0k | WORD32 sbr_ratio_index) { |
368 | 13.0k | pstr_usac_element_config->tw_mdct = ixheaacd_read_bits_buf(it_bit_buff, 1); |
369 | 13.0k | pstr_usac_element_config->noise_filling = |
370 | 13.0k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
371 | | |
372 | 13.0k | if (sbr_ratio_index > 0) { |
373 | 4.13k | ixheaacd_sbr_config(it_bit_buff, |
374 | 4.13k | &(pstr_usac_element_config->str_usac_sbr_config)); |
375 | 4.13k | pstr_usac_element_config->stereo_config_index = |
376 | 4.13k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
377 | | |
378 | 8.89k | } else { |
379 | 8.89k | pstr_usac_element_config->stereo_config_index = 0; |
380 | 8.89k | } |
381 | | |
382 | 13.0k | if (pstr_usac_element_config->stereo_config_index > 0) |
383 | 3.81k | return ixheaacd_mps212_config( |
384 | 3.81k | it_bit_buff, &(pstr_usac_element_config->str_usac_mps212_config), |
385 | 3.81k | pstr_usac_element_config->stereo_config_index); |
386 | | |
387 | 9.21k | return IA_NO_ERROR; |
388 | 13.0k | } |
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 | 29.4k | WORD32 sbr_ratio_index, UINT32 *chan, WORD32 ec_flag) { |
394 | 29.4k | UWORD32 elem_idx = 0; |
395 | 29.4k | UWORD32 err = 0; |
396 | 29.4k | WORD32 num_channels = 0; |
397 | | |
398 | 29.4k | ixheaacd_read_escape_value( |
399 | 29.4k | it_bit_buff, &(pstr_usac_decoder_config->num_elements), 4, 8, 16); |
400 | 29.4k | pstr_usac_decoder_config->num_elements += 1; |
401 | 29.4k | pstr_usac_decoder_config->preroll_flag = 0; |
402 | | |
403 | 29.4k | if (pstr_usac_decoder_config->num_elements > USAC_MAX_ELEMENTS) { |
404 | 12 | 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 | 12 | } else { |
408 | 12 | return IA_FATAL_ERROR; |
409 | 12 | } |
410 | 12 | } |
411 | | |
412 | 76.9k | for (elem_idx = 0; elem_idx < pstr_usac_decoder_config->num_elements; |
413 | 47.6k | elem_idx++) { |
414 | 47.6k | ia_usac_dec_element_config_struct *pstr_usac_element_config = |
415 | 47.6k | &(pstr_usac_decoder_config->str_usac_element_config[elem_idx]); |
416 | | |
417 | 47.6k | pstr_usac_decoder_config->usac_element_type[elem_idx] = |
418 | 47.6k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
419 | | |
420 | 47.6k | switch (pstr_usac_decoder_config->usac_element_type[elem_idx]) { |
421 | 16.0k | case ID_USAC_SCE: |
422 | 16.0k | num_channels++; |
423 | 16.0k | pstr_usac_element_config->tw_mdct = |
424 | 16.0k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
425 | 16.0k | pstr_usac_element_config->noise_filling = |
426 | 16.0k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
427 | 16.0k | pstr_usac_element_config->stereo_config_index = 0; |
428 | 16.0k | if (sbr_ratio_index > 0) |
429 | 4.57k | ixheaacd_sbr_config(it_bit_buff, |
430 | 4.57k | &(pstr_usac_element_config->str_usac_sbr_config)); |
431 | | |
432 | 16.0k | break; |
433 | | |
434 | 13.0k | case ID_USAC_CPE: |
435 | 13.0k | num_channels += 2; |
436 | 13.0k | if (ixheaacd_cpe_config(it_bit_buff, pstr_usac_element_config, sbr_ratio_index) != |
437 | 13.0k | IA_NO_ERROR) { |
438 | 4 | if (ec_flag) { |
439 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
440 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
441 | 4 | } else { |
442 | 4 | return IA_FATAL_ERROR; |
443 | 4 | } |
444 | 4 | } |
445 | 13.0k | if (pstr_usac_element_config->stereo_config_index > 1 && *chan < 2) { |
446 | 4 | if (ec_flag) { |
447 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
448 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
449 | 4 | } else { |
450 | 4 | return IA_FATAL_ERROR; |
451 | 4 | } |
452 | 4 | } |
453 | 13.0k | break; |
454 | | |
455 | 13.0k | case ID_USAC_LFE: |
456 | 332 | num_channels++; |
457 | 332 | pstr_usac_element_config->tw_mdct = 0; |
458 | 332 | pstr_usac_element_config->noise_filling = 0; |
459 | 332 | pstr_usac_element_config->stereo_config_index = 0; |
460 | 332 | break; |
461 | | |
462 | 18.2k | case ID_USAC_EXT: |
463 | 18.2k | err = ixheaacd_ext_element_config( |
464 | 18.2k | it_bit_buff, pstr_usac_element_config, |
465 | 18.2k | &pstr_usac_decoder_config->usac_ext_ele_payload_buf[elem_idx][0], |
466 | 18.2k | &pstr_usac_decoder_config->usac_ext_ele_payload_len[elem_idx], |
467 | 18.2k | &(pstr_usac_decoder_config->preroll_flag)); |
468 | | |
469 | 18.2k | if (pstr_usac_decoder_config->usac_ext_ele_payload_len[elem_idx] > 0) { |
470 | 2.05k | pstr_usac_decoder_config->usac_ext_ele_payload_present[elem_idx] = 1; |
471 | 16.1k | } else { |
472 | 16.1k | pstr_usac_decoder_config->usac_ext_ele_payload_present[elem_idx] = 0; |
473 | 16.1k | } |
474 | 18.2k | if (err != 0) { |
475 | 19 | if (ec_flag) { |
476 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
477 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
478 | 19 | } else { |
479 | 19 | return IA_FATAL_ERROR; |
480 | 19 | } |
481 | 19 | } |
482 | 18.1k | break; |
483 | 18.1k | 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.6k | } |
492 | 47.6k | if (num_channels > 2) { |
493 | 17 | if (ec_flag) { |
494 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
495 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
496 | 17 | } else { |
497 | 17 | return IA_FATAL_ERROR; |
498 | 17 | } |
499 | 17 | } |
500 | 47.6k | } |
501 | 29.3k | return err; |
502 | 29.4k | } |
503 | | |
504 | | WORD32 ixheaacd_config_extension(ia_bit_buf_struct *it_bit_buff, |
505 | 3.46k | ia_usac_decoder_config_struct *pstr_usac_decoder_config, WORD32 ec_flag) { |
506 | 3.46k | UWORD32 i, j; |
507 | 3.46k | UWORD32 num_config_extensions; |
508 | 3.46k | UWORD32 usac_config_ext_type, usac_config_ext_len; |
509 | | |
510 | 3.46k | ixheaacd_read_escape_value(it_bit_buff, &(num_config_extensions), 2, 4, 8); |
511 | 3.46k | num_config_extensions += 1; |
512 | 3.46k | if (USAC_MAX_CONFIG_EXTENSIONS < num_config_extensions) { |
513 | 6 | if (ec_flag) { |
514 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
515 | 6 | } else { |
516 | 6 | return IA_FATAL_ERROR; |
517 | 6 | } |
518 | 6 | } |
519 | | |
520 | 3.45k | pstr_usac_decoder_config->num_config_extensions = num_config_extensions; |
521 | 3.45k | memset(pstr_usac_decoder_config->usac_cfg_ext_info_len, 0, |
522 | 3.45k | USAC_MAX_CONFIG_EXTENSIONS * sizeof(WORD32)); |
523 | 3.45k | memset(pstr_usac_decoder_config->usac_cfg_ext_info_present, 0, |
524 | 3.45k | USAC_MAX_CONFIG_EXTENSIONS * sizeof(WORD32)); |
525 | | |
526 | 20.6k | for (j = 0; j < num_config_extensions; j++) { |
527 | 17.2k | UWORD32 fill_byte_val = 0xa5; |
528 | | |
529 | 17.2k | ixheaacd_read_escape_value(it_bit_buff, &(usac_config_ext_type), 4, 8, 16); |
530 | 17.2k | ixheaacd_read_escape_value(it_bit_buff, &(usac_config_ext_len), 4, 8, 16); |
531 | | |
532 | 17.2k | if (usac_config_ext_len > 768) { |
533 | 7 | if (ec_flag) { |
534 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
535 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
536 | 7 | } else { |
537 | 7 | return IA_FATAL_ERROR; |
538 | 7 | } |
539 | 7 | } |
540 | | |
541 | 17.2k | switch (usac_config_ext_type) { |
542 | 7.64k | case ID_CONFIG_EXT_FILL: |
543 | 7.66k | for (i = 0; i < usac_config_ext_len; i++) { |
544 | 29 | fill_byte_val = ixheaacd_read_bits_buf(it_bit_buff, 8); |
545 | 29 | if (fill_byte_val != 0xa5) { |
546 | 16 | if (ec_flag) { |
547 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
548 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
549 | 16 | } else { |
550 | 16 | return IA_FATAL_ERROR; |
551 | 16 | } |
552 | 16 | } |
553 | 29 | } |
554 | 7.63k | break; |
555 | 9.55k | default: |
556 | 9.55k | if ((WORD32)usac_config_ext_len > (it_bit_buff->cnt_bits >> 3)) { |
557 | 20 | if (ec_flag) { |
558 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
559 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
560 | 20 | } else { |
561 | 20 | return IA_FATAL_ERROR; |
562 | 20 | } |
563 | 20 | } |
564 | 9.53k | if (ID_CONFIG_EXT_LOUDNESS_INFO == usac_config_ext_type) { |
565 | 45.9k | for (i = 0; i < usac_config_ext_len; i++) { |
566 | 43.9k | UWORD8 byte_val = ixheaacd_read_bits_buf(it_bit_buff, 8); |
567 | 43.9k | pstr_usac_decoder_config->usac_cfg_ext_info_buf[j][i] = byte_val; |
568 | 43.9k | } |
569 | 2.04k | pstr_usac_decoder_config->usac_cfg_ext_info_len[j] = |
570 | 2.04k | usac_config_ext_len; |
571 | 2.04k | pstr_usac_decoder_config->usac_cfg_ext_info_present[j] = 1; |
572 | 7.49k | } else { |
573 | 26.5k | for (i = 0; i < usac_config_ext_len; i++) |
574 | 19.0k | ixheaacd_read_bits_buf(it_bit_buff, 8); |
575 | 7.49k | } |
576 | 9.53k | break; |
577 | 17.2k | } |
578 | 17.2k | } |
579 | | |
580 | 3.38k | return 0; |
581 | 3.45k | } |
582 | | |
583 | | WORD32 ixheaacd_config(ia_bit_buf_struct *it_bit_buff, ia_usac_config_struct *pstr_usac_conf, |
584 | 29.5k | UINT32 *chan, WORD32 ec_flag) { |
585 | 29.5k | WORD32 tmp, err; |
586 | 29.5k | err = 0; |
587 | | |
588 | 29.5k | pstr_usac_conf->usac_sampling_frequency_index = |
589 | 29.5k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
590 | | |
591 | 29.5k | if (pstr_usac_conf->usac_sampling_frequency_index == 0x1f) { |
592 | 49 | pstr_usac_conf->usac_sampling_frequency = |
593 | 49 | ixheaacd_read_bits_buf(it_bit_buff, 24); |
594 | | |
595 | 49 | if (pstr_usac_conf->usac_sampling_frequency > USAC_MAX_SAMPLE_RATE) { |
596 | 8 | if (ec_flag) { |
597 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
598 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
599 | 8 | } else { |
600 | 8 | return IA_FATAL_ERROR; |
601 | 8 | } |
602 | 8 | } |
603 | | |
604 | 29.4k | } else { |
605 | 29.4k | pstr_usac_conf->usac_sampling_frequency = |
606 | 29.4k | sampling_rate_tbl[pstr_usac_conf->usac_sampling_frequency_index]; |
607 | 29.4k | } |
608 | | |
609 | 29.5k | if (pstr_usac_conf->usac_sampling_frequency == 0) { |
610 | 2 | if (ec_flag) { |
611 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
612 | 2 | } else { |
613 | 2 | return IA_FATAL_ERROR; |
614 | 2 | } |
615 | 2 | } |
616 | 29.5k | pstr_usac_conf->core_sbr_framelength_index = |
617 | 29.5k | ixheaacd_read_bits_buf(it_bit_buff, 3); |
618 | | |
619 | 29.5k | if (pstr_usac_conf->core_sbr_framelength_index > MAX_CORE_SBR_FRAME_LEN_IDX) { |
620 | 7 | if (ec_flag) { |
621 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
622 | 7 | } else { |
623 | 7 | return IA_FATAL_ERROR; |
624 | 7 | } |
625 | 7 | } |
626 | | |
627 | 29.5k | pstr_usac_conf->channel_configuration_index = |
628 | 29.5k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
629 | 29.5k | if ((pstr_usac_conf->channel_configuration_index >= 3) && |
630 | 29.5k | (pstr_usac_conf->channel_configuration_index != 8)) { |
631 | 17 | if (ec_flag) { |
632 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
633 | 17 | } else { |
634 | 17 | return IA_FATAL_ERROR; |
635 | 17 | } |
636 | 17 | } |
637 | | |
638 | 29.4k | if (pstr_usac_conf->channel_configuration_index == 0) { |
639 | 6.33k | UWORD32 i; |
640 | | |
641 | 6.33k | ixheaacd_read_escape_value(it_bit_buff, |
642 | 6.33k | (UWORD32 *)(&(pstr_usac_conf->num_out_channels)), |
643 | 6.33k | 5, 8, 16); |
644 | 6.33k | if (BS_MAX_NUM_OUT_CHANNELS < pstr_usac_conf->num_out_channels) { |
645 | 9 | return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX; |
646 | 9 | } |
647 | 6.33k | if (pstr_usac_conf->num_out_channels < 1) { |
648 | 10 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
649 | 10 | } |
650 | 514k | for (i = 0; i < pstr_usac_conf->num_out_channels; i++) |
651 | 507k | pstr_usac_conf->output_channel_pos[i] = |
652 | 507k | ixheaacd_read_bits_buf(it_bit_buff, 5); |
653 | | |
654 | 6.32k | if (ec_flag) { |
655 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
656 | 0 | } |
657 | 23.1k | } else { |
658 | 23.1k | err = ixheaacd_get_usac_chan_conf(pstr_usac_conf, pstr_usac_conf->channel_configuration_index, |
659 | 23.1k | it_bit_buff, ec_flag); |
660 | 23.1k | if (err != 0) |
661 | 0 | return err; |
662 | 23.1k | } |
663 | | |
664 | 29.4k | err = ixheaacd_decoder_config( |
665 | 29.4k | it_bit_buff, &(pstr_usac_conf->str_usac_dec_config), |
666 | 29.4k | ixheaacd_sbr_ratio(pstr_usac_conf->core_sbr_framelength_index), chan, ec_flag); |
667 | 29.4k | if (err != 0) return err; |
668 | | |
669 | 29.4k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 1); |
670 | | |
671 | 29.4k | if (tmp) { |
672 | 3.46k | err = ixheaacd_config_extension(it_bit_buff, |
673 | 3.46k | &pstr_usac_conf->str_usac_dec_config, ec_flag); |
674 | 3.46k | if (err != 0) return -1; |
675 | 3.46k | } |
676 | | |
677 | 29.3k | return err; |
678 | 29.4k | } |
679 | | |
680 | 29.4k | VOID ixheaacd_conf_default(ia_usac_config_struct *pstr_usac_conf) { |
681 | 29.4k | WORD32 i; |
682 | | |
683 | 29.4k | pstr_usac_conf->num_out_channels = 0; |
684 | | |
685 | 7.54M | for (i = 0; i < BS_MAX_NUM_OUT_CHANNELS; i++) |
686 | 7.51M | pstr_usac_conf->output_channel_pos[i] = BS_OUTPUT_CHANNEL_POS_NA; |
687 | | |
688 | 29.4k | pstr_usac_conf->str_usac_dec_config.num_elements = 0; |
689 | | |
690 | 501k | for (i = 0; i < USAC_MAX_ELEMENTS; i++) |
691 | 471k | pstr_usac_conf->str_usac_dec_config.usac_element_type[i] = ID_USAC_INVALID; |
692 | | |
693 | 29.4k | return; |
694 | 29.4k | } |