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 #ifndef IXHEAACD_STRUCT_DEF_H 21 #define IXHEAACD_STRUCT_DEF_H 22 23 #include <setjmp.h> 24 #include <stdbool.h> 25 #include "ixheaacd_peak_limiter_struct_def.h" 26 27 #define MAX_DECOR_CONFIG_IDX (2) 28 #define MAX_TIME_SLOTS (72) 29 #define NUM_MPS_TABLES (13) 30 31 #define MAX_PREROLL_FRAME_OFFSET 4 32 // max of escapedValue(4, 4, 8) i.e. 2^4 -1 + 2^4 -1 + 2^8 -1; 33 #define MAX_PREROLL_SIZE 285 34 #define IA_ENHAACPLUS_DEC_MPS_PAYLOAD_SIZE (1024) 35 36 typedef struct { 37 WORD8 element_instance_tag; 38 WORD32 object_type; 39 WORD32 samp_freq_index; 40 WORD32 num_front_channel_elements; 41 WORD32 num_side_channel_elements; 42 WORD32 num_back_channel_elements; 43 WORD32 num_lfe_channel_elements; 44 WORD32 num_assoc_data_elements; 45 WORD32 num_valid_cc_elements; 46 47 WORD8 front_element_is_cpe[16]; 48 WORD8 front_element_tag_select[16]; 49 WORD8 side_element_is_cpe[16]; 50 WORD8 side_element_tag_select[16]; 51 WORD8 back_element_is_cpe[16]; 52 WORD8 back_element_tag_select[16]; 53 WORD8 lfe_element_tag_select[16]; 54 55 WORD32 channels; 56 WORD32 alignment_bits; 57 58 } ia_program_config_struct; 59 60 typedef struct ia_enhaacplus_dec_ind_cc { 61 WORD8 cc_target_is_cpe[MAX_BS_ELEMENT]; 62 WORD8 cc_target_tag_select[MAX_BS_ELEMENT]; 63 WORD8 cc_l[MAX_BS_ELEMENT]; 64 WORD8 cc_r[MAX_BS_ELEMENT]; 65 WORD32 cc_gain[2 * MAX_BS_ELEMENT]; 66 WORD8 elements_coupled[MAX_BS_ELEMENT]; 67 WORD num_coupled_elements; 68 69 } ia_enhaacplus_dec_ind_cc; 70 71 typedef struct { 72 UWORD32 ui_pcm_wdsz; 73 UWORD32 ui_samp_freq; 74 UWORD32 ui_n_channels; 75 WORD32 i_channel_mask; 76 UWORD32 ui_channel_mode; 77 UWORD32 ui_sbr_mode; 78 WORD32 ui_effect_type; 79 WORD32 ui_target_loudness; 80 WORD32 ui_loud_norm_flag; 81 82 UWORD32 flag_downmix; 83 UWORD32 flag_08khz_out; 84 UWORD32 flag_16khz_out; 85 UWORD32 flag_to_stereo; 86 UWORD32 down_sample_flag; 87 UWORD32 header_dec_done; 88 UWORD32 ui_mp4_flag; 89 UWORD32 ui_disable_sync; 90 UWORD32 ui_auto_sbr_upsample; 91 WORD32 frame_status; 92 UWORD32 ui_max_channels; 93 UWORD32 ui_pce_found_in_hdr; 94 UWORD32 ui_n_memtabs; 95 96 WORD32 ui_drc_boost; 97 WORD32 ui_drc_cut; 98 WORD32 ui_drc_target_level; 99 WORD32 ui_drc_set; 100 WORD32 ui_drc_heavy_comp; 101 102 ia_program_config_struct str_prog_config; 103 WORD32 element_type[MAX_BS_ELEMENT + 1]; 104 WORD32 slot_element[MAX_BS_ELEMENT + 1]; 105 106 WORD element_instance_order[MAX_BS_ELEMENT]; 107 WORD ui_coupling_channel; 108 WORD downmix; 109 WORD32 loas_present; 110 111 WORD framesize_480; 112 WORD ld_decoder; 113 114 WORD eld_sbr_present; 115 116 UWORD32 ui_out_channels; 117 WORD32 ui_channel_mask; 118 119 WORD32 ui_dec_type; 120 121 UWORD32 ui_qmf_bands; 122 123 WORD32 ui_flush_cmd; 124 125 ia_drc_config drc_config_struct; 126 WORD32 output_level; 127 WORD32 i_loud_ref_level; 128 UWORD8 dup_stereo_flag; 129 WORD32 peak_limiter_off; 130 131 WORD32 mps_present; 132 UWORD32 ui_frame_size; 133 WORD32 ui_enh_sbr; 134 WORD32 ui_hq_esbr; 135 WORD32 ui_enh_sbr_ps; 136 WORD32 ui_usac_flag; 137 138 WORD32 ui_err_conceal; 139 FLAG first_frame; 140 } ia_aac_dec_config_struct; 141 142 typedef struct ia_aac_dec_state_struct { 143 ia_aac_dec_config_struct *p_config; 144 145 AUDIO_OBJECT_TYPE audio_object_type; 146 147 UWORD32 ui_in_bytes; 148 UWORD32 ui_out_bytes; 149 UWORD32 ui_exec_done; 150 151 WORD16 b_n_raw_data_blk; 152 WORD16 s_adts_hdr_present; 153 WORD16 s_adif_hdr_present; 154 WORD16 num_channel_last; 155 UWORD32 sampling_rate; 156 UWORD32 extension_samp_rate; 157 UWORD32 bit_rate; 158 UWORD32 ui_init_done; 159 UWORD32 ui_input_over; 160 UWORD32 header_dec_done; 161 WORD32 frame_counter; 162 ia_aac_decoder_struct *pstr_aac_dec_info[MAX_BS_ELEMENT]; 163 164 UWORD32 ch_config; 165 struct ia_bit_buf_struct str_bit_buf, *pstr_bit_buf; 166 ia_aac_dec_sbr_bitstream_struct (*pstr_stream_sbr)[2]; 167 ia_handle_sbr_dec_inst_struct str_sbr_dec_info[MAX_BS_ELEMENT]; 168 WORD32 sbr_present_flag; 169 WORD32 ps_present; 170 171 ia_bit_buf_struct *ptr_bit_stream; 172 173 VOID *aac_scratch_mem_v; 174 VOID *aac_persistent_mem_v; 175 176 VOID *sbr_persistent_mem_v; 177 WORD32 *ptr_overlap_buf; 178 WORD16 num_of_out_samples; 179 WORD32 last_frame_ok; 180 WORD32 i_bytes_consumed; 181 182 WORD32 *coup_ch_output; 183 ia_enhaacplus_dec_ind_cc ind_cc_info; 184 185 WORD8 protection_absent; 186 WORD32 crc_check; 187 WORD32 ui_flush_cmd; 188 189 WORD32 frame_len_flag; 190 WORD32 depends_on_core_coder; 191 WORD32 extension_flag; 192 193 WORD32 bs_format; 194 WORD32 bit_count; 195 WORD32 sync_status; 196 WORD32 extension_flag_3; 197 198 ixheaacd_latm_struct latm_struct_element; 199 WORD32 latm_initialized; 200 201 ia_drc_dec_struct str_drc_dec_info; 202 ia_drc_dec_struct drc_dummy; 203 ia_drc_dec_struct *pstr_drc_dec; 204 ixheaac_drc_data_struct *pstr_hdrc_data[MAX_BS_ELEMENT * 3]; 205 206 WORD32 prev_channel_mode; 207 WORD32 drc_cut_fac; 208 WORD32 drc_boost_fac; 209 210 WORD32 first_drc_frame; 211 212 ia_aac_err_config_struct str_err_config; 213 WORD32 frame_size; 214 WORD32 frame_length; 215 216 WORD32 dwnsmp_signal; 217 ia_eld_specific_config_struct eld_specific_config; 218 FLAG usac_flag; 219 220 WORD32 num_of_output_ch; 221 VOID *ia_audio_specific_config; 222 ia_mps_dec_state_struct mps_dec_handle; 223 224 ia_heaac_mps_state_struct heaac_mps_handle; 225 UWORD8 mps_buffer[IA_ENHAACPLUS_DEC_MPS_PAYLOAD_SIZE]; 226 227 UWORD16 *huffman_code_book_scl; 228 UWORD32 *huffman_code_book_scl_index; 229 230 ia_aac_dec_tables_struct *pstr_aac_tables; 231 232 VOID *pstr_dec_data; 233 VOID *sbr_persistent_mem_u; 234 VOID *sbr_scratch_mem_u; 235 UWORD8 *header_ptr; 236 WORD32 header_length; 237 ia_sbr_header_data_struct str_sbr_config; 238 jmp_buf xaac_jmp_buf; 239 WORD32 decode_create_done; 240 WORD32 ldmps_present; 241 WORD32 fatal_err_present; 242 WORD8 *pers_mem_ptr; 243 UWORD8 preroll_config_present; 244 UWORD8 preroll_config_prev[MAX_PREROLL_SIZE]; 245 246 UWORD8 qshift_cnt; 247 WORD8 qshift_adj[16]; 248 UWORD32 delay_in_samples; 249 UWORD8 peak_lim_init; 250 ia_peak_limiter_struct peak_limiter; 251 UWORD8 sbr_present; 252 UWORD8 slot_pos; 253 WORD32 mps_header; 254 WORD32 ui_mps_out_bytes; 255 WORD32 drc_config_changed; 256 WORD32 apply_crossfade; 257 WORD32 ec_enable; 258 WORD32 first_frame; 259 } ia_aac_dec_state_struct; 260 261 typedef struct ia_exhaacplus_dec_api_struct { 262 ia_aac_dec_state_struct *p_state_aac; 263 264 ia_aac_dec_config_struct aac_config; 265 266 ia_mem_info_struct *p_mem_info_aac; 267 268 pVOID *pp_mem_aac; 269 270 ia_aac_dec_tables_struct aac_tables; 271 ixheaacd_misc_tables *common_tables; 272 ia_sbr_tables_struct str_sbr_tables; 273 274 } ia_exhaacplus_dec_api_struct; 275 276 WORD32 ixheaacd_aacdec_decodeframe( 277 ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, 278 ia_aac_dec_scratch_struct *aac_scratch_ptrs, VOID *time_data, FLAG frame_status, WORD *type, 279 WORD *ch_idx, WORD init_flag, WORD channel, WORD *element_index_order, WORD skip_full_decode, 280 WORD ch_fac, WORD slot_element, WORD max_channels, WORD32 total_channels, WORD32 frame_length, 281 WORD32 frame_size, ia_drc_dec_struct *pstr_drc_dec, WORD32 object_type, WORD32 ch_config, 282 ia_eld_specific_config_struct eld_specific_config, WORD16 adtsheader, 283 ia_drc_dec_struct *drc_dummy, WORD32 ldmps_present, UWORD8 *slot_pos, UWORD8 *mps_buffer, 284 WORD32 *mps_header, WORD32 *mps_bytes, WORD32 is_init, WORD32 first_frame); 285 286 WORD ixheaacd_get_channel_mask( 287 ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec); 288 289 VOID ixheaacd_allocate_mem_persistent( 290 ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, 291 ia_aac_dec_state_struct *p_state_enhaacplus_dec, WORD channels, 292 WORD *persistent_used_total, WORD *sbr_persistent_start, WORD ps_enable); 293 294 WORD32 ixheaacd_dec_mem_api(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, 295 WORD32 i_cmd, WORD32 i_idx, VOID *pv_value); 296 297 VOID ixheaacd_fill_aac_mem_tables( 298 ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec); 299 300 WORD32 ixheaacd_decoder_2_ga_hdr( 301 ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec); 302 303 WORD32 ixheaacd_decoder_flush_api( 304 ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec); 305 306 WORD32 ixheaacd_fill_usac_mem_tables(ia_exhaacplus_dec_api_struct *self); 307 308 WORD32 ixheaacd_dec_init(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec); 309 310 WORD32 ixheaacd_dec_execute(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec); 311 312 WORD32 ixheaacd_dec_table_api( 313 ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, WORD32 i_cmd, 314 WORD32 i_idx, VOID *pv_value); 315 316 IA_ERRORCODE ixheaacd_aac_mps_init(ia_exhaacplus_dec_api_struct *p_obj_mps_dec, 317 UWORD8 *databuf, WORD32 buffer_size, 318 WORD32 sample_rate); 319 320 WORD32 ixheaacd_peak_limiter_init(ia_peak_limiter_struct *peak_limiter, UWORD32 num_channels, 321 UWORD32 sample_rate, FLOAT32 *buffer, 322 UWORD32 *delay_in_samples); 323 324 VOID ixheaacd_peak_limiter_process(ia_peak_limiter_struct *peak_limiter, VOID *samples, 325 UWORD32 frame_len, WORD8 *qshift_adj); 326 327 VOID ixheaacd_scale_adjust(VOID *samples, UWORD32 frame_len, WORD8 *qshift_adj, 328 WORD num_channels); 329 VOID ixheaacd_peak_limiter_process_float(ia_peak_limiter_struct *peak_limiter, 330 FLOAT32 samples[MAX_NUM_CHANNELS][4096], 331 UWORD32 frame_len); 332 333 334 #endif /* IXHEAACD_STRUCT_DEF_H */ 335