/src/libxaac/decoder/ixheaacd_aacdecoder.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 <stdio.h> |
21 | | #include <string.h> |
22 | | #include "ixheaacd_sbr_common.h" |
23 | | #include "ixheaac_type_def.h" |
24 | | |
25 | | #include "ixheaac_constants.h" |
26 | | #include "ixheaac_basic_ops32.h" |
27 | | #include "ixheaac_basic_ops16.h" |
28 | | #include "ixheaac_basic_ops40.h" |
29 | | #include "ixheaac_basic_ops.h" |
30 | | #include "ixheaacd_bitbuffer.h" |
31 | | |
32 | | #include "ixheaacd_defines.h" |
33 | | |
34 | | #include "ixheaacd_aac_rom.h" |
35 | | |
36 | | #include "ixheaacd_error_codes.h" |
37 | | |
38 | | #include "ixheaacd_pulsedata.h" |
39 | | |
40 | | #include "ixheaacd_pns.h" |
41 | | #include "ixheaacd_drc_data_struct.h" |
42 | | |
43 | | #include "ixheaacd_interface.h" |
44 | | #include "ixheaacd_info.h" |
45 | | #include "ixheaacd_cnst.h" |
46 | | #include "ixheaacd_sbrdecsettings.h" |
47 | | #include "ixheaacd_sbr_scale.h" |
48 | | #include "ixheaacd_common_rom.h" |
49 | | #include "ixheaacd_env_extr_part.h" |
50 | | #include "ixheaacd_sbr_rom.h" |
51 | | #include "ixheaacd_hybrid.h" |
52 | | #include "ixheaacd_ps_dec.h" |
53 | | #include "ixheaacd_qmf_dec.h" |
54 | | #include "ixheaacd_mps_polyphase.h" |
55 | | #include "ixheaacd_config.h" |
56 | | #include "ixheaacd_mps_struct_def.h" |
57 | | #include "ixheaacd_mps_res_rom.h" |
58 | | #include "ixheaacd_mps_aac_struct.h" |
59 | | #include "ixheaacd_mps_dec.h" |
60 | | #include "ixheaac_error_standards.h" |
61 | | #include "ixheaacd_sbrdecoder.h" |
62 | | #include "ixheaacd_acelp_info.h" |
63 | | #include "ixheaacd_tns_usac.h" |
64 | | #include "ixheaacd_ec_defines.h" |
65 | | #include "ixheaacd_ec_rom.h" |
66 | | #include "ixheaacd_ec_struct_def.h" |
67 | | #include "ixheaacd_main.h" |
68 | | #include "ixheaacd_channelinfo.h" |
69 | | #include "ixheaacd_ec.h" |
70 | | #include "ixheaacd_drc_dec.h" |
71 | | |
72 | | #include "ixheaacd_block.h" |
73 | | #include "ixheaacd_channel.h" |
74 | | #include "ixheaacd_sbr_payload.h" |
75 | | #include "ixheaacd_stereo.h" |
76 | | #include "ixheaacd_adts.h" |
77 | | #include "ixheaacd_audioobjtypes.h" |
78 | | #include "ixheaacd_memory_standards.h" |
79 | | #include "ixheaacd_latmdemux.h" |
80 | | #include "ixheaacd_aacdec.h" |
81 | | |
82 | | #include "ixheaacd_struct_def.h" |
83 | | #include "ixheaacd_headerdecode.h" |
84 | | #include "ixheaacd_multichannel.h" |
85 | | #include "ixheaacd_adts_crc_check.h" |
86 | | #include "ixheaacd_ld_mps_dec.h" |
87 | | |
88 | | #include "ixheaacd_hcr.h" |
89 | | #include "ixheaacd_struct.h" |
90 | | |
91 | 1.78M | #define SIZEOF_INT(x) ((sizeof(x) + sizeof(WORD32) - 1) / sizeof(WORD32)) |
92 | | |
93 | 8.05k | #define EXT_FILL_DATA 1 |
94 | 59.7k | #define EXT_FIL 0 |
95 | 2.09k | #define EXT_DATA_LENGTH 3 |
96 | 8.95k | #define EXT_LDSAC_DATA 9 |
97 | | |
98 | | extern const ia_usac_samp_rate_info ixheaacd_samp_rate_info[]; |
99 | | |
100 | | WORD32 ixheaacd_aacdec_decodeframe( |
101 | | ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, |
102 | | ia_aac_dec_scratch_struct *aac_scratch_ptrs, VOID *time_data_tmp, |
103 | | FLAG frame_status, WORD *type, WORD *ch_idx, WORD init_flag, WORD channel, |
104 | | WORD *element_index_order, WORD skip_full_decode, WORD ch_fac, |
105 | | WORD slot_element, WORD max_channels, WORD32 total_channels, |
106 | | WORD32 frame_length, WORD32 frame_size, ia_drc_dec_struct *pstr_drc_dec, |
107 | | WORD32 object_type, WORD32 ch_config, |
108 | | ia_eld_specific_config_struct eld_specific_config, WORD16 adtsheader, |
109 | | ia_drc_dec_struct *drc_dummy, WORD32 ldmps_present, UWORD8 *slot_pos, UWORD8 *mps_buffer, |
110 | 310k | WORD32 *mps_header, WORD32 *mps_bytes, WORD32 is_init, WORD32 first_frame) { |
111 | 310k | WORD ch, ele_type; |
112 | 310k | ia_aac_dec_state_struct *p_state_enhaacplus_dec; |
113 | 310k | ia_aac_decoder_struct *aac_dec_handle; |
114 | 310k | ia_bit_buf_struct *it_bit_buff; |
115 | 310k | ixheaacd_latm_struct *latm_element; |
116 | | |
117 | 310k | WORD error_code = (WORD)frame_status; |
118 | 310k | WORD previous_element; |
119 | 310k | WORD prev_data_ele_present = 0; |
120 | 310k | WORD new_element; |
121 | 310k | WORD32 num_ch = 0; |
122 | | |
123 | 310k | WORD32 crc_reg = 0; |
124 | 310k | ia_adts_crc_info_struct *ptr_adts_crc_info; |
125 | | |
126 | 310k | WORD32 cnt_bits = 0; |
127 | | |
128 | 310k | WORD32 eld_sbr_flag = eld_specific_config.ld_sbr_flag_present; |
129 | 310k | WORD32 ld_sbr_crc_flag = eld_specific_config.ld_sbr_crc_flag; |
130 | 310k | WORD32 aac_spect_data_resil_flag = |
131 | 310k | eld_specific_config.aac_spect_data_resil_flag; |
132 | | |
133 | 310k | WORD32 ele_ch = 0; |
134 | | |
135 | 310k | ia_aac_sfb_code_book_struct *ptr_aac_sfb_code_book_data[CHANNELS]; |
136 | 310k | ia_pns_stereo_data_struct *ptr_pns_stereo_data; |
137 | | |
138 | 310k | WORD32 *work_buffer_core = aac_scratch_ptrs->base_scr_8k; |
139 | 310k | WORD32 *work_buffer_1 = aac_scratch_ptrs->extra_scr_4k[0]; |
140 | 310k | WORD32 *work_buffer_2 = aac_scratch_ptrs->extra_scr_4k[2]; |
141 | 310k | p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac; |
142 | | |
143 | 310k | WORD32 *time_data = (WORD32 *)time_data_tmp; |
144 | | |
145 | 310k | aac_dec_handle = p_state_enhaacplus_dec->pstr_aac_dec_info[*ch_idx]; |
146 | 310k | it_bit_buff = p_state_enhaacplus_dec->ptr_bit_stream; |
147 | 310k | p_obj_exhaacplus_dec->aac_config.str_prog_config.alignment_bits = it_bit_buff->bit_pos; |
148 | | |
149 | 310k | ptr_adts_crc_info = it_bit_buff->pstr_adts_crc_info; |
150 | | |
151 | 310k | latm_element = &p_state_enhaacplus_dec->latm_struct_element; |
152 | | |
153 | 310k | ptr_pns_stereo_data = |
154 | 310k | (ia_pns_stereo_data_struct |
155 | 310k | *)&work_buffer_1[2 * SIZEOF_INT(ia_aac_dec_channel_info_struct) + |
156 | 310k | 2 * SIZEOF_INT(ia_aac_sfb_code_book_struct)]; |
157 | | |
158 | 310k | aac_dec_handle->frame_status = 1; |
159 | | |
160 | 698k | for (ch = 0; ch < channel; ch++) { |
161 | 387k | const ia_aac_dec_imdct_tables_struct *pstr_imdct_tables; |
162 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch] = |
163 | 387k | (ia_aac_dec_channel_info_struct |
164 | 387k | *)&work_buffer_1[ch * SIZEOF_INT(ia_aac_dec_channel_info_struct)]; |
165 | 387k | ptr_aac_sfb_code_book_data[ch] = |
166 | 387k | (ia_aac_sfb_code_book_struct |
167 | 387k | *)&work_buffer_1[2 * SIZEOF_INT(ia_aac_dec_channel_info_struct) + |
168 | 387k | (ch * SIZEOF_INT(ia_aac_sfb_code_book_struct))]; |
169 | | |
170 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_scale_factor = |
171 | 387k | ptr_aac_sfb_code_book_data[ch]->scale_factor; |
172 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_code_book = |
173 | 387k | ptr_aac_sfb_code_book_data[ch]->code_book; |
174 | | |
175 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff = |
176 | 387k | &work_buffer_core[ch * MAX_BINS_LONG]; |
177 | | |
178 | 387k | if (object_type == AOT_ER_AAC_ELD) { |
179 | 134k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff = |
180 | 134k | &work_buffer_core[2 * ch * MAX_BINS_LONG]; |
181 | 134k | } |
182 | | |
183 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_stereo_info = |
184 | 387k | &ptr_pns_stereo_data->str_stereo_info; |
185 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_pns_corr_info = |
186 | 387k | &ptr_pns_stereo_data->str_pns_corr_info; |
187 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_pns_rand_vec_data = |
188 | 387k | aac_dec_handle->pstr_pns_rand_vec_data; |
189 | | |
190 | 387k | pstr_imdct_tables = aac_dec_handle->pstr_aac_tables->pstr_imdct_tables; |
191 | | |
192 | 387k | if (960 != frame_length) { |
193 | 307k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
194 | 307k | pstr_imdct_tables->only_long_window_sine; |
195 | 307k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[0] = |
196 | 307k | pstr_imdct_tables->only_short_window_sine; |
197 | 307k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
198 | 307k | pstr_imdct_tables->only_long_window_kbd; |
199 | 307k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[1] = |
200 | 307k | pstr_imdct_tables->only_short_window_kbd; |
201 | | |
202 | 307k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[0] = |
203 | 307k | pstr_imdct_tables->only_long_window_sine; |
204 | 307k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[0] = |
205 | 307k | pstr_imdct_tables->only_short_window_sine; |
206 | 307k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[1] = |
207 | 307k | pstr_imdct_tables->only_long_window_kbd; |
208 | 307k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[1] = |
209 | 307k | pstr_imdct_tables->only_short_window_kbd; |
210 | 307k | } else { |
211 | 79.8k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
212 | 79.8k | pstr_imdct_tables->only_long_window_sine_960; |
213 | 79.8k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[0] = |
214 | 79.8k | pstr_imdct_tables->only_short_window_sine_120; |
215 | 79.8k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
216 | 79.8k | pstr_imdct_tables->only_long_window_kbd_960; |
217 | 79.8k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[1] = |
218 | 79.8k | pstr_imdct_tables->only_short_window_kbd_120; |
219 | | |
220 | 79.8k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[0] = |
221 | 79.8k | pstr_imdct_tables->only_long_window_sine_960; |
222 | 79.8k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[0] = |
223 | 79.8k | pstr_imdct_tables->only_short_window_sine_120; |
224 | 79.8k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[1] = |
225 | 79.8k | pstr_imdct_tables->only_long_window_kbd_960; |
226 | 79.8k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[1] = |
227 | 79.8k | pstr_imdct_tables->only_short_window_kbd_120; |
228 | 79.8k | } |
229 | | |
230 | 387k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && frame_status == 0) |
231 | 0 | { |
232 | 0 | memset(&aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info, 0, |
233 | 0 | sizeof(ia_ics_info_struct)); |
234 | 0 | } |
235 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.frame_length = frame_length; |
236 | 387k | if (object_type == AOT_ER_AAC_ELD || object_type == AOT_ER_AAC_LD || |
237 | 264k | object_type == AOT_AAC_LTP) { |
238 | 264k | if (512 == aac_dec_handle->samples_per_frame) { |
239 | 165k | if (object_type != AOT_ER_AAC_ELD) { |
240 | 76.0k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
241 | 76.0k | (WORD16 *)pstr_imdct_tables->low_overlap_win; |
242 | 76.0k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
243 | 76.0k | (WORD16 *)pstr_imdct_tables->window_sine_512; |
244 | | |
245 | 76.0k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
246 | 76.0k | ->ptr_long_window[1] = |
247 | 76.0k | (WORD16 *)pstr_imdct_tables->low_overlap_win; |
248 | 76.0k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
249 | 76.0k | ->ptr_long_window[0] = |
250 | 76.0k | (WORD16 *)pstr_imdct_tables->window_sine_512; |
251 | 89.4k | } else { |
252 | 89.4k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
253 | 89.4k | (WORD16 *)pstr_imdct_tables->window_sine_512_eld; |
254 | 89.4k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
255 | 89.4k | (WORD16 *)pstr_imdct_tables->window_sine_512_eld; |
256 | 89.4k | } |
257 | 165k | } else if (480 == aac_dec_handle->samples_per_frame) { |
258 | 63.8k | if (object_type != AOT_ER_AAC_ELD) { |
259 | 18.9k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
260 | 18.9k | (WORD16 *)pstr_imdct_tables->low_overlap_win_480; |
261 | 18.9k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
262 | 18.9k | (WORD16 *)pstr_imdct_tables->window_sine_480; |
263 | | |
264 | 18.9k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
265 | 18.9k | ->ptr_long_window[1] = |
266 | 18.9k | (WORD16 *)pstr_imdct_tables->low_overlap_win_480; |
267 | 18.9k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
268 | 18.9k | ->ptr_long_window[0] = |
269 | 18.9k | (WORD16 *)pstr_imdct_tables->window_sine_480; |
270 | | |
271 | 44.8k | } else { |
272 | 44.8k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
273 | 44.8k | (WORD16 *)pstr_imdct_tables->window_sine_480_eld; |
274 | 44.8k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
275 | 44.8k | (WORD16 *)pstr_imdct_tables->window_sine_480_eld; |
276 | 44.8k | } |
277 | 63.8k | } |
278 | 264k | } |
279 | 387k | if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) { |
280 | 130k | if (aac_dec_handle->samples_per_frame <= 512) { |
281 | 94.9k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.lag = |
282 | 94.9k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1; |
283 | 94.9k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.lag = |
284 | 94.9k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_2; |
285 | 94.9k | } |
286 | 130k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ltp_buf = |
287 | 130k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_buf; |
288 | 130k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ltp_lag = |
289 | 130k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1; |
290 | 130k | } |
291 | | |
292 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->scratch_buf_ptr = work_buffer_2; |
293 | 387k | if (object_type == AOT_ER_AAC_ELD) { |
294 | 134k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->pulse_scratch = |
295 | 134k | aac_scratch_ptrs->extra_scr_4k[3]; |
296 | 134k | } |
297 | 387k | } |
298 | | |
299 | 310k | if (channel == 2) { |
300 | 77.0k | if (aac_dec_handle->pstr_aac_dec_ch_info[1]->ptr_spec_coeff == |
301 | 77.0k | aac_scratch_ptrs->extra_scr_4k[0]) { |
302 | 0 | aac_dec_handle->pstr_aac_dec_ch_info[1]->ptr_spec_coeff = |
303 | 0 | aac_dec_handle->pstr_aac_dec_ch_info[0]->ptr_spec_coeff; |
304 | 0 | } |
305 | 77.0k | } |
306 | | |
307 | 698k | for (ch = 0; ch < channel; ch++) { |
308 | 387k | ia_pns_info_struct *ptr_pns_info = |
309 | 387k | &aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_pns_info; |
310 | 387k | memset(ptr_pns_info, 0, sizeof(ia_pns_info_struct)); |
311 | 387k | } |
312 | | |
313 | 310k | if (channel > 0) { |
314 | 310k | ia_pns_correlation_info_struct *ptr_corr_info = |
315 | 310k | aac_dec_handle->pstr_aac_dec_ch_info[0]->pstr_pns_corr_info; |
316 | 310k | memset(ptr_corr_info->correlated, 0, sizeof(UWORD8) * PNS_BAND_FLAGS_SIZE); |
317 | 310k | } |
318 | | |
319 | 698k | for (ch = 0; ch < channel; ch++) { |
320 | 387k | memset(&aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_hcr_info, 0, |
321 | 387k | sizeof(ia_hcr_info_struct)); |
322 | 387k | ixheaacd_huff_code_reorder_tbl_init( |
323 | 387k | &aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_hcr_info); |
324 | 387k | } |
325 | | |
326 | 698k | for (ch = 0; ch < channel; ch++) { |
327 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.data_present = 0; |
328 | 387k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.data_present = |
329 | 387k | 0; |
330 | 387k | } |
331 | | |
332 | 698k | for (ch = 0; ch < channel; ch++) { |
333 | 387k | if (object_type == AOT_ER_AAC_ELD || object_type == AOT_ER_AAC_LD) |
334 | 229k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->granule_len = |
335 | 229k | aac_dec_handle->samples_per_frame; |
336 | 387k | if (object_type == AOT_ER_AAC_LC) |
337 | 59.5k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->granule_len = |
338 | 59.5k | aac_dec_handle->samples_per_frame / 8; |
339 | 387k | } |
340 | 310k | previous_element = ID_END; |
341 | | |
342 | 310k | aac_dec_handle->pstr_sbr_bitstream->no_elements = 0; |
343 | 310k | new_element = 0; |
344 | 310k | ele_type = *type; |
345 | | |
346 | 310k | cnt_bits = it_bit_buff->cnt_bits; |
347 | | |
348 | 310k | WORD32 err = 0; |
349 | 310k | jmp_buf local; |
350 | | |
351 | 310k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
352 | 0 | err = setjmp(local); |
353 | 0 | } |
354 | | |
355 | 310k | if (!err && frame_status) { |
356 | 310k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
357 | 0 | it_bit_buff->xaac_jmp_buf = &local; |
358 | 0 | } |
359 | | |
360 | 310k | if (((object_type != AOT_ER_AAC_ELD) && (object_type != AOT_ER_AAC_LD) && |
361 | 139k | (object_type != AOT_ER_AAC_LC)) || |
362 | 224k | (object_type < ER_OBJECT_START)) { |
363 | 290k | while (ele_type != ID_END && aac_dec_handle->frame_status) { |
364 | 229k | ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3); |
365 | 229k | ixheaacd_read_bidirection(it_bit_buff, -3); |
366 | | |
367 | 229k | if (it_bit_buff->cnt_bits < 3) { |
368 | 0 | it_bit_buff->cnt_bits = -1; |
369 | 0 | error_code = (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
370 | 0 | break; |
371 | 0 | } |
372 | | |
373 | 229k | if ((ele_type == ID_FIL) || (ele_type == ID_DSE) || (new_element == 0)) { |
374 | 146k | ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3); |
375 | 146k | new_element = 1; |
376 | 146k | } else if ((ele_type != ID_END)) { |
377 | 23.3k | ele_type = -1; |
378 | 23.3k | break; |
379 | 60.2k | } else { |
380 | 60.2k | ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3); |
381 | 60.2k | } |
382 | | |
383 | 206k | if (it_bit_buff->cnt_bits < 0) { |
384 | 0 | aac_dec_handle->frame_status = 0; |
385 | 0 | } |
386 | | |
387 | 206k | switch (ele_type) { |
388 | 66.5k | case ID_SCE: |
389 | 69.0k | case ID_CPE: |
390 | 84.6k | case ID_LFE: |
391 | | |
392 | 84.6k | if (aac_dec_handle->frame_status) { |
393 | 84.6k | ia_aac_dec_channel_info_struct *pstr_aac_dec_ch_info = |
394 | 84.6k | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]; |
395 | 84.6k | ia_ics_info_struct *ptr_ics_info = &pstr_aac_dec_ch_info->str_ics_info; |
396 | 84.6k | ele_ch = 1; |
397 | 84.6k | if (ele_type == ID_CPE) { |
398 | 2.42k | ele_ch = 2; |
399 | 82.2k | } else { |
400 | 82.2k | ele_ch = 1; |
401 | 82.2k | } |
402 | | |
403 | 84.6k | prev_data_ele_present = 1; |
404 | | |
405 | 84.6k | if (ptr_adts_crc_info->crc_active == 1 && ptr_adts_crc_info->no_reg < 7) { |
406 | 255 | crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff, |
407 | 255 | CRC_ADTS_RAW_DATA_BLK_LEN); |
408 | 255 | } |
409 | | |
410 | 84.6k | pstr_aac_dec_ch_info->element_instance_tag = |
411 | 84.6k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4); |
412 | | |
413 | 84.6k | element_index_order[*ch_idx] = pstr_aac_dec_ch_info->element_instance_tag; |
414 | 84.6k | pstr_aac_dec_ch_info->common_window = 0; |
415 | | |
416 | 84.6k | ptr_ics_info->num_swb_window = 0; |
417 | 84.6k | ptr_ics_info->sampling_rate_index = aac_dec_handle->sampling_rate_index; |
418 | 84.6k | if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) { |
419 | 32.9k | ptr_ics_info->ltp.data_present = 0; |
420 | 32.9k | ptr_ics_info->ltp2.data_present = 0; |
421 | 32.9k | ptr_ics_info->predictor_data_present = 0; |
422 | 32.9k | } |
423 | | |
424 | 84.6k | if (ele_ch > 1) { |
425 | 2.41k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.num_swb_window = 0; |
426 | 2.41k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.sampling_rate_index = |
427 | 2.41k | aac_dec_handle->sampling_rate_index; |
428 | | |
429 | 2.41k | pstr_aac_dec_ch_info->common_window = |
430 | 2.41k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 1); |
431 | | |
432 | 2.41k | if (pstr_aac_dec_ch_info->common_window) { |
433 | 1.07k | error_code = ixheaacd_ics_read( |
434 | 1.07k | it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, object_type, |
435 | 1.07k | pstr_aac_dec_ch_info->common_window, aac_dec_handle->samples_per_frame); |
436 | 1.07k | if (error_code) { |
437 | 18 | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info = |
438 | 18 | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->str_ics_info; |
439 | 18 | if (it_bit_buff->cnt_bits < 0) { |
440 | 0 | error_code = |
441 | 0 | (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
442 | 0 | } |
443 | | |
444 | 18 | goto _ia_handle_error; |
445 | 18 | } |
446 | | |
447 | 1.05k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info = |
448 | 1.05k | pstr_aac_dec_ch_info->str_ics_info; |
449 | | |
450 | 1.05k | ixheaacd_read_ms_data(it_bit_buff, pstr_aac_dec_ch_info); |
451 | 1.05k | } |
452 | 2.41k | } |
453 | | |
454 | 84.6k | error_code = ixheaacd_individual_ch_stream( |
455 | 84.6k | it_bit_buff, aac_dec_handle, ele_ch, frame_length, total_channels, object_type, |
456 | 84.6k | eld_specific_config, ele_type); |
457 | | |
458 | 84.6k | if (error_code) { |
459 | 1.23k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
460 | 0 | aac_dec_handle->frame_status = 0; |
461 | 1.23k | } else { |
462 | 1.23k | return error_code; |
463 | 1.23k | } |
464 | 1.23k | } |
465 | | |
466 | 83.4k | if (ptr_adts_crc_info->crc_active == 1) { |
467 | 225 | ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg); |
468 | 225 | } |
469 | | |
470 | 83.4k | if (it_bit_buff->cnt_bits < 0) { |
471 | 21 | error_code = |
472 | 21 | (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
473 | 21 | } |
474 | | |
475 | 83.4k | if (error_code) { |
476 | 21 | goto _ia_handle_error; |
477 | 21 | } |
478 | | |
479 | 83.3k | _ia_handle_error: |
480 | 82.8k | if (error_code) { |
481 | 39 | aac_dec_handle->frame_status = 0; |
482 | 39 | if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) num_ch = num_ch + ele_ch; |
483 | 39 | break; |
484 | 82.7k | } else { |
485 | 82.7k | error_code = ixheaacd_channel_pair_process( |
486 | 82.7k | aac_dec_handle->pstr_aac_dec_ch_info, ele_ch, aac_dec_handle->pstr_aac_tables, |
487 | 82.7k | total_channels, object_type, aac_spect_data_resil_flag, |
488 | 82.7k | eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data, |
489 | 82.7k | aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle); |
490 | 82.7k | if (error_code) { |
491 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
492 | 0 | aac_dec_handle->frame_status = 0; |
493 | 0 | } else { |
494 | 0 | return error_code; |
495 | 0 | } |
496 | 0 | } |
497 | 82.7k | num_ch = num_ch + ele_ch; |
498 | 82.7k | } |
499 | 82.8k | } |
500 | | |
501 | 82.7k | break; |
502 | 82.7k | case ID_CCE: |
503 | 1.00k | if (max_channels > 2) { |
504 | 1.00k | prev_data_ele_present = 1; |
505 | 1.00k | error_code = ixheaacd_dec_coupling_channel_element( |
506 | 1.00k | it_bit_buff, aac_dec_handle, aac_dec_handle->sampling_rate_index, |
507 | 1.00k | aac_dec_handle->pstr_aac_tables, aac_dec_handle->pstr_common_tables, |
508 | 1.00k | &element_index_order[*ch_idx], |
509 | 1.00k | (ia_enhaacplus_dec_ind_cc *)aac_dec_handle->p_ind_channel_info, total_channels, |
510 | 1.00k | frame_length, object_type, eld_specific_config, ele_type); |
511 | | |
512 | 1.00k | num_ch = num_ch + 1; |
513 | | |
514 | 1.00k | if (error_code) { |
515 | 51 | aac_dec_handle->frame_status = 0; |
516 | 51 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
517 | 0 | aac_dec_handle->frame_status = 0; |
518 | 51 | } else { |
519 | 51 | return error_code; |
520 | 51 | } |
521 | 952 | } else { |
522 | 952 | error_code = ixheaacd_channel_pair_process( |
523 | 952 | aac_dec_handle->pstr_aac_dec_ch_info, 1, aac_dec_handle->pstr_aac_tables, |
524 | 952 | total_channels, object_type, aac_spect_data_resil_flag, |
525 | 952 | eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data, |
526 | 952 | aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle); |
527 | 952 | if (error_code) { |
528 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
529 | 0 | aac_dec_handle->frame_status = 0; |
530 | 0 | } else { |
531 | 0 | return error_code; |
532 | 0 | } |
533 | 0 | } |
534 | 952 | } |
535 | 1.00k | } else { |
536 | 0 | error_code = (WORD32)((WORD32)IA_XHEAAC_DEC_EXE_FATAL_UNIMPLEMENTED_CCE); |
537 | 0 | } |
538 | 952 | if (it_bit_buff->cnt_bits < 0) { |
539 | 0 | error_code = (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
540 | 0 | goto _ia_handle_error; |
541 | 0 | } |
542 | 952 | break; |
543 | | |
544 | 9.65k | case ID_DSE: |
545 | 9.87k | case ID_PCE: |
546 | 60.6k | case ID_FIL: |
547 | | |
548 | 60.6k | { |
549 | 60.6k | WORD32 flag = 1; |
550 | | |
551 | 60.6k | if ((ele_type != ID_FIL) && (ptr_adts_crc_info->crc_active == 1) && |
552 | 188 | (ptr_adts_crc_info->no_reg < 7)) { |
553 | 68 | crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff, 0); |
554 | 68 | } |
555 | 60.6k | if (ele_type == ID_DSE) { |
556 | 9.65k | ixheaacd_read_data_stream_element(it_bit_buff, &aac_dec_handle->byte_align_bits, |
557 | 9.65k | p_obj_exhaacplus_dec->p_state_aac->pstr_drc_dec); |
558 | 9.65k | } |
559 | | |
560 | 50.9k | else if (ele_type == ID_PCE) { |
561 | 220 | error_code = ixheaacd_decode_pce( |
562 | 220 | it_bit_buff, &p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr, |
563 | 220 | &p_obj_exhaacplus_dec->aac_config.str_prog_config); |
564 | 220 | if (error_code != 0) { |
565 | 44 | if (it_bit_buff->cnt_bits < 0) { |
566 | 0 | error_code = |
567 | 0 | (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
568 | 0 | goto _ia_handle_error; |
569 | 0 | } |
570 | 44 | aac_dec_handle->frame_status = 0; |
571 | 44 | if (error_code > 0) { |
572 | 13 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
573 | 0 | aac_dec_handle->frame_status = 0; |
574 | 13 | } else { |
575 | 13 | return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; |
576 | 13 | } |
577 | 31 | } else { |
578 | 31 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
579 | 0 | aac_dec_handle->frame_status = 0; |
580 | 31 | } else { |
581 | 31 | return error_code; |
582 | 31 | } |
583 | 31 | } |
584 | 44 | } |
585 | 220 | } |
586 | | |
587 | 50.7k | else if (ele_type == ID_FIL) { |
588 | 50.7k | WORD32 bits_decoded = 0; |
589 | 50.7k | if (object_type == AOT_ER_AAC_ELD) { |
590 | 0 | bits_decoded = (it_bit_buff->size - it_bit_buff->cnt_bits); |
591 | 0 | cnt_bits = (frame_size * 8 - bits_decoded); |
592 | 0 | if (adtsheader == 1) { |
593 | 0 | if (cnt_bits > it_bit_buff->cnt_bits) { |
594 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
595 | 0 | aac_dec_handle->frame_status = 0; |
596 | 0 | } else { |
597 | 0 | return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES; |
598 | 0 | } |
599 | 0 | } |
600 | 0 | } |
601 | 0 | } |
602 | | |
603 | 50.7k | if (ixheaacd_check_for_sbr_payload( |
604 | 50.7k | it_bit_buff, aac_dec_handle->pstr_sbr_bitstream, (WORD16)previous_element, |
605 | 50.7k | pstr_drc_dec, object_type, adtsheader, cnt_bits, ld_sbr_crc_flag, drc_dummy, |
606 | 50.7k | mps_buffer, mps_header, mps_bytes, is_init, &aac_dec_handle->is_first, |
607 | 50.7k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal)) { |
608 | 23.5k | flag = 0; |
609 | 23.5k | } |
610 | 50.7k | } |
611 | | |
612 | 60.5k | if (it_bit_buff->cnt_bits < 0) { |
613 | 0 | error_code = (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
614 | 0 | goto _ia_handle_error; |
615 | 0 | } |
616 | | |
617 | 60.5k | if (flag) { |
618 | 36.9k | if (prev_data_ele_present == 0) { |
619 | 2.89k | new_element = 0; |
620 | 2.89k | } |
621 | 36.9k | } |
622 | 60.5k | if ((ele_type != ID_FIL) && (ptr_adts_crc_info->crc_active == 1)) { |
623 | 177 | ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg); |
624 | 177 | } |
625 | | |
626 | 60.5k | if (ele_type == ID_PCE) { |
627 | 159 | if (ptr_adts_crc_info->str_crc_reg_data[crc_reg].bit_buf_cnt) { |
628 | 152 | ptr_adts_crc_info->str_crc_reg_data[crc_reg].max_bits = |
629 | 152 | ptr_adts_crc_info->str_crc_reg_data[crc_reg].bit_buf_cnt; |
630 | 152 | } |
631 | 159 | } |
632 | 60.5k | } |
633 | | |
634 | 0 | break; |
635 | | |
636 | 60.1k | case ID_END: |
637 | 60.1k | error_code = 0; |
638 | 60.1k | break; |
639 | 206k | } |
640 | | |
641 | 204k | previous_element = ele_type; |
642 | | |
643 | 204k | if (init_flag) { |
644 | 27.9k | if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) { |
645 | 10.3k | p_obj_exhaacplus_dec->aac_config.element_type[*ch_idx] = ele_type; |
646 | 10.3k | } |
647 | 27.9k | } |
648 | 204k | } |
649 | 224k | } else { |
650 | 224k | { |
651 | 224k | switch (ch_config) { |
652 | 224k | default: |
653 | 224k | if (aac_dec_handle->frame_status) { |
654 | 224k | ia_aac_dec_channel_info_struct *pstr_aac_dec_ch_info = |
655 | 224k | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]; |
656 | 224k | ia_ics_info_struct *ptr_ics_info = &pstr_aac_dec_ch_info->str_ics_info; |
657 | | |
658 | 224k | if (ch_config == 2) |
659 | 59.6k | ele_ch = 2, ele_type = 1; |
660 | 165k | else |
661 | 165k | ele_ch = 1, ele_type = 0; |
662 | | |
663 | 224k | prev_data_ele_present = 1; |
664 | | |
665 | 224k | if ((ptr_adts_crc_info->crc_active == 1) && (ptr_adts_crc_info->no_reg < 7)) { |
666 | 0 | crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff, |
667 | 0 | CRC_ADTS_RAW_DATA_BLK_LEN); |
668 | 0 | } |
669 | | |
670 | 224k | if (object_type != AOT_ER_AAC_ELD) |
671 | 137k | pstr_aac_dec_ch_info->element_instance_tag = |
672 | 137k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4); |
673 | | |
674 | 224k | element_index_order[*ch_idx] = pstr_aac_dec_ch_info->element_instance_tag; |
675 | 224k | pstr_aac_dec_ch_info->common_window = 0; |
676 | | |
677 | 224k | ptr_ics_info->num_swb_window = 0; |
678 | 224k | ptr_ics_info->sampling_rate_index = aac_dec_handle->sampling_rate_index; |
679 | | |
680 | 224k | if (object_type == AOT_ER_AAC_LD) { |
681 | 83.3k | ptr_ics_info->ltp.data_present = 0; |
682 | 83.3k | ptr_ics_info->ltp2.data_present = 0; |
683 | 83.3k | ptr_ics_info->predictor_data_present = 0; |
684 | 83.3k | } |
685 | 224k | if (ele_ch > 1) { |
686 | 59.6k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.num_swb_window = 0; |
687 | 59.6k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.sampling_rate_index = |
688 | 59.6k | aac_dec_handle->sampling_rate_index; |
689 | | |
690 | 59.6k | if (object_type != 39) |
691 | 14.5k | pstr_aac_dec_ch_info->common_window = |
692 | 14.5k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 1); |
693 | 45.1k | else |
694 | 45.1k | pstr_aac_dec_ch_info->common_window = 1; |
695 | | |
696 | 59.6k | if (pstr_aac_dec_ch_info->common_window) { |
697 | 57.6k | error_code = ixheaacd_ics_read( |
698 | 57.6k | it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, object_type, |
699 | 57.6k | pstr_aac_dec_ch_info->common_window, aac_dec_handle->samples_per_frame); |
700 | 57.6k | if (error_code) { |
701 | 33.6k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info = |
702 | 33.6k | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->str_ics_info; |
703 | 33.6k | if (it_bit_buff->cnt_bits < 0) { |
704 | 0 | error_code = |
705 | 0 | (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
706 | 0 | } |
707 | | |
708 | 33.6k | goto _ia_handle_error1; |
709 | 33.6k | } |
710 | | |
711 | 23.9k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info = |
712 | 23.9k | pstr_aac_dec_ch_info->str_ics_info; |
713 | | |
714 | 23.9k | ixheaacd_read_ms_data(it_bit_buff, pstr_aac_dec_ch_info); |
715 | | |
716 | 23.9k | { |
717 | 23.9k | if (object_type == AOT_ER_AAC_LD) { |
718 | 8.21k | IA_ERRORCODE temp = |
719 | 8.21k | ixheaacd_ltp_decode(it_bit_buff, ptr_ics_info, object_type, |
720 | 8.21k | aac_dec_handle->samples_per_frame, LEFT); |
721 | | |
722 | 8.21k | if (temp != 0) { |
723 | 1 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
724 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
725 | 1 | } else { |
726 | 1 | return temp; |
727 | 1 | } |
728 | 1 | } |
729 | 8.21k | } |
730 | 23.9k | } |
731 | 23.9k | } |
732 | 59.6k | } |
733 | | |
734 | 191k | error_code = ixheaacd_individual_ch_stream( |
735 | 191k | it_bit_buff, aac_dec_handle, ele_ch, frame_length, total_channels, object_type, |
736 | 191k | eld_specific_config, ele_type); |
737 | 191k | if (error_code) { |
738 | 3.41k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
739 | 0 | aac_dec_handle->frame_status = 0; |
740 | 3.41k | } else { |
741 | 3.41k | return error_code; |
742 | 3.41k | } |
743 | 3.41k | } |
744 | | |
745 | 187k | if (ptr_adts_crc_info->crc_active == 1) { |
746 | 0 | ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg); |
747 | 0 | } |
748 | | |
749 | 187k | if (it_bit_buff->cnt_bits < 0) { |
750 | 41 | error_code = |
751 | 41 | (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
752 | 41 | } |
753 | | |
754 | 187k | if (error_code) { |
755 | 41 | goto _ia_handle_error1; |
756 | 41 | } |
757 | | |
758 | 220k | _ia_handle_error1: |
759 | 220k | if (error_code) { |
760 | 33.7k | aac_dec_handle->frame_status = 0; |
761 | 33.7k | if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) num_ch = num_ch + ele_ch; |
762 | 33.7k | break; |
763 | 187k | } else { |
764 | 187k | error_code = ixheaacd_channel_pair_process( |
765 | 187k | aac_dec_handle->pstr_aac_dec_ch_info, ele_ch, aac_dec_handle->pstr_aac_tables, |
766 | 187k | total_channels, object_type, aac_spect_data_resil_flag, |
767 | 187k | eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data, |
768 | 187k | aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle); |
769 | 187k | if (error_code) { |
770 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
771 | 0 | aac_dec_handle->frame_status = 0; |
772 | 0 | } else { |
773 | 0 | return error_code; |
774 | 0 | } |
775 | 0 | } |
776 | 187k | num_ch = num_ch + ele_ch; |
777 | 187k | } |
778 | 220k | } |
779 | | |
780 | 187k | p_obj_exhaacplus_dec->aac_config.element_type[*ch_idx] = ele_ch - 1; |
781 | 187k | break; |
782 | 224k | } |
783 | | |
784 | 220k | if ((object_type == AOT_ER_AAC_LC) || (!eld_sbr_flag)) { |
785 | 138k | WORD32 cnt_bits; |
786 | 138k | cnt_bits = it_bit_buff->cnt_bits; |
787 | 138k | p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.ldmps_config.no_ldsbr_present = 1; |
788 | | |
789 | 138k | if (cnt_bits >= 8) { |
790 | 137k | error_code = ixheaacd_extension_payload( |
791 | 137k | it_bit_buff, &cnt_bits, &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle); |
792 | 137k | if (error_code) { |
793 | 88 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
794 | 0 | aac_dec_handle->frame_status = 0; |
795 | 88 | } else { |
796 | 88 | return error_code; |
797 | 88 | } |
798 | 88 | } |
799 | 137k | } |
800 | | |
801 | 138k | if (it_bit_buff->cnt_bits) { |
802 | 10.3k | WORD32 alignment = it_bit_buff->bit_pos & 0x07; |
803 | 10.3k | it_bit_buff->cnt_bits = (it_bit_buff->cnt_bits + alignment) & 7; |
804 | 10.3k | it_bit_buff->bit_pos = 7; |
805 | 10.3k | it_bit_buff->ptr_read_next++; |
806 | 10.3k | } |
807 | 138k | } |
808 | | |
809 | 82.6k | else if ((object_type != AOT_ER_AAC_ELD) || (!eld_sbr_flag)) { |
810 | 0 | WORD32 bits_decoded, cnt_bits; |
811 | 0 | bits_decoded = (it_bit_buff->size - it_bit_buff->cnt_bits); |
812 | |
|
813 | 0 | cnt_bits = (frame_size * 8 - bits_decoded); |
814 | |
|
815 | 0 | if (object_type == AOT_ER_AAC_LC) cnt_bits = it_bit_buff->cnt_bits; |
816 | |
|
817 | 0 | p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.ldmps_config.no_ldsbr_present = 1; |
818 | |
|
819 | 0 | if (cnt_bits >= 8) { |
820 | 0 | error_code = ixheaacd_extension_payload( |
821 | 0 | it_bit_buff, &cnt_bits, &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle); |
822 | 0 | if (error_code) { |
823 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
824 | 0 | aac_dec_handle->frame_status = 0; |
825 | 0 | } else { |
826 | 0 | return error_code; |
827 | 0 | } |
828 | 0 | } |
829 | 0 | } |
830 | | |
831 | 0 | if (((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD)) && |
832 | 0 | (p_obj_exhaacplus_dec->aac_config.ld_decoder != 1)) { |
833 | 0 | if (it_bit_buff->cnt_bits) { |
834 | 0 | WORD32 alignment = it_bit_buff->bit_pos & 0x07; |
835 | 0 | it_bit_buff->cnt_bits = (it_bit_buff->cnt_bits + alignment) & 7; |
836 | 0 | it_bit_buff->bit_pos = 7; |
837 | 0 | it_bit_buff->ptr_read_next++; |
838 | 0 | } |
839 | 0 | } else { |
840 | 0 | if (it_bit_buff->bit_pos != 7) { |
841 | 0 | WORD32 alignment = it_bit_buff->bit_pos & 0x07; |
842 | 0 | it_bit_buff->cnt_bits -= alignment + 1; |
843 | 0 | it_bit_buff->bit_pos += 7 - alignment; |
844 | 0 | it_bit_buff->ptr_read_next++; |
845 | 0 | } |
846 | 0 | } |
847 | 82.6k | } else { |
848 | 82.6k | WORD32 bits_decoded, cnt_bits; |
849 | 82.6k | bits_decoded = (it_bit_buff->size - it_bit_buff->cnt_bits); |
850 | 82.6k | cnt_bits = (frame_size * 8 - bits_decoded); |
851 | 82.6k | if (adtsheader == 1) { |
852 | 0 | if (cnt_bits > it_bit_buff->cnt_bits) { |
853 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
854 | 0 | aac_dec_handle->frame_status = 0; |
855 | 0 | } else { |
856 | 0 | return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES; |
857 | 0 | } |
858 | 0 | } |
859 | 0 | } |
860 | 82.6k | ixheaacd_check_for_sbr_payload( |
861 | 82.6k | it_bit_buff, aac_dec_handle->pstr_sbr_bitstream, (WORD16)(ch_config - 1), |
862 | 82.6k | pstr_drc_dec, object_type, adtsheader, cnt_bits, ld_sbr_crc_flag, drc_dummy, |
863 | 82.6k | mps_buffer, mps_header, mps_bytes, is_init, &aac_dec_handle->is_first, |
864 | 82.6k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal); |
865 | 82.6k | } |
866 | 220k | } |
867 | 220k | } |
868 | 310k | } |
869 | 304k | if ((err || (aac_dec_handle->frame_status == 0) || (frame_status == 0)) && (!is_init)) { |
870 | 33.7k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
871 | 0 | aac_dec_handle->frame_status = 0; |
872 | 0 | error_code = 0; |
873 | 0 | num_ch = channel; |
874 | 0 | ele_type = ID_END; |
875 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
876 | 0 | it_bit_buff->cnt_bits = 0; |
877 | 0 | aac_dec_handle->byte_align_bits = 0; |
878 | 33.7k | } else { |
879 | 33.7k | return err; |
880 | 33.7k | } |
881 | 33.7k | } |
882 | 270k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && aac_dec_handle->conceal_count == 0) { |
883 | 0 | for (ch = 0; ch < channel; ch++) { |
884 | 0 | ixheaacd_aac_ec_init(&aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->str_ec_state); |
885 | 0 | } |
886 | 0 | } |
887 | | |
888 | 270k | if (ele_type == ID_END && p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) { |
889 | 12.8k | WORD32 tmp; |
890 | 12.8k | tmp = ((WORD32)latm_element->layer_info[0][0].frame_len_bits) - |
891 | 12.8k | (it_bit_buff->initial_cnt_bits - it_bit_buff->cnt_bits); |
892 | | |
893 | 12.8k | if (tmp > 0) ixheaacd_read_bidirection(it_bit_buff, tmp); |
894 | | |
895 | 12.8k | if (latm_element->other_data_present) { |
896 | 3.03k | WORD32 count_bits = (WORD32)latm_element->other_data_length; |
897 | 3.03k | ixheaacd_read_bidirection(it_bit_buff, count_bits); |
898 | 3.03k | } |
899 | 12.8k | } |
900 | | |
901 | 270k | if (object_type == AOT_ER_AAC_LD) { |
902 | 174k | for (ch = 0; ch < channel; ch++) { |
903 | 92.8k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1 = |
904 | 92.8k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.lag; |
905 | 92.8k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_2 = |
906 | 92.8k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.lag; |
907 | 92.8k | } |
908 | 81.5k | } |
909 | 270k | aac_dec_handle->frame_status = aac_dec_handle->frame_status && frame_status; |
910 | | |
911 | 270k | aac_dec_handle->channels = num_ch; |
912 | | |
913 | 270k | if (error_code == 0) |
914 | 270k | if ((skip_full_decode == 0) || ((skip_full_decode == 1) && error_code)) { |
915 | 270k | ia_ics_info_struct str_ics_info[2]; |
916 | 270k | WORD32 *spec_coef[2]; |
917 | 270k | WORD32 *scratch[2]; |
918 | | |
919 | 580k | for (ch = 0; ch < channel; ch++) { |
920 | 310k | str_ics_info[ch] = aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info; |
921 | 310k | spec_coef[ch] = aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff; |
922 | 310k | } |
923 | | |
924 | 270k | scratch[0] = (WORD32 *)aac_scratch_ptrs->extra_scr_4k[2]; |
925 | 270k | scratch[1] = (WORD32 *)aac_scratch_ptrs->extra_scr_4k[1]; |
926 | | |
927 | 270k | error_code = ixheaacd_drc_map_channels( |
928 | 270k | pstr_drc_dec, aac_dec_handle->channels, |
929 | 270k | aac_dec_handle->pstr_aac_dec_ch_info[0]->str_ics_info.frame_length); |
930 | 270k | if (error_code) { |
931 | 2 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
932 | 0 | error_code = 0; |
933 | 0 | aac_dec_handle->frame_status = 0; |
934 | 2 | } else { |
935 | 2 | return error_code; |
936 | 2 | } |
937 | 2 | } |
938 | | |
939 | 567k | for (ch = 0; ch < aac_dec_handle->channels; ch++) { |
940 | 297k | WORD32 *overlap1 = |
941 | 297k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->overlap_add_data.ptr_overlap_buf; |
942 | 297k | const WORD16 *ptr_long_window_next = |
943 | 297k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
944 | 297k | ->ptr_long_window[(int)str_ics_info[ch].window_shape]; |
945 | 297k | const WORD16 *ptr_short_window_next = |
946 | 297k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
947 | 297k | ->ptr_short_window[(int)str_ics_info[ch].window_shape]; |
948 | 297k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
949 | 0 | ia_aac_dec_channel_info_struct *pstr_aac_dec_channel_info = |
950 | 0 | aac_dec_handle->pstr_aac_dec_ch_info[ch]; |
951 | 0 | ia_aac_dec_channel_info *pstr_aac_dec_static_channel_info = |
952 | 0 | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]; |
953 | |
|
954 | 0 | ia_aac_dec_channel_info_struct **ppstr_aac_dec_channel_info = |
955 | 0 | &pstr_aac_dec_channel_info; |
956 | 0 | ia_aac_dec_channel_info **ppstr_aac_dec_static_channel_info = |
957 | 0 | &pstr_aac_dec_static_channel_info; |
958 | 0 | ia_audio_specific_config_struct *pstr_audio_specific_config; |
959 | 0 | pstr_audio_specific_config = p_state_enhaacplus_dec->ia_audio_specific_config; |
960 | |
|
961 | 0 | if (str_ics_info[ch].max_sfb > str_ics_info[ch].num_swb_window) { |
962 | 0 | aac_dec_handle->frame_status = 0; |
963 | 0 | } |
964 | |
|
965 | 0 | ixheaacd_aac_apply_ec( |
966 | 0 | &(*ppstr_aac_dec_static_channel_info)->str_ec_state, *ppstr_aac_dec_channel_info, |
967 | 0 | &ixheaacd_samp_rate_info[pstr_audio_specific_config->samp_frequency_index], |
968 | 0 | aac_dec_handle->samples_per_frame, &str_ics_info[ch], aac_dec_handle->frame_status); |
969 | |
|
970 | 0 | aac_dec_handle->conceal_count = aac_dec_handle->conceal_count + 1; |
971 | 0 | if (aac_dec_handle->frame_status) { |
972 | 0 | aac_dec_handle->sbr_num_elements = aac_dec_handle->pstr_sbr_bitstream->no_elements; |
973 | 0 | } else { |
974 | 0 | aac_dec_handle->pstr_sbr_bitstream->no_elements = aac_dec_handle->sbr_num_elements; |
975 | 0 | } |
976 | 0 | if (first_frame == 1) |
977 | 0 | skip_full_decode = 1; |
978 | 0 | else |
979 | 0 | skip_full_decode = 0; |
980 | 0 | } |
981 | 297k | if (pstr_drc_dec->drc_on) { |
982 | 297k | ixheaacd_drc_apply(pstr_drc_dec, spec_coef[ch], |
983 | 297k | str_ics_info[ch].window_sequence, ch, |
984 | 297k | str_ics_info[ch].frame_length, |
985 | 297k | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr, object_type); |
986 | 297k | } |
987 | 297k | if (skip_full_decode == 0) { |
988 | 297k | ixheaacd_imdct_process(aac_dec_handle->pstr_aac_dec_overlap_info[ch], |
989 | 297k | spec_coef[ch], &str_ics_info[ch], |
990 | 297k | time_data + slot_element, ch_fac, scratch[ch], |
991 | 297k | aac_dec_handle->pstr_aac_tables, object_type, |
992 | 297k | ldmps_present, slot_element); |
993 | | |
994 | 297k | if (slot_pos != NULL) *slot_pos = slot_element; |
995 | 297k | if (p_obj_exhaacplus_dec->p_state_aac->qshift_cnt > 15) { |
996 | 2 | return IA_FATAL_ERROR; |
997 | 2 | } |
998 | | |
999 | 297k | p_obj_exhaacplus_dec->p_state_aac |
1000 | 297k | ->qshift_adj[p_obj_exhaacplus_dec->p_state_aac->qshift_cnt++] = |
1001 | 297k | str_ics_info[ch].qshift_adj; |
1002 | | |
1003 | 297k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
1004 | 297k | ->overlap_add_data.win_shape = str_ics_info[ch].window_shape; |
1005 | 297k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
1006 | 297k | ->overlap_add_data.win_seq = str_ics_info[ch].window_sequence; |
1007 | 297k | if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) { |
1008 | 124k | { |
1009 | 124k | if ((str_ics_info[ch].window_sequence == ONLY_LONG_SEQUENCE) || |
1010 | 83.7k | (str_ics_info[ch].window_sequence == LONG_STOP_SEQUENCE)) { |
1011 | 83.7k | ixheaacd_lt_update_state( |
1012 | 83.7k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
1013 | 83.7k | ->ltp_buf, |
1014 | 83.7k | time_data + slot_element, overlap1, |
1015 | 83.7k | aac_dec_handle->samples_per_frame, object_type, |
1016 | 83.7k | (WORD16)ch_fac, str_ics_info[ch].window_sequence, |
1017 | 83.7k | (WORD16 *)ptr_long_window_next, slot_element); |
1018 | 83.7k | } else { |
1019 | 40.9k | ixheaacd_lt_update_state( |
1020 | 40.9k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
1021 | 40.9k | ->ltp_buf, |
1022 | 40.9k | time_data + slot_element, overlap1, |
1023 | 40.9k | aac_dec_handle->samples_per_frame, object_type, |
1024 | 40.9k | (WORD16)ch_fac, str_ics_info[ch].window_sequence, |
1025 | 40.9k | (WORD16 *)ptr_short_window_next, slot_element); |
1026 | 40.9k | } |
1027 | 124k | } |
1028 | 124k | } |
1029 | 297k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
1030 | 0 | ia_aac_dec_channel_info *pstr_aac_dec_static_channel_info = |
1031 | 0 | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]; |
1032 | 0 | ia_ec_state_str *pstr_ec_state = &pstr_aac_dec_static_channel_info->str_ec_state; |
1033 | 0 | WORD32 k; |
1034 | |
|
1035 | 0 | if (pstr_ec_state->fade_idx < MAX_FADE_FRAMES) { |
1036 | 0 | WORD32 fade_fac = ia_ec_fade_factors_fix[pstr_ec_state->fade_idx]; |
1037 | 0 | for (k = 0; k < str_ics_info[ch].frame_length; k++) { |
1038 | 0 | time_data[k] = ixheaac_mul32_sh(time_data[k], fade_fac, 30); |
1039 | 0 | } |
1040 | 0 | } else { |
1041 | 0 | memset(time_data, 0, str_ics_info[ch].frame_length * sizeof(time_data[0])); |
1042 | 0 | } |
1043 | 0 | } |
1044 | 297k | slot_element++; |
1045 | 297k | } |
1046 | 297k | } |
1047 | 270k | } |
1048 | | |
1049 | 270k | if (ele_type == ID_END) { |
1050 | 60.1k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
1051 | 0 | if (err && !is_init) { |
1052 | 0 | aac_dec_handle->frame_status = 0; |
1053 | 0 | } else { |
1054 | 0 | ixheaacd_byte_align(it_bit_buff, &aac_dec_handle->byte_align_bits); |
1055 | 0 | if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) { |
1056 | 0 | ixheaacd_byte_align(it_bit_buff, &it_bit_buff->audio_mux_align); |
1057 | 0 | } |
1058 | 0 | } |
1059 | 60.1k | } else { |
1060 | 60.1k | ixheaacd_byte_align(it_bit_buff, &aac_dec_handle->byte_align_bits); |
1061 | 60.1k | if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) { |
1062 | 12.8k | ixheaacd_byte_align(it_bit_buff, &it_bit_buff->audio_mux_align); |
1063 | 12.8k | } |
1064 | 60.1k | } |
1065 | 60.1k | } |
1066 | 270k | *type = ele_type; |
1067 | | |
1068 | 270k | aac_dec_handle->block_number = |
1069 | 270k | ixheaac_add32(aac_dec_handle->block_number, 1); |
1070 | 270k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
1071 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = aac_dec_handle->frame_status; |
1072 | 0 | return IA_NO_ERROR; |
1073 | 270k | } else { |
1074 | 270k | return error_code; |
1075 | 270k | } |
1076 | 270k | } |
1077 | | |
1078 | | WORD32 ixheaacd_extension_payload(ia_bit_buf_struct *it_bit_buff, WORD32 *cnt, |
1079 | 146k | ia_mps_dec_state_struct *self) { |
1080 | 146k | WORD16 extension_type; |
1081 | 146k | WORD32 len, add_len; |
1082 | 146k | WORD32 i; |
1083 | 146k | WORD32 fill_nibble; |
1084 | | |
1085 | 146k | WORD32 err = 0; |
1086 | 146k | extension_type = (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4); |
1087 | 146k | switch (extension_type) { |
1088 | 8.05k | case EXT_FILL_DATA: |
1089 | | |
1090 | 8.05k | fill_nibble = ixheaacd_read_bits_buf(it_bit_buff, 4); |
1091 | | |
1092 | 8.05k | if (fill_nibble == 0) { |
1093 | 23.3M | for (i = 0; i < (*cnt >> 3) - 1; i++) { |
1094 | 23.3M | if (it_bit_buff->cnt_bits >= 8) |
1095 | 23.3M | ixheaacd_read_bits_buf(it_bit_buff, 8); |
1096 | 432 | else |
1097 | 432 | ixheaacd_read_bits_buf(it_bit_buff, it_bit_buff->cnt_bits); |
1098 | 23.3M | } |
1099 | | |
1100 | 4.55k | } else |
1101 | 3.49k | err = -1; |
1102 | 8.05k | *cnt = it_bit_buff->cnt_bits; |
1103 | 8.05k | break; |
1104 | | |
1105 | 2.09k | case EXT_DATA_LENGTH: |
1106 | | |
1107 | 2.09k | len = ixheaacd_read_bits_buf(it_bit_buff, 4); |
1108 | | |
1109 | 2.09k | if (len == 15) { |
1110 | 469 | add_len = ixheaacd_read_bits_buf(it_bit_buff, 8); |
1111 | 469 | len += add_len; |
1112 | | |
1113 | 469 | if (add_len == 255) { |
1114 | 104 | len += ixheaacd_read_bits_buf(it_bit_buff, 16); |
1115 | 104 | } |
1116 | 469 | } |
1117 | 2.09k | len <<= 3; |
1118 | | |
1119 | 2.09k | ixheaacd_extension_payload(it_bit_buff, cnt, self); |
1120 | 2.09k | break; |
1121 | | |
1122 | 8.95k | case EXT_LDSAC_DATA: |
1123 | | |
1124 | 8.95k | self->parse_nxt_frame = 1; |
1125 | 8.95k | ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_type*/ |
1126 | 8.95k | ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_start_stop*/ |
1127 | | |
1128 | 8.95k | if (self->ldmps_config.ldmps_present_flag == 1) { |
1129 | 2.89k | err = ixheaacd_ld_mps_frame_parsing(self, it_bit_buff); |
1130 | 2.89k | if (err) return err; |
1131 | 2.89k | } |
1132 | | |
1133 | 8.90k | *cnt = it_bit_buff->cnt_bits; |
1134 | 8.90k | break; |
1135 | 59.7k | case EXT_FIL: |
1136 | 127k | default: |
1137 | | |
1138 | 5.39G | for (i = 0; i < (*cnt) - 4; i++) { |
1139 | 5.39G | ixheaacd_skip_bits_buf(it_bit_buff, 1);/*discard*/ |
1140 | 5.39G | } |
1141 | | |
1142 | 127k | *cnt = it_bit_buff->cnt_bits; |
1143 | 127k | break; |
1144 | 146k | } |
1145 | | |
1146 | 144k | return err; |
1147 | 146k | } |