/src/libxaac/decoder/ixheaacd_api.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | #include <string.h> |
21 | | #include <stdio.h> |
22 | | #include <stdlib.h> |
23 | | #include "ixheaacd_sbr_common.h" |
24 | | #include "ixheaac_type_def.h" |
25 | | #include "ixheaacd_memory_standards.h" |
26 | | #include "ixheaacd_mps_struct_def.h" |
27 | | #include "ixheaacd_mps_res_rom.h" |
28 | | #include "ixheaacd_mps_aac_struct.h" |
29 | | #include "ixheaac_constants.h" |
30 | | #include "ixheaac_basic_ops32.h" |
31 | | #include "ixheaac_basic_ops16.h" |
32 | | #include "ixheaac_basic_ops40.h" |
33 | | #include "ixheaac_basic_ops.h" |
34 | | |
35 | | #include "ixheaac_error_standards.h" |
36 | | #include "ixheaacd_apicmd_standards.h" |
37 | | #include "ixheaacd_aac_config.h" |
38 | | #include "ixheaacd_api_defs.h" |
39 | | |
40 | | #include "ixheaacd_definitions.h" |
41 | | #include "ixheaacd_error_codes.h" |
42 | | #include "ixheaacd_bitbuffer.h" |
43 | | |
44 | | #include "ixheaacd_audioobjtypes.h" |
45 | | #include "ixheaacd_sbrdecsettings.h" |
46 | | #include "ixheaacd_memory_standards.h" |
47 | | |
48 | | #include "ixheaacd_bitbuffer.h" |
49 | | #include "ixheaacd_adts.h" |
50 | | #include "ixheaacd_defines.h" |
51 | | #include "ixheaacd_cnst.h" |
52 | | #include "ixheaacd_aac_rom.h" |
53 | | #include "ixheaacd_ec_defines.h" |
54 | | #include "ixheaacd_ec_struct_def.h" |
55 | | |
56 | | #include "ixheaacd_sbr_scale.h" |
57 | | #include "ixheaacd_lpp_tran.h" |
58 | | #include "ixheaacd_env_extr_part.h" |
59 | | #include "ixheaacd_sbr_rom.h" |
60 | | |
61 | | #include "ixheaacd_hybrid.h" |
62 | | #include "ixheaacd_ps_dec.h" |
63 | | #include "ixheaacd_ps_bitdec.h" |
64 | | |
65 | | #include "ixheaacd_pulsedata.h" |
66 | | |
67 | | #include "ixheaacd_pns.h" |
68 | | #include "ixheaacd_drc_data_struct.h" |
69 | | |
70 | | #include "ixheaacd_lt_predict.h" |
71 | | |
72 | | #include "ixheaacd_channelinfo.h" |
73 | | #include "ixheaacd_drc_dec.h" |
74 | | #include "ixheaac_sbr_const.h" |
75 | | #include "ixheaacd_sbrdecoder.h" |
76 | | #include "ixheaacd_env_extr.h" |
77 | | #include "ixheaacd_common_rom.h" |
78 | | #include "ixheaacd_freq_sca.h" |
79 | | #include "ixheaacd_qmf_dec.h" |
80 | | #include "ixheaacd_env_calc.h" |
81 | | |
82 | | #include "ixheaacd_pvc_dec.h" |
83 | | #include "ixheaacd_sbr_dec.h" |
84 | | #include "ixheaacd_block.h" |
85 | | #include "ixheaacd_channel.h" |
86 | | |
87 | | #include "ixheaacd_audioobjtypes.h" |
88 | | #include "ixheaacd_latmdemux.h" |
89 | | |
90 | | #include "ixheaacd_aacdec.h" |
91 | | #include "ixheaacd_mps_polyphase.h" |
92 | | #include "ixheaacd_config.h" |
93 | | #include "ixheaacd_mps_dec.h" |
94 | | #include "ixheaacd_struct_def.h" |
95 | | #include "ixheaacd_headerdecode.h" |
96 | | #include "ixheaacd_adts_crc_check.h" |
97 | | |
98 | | #include "ixheaacd_multichannel.h" |
99 | | #include "ixheaacd_ver_number.h" |
100 | | |
101 | | #include "ixheaacd_interface.h" |
102 | | #include "ixheaacd_info.h" |
103 | | |
104 | | #include "ixheaacd_config.h" |
105 | | |
106 | | #include "ixheaacd_struct.h" |
107 | | #include "ixheaacd_mps_polyphase.h" |
108 | | #include "ixheaacd_tns_usac.h" |
109 | | #include "ixheaacd_acelp_info.h" |
110 | | |
111 | | #include "ixheaacd_main.h" |
112 | | #include "ixheaacd_arith_dec.h" |
113 | | #include "ixheaacd_create.h" |
114 | | #include "ixheaacd_function_selector.h" |
115 | | #include "ixheaacd_ld_mps_dec.h" |
116 | | #include "ixheaacd_mps_tables.h" |
117 | | #define MAX_TRACKS_PER_LAYER 50 |
118 | | |
119 | | #define ALIGN_SIZE64(x) ((((x) + 7) >> 3) << 3) |
120 | | |
121 | 500k | #define IA_ENHAACPDEC_NUM_MEMTABS (4) |
122 | | |
123 | 0 | #define NUM_AAC_TABLES 8 |
124 | | |
125 | 1.03M | #define LD_OBJ -2 |
126 | | |
127 | | #define SCR_BASE_SCR_8K_SIZE \ |
128 | 321k | (IXHEAAC_GET_SIZE_ALIGNED((2 * CHANNELS * MAX_BINS_LONG * sizeof(WORD32)), BYTE_ALIGN_8)) |
129 | | #define SCR_EXTRA_SCR_4K_0_SIZE \ |
130 | 497k | (2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_channel_info_struct), sizeof(WORD32)) + \ |
131 | 497k | 2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_sfb_code_book_struct), sizeof(WORD32)) + \ |
132 | 497k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_pns_stereo_data_struct), sizeof(WORD32))) |
133 | | #define SCR_EXTRA_SCR_4K_2_SIZE \ |
134 | 497k | (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8)) |
135 | | #define SCR_EXTRA_SCR_4K_3_SIZE \ |
136 | 175k | (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8)) |
137 | | #define SCR_OUT_DATA_SIZE \ |
138 | 130k | (IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), BYTE_ALIGN_8)) |
139 | | #define SCR_IN_DATA_SIZE \ |
140 | 130k | (2 * IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD32)), \ |
141 | 130k | BYTE_ALIGN_8)) |
142 | | #define SCR_INTER_SCR_SIZE \ |
143 | 294k | (MAX_CHANNEL_COUNT * \ |
144 | 294k | IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD16)), \ |
145 | 294k | BYTE_ALIGN_8)) |
146 | | #define SCR_COUP_CH_OUT_SIZE \ |
147 | 279k | (MAX_CHANNEL_COUNT * \ |
148 | 279k | IXHEAAC_GET_SIZE_ALIGNED((IA_ENHAACPLUS_DEC_SAMPLES_PER_FRAME * sizeof(WORD16)), \ |
149 | 279k | BYTE_ALIGN_8)) |
150 | | |
151 | | #define P_IND_CH_INFO_OFFSET \ |
152 | 303 | (SCR_BASE_SCR_8K_SIZE + SCR_EXTRA_SCR_4K_0_SIZE + SCR_EXTRA_SCR_4K_2_SIZE) |
153 | | |
154 | | #define HEAACV2_MAX_SIZE \ |
155 | | (max(SCR_BASE_SCR_8K_SIZE + SCR_EXTRA_SCR_4K_0_SIZE + SCR_EXTRA_SCR_4K_2_SIZE + \ |
156 | | SCR_INTER_SCR_SIZE + SCR_COUP_CH_OUT_SIZE, \ |
157 | | MPS_SCRATCH_MEM_SIZE)) |
158 | | #define ELDV2_MAX_SIZE \ |
159 | | (max(SCR_BASE_SCR_8K_SIZE + SCR_EXTRA_SCR_4K_0_SIZE + SCR_EXTRA_SCR_4K_2_SIZE + \ |
160 | | SCR_EXTRA_SCR_4K_3_SIZE + SCR_INTER_SCR_SIZE + SCR_COUP_CH_OUT_SIZE, \ |
161 | | MPS_SCRATCH_MEM_SIZE)) |
162 | | #define LD_MAX_SIZE \ |
163 | | (max(SCR_BASE_SCR_8K_SIZE + SCR_EXTRA_SCR_4K_0_SIZE + SCR_EXTRA_SCR_4K_2_SIZE + \ |
164 | | SCR_OUT_DATA_SIZE + SCR_IN_DATA_SIZE + SCR_INTER_SCR_SIZE + SCR_COUP_CH_OUT_SIZE, \ |
165 | | MPS_SCRATCH_MEM_SIZE)) |
166 | | |
167 | 321k | #define MAX_SCR_SIZE (max(max(HEAACV2_MAX_SIZE, ELDV2_MAX_SIZE), LD_MAX_SIZE)) |
168 | | |
169 | | IA_ERRORCODE ixheaacd_dec_mem_api(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, |
170 | 421k | WORD32 i_cmd, WORD32 i_idx, VOID *pv_value) { |
171 | 421k | pUWORD32 pui_value = pv_value; |
172 | | |
173 | 421k | if (i_idx < 0 || i_idx >= IA_ENHAACPDEC_NUM_MEMTABS) { |
174 | 0 | return IA_XHEAAC_DEC_API_FATAL_INVALID_MEMTAB_INDEX; |
175 | 0 | } |
176 | | |
177 | 421k | if (i_cmd == IA_API_CMD_SET_MEM_PTR) { |
178 | 105k | if (pv_value == 0) { |
179 | 0 | return (IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC); |
180 | 0 | } |
181 | 105k | if (((SIZE_T)pv_value % |
182 | 105k | p_obj_exhaacplus_dec->p_mem_info_aac[i_idx].ui_alignment) != 0) { |
183 | 0 | return (IA_XHEAAC_DEC_API_FATAL_MEM_ALIGN); |
184 | 0 | } |
185 | 105k | p_obj_exhaacplus_dec->pp_mem_aac[i_idx] = pv_value; |
186 | 105k | memset(p_obj_exhaacplus_dec->pp_mem_aac[i_idx], 0, |
187 | 105k | p_obj_exhaacplus_dec->p_mem_info_aac[i_idx].ui_size); |
188 | | |
189 | 105k | if (i_idx == IA_ENHAACPLUS_DEC_PERSIST_IDX) { |
190 | 26.3k | pUWORD8 p_temp = pv_value; |
191 | 26.3k | UWORD32 *meminfo = |
192 | 26.3k | (UWORD32 *)p_obj_exhaacplus_dec->p_mem_info_aac + i_idx; |
193 | 26.3k | UWORD32 pers_size = meminfo[0]; |
194 | 26.3k | p_temp = p_temp + pers_size - |
195 | 26.3k | (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) + |
196 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8) + |
197 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(MAX_HEADER_BUF_SIZE, BYTE_ALIGN_8)); |
198 | 26.3k | p_obj_exhaacplus_dec->p_state_aac = pv_value; |
199 | 26.3k | memset(p_obj_exhaacplus_dec->p_state_aac, 0, |
200 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8)); |
201 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data = p_temp; |
202 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config = |
203 | 26.3k | p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8); |
204 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->header_ptr = |
205 | 26.3k | p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) + |
206 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8); |
207 | 26.3k | } |
208 | | |
209 | 316k | } else { |
210 | 316k | UWORD32 *meminfo = |
211 | 316k | (UWORD32 *)(p_obj_exhaacplus_dec->p_mem_info_aac + i_idx); |
212 | 316k | *pui_value = *(meminfo + (i_cmd - IA_API_CMD_GET_MEM_INFO_SIZE)); |
213 | 316k | } |
214 | | |
215 | 421k | return IA_NO_ERROR; |
216 | 421k | } |
217 | | |
218 | | static PLATFORM_INLINE VOID |
219 | 26.3k | ixheaacd_init_sbr_tables(ia_sbr_tables_struct *ptr_sbr_tables) { |
220 | 26.3k | ptr_sbr_tables->env_calc_tables_ptr = |
221 | 26.3k | (ia_env_calc_tables_struct *)&ixheaacd_aac_dec_env_calc_tables; |
222 | 26.3k | ptr_sbr_tables->qmf_dec_tables_ptr = |
223 | 26.3k | (ia_qmf_dec_tables_struct *)&ixheaacd_aac_qmf_dec_tables; |
224 | 26.3k | ptr_sbr_tables->env_extr_tables_ptr = |
225 | 26.3k | (ia_env_extr_tables_struct *)&ixheaacd_aac_dec_env_extr_tables; |
226 | 26.3k | ptr_sbr_tables->ps_tables_ptr = |
227 | 26.3k | (ia_ps_tables_struct *)&ixheaacd_aac_dec_ps_tables; |
228 | 26.3k | } |
229 | | |
230 | | VOID ixheaacd_updatebytesconsumed( |
231 | | ia_aac_dec_state_struct *p_state_enhaacplus_dec, |
232 | 283k | struct ia_bit_buf_struct *it_bit_buff) { |
233 | 283k | p_state_enhaacplus_dec->i_bytes_consumed = |
234 | 283k | (WORD32)(it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base); |
235 | 283k | if ((p_state_enhaacplus_dec->i_bytes_consumed == 0) && |
236 | 283k | (it_bit_buff->cnt_bits == 0)) { |
237 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = |
238 | 0 | p_state_enhaacplus_dec->ui_in_bytes; |
239 | 0 | } |
240 | 283k | if (it_bit_buff->cnt_bits < 0) { |
241 | 198 | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
242 | 198 | p_state_enhaacplus_dec->ui_out_bytes = 0; |
243 | 198 | p_state_enhaacplus_dec->ui_mps_out_bytes = 0; |
244 | 198 | p_state_enhaacplus_dec->b_n_raw_data_blk = 0; |
245 | 198 | } |
246 | 283k | } |
247 | | |
248 | | static VOID copy_qmf_to_ldmps(ia_mps_dec_state_struct *mps_dec_handle, |
249 | 15.0k | VOID *sbr_persistent_mem_v) { |
250 | 15.0k | ia_sbr_pers_struct *sbr_persistent_mem = |
251 | 15.0k | (ia_sbr_pers_struct *)sbr_persistent_mem_v; |
252 | 15.0k | memcpy(&mps_dec_handle->str_mps_qmf_bank, |
253 | 15.0k | &sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[0] |
254 | 15.0k | ->str_sbr_dec.str_codec_qmf_bank, |
255 | 15.0k | sizeof(ia_sbr_qmf_filter_bank_struct)); |
256 | | |
257 | 15.0k | mps_dec_handle->sbr_tables_ptr = |
258 | 15.0k | sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables; |
259 | 15.0k | mps_dec_handle->qmf_dec_tables_ptr = |
260 | 15.0k | sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables->qmf_dec_tables_ptr; |
261 | 15.0k | mps_dec_handle->str_sbr_scale_fact = |
262 | 15.0k | &sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[0] |
263 | 15.0k | ->str_sbr_dec.str_sbr_scale_fact; |
264 | 15.0k | } |
265 | | |
266 | | WORD32 ixheaacd_readifadts(ia_aac_dec_state_struct *p_state_enhaacplus_dec, |
267 | | struct ia_bit_buf_struct *it_bit_buff, |
268 | 52.9k | ia_adts_header_struct *adts) { |
269 | 52.9k | WORD error; |
270 | | |
271 | 52.9k | if ((error = ixheaacd_find_syncword(adts, it_bit_buff)) != 0) { |
272 | 1.79k | ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff); |
273 | 1.79k | return IA_XHEAAC_DEC_EXE_NONFATAL_ADTS_SYNC_LOST; |
274 | 1.79k | } |
275 | 51.1k | if ((error = ixheaacd_check_if_adts( |
276 | 51.1k | adts, it_bit_buff, |
277 | 51.1k | p_state_enhaacplus_dec->p_config->ui_max_channels)) != 0) { |
278 | 664 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
279 | | |
280 | 664 | if (it_bit_buff->cnt_bits < 0) { |
281 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
282 | 0 | p_state_enhaacplus_dec->ui_out_bytes = 0; |
283 | 0 | p_state_enhaacplus_dec->ui_mps_out_bytes = 0; |
284 | 0 | error = IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES; |
285 | 0 | return error; |
286 | 0 | } |
287 | 664 | return IA_XHEAAC_DEC_EXE_NONFATAL_ADTS_SYNC_LOST; |
288 | 664 | } |
289 | 50.5k | p_state_enhaacplus_dec->b_n_raw_data_blk = |
290 | 50.5k | (WORD8)(adts->no_raw_data_blocks + 1); |
291 | 50.5k | return 0; |
292 | 51.1k | } |
293 | | |
294 | | static VOID ixheaacd_allocate_aac_scr( |
295 | | ia_aac_dec_scratch_struct *aac_scratch_struct, VOID *base_scratch_ptr, |
296 | | VOID *output_ptr, WORD channel, WORD max_channel, |
297 | 321k | WORD32 audio_object_type) { |
298 | 321k | WORD32 scratch_used = 0; |
299 | 321k | aac_scratch_struct->base_scr_8k = base_scratch_ptr; |
300 | 321k | aac_scratch_struct->extra_scr_4k[1] = (WORD8 *)base_scratch_ptr; |
301 | 321k | scratch_used += SCR_BASE_SCR_8K_SIZE; |
302 | 321k | if (channel == 1) { |
303 | 259k | aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used; |
304 | 259k | scratch_used += SCR_EXTRA_SCR_4K_0_SIZE; |
305 | 259k | aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used; |
306 | 259k | scratch_used += SCR_EXTRA_SCR_4K_2_SIZE; |
307 | 259k | } else { |
308 | 62.0k | aac_scratch_struct->extra_scr_4k[0] = output_ptr; |
309 | | |
310 | 62.0k | if (max_channel > 2) { |
311 | 62.0k | aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used; |
312 | 62.0k | scratch_used += SCR_EXTRA_SCR_4K_0_SIZE; |
313 | 62.0k | } |
314 | 62.0k | aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used; |
315 | 62.0k | scratch_used += SCR_EXTRA_SCR_4K_2_SIZE; |
316 | 62.0k | } |
317 | | |
318 | 321k | if (audio_object_type == AOT_ER_AAC_ELD || audio_object_type == AOT_ER_AAC_LD) { |
319 | 175k | aac_scratch_struct->extra_scr_4k[0] = (WORD8 *)base_scratch_ptr + scratch_used; |
320 | 175k | scratch_used += SCR_EXTRA_SCR_4K_0_SIZE; |
321 | | |
322 | 175k | aac_scratch_struct->extra_scr_4k[2] = (WORD8 *)base_scratch_ptr + scratch_used; |
323 | 175k | scratch_used += SCR_EXTRA_SCR_4K_2_SIZE; |
324 | | |
325 | 175k | aac_scratch_struct->extra_scr_4k[3] = (WORD8 *)base_scratch_ptr + scratch_used; |
326 | 175k | scratch_used += SCR_EXTRA_SCR_4K_3_SIZE; |
327 | 175k | } |
328 | 321k | if ((audio_object_type == AOT_ER_AAC_LD) || (audio_object_type == AOT_AAC_LTP)) { |
329 | 130k | aac_scratch_struct->out_data = (WORD32 *)((WORD8 *)base_scratch_ptr + scratch_used); |
330 | 130k | scratch_used += SCR_OUT_DATA_SIZE; |
331 | | |
332 | 130k | aac_scratch_struct->in_data = (WORD32 *)((WORD8 *)base_scratch_ptr + scratch_used); |
333 | 130k | scratch_used += SCR_IN_DATA_SIZE; |
334 | 130k | } |
335 | 321k | } |
336 | | |
337 | | VOID ixheaacd_allocate_sbr_scr(ia_sbr_scr_struct *sbr_scratch_struct, VOID *base_scratch_ptr, |
338 | | VOID *output_ptr, WORD32 total_channels, WORD8 *p_qshift_arr, |
339 | 316k | UWORD8 slot_pos, UWORD8 num_ch) { |
340 | 316k | WORD32 j, i; |
341 | 316k | sbr_scratch_struct->ptr_work_buf_core = base_scratch_ptr; |
342 | | |
343 | 316k | if (p_qshift_arr != NULL && *p_qshift_arr != LD_OBJ) { |
344 | 47.2k | WORD32 *tmp_buf = (WORD32 *)output_ptr; |
345 | | |
346 | 69.6k | for (j = 1; j < num_ch; j++) { |
347 | 22.4k | if ((*p_qshift_arr + j) == 0) |
348 | 0 | *(p_qshift_arr + j) = *(p_qshift_arr + j - 1); |
349 | 22.4k | } |
350 | | |
351 | 47.2k | if (total_channels > 2) { |
352 | 426 | for (j = 0; j < num_ch; j++) { |
353 | 240k | for (i = 0; i < 1024; i++) { |
354 | 240k | *((WORD16 *)tmp_buf + slot_pos + total_channels * i + j) = |
355 | 240k | ixheaac_round16(ixheaac_shl32_sat( |
356 | 240k | *(tmp_buf + slot_pos + total_channels * i + j), |
357 | 240k | *(p_qshift_arr + j))); |
358 | 240k | } |
359 | 235 | } |
360 | 47.0k | } else { |
361 | 116k | for (j = 0; j < num_ch; j++) { |
362 | 71.1M | for (i = 0; i < 1024; i++) { |
363 | 71.1M | *((WORD16 *)tmp_buf + total_channels * i + j) = |
364 | 71.1M | ixheaac_round16(ixheaac_shl32_sat( |
365 | 71.1M | *(tmp_buf + total_channels * i + j), *(p_qshift_arr + j))); |
366 | 71.1M | } |
367 | 69.4k | } |
368 | 47.0k | } |
369 | 47.2k | } |
370 | 316k | } |
371 | | |
372 | 0 | VOID ixheaacd_get_lib_id_strings(pVOID pv_output) { |
373 | 0 | ia_lib_info_struct *pstr_lib_info = (ia_lib_info_struct *)pv_output; |
374 | |
|
375 | 0 | pstr_lib_info->p_lib_name = (WORD8 *)LIBNAME; |
376 | 0 | pstr_lib_info->p_version_num = (WORD8 *)xHE_AAC_DEC_ITTIAM_VER; |
377 | |
|
378 | 0 | return; |
379 | 0 | } |
380 | | |
381 | | IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_xheaac_dec_obj, WORD32 i_cmd, |
382 | 5.17M | WORD32 i_idx, pVOID pv_value) { |
383 | 5.17M | ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec = p_ia_xheaac_dec_obj; |
384 | 5.17M | pUWORD32 pui_value = pv_value; |
385 | 5.17M | pWORD32 pui_value_signed = pv_value; |
386 | 5.17M | pWORD8 pb_value = pv_value; |
387 | 5.17M | pVOID *pp_value = (pVOID *)pv_value; |
388 | 5.17M | float *pf_value = pv_value; |
389 | | |
390 | 5.17M | if ((i_cmd != IA_API_CMD_GET_API_SIZE) && |
391 | 5.17M | (i_cmd != IA_API_CMD_GET_LIB_ID_STRINGS)) { |
392 | 5.15M | if (p_ia_xheaac_dec_obj == 0) { |
393 | 0 | return (IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC); |
394 | 0 | } |
395 | 5.15M | if (((SIZE_T)p_ia_xheaac_dec_obj & 3) != 0) { |
396 | 0 | return (IA_XHEAAC_DEC_API_FATAL_MEM_ALIGN); |
397 | 0 | } |
398 | 5.15M | } |
399 | | |
400 | 5.17M | switch (i_cmd) { |
401 | 105k | case IA_API_CMD_GET_MEM_INFO_SIZE: |
402 | 210k | case IA_API_CMD_GET_MEM_INFO_ALIGNMENT: |
403 | 316k | case IA_API_CMD_GET_MEM_INFO_TYPE: |
404 | 421k | case IA_API_CMD_SET_MEM_PTR: { |
405 | 421k | return ixheaacd_dec_mem_api(p_ia_xheaac_dec_obj, i_cmd, i_idx, |
406 | 421k | pv_value); |
407 | 316k | } |
408 | | |
409 | 0 | case IA_API_CMD_GET_TABLE_INFO_SIZE: |
410 | 0 | case IA_API_CMD_GET_TABLE_INFO_ALIGNMENT: |
411 | 0 | case IA_API_CMD_SET_TABLE_PTR: |
412 | 0 | case IA_API_CMD_GET_TABLE_PTR: { |
413 | 0 | return ixheaacd_dec_table_api(p_ia_xheaac_dec_obj, i_cmd, i_idx, |
414 | 0 | pv_value); |
415 | 0 | } |
416 | 5.17M | }; |
417 | | |
418 | 4.75M | switch (i_cmd) { |
419 | 0 | case IA_API_CMD_GET_LIB_ID_STRINGS: { |
420 | 0 | WORD8 *i1_ver; |
421 | 0 | WORD8 ver_char; |
422 | |
|
423 | 0 | if (i_idx == IA_CMD_TYPE_LIB_NAME) |
424 | 0 | i1_ver = (WORD8 *)LIBNAME; |
425 | 0 | else if (i_idx == IA_CMD_TYPE_LIB_VERSION) |
426 | 0 | i1_ver = (WORD8 *)xHE_AAC_DEC_ITTIAM_VER; |
427 | 0 | else |
428 | 0 | return IA_XHEAAC_DEC_API_FATAL_INVALID_LIB_ID_STRINGS_IDX; |
429 | | |
430 | 0 | ver_char = *i1_ver++; |
431 | |
|
432 | 0 | for (; ver_char != '\0';) { |
433 | 0 | if (ver_char != '$') { |
434 | 0 | *pb_value++ = ver_char; |
435 | 0 | } |
436 | 0 | ver_char = *i1_ver++; |
437 | 0 | } |
438 | 0 | *pb_value = ver_char; |
439 | |
|
440 | 0 | break; |
441 | 0 | } |
442 | 26.3k | case IA_API_CMD_GET_API_SIZE: { |
443 | 26.3k | *pui_value = sizeof(ia_exhaacplus_dec_api_struct); |
444 | 26.3k | break; |
445 | 0 | } |
446 | 138k | case IA_API_CMD_INIT: { |
447 | 138k | switch (i_idx) { |
448 | 26.3k | case IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS: { |
449 | 26.3k | memset(p_obj_exhaacplus_dec, 0, sizeof(*p_obj_exhaacplus_dec)); |
450 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16; |
451 | 26.3k | p_obj_exhaacplus_dec->aac_config.flag_downmix = 0; |
452 | 26.3k | p_obj_exhaacplus_dec->aac_config.flag_08khz_out = 0; |
453 | 26.3k | p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0; |
454 | 26.3k | p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 0; |
455 | 26.3k | p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0; |
456 | 26.3k | p_obj_exhaacplus_dec->aac_config.header_dec_done = 0; |
457 | 26.3k | p_obj_exhaacplus_dec->aac_config.frame_status = 1; |
458 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 0; |
459 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0; |
460 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 1; |
461 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_samp_freq = 0; |
462 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_frame_size = 0; |
463 | | |
464 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_n_channels = 2; |
465 | 26.3k | p_obj_exhaacplus_dec->aac_config.i_channel_mask = 3; |
466 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 3; |
467 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0; |
468 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_effect_type = 0; |
469 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_target_loudness = -24; |
470 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_loud_norm_flag = 0; |
471 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_hq_esbr = 0; |
472 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr = 1; |
473 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps = 0; |
474 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr = 0; |
475 | 26.3k | p_obj_exhaacplus_dec->aac_config.loas_present = 0; |
476 | 26.3k | p_obj_exhaacplus_dec->aac_config.ld_decoder = 0; |
477 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 0; |
478 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 0; |
479 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108; |
480 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_set = 0; |
481 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 0; |
482 | 26.3k | p_obj_exhaacplus_dec->aac_config.output_level = -1; |
483 | 26.3k | #ifdef LOUDNESS_LEVELING_SUPPORT |
484 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = 1; |
485 | 26.3k | #endif |
486 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_max_channels = 6; |
487 | | |
488 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 0; |
489 | 26.3k | p_obj_exhaacplus_dec->aac_config.downmix = 0; |
490 | | |
491 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal = 0; |
492 | | |
493 | 26.3k | { |
494 | 26.3k | ia_aac_dec_tables_struct *pstr_aac_tables = |
495 | 26.3k | &p_obj_exhaacplus_dec->aac_tables; |
496 | 26.3k | pstr_aac_tables->pstr_huffmann_tables = |
497 | 26.3k | (ia_aac_dec_huffman_tables_struct |
498 | 26.3k | *)&ixheaacd_aac_huffmann_tables; |
499 | 26.3k | pstr_aac_tables->pstr_block_tables = |
500 | 26.3k | (ia_aac_dec_block_tables_struct *)&ixheaacd_aac_block_tables; |
501 | 26.3k | pstr_aac_tables->pstr_imdct_tables = |
502 | 26.3k | (ia_aac_dec_imdct_tables_struct *)&ixheaacd_imdct_tables; |
503 | | |
504 | 26.3k | ixheaacd_huff_tables_create(pstr_aac_tables); |
505 | 26.3k | } |
506 | 26.3k | ixheaacd_init_sbr_tables(&p_obj_exhaacplus_dec->str_sbr_tables); |
507 | 26.3k | p_obj_exhaacplus_dec->common_tables = |
508 | 26.3k | (ixheaacd_misc_tables *)&ixheaacd_str_fft_n_transcendent_tables; |
509 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_qmf_bands = 64; |
510 | | |
511 | 26.3k | break; |
512 | 0 | } |
513 | 26.3k | case IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS: { |
514 | 26.3k | ixheaacd_fill_aac_mem_tables(p_obj_exhaacplus_dec); |
515 | 26.3k | break; |
516 | 0 | } |
517 | 42.6k | case IA_CMD_TYPE_INIT_PROCESS: { |
518 | 42.6k | WORD32 err_code = 0; |
519 | 42.6k | if (p_obj_exhaacplus_dec->p_state_aac->fatal_err_present) { |
520 | 436 | err_code = IA_FATAL_ERROR; |
521 | 42.2k | } else { |
522 | 42.2k | err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec); |
523 | 42.2k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && err_code) { |
524 | 0 | if (err_code & IA_FATAL_ERROR) { |
525 | 0 | err_code = IA_XHEAAC_DEC_INIT_FATAL_EC_INIT_FAIL; |
526 | 0 | } else { |
527 | 0 | err_code = IA_XHEAAC_DEC_INIT_NONFATAL_EC_INIT_FAIL; |
528 | 0 | } |
529 | 0 | } |
530 | 42.2k | } |
531 | 42.6k | if (err_code != 0) { |
532 | 2.07k | if (err_code < 0) |
533 | 1.29k | p_obj_exhaacplus_dec->p_state_aac->fatal_err_present = 1; |
534 | 2.07k | p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = |
535 | 2.07k | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; |
536 | 2.07k | } |
537 | 42.6k | return err_code; |
538 | 0 | break; |
539 | 0 | } |
540 | 42.6k | case IA_CMD_TYPE_INIT_DONE_QUERY: { |
541 | 42.6k | if (p_obj_exhaacplus_dec->p_state_aac->ui_init_done == 1) { |
542 | 22.1k | *pui_value = 1; |
543 | 22.1k | } else { |
544 | 20.5k | *pui_value = 0; |
545 | 20.5k | } |
546 | 42.6k | break; |
547 | 0 | } |
548 | | |
549 | 0 | case IA_CMD_TYPE_GA_HDR: { |
550 | 0 | return ixheaacd_decoder_2_ga_hdr(p_obj_exhaacplus_dec); |
551 | 0 | break; |
552 | 0 | } |
553 | | |
554 | 0 | case IA_CMD_TYPE_FLUSH_MEM: { |
555 | 0 | return ixheaacd_decoder_flush_api(p_obj_exhaacplus_dec); |
556 | 0 | break; |
557 | 0 | } |
558 | | |
559 | 0 | default: { |
560 | 0 | return IA_XHEAAC_DEC_API_NONFATAL_CMD_TYPE_NOT_SUPPORTED; |
561 | 0 | } |
562 | 138k | }; |
563 | 95.3k | break; |
564 | 138k | } |
565 | 210k | case IA_API_CMD_SET_CONFIG_PARAM: { |
566 | 210k | switch (i_idx) { |
567 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_SAMP_FREQ: { |
568 | 0 | if ((*pui_value < 8000) || (*pui_value > 96000)) { |
569 | 0 | return (IA_XHEAAC_DEC_CONFIG_FATAL_INVALID_SAMPLE_RATE); |
570 | 0 | } |
571 | 0 | p_obj_exhaacplus_dec->aac_config.ui_samp_freq = *pui_value; |
572 | 0 | break; |
573 | 0 | } |
574 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_FRAMELENGTH_FLAG: { |
575 | 0 | if ((*pui_value != 1) && (*pui_value != 0)) { |
576 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_FRAMELENGTHFLAG); |
577 | 0 | } |
578 | 0 | p_obj_exhaacplus_dec->aac_config.ui_frame_size = *pui_value; |
579 | 0 | break; |
580 | 0 | } |
581 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_PCM_WDSZ: { |
582 | 0 | if ((*pui_value != 16) && (*pui_value != 24)) { |
583 | 0 | p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16; |
584 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_PCM_WDSZ); |
585 | 0 | } |
586 | 0 | p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = *pui_value; |
587 | 0 | break; |
588 | 0 | } |
589 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_DOWNMIX: { |
590 | 0 | if ((*pui_value != 1) && (*pui_value != 0)) { |
591 | 0 | p_obj_exhaacplus_dec->aac_config.flag_downmix = 0; |
592 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DOWNMIX); |
593 | 0 | } |
594 | 0 | p_obj_exhaacplus_dec->aac_config.flag_downmix = *pui_value; |
595 | 0 | p_obj_exhaacplus_dec->aac_config.downmix = *pui_value; |
596 | 0 | break; |
597 | 0 | } |
598 | | |
599 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_TOSTEREO: { |
600 | 0 | if ((*pui_value != 1) && (*pui_value != 0)) { |
601 | 0 | p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 1; |
602 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_TOSTEREO); |
603 | 0 | } |
604 | 0 | p_obj_exhaacplus_dec->aac_config.flag_to_stereo = *pui_value; |
605 | 0 | break; |
606 | 0 | } |
607 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_DSAMPLE: { |
608 | 0 | if ((*pui_value != 1) && (*pui_value != 0)) { |
609 | 0 | p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0; |
610 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DSAMPLE); |
611 | 0 | } |
612 | 0 | p_obj_exhaacplus_dec->aac_config.down_sample_flag = *pui_value; |
613 | 0 | break; |
614 | 0 | } |
615 | | |
616 | 26.3k | case IA_XHEAAC_DEC_CONFIG_PARAM_MP4FLAG: { |
617 | 26.3k | if ((*pui_value != 1) && (*pui_value != 0)) { |
618 | 0 | p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 0; |
619 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MP4FLAG); |
620 | 0 | } |
621 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = *pui_value; |
622 | 26.3k | break; |
623 | 26.3k | } |
624 | 26.3k | case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_CUT: { |
625 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1; |
626 | 26.3k | if (*pf_value > 1) { |
627 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 0; |
628 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRC_CUT); |
629 | 0 | } |
630 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_cut = |
631 | 26.3k | (WORD32)((*pf_value) * 100); |
632 | 26.3k | break; |
633 | 26.3k | } |
634 | | |
635 | 26.3k | case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_BOOST: { |
636 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1; |
637 | 26.3k | if (*pf_value > 1) { |
638 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 0; |
639 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRC_BOOST); |
640 | 0 | } |
641 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_boost = |
642 | 26.3k | (WORD32)((*pf_value) * 100); |
643 | 26.3k | break; |
644 | 26.3k | } |
645 | | |
646 | 26.3k | case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL: { |
647 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1; |
648 | 26.3k | p_obj_exhaacplus_dec->aac_config.i_loud_ref_level = *pui_value_signed; |
649 | 26.3k | if (*pui_value > 127) { |
650 | 9.73k | p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108; |
651 | 9.73k | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRC_TARGET); |
652 | 9.73k | } |
653 | 16.6k | p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = *pui_value; |
654 | 16.6k | break; |
655 | 26.3k | } |
656 | 26.3k | case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_HEAVY_COMP: { |
657 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_set = 1; |
658 | 26.3k | if ((*pui_value != 1) && (*pui_value != 0)) { |
659 | 19.3k | p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp = 0; |
660 | 19.3k | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DRCFLAG); |
661 | 19.3k | } |
662 | 6.96k | p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp = *pui_value; |
663 | 6.96k | break; |
664 | 26.3k | } |
665 | 0 | case IA_XHEAAC_DEC_CONFIG_DISABLE_SYNC: { |
666 | 0 | if ((*pui_value != 1) && (*pui_value != 0)) { |
667 | 0 | p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0; |
668 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_SYNCFLAG); |
669 | 0 | } |
670 | 0 | p_obj_exhaacplus_dec->aac_config.ui_disable_sync = *pui_value; |
671 | 0 | break; |
672 | 0 | } |
673 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_AUTO_SBR_UPSAMPLE: { |
674 | 0 | if ((*pui_value != 1) && (*pui_value != 0)) { |
675 | 0 | p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 0; |
676 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_SBRUPFLAG); |
677 | 0 | } |
678 | 0 | p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = *pui_value; |
679 | 0 | break; |
680 | 0 | } |
681 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_MAX_CHANNEL: { |
682 | 0 | if (*pui_value > 8) { |
683 | 0 | p_obj_exhaacplus_dec->aac_config.ui_max_channels = 8; |
684 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MAX_CHANNEL); |
685 | 0 | } |
686 | 0 | if (*pui_value < 2) { |
687 | 0 | p_obj_exhaacplus_dec->aac_config.ui_max_channels = 2; |
688 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MAX_CHANNEL); |
689 | 0 | } |
690 | 0 | p_obj_exhaacplus_dec->aac_config.ui_max_channels = *pui_value; |
691 | 0 | break; |
692 | 0 | } |
693 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_FRAMESIZE: { |
694 | 0 | if (*pui_value == 1) { |
695 | 0 | p_obj_exhaacplus_dec->aac_config.framesize_480 = 1; |
696 | 0 | } else if (*pui_value == 0) { |
697 | 0 | p_obj_exhaacplus_dec->aac_config.framesize_480 = 0; |
698 | 0 | } else { |
699 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_FRAMSZ); |
700 | 0 | } |
701 | 0 | break; |
702 | 0 | } |
703 | | |
704 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_LD_TESTING: { |
705 | 0 | if (*pui_value == 1) { |
706 | 0 | p_obj_exhaacplus_dec->aac_config.ld_decoder = 1; |
707 | 0 | } else if (*pui_value == 0) { |
708 | 0 | p_obj_exhaacplus_dec->aac_config.ld_decoder = 0; |
709 | 0 | } else { |
710 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_LD_CONFIG); |
711 | 0 | } |
712 | 0 | break; |
713 | 0 | } |
714 | | |
715 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_COUP_CHANNEL: { |
716 | 0 | if (*pui_value > 16) { |
717 | 0 | p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 1; |
718 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_COUP_CHANNEL); |
719 | 0 | } |
720 | 0 | p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = *pui_value; |
721 | 0 | break; |
722 | 0 | } |
723 | | |
724 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_DOWNMIX_STEREO: { |
725 | 0 | if ((*pui_value != 1) && (*pui_value != 0)) { |
726 | 0 | p_obj_exhaacplus_dec->aac_config.downmix = 0; |
727 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_DOWNMIX_STEREO); |
728 | 0 | } |
729 | 0 | p_obj_exhaacplus_dec->aac_config.downmix = *pui_value; |
730 | 0 | break; |
731 | 0 | } |
732 | | |
733 | 26.3k | case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE: { |
734 | 26.3k | if (((*pui_value_signed) > 8) || ((*pui_value_signed) < -1)) { |
735 | 20.5k | p_obj_exhaacplus_dec->aac_config.ui_effect_type = -1; |
736 | 20.5k | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_EFFECT_TYPE); |
737 | 20.5k | } |
738 | 5.76k | p_obj_exhaacplus_dec->aac_config.ui_effect_type = *pui_value_signed; |
739 | 5.76k | break; |
740 | 26.3k | } |
741 | 26.3k | case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS: { |
742 | 26.3k | if (*pui_value_signed >= 0) { |
743 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_loud_norm_flag = 1; |
744 | 26.3k | } |
745 | 26.3k | *pui_value_signed = -(*pui_value_signed >> 2); |
746 | 26.3k | if (((*pui_value_signed) > 0) || ((*pui_value_signed) < -63)) { |
747 | 0 | p_obj_exhaacplus_dec->aac_config.ui_target_loudness = 0; |
748 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_TARGET_LOUDNESS); |
749 | 0 | } |
750 | 26.3k | p_obj_exhaacplus_dec->aac_config.ui_target_loudness = |
751 | 26.3k | *pui_value_signed; |
752 | 26.3k | break; |
753 | 26.3k | } |
754 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_HQ_ESBR: { |
755 | 0 | if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) { |
756 | 0 | p_obj_exhaacplus_dec->aac_config.ui_hq_esbr = 0; |
757 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_ESBR_HQ_FLAG); |
758 | 0 | } |
759 | 0 | p_obj_exhaacplus_dec->aac_config.ui_hq_esbr = *pui_value_signed; |
760 | 0 | break; |
761 | 0 | } |
762 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_PS_ENABLE: { |
763 | 0 | if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) { |
764 | 0 | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps = 0; |
765 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_ESBR_PS_FLAG); |
766 | 0 | } |
767 | 0 | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps = *pui_value_signed; |
768 | 0 | break; |
769 | 0 | } |
770 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_PEAK_LIMITER: { |
771 | 0 | if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) { |
772 | 0 | p_obj_exhaacplus_dec->aac_config.peak_limiter_off = 0; |
773 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_PEAK_LIM_FLAG_TYPE); |
774 | 0 | } |
775 | 0 | p_obj_exhaacplus_dec->aac_config.peak_limiter_off = *pui_value_signed; |
776 | 0 | break; |
777 | 0 | } |
778 | 0 | case IA_XHEAAC_DEC_CONFIG_ERROR_CONCEALMENT: { |
779 | 0 | if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) { |
780 | 0 | p_obj_exhaacplus_dec->aac_config.ui_err_conceal = 0; |
781 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_ERR_CONCEAL_FLAG_TYPE); |
782 | 0 | } |
783 | 0 | p_obj_exhaacplus_dec->aac_config.ui_err_conceal = *pui_value_signed; |
784 | 0 | break; |
785 | 0 | } |
786 | 0 | case IA_XHEAAC_DEC_CONFIG_PARAM_ESBR: { |
787 | 0 | if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) { |
788 | 0 | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr = 1; |
789 | 0 | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_ESBR_FLAG); |
790 | 0 | } |
791 | 0 | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr = *pui_value_signed; |
792 | 0 | break; |
793 | 0 | } |
794 | 0 | #ifdef LOUDNESS_LEVELING_SUPPORT |
795 | 26.3k | case IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUDNESS_LEVELING: { |
796 | 26.3k | if (((*pui_value_signed) != 0) && ((*pui_value_signed) != 1)) { |
797 | 22.1k | p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = 1; |
798 | 22.1k | return (IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_LOUDNESS_LEVELING_FLAG); |
799 | 22.1k | } |
800 | 4.23k | p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag = *pui_value_signed; |
801 | 4.23k | break; |
802 | 26.3k | } |
803 | 0 | #endif |
804 | 0 | default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_CONFIG_PARAM; } |
805 | 210k | } |
806 | 138k | break; |
807 | 210k | } |
808 | | |
809 | 1.42M | case IA_API_CMD_GET_CONFIG_PARAM: { |
810 | 1.42M | UWORD32 i; |
811 | 1.42M | WORD32 *pvalue = |
812 | 1.42M | (WORD32 *)(&p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz); |
813 | 1.42M | if (IA_XHEAAC_DEC_CONFIG_PARAM_NUM_CHANNELS == i_idx) { |
814 | 22.1k | if (p_obj_exhaacplus_dec->p_state_aac != NULL && |
815 | 22.1k | p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle |
816 | 22.1k | .heaac_mps_present == 1) { |
817 | 5.05k | *pui_value = p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle |
818 | 5.05k | .num_output_channels_at; |
819 | 17.0k | } else { |
820 | 17.0k | *pui_value = pvalue[i_idx]; |
821 | 17.0k | } |
822 | 1.40M | } else if (IA_XHEAAC_DEC_CONFIG_PARAM_CHANNEL_MASK == i_idx) { |
823 | 22.1k | if (p_obj_exhaacplus_dec->p_state_aac != NULL && |
824 | 22.1k | p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle |
825 | 22.1k | .heaac_mps_present == 1) { |
826 | 5.05k | *pui_value = p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle |
827 | 5.05k | .bs_config.ui_channel_mask; |
828 | 17.0k | } else { |
829 | 17.0k | *pui_value = pvalue[i_idx]; |
830 | 17.0k | } |
831 | 22.1k | } else |
832 | 1.38M | if (i_idx >= 0 && i_idx <= 8) { |
833 | 176k | *pui_value = pvalue[i_idx]; |
834 | 1.20M | } else if (IA_ENHAACPLUS_DEC_CONFIG_GET_NUM_PRE_ROLL_FRAMES == i_idx) { |
835 | 0 | WORD32 *ptri_value = (WORD32 *)pv_value; |
836 | 0 | ia_audio_specific_config_struct *ptr_audio_specific_config = |
837 | 0 | ((ia_audio_specific_config_struct *) |
838 | 0 | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
839 | |
|
840 | 0 | for (i = 0; i < MAX_AUDIO_PREROLLS + 1; i++) { |
841 | 0 | if (ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
842 | 0 | .preroll_bytes[i] == 0) { |
843 | 0 | break; |
844 | 0 | } |
845 | 0 | } |
846 | |
|
847 | 0 | *ptri_value = i; |
848 | 1.20M | } else if (IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR == i_idx) { |
849 | 22.1k | ia_audio_specific_config_struct *ptr_audio_specific_config = |
850 | 22.1k | ((ia_audio_specific_config_struct *) |
851 | 22.1k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
852 | | |
853 | 32.5k | for (i = 0; i < ptr_audio_specific_config->str_usac_config |
854 | 32.5k | .str_usac_dec_config.num_config_extensions; |
855 | 22.1k | i++) { |
856 | 10.3k | pp_value[i] = ptr_audio_specific_config->str_usac_config |
857 | 10.3k | .str_usac_dec_config.usac_cfg_ext_info_buf[i]; |
858 | 10.3k | } |
859 | | |
860 | 41.9k | for (i = 0; i < ptr_audio_specific_config->str_usac_config |
861 | 41.9k | .str_usac_dec_config.num_elements; |
862 | 22.1k | i++) { |
863 | 19.8k | if (ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
864 | 19.8k | .usac_ext_ele_payload_present[i]) { |
865 | 1.81k | pp_value[i + 16] = |
866 | 1.81k | ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
867 | 1.81k | .usac_ext_ele_payload_buf[i]; |
868 | 1.81k | } |
869 | 19.8k | } |
870 | 1.18M | } else if (IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES == i_idx) { |
871 | 22.1k | WORD32 *ptri_value = (WORD32 *)pv_value; |
872 | 22.1k | ia_audio_specific_config_struct *ptr_audio_specific_config = |
873 | 22.1k | ((ia_audio_specific_config_struct *) |
874 | 22.1k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
875 | 32.5k | for (i = 0; i < ptr_audio_specific_config->str_usac_config |
876 | 32.5k | .str_usac_dec_config.num_config_extensions; |
877 | 22.1k | i++) { |
878 | 10.3k | ptri_value[i] = ptr_audio_specific_config->str_usac_config |
879 | 10.3k | .str_usac_dec_config.usac_cfg_ext_info_len[i]; |
880 | 10.3k | } |
881 | 41.9k | for (i = 0; i < ptr_audio_specific_config->str_usac_config |
882 | 41.9k | .str_usac_dec_config.num_elements; |
883 | 22.1k | i++) { |
884 | 19.8k | ptri_value[i + 16] = |
885 | 19.8k | ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
886 | 19.8k | .usac_ext_ele_payload_len[i]; |
887 | 19.8k | } |
888 | | |
889 | 1.16M | } else if (IA_ENHAACPLUS_DEC_DRC_IS_CONFIG_CHANGED == i_idx) { |
890 | 0 | *pui_value = p_obj_exhaacplus_dec->p_state_aac->drc_config_changed; |
891 | 1.16M | } else if (IA_ENHAACPLUS_DEC_DRC_APPLY_CROSSFADE == i_idx) { |
892 | 0 | *pui_value = p_obj_exhaacplus_dec->p_state_aac->apply_crossfade; |
893 | 1.16M | } else if (IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE == i_idx) { |
894 | 22.1k | UWORD32 *ptri_value = (UWORD32 *)pv_value; |
895 | 22.1k | ia_audio_specific_config_struct *ptr_audio_specific_config = |
896 | 22.1k | ((ia_audio_specific_config_struct *) |
897 | 22.1k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
898 | 22.1k | *ptri_value = ptr_audio_specific_config->str_usac_config |
899 | 22.1k | .str_usac_dec_config.num_elements; |
900 | | |
901 | 1.13M | } else if (IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT == i_idx) { |
902 | 22.1k | UWORD32 *ptri_value = (UWORD32 *)pv_value; |
903 | 22.1k | ia_audio_specific_config_struct *ptr_audio_specific_config = |
904 | 22.1k | ((ia_audio_specific_config_struct *) |
905 | 22.1k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
906 | 22.1k | *ptri_value = ptr_audio_specific_config->str_usac_config |
907 | 22.1k | .str_usac_dec_config.num_config_extensions; |
908 | 1.11M | } else if (IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN == i_idx) { |
909 | 558k | UWORD32 *ptri_value = (UWORD32 *)pv_value; |
910 | 558k | ia_audio_specific_config_struct *ptr_audio_specific_config = |
911 | 558k | ((ia_audio_specific_config_struct *) |
912 | 558k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
913 | 558k | WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config |
914 | 558k | .str_usac_dec_config.preroll_counter; |
915 | 558k | *ptri_value = |
916 | 558k | ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
917 | 558k | .usac_ext_gain_payload_len[preroll_counter]; |
918 | 558k | } else if (IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF == i_idx) { |
919 | 558k | WORD32 payload_buffer_offeset = 0; |
920 | 558k | ia_audio_specific_config_struct *ptr_audio_specific_config = |
921 | 558k | ((ia_audio_specific_config_struct *) |
922 | 558k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
923 | 558k | WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config |
924 | 558k | .str_usac_dec_config.preroll_counter; |
925 | 560k | for (i = 0; i < (UWORD32)preroll_counter; i++) |
926 | 2.16k | payload_buffer_offeset += |
927 | 2.16k | ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
928 | 2.16k | .usac_ext_gain_payload_len[i] * |
929 | 2.16k | sizeof(WORD8); |
930 | 558k | *pp_value = ptr_audio_specific_config->str_usac_config |
931 | 558k | .str_usac_dec_config.usac_ext_gain_payload_buf + |
932 | 558k | payload_buffer_offeset; |
933 | 558k | } else if (IA_XHEAAC_DEC_CONFIG_PARAM_AOT == i_idx) { |
934 | 0 | if (p_obj_exhaacplus_dec->p_state_aac != NULL) { |
935 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag == 1) { |
936 | 0 | ia_audio_specific_config_struct *ptr_audio_specific_config = |
937 | 0 | ((ia_audio_specific_config_struct *) |
938 | 0 | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
939 | 0 | *pui_value = ptr_audio_specific_config->audio_object_type; |
940 | 0 | } else { |
941 | 0 | *pui_value = p_obj_exhaacplus_dec->p_state_aac->audio_object_type; |
942 | 0 | } |
943 | 0 | } else { |
944 | 0 | *pui_value = AOT_AAC_LC; |
945 | 0 | } |
946 | 0 | } |
947 | 0 | #ifdef LOUDNESS_LEVELING_SUPPORT |
948 | 0 | else if (IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUDNESS_LEVELING == i_idx) { |
949 | 0 | WORD32 *ui_value = |
950 | 0 | (WORD32 *)(&p_obj_exhaacplus_dec->aac_config.ui_loudness_leveling_flag); |
951 | 0 | *pui_value = *ui_value; |
952 | 0 | } |
953 | 0 | #endif |
954 | 0 | else { |
955 | 0 | return IA_XHEAAC_DEC_API_FATAL_INVALID_CONFIG_PARAM; |
956 | 0 | } |
957 | 1.42M | break; |
958 | 1.42M | } |
959 | | |
960 | 1.42M | case IA_API_CMD_GET_MEMTABS_SIZE: { |
961 | 26.3k | *pui_value = (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) * |
962 | 26.3k | (IA_ENHAACPDEC_NUM_MEMTABS); |
963 | 26.3k | break; |
964 | 1.42M | } |
965 | 0 | case IA_API_CMD_GET_LOUDNESS_VAL: { |
966 | 0 | *pui_value = p_obj_exhaacplus_dec->aac_config.output_level; |
967 | 0 | break; |
968 | 1.42M | } |
969 | 26.3k | case IA_API_CMD_SET_MEMTABS_PTR: { |
970 | 26.3k | if (pv_value == NULL) return IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC; |
971 | 26.3k | memset(pv_value, 0, (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) * |
972 | 26.3k | (IA_ENHAACPDEC_NUM_MEMTABS)); |
973 | | |
974 | 26.3k | p_obj_exhaacplus_dec->p_mem_info_aac = pv_value; |
975 | 26.3k | p_obj_exhaacplus_dec->pp_mem_aac = |
976 | 26.3k | (pVOID *)((WORD8 *)pv_value + |
977 | 26.3k | sizeof(ia_mem_info_struct) * IA_ENHAACPDEC_NUM_MEMTABS); |
978 | | |
979 | 26.3k | break; |
980 | 26.3k | } |
981 | 0 | case IA_API_CMD_GET_N_MEMTABS: { |
982 | 0 | *pui_value = IA_ENHAACPDEC_NUM_MEMTABS; |
983 | 0 | break; |
984 | 26.3k | } |
985 | | |
986 | 0 | case IA_API_CMD_GET_N_TABLES: { |
987 | 0 | *pui_value = NUM_AAC_TABLES + NUM_MPS_TABLES; |
988 | 0 | break; |
989 | 26.3k | } |
990 | 1.11M | case IA_API_CMD_EXECUTE: { |
991 | 1.11M | switch (i_idx) { |
992 | 558k | case IA_CMD_TYPE_DO_EXECUTE: { |
993 | 558k | WORD32 err_code = 0; |
994 | 558k | if (!p_obj_exhaacplus_dec->p_state_aac->ui_init_done || |
995 | 558k | p_obj_exhaacplus_dec->p_state_aac->fatal_err_present) { |
996 | 3.96k | err_code = IA_FATAL_ERROR; |
997 | 554k | } else { |
998 | 554k | memset(p_obj_exhaacplus_dec->p_state_aac->qshift_adj, 0, |
999 | 554k | sizeof(p_obj_exhaacplus_dec->p_state_aac->qshift_adj)); |
1000 | 554k | p_obj_exhaacplus_dec->p_state_aac->qshift_cnt = 0; |
1001 | 554k | err_code = ixheaacd_dec_execute(p_obj_exhaacplus_dec); |
1002 | 554k | } |
1003 | 558k | if (err_code != IA_NO_ERROR) { |
1004 | 22.8k | if (err_code < 0) { |
1005 | 7.57k | p_obj_exhaacplus_dec->p_state_aac->fatal_err_present = 1; |
1006 | 7.57k | } |
1007 | 22.8k | p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = |
1008 | 22.8k | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; |
1009 | 22.8k | } |
1010 | 558k | return err_code; |
1011 | 0 | break; |
1012 | 0 | } |
1013 | 558k | case IA_CMD_TYPE_DONE_QUERY: { |
1014 | 558k | if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 1) { |
1015 | 0 | *pui_value = 1; |
1016 | 558k | } else { |
1017 | 558k | *pui_value = 0; |
1018 | 558k | } |
1019 | | |
1020 | 558k | break; |
1021 | 0 | } |
1022 | 0 | default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_EXECUTE_TYPE; } |
1023 | 1.11M | }; |
1024 | 558k | break; |
1025 | 1.11M | } |
1026 | 601k | case IA_API_CMD_GET_CURIDX_INPUT_BUF: { |
1027 | 601k | *pui_value = p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed; |
1028 | 601k | break; |
1029 | 1.11M | } |
1030 | 601k | case IA_API_CMD_SET_INPUT_BYTES: { |
1031 | 601k | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes = *pui_value; |
1032 | 601k | break; |
1033 | 1.11M | } |
1034 | 558k | case IA_API_CMD_GET_OUTPUT_BYTES: { |
1035 | 558k | if (1 == i_idx) { |
1036 | 0 | *pui_value = p_obj_exhaacplus_dec->p_state_aac->ui_mps_out_bytes; |
1037 | 558k | } else { |
1038 | 558k | *pui_value = p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes; |
1039 | 558k | } |
1040 | 558k | if (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_USAC) { |
1041 | 261k | ia_audio_specific_config_struct *ptr_audio_specific_config = |
1042 | 261k | ((ia_audio_specific_config_struct *) |
1043 | 261k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
1044 | | |
1045 | 261k | WORD32 preroll_counter = ptr_audio_specific_config->str_usac_config |
1046 | 261k | .str_usac_dec_config.preroll_counter; |
1047 | | |
1048 | 261k | *pui_value = ptr_audio_specific_config->str_usac_config |
1049 | 261k | .str_usac_dec_config.preroll_bytes[preroll_counter]; |
1050 | | |
1051 | 261k | preroll_counter++; |
1052 | 261k | if (preroll_counter > (MAX_AUDIO_PREROLLS + 1)) return IA_FATAL_ERROR; |
1053 | 261k | ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
1054 | 261k | .preroll_counter = preroll_counter; |
1055 | 261k | } |
1056 | 557k | break; |
1057 | 558k | } |
1058 | 557k | case IA_API_CMD_INPUT_OVER: { |
1059 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->ui_input_over = 1; |
1060 | 26.3k | break; |
1061 | 558k | } |
1062 | 0 | default: { return IA_XHEAAC_DEC_API_FATAL_INVALID_CMD; } |
1063 | 4.75M | }; |
1064 | 4.08M | return IA_NO_ERROR; |
1065 | 4.75M | } |
1066 | | |
1067 | 0 | IA_ERRORCODE ixheaacd_decoder_2_ga_hdr(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) { |
1068 | 0 | IA_ERRORCODE err_code = IA_NO_ERROR; |
1069 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) { |
1070 | 0 | p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16; |
1071 | 0 | p_obj_exhaacplus_dec->aac_config.flag_downmix = 0; |
1072 | 0 | p_obj_exhaacplus_dec->aac_config.flag_08khz_out = 0; |
1073 | 0 | p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0; |
1074 | 0 | p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 0; |
1075 | 0 | p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0; |
1076 | 0 | p_obj_exhaacplus_dec->aac_config.header_dec_done = 0; |
1077 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 1; |
1078 | 0 | p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 1; |
1079 | 0 | p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0; |
1080 | 0 | p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 1; |
1081 | 0 | p_obj_exhaacplus_dec->aac_config.ui_samp_freq = 0; |
1082 | 0 | p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 3; |
1083 | 0 | p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 2; |
1084 | 0 | p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr = 0; |
1085 | 0 | p_obj_exhaacplus_dec->aac_config.loas_present = 0; |
1086 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 0; |
1087 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 0; |
1088 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108; |
1089 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_set = 0; |
1090 | 0 | p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 1; |
1091 | |
|
1092 | 0 | p_obj_exhaacplus_dec->aac_config.ui_max_channels = 6; |
1093 | |
|
1094 | 0 | p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 0; |
1095 | 0 | p_obj_exhaacplus_dec->aac_config.downmix = 0; |
1096 | |
|
1097 | 0 | { |
1098 | 0 | ia_aac_dec_tables_struct *pstr_aac_tables = |
1099 | 0 | &p_obj_exhaacplus_dec->aac_tables; |
1100 | 0 | pstr_aac_tables->pstr_huffmann_tables = |
1101 | 0 | (ia_aac_dec_huffman_tables_struct *)&ixheaacd_aac_huffmann_tables; |
1102 | 0 | pstr_aac_tables->pstr_block_tables = |
1103 | 0 | (ia_aac_dec_block_tables_struct *)&ixheaacd_aac_block_tables; |
1104 | 0 | pstr_aac_tables->pstr_imdct_tables = |
1105 | 0 | (ia_aac_dec_imdct_tables_struct *)&ixheaacd_imdct_tables; |
1106 | |
|
1107 | 0 | ixheaacd_huff_tables_create(pstr_aac_tables); |
1108 | 0 | } |
1109 | 0 | ixheaacd_init_sbr_tables(&p_obj_exhaacplus_dec->str_sbr_tables); |
1110 | 0 | p_obj_exhaacplus_dec->common_tables = |
1111 | 0 | (ixheaacd_misc_tables *)&ixheaacd_str_fft_n_transcendent_tables; |
1112 | 0 | p_obj_exhaacplus_dec->aac_config.ui_qmf_bands = 64; |
1113 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_init_done = 0; |
1114 | |
|
1115 | 0 | err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec); |
1116 | 0 | } else { |
1117 | 0 | p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 0; |
1118 | 0 | err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec); |
1119 | 0 | } |
1120 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && err_code) { |
1121 | 0 | if (err_code & IA_FATAL_ERROR) { |
1122 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_EC_INIT_FAIL; |
1123 | 0 | } else { |
1124 | 0 | return IA_XHEAAC_DEC_INIT_NONFATAL_EC_INIT_FAIL; |
1125 | 0 | } |
1126 | 0 | } else { |
1127 | 0 | return err_code; |
1128 | 0 | } |
1129 | 0 | } |
1130 | | |
1131 | 0 | IA_ERRORCODE ixheaacd_decoder_flush_api(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) { |
1132 | 0 | IA_ERRORCODE err_code = IA_NO_ERROR; |
1133 | 0 | UWORD8 *header_temp_ptr; |
1134 | 0 | WORD32 header_length; |
1135 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) { |
1136 | 0 | header_temp_ptr = p_obj_exhaacplus_dec->p_state_aac->header_ptr; |
1137 | 0 | header_length = p_obj_exhaacplus_dec->p_state_aac->header_length; |
1138 | 0 | memset(p_obj_exhaacplus_dec->p_state_aac, 0, |
1139 | 0 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8)); |
1140 | 0 | { |
1141 | 0 | pUWORD8 p_temp = (pUWORD8)p_obj_exhaacplus_dec->p_state_aac; |
1142 | 0 | UWORD32 *meminfo = (UWORD32 *)p_obj_exhaacplus_dec->p_mem_info_aac; |
1143 | 0 | UWORD32 pers_size = meminfo[0]; |
1144 | 0 | p_temp = p_temp + pers_size - |
1145 | 0 | (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) + |
1146 | 0 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8) + |
1147 | 0 | IXHEAAC_GET_SIZE_ALIGNED(MAX_HEADER_BUF_SIZE, BYTE_ALIGN_8)); |
1148 | |
|
1149 | 0 | p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data = p_temp; |
1150 | 0 | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config = |
1151 | 0 | p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8); |
1152 | 0 | p_obj_exhaacplus_dec->p_state_aac->header_ptr = |
1153 | 0 | p_temp + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8) + |
1154 | 0 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8); |
1155 | 0 | } |
1156 | 0 | memset(&(p_obj_exhaacplus_dec->aac_config), 0, |
1157 | 0 | sizeof(ia_aac_dec_config_struct)); |
1158 | |
|
1159 | 0 | p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16; |
1160 | 0 | p_obj_exhaacplus_dec->aac_config.flag_downmix = 0; |
1161 | 0 | p_obj_exhaacplus_dec->aac_config.flag_08khz_out = 0; |
1162 | 0 | p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0; |
1163 | 0 | p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 0; |
1164 | 0 | p_obj_exhaacplus_dec->aac_config.down_sample_flag = 0; |
1165 | 0 | p_obj_exhaacplus_dec->aac_config.header_dec_done = 0; |
1166 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 1; |
1167 | 0 | p_obj_exhaacplus_dec->aac_config.ui_mp4_flag = 1; |
1168 | 0 | p_obj_exhaacplus_dec->aac_config.ui_disable_sync = 0; |
1169 | 0 | p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample = 1; |
1170 | 0 | p_obj_exhaacplus_dec->aac_config.ui_samp_freq = 0; |
1171 | 0 | p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 3; |
1172 | 0 | p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 2; |
1173 | 0 | p_obj_exhaacplus_dec->aac_config.ui_pce_found_in_hdr = 0; |
1174 | 0 | p_obj_exhaacplus_dec->aac_config.loas_present = 0; |
1175 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_boost = 0; |
1176 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_cut = 0; |
1177 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_target_level = 108; |
1178 | 0 | p_obj_exhaacplus_dec->aac_config.ui_drc_set = 0; |
1179 | 0 | p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 1; |
1180 | |
|
1181 | 0 | p_obj_exhaacplus_dec->aac_config.ui_max_channels = 6; |
1182 | |
|
1183 | 0 | p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 0; |
1184 | 0 | p_obj_exhaacplus_dec->aac_config.downmix = 0; |
1185 | 0 | p_obj_exhaacplus_dec->p_state_aac->peak_lim_init = 0; |
1186 | |
|
1187 | 0 | { |
1188 | 0 | ia_aac_dec_tables_struct *pstr_aac_tables = |
1189 | 0 | &p_obj_exhaacplus_dec->aac_tables; |
1190 | 0 | pstr_aac_tables->pstr_huffmann_tables = |
1191 | 0 | (ia_aac_dec_huffman_tables_struct *)&ixheaacd_aac_huffmann_tables; |
1192 | 0 | pstr_aac_tables->pstr_block_tables = |
1193 | 0 | (ia_aac_dec_block_tables_struct *)&ixheaacd_aac_block_tables; |
1194 | 0 | pstr_aac_tables->pstr_imdct_tables = |
1195 | 0 | (ia_aac_dec_imdct_tables_struct *)&ixheaacd_imdct_tables; |
1196 | |
|
1197 | 0 | ixheaacd_huff_tables_create(pstr_aac_tables); |
1198 | 0 | } |
1199 | 0 | ixheaacd_init_sbr_tables(&p_obj_exhaacplus_dec->str_sbr_tables); |
1200 | 0 | p_obj_exhaacplus_dec->common_tables = |
1201 | 0 | (ixheaacd_misc_tables *)&ixheaacd_str_fft_n_transcendent_tables; |
1202 | 0 | p_obj_exhaacplus_dec->aac_config.ui_qmf_bands = 64; |
1203 | 0 | p_obj_exhaacplus_dec->p_state_aac->header_ptr = header_temp_ptr; |
1204 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes = header_length; |
1205 | 0 | p_obj_exhaacplus_dec->p_state_aac->header_length = header_length; |
1206 | |
|
1207 | 0 | err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec); |
1208 | 0 | } else { |
1209 | 0 | p_obj_exhaacplus_dec->aac_config.ui_flush_cmd = 0; |
1210 | 0 | err_code = ixheaacd_dec_init(p_obj_exhaacplus_dec); |
1211 | 0 | } |
1212 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && err_code) { |
1213 | 0 | if (err_code & IA_FATAL_ERROR) { |
1214 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_EC_INIT_FAIL; |
1215 | 0 | } else { |
1216 | 0 | return IA_XHEAAC_DEC_INIT_NONFATAL_EC_INIT_FAIL; |
1217 | 0 | } |
1218 | 0 | } else { |
1219 | 0 | return err_code; |
1220 | 0 | } |
1221 | 0 | } |
1222 | | |
1223 | | static PLATFORM_INLINE WORD32 |
1224 | 26.3k | ixheaacd_persistent_buffer_sizes(WORD32 num_channel) { |
1225 | 26.3k | WORD32 size_buffers = 0; |
1226 | | |
1227 | 26.3k | WORD32 temp; |
1228 | 26.3k | WORD32 max_channels; |
1229 | | |
1230 | 26.3k | size_buffers += IXHEAAC_GET_SIZE_ALIGNED(4 * 512 * num_channel * sizeof(WORD32), BYTE_ALIGN_8); |
1231 | | |
1232 | 26.3k | size_buffers += |
1233 | 26.3k | num_channel * IXHEAAC_GET_SIZE_ALIGNED(ltp_buffer_size * sizeof(WORD16), BYTE_ALIGN_8); |
1234 | | |
1235 | 26.3k | size_buffers += |
1236 | 26.3k | num_channel * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_channel_info), BYTE_ALIGN_8); |
1237 | | |
1238 | 26.3k | if (num_channel > 2) { |
1239 | 26.3k | max_channels = MAX_BS_ELEMENT; |
1240 | 26.3k | } else { |
1241 | 0 | max_channels = 2; |
1242 | 0 | } |
1243 | 26.3k | size_buffers += (max_channels)*2 * |
1244 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), BYTE_ALIGN_8); |
1245 | | |
1246 | 26.3k | size_buffers += |
1247 | 26.3k | num_channel * IXHEAAC_GET_SIZE_ALIGNED(MAXSBRBYTES * sizeof(WORD8), BYTE_ALIGN_8); |
1248 | | |
1249 | 26.3k | size_buffers += |
1250 | 26.3k | num_channel * IXHEAAC_GET_SIZE_ALIGNED(MAXSBRBYTES * sizeof(WORD8), BYTE_ALIGN_8); |
1251 | | |
1252 | 26.3k | size_buffers += |
1253 | 26.3k | 2 * num_channel * |
1254 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED( |
1255 | 26.3k | (QMF_FILTER_STATE_ANA_SIZE + 2 * NO_ANALYSIS_CHANNELS) * sizeof(WORD16), BYTE_ALIGN_8); |
1256 | | |
1257 | 26.3k | size_buffers += |
1258 | 26.3k | 2 * num_channel * |
1259 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED( |
1260 | 26.3k | (QMF_FILTER_STATE_ANA_SIZE + 2 * NO_ANALYSIS_CHANNELS) * sizeof(WORD32), BYTE_ALIGN_8); |
1261 | | |
1262 | 26.3k | size_buffers += |
1263 | 26.3k | 2 * num_channel * |
1264 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED( |
1265 | 26.3k | (QMF_FILTER_STATE_SYN_SIZE + 2 * NO_SYNTHESIS_CHANNELS) * sizeof(WORD16), BYTE_ALIGN_8); |
1266 | | |
1267 | 26.3k | size_buffers += |
1268 | 26.3k | 2 * num_channel * |
1269 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED( |
1270 | 26.3k | (QMF_FILTER_STATE_SYN_SIZE + 2 * NO_SYNTHESIS_CHANNELS) * sizeof(WORD32), BYTE_ALIGN_8); |
1271 | | |
1272 | 26.3k | size_buffers += num_channel * 2 * |
1273 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(MAX_OV_COLS * NO_SYNTHESIS_CHANNELS * sizeof(WORD32), |
1274 | 26.3k | BYTE_ALIGN_8); |
1275 | | |
1276 | 26.3k | size_buffers += 2 * LPC_ORDER * num_channel * |
1277 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(NO_ANALYSIS_CHANNELS * sizeof(WORD32), BYTE_ALIGN_8); |
1278 | | |
1279 | 26.3k | size_buffers += 2 * IXHEAAC_GET_SIZE_ALIGNED(LPC_ORDER * sizeof(WORD32 *), BYTE_ALIGN_8); |
1280 | | |
1281 | 26.3k | size_buffers += 2 * LPC_ORDER * num_channel * |
1282 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(NO_ANALYSIS_CHANNELS * sizeof(WORD32), BYTE_ALIGN_8); |
1283 | | |
1284 | 26.3k | size_buffers += 2 * num_channel * 3 * |
1285 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(MAX_FREQ_COEFFS * sizeof(WORD16), BYTE_ALIGN_8); |
1286 | | |
1287 | 26.3k | temp = IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_freq_band_data_struct), BYTE_ALIGN_8) + |
1288 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_prev_frame_data_struct), BYTE_ALIGN_8) + |
1289 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_channel_struct), BYTE_ALIGN_8) + |
1290 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_header_data_struct), BYTE_ALIGN_8); |
1291 | 26.3k | size_buffers += 2 * num_channel * temp; |
1292 | | |
1293 | 26.3k | size_buffers += MAX_BS_ELEMENT * |
1294 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaac_drc_bs_data_struct *), BYTE_ALIGN_8); |
1295 | | |
1296 | 26.3k | size_buffers += num_channel * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_ps_dec_struct), BYTE_ALIGN_8); |
1297 | | |
1298 | 26.3k | { |
1299 | 26.3k | WORD32 temp_size = 0; |
1300 | 26.3k | size_buffers += (num_channel * 2 * |
1301 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_sbr_frame_info_data_struct) + |
1302 | 26.3k | MAX_FREQ_COEFFS * sizeof(WORD32) * 2 + 8, |
1303 | 26.3k | BYTE_ALIGN_8)); |
1304 | 26.3k | temp_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_pvc_data_struct), BYTE_ALIGN_8); |
1305 | 26.3k | temp_size += 2 * IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_esbr_hbe_txposer_struct), BYTE_ALIGN_8); |
1306 | 26.3k | temp_size += 2 * IXHEAAC_GET_SIZE_ALIGNED(MAX_HBE_PERSISTENT_SIZE, BYTE_ALIGN_8); |
1307 | 26.3k | temp_size += |
1308 | 26.3k | 2 * 2 * IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(FLOAT32 *), BYTE_ALIGN_8); |
1309 | 26.3k | temp_size += 2 * 2 * MAX_QMF_BUF_LEN * |
1310 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(FLOAT32), BYTE_ALIGN_8); |
1311 | 26.3k | temp_size += 2 * 2 * MAX_ENV_COLS * |
1312 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(MAX_QMF_BUF_LEN * sizeof(WORD32), BYTE_ALIGN_8); |
1313 | 26.3k | size_buffers += num_channel * temp_size; |
1314 | 26.3k | } |
1315 | | |
1316 | 26.3k | return (size_buffers); |
1317 | 26.3k | } |
1318 | | |
1319 | | VOID ixheaacd_fill_aac_mem_tables( |
1320 | 26.3k | ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) { |
1321 | 26.3k | ia_mem_info_struct *p_mem_info_aac; |
1322 | | |
1323 | 26.3k | WORD32 num_channels; |
1324 | 26.3k | WORD32 channels; |
1325 | 26.3k | WORD32 buffer_size; |
1326 | | |
1327 | 26.3k | if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) { |
1328 | 26.3k | num_channels = (p_obj_exhaacplus_dec->aac_config.ui_max_channels + 1); |
1329 | 26.3k | } else |
1330 | | |
1331 | 0 | { |
1332 | 0 | num_channels = p_obj_exhaacplus_dec->aac_config.ui_max_channels; |
1333 | 0 | } |
1334 | | |
1335 | 26.3k | channels = num_channels; |
1336 | 26.3k | buffer_size = ixheaacd_persistent_buffer_sizes(num_channels); |
1337 | | |
1338 | 26.3k | { |
1339 | 26.3k | p_mem_info_aac = |
1340 | 26.3k | &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX]; |
1341 | 26.3k | p_mem_info_aac->ui_size = |
1342 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8) + |
1343 | 26.3k | channels * |
1344 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ia_aac_persistent_struct), BYTE_ALIGN_8) + |
1345 | 26.3k | buffer_size + channels * ixheaacd_getsize_sbr_persistent() + channels * 16 + |
1346 | 26.3k | ixheaacd_mps_persistent_buffer_sizes(); |
1347 | 26.3k | p_mem_info_aac->ui_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8); |
1348 | 26.3k | p_mem_info_aac->ui_size += |
1349 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_audio_specific_config_struct), BYTE_ALIGN_8); |
1350 | 26.3k | p_mem_info_aac->ui_size += IXHEAAC_GET_SIZE_ALIGNED(MAX_HEADER_BUF_SIZE, BYTE_ALIGN_8); |
1351 | 26.3k | p_mem_info_aac->ui_alignment = 16; |
1352 | 26.3k | p_mem_info_aac->ui_type = IA_MEMTYPE_PERSIST; |
1353 | 26.3k | } |
1354 | | |
1355 | 26.3k | { |
1356 | 26.3k | p_mem_info_aac = |
1357 | 26.3k | &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX]; |
1358 | | |
1359 | 26.3k | p_mem_info_aac->ui_size = MAX_SCR_SIZE; |
1360 | | |
1361 | 26.3k | p_mem_info_aac->ui_alignment = 8; |
1362 | 26.3k | p_mem_info_aac->ui_type = IA_MEMTYPE_SCRATCH; |
1363 | 26.3k | } |
1364 | 26.3k | { |
1365 | 26.3k | p_mem_info_aac = |
1366 | 26.3k | &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]; |
1367 | | |
1368 | 26.3k | p_mem_info_aac->ui_size = IA_MAX_INP_BUFFER_SIZE; |
1369 | | |
1370 | 26.3k | p_mem_info_aac->ui_alignment = 8; |
1371 | 26.3k | p_mem_info_aac->ui_type = IA_MEMTYPE_INPUT; |
1372 | 26.3k | } |
1373 | 26.3k | { |
1374 | 26.3k | p_mem_info_aac = |
1375 | 26.3k | &p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]; |
1376 | 26.3k | p_mem_info_aac->ui_size = IA_ENHAACPLUS_DEC_OUT_BUF_SIZE; |
1377 | 26.3k | p_mem_info_aac->ui_alignment = 8; |
1378 | 26.3k | p_mem_info_aac->ui_type = IA_MEMTYPE_OUTPUT; |
1379 | 26.3k | } |
1380 | 26.3k | return; |
1381 | 26.3k | } |
1382 | | |
1383 | | IA_ERRORCODE ixheaacd_dec_table_api( |
1384 | | ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, WORD32 i_cmd, |
1385 | 0 | WORD32 i_idx, pVOID pv_value) { |
1386 | 0 | ia_heaac_mps_state_struct *pstr_mps_state = |
1387 | 0 | &p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle; |
1388 | 0 | pUWORD32 pui_value = pv_value; |
1389 | 0 | pUWORD32 *p_pui_value = pv_value; |
1390 | 0 | SIZE_T ui_get_vals[5]; |
1391 | |
|
1392 | 0 | pVOID *table_ptrs[8 + NUM_MPS_TABLES]; |
1393 | 0 | UWORD32 table_sizes[8 + NUM_MPS_TABLES] = { |
1394 | 0 | sizeof(ixheaacd_aac_huffmann_tables), |
1395 | 0 | sizeof(ixheaacd_aac_block_tables), |
1396 | 0 | sizeof(ixheaacd_imdct_tables), |
1397 | 0 | sizeof(ixheaacd_str_fft_n_transcendent_tables), |
1398 | 0 | sizeof(ixheaacd_aac_dec_env_calc_tables), |
1399 | 0 | sizeof(ixheaacd_aac_qmf_dec_tables), |
1400 | 0 | sizeof(ixheaacd_aac_dec_env_extr_tables), |
1401 | 0 | sizeof(ixheaacd_aac_dec_ps_tables), |
1402 | 0 | sizeof(ixheaacd_mps_dec_qmf_tables), |
1403 | 0 | sizeof(ixheaacd_mps_dec_common_tables), |
1404 | 0 | sizeof(ixheaacd_mps_dec_hybrid_tables), |
1405 | 0 | sizeof(ixheaacd_mps_dec_m1_m2_tables), |
1406 | 0 | sizeof(ixheaacd_mps_dec_decorr_tables), |
1407 | 0 | sizeof(ixheaacd_mps_dec_tp_process_tables), |
1408 | 0 | sizeof(ixheaacd_mps_dec_mdct2qmf_table), |
1409 | 0 | sizeof(ixheaacd_mps_dec_tonality_tables), |
1410 | 0 | sizeof(ixheaacd_mps_dec_bitdec_tables), |
1411 | 0 | sizeof(ixheaacd_mps_dec_blind_tables), |
1412 | 0 | sizeof(ixheaacd_mps_dec_mdct2qmf_tables), |
1413 | 0 | sizeof(ia_mps_dec_mdct2qmf_cos_table_struct), |
1414 | 0 | sizeof(ia_mps_dec_residual_aac_tables_struct)}; |
1415 | 0 | table_ptrs[0] = |
1416 | 0 | (pVOID *)&(p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables); |
1417 | 0 | table_ptrs[1] = |
1418 | 0 | (pVOID *)&(p_obj_exhaacplus_dec->aac_tables.pstr_block_tables); |
1419 | 0 | table_ptrs[2] = |
1420 | 0 | (pVOID *)&(p_obj_exhaacplus_dec->aac_tables.pstr_imdct_tables); |
1421 | 0 | table_ptrs[3] = (pVOID *)&(p_obj_exhaacplus_dec->common_tables); |
1422 | 0 | table_ptrs[4] = |
1423 | 0 | (pVOID *)&p_obj_exhaacplus_dec->str_sbr_tables.env_calc_tables_ptr; |
1424 | 0 | table_ptrs[5] = |
1425 | 0 | (pVOID *)&p_obj_exhaacplus_dec->str_sbr_tables.qmf_dec_tables_ptr; |
1426 | 0 | table_ptrs[6] = |
1427 | 0 | (pVOID *)&p_obj_exhaacplus_dec->str_sbr_tables.env_extr_tables_ptr; |
1428 | 0 | table_ptrs[7] = (pVOID *)&p_obj_exhaacplus_dec->str_sbr_tables.ps_tables_ptr; |
1429 | 0 | table_ptrs[8] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.qmf_table_ptr); |
1430 | 0 | table_ptrs[9] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr); |
1431 | 0 | table_ptrs[10] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.hybrid_table_ptr); |
1432 | 0 | table_ptrs[11] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr); |
1433 | 0 | table_ptrs[12] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.decor_table_ptr); |
1434 | 0 | table_ptrs[13] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.tp_process_table_ptr); |
1435 | 0 | table_ptrs[14] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.mdct2qmf_table_ptr); |
1436 | 0 | table_ptrs[15] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.tonality_table_ptr); |
1437 | 0 | table_ptrs[16] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr); |
1438 | 0 | table_ptrs[17] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.blind_table_ptr); |
1439 | 0 | table_ptrs[18] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.mdct2qmfcos_table_ptr); |
1440 | 0 | table_ptrs[19] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.mdct2qmfcos_tab_ptr); |
1441 | 0 | table_ptrs[20] = (pVOID *)&(pstr_mps_state->ia_mps_dec_mps_table.aac_tab); |
1442 | |
|
1443 | 0 | if (i_idx < 0 || i_idx >= (NUM_AAC_TABLES + NUM_MPS_TABLES)) { |
1444 | 0 | return IA_XHEAAC_DEC_API_FATAL_INVALID_MEMTAB_INDEX; |
1445 | 0 | } |
1446 | | |
1447 | 0 | ui_get_vals[0] = table_sizes[i_idx]; |
1448 | 0 | ui_get_vals[1] = 4; |
1449 | 0 | ui_get_vals[4] = (SIZE_T)(*table_ptrs[i_idx]); |
1450 | |
|
1451 | 0 | if (i_cmd == IA_API_CMD_SET_TABLE_PTR) { |
1452 | 0 | if (pv_value == 0) { |
1453 | 0 | return (IA_XHEAAC_DEC_API_FATAL_MEM_ALLOC); |
1454 | 0 | } |
1455 | 0 | if (((SIZE_T)pv_value) & 3) { |
1456 | 0 | return IA_XHEAAC_DEC_API_FATAL_MEM_ALIGN; |
1457 | 0 | } |
1458 | | |
1459 | 0 | *table_ptrs[i_idx] = pv_value; |
1460 | |
|
1461 | 0 | if (i_idx == 0) { |
1462 | 0 | ixheaacd_huff_tables_create(&p_obj_exhaacplus_dec->aac_tables); |
1463 | 0 | } |
1464 | |
|
1465 | 0 | } |
1466 | | |
1467 | 0 | else if (i_cmd == IA_API_CMD_GET_TABLE_PTR) { |
1468 | 0 | *p_pui_value = (UWORD32 *)((SIZE_T)( |
1469 | 0 | ui_get_vals[i_cmd - IA_API_CMD_GET_TABLE_INFO_SIZE])); |
1470 | 0 | } else { |
1471 | 0 | *pui_value = (WORD32)(ui_get_vals[i_cmd - IA_API_CMD_GET_TABLE_INFO_SIZE]); |
1472 | 0 | } |
1473 | | |
1474 | 0 | return IA_NO_ERROR; |
1475 | 0 | } |
1476 | | |
1477 | | VOID ixheaacd_mps_payload(ia_handle_sbr_dec_inst_struct self, |
1478 | 5.54k | ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) { |
1479 | 5.54k | struct ia_bit_buf_struct local_bit_buff; |
1480 | 5.54k | struct ia_bit_buf_struct *it_bit_buff; |
1481 | 5.54k | if (self->ptr_mps_data != NULL) { |
1482 | 3.47k | ixheaacd_create_init_bit_buf(&local_bit_buff, (UWORD8 *)self->ptr_mps_data, |
1483 | 3.47k | (self->left_mps_bits >> 3) + 1); |
1484 | 3.47k | } |
1485 | | |
1486 | 5.54k | local_bit_buff.xaac_jmp_buf = |
1487 | 5.54k | &p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf; |
1488 | | |
1489 | 5.54k | it_bit_buff = &local_bit_buff; |
1490 | | |
1491 | 5.54k | it_bit_buff->bit_pos = self->mps_bits_pos; |
1492 | 5.54k | it_bit_buff->cnt_bits = self->left_mps_bits; |
1493 | | |
1494 | 12.0k | while (self->left_mps_bits >= 8) { |
1495 | 6.46k | ixheaacd_extension_payload( |
1496 | 6.46k | it_bit_buff, &self->left_mps_bits, |
1497 | 6.46k | &p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle); |
1498 | 6.46k | } |
1499 | 5.54k | } |
1500 | | |
1501 | | IA_ERRORCODE ixheaacd_dec_init( |
1502 | 42.2k | ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) { |
1503 | 42.2k | FLAG frame_status = 1; |
1504 | 42.2k | WORD32 frame_size_1; |
1505 | 42.2k | WORD32 sample_rate_1; |
1506 | 42.2k | WORD16 num_channels_1; |
1507 | 42.2k | WORD32 ps_detected = 0; |
1508 | 42.2k | UWORD8 *in_buffer; |
1509 | 42.2k | WORD16 *time_data; |
1510 | 42.2k | WORD ch_idx; |
1511 | 42.2k | WORD sbr_present_flag = 0; |
1512 | 42.2k | UWORD8 *mps_buffer; |
1513 | 42.2k | ia_aac_dec_state_struct *p_state_enhaacplus_dec; |
1514 | | |
1515 | 42.2k | WORD32 error_code = IA_NO_ERROR; |
1516 | 42.2k | WORD32 persistent_used = 0; |
1517 | 42.2k | IA_ERRORCODE err_code = IA_NO_ERROR; |
1518 | 42.2k | struct ia_aac_persistent_struct *aac_persistent_mem; |
1519 | 42.2k | struct ia_sbr_pers_struct *sbr_persistent_mem; |
1520 | 42.2k | WORD32 ret_val; |
1521 | | |
1522 | 42.2k | p_obj_exhaacplus_dec->p_state_aac = |
1523 | 42.2k | p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX]; |
1524 | | |
1525 | 42.2k | if (p_obj_exhaacplus_dec->p_state_aac->ui_init_done) |
1526 | 0 | { |
1527 | 0 | return IA_NO_ERROR; |
1528 | 0 | } |
1529 | | |
1530 | 42.2k | p_obj_exhaacplus_dec->p_state_aac->preroll_config_present = 0; |
1531 | | |
1532 | 42.2k | if (p_obj_exhaacplus_dec->p_state_aac != NULL) { |
1533 | 42.2k | ret_val = setjmp(p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf); |
1534 | 42.2k | if (ret_val != 0) { |
1535 | 2.49k | p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = |
1536 | 2.49k | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; |
1537 | 2.49k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0; |
1538 | 2.49k | return IA_NO_ERROR; |
1539 | 2.49k | } |
1540 | 42.2k | } |
1541 | | |
1542 | 39.7k | time_data = (WORD16 *)(p_obj_exhaacplus_dec |
1543 | 39.7k | ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]); |
1544 | | |
1545 | 42.2k | if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) { |
1546 | 42.2k | in_buffer = p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]; |
1547 | 18.4E | } else { |
1548 | 18.4E | in_buffer = p_obj_exhaacplus_dec->p_state_aac->header_ptr; |
1549 | 18.4E | } |
1550 | | |
1551 | 39.7k | p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac; |
1552 | | |
1553 | 39.7k | p_state_enhaacplus_dec->aac_scratch_mem_v = |
1554 | 39.7k | p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX]; |
1555 | 39.7k | p_obj_exhaacplus_dec->p_state_aac->huffman_code_book_scl = |
1556 | 39.7k | p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables |
1557 | 39.7k | ->huffman_code_book_scl; |
1558 | 39.7k | mps_buffer = p_obj_exhaacplus_dec->p_state_aac->mps_buffer; |
1559 | 39.7k | p_state_enhaacplus_dec->mps_header = -1; |
1560 | 39.7k | p_obj_exhaacplus_dec->p_state_aac->huffman_code_book_scl_index = |
1561 | 39.7k | p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables |
1562 | 39.7k | ->huffman_code_book_scl_index; |
1563 | | |
1564 | 39.7k | p_state_enhaacplus_dec->pstr_aac_tables = &p_obj_exhaacplus_dec->aac_tables; |
1565 | 39.7k | if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 0) |
1566 | 26.3k | { |
1567 | 26.3k | p_obj_exhaacplus_dec->aac_config.header_dec_done = 0; |
1568 | 26.3k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.ldmps_present_flag = 0; |
1569 | 26.3k | } |
1570 | 39.7k | if (p_obj_exhaacplus_dec->aac_config.header_dec_done == 0) { |
1571 | 26.3k | WORD32 channels; |
1572 | 26.3k | UWORD32 total_persistent_used = 0; |
1573 | | |
1574 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->p_config = |
1575 | 26.3k | &p_obj_exhaacplus_dec->aac_config; |
1576 | | |
1577 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr = |
1578 | 26.3k | (pVOID)((pWORD8)p_obj_exhaacplus_dec->p_state_aac + |
1579 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_state_struct), BYTE_ALIGN_8)); |
1580 | 26.3k | if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) { |
1581 | 26.3k | p_state_enhaacplus_dec->aac_persistent_mem_v = |
1582 | 26.3k | (pVOID)((pWORD8)p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr + |
1583 | 26.3k | (MAX_BS_ELEMENT)*2 * |
1584 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), |
1585 | 26.3k | BYTE_ALIGN_8)); |
1586 | | |
1587 | 26.3k | memset(p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr, 0, |
1588 | 26.3k | (MAX_BS_ELEMENT)*2 * |
1589 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), BYTE_ALIGN_8)); |
1590 | 26.3k | } else { |
1591 | 0 | p_state_enhaacplus_dec->aac_persistent_mem_v = |
1592 | 0 | (pVOID)((pWORD8)p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr + |
1593 | 0 | (2) * 2 * |
1594 | 0 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), |
1595 | 0 | BYTE_ALIGN_8)); |
1596 | |
|
1597 | 0 | memset(p_obj_exhaacplus_dec->p_state_aac->pstr_stream_sbr, 0, |
1598 | 0 | (2) * 2 * |
1599 | 0 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_aac_dec_sbr_bitstream_struct), BYTE_ALIGN_8)); |
1600 | 0 | } |
1601 | 26.3k | if (1 == p_obj_exhaacplus_dec->aac_config.ui_max_channels) |
1602 | 0 | channels = 1; |
1603 | 26.3k | else |
1604 | 26.3k | channels = 2; |
1605 | | |
1606 | 26.3k | persistent_used = ixheaacd_set_aac_persistent_buffers( |
1607 | 26.3k | p_state_enhaacplus_dec->aac_persistent_mem_v, channels); |
1608 | | |
1609 | 26.3k | p_state_enhaacplus_dec->sbr_persistent_mem_v = |
1610 | 26.3k | (pVOID)((pWORD8)p_state_enhaacplus_dec->aac_persistent_mem_v + |
1611 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8)); |
1612 | 26.3k | total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8); |
1613 | | |
1614 | 26.3k | persistent_used = ixheaacd_getsize_sbr_persistent(); |
1615 | 26.3k | ixheaacd_set_sbr_persistent_buffers( |
1616 | 26.3k | p_state_enhaacplus_dec->sbr_persistent_mem_v, &persistent_used, |
1617 | 26.3k | channels, 1); |
1618 | | |
1619 | 26.3k | p_state_enhaacplus_dec->heaac_mps_handle.mps_persistent_mem_v = |
1620 | 26.3k | (pVOID)((pWORD8)p_state_enhaacplus_dec->sbr_persistent_mem_v + |
1621 | 26.3k | IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8)); |
1622 | 26.3k | total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8); |
1623 | | |
1624 | 26.3k | persistent_used = ixheaacd_getsize_mps_persistent(); |
1625 | | |
1626 | 26.3k | ixheaacd_set_mps_persistent_buffers( |
1627 | 26.3k | &p_state_enhaacplus_dec->heaac_mps_handle, &persistent_used, channels, |
1628 | 26.3k | p_state_enhaacplus_dec->heaac_mps_handle.mps_persistent_mem_v); |
1629 | 26.3k | total_persistent_used += IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8); |
1630 | | |
1631 | 26.3k | if (total_persistent_used > |
1632 | 26.3k | p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX].ui_size) { |
1633 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
1634 | 0 | } |
1635 | | |
1636 | 26.3k | aac_persistent_mem = (struct ia_aac_persistent_struct *) |
1637 | 26.3k | p_state_enhaacplus_dec->aac_persistent_mem_v; |
1638 | 26.3k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD || |
1639 | 26.3k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) |
1640 | 2 | p_state_enhaacplus_dec->frame_len_flag = |
1641 | 2 | p_obj_exhaacplus_dec->aac_config.framesize_480; |
1642 | | |
1643 | 26.3k | p_state_enhaacplus_dec->ptr_overlap_buf = |
1644 | 26.3k | aac_persistent_mem->overlap_buffer; |
1645 | | |
1646 | 26.3k | p_state_enhaacplus_dec->bit_count = 0; |
1647 | 26.3k | p_state_enhaacplus_dec->ec_enable = p_obj_exhaacplus_dec->aac_config.ui_err_conceal; |
1648 | 26.3k | p_state_enhaacplus_dec->sync_status = 0; |
1649 | 26.3k | p_state_enhaacplus_dec->bs_format = ADTS_BSFORMAT; |
1650 | 26.3k | p_state_enhaacplus_dec->latm_initialized = 0; |
1651 | 26.3k | p_state_enhaacplus_dec->frame_size = 0; |
1652 | 26.3k | memset(&p_state_enhaacplus_dec->latm_struct_element, 0, |
1653 | 26.3k | sizeof(ixheaacd_latm_struct)); |
1654 | 26.3k | memset(&p_state_enhaacplus_dec->b_n_raw_data_blk, 0, |
1655 | 26.3k | sizeof(WORD32) * (9 + MAX_BS_ELEMENT)); |
1656 | | |
1657 | 26.3k | p_state_enhaacplus_dec->sbr_present_flag = 0; |
1658 | | |
1659 | 289k | for (ch_idx = 0; ch_idx < MAX_BS_ELEMENT; ch_idx++) { |
1660 | 263k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0; |
1661 | 263k | } |
1662 | | |
1663 | 26.3k | memset(&p_state_enhaacplus_dec->ind_cc_info, 0, |
1664 | 26.3k | sizeof(ia_enhaacplus_dec_ind_cc)); |
1665 | | |
1666 | 26.3k | p_state_enhaacplus_dec->last_frame_ok = 1; |
1667 | 26.3k | p_obj_exhaacplus_dec->aac_config.header_dec_done = 1; |
1668 | | |
1669 | 26.3k | aac_persistent_mem->str_aac_decoder.pstr_aac_tables = |
1670 | 26.3k | &p_obj_exhaacplus_dec->aac_tables; |
1671 | 26.3k | aac_persistent_mem->str_aac_decoder.pstr_common_tables = |
1672 | 26.3k | p_obj_exhaacplus_dec->common_tables; |
1673 | | |
1674 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_u = |
1675 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_v; |
1676 | | |
1677 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->sbr_scratch_mem_u = |
1678 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->aac_scratch_mem_v; |
1679 | | |
1680 | 26.3k | ixheaacd_set_sbr_persistent_table_pointer( |
1681 | 26.3k | p_obj_exhaacplus_dec->p_state_aac->sbr_persistent_mem_v, |
1682 | 26.3k | &p_obj_exhaacplus_dec->str_sbr_tables, |
1683 | 26.3k | p_obj_exhaacplus_dec->common_tables); |
1684 | 26.3k | ixheaacd_set_scratch_buffers( |
1685 | 26.3k | &p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle, |
1686 | 26.3k | p_state_enhaacplus_dec->aac_scratch_mem_v); |
1687 | 26.3k | } |
1688 | | |
1689 | 39.7k | if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 1) { |
1690 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_EO_INPUT_REACHED; |
1691 | 0 | } |
1692 | | |
1693 | 39.7k | if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 0) { |
1694 | 26.3k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD || |
1695 | 26.3k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) |
1696 | 2 | p_state_enhaacplus_dec->frame_len_flag = |
1697 | 2 | p_obj_exhaacplus_dec->aac_config.framesize_480; |
1698 | | |
1699 | 26.3k | aac_persistent_mem = (struct ia_aac_persistent_struct *) |
1700 | 26.3k | p_state_enhaacplus_dec->aac_persistent_mem_v; |
1701 | 26.3k | sbr_persistent_mem = (struct ia_sbr_pers_struct *) |
1702 | 26.3k | p_state_enhaacplus_dec->sbr_persistent_mem_v; |
1703 | 26.3k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
1704 | 0 | p_obj_exhaacplus_dec->p_state_aac->first_frame = 1; |
1705 | 0 | } |
1706 | | |
1707 | 26.3k | if (p_obj_exhaacplus_dec->aac_config.ui_samp_freq == 0) { |
1708 | 26.3k | WORD32 header_bytes_consumed, return_val; |
1709 | | |
1710 | 26.3k | if (p_state_enhaacplus_dec->ui_in_bytes == 0) { |
1711 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
1712 | 0 | return IA_NO_ERROR; |
1713 | 0 | } |
1714 | | |
1715 | 26.3k | if (1 == p_obj_exhaacplus_dec->aac_config.ui_frame_size) { |
1716 | 0 | p_state_enhaacplus_dec->frame_len_flag = 1; |
1717 | 0 | p_state_enhaacplus_dec->frame_length = 960; |
1718 | 26.3k | } else { |
1719 | 26.3k | p_state_enhaacplus_dec->frame_len_flag = 0; |
1720 | 26.3k | p_state_enhaacplus_dec->frame_length = 1024; |
1721 | 26.3k | } |
1722 | | |
1723 | 26.3k | p_state_enhaacplus_dec->ui_init_done = 0; |
1724 | 26.3k | memset(&(p_state_enhaacplus_dec->eld_specific_config), 0, |
1725 | 26.3k | sizeof(ia_eld_specific_config_struct)); |
1726 | 26.3k | return_val = ixheaacd_aac_headerdecode( |
1727 | 26.3k | p_obj_exhaacplus_dec, (UWORD8 *)in_buffer, &header_bytes_consumed, |
1728 | 26.3k | aac_persistent_mem->str_aac_decoder.pstr_aac_tables |
1729 | 26.3k | ->pstr_huffmann_tables); |
1730 | 26.3k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD || |
1731 | 26.3k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD || |
1732 | 26.3k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) { |
1733 | 6.81k | *sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[0] = |
1734 | 6.81k | p_obj_exhaacplus_dec->p_state_aac->str_sbr_config; |
1735 | 6.81k | *sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[1] = |
1736 | 6.81k | p_obj_exhaacplus_dec->p_state_aac->str_sbr_config; |
1737 | 19.5k | } else { |
1738 | 19.5k | memset(&(p_state_enhaacplus_dec->eld_specific_config), 0, |
1739 | 19.5k | sizeof(ia_eld_specific_config_struct)); |
1740 | 19.5k | } |
1741 | | |
1742 | 26.3k | if (return_val < 0) { |
1743 | 677 | if (return_val == |
1744 | 677 | (WORD32)IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX) { |
1745 | 13 | p_state_enhaacplus_dec->i_bytes_consumed = header_bytes_consumed; |
1746 | 13 | return return_val; |
1747 | 13 | } |
1748 | 664 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
1749 | | |
1750 | 664 | return return_val; |
1751 | 677 | } |
1752 | | |
1753 | 25.6k | if (return_val == |
1754 | 25.6k | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES) { |
1755 | 31 | p_state_enhaacplus_dec->i_bytes_consumed = header_bytes_consumed; |
1756 | 31 | return return_val; |
1757 | 31 | } |
1758 | | |
1759 | 25.6k | p_state_enhaacplus_dec->i_bytes_consumed = header_bytes_consumed; |
1760 | | |
1761 | 25.6k | if ((return_val == 0) && |
1762 | 25.6k | (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_USAC)) { |
1763 | 9.02k | { |
1764 | 9.02k | WORD32 pcm_size = p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz; |
1765 | 9.02k | WORD8 *inbuffer = |
1766 | 9.02k | p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]; |
1767 | 9.02k | WORD8 *outbuffer = |
1768 | 9.02k | p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]; |
1769 | 9.02k | WORD32 out_bytes = 0; |
1770 | 9.02k | WORD32 frames_done = p_obj_exhaacplus_dec->p_state_aac->frame_counter; |
1771 | 9.02k | p_obj_exhaacplus_dec->p_state_aac->decode_create_done = 0; |
1772 | | |
1773 | 9.02k | if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 0) { |
1774 | 9.02k | error_code = ixheaacd_dec_main( |
1775 | 9.02k | p_obj_exhaacplus_dec, inbuffer, outbuffer, &out_bytes, |
1776 | 9.02k | frames_done, pcm_size, |
1777 | 9.02k | &p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch); |
1778 | 9.02k | if (error_code) return error_code; |
1779 | 8.99k | p_obj_exhaacplus_dec->p_state_aac->frame_counter++; |
1780 | 8.99k | } else { |
1781 | 0 | out_bytes = 0; |
1782 | 0 | } |
1783 | | |
1784 | 8.99k | p_obj_exhaacplus_dec->aac_config.ui_n_channels = |
1785 | 8.99k | p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch; |
1786 | 8.99k | } |
1787 | 8.99k | if (return_val == 0) |
1788 | 8.99k | p_obj_exhaacplus_dec->p_state_aac->ui_init_done = 1; |
1789 | 8.99k | return return_val; |
1790 | 9.02k | } |
1791 | | |
1792 | 16.6k | if (return_val == 0) { |
1793 | 16.0k | p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 1; |
1794 | 16.0k | if (p_obj_exhaacplus_dec->aac_config.ui_flush_cmd == 0) { |
1795 | 16.0k | memcpy(p_state_enhaacplus_dec->header_ptr, in_buffer, |
1796 | 16.0k | header_bytes_consumed * sizeof(UWORD8)); |
1797 | 16.0k | p_state_enhaacplus_dec->header_length = header_bytes_consumed; |
1798 | 16.0k | } |
1799 | 16.0k | } |
1800 | | |
1801 | 16.6k | if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done != 1) |
1802 | 21 | return IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START; |
1803 | | |
1804 | 16.6k | if (p_state_enhaacplus_dec->dwnsmp_signal == 1 && |
1805 | 16.6k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) |
1806 | 2.01k | p_obj_exhaacplus_dec->aac_config.down_sample_flag = 1; |
1807 | | |
1808 | 16.6k | if (p_state_enhaacplus_dec->sampling_rate == |
1809 | 16.6k | p_state_enhaacplus_dec->extension_samp_rate) { |
1810 | 4 | p_obj_exhaacplus_dec->aac_config.down_sample_flag = 1; |
1811 | 4 | } |
1812 | | |
1813 | 16.6k | } else { |
1814 | 2 | p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 1; |
1815 | 2 | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
1816 | | |
1817 | 2 | p_state_enhaacplus_dec->sampling_rate = |
1818 | 2 | p_obj_exhaacplus_dec->aac_config.ui_samp_freq; |
1819 | | |
1820 | 2 | if (1 == p_obj_exhaacplus_dec->aac_config.ui_frame_size) { |
1821 | 0 | p_state_enhaacplus_dec->frame_len_flag = 1; |
1822 | 0 | p_state_enhaacplus_dec->frame_length = 960; |
1823 | 2 | } else { |
1824 | 2 | p_state_enhaacplus_dec->frame_len_flag = 0; |
1825 | 2 | p_state_enhaacplus_dec->frame_length = 1024; |
1826 | 2 | } |
1827 | 2 | } |
1828 | | |
1829 | 16.6k | p_state_enhaacplus_dec->pstr_bit_buf = ixheaacd_create_bit_buf( |
1830 | 16.6k | &p_state_enhaacplus_dec->str_bit_buf, (UWORD8 *)in_buffer, |
1831 | 16.6k | p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_INPUT_IDX] |
1832 | 16.6k | .ui_size); |
1833 | 16.6k | p_state_enhaacplus_dec->pstr_bit_buf->xaac_jmp_buf = |
1834 | 16.6k | &(p_state_enhaacplus_dec->xaac_jmp_buf); |
1835 | | |
1836 | 16.6k | p_state_enhaacplus_dec->ptr_bit_stream = |
1837 | 16.6k | p_state_enhaacplus_dec->pstr_bit_buf; |
1838 | | |
1839 | 16.6k | if (p_state_enhaacplus_dec->s_adts_hdr_present) { |
1840 | 8.70k | if (p_obj_exhaacplus_dec->aac_config.ld_decoder == 1) |
1841 | 0 | p_state_enhaacplus_dec->audio_object_type = 23; |
1842 | 8.70k | } |
1843 | | |
1844 | 16.6k | if ((p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) || |
1845 | 16.6k | (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD)) |
1846 | 5.41k | if (p_state_enhaacplus_dec->s_adts_hdr_present) { |
1847 | 0 | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) { |
1848 | 0 | p_state_enhaacplus_dec->eld_specific_config.ld_sbr_samp_rate = 1; |
1849 | 0 | p_state_enhaacplus_dec->eld_specific_config.ld_sbr_crc_flag = 0; |
1850 | 0 | p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present = 0; |
1851 | |
|
1852 | 0 | if (p_obj_exhaacplus_dec->aac_config.eld_sbr_present == 1) { |
1853 | 0 | p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present = 1; |
1854 | 0 | } |
1855 | 0 | } |
1856 | 0 | if (p_obj_exhaacplus_dec->aac_config.framesize_480) |
1857 | 0 | p_state_enhaacplus_dec->frame_length = 480; |
1858 | 0 | else |
1859 | 0 | p_state_enhaacplus_dec->frame_length = 512; |
1860 | 0 | } |
1861 | | |
1862 | 16.6k | { |
1863 | 176k | for (ch_idx = 0; ch_idx < MAX_BS_ELEMENT; ch_idx++) { |
1864 | 160k | WORD32 channels; |
1865 | 160k | channels = 2; |
1866 | | |
1867 | 160k | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] = |
1868 | 160k | ixheaacd_aac_decoder_init( |
1869 | 160k | p_state_enhaacplus_dec, |
1870 | | |
1871 | 160k | p_state_enhaacplus_dec->pstr_stream_sbr[0], channels, |
1872 | 160k | p_state_enhaacplus_dec->aac_persistent_mem_v, |
1873 | 160k | p_state_enhaacplus_dec->frame_length); |
1874 | | |
1875 | 160k | if (!p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]) { |
1876 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
1877 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
1878 | 0 | } |
1879 | 160k | } |
1880 | | |
1881 | 16.6k | { |
1882 | 16.6k | p_state_enhaacplus_dec->pstr_drc_dec = |
1883 | 16.6k | &p_state_enhaacplus_dec->str_drc_dec_info; |
1884 | 16.6k | ixheaacd_drc_dec_create(p_state_enhaacplus_dec->pstr_drc_dec, 127, 127); |
1885 | 16.6k | } |
1886 | 16.6k | p_state_enhaacplus_dec->pstr_drc_dec->cut_factor = |
1887 | 16.6k | p_obj_exhaacplus_dec->aac_config.ui_drc_cut; |
1888 | 16.6k | p_state_enhaacplus_dec->pstr_drc_dec->boost_factor = |
1889 | 16.6k | p_obj_exhaacplus_dec->aac_config.ui_drc_boost; |
1890 | 16.6k | p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level = |
1891 | 16.6k | p_obj_exhaacplus_dec->aac_config.ui_drc_target_level; |
1892 | 16.6k | p_state_enhaacplus_dec->pstr_drc_dec->prog_ref_level = |
1893 | 16.6k | p_obj_exhaacplus_dec->aac_config.ui_drc_target_level; |
1894 | | |
1895 | 16.6k | if (1 == p_obj_exhaacplus_dec->aac_config.ui_drc_set) { |
1896 | 16.0k | if (p_obj_exhaacplus_dec->aac_config.ui_drc_heavy_comp == 1) { |
1897 | 542 | p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 1; |
1898 | 542 | p_state_enhaacplus_dec->pstr_drc_dec->heavy_mode = 1; |
1899 | 15.4k | } else { |
1900 | 15.4k | p_state_enhaacplus_dec->pstr_drc_dec->heavy_mode = 0; |
1901 | 15.4k | if (p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level > 127) |
1902 | 0 | p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level = 127; |
1903 | 15.4k | if (p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level < 0) { |
1904 | 0 | if (p_state_enhaacplus_dec->pstr_drc_dec->cut_factor > 0 || |
1905 | 0 | p_state_enhaacplus_dec->pstr_drc_dec->boost_factor > 0) |
1906 | 0 | p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 1; |
1907 | 0 | else |
1908 | 0 | p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 0; |
1909 | 0 | p_state_enhaacplus_dec->pstr_drc_dec->drc_dig_norm = 0; |
1910 | 0 | p_state_enhaacplus_dec->pstr_drc_dec->target_ref_level = 108; |
1911 | 15.4k | } else { |
1912 | 15.4k | p_state_enhaacplus_dec->pstr_drc_dec->drc_on = 1; |
1913 | 15.4k | p_state_enhaacplus_dec->pstr_drc_dec->drc_dig_norm = 1; |
1914 | 15.4k | } |
1915 | 15.4k | } |
1916 | 16.0k | } |
1917 | 16.6k | } |
1918 | 16.6k | } else { |
1919 | 13.3k | struct ia_bit_buf_struct temp_bit_buff = {0}; |
1920 | 13.3k | ia_adts_header_struct adts; |
1921 | 13.3k | struct ia_bit_buf_struct *it_bit_buff; |
1922 | | |
1923 | 13.3k | WORD16 frame_size_2 = 0; |
1924 | 13.3k | WORD32 sample_rate_2 = 0; |
1925 | 13.3k | WORD32 sample_rate = 0; |
1926 | 13.3k | WORD type, i; |
1927 | 13.3k | WORD elements_number; |
1928 | | |
1929 | 13.3k | if (p_state_enhaacplus_dec->audio_object_type == AOT_USAC) |
1930 | 0 | return IA_FATAL_ERROR; |
1931 | | |
1932 | 13.3k | memset(&adts, 0, sizeof(ia_adts_header_struct)); |
1933 | | |
1934 | 188k | for (i = 0; i < MAX_BS_ELEMENT + 1; i++) { |
1935 | 174k | p_obj_exhaacplus_dec->aac_config.element_type[i] = -1; |
1936 | 174k | } |
1937 | | |
1938 | 13.3k | it_bit_buff = p_state_enhaacplus_dec->pstr_bit_buf; |
1939 | | |
1940 | 13.3k | p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0; |
1941 | 13.3k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0; |
1942 | 13.3k | p_state_enhaacplus_dec->ui_mps_out_bytes = 0; |
1943 | 13.3k | if (p_state_enhaacplus_dec->ui_in_bytes == 0) { |
1944 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
1945 | 0 | return IA_NO_ERROR; |
1946 | 0 | } |
1947 | | |
1948 | 13.3k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD || |
1949 | 13.8k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) { |
1950 | 5.35k | if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag) |
1951 | 50 | p_state_enhaacplus_dec->frame_size = |
1952 | 50 | p_state_enhaacplus_dec->ui_in_bytes; |
1953 | 5.35k | } |
1954 | | |
1955 | 13.3k | ixheaacd_create_init_bit_buf(it_bit_buff, in_buffer, |
1956 | 13.3k | p_state_enhaacplus_dec->ui_in_bytes); |
1957 | 13.3k | p_state_enhaacplus_dec->pstr_bit_buf->xaac_jmp_buf = |
1958 | 13.3k | &(p_state_enhaacplus_dec->xaac_jmp_buf); |
1959 | | |
1960 | 13.3k | it_bit_buff->adts_header_present = |
1961 | 13.3k | p_state_enhaacplus_dec->s_adts_hdr_present; |
1962 | 13.3k | it_bit_buff->no_raw_data_blocks = |
1963 | 13.3k | (WORD8)p_state_enhaacplus_dec->b_n_raw_data_blk; |
1964 | 13.3k | it_bit_buff->protection_absent = p_state_enhaacplus_dec->protection_absent; |
1965 | | |
1966 | 13.3k | memcpy(&temp_bit_buff, it_bit_buff, sizeof(struct ia_bit_buf_struct)); |
1967 | | |
1968 | 13.3k | if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) |
1969 | 15.8k | elements_number = MAX_BS_ELEMENT; |
1970 | 18.4E | else |
1971 | 18.4E | elements_number = 2; |
1972 | | |
1973 | 172k | for (i = 0; i < elements_number; i++) |
1974 | 158k | p_state_enhaacplus_dec->pstr_stream_sbr[i][0].no_elements = 0; |
1975 | | |
1976 | 13.3k | { it_bit_buff->initial_cnt_bits = it_bit_buff->cnt_bits; } |
1977 | | |
1978 | 13.3k | ixheaacd_byte_align( |
1979 | 13.3k | p_state_enhaacplus_dec->ptr_bit_stream, |
1980 | 13.3k | &p_state_enhaacplus_dec->pstr_aac_dec_info[0]->byte_align_bits); |
1981 | | |
1982 | 13.3k | if (p_state_enhaacplus_dec->s_adts_hdr_present) { |
1983 | 8.70k | WORD32 error; |
1984 | | |
1985 | 8.70k | if (p_state_enhaacplus_dec->b_n_raw_data_blk == 0) { |
1986 | 8.70k | error = ixheaacd_readifadts(p_state_enhaacplus_dec, it_bit_buff, &adts); |
1987 | | |
1988 | 8.70k | if (error) return error; |
1989 | | |
1990 | 8.70k | p_state_enhaacplus_dec->protection_absent = adts.protection_absent; |
1991 | | |
1992 | 8.70k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD || |
1993 | 8.70k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) { |
1994 | 0 | p_state_enhaacplus_dec->frame_size = adts.aac_frame_length; |
1995 | 0 | if (p_obj_exhaacplus_dec->aac_config.framesize_480) |
1996 | 0 | p_state_enhaacplus_dec->frame_length = 480; |
1997 | 0 | else |
1998 | 0 | p_state_enhaacplus_dec->frame_length = 512; |
1999 | 0 | } |
2000 | 8.70k | } |
2001 | 8.70k | } |
2002 | | |
2003 | 13.3k | if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) { |
2004 | 7.02k | WORD32 result; |
2005 | 7.02k | WORD32 sync; |
2006 | 7.02k | WORD32 cnt_bits; |
2007 | | |
2008 | 7.02k | sync = ixheaacd_read_bits_buf(it_bit_buff, 11); |
2009 | 7.02k | cnt_bits = it_bit_buff->cnt_bits; |
2010 | 7.02k | if (it_bit_buff->cnt_bits <= 24) { |
2011 | 0 | return IA_XHEAAC_DEC_INIT_NONFATAL_INSUFFICIENT_INPUT_BYTES; |
2012 | 0 | } |
2013 | | |
2014 | 7.03k | while (sync != 0x2b7) { |
2015 | 6 | sync = ((sync & 0x3ff) << 1) | ixheaacd_read_bits_buf(it_bit_buff, 1); |
2016 | 6 | if (it_bit_buff->cnt_bits < 11) { |
2017 | 0 | ixheaacd_read_bidirection(it_bit_buff, -11); |
2018 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = |
2019 | 0 | (cnt_bits - it_bit_buff->cnt_bits) / 8; |
2020 | 0 | return (IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START); |
2021 | 0 | } |
2022 | 6 | } |
2023 | | |
2024 | 7.02k | it_bit_buff->audio_mux_align = it_bit_buff->cnt_bits - 13; |
2025 | | |
2026 | 7.02k | if (sync == 0x2b7) { |
2027 | 7.02k | result = ixheaacd_latm_audio_mux_element( |
2028 | 7.02k | it_bit_buff, &p_state_enhaacplus_dec->latm_struct_element, |
2029 | 7.02k | p_state_enhaacplus_dec, |
2030 | 7.02k | (ia_sampling_rate_info_struct *)&p_obj_exhaacplus_dec->aac_tables |
2031 | 7.02k | .pstr_huffmann_tables->str_sample_rate_info[0]); |
2032 | 7.02k | if (result < 0) { |
2033 | 2 | return result; |
2034 | 2 | } |
2035 | 7.02k | } |
2036 | 7.02k | } |
2037 | | |
2038 | 13.3k | p_state_enhaacplus_dec->pstr_aac_dec_info[0]->byte_align_bits = |
2039 | 13.3k | it_bit_buff->cnt_bits; |
2040 | | |
2041 | 13.3k | type = -1; |
2042 | 13.3k | ch_idx = 0; |
2043 | | |
2044 | 26.4k | while ((type != 7)) { |
2045 | 19.8k | ia_aac_dec_scratch_struct aac_scratch_struct; |
2046 | 19.8k | memset(&aac_scratch_struct, 0, sizeof(aac_scratch_struct)); |
2047 | | |
2048 | 19.8k | if (ch_idx >= elements_number) { |
2049 | 12 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
2050 | | |
2051 | 12 | return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX; |
2052 | 12 | } |
2053 | | |
2054 | 19.8k | ixheaacd_allocate_aac_scr( |
2055 | 19.8k | &aac_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v, |
2056 | 19.8k | time_data, 1, p_obj_exhaacplus_dec->aac_config.ui_max_channels, |
2057 | 19.8k | p_state_enhaacplus_dec->audio_object_type); |
2058 | | |
2059 | 19.8k | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info = |
2060 | 19.8k | &p_state_enhaacplus_dec->ind_cc_info; |
2061 | 19.8k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2062 | 0 | p_obj_exhaacplus_dec->aac_config.first_frame = 1; |
2063 | 0 | } |
2064 | | |
2065 | 19.8k | error_code = ixheaacd_aacdec_decodeframe( |
2066 | 19.8k | p_obj_exhaacplus_dec, &aac_scratch_struct, time_data, frame_status, &type, &ch_idx, 1, |
2067 | 19.8k | 2, p_obj_exhaacplus_dec->aac_config.element_instance_order, 0, 1, 0, |
2068 | 19.8k | p_obj_exhaacplus_dec->aac_config.ui_max_channels, 2, |
2069 | 19.8k | p_obj_exhaacplus_dec->p_state_aac->frame_length, |
2070 | 19.8k | p_obj_exhaacplus_dec->p_state_aac->frame_size, p_state_enhaacplus_dec->pstr_drc_dec, |
2071 | 19.8k | p_state_enhaacplus_dec->audio_object_type, p_state_enhaacplus_dec->ch_config, |
2072 | 19.8k | p_state_enhaacplus_dec->eld_specific_config, p_state_enhaacplus_dec->s_adts_hdr_present, |
2073 | 19.8k | &p_state_enhaacplus_dec->drc_dummy, p_state_enhaacplus_dec->ldmps_present, |
2074 | 19.8k | &p_state_enhaacplus_dec->slot_pos, mps_buffer, &p_state_enhaacplus_dec->mps_header, |
2075 | 19.8k | &p_state_enhaacplus_dec->ui_mps_out_bytes, 1, |
2076 | 19.8k | p_obj_exhaacplus_dec->aac_config.first_frame); |
2077 | | |
2078 | 19.8k | if (p_state_enhaacplus_dec->pstr_drc_dec->drc_element_found == 1) { |
2079 | 500 | if (p_obj_exhaacplus_dec->aac_config.i_loud_ref_level < 0) { |
2080 | 0 | p_obj_exhaacplus_dec->aac_config.output_level = |
2081 | 0 | p_state_enhaacplus_dec->pstr_drc_dec->prog_ref_level; |
2082 | 500 | } else { |
2083 | 500 | p_obj_exhaacplus_dec->aac_config.output_level = |
2084 | 500 | p_obj_exhaacplus_dec->aac_config.i_loud_ref_level; |
2085 | 500 | } |
2086 | 500 | } |
2087 | | |
2088 | 19.8k | memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx] |
2089 | 19.8k | ->pstr_aac_dec_ch_info[0] |
2090 | 19.8k | ->str_ics_info.ltp), |
2091 | 19.8k | 0, sizeof(ltp_info)); |
2092 | 19.8k | memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx] |
2093 | 19.8k | ->pstr_aac_dec_ch_info[0] |
2094 | 19.8k | ->str_ics_info.ltp2), |
2095 | 19.8k | 0, sizeof(ltp_info)); |
2096 | 19.8k | memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx] |
2097 | 19.8k | ->pstr_aac_dec_ch_info[1] |
2098 | 19.8k | ->str_ics_info.ltp), |
2099 | 19.8k | 0, sizeof(ltp_info)); |
2100 | 19.8k | memset(&(p_obj_exhaacplus_dec->p_state_aac->pstr_aac_dec_info[ch_idx] |
2101 | 19.8k | ->pstr_aac_dec_ch_info[1] |
2102 | 19.8k | ->str_ics_info.ltp2), |
2103 | 19.8k | 0, sizeof(ltp_info)); |
2104 | | |
2105 | 19.8k | { |
2106 | | |
2107 | 19.8k | frame_size_1 = p_state_enhaacplus_dec->frame_length; |
2108 | 19.8k | sample_rate_1 = |
2109 | 19.8k | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->sampling_rate; |
2110 | 19.8k | num_channels_1 = |
2111 | 19.8k | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->channels; |
2112 | 19.8k | } |
2113 | | |
2114 | 19.8k | if ((p_obj_exhaacplus_dec->aac_config.ui_max_channels <= 2) && |
2115 | 19.8k | (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 2)) { |
2116 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
2117 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_UNIMPLEMENTED_CCE; |
2118 | 0 | } |
2119 | | |
2120 | 19.8k | if (p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) { |
2121 | 3.30k | sbr_present_flag = 1; |
2122 | 3.30k | p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 1; |
2123 | 3.30k | } |
2124 | | |
2125 | 19.8k | if (error_code) { |
2126 | 642 | if (p_state_enhaacplus_dec->ui_input_over) { |
2127 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_EO_INPUT_REACHED; |
2128 | 0 | } |
2129 | | |
2130 | 642 | ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff); |
2131 | 642 | return error_code; |
2132 | 642 | } |
2133 | | |
2134 | 19.1k | if (p_state_enhaacplus_dec->s_adts_hdr_present) { |
2135 | 9.59k | if (adts.no_raw_data_blocks != 0) { |
2136 | 4.74k | if (adts.protection_absent == 0 && it_bit_buff->cnt_bits >= 16) { |
2137 | 104 | adts.crc_check = ixheaacd_read_bits_buf(it_bit_buff, 16); |
2138 | 104 | } |
2139 | 4.74k | } |
2140 | 9.59k | p_state_enhaacplus_dec->b_n_raw_data_blk--; |
2141 | 9.59k | } |
2142 | | |
2143 | 19.1k | sample_rate_2 = sample_rate_1; |
2144 | 19.1k | frame_size_2 = frame_size_1; |
2145 | | |
2146 | 19.1k | if (!p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] && |
2147 | 19.1k | p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) { |
2148 | 3.30k | WORD32 harmonic_sbr_flag = 0; |
2149 | 3.30k | if ((p_obj_exhaacplus_dec->aac_config.flag_16khz_out == 1) && |
2150 | 3.30k | (sample_rate_1 == 8000)) { |
2151 | 0 | p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0; |
2152 | 0 | } |
2153 | | |
2154 | 3.30k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr( |
2155 | 3.30k | sample_rate_1, frame_size_1, |
2156 | 3.30k | (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag, |
2157 | 3.30k | p_state_enhaacplus_dec->sbr_persistent_mem_v, |
2158 | 3.30k | p_state_enhaacplus_dec->ptr_overlap_buf, MAXNRSBRCHANNELS, (WORD)1, |
2159 | 3.30k | 1, frame_size_1 * 2, &harmonic_sbr_flag, NULL, |
2160 | 3.30k | p_state_enhaacplus_dec->str_sbr_config, |
2161 | 3.30k | p_state_enhaacplus_dec->audio_object_type, |
2162 | 3.30k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
2163 | 3.30k | .ldmps_present_flag, |
2164 | 3.30k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
2165 | 3.30k | .no_ldsbr_present); |
2166 | 3.30k | if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { |
2167 | 3.28k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf = |
2168 | 3.28k | &(p_state_enhaacplus_dec->xaac_jmp_buf); |
2169 | 3.28k | } |
2170 | 15.8k | } else { |
2171 | 15.8k | } |
2172 | | |
2173 | 19.1k | if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] && |
2174 | 19.1k | p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) { |
2175 | 3.28k | ia_sbr_scr_struct sbr_scratch_struct; |
2176 | 3.28k | WORD16 num_channels_1_t = num_channels_1; |
2177 | 3.28k | ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v, |
2178 | 3.28k | time_data, 0, NULL, 0, 0); |
2179 | 3.28k | { |
2180 | 3.28k | WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type; |
2181 | | |
2182 | 3.28k | if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) { |
2183 | 708 | WORD32 i = 0; |
2184 | 708 | ia_dec_data_struct *pstr_dec_data = |
2185 | 708 | (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data; |
2186 | 708 | if (num_channels_1 == 1) { |
2187 | 666k | for (; i < 1024; i++) { |
2188 | 665k | pstr_dec_data->str_usac_data.time_sample_vector[0][i] = |
2189 | 665k | ((FLOAT32)time_data[i]); |
2190 | 665k | } |
2191 | 650 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] = |
2192 | 650 | &pstr_dec_data->str_usac_data.time_sample_vector[0][0]; |
2193 | | |
2194 | 650 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] = |
2195 | 650 | &pstr_dec_data->str_usac_data.time_sample_vector[1][0]; |
2196 | 650 | } else if (num_channels_1 == 2) { |
2197 | 59.4k | for (; i < 1024; i++) { |
2198 | 59.3k | pstr_dec_data->str_usac_data.time_sample_vector[0][i] = |
2199 | 59.3k | ((FLOAT32)time_data[2 * i + 0]); |
2200 | 59.3k | pstr_dec_data->str_usac_data.time_sample_vector[1][i] = |
2201 | 59.3k | ((FLOAT32)time_data[2 * i + 1]); |
2202 | 59.3k | } |
2203 | 58 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] = |
2204 | 58 | &pstr_dec_data->str_usac_data.time_sample_vector[0][0]; |
2205 | | |
2206 | 58 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] = |
2207 | 58 | &pstr_dec_data->str_usac_data.time_sample_vector[1][0]; |
2208 | 58 | } |
2209 | 708 | } |
2210 | 3.28k | } |
2211 | 3.28k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->ec_flag = |
2212 | 3.28k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal; |
2213 | 3.28k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->esbr_hq = |
2214 | 3.28k | p_obj_exhaacplus_dec->aac_config.ui_hq_esbr; |
2215 | 3.28k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr = |
2216 | 3.28k | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr; |
2217 | 3.28k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr_ps = |
2218 | 3.28k | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps; |
2219 | | |
2220 | 3.28k | if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { |
2221 | 3.28k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf = |
2222 | 3.28k | &(p_state_enhaacplus_dec->xaac_jmp_buf); |
2223 | 3.28k | } |
2224 | | |
2225 | 3.28k | if (ixheaacd_applysbr(p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx], |
2226 | 3.28k | &p_state_enhaacplus_dec->pstr_stream_sbr[0][0], time_data, |
2227 | 3.28k | &num_channels_1, frame_status, |
2228 | 3.28k | p_obj_exhaacplus_dec->aac_config.down_sample_flag, 0, |
2229 | 3.28k | &sbr_scratch_struct, 1, 1, 0, NULL, NULL, |
2230 | 3.28k | p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present, |
2231 | 3.28k | p_state_enhaacplus_dec->audio_object_type, 1, |
2232 | 3.28k | p_state_enhaacplus_dec->ldmps_present, frame_size_1, |
2233 | 3.28k | p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present, |
2234 | 3.28k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal, |
2235 | 3.28k | p_obj_exhaacplus_dec->aac_config.first_frame) != SBRDEC_OK) { |
2236 | 25 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0; |
2237 | 25 | return -1; |
2238 | 3.26k | } else { |
2239 | 3.26k | if (!p_obj_exhaacplus_dec->aac_config.down_sample_flag) { |
2240 | 1.50k | sample_rate_1 *= 2; |
2241 | 1.50k | } |
2242 | 3.26k | if (p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present == 1) { |
2243 | 2.48k | p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.pre_mix_req = 1; |
2244 | 2.48k | ixheaacd_mps_payload( |
2245 | 2.48k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx], |
2246 | 2.48k | p_obj_exhaacplus_dec); |
2247 | 2.48k | } |
2248 | 3.26k | } |
2249 | 3.26k | { |
2250 | 3.26k | WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type; |
2251 | | |
2252 | 3.26k | if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) { |
2253 | 708 | WORD32 out_bytes = 0; |
2254 | 708 | ia_dec_data_struct *pstr_dec_data = |
2255 | 708 | (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data; |
2256 | 708 | ixheaacd_samples_sat((WORD8 *)time_data, 2048, 16, |
2257 | 708 | pstr_dec_data->str_usac_data.time_sample_vector, &out_bytes, 1); |
2258 | 708 | } |
2259 | 3.26k | } |
2260 | 3.26k | if (p_obj_exhaacplus_dec->aac_config.flag_downmix) { |
2261 | 0 | num_channels_1 = 1; |
2262 | 0 | } |
2263 | 3.26k | if (num_channels_1_t == 1 && num_channels_1 == 2) ps_detected = 1; |
2264 | 15.9k | } else { |
2265 | 15.9k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present = 1; |
2266 | 15.9k | } |
2267 | | |
2268 | 19.1k | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
2269 | 19.1k | p_state_enhaacplus_dec->pstr_bit_buf = it_bit_buff; |
2270 | | |
2271 | 19.1k | { |
2272 | 19.1k | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] = |
2273 | 19.1k | ixheaacd_aac_decoder_init( |
2274 | 19.1k | p_state_enhaacplus_dec, |
2275 | 19.1k | p_state_enhaacplus_dec->pstr_stream_sbr[0], 2, |
2276 | 19.1k | p_state_enhaacplus_dec->aac_persistent_mem_v, |
2277 | 19.1k | p_state_enhaacplus_dec->frame_length); |
2278 | | |
2279 | 19.1k | if (!p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]) { |
2280 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
2281 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
2282 | 0 | } |
2283 | | |
2284 | 19.1k | if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { |
2285 | 3.15k | WORD32 harmonic_sbr_flag = 0; |
2286 | 3.15k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr( |
2287 | 3.15k | sample_rate_2, frame_size_2, |
2288 | 3.15k | (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag, |
2289 | 3.15k | p_state_enhaacplus_dec->sbr_persistent_mem_v, |
2290 | 3.15k | p_state_enhaacplus_dec->ptr_overlap_buf, MAXNRSBRCHANNELS, 1, 1, |
2291 | 3.15k | frame_size_2 * 2, &harmonic_sbr_flag, NULL, |
2292 | 3.15k | p_state_enhaacplus_dec->str_sbr_config, |
2293 | 3.15k | p_state_enhaacplus_dec->audio_object_type, |
2294 | 3.15k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
2295 | 3.15k | .ldmps_present_flag, |
2296 | 3.15k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
2297 | 3.15k | .no_ldsbr_present); |
2298 | 3.15k | } |
2299 | 19.1k | if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { |
2300 | 3.15k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf = |
2301 | 3.15k | &(p_state_enhaacplus_dec->xaac_jmp_buf); |
2302 | 3.15k | } |
2303 | 19.1k | } |
2304 | | |
2305 | 19.1k | if (sample_rate < sample_rate_1) sample_rate = sample_rate_1; |
2306 | | |
2307 | 19.1k | ch_idx++; |
2308 | | |
2309 | 19.1k | if (p_state_enhaacplus_dec->audio_object_type >= ER_OBJECT_START && |
2310 | 19.1k | (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD || |
2311 | 6.19k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD || |
2312 | 6.19k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC)) |
2313 | 6.14k | break; |
2314 | 19.1k | } |
2315 | | |
2316 | 12.7k | { |
2317 | 12.7k | ia_adts_crc_info_struct *ptr_adts_crc_info = |
2318 | 12.7k | p_state_enhaacplus_dec->ptr_bit_stream->pstr_adts_crc_info; |
2319 | 12.7k | if (ptr_adts_crc_info->crc_active == 1) { |
2320 | 92 | if ((error_code = ixheaacd_adts_crc_check_crc(ptr_adts_crc_info))) { |
2321 | 92 | return error_code; |
2322 | 92 | } |
2323 | 92 | } |
2324 | 12.7k | } |
2325 | | |
2326 | 12.6k | { |
2327 | 12.6k | VOID *temp; |
2328 | 12.6k | WORD prev_persistent_used_t; |
2329 | 12.6k | WORD prev_sbrpersistent_used_t; |
2330 | 12.6k | WORD ps_enable; |
2331 | 12.6k | WORD ch_idx_err = 0; |
2332 | 12.6k | WORD persistent_used_t = 0; |
2333 | 12.6k | WORD channel_check = 0; |
2334 | 12.6k | WORD cc_channel_check = 0; |
2335 | 12.6k | WORD max_ch_num = p_obj_exhaacplus_dec->aac_config.ui_max_channels; |
2336 | 12.6k | WORD32 harmonic_sbr_flag = 0; |
2337 | 12.6k | i = 0; |
2338 | | |
2339 | 12.6k | p_obj_exhaacplus_dec->aac_config.ui_n_channels = ch_idx; |
2340 | 28.0k | while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx_err] <= 3 && |
2341 | 28.6k | p_obj_exhaacplus_dec->aac_config.element_type[ch_idx_err] >= 0) { |
2342 | 15.3k | ch_idx_err++; |
2343 | 15.3k | } |
2344 | | |
2345 | 12.6k | if (ch_idx_err == 0) { |
2346 | 29 | p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0; |
2347 | 29 | p_state_enhaacplus_dec->i_bytes_consumed = (WORD32)( |
2348 | 29 | it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base); |
2349 | 29 | return IA_XHEAAC_DEC_INIT_NONFATAL_DECODE_FRAME_ERROR; |
2350 | 29 | } |
2351 | | |
2352 | 12.5k | if (ch_idx_err == 1) |
2353 | 12.3k | ps_enable = 1; |
2354 | 249 | else |
2355 | 249 | ps_enable = 0; |
2356 | | |
2357 | 22.7k | while (p_obj_exhaacplus_dec->aac_config.element_type[i] >= 0 && |
2358 | 22.7k | p_obj_exhaacplus_dec->aac_config.element_type[i] <= 3) { |
2359 | 15.3k | WORD32 channel = 0; |
2360 | 15.3k | switch (p_obj_exhaacplus_dec->aac_config.element_type[i]) { |
2361 | 10.1k | case 0: |
2362 | 12.2k | case 3: |
2363 | 12.2k | channel = 1; |
2364 | 12.2k | break; |
2365 | 2.70k | case 1: |
2366 | 2.70k | channel = 2; |
2367 | 2.70k | break; |
2368 | 426 | case 2: |
2369 | 426 | if (max_ch_num > 2) { |
2370 | 426 | if (p_obj_exhaacplus_dec->aac_config.element_instance_order[i] != |
2371 | 426 | p_obj_exhaacplus_dec->aac_config.ui_coupling_channel) { |
2372 | 271 | i++; |
2373 | 271 | continue; |
2374 | 271 | } |
2375 | 155 | channel = 1; |
2376 | 155 | } else { |
2377 | 0 | i++; |
2378 | 0 | continue; |
2379 | 0 | } |
2380 | 155 | cc_channel_check++; |
2381 | 155 | break; |
2382 | 0 | default: |
2383 | 0 | return -1; |
2384 | 15.3k | } |
2385 | | |
2386 | 15.1k | if (cc_channel_check > MAX_CC_CHANNEL_NUM) |
2387 | 1 | return IA_XHEAAC_DEC_EXE_FATAL_UNIMPLEMENTED_CCE; |
2388 | 15.1k | if (ps_enable == 1) { |
2389 | 12.3k | channel = 2; |
2390 | 12.3k | } |
2391 | | |
2392 | 15.1k | if (p_obj_exhaacplus_dec->aac_config.element_type[i] != 2) { |
2393 | 14.9k | channel_check += channel; |
2394 | 14.9k | } |
2395 | | |
2396 | 15.1k | if (channel_check > max_ch_num) { |
2397 | 4 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
2398 | 4 | return IA_XHEAAC_DEC_INIT_FATAL_STREAM_CHAN_GT_MAX; |
2399 | 4 | } |
2400 | | |
2401 | 15.0k | temp = p_state_enhaacplus_dec->aac_persistent_mem_v; |
2402 | | |
2403 | 15.0k | prev_persistent_used_t = persistent_used_t; |
2404 | | |
2405 | 15.0k | ixheaacd_allocate_mem_persistent( |
2406 | 15.0k | p_obj_exhaacplus_dec, p_state_enhaacplus_dec, channel, |
2407 | 15.0k | &persistent_used_t, &prev_sbrpersistent_used_t, ps_enable); |
2408 | | |
2409 | 15.0k | p_state_enhaacplus_dec->aac_persistent_mem_v = temp; |
2410 | 15.0k | p_state_enhaacplus_dec->last_frame_ok = 1; |
2411 | | |
2412 | 15.0k | p_state_enhaacplus_dec->num_channel_last = 0; |
2413 | 15.0k | p_state_enhaacplus_dec->ui_init_done = 0; |
2414 | 15.0k | p_state_enhaacplus_dec->ui_input_over = 0; |
2415 | 15.0k | p_state_enhaacplus_dec->ptr_bit_stream = |
2416 | 15.0k | p_state_enhaacplus_dec->pstr_bit_buf; |
2417 | | |
2418 | 15.0k | p_state_enhaacplus_dec->pstr_aac_dec_info[i] = 0; |
2419 | | |
2420 | 15.0k | p_state_enhaacplus_dec->pstr_aac_dec_info[i] = |
2421 | 15.0k | ixheaacd_aac_decoder_init( |
2422 | 15.0k | p_state_enhaacplus_dec, |
2423 | 15.0k | p_state_enhaacplus_dec->pstr_stream_sbr[i], channel, |
2424 | 15.0k | (WORD8 *)p_state_enhaacplus_dec->aac_persistent_mem_v + |
2425 | 15.0k | prev_persistent_used_t, |
2426 | 15.0k | p_state_enhaacplus_dec->frame_length); |
2427 | | |
2428 | 15.0k | if (!p_state_enhaacplus_dec->pstr_aac_dec_info[i]) { |
2429 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
2430 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
2431 | 0 | } |
2432 | | |
2433 | 15.0k | p_state_enhaacplus_dec->str_sbr_dec_info[i] = ixheaacd_init_sbr( |
2434 | 15.0k | sample_rate_2, frame_size_2, |
2435 | 15.0k | (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag, |
2436 | 15.0k | p_state_enhaacplus_dec->sbr_persistent_mem_v, |
2437 | 15.0k | p_state_enhaacplus_dec->ptr_overlap_buf, channel, ps_enable, 1, |
2438 | 15.0k | frame_size_2 * 2, &harmonic_sbr_flag, NULL, |
2439 | 15.0k | p_state_enhaacplus_dec->str_sbr_config, |
2440 | 15.0k | p_state_enhaacplus_dec->audio_object_type, |
2441 | 15.0k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
2442 | 15.0k | .ldmps_present_flag, |
2443 | 15.0k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
2444 | 15.0k | .no_ldsbr_present); |
2445 | 15.0k | if (p_state_enhaacplus_dec->str_sbr_dec_info[i]) { |
2446 | 15.0k | p_state_enhaacplus_dec->str_sbr_dec_info[i]->xaac_jmp_buf = |
2447 | 15.0k | &(p_state_enhaacplus_dec->xaac_jmp_buf); |
2448 | 15.0k | } |
2449 | 15.0k | if ((sbr_present_flag && |
2450 | 15.0k | ((p_obj_exhaacplus_dec->p_state_aac->audio_object_type == |
2451 | 3.23k | AOT_AAC_LC) || |
2452 | 3.23k | (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == |
2453 | 2.51k | AOT_SBR) || |
2454 | 3.23k | (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == |
2455 | 2.51k | AOT_PS))) || |
2456 | 15.0k | ((p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
2457 | 14.3k | .ldmps_present_flag == 1) && |
2458 | 14.3k | (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == |
2459 | 373 | AOT_ER_AAC_ELD))) |
2460 | 1.10k | p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 1; |
2461 | 15.0k | copy_qmf_to_ldmps(&p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle, |
2462 | 15.0k | p_state_enhaacplus_dec->sbr_persistent_mem_v); |
2463 | 15.0k | if (p_state_enhaacplus_dec->audio_object_type == AOT_AAC_LC && |
2464 | 15.0k | p_state_enhaacplus_dec->ui_mps_out_bytes != 0) { |
2465 | 5.16k | p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present = 1; |
2466 | 5.16k | if (p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) { |
2467 | 0 | p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.mps_with_sbr = 1; |
2468 | 0 | } |
2469 | 5.16k | error_code = |
2470 | 5.16k | ixheaacd_aac_mps_init(p_obj_exhaacplus_dec, mps_buffer, |
2471 | 5.16k | p_state_enhaacplus_dec->ui_mps_out_bytes, sample_rate_1); |
2472 | 5.16k | if (error_code) return error_code; |
2473 | 5.09k | p_obj_exhaacplus_dec->aac_config.ui_n_channels = |
2474 | 5.09k | p_state_enhaacplus_dec->heaac_mps_handle.num_output_channels_at; |
2475 | 5.09k | if (p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.mps_with_sbr == 1) { |
2476 | 0 | p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 1; |
2477 | 0 | } |
2478 | 5.09k | if (p_obj_exhaacplus_dec->aac_config.element_type[i + 1] >= 0 && |
2479 | 5.09k | p_obj_exhaacplus_dec->aac_config.element_type[i + 1] <= 3) { |
2480 | 1 | return IA_FATAL_ERROR; |
2481 | 1 | } |
2482 | 5.09k | break; |
2483 | 5.09k | } |
2484 | 9.93k | i++; |
2485 | 9.93k | } |
2486 | 12.5k | p_state_enhaacplus_dec->pers_mem_ptr = |
2487 | 12.5k | (WORD8 *)p_state_enhaacplus_dec->aac_persistent_mem_v + |
2488 | 12.5k | persistent_used_t; |
2489 | | |
2490 | 12.5k | p_obj_exhaacplus_dec->aac_config.i_channel_mask = |
2491 | 12.5k | ixheaacd_get_channel_mask(p_obj_exhaacplus_dec); |
2492 | | |
2493 | 12.5k | { |
2494 | 12.5k | num_channels_1 = 0; |
2495 | 12.5k | ch_idx = 0; |
2496 | 27.7k | while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] >= 0 && |
2497 | 27.7k | p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] <= 3) { |
2498 | 15.2k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 0 || |
2499 | 15.2k | p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 3) |
2500 | 12.1k | num_channels_1 += 1; |
2501 | 15.2k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 1) |
2502 | 2.69k | num_channels_1 += 2; |
2503 | 15.2k | ch_idx++; |
2504 | 15.2k | } |
2505 | | |
2506 | 12.5k | if (ch_idx == 2 && num_channels_1 == 2) { |
2507 | 233 | p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 2; |
2508 | 233 | } |
2509 | 12.5k | if (ch_idx == 1) { |
2510 | 12.2k | if (num_channels_1 == 1) |
2511 | 9.78k | p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 0; |
2512 | 12.2k | if (num_channels_1 == 2) |
2513 | 2.39k | p_obj_exhaacplus_dec->aac_config.ui_channel_mode = 1; |
2514 | 12.2k | } |
2515 | | |
2516 | 12.5k | if (ps_detected == 1 && num_channels_1 == 1) num_channels_1 = 2; |
2517 | 12.5k | } |
2518 | 12.5k | } |
2519 | 12.5k | if (1 == p_obj_exhaacplus_dec->aac_config.downmix) num_channels_1 = 2; |
2520 | | |
2521 | 12.5k | if (p_obj_exhaacplus_dec->aac_config.flag_downmix == 1) { |
2522 | 0 | num_channels_1 = 1; |
2523 | 0 | } |
2524 | | |
2525 | 12.5k | if ((p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1) && |
2526 | 12.5k | (ch_idx == 1 || num_channels_1 <= 2)) { |
2527 | 884 | num_channels_1 = 2; |
2528 | 884 | } |
2529 | | |
2530 | 12.5k | p_obj_exhaacplus_dec->aac_config.ui_n_channels = num_channels_1; |
2531 | 12.5k | p_obj_exhaacplus_dec->aac_config.ui_samp_freq = sample_rate; |
2532 | 12.5k | p_state_enhaacplus_dec->ui_init_done = 1; |
2533 | | |
2534 | 12.5k | memcpy(it_bit_buff, &temp_bit_buff, sizeof(struct ia_bit_buf_struct)); |
2535 | | |
2536 | 12.5k | p_state_enhaacplus_dec->b_n_raw_data_blk = 0; |
2537 | | |
2538 | 13.1k | if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 1) { |
2539 | 13.1k | p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0; |
2540 | 13.1k | } |
2541 | 12.5k | } |
2542 | 29.1k | return err_code; |
2543 | 39.7k | } |
2544 | | |
2545 | | VOID ixheaacd_fill_slot_order(ia_aac_dec_state_struct *p_state_enhaacplus_dec, |
2546 | | WORD32 ch, WORD8 *ptr_is_cpe, |
2547 | 14.5k | WORD8 *ptr_tag_select, WORD32 *ptr_idx_no) { |
2548 | 14.5k | WORD32 i; |
2549 | 14.5k | WORD32 idx_no = *ptr_idx_no; |
2550 | 14.5k | WORD *p_slot_element = p_state_enhaacplus_dec->p_config->slot_element; |
2551 | 14.5k | WORD *p_element_type = p_state_enhaacplus_dec->p_config->element_type; |
2552 | 14.5k | WORD *p_element_instance_order = |
2553 | 14.5k | p_state_enhaacplus_dec->p_config->element_instance_order; |
2554 | | |
2555 | 15.7k | for (i = 0; i < ch; i++) { |
2556 | 1.18k | if (ptr_is_cpe[i] == 0) { |
2557 | 990 | *p_slot_element++ = idx_no++; |
2558 | 990 | *p_element_type++ = 0; |
2559 | 990 | *p_element_instance_order++ = ptr_tag_select[i]; |
2560 | 990 | } |
2561 | 1.18k | } |
2562 | 14.5k | *ptr_idx_no = idx_no; |
2563 | 14.5k | } |
2564 | | |
2565 | | VOID ixheaacd_fill_prog_config_slots( |
2566 | 4.84k | ia_aac_dec_state_struct *p_state_enhaacplus_dec) { |
2567 | 4.84k | WORD32 idx_no = 0; |
2568 | | |
2569 | 4.84k | ixheaacd_fill_slot_order( |
2570 | 4.84k | p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config |
2571 | 4.84k | .num_front_channel_elements, |
2572 | 4.84k | p_state_enhaacplus_dec->p_config->str_prog_config.front_element_is_cpe, |
2573 | 4.84k | p_state_enhaacplus_dec->p_config->str_prog_config |
2574 | 4.84k | .front_element_tag_select, |
2575 | 4.84k | &idx_no); |
2576 | | |
2577 | 4.84k | ixheaacd_fill_slot_order( |
2578 | 4.84k | p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config |
2579 | 4.84k | .num_side_channel_elements, |
2580 | 4.84k | p_state_enhaacplus_dec->p_config->str_prog_config.side_element_is_cpe, |
2581 | 4.84k | p_state_enhaacplus_dec->p_config->str_prog_config.side_element_tag_select, |
2582 | 4.84k | &idx_no); |
2583 | | |
2584 | 4.84k | ixheaacd_fill_slot_order( |
2585 | 4.84k | p_state_enhaacplus_dec, p_state_enhaacplus_dec->p_config->str_prog_config |
2586 | 4.84k | .num_back_channel_elements, |
2587 | 4.84k | p_state_enhaacplus_dec->p_config->str_prog_config.back_element_is_cpe, |
2588 | 4.84k | p_state_enhaacplus_dec->p_config->str_prog_config.back_element_tag_select, |
2589 | 4.84k | &idx_no); |
2590 | 4.84k | } |
2591 | | |
2592 | | IA_ERRORCODE ixheaacd_dec_execute( |
2593 | 554k | ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) { |
2594 | 554k | ia_adts_header_struct adts = {0}; |
2595 | 554k | ia_aac_dec_state_struct *p_state_enhaacplus_dec; |
2596 | | |
2597 | 554k | UWORD8 *in_buffer; |
2598 | 554k | WORD16 *time_data; |
2599 | 554k | WORD16 num_of_out_samples = 0; |
2600 | 554k | WORD16 frame_size = 0; |
2601 | 554k | WORD32 sample_rate_dec = 0; |
2602 | 554k | WORD32 sample_rate = 0; |
2603 | 554k | WORD16 num_ch = 0; |
2604 | 554k | struct ia_bit_buf_struct *it_bit_buff; |
2605 | 554k | UWORD8 *mps_buffer; |
2606 | 554k | WORD32 error_code = IA_NO_ERROR; |
2607 | 554k | WORD ch_idx1; |
2608 | 554k | WORD type; |
2609 | 554k | WORD total_channels = 0; |
2610 | 554k | WORD total_elements = 0; |
2611 | 554k | WORD16 *actual_out_buffer = NULL; |
2612 | 554k | WORD ps_enable; |
2613 | 554k | WORD esbr_mono_downmix = 0; |
2614 | 554k | WORD8 element_used[MAX_BS_ELEMENT]; |
2615 | 554k | WORD32 channel_coupling_flag = 0; |
2616 | | |
2617 | 554k | SIZE_T bytes_for_sync; |
2618 | 554k | WORD32 audio_mux_length_bytes_last = 0; |
2619 | 554k | WORD32 ret_val; |
2620 | 554k | WORD32 mps_out_samples; |
2621 | | |
2622 | 554k | p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0; |
2623 | 554k | p_obj_exhaacplus_dec->aac_config.frame_status = 1; |
2624 | | |
2625 | 554k | if (p_obj_exhaacplus_dec->p_state_aac != NULL) { |
2626 | 554k | ret_val = setjmp(p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf); |
2627 | 554k | if (ret_val != 0) { |
2628 | 6.49k | p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = |
2629 | 6.49k | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; |
2630 | 6.49k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0; |
2631 | 6.49k | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2632 | 6.49k | return IA_NO_ERROR; |
2633 | 6.49k | } |
2634 | 554k | } |
2635 | | |
2636 | 547k | time_data = (WORD16 *)(p_obj_exhaacplus_dec |
2637 | 547k | ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]); |
2638 | 547k | in_buffer = p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]; |
2639 | 547k | p_state_enhaacplus_dec = p_obj_exhaacplus_dec->p_state_aac; |
2640 | 547k | p_state_enhaacplus_dec->aac_scratch_mem_v = |
2641 | 547k | p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_SCRATCH_IDX]; |
2642 | 547k | p_state_enhaacplus_dec->mps_header = -1; |
2643 | 547k | mps_buffer = p_state_enhaacplus_dec->mps_buffer; |
2644 | 547k | it_bit_buff = p_state_enhaacplus_dec->pstr_bit_buf; |
2645 | | |
2646 | 547k | ch_idx1 = 0; |
2647 | 547k | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
2648 | | |
2649 | 547k | if (p_state_enhaacplus_dec->audio_object_type == AOT_USAC) { |
2650 | 261k | WORD32 pcm_size = p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz; |
2651 | 261k | WORD8 *inbuffer = (WORD8 *)(p_obj_exhaacplus_dec |
2652 | 261k | ->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]); |
2653 | 261k | WORD8 *outbuffer = |
2654 | 261k | (WORD8 *)(p_obj_exhaacplus_dec |
2655 | 261k | ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]); |
2656 | 261k | WORD32 out_bytes = 0; |
2657 | | |
2658 | 261k | WORD32 frames_done = p_obj_exhaacplus_dec->p_state_aac->frame_counter; |
2659 | | |
2660 | 261k | ia_dec_data_struct *pstr_dec_data = |
2661 | 261k | (ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac |
2662 | 261k | ->pstr_dec_data); |
2663 | | |
2664 | 261k | if (pstr_dec_data->str_usac_data.down_samp_sbr != 0) return IA_FATAL_ERROR; |
2665 | | |
2666 | 261k | if (p_obj_exhaacplus_dec->p_state_aac->ui_input_over == 0) { |
2667 | 261k | ia_audio_specific_config_struct *ptr_audio_specific_config = |
2668 | 261k | ((ia_audio_specific_config_struct *) |
2669 | 261k | p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config); |
2670 | | |
2671 | 261k | ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
2672 | 261k | .preroll_counter = 0; |
2673 | 261k | { |
2674 | 261k | WORD32 iii = 0; |
2675 | 1.30M | for (iii = 0; iii < (MAX_AUDIO_PREROLLS + 1); iii++) { |
2676 | 1.04M | ((ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac |
2677 | 1.04M | ->pstr_dec_data)) |
2678 | 1.04M | ->str_frame_data.str_audio_specific_config.str_usac_config |
2679 | 1.04M | .str_usac_dec_config.usac_ext_gain_payload_len[iii] = 0; |
2680 | 1.04M | ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
2681 | 1.04M | .usac_ext_gain_payload_len[iii] = |
2682 | 1.04M | 0; // reinitilize the payload len buff |
2683 | 1.04M | ptr_audio_specific_config->str_usac_config.str_usac_dec_config |
2684 | 1.04M | .preroll_bytes[iii] = 0; |
2685 | 1.04M | } |
2686 | 261k | } |
2687 | | |
2688 | 261k | ((ia_dec_data_struct *)(p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data)) |
2689 | 261k | ->str_frame_data.str_audio_specific_config.str_usac_config |
2690 | 261k | .str_usac_dec_config.preroll_counter = 0; |
2691 | 261k | error_code = ixheaacd_dec_main( |
2692 | 261k | p_obj_exhaacplus_dec, inbuffer, outbuffer, &out_bytes, frames_done, |
2693 | 261k | pcm_size, &p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch); |
2694 | 261k | if (error_code) { |
2695 | 1.73k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2696 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2697 | 1.73k | } else { |
2698 | 1.73k | return error_code; |
2699 | 1.73k | } |
2700 | 1.73k | } |
2701 | 259k | p_obj_exhaacplus_dec->p_state_aac->frame_counter++; |
2702 | 259k | } else { |
2703 | 0 | out_bytes = 0; |
2704 | 0 | } |
2705 | | |
2706 | 259k | if (pstr_dec_data->str_usac_data.ec_flag == 0) { |
2707 | 256k | if (p_state_enhaacplus_dec->bs_format != LOAS_BSFORMAT) { |
2708 | 4.02k | p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = |
2709 | 4.02k | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; |
2710 | 4.02k | } |
2711 | 256k | } else { |
2712 | 3.40k | if (p_state_enhaacplus_dec->bs_format != LOAS_BSFORMAT) { |
2713 | 0 | if (pstr_dec_data->str_usac_data.frame_ok == 0) { |
2714 | 0 | p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = |
2715 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; |
2716 | 0 | pstr_dec_data->dec_bit_buf.cnt_bits = 0; |
2717 | 0 | } else { |
2718 | 0 | ia_dec_data_struct *pstr_dec_data = |
2719 | 0 | (ia_dec_data_struct *)p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data; |
2720 | |
|
2721 | 0 | if (pstr_dec_data->dec_bit_buf.cnt_bits & 7) { |
2722 | 0 | pstr_dec_data->dec_bit_buf.cnt_bits -= (pstr_dec_data->dec_bit_buf.cnt_bits & 7); |
2723 | 0 | } |
2724 | 0 | if (pstr_dec_data->dec_bit_buf.cnt_bits == 0) { |
2725 | 0 | p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = |
2726 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; |
2727 | 0 | } else { |
2728 | 0 | p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = |
2729 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes - |
2730 | 0 | (pstr_dec_data->dec_bit_buf.cnt_bits >> 3); |
2731 | 0 | } |
2732 | 0 | } |
2733 | 0 | } |
2734 | 3.40k | } |
2735 | | |
2736 | 259k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = out_bytes; |
2737 | 259k | p_obj_exhaacplus_dec->aac_config.ui_n_channels = |
2738 | 259k | p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch; |
2739 | 259k | pstr_dec_data->str_usac_data.sbr_parse_err_flag = 0; |
2740 | | |
2741 | 259k | return 0; |
2742 | 261k | } |
2743 | | |
2744 | 609k | while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] <= 3 && |
2745 | 615k | p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] >= 0) { |
2746 | 322k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 0 || |
2747 | 322k | p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 3) { |
2748 | 254k | total_channels += 1; |
2749 | 254k | total_elements += 1; |
2750 | 254k | } |
2751 | 322k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 1) { |
2752 | 65.7k | total_elements += 1; |
2753 | 65.7k | total_channels += 2; |
2754 | 65.7k | } |
2755 | 322k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx1] == 2) { |
2756 | 2.41k | total_elements += 1; |
2757 | 2.41k | } |
2758 | | |
2759 | 322k | ch_idx1++; |
2760 | 322k | if (ch_idx1 > MAX_BS_ELEMENT) { |
2761 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) |
2762 | 0 | break; |
2763 | 0 | else |
2764 | 0 | return IA_FATAL_ERROR; |
2765 | 0 | } |
2766 | 322k | } |
2767 | | |
2768 | 286k | if (ch_idx1 != 1) { |
2769 | 15.1k | ps_enable = 0; |
2770 | 15.1k | if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) { |
2771 | 15.1k | WORD32 scratch_pointer; |
2772 | | |
2773 | 15.1k | scratch_pointer = (MAX_SCR_SIZE - SCR_INTER_SCR_SIZE); |
2774 | | |
2775 | 15.1k | p_state_enhaacplus_dec->coup_ch_output = |
2776 | 15.1k | (WORD32 *)((WORD8 *) |
2777 | 15.1k | p_obj_exhaacplus_dec->p_state_aac->aac_scratch_mem_v + |
2778 | 15.1k | scratch_pointer); |
2779 | 15.1k | } |
2780 | | |
2781 | 15.1k | } |
2782 | | |
2783 | 271k | else { |
2784 | 271k | if (total_channels < (WORD)p_obj_exhaacplus_dec->aac_config.ui_n_channels) |
2785 | 25.2k | total_channels = p_obj_exhaacplus_dec->aac_config.ui_n_channels; |
2786 | 271k | ps_enable = 1; |
2787 | 271k | } |
2788 | | |
2789 | 286k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0; |
2790 | 286k | p_obj_exhaacplus_dec->p_state_aac->ui_mps_out_bytes = 0; |
2791 | 286k | if (p_state_enhaacplus_dec->ui_in_bytes == 0) { |
2792 | 0 | UWORD32 i; |
2793 | 0 | WORD32 j; |
2794 | 0 | if (p_state_enhaacplus_dec->peak_lim_init == 1) { |
2795 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = |
2796 | 0 | (p_state_enhaacplus_dec->peak_limiter.attack_time_samples) * |
2797 | 0 | total_channels * sizeof(WORD16); |
2798 | |
|
2799 | 0 | for (j = 0; j < total_channels; j++) { |
2800 | 0 | for (i = 0; |
2801 | 0 | i < (p_state_enhaacplus_dec->peak_limiter.attack_time_samples - |
2802 | 0 | p_state_enhaacplus_dec->peak_limiter.delayed_input_index); |
2803 | 0 | i++) { |
2804 | 0 | *(time_data + total_channels * i + j) = ixheaac_round16( |
2805 | 0 | (WORD32)*(p_state_enhaacplus_dec->peak_limiter.delayed_input + |
2806 | 0 | (p_state_enhaacplus_dec->peak_limiter.delayed_input_index) * |
2807 | 0 | total_channels + |
2808 | 0 | total_channels * i + j)); |
2809 | 0 | } |
2810 | 0 | } |
2811 | |
|
2812 | 0 | for (j = 0; j < total_channels; j++) { |
2813 | 0 | for (i = 0; |
2814 | 0 | i < p_state_enhaacplus_dec->peak_limiter.delayed_input_index; |
2815 | 0 | i++) { |
2816 | 0 | *(time_data + |
2817 | 0 | (p_state_enhaacplus_dec->peak_limiter.attack_time_samples - |
2818 | 0 | p_state_enhaacplus_dec->peak_limiter.delayed_input_index) * |
2819 | 0 | total_channels + |
2820 | 0 | total_channels * i + j) = |
2821 | 0 | ixheaac_round16( |
2822 | 0 | (WORD32)*(p_state_enhaacplus_dec->peak_limiter.delayed_input + |
2823 | 0 | total_channels * i + j)); |
2824 | 0 | } |
2825 | 0 | } |
2826 | |
|
2827 | 0 | if (p_obj_exhaacplus_dec->aac_config.dup_stereo_flag) { |
2828 | 0 | for (i = 0; |
2829 | 0 | i < (p_state_enhaacplus_dec->peak_limiter.attack_time_samples); |
2830 | 0 | i++) { |
2831 | 0 | time_data[2 * i + 1] = time_data[2 * i + 0]; |
2832 | 0 | } |
2833 | 0 | } |
2834 | 0 | } else { |
2835 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0; |
2836 | 0 | } |
2837 | |
|
2838 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
2839 | 0 | return IA_NO_ERROR; |
2840 | 0 | } |
2841 | | |
2842 | 286k | if (ch_idx1 == 0) { |
2843 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
2844 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2845 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2846 | 0 | } else { |
2847 | 0 | return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; |
2848 | 0 | } |
2849 | 0 | } |
2850 | 286k | if (total_channels > (WORD)p_obj_exhaacplus_dec->aac_config.ui_max_channels) { |
2851 | 129 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
2852 | 129 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2853 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2854 | 129 | } else { |
2855 | 129 | return IA_XHEAAC_DEC_CONFIG_NONFATAL_INVALID_MAX_CHANNEL; |
2856 | 129 | } |
2857 | 129 | } |
2858 | | |
2859 | 286k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD || |
2860 | 286k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) { |
2861 | 174k | if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag) |
2862 | 1.28k | p_state_enhaacplus_dec->frame_size = p_state_enhaacplus_dec->ui_in_bytes; |
2863 | 174k | } |
2864 | | |
2865 | 286k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) { |
2866 | 58.5k | if (p_obj_exhaacplus_dec->aac_config.ui_mp4_flag) |
2867 | 121 | p_state_enhaacplus_dec->frame_size = 1024; |
2868 | 58.5k | } |
2869 | | |
2870 | 286k | { |
2871 | 286k | ixheaacd_create_init_bit_buf(it_bit_buff, in_buffer, |
2872 | 286k | p_state_enhaacplus_dec->ui_in_bytes); |
2873 | 286k | it_bit_buff->xaac_jmp_buf = &(p_state_enhaacplus_dec->xaac_jmp_buf); |
2874 | | |
2875 | 286k | it_bit_buff->adts_header_present = |
2876 | 286k | p_state_enhaacplus_dec->s_adts_hdr_present; |
2877 | 286k | it_bit_buff->no_raw_data_blocks = |
2878 | 286k | (WORD8)p_state_enhaacplus_dec->b_n_raw_data_blk; |
2879 | 286k | it_bit_buff->protection_absent = p_state_enhaacplus_dec->protection_absent; |
2880 | | |
2881 | 286k | if (p_state_enhaacplus_dec->s_adts_hdr_present) { |
2882 | 46.4k | if (p_state_enhaacplus_dec->b_n_raw_data_blk == 0) { |
2883 | 44.2k | WORD32 error; |
2884 | | |
2885 | 44.2k | error = ixheaacd_readifadts(p_state_enhaacplus_dec, it_bit_buff, &adts); |
2886 | 44.2k | if (error) { |
2887 | 2.45k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2888 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2889 | 0 | if (adts.samp_freq_index > 11) { |
2890 | 0 | adts.samp_freq_index = 11; |
2891 | 0 | } |
2892 | 2.45k | } else { |
2893 | 2.45k | return error; |
2894 | 2.45k | } |
2895 | 2.45k | } |
2896 | | |
2897 | 41.8k | if ((WORD32)p_state_enhaacplus_dec->sampling_rate != |
2898 | 41.8k | (WORD32)((p_obj_exhaacplus_dec->aac_tables.pstr_huffmann_tables |
2899 | 41.8k | ->str_sample_rate_info[adts.samp_freq_index] |
2900 | 41.8k | .sampling_frequency))) { |
2901 | 27 | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
2902 | 27 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2903 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2904 | 27 | } else { |
2905 | 27 | return IA_XHEAAC_DEC_EXE_NONFATAL_CHANGED_ADTS_SF; |
2906 | 27 | } |
2907 | 27 | } |
2908 | 41.8k | } |
2909 | 46.4k | } |
2910 | | |
2911 | 283k | bytes_for_sync = (SIZE_T)it_bit_buff->ptr_read_next; |
2912 | | |
2913 | 283k | if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) { |
2914 | 243k | WORD32 result, audio_mux_len_bytes_last; |
2915 | 243k | WORD32 cnt_bits = it_bit_buff->cnt_bits; |
2916 | 243k | WORD32 sync = ixheaacd_read_bits_buf(it_bit_buff, 11); |
2917 | 243k | UWORD32 curr_samp_rate = 0; |
2918 | | |
2919 | 243k | if (p_state_enhaacplus_dec->latm_initialized) |
2920 | 236k | curr_samp_rate = |
2921 | 236k | p_state_enhaacplus_dec->latm_struct_element.layer_info[0][0] |
2922 | 236k | .asc.sampling_freq; |
2923 | | |
2924 | 189M | while (sync != 0x2b7) { |
2925 | 188M | sync = ((sync & 0x3ff) << 1) | ixheaacd_read_bits_buf(it_bit_buff, 1); |
2926 | 188M | if (it_bit_buff->cnt_bits < 13) { |
2927 | 2.39k | ixheaacd_read_bidirection(it_bit_buff, -11); |
2928 | 2.39k | p_state_enhaacplus_dec->i_bytes_consumed = |
2929 | 2.39k | (cnt_bits - it_bit_buff->cnt_bits) / 8; |
2930 | | |
2931 | 2.39k | if (p_state_enhaacplus_dec->i_bytes_consumed == 0) |
2932 | 75 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
2933 | 2.39k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2934 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2935 | 2.39k | } else { |
2936 | 2.39k | return (IA_XHEAAC_DEC_INIT_NONFATAL_HEADER_NOT_AT_START); |
2937 | 2.39k | } |
2938 | 2.39k | } |
2939 | 188M | } |
2940 | | |
2941 | 240k | it_bit_buff->audio_mux_align = it_bit_buff->cnt_bits - 13; |
2942 | | |
2943 | 240k | audio_mux_len_bytes_last = ixheaacd_read_bits_buf(it_bit_buff, 13); |
2944 | | |
2945 | 240k | audio_mux_length_bytes_last = audio_mux_len_bytes_last; |
2946 | | |
2947 | 240k | bytes_for_sync = (SIZE_T)it_bit_buff->ptr_read_next - bytes_for_sync; |
2948 | | |
2949 | 240k | if (it_bit_buff->cnt_bits < (audio_mux_len_bytes_last << 3)) { |
2950 | 1.29k | ixheaacd_read_bidirection(it_bit_buff, -(13 + 11)); |
2951 | 1.29k | p_state_enhaacplus_dec->i_bytes_consumed = (cnt_bits - it_bit_buff->cnt_bits) / 8; |
2952 | 1.29k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2953 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2954 | 1.29k | } else { |
2955 | 1.29k | return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES; |
2956 | 1.29k | } |
2957 | 239k | } else { |
2958 | 239k | ixheaacd_read_bidirection(it_bit_buff, -(13)); |
2959 | 239k | } |
2960 | | |
2961 | 239k | if (sync == 0x2b7) { |
2962 | 239k | result = ixheaacd_latm_audio_mux_element( |
2963 | 239k | it_bit_buff, &p_state_enhaacplus_dec->latm_struct_element, |
2964 | 239k | p_state_enhaacplus_dec, |
2965 | 239k | (ia_sampling_rate_info_struct *)&p_obj_exhaacplus_dec->aac_tables |
2966 | 239k | .pstr_huffmann_tables->str_sample_rate_info[0]); |
2967 | 239k | if (result < 0) { |
2968 | 535 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2969 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2970 | 535 | } else { |
2971 | 535 | return result; |
2972 | 535 | } |
2973 | 535 | } |
2974 | 238k | if (!p_state_enhaacplus_dec->latm_initialized) { |
2975 | 6.34k | p_state_enhaacplus_dec->sampling_rate = |
2976 | 6.34k | p_state_enhaacplus_dec->latm_struct_element.layer_info[0][0].asc.sampling_freq; |
2977 | 6.34k | p_state_enhaacplus_dec->latm_initialized = 1; |
2978 | 232k | } else { |
2979 | 232k | if (p_state_enhaacplus_dec->sampling_rate != curr_samp_rate) { |
2980 | 86 | p_state_enhaacplus_dec->i_bytes_consumed = 0; |
2981 | 86 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
2982 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
2983 | 86 | } else { |
2984 | 86 | return IA_XHEAAC_DEC_EXE_NONFATAL_CHANGED_ADTS_SF; |
2985 | 86 | } |
2986 | 86 | } |
2987 | 232k | } |
2988 | 238k | } |
2989 | 239k | } |
2990 | 283k | } |
2991 | | |
2992 | 279k | if (total_elements == 2 && total_channels == 2 && |
2993 | 279k | (p_state_enhaacplus_dec->p_config->ui_pce_found_in_hdr == 1 || |
2994 | 7.01k | p_state_enhaacplus_dec->p_config->ui_pce_found_in_hdr == 3)) { |
2995 | 4.01k | ixheaacd_fill_prog_config_slots(p_state_enhaacplus_dec); |
2996 | 4.01k | } |
2997 | | |
2998 | 279k | memset(element_used, 0, sizeof(WORD8) * MAX_BS_ELEMENT); |
2999 | | |
3000 | 279k | if (it_bit_buff->cnt_bits <= 0) { |
3001 | 7 | it_bit_buff->cnt_bits = -1; |
3002 | 7 | ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff); |
3003 | 7 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3004 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3005 | 7 | } else { |
3006 | 7 | return (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
3007 | 7 | } |
3008 | 7 | } |
3009 | | |
3010 | 279k | { it_bit_buff->initial_cnt_bits = it_bit_buff->cnt_bits; } |
3011 | | |
3012 | 279k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD) { |
3013 | 97.5k | if (p_state_enhaacplus_dec->s_adts_hdr_present) |
3014 | 0 | p_state_enhaacplus_dec->frame_size = adts.aac_frame_length; |
3015 | 97.5k | } |
3016 | | |
3017 | 279k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LC) { |
3018 | 57.8k | if (p_state_enhaacplus_dec->s_adts_hdr_present) |
3019 | 0 | p_state_enhaacplus_dec->frame_size = 1024; |
3020 | 57.8k | } |
3021 | | |
3022 | 285k | if (p_state_enhaacplus_dec->pstr_drc_dec) { |
3023 | 285k | p_state_enhaacplus_dec->pstr_drc_dec->num_drc_elements = 0; |
3024 | | |
3025 | 285k | p_state_enhaacplus_dec->pstr_drc_dec->state = 1; |
3026 | 285k | } |
3027 | 279k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3028 | 0 | if (total_elements > MAX_BS_ELEMENT) { |
3029 | 0 | total_elements = MAX_BS_ELEMENT; |
3030 | 0 | } |
3031 | 0 | } |
3032 | | |
3033 | 279k | WORD16 *intermediate_scr = (WORD16 *)(WORD8 *)p_state_enhaacplus_dec->aac_scratch_mem_v + |
3034 | 279k | (MAX_SCR_SIZE - SCR_INTER_SCR_SIZE - SCR_COUP_CH_OUT_SIZE); |
3035 | | |
3036 | 575k | for (ch_idx1 = 0; ch_idx1 < total_elements; ch_idx1++) { |
3037 | 305k | WORD32 skip_full_decode = 0; |
3038 | 305k | WORD32 ch_idx = ch_idx1; |
3039 | 305k | WORD32 channel = 0; |
3040 | 305k | WORD ch_fac, slot_ele; |
3041 | | |
3042 | 305k | if (p_state_enhaacplus_dec->audio_object_type < ER_OBJECT_START || |
3043 | 305k | (p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LD && |
3044 | 228k | p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_ELD && |
3045 | 228k | p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LC)) { |
3046 | 76.7k | jmp_buf local; |
3047 | | |
3048 | 76.7k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal == 1) { |
3049 | 0 | ret_val = setjmp(local); |
3050 | 0 | } |
3051 | 76.7k | if (ret_val == 0) { |
3052 | 76.7k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal == 1) { |
3053 | 0 | p_obj_exhaacplus_dec->p_state_aac->ptr_bit_stream->xaac_jmp_buf = &local; |
3054 | 0 | } |
3055 | 76.7k | error_code = ixheaacd_get_element_index_tag( |
3056 | 76.7k | p_obj_exhaacplus_dec, ch_idx1, &ch_idx, &channel, |
3057 | 76.7k | p_obj_exhaacplus_dec->aac_config.element_instance_order, total_elements, element_used, |
3058 | 76.7k | total_channels, p_state_enhaacplus_dec->pstr_drc_dec, |
3059 | 76.7k | &p_state_enhaacplus_dec->drc_dummy, mps_buffer, &p_state_enhaacplus_dec->mps_header, |
3060 | 76.7k | &p_state_enhaacplus_dec->ui_mps_out_bytes); |
3061 | 76.7k | } |
3062 | | |
3063 | 76.7k | if (error_code || ret_val) { |
3064 | 3.50k | ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff); |
3065 | 3.50k | if (it_bit_buff->cnt_bits < 0) { |
3066 | 10 | p_state_enhaacplus_dec->ui_out_bytes = 0; |
3067 | 10 | p_state_enhaacplus_dec->ui_mps_out_bytes = 0; |
3068 | 10 | p_state_enhaacplus_dec->b_n_raw_data_blk = 0; |
3069 | 10 | } |
3070 | 3.50k | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
3071 | 3.50k | p_state_enhaacplus_dec->b_n_raw_data_blk = 0; |
3072 | 3.50k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3073 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3074 | 3.50k | } else { |
3075 | 3.50k | return error_code; |
3076 | 3.50k | } |
3077 | 3.50k | } |
3078 | 73.1k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == ID_CPE) |
3079 | 1.69k | { |
3080 | 1.69k | if (channel != 2) |
3081 | 0 | { |
3082 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) |
3083 | 0 | { |
3084 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3085 | 0 | channel = 2; |
3086 | 0 | } |
3087 | 0 | else |
3088 | 0 | { |
3089 | 0 | return IA_FATAL_ERROR; |
3090 | 0 | } |
3091 | 0 | } |
3092 | 1.69k | } |
3093 | 71.5k | else |
3094 | 71.5k | { |
3095 | 71.5k | if (channel != 1) |
3096 | 0 | { |
3097 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) |
3098 | 0 | { |
3099 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3100 | 0 | channel = 1; |
3101 | 0 | } |
3102 | 0 | else |
3103 | 0 | { |
3104 | 0 | return IA_FATAL_ERROR; |
3105 | 0 | } |
3106 | 0 | } |
3107 | 71.5k | } |
3108 | 228k | } else { |
3109 | 228k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == ID_SCE) |
3110 | 168k | channel = 1; |
3111 | 60.3k | else |
3112 | 60.3k | channel = 2; |
3113 | 228k | } |
3114 | | |
3115 | 301k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && (error_code || ret_val)) { |
3116 | 0 | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 0 || |
3117 | 0 | p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 3) { |
3118 | 0 | if (channel > 1) { |
3119 | 0 | channel = 1; |
3120 | 0 | } |
3121 | 0 | } |
3122 | 0 | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 1) { |
3123 | 0 | if (channel > 2) { |
3124 | 0 | channel = 2; |
3125 | 0 | } |
3126 | 0 | } |
3127 | 0 | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 2) { |
3128 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) { |
3129 | 0 | if (!(p_obj_exhaacplus_dec->aac_config.element_instance_order[ch_idx] != |
3130 | 0 | p_obj_exhaacplus_dec->aac_config.ui_coupling_channel)) { |
3131 | 0 | if (channel > 1) { |
3132 | 0 | channel = 1; |
3133 | 0 | } |
3134 | 0 | } |
3135 | 0 | } |
3136 | 0 | } |
3137 | 0 | if (ps_enable == 1) { |
3138 | 0 | if (channel > 2) { |
3139 | 0 | channel = 2; |
3140 | 0 | } |
3141 | 0 | } |
3142 | 0 | } |
3143 | | |
3144 | 301k | ch_fac = total_channels; |
3145 | 301k | slot_ele = p_obj_exhaacplus_dec->aac_config.slot_element[ch_idx]; |
3146 | 301k | actual_out_buffer = time_data; |
3147 | 301k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] == 2) { |
3148 | 829 | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info = |
3149 | 829 | &p_state_enhaacplus_dec->ind_cc_info; |
3150 | 829 | if (p_obj_exhaacplus_dec->aac_config.element_instance_order[ch_idx] != |
3151 | 829 | p_obj_exhaacplus_dec->aac_config.ui_coupling_channel) { |
3152 | 303 | skip_full_decode = 1; |
3153 | 303 | ixheaacd_set_aac_persistent_buffers( |
3154 | 303 | p_state_enhaacplus_dec->pers_mem_ptr, channel); |
3155 | | |
3156 | 303 | { |
3157 | 303 | struct ia_aac_persistent_struct *aac_persistent_mem = |
3158 | 303 | (struct ia_aac_persistent_struct *) |
3159 | 303 | p_state_enhaacplus_dec->pers_mem_ptr; |
3160 | 303 | aac_persistent_mem->str_aac_decoder.pstr_aac_tables = |
3161 | 303 | &p_obj_exhaacplus_dec->aac_tables; |
3162 | 303 | aac_persistent_mem->str_aac_decoder.pstr_common_tables = |
3163 | 303 | p_obj_exhaacplus_dec->common_tables; |
3164 | 303 | } |
3165 | | |
3166 | 303 | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] = 0; |
3167 | | |
3168 | 303 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0; |
3169 | | |
3170 | 303 | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx] = |
3171 | 303 | ixheaacd_aac_decoder_init( |
3172 | 303 | p_state_enhaacplus_dec, |
3173 | | |
3174 | 303 | p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx], |
3175 | | |
3176 | 303 | channel, p_state_enhaacplus_dec->pers_mem_ptr, |
3177 | 303 | p_state_enhaacplus_dec->frame_length |
3178 | | |
3179 | 303 | ); |
3180 | 303 | if (!p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]) { |
3181 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = 1; |
3182 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3183 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3184 | 0 | } else { |
3185 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL; |
3186 | 0 | } |
3187 | 0 | } |
3188 | 303 | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info = |
3189 | 303 | (WORD8 *)p_state_enhaacplus_dec->aac_scratch_mem_v + (P_IND_CH_INFO_OFFSET); |
3190 | 303 | } |
3191 | 829 | if (p_obj_exhaacplus_dec->aac_config.element_type[1] < 3 && |
3192 | 829 | p_obj_exhaacplus_dec->aac_config.element_type[1] > 0 && |
3193 | 829 | p_obj_exhaacplus_dec->aac_config.ui_max_channels > 2) { |
3194 | 115 | actual_out_buffer = |
3195 | 115 | (WORD16 *)(VOID *)p_state_enhaacplus_dec->coup_ch_output; |
3196 | 115 | } |
3197 | 829 | ch_fac = 1; |
3198 | 829 | slot_ele = 0; |
3199 | 829 | } |
3200 | | |
3201 | 301k | type = -1; |
3202 | 301k | p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements = 0; |
3203 | | |
3204 | 301k | { |
3205 | 301k | WORD element_index_order1[MAX_BS_ELEMENT]; |
3206 | 301k | ia_aac_dec_scratch_struct aac_scratch_struct; |
3207 | 301k | memset(&aac_scratch_struct, 0, sizeof(aac_scratch_struct)); |
3208 | | |
3209 | 301k | ixheaacd_allocate_aac_scr( |
3210 | 301k | &aac_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v, |
3211 | 301k | time_data, channel, p_obj_exhaacplus_dec->aac_config.ui_max_channels, |
3212 | 301k | p_state_enhaacplus_dec->audio_object_type); |
3213 | | |
3214 | 301k | if (p_state_enhaacplus_dec->ch_config == 2 && channel == 1) { |
3215 | 97 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3216 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3217 | 97 | } else { |
3218 | 97 | return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; |
3219 | 97 | } |
3220 | 97 | } |
3221 | | |
3222 | 301k | error_code = ixheaacd_aacdec_decodeframe( |
3223 | 301k | p_obj_exhaacplus_dec, &aac_scratch_struct, actual_out_buffer, |
3224 | 301k | p_obj_exhaacplus_dec->aac_config.frame_status, &type, &ch_idx, 0, channel, |
3225 | 301k | element_index_order1, skip_full_decode, ch_fac, slot_ele, |
3226 | 301k | p_obj_exhaacplus_dec->aac_config.ui_max_channels, total_channels, |
3227 | 301k | p_obj_exhaacplus_dec->p_state_aac->frame_length, |
3228 | 301k | p_obj_exhaacplus_dec->p_state_aac->frame_size, p_state_enhaacplus_dec->pstr_drc_dec, |
3229 | 301k | p_state_enhaacplus_dec->audio_object_type, p_state_enhaacplus_dec->ch_config, |
3230 | 301k | p_state_enhaacplus_dec->eld_specific_config, p_state_enhaacplus_dec->s_adts_hdr_present, |
3231 | 301k | &p_state_enhaacplus_dec->drc_dummy, p_state_enhaacplus_dec->ldmps_present, |
3232 | 301k | &p_state_enhaacplus_dec->slot_pos, mps_buffer, &p_state_enhaacplus_dec->mps_header, |
3233 | 301k | &p_state_enhaacplus_dec->ui_mps_out_bytes, 0, |
3234 | 301k | p_obj_exhaacplus_dec->aac_config.first_frame); |
3235 | | |
3236 | 301k | p_state_enhaacplus_dec->slot_pos -= (channel - 1); |
3237 | 301k | p_state_enhaacplus_dec->sbr_present = 0; |
3238 | | |
3239 | 301k | if (p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ && |
3240 | 301k | p_state_enhaacplus_dec->frame_counter == 0) { |
3241 | 11.4k | ixheaacd_peak_limiter_init( |
3242 | 11.4k | &p_state_enhaacplus_dec->peak_limiter, total_channels, |
3243 | 11.4k | p_obj_exhaacplus_dec->p_state_aac->p_config->ui_samp_freq, |
3244 | 11.4k | &p_state_enhaacplus_dec->peak_limiter.buffer[0], |
3245 | 11.4k | &p_obj_exhaacplus_dec->p_state_aac->delay_in_samples); |
3246 | 11.4k | p_obj_exhaacplus_dec->p_state_aac->peak_lim_init = 1; |
3247 | 11.4k | } |
3248 | | |
3249 | 301k | if (p_state_enhaacplus_dec->audio_object_type < ER_OBJECT_START || |
3250 | 301k | (p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LD && |
3251 | 227k | p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_ELD && |
3252 | 227k | p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LC)) { |
3253 | 72.7k | if ((error_code == 0) && ((ch_idx1 + 1) == total_elements) && |
3254 | 72.7k | (type != ID_END)) { |
3255 | 1.06k | { |
3256 | 1.06k | p_state_enhaacplus_dec->i_bytes_consumed = (WORD32)( |
3257 | 1.06k | it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base); |
3258 | 1.06k | p_state_enhaacplus_dec->b_n_raw_data_blk = 0; |
3259 | 1.06k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3260 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3261 | 1.06k | } else { |
3262 | 1.06k | return IA_XHEAAC_DEC_EXE_NONFATAL_ELE_INSTANCE_TAG_NOT_FOUND; |
3263 | 1.06k | } |
3264 | 1.06k | } |
3265 | 1.06k | } |
3266 | 72.7k | } |
3267 | | |
3268 | 300k | num_ch = p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->channels; |
3269 | 300k | if (skip_full_decode == 0) { |
3270 | 298k | if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD || |
3271 | 298k | p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD) |
3272 | 170k | frame_size = p_state_enhaacplus_dec->frame_length; |
3273 | 128k | else { |
3274 | 128k | frame_size = p_state_enhaacplus_dec->frame_length; |
3275 | 128k | } |
3276 | | |
3277 | 298k | sample_rate_dec = |
3278 | 298k | p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->sampling_rate; |
3279 | 298k | } |
3280 | 300k | } |
3281 | | |
3282 | 300k | if (skip_full_decode == 1) { |
3283 | 298 | p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements = 0; |
3284 | 298 | } |
3285 | | |
3286 | 300k | if (p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements != 0) { |
3287 | 60.0k | p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 1; |
3288 | 60.0k | } |
3289 | | |
3290 | 300k | if (error_code) { |
3291 | 4.22k | if (p_state_enhaacplus_dec->ui_input_over) { |
3292 | 0 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3293 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3294 | 0 | } else { |
3295 | 0 | return IA_XHEAAC_DEC_INIT_FATAL_EO_INPUT_REACHED; |
3296 | 0 | } |
3297 | 0 | } |
3298 | 4.22k | ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff); |
3299 | 4.22k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes += |
3300 | 4.22k | p_state_enhaacplus_dec->num_of_out_samples * num_ch * sizeof(WORD16); |
3301 | 4.22k | if (error_code) { |
3302 | 4.22k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3303 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3304 | 4.22k | } else { |
3305 | 4.22k | return error_code; |
3306 | 4.22k | } |
3307 | 4.22k | } |
3308 | 4.22k | } |
3309 | | |
3310 | 296k | error_code = IA_NO_ERROR; |
3311 | | |
3312 | 296k | if (p_obj_exhaacplus_dec->aac_config.ui_auto_sbr_upsample == 0) { |
3313 | 0 | if (p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements == 0 && |
3314 | 0 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { |
3315 | 0 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0; |
3316 | 0 | error_code = IA_XHEAAC_DEC_EXE_NONFATAL_SBR_TURNED_OFF; |
3317 | 0 | } |
3318 | 0 | } |
3319 | 296k | if ((!p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) && |
3320 | 296k | p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0].no_elements) { |
3321 | 33 | WORD32 harmonic_sbr_flag = 0; |
3322 | 33 | error_code = IA_XHEAAC_DEC_EXE_NONFATAL_SBR_TURNED_ON; |
3323 | 33 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr( |
3324 | 33 | sample_rate_dec, frame_size, |
3325 | 33 | (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag, |
3326 | 33 | p_state_enhaacplus_dec->sbr_persistent_mem_v, |
3327 | 33 | p_state_enhaacplus_dec->ptr_overlap_buf, ps_enable ? 2 : channel, |
3328 | 33 | ps_enable, 1, frame_size * 2, &harmonic_sbr_flag, NULL, |
3329 | 33 | p_state_enhaacplus_dec->str_sbr_config, |
3330 | 33 | p_state_enhaacplus_dec->audio_object_type, |
3331 | 33 | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
3332 | 33 | .ldmps_present_flag, |
3333 | 33 | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present); |
3334 | 33 | if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { |
3335 | 5 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf = |
3336 | 5 | &(p_state_enhaacplus_dec->xaac_jmp_buf); |
3337 | 5 | } |
3338 | 33 | } |
3339 | | |
3340 | 296k | { |
3341 | 296k | if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] && |
3342 | 296k | p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) { |
3343 | 59.8k | ia_sbr_scr_struct sbr_scratch_struct; |
3344 | 59.8k | ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v, |
3345 | 59.8k | time_data, total_channels, |
3346 | 59.8k | p_obj_exhaacplus_dec->p_state_aac->qshift_adj, |
3347 | 59.8k | p_state_enhaacplus_dec->slot_pos, channel); |
3348 | | |
3349 | 59.8k | p_state_enhaacplus_dec->sbr_present = 1; |
3350 | 59.8k | p_state_enhaacplus_dec->peak_lim_init = 0; |
3351 | | |
3352 | 59.8k | if (p_obj_exhaacplus_dec->aac_config.ui_enh_sbr) |
3353 | 59.8k | { |
3354 | 59.8k | WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type; |
3355 | | |
3356 | 59.8k | if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) { |
3357 | 24.9k | WORD32 i = 0; |
3358 | 24.9k | ia_dec_data_struct* pstr_dec_data = |
3359 | 24.9k | (ia_dec_data_struct*)p_state_enhaacplus_dec->pstr_dec_data; |
3360 | 24.9k | if (ch_fac == 1) { |
3361 | 2.00M | for (; i < 1024; i++) { |
3362 | 2.00M | pstr_dec_data->str_usac_data.time_sample_vector[0][i] = |
3363 | 2.00M | (FLOAT32)time_data[i]; |
3364 | 2.00M | } |
3365 | 1.95k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] = |
3366 | 1.95k | &pstr_dec_data->str_usac_data.time_sample_vector[0][0]; |
3367 | | |
3368 | 1.95k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] = |
3369 | 1.95k | &pstr_dec_data->str_usac_data.time_sample_vector[1][0]; |
3370 | 23.0k | } else if (ch_fac == 2) { |
3371 | 23.3M | for (; i < 1024; i++) { |
3372 | 23.3M | pstr_dec_data->str_usac_data.time_sample_vector[0][i] = |
3373 | 23.3M | (FLOAT32)time_data[2 * i + 0]; |
3374 | 23.3M | pstr_dec_data->str_usac_data.time_sample_vector[1][i] = |
3375 | 23.3M | (FLOAT32)time_data[2 * i + 1]; |
3376 | 23.3M | } |
3377 | 22.8k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] = |
3378 | 22.8k | &pstr_dec_data->str_usac_data.time_sample_vector[0][0]; |
3379 | | |
3380 | 22.8k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] = |
3381 | 22.8k | &pstr_dec_data->str_usac_data.time_sample_vector[1][0]; |
3382 | 22.8k | } else if (ch_fac > 2) { |
3383 | 189 | if (channel == 1) { |
3384 | 148k | for (; i < 1024; i++) { |
3385 | 148k | pstr_dec_data->str_usac_data.time_sample_vector[0][i] = |
3386 | 148k | (FLOAT32)(time_data + slot_ele)[i* ch_fac]; |
3387 | 148k | } |
3388 | 145 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] = |
3389 | 145 | &pstr_dec_data->str_usac_data.time_sample_vector[0][0]; |
3390 | 145 | } else if (channel == 2) { |
3391 | 45.1k | for (; i < 1024; i++) { |
3392 | 45.0k | pstr_dec_data->str_usac_data.time_sample_vector[0][i] = |
3393 | 45.0k | (FLOAT32)(time_data + slot_ele)[ch_fac * i + 0]; |
3394 | 45.0k | pstr_dec_data->str_usac_data.time_sample_vector[1][i] = |
3395 | 45.0k | (FLOAT32)(time_data + slot_ele)[ch_fac * i + 1]; |
3396 | 45.0k | } |
3397 | 44 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[0] = |
3398 | 44 | &pstr_dec_data->str_usac_data.time_sample_vector[0][0]; |
3399 | | |
3400 | 44 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->time_sample_buf[1] = |
3401 | 44 | &pstr_dec_data->str_usac_data.time_sample_vector[1][0]; |
3402 | 44 | } |
3403 | 189 | } |
3404 | 24.9k | } |
3405 | 59.8k | } |
3406 | 59.8k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->esbr_hq = |
3407 | 59.8k | p_obj_exhaacplus_dec->aac_config.ui_hq_esbr; |
3408 | 59.8k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr = |
3409 | 59.8k | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr; |
3410 | 59.8k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->enh_sbr_ps = |
3411 | 59.8k | p_obj_exhaacplus_dec->aac_config.ui_enh_sbr_ps; |
3412 | | |
3413 | 59.8k | if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { |
3414 | 59.8k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf = |
3415 | 59.8k | &(p_state_enhaacplus_dec->xaac_jmp_buf); |
3416 | 59.8k | } |
3417 | | |
3418 | 59.8k | if (ixheaacd_applysbr(p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx], |
3419 | 59.8k | &p_state_enhaacplus_dec->pstr_stream_sbr[ch_idx][0], |
3420 | 59.8k | actual_out_buffer, &num_ch, |
3421 | 59.8k | p_obj_exhaacplus_dec->aac_config.frame_status, |
3422 | 59.8k | p_obj_exhaacplus_dec->aac_config.down_sample_flag, |
3423 | 59.8k | esbr_mono_downmix, &sbr_scratch_struct, ps_enable, ch_fac, slot_ele, |
3424 | 59.8k | NULL, &p_state_enhaacplus_dec->str_drc_dec_info, |
3425 | 59.8k | p_state_enhaacplus_dec->eld_specific_config.ld_sbr_flag_present, |
3426 | 59.8k | p_state_enhaacplus_dec->audio_object_type, 0, |
3427 | 59.8k | p_state_enhaacplus_dec->ldmps_present, frame_size, |
3428 | 59.8k | p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present, |
3429 | 59.8k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal, |
3430 | 59.8k | p_obj_exhaacplus_dec->aac_config.first_frame) != SBRDEC_OK) { |
3431 | 244 | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = 0; |
3432 | 244 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3433 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3434 | 244 | } else { |
3435 | 244 | return -1; |
3436 | 244 | } |
3437 | 59.6k | } else { |
3438 | 59.6k | if (!p_obj_exhaacplus_dec->aac_config.down_sample_flag) { |
3439 | 38.2k | frame_size = (WORD16)(frame_size * 2); |
3440 | 38.2k | sample_rate_dec *= 2; |
3441 | 38.2k | } |
3442 | 59.6k | if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
3443 | 59.6k | .ldmps_present_flag == 1) { |
3444 | 3.06k | ixheaacd_mps_payload( |
3445 | 3.06k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx], |
3446 | 3.06k | p_obj_exhaacplus_dec); |
3447 | 3.06k | } |
3448 | 59.6k | } |
3449 | | |
3450 | 59.6k | if (p_obj_exhaacplus_dec->aac_config.ui_enh_sbr) |
3451 | 58.9k | { |
3452 | 58.9k | WORD32 audio_object_type = p_state_enhaacplus_dec->audio_object_type; |
3453 | | |
3454 | 58.9k | if (audio_object_type != AOT_ER_AAC_ELD && audio_object_type != AOT_ER_AAC_LD) { |
3455 | 24.8k | WORD32 out_bytes = 0; |
3456 | 24.8k | ia_dec_data_struct *pstr_dec_data = |
3457 | 24.8k | (ia_dec_data_struct *)p_state_enhaacplus_dec->pstr_dec_data; |
3458 | 24.8k | if (ch_fac <= 2) { |
3459 | 24.7k | ixheaacd_samples_sat((WORD8*)time_data, 2048, 16, |
3460 | 24.7k | pstr_dec_data->str_usac_data.time_sample_vector, |
3461 | 24.7k | &out_bytes, ch_fac); |
3462 | 24.7k | } else { |
3463 | 186 | ixheaacd_samples_sat_mc((WORD8*)(time_data + slot_ele), 2048, |
3464 | 186 | pstr_dec_data->str_usac_data.time_sample_vector, |
3465 | 186 | &out_bytes, channel, ch_fac); |
3466 | 186 | } |
3467 | 24.8k | } |
3468 | 58.9k | } |
3469 | 59.6k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present = |
3470 | 59.6k | 0; |
3471 | 59.6k | if (p_state_enhaacplus_dec->ui_mps_out_bytes > 0) { |
3472 | 157 | p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present = 1; |
3473 | 157 | } |
3474 | 236k | } else { |
3475 | 236k | p_state_enhaacplus_dec->mps_dec_handle.ldmps_config.no_ldsbr_present = 1; |
3476 | 236k | } |
3477 | 296k | } |
3478 | | |
3479 | 296k | if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
3480 | 296k | .ldmps_present_flag == 1 && |
3481 | 296k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] && |
3482 | 296k | p_state_enhaacplus_dec->mps_dec_handle.mps_init_done == 1) { |
3483 | 3.13k | if (p_state_enhaacplus_dec->ec_enable) { |
3484 | 0 | if (!p_obj_exhaacplus_dec->aac_config.first_frame) { |
3485 | 0 | error_code = ixheaacd_ld_mps_apply(p_obj_exhaacplus_dec, actual_out_buffer); |
3486 | 0 | if (error_code) p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3487 | 0 | } |
3488 | 3.13k | } else { |
3489 | 3.13k | error_code = ixheaacd_ld_mps_apply(p_obj_exhaacplus_dec, actual_out_buffer); |
3490 | | |
3491 | 3.13k | if (error_code) |
3492 | 89 | return error_code; |
3493 | 3.13k | } |
3494 | 3.13k | } |
3495 | 295k | if (sample_rate < sample_rate_dec) { |
3496 | 275k | sample_rate = sample_rate_dec; |
3497 | 275k | } |
3498 | | |
3499 | 295k | if (p_state_enhaacplus_dec->sbr_present || |
3500 | 295k | p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] == LD_OBJ) { |
3501 | 123k | num_of_out_samples = frame_size; |
3502 | | |
3503 | 172k | } else { |
3504 | 172k | num_of_out_samples = |
3505 | 172k | frame_size - |
3506 | 172k | MIN((WORD16)p_obj_exhaacplus_dec->p_state_aac->delay_in_samples, frame_size); |
3507 | 172k | } |
3508 | | |
3509 | 295k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && |
3510 | 295k | p_obj_exhaacplus_dec->aac_config.first_frame && |
3511 | 295k | (p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_ER_AAC_ELD || |
3512 | 0 | p_obj_exhaacplus_dec->p_state_aac->audio_object_type == AOT_ER_AAC_LD)) { |
3513 | 0 | num_of_out_samples = frame_size; |
3514 | 0 | } |
3515 | | |
3516 | 295k | p_obj_exhaacplus_dec->aac_config.ui_samp_freq = sample_rate; |
3517 | | |
3518 | 295k | p_state_enhaacplus_dec->num_channel_last = num_ch; |
3519 | 295k | p_state_enhaacplus_dec->num_of_out_samples = num_of_out_samples; |
3520 | | |
3521 | 295k | if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config |
3522 | 295k | .ldmps_present_flag == 1 && |
3523 | 295k | p_state_enhaacplus_dec->mps_dec_handle.mps_init_done == 1 && |
3524 | 295k | p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { |
3525 | 3.04k | if (p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.output_buffer) { |
3526 | 3.04k | ixheaacd_samples_sat((WORD8 *)actual_out_buffer, num_of_out_samples, |
3527 | 3.04k | p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz, |
3528 | 3.04k | p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.output_buffer, |
3529 | 3.04k | &mps_out_samples, 2); |
3530 | 3.04k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = mps_out_samples; |
3531 | 3.04k | } |
3532 | 3.04k | num_ch = p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle.out_ch_count; |
3533 | 3.04k | if (p_state_enhaacplus_dec->ec_enable) { |
3534 | 0 | if (p_obj_exhaacplus_dec->aac_config.first_frame) { |
3535 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = |
3536 | 0 | p_state_enhaacplus_dec->num_of_out_samples * num_ch * sizeof(WORD16); |
3537 | 0 | } |
3538 | 0 | } |
3539 | 292k | } else { |
3540 | 292k | if (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx] != 2) { |
3541 | 290k | if (p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1 && |
3542 | 290k | channel == 1 && total_elements == 1 && num_ch == 1) { |
3543 | 6.76k | num_ch = 2; |
3544 | 6.76k | p_obj_exhaacplus_dec->aac_config.dup_stereo_flag = 1; |
3545 | | |
3546 | 283k | } else { |
3547 | 283k | p_obj_exhaacplus_dec->aac_config.dup_stereo_flag = 0; |
3548 | 283k | } |
3549 | | |
3550 | 290k | p_obj_exhaacplus_dec->aac_config.ui_n_channels = 2; |
3551 | | |
3552 | 290k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes += |
3553 | 290k | p_state_enhaacplus_dec->num_of_out_samples * num_ch * sizeof(WORD16); |
3554 | | |
3555 | 290k | } else { |
3556 | 2.80k | channel_coupling_flag = 1; |
3557 | 2.80k | } |
3558 | 292k | } |
3559 | | |
3560 | 295k | if (p_state_enhaacplus_dec->sbr_present && total_channels > 2) { |
3561 | 419 | for (WORD32 j = 0; j < channel; j++) { |
3562 | 385k | for (WORD32 i = 0; i < frame_size; i++) { |
3563 | 385k | intermediate_scr[total_channels * i + j + |
3564 | 385k | p_state_enhaacplus_dec->slot_pos] = |
3565 | 385k | actual_out_buffer[total_channels * i + j + |
3566 | 385k | p_state_enhaacplus_dec->slot_pos]; |
3567 | 385k | } |
3568 | 231 | } |
3569 | 188 | } |
3570 | 295k | } |
3571 | | |
3572 | 270k | if (p_state_enhaacplus_dec->sbr_present && total_channels > 2) { |
3573 | 62 | memcpy(time_data, intermediate_scr, |
3574 | 62 | sizeof(WORD16) * frame_size * total_channels); |
3575 | 62 | } |
3576 | | |
3577 | 270k | { |
3578 | 270k | ia_adts_crc_info_struct *ptr_adts_crc_info = |
3579 | 270k | p_state_enhaacplus_dec->ptr_bit_stream->pstr_adts_crc_info; |
3580 | 270k | if (ptr_adts_crc_info->crc_active == 1) { |
3581 | 1 | if ((error_code = ixheaacd_adts_crc_check_crc(ptr_adts_crc_info))) { |
3582 | 1 | if (error_code) { |
3583 | 1 | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3584 | 0 | p_obj_exhaacplus_dec->aac_config.frame_status = 0; |
3585 | 1 | } else { |
3586 | 1 | return error_code; |
3587 | 1 | } |
3588 | 1 | } |
3589 | 1 | } |
3590 | 1 | } |
3591 | 270k | } |
3592 | | |
3593 | 270k | p_obj_exhaacplus_dec->aac_config.ui_n_channels = total_channels; |
3594 | | |
3595 | 270k | p_state_enhaacplus_dec->frame_counter++; |
3596 | | |
3597 | 270k | WORD32 i, j; |
3598 | | |
3599 | 270k | if (channel_coupling_flag) { |
3600 | 514 | error_code = ixheaacd_dec_ind_coupling(p_obj_exhaacplus_dec, |
3601 | 514 | p_state_enhaacplus_dec->coup_ch_output, |
3602 | 514 | num_of_out_samples, total_channels, time_data); |
3603 | 514 | if (error_code) |
3604 | 26 | return error_code; |
3605 | 514 | } |
3606 | | |
3607 | 644k | for (i = 0; i < total_channels; i++) { |
3608 | 373k | if (p_obj_exhaacplus_dec->p_state_aac->qshift_adj[i + 1] == 0) |
3609 | 327k | p_obj_exhaacplus_dec->p_state_aac->qshift_adj[i + 1] = |
3610 | 327k | p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0]; |
3611 | 373k | } |
3612 | | |
3613 | 270k | if (p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1 && |
3614 | 270k | total_elements == 1 && num_ch == 2 && |
3615 | 270k | p_obj_exhaacplus_dec->aac_config.dup_stereo_flag == 1) { |
3616 | 6.76k | WORD i; |
3617 | | |
3618 | 6.76k | if (!p_state_enhaacplus_dec->sbr_present && |
3619 | 6.76k | p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ) { |
3620 | 341k | for (i = 0; i < frame_size; i++) { |
3621 | 340k | *((WORD32 *)actual_out_buffer + 2 * i + 1) = |
3622 | 340k | *((WORD32 *)actual_out_buffer + 2 * i); |
3623 | 340k | } |
3624 | 6.42k | } else { |
3625 | 13.1M | for (i = 0; i < frame_size; i++) { |
3626 | 13.0M | *(actual_out_buffer + 2 * i + 1) = *(actual_out_buffer + 2 * i); |
3627 | 13.0M | } |
3628 | 6.42k | } |
3629 | 6.76k | } |
3630 | | |
3631 | 270k | if (!p_state_enhaacplus_dec->sbr_present && |
3632 | 270k | p_obj_exhaacplus_dec->p_state_aac->peak_lim_init == 1 && |
3633 | 270k | p_obj_exhaacplus_dec->p_state_aac->qshift_adj[0] != LD_OBJ) { |
3634 | 124k | if (!p_obj_exhaacplus_dec->aac_config.peak_limiter_off) { |
3635 | 124k | ixheaacd_peak_limiter_process( |
3636 | 124k | &p_state_enhaacplus_dec->peak_limiter, time_data, frame_size, |
3637 | 124k | p_obj_exhaacplus_dec->p_state_aac->qshift_adj); |
3638 | 124k | } else { |
3639 | 0 | ixheaacd_scale_adjust(time_data, frame_size, |
3640 | 0 | p_obj_exhaacplus_dec->p_state_aac->qshift_adj, |
3641 | 0 | total_channels); |
3642 | 0 | } |
3643 | | |
3644 | 211M | for (i = 0; i < frame_size * 2; i++) { |
3645 | 469M | for (j = 0; j < total_channels; j++) { |
3646 | 258M | *((WORD16 *)time_data + total_channels * i + j) = |
3647 | 258M | ixheaac_round16(*((WORD32 *)time_data + total_channels * i + j)); |
3648 | 258M | } |
3649 | 211M | } |
3650 | | |
3651 | 124k | memmove( |
3652 | 124k | time_data, |
3653 | 124k | (time_data + |
3654 | 124k | total_channels * p_obj_exhaacplus_dec->p_state_aac->delay_in_samples), |
3655 | 124k | sizeof(WORD16) * num_of_out_samples * total_channels); |
3656 | | |
3657 | 124k | p_obj_exhaacplus_dec->p_state_aac->delay_in_samples = |
3658 | 124k | p_obj_exhaacplus_dec->p_state_aac->delay_in_samples - |
3659 | 124k | MIN(p_obj_exhaacplus_dec->p_state_aac->delay_in_samples, (UWORD16)frame_size); |
3660 | 124k | } |
3661 | 270k | if (p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present == 1) { |
3662 | 15.8k | ia_heaac_mps_state_struct *pstr_mps_state = |
3663 | 15.8k | &p_state_enhaacplus_dec->heaac_mps_handle; |
3664 | 15.8k | if (p_state_enhaacplus_dec->sbr_present == 0) { |
3665 | 15.4k | p_state_enhaacplus_dec->heaac_mps_handle.mps_decode = 1; |
3666 | 15.4k | } else { |
3667 | 404 | p_state_enhaacplus_dec->heaac_mps_handle.mps_with_sbr = 1; |
3668 | 404 | } |
3669 | 15.8k | if (!p_obj_exhaacplus_dec->aac_config.ui_enh_sbr) |
3670 | 0 | { |
3671 | 0 | p_state_enhaacplus_dec->heaac_mps_handle.mps_decode = 1; |
3672 | 0 | } |
3673 | 15.8k | if (p_state_enhaacplus_dec->heaac_mps_handle.mps_init_done == 1) { |
3674 | 15.7k | p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.frame_ok = |
3675 | 15.7k | p_obj_exhaacplus_dec->aac_config.frame_status; |
3676 | 15.7k | p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.ec_flag = |
3677 | 15.7k | p_obj_exhaacplus_dec->aac_config.ui_err_conceal; |
3678 | | |
3679 | 15.7k | error_code = ixheaacd_heaac_mps_apply(p_obj_exhaacplus_dec, actual_out_buffer, mps_buffer, |
3680 | 15.7k | p_state_enhaacplus_dec->ui_mps_out_bytes); |
3681 | | |
3682 | 15.7k | if (error_code != IA_NO_ERROR) { |
3683 | 937 | return error_code; |
3684 | 937 | } |
3685 | | |
3686 | 14.8k | p_state_enhaacplus_dec->heaac_mps_handle.mps_decode = 1; |
3687 | 14.8k | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = |
3688 | 14.8k | (pstr_mps_state->num_output_channels_at * |
3689 | 14.8k | pstr_mps_state->frame_length * |
3690 | 14.8k | (p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz >> 3)); |
3691 | 14.8k | p_obj_exhaacplus_dec->p_state_aac->heaac_mps_handle.first_frame = 0; |
3692 | 14.8k | } |
3693 | 15.8k | } |
3694 | 269k | if ((total_channels > 2) && (1 == p_obj_exhaacplus_dec->aac_config.downmix)) { |
3695 | 0 | ixheaacd_dec_downmix_to_stereo(p_obj_exhaacplus_dec, num_of_out_samples, |
3696 | 0 | total_elements, time_data, total_channels); |
3697 | |
|
3698 | 0 | total_channels = 2; |
3699 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = |
3700 | 0 | p_state_enhaacplus_dec->num_of_out_samples * 2 * sizeof(WORD16); |
3701 | 0 | } |
3702 | | |
3703 | 269k | if (p_obj_exhaacplus_dec->aac_config.flag_downmix && total_channels == 2) { |
3704 | 0 | WORD32 out_ch = 1; |
3705 | 0 | WORD i; |
3706 | 0 | if (p_obj_exhaacplus_dec->aac_config.flag_to_stereo == 1) { |
3707 | 0 | out_ch = 2; |
3708 | 0 | } |
3709 | |
|
3710 | 0 | p_obj_exhaacplus_dec->aac_config.ui_n_channels = out_ch; |
3711 | 0 | p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = |
3712 | 0 | p_state_enhaacplus_dec->num_of_out_samples * out_ch * sizeof(WORD16); |
3713 | |
|
3714 | 0 | for (i = 0; i < num_of_out_samples; i++) { |
3715 | 0 | WORD16 temp; |
3716 | |
|
3717 | 0 | temp = (time_data[2 * i + 0] >> 1) + (time_data[2 * i + 1] >> 1); |
3718 | |
|
3719 | 0 | if (out_ch == 2) { |
3720 | 0 | time_data[2 * i + 0] = temp; |
3721 | 0 | time_data[2 * i + 1] = time_data[2 * i + 0]; |
3722 | 0 | } else { |
3723 | 0 | time_data[i] = temp; |
3724 | 0 | } |
3725 | 0 | } |
3726 | 0 | } |
3727 | | |
3728 | 269k | if (p_state_enhaacplus_dec->s_adts_hdr_present) { |
3729 | 40.0k | if (adts.no_raw_data_blocks != 0) { |
3730 | 2.56k | if (adts.protection_absent == 0 && it_bit_buff->cnt_bits >= 16) { |
3731 | 0 | adts.crc_check = ixheaacd_read_bits_buf(it_bit_buff, 16); |
3732 | 0 | } |
3733 | 2.56k | } |
3734 | 40.0k | p_state_enhaacplus_dec->b_n_raw_data_blk--; |
3735 | 40.0k | } |
3736 | | |
3737 | 269k | ixheaacd_updatebytesconsumed(p_state_enhaacplus_dec, it_bit_buff); |
3738 | | |
3739 | 269k | if (p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) |
3740 | 232k | p_state_enhaacplus_dec->i_bytes_consumed = |
3741 | 232k | (WORD32)(audio_mux_length_bytes_last + bytes_for_sync); |
3742 | | |
3743 | 269k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal && |
3744 | 269k | p_obj_exhaacplus_dec->aac_config.first_frame) { |
3745 | 0 | p_obj_exhaacplus_dec->aac_config.first_frame = 0; |
3746 | 0 | } |
3747 | | |
3748 | 269k | if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal) { |
3749 | 0 | if (p_obj_exhaacplus_dec->aac_config.frame_status != 1) { |
3750 | 0 | p_state_enhaacplus_dec->i_bytes_consumed = p_state_enhaacplus_dec->ui_in_bytes; |
3751 | 0 | } |
3752 | 0 | return IA_NO_ERROR; |
3753 | 269k | } else { |
3754 | 269k | return error_code; |
3755 | 269k | } |
3756 | 269k | } |