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