• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2023 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 
21 #pragma once
22 
23 /* read only memory, intra frame */
24 #define IA_MEMTYPE_INPUT 0x02
25 /* read-write memory, for usable output, intra frame */
26 #define IA_MEMTYPE_OUTPUT 0x03
27 
28 #define DEFAULT_MEM_ALIGN_8 (8)
29 #define IXHEAACE_MEM_ALLOC_CNT (6)
30 /* 1 <ixheaace_api_struct>  2 <ixheaace_mem_info_struct>  3 <Persistent>  4 <Scratch>  5 <Input>
31  * 6 <Output> */
32 
33 /* Audio Object Type */
34 #define AOT_AAC_LC (2)
35 #define AOT_SBR (5)
36 #define AOT_AAC_LD (23)
37 #define AOT_AAC_ELD (39)
38 #define AOT_USAC (42)
39 #define AOT_PS (29)
40 
41 /* standard memory table descriptor for libraries */
42 typedef struct {
43   UWORD32 ui_size;         /* size of the memory in bytes	*/
44   UWORD32 ui_alignment;    /* alignment in bytes 			*/
45   UWORD32 ui_type;         /* type of memory 				*/
46   UWORD32 ui_placement[2]; /* 64 bit placement info		*/
47   UWORD32 ui_priority;     /* the importance for placement	*/
48   UWORD32 ui_placed[2];    /* the o_red location for placement	*/
49 } ixheaace_mem_info_struct;
50 
51 typedef struct {
52   UWORD32 ui_size;
53   UWORD32 ui_alignment;
54   UWORD32 ui_type;
55   pVOID mem_ptr;
56 } ixheaace_mem_info_table;
57 
58 typedef struct {
59   WORD32 sample_rate;               /* audio file sample rate */
60   WORD32 bitrate;                   /* encoder bit rate in bits/sec */
61   WORD32 num_channels_in;           /* number of channels on input (1,2) */
62   WORD32 num_channels_out;          /* number of channels on output (1,2) */
63   WORD32 bandwidth;                 /* targeted audio bandwidth in Hz */
64   WORD32 dual_mono;                 /* flag: make 2 SCEs for stereo input files */
65   WORD32 use_tns;                   /* flag: use temporal noise shaping */
66   WORD32 noise_filling;             /* flag: use noise filling */
67   WORD32 use_adts;                  /* flag: use ADTS instead of ADIF */
68   WORD32 private_bit;               /* private bit of MPEG Header */
69   WORD32 copyright_bit;             /* copyright bit of MPEG Header */
70   WORD32 original_copy_bit;         /* original bit of MPEG Header */
71   WORD32 f_no_stereo_preprocessing; /* forbid usage of stereo prerpocessing */
72   WORD32 inv_quant;                 /* improve distortion by inverse quantization */
73   WORD32 full_bandwidth;            /* improve distortion by inverse quantization */
74   WORD32 bitreservoir_size;         /* size of bit reservoir (default:0; max 6144)*/
75   WORD32 length;
76 } ixheaace_aac_enc_config;
77 
78 typedef struct {
79   UWORD32 ui_pcm_wd_sz;
80   WORD32 i_bitrate;
81   WORD32 frame_length;
82   WORD32 frame_cmd_flag;
83   WORD32 out_bytes_flag;
84   WORD32 user_tns_flag;
85   WORD32 user_esbr_flag;
86   WORD32 aot;
87   WORD32 i_mps_tree_config;
88   WORD32 esbr_flag;
89   WORD32 i_channels;
90   UWORD32 i_samp_freq;
91   WORD32 i_native_samp_freq;
92   WORD32 i_channels_mask;
93   WORD32 i_num_coupling_chan;
94   /* Add config params here */
95   WORD32 i_use_mps;
96   WORD32 i_use_adts;
97   WORD32 i_use_es;
98   WORD32 usac_en;
99   WORD32 codec_mode;
100   WORD32 cplx_pred;
101   WORD32 ccfl_idx;
102   WORD32 pvc_active;
103   WORD32 harmonic_sbr;
104   WORD32 inter_tes_active;
105   pVOID pv_drc_cfg;
106   FLAG use_drc_element;
107   WORD32 drc_frame_size;
108   WORD32 hq_esbr;
109   FLAG write_program_config_element;
110   ixheaace_aac_enc_config aac_config;
111   WORD32 random_access_interval;
112   UWORD32 method_def;
113   FLAG use_measured_loudness;
114   FLOAT64 measured_loudness;
115   UWORD32 measurement_system;
116   FLOAT32 sample_peak_level;
117   UWORD16 stream_id;
118   FLAG use_delay_adjustment;
119 } ixheaace_input_config;
120 
121 typedef struct {
122   WORD8 *p_lib_name;
123   WORD8 *p_version_num;
124 
125 } ixheaace_version;
126 typedef struct {
127   WORD32 i_out_bytes;
128   WORD32 i_bytes_consumed;
129   UWORD32 ui_inp_buf_size;
130   UWORD32 malloc_count;
131   SIZE_T ui_rem;
132   UWORD32 ui_proc_mem_tabs_size;
133   pVOID pv_ia_process_api_obj;
134   pVOID arr_alloc_memory[IXHEAACE_MEM_ALLOC_CNT];
135   pVOID (*malloc_xheaace)(UWORD32, UWORD32);
136   VOID (*free_xheaace)(pVOID);
137   ixheaace_version version;
138   ixheaace_mem_info_table mem_info_table[4];
139   WORD32 input_size;
140   WORD32 samp_freq;
141   WORD32 header_samp_freq;
142   WORD32 audio_profile;
143   FLOAT32 down_sampling_ratio;
144   WORD32 expected_frame_count;
145 } ixheaace_output_config;
146 
147 typedef struct {
148   ixheaace_input_config input_config;
149   ixheaace_output_config output_config;
150 } ixheaace_user_config_struct;
151 
152 typedef struct {
153   WORD32 codec_mode;
154 } ia_input_config;
155 
156 /* gets the encoder library name and version number details */
157 IA_ERRORCODE ixheaace_get_lib_id_strings(pVOID pv_output);
158 
159 /* handles memory requirements and initialization*/
160 IA_ERRORCODE ixheaace_create(pVOID pv_input, pVOID pv_output);
161 
162 /* encodes the input frame data */
163 IA_ERRORCODE ixheaace_process(pVOID pv_ia_process_api_obj, pVOID pstr_in_cfg, pVOID pstr_out_cfg);
164 
165 /* frees the allocated memories for the encoder*/
166 IA_ERRORCODE ixheaace_delete(pVOID pv_output);
167