/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.28M | #define SIZEOF_INT(x) ((sizeof(x) + sizeof(WORD32) - 1) / sizeof(WORD32)) |
92 | | |
93 | 5.25k | #define EXT_FILL_DATA 1 |
94 | 45.3k | #define EXT_FIL 0 |
95 | 1.80k | #define EXT_DATA_LENGTH 3 |
96 | 5.33k | #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 | 225k | WORD32 *mps_header, WORD32 *mps_bytes, WORD32 is_init, WORD32 first_frame) { |
111 | 225k | WORD ch, ele_type; |
112 | 225k | ia_aac_dec_state_struct *p_state_enhaacplus_dec; |
113 | 225k | ia_aac_decoder_struct *aac_dec_handle; |
114 | 225k | ia_bit_buf_struct *it_bit_buff; |
115 | 225k | ixheaacd_latm_struct *latm_element; |
116 | | |
117 | 225k | WORD error_code = (WORD)frame_status; |
118 | 225k | WORD previous_element; |
119 | 225k | WORD prev_data_ele_present = 0; |
120 | 225k | WORD new_element; |
121 | 225k | WORD32 num_ch = 0; |
122 | | |
123 | 225k | WORD32 crc_reg = 0; |
124 | 225k | ia_adts_crc_info_struct *ptr_adts_crc_info; |
125 | | |
126 | 225k | WORD32 cnt_bits = 0; |
127 | | |
128 | 225k | WORD32 eld_sbr_flag = eld_specific_config.ld_sbr_flag_present; |
129 | 225k | WORD32 ld_sbr_crc_flag = eld_specific_config.ld_sbr_crc_flag; |
130 | 225k | WORD32 aac_spect_data_resil_flag = |
131 | 225k | eld_specific_config.aac_spect_data_resil_flag; |
132 | | |
133 | 225k | WORD32 ele_ch = 0; |
134 | | |
135 | 225k | ia_aac_sfb_code_book_struct *ptr_aac_sfb_code_book_data[CHANNELS]; |
136 | 225k | ia_pns_stereo_data_struct *ptr_pns_stereo_data; |
137 | | |
138 | 225k | WORD32 *work_buffer_core = aac_scratch_ptrs->base_scr_8k; |
139 | 225k | WORD32 *work_buffer_1 = aac_scratch_ptrs->extra_scr_4k[0]; |
140 | 225k | WORD32 *work_buffer_2 = aac_scratch_ptrs->extra_scr_4k[2]; |
141 | 225k | p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac; |
142 | | |
143 | 225k | WORD32 *time_data = (WORD32 *)time_data_tmp; |
144 | | |
145 | 225k | aac_dec_handle = p_state_enhaacplus_dec->pstr_aac_dec_info[*ch_idx]; |
146 | 225k | it_bit_buff = p_state_enhaacplus_dec->ptr_bit_stream; |
147 | 225k | p_obj_exhaacplus_dec->aac_config.str_prog_config.alignment_bits = it_bit_buff->bit_pos; |
148 | | |
149 | 225k | ptr_adts_crc_info = it_bit_buff->pstr_adts_crc_info; |
150 | | |
151 | 225k | latm_element = &p_state_enhaacplus_dec->latm_struct_element; |
152 | | |
153 | 225k | ptr_pns_stereo_data = |
154 | 225k | (ia_pns_stereo_data_struct |
155 | 225k | *)&work_buffer_1[2 * SIZEOF_INT(ia_aac_dec_channel_info_struct) + |
156 | 225k | 2 * SIZEOF_INT(ia_aac_sfb_code_book_struct)]; |
157 | | |
158 | 225k | aac_dec_handle->frame_status = 1; |
159 | | |
160 | 504k | for (ch = 0; ch < channel; ch++) { |
161 | 279k | const ia_aac_dec_imdct_tables_struct *pstr_imdct_tables; |
162 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch] = |
163 | 279k | (ia_aac_dec_channel_info_struct |
164 | 279k | *)&work_buffer_1[ch * SIZEOF_INT(ia_aac_dec_channel_info_struct)]; |
165 | 279k | ptr_aac_sfb_code_book_data[ch] = |
166 | 279k | (ia_aac_sfb_code_book_struct |
167 | 279k | *)&work_buffer_1[2 * SIZEOF_INT(ia_aac_dec_channel_info_struct) + |
168 | 279k | (ch * SIZEOF_INT(ia_aac_sfb_code_book_struct))]; |
169 | | |
170 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_scale_factor = |
171 | 279k | ptr_aac_sfb_code_book_data[ch]->scale_factor; |
172 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_code_book = |
173 | 279k | ptr_aac_sfb_code_book_data[ch]->code_book; |
174 | | |
175 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff = |
176 | 279k | &work_buffer_core[ch * MAX_BINS_LONG]; |
177 | | |
178 | 279k | if (object_type == AOT_ER_AAC_ELD) { |
179 | 88.1k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff = |
180 | 88.1k | &work_buffer_core[2 * ch * MAX_BINS_LONG]; |
181 | 88.1k | } |
182 | | |
183 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_stereo_info = |
184 | 279k | &ptr_pns_stereo_data->str_stereo_info; |
185 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_pns_corr_info = |
186 | 279k | &ptr_pns_stereo_data->str_pns_corr_info; |
187 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->pstr_pns_rand_vec_data = |
188 | 279k | aac_dec_handle->pstr_pns_rand_vec_data; |
189 | | |
190 | 279k | pstr_imdct_tables = aac_dec_handle->pstr_aac_tables->pstr_imdct_tables; |
191 | | |
192 | 279k | if (960 != frame_length) { |
193 | 219k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
194 | 219k | pstr_imdct_tables->only_long_window_sine; |
195 | 219k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[0] = |
196 | 219k | pstr_imdct_tables->only_short_window_sine; |
197 | 219k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
198 | 219k | pstr_imdct_tables->only_long_window_kbd; |
199 | 219k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[1] = |
200 | 219k | pstr_imdct_tables->only_short_window_kbd; |
201 | | |
202 | 219k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[0] = |
203 | 219k | pstr_imdct_tables->only_long_window_sine; |
204 | 219k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[0] = |
205 | 219k | pstr_imdct_tables->only_short_window_sine; |
206 | 219k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[1] = |
207 | 219k | pstr_imdct_tables->only_long_window_kbd; |
208 | 219k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[1] = |
209 | 219k | pstr_imdct_tables->only_short_window_kbd; |
210 | 219k | } else { |
211 | 59.5k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
212 | 59.5k | pstr_imdct_tables->only_long_window_sine_960; |
213 | 59.5k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[0] = |
214 | 59.5k | pstr_imdct_tables->only_short_window_sine_120; |
215 | 59.5k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
216 | 59.5k | pstr_imdct_tables->only_long_window_kbd_960; |
217 | 59.5k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_short_window[1] = |
218 | 59.5k | pstr_imdct_tables->only_short_window_kbd_120; |
219 | | |
220 | 59.5k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[0] = |
221 | 59.5k | pstr_imdct_tables->only_long_window_sine_960; |
222 | 59.5k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[0] = |
223 | 59.5k | pstr_imdct_tables->only_short_window_sine_120; |
224 | 59.5k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_long_window[1] = |
225 | 59.5k | pstr_imdct_tables->only_long_window_kbd_960; |
226 | 59.5k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ptr_short_window[1] = |
227 | 59.5k | pstr_imdct_tables->only_short_window_kbd_120; |
228 | 59.5k | } |
229 | | |
230 | 279k | 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 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.frame_length = frame_length; |
236 | 279k | if (object_type == AOT_ER_AAC_ELD || object_type == AOT_ER_AAC_LD || |
237 | 191k | object_type == AOT_AAC_LTP) { |
238 | 191k | if (512 == aac_dec_handle->samples_per_frame) { |
239 | 119k | if (object_type != AOT_ER_AAC_ELD) { |
240 | 60.2k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
241 | 60.2k | (WORD16 *)pstr_imdct_tables->low_overlap_win; |
242 | 60.2k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
243 | 60.2k | (WORD16 *)pstr_imdct_tables->window_sine_512; |
244 | | |
245 | 60.2k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
246 | 60.2k | ->ptr_long_window[1] = |
247 | 60.2k | (WORD16 *)pstr_imdct_tables->low_overlap_win; |
248 | 60.2k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
249 | 60.2k | ->ptr_long_window[0] = |
250 | 60.2k | (WORD16 *)pstr_imdct_tables->window_sine_512; |
251 | 60.2k | } else { |
252 | 58.8k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
253 | 58.8k | (WORD16 *)pstr_imdct_tables->window_sine_512_eld; |
254 | 58.8k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
255 | 58.8k | (WORD16 *)pstr_imdct_tables->window_sine_512_eld; |
256 | 58.8k | } |
257 | 119k | } else if (480 == aac_dec_handle->samples_per_frame) { |
258 | 45.1k | if (object_type != AOT_ER_AAC_ELD) { |
259 | 15.9k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
260 | 15.9k | (WORD16 *)pstr_imdct_tables->low_overlap_win_480; |
261 | 15.9k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
262 | 15.9k | (WORD16 *)pstr_imdct_tables->window_sine_480; |
263 | | |
264 | 15.9k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
265 | 15.9k | ->ptr_long_window[1] = |
266 | 15.9k | (WORD16 *)pstr_imdct_tables->low_overlap_win_480; |
267 | 15.9k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
268 | 15.9k | ->ptr_long_window[0] = |
269 | 15.9k | (WORD16 *)pstr_imdct_tables->window_sine_480; |
270 | | |
271 | 29.2k | } else { |
272 | 29.2k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[1] = |
273 | 29.2k | (WORD16 *)pstr_imdct_tables->window_sine_480_eld; |
274 | 29.2k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]->ptr_long_window[0] = |
275 | 29.2k | (WORD16 *)pstr_imdct_tables->window_sine_480_eld; |
276 | 29.2k | } |
277 | 45.1k | } |
278 | 191k | } |
279 | 279k | if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) { |
280 | 102k | if (aac_dec_handle->samples_per_frame <= 512) { |
281 | 76.1k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.lag = |
282 | 76.1k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1; |
283 | 76.1k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.lag = |
284 | 76.1k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_2; |
285 | 76.1k | } |
286 | 102k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ltp_buf = |
287 | 102k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_buf; |
288 | 102k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->ltp_lag = |
289 | 102k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1; |
290 | 102k | } |
291 | | |
292 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->scratch_buf_ptr = work_buffer_2; |
293 | 279k | if (object_type == AOT_ER_AAC_ELD) { |
294 | 88.1k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->pulse_scratch = |
295 | 88.1k | aac_scratch_ptrs->extra_scr_4k[3]; |
296 | 88.1k | } |
297 | 279k | } |
298 | | |
299 | 225k | if (channel == 2) { |
300 | 53.5k | if (aac_dec_handle->pstr_aac_dec_ch_info[1]->ptr_spec_coeff == |
301 | 53.5k | 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 | 53.5k | } |
306 | | |
307 | 504k | for (ch = 0; ch < channel; ch++) { |
308 | 279k | ia_pns_info_struct *ptr_pns_info = |
309 | 279k | &aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_pns_info; |
310 | 279k | memset(ptr_pns_info, 0, sizeof(ia_pns_info_struct)); |
311 | 279k | } |
312 | | |
313 | 225k | if (channel > 0) { |
314 | 225k | ia_pns_correlation_info_struct *ptr_corr_info = |
315 | 225k | aac_dec_handle->pstr_aac_dec_ch_info[0]->pstr_pns_corr_info; |
316 | 225k | memset(ptr_corr_info->correlated, 0, sizeof(UWORD8) * PNS_BAND_FLAGS_SIZE); |
317 | 225k | } |
318 | | |
319 | 504k | for (ch = 0; ch < channel; ch++) { |
320 | 279k | memset(&aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_hcr_info, 0, |
321 | 279k | sizeof(ia_hcr_info_struct)); |
322 | 279k | ixheaacd_huff_code_reorder_tbl_init( |
323 | 279k | &aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_hcr_info); |
324 | 279k | } |
325 | | |
326 | 504k | for (ch = 0; ch < channel; ch++) { |
327 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.data_present = 0; |
328 | 279k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.data_present = |
329 | 279k | 0; |
330 | 279k | } |
331 | | |
332 | 504k | for (ch = 0; ch < channel; ch++) { |
333 | 279k | if (object_type == AOT_ER_AAC_ELD || object_type == AOT_ER_AAC_LD) |
334 | 164k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->granule_len = |
335 | 164k | aac_dec_handle->samples_per_frame; |
336 | 279k | if (object_type == AOT_ER_AAC_LC) |
337 | 43.5k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->granule_len = |
338 | 43.5k | aac_dec_handle->samples_per_frame / 8; |
339 | 279k | } |
340 | 225k | previous_element = ID_END; |
341 | | |
342 | 225k | aac_dec_handle->pstr_sbr_bitstream->no_elements = 0; |
343 | 225k | new_element = 0; |
344 | 225k | ele_type = *type; |
345 | | |
346 | 225k | cnt_bits = it_bit_buff->cnt_bits; |
347 | | |
348 | 225k | WORD32 err = 0; |
349 | 225k | jmp_buf local; |
350 | | |
351 | 225k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
352 | 0 | err = setjmp(local); |
353 | 0 | } |
354 | | |
355 | 225k | if (!err && frame_status) { |
356 | 225k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
357 | 0 | it_bit_buff->xaac_jmp_buf = &local; |
358 | 0 | } |
359 | | |
360 | 225k | if (((object_type != AOT_ER_AAC_ELD) && (object_type != AOT_ER_AAC_LD) && |
361 | 101k | (object_type != AOT_ER_AAC_LC)) || |
362 | 163k | (object_type < ER_OBJECT_START)) { |
363 | 206k | while (ele_type != ID_END && aac_dec_handle->frame_status) { |
364 | 163k | ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3); |
365 | 163k | ixheaacd_read_bidirection(it_bit_buff, -3); |
366 | | |
367 | 163k | 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 | 163k | if ((ele_type == ID_FIL) || (ele_type == ID_DSE) || (new_element == 0)) { |
374 | 102k | ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3); |
375 | 102k | new_element = 1; |
376 | 102k | } else if ((ele_type != ID_END)) { |
377 | 17.3k | ele_type = -1; |
378 | 17.3k | break; |
379 | 43.3k | } else { |
380 | 43.3k | ele_type = (WORD)ixheaacd_read_bits_buf(it_bit_buff, 3); |
381 | 43.3k | } |
382 | | |
383 | 145k | if (it_bit_buff->cnt_bits < 0) { |
384 | 0 | aac_dec_handle->frame_status = 0; |
385 | 0 | } |
386 | | |
387 | 145k | switch (ele_type) { |
388 | 46.7k | case ID_SCE: |
389 | 48.5k | case ID_CPE: |
390 | 61.0k | case ID_LFE: |
391 | | |
392 | 61.0k | if (aac_dec_handle->frame_status) { |
393 | 61.0k | ia_aac_dec_channel_info_struct *pstr_aac_dec_ch_info = |
394 | 61.0k | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]; |
395 | 61.0k | ia_ics_info_struct *ptr_ics_info = &pstr_aac_dec_ch_info->str_ics_info; |
396 | 61.0k | ele_ch = 1; |
397 | 61.0k | if (ele_type == ID_CPE) { |
398 | 1.78k | ele_ch = 2; |
399 | 59.2k | } else { |
400 | 59.2k | ele_ch = 1; |
401 | 59.2k | } |
402 | | |
403 | 61.0k | prev_data_ele_present = 1; |
404 | | |
405 | 61.0k | if (ptr_adts_crc_info->crc_active == 1 && ptr_adts_crc_info->no_reg < 7) { |
406 | 183 | crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff, |
407 | 183 | CRC_ADTS_RAW_DATA_BLK_LEN); |
408 | 183 | } |
409 | | |
410 | 61.0k | pstr_aac_dec_ch_info->element_instance_tag = |
411 | 61.0k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4); |
412 | | |
413 | 61.0k | element_index_order[*ch_idx] = pstr_aac_dec_ch_info->element_instance_tag; |
414 | 61.0k | pstr_aac_dec_ch_info->common_window = 0; |
415 | | |
416 | 61.0k | ptr_ics_info->num_swb_window = 0; |
417 | 61.0k | ptr_ics_info->sampling_rate_index = aac_dec_handle->sampling_rate_index; |
418 | 61.0k | if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) { |
419 | 24.5k | ptr_ics_info->ltp.data_present = 0; |
420 | 24.5k | ptr_ics_info->ltp2.data_present = 0; |
421 | 24.5k | ptr_ics_info->predictor_data_present = 0; |
422 | 24.5k | } |
423 | | |
424 | 61.0k | if (ele_ch > 1) { |
425 | 1.77k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.num_swb_window = 0; |
426 | 1.77k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.sampling_rate_index = |
427 | 1.77k | aac_dec_handle->sampling_rate_index; |
428 | | |
429 | 1.77k | pstr_aac_dec_ch_info->common_window = |
430 | 1.77k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 1); |
431 | | |
432 | 1.77k | if (pstr_aac_dec_ch_info->common_window) { |
433 | 681 | error_code = ixheaacd_ics_read( |
434 | 681 | it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, object_type, |
435 | 681 | pstr_aac_dec_ch_info->common_window, aac_dec_handle->samples_per_frame); |
436 | 681 | if (error_code) { |
437 | 15 | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info = |
438 | 15 | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->str_ics_info; |
439 | 15 | 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 | 15 | goto _ia_handle_error; |
445 | 15 | } |
446 | | |
447 | 666 | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info = |
448 | 666 | pstr_aac_dec_ch_info->str_ics_info; |
449 | | |
450 | 666 | ixheaacd_read_ms_data(it_bit_buff, pstr_aac_dec_ch_info); |
451 | 666 | } |
452 | 1.77k | } |
453 | | |
454 | 60.9k | error_code = ixheaacd_individual_ch_stream( |
455 | 60.9k | it_bit_buff, aac_dec_handle, ele_ch, frame_length, total_channels, object_type, |
456 | 60.9k | eld_specific_config, ele_type); |
457 | | |
458 | 60.9k | if (error_code) { |
459 | 708 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
460 | 0 | aac_dec_handle->frame_status = 0; |
461 | 708 | } else { |
462 | 708 | return error_code; |
463 | 708 | } |
464 | 708 | } |
465 | | |
466 | 60.2k | if (ptr_adts_crc_info->crc_active == 1) { |
467 | 187 | ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg); |
468 | 187 | } |
469 | | |
470 | 60.2k | if (it_bit_buff->cnt_bits < 0) { |
471 | 12 | error_code = |
472 | 12 | (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
473 | 12 | } |
474 | | |
475 | 60.2k | if (error_code) { |
476 | 12 | goto _ia_handle_error; |
477 | 12 | } |
478 | | |
479 | 60.2k | _ia_handle_error: |
480 | 59.9k | if (error_code) { |
481 | 27 | aac_dec_handle->frame_status = 0; |
482 | 27 | if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) num_ch = num_ch + ele_ch; |
483 | 27 | break; |
484 | 59.8k | } else { |
485 | 59.8k | error_code = ixheaacd_channel_pair_process( |
486 | 59.8k | aac_dec_handle->pstr_aac_dec_ch_info, ele_ch, aac_dec_handle->pstr_aac_tables, |
487 | 59.8k | total_channels, object_type, aac_spect_data_resil_flag, |
488 | 59.8k | eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data, |
489 | 59.8k | aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle); |
490 | 59.8k | 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 | 59.8k | num_ch = num_ch + ele_ch; |
498 | 59.8k | } |
499 | 59.9k | } |
500 | | |
501 | 59.8k | break; |
502 | 59.8k | case ID_CCE: |
503 | 858 | if (max_channels > 2) { |
504 | 858 | prev_data_ele_present = 1; |
505 | 858 | error_code = ixheaacd_dec_coupling_channel_element( |
506 | 858 | it_bit_buff, aac_dec_handle, aac_dec_handle->sampling_rate_index, |
507 | 858 | aac_dec_handle->pstr_aac_tables, aac_dec_handle->pstr_common_tables, |
508 | 858 | &element_index_order[*ch_idx], |
509 | 858 | (ia_enhaacplus_dec_ind_cc *)aac_dec_handle->p_ind_channel_info, total_channels, |
510 | 858 | frame_length, object_type, eld_specific_config, ele_type); |
511 | | |
512 | 858 | num_ch = num_ch + 1; |
513 | | |
514 | 858 | if (error_code) { |
515 | 34 | aac_dec_handle->frame_status = 0; |
516 | 34 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
517 | 0 | aac_dec_handle->frame_status = 0; |
518 | 34 | } else { |
519 | 34 | return error_code; |
520 | 34 | } |
521 | 824 | } else { |
522 | 824 | error_code = ixheaacd_channel_pair_process( |
523 | 824 | aac_dec_handle->pstr_aac_dec_ch_info, 1, aac_dec_handle->pstr_aac_tables, |
524 | 824 | total_channels, object_type, aac_spect_data_resil_flag, |
525 | 824 | eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data, |
526 | 824 | aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle); |
527 | 824 | 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 | 824 | } |
535 | 858 | } else { |
536 | 0 | error_code = (WORD32)((WORD32)IA_XHEAAC_DEC_EXE_FATAL_UNIMPLEMENTED_CCE); |
537 | 0 | } |
538 | 824 | 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 | 824 | break; |
543 | | |
544 | 5.67k | case ID_DSE: |
545 | 5.79k | case ID_PCE: |
546 | 40.6k | case ID_FIL: |
547 | | |
548 | 40.6k | { |
549 | 40.6k | WORD32 flag = 1; |
550 | | |
551 | 40.6k | if ((ele_type != ID_FIL) && (ptr_adts_crc_info->crc_active == 1) && |
552 | 159 | (ptr_adts_crc_info->no_reg < 7)) { |
553 | 57 | crc_reg = ixheaacd_adts_crc_start_reg(ptr_adts_crc_info, it_bit_buff, 0); |
554 | 57 | } |
555 | 40.6k | if (ele_type == ID_DSE) { |
556 | 5.67k | ixheaacd_read_data_stream_element(it_bit_buff, &aac_dec_handle->byte_align_bits, |
557 | 5.67k | p_obj_exhaacplus_dec->p_state_aac->pstr_drc_dec); |
558 | 5.67k | } |
559 | | |
560 | 34.9k | else if (ele_type == ID_PCE) { |
561 | 119 | error_code = ixheaacd_decode_pce( |
562 | 119 | it_bit_buff, &p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr, |
563 | 119 | &p_obj_exhaacplus_dec->aac_config.str_prog_config); |
564 | 119 | if (error_code != 0) { |
565 | 38 | 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 | 38 | aac_dec_handle->frame_status = 0; |
571 | 38 | if (error_code > 0) { |
572 | 9 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
573 | 0 | aac_dec_handle->frame_status = 0; |
574 | 9 | } else { |
575 | 9 | return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; |
576 | 9 | } |
577 | 29 | } else { |
578 | 29 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
579 | 0 | aac_dec_handle->frame_status = 0; |
580 | 29 | } else { |
581 | 29 | return error_code; |
582 | 29 | } |
583 | 29 | } |
584 | 38 | } |
585 | 119 | } |
586 | | |
587 | 34.8k | else if (ele_type == ID_FIL) { |
588 | 34.8k | WORD32 bits_decoded = 0; |
589 | 34.8k | 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 | 34.8k | if (ixheaacd_check_for_sbr_payload( |
604 | 34.8k | it_bit_buff, aac_dec_handle->pstr_sbr_bitstream, (WORD16)previous_element, |
605 | 34.8k | pstr_drc_dec, object_type, adtsheader, cnt_bits, ld_sbr_crc_flag, drc_dummy, |
606 | 34.8k | mps_buffer, mps_header, mps_bytes, is_init, &aac_dec_handle->is_first, |
607 | 34.8k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal)) { |
608 | 15.2k | flag = 0; |
609 | 15.2k | } |
610 | 34.8k | } |
611 | | |
612 | 40.6k | 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 | 40.6k | if (flag) { |
618 | 25.2k | if (prev_data_ele_present == 0) { |
619 | 1.98k | new_element = 0; |
620 | 1.98k | } |
621 | 25.2k | } |
622 | 40.6k | if ((ele_type != ID_FIL) && (ptr_adts_crc_info->crc_active == 1)) { |
623 | 149 | ixheaacd_adts_crc_end_reg(ptr_adts_crc_info, it_bit_buff, crc_reg); |
624 | 149 | } |
625 | | |
626 | 40.6k | if (ele_type == ID_PCE) { |
627 | 69 | if (ptr_adts_crc_info->str_crc_reg_data[crc_reg].bit_buf_cnt) { |
628 | 63 | ptr_adts_crc_info->str_crc_reg_data[crc_reg].max_bits = |
629 | 63 | ptr_adts_crc_info->str_crc_reg_data[crc_reg].bit_buf_cnt; |
630 | 63 | } |
631 | 69 | } |
632 | 40.6k | } |
633 | | |
634 | 0 | break; |
635 | | |
636 | 43.1k | case ID_END: |
637 | 43.1k | error_code = 0; |
638 | 43.1k | break; |
639 | 145k | } |
640 | | |
641 | 144k | previous_element = ele_type; |
642 | | |
643 | 144k | if (init_flag) { |
644 | 19.9k | if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) { |
645 | 7.50k | p_obj_exhaacplus_dec->aac_config.element_type[*ch_idx] = ele_type; |
646 | 7.50k | } |
647 | 19.9k | } |
648 | 144k | } |
649 | 163k | } else { |
650 | 163k | { |
651 | 163k | switch (ch_config) { |
652 | 163k | default: |
653 | 163k | if (aac_dec_handle->frame_status) { |
654 | 163k | ia_aac_dec_channel_info_struct *pstr_aac_dec_ch_info = |
655 | 163k | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]; |
656 | 163k | ia_ics_info_struct *ptr_ics_info = &pstr_aac_dec_ch_info->str_ics_info; |
657 | | |
658 | 163k | if (ch_config == 2) |
659 | 41.2k | ele_ch = 2, ele_type = 1; |
660 | 122k | else |
661 | 122k | ele_ch = 1, ele_type = 0; |
662 | | |
663 | 163k | prev_data_ele_present = 1; |
664 | | |
665 | 163k | 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 | 163k | if (object_type != AOT_ER_AAC_ELD) |
671 | 106k | pstr_aac_dec_ch_info->element_instance_tag = |
672 | 106k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4); |
673 | | |
674 | 163k | element_index_order[*ch_idx] = pstr_aac_dec_ch_info->element_instance_tag; |
675 | 163k | pstr_aac_dec_ch_info->common_window = 0; |
676 | | |
677 | 163k | ptr_ics_info->num_swb_window = 0; |
678 | 163k | ptr_ics_info->sampling_rate_index = aac_dec_handle->sampling_rate_index; |
679 | | |
680 | 163k | if (object_type == AOT_ER_AAC_LD) { |
681 | 66.8k | ptr_ics_info->ltp.data_present = 0; |
682 | 66.8k | ptr_ics_info->ltp2.data_present = 0; |
683 | 66.8k | ptr_ics_info->predictor_data_present = 0; |
684 | 66.8k | } |
685 | 163k | if (ele_ch > 1) { |
686 | 41.2k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.num_swb_window = 0; |
687 | 41.2k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info.sampling_rate_index = |
688 | 41.2k | aac_dec_handle->sampling_rate_index; |
689 | | |
690 | 41.2k | if (object_type != 39) |
691 | 11.0k | pstr_aac_dec_ch_info->common_window = |
692 | 11.0k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 1); |
693 | 30.1k | else |
694 | 30.1k | pstr_aac_dec_ch_info->common_window = 1; |
695 | | |
696 | 41.2k | if (pstr_aac_dec_ch_info->common_window) { |
697 | 39.5k | error_code = ixheaacd_ics_read( |
698 | 39.5k | it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, object_type, |
699 | 39.5k | pstr_aac_dec_ch_info->common_window, aac_dec_handle->samples_per_frame); |
700 | 39.5k | if (error_code) { |
701 | 21.9k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info = |
702 | 21.9k | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->str_ics_info; |
703 | 21.9k | 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 | 21.9k | goto _ia_handle_error1; |
709 | 21.9k | } |
710 | | |
711 | 17.5k | aac_dec_handle->pstr_aac_dec_ch_info[RIGHT]->str_ics_info = |
712 | 17.5k | pstr_aac_dec_ch_info->str_ics_info; |
713 | | |
714 | 17.5k | ixheaacd_read_ms_data(it_bit_buff, pstr_aac_dec_ch_info); |
715 | | |
716 | 17.5k | { |
717 | 17.5k | if (object_type == AOT_ER_AAC_LD) { |
718 | 6.59k | IA_ERRORCODE temp = |
719 | 6.59k | ixheaacd_ltp_decode(it_bit_buff, ptr_ics_info, object_type, |
720 | 6.59k | aac_dec_handle->samples_per_frame, LEFT); |
721 | | |
722 | 6.59k | 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 | 6.59k | } |
730 | 17.5k | } |
731 | 17.5k | } |
732 | 41.2k | } |
733 | | |
734 | 141k | error_code = ixheaacd_individual_ch_stream( |
735 | 141k | it_bit_buff, aac_dec_handle, ele_ch, frame_length, total_channels, object_type, |
736 | 141k | eld_specific_config, ele_type); |
737 | 141k | if (error_code) { |
738 | 2.55k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
739 | 0 | aac_dec_handle->frame_status = 0; |
740 | 2.55k | } else { |
741 | 2.55k | return error_code; |
742 | 2.55k | } |
743 | 2.55k | } |
744 | | |
745 | 139k | 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 | 139k | if (it_bit_buff->cnt_bits < 0) { |
750 | 42 | error_code = |
751 | 42 | (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
752 | 42 | } |
753 | | |
754 | 139k | if (error_code) { |
755 | 42 | goto _ia_handle_error1; |
756 | 42 | } |
757 | | |
758 | 160k | _ia_handle_error1: |
759 | 160k | if (error_code) { |
760 | 22.0k | aac_dec_handle->frame_status = 0; |
761 | 22.0k | if ((ele_type >= ID_SCE) && (ele_type <= ID_LFE)) num_ch = num_ch + ele_ch; |
762 | 22.0k | break; |
763 | 138k | } else { |
764 | 138k | error_code = ixheaacd_channel_pair_process( |
765 | 138k | aac_dec_handle->pstr_aac_dec_ch_info, ele_ch, aac_dec_handle->pstr_aac_tables, |
766 | 138k | total_channels, object_type, aac_spect_data_resil_flag, |
767 | 138k | eld_specific_config.aac_sf_data_resil_flag, aac_scratch_ptrs->in_data, |
768 | 138k | aac_scratch_ptrs->out_data, (VOID *)aac_dec_handle); |
769 | 138k | 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 | 138k | num_ch = num_ch + ele_ch; |
777 | 138k | } |
778 | 160k | } |
779 | | |
780 | 138k | p_obj_exhaacplus_dec->aac_config.element_type[*ch_idx] = ele_ch - 1; |
781 | 138k | break; |
782 | 163k | } |
783 | | |
784 | 160k | if ((object_type == AOT_ER_AAC_LC) || (!eld_sbr_flag)) { |
785 | 107k | WORD32 cnt_bits; |
786 | 107k | cnt_bits = it_bit_buff->cnt_bits; |
787 | 107k | p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.ldmps_config.no_ldsbr_present = 1; |
788 | | |
789 | 107k | if (cnt_bits >= 8) { |
790 | 106k | error_code = ixheaacd_extension_payload( |
791 | 106k | it_bit_buff, &cnt_bits, &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle); |
792 | 106k | if (error_code) { |
793 | 57 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && !is_init) { |
794 | 0 | aac_dec_handle->frame_status = 0; |
795 | 57 | } else { |
796 | 57 | return error_code; |
797 | 57 | } |
798 | 57 | } |
799 | 106k | } |
800 | | |
801 | 106k | if (it_bit_buff->cnt_bits) { |
802 | 6.12k | WORD32 alignment = it_bit_buff->bit_pos & 0x07; |
803 | 6.12k | it_bit_buff->cnt_bits = (it_bit_buff->cnt_bits + alignment) & 7; |
804 | 6.12k | it_bit_buff->bit_pos = 7; |
805 | 6.12k | it_bit_buff->ptr_read_next++; |
806 | 6.12k | } |
807 | 106k | } |
808 | | |
809 | 53.4k | 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 | 53.4k | } else { |
848 | 53.4k | WORD32 bits_decoded, cnt_bits; |
849 | 53.4k | bits_decoded = (it_bit_buff->size - it_bit_buff->cnt_bits); |
850 | 53.4k | cnt_bits = (frame_size * 8 - bits_decoded); |
851 | 53.4k | 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 | 53.4k | ixheaacd_check_for_sbr_payload( |
861 | 53.4k | it_bit_buff, aac_dec_handle->pstr_sbr_bitstream, (WORD16)(ch_config - 1), |
862 | 53.4k | pstr_drc_dec, object_type, adtsheader, cnt_bits, ld_sbr_crc_flag, drc_dummy, |
863 | 53.4k | mps_buffer, mps_header, mps_bytes, is_init, &aac_dec_handle->is_first, |
864 | 53.4k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal); |
865 | 53.4k | } |
866 | 160k | } |
867 | 160k | } |
868 | 225k | } |
869 | 220k | if ((err || (aac_dec_handle->frame_status == 0) || (frame_status == 0)) && (!is_init)) { |
870 | 22.0k | 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 | 22.0k | } else { |
879 | 22.0k | return err; |
880 | 22.0k | } |
881 | 22.0k | } |
882 | 198k | 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 | 198k | if (ele_type == ID_END && p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) { |
889 | 9.58k | WORD32 tmp; |
890 | 9.58k | tmp = ((WORD32)latm_element->layer_info[0][0].frame_len_bits) - |
891 | 9.58k | (it_bit_buff->initial_cnt_bits - it_bit_buff->cnt_bits); |
892 | | |
893 | 9.58k | if (tmp > 0) ixheaacd_read_bidirection(it_bit_buff, tmp); |
894 | | |
895 | 9.58k | if (latm_element->other_data_present) { |
896 | 2.25k | WORD32 count_bits = (WORD32)latm_element->other_data_length; |
897 | 2.25k | ixheaacd_read_bidirection(it_bit_buff, count_bits); |
898 | 2.25k | } |
899 | 9.58k | } |
900 | | |
901 | 198k | if (object_type == AOT_ER_AAC_LD) { |
902 | 139k | for (ch = 0; ch < channel; ch++) { |
903 | 74.4k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_1 = |
904 | 74.4k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp2.lag; |
905 | 74.4k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->ltp_lag_2 = |
906 | 74.4k | aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info.ltp.lag; |
907 | 74.4k | } |
908 | 65.4k | } |
909 | 198k | aac_dec_handle->frame_status = aac_dec_handle->frame_status && frame_status; |
910 | | |
911 | 198k | aac_dec_handle->channels = num_ch; |
912 | | |
913 | 198k | if (error_code == 0) |
914 | 198k | if ((skip_full_decode == 0) || ((skip_full_decode == 1) && error_code)) { |
915 | 198k | ia_ics_info_struct str_ics_info[2]; |
916 | 198k | WORD32 *spec_coef[2]; |
917 | 198k | WORD32 *scratch[2]; |
918 | | |
919 | 426k | for (ch = 0; ch < channel; ch++) { |
920 | 228k | str_ics_info[ch] = aac_dec_handle->pstr_aac_dec_ch_info[ch]->str_ics_info; |
921 | 228k | spec_coef[ch] = aac_dec_handle->pstr_aac_dec_ch_info[ch]->ptr_spec_coeff; |
922 | 228k | } |
923 | | |
924 | 198k | scratch[0] = (WORD32 *)aac_scratch_ptrs->extra_scr_4k[2]; |
925 | 198k | scratch[1] = (WORD32 *)aac_scratch_ptrs->extra_scr_4k[1]; |
926 | | |
927 | 198k | error_code = ixheaacd_drc_map_channels( |
928 | 198k | pstr_drc_dec, aac_dec_handle->channels, |
929 | 198k | aac_dec_handle->pstr_aac_dec_ch_info[0]->str_ics_info.frame_length); |
930 | 198k | if (error_code) { |
931 | 1 | 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 | 1 | } else { |
935 | 1 | return error_code; |
936 | 1 | } |
937 | 1 | } |
938 | | |
939 | 417k | for (ch = 0; ch < aac_dec_handle->channels; ch++) { |
940 | 218k | WORD32 *overlap1 = |
941 | 218k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch]->overlap_add_data.ptr_overlap_buf; |
942 | 218k | const WORD16 *ptr_long_window_next = |
943 | 218k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
944 | 218k | ->ptr_long_window[(int)str_ics_info[ch].window_shape]; |
945 | 218k | const WORD16 *ptr_short_window_next = |
946 | 218k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
947 | 218k | ->ptr_short_window[(int)str_ics_info[ch].window_shape]; |
948 | 218k | 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 | 218k | if (pstr_drc_dec->drc_on) { |
982 | 218k | ixheaacd_drc_apply(pstr_drc_dec, spec_coef[ch], |
983 | 218k | str_ics_info[ch].window_sequence, ch, |
984 | 218k | str_ics_info[ch].frame_length, |
985 | 218k | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr, object_type); |
986 | 218k | } |
987 | 218k | if (skip_full_decode == 0) { |
988 | 218k | ixheaacd_imdct_process(aac_dec_handle->pstr_aac_dec_overlap_info[ch], |
989 | 218k | spec_coef[ch], &str_ics_info[ch], |
990 | 218k | time_data + slot_element, ch_fac, scratch[ch], |
991 | 218k | aac_dec_handle->pstr_aac_tables, object_type, |
992 | 218k | ldmps_present, slot_element); |
993 | | |
994 | 218k | if (slot_pos != NULL) *slot_pos = slot_element; |
995 | 218k | if (p_obj_exhaacplus_dec->p_state_aac->qshift_cnt > 15) { |
996 | 2 | return IA_FATAL_ERROR; |
997 | 2 | } |
998 | | |
999 | 218k | p_obj_exhaacplus_dec->p_state_aac |
1000 | 218k | ->qshift_adj[p_obj_exhaacplus_dec->p_state_aac->qshift_cnt++] = |
1001 | 218k | str_ics_info[ch].qshift_adj; |
1002 | | |
1003 | 218k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
1004 | 218k | ->overlap_add_data.win_shape = str_ics_info[ch].window_shape; |
1005 | 218k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
1006 | 218k | ->overlap_add_data.win_seq = str_ics_info[ch].window_sequence; |
1007 | 218k | if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) { |
1008 | 98.4k | { |
1009 | 98.4k | if ((str_ics_info[ch].window_sequence == ONLY_LONG_SEQUENCE) || |
1010 | 65.0k | (str_ics_info[ch].window_sequence == LONG_STOP_SEQUENCE)) { |
1011 | 65.0k | ixheaacd_lt_update_state( |
1012 | 65.0k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
1013 | 65.0k | ->ltp_buf, |
1014 | 65.0k | time_data + slot_element, overlap1, |
1015 | 65.0k | aac_dec_handle->samples_per_frame, object_type, |
1016 | 65.0k | (WORD16)ch_fac, str_ics_info[ch].window_sequence, |
1017 | 65.0k | (WORD16 *)ptr_long_window_next, slot_element); |
1018 | 65.0k | } else { |
1019 | 33.4k | ixheaacd_lt_update_state( |
1020 | 33.4k | aac_dec_handle->ptr_aac_dec_static_channel_info[ch] |
1021 | 33.4k | ->ltp_buf, |
1022 | 33.4k | time_data + slot_element, overlap1, |
1023 | 33.4k | aac_dec_handle->samples_per_frame, object_type, |
1024 | 33.4k | (WORD16)ch_fac, str_ics_info[ch].window_sequence, |
1025 | 33.4k | (WORD16 *)ptr_short_window_next, slot_element); |
1026 | 33.4k | } |
1027 | 98.4k | } |
1028 | 98.4k | } |
1029 | 218k | 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 | 218k | slot_element++; |
1045 | 218k | } |
1046 | 218k | } |
1047 | 198k | } |
1048 | | |
1049 | 198k | if (ele_type == ID_END) { |
1050 | 43.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 | 43.1k | } else { |
1060 | 43.1k | ixheaacd_byte_align(it_bit_buff, &aac_dec_handle->byte_align_bits); |
1061 | 43.1k | if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) { |
1062 | 9.56k | ixheaacd_byte_align(it_bit_buff, &it_bit_buff->audio_mux_align); |
1063 | 9.56k | } |
1064 | 43.1k | } |
1065 | 43.1k | } |
1066 | 198k | *type = ele_type; |
1067 | | |
1068 | 198k | aac_dec_handle->block_number = |
1069 | 198k | ixheaac_add32(aac_dec_handle->block_number, 1); |
1070 | 198k | 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 | 198k | } else { |
1074 | 198k | return error_code; |
1075 | 198k | } |
1076 | 198k | } |
1077 | | |
1078 | | WORD32 ixheaacd_extension_payload(ia_bit_buf_struct *it_bit_buff, WORD32 *cnt, |
1079 | 113k | ia_mps_dec_state_struct *self) { |
1080 | 113k | WORD16 extension_type; |
1081 | 113k | WORD32 len, add_len; |
1082 | 113k | WORD32 i; |
1083 | 113k | WORD32 fill_nibble; |
1084 | | |
1085 | 113k | WORD32 err = 0; |
1086 | 113k | extension_type = (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 4); |
1087 | 113k | switch (extension_type) { |
1088 | 5.25k | case EXT_FILL_DATA: |
1089 | | |
1090 | 5.25k | fill_nibble = ixheaacd_read_bits_buf(it_bit_buff, 4); |
1091 | | |
1092 | 5.25k | if (fill_nibble == 0) { |
1093 | 12.4M | for (i = 0; i < (*cnt >> 3) - 1; i++) { |
1094 | 12.4M | if (it_bit_buff->cnt_bits >= 8) |
1095 | 12.4M | ixheaacd_read_bits_buf(it_bit_buff, 8); |
1096 | 418 | else |
1097 | 418 | ixheaacd_read_bits_buf(it_bit_buff, it_bit_buff->cnt_bits); |
1098 | 12.4M | } |
1099 | | |
1100 | 2.18k | } else |
1101 | 3.07k | err = -1; |
1102 | 5.25k | *cnt = it_bit_buff->cnt_bits; |
1103 | 5.25k | break; |
1104 | | |
1105 | 1.80k | case EXT_DATA_LENGTH: |
1106 | | |
1107 | 1.80k | len = ixheaacd_read_bits_buf(it_bit_buff, 4); |
1108 | | |
1109 | 1.80k | if (len == 15) { |
1110 | 715 | add_len = ixheaacd_read_bits_buf(it_bit_buff, 8); |
1111 | 715 | len += add_len; |
1112 | | |
1113 | 715 | if (add_len == 255) { |
1114 | 603 | len += ixheaacd_read_bits_buf(it_bit_buff, 16); |
1115 | 603 | } |
1116 | 715 | } |
1117 | 1.80k | len <<= 3; |
1118 | | |
1119 | 1.80k | ixheaacd_extension_payload(it_bit_buff, cnt, self); |
1120 | 1.80k | break; |
1121 | | |
1122 | 5.33k | case EXT_LDSAC_DATA: |
1123 | | |
1124 | 5.33k | self->parse_nxt_frame = 1; |
1125 | 5.33k | ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_type*/ |
1126 | 5.33k | ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_start_stop*/ |
1127 | | |
1128 | 5.33k | if (self->ldmps_config.ldmps_present_flag == 1) { |
1129 | 1.91k | err = ixheaacd_ld_mps_frame_parsing(self, it_bit_buff); |
1130 | 1.91k | if (err) return err; |
1131 | 1.91k | } |
1132 | | |
1133 | 5.27k | *cnt = it_bit_buff->cnt_bits; |
1134 | 5.27k | break; |
1135 | 45.3k | case EXT_FIL: |
1136 | 100k | default: |
1137 | | |
1138 | 4.47G | for (i = 0; i < (*cnt) - 4; i++) { |
1139 | 4.47G | ixheaacd_skip_bits_buf(it_bit_buff, 1);/*discard*/ |
1140 | 4.47G | } |
1141 | | |
1142 | 100k | *cnt = it_bit_buff->cnt_bits; |
1143 | 100k | break; |
1144 | 113k | } |
1145 | | |
1146 | 112k | return err; |
1147 | 113k | } |