xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_enc_main.h (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
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 #define IXHEAACE_MEM_FREE(pv_output)                                                   \
24   {                                                                                    \
25     WORD32 idx;                                                                        \
26     ixheaace_output_config *pstr_output_config = (ixheaace_output_config *)pv_output;  \
27     if (pstr_output_config->malloc_count > 0) {                                        \
28       for (idx = pstr_output_config->malloc_count - 1; idx >= 0; idx--) {              \
29         if (pstr_output_config->arr_alloc_memory[idx]) {                               \
30           pstr_output_config->free_xheaace(pstr_output_config->arr_alloc_memory[idx]); \
31         }                                                                              \
32       }                                                                                \
33       pstr_output_config->malloc_count = 0;                                            \
34     }                                                                                  \
35   }
36 
37 /*-------------------- structure definitions ------------------------------*/
38 
39 typedef struct {
40   WORD32 sample_rate;              /* mapped input sample rate */
41   WORD32 core_sample_rate;         /* core coder processing sample rate */
42   WORD32 native_sample_rate;       /* audio file sample rate */
43   WORD32 bit_rate;                 /* encoder bit rate in bits/sec */
44   WORD32 num_in_channels;          /* number of channels on input (1,2) */
45   WORD32 num_out_channels;         /* number of channels on output (1,2) */
46   WORD32 band_width;               /* targeted audio bandwidth in Hz */
47   WORD32 dual_mono;                /* flag: make 2 SCEs for stereo input files */
48   WORD32 use_tns;                  /* flag: use temporal noise shaping */
49   WORD32 use_adts;                 /* flag: use ADTS instead of ADIF */
50   WORD32 calc_crc;                 /* flag: write CRC checks */
51   WORD32 private_bit;              /* private bit of MPEG Header */
52   WORD32 copyright_bit;            /* copyright bit of MPEG Header */
53   WORD32 original_copy_bit;        /* original bit of MPEG Header */
54   WORD32 num_stereo_preprocessing; /* forbid usage of stereo prerpocessing */
55   WORD32 inv_quant;                /* improve distortion by inverse quantization */
56   WORD32 full_bandwidth;           /* improve distortion by inverse quantization */
57   WORD32 flag_framelength_small;   /* indicates frame size. 0 -> 512, 1 -> 480
58                                    indicates frame size. 0 -> 1024, 1 -> 960 */
59   WORD32 bitreservoir_size;        /* size of bit reservoir (default:0; max 6144)*/
60 } iaace_config;
61 
62 typedef struct {
63   WORD32 *shared_buffer1;
64   WORD32 *shared_buffer_2;
65   WORD32 *shared_buffer3;
66   WORD8 *shared_buffer5;
67 } iaace_scratch;
68 
69 /* pstr_ancillary configuration struct */
70 typedef struct {
71   WORD32 anc_flag;
72   WORD32 anc_mode;
73   WORD32 anc_rate;
74 } ixheaace_config_ancillary;
75 
76 typedef struct {
77   iaace_config config;
78   ixheaace_element_info element_info;
79   ixheaace_psy_out psy_out;
80   ixheaace_psy_kernel psy_kernel;
81   ixheaace_qc_state qc_kernel;
82   ixheaace_qc_out qc_out;
83   ixheaace_bitstream_enc_init bse_init;
84   ixheaace_stereo_pre_pro_struct str_stereo_pre_pro;
85   WORD32 downmix;
86   WORD32 downmix_fac;
87   WORD32 dual_mono;
88   WORD32 bandwidth_90_dB;
89   iaace_scratch *pstr_aac_scratch;
90 } iexheaac_encoder_str;
91 
92 VOID ia_enhaacplus_enc_aac_init_default_config(iaace_config *config, WORD32 aot);
93 
94 WORD32 ia_enhaacplus_enc_aac_enc_pers_size(WORD32 num_aac_chan, WORD32 aot);
95 WORD32 ia_enhaacplus_enc_aac_enc_scr_size(VOID);
96 
97 VOID ia_enhaacplus_enc_init_aac_tabs(ixheaace_aac_tables *pstr_aac_tabs);
98 
99 IA_ERRORCODE ia_enhaacplus_enc_aac_enc_open(iexheaac_encoder_str **ppstr_exheaac_encoder,
100                                             const iaace_config config,
101                                             iaace_scratch *pstr_aac_scratch,
102                                             ixheaace_aac_tables *pstr_aac_tabs, WORD32 ele_type,
103                                             WORD32 element_instance_tag, WORD32 aot);
104 
105 IA_ERRORCODE ia_enhaacplus_enc_aac_core_encode(
106     iexheaac_encoder_str **pstr_aac_enc, FLOAT32 *ptr_time_signal, UWORD32 time_sn_stride,
107     const UWORD8 *ptr_anc_bytes, UWORD8 *num_anc_bytes, UWORD8 *ptr_out_bytes,
108     WORD32 *num_out_bytes, ixheaace_aac_tables *pstr_aac_tables, VOID *ptr_bit_stream_handle,
109     VOID *ptr_bit_stream, FLAG flag_last_element, WORD32 *write_program_config_element,
110     WORD32 i_num_coup_channels, WORD32 i_channels_mask, WORD32 ele_idx, WORD32 *total_fill_bits,
111     WORD32 total_channels, WORD32 aot, WORD32 adts_flag, WORD32 num_bs_elements,
112     WORD32 *is_quant_spec_zero, WORD32 *is_gain_limited);
113 
114 VOID ia_enhaacplus_enc_set_shared_bufs(iaace_scratch *scr, WORD32 **shared_buf1,
115                                        WORD32 **shared_buf2, WORD32 **shared_buf3,
116                                        WORD8 **shared_buf5);
117