Home | History | Annotate | Download | only in decoder
      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 
     25 #define MAX_OUTPUT_CHANNELS (8)
     26 #define MAX_NUM_OTT (1)
     27 
     28 #define MAX_ARBITRARY_TREE_LEVELS (2)
     29 #define MAX_PARAMETER_SETS (8)
     30 #define MAX_ARBITRARY_TREE_INDEX ((1 << (MAX_ARBITRARY_TREE_LEVELS + 1)) - 1)
     31 #define MAX_NUM_QMF_BANDS (64)
     32 #define MAX_NUM_OTT_AT \
     33   (MAX_OUTPUT_CHANNELS * ((1 << MAX_ARBITRARY_TREE_LEVELS) - 1))
     34 #define MAX_PARAMETER_BANDS (28)
     35 
     36 #define MAX_HYBRID_BANDS (MAX_NUM_QMF_BANDS - 3 + 10)
     37 
     38 #define MAX_TIME_SLOTS (72)
     39 
     40 #define MAX_M2_OUTPUT (8)
     41 #define QMF_BANDS_TO_HYBRID (3)
     42 #define PROTO_LEN (13)
     43 #define BUFFER_LEN_LF (PROTO_LEN - 1 + MAX_TIME_SLOTS)
     44 #define BUFFER_LEN_HF ((PROTO_LEN - 1) / 2)
     45 #define MAX_TIME_SLOTS (72)
     46 #define MAX_NO_TIME_SLOTS_DELAY (14)
     47 
     48 typedef struct {
     49   WORD8 element_instance_tag;
     50   WORD32 object_type;
     51   WORD32 samp_freq_index;
     52   WORD32 num_front_channel_elements;
     53   WORD32 num_side_channel_elements;
     54   WORD32 num_back_channel_elements;
     55   WORD32 num_lfe_channel_elements;
     56   WORD32 num_assoc_data_elements;
     57   WORD32 num_valid_cc_elements;
     58 
     59   WORD8 front_element_is_cpe[16];
     60   WORD8 front_element_tag_select[16];
     61   WORD8 side_element_is_cpe[16];
     62   WORD8 side_element_tag_select[16];
     63   WORD8 back_element_is_cpe[16];
     64   WORD8 back_element_tag_select[16];
     65   WORD8 lfe_element_tag_select[16];
     66 
     67   WORD32 channels;
     68   WORD32 alignment_bits;
     69 
     70 } ia_program_config_struct;
     71 
     72 typedef struct ia_enhaacplus_dec_ind_cc {
     73   WORD8 cc_target_is_cpe[MAX_BS_ELEMENT];
     74   WORD8 cc_target_tag_select[MAX_BS_ELEMENT];
     75   WORD8 cc_l[MAX_BS_ELEMENT];
     76   WORD8 cc_r[MAX_BS_ELEMENT];
     77   WORD32 cc_gain[2 * MAX_BS_ELEMENT];
     78   WORD8 elements_coupled[MAX_BS_ELEMENT];
     79   WORD num_coupled_elements;
     80 
     81 } ia_enhaacplus_dec_ind_cc;
     82 
     83 typedef struct {
     84   UWORD32 ui_pcm_wdsz;
     85   UWORD32 ui_samp_freq;
     86   UWORD32 ui_n_channels;
     87   WORD32 i_channel_mask;
     88   UWORD32 ui_channel_mode;
     89   UWORD32 ui_sbr_mode;
     90   WORD32 ui_effect_type;
     91   WORD32 ui_target_loudness;
     92   WORD32 ui_loud_norm_flag;
     93 
     94   UWORD32 flag_downmix;
     95   UWORD32 flag_08khz_out;
     96   UWORD32 flag_16khz_out;
     97   UWORD32 flag_to_stereo;
     98   UWORD32 down_sample_flag;
     99   UWORD32 header_dec_done;
    100   UWORD32 ui_mp4_flag;
    101   UWORD32 ui_disable_sync;
    102   UWORD32 ui_auto_sbr_upsample;
    103   WORD32 frame_status;
    104   UWORD32 ui_max_channels;
    105   UWORD32 ui_pce_found_in_hdr;
    106   UWORD32 ui_n_memtabs;
    107 
    108   WORD32 ui_drc_enable;
    109   WORD32 ui_drc_boost;
    110   WORD32 ui_drc_cut;
    111   WORD32 ui_drc_target_level;
    112   WORD32 ui_drc_set;
    113   WORD32 ui_drc_heavy_comp;
    114 
    115   ia_program_config_struct str_prog_config;
    116   WORD32 element_type[MAX_BS_ELEMENT + 1];
    117   WORD32 slot_element[MAX_BS_ELEMENT + 1];
    118 
    119   WORD element_instance_order[MAX_BS_ELEMENT];
    120   WORD ui_coupling_channel;
    121   WORD downmix;
    122   WORD32 loas_present;
    123 
    124   WORD framesize_480;
    125   WORD ld_decoder;
    126 
    127   WORD eld_sbr_present;
    128 
    129   UWORD32 ui_out_channels;
    130   WORD32 ui_channel_mask;
    131 
    132   WORD32 ui_dec_type;
    133 
    134   UWORD32 ui_qmf_bands;
    135 
    136   WORD32 ui_flush_cmd;
    137 
    138   ia_drc_config drc_config_struct;
    139 
    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   WORD16 *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   UWORD16 *huffman_code_book_scl;
    225   UWORD32 *huffman_code_book_scl_index;
    226 
    227   ia_aac_dec_tables_struct *pstr_aac_tables;
    228 
    229   VOID *pstr_dec_data;
    230   VOID *sbr_persistent_mem_u;
    231   VOID *sbr_scratch_mem_u;
    232   UWORD8 *header_ptr;
    233   WORD32 header_length;
    234   ia_sbr_header_data_struct str_sbr_config;
    235   jmp_buf xaac_jmp_buf;
    236   WORD32 decode_create_done;
    237 } ia_aac_dec_state_struct;
    238 
    239 typedef struct ia_exhaacplus_dec_api_struct {
    240   ia_aac_dec_state_struct *p_state_aac;
    241 
    242   ia_aac_dec_config_struct aac_config;
    243 
    244   ia_mem_info_struct *p_mem_info_aac;
    245 
    246   pVOID *pp_mem_aac;
    247 
    248   ia_aac_dec_tables_struct aac_tables;
    249   ixheaacd_misc_tables *common_tables;
    250   ia_sbr_tables_struct str_sbr_tables;
    251 
    252 } ia_exhaacplus_dec_api_struct;
    253 
    254 WORD32 ixheaacd_aacdec_decodeframe(
    255     ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec,
    256     ia_aac_dec_scratch_struct *aac_scratch_ptrs, WORD16 *time_data,
    257     FLAG frame_status, WORD *type, WORD *ch_idx, WORD init_flag, WORD channel,
    258     WORD *element_index_order, WORD skip_full_decode, WORD ch_fac,
    259     WORD slot_element, WORD max_channels, WORD32 total_channels,
    260     WORD32 frame_length, WORD32 frame_size, ia_drc_dec_struct *pstr_drc_dec,
    261     WORD32 object_type, WORD32 ch_config,
    262     ia_eld_specific_config_struct eld_specific_config, WORD16 adtsheader,
    263     ia_drc_dec_struct *drc_dummy);
    264 
    265 WORD ixheaacd_get_channel_mask(
    266     ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec);
    267 
    268 VOID ixheaacd_allocate_mem_persistent(
    269     ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec,
    270     ia_aac_dec_state_struct *p_state_enhaacplus_dec, WORD channels,
    271     WORD *persistent_used_total, WORD *sbr_persistent_start, WORD ps_enable);
    272 
    273 WORD32 ixheaacd_dec_mem_api(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec,
    274                             WORD32 i_cmd, WORD32 i_idx, VOID *pv_value);
    275 
    276 WORD32 ixheaacd_fill_aac_mem_tables(
    277     ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec);
    278 
    279 WORD32 ixheaacd_decoder_2_ga_hdr(
    280     ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec);
    281 
    282 WORD32 ixheaacd_decoder_flush_api(
    283     ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec);
    284 
    285 WORD32 ixheaacd_fill_usac_mem_tables(ia_exhaacplus_dec_api_struct *self);
    286 
    287 WORD32 ixheaacd_dec_init(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec);
    288 
    289 WORD32 ixheaacd_dec_execute(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec);
    290 
    291 WORD32 ixheaacd_dec_table_api(
    292     ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, WORD32 i_cmd,
    293     WORD32 i_idx, VOID *pv_value);
    294 
    295 #endif /* IXHEAACD_STRUCT_DEF_H */
    296