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 "ixheaacd_sbr_common.h"
22 #include "ixheaac_type_def.h"
23
24 #include "ixheaac_constants.h"
25 #include "ixheaac_basic_ops32.h"
26 #include "ixheaac_basic_ops16.h"
27 #include "ixheaac_basic_ops40.h"
28 #include "ixheaacd_bitbuffer.h"
29 #include "ixheaacd_defines.h"
30 #include "ixheaacd_aac_rom.h"
31 #include "ixheaacd_pulsedata.h"
32
33 #include "ixheaacd_pns.h"
34 #include "ixheaacd_drc_data_struct.h"
35
36 #include "ixheaacd_lt_predict.h"
37
38 #include "ixheaacd_cnst.h"
39 #include "ixheaacd_ec_defines.h"
40 #include "ixheaacd_ec_struct_def.h"
41 #include "ixheaacd_channelinfo.h"
42 #include "ixheaacd_drc_dec.h"
43 #include "ixheaacd_sbrdecoder.h"
44
45 #include "ixheaacd_audioobjtypes.h"
46 #include "ixheaacd_sbrdecsettings.h"
47 #include "ixheaacd_memory_standards.h"
48 #include "ixheaacd_error_codes.h"
49
50 #include "ixheaacd_defines.h"
51
52 #include "ixheaacd_sbr_scale.h"
53 #include "ixheaacd_lpp_tran.h"
54 #include "ixheaacd_env_extr_part.h"
55 #include "ixheaacd_sbr_rom.h"
56
57 #include "ixheaacd_hybrid.h"
58 #include "ixheaacd_ps_dec.h"
59 #include "ixheaacd_ps_bitdec.h"
60
61 #include "ixheaacd_pulsedata.h"
62
63 #include "ixheaacd_env_extr.h"
64 #include "ixheaacd_common_rom.h"
65 #include "ixheaacd_block.h"
66 #include "ixheaacd_channel.h"
67
68 #include "ixheaacd_audioobjtypes.h"
69 #include "ixheaacd_latmdemux.h"
70
71 #include "ixheaacd_aacdec.h"
72 #include "ixheaacd_hybrid.h"
73 #include "ixheaacd_ps_dec.h"
74 #include "ixheaacd_mps_polyphase.h"
75 #include "ixheaacd_config.h"
76 #include "ixheaacd_qmf_dec.h"
77 #include "ixheaacd_mps_macro_def.h"
78 #include "ixheaacd_mps_struct_def.h"
79 #include "ixheaacd_mps_res_rom.h"
80 #include "ixheaacd_mps_aac_struct.h"
81 #include "ixheaacd_mps_dec.h"
82 #include "ixheaacd_struct_def.h"
83 #include "ixheaacd_headerdecode.h"
84
85 #include "ixheaacd_multichannel.h"
86
87 #include "ixheaac_basic_op.h"
88 #include "ixheaacd_adts_crc_check.h"
89 #include "ixheaacd_function_selector.h"
90
ixheaacd_allocate_mem_persistent(ia_exhaacplus_dec_api_struct * p_obj_enhaacplus_dec,ia_aac_dec_state_struct * p_state_enhaacplus_dec,WORD channels,WORD * persistent_used_total,WORD * sbr_persistent_start,WORD ps_enable)91 VOID ixheaacd_allocate_mem_persistent(
92 ia_exhaacplus_dec_api_struct *p_obj_enhaacplus_dec,
93 ia_aac_dec_state_struct *p_state_enhaacplus_dec, WORD channels,
94 WORD *persistent_used_total, WORD *sbr_persistent_start, WORD ps_enable) {
95 WORD persistent_used;
96 WORD8 **temp_persistent =
97 (WORD8 **)&(p_state_enhaacplus_dec->aac_persistent_mem_v);
98 *temp_persistent += *persistent_used_total;
99
100 persistent_used = ixheaacd_set_aac_persistent_buffers(
101 p_state_enhaacplus_dec->aac_persistent_mem_v, channels);
102
103 *persistent_used_total += persistent_used;
104
105 *sbr_persistent_start = *persistent_used_total;
106
107 p_state_enhaacplus_dec->sbr_persistent_mem_v =
108 (pVOID)((pWORD8)p_state_enhaacplus_dec->aac_persistent_mem_v +
109 IXHEAAC_GET_SIZE_ALIGNED(persistent_used, BYTE_ALIGN_8));
110
111 persistent_used = ixheaacd_getsize_sbr_persistent();
112
113 ixheaacd_set_sbr_persistent_buffers(
114 p_state_enhaacplus_dec->sbr_persistent_mem_v, &persistent_used, channels,
115 ps_enable);
116
117 *persistent_used_total += persistent_used;
118
119 {
120 struct ia_aac_persistent_struct *aac_persistent_mem =
121 (struct ia_aac_persistent_struct *)
122 p_obj_enhaacplus_dec->p_state_aac->aac_persistent_mem_v;
123 aac_persistent_mem->str_aac_decoder.pstr_aac_tables =
124 &p_obj_enhaacplus_dec->aac_tables;
125 aac_persistent_mem->str_aac_decoder.pstr_common_tables =
126 p_obj_enhaacplus_dec->common_tables;
127 }
128
129 ixheaacd_set_sbr_persistent_table_pointer(
130 p_obj_enhaacplus_dec->p_state_aac->sbr_persistent_mem_v,
131 &p_obj_enhaacplus_dec->str_sbr_tables,
132 p_obj_enhaacplus_dec->common_tables);
133 }
134
ixheaacd_create_bit_buf(ia_bit_buf_struct * it_bit_buff,UWORD8 * ptr_bit_buf_base,WORD32 bit_buf_size)135 ia_bit_buf_struct *ixheaacd_create_bit_buf(ia_bit_buf_struct *it_bit_buff,
136 UWORD8 *ptr_bit_buf_base,
137 WORD32 bit_buf_size) {
138 it_bit_buff->ptr_bit_buf_base = ptr_bit_buf_base;
139 it_bit_buff->ptr_bit_buf_end = ptr_bit_buf_base + bit_buf_size - 1;
140
141 it_bit_buff->ptr_read_next = ptr_bit_buf_base;
142 it_bit_buff->bit_pos = 7;
143
144 it_bit_buff->cnt_bits = 0;
145 it_bit_buff->size = bit_buf_size << 3;
146
147 it_bit_buff->adts_header_present = 0;
148 it_bit_buff->protection_absent = 0;
149 it_bit_buff->pstr_adts_crc_info = &it_bit_buff->str_adts_crc_info;
150
151 it_bit_buff->max_size = it_bit_buff->size;
152
153 ixheaacd_adts_crc_open(it_bit_buff->pstr_adts_crc_info);
154
155 return it_bit_buff;
156 }
157
ixheaacd_create_init_bit_buf(ia_bit_buf_struct * it_bit_buff,UWORD8 * ptr_bit_buf_base,WORD32 bit_buf_size)158 VOID ixheaacd_create_init_bit_buf(ia_bit_buf_struct *it_bit_buff,
159 UWORD8 *ptr_bit_buf_base,
160 WORD32 bit_buf_size) {
161 ixheaacd_create_bit_buf(it_bit_buff, ptr_bit_buf_base, bit_buf_size);
162 it_bit_buff->cnt_bits = (bit_buf_size << 3);
163 return;
164 }
165
ixheaacd_read_bidirection(ia_bit_buf_struct * it_bit_buff,WORD32 ixheaacd_drc_offset)166 VOID ixheaacd_read_bidirection(ia_bit_buf_struct *it_bit_buff,
167 WORD32 ixheaacd_drc_offset) {
168 if (ixheaacd_drc_offset != 0) {
169 WORD32 byte_offset;
170 if ((it_bit_buff->cnt_bits < 0) ||
171 (it_bit_buff->cnt_bits - ixheaacd_drc_offset < 0) ||
172 (it_bit_buff->cnt_bits - ixheaacd_drc_offset > it_bit_buff->size)) {
173 longjmp(*(it_bit_buff->xaac_jmp_buf),
174 IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
175 }
176 it_bit_buff->cnt_bits = it_bit_buff->cnt_bits - ixheaacd_drc_offset;
177 it_bit_buff->bit_pos = it_bit_buff->bit_pos - ixheaacd_drc_offset;
178 byte_offset = it_bit_buff->bit_pos >> 3;
179 it_bit_buff->bit_pos = it_bit_buff->bit_pos - (byte_offset << 3);
180
181 if (byte_offset) {
182 UWORD8 *ptr_read_next;
183
184 ptr_read_next = it_bit_buff->ptr_read_next;
185
186 ptr_read_next = ptr_read_next - (byte_offset);
187
188 it_bit_buff->ptr_read_next = ptr_read_next;
189 }
190 }
191 }
192