/src/libxaac/decoder/ixheaacd_huff_code_reorder.c
Line | Count | Source |
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 | | #include "ixheaac_error_standards.h" |
24 | | |
25 | | #include "ixheaac_constants.h" |
26 | | #include "ixheaac_basic_ops32.h" |
27 | | #include "ixheaac_basic_ops40.h" |
28 | | #include "ixheaac_basic_ops.h" |
29 | | |
30 | | #include "ixheaacd_bitbuffer.h" |
31 | | #include "ixheaacd_defines.h" |
32 | | #include "ixheaacd_aac_rom.h" |
33 | | #include "ixheaacd_pulsedata.h" |
34 | | |
35 | | #include "ixheaacd_pns.h" |
36 | | |
37 | | #include "ixheaacd_lt_predict.h" |
38 | | #include "ixheaacd_cnst.h" |
39 | | #include "ixheaacd_ec_defines.h" |
40 | | #include "ixheaacd_ec_struct_def.h" |
41 | | #include "ixheaacd_channelinfo.h" |
42 | | |
43 | | #include "ixheaacd_drc_data_struct.h" |
44 | | #include "ixheaacd_drc_dec.h" |
45 | | |
46 | | #include "ixheaacd_sbrdecoder.h" |
47 | | |
48 | | #include "ixheaacd_block.h" |
49 | | #include "ixheaacd_channel.h" |
50 | | #include "ixheaacd_common_rom.h" |
51 | | |
52 | | #include "ixheaacd_aacdec.h" |
53 | | |
54 | | #include "ixheaacd_sbrdecsettings.h" |
55 | | #include "ixheaacd_sbr_scale.h" |
56 | | #include "ixheaacd_env_extr_part.h" |
57 | | #include "ixheaacd_sbr_rom.h" |
58 | | #include "ixheaacd_audioobjtypes.h" |
59 | | #include "ixheaacd_memory_standards.h" |
60 | | #include "ixheaacd_latmdemux.h" |
61 | | #include "ixheaacd_mps_polyphase.h" |
62 | | #include "ixheaacd_config.h" |
63 | | #include "ixheaacd_hybrid.h" |
64 | | #include "ixheaacd_ps_dec.h" |
65 | | #include "ixheaacd_qmf_dec.h" |
66 | | #include "ixheaacd_mps_macro_def.h" |
67 | | #include "ixheaacd_mps_struct_def.h" |
68 | | #include "ixheaacd_mps_res_rom.h" |
69 | | #include "ixheaacd_mps_aac_struct.h" |
70 | | #include "ixheaacd_mps_dec.h" |
71 | | #include "ixheaacd_struct_def.h" |
72 | | |
73 | | #include "ixheaacd_rvlc.h" |
74 | | |
75 | | const UWORD8 ixheaacd_min_huff_cb_pair_tbl[MAX_CB_PAIRS] = { |
76 | | 0, 1, 3, 5, 7, 9, 16, 17, 18, 19, 20, 21, |
77 | | 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 11}; |
78 | | const UWORD8 ixheaacd_max_huff_cb_pair_table[MAX_CB_PAIRS] = { |
79 | | 0, 2, 4, 6, 8, 10, 16, 17, 18, 19, 20, 21, |
80 | | 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 11}; |
81 | | const UWORD8 ixheaacd_max_huff_cw_len_table[MAX_CB] = { |
82 | | 0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14, 49, 0, 0, 0, 0, |
83 | | 14, 17, 21, 21, 25, 25, 29, 29, 29, 29, 33, 33, 33, 37, 37, 41}; |
84 | | const UWORD8 ixheaacd_huff_cb_dim_table[MAX_CB] = { |
85 | | 2, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, |
86 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; |
87 | | const UWORD8 ixheaacd_huff_cb_dim_shift_table[MAX_CB] = { |
88 | | 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, |
89 | | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; |
90 | | const UWORD8 ixheaacd_huff_cb_sign_table[MAX_CB] = { |
91 | | 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, |
92 | | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; |
93 | | const UWORD8 ixheaacd_huff_cb_priority_table[MAX_CB] = { |
94 | | 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 22, 0, 0, 0, 0, |
95 | | 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; |
96 | | const UWORD16 ixheaacd_huff_reord_lav_table[MAX_CB] = { |
97 | | 0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, |
98 | | 8191, 0, 0, 0, 0, 15, 31, 47, 63, 95, 127, |
99 | | 159, 191, 223, 255, 319, 383, 511, 767, 1023, 2047}; |
100 | | |
101 | 338k | VOID ixheaacd_huff_code_reorder_tbl_init(ia_hcr_info_struct *ptr_hcr_info) { |
102 | 338k | ptr_hcr_info->codebook_pairs.ptr_min_cb_pair_tbl = |
103 | 338k | ixheaacd_min_huff_cb_pair_tbl; |
104 | 338k | ptr_hcr_info->codebook_pairs.ptr_max_cb_pair_tbl = |
105 | 338k | ixheaacd_max_huff_cb_pair_table; |
106 | 338k | ptr_hcr_info->table_info.ptr_max_cw_len_tbl = ixheaacd_max_huff_cw_len_table; |
107 | 338k | ptr_hcr_info->table_info.ptr_cb_dimension_tbl = ixheaacd_huff_cb_dim_table; |
108 | 338k | ptr_hcr_info->table_info.ptr_cb_dim_shift_tbl = |
109 | 338k | ixheaacd_huff_cb_dim_shift_table; |
110 | 338k | ptr_hcr_info->table_info.ptr_cb_sign_tbl = ixheaacd_huff_cb_sign_table; |
111 | 338k | ptr_hcr_info->table_info.ptr_cb_priority = ixheaacd_huff_cb_priority_table; |
112 | 338k | ptr_hcr_info->table_info.ptr_lav_tbl = ixheaacd_huff_reord_lav_table; |
113 | 338k | } |
114 | | |
115 | 32.7k | VOID ixheaacd_huff_mute_erroneous_lines(ia_hcr_info_struct *ptr_hcr_info) { |
116 | 32.7k | WORD32 c; |
117 | 32.7k | WORD32 *ptr_long = ptr_hcr_info->str_dec_io.ptr_quant_spec_coeff_base; |
118 | | |
119 | 33.5M | for (c = 0; c < 1024; c++) { |
120 | 33.5M | if (ptr_long[c] == (WORD32)8192) { |
121 | 117k | ptr_long[c] = 0; |
122 | 117k | } |
123 | 33.5M | } |
124 | 32.7k | } |
125 | | |
126 | | static UWORD8 ixheaacd_err_detect_pcw_segment(WORD8 remaining_bits_in_segment, |
127 | | ia_hcr_info_struct *ptr_hcr_info, |
128 | | ia_pcw_type_struct kind, |
129 | | WORD32 *qsc_base_of_cw, |
130 | 240k | UWORD8 dimension) { |
131 | 240k | WORD8 i; |
132 | 240k | if (remaining_bits_in_segment < 0) { |
133 | 0 | switch (kind) { |
134 | 0 | case PCW: |
135 | 0 | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 31); |
136 | 0 | break; |
137 | 0 | case PCW_SIGN: |
138 | 0 | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 30); |
139 | 0 | break; |
140 | 0 | case PCW_ESC_SIGN: |
141 | 0 | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 29); |
142 | 0 | break; |
143 | 0 | } |
144 | 0 | for (i = dimension; i != 0; i--) { |
145 | 0 | *qsc_base_of_cw++ = (WORD32)8192; |
146 | 0 | } |
147 | 0 | return 1; |
148 | 0 | } |
149 | 240k | return 0; |
150 | 240k | } |
151 | | |
152 | 111k | static VOID ixheaacd_nonpcw_sideinfo_init(ia_hcr_info_struct *ptr_hcr_info) { |
153 | 111k | UWORD16 i, k; |
154 | 111k | UWORD8 cb_dim; |
155 | 111k | UWORD8 *ptr_cb = ptr_hcr_info->str_non_pcw_side_info.ptr_cb; |
156 | 111k | UWORD16 *res_ptr_idx = ptr_hcr_info->str_non_pcw_side_info.res_ptr_idx; |
157 | 111k | UWORD16 *ptr_num_ext_sorted_cw_in_sect = |
158 | 111k | ptr_hcr_info->sect_info.ptr_num_ext_sorted_cw_in_sect; |
159 | 111k | WORD32 num_ext_sorted_cw_in_sect_idx = |
160 | 111k | ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx; |
161 | 111k | UWORD8 *ptr_ext_sorted_cw = ptr_hcr_info->sect_info.ptr_ext_sorted_cw; |
162 | 111k | WORD32 ext_sorted_cw_idx = ptr_hcr_info->sect_info.ext_sorted_cw_idx; |
163 | 111k | UWORD16 *ptr_num_ext_sorted_sect_in_sets = |
164 | 111k | ptr_hcr_info->sect_info.ptr_num_ext_sorted_sect_in_sets; |
165 | 111k | WORD32 num_ext_sorted_sect_in_sets_idx = |
166 | 111k | ptr_hcr_info->sect_info.num_ext_sorted_sect_in_sets_idx; |
167 | 111k | WORD32 quant_spec_coeff_idx = ptr_hcr_info->str_dec_io.quant_spec_coeff_idx; |
168 | 111k | const UWORD8 *ptr_cb_dimension_tbl = |
169 | 111k | ptr_hcr_info->table_info.ptr_cb_dimension_tbl; |
170 | 111k | WORD32 loop_idx = 0; |
171 | | |
172 | 111k | for (i = ptr_num_ext_sorted_sect_in_sets[num_ext_sorted_sect_in_sets_idx]; |
173 | 2.58M | i != 0; i--) { |
174 | 2.50M | cb_dim = ptr_cb_dimension_tbl[ptr_ext_sorted_cw[ext_sorted_cw_idx]]; |
175 | | |
176 | 2.50M | for (k = ptr_num_ext_sorted_cw_in_sect[num_ext_sorted_cw_in_sect_idx]; |
177 | 7.22M | k != 0; k--) { |
178 | 4.73M | loop_idx++; |
179 | 4.73M | if (loop_idx > 256) { |
180 | 11.0k | return; |
181 | 11.0k | } |
182 | 4.71M | *ptr_cb++ = ptr_ext_sorted_cw[ext_sorted_cw_idx]; |
183 | 4.71M | *res_ptr_idx++ = quant_spec_coeff_idx; |
184 | 4.71M | quant_spec_coeff_idx += cb_dim; |
185 | 4.71M | if (quant_spec_coeff_idx >= 1024) { |
186 | 304 | return; |
187 | 304 | } |
188 | 4.71M | } |
189 | 2.49M | num_ext_sorted_cw_in_sect_idx++; |
190 | 2.49M | ext_sorted_cw_idx++; |
191 | 2.49M | if (num_ext_sorted_cw_in_sect_idx >= (MAX_SFB_HCR + MAX_HCR_SETS) || |
192 | 2.47M | ext_sorted_cw_idx >= (MAX_SFB_HCR + MAX_HCR_SETS)) { |
193 | 16.7k | return; |
194 | 16.7k | } |
195 | 2.49M | } |
196 | 83.7k | num_ext_sorted_sect_in_sets_idx++; |
197 | 83.7k | if (num_ext_sorted_cw_in_sect_idx >= (MAX_SFB_HCR + MAX_HCR_SETS)) { |
198 | 0 | return; |
199 | 0 | } |
200 | | |
201 | 83.7k | ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx = |
202 | 83.7k | num_ext_sorted_cw_in_sect_idx; |
203 | 83.7k | ptr_hcr_info->sect_info.ext_sorted_cw_idx = ext_sorted_cw_idx; |
204 | 83.7k | ptr_hcr_info->sect_info.num_ext_sorted_sect_in_sets_idx = |
205 | 83.7k | num_ext_sorted_sect_in_sets_idx; |
206 | 83.7k | ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx = |
207 | 83.7k | num_ext_sorted_cw_in_sect_idx; |
208 | 83.7k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx = quant_spec_coeff_idx; |
209 | 83.7k | } |
210 | | |
211 | | static VOID ixheaacd_calc_num_ext_sorted_sect_sets( |
212 | | UWORD32 num_segment, UWORD16 *ptr_num_ext_sorted_cw_in_sect, |
213 | | WORD32 num_ext_sorted_cw_in_sect_idx, |
214 | | UWORD16 *ptr_num_ext_sorted_sect_in_sets, |
215 | 36.4k | WORD32 num_ext_sorted_sect_in_sets_idx) { |
216 | 36.4k | UWORD16 counter = 0; |
217 | 36.4k | UWORD32 cw_sum = 0; |
218 | 36.4k | UWORD16 *ptr_num_ext_sort_cw_in_sect = ptr_num_ext_sorted_cw_in_sect; |
219 | 36.4k | UWORD16 *ptr_num_ext_sort_sect_in_sets = ptr_num_ext_sorted_sect_in_sets; |
220 | | |
221 | 621k | while (ptr_num_ext_sort_cw_in_sect[num_ext_sorted_cw_in_sect_idx] != 0) { |
222 | 588k | cw_sum += ptr_num_ext_sort_cw_in_sect[num_ext_sorted_cw_in_sect_idx]; |
223 | 588k | num_ext_sorted_cw_in_sect_idx++; |
224 | 588k | if (num_ext_sorted_cw_in_sect_idx >= (MAX_SFB_HCR + MAX_HCR_SETS)) { |
225 | 0 | return; |
226 | 0 | } |
227 | 588k | if (cw_sum > num_segment) { |
228 | 0 | return; |
229 | 0 | } |
230 | 588k | counter++; |
231 | 588k | if (counter > 256) { |
232 | 0 | return; |
233 | 0 | } |
234 | 588k | if (cw_sum == num_segment) { |
235 | 125k | ptr_num_ext_sort_sect_in_sets[num_ext_sorted_sect_in_sets_idx] = counter; |
236 | 125k | num_ext_sorted_sect_in_sets_idx++; |
237 | 125k | if (num_ext_sorted_sect_in_sets_idx >= MAX_HCR_SETS) { |
238 | 2.82k | return; |
239 | 2.82k | } |
240 | 122k | counter = 0; |
241 | 122k | cw_sum = 0; |
242 | 122k | } |
243 | 588k | } |
244 | 33.6k | ptr_num_ext_sort_sect_in_sets[num_ext_sorted_sect_in_sets_idx] = counter; |
245 | 33.6k | } |
246 | | |
247 | | static VOID ixheaacd_validate_hcr_sideinfo(WORD8 cb, WORD32 num_line, |
248 | 580k | UWORD32 *error_word) { |
249 | 580k | if (cb < ZERO_HCB || cb >= MAX_CB_CHECK || cb == (ESC_HCB + 1)) { |
250 | 0 | *error_word |= (ERROR_POS << 4); |
251 | 0 | } |
252 | 580k | if (num_line < 0 || num_line > 1024) { |
253 | 0 | *error_word |= (ERROR_POS << 5); |
254 | 0 | } |
255 | 580k | } |
256 | | |
257 | | static VOID ixheaacd_validate_hcr_lengths(WORD8 longest_cw_len, |
258 | | WORD16 reordered_spec_data_len, |
259 | 40.2k | UWORD32 *error_word) { |
260 | 40.2k | if (reordered_spec_data_len < longest_cw_len) { |
261 | 180 | *error_word |= (ERROR_POS << 8); |
262 | 180 | } |
263 | 40.2k | } |
264 | | |
265 | | UWORD32 ixheaacd_huff_code_reorder_init( |
266 | | ia_hcr_info_struct *ptr_hcr_info, |
267 | | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, |
268 | 40.2k | ia_aac_dec_tables_struct *ptr_aac_tables, ia_bit_buf_struct *itt_bit_buff) { |
269 | 40.2k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_channel_info->str_ics_info; |
270 | 40.2k | WORD16 *ptr_num_sect_lines; |
271 | 40.2k | UWORD8 *ptr_cb; |
272 | 40.2k | WORD16 num_sect; |
273 | 40.2k | WORD8 cb; |
274 | 40.2k | WORD32 num_line; |
275 | 40.2k | WORD32 i; |
276 | | |
277 | 40.2k | ptr_hcr_info->str_dec_io.reordered_spec_data_len = |
278 | 40.2k | ptr_aac_dec_channel_info->reorder_spect_data_len; |
279 | 40.2k | ptr_hcr_info->str_dec_io.longest_cw_len = |
280 | 40.2k | ptr_aac_dec_channel_info->longest_cw_len; |
281 | 40.2k | ptr_hcr_info->str_dec_io.ptr_quant_spec_coeff_base = |
282 | 40.2k | ptr_aac_dec_channel_info->ptr_spec_coeff; |
283 | 40.2k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx = 0; |
284 | 40.2k | ptr_hcr_info->str_dec_io.ptr_cb = ptr_aac_dec_channel_info->cb4_hcr_arr; |
285 | 40.2k | ptr_hcr_info->str_dec_io.ptr_num_line_in_sect = |
286 | 40.2k | ptr_aac_dec_channel_info->num_line_in_sec4_hcr_arr; |
287 | 40.2k | ptr_hcr_info->str_dec_io.num_sect = ptr_aac_dec_channel_info->number_sect; |
288 | 40.2k | ptr_hcr_info->str_dec_io.err_log = 0; |
289 | 40.2k | ptr_hcr_info->str_non_pcw_side_info.ptr_result_base = |
290 | 40.2k | ptr_aac_dec_channel_info->ptr_spec_coeff; |
291 | | |
292 | 40.2k | ptr_hcr_info->str_dec_io.bit_str_idx = |
293 | 40.2k | itt_bit_buff->size - itt_bit_buff->cnt_bits; |
294 | 40.2k | itt_bit_buff->byte_ptr = (UWORD8 *)ptr_aac_dec_channel_info->scratch_buf_ptr; |
295 | 40.2k | itt_bit_buff->ptr_start = (UWORD8 *)ptr_aac_dec_channel_info->scratch_buf_ptr; |
296 | | |
297 | 40.2k | if (ptr_aac_dec_channel_info->str_ics_info.window_sequence == |
298 | 40.2k | EIGHT_SHORT_SEQUENCE) { |
299 | 20.4k | WORD16 band; |
300 | 20.4k | WORD16 max_band; |
301 | 20.4k | WORD8 group; |
302 | 20.4k | WORD8 win_group_len; |
303 | 20.4k | WORD8 window; |
304 | 20.4k | WORD8 num_unit_in_band; |
305 | 20.4k | WORD8 cnt_unit_in_band; |
306 | 20.4k | WORD8 grp_win; |
307 | 20.4k | WORD8 cb_prev; |
308 | | |
309 | 20.4k | WORD8 *ptr_code_book; |
310 | 20.4k | const WORD16 *band_offsets; |
311 | 20.4k | WORD16 num_groups; |
312 | | |
313 | 20.4k | ptr_code_book = ptr_aac_dec_channel_info->ptr_code_book; |
314 | 20.4k | ptr_num_sect_lines = ptr_hcr_info->str_dec_io.ptr_num_line_in_sect; |
315 | 20.4k | ptr_cb = ptr_hcr_info->str_dec_io.ptr_cb; |
316 | 20.4k | band_offsets = (WORD16 *)ixheaacd_getscalefactorbandoffsets(ptr_ics_info, |
317 | 20.4k | ptr_aac_tables); |
318 | 20.4k | num_groups = ptr_ics_info->num_window_groups; |
319 | | |
320 | 20.4k | num_line = 0; |
321 | 20.4k | num_sect = 0; |
322 | 20.4k | cb = ptr_code_book[0]; |
323 | 20.4k | cb_prev = ptr_code_book[0]; |
324 | | |
325 | 20.4k | *ptr_cb++ = cb_prev; |
326 | | |
327 | 20.4k | max_band = ptr_ics_info->max_sfb; |
328 | 177k | for (band = 0; band < max_band; band++) { |
329 | 156k | num_unit_in_band = ((band_offsets[band + 1] - band_offsets[band]) >> 2); |
330 | 446k | for (cnt_unit_in_band = num_unit_in_band; cnt_unit_in_band != 0; |
331 | 289k | cnt_unit_in_band--) { |
332 | 991k | for (window = 0, group = 0; group < num_groups; group++) { |
333 | 701k | win_group_len = ptr_ics_info->window_group_length[group]; |
334 | 3.01M | for (grp_win = win_group_len; grp_win != 0; grp_win--, window++) { |
335 | 2.31M | cb = ptr_code_book[group * 16 + band]; |
336 | 2.31M | if (cb != cb_prev) { |
337 | 560k | ixheaacd_validate_hcr_sideinfo(cb, num_line, |
338 | 560k | &ptr_hcr_info->str_dec_io.err_log); |
339 | 560k | if (ptr_hcr_info->str_dec_io.err_log != 0) { |
340 | 0 | return (ptr_hcr_info->str_dec_io.err_log); |
341 | 0 | } |
342 | 560k | *ptr_cb++ = cb; |
343 | 560k | *ptr_num_sect_lines++ = num_line; |
344 | 560k | num_sect++; |
345 | | |
346 | 560k | cb_prev = cb; |
347 | 560k | num_line = LINES_PER_UNIT; |
348 | 1.75M | } else { |
349 | 1.75M | num_line += LINES_PER_UNIT; |
350 | 1.75M | } |
351 | 2.31M | } |
352 | 701k | } |
353 | 289k | } |
354 | 156k | } |
355 | | |
356 | 20.4k | num_sect++; |
357 | | |
358 | 20.4k | ixheaacd_validate_hcr_sideinfo(cb, num_line, |
359 | 20.4k | &ptr_hcr_info->str_dec_io.err_log); |
360 | 20.4k | if (num_sect <= 0 || num_sect > 1024 / 2) { |
361 | 0 | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 7); |
362 | 0 | } |
363 | 20.4k | ixheaacd_validate_hcr_lengths( |
364 | 20.4k | ptr_hcr_info->str_dec_io.longest_cw_len, |
365 | 20.4k | ptr_hcr_info->str_dec_io.reordered_spec_data_len, |
366 | 20.4k | &ptr_hcr_info->str_dec_io.err_log); |
367 | 20.4k | if (ptr_hcr_info->str_dec_io.err_log != 0) { |
368 | 74 | return (ptr_hcr_info->str_dec_io.err_log); |
369 | 74 | } |
370 | | |
371 | 20.3k | *ptr_cb = cb; |
372 | 20.3k | *ptr_num_sect_lines = num_line; |
373 | 20.3k | ptr_hcr_info->str_dec_io.num_sect = num_sect; |
374 | | |
375 | 20.3k | } else { |
376 | 19.8k | ixheaacd_validate_hcr_lengths( |
377 | 19.8k | ptr_hcr_info->str_dec_io.longest_cw_len, |
378 | 19.8k | ptr_hcr_info->str_dec_io.reordered_spec_data_len, |
379 | 19.8k | &ptr_hcr_info->str_dec_io.err_log); |
380 | 19.8k | num_sect = ptr_hcr_info->str_dec_io.num_sect; |
381 | 19.8k | ptr_num_sect_lines = ptr_hcr_info->str_dec_io.ptr_num_line_in_sect; |
382 | 19.8k | ptr_cb = ptr_hcr_info->str_dec_io.ptr_cb; |
383 | 19.8k | if (num_sect <= 0 || num_sect > 64) { |
384 | 75 | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 6); |
385 | 75 | num_sect = 0; |
386 | 75 | } |
387 | | |
388 | 117k | for (i = num_sect; i != 0; i--) { |
389 | 97.4k | cb = *ptr_cb++; |
390 | | |
391 | 97.4k | if (cb < ZERO_HCB || cb >= MAX_CB_CHECK || cb == (ESC_HCB + 1)) { |
392 | 0 | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 2); |
393 | 0 | } |
394 | | |
395 | 97.4k | num_line = *ptr_num_sect_lines++; |
396 | | |
397 | 97.4k | if ((num_line <= 0) || (num_line > 1024)) { |
398 | 124 | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 3); |
399 | 124 | } |
400 | 97.4k | } |
401 | 19.8k | if (ptr_hcr_info->str_dec_io.err_log != 0) { |
402 | 192 | return (ptr_hcr_info->str_dec_io.err_log); |
403 | 192 | } |
404 | 19.8k | } |
405 | | |
406 | 39.9k | ptr_cb = ptr_hcr_info->str_dec_io.ptr_cb; |
407 | 716k | for (i = 0; i < num_sect; i++) { |
408 | 676k | if ((*ptr_cb == NOISE_HCB) || (*ptr_cb == INTENSITY_HCB2) || |
409 | 619k | (*ptr_cb == INTENSITY_HCB)) { |
410 | 99.1k | *ptr_cb = 0; |
411 | 99.1k | } |
412 | 676k | ptr_cb++; |
413 | 676k | } |
414 | | |
415 | 39.9k | return (ptr_hcr_info->str_dec_io.err_log); |
416 | 40.2k | } |
417 | | |
418 | 39.9k | static VOID ixheaacd_huff_calc_num_cwd(ia_hcr_info_struct *ptr_hcr_info) { |
419 | 39.9k | WORD32 sect_idx; |
420 | 39.9k | UWORD32 num_code_word; |
421 | | |
422 | 39.9k | UWORD32 num_sect = ptr_hcr_info->str_dec_io.num_sect; |
423 | 39.9k | UWORD8 *ptr_cb = ptr_hcr_info->str_dec_io.ptr_cb; |
424 | 39.9k | WORD16 *ptr_num_line_in_sect = ptr_hcr_info->str_dec_io.ptr_num_line_in_sect; |
425 | 39.9k | const UWORD8 *ptr_cb_dim_shift_tbl = |
426 | 39.9k | ptr_hcr_info->table_info.ptr_cb_dim_shift_tbl; |
427 | 39.9k | UWORD16 *ptr_num_cw_in_sect = ptr_hcr_info->sect_info.ptr_num_cw_in_sect; |
428 | | |
429 | 39.9k | num_code_word = 0; |
430 | 716k | for (sect_idx = num_sect; sect_idx != 0; sect_idx--) { |
431 | 676k | *ptr_num_cw_in_sect = |
432 | 676k | *ptr_num_line_in_sect++ >> ptr_cb_dim_shift_tbl[*ptr_cb]; |
433 | 676k | if (*ptr_cb != 0) { |
434 | 563k | num_code_word += *ptr_num_cw_in_sect; |
435 | 563k | } |
436 | 676k | ptr_num_cw_in_sect++; |
437 | 676k | ptr_cb++; |
438 | 676k | } |
439 | 39.9k | ptr_hcr_info->sect_info.num_code_word = num_code_word; |
440 | 39.9k | } |
441 | | |
442 | 39.9k | static VOID ixheaacd_huff_sort_sect_cb_cwd(ia_hcr_info_struct *ptr_hcr_info) { |
443 | 39.9k | UWORD32 i, j, k; |
444 | 39.9k | UWORD8 temp; |
445 | 39.9k | UWORD32 counter; |
446 | 39.9k | UWORD32 start_offset; |
447 | 39.9k | UWORD32 num_zero_sect; |
448 | 39.9k | UWORD8 *ptr_dest; |
449 | 39.9k | UWORD32 num_sect_dec; |
450 | | |
451 | 39.9k | UWORD32 num_sect = ptr_hcr_info->str_dec_io.num_sect; |
452 | 39.9k | UWORD8 *ptr_cb = ptr_hcr_info->str_dec_io.ptr_cb; |
453 | 39.9k | UWORD8 *ptr_sorted_cb = ptr_hcr_info->sect_info.ptr_sorted_cb; |
454 | 39.9k | UWORD16 *ptr_num_cw_in_sect = ptr_hcr_info->sect_info.ptr_num_cw_in_sect; |
455 | 39.9k | UWORD16 *ptr_num_sorted_cw_in_sect = |
456 | 39.9k | ptr_hcr_info->sect_info.ptr_num_sorted_cw_in_sect; |
457 | 39.9k | UWORD8 *ptr_cb_switch = ptr_hcr_info->sect_info.ptr_cb_switch; |
458 | 39.9k | UWORD16 *ptr_reorder_offset = ptr_hcr_info->sect_info.ptr_reorder_offset; |
459 | 39.9k | const UWORD8 *ptr_cb_priority = ptr_hcr_info->table_info.ptr_cb_priority; |
460 | 39.9k | const UWORD8 *ptr_min_cb_pair_tbl = |
461 | 39.9k | ptr_hcr_info->codebook_pairs.ptr_min_cb_pair_tbl; |
462 | 39.9k | const UWORD8 *ptr_max_cb_pair_tbl = |
463 | 39.9k | ptr_hcr_info->codebook_pairs.ptr_max_cb_pair_tbl; |
464 | 39.9k | const UWORD8 *ptr_cb_dim_shift_tbl = |
465 | 39.9k | ptr_hcr_info->table_info.ptr_cb_dim_shift_tbl; |
466 | | |
467 | 39.9k | UWORD32 search_start_idx = 0; |
468 | | |
469 | 39.9k | ptr_dest = ptr_sorted_cb; |
470 | 39.9k | num_zero_sect = 0; |
471 | 716k | for (i = num_sect; i != 0; i--) { |
472 | 676k | if (ptr_cb_priority[*ptr_cb] == 0) { |
473 | 112k | num_zero_sect += 1; |
474 | 112k | } |
475 | 676k | *ptr_dest++ = ptr_cb_priority[*ptr_cb++]; |
476 | 676k | } |
477 | 39.9k | ptr_hcr_info->sect_info.num_sorted_section = num_sect - num_zero_sect; |
478 | 39.9k | ptr_cb = ptr_hcr_info->str_dec_io.ptr_cb; |
479 | | |
480 | 39.9k | num_sect_dec = num_sect - 1; |
481 | 39.9k | if (num_sect_dec > 0) { |
482 | 28.9k | counter = num_sect_dec; |
483 | 665k | for (j = num_sect_dec; j != 0; j--) { |
484 | 14.5M | for (i = 0; i < counter; i++) { |
485 | 13.9M | if (ptr_sorted_cb[i + 1] > ptr_sorted_cb[i]) { |
486 | 5.58M | temp = ptr_sorted_cb[i]; |
487 | 5.58M | ptr_sorted_cb[i] = ptr_sorted_cb[i + 1]; |
488 | 5.58M | ptr_sorted_cb[i + 1] = temp; |
489 | 5.58M | } |
490 | 13.9M | } |
491 | 636k | counter -= 1; |
492 | 636k | } |
493 | 28.9k | } |
494 | | |
495 | 716k | for (i = num_sect; i != 0; i--) { |
496 | 676k | *ptr_cb_switch++ = 0; |
497 | 676k | } |
498 | 39.9k | ptr_cb_switch = ptr_hcr_info->sect_info.ptr_cb_switch; |
499 | | |
500 | 716k | for (j = 0; j < num_sect; j++) { |
501 | 11.3M | for (i = search_start_idx; i < num_sect; i++) { |
502 | 11.3M | if (ptr_cb_switch[i] == 0 && |
503 | 6.26M | (ptr_min_cb_pair_tbl[ptr_sorted_cb[j]] == ptr_cb[i] || |
504 | 5.64M | ptr_max_cb_pair_tbl[ptr_sorted_cb[j]] == ptr_cb[i])) { |
505 | 676k | ptr_cb_switch[i] = 1; |
506 | 676k | ptr_sorted_cb[j] = ptr_cb[i]; |
507 | 676k | ptr_num_sorted_cw_in_sect[j] = ptr_num_cw_in_sect[i]; |
508 | | |
509 | 676k | start_offset = 0; |
510 | 14.6M | for (k = 0; k < i; k++) { |
511 | 13.9M | start_offset += ptr_num_cw_in_sect[k] |
512 | 13.9M | << ptr_cb_dim_shift_tbl[ptr_cb[k]]; |
513 | 13.9M | } |
514 | 676k | ptr_reorder_offset[j] = start_offset; |
515 | | |
516 | 676k | if (i == search_start_idx) { |
517 | 197k | UWORD32 k = i; |
518 | 874k | while (ptr_cb_switch[k++] == 1) search_start_idx++; |
519 | 197k | } |
520 | 676k | break; |
521 | 676k | } |
522 | 11.3M | } |
523 | 676k | } |
524 | 39.9k | } |
525 | | |
526 | 36.4k | static VOID ixheaacd_huff_ext_sect_info(ia_hcr_info_struct *ptr_hcr_info) { |
527 | 36.4k | UWORD32 srt_sec_cnt = 0; |
528 | 36.4k | UWORD32 x_srt_sc_cnt = 0; |
529 | 36.4k | UWORD32 remain_num_cw_sort_sec; |
530 | 36.4k | UWORD32 in_segment_remain_num_cw; |
531 | | |
532 | 36.4k | UWORD32 num_sorted_section = ptr_hcr_info->sect_info.num_sorted_section; |
533 | 36.4k | UWORD8 *ptr_sorted_cb = ptr_hcr_info->sect_info.ptr_sorted_cb; |
534 | 36.4k | UWORD16 *ptr_num_sorted_cw_in_sect = |
535 | 36.4k | ptr_hcr_info->sect_info.ptr_num_sorted_cw_in_sect; |
536 | 36.4k | UWORD8 *ptr_extended_sorted_code_book = |
537 | 36.4k | ptr_hcr_info->sect_info.ptr_ext_sorted_cw; |
538 | 36.4k | UWORD16 *ptr_num_ext_sort_cw_sect = |
539 | 36.4k | ptr_hcr_info->sect_info.ptr_num_ext_sorted_cw_in_sect; |
540 | 36.4k | UWORD32 num_segment = ptr_hcr_info->str_segment_info.num_segment; |
541 | 36.4k | UWORD8 *ptr_ext_sorted_sect_max_cb_len = |
542 | 36.4k | ptr_hcr_info->sect_info.ptr_ext_sorted_sect_max_cb_len; |
543 | 36.4k | WORD8 longest_cw_len = ptr_hcr_info->str_dec_io.longest_cw_len; |
544 | 36.4k | const UWORD8 *ptr_max_cw_len_tbl = |
545 | 36.4k | ptr_hcr_info->table_info.ptr_max_cw_len_tbl; |
546 | | |
547 | 36.4k | remain_num_cw_sort_sec = ptr_num_sorted_cw_in_sect[srt_sec_cnt]; |
548 | 36.4k | in_segment_remain_num_cw = num_segment; |
549 | | |
550 | 770k | while (srt_sec_cnt < num_sorted_section) { |
551 | 734k | if (in_segment_remain_num_cw < remain_num_cw_sort_sec) { |
552 | 170k | ptr_num_ext_sort_cw_sect[x_srt_sc_cnt] = in_segment_remain_num_cw; |
553 | 170k | ptr_extended_sorted_code_book[x_srt_sc_cnt] = ptr_sorted_cb[srt_sec_cnt]; |
554 | | |
555 | 170k | remain_num_cw_sort_sec -= in_segment_remain_num_cw; |
556 | 170k | in_segment_remain_num_cw = num_segment; |
557 | 563k | } else if (in_segment_remain_num_cw == remain_num_cw_sort_sec) { |
558 | 60.7k | ptr_num_ext_sort_cw_sect[x_srt_sc_cnt] = in_segment_remain_num_cw; |
559 | 60.7k | ptr_extended_sorted_code_book[x_srt_sc_cnt] = ptr_sorted_cb[srt_sec_cnt]; |
560 | | |
561 | 60.7k | srt_sec_cnt++; |
562 | 60.7k | remain_num_cw_sort_sec = ptr_num_sorted_cw_in_sect[srt_sec_cnt]; |
563 | 60.7k | in_segment_remain_num_cw = num_segment; |
564 | 503k | } else { |
565 | 503k | ptr_num_ext_sort_cw_sect[x_srt_sc_cnt] = remain_num_cw_sort_sec; |
566 | 503k | ptr_extended_sorted_code_book[x_srt_sc_cnt] = ptr_sorted_cb[srt_sec_cnt]; |
567 | | |
568 | 503k | in_segment_remain_num_cw -= remain_num_cw_sort_sec; |
569 | 503k | srt_sec_cnt++; |
570 | 503k | remain_num_cw_sort_sec = ptr_num_sorted_cw_in_sect[srt_sec_cnt]; |
571 | 503k | } |
572 | 734k | ptr_ext_sorted_sect_max_cb_len[x_srt_sc_cnt] = |
573 | 734k | min(ptr_max_cw_len_tbl[ptr_extended_sorted_code_book[x_srt_sc_cnt]], |
574 | 734k | longest_cw_len); |
575 | | |
576 | 734k | x_srt_sc_cnt += 1; |
577 | | |
578 | 734k | if (x_srt_sc_cnt >= (MAX_SFB_HCR + MAX_HCR_SETS)) { |
579 | 26 | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 28); |
580 | 26 | return; |
581 | 26 | } |
582 | 734k | } |
583 | 36.4k | ptr_num_ext_sort_cw_sect[x_srt_sc_cnt] = 0; |
584 | 36.4k | } |
585 | | |
586 | | static UWORD32 ixheaacd_hcr_prepare_segmentation_grid( |
587 | 39.9k | ia_hcr_info_struct *ptr_hcr_info) { |
588 | 39.9k | UWORD16 i, j; |
589 | 39.9k | UWORD16 num_segment = 0; |
590 | 39.9k | UWORD16 segment_start = 0; |
591 | 39.9k | UWORD8 segment_width; |
592 | 39.9k | UWORD8 last_segment_width; |
593 | 39.9k | UWORD8 sorted_code_book; |
594 | 39.9k | UWORD8 end_flag = 0; |
595 | 39.9k | UWORD16 intermediate_result; |
596 | | |
597 | 39.9k | WORD8 longest_cw_len = ptr_hcr_info->str_dec_io.longest_cw_len; |
598 | 39.9k | WORD16 reordered_spec_data_len = |
599 | 39.9k | ptr_hcr_info->str_dec_io.reordered_spec_data_len; |
600 | 39.9k | UWORD32 num_sorted_section = ptr_hcr_info->sect_info.num_sorted_section; |
601 | 39.9k | UWORD8 *ptr_sorted_cb = ptr_hcr_info->sect_info.ptr_sorted_cb; |
602 | 39.9k | UWORD16 *ptr_num_sorted_cw_in_sect = |
603 | 39.9k | ptr_hcr_info->sect_info.ptr_num_sorted_cw_in_sect; |
604 | 39.9k | UWORD16 *arr_seg_start_l = ptr_hcr_info->str_segment_info.arr_seg_start_l; |
605 | 39.9k | UWORD16 *arr_seg_start_r = ptr_hcr_info->str_segment_info.arr_seg_start_r; |
606 | 39.9k | WORD8 *p_remaining_bits_in_seg = |
607 | 39.9k | ptr_hcr_info->str_segment_info.p_remaining_bits_in_seg; |
608 | 39.9k | UWORD16 bit_str_idx = ptr_hcr_info->str_dec_io.bit_str_idx; |
609 | 39.9k | const UWORD8 *ptr_max_cw_len_tbl = |
610 | 39.9k | ptr_hcr_info->table_info.ptr_max_cw_len_tbl; |
611 | | |
612 | 264k | for (i = num_sorted_section; i != 0; i--) { |
613 | 244k | sorted_code_book = *ptr_sorted_cb++; |
614 | 244k | segment_width = min(ptr_max_cw_len_tbl[sorted_code_book], longest_cw_len); |
615 | | |
616 | 5.06M | for (j = *ptr_num_sorted_cw_in_sect; j != 0; j--) { |
617 | 4.83M | intermediate_result = bit_str_idx + segment_start; |
618 | 4.83M | if ((segment_start + segment_width) <= reordered_spec_data_len) { |
619 | 4.81M | *arr_seg_start_l++ = intermediate_result; |
620 | 4.81M | *arr_seg_start_r++ = intermediate_result + segment_width - 1; |
621 | 4.81M | *p_remaining_bits_in_seg++ = segment_width; |
622 | 4.81M | segment_start += segment_width; |
623 | 4.81M | num_segment += 1; |
624 | 4.81M | } else { |
625 | 20.3k | arr_seg_start_l--; |
626 | 20.3k | arr_seg_start_r--; |
627 | 20.3k | p_remaining_bits_in_seg--; |
628 | 20.3k | segment_start = *arr_seg_start_l - bit_str_idx; |
629 | | |
630 | 20.3k | last_segment_width = reordered_spec_data_len - segment_start; |
631 | 20.3k | *p_remaining_bits_in_seg = last_segment_width; |
632 | 20.3k | *arr_seg_start_r = bit_str_idx + segment_start + last_segment_width - 1; |
633 | 20.3k | end_flag = 1; |
634 | 20.3k | break; |
635 | 20.3k | } |
636 | 4.83M | } |
637 | 244k | ptr_num_sorted_cw_in_sect++; |
638 | 244k | if (end_flag != 0) { |
639 | 20.3k | break; |
640 | 20.3k | } |
641 | 244k | } |
642 | | |
643 | 39.9k | if (num_segment == 0) ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 9); |
644 | | |
645 | 39.9k | ptr_hcr_info->str_segment_info.num_segment = num_segment; |
646 | | |
647 | 39.9k | return (ptr_hcr_info->str_dec_io.err_log); |
648 | 39.9k | } |
649 | | |
650 | | static PLATFORM_INLINE UWORD16 *ixheaacd_huff_dec_pair_hcr_pcw( |
651 | | ia_hcr_info_struct *ptr_hcr_info, ia_bit_buf_struct *it_bit_buff, |
652 | | WORD no_bands, const UWORD16 *code_book_tbl, WORD32 *read_word, |
653 | | WORD32 tbl_sign, const UWORD32 *idx_table, UWORD16 *arr_seg_start_l, |
654 | | WORD32 *read_bits, WORD32 huff_mode, WORD8 *p_remaining_bits_in_seg, |
655 | | WORD32 *ptr_num_decoded_bits) |
656 | | |
657 | 33.9k | { |
658 | 33.9k | WORD32 spec_index = ptr_hcr_info->str_dec_io.quant_spec_coeff_idx; |
659 | 33.9k | WORD32 *spec_coef = |
660 | 33.9k | ptr_hcr_info->str_dec_io.ptr_quant_spec_coeff_base + spec_index; |
661 | 33.9k | WORD16 index, length; |
662 | 33.9k | WORD32 y, z; |
663 | 33.9k | UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; |
664 | 33.9k | WORD32 *bit_pos = &it_bit_buff->bit_pos; |
665 | | |
666 | 3.22M | do { |
667 | 3.22M | UWORD32 read_word1; |
668 | | |
669 | 3.22M | WORD32 read_bit_offset = |
670 | 3.22M | *arr_seg_start_l - (it_bit_buff->size - *read_bits); |
671 | | |
672 | 3.22M | if (read_bit_offset) { |
673 | 3.16M | *read_bits -= read_bit_offset; |
674 | 3.16M | *bit_pos += read_bit_offset; |
675 | 3.16M | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
676 | 3.16M | it_bit_buff->ptr_bit_buf_end); |
677 | 3.16M | } |
678 | 3.22M | *bit_pos = max(0, *bit_pos); |
679 | 3.22M | read_word1 = *read_word << *bit_pos; |
680 | 3.22M | ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl, |
681 | 3.22M | idx_table); |
682 | 3.22M | *bit_pos += length; |
683 | 3.22M | *ptr_num_decoded_bits += length; |
684 | 3.22M | *p_remaining_bits_in_seg -= length; |
685 | 3.22M | *arr_seg_start_l += length; |
686 | 3.22M | *read_bits -= length; |
687 | 3.22M | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
688 | 3.22M | it_bit_buff->ptr_bit_buf_end); |
689 | 3.22M | if (tbl_sign) { |
690 | 75.4k | WORD32 temp_word; |
691 | 75.4k | temp_word = *read_word << *bit_pos; |
692 | 75.4k | y = index / huff_mode; |
693 | 75.4k | z = index - huff_mode * y; |
694 | | |
695 | 75.4k | if (y) { |
696 | 27.7k | if (temp_word & 0x80000000) y = -y; |
697 | | |
698 | 27.7k | temp_word = temp_word << 1; |
699 | 27.7k | *bit_pos += 1; |
700 | 27.7k | *p_remaining_bits_in_seg -= 1; |
701 | 27.7k | *ptr_num_decoded_bits += 1; |
702 | 27.7k | *arr_seg_start_l += 1; |
703 | 27.7k | *read_bits -= 1; |
704 | 27.7k | } |
705 | 75.4k | *spec_coef++ = y; |
706 | 75.4k | spec_index++; |
707 | | |
708 | 75.4k | if (z) { |
709 | 29.0k | if (temp_word & 0x80000000) { |
710 | 15.6k | z = -z; |
711 | 15.6k | } |
712 | 29.0k | temp_word <<= 1; |
713 | 29.0k | *bit_pos += 1; |
714 | 29.0k | *p_remaining_bits_in_seg -= 1; |
715 | 29.0k | *ptr_num_decoded_bits += 1; |
716 | 29.0k | *arr_seg_start_l += 1; |
717 | 29.0k | *read_bits -= 1; |
718 | 29.0k | } |
719 | 75.4k | *spec_coef++ = z; |
720 | 75.4k | spec_index++; |
721 | 3.14M | } else { |
722 | 3.14M | y = (index / huff_mode) - 4; |
723 | 3.14M | z = index - ((y + 4) * huff_mode) - 4; |
724 | | |
725 | 3.14M | *spec_coef++ = y; |
726 | 3.14M | *spec_coef++ = z; |
727 | 3.14M | spec_index += 2; |
728 | 3.14M | } |
729 | 3.22M | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
730 | 3.22M | it_bit_buff->ptr_bit_buf_end); |
731 | 3.22M | no_bands--; |
732 | 3.22M | arr_seg_start_l++; |
733 | 3.22M | p_remaining_bits_in_seg++; |
734 | 3.22M | } while (no_bands != 0); |
735 | | |
736 | 33.9k | it_bit_buff->ptr_read_next = ptr_read_next; |
737 | 33.9k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx = spec_index; |
738 | | |
739 | 33.9k | return arr_seg_start_l; |
740 | 33.9k | } |
741 | | |
742 | | static PLATFORM_INLINE WORD16 ixheaacd_huff_dec_pair_hcr_non_pcw( |
743 | | ia_bit_buf_struct *itt_bit_buff, WORD32 *spec_coef, |
744 | | const UWORD16 *code_book_tbl, WORD32 tbl_sign, const UWORD32 *idx_table, |
745 | | WORD32 huff_mode) |
746 | | |
747 | 318k | { |
748 | 318k | WORD16 index, length; |
749 | 318k | WORD32 y, z; |
750 | 318k | WORD32 read_word1; |
751 | 318k | WORD32 read_word; |
752 | | |
753 | 318k | read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr, |
754 | 318k | itt_bit_buff->bit_count, NULL); |
755 | | |
756 | 318k | ixheaacd_huffman_decode(read_word, &index, &length, code_book_tbl, idx_table); |
757 | 318k | read_word1 = read_word << length; |
758 | 318k | if (tbl_sign) { |
759 | 250k | WORD32 temp_word; |
760 | 250k | temp_word = read_word1; |
761 | 250k | y = index / huff_mode; |
762 | 250k | z = index - huff_mode * y; |
763 | | |
764 | 250k | if (y) { |
765 | 106k | if (temp_word & 0x80000000) y = -y; |
766 | | |
767 | 106k | temp_word = temp_word << 1; |
768 | 106k | length++; |
769 | 106k | } |
770 | 250k | *spec_coef++ = y; |
771 | | |
772 | 250k | if (z) { |
773 | 98.2k | if (temp_word & 0x80000000) { |
774 | 26.4k | z = -z; |
775 | 26.4k | } |
776 | 98.2k | temp_word <<= 1; |
777 | 98.2k | length++; |
778 | 98.2k | } |
779 | 250k | *spec_coef++ = z; |
780 | 250k | } else { |
781 | 67.6k | y = (index / huff_mode) - 4; |
782 | 67.6k | z = index - ((y + 4) * huff_mode) - 4; |
783 | | |
784 | 67.6k | *spec_coef++ = y; |
785 | 67.6k | *spec_coef++ = z; |
786 | 67.6k | } |
787 | | |
788 | 318k | return length; |
789 | 318k | } |
790 | | |
791 | | static PLATFORM_INLINE UWORD16 *ixheaacd_huff_dec_quad_hcr_pcw( |
792 | | ia_hcr_info_struct *ptr_hcr_info, ia_bit_buf_struct *it_bit_buff, |
793 | | WORD no_bands, const UWORD16 *code_book_tbl, WORD32 tbl_sign, |
794 | | const UWORD32 *idx_table, WORD32 *read_word, WORD32 *read_bits, |
795 | | UWORD16 *arr_seg_start_l, WORD8 *p_remaining_bits_in_seg, |
796 | 19.1k | WORD32 *ptr_num_decoded_bits) { |
797 | 19.1k | WORD16 index, length; |
798 | | |
799 | 19.1k | UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; |
800 | 19.1k | WORD32 spec_index = ptr_hcr_info->str_dec_io.quant_spec_coeff_idx; |
801 | 19.1k | WORD32 *spec_coef = |
802 | 19.1k | ptr_hcr_info->str_dec_io.ptr_quant_spec_coeff_base + spec_index; |
803 | 19.1k | WORD32 *bit_pos = &it_bit_buff->bit_pos; |
804 | | |
805 | 79.2k | do { |
806 | 79.2k | UWORD32 read_word1; |
807 | | |
808 | 79.2k | WORD32 read_bit_offset = |
809 | 79.2k | *arr_seg_start_l - (it_bit_buff->size - *read_bits); |
810 | | |
811 | 79.2k | if (read_bit_offset) { |
812 | 69.9k | *read_bits -= read_bit_offset; |
813 | 69.9k | *bit_pos += read_bit_offset; |
814 | 69.9k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
815 | 69.9k | it_bit_buff->ptr_bit_buf_end); |
816 | 69.9k | } |
817 | 79.2k | *bit_pos = max(0, *bit_pos); |
818 | 79.2k | read_word1 = *read_word << *bit_pos; |
819 | 79.2k | ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl, |
820 | 79.2k | idx_table); |
821 | 79.2k | *bit_pos += length; |
822 | 79.2k | *p_remaining_bits_in_seg -= length; |
823 | 79.2k | *read_bits -= length; |
824 | 79.2k | *ptr_num_decoded_bits += length; |
825 | 79.2k | *arr_seg_start_l += length; |
826 | 79.2k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
827 | 79.2k | it_bit_buff->ptr_bit_buf_end); |
828 | 79.2k | if (tbl_sign) { |
829 | 30.8k | WORD32 temp_word; |
830 | 30.8k | WORD32 w, x, y, z; |
831 | 30.8k | temp_word = *read_word << *bit_pos; |
832 | 30.8k | w = index / 27; |
833 | 30.8k | index = index - w * 27; |
834 | 30.8k | x = index / 9; |
835 | 30.8k | index = index - x * 9; |
836 | 30.8k | y = index / 3; |
837 | 30.8k | z = index - y * 3; |
838 | 30.8k | if (w) { |
839 | 20.9k | if (temp_word & 0x80000000) w = -w; |
840 | 20.9k | temp_word <<= 1; |
841 | 20.9k | *bit_pos += 1; |
842 | 20.9k | *p_remaining_bits_in_seg -= 1; |
843 | 20.9k | *read_bits -= 1; |
844 | 20.9k | *ptr_num_decoded_bits += 1; |
845 | 20.9k | *arr_seg_start_l += 1; |
846 | 20.9k | } |
847 | 30.8k | *spec_coef++ = w; |
848 | 30.8k | spec_index++; |
849 | | |
850 | 30.8k | if (x) { |
851 | 16.7k | if (temp_word & 0x80000000) x = -x; |
852 | 16.7k | temp_word <<= 1; |
853 | 16.7k | *bit_pos += 1; |
854 | 16.7k | *p_remaining_bits_in_seg -= 1; |
855 | 16.7k | *read_bits -= 1; |
856 | 16.7k | *ptr_num_decoded_bits += 1; |
857 | 16.7k | *arr_seg_start_l += 1; |
858 | 16.7k | } |
859 | 30.8k | *spec_coef++ = x; |
860 | 30.8k | spec_index++; |
861 | 30.8k | if (y) { |
862 | 22.6k | if (temp_word & 0x80000000) y = -y; |
863 | 22.6k | temp_word <<= 1; |
864 | 22.6k | *bit_pos += 1; |
865 | 22.6k | *p_remaining_bits_in_seg -= 1; |
866 | 22.6k | *read_bits -= 1; |
867 | 22.6k | *ptr_num_decoded_bits += 1; |
868 | 22.6k | *arr_seg_start_l += 1; |
869 | 22.6k | } |
870 | 30.8k | *spec_coef++ = y; |
871 | 30.8k | spec_index++; |
872 | 30.8k | if (z) { |
873 | 19.3k | if (temp_word & 0x80000000) z = -z; |
874 | 19.3k | temp_word <<= 1; |
875 | 19.3k | *bit_pos += 1; |
876 | 19.3k | *p_remaining_bits_in_seg -= 1; |
877 | 19.3k | *read_bits -= 1; |
878 | 19.3k | *ptr_num_decoded_bits += 1; |
879 | 19.3k | *arr_seg_start_l += 1; |
880 | 19.3k | } |
881 | 30.8k | *spec_coef++ = z; |
882 | 30.8k | spec_index++; |
883 | | |
884 | 30.8k | } |
885 | | |
886 | 48.3k | else { |
887 | 48.3k | WORD32 w, x, y, z; |
888 | | |
889 | 48.3k | w = index / 27 - 1; |
890 | 48.3k | index = index - (w + 1) * 27; |
891 | 48.3k | x = index / 9 - 1; |
892 | 48.3k | index = index - (x + 1) * 9; |
893 | 48.3k | y = index / 3 - 1; |
894 | 48.3k | z = index - ((y + 1) * 3) - 1; |
895 | 48.3k | *spec_coef++ = w; |
896 | | |
897 | 48.3k | *spec_coef++ = x; |
898 | | |
899 | 48.3k | *spec_coef++ = y; |
900 | | |
901 | 48.3k | *spec_coef++ = z; |
902 | 48.3k | spec_index += 4; |
903 | 48.3k | } |
904 | | |
905 | 79.2k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
906 | 79.2k | it_bit_buff->ptr_bit_buf_end); |
907 | 79.2k | arr_seg_start_l++; |
908 | 79.2k | p_remaining_bits_in_seg++; |
909 | 79.2k | no_bands--; |
910 | 79.2k | } while (no_bands != 0); |
911 | | |
912 | 19.1k | it_bit_buff->ptr_read_next = ptr_read_next; |
913 | 19.1k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx = spec_index; |
914 | | |
915 | 19.1k | return arr_seg_start_l; |
916 | 19.1k | } |
917 | | |
918 | | static UWORD16 *ixheaacd_huff_dec_word_hcr_pcw( |
919 | | ia_hcr_info_struct *ptr_hcr_info, ia_bit_buf_struct *it_bit_buff, |
920 | | WORD no_bands, const UWORD16 *code_book_tbl, WORD32 *read_word, |
921 | | const UWORD32 *idx_table, UWORD16 *arr_seg_start_l, WORD32 *read_bits, |
922 | 187k | WORD8 *p_remaining_bits_in_seg, WORD32 *ptr_num_decoded_bits) { |
923 | 187k | WORD32 sp1, sp2; |
924 | 187k | WORD32 flush_cw; |
925 | 187k | WORD32 i, value, norm_val, off; |
926 | 187k | WORD32 out1, out2; |
927 | 187k | WORD16 index; |
928 | 187k | WORD32 length; |
929 | 187k | UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; |
930 | 187k | WORD32 spec_index = ptr_hcr_info->str_dec_io.quant_spec_coeff_idx; |
931 | 187k | WORD32 *spec_coef = |
932 | 187k | ptr_hcr_info->str_dec_io.ptr_quant_spec_coeff_base + spec_index; |
933 | 187k | WORD32 *bit_pos = &it_bit_buff->bit_pos; |
934 | | |
935 | 1.51M | do { |
936 | 1.51M | UWORD32 read_word1; |
937 | | |
938 | 1.51M | WORD32 read_bit_offset = |
939 | 1.51M | *arr_seg_start_l - (it_bit_buff->size - *read_bits); |
940 | | |
941 | 1.51M | if (read_bit_offset) { |
942 | 1.46M | *read_bits -= read_bit_offset; |
943 | 1.46M | *bit_pos += read_bit_offset; |
944 | 1.46M | ixheaacd_aac_read_byte_corr1(&ptr_read_next, bit_pos, read_word, |
945 | 1.46M | it_bit_buff->ptr_bit_buf_end); |
946 | 1.46M | } |
947 | 1.51M | *bit_pos = max(0, *bit_pos); |
948 | 1.51M | read_word1 = *read_word << *bit_pos; |
949 | 1.51M | ixheaacd_huff_sfb_table(read_word1, &index, &length, code_book_tbl, |
950 | 1.51M | idx_table); |
951 | 1.51M | *bit_pos += length; |
952 | 1.51M | *read_bits -= length; |
953 | 1.51M | *arr_seg_start_l += length; |
954 | 1.51M | *p_remaining_bits_in_seg -= length; |
955 | 1.51M | *ptr_num_decoded_bits += length; |
956 | 1.51M | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
957 | 1.51M | it_bit_buff->ptr_bit_buf_end); |
958 | | |
959 | 1.51M | out1 = index / 17; |
960 | 1.51M | out2 = index - out1 * 17; |
961 | 1.51M | flush_cw = *read_word << *bit_pos; |
962 | | |
963 | 1.51M | sp1 = out1; |
964 | 1.51M | sp2 = out2; |
965 | | |
966 | 1.51M | if (out1) { |
967 | 1.17M | if (flush_cw & 0x80000000) { |
968 | 640k | out1 = -out1; |
969 | 640k | } |
970 | 1.17M | *bit_pos += 1; |
971 | 1.17M | *read_bits -= 1; |
972 | 1.17M | *p_remaining_bits_in_seg -= 1; |
973 | 1.17M | *ptr_num_decoded_bits += 1; |
974 | 1.17M | *arr_seg_start_l += 1; |
975 | 1.17M | flush_cw = (WORD32)flush_cw << 1; |
976 | 1.17M | } |
977 | | |
978 | 1.51M | if (out2) { |
979 | 1.19M | *bit_pos += 1; |
980 | 1.19M | *read_bits -= 1; |
981 | 1.19M | *p_remaining_bits_in_seg -= 1; |
982 | 1.19M | *ptr_num_decoded_bits += 1; |
983 | 1.19M | *arr_seg_start_l += 1; |
984 | 1.19M | if (flush_cw & 0x80000000) { |
985 | 492k | out2 = -out2; |
986 | 492k | } |
987 | 1.19M | } |
988 | | |
989 | 1.51M | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
990 | 1.51M | it_bit_buff->ptr_bit_buf_end); |
991 | | |
992 | 1.51M | if (sp1 == 16) { |
993 | 165k | i = 4; |
994 | 165k | value = ixheaac_extu(*read_word, *bit_pos, 23); |
995 | 165k | value = value | 0xfffffe00; |
996 | 165k | norm_val = ixheaac_norm32(value); |
997 | | |
998 | 165k | i += (norm_val - 22); |
999 | 165k | *bit_pos += (norm_val - 21); |
1000 | 165k | *p_remaining_bits_in_seg -= (norm_val - 21); |
1001 | 165k | *ptr_num_decoded_bits += (norm_val - 21); |
1002 | 165k | *read_bits -= (norm_val - 21); |
1003 | 165k | *arr_seg_start_l += (norm_val - 21); |
1004 | | |
1005 | 165k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
1006 | 165k | it_bit_buff->ptr_bit_buf_end); |
1007 | | |
1008 | 165k | off = ixheaac_extu(*read_word, *bit_pos, 32 - i); |
1009 | | |
1010 | 165k | *bit_pos += i; |
1011 | 165k | *p_remaining_bits_in_seg -= i; |
1012 | 165k | *ptr_num_decoded_bits += i; |
1013 | 165k | *read_bits -= i; |
1014 | 165k | *arr_seg_start_l += i; |
1015 | | |
1016 | 165k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
1017 | 165k | it_bit_buff->ptr_bit_buf_end); |
1018 | 165k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
1019 | 165k | it_bit_buff->ptr_bit_buf_end); |
1020 | | |
1021 | 165k | i = off + ((WORD32)1 << i); |
1022 | | |
1023 | 165k | if (out1 < 0) |
1024 | 83.2k | *spec_coef++ = -i; |
1025 | 82.6k | else |
1026 | 82.6k | *spec_coef++ = i; |
1027 | 165k | spec_index++; |
1028 | 1.35M | } else { |
1029 | 1.35M | *spec_coef++ = out1; |
1030 | 1.35M | spec_index++; |
1031 | 1.35M | } |
1032 | | |
1033 | 1.51M | if (sp2 == 16) { |
1034 | 134k | i = 4; |
1035 | 134k | value = ixheaac_extu(*read_word, *bit_pos, 23); |
1036 | 134k | value = value | 0xfffffe00; |
1037 | 134k | norm_val = ixheaac_norm32(value); |
1038 | | |
1039 | 134k | i += (norm_val - 22); |
1040 | | |
1041 | 134k | *bit_pos += (norm_val - 21); |
1042 | 134k | *read_bits -= (norm_val - 21); |
1043 | 134k | *p_remaining_bits_in_seg -= (norm_val - 21); |
1044 | 134k | *ptr_num_decoded_bits += (norm_val - 21); |
1045 | 134k | *arr_seg_start_l += (norm_val - 21); |
1046 | 134k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
1047 | 134k | it_bit_buff->ptr_bit_buf_end); |
1048 | | |
1049 | 134k | off = ixheaac_extu(*read_word, *bit_pos, 32 - i); |
1050 | | |
1051 | 134k | *bit_pos += i; |
1052 | 134k | *p_remaining_bits_in_seg -= i; |
1053 | 134k | *ptr_num_decoded_bits += i; |
1054 | 134k | *read_bits -= i; |
1055 | 134k | *arr_seg_start_l += i; |
1056 | | |
1057 | 134k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
1058 | 134k | it_bit_buff->ptr_bit_buf_end); |
1059 | 134k | ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word, |
1060 | 134k | it_bit_buff->ptr_bit_buf_end); |
1061 | | |
1062 | 134k | i = off + ((WORD32)1 << i); |
1063 | | |
1064 | 134k | if (out2 < 0) |
1065 | 35.0k | *spec_coef++ = -i; |
1066 | 99.0k | else |
1067 | 99.0k | *spec_coef++ = i; |
1068 | 134k | spec_index++; |
1069 | 1.38M | } else { |
1070 | 1.38M | *spec_coef++ = out2; |
1071 | 1.38M | spec_index++; |
1072 | 1.38M | } |
1073 | | |
1074 | 1.51M | arr_seg_start_l++; |
1075 | 1.51M | p_remaining_bits_in_seg++; |
1076 | | |
1077 | 1.51M | no_bands--; |
1078 | 1.51M | } while (no_bands != 0); |
1079 | | |
1080 | 187k | it_bit_buff->ptr_read_next = ptr_read_next; |
1081 | 187k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx = spec_index; |
1082 | | |
1083 | 187k | return arr_seg_start_l; |
1084 | 187k | } |
1085 | | |
1086 | | static VOID ixheaacd_decode_pcw(ia_bit_buf_struct *itt_bit_buff, |
1087 | | ia_hcr_info_struct *ptr_hcr_info, |
1088 | 36.4k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
1089 | 36.4k | UWORD16 ext_sort_sec; |
1090 | 36.4k | UWORD16 cur_ext_sort_cw_sec; |
1091 | 36.4k | UWORD8 codebook; |
1092 | 36.4k | UWORD8 dimension; |
1093 | 36.4k | WORD32 increment; |
1094 | | |
1095 | 36.4k | WORD32 num_ext_sorted_cw_in_sect_idx = |
1096 | 36.4k | ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx; |
1097 | 36.4k | UWORD8 *ptr_ext_sorted_cw = ptr_hcr_info->sect_info.ptr_ext_sorted_cw; |
1098 | 36.4k | WORD32 ext_sorted_cw_idx = ptr_hcr_info->sect_info.ext_sorted_cw_idx; |
1099 | 36.4k | UWORD16 *ptr_num_ext_sorted_sect_in_sets = |
1100 | 36.4k | ptr_hcr_info->sect_info.ptr_num_ext_sorted_sect_in_sets; |
1101 | 36.4k | WORD32 num_ext_sorted_sect_in_sets_idx = |
1102 | 36.4k | ptr_hcr_info->sect_info.num_ext_sorted_sect_in_sets_idx; |
1103 | 36.4k | WORD32 *ptr_quant_spec_coeff = |
1104 | 36.4k | ptr_hcr_info->str_dec_io.ptr_quant_spec_coeff_base; |
1105 | 36.4k | UWORD16 *arr_seg_start_l = ptr_hcr_info->str_segment_info.arr_seg_start_l; |
1106 | 36.4k | WORD8 *p_remaining_bits_in_seg = |
1107 | 36.4k | ptr_hcr_info->str_segment_info.p_remaining_bits_in_seg; |
1108 | 36.4k | UWORD8 *ptr_ext_sorted_sect_max_cb_len = |
1109 | 36.4k | ptr_hcr_info->sect_info.ptr_ext_sorted_sect_max_cb_len; |
1110 | 36.4k | WORD32 ext_sorted_sect_max_cb_len_idx = |
1111 | 36.4k | ptr_hcr_info->sect_info.ext_sorted_sect_max_cb_len_idx; |
1112 | 36.4k | UWORD8 max_allowed_cw_len; |
1113 | 36.4k | WORD32 num_decoded_bits; |
1114 | 36.4k | const UWORD8 *ptr_cb_dimension_tbl = |
1115 | 36.4k | ptr_hcr_info->table_info.ptr_cb_dimension_tbl; |
1116 | | |
1117 | 36.4k | WORD32 read_word = ixheaacd_aac_showbits_32( |
1118 | 36.4k | itt_bit_buff->ptr_read_next, itt_bit_buff->cnt_bits, &increment); |
1119 | 36.4k | WORD32 read_bits = itt_bit_buff->cnt_bits; |
1120 | | |
1121 | 36.4k | itt_bit_buff->ptr_read_next += increment; |
1122 | | |
1123 | 36.4k | for (ext_sort_sec = |
1124 | 36.4k | ptr_num_ext_sorted_sect_in_sets[num_ext_sorted_sect_in_sets_idx]; |
1125 | 276k | ext_sort_sec != 0; ext_sort_sec--) { |
1126 | 240k | codebook = ptr_ext_sorted_cw[ext_sorted_cw_idx]; |
1127 | 240k | if (codebook <= 0) return; |
1128 | | |
1129 | 240k | ext_sorted_cw_idx++; |
1130 | 240k | if (ext_sorted_cw_idx >= (MAX_SFB_HCR + MAX_HCR_SETS)) { |
1131 | 0 | return; |
1132 | 0 | } |
1133 | 240k | dimension = ptr_cb_dimension_tbl[codebook]; |
1134 | 240k | max_allowed_cw_len = |
1135 | 240k | ptr_ext_sorted_sect_max_cb_len[ext_sorted_sect_max_cb_len_idx]; |
1136 | 240k | ext_sorted_sect_max_cb_len_idx++; |
1137 | 240k | if (ext_sorted_sect_max_cb_len_idx >= (MAX_SFB_HCR + MAX_HCR_SETS)) { |
1138 | 0 | return; |
1139 | 0 | } |
1140 | | |
1141 | 240k | if (codebook <= 4) { |
1142 | 19.1k | WORD32 tbl_sign = 0; |
1143 | 19.1k | const UWORD16 *cb_table = |
1144 | 19.1k | (UWORD16 *)(ptr_aac_tables->code_book[codebook]); |
1145 | 19.1k | const UWORD32 *idx_table = |
1146 | 19.1k | (UWORD32 *)(ptr_aac_tables->index_table[codebook]); |
1147 | | |
1148 | 19.1k | if (codebook > 2) { |
1149 | 5.91k | tbl_sign = 1; |
1150 | 5.91k | } |
1151 | | |
1152 | 19.1k | { |
1153 | 19.1k | num_decoded_bits = 0; |
1154 | 19.1k | cur_ext_sort_cw_sec = |
1155 | 19.1k | ptr_hcr_info->sect_info |
1156 | 19.1k | .ptr_num_ext_sorted_cw_in_sect[num_ext_sorted_cw_in_sect_idx]; |
1157 | | |
1158 | 19.1k | arr_seg_start_l = ixheaacd_huff_dec_quad_hcr_pcw( |
1159 | 19.1k | ptr_hcr_info, itt_bit_buff, cur_ext_sort_cw_sec, cb_table, tbl_sign, |
1160 | 19.1k | idx_table, &read_word, &read_bits, arr_seg_start_l, |
1161 | 19.1k | p_remaining_bits_in_seg, &num_decoded_bits); |
1162 | | |
1163 | 19.1k | p_remaining_bits_in_seg += cur_ext_sort_cw_sec; |
1164 | | |
1165 | 19.1k | if (cur_ext_sort_cw_sec * max_allowed_cw_len < num_decoded_bits) { |
1166 | 6.90k | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 19); |
1167 | 6.90k | } |
1168 | | |
1169 | 19.1k | if (1 == |
1170 | 19.1k | ixheaacd_err_detect_pcw_segment( |
1171 | 19.1k | *p_remaining_bits_in_seg, ptr_hcr_info, PCW, |
1172 | 19.1k | ptr_quant_spec_coeff + |
1173 | 19.1k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx - dimension, |
1174 | 19.1k | dimension)) { |
1175 | 0 | return; |
1176 | 0 | } |
1177 | 19.1k | } |
1178 | 221k | } else if (codebook < 11) { |
1179 | 33.9k | { |
1180 | 33.9k | WORD32 tbl_sign = 0; |
1181 | 33.9k | WORD32 huff_mode = 9; |
1182 | 33.9k | const UWORD16 *cb_table = |
1183 | 33.9k | (UWORD16 *)(ptr_aac_tables->code_book[codebook]); |
1184 | 33.9k | const UWORD32 *idx_table = |
1185 | 33.9k | (UWORD32 *)(ptr_aac_tables->index_table[codebook]); |
1186 | 33.9k | num_decoded_bits = 0; |
1187 | | |
1188 | 33.9k | if (codebook > 6) { |
1189 | 20.9k | if (codebook > 8) |
1190 | 17.7k | huff_mode = 13; |
1191 | 3.21k | else |
1192 | 3.21k | huff_mode = 8; |
1193 | 20.9k | tbl_sign = 1; |
1194 | 20.9k | } |
1195 | | |
1196 | 33.9k | cur_ext_sort_cw_sec = |
1197 | 33.9k | ptr_hcr_info->sect_info |
1198 | 33.9k | .ptr_num_ext_sorted_cw_in_sect[num_ext_sorted_cw_in_sect_idx]; |
1199 | | |
1200 | 33.9k | arr_seg_start_l = ixheaacd_huff_dec_pair_hcr_pcw( |
1201 | 33.9k | ptr_hcr_info, itt_bit_buff, cur_ext_sort_cw_sec, cb_table, |
1202 | 33.9k | &read_word, tbl_sign, idx_table, arr_seg_start_l, &read_bits, |
1203 | 33.9k | huff_mode, p_remaining_bits_in_seg, &num_decoded_bits); |
1204 | | |
1205 | 33.9k | p_remaining_bits_in_seg += cur_ext_sort_cw_sec; |
1206 | | |
1207 | 33.9k | if (cur_ext_sort_cw_sec * max_allowed_cw_len < num_decoded_bits) { |
1208 | 13.4k | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 18); |
1209 | 13.4k | } |
1210 | | |
1211 | 33.9k | if (1 == |
1212 | 33.9k | ixheaacd_err_detect_pcw_segment( |
1213 | 33.9k | *p_remaining_bits_in_seg, ptr_hcr_info, PCW_SIGN, |
1214 | 33.9k | ptr_quant_spec_coeff + |
1215 | 33.9k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx - dimension, |
1216 | 33.9k | dimension)) { |
1217 | 0 | return; |
1218 | 0 | } |
1219 | 33.9k | } |
1220 | 187k | } else if ((codebook >= 11)) { |
1221 | 187k | const UWORD32 *idx_table = |
1222 | 187k | ptr_aac_tables->pstr_huffmann_tables->idx_table_hf11; |
1223 | 187k | const UWORD16 *cb_table = |
1224 | 187k | ptr_aac_tables->pstr_huffmann_tables->input_table_cb11; |
1225 | 187k | num_decoded_bits = 0; |
1226 | | |
1227 | 187k | cur_ext_sort_cw_sec = |
1228 | 187k | ptr_hcr_info->sect_info |
1229 | 187k | .ptr_num_ext_sorted_cw_in_sect[num_ext_sorted_cw_in_sect_idx]; |
1230 | | |
1231 | 187k | arr_seg_start_l = ixheaacd_huff_dec_word_hcr_pcw( |
1232 | 187k | ptr_hcr_info, itt_bit_buff, cur_ext_sort_cw_sec, cb_table, &read_word, |
1233 | 187k | idx_table, arr_seg_start_l, &read_bits, p_remaining_bits_in_seg, |
1234 | 187k | &num_decoded_bits); |
1235 | | |
1236 | 187k | p_remaining_bits_in_seg += cur_ext_sort_cw_sec; |
1237 | | |
1238 | 187k | if (cur_ext_sort_cw_sec * max_allowed_cw_len < num_decoded_bits) { |
1239 | 77.1k | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 17); |
1240 | 77.1k | } |
1241 | | |
1242 | 187k | if (1 == ixheaacd_err_detect_pcw_segment( |
1243 | 187k | *p_remaining_bits_in_seg, ptr_hcr_info, PCW_ESC_SIGN, |
1244 | 187k | ptr_quant_spec_coeff + |
1245 | 187k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx - 2, |
1246 | 187k | 2)) { |
1247 | 0 | return; |
1248 | 0 | } |
1249 | 187k | } |
1250 | | |
1251 | 240k | num_ext_sorted_cw_in_sect_idx++; |
1252 | 240k | if (num_ext_sorted_cw_in_sect_idx >= MAX_SFB_HCR + MAX_HCR_SETS) { |
1253 | 0 | return; |
1254 | 0 | } |
1255 | 240k | } |
1256 | | |
1257 | 36.4k | num_ext_sorted_sect_in_sets_idx++; |
1258 | 36.4k | if (num_ext_sorted_sect_in_sets_idx >= MAX_HCR_SETS) { |
1259 | 0 | return; |
1260 | 0 | } |
1261 | | |
1262 | 36.4k | itt_bit_buff->cnt_bits = read_bits; |
1263 | | |
1264 | 36.4k | ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx = |
1265 | 36.4k | num_ext_sorted_cw_in_sect_idx; |
1266 | 36.4k | ptr_hcr_info->sect_info.ext_sorted_cw_idx = ext_sorted_cw_idx; |
1267 | 36.4k | ptr_hcr_info->sect_info.num_ext_sorted_sect_in_sets_idx = |
1268 | 36.4k | num_ext_sorted_sect_in_sets_idx; |
1269 | 36.4k | ptr_hcr_info->sect_info.ext_sorted_sect_max_cb_len_idx = |
1270 | 36.4k | ext_sorted_sect_max_cb_len_idx; |
1271 | 36.4k | } |
1272 | | |
1273 | | static UWORD32 ixheaacd_init_segment_bit_field(WORD32 num_segment, |
1274 | 22.2k | WORD8 *p_remaining_bits_in_seg) { |
1275 | 22.2k | WORD16 i; |
1276 | 22.2k | WORD16 num_valid_segment = 0; |
1277 | | |
1278 | 1.18M | for (i = 0; i < num_segment; i++) { |
1279 | 1.15M | if (p_remaining_bits_in_seg[i] != 0) { |
1280 | 1.12M | num_valid_segment += 1; |
1281 | 1.12M | } |
1282 | 1.15M | } |
1283 | | |
1284 | 22.2k | return num_valid_segment; |
1285 | 22.2k | } |
1286 | | |
1287 | 111k | UWORD8 ixheaacd_toggle_read_dir(UWORD8 read_direction) { |
1288 | 111k | if (read_direction == FROM_LEFT_TO_RIGHT) { |
1289 | 48.6k | return FROM_RIGHT_TO_LEFT; |
1290 | 63.0k | } else { |
1291 | 63.0k | return FROM_LEFT_TO_RIGHT; |
1292 | 63.0k | } |
1293 | 111k | } |
1294 | | |
1295 | | static PLATFORM_INLINE UWORD16 ixheaacd_huff_dec_quad_hcr_non_pcw( |
1296 | | ia_bit_buf_struct *itt_bit_buff, WORD32 *spec_coef, |
1297 | 229k | const UWORD16 *code_book_tbl, WORD32 tbl_sign, const UWORD32 *idx_table) { |
1298 | 229k | WORD16 index, length; |
1299 | 229k | WORD16 cw_len; |
1300 | 229k | WORD32 read_word; |
1301 | | |
1302 | 229k | read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr, |
1303 | 229k | itt_bit_buff->bit_count, NULL); |
1304 | 229k | ixheaacd_huffman_decode(read_word, &index, &length, code_book_tbl, idx_table); |
1305 | 229k | cw_len = length; |
1306 | 229k | if (tbl_sign) { |
1307 | 149k | WORD32 temp_word; |
1308 | 149k | WORD32 w, x, y, z; |
1309 | 149k | temp_word = read_word << length; |
1310 | 149k | w = index / 27; |
1311 | 149k | index = index - w * 27; |
1312 | 149k | x = index / 9; |
1313 | 149k | index = index - x * 9; |
1314 | 149k | y = index / 3; |
1315 | 149k | z = index - y * 3; |
1316 | 149k | if (w) { |
1317 | 106k | if (temp_word & 0x80000000) w = -w; |
1318 | 106k | temp_word <<= 1; |
1319 | 106k | cw_len++; |
1320 | 106k | } |
1321 | 149k | *spec_coef++ = w; |
1322 | | |
1323 | 149k | if (x) { |
1324 | 94.9k | if (temp_word & 0x80000000) x = -x; |
1325 | 94.9k | temp_word <<= 1; |
1326 | 94.9k | cw_len++; |
1327 | 94.9k | } |
1328 | 149k | *spec_coef++ = x; |
1329 | 149k | if (y) { |
1330 | 113k | if (temp_word & 0x80000000) y = -y; |
1331 | 113k | temp_word <<= 1; |
1332 | 113k | cw_len++; |
1333 | 113k | } |
1334 | 149k | *spec_coef++ = y; |
1335 | 149k | if (z) { |
1336 | 110k | if (temp_word & 0x80000000) z = -z; |
1337 | 110k | temp_word <<= 1; |
1338 | 110k | cw_len++; |
1339 | 110k | } |
1340 | 149k | *spec_coef++ = z; |
1341 | | |
1342 | 149k | } |
1343 | | |
1344 | 80.3k | else { |
1345 | 80.3k | WORD32 w, x, y, z; |
1346 | | |
1347 | 80.3k | w = index / 27 - 1; |
1348 | 80.3k | index = index - (w + 1) * 27; |
1349 | 80.3k | x = index / 9 - 1; |
1350 | 80.3k | index = index - (x + 1) * 9; |
1351 | 80.3k | y = index / 3 - 1; |
1352 | 80.3k | z = index - ((y + 1) * 3) - 1; |
1353 | 80.3k | *spec_coef++ = w; |
1354 | 80.3k | *spec_coef++ = x; |
1355 | 80.3k | *spec_coef++ = y; |
1356 | 80.3k | *spec_coef++ = z; |
1357 | 80.3k | } |
1358 | | |
1359 | 229k | return cw_len; |
1360 | 229k | } |
1361 | | |
1362 | | static PLATFORM_INLINE UWORD16 ixheaacd_huff_dec_word_hcr_non_pcw( |
1363 | | ia_bit_buf_struct *itt_bit_buff, WORD32 *spec_coef, |
1364 | 1.12M | const UWORD16 *code_book_tbl, const UWORD32 *idx_table) { |
1365 | 1.12M | WORD32 sp1, sp2; |
1366 | 1.12M | WORD32 flush_cw; |
1367 | 1.12M | WORD32 i, value, norm_val, off; |
1368 | 1.12M | WORD32 out1, out2; |
1369 | 1.12M | UWORD16 cw_len; |
1370 | | |
1371 | 1.12M | WORD16 index; |
1372 | 1.12M | WORD32 length; |
1373 | | |
1374 | 1.12M | WORD32 read_word; |
1375 | 1.12M | WORD32 increment; |
1376 | 1.12M | UWORD8 *ptr_read_next; |
1377 | | |
1378 | 1.12M | read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr, |
1379 | 1.12M | itt_bit_buff->bit_count, &increment); |
1380 | | |
1381 | 1.12M | ptr_read_next = itt_bit_buff->byte_ptr; |
1382 | 1.12M | ptr_read_next += increment; |
1383 | | |
1384 | 1.12M | ixheaacd_huff_sfb_table(read_word, &index, &length, code_book_tbl, idx_table); |
1385 | 1.12M | cw_len = length; |
1386 | | |
1387 | 1.12M | ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); |
1388 | | |
1389 | 1.12M | out1 = index / 17; |
1390 | 1.12M | out2 = index - out1 * 17; |
1391 | 1.12M | flush_cw = read_word << length; |
1392 | | |
1393 | 1.12M | sp1 = out1; |
1394 | 1.12M | sp2 = out2; |
1395 | | |
1396 | 1.12M | if (out1) { |
1397 | 862k | if (flush_cw & 0x80000000) { |
1398 | 323k | out1 = -out1; |
1399 | 323k | } |
1400 | 862k | flush_cw = (WORD32)flush_cw << 1; |
1401 | 862k | length++; |
1402 | 862k | cw_len++; |
1403 | 862k | } |
1404 | | |
1405 | 1.12M | if (out2) { |
1406 | 856k | if (flush_cw & 0x80000000) { |
1407 | 289k | out2 = -out2; |
1408 | 289k | } |
1409 | 856k | length++; |
1410 | 856k | cw_len++; |
1411 | 856k | } |
1412 | | |
1413 | 1.12M | ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); |
1414 | | |
1415 | 1.12M | if (sp1 == 16) { |
1416 | 190k | i = 4; |
1417 | 190k | value = ixheaac_extu(read_word, length, 23); |
1418 | 190k | value = value | 0xfffffe00; |
1419 | 190k | norm_val = ixheaac_norm32(value); |
1420 | | |
1421 | 190k | i += (norm_val - 22); |
1422 | 190k | length += (norm_val - 21); |
1423 | 190k | cw_len += (norm_val - 21); |
1424 | | |
1425 | 190k | ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); |
1426 | | |
1427 | 190k | off = ixheaac_extu(read_word, length, 32 - i); |
1428 | 190k | length += i; |
1429 | 190k | cw_len += i; |
1430 | | |
1431 | 190k | ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); |
1432 | | |
1433 | 190k | i = off + ((WORD32)1 << i); |
1434 | | |
1435 | 190k | if (out1 < 0) |
1436 | 57.8k | *spec_coef++ = -i; |
1437 | 132k | else |
1438 | 132k | *spec_coef++ = i; |
1439 | 931k | } else { |
1440 | 931k | *spec_coef++ = out1; |
1441 | 931k | } |
1442 | | |
1443 | 1.12M | if (sp2 == 16) { |
1444 | 152k | i = 4; |
1445 | 152k | value = ixheaac_extu(read_word, length, 23); |
1446 | 152k | value = value | 0xfffffe00; |
1447 | 152k | norm_val = ixheaac_norm32(value); |
1448 | | |
1449 | 152k | i += (norm_val - 22); |
1450 | 152k | length += (norm_val - 21); |
1451 | 152k | cw_len += (norm_val - 21); |
1452 | | |
1453 | 152k | ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); |
1454 | | |
1455 | 152k | off = ixheaac_extu(read_word, length, 32 - i); |
1456 | 152k | length += i; |
1457 | 152k | cw_len += i; |
1458 | | |
1459 | 152k | ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); |
1460 | 152k | i = off + ((WORD32)1 << i); |
1461 | | |
1462 | 152k | if (out2 < 0) |
1463 | 54.1k | *spec_coef++ = -i; |
1464 | 98.6k | else |
1465 | 98.6k | *spec_coef++ = i; |
1466 | 969k | } else { |
1467 | 969k | *spec_coef++ = out2; |
1468 | 969k | } |
1469 | | |
1470 | 1.12M | return cw_len; |
1471 | 1.12M | } |
1472 | | |
1473 | | static VOID ixheaacd_decode_hcr_non_pcw( |
1474 | | ia_bit_buf_struct *itt_bit_buff, ia_hcr_info_struct *ptr_hcr_info, |
1475 | | ia_aac_dec_tables_struct *ptr_aac_tables, WORD32 *cw_offset, WORD32 trial, |
1476 | 4.65M | WORD32 start) { |
1477 | 4.65M | WORD16 codeword_len = 0; |
1478 | 4.65M | WORD8 seg_bits_left; |
1479 | 4.65M | UWORD8 tot_bits_to_save, code_bits_to_save, extra_code_bits; |
1480 | 4.65M | WORD32 segment_offset = 0; |
1481 | 4.65M | WORD8 *p_remaining_bits_in_seg = |
1482 | 4.65M | ptr_hcr_info->str_segment_info.p_remaining_bits_in_seg; |
1483 | 4.65M | WORD32 num_segment = ptr_hcr_info->str_segment_info.num_segment; |
1484 | | |
1485 | 141M | for (segment_offset = start; segment_offset < trial; |
1486 | 137M | segment_offset++, *cw_offset += 1) { |
1487 | 137M | if (p_remaining_bits_in_seg[segment_offset] && |
1488 | 76.4M | !ptr_hcr_info->str_segment_info.is_decoded[*cw_offset]) { |
1489 | 1.66M | { |
1490 | 1.66M | UWORD32 i_qsc; |
1491 | 1.66M | WORD8 current_seg_bits = p_remaining_bits_in_seg[segment_offset]; |
1492 | | |
1493 | 1.66M | itt_bit_buff->byte_ptr = itt_bit_buff->ptr_start; |
1494 | 1.66M | itt_bit_buff->valid_bits = 0; |
1495 | 1.66M | itt_bit_buff->byte = 0; |
1496 | 1.66M | itt_bit_buff->bit_count = 0; |
1497 | 1.66M | itt_bit_buff->write_bit_count = 0; |
1498 | | |
1499 | 1.66M | if (ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset]) { |
1500 | 404k | extra_code_bits = max( |
1501 | 404k | ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset] - 32, 0); |
1502 | 404k | code_bits_to_save = |
1503 | 404k | min(ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset], 32); |
1504 | | |
1505 | 404k | ixheaacd_write_bit( |
1506 | 404k | itt_bit_buff, |
1507 | 404k | ptr_hcr_info->str_segment_info.code_extra[*cw_offset], |
1508 | 404k | extra_code_bits); |
1509 | 404k | ixheaacd_write_bit(itt_bit_buff, |
1510 | 404k | ptr_hcr_info->str_segment_info.code[*cw_offset], |
1511 | 404k | code_bits_to_save); |
1512 | 404k | } |
1513 | 1.66M | { |
1514 | 1.66M | UWORD32 bit; |
1515 | 1.66M | WORD32 read_bit_offset; |
1516 | | |
1517 | 1.66M | if (ptr_hcr_info->str_segment_info.read_direction == |
1518 | 1.66M | FROM_LEFT_TO_RIGHT) { |
1519 | 597k | read_bit_offset = |
1520 | 597k | ptr_hcr_info->str_segment_info.arr_seg_start_l[segment_offset] - |
1521 | 597k | (itt_bit_buff->size - itt_bit_buff->cnt_bits); |
1522 | 597k | if (read_bit_offset) { |
1523 | 597k | itt_bit_buff->cnt_bits += -read_bit_offset; |
1524 | 597k | } |
1525 | 597k | itt_bit_buff->ptr_read_next = |
1526 | 597k | itt_bit_buff->ptr_bit_buf_base + |
1527 | 597k | ((itt_bit_buff->size - itt_bit_buff->cnt_bits) >> 3); |
1528 | 597k | itt_bit_buff->bit_pos = |
1529 | 597k | ((itt_bit_buff->size - itt_bit_buff->cnt_bits) & 7); |
1530 | | |
1531 | 7.44M | for (; p_remaining_bits_in_seg[segment_offset] > 0; |
1532 | 6.84M | p_remaining_bits_in_seg[segment_offset] -= 1) { |
1533 | 6.84M | bit = ixheaacd_aac_read_bit_rev(itt_bit_buff); |
1534 | 6.84M | ptr_hcr_info->str_segment_info.arr_seg_start_l[segment_offset] += |
1535 | 6.84M | 1; |
1536 | | |
1537 | 6.84M | ixheaacd_write_bit(itt_bit_buff, bit, 1); |
1538 | 6.84M | } |
1539 | | |
1540 | 1.07M | } else { |
1541 | 1.07M | read_bit_offset = |
1542 | 1.07M | ptr_hcr_info->str_segment_info.arr_seg_start_r[segment_offset] - |
1543 | 1.07M | (itt_bit_buff->size - itt_bit_buff->cnt_bits); |
1544 | 1.07M | if (read_bit_offset) { |
1545 | 1.07M | itt_bit_buff->cnt_bits += -read_bit_offset; |
1546 | 1.07M | } |
1547 | 1.07M | itt_bit_buff->ptr_read_next = |
1548 | 1.07M | itt_bit_buff->ptr_bit_buf_base + |
1549 | 1.07M | ((itt_bit_buff->size - itt_bit_buff->cnt_bits) >> 3); |
1550 | 1.07M | itt_bit_buff->bit_pos = |
1551 | 1.07M | ((itt_bit_buff->size - itt_bit_buff->cnt_bits) & 7); |
1552 | | |
1553 | 17.2M | for (; p_remaining_bits_in_seg[segment_offset] > 0; |
1554 | 16.1M | p_remaining_bits_in_seg[segment_offset] -= 1) { |
1555 | 16.1M | bit = ixheaacd_aac_read_bit(itt_bit_buff); |
1556 | 16.1M | ptr_hcr_info->str_segment_info.arr_seg_start_r[segment_offset] -= |
1557 | 16.1M | 1; |
1558 | 16.1M | ixheaacd_write_bit(itt_bit_buff, bit, 1); |
1559 | 16.1M | } |
1560 | 1.07M | } |
1561 | 1.66M | } |
1562 | | |
1563 | 1.66M | ixheaacd_write_bit(itt_bit_buff, 0, 32 - itt_bit_buff->bit_count % 32); |
1564 | 1.66M | itt_bit_buff->valid_bits = 8; |
1565 | 1.66M | itt_bit_buff->byte_ptr = itt_bit_buff->ptr_start; |
1566 | 1.66M | itt_bit_buff->byte = *itt_bit_buff->ptr_start; |
1567 | | |
1568 | 1.66M | if (current_seg_bits) { |
1569 | 1.66M | i_qsc = ptr_hcr_info->str_non_pcw_side_info |
1570 | 1.66M | .res_ptr_idx[*cw_offset % num_segment]; |
1571 | | |
1572 | 1.66M | if (ptr_hcr_info->str_non_pcw_side_info |
1573 | 1.66M | .ptr_cb[*cw_offset % num_segment] <= 4) { |
1574 | 229k | WORD32 tbl_sign = 0; |
1575 | 229k | const UWORD16 *cb_table = |
1576 | 229k | (UWORD16 |
1577 | 229k | *)(ptr_aac_tables |
1578 | 229k | ->code_book[ptr_hcr_info->str_non_pcw_side_info |
1579 | 229k | .ptr_cb[*cw_offset % num_segment]]); |
1580 | 229k | const UWORD32 *idx_table = |
1581 | 229k | (UWORD32 *)(ptr_aac_tables->index_table |
1582 | 229k | [ptr_hcr_info->str_non_pcw_side_info |
1583 | 229k | .ptr_cb[*cw_offset % num_segment]]); |
1584 | | |
1585 | 229k | if (ptr_hcr_info->str_non_pcw_side_info |
1586 | 229k | .ptr_cb[*cw_offset % num_segment] > 2) { |
1587 | 149k | tbl_sign = 1; |
1588 | 149k | } |
1589 | | |
1590 | 229k | codeword_len = ixheaacd_huff_dec_quad_hcr_non_pcw( |
1591 | 229k | itt_bit_buff, |
1592 | 229k | &ptr_hcr_info->str_non_pcw_side_info.ptr_result_base[i_qsc], |
1593 | 229k | cb_table, tbl_sign, idx_table); |
1594 | | |
1595 | 229k | seg_bits_left = |
1596 | 229k | current_seg_bits - codeword_len + |
1597 | 229k | ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset]; |
1598 | | |
1599 | 229k | } |
1600 | | |
1601 | 1.44M | else if (ptr_hcr_info->str_non_pcw_side_info |
1602 | 1.44M | .ptr_cb[*cw_offset % num_segment] < 11) { |
1603 | 318k | WORD32 tbl_sign = 0; |
1604 | 318k | WORD32 huff_mode = 9; |
1605 | | |
1606 | 318k | const UWORD16 *cb_table = |
1607 | 318k | (UWORD16 |
1608 | 318k | *)(ptr_aac_tables |
1609 | 318k | ->code_book[ptr_hcr_info->str_non_pcw_side_info |
1610 | 318k | .ptr_cb[*cw_offset % num_segment]]); |
1611 | 318k | const UWORD32 *idx_table = |
1612 | 318k | (UWORD32 *)(ptr_aac_tables->index_table |
1613 | 318k | [ptr_hcr_info->str_non_pcw_side_info |
1614 | 318k | .ptr_cb[*cw_offset % num_segment]]); |
1615 | | |
1616 | 318k | if (ptr_hcr_info->str_non_pcw_side_info |
1617 | 318k | .ptr_cb[*cw_offset % num_segment] > 6) { |
1618 | 250k | if (ptr_hcr_info->str_non_pcw_side_info |
1619 | 250k | .ptr_cb[*cw_offset % num_segment] > 8) |
1620 | 211k | huff_mode = 13; |
1621 | 39.5k | else |
1622 | 39.5k | huff_mode = 8; |
1623 | 250k | tbl_sign = 1; |
1624 | 250k | } |
1625 | 318k | codeword_len = ixheaacd_huff_dec_pair_hcr_non_pcw( |
1626 | 318k | itt_bit_buff, |
1627 | 318k | &ptr_hcr_info->str_non_pcw_side_info.ptr_result_base[i_qsc], |
1628 | 318k | cb_table, tbl_sign, idx_table, huff_mode); |
1629 | | |
1630 | 318k | seg_bits_left = |
1631 | 318k | current_seg_bits - codeword_len + |
1632 | 318k | ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset]; |
1633 | 318k | } |
1634 | 1.66M | if (ptr_hcr_info->str_non_pcw_side_info |
1635 | 1.66M | .ptr_cb[*cw_offset % num_segment] >= 11) { |
1636 | 1.12M | const UWORD32 *idx_table = |
1637 | 1.12M | ptr_aac_tables->pstr_huffmann_tables->idx_table_hf11; |
1638 | 1.12M | const UWORD16 *cb_table = |
1639 | 1.12M | ptr_aac_tables->pstr_huffmann_tables->input_table_cb11; |
1640 | | |
1641 | 1.12M | codeword_len = ixheaacd_huff_dec_word_hcr_non_pcw( |
1642 | 1.12M | itt_bit_buff, |
1643 | 1.12M | &ptr_hcr_info->str_non_pcw_side_info.ptr_result_base[i_qsc], |
1644 | 1.12M | cb_table, idx_table); |
1645 | | |
1646 | 1.12M | seg_bits_left = |
1647 | 1.12M | current_seg_bits - codeword_len + |
1648 | 1.12M | ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset]; |
1649 | 1.12M | } |
1650 | 1.66M | if (seg_bits_left < 0) { |
1651 | 436k | tot_bits_to_save = |
1652 | 436k | current_seg_bits + |
1653 | 436k | ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset]; |
1654 | 436k | extra_code_bits = max(tot_bits_to_save - 32, 0); |
1655 | 436k | code_bits_to_save = min(tot_bits_to_save, 32); |
1656 | | |
1657 | 436k | ptr_hcr_info->str_segment_info.code_extra[*cw_offset] = |
1658 | 436k | ixheaacd_read_bit(itt_bit_buff, extra_code_bits); |
1659 | 436k | ptr_hcr_info->str_segment_info.code[*cw_offset] = |
1660 | 436k | ixheaacd_read_bit(itt_bit_buff, code_bits_to_save); |
1661 | 436k | ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset] = |
1662 | 436k | tot_bits_to_save; |
1663 | | |
1664 | 436k | p_remaining_bits_in_seg[segment_offset] = 0; |
1665 | 436k | if (p_remaining_bits_in_seg[segment_offset] < 0) |
1666 | 0 | p_remaining_bits_in_seg[segment_offset] = 0; |
1667 | 1.23M | } else { |
1668 | 1.23M | p_remaining_bits_in_seg[segment_offset] = |
1669 | 1.23M | current_seg_bits - |
1670 | 1.23M | (codeword_len - |
1671 | 1.23M | ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset]); |
1672 | 1.23M | ptr_hcr_info->str_segment_info.p_num_bits[*cw_offset] = 0; |
1673 | 1.23M | ptr_hcr_info->str_segment_info.is_decoded[*cw_offset] = 1; |
1674 | 1.23M | if (p_remaining_bits_in_seg[segment_offset] < 0) |
1675 | 0 | p_remaining_bits_in_seg[segment_offset] = 0; |
1676 | 1.23M | } |
1677 | | |
1678 | 1.66M | if (p_remaining_bits_in_seg[segment_offset] > 0) { |
1679 | 1.16M | if (ptr_hcr_info->str_segment_info.read_direction == |
1680 | 1.16M | FROM_LEFT_TO_RIGHT) |
1681 | 382k | ptr_hcr_info->str_segment_info.arr_seg_start_l[segment_offset] -= |
1682 | 382k | (p_remaining_bits_in_seg[segment_offset]); |
1683 | 784k | else |
1684 | 784k | ptr_hcr_info->str_segment_info.arr_seg_start_r[segment_offset] += |
1685 | 784k | (p_remaining_bits_in_seg[segment_offset]); |
1686 | 1.16M | } |
1687 | 1.66M | } |
1688 | 1.66M | } |
1689 | 1.66M | } |
1690 | 137M | } |
1691 | 4.65M | } |
1692 | | |
1693 | | VOID ixheaacd_decode_non_pcw(ia_bit_buf_struct *itt_bit_buff, |
1694 | | ia_hcr_info_struct *ptr_hcr_info, |
1695 | 22.2k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
1696 | 22.2k | UWORD32 num_valid_segment; |
1697 | 22.2k | WORD32 cw_offset; |
1698 | 22.2k | WORD32 trial; |
1699 | 22.2k | WORD32 num_segment; |
1700 | 22.2k | WORD32 num_code_word; |
1701 | 22.2k | UWORD8 num_set; |
1702 | 22.2k | UWORD8 current_set; |
1703 | 22.2k | WORD32 code_word_set; |
1704 | 22.2k | WORD32 loop1, loop2; |
1705 | | |
1706 | 22.2k | num_segment = ptr_hcr_info->str_segment_info.num_segment; |
1707 | | |
1708 | 22.2k | num_valid_segment = ixheaacd_init_segment_bit_field( |
1709 | 22.2k | num_segment, ptr_hcr_info->str_segment_info.p_remaining_bits_in_seg); |
1710 | | |
1711 | 22.2k | if (num_valid_segment != 0) { |
1712 | 22.2k | num_code_word = ptr_hcr_info->sect_info.num_code_word; |
1713 | 22.2k | num_set = ((num_code_word - 1) / num_segment) + 1; |
1714 | | |
1715 | 22.2k | ptr_hcr_info->str_segment_info.read_direction = FROM_RIGHT_TO_LEFT; |
1716 | | |
1717 | 134k | for (current_set = 1; current_set < num_set; current_set++) { |
1718 | 111k | num_code_word -= num_segment; |
1719 | 111k | if (num_code_word < num_segment) { |
1720 | 15.7k | code_word_set = num_code_word; |
1721 | 96.0k | } else { |
1722 | 96.0k | code_word_set = num_segment; |
1723 | 96.0k | } |
1724 | | |
1725 | 111k | ixheaacd_nonpcw_sideinfo_init(ptr_hcr_info); |
1726 | | |
1727 | 111k | cw_offset = num_segment * current_set; |
1728 | | |
1729 | 111k | ixheaacd_decode_hcr_non_pcw(itt_bit_buff, ptr_hcr_info, ptr_aac_tables, |
1730 | 111k | &cw_offset, code_word_set, 0); |
1731 | | |
1732 | 2.38M | for (trial = 1; trial < num_segment; trial++) { |
1733 | 2.27M | cw_offset = num_segment * current_set; |
1734 | | |
1735 | 2.27M | loop1 = min(num_segment, trial + code_word_set); |
1736 | 2.27M | loop2 = max(0, trial + code_word_set - num_segment); |
1737 | | |
1738 | 2.27M | ixheaacd_decode_hcr_non_pcw(itt_bit_buff, ptr_hcr_info, ptr_aac_tables, |
1739 | 2.27M | &cw_offset, loop1, trial); |
1740 | | |
1741 | 2.27M | ixheaacd_decode_hcr_non_pcw(itt_bit_buff, ptr_hcr_info, ptr_aac_tables, |
1742 | 2.27M | &cw_offset, loop2, 0); |
1743 | 2.27M | } |
1744 | | |
1745 | 111k | ptr_hcr_info->str_segment_info.read_direction = ixheaacd_toggle_read_dir( |
1746 | 111k | ptr_hcr_info->str_segment_info.read_direction); |
1747 | 111k | } |
1748 | 22.2k | } |
1749 | 22.2k | } |
1750 | | |
1751 | | static VOID ixheaacd_hcr_reorder_quantized_spec_coeff( |
1752 | | ia_hcr_info_struct *ptr_hcr_info, |
1753 | 36.3k | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) { |
1754 | 36.3k | WORD32 qsc; |
1755 | 36.3k | UWORD32 abs_qsc; |
1756 | 36.3k | UWORD32 i, j; |
1757 | 36.3k | UWORD16 num_spec_val_sect; |
1758 | 36.3k | WORD32 *ptr_teva; |
1759 | 36.3k | UWORD16 lav_err_cnt = 0; |
1760 | | |
1761 | 36.3k | UWORD32 num_sect = ptr_hcr_info->str_dec_io.num_sect; |
1762 | 36.3k | WORD32 *ptr_quant_spec_coeff_base = |
1763 | 36.3k | ptr_hcr_info->str_dec_io.ptr_quant_spec_coeff_base; |
1764 | 36.3k | WORD32 *ptr_quant_spec_coeff = |
1765 | 36.3k | ptr_hcr_info->str_dec_io.ptr_quant_spec_coeff_base; |
1766 | 36.3k | const UWORD8 *ptr_cb_dim_shift_tbl = |
1767 | 36.3k | ptr_hcr_info->table_info.ptr_cb_dim_shift_tbl; |
1768 | 36.3k | const UWORD16 *ptr_lav_tbl = ptr_hcr_info->table_info.ptr_lav_tbl; |
1769 | 36.3k | UWORD8 *ptr_sorted_cb = ptr_hcr_info->sect_info.ptr_sorted_cb; |
1770 | 36.3k | UWORD16 *ptr_num_sorted_cw_in_sect = |
1771 | 36.3k | ptr_hcr_info->sect_info.ptr_num_sorted_cw_in_sect; |
1772 | 36.3k | UWORD16 *ptr_reorder_offset = ptr_hcr_info->sect_info.ptr_reorder_offset; |
1773 | 36.3k | WORD32 *arr_temp_values = ptr_hcr_info->str_segment_info.arr_temp_values; |
1774 | 36.3k | WORD32 *ptr_bak = ptr_hcr_info->str_segment_info.arr_temp_values; |
1775 | | |
1776 | 705k | for (i = num_sect; i != 0; i--) { |
1777 | 669k | num_spec_val_sect = *ptr_num_sorted_cw_in_sect++ |
1778 | 669k | << ptr_cb_dim_shift_tbl[*ptr_sorted_cb]; |
1779 | 669k | ptr_teva = &arr_temp_values[*ptr_reorder_offset++]; |
1780 | 19.3M | for (j = num_spec_val_sect; j != 0; j--) { |
1781 | 18.6M | qsc = *ptr_quant_spec_coeff++; |
1782 | 18.6M | abs_qsc = ixheaac_abs32(qsc); |
1783 | 18.6M | if (abs_qsc <= ptr_lav_tbl[*ptr_sorted_cb]) { |
1784 | 18.5M | *ptr_teva++ = (WORD32)qsc; |
1785 | 18.5M | } else { |
1786 | 118k | if (abs_qsc == 8192) { |
1787 | 1.11k | *ptr_teva++ = (WORD32)qsc; |
1788 | 116k | } else { |
1789 | 116k | *ptr_teva++ = (WORD32)8192; |
1790 | 116k | lav_err_cnt += 1; |
1791 | 116k | } |
1792 | 118k | } |
1793 | 18.6M | } |
1794 | 669k | ptr_sorted_cb++; |
1795 | 669k | } |
1796 | | |
1797 | 36.3k | if (ptr_aac_dec_channel_info->str_ics_info.window_sequence == |
1798 | 36.3k | EIGHT_SHORT_SEQUENCE) { |
1799 | 19.6k | WORD32 *ptr_out; |
1800 | 19.6k | WORD8 window; |
1801 | | |
1802 | 19.6k | ptr_bak = ptr_hcr_info->str_segment_info.arr_temp_values; |
1803 | 177k | for (window = 0; window < 8; window++) { |
1804 | 157k | ptr_out = ptr_quant_spec_coeff_base + |
1805 | 157k | (window * ptr_aac_dec_channel_info->granule_len); |
1806 | 5.19M | for (i = 0; i < (LINES_PER_UNIT_GROUP); i++) { |
1807 | 5.03M | ptr_teva = ptr_bak + (window << 2) + i * 32; |
1808 | 25.1M | for (j = (LINES_PER_UNIT); j != 0; j--) { |
1809 | 20.1M | *ptr_out++ = *ptr_teva++; |
1810 | 20.1M | } |
1811 | 5.03M | } |
1812 | 157k | } |
1813 | 19.6k | } else { |
1814 | 16.6k | ptr_quant_spec_coeff = ptr_quant_spec_coeff_base; |
1815 | 17.0M | for (i = 1024; i != 0; i--) { |
1816 | 17.0M | *ptr_quant_spec_coeff++ = *ptr_bak++; |
1817 | 17.0M | } |
1818 | 16.6k | } |
1819 | | |
1820 | 36.3k | if (lav_err_cnt != 0) { |
1821 | 12.6k | ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 1); |
1822 | 12.6k | } |
1823 | 36.3k | } |
1824 | | |
1825 | | static VOID ixheaacd_err_detect_segmentation_final( |
1826 | 36.3k | ia_hcr_info_struct *ptr_hcr_info) { |
1827 | 36.3k | UWORD8 segmentation_err_flag = 0; |
1828 | 36.3k | UWORD16 i; |
1829 | 36.3k | WORD8 *p_remaining_bits_in_seg = |
1830 | 36.3k | ptr_hcr_info->str_segment_info.p_remaining_bits_in_seg; |
1831 | 36.3k | UWORD32 num_segment = ptr_hcr_info->str_segment_info.num_segment; |
1832 | | |
1833 | 4.84M | for (i = num_segment; i != 0; i--) { |
1834 | 4.81M | if (*p_remaining_bits_in_seg++ != 0) { |
1835 | 4.22M | segmentation_err_flag = 1; |
1836 | 4.22M | } |
1837 | 4.81M | } |
1838 | 36.3k | if (segmentation_err_flag == 1) { |
1839 | 26.4k | ptr_hcr_info->str_dec_io.err_log |= ERROR_POS; |
1840 | 26.4k | } |
1841 | 36.3k | } |
1842 | | |
1843 | | UWORD32 ixheaacd_hcr_decoder( |
1844 | | ia_hcr_info_struct *ptr_hcr_info, |
1845 | | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, |
1846 | 39.9k | ia_aac_dec_tables_struct *ptr_aac_tables, ia_bit_buf_struct *itt_bit_buff) { |
1847 | 39.9k | WORD32 ptr_tmp1, ptr_tmp2, ptr_tmp3, ptr_tmp4; |
1848 | 39.9k | WORD32 ptr_tmp5; |
1849 | | |
1850 | 39.9k | WORD32 bit_cnt_offset; |
1851 | 39.9k | UWORD32 save_bit_cnt = itt_bit_buff->cnt_bits; |
1852 | | |
1853 | 39.9k | ixheaacd_huff_calc_num_cwd(ptr_hcr_info); |
1854 | | |
1855 | 39.9k | ixheaacd_huff_sort_sect_cb_cwd(ptr_hcr_info); |
1856 | | |
1857 | 39.9k | if (ixheaacd_hcr_prepare_segmentation_grid(ptr_hcr_info) != 0) |
1858 | 3.51k | return (ptr_hcr_info->str_dec_io.err_log); |
1859 | | |
1860 | 36.4k | ixheaacd_huff_ext_sect_info(ptr_hcr_info); |
1861 | | |
1862 | 36.4k | if ((ptr_hcr_info->str_dec_io.err_log & HCR_FATAL_PCW_ERROR_MASK) != 0) { |
1863 | 26 | return (ptr_hcr_info->str_dec_io.err_log); |
1864 | 26 | } |
1865 | | |
1866 | 36.4k | ixheaacd_calc_num_ext_sorted_sect_sets( |
1867 | 36.4k | ptr_hcr_info->str_segment_info.num_segment, |
1868 | 36.4k | ptr_hcr_info->sect_info.ptr_num_ext_sorted_cw_in_sect, |
1869 | 36.4k | ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx, |
1870 | 36.4k | ptr_hcr_info->sect_info.ptr_num_ext_sorted_sect_in_sets, |
1871 | 36.4k | ptr_hcr_info->sect_info.num_ext_sorted_sect_in_sets_idx); |
1872 | | |
1873 | 36.4k | ptr_tmp1 = ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx; |
1874 | 36.4k | ptr_tmp2 = ptr_hcr_info->sect_info.ext_sorted_cw_idx; |
1875 | 36.4k | ptr_tmp3 = ptr_hcr_info->sect_info.num_ext_sorted_sect_in_sets_idx; |
1876 | 36.4k | ptr_tmp4 = ptr_hcr_info->str_dec_io.quant_spec_coeff_idx; |
1877 | 36.4k | ptr_tmp5 = ptr_hcr_info->sect_info.ext_sorted_sect_max_cb_len_idx; |
1878 | | |
1879 | 36.4k | ixheaacd_decode_pcw(itt_bit_buff, ptr_hcr_info, ptr_aac_tables); |
1880 | | |
1881 | 36.4k | if ((ptr_hcr_info->str_dec_io.err_log & HCR_FATAL_PCW_ERROR_MASK) == 0) { |
1882 | 22.2k | ixheaacd_decode_non_pcw(itt_bit_buff, ptr_hcr_info, ptr_aac_tables); |
1883 | 22.2k | } |
1884 | | |
1885 | 36.4k | ixheaacd_err_detect_segmentation_final(ptr_hcr_info); |
1886 | | |
1887 | 36.4k | ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx = ptr_tmp1; |
1888 | 36.4k | ptr_hcr_info->sect_info.ext_sorted_cw_idx = ptr_tmp2; |
1889 | 36.4k | ptr_hcr_info->sect_info.num_ext_sorted_sect_in_sets_idx = ptr_tmp3; |
1890 | 36.4k | ptr_hcr_info->str_dec_io.quant_spec_coeff_idx = ptr_tmp4; |
1891 | 36.4k | ptr_hcr_info->sect_info.ext_sorted_sect_max_cb_len_idx = ptr_tmp5; |
1892 | | |
1893 | 36.4k | ixheaacd_hcr_reorder_quantized_spec_coeff(ptr_hcr_info, |
1894 | 36.4k | ptr_aac_dec_channel_info); |
1895 | | |
1896 | 36.4k | bit_cnt_offset = (WORD32)itt_bit_buff->cnt_bits - (WORD32)save_bit_cnt; |
1897 | 36.4k | if (bit_cnt_offset) { |
1898 | 36.0k | itt_bit_buff->cnt_bits += -bit_cnt_offset; |
1899 | 36.0k | itt_bit_buff->ptr_read_next = |
1900 | 36.0k | itt_bit_buff->ptr_bit_buf_base + |
1901 | 36.0k | ((itt_bit_buff->size - itt_bit_buff->cnt_bits) >> 3); |
1902 | 36.0k | itt_bit_buff->bit_pos = (itt_bit_buff->size - itt_bit_buff->cnt_bits) & 7; |
1903 | 36.0k | } |
1904 | | |
1905 | 36.4k | return (ptr_hcr_info->str_dec_io.err_log); |
1906 | 36.4k | } |