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 "ixheaacd_type_def.h"
23
24 #include "ixheaacd_constants.h"
25 #include "ixheaacd_basic_ops32.h"
26 #include "ixheaacd_basic_ops16.h"
27 #include "ixheaacd_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 "ixheaacd_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)((SIZE_T)((pWORD8)p_state_enhaacplus_dec->aac_persistent_mem_v +
109 persistent_used + sizeof(SIZE_T) - 1) &
110 (SIZE_T)(~(sizeof(SIZE_T) - 1)));
111
112 persistent_used = ixheaacd_getsize_sbr_persistent();
113
114 ixheaacd_set_sbr_persistent_buffers(
115 p_state_enhaacplus_dec->sbr_persistent_mem_v, &persistent_used, channels,
116 ps_enable);
117
118 *persistent_used_total += persistent_used;
119
120 {
121 struct ia_aac_persistent_struct *aac_persistent_mem =
122 (struct ia_aac_persistent_struct *)
123 p_obj_enhaacplus_dec->p_state_aac->aac_persistent_mem_v;
124 aac_persistent_mem->str_aac_decoder.pstr_aac_tables =
125 &p_obj_enhaacplus_dec->aac_tables;
126 aac_persistent_mem->str_aac_decoder.pstr_common_tables =
127 p_obj_enhaacplus_dec->common_tables;
128 }
129
130 ixheaacd_set_sbr_persistent_table_pointer(
131 p_obj_enhaacplus_dec->p_state_aac->sbr_persistent_mem_v,
132 &p_obj_enhaacplus_dec->str_sbr_tables,
133 p_obj_enhaacplus_dec->common_tables);
134 }
135
ixheaacd_create_bit_buf(ia_bit_buf_struct * it_bit_buff,UWORD8 * ptr_bit_buf_base,WORD32 bit_buf_size)136 ia_bit_buf_struct *ixheaacd_create_bit_buf(ia_bit_buf_struct *it_bit_buff,
137 UWORD8 *ptr_bit_buf_base,
138 WORD32 bit_buf_size) {
139 it_bit_buff->ptr_bit_buf_base = ptr_bit_buf_base;
140 it_bit_buff->ptr_bit_buf_end = ptr_bit_buf_base + bit_buf_size - 1;
141
142 it_bit_buff->ptr_read_next = ptr_bit_buf_base;
143 it_bit_buff->bit_pos = 7;
144
145 it_bit_buff->cnt_bits = 0;
146 it_bit_buff->size = bit_buf_size << 3;
147
148 it_bit_buff->adts_header_present = 0;
149 it_bit_buff->protection_absent = 0;
150 it_bit_buff->pstr_adts_crc_info = &it_bit_buff->str_adts_crc_info;
151
152 it_bit_buff->max_size = it_bit_buff->size;
153
154 ixheaacd_adts_crc_open(it_bit_buff->pstr_adts_crc_info);
155
156 return it_bit_buff;
157 }
158
ixheaacd_create_init_bit_buf(ia_bit_buf_struct * it_bit_buff,UWORD8 * ptr_bit_buf_base,WORD32 bit_buf_size)159 VOID ixheaacd_create_init_bit_buf(ia_bit_buf_struct *it_bit_buff,
160 UWORD8 *ptr_bit_buf_base,
161 WORD32 bit_buf_size) {
162 ixheaacd_create_bit_buf(it_bit_buff, ptr_bit_buf_base, bit_buf_size);
163 it_bit_buff->cnt_bits = (bit_buf_size << 3);
164 return;
165 }
166
ixheaacd_read_bidirection(ia_bit_buf_struct * it_bit_buff,WORD32 ixheaacd_drc_offset)167 VOID ixheaacd_read_bidirection(ia_bit_buf_struct *it_bit_buff,
168 WORD32 ixheaacd_drc_offset) {
169 if (ixheaacd_drc_offset != 0) {
170 WORD32 byte_offset;
171 if ((it_bit_buff->cnt_bits < 0) ||
172 (it_bit_buff->cnt_bits - ixheaacd_drc_offset < 0) ||
173 (it_bit_buff->cnt_bits - ixheaacd_drc_offset > it_bit_buff->size)) {
174 longjmp(*(it_bit_buff->xaac_jmp_buf),
175 IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
176 }
177 it_bit_buff->cnt_bits = it_bit_buff->cnt_bits - ixheaacd_drc_offset;
178 it_bit_buff->bit_pos = it_bit_buff->bit_pos - ixheaacd_drc_offset;
179 byte_offset = it_bit_buff->bit_pos >> 3;
180 it_bit_buff->bit_pos = it_bit_buff->bit_pos - (byte_offset << 3);
181
182 if (byte_offset) {
183 UWORD8 *ptr_read_next;
184
185 ptr_read_next = it_bit_buff->ptr_read_next;
186
187 ptr_read_next = ptr_read_next - (byte_offset);
188
189 it_bit_buff->ptr_read_next = ptr_read_next;
190 }
191 }
192 }
193