/src/libxaac/decoder/ixheaacd_headerdecode.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 "ixheaac_type_def.h" |
22 | | #include "ixheaac_error_standards.h" |
23 | | #include "ixheaac_constants.h" |
24 | | #include "ixheaac_basic_ops32.h" |
25 | | #include "ixheaac_basic_ops16.h" |
26 | | #include "ixheaac_basic_ops40.h" |
27 | | #include "ixheaacd_sbr_common.h" |
28 | | |
29 | | #include "ixheaacd_bitbuffer.h" |
30 | | #include "ixheaacd_defines.h" |
31 | | #include "ixheaacd_aac_rom.h" |
32 | | |
33 | | #include "ixheaacd_sbrdecsettings.h" |
34 | | #include "ixheaacd_sbr_scale.h" |
35 | | #include "ixheaacd_env_extr_part.h" |
36 | | #include "ixheaacd_sbr_rom.h" |
37 | | |
38 | | #include "ixheaacd_lpp_tran.h" |
39 | | #include "ixheaacd_hybrid.h" |
40 | | #include "ixheaacd_ps_dec.h" |
41 | | |
42 | | #include "ixheaacd_env_extr.h" |
43 | | #include "ixheaacd_common_rom.h" |
44 | | |
45 | | #include "ixheaacd_pulsedata.h" |
46 | | |
47 | | #include "ixheaacd_pns.h" |
48 | | #include "ixheaacd_drc_data_struct.h" |
49 | | |
50 | | #include "ixheaacd_lt_predict.h" |
51 | | |
52 | | #include "ixheaacd_cnst.h" |
53 | | #include "ixheaacd_ec_defines.h" |
54 | | #include "ixheaacd_ec_struct_def.h" |
55 | | #include "ixheaacd_channelinfo.h" |
56 | | #include "ixheaacd_drc_dec.h" |
57 | | #include "ixheaacd_sbrdecoder.h" |
58 | | #include "ixheaacd_block.h" |
59 | | #include "ixheaacd_channel.h" |
60 | | |
61 | | #include "ixheaacd_adts.h" |
62 | | #include "ixheaacd_audioobjtypes.h" |
63 | | #include "ixheaacd_sbrdecoder.h" |
64 | | #include "ixheaacd_memory_standards.h" |
65 | | |
66 | | #include "ixheaacd_latmdemux.h" |
67 | | |
68 | | #include "ixheaacd_aacdec.h" |
69 | | #include "ixheaacd_mps_polyphase.h" |
70 | | #include "ixheaacd_config.h" |
71 | | #include "ixheaacd_qmf_dec.h" |
72 | | #include "ixheaacd_mps_macro_def.h" |
73 | | #include "ixheaacd_mps_struct_def.h" |
74 | | #include "ixheaacd_mps_res_rom.h" |
75 | | #include "ixheaacd_mps_aac_struct.h" |
76 | | #include "ixheaacd_mps_dec.h" |
77 | | #include "ixheaacd_struct_def.h" |
78 | | #include "ixheaacd_error_codes.h" |
79 | | #include "ixheaacd_definitions.h" |
80 | | #include "ixheaacd_adts_crc_check.h" |
81 | | |
82 | | #include "ixheaacd_headerdecode.h" |
83 | | |
84 | | #include "ixheaacd_interface.h" |
85 | | #include "ixheaacd_info.h" |
86 | | #include "ixheaacd_mps_interface.h" |
87 | | #include "ixheaacd_config.h" |
88 | | |
89 | | #include "ixheaacd_struct.h" |
90 | | #include "ixheaacd_function_selector.h" |
91 | | #include "ixheaacd_ld_mps_dec.h" |
92 | | |
93 | | #include "ixheaac_error_standards.h" |
94 | | |
95 | 843 | #define ELDEXT_SAOC 1 |
96 | 38.3k | #define ELDEXT_TERM 0 |
97 | 1.52k | #define ELDEXT_LDSAC 2 |
98 | | |
99 | | extern const WORD32 ixheaacd_sampl_freq_idx_table[17]; |
100 | | |
101 | 209k | #define AAC_LC_PROFILE (2) |
102 | | |
103 | 18.1k | #define ADTS_HEADER_LENGTH 7 |
104 | | |
105 | | static PLATFORM_INLINE VOID |
106 | 71.8k | ixheaacd_aac_bytealign(struct ia_bit_buf_struct *it_bit_buff) { |
107 | 71.8k | WORD16 num_bit; |
108 | 71.8k | num_bit = (it_bit_buff->bit_pos + 1); |
109 | 71.8k | if (num_bit != 8) { |
110 | 0 | it_bit_buff->bit_pos = 7; |
111 | 0 | it_bit_buff->cnt_bits -= num_bit; |
112 | 0 | it_bit_buff->ptr_read_next += 1; |
113 | 0 | } |
114 | 71.8k | } |
115 | | |
116 | | WORD32 ixheaacd_read_pce_channel_info(WORD32 ch, WORD8 *ptr_is_cpe, |
117 | | WORD8 *ptr_tag_select, |
118 | 13.6k | struct ia_bit_buf_struct *it_bit_buff) { |
119 | 13.6k | WORD32 num_ch = 0, i, tmp; |
120 | 40.2k | for (i = 0; i < ch; i++) { |
121 | 26.5k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 5); |
122 | 26.5k | ptr_is_cpe[i] = (tmp & 0x10) >> 4; |
123 | | |
124 | 26.5k | if (ptr_is_cpe[i]) { |
125 | 3.32k | num_ch += 2; |
126 | 23.2k | } else { |
127 | 23.2k | num_ch++; |
128 | 23.2k | } |
129 | | |
130 | 26.5k | ptr_tag_select[i] = (tmp & 0xF); |
131 | 26.5k | } |
132 | 13.6k | return num_ch; |
133 | 13.6k | } |
134 | | |
135 | | VOID ixheaacd_read_pce_mixdown_data(struct ia_bit_buf_struct *it_bit_buff, |
136 | | WORD32 mix_down_present, |
137 | 13.7k | WORD32 mix_down_element_no) { |
138 | 13.7k | WORD32 mix_down_flag = ixheaacd_read_bits_buf(it_bit_buff, mix_down_present); |
139 | 13.7k | if (mix_down_flag == 1) { |
140 | 5.98k | ixheaacd_read_bits_buf(it_bit_buff, mix_down_element_no); |
141 | 5.98k | } |
142 | 13.7k | } |
143 | | |
144 | | VOID ixheaacd_skip_bits(struct ia_bit_buf_struct *it_bit_buff, WORD32 bits, |
145 | 13.2k | WORD32 num_element) { |
146 | 13.2k | WORD32 i; |
147 | 213k | for (i = 0; i < num_element; i++) { |
148 | 199k | ixheaacd_read_bits_buf(it_bit_buff, bits); |
149 | 199k | } |
150 | 13.2k | } |
151 | | |
152 | | WORD32 ixheaacd_read_prog_config_element( |
153 | | ia_program_config_struct *ptr_config_element, |
154 | 23.1k | struct ia_bit_buf_struct *it_bit_buff) { |
155 | 23.1k | WORD32 i, tmp; |
156 | 23.1k | WORD count = 0, num_ch = 0; |
157 | | |
158 | 23.1k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 6); |
159 | | |
160 | 23.1k | ptr_config_element->element_instance_tag = (tmp >> 2); |
161 | 23.1k | ptr_config_element->object_type = tmp & 0x3; |
162 | | |
163 | 23.1k | if ((ptr_config_element->object_type + 1) != 2 |
164 | | |
165 | 7.25k | && (ptr_config_element->object_type + 1) != 4 |
166 | | |
167 | 23.1k | ) { |
168 | 3.39k | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
169 | 3.39k | } |
170 | | |
171 | 19.7k | ptr_config_element->samp_freq_index = ixheaacd_read_bits_buf(it_bit_buff, 4); |
172 | 19.7k | if (ptr_config_element->samp_freq_index > 11) { |
173 | 13.9k | return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; |
174 | 13.9k | } |
175 | | |
176 | 5.89k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 21); |
177 | | |
178 | 5.89k | count += ptr_config_element->num_front_channel_elements = (tmp >> 17); |
179 | 5.89k | count += ptr_config_element->num_side_channel_elements = |
180 | 5.89k | (tmp & 0x1E000) >> 13; |
181 | 5.89k | count += ptr_config_element->num_back_channel_elements = (tmp & 0x1E00) >> 9; |
182 | 5.89k | count += ptr_config_element->num_lfe_channel_elements = (tmp & 0x180) >> 7; |
183 | 5.89k | ptr_config_element->num_assoc_data_elements = (tmp & 0x70) >> 4; |
184 | 5.89k | count += ptr_config_element->num_valid_cc_elements = tmp & 0xF; |
185 | | |
186 | 5.89k | if (count > MAX_BS_ELEMENT) { |
187 | 1.28k | return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX; |
188 | 1.28k | } |
189 | | |
190 | 4.60k | ixheaacd_read_pce_mixdown_data(it_bit_buff, 1, 4); |
191 | 4.60k | ixheaacd_read_pce_mixdown_data(it_bit_buff, 1, 4); |
192 | 4.60k | ixheaacd_read_pce_mixdown_data(it_bit_buff, 1, 3); |
193 | | |
194 | 4.60k | num_ch += ixheaacd_read_pce_channel_info( |
195 | 4.60k | ptr_config_element->num_front_channel_elements, |
196 | 4.60k | ptr_config_element->front_element_is_cpe, |
197 | 4.60k | ptr_config_element->front_element_tag_select, it_bit_buff); |
198 | | |
199 | 4.60k | num_ch += ixheaacd_read_pce_channel_info( |
200 | 4.60k | ptr_config_element->num_side_channel_elements, |
201 | 4.60k | ptr_config_element->side_element_is_cpe, |
202 | 4.60k | ptr_config_element->side_element_tag_select, it_bit_buff); |
203 | | |
204 | 4.60k | num_ch += ixheaacd_read_pce_channel_info( |
205 | 4.60k | ptr_config_element->num_back_channel_elements, |
206 | 4.60k | ptr_config_element->back_element_is_cpe, |
207 | 4.60k | ptr_config_element->back_element_tag_select, it_bit_buff); |
208 | | |
209 | 4.60k | num_ch += ptr_config_element->num_lfe_channel_elements; |
210 | | |
211 | 7.96k | for (i = 0; i < (ptr_config_element->num_lfe_channel_elements); i++) { |
212 | 3.36k | ptr_config_element->lfe_element_tag_select[i] = |
213 | 3.36k | ixheaacd_read_bits_buf(it_bit_buff, 4); |
214 | 3.36k | } |
215 | | |
216 | 4.60k | ptr_config_element->channels = num_ch; |
217 | | |
218 | 15.1k | for (i = 0; i < (ptr_config_element->num_assoc_data_elements); i++) { |
219 | 10.5k | ixheaacd_read_bits_buf(it_bit_buff, 4); |
220 | 10.5k | } |
221 | | |
222 | 4.60k | ixheaacd_skip_bits(it_bit_buff, 5, ptr_config_element->num_valid_cc_elements); |
223 | | |
224 | 4.60k | { |
225 | 4.60k | WORD32 bits_to_read = ptr_config_element->alignment_bits; |
226 | 4.60k | if (bits_to_read <= it_bit_buff->bit_pos) { |
227 | 170 | bits_to_read = it_bit_buff->bit_pos - bits_to_read; |
228 | 4.43k | } else { |
229 | 4.43k | bits_to_read = 8 - (bits_to_read) + it_bit_buff->bit_pos; |
230 | 4.43k | } |
231 | 4.60k | tmp = ixheaacd_read_bits_buf(it_bit_buff, bits_to_read); |
232 | 4.60k | } |
233 | 4.60k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 8); |
234 | | |
235 | 4.60k | ixheaacd_skip_bits(it_bit_buff, 8, tmp); |
236 | | |
237 | 4.60k | return 0; |
238 | 5.89k | } |
239 | | |
240 | | WORD ixheaacd_decode_pce(struct ia_bit_buf_struct *it_bit_buff, |
241 | | UWORD32 *ui_pce_found_in_hdr, |
242 | 633 | ia_program_config_struct *ptr_prog_config) { |
243 | 633 | WORD32 error_code = 0; |
244 | | |
245 | 633 | if (*ui_pce_found_in_hdr == 1 || *ui_pce_found_in_hdr == 3) { |
246 | 140 | ia_program_config_struct ptr_config_element = {0}; |
247 | 140 | ptr_config_element.alignment_bits = ptr_prog_config->alignment_bits; |
248 | 140 | error_code = |
249 | 140 | ixheaacd_read_prog_config_element(&ptr_config_element, it_bit_buff); |
250 | 140 | *ui_pce_found_in_hdr = 3; |
251 | 493 | } else { |
252 | 493 | error_code = |
253 | 493 | ixheaacd_read_prog_config_element(ptr_prog_config, it_bit_buff); |
254 | 493 | *ui_pce_found_in_hdr = 2; |
255 | 493 | } |
256 | 633 | return error_code; |
257 | 633 | } |
258 | | |
259 | | static PLATFORM_INLINE WORD32 ixheaacd_get_adif_header( |
260 | 5.83k | ia_adif_header_struct *adif, struct ia_bit_buf_struct *it_bit_buff) { |
261 | 5.83k | WORD32 i; |
262 | 5.83k | WORD32 ret_val = 0, tmp; |
263 | | |
264 | 5.83k | ixheaacd_read_bits_buf(it_bit_buff, 16); |
265 | 5.83k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 17); |
266 | | |
267 | 5.83k | if (tmp & 0x1) { |
268 | 1.13k | ixheaacd_skip_bits(it_bit_buff, 8, 9); |
269 | 1.13k | } |
270 | | |
271 | 5.83k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 3); |
272 | | |
273 | 5.83k | adif->bit_stream_type = (tmp & 0x1); |
274 | | |
275 | 5.83k | ixheaacd_read_bits_buf(it_bit_buff, 23); |
276 | | |
277 | 5.83k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 4); |
278 | | |
279 | 9.72k | for (i = 0; i <= tmp; i++) { |
280 | 9.68k | if (adif->bit_stream_type == 0) { |
281 | 9.11k | ixheaacd_read_bits_buf(it_bit_buff, 20); |
282 | 9.11k | } |
283 | | |
284 | 9.68k | adif->prog_config_present = 1; |
285 | 9.68k | adif->str_prog_config.alignment_bits = 7; |
286 | 9.68k | ret_val = |
287 | 9.68k | ixheaacd_read_prog_config_element(&adif->str_prog_config, it_bit_buff); |
288 | 9.68k | if (ret_val) { |
289 | 5.79k | return ret_val; |
290 | 5.79k | } |
291 | 9.68k | } |
292 | | |
293 | 38 | return 0; |
294 | 5.83k | } |
295 | | |
296 | | WORD32 ixheaacd_find_syncword(ia_adts_header_struct *adts, |
297 | 191k | struct ia_bit_buf_struct *it_bit_buff) { |
298 | 191k | adts->sync_word = (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 12); |
299 | 191k | if (adts->sync_word == 0xFFF) { |
300 | 190k | return 0; |
301 | 190k | } |
302 | | |
303 | 774k | while (1) { |
304 | 773k | ixheaacd_read_bidirection(it_bit_buff, -4); |
305 | 773k | if (it_bit_buff->cnt_bits < 12) { |
306 | 392 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
307 | 392 | } |
308 | 773k | adts->sync_word = (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 12); |
309 | 773k | if (adts->sync_word == 0xFFF) { |
310 | 467 | ixheaacd_read_bidirection(it_bit_buff, -12); |
311 | 467 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
312 | 467 | } |
313 | 773k | } |
314 | 1.00k | } |
315 | | |
316 | | WORD32 ixheaacd_adtsframe(ia_adts_header_struct *adts, |
317 | 143k | struct ia_bit_buf_struct *it_bit_buff) { |
318 | 143k | WORD32 tmp; |
319 | 143k | IA_ERRORCODE err = IA_NO_ERROR; |
320 | 143k | WORD32 crc_reg; |
321 | 143k | ia_adts_crc_info_struct *ptr_adts_crc_info = it_bit_buff->pstr_adts_crc_info; |
322 | 143k | ptr_adts_crc_info->crc_active = 1; |
323 | 143k | ptr_adts_crc_info->no_reg = 0; |
324 | 143k | ixheaacd_read_bidirection(it_bit_buff, -12); |
325 | 143k | crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff, |
326 | 143k | CRC_ADTS_HEADER_LEN); |
327 | 143k | err = ixheaacd_find_syncword(adts, it_bit_buff); |
328 | 143k | if (err) return err; |
329 | | |
330 | 143k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 10); |
331 | | |
332 | 143k | adts->id = (tmp & 0x200) >> 9; |
333 | 143k | adts->layer = (tmp & 0x180) >> 7; |
334 | 143k | adts->protection_absent = (tmp & 0x40) >> 6; |
335 | 143k | adts->profile = (tmp & 0x30) >> 4; |
336 | 143k | { adts->profile++; } |
337 | 143k | adts->samp_freq_index = (tmp & 0xF); |
338 | | |
339 | 143k | if (((adts->profile != AAC_LC_PROFILE)) || (adts->samp_freq_index > 11)) |
340 | | |
341 | 71.7k | { |
342 | 71.7k | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
343 | 71.7k | } |
344 | | |
345 | 71.8k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 21); |
346 | | |
347 | 71.8k | adts->channel_configuration = (WORD32)(tmp & 0xE0000) >> 17; |
348 | | |
349 | 71.8k | adts->aac_frame_length = (tmp & 0x1FFF); |
350 | | |
351 | 71.8k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 13); |
352 | | |
353 | 71.8k | adts->no_raw_data_blocks = (tmp & 0x3); |
354 | | |
355 | 71.8k | ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg); |
356 | | |
357 | 71.8k | if (adts->protection_absent == 0) { |
358 | 3.02k | ixheaacd_skip_bits(it_bit_buff, 16, adts->no_raw_data_blocks); |
359 | 3.02k | adts->crc_check = ixheaacd_read_bits_buf(it_bit_buff, 16); |
360 | | |
361 | 3.02k | ptr_adts_crc_info->crc_active = 1; |
362 | 3.02k | ptr_adts_crc_info->file_value = adts->crc_check; |
363 | 3.02k | } else |
364 | 68.8k | ptr_adts_crc_info->crc_active = 0; |
365 | | |
366 | 71.8k | ixheaacd_aac_bytealign(it_bit_buff); |
367 | 71.8k | return 0; |
368 | 143k | } |
369 | | |
370 | | WORD32 ixheaacd_get_samp_rate( |
371 | | struct ia_bit_buf_struct *it_bit_buff, |
372 | | ia_sampling_rate_info_struct *pstr_samp_rate_info, |
373 | 180k | ia_audio_specific_config_struct *pstr_audio_specific_config) { |
374 | 180k | WORD32 index; |
375 | 180k | WORD32 sampling_rate; |
376 | 180k | index = ixheaacd_read_bits_buf(it_bit_buff, 4); |
377 | 180k | pstr_audio_specific_config->samp_frequency_index = index; |
378 | | |
379 | 180k | if (index == 0x0F) { |
380 | 625 | sampling_rate = ixheaacd_read_bits_buf(it_bit_buff, 24); |
381 | | |
382 | 625 | if (pstr_audio_specific_config->audio_object_type != AOT_USAC) { |
383 | 508 | if (sampling_rate < 9391) |
384 | 7 | sampling_rate = 8000; |
385 | 501 | else if ((sampling_rate >= 9391) && (sampling_rate < 11502)) |
386 | 12 | sampling_rate = 11025; |
387 | 489 | else if ((sampling_rate >= 11502) && (sampling_rate < 13856)) |
388 | 12 | sampling_rate = 12000; |
389 | 477 | else if ((sampling_rate >= 13856) && (sampling_rate < 18783)) |
390 | 6 | sampling_rate = 16000; |
391 | 471 | else if ((sampling_rate >= 18783) && (sampling_rate < 23004)) |
392 | 12 | sampling_rate = 22050; |
393 | 459 | else if ((sampling_rate >= 23004) && (sampling_rate < 27713)) |
394 | 16 | sampling_rate = 24000; |
395 | 443 | else if ((sampling_rate >= 27713) && (sampling_rate < 37566)) |
396 | 13 | sampling_rate = 32000; |
397 | 430 | else if ((sampling_rate >= 37566) && (sampling_rate < 46009)) |
398 | 13 | sampling_rate = 44100; |
399 | 417 | else if ((sampling_rate >= 46009) && (sampling_rate < 55426)) |
400 | 15 | sampling_rate = 48000; |
401 | 402 | else if ((sampling_rate >= 55426) && (sampling_rate < 75132)) |
402 | 9 | sampling_rate = 64000; |
403 | 393 | else if ((sampling_rate >= 75132) && (sampling_rate < 92017)) |
404 | 12 | sampling_rate = 88200; |
405 | 381 | else if (sampling_rate >= 92017) |
406 | 381 | sampling_rate = 96000; |
407 | 508 | } |
408 | 625 | return sampling_rate; |
409 | 180k | } else if ((index > 12) && (index < 15)) { |
410 | 7 | return -1; |
411 | 180k | } else { |
412 | 180k | return ((pstr_samp_rate_info[index].sampling_frequency)); |
413 | 180k | } |
414 | 180k | } |
415 | | static int ixheaacd_get_ld_sbr_header( |
416 | | ia_bit_buf_struct *it_bit_buff, |
417 | 34.3k | ia_sbr_header_data_struct *sbr_header_data) { |
418 | 34.3k | WORD32 header_extra_1, header_extra_2; |
419 | 34.3k | UWORD32 tmp, bit_cnt = 0; |
420 | | |
421 | 34.3k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 16); |
422 | 34.3k | bit_cnt += 16; |
423 | | |
424 | 34.3k | sbr_header_data->amp_res = (tmp & 0x8000) >> 15; |
425 | 34.3k | sbr_header_data->start_freq = (tmp & 0x7800) >> 11; |
426 | 34.3k | sbr_header_data->stop_freq = (tmp & 0x780) >> 7; |
427 | 34.3k | sbr_header_data->xover_band = (tmp & 0x70) >> 4; |
428 | 34.3k | header_extra_1 = (tmp & 0x0002) >> 1; |
429 | 34.3k | header_extra_2 = (tmp & 0x0001); |
430 | | |
431 | 34.3k | if (header_extra_1) { |
432 | 3.28k | sbr_header_data->freq_scale = ixheaacd_read_bits_buf(it_bit_buff, 2); |
433 | 3.28k | sbr_header_data->alter_scale = ixheaacd_read_bits_buf(it_bit_buff, 1); |
434 | 3.28k | sbr_header_data->noise_bands = ixheaacd_read_bits_buf(it_bit_buff, 2); |
435 | 31.0k | } else { |
436 | 31.0k | sbr_header_data->freq_scale = 2; |
437 | 31.0k | sbr_header_data->alter_scale = 1; |
438 | 31.0k | sbr_header_data->noise_bands = 2; |
439 | 31.0k | } |
440 | | |
441 | 34.3k | if (header_extra_2) { |
442 | 1.90k | sbr_header_data->limiter_bands = ixheaacd_read_bits_buf(it_bit_buff, 2); |
443 | 1.90k | sbr_header_data->limiter_gains = ixheaacd_read_bits_buf(it_bit_buff, 2); |
444 | 1.90k | sbr_header_data->interpol_freq = ixheaacd_read_bits_buf(it_bit_buff, 1); |
445 | 1.90k | sbr_header_data->smoothing_mode = ixheaacd_read_bits_buf(it_bit_buff, 1); |
446 | 32.4k | } else { |
447 | 32.4k | sbr_header_data->limiter_bands = 2; |
448 | 32.4k | sbr_header_data->limiter_gains = 2; |
449 | 32.4k | sbr_header_data->interpol_freq = 1; |
450 | 32.4k | sbr_header_data->smoothing_mode = 1; |
451 | 32.4k | } |
452 | | |
453 | 34.3k | return (bit_cnt); |
454 | 34.3k | } |
455 | | |
456 | | WORD32 ixheaacd_eld_sbr_header(ia_bit_buf_struct *it_bit_buff, WORD32 channels, |
457 | 22.1k | ia_sbr_header_data_struct *pstr_sbr_config) { |
458 | 22.1k | int num_sbr_header, el, bit_cnt = 0; |
459 | 22.1k | switch (channels) { |
460 | 1.14k | default: |
461 | 1.14k | num_sbr_header = 0; |
462 | 1.14k | break; |
463 | 211 | case 1: |
464 | 9.74k | case 2: |
465 | 9.74k | num_sbr_header = 1; |
466 | 9.74k | break; |
467 | 10.1k | case 3: |
468 | 10.1k | num_sbr_header = 2; |
469 | 10.1k | break; |
470 | 7 | case 4: |
471 | 19 | case 5: |
472 | 25 | case 6: |
473 | 25 | num_sbr_header = 3; |
474 | 25 | break; |
475 | 1.07k | case 7: |
476 | 1.07k | num_sbr_header = 4; |
477 | 1.07k | break; |
478 | 22.1k | } |
479 | 56.4k | for (el = 0; el < num_sbr_header; el++) { |
480 | 34.3k | bit_cnt = ixheaacd_get_ld_sbr_header(it_bit_buff, pstr_sbr_config); |
481 | 34.3k | } |
482 | 22.1k | return (bit_cnt); |
483 | 22.1k | } |
484 | | |
485 | | WORD32 ixheaacd_ga_hdr_dec(ia_aac_dec_state_struct *aac_state_struct, |
486 | | WORD32 header_len, WORD32 *bytes_consumed, |
487 | | ia_sampling_rate_info_struct *pstr_samp_rate_info, |
488 | 180k | struct ia_bit_buf_struct *it_bit_buff) { |
489 | 180k | WORD32 tmp; |
490 | 180k | WORD32 cnt_bits = it_bit_buff->cnt_bits; |
491 | 180k | UWORD32 aot_init; |
492 | 180k | UWORD32 tmp_aot; |
493 | | |
494 | 180k | ia_audio_specific_config_struct *pstr_audio_specific_config; |
495 | | |
496 | 180k | memset(aac_state_struct->ia_audio_specific_config, 0, |
497 | 180k | sizeof(ia_audio_specific_config_struct)); |
498 | | |
499 | 180k | memset(&(aac_state_struct->eld_specific_config), 0, |
500 | 180k | sizeof(ia_eld_specific_config_struct)); |
501 | | |
502 | 180k | pstr_audio_specific_config = aac_state_struct->ia_audio_specific_config; |
503 | | |
504 | 180k | aac_state_struct->p_config->str_prog_config.alignment_bits = |
505 | 180k | it_bit_buff->bit_pos; |
506 | | |
507 | 180k | aot_init = aac_state_struct->audio_object_type; |
508 | 180k | aac_state_struct->frame_length = FRAME_SIZE; |
509 | | |
510 | 180k | tmp_aot = ixheaacd_read_bits_buf(it_bit_buff, 5); |
511 | | |
512 | 180k | if (tmp_aot == 31) { |
513 | 52.9k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 6); |
514 | 52.9k | tmp_aot = 32 + tmp; |
515 | 52.9k | } |
516 | | |
517 | 180k | if (aac_state_struct->header_dec_done || aac_state_struct->ui_init_done) { |
518 | 165k | if (tmp_aot != aot_init && tmp_aot != AOT_SBR && tmp_aot != AOT_PS) |
519 | 244 | return IA_FATAL_ERROR; |
520 | 165k | } |
521 | | |
522 | 180k | pstr_audio_specific_config->audio_object_type = |
523 | 180k | aac_state_struct->audio_object_type = tmp_aot; |
524 | | |
525 | 180k | tmp = ixheaacd_get_samp_rate(it_bit_buff, pstr_samp_rate_info, |
526 | 180k | pstr_audio_specific_config); |
527 | 180k | pstr_audio_specific_config->sampling_frequency = tmp; |
528 | | |
529 | 180k | if (tmp == -1) { |
530 | 5 | *bytes_consumed = 1; |
531 | 5 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
532 | 5 | } else |
533 | 180k | aac_state_struct->sampling_rate = tmp; |
534 | 180k | aac_state_struct->p_config->ui_samp_freq = tmp; |
535 | | |
536 | 180k | aac_state_struct->ch_config = ixheaacd_read_bits_buf(it_bit_buff, 4); |
537 | | |
538 | 180k | if (aac_state_struct->audio_object_type == AOT_USAC && |
539 | 28.3k | ((aac_state_struct->ch_config >= 3) && (aac_state_struct->ch_config != 8))) { |
540 | 8 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
541 | 8 | } |
542 | | |
543 | 180k | pstr_audio_specific_config->channel_configuration = |
544 | 180k | aac_state_struct->ch_config; |
545 | | |
546 | 180k | if (aac_state_struct->audio_object_type == AOT_SBR || |
547 | 180k | aac_state_struct->audio_object_type == AOT_PS) { |
548 | 141 | tmp = ixheaacd_get_samp_rate(it_bit_buff, pstr_samp_rate_info, |
549 | 141 | pstr_audio_specific_config); |
550 | 141 | aac_state_struct->sbr_present_flag = 1; |
551 | 141 | if (tmp == -1) { |
552 | 1 | *bytes_consumed = 1; |
553 | 1 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
554 | 1 | } else |
555 | 140 | aac_state_struct->extension_samp_rate = tmp; |
556 | | |
557 | 140 | aac_state_struct->audio_object_type = |
558 | 140 | ixheaacd_read_bits_buf(it_bit_buff, 5); |
559 | 140 | } |
560 | | |
561 | 180k | if (aac_state_struct->header_dec_done || aac_state_struct->ui_init_done) { |
562 | 165k | if (aac_state_struct->audio_object_type != aot_init) return IA_FATAL_ERROR; |
563 | 165k | } |
564 | | |
565 | 180k | if (((aac_state_struct->audio_object_type >= AOT_AAC_MAIN && |
566 | 180k | aac_state_struct->audio_object_type <= AOT_AAC_LTP) || |
567 | 170k | aac_state_struct->audio_object_type == AOT_AAC_SCAL || |
568 | 169k | aac_state_struct->audio_object_type == AOT_TWIN_VQ || |
569 | 169k | aac_state_struct->audio_object_type == AOT_ER_AAC_LD || |
570 | 96.5k | aac_state_struct->audio_object_type == AOT_ER_AAC_ELD || |
571 | 71.9k | aac_state_struct->audio_object_type == AOT_ER_AAC_SCAL || |
572 | 71.9k | aac_state_struct->audio_object_type == AOT_ER_AAC_LC) && |
573 | 152k | aac_state_struct->audio_object_type != AOT_USAC) |
574 | | |
575 | 152k | { |
576 | 152k | aac_state_struct->usac_flag = 0; |
577 | | |
578 | 152k | aac_state_struct->frame_len_flag = ixheaacd_read_bits_buf(it_bit_buff, 1); |
579 | 152k | if (aac_state_struct->audio_object_type != AOT_ER_AAC_ELD) { |
580 | 127k | aac_state_struct->depends_on_core_coder = |
581 | 127k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
582 | 127k | aac_state_struct->extension_flag = ixheaacd_read_bits_buf(it_bit_buff, 1); |
583 | | |
584 | 127k | if (aac_state_struct->ch_config == 0) { |
585 | 12.8k | WORD32 error_code; |
586 | 12.8k | error_code = ixheaacd_read_prog_config_element( |
587 | 12.8k | &aac_state_struct->p_config->str_prog_config, it_bit_buff); |
588 | 12.8k | if (error_code != 0) { |
589 | 12.5k | *bytes_consumed = 1; |
590 | 12.5k | return error_code; |
591 | 12.5k | } |
592 | 376 | aac_state_struct->p_config->ui_pce_found_in_hdr = 1; |
593 | 376 | } |
594 | 127k | } |
595 | 139k | if (aac_state_struct->audio_object_type == AOT_ER_AAC_ELD || |
596 | 114k | aac_state_struct->audio_object_type == AOT_ER_AAC_LD || |
597 | 53.8k | aac_state_struct->audio_object_type == AOT_ER_AAC_LC || |
598 | 129k | aac_state_struct->audio_object_type == AOT_ER_AAC_SCAL) { |
599 | 129k | aac_state_struct->eld_specific_config.aac_sect_data_resil_flag = 0; |
600 | 129k | aac_state_struct->eld_specific_config.aac_sf_data_resil_flag = 0; |
601 | 129k | aac_state_struct->eld_specific_config.aac_spect_data_resil_flag = 0; |
602 | 129k | aac_state_struct->eld_specific_config.ep_config = 0; |
603 | 129k | if ((aac_state_struct->extension_flag == 1) || |
604 | 126k | aac_state_struct->audio_object_type == AOT_ER_AAC_ELD) { |
605 | 126k | if (aac_state_struct->audio_object_type >= ER_OBJECT_START) { |
606 | 126k | aac_state_struct->eld_specific_config.aac_sect_data_resil_flag = |
607 | 126k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
608 | 126k | aac_state_struct->eld_specific_config.aac_sf_data_resil_flag = |
609 | 126k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
610 | 126k | aac_state_struct->eld_specific_config.aac_spect_data_resil_flag = |
611 | 126k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
612 | 126k | if (aac_state_struct->audio_object_type == AOT_ER_AAC_LD) |
613 | 61.0k | aac_state_struct->eld_specific_config.ep_config = |
614 | 61.0k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
615 | 126k | if (aac_state_struct->audio_object_type == AOT_ER_AAC_ELD) |
616 | 24.5k | aac_state_struct->eld_specific_config.ld_sbr_flag_present = |
617 | 24.5k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
618 | 126k | } |
619 | 126k | } |
620 | 129k | } |
621 | 139k | } |
622 | 168k | if (pstr_audio_specific_config->audio_object_type == AOT_USAC) { |
623 | 28.2k | { |
624 | 28.2k | pstr_audio_specific_config->sbr_present_flag = 0; |
625 | 28.2k | pstr_audio_specific_config->ext_audio_object_type = 0; |
626 | 28.2k | } |
627 | | |
628 | 28.2k | { |
629 | 28.2k | { |
630 | 28.2k | SIZE_T tmp = 0xf; |
631 | 28.2k | UWORD32 i; |
632 | 28.2k | WORD32 err = 0; |
633 | | |
634 | 28.2k | aac_state_struct->usac_flag = 1; |
635 | | |
636 | 28.2k | ixheaacd_conf_default(&(pstr_audio_specific_config->str_usac_config)); |
637 | 28.2k | err = ixheaacd_config(it_bit_buff, &(pstr_audio_specific_config->str_usac_config), |
638 | 28.2k | &(pstr_audio_specific_config->channel_configuration), |
639 | 28.2k | aac_state_struct->ec_enable); |
640 | 28.2k | if (err != 0) return err; |
641 | | |
642 | 28.1k | pstr_audio_specific_config->sampling_frequency = |
643 | 28.1k | pstr_audio_specific_config->str_usac_config.usac_sampling_frequency; |
644 | | |
645 | 28.1k | if (pstr_audio_specific_config->audio_object_type == AOT_USAC) { |
646 | 28.0k | pstr_audio_specific_config->sbr_present_flag = 1; |
647 | 28.0k | pstr_audio_specific_config->ext_audio_object_type = AOT_SBR; |
648 | 28.0k | pstr_audio_specific_config->ext_sampling_frequency = |
649 | 28.0k | pstr_audio_specific_config->sampling_frequency; |
650 | 28.0k | pstr_audio_specific_config->ext_samp_frequency_index = |
651 | 28.0k | pstr_audio_specific_config->samp_frequency_index; |
652 | | |
653 | 321k | for (i = 0; i < sizeof(ixheaacd_sampl_freq_idx_table) / |
654 | 321k | sizeof(ixheaacd_sampl_freq_idx_table[0]); |
655 | 317k | i++) { |
656 | 317k | if (ixheaacd_sampl_freq_idx_table[i] == |
657 | 317k | (int)(pstr_audio_specific_config->sampling_frequency)) { |
658 | 24.4k | tmp = i; |
659 | 24.4k | break; |
660 | 24.4k | } |
661 | 317k | } |
662 | 28.0k | pstr_audio_specific_config->samp_frequency_index = (UINT32)tmp; |
663 | 28.0k | } else { |
664 | 125 | pstr_audio_specific_config->sbr_present_flag = 0; |
665 | 125 | } |
666 | 28.1k | } |
667 | 28.1k | } |
668 | | |
669 | 28.1k | if (aac_state_struct->bs_format != LOAS_BSFORMAT) { |
670 | 1.36k | ixheaacd_skip_bits_buf(it_bit_buff, it_bit_buff->cnt_bits); |
671 | | |
672 | 1.36k | if ((SIZE_T)it_bit_buff->ptr_read_next == |
673 | 1.36k | (SIZE_T)it_bit_buff->ptr_bit_buf_base) { |
674 | 0 | *bytes_consumed = ((WORD32)it_bit_buff->size) >> 3; |
675 | 1.36k | } else { |
676 | 1.36k | *bytes_consumed = (WORD32)((((((SIZE_T)it_bit_buff->ptr_read_next - |
677 | 1.36k | (SIZE_T)it_bit_buff->ptr_bit_buf_base)) |
678 | 1.36k | << 3) + |
679 | 1.36k | 7 - it_bit_buff->bit_pos + 7) >> |
680 | 1.36k | 3); |
681 | 1.36k | } |
682 | 1.36k | } |
683 | 28.1k | return 0; |
684 | 28.2k | } |
685 | | |
686 | 139k | aac_state_struct->frame_length = FRAME_SIZE; |
687 | 139k | if (aac_state_struct->frame_len_flag) |
688 | 68.6k | aac_state_struct->frame_length = FRAME_SIZE_SMALL; |
689 | | |
690 | 139k | if (aac_state_struct->extension_flag) |
691 | 102k | aac_state_struct->extension_flag_3 = ixheaacd_read_bits_buf(it_bit_buff, 1); |
692 | | |
693 | 139k | if (aac_state_struct->audio_object_type == AOT_ER_AAC_LD) |
694 | 61.0k | aac_state_struct->frame_length >>= 1; |
695 | | |
696 | 139k | if (aac_state_struct->audio_object_type == AOT_ER_AAC_ELD) { |
697 | 24.5k | aac_state_struct->frame_length >>= 1; |
698 | 24.5k | if (aac_state_struct->eld_specific_config.ld_sbr_flag_present) { |
699 | 22.1k | aac_state_struct->eld_specific_config.ld_sbr_samp_rate = |
700 | 22.1k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
701 | 22.1k | aac_state_struct->eld_specific_config.ld_sbr_crc_flag = |
702 | 22.1k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
703 | | |
704 | 22.1k | ixheaacd_eld_sbr_header(it_bit_buff, aac_state_struct->ch_config, |
705 | 22.1k | &aac_state_struct->str_sbr_config); |
706 | | |
707 | 22.1k | aac_state_struct->dwnsmp_signal = |
708 | 22.1k | !aac_state_struct->eld_specific_config.ld_sbr_samp_rate; |
709 | 22.1k | } |
710 | | |
711 | 24.5k | { |
712 | 24.5k | UWORD16 len, eld_ext_type; |
713 | 24.5k | WORD32 err; |
714 | 24.5k | UWORD16 cnt; |
715 | | |
716 | 24.5k | if (ixheaacd_show_bits_buf(it_bit_buff, 4) != ELDEXT_TERM) { |
717 | 13.8k | while ((eld_ext_type = ixheaacd_read_bits_buf(it_bit_buff, 4)) != |
718 | 13.8k | ELDEXT_TERM) { |
719 | 13.8k | len = ixheaacd_read_bits_buf(it_bit_buff, 4); |
720 | 13.8k | if (len == 15) { |
721 | 52 | len += ixheaacd_read_bits_buf(it_bit_buff, 8); |
722 | 52 | } |
723 | 13.8k | if (len == 15 + 255) { |
724 | 15 | len += ixheaacd_read_bits_buf(it_bit_buff, 16); |
725 | 15 | } |
726 | | |
727 | 13.8k | switch (eld_ext_type) { |
728 | 843 | case ELDEXT_SAOC: |
729 | 843 | break; |
730 | 1.52k | case ELDEXT_LDSAC: |
731 | 1.52k | aac_state_struct->ldmps_present = 1; |
732 | 1.52k | aac_state_struct->mps_dec_handle.ldmps_config.ldmps_present_flag = |
733 | 1.52k | 1; |
734 | 1.52k | aac_state_struct->mps_dec_handle.object_type = |
735 | 1.52k | aac_state_struct->audio_object_type; |
736 | 1.52k | aac_state_struct->mps_dec_handle.ec_flag = aac_state_struct->ec_enable; |
737 | 1.52k | err = ixheaacd_ld_spatial_specific_config( |
738 | 1.52k | &(aac_state_struct->mps_dec_handle.ldmps_config), it_bit_buff); |
739 | 1.52k | if (err) return err; |
740 | | |
741 | 1.51k | if (ixheaacd_mps_create( |
742 | 1.51k | &aac_state_struct->mps_dec_handle, |
743 | 1.51k | aac_state_struct->mps_dec_handle.ldmps_config |
744 | 1.51k | .bs_frame_length, |
745 | 1.51k | 0, &(aac_state_struct->mps_dec_handle.ldmps_config))) { |
746 | 27 | return -1; |
747 | 27 | } |
748 | 1.48k | break; |
749 | 11.4k | default: |
750 | 17.1k | for (cnt = 0; cnt < len; cnt++) { |
751 | 5.70k | ixheaacd_read_bits_buf(it_bit_buff, 8); |
752 | 5.70k | } |
753 | | |
754 | 11.4k | break; |
755 | 13.8k | } |
756 | 13.4k | break; |
757 | 13.8k | } |
758 | 13.8k | } |
759 | 24.5k | } |
760 | 24.1k | if (!((aac_state_struct->ldmps_present == 1) && |
761 | 8.98k | !(it_bit_buff->cnt_bits >= 1))) |
762 | 24.0k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
763 | 24.1k | } |
764 | 139k | if (!((aac_state_struct->ldmps_present == 1) && !(it_bit_buff->cnt_bits > 0))) { |
765 | 139k | if (aac_state_struct->audio_object_type == AOT_ER_AAC_ELD || |
766 | 115k | aac_state_struct->audio_object_type == AOT_ER_AAC_LC || |
767 | 71.7k | aac_state_struct->audio_object_type == AOT_ER_AAC_SCAL) { |
768 | 67.4k | WORD32 ep_config = ixheaacd_read_bits_buf(it_bit_buff, 2); |
769 | 67.4k | if (ep_config == 2 || ep_config == 3) { |
770 | 538 | } |
771 | 67.4k | if (ep_config == 3) { |
772 | 379 | WORD32 direct_map = ixheaacd_read_bits_buf(it_bit_buff, 1); |
773 | 379 | if (!direct_map) { |
774 | 179 | } |
775 | 379 | } |
776 | 67.4k | } |
777 | | |
778 | 139k | tmp = (header_len * 8) - it_bit_buff->cnt_bits; |
779 | | |
780 | 139k | if (aac_state_struct->audio_object_type != AOT_SBR && |
781 | 139k | (it_bit_buff->cnt_bits >= 16)) { |
782 | 139k | tmp = ixheaacd_read_bits_buf(it_bit_buff, 11); |
783 | | |
784 | 139k | if (tmp == 0x2b7) { |
785 | 52 | tmp = ixheaacd_read_bits_buf(it_bit_buff, 5); |
786 | | |
787 | 52 | if (tmp == AOT_SBR) { |
788 | 42 | WORD32 sbr_present_flag = ixheaacd_read_bits_buf(it_bit_buff, 1); |
789 | 42 | if (sbr_present_flag) { |
790 | 39 | tmp = ixheaacd_get_samp_rate(it_bit_buff, pstr_samp_rate_info, |
791 | 39 | pstr_audio_specific_config); |
792 | 39 | if (tmp == -1) { |
793 | 1 | *bytes_consumed = 1; |
794 | 1 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
795 | 1 | } else |
796 | 38 | aac_state_struct->extension_samp_rate = tmp; |
797 | | |
798 | 38 | if (it_bit_buff->cnt_bits >= 12) { |
799 | 14 | tmp = ixheaacd_read_bits_buf(it_bit_buff, 11); |
800 | 14 | if (tmp == 0x548) { |
801 | 0 | tmp = ixheaacd_read_bits_buf(it_bit_buff, 1); |
802 | 0 | } |
803 | 14 | } |
804 | 38 | } |
805 | 42 | } |
806 | 138k | } else if (aac_state_struct->bs_format == LOAS_BSFORMAT) { |
807 | 138k | ixheaacd_read_bidirection(it_bit_buff, -11); |
808 | 138k | } |
809 | 139k | } |
810 | 139k | } |
811 | | |
812 | 139k | if (aac_state_struct->audio_object_type != AOT_AAC_LC && |
813 | 139k | aac_state_struct->audio_object_type != AOT_SBR && |
814 | 139k | aac_state_struct->audio_object_type != AOT_PS && |
815 | 139k | aac_state_struct->audio_object_type != AOT_ER_AAC_LC && |
816 | 95.7k | aac_state_struct->audio_object_type != AOT_ER_AAC_LD && |
817 | 34.6k | aac_state_struct->audio_object_type != AOT_ER_AAC_ELD && |
818 | 10.5k | aac_state_struct->audio_object_type != AOT_AAC_LTP) { |
819 | 187 | *bytes_consumed = 1; |
820 | 187 | return IA_XHEAAC_DEC_INIT_FATAL_AUDIOOBJECTTYPE_NOT_SUPPORTED; |
821 | 139k | } else { |
822 | 139k | if (aac_state_struct->bs_format == LOAS_BSFORMAT) { |
823 | 138k | *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) >> 3; |
824 | 138k | if (it_bit_buff->bit_pos < 7) *bytes_consumed += 1; |
825 | | |
826 | 138k | } else |
827 | 354 | *bytes_consumed = header_len; |
828 | | |
829 | 139k | return 0; |
830 | 139k | } |
831 | 139k | } |
832 | | |
833 | | WORD32 ixheaacd_check_if_adts(ia_adts_header_struct *adts, |
834 | | struct ia_bit_buf_struct *it_bit_buff, |
835 | 143k | WORD32 usr_max_ch) { |
836 | 143k | WORD32 max_frm_len_per_ch, result = 0; |
837 | | |
838 | 143k | result = ixheaacd_adtsframe(adts, it_bit_buff); |
839 | | |
840 | 143k | max_frm_len_per_ch = ixheaac_mult32(768, (adts->no_raw_data_blocks + 1)); |
841 | | |
842 | 143k | if (adts->channel_configuration != 0) |
843 | 93.0k | max_frm_len_per_ch = |
844 | 93.0k | ixheaac_mult32(max_frm_len_per_ch, adts->channel_configuration); |
845 | 50.5k | else |
846 | 50.5k | max_frm_len_per_ch = max_frm_len_per_ch * usr_max_ch; |
847 | | |
848 | 143k | return ((result != 0) || (adts->aac_frame_length < 8) || (adts->layer != 0) || |
849 | 65.6k | (adts->profile != AAC_LC_PROFILE)); |
850 | 143k | } |
851 | | |
852 | | IA_ERRORCODE ixheaacd_latm_header_decode( |
853 | | ia_aac_dec_state_struct *aac_state_struct, |
854 | | struct ia_bit_buf_struct *it_bit_buff, WORD32 *bytes_consumed, |
855 | 12.6k | ia_sampling_rate_info_struct *pstr_samp_rate_info) { |
856 | 12.6k | WORD32 sync; |
857 | 12.6k | IA_ERRORCODE result; |
858 | 12.6k | WORD32 next_sync, audio_mux_len_bytes_last; |
859 | 12.6k | WORD32 audio_mux_len_bits_last; |
860 | 12.6k | WORD32 sync_status = aac_state_struct->sync_status; |
861 | 12.6k | WORD32 bit_count = aac_state_struct->bit_count; |
862 | 12.6k | WORD32 cnt_bits = it_bit_buff->cnt_bits; |
863 | | |
864 | 12.6k | *bytes_consumed = 0; |
865 | | |
866 | 12.6k | aac_state_struct->bs_format = LOAS_BSFORMAT; |
867 | | |
868 | 12.6k | if (sync_status == 0) { |
869 | 35.5k | do { |
870 | 35.5k | sync = ixheaacd_read_bits_buf(it_bit_buff, 11); |
871 | 35.5k | bit_count += 11; |
872 | 12.8M | while (sync != 0x2B7) { |
873 | 12.8M | sync = ((sync & 0x3ff) << 1) | ixheaacd_read_bits_buf(it_bit_buff, 1); |
874 | 12.8M | bit_count += 1; |
875 | 12.8M | if (it_bit_buff->cnt_bits < 13) { |
876 | 14 | ixheaacd_read_bidirection(it_bit_buff, -11); |
877 | 14 | *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8; |
878 | 14 | return (IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START); |
879 | 14 | } |
880 | 12.8M | } |
881 | | |
882 | 35.4k | audio_mux_len_bytes_last = ixheaacd_read_bits_buf(it_bit_buff, 13); |
883 | 35.4k | bit_count += 13; |
884 | 35.4k | audio_mux_len_bits_last = audio_mux_len_bytes_last << 3; |
885 | 35.4k | if (it_bit_buff->cnt_bits >= (audio_mux_len_bits_last + 11)) { |
886 | 35.3k | ixheaacd_read_bidirection(it_bit_buff, audio_mux_len_bits_last); |
887 | 35.3k | bit_count += audio_mux_len_bits_last; |
888 | | |
889 | 35.3k | next_sync = ixheaacd_read_bits_buf(it_bit_buff, 11); |
890 | 35.3k | bit_count += 11; |
891 | | |
892 | 35.3k | if (next_sync == 0x2B7) { |
893 | 12.4k | ixheaacd_read_bidirection(it_bit_buff, |
894 | 12.4k | -(11 + audio_mux_len_bits_last + 13 + 11)); |
895 | 12.4k | bit_count -= 11 + audio_mux_len_bits_last + 13 + 11; |
896 | 12.4k | break; |
897 | 22.8k | } else { |
898 | 22.8k | ixheaacd_read_bidirection(it_bit_buff, |
899 | 22.8k | -(audio_mux_len_bits_last + 24 + 11 - 1)); |
900 | 22.8k | bit_count -= audio_mux_len_bits_last + 24 + 11 - 1; |
901 | 22.8k | } |
902 | | |
903 | 35.3k | } else { |
904 | 129 | if (it_bit_buff->cnt_bits != audio_mux_len_bits_last) { |
905 | 36 | ixheaacd_read_bidirection(it_bit_buff, -(13 + 11)); |
906 | 36 | bit_count -= (13 + 11); |
907 | 36 | *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8; |
908 | 36 | return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES; |
909 | 93 | } else { |
910 | 93 | ixheaacd_read_bidirection(it_bit_buff, -(13 + 11)); |
911 | 93 | bit_count -= (13 + 11); |
912 | 93 | break; |
913 | 93 | } |
914 | 129 | } |
915 | 35.4k | } while (1); |
916 | | |
917 | 12.5k | do { |
918 | 12.5k | WORD32 audio_mux_len_bytes_last; |
919 | 12.5k | WORD32 use_same_stream_mux; |
920 | | |
921 | 12.5k | sync = ixheaacd_read_bits_buf(it_bit_buff, 11); |
922 | 12.5k | bit_count += 11; |
923 | | |
924 | 12.5k | if (sync != 0x2b7) { |
925 | 0 | ixheaacd_read_bidirection(it_bit_buff, -25); |
926 | 0 | bit_count -= 11; |
927 | 0 | *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8; |
928 | 0 | return IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START; |
929 | 0 | } |
930 | | |
931 | 12.5k | audio_mux_len_bytes_last = ixheaacd_read_bits_buf(it_bit_buff, 13); |
932 | 12.5k | bit_count += 13; |
933 | | |
934 | 12.5k | use_same_stream_mux = ixheaacd_read_bits_buf(it_bit_buff, 1); |
935 | 12.5k | bit_count += 1; |
936 | | |
937 | 12.5k | if (!use_same_stream_mux) { |
938 | 12.5k | ixheaacd_read_bidirection(it_bit_buff, -25); |
939 | 12.5k | bit_count -= 25; |
940 | 12.5k | sync_status = 1; |
941 | 12.5k | aac_state_struct->sync_status = sync_status; |
942 | 12.5k | break; |
943 | 12.5k | } else { |
944 | 5 | ixheaacd_read_bidirection(it_bit_buff, -25); |
945 | 5 | bit_count -= 25; |
946 | 5 | aac_state_struct->bit_count = bit_count; |
947 | 5 | *bytes_consumed = 1; |
948 | 5 | return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES; |
949 | 5 | } |
950 | | |
951 | | |
952 | 0 | ixheaacd_read_bidirection(it_bit_buff, audio_mux_len_bytes_last * 8 - 1); |
953 | 0 | bit_count += audio_mux_len_bytes_last * 8 - 1; |
954 | |
|
955 | 0 | } while (sync_status == 0); |
956 | | |
957 | 12.5k | *bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8; |
958 | 12.5k | { |
959 | 12.5k | ixheaacd_latm_struct latm_struct_element; |
960 | 12.5k | WORD32 sync; |
961 | 12.5k | memset(&latm_struct_element, 0, sizeof(ixheaacd_latm_struct)); |
962 | | |
963 | 12.5k | sync = ixheaacd_read_bits_buf(it_bit_buff, 11); |
964 | 12.5k | if (sync == 0x2b7) { |
965 | 12.5k | result = ixheaacd_latm_audio_mux_element( |
966 | 12.5k | it_bit_buff, &latm_struct_element, aac_state_struct, |
967 | 12.5k | pstr_samp_rate_info); |
968 | 12.5k | if (result != 0) { |
969 | 401 | sync_status = 0; |
970 | 401 | aac_state_struct->sync_status = sync_status; |
971 | | |
972 | 401 | *bytes_consumed += 1; |
973 | 401 | return result; |
974 | 401 | } |
975 | 12.5k | } |
976 | 12.5k | } |
977 | 12.5k | } |
978 | 12.1k | return IA_NO_ERROR; |
979 | 12.6k | } |
980 | | |
981 | | WORD32 ixheaacd_aac_headerdecode( |
982 | | ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, UWORD8 *buffer, |
983 | | WORD32 *bytes_consumed, |
984 | 21.1k | const ia_aac_dec_huffman_tables_struct *pstr_huffmann_tables) { |
985 | 21.1k | struct ia_bit_buf_struct it_bit_buff = {0}, *handle_bit_buff; |
986 | 21.1k | ia_adif_header_struct adif = {0}; |
987 | 21.1k | ia_adts_header_struct adts = {0}; |
988 | 21.1k | WORD32 result; |
989 | 21.1k | WORD32 header_len; |
990 | 21.1k | WORD32 sync = 0; |
991 | | |
992 | 21.1k | WORD32 disable_sync = p_obj_exhaacplus_dec->aac_config.ui_disable_sync; |
993 | 21.1k | WORD32 is_ga_header = p_obj_exhaacplus_dec->aac_config.ui_mp4_flag; |
994 | | |
995 | 21.1k | WORD32 loas_present = p_obj_exhaacplus_dec->aac_config.loas_present; |
996 | | |
997 | 21.1k | ia_aac_dec_state_struct *aac_state_struct = |
998 | 21.1k | p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX]; |
999 | 21.1k | WORD32 usr_max_ch = aac_state_struct->p_config->ui_max_channels; |
1000 | | |
1001 | 21.1k | ia_sampling_rate_info_struct *pstr_samp_rate_info = |
1002 | 21.1k | (ia_sampling_rate_info_struct *)&pstr_huffmann_tables |
1003 | 21.1k | ->str_sample_rate_info[0]; |
1004 | | |
1005 | 21.1k | if (buffer == 0) { |
1006 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
1007 | 0 | } |
1008 | | |
1009 | 21.1k | header_len = aac_state_struct->ui_in_bytes; |
1010 | | |
1011 | 21.1k | handle_bit_buff = ixheaacd_create_bit_buf(&it_bit_buff, (UWORD8 *)buffer, |
1012 | 21.1k | (WORD16)header_len); |
1013 | 21.1k | handle_bit_buff->cnt_bits += (header_len << 3); |
1014 | 21.1k | handle_bit_buff->xaac_jmp_buf = &aac_state_struct->xaac_jmp_buf; |
1015 | | |
1016 | 21.1k | if (is_ga_header == 1) { |
1017 | 2.31k | return ixheaacd_ga_hdr_dec(aac_state_struct, header_len, bytes_consumed, |
1018 | 2.31k | pstr_samp_rate_info, handle_bit_buff); |
1019 | 18.8k | } else if (loas_present) { |
1020 | 0 | return ixheaacd_latm_header_decode(aac_state_struct, &it_bit_buff, |
1021 | 0 | bytes_consumed, pstr_samp_rate_info); |
1022 | 0 | } |
1023 | | |
1024 | 18.8k | else { |
1025 | 18.8k | WORD32 header_found = 0; |
1026 | 18.8k | WORD32 bytes_taken = -1; |
1027 | 18.8k | WORD32 prev_offset = 0; |
1028 | 18.8k | WORD32 run_once = 1; |
1029 | 18.8k | if (disable_sync == 0) run_once = 0; |
1030 | | |
1031 | 748k | do { |
1032 | 748k | bytes_taken++; |
1033 | 748k | buffer += (bytes_taken - prev_offset); |
1034 | | |
1035 | 748k | prev_offset = bytes_taken; |
1036 | | |
1037 | 748k | handle_bit_buff = ixheaacd_create_bit_buf( |
1038 | 748k | &it_bit_buff, (UWORD8 *)buffer, (WORD16)(header_len - bytes_taken)); |
1039 | 748k | handle_bit_buff->cnt_bits += (8 * (header_len - bytes_taken)); |
1040 | | |
1041 | 748k | handle_bit_buff->pstr_adts_crc_info = &handle_bit_buff->str_adts_crc_info; |
1042 | 748k | ixheaacd_adts_crc_open(handle_bit_buff->pstr_adts_crc_info); |
1043 | | |
1044 | 748k | aac_state_struct->ldmps_present = 0; |
1045 | 748k | aac_state_struct->latm_initialized = 0; |
1046 | 748k | memset(&aac_state_struct->mps_dec_handle, 0, |
1047 | 748k | sizeof(aac_state_struct->mps_dec_handle)); |
1048 | 748k | memset(&aac_state_struct->eld_specific_config, 0, |
1049 | 748k | sizeof(aac_state_struct->eld_specific_config)); |
1050 | | |
1051 | 748k | if ((buffer[0] == 'A') && (buffer[1] == 'D') && (buffer[2] == 'I') && |
1052 | 8.13k | (buffer[3] == 'F')) { |
1053 | 5.83k | adif.prog_config_present = 0; |
1054 | 5.83k | result = ixheaacd_get_adif_header(&adif, handle_bit_buff); |
1055 | 5.83k | if (result == 0) { |
1056 | 13 | if (adif.prog_config_present == 1) { |
1057 | 13 | aac_state_struct->p_config->ui_pce_found_in_hdr = 1; |
1058 | 13 | aac_state_struct->p_config->str_prog_config = adif.str_prog_config; |
1059 | 13 | } |
1060 | 13 | aac_state_struct->s_adif_hdr_present = 1; |
1061 | 13 | aac_state_struct->audio_object_type = |
1062 | 13 | adif.str_prog_config.object_type; |
1063 | 13 | aac_state_struct->sampling_rate = |
1064 | 13 | pstr_samp_rate_info[adif.str_prog_config.samp_freq_index] |
1065 | 13 | .sampling_frequency; |
1066 | 13 | aac_state_struct->ch_config = adif.str_prog_config.channels; |
1067 | 13 | bytes_taken += |
1068 | 13 | ((handle_bit_buff->size - handle_bit_buff->cnt_bits) >> 3); |
1069 | | |
1070 | 13 | header_found = 1; |
1071 | 13 | aac_state_struct->frame_length = FRAME_SIZE; |
1072 | 13 | if (aac_state_struct->audio_object_type == AOT_ER_AAC_LD) |
1073 | 0 | aac_state_struct->frame_length >>= 1; |
1074 | 13 | } |
1075 | 5.83k | } |
1076 | | |
1077 | 742k | else if ((sync = ixheaacd_read_bits_buf(&it_bit_buff, 12)) == 0xfff) { |
1078 | 94.8k | result = ixheaacd_check_if_adts(&adts, handle_bit_buff, usr_max_ch); |
1079 | 94.8k | if (result != 0) { |
1080 | 76.7k | continue; |
1081 | 76.7k | } |
1082 | | |
1083 | 18.1k | if ((adts.aac_frame_length + ADTS_HEADER_LENGTH) < |
1084 | 18.1k | (header_len - bytes_taken)) { |
1085 | 11.6k | ia_adts_header_struct adts_loc = {0}; |
1086 | | |
1087 | 11.6k | ixheaacd_create_init_bit_buf( |
1088 | 11.6k | &it_bit_buff, (UWORD8 *)(buffer + adts.aac_frame_length), |
1089 | 11.6k | (WORD16)(header_len - bytes_taken - adts.aac_frame_length)); |
1090 | | |
1091 | 11.6k | handle_bit_buff = &it_bit_buff; |
1092 | | |
1093 | 11.6k | adts_loc.sync_word = |
1094 | 11.6k | (WORD16)ixheaacd_read_bits_buf(handle_bit_buff, 12); |
1095 | | |
1096 | 11.6k | if (adts_loc.sync_word != 0xFFF) { |
1097 | 10.0k | continue; |
1098 | 10.0k | } |
1099 | | |
1100 | 1.62k | result = |
1101 | 1.62k | ixheaacd_check_if_adts(&adts_loc, handle_bit_buff, usr_max_ch); |
1102 | 1.62k | if ((result != 0) || |
1103 | 524 | (adts.samp_freq_index != adts_loc.samp_freq_index) || |
1104 | 1.60k | (adts.channel_configuration != adts_loc.channel_configuration)) { |
1105 | 1.60k | continue; |
1106 | 1.60k | } |
1107 | 1.62k | } |
1108 | | |
1109 | 6.44k | { |
1110 | 6.44k | WORD32 obj_type; |
1111 | 6.44k | obj_type = adts.profile; |
1112 | | |
1113 | 6.44k | aac_state_struct->audio_object_type = obj_type; |
1114 | 6.44k | aac_state_struct->sampling_rate = |
1115 | 6.44k | ((pstr_samp_rate_info[adts.samp_freq_index].sampling_frequency)); |
1116 | 6.44k | aac_state_struct->ch_config = adts.channel_configuration; |
1117 | 6.44k | aac_state_struct->s_adts_hdr_present = 1; |
1118 | 6.44k | header_found = 1; |
1119 | 6.44k | aac_state_struct->bs_format = ADTS_BSFORMAT; |
1120 | 6.44k | aac_state_struct->frame_length = FRAME_SIZE; |
1121 | 6.44k | if (aac_state_struct->audio_object_type == AOT_ER_AAC_LD) |
1122 | 0 | aac_state_struct->frame_length >>= 1; |
1123 | 6.44k | } |
1124 | 647k | } else if (0x2b7 == (sync >> 1)) { |
1125 | 12.6k | ixheaacd_read_bidirection(&it_bit_buff, -12); |
1126 | 12.6k | result = |
1127 | 12.6k | ixheaacd_latm_header_decode(aac_state_struct, &it_bit_buff, |
1128 | 12.6k | bytes_consumed, pstr_samp_rate_info); |
1129 | 12.6k | if (result != 0) { |
1130 | 456 | if ((result == (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES) || |
1131 | 415 | (result < 0)) { |
1132 | 81 | bytes_taken += *bytes_consumed; |
1133 | 81 | *bytes_consumed = bytes_taken; |
1134 | 81 | return result; |
1135 | 81 | } else |
1136 | 375 | bytes_taken += *bytes_consumed - 1; |
1137 | 375 | continue; |
1138 | 456 | } |
1139 | 12.1k | header_found = 1; |
1140 | 12.1k | aac_state_struct->bs_format = LOAS_BSFORMAT; |
1141 | 12.1k | bytes_taken += *bytes_consumed; |
1142 | 12.1k | } |
1143 | | |
1144 | 748k | } while ((header_found == 0 && ((bytes_taken + 1) < (header_len - 68))) && |
1145 | 729k | run_once != 1); |
1146 | | |
1147 | 18.7k | if (header_found == 0 && disable_sync == 1) { |
1148 | 0 | WORD32 err_code; |
1149 | 0 | ixheaacd_read_bidirection(&it_bit_buff, -12); |
1150 | 0 | err_code = |
1151 | 0 | ixheaacd_ga_hdr_dec(aac_state_struct, header_len, bytes_consumed, |
1152 | 0 | pstr_samp_rate_info, handle_bit_buff); |
1153 | |
|
1154 | 0 | if (err_code == 0) p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 1; |
1155 | 0 | return err_code; |
1156 | 0 | } |
1157 | | |
1158 | 18.7k | switch (aac_state_struct->audio_object_type) { |
1159 | 16 | case AOT_AAC_MAIN: |
1160 | 6.45k | case AOT_AAC_LC: |
1161 | 6.45k | case AOT_AAC_SSR: |
1162 | 6.78k | case AOT_AAC_LTP: |
1163 | 6.78k | case AOT_AAC_SCAL: |
1164 | 6.78k | case AOT_TWIN_VQ: |
1165 | 8.34k | case AOT_ER_AAC_LD: |
1166 | 11.0k | case AOT_ER_AAC_ELD: |
1167 | 12.2k | case AOT_ER_AAC_LC: |
1168 | 18.6k | case AOT_USAC: |
1169 | 18.6k | break; |
1170 | 145 | default: |
1171 | 145 | return IA_XHEAAC_DEC_INIT_FATAL_AUDIOOBJECTTYPE_NOT_SUPPORTED; |
1172 | 18.7k | } |
1173 | | |
1174 | 18.6k | if (aac_state_struct->audio_object_type != AOT_USAC) |
1175 | 12.2k | aac_state_struct->usac_flag = 0; |
1176 | 18.6k | *bytes_consumed = bytes_taken; |
1177 | | |
1178 | 18.6k | if ((handle_bit_buff->cnt_bits < 0) && |
1179 | 0 | (handle_bit_buff->size < |
1180 | 0 | (usr_max_ch * (IA_ENHAACPLUS_DEC_INP_BUF_SIZE << 3)))) { |
1181 | 0 | return (WORD16)( |
1182 | 0 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
1183 | 0 | } |
1184 | | |
1185 | 18.6k | if (header_found == 0) { |
1186 | 11 | *bytes_consumed = bytes_taken + 1; |
1187 | 11 | return IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START; |
1188 | 18.5k | } else { |
1189 | 18.5k | return 0; |
1190 | 18.5k | } |
1191 | 18.6k | } |
1192 | 21.1k | } |