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