/src/libavc/decoder/ih264d_parse_cabac.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2015 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | /*! |
21 | | *************************************************************************** |
22 | | * \file ih264d_parse_cabac.c |
23 | | * |
24 | | * \brief |
25 | | * This file contains cabac Residual decoding routines. |
26 | | * |
27 | | * \date |
28 | | * 20/03/2003 |
29 | | * |
30 | | * \author NS |
31 | | *************************************************************************** |
32 | | */ |
33 | | |
34 | | #include "ih264_typedefs.h" |
35 | | #include "ih264_macros.h" |
36 | | #include "ih264_platform_macros.h" |
37 | | #include "ih264d_defs.h" |
38 | | #include "ih264d_structs.h" |
39 | | |
40 | | #include "ih264d_cabac.h" |
41 | | #include "ih264d_bitstrm.h" |
42 | | #include "ih264d_parse_mb_header.h" |
43 | | #include "ih264d_debug.h" |
44 | | #include "ih264d_tables.h" |
45 | | #include "ih264d_error_handler.h" |
46 | | #include "ih264d_parse_cabac.h" |
47 | | #include "ih264d_parse_slice.h" |
48 | | #include "ih264d_tables.h" |
49 | | #include "ih264d_mb_utils.h" |
50 | | #include "ih264d_utils.h" |
51 | | |
52 | | /*! |
53 | | ******************************************************************************** |
54 | | * \if Function name : ih264d_read_coeff4x4_cabac \endif |
55 | | * |
56 | | * \brief This function encodes residual_block_cabac as defined in 7.3.5.3.2. |
57 | | * |
58 | | * \return |
59 | | * Returns the index of last significant coeff. |
60 | | * |
61 | | ******************************************************************************** |
62 | | */ |
63 | | |
64 | | UWORD8 ih264d_read_coeff4x4_cabac(dec_bit_stream_t *ps_bitstrm, |
65 | | UWORD32 u4_ctxcat, |
66 | | bin_ctxt_model_t *ps_ctxt_sig_coeff, |
67 | | dec_struct_t *ps_dec, /*!< pointer to access global variables*/ |
68 | | bin_ctxt_model_t *ps_ctxt_coded) |
69 | 7.28M | { |
70 | | |
71 | 7.28M | decoding_envirnoment_t *ps_cab_env = &ps_dec->s_cab_dec_env; |
72 | 7.28M | UWORD32 u4_coded_flag; |
73 | 7.28M | UWORD32 u4_offset, *pu4_buffer; |
74 | 7.28M | UWORD32 u4_code_int_range, u4_code_int_val_ofst; |
75 | 7.28M | tu_sblk4x4_coeff_data_t *ps_tu_4x4; |
76 | 7.28M | WORD16 *pi2_coeff_data; |
77 | 7.28M | WORD32 num_sig_coeffs = 0; |
78 | | |
79 | | /*loading from strcuctures*/ |
80 | | |
81 | 7.28M | ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data; |
82 | 7.28M | ps_tu_4x4->u2_sig_coeff_map = 0; |
83 | 7.28M | pi2_coeff_data = &ps_tu_4x4->ai2_level[0]; |
84 | | |
85 | 7.28M | u4_offset = ps_bitstrm->u4_ofst; |
86 | 7.28M | pu4_buffer = ps_bitstrm->pu4_buffer; |
87 | | |
88 | 7.28M | u4_code_int_range = ps_cab_env->u4_code_int_range; |
89 | 7.28M | u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst; |
90 | | |
91 | 7.28M | { |
92 | | |
93 | | /*inilined DecodeDecision_onebin begins*/ |
94 | | |
95 | 7.28M | { |
96 | | |
97 | 7.28M | UWORD32 u4_qnt_int_range, u4_int_range_lps; |
98 | 7.28M | UWORD32 u4_symbol, u1_mps_state; |
99 | | |
100 | 7.28M | UWORD32 table_lookup; |
101 | 7.28M | const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table; |
102 | 7.28M | UWORD32 u4_clz; |
103 | | |
104 | 7.28M | u1_mps_state = (ps_ctxt_coded->u1_mps_state); |
105 | 7.28M | u4_clz = CLZ(u4_code_int_range); |
106 | 7.28M | u4_qnt_int_range = u4_code_int_range << u4_clz; |
107 | 7.28M | u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3; |
108 | 7.28M | table_lookup = |
109 | 7.28M | pu4_table[(u1_mps_state << 2) + u4_qnt_int_range]; |
110 | 7.28M | u4_int_range_lps = table_lookup & 0xff; |
111 | 7.28M | u4_int_range_lps = u4_int_range_lps << (23 - u4_clz); |
112 | 7.28M | u4_code_int_range = u4_code_int_range - u4_int_range_lps; |
113 | 7.28M | u4_symbol = ((u1_mps_state >> 6) & 0x1); |
114 | 7.28M | u1_mps_state = (table_lookup >> 8) & 0x7F; |
115 | | |
116 | 7.28M | CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, u4_symbol, |
117 | 7.28M | u4_int_range_lps, u1_mps_state, table_lookup) |
118 | | |
119 | 7.28M | if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_8) |
120 | 58.3k | { |
121 | | |
122 | 58.3k | RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst, |
123 | 58.3k | u4_offset, pu4_buffer) |
124 | 58.3k | } |
125 | | |
126 | 7.28M | ps_ctxt_coded->u1_mps_state = u1_mps_state; |
127 | 7.28M | u4_coded_flag = u4_symbol; |
128 | | |
129 | | /*inilined DecodeDecision_onebin ends*/ |
130 | | |
131 | 7.28M | } |
132 | | |
133 | 7.28M | } |
134 | | |
135 | 7.28M | if(u4_coded_flag) |
136 | 3.03M | { |
137 | | |
138 | 3.03M | { |
139 | 3.03M | bin_ctxt_model_t *p_binCtxt_last, *p_binCtxt_last_org; |
140 | 3.03M | UWORD32 uc_last_coeff_idx; |
141 | 3.03M | UWORD32 uc_bin; |
142 | 3.03M | UWORD32 i; |
143 | 3.03M | WORD32 first_coeff_offset = 0; |
144 | | |
145 | 3.03M | if((u4_ctxcat == CHROMA_AC_CTXCAT) || (u4_ctxcat == LUMA_AC_CTXCAT)) |
146 | 560k | { |
147 | 560k | first_coeff_offset = 1; |
148 | 560k | } |
149 | | |
150 | 3.03M | i = 0; |
151 | 3.03M | if(u4_ctxcat == CHROMA_DC_CTXCAT) |
152 | 324k | { |
153 | 324k | uc_last_coeff_idx = 3; |
154 | 324k | } |
155 | 2.70M | else |
156 | 2.70M | { |
157 | 2.70M | UWORD32 u4_start; |
158 | 2.70M | u4_start = (u4_ctxcat & 1) + (u4_ctxcat >> 2); |
159 | 2.70M | uc_last_coeff_idx = 15 - u4_start; |
160 | 2.70M | } |
161 | 3.03M | p_binCtxt_last_org = ps_ctxt_sig_coeff |
162 | 3.03M | + LAST_COEFF_CTXT_MINUS_SIG_COEFF_CTXT; |
163 | | |
164 | 3.03M | do |
165 | 24.6M | { |
166 | | |
167 | | /*inilined DecodeDecision_onebin begins*/ |
168 | 24.6M | { |
169 | | |
170 | 24.6M | UWORD32 u4_qnt_int_range, u4_int_range_lps; |
171 | 24.6M | UWORD32 u4_symbol, u1_mps_state; |
172 | 24.6M | UWORD32 table_lookup; |
173 | 24.6M | const UWORD32 *pu4_table = |
174 | 24.6M | (const UWORD32 *)ps_cab_env->cabac_table; |
175 | 24.6M | UWORD32 u4_clz; |
176 | | |
177 | 24.6M | u1_mps_state = (ps_ctxt_sig_coeff->u1_mps_state); |
178 | | |
179 | 24.6M | u4_clz = CLZ(u4_code_int_range); |
180 | | |
181 | 24.6M | u4_qnt_int_range = u4_code_int_range << u4_clz; |
182 | 24.6M | u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3; |
183 | | |
184 | 24.6M | table_lookup = pu4_table[(u1_mps_state << 2) |
185 | 24.6M | + u4_qnt_int_range]; |
186 | | |
187 | 24.6M | u4_int_range_lps = table_lookup & 0xff; |
188 | | |
189 | 24.6M | u4_int_range_lps = u4_int_range_lps << (23 - u4_clz); |
190 | 24.6M | u4_code_int_range = u4_code_int_range - u4_int_range_lps; |
191 | 24.6M | u4_symbol = ((u1_mps_state >> 6) & 0x1); |
192 | 24.6M | u1_mps_state = (table_lookup >> 8) & 0x7F; |
193 | | |
194 | 24.6M | CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, |
195 | 24.6M | u4_symbol, u4_int_range_lps, u1_mps_state, |
196 | 24.6M | table_lookup) |
197 | | |
198 | 24.6M | if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_14) |
199 | 1.06M | { |
200 | | |
201 | 1.06M | UWORD32 read_bits, u4_clz; |
202 | 1.06M | u4_clz = CLZ(u4_code_int_range); |
203 | 1.06M | NEXTBITS(read_bits, (u4_offset + 23), pu4_buffer, |
204 | 1.06M | u4_clz) |
205 | 1.06M | FLUSHBITS(u4_offset, (u4_clz)) |
206 | 1.06M | u4_code_int_range = u4_code_int_range << u4_clz; |
207 | 1.06M | u4_code_int_val_ofst = (u4_code_int_val_ofst << u4_clz) |
208 | 1.06M | | read_bits; |
209 | 1.06M | } |
210 | | |
211 | 24.6M | INC_BIN_COUNT( |
212 | 24.6M | ps_cab_env) |
213 | | |
214 | 24.6M | ps_ctxt_sig_coeff->u1_mps_state = u1_mps_state; |
215 | 24.6M | uc_bin = u4_symbol; |
216 | | |
217 | 24.6M | } |
218 | | /*incrementing pointer to point to the context of the next bin*/ |
219 | 24.6M | ps_ctxt_sig_coeff++; |
220 | | |
221 | | /*inilined DecodeDecision_onebin ends*/ |
222 | | |
223 | 24.6M | if(uc_bin) |
224 | 13.2M | { |
225 | 13.2M | num_sig_coeffs++; |
226 | 13.2M | SET_BIT(ps_tu_4x4->u2_sig_coeff_map, (i + first_coeff_offset)); |
227 | | |
228 | 13.2M | p_binCtxt_last = p_binCtxt_last_org + i; |
229 | | |
230 | | /*inilined DecodeDecision_onebin begins*/ |
231 | | |
232 | 13.2M | { |
233 | | |
234 | 13.2M | UWORD32 u4_qnt_int_range, u4_int_range_lps; |
235 | 13.2M | UWORD32 u4_symbol, u1_mps_state; |
236 | 13.2M | UWORD32 table_lookup; |
237 | 13.2M | const UWORD32 *pu4_table = |
238 | 13.2M | (const UWORD32 *)ps_cab_env->cabac_table; |
239 | 13.2M | UWORD32 u4_clz; |
240 | | |
241 | 13.2M | u1_mps_state = (p_binCtxt_last->u1_mps_state); |
242 | | |
243 | 13.2M | u4_clz = CLZ(u4_code_int_range); |
244 | 13.2M | u4_qnt_int_range = u4_code_int_range << u4_clz; |
245 | 13.2M | u4_qnt_int_range = (u4_qnt_int_range >> 29) |
246 | 13.2M | & 0x3; |
247 | | |
248 | 13.2M | table_lookup = pu4_table[(u1_mps_state << 2) |
249 | 13.2M | + u4_qnt_int_range]; |
250 | 13.2M | u4_int_range_lps = table_lookup & 0xff; |
251 | | |
252 | 13.2M | u4_int_range_lps = u4_int_range_lps |
253 | 13.2M | << (23 - u4_clz); |
254 | | |
255 | 13.2M | u4_code_int_range = u4_code_int_range |
256 | 13.2M | - u4_int_range_lps; |
257 | 13.2M | u4_symbol = ((u1_mps_state >> 6) & 0x1); |
258 | 13.2M | u1_mps_state = (table_lookup >> 8) & 0x7F; |
259 | | |
260 | 13.2M | CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, |
261 | 13.2M | u4_symbol, u4_int_range_lps, |
262 | 13.2M | u1_mps_state, table_lookup) |
263 | | |
264 | 13.2M | INC_BIN_COUNT(ps_cab_env) |
265 | | |
266 | 13.2M | p_binCtxt_last->u1_mps_state = u1_mps_state; |
267 | 13.2M | uc_bin = u4_symbol; |
268 | | |
269 | 13.2M | } |
270 | | |
271 | | /*inilined DecodeDecision_onebin ends*/ |
272 | 13.2M | if(uc_bin == 1) |
273 | 2.57M | goto label_read_levels; |
274 | | |
275 | 13.2M | } |
276 | | |
277 | 22.0M | i = i + 1; |
278 | | |
279 | 22.0M | } |
280 | 22.0M | while(i < uc_last_coeff_idx); |
281 | | |
282 | 457k | num_sig_coeffs++; |
283 | 457k | SET_BIT(ps_tu_4x4->u2_sig_coeff_map, (i + first_coeff_offset)); |
284 | | |
285 | 3.03M | label_read_levels: ; |
286 | | |
287 | 3.03M | } |
288 | | |
289 | | /// VALUE of No of Coeff in BLOCK = i + 1 for second case else i; |
290 | | |
291 | | /* Decode coeff_abs_level_minus1 and coeff_sign_flag */ |
292 | 0 | { |
293 | | |
294 | 3.03M | WORD32 i2_abs_lvl; |
295 | 3.03M | UWORD32 u1_abs_level_equal1 = 1, u1_abs_level_gt1 = 0; |
296 | | |
297 | 3.03M | UWORD32 u4_ctx_inc; |
298 | 3.03M | UWORD32 ui_prefix; |
299 | 3.03M | bin_ctxt_model_t *p_ctxt_abs_level; |
300 | | |
301 | | |
302 | 3.03M | p_ctxt_abs_level = ps_dec->p_coeff_abs_level_minus1_t[u4_ctxcat]; |
303 | 3.03M | u4_ctx_inc = ((0x51)); |
304 | | |
305 | | /*****************************************************/ |
306 | | /* Main Loop runs for no. of Significant coefficient */ |
307 | | /*****************************************************/ |
308 | | |
309 | | |
310 | 3.03M | do |
311 | 13.6M | { |
312 | | |
313 | 13.6M | { |
314 | 13.6M | INC_SYM_COUNT(&(ps_dec.s_cab_dec_env)); |
315 | | |
316 | | /*****************************************************/ |
317 | | /* inilining a modified ih264d_decode_bins_unary */ |
318 | | /*****************************************************/ |
319 | | |
320 | 13.6M | { |
321 | 13.6M | UWORD32 u4_value; |
322 | 13.6M | UWORD32 u4_symbol; |
323 | 13.6M | bin_ctxt_model_t *ps_bin_ctxt; |
324 | 13.6M | UWORD32 u4_ctx_Inc; |
325 | | |
326 | 13.6M | u4_value = 0; |
327 | | |
328 | 13.6M | u4_ctx_Inc = u4_ctx_inc & 0xf; |
329 | 13.6M | ps_bin_ctxt = p_ctxt_abs_level + u4_ctx_Inc; |
330 | | |
331 | 13.6M | do |
332 | 62.0M | { |
333 | | |
334 | 62.0M | { |
335 | | |
336 | 62.0M | UWORD32 u4_qnt_int_range, |
337 | 62.0M | u4_int_range_lps; |
338 | 62.0M | UWORD32 u1_mps_state; |
339 | 62.0M | UWORD32 table_lookup; |
340 | 62.0M | const UWORD32 *pu4_table = |
341 | 62.0M | (const UWORD32 *)ps_cab_env->cabac_table; |
342 | 62.0M | UWORD32 u4_clz; |
343 | | |
344 | 62.0M | u1_mps_state = (ps_bin_ctxt->u1_mps_state); |
345 | 62.0M | u4_clz = CLZ(u4_code_int_range); |
346 | 62.0M | u4_qnt_int_range = u4_code_int_range |
347 | 62.0M | << u4_clz; |
348 | 62.0M | u4_qnt_int_range = (u4_qnt_int_range |
349 | 62.0M | >> 29) & 0x3; |
350 | 62.0M | table_lookup = pu4_table[(u1_mps_state << 2) |
351 | 62.0M | + u4_qnt_int_range]; |
352 | 62.0M | u4_int_range_lps = table_lookup & 0xff; |
353 | | |
354 | 62.0M | u4_int_range_lps = u4_int_range_lps |
355 | 62.0M | << (23 - u4_clz); |
356 | 62.0M | u4_code_int_range = u4_code_int_range |
357 | 62.0M | - u4_int_range_lps; |
358 | 62.0M | u4_symbol = ((u1_mps_state >> 6) & 0x1); |
359 | 62.0M | u1_mps_state = (table_lookup >> 8) & 0x7F; |
360 | | |
361 | 62.0M | CHECK_IF_LPS(u4_code_int_range, |
362 | 62.0M | u4_code_int_val_ofst, u4_symbol, |
363 | 62.0M | u4_int_range_lps, u1_mps_state, |
364 | 62.0M | table_lookup) |
365 | | |
366 | 62.0M | if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9) |
367 | 410k | { |
368 | | |
369 | 410k | RENORM_RANGE_OFFSET(u4_code_int_range, |
370 | 410k | u4_code_int_val_ofst, |
371 | 410k | u4_offset, pu4_buffer) |
372 | 410k | } |
373 | | |
374 | 62.0M | INC_BIN_COUNT(ps_cab_env); |
375 | | |
376 | 62.0M | ps_bin_ctxt->u1_mps_state = u1_mps_state; |
377 | 62.0M | } |
378 | | |
379 | 62.0M | INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env); |
380 | | |
381 | 62.0M | u4_value++; |
382 | 62.0M | ps_bin_ctxt = p_ctxt_abs_level + (u4_ctx_inc >> 4); |
383 | | |
384 | 62.0M | } |
385 | 62.0M | while(u4_symbol && (u4_value < UCOFF_LEVEL)); |
386 | | |
387 | 13.6M | ui_prefix = u4_value - 1 + u4_symbol; |
388 | | |
389 | 13.6M | } |
390 | | |
391 | 13.6M | if(ui_prefix == UCOFF_LEVEL) |
392 | 3.37M | { |
393 | 3.37M | UWORD32 ui16_sufS = 0; |
394 | 3.37M | UWORD32 u1_max_bins; |
395 | 3.37M | UWORD32 u4_value; |
396 | | |
397 | 3.37M | i2_abs_lvl = UCOFF_LEVEL; |
398 | | /*inlining ih264d_decode_bypass_bins_unary begins*/ |
399 | | |
400 | 3.37M | { |
401 | 3.37M | UWORD32 uc_bin; |
402 | 3.37M | UWORD32 bits_to_flush; |
403 | | |
404 | | |
405 | 3.37M | bits_to_flush = 0; |
406 | | /*renormalize to ensure there 23 bits more in the u4_code_int_val_ofst*/ |
407 | 3.37M | { |
408 | 3.37M | UWORD32 u4_clz, read_bits; |
409 | | |
410 | 3.37M | u4_clz = CLZ(u4_code_int_range); |
411 | 3.37M | FLUSHBITS(u4_offset, u4_clz) |
412 | 3.37M | NEXTBITS(read_bits, u4_offset, pu4_buffer, CABAC_BITS_TO_READ) |
413 | 3.37M | u4_code_int_range = u4_code_int_range << u4_clz; |
414 | 3.37M | u4_code_int_val_ofst = (u4_code_int_val_ofst |
415 | 3.37M | << u4_clz) | read_bits; |
416 | | |
417 | 3.37M | } |
418 | | |
419 | 3.37M | do |
420 | 3.50M | { |
421 | 3.50M | bits_to_flush++; |
422 | | |
423 | 3.50M | u4_code_int_range = u4_code_int_range >> 1; |
424 | | |
425 | 3.50M | if(u4_code_int_val_ofst >= u4_code_int_range) |
426 | 131k | { |
427 | | /* S=1 */ |
428 | 131k | uc_bin = 1; |
429 | 131k | u4_code_int_val_ofst -= u4_code_int_range; |
430 | 131k | } |
431 | 3.37M | else |
432 | 3.37M | { |
433 | | /* S=0 */ |
434 | 3.37M | uc_bin = 0; |
435 | 3.37M | } |
436 | | |
437 | 3.50M | INC_BIN_COUNT( |
438 | 3.50M | ps_cab_env);INC_BYPASS_BINS(ps_cab_env); |
439 | | |
440 | 3.50M | } |
441 | 3.50M | while(uc_bin && (bits_to_flush < CABAC_BITS_TO_READ)); |
442 | | |
443 | 3.37M | u4_value = (bits_to_flush - 1); |
444 | | |
445 | 3.37M | } |
446 | | /*inlining ih264d_decode_bypass_bins_unary ends*/ |
447 | | |
448 | 3.37M | ui16_sufS = (1 << u4_value); |
449 | 3.37M | u1_max_bins = u4_value; |
450 | | |
451 | 3.37M | if(u4_value > 0) |
452 | 50.0k | { |
453 | | |
454 | | /*inline bypassbins_flc begins*/ |
455 | | |
456 | 50.0k | if(u4_value > 10) |
457 | 661 | { |
458 | 661 | UWORD32 u4_clz, read_bits; |
459 | | |
460 | 661 | u4_clz = CLZ(u4_code_int_range); |
461 | 661 | FLUSHBITS(u4_offset, u4_clz) |
462 | 661 | NEXTBITS(read_bits, u4_offset, pu4_buffer, CABAC_BITS_TO_READ) |
463 | 661 | u4_code_int_range = u4_code_int_range << u4_clz; |
464 | 661 | u4_code_int_val_ofst = (u4_code_int_val_ofst |
465 | 661 | << u4_clz) | read_bits; |
466 | 661 | } |
467 | | |
468 | 50.0k | { |
469 | 50.0k | UWORD32 ui_bins; |
470 | 50.0k | UWORD32 uc_bin; |
471 | 50.0k | UWORD32 bits_to_flush; |
472 | | |
473 | 50.0k | ui_bins = 0; |
474 | 50.0k | bits_to_flush = 0; |
475 | | |
476 | 50.0k | do |
477 | 130k | { |
478 | 130k | bits_to_flush++; |
479 | | |
480 | 130k | u4_code_int_range = u4_code_int_range >> 1; |
481 | | |
482 | 130k | if(u4_code_int_val_ofst |
483 | 130k | >= u4_code_int_range) |
484 | 63.3k | { |
485 | | /* S=1 */ |
486 | 63.3k | uc_bin = 1; |
487 | 63.3k | u4_code_int_val_ofst -= |
488 | 63.3k | u4_code_int_range; |
489 | 63.3k | } |
490 | 67.5k | else |
491 | 67.5k | { |
492 | | /* S=0 */ |
493 | 67.5k | uc_bin = 0; |
494 | 67.5k | } |
495 | | |
496 | 130k | INC_BIN_COUNT( |
497 | 130k | ps_cab_env);INC_BYPASS_BINS(ps_cab_env); |
498 | | |
499 | 130k | ui_bins = ((ui_bins << 1) | uc_bin); |
500 | | |
501 | 130k | } |
502 | 130k | while(bits_to_flush < u1_max_bins); |
503 | | |
504 | 50.0k | u4_value = ui_bins; |
505 | 50.0k | } |
506 | | |
507 | | /*inline bypassbins_flc ends*/ |
508 | | |
509 | 50.0k | } |
510 | | |
511 | | //Value of K |
512 | 3.37M | ui16_sufS += u4_value; |
513 | 3.37M | i2_abs_lvl += ui16_sufS; |
514 | | |
515 | 3.37M | } |
516 | 10.2M | else |
517 | 10.2M | i2_abs_lvl = 1 + ui_prefix; |
518 | | |
519 | 13.6M | if(i2_abs_lvl > 1) |
520 | 5.42M | { |
521 | 5.42M | u1_abs_level_gt1++; |
522 | 5.42M | } |
523 | 13.6M | if(!u1_abs_level_gt1) |
524 | 7.42M | { |
525 | 7.42M | u1_abs_level_equal1++; |
526 | 7.42M | u4_ctx_inc = (5 << 4) + MIN(u1_abs_level_equal1, 4); |
527 | 7.42M | } |
528 | 6.24M | else |
529 | 6.24M | u4_ctx_inc = (5 + MIN(u1_abs_level_gt1, 4)) << 4; |
530 | | |
531 | | /*u4_ctx_inc = g_table_temp[u1_abs_level_gt1][u1_abs_level_equal1];*/ |
532 | | |
533 | | /* encode coeff_sign_flag[i] */ |
534 | | |
535 | 13.6M | { |
536 | 13.6M | u4_code_int_range = u4_code_int_range >> 1; |
537 | | |
538 | 13.6M | if(u4_code_int_val_ofst >= (u4_code_int_range)) |
539 | 3.22M | { |
540 | | /* S=1 */ |
541 | 3.22M | u4_code_int_val_ofst -= u4_code_int_range; |
542 | 3.22M | i2_abs_lvl = (-i2_abs_lvl); |
543 | 3.22M | } |
544 | | |
545 | 13.6M | } |
546 | 13.6M | num_sig_coeffs--; |
547 | 13.6M | *pi2_coeff_data++ = i2_abs_lvl; |
548 | 13.6M | } |
549 | 13.6M | } |
550 | 13.6M | while(num_sig_coeffs > 0); |
551 | 3.03M | } |
552 | 3.03M | } |
553 | | |
554 | 7.28M | if(u4_coded_flag) |
555 | 3.03M | { |
556 | 3.03M | WORD32 offset; |
557 | 3.03M | offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4; |
558 | 3.03M | offset = ALIGN4(offset); |
559 | 3.03M | ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset); |
560 | 3.03M | } |
561 | | |
562 | | |
563 | | /*updating structures*/ |
564 | 7.28M | ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst; |
565 | 7.28M | ps_cab_env->u4_code_int_range = u4_code_int_range; |
566 | 7.28M | ps_bitstrm->u4_ofst = u4_offset; |
567 | 7.28M | return (u4_coded_flag); |
568 | 7.28M | } |
569 | | /*! |
570 | | ******************************************************************************** |
571 | | * \if Function name : ih264d_read_coeff8x8_cabac \endif |
572 | | * |
573 | | * \brief This function encodes residual_block_cabac as defined in 7.3.5.3.2. |
574 | | when transform_8x8_flag = 1 |
575 | | * |
576 | | * \return |
577 | | * Returns the index of last significant coeff. |
578 | | * |
579 | | ******************************************************************************** |
580 | | */ |
581 | | |
582 | | void ih264d_read_coeff8x8_cabac(dec_bit_stream_t *ps_bitstrm, |
583 | | dec_struct_t *ps_dec, /*!< pointer to access global variables*/ |
584 | | dec_mb_info_t *ps_cur_mb_info) |
585 | 413k | { |
586 | 413k | decoding_envirnoment_t *ps_cab_env = &ps_dec->s_cab_dec_env; |
587 | 413k | UWORD32 u4_offset, *pu4_buffer; |
588 | 413k | UWORD32 u4_code_int_range, u4_code_int_val_ofst; |
589 | | |
590 | | /* High profile related declarations */ |
591 | 413k | UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld; |
592 | 413k | const UWORD8 *pu1_lastcoeff_context_inc = |
593 | 413k | (UWORD8 *)gau1_ih264d_lastcoeff_context_inc; |
594 | 413k | const UWORD8 *pu1_sigcoeff_context_inc; |
595 | 413k | bin_ctxt_model_t *ps_ctxt_sig_coeff; |
596 | 413k | WORD32 num_sig_coeffs = 0; |
597 | 413k | tu_blk8x8_coeff_data_t *ps_tu_8x8; |
598 | 413k | WORD16 *pi2_coeff_data; |
599 | | |
600 | | /*loading from strcuctures*/ |
601 | | |
602 | 413k | ps_tu_8x8 = (tu_blk8x8_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data; |
603 | 413k | ps_tu_8x8->au4_sig_coeff_map[0] = 0; |
604 | 413k | ps_tu_8x8->au4_sig_coeff_map[1] = 0; |
605 | 413k | pi2_coeff_data = &ps_tu_8x8->ai2_level[0]; |
606 | | |
607 | | |
608 | 413k | if(!u1_field_coding_flag) |
609 | 393k | { |
610 | 393k | pu1_sigcoeff_context_inc = |
611 | 393k | (UWORD8 *)gau1_ih264d_sigcoeff_context_inc_frame; |
612 | | |
613 | | /*******************************************************************/ |
614 | | /* last coefficient context is derived from significant coeff u4_flag */ |
615 | | /* only significant coefficient matrix need to be initialized */ |
616 | | /*******************************************************************/ |
617 | 393k | ps_ctxt_sig_coeff = ps_dec->s_high_profile.ps_sigcoeff_8x8_frame; |
618 | 393k | } |
619 | 20.1k | else |
620 | 20.1k | { |
621 | 20.1k | pu1_sigcoeff_context_inc = |
622 | 20.1k | (UWORD8 *)gau1_ih264d_sigcoeff_context_inc_field; |
623 | | |
624 | | /*******************************************************************/ |
625 | | /* last coefficient context is derived from significant coeff u4_flag */ |
626 | | /* only significant coefficient matrix need to be initialized */ |
627 | | /*******************************************************************/ |
628 | 20.1k | ps_ctxt_sig_coeff = ps_dec->s_high_profile.ps_sigcoeff_8x8_field; |
629 | 20.1k | } |
630 | | |
631 | | /*loading from strcuctures*/ |
632 | | |
633 | 413k | u4_offset = ps_bitstrm->u4_ofst; |
634 | 413k | pu4_buffer = ps_bitstrm->pu4_buffer; |
635 | | |
636 | 413k | u4_code_int_range = ps_cab_env->u4_code_int_range; |
637 | 413k | u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst; |
638 | | |
639 | 413k | { |
640 | 413k | { |
641 | 413k | bin_ctxt_model_t *p_binCtxt_last, *p_binCtxt_last_org, |
642 | 413k | *p_ctxt_sig_coeff_org; |
643 | 413k | UWORD32 uc_last_coeff_idx; |
644 | 413k | UWORD32 uc_bin; |
645 | 413k | UWORD32 i; |
646 | | |
647 | 413k | i = 0; |
648 | | |
649 | 413k | uc_last_coeff_idx = 63; |
650 | | |
651 | 413k | p_binCtxt_last_org = ps_ctxt_sig_coeff |
652 | 413k | + LAST_COEFF_CTXT_MINUS_SIG_COEFF_CTXT_8X8; |
653 | | |
654 | 413k | p_ctxt_sig_coeff_org = ps_ctxt_sig_coeff; |
655 | | |
656 | 413k | do |
657 | 7.56M | { |
658 | | /*inilined DecodeDecision_onebin begins*/ |
659 | 7.56M | { |
660 | 7.56M | UWORD32 u4_qnt_int_range, u4_int_range_lps; |
661 | 7.56M | UWORD32 u4_symbol, u1_mps_state; |
662 | 7.56M | UWORD32 table_lookup; |
663 | 7.56M | const UWORD32 *pu4_table = |
664 | 7.56M | (const UWORD32 *)ps_cab_env->cabac_table; |
665 | 7.56M | UWORD32 u4_clz; |
666 | | |
667 | 7.56M | u1_mps_state = (ps_ctxt_sig_coeff->u1_mps_state); |
668 | | |
669 | 7.56M | u4_clz = CLZ(u4_code_int_range); |
670 | | |
671 | 7.56M | u4_qnt_int_range = u4_code_int_range << u4_clz; |
672 | 7.56M | u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3; |
673 | | |
674 | 7.56M | table_lookup = pu4_table[(u1_mps_state << 2) |
675 | 7.56M | + u4_qnt_int_range]; |
676 | | |
677 | 7.56M | u4_int_range_lps = table_lookup & 0xff; |
678 | | |
679 | 7.56M | u4_int_range_lps = u4_int_range_lps << (23 - u4_clz); |
680 | 7.56M | u4_code_int_range = u4_code_int_range - u4_int_range_lps; |
681 | 7.56M | u4_symbol = ((u1_mps_state >> 6) & 0x1); |
682 | 7.56M | u1_mps_state = (table_lookup >> 8) & 0x7F; |
683 | | |
684 | 7.56M | CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, |
685 | 7.56M | u4_symbol, u4_int_range_lps, u1_mps_state, |
686 | 7.56M | table_lookup) |
687 | | |
688 | 7.56M | if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_14) |
689 | 189k | { |
690 | 189k | UWORD32 read_bits, u4_clz; |
691 | 189k | u4_clz = CLZ(u4_code_int_range); |
692 | 189k | NEXTBITS(read_bits, (u4_offset + 23), pu4_buffer, |
693 | 189k | u4_clz) |
694 | 189k | FLUSHBITS(u4_offset, (u4_clz)) |
695 | 189k | u4_code_int_range = u4_code_int_range << u4_clz; |
696 | 189k | u4_code_int_val_ofst = (u4_code_int_val_ofst << u4_clz) |
697 | 189k | | read_bits; |
698 | 189k | } |
699 | | |
700 | 7.56M | ps_ctxt_sig_coeff->u1_mps_state = u1_mps_state; |
701 | 7.56M | uc_bin = u4_symbol; |
702 | 7.56M | } |
703 | | /*incrementing pointer to point to the context of the next bin*/ |
704 | 7.56M | ps_ctxt_sig_coeff = p_ctxt_sig_coeff_org |
705 | 7.56M | + pu1_sigcoeff_context_inc[i + 1]; |
706 | | |
707 | | /*inilined DecodeDecision_onebin ends*/ |
708 | 7.56M | if(uc_bin) |
709 | 1.71M | { |
710 | 1.71M | num_sig_coeffs++; |
711 | 1.71M | SET_BIT(ps_tu_8x8->au4_sig_coeff_map[i>31], (i > 31 ? i - 32:i)); |
712 | | |
713 | 1.71M | p_binCtxt_last = p_binCtxt_last_org |
714 | 1.71M | + pu1_lastcoeff_context_inc[i]; |
715 | | |
716 | | /*inilined DecodeDecision_onebin begins*/ |
717 | | |
718 | 1.71M | { |
719 | 1.71M | UWORD32 u4_qnt_int_range, u4_int_range_lps; |
720 | 1.71M | UWORD32 u4_symbol, u1_mps_state; |
721 | 1.71M | UWORD32 table_lookup; |
722 | 1.71M | const UWORD32 *pu4_table = |
723 | 1.71M | (const UWORD32 *)ps_cab_env->cabac_table; |
724 | 1.71M | UWORD32 u4_clz; |
725 | | |
726 | 1.71M | u1_mps_state = (p_binCtxt_last->u1_mps_state); |
727 | | |
728 | 1.71M | u4_clz = CLZ(u4_code_int_range); |
729 | 1.71M | u4_qnt_int_range = u4_code_int_range << u4_clz; |
730 | 1.71M | u4_qnt_int_range = (u4_qnt_int_range >> 29) |
731 | 1.71M | & 0x3; |
732 | | |
733 | 1.71M | table_lookup = pu4_table[(u1_mps_state << 2) |
734 | 1.71M | + u4_qnt_int_range]; |
735 | 1.71M | u4_int_range_lps = table_lookup & 0xff; |
736 | | |
737 | 1.71M | u4_int_range_lps = u4_int_range_lps |
738 | 1.71M | << (23 - u4_clz); |
739 | | |
740 | 1.71M | u4_code_int_range = u4_code_int_range |
741 | 1.71M | - u4_int_range_lps; |
742 | 1.71M | u4_symbol = ((u1_mps_state >> 6) & 0x1); |
743 | 1.71M | u1_mps_state = (table_lookup >> 8) & 0x7F; |
744 | | |
745 | 1.71M | CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, |
746 | 1.71M | u4_symbol, u4_int_range_lps, |
747 | 1.71M | u1_mps_state, table_lookup) |
748 | | |
749 | 1.71M | p_binCtxt_last->u1_mps_state = u1_mps_state; |
750 | 1.71M | uc_bin = u4_symbol; |
751 | 1.71M | } |
752 | | |
753 | | /*inilined DecodeDecision_onebin ends*/ |
754 | 1.71M | if(uc_bin == 1) |
755 | 368k | goto label_read_levels; |
756 | | |
757 | 1.71M | } |
758 | | |
759 | 7.19M | i = i + 1; |
760 | | |
761 | 7.19M | } |
762 | 7.19M | while(i < uc_last_coeff_idx); |
763 | | |
764 | 45.2k | num_sig_coeffs++; |
765 | 45.2k | SET_BIT(ps_tu_8x8->au4_sig_coeff_map[i>31], (i > 31 ? i - 32:i)); |
766 | | |
767 | 413k | label_read_levels: ; |
768 | 413k | } |
769 | | |
770 | | /// VALUE of No of Coeff in BLOCK = i + 1 for second case else i; |
771 | | |
772 | | /* Decode coeff_abs_level_minus1 and coeff_sign_flag */ |
773 | 0 | { |
774 | 413k | WORD32 i2_abs_lvl; |
775 | 413k | UWORD32 u1_abs_level_equal1 = 1, u1_abs_level_gt1 = 0; |
776 | | |
777 | 413k | UWORD32 u4_ctx_inc; |
778 | 413k | UWORD32 ui_prefix; |
779 | 413k | bin_ctxt_model_t *p_ctxt_abs_level; |
780 | | |
781 | 413k | p_ctxt_abs_level = |
782 | 413k | ps_dec->p_coeff_abs_level_minus1_t[LUMA_8X8_CTXCAT]; |
783 | 413k | u4_ctx_inc = ((0x51)); |
784 | | |
785 | | /*****************************************************/ |
786 | | /* Main Loop runs for no. of Significant coefficient */ |
787 | | /*****************************************************/ |
788 | 413k | do |
789 | 1.75M | { |
790 | 1.75M | { |
791 | | |
792 | | /*****************************************************/ |
793 | | /* inilining a modified ih264d_decode_bins_unary */ |
794 | | /*****************************************************/ |
795 | | |
796 | 1.75M | { |
797 | 1.75M | UWORD32 u4_value; |
798 | 1.75M | UWORD32 u4_symbol; |
799 | 1.75M | bin_ctxt_model_t *ps_bin_ctxt; |
800 | 1.75M | UWORD32 u4_ctx_Inc; |
801 | 1.75M | u4_value = 0; |
802 | | |
803 | 1.75M | u4_ctx_Inc = u4_ctx_inc & 0xf; |
804 | 1.75M | ps_bin_ctxt = p_ctxt_abs_level + u4_ctx_Inc; |
805 | | |
806 | 1.75M | do |
807 | 2.83M | { |
808 | 2.83M | { |
809 | 2.83M | UWORD32 u4_qnt_int_range, |
810 | 2.83M | u4_int_range_lps; |
811 | 2.83M | UWORD32 u1_mps_state; |
812 | 2.83M | UWORD32 table_lookup; |
813 | 2.83M | const UWORD32 *pu4_table = |
814 | 2.83M | (const UWORD32 *)ps_cab_env->cabac_table; |
815 | 2.83M | UWORD32 u4_clz; |
816 | | |
817 | 2.83M | u1_mps_state = (ps_bin_ctxt->u1_mps_state); |
818 | 2.83M | u4_clz = CLZ(u4_code_int_range); |
819 | 2.83M | u4_qnt_int_range = u4_code_int_range |
820 | 2.83M | << u4_clz; |
821 | 2.83M | u4_qnt_int_range = (u4_qnt_int_range |
822 | 2.83M | >> 29) & 0x3; |
823 | 2.83M | table_lookup = pu4_table[(u1_mps_state << 2) |
824 | 2.83M | + u4_qnt_int_range]; |
825 | 2.83M | u4_int_range_lps = table_lookup & 0xff; |
826 | | |
827 | 2.83M | u4_int_range_lps = u4_int_range_lps |
828 | 2.83M | << (23 - u4_clz); |
829 | 2.83M | u4_code_int_range = u4_code_int_range |
830 | 2.83M | - u4_int_range_lps; |
831 | 2.83M | u4_symbol = ((u1_mps_state >> 6) & 0x1); |
832 | 2.83M | u1_mps_state = (table_lookup >> 8) & 0x7F; |
833 | | |
834 | 2.83M | CHECK_IF_LPS(u4_code_int_range, |
835 | 2.83M | u4_code_int_val_ofst, u4_symbol, |
836 | 2.83M | u4_int_range_lps, u1_mps_state, |
837 | 2.83M | table_lookup) |
838 | | |
839 | 2.83M | if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9) |
840 | 94.5k | { |
841 | | |
842 | 94.5k | RENORM_RANGE_OFFSET(u4_code_int_range, |
843 | 94.5k | u4_code_int_val_ofst, |
844 | 94.5k | u4_offset, pu4_buffer) |
845 | 94.5k | } |
846 | | |
847 | 2.83M | ps_bin_ctxt->u1_mps_state = u1_mps_state; |
848 | 2.83M | } |
849 | | |
850 | 2.83M | u4_value++; |
851 | 2.83M | ps_bin_ctxt = p_ctxt_abs_level + (u4_ctx_inc >> 4); |
852 | | |
853 | 2.83M | } |
854 | 2.83M | while(u4_symbol && (u4_value < UCOFF_LEVEL)); |
855 | | |
856 | 1.75M | ui_prefix = u4_value - 1 + u4_symbol; |
857 | 1.75M | } |
858 | | |
859 | 1.75M | if(ui_prefix == UCOFF_LEVEL) |
860 | 32.2k | { |
861 | 32.2k | UWORD32 ui16_sufS = 0; |
862 | 32.2k | UWORD32 u1_max_bins; |
863 | 32.2k | UWORD32 u4_value; |
864 | | |
865 | 32.2k | i2_abs_lvl = UCOFF_LEVEL; |
866 | | /*inlining ih264d_decode_bypass_bins_unary begins*/ |
867 | | |
868 | 32.2k | { |
869 | 32.2k | UWORD32 uc_bin; |
870 | 32.2k | UWORD32 bits_to_flush; |
871 | | |
872 | | |
873 | 32.2k | bits_to_flush = 0; |
874 | | /*renormalize to ensure there 23 bits more in the u4_code_int_val_ofst*/ |
875 | 32.2k | { |
876 | 32.2k | UWORD32 u4_clz, read_bits; |
877 | | |
878 | 32.2k | u4_clz = CLZ(u4_code_int_range); |
879 | 32.2k | FLUSHBITS(u4_offset, u4_clz) |
880 | 32.2k | NEXTBITS(read_bits, u4_offset, pu4_buffer, CABAC_BITS_TO_READ) |
881 | 32.2k | u4_code_int_range = u4_code_int_range << u4_clz; |
882 | 32.2k | u4_code_int_val_ofst = (u4_code_int_val_ofst |
883 | 32.2k | << u4_clz) | read_bits; |
884 | 32.2k | } |
885 | | |
886 | 32.2k | do |
887 | 64.3k | { |
888 | 64.3k | bits_to_flush++; |
889 | | |
890 | 64.3k | u4_code_int_range = u4_code_int_range >> 1; |
891 | | |
892 | 64.3k | if(u4_code_int_val_ofst >= u4_code_int_range) |
893 | 32.4k | { |
894 | | /* S=1 */ |
895 | 32.4k | uc_bin = 1; |
896 | 32.4k | u4_code_int_val_ofst -= u4_code_int_range; |
897 | 32.4k | } |
898 | 31.8k | else |
899 | 31.8k | { |
900 | | /* S=0 */ |
901 | 31.8k | uc_bin = 0; |
902 | 31.8k | } |
903 | | |
904 | 64.3k | } |
905 | 64.3k | while(uc_bin && (bits_to_flush < CABAC_BITS_TO_READ)); |
906 | | |
907 | 32.2k | u4_value = (bits_to_flush - 1); |
908 | 32.2k | } |
909 | | /*inlining ih264d_decode_bypass_bins_unary ends*/ |
910 | | |
911 | 32.2k | ui16_sufS = (1 << u4_value); |
912 | 32.2k | u1_max_bins = u4_value; |
913 | | |
914 | 32.2k | if(u4_value > 0) |
915 | 8.75k | { |
916 | | /*inline bypassbins_flc begins*/ |
917 | | |
918 | 8.75k | if(u4_value > 10) |
919 | 726 | { |
920 | 726 | UWORD32 u4_clz, read_bits; |
921 | | |
922 | 726 | u4_clz = CLZ(u4_code_int_range); |
923 | 726 | FLUSHBITS(u4_offset, u4_clz) |
924 | 726 | NEXTBITS(read_bits, u4_offset, pu4_buffer, CABAC_BITS_TO_READ) |
925 | 726 | u4_code_int_range = u4_code_int_range << u4_clz; |
926 | 726 | u4_code_int_val_ofst = (u4_code_int_val_ofst |
927 | 726 | << u4_clz) | read_bits; |
928 | 726 | } |
929 | | |
930 | 8.75k | { |
931 | 8.75k | UWORD32 ui_bins; |
932 | 8.75k | UWORD32 uc_bin; |
933 | 8.75k | UWORD32 bits_to_flush; |
934 | | |
935 | 8.75k | ui_bins = 0; |
936 | 8.75k | bits_to_flush = 0; |
937 | | |
938 | 8.75k | do |
939 | 32.0k | { |
940 | 32.0k | bits_to_flush++; |
941 | | |
942 | 32.0k | u4_code_int_range = u4_code_int_range >> 1; |
943 | | |
944 | 32.0k | if(u4_code_int_val_ofst |
945 | 32.0k | >= u4_code_int_range) |
946 | 17.0k | { |
947 | | /* S=1 */ |
948 | 17.0k | uc_bin = 1; |
949 | 17.0k | u4_code_int_val_ofst -= |
950 | 17.0k | u4_code_int_range; |
951 | 17.0k | } |
952 | 15.0k | else |
953 | 15.0k | { |
954 | | /* S=0 */ |
955 | 15.0k | uc_bin = 0; |
956 | 15.0k | } |
957 | | |
958 | 32.0k | ui_bins = ((ui_bins << 1) | uc_bin); |
959 | | |
960 | 32.0k | } |
961 | 32.0k | while(bits_to_flush < u1_max_bins); |
962 | | |
963 | 8.75k | u4_value = ui_bins; |
964 | 8.75k | } |
965 | | /*inline bypassbins_flc ends*/ |
966 | 8.75k | } |
967 | | |
968 | | //Value of K |
969 | 32.2k | ui16_sufS += u4_value; |
970 | 32.2k | i2_abs_lvl += (WORD32)ui16_sufS; |
971 | 32.2k | } |
972 | 1.72M | else |
973 | 1.72M | { |
974 | 1.72M | i2_abs_lvl = 1 + ui_prefix; |
975 | 1.72M | } |
976 | | |
977 | 1.75M | if(i2_abs_lvl > 1) |
978 | 359k | { |
979 | 359k | u1_abs_level_gt1++; |
980 | 359k | } |
981 | 1.75M | if(!u1_abs_level_gt1) |
982 | 1.18M | { |
983 | 1.18M | u1_abs_level_equal1++; |
984 | 1.18M | u4_ctx_inc = (5 << 4) + MIN(u1_abs_level_equal1, 4); |
985 | 1.18M | } |
986 | 573k | else |
987 | 573k | { |
988 | 573k | u4_ctx_inc = (5 + MIN(u1_abs_level_gt1, 4)) << 4; |
989 | 573k | } |
990 | | |
991 | | /*u4_ctx_inc = g_table_temp[u1_abs_level_gt1][u1_abs_level_equal1];*/ |
992 | | |
993 | | /* encode coeff_sign_flag[i] */ |
994 | | |
995 | 1.75M | { |
996 | 1.75M | u4_code_int_range = u4_code_int_range >> 1; |
997 | | |
998 | 1.75M | if(u4_code_int_val_ofst >= (u4_code_int_range)) |
999 | 707k | { |
1000 | | /* S=1 */ |
1001 | 707k | u4_code_int_val_ofst -= u4_code_int_range; |
1002 | 707k | i2_abs_lvl = (-i2_abs_lvl); |
1003 | 707k | } |
1004 | 1.75M | } |
1005 | | |
1006 | 1.75M | *pi2_coeff_data++ = i2_abs_lvl; |
1007 | 1.75M | num_sig_coeffs--; |
1008 | 1.75M | } |
1009 | 1.75M | } |
1010 | 1.75M | while(num_sig_coeffs > 0); |
1011 | 413k | } |
1012 | 413k | } |
1013 | | |
1014 | 0 | { |
1015 | 413k | WORD32 offset; |
1016 | 413k | offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_8x8; |
1017 | 413k | offset = ALIGN4(offset); |
1018 | 413k | ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset); |
1019 | 413k | } |
1020 | | |
1021 | | /*updating structures*/ |
1022 | 413k | ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst; |
1023 | 413k | ps_cab_env->u4_code_int_range = u4_code_int_range; |
1024 | 413k | ps_bitstrm->u4_ofst = u4_offset; |
1025 | 413k | } |
1026 | | |
1027 | | /*****************************************************************************/ |
1028 | | /* */ |
1029 | | /* Function Name : ih264d_cabac_parse_8x8block */ |
1030 | | /* */ |
1031 | | /* Description : This function does the residual parsing of 4 subblocks */ |
1032 | | /* in a 8x8 block. */ |
1033 | | /* */ |
1034 | | /* Inputs : pi2_coeff_block : pointer to residual block where */ |
1035 | | /* decoded and inverse scan coefficients are updated */ |
1036 | | /* */ |
1037 | | /* u4_sub_block_strd : indicates the number of sublocks */ |
1038 | | /* in a row. It is 4 for luma and 2 for chroma. */ |
1039 | | /* */ |
1040 | | /* u4_ctx_cat : inidicates context category for residual */ |
1041 | | /* decoding. */ |
1042 | | /* */ |
1043 | | /* ps_dec : pointer to Decstruct (decoder context) */ |
1044 | | /* */ |
1045 | | /* pu1_top_nnz : top nnz pointer */ |
1046 | | /* */ |
1047 | | /* pu1_left_nnz : left nnz pointer */ |
1048 | | /* */ |
1049 | | /* Globals : No */ |
1050 | | /* Processing : Parsing for four subblocks in unrolled, top and left nnz */ |
1051 | | /* are updated on the fly. csbp is set in accordance to */ |
1052 | | /* decoded numcoeff for the subblock index in raster order */ |
1053 | | /* */ |
1054 | | /* Outputs : The updated residue buffer, nnzs and csbp current block */ |
1055 | | /* */ |
1056 | | /* Returns : Returns the coded sub block pattern csbp for the block */ |
1057 | | /* */ |
1058 | | /* Issues : <List any issues or problems with this function> */ |
1059 | | /* */ |
1060 | | /* Revision History: */ |
1061 | | /* */ |
1062 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
1063 | | /* 09 10 2008 Jay Draft */ |
1064 | | /* */ |
1065 | | /*****************************************************************************/ |
1066 | | UWORD32 ih264d_cabac_parse_8x8block(WORD16 *pi2_coeff_block, |
1067 | | UWORD32 u4_sub_block_strd, |
1068 | | UWORD32 u4_ctx_cat, |
1069 | | dec_struct_t * ps_dec, |
1070 | | UWORD8 *pu1_top_nnz, |
1071 | | UWORD8 *pu1_left_nnz) |
1072 | 1.52M | { |
1073 | 1.52M | UWORD32 u4_ctxinc, u4_subblock_coded; |
1074 | 1.52M | UWORD32 u4_top0, u4_top1; |
1075 | 1.52M | UWORD32 u4_csbp = 0; |
1076 | 1.52M | UWORD32 u4_idx = 0; |
1077 | 1.52M | dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; |
1078 | 1.52M | bin_ctxt_model_t * const ps_cbf = ps_dec->p_cbf_t[u4_ctx_cat]; |
1079 | 1.52M | bin_ctxt_model_t *ps_src_bin_ctxt; |
1080 | 1.52M | bin_ctxt_model_t * const ps_sig_coeff_flag = |
1081 | 1.52M | ps_dec->p_significant_coeff_flag_t[u4_ctx_cat]; |
1082 | | |
1083 | 1.52M | UWORD8 *pu1_inv_scan = ps_dec->pu1_inv_scan; |
1084 | | |
1085 | | /*------------------------------------------------------*/ |
1086 | | /* Residual 4x4 decoding: SubBlock 0 */ |
1087 | | /*------------------------------------------------------*/ |
1088 | 1.52M | u4_ctxinc = ((!!pu1_top_nnz[0]) << 1) + (!!pu1_left_nnz[0]); |
1089 | | |
1090 | 1.52M | ps_src_bin_ctxt = ps_cbf + u4_ctxinc; |
1091 | | |
1092 | 1.52M | u4_top0 = ih264d_read_coeff4x4_cabac( ps_bitstrm, |
1093 | 1.52M | u4_ctx_cat, ps_sig_coeff_flag, ps_dec, |
1094 | 1.52M | ps_src_bin_ctxt); |
1095 | | |
1096 | 1.52M | INSERT_BIT(u4_csbp, u4_idx, u4_top0); |
1097 | | |
1098 | | /*------------------------------------------------------*/ |
1099 | | /* Residual 4x4 decoding: SubBlock 1 */ |
1100 | | /*------------------------------------------------------*/ |
1101 | 1.52M | u4_idx++; |
1102 | 1.52M | pi2_coeff_block += NUM_COEFFS_IN_4x4BLK; |
1103 | 1.52M | u4_ctxinc = ((!!pu1_top_nnz[1]) << 1) + u4_top0; |
1104 | | |
1105 | 1.52M | ps_src_bin_ctxt = ps_cbf + u4_ctxinc; |
1106 | | |
1107 | 1.52M | u4_top1 = ih264d_read_coeff4x4_cabac(ps_bitstrm, |
1108 | 1.52M | u4_ctx_cat, ps_sig_coeff_flag, ps_dec, |
1109 | 1.52M | ps_src_bin_ctxt); |
1110 | | |
1111 | 1.52M | INSERT_BIT(u4_csbp, u4_idx, u4_top1); |
1112 | 1.52M | pu1_left_nnz[0] = u4_top1; |
1113 | | |
1114 | | /*------------------------------------------------------*/ |
1115 | | /* Residual 4x4 decoding: SubBlock 2 */ |
1116 | | /*------------------------------------------------------*/ |
1117 | 1.52M | u4_idx += (u4_sub_block_strd - 1); |
1118 | 1.52M | pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK); |
1119 | 1.52M | u4_ctxinc = (u4_top0 << 1) + (!!pu1_left_nnz[1]); |
1120 | | |
1121 | 1.52M | ps_src_bin_ctxt = ps_cbf + u4_ctxinc; |
1122 | | |
1123 | 1.52M | u4_subblock_coded = ih264d_read_coeff4x4_cabac(ps_bitstrm, u4_ctx_cat, |
1124 | 1.52M | ps_sig_coeff_flag, ps_dec, |
1125 | 1.52M | ps_src_bin_ctxt); |
1126 | | |
1127 | 1.52M | INSERT_BIT(u4_csbp, u4_idx, u4_subblock_coded); |
1128 | 1.52M | pu1_top_nnz[0] = u4_subblock_coded; |
1129 | | |
1130 | | /*------------------------------------------------------*/ |
1131 | | /* Residual 4x4 decoding: SubBlock 3 */ |
1132 | | /*------------------------------------------------------*/ |
1133 | 1.52M | u4_idx++; |
1134 | 1.52M | pi2_coeff_block += NUM_COEFFS_IN_4x4BLK; |
1135 | 1.52M | u4_ctxinc = (u4_top1 << 1) + u4_subblock_coded; |
1136 | | |
1137 | 1.52M | ps_src_bin_ctxt = ps_cbf + u4_ctxinc; |
1138 | | |
1139 | 1.52M | u4_subblock_coded = ih264d_read_coeff4x4_cabac(ps_bitstrm, u4_ctx_cat, |
1140 | 1.52M | ps_sig_coeff_flag, ps_dec, |
1141 | 1.52M | ps_src_bin_ctxt); |
1142 | | |
1143 | 1.52M | INSERT_BIT(u4_csbp, u4_idx, u4_subblock_coded); |
1144 | 1.52M | pu1_top_nnz[1] = pu1_left_nnz[1] = u4_subblock_coded; |
1145 | | |
1146 | 1.52M | return (u4_csbp); |
1147 | 1.52M | } |
1148 | | |
1149 | | /*! |
1150 | | ************************************************************************** |
1151 | | * \if Function name : ih264d_parse_residual4x4_cabac \endif |
1152 | | * |
1153 | | * \brief |
1154 | | * This function parses CABAC syntax of a Luma and Chroma AC Residuals. |
1155 | | * |
1156 | | * \return |
1157 | | * 0 on Success and Error code otherwise |
1158 | | ************************************************************************** |
1159 | | */ |
1160 | | |
1161 | | WORD32 ih264d_parse_residual4x4_cabac(dec_struct_t * ps_dec, |
1162 | | dec_mb_info_t *ps_cur_mb_info, |
1163 | | UWORD8 u1_offset) |
1164 | 2.01M | { |
1165 | 2.01M | UWORD8 u1_cbp = ps_cur_mb_info->u1_cbp; |
1166 | 2.01M | UWORD16 ui16_csbp = 0; |
1167 | 2.01M | WORD16 *pi2_residual_buf; |
1168 | 2.01M | UWORD8 uc_ctx_cat; |
1169 | 2.01M | UWORD8 *pu1_top_nnz = ps_cur_mb_info->ps_curmb->pu1_nnz_y; |
1170 | 2.01M | UWORD8 *pu1_left_nnz = ps_dec->pu1_left_nnz_y; |
1171 | 2.01M | UWORD8 *pu1_top_nnz_uv = ps_cur_mb_info->ps_curmb->pu1_nnz_uv; |
1172 | 2.01M | ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info; |
1173 | 2.01M | ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info; |
1174 | 2.01M | dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; |
1175 | 2.01M | UWORD32 u4_nbr_avail = ps_dec->u1_mb_ngbr_availablity; |
1176 | 2.01M | WORD16 *pi2_coeff_block = NULL; |
1177 | 2.01M | bin_ctxt_model_t *ps_src_bin_ctxt; |
1178 | | |
1179 | 2.01M | UWORD8 u1_top_dc_csbp = (ps_top_ctxt->u1_yuv_dc_csbp) >> 1; |
1180 | 2.01M | UWORD8 u1_left_dc_csbp = (ps_dec->pu1_left_yuv_dc_csbp[0]) >> 1; |
1181 | | |
1182 | | |
1183 | 2.01M | if(!(u4_nbr_avail & TOP_MB_AVAILABLE_MASK)) |
1184 | 294k | { |
1185 | 294k | if(p_curr_ctxt->u1_mb_type & CAB_INTRA_MASK) |
1186 | 140k | { |
1187 | 140k | *(UWORD32 *)pu1_top_nnz = 0; |
1188 | 140k | u1_top_dc_csbp = 0; |
1189 | 140k | *(UWORD32 *)pu1_top_nnz_uv = 0; |
1190 | 140k | } |
1191 | 154k | else |
1192 | 154k | { |
1193 | 154k | *(UWORD32 *)pu1_top_nnz = 0x01010101; |
1194 | 154k | u1_top_dc_csbp = 0x3; |
1195 | 154k | *(UWORD32 *)pu1_top_nnz_uv = 0x01010101; |
1196 | 154k | } |
1197 | 294k | } |
1198 | 1.71M | else |
1199 | 1.71M | { |
1200 | 1.71M | UWORD32 *pu4_buf; |
1201 | 1.71M | UWORD8 *pu1_buf; |
1202 | 1.71M | pu1_buf = ps_cur_mb_info->ps_top_mb->pu1_nnz_y; |
1203 | 1.71M | pu4_buf = (UWORD32 *)pu1_buf; |
1204 | 1.71M | *(UWORD32 *)(pu1_top_nnz) = *pu4_buf; |
1205 | | |
1206 | 1.71M | pu1_buf = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv; |
1207 | 1.71M | pu4_buf = (UWORD32 *)pu1_buf; |
1208 | 1.71M | *(UWORD32 *)(pu1_top_nnz_uv) = *pu4_buf; |
1209 | | |
1210 | 1.71M | } |
1211 | | |
1212 | 2.01M | if(!(u4_nbr_avail & LEFT_MB_AVAILABLE_MASK)) |
1213 | 188k | { |
1214 | 188k | if(p_curr_ctxt->u1_mb_type & CAB_INTRA_MASK) |
1215 | 113k | { |
1216 | 113k | UWORD32 *pu4_buf; |
1217 | 113k | UWORD8 *pu1_buf; |
1218 | 113k | *(UWORD32 *)pu1_left_nnz = 0; |
1219 | 113k | u1_left_dc_csbp = 0; |
1220 | 113k | pu1_buf = ps_dec->pu1_left_nnz_uv; |
1221 | 113k | pu4_buf = (UWORD32 *)pu1_buf; |
1222 | 113k | *pu4_buf = 0; |
1223 | 113k | } |
1224 | 75.7k | else |
1225 | 75.7k | { |
1226 | 75.7k | UWORD32 *pu4_buf; |
1227 | 75.7k | UWORD8 *pu1_buf; |
1228 | 75.7k | *(UWORD32 *)pu1_left_nnz = 0x01010101; |
1229 | 75.7k | u1_left_dc_csbp = 0x3; |
1230 | 75.7k | pu1_buf = ps_dec->pu1_left_nnz_uv; |
1231 | 75.7k | pu4_buf = (UWORD32 *)pu1_buf; |
1232 | 75.7k | *pu4_buf = 0x01010101; |
1233 | 75.7k | } |
1234 | 188k | } |
1235 | | |
1236 | 2.01M | uc_ctx_cat = u1_offset ? LUMA_AC_CTXCAT : LUMA_4X4_CTXCAT; |
1237 | | |
1238 | 2.01M | ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6; |
1239 | 2.01M | ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6; |
1240 | 2.01M | ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6; |
1241 | 2.01M | ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6; |
1242 | | // CHECK_THIS |
1243 | 2.01M | ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6; |
1244 | 2.01M | ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6; |
1245 | | |
1246 | 2.01M | if(u1_cbp & 0x0f) |
1247 | 586k | { |
1248 | 586k | if(ps_cur_mb_info->u1_tran_form8x8 == 0) |
1249 | 430k | { |
1250 | | /*******************************************************************/ |
1251 | | /* Block 0 residual decoding, check cbp and proceed (subblock = 0) */ |
1252 | | /*******************************************************************/ |
1253 | 430k | if(!(u1_cbp & 0x1)) |
1254 | 107k | { |
1255 | 107k | *(UWORD16 *)(pu1_top_nnz) = 0; |
1256 | 107k | *(UWORD16 *)(pu1_left_nnz) = 0; |
1257 | 107k | } |
1258 | 322k | else |
1259 | 322k | { |
1260 | 322k | ui16_csbp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 4, |
1261 | 322k | uc_ctx_cat, ps_dec, |
1262 | 322k | pu1_top_nnz, |
1263 | 322k | pu1_left_nnz); |
1264 | 322k | } |
1265 | | |
1266 | | /*******************************************************************/ |
1267 | | /* Block 1 residual decoding, check cbp and proceed (subblock = 2) */ |
1268 | | /*******************************************************************/ |
1269 | 430k | pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK); |
1270 | 430k | if(!(u1_cbp & 0x2)) |
1271 | 113k | { |
1272 | 113k | *(UWORD16 *)(pu1_top_nnz + 2) = 0; |
1273 | 113k | *(UWORD16 *)(pu1_left_nnz) = 0; |
1274 | 113k | } |
1275 | 316k | else |
1276 | 316k | { |
1277 | 316k | UWORD32 u4_temp = ih264d_cabac_parse_8x8block(pi2_coeff_block, |
1278 | 316k | 4, uc_ctx_cat, |
1279 | 316k | ps_dec, |
1280 | 316k | (pu1_top_nnz + 2), |
1281 | 316k | pu1_left_nnz); |
1282 | 316k | ui16_csbp |= (u4_temp << 2); |
1283 | 316k | } |
1284 | | |
1285 | | /*******************************************************************/ |
1286 | | /* Block 2 residual decoding, check cbp and proceed (subblock = 8) */ |
1287 | | /*******************************************************************/ |
1288 | 430k | pi2_coeff_block += (6 * NUM_COEFFS_IN_4x4BLK); |
1289 | 430k | if(!(u1_cbp & 0x4)) |
1290 | 105k | { |
1291 | 105k | *(UWORD16 *)(pu1_top_nnz) = 0; |
1292 | 105k | *(UWORD16 *)(pu1_left_nnz + 2) = 0; |
1293 | 105k | } |
1294 | 325k | else |
1295 | 325k | { |
1296 | 325k | UWORD32 u4_temp = ih264d_cabac_parse_8x8block( |
1297 | 325k | pi2_coeff_block, 4, uc_ctx_cat, ps_dec, |
1298 | 325k | pu1_top_nnz, (pu1_left_nnz + 2)); |
1299 | 325k | ui16_csbp |= (u4_temp << 8); |
1300 | 325k | } |
1301 | | |
1302 | | /*******************************************************************/ |
1303 | | /* Block 3 residual decoding, check cbp and proceed (subblock = 10)*/ |
1304 | | /*******************************************************************/ |
1305 | 430k | pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK); |
1306 | 430k | if(!(u1_cbp & 0x8)) |
1307 | 113k | { |
1308 | 113k | *(UWORD16 *)(pu1_top_nnz + 2) = 0; |
1309 | 113k | *(UWORD16 *)(pu1_left_nnz + 2) = 0; |
1310 | 113k | } |
1311 | 316k | else |
1312 | 316k | { |
1313 | 316k | UWORD32 u4_temp = ih264d_cabac_parse_8x8block( |
1314 | 316k | pi2_coeff_block, 4, uc_ctx_cat, ps_dec, |
1315 | 316k | (pu1_top_nnz + 2), (pu1_left_nnz + 2)); |
1316 | 316k | ui16_csbp |= (u4_temp << 10); |
1317 | 316k | } |
1318 | | |
1319 | 430k | } |
1320 | 156k | else |
1321 | 156k | { |
1322 | 156k | ui16_csbp = 0; |
1323 | | |
1324 | | /*******************************************************************/ |
1325 | | /* Block 0 residual decoding, check cbp and proceed (subblock = 0) */ |
1326 | | /*******************************************************************/ |
1327 | 156k | if(!(u1_cbp & 0x1)) |
1328 | 51.6k | { |
1329 | 51.6k | *(UWORD16 *)(pu1_top_nnz) = 0; |
1330 | 51.6k | *(UWORD16 *)(pu1_left_nnz) = 0; |
1331 | 51.6k | } |
1332 | 104k | else |
1333 | 104k | { |
1334 | | |
1335 | 104k | dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; |
1336 | | |
1337 | 104k | ih264d_read_coeff8x8_cabac( ps_bitstrm, |
1338 | 104k | ps_dec, ps_cur_mb_info); |
1339 | | |
1340 | 104k | pu1_left_nnz[0] = 1; |
1341 | 104k | pu1_left_nnz[1] = 1; |
1342 | | |
1343 | 104k | pu1_top_nnz[0] = 1; |
1344 | 104k | pu1_top_nnz[1] = 1; |
1345 | | |
1346 | | /* added to be used by BS computation module */ |
1347 | 104k | ui16_csbp |= 0x0033; |
1348 | 104k | } |
1349 | | |
1350 | | /*******************************************************************/ |
1351 | | /* Block 1 residual decoding, check cbp and proceed (subblock = 2) */ |
1352 | | /*******************************************************************/ |
1353 | 156k | pi2_coeff_block += 64; |
1354 | | |
1355 | 156k | if(!(u1_cbp & 0x2)) |
1356 | 52.4k | { |
1357 | 52.4k | *(UWORD16 *)(pu1_top_nnz + 2) = 0; |
1358 | 52.4k | *(UWORD16 *)(pu1_left_nnz) = 0; |
1359 | 52.4k | } |
1360 | 103k | else |
1361 | 103k | { |
1362 | | |
1363 | | |
1364 | 103k | dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; |
1365 | | |
1366 | 103k | ih264d_read_coeff8x8_cabac(ps_bitstrm, |
1367 | 103k | ps_dec, ps_cur_mb_info); |
1368 | | |
1369 | 103k | pu1_left_nnz[0] = 1; |
1370 | 103k | pu1_left_nnz[1] = 1; |
1371 | | |
1372 | 103k | pu1_top_nnz[2] = 1; |
1373 | 103k | pu1_top_nnz[3] = 1; |
1374 | | |
1375 | | /* added to be used by BS computation module */ |
1376 | 103k | ui16_csbp |= 0x00CC; |
1377 | | |
1378 | 103k | } |
1379 | | |
1380 | | /*******************************************************************/ |
1381 | | /* Block 2 residual decoding, check cbp and proceed (subblock = 8) */ |
1382 | | /*******************************************************************/ |
1383 | 156k | pi2_coeff_block += 64; |
1384 | 156k | if(!(u1_cbp & 0x4)) |
1385 | 52.6k | { |
1386 | 52.6k | *(UWORD16 *)(pu1_top_nnz) = 0; |
1387 | 52.6k | *(UWORD16 *)(pu1_left_nnz + 2) = 0; |
1388 | 52.6k | } |
1389 | 103k | else |
1390 | 103k | { |
1391 | | |
1392 | 103k | dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; |
1393 | | |
1394 | 103k | ih264d_read_coeff8x8_cabac(ps_bitstrm, |
1395 | 103k | ps_dec, ps_cur_mb_info); |
1396 | | |
1397 | 103k | pu1_left_nnz[2] = 1; |
1398 | 103k | pu1_left_nnz[3] = 1; |
1399 | | |
1400 | 103k | pu1_top_nnz[0] = 1; |
1401 | 103k | pu1_top_nnz[1] = 1; |
1402 | | |
1403 | | /* added to be used by BS computation module */ |
1404 | 103k | ui16_csbp |= 0x3300; |
1405 | 103k | } |
1406 | | |
1407 | | /*******************************************************************/ |
1408 | | /* Block 3 residual decoding, check cbp and proceed (subblock = 10)*/ |
1409 | | /*******************************************************************/ |
1410 | 156k | pi2_coeff_block += 64; |
1411 | | |
1412 | 156k | if(!(u1_cbp & 0x8)) |
1413 | 54.8k | { |
1414 | 54.8k | *(UWORD16 *)(pu1_top_nnz + 2) = 0; |
1415 | 54.8k | *(UWORD16 *)(pu1_left_nnz + 2) = 0; |
1416 | 54.8k | } |
1417 | 101k | else |
1418 | 101k | { |
1419 | | |
1420 | 101k | dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; |
1421 | | |
1422 | 101k | ih264d_read_coeff8x8_cabac(ps_bitstrm, |
1423 | 101k | ps_dec, ps_cur_mb_info); |
1424 | | |
1425 | 101k | pu1_left_nnz[2] = 1; |
1426 | 101k | pu1_left_nnz[3] = 1; |
1427 | | |
1428 | 101k | pu1_top_nnz[2] = 1; |
1429 | 101k | pu1_top_nnz[3] = 1; |
1430 | | |
1431 | | /* added to be used by BS computation module */ |
1432 | 101k | ui16_csbp |= 0xCC00; |
1433 | 101k | } |
1434 | 156k | } |
1435 | 586k | } |
1436 | 1.42M | else |
1437 | 1.42M | { |
1438 | 1.42M | *(UWORD32 *)(pu1_top_nnz) = 0; |
1439 | 1.42M | *(UWORD32 *)(pu1_left_nnz) = 0; |
1440 | 1.42M | } |
1441 | | /*--------------------------------------------------------------------*/ |
1442 | | /* Store the last row of N values to top row */ |
1443 | | /*--------------------------------------------------------------------*/ |
1444 | 2.01M | ps_cur_mb_info->u2_luma_csbp = ui16_csbp; |
1445 | 2.01M | ps_cur_mb_info->ps_curmb->u2_luma_csbp = ui16_csbp; |
1446 | 2.01M | { |
1447 | 2.01M | WORD8 i; |
1448 | 2.01M | UWORD16 u2_chroma_csbp = 0; |
1449 | 2.01M | ps_cur_mb_info->u2_chroma_csbp = 0; |
1450 | | |
1451 | 2.01M | u1_cbp >>= 4; |
1452 | 2.01M | pu1_top_nnz = pu1_top_nnz_uv; |
1453 | 2.01M | pu1_left_nnz = ps_dec->pu1_left_nnz_uv; |
1454 | | /*--------------------------------------------------------------------*/ |
1455 | | /* if Chroma Component not present OR no ac values present */ |
1456 | | /* Set the values of N to zero */ |
1457 | | /*--------------------------------------------------------------------*/ |
1458 | 2.01M | if(u1_cbp == CBPC_ALLZERO) |
1459 | 1.76M | { |
1460 | 1.76M | ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x1; |
1461 | 1.76M | *(UWORD32 *)(pu1_top_nnz) = 0; |
1462 | 1.76M | *(UWORD32 *)(pu1_left_nnz) = 0; |
1463 | 1.76M | p_curr_ctxt->u1_yuv_dc_csbp &= 0x1; |
1464 | 1.76M | return (0); |
1465 | 1.76M | } |
1466 | | |
1467 | | /*--------------------------------------------------------------------*/ |
1468 | | /* Decode Chroma DC values */ |
1469 | | /*--------------------------------------------------------------------*/ |
1470 | 737k | for(i = 0; i < 2; i++) |
1471 | 491k | { |
1472 | 491k | UWORD8 uc_a = 1, uc_b = 1; |
1473 | 491k | UWORD32 u4_ctx_inc; |
1474 | 491k | UWORD8 uc_codedBlockFlag; |
1475 | 491k | UWORD8 pu1_inv_scan[4] = |
1476 | 491k | { 0, 1, 2, 3 }; |
1477 | 491k | WORD32 u4_scale; |
1478 | 491k | WORD32 i4_mb_inter_inc; |
1479 | 491k | tu_sblk4x4_coeff_data_t *ps_tu_4x4 = |
1480 | 491k | (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data; |
1481 | 491k | WORD16 *pi2_coeff_data = |
1482 | 491k | (WORD16 *)ps_dec->pv_parse_tu_coeff_data; |
1483 | 491k | WORD16 ai2_dc_coef[4]; |
1484 | | |
1485 | 491k | INC_SYM_COUNT(&(ps_dec->s_cab_dec_env)); |
1486 | 491k | u4_scale = (i) ? |
1487 | 245k | (ps_dec->pu2_quant_scale_v[0] |
1488 | 245k | << ps_dec->u1_qp_v_div6) : |
1489 | 491k | (ps_dec->pu2_quant_scale_u[0] |
1490 | 245k | << ps_dec->u1_qp_u_div6); |
1491 | | |
1492 | | /*--------------------------------------------------------------------*/ |
1493 | | /* Decode Bitstream to get the DC coeff */ |
1494 | | /*--------------------------------------------------------------------*/ |
1495 | 491k | uc_a = (u1_left_dc_csbp >> i) & 0x01; |
1496 | 491k | uc_b = (u1_top_dc_csbp >> i) & 0x01; |
1497 | 491k | u4_ctx_inc = (uc_a + (uc_b << 1)); |
1498 | | |
1499 | 491k | ps_src_bin_ctxt = (ps_dec->p_cbf_t[CHROMA_DC_CTXCAT]) + u4_ctx_inc; |
1500 | | |
1501 | 491k | uc_codedBlockFlag = |
1502 | 491k | ih264d_read_coeff4x4_cabac(ps_bitstrm, |
1503 | 491k | CHROMA_DC_CTXCAT, |
1504 | 491k | ps_dec->p_significant_coeff_flag_t[CHROMA_DC_CTXCAT], |
1505 | 491k | ps_dec, ps_src_bin_ctxt); |
1506 | | |
1507 | 491k | i4_mb_inter_inc = (!((ps_cur_mb_info->ps_curmb->u1_mb_type == I_4x4_MB) |
1508 | 491k | || (ps_cur_mb_info->ps_curmb->u1_mb_type == I_16x16_MB))) |
1509 | 491k | * 3; |
1510 | | |
1511 | 491k | if(ps_dec->s_high_profile.u1_scaling_present) |
1512 | 91.0k | { |
1513 | 91.0k | u4_scale *= |
1514 | 91.0k | ps_dec->s_high_profile.i2_scalinglist4x4[i4_mb_inter_inc |
1515 | 91.0k | + 1 + i][0]; |
1516 | | |
1517 | 91.0k | } |
1518 | 400k | else |
1519 | 400k | { |
1520 | 400k | u4_scale <<= 4; |
1521 | 400k | } |
1522 | | |
1523 | 491k | if(uc_codedBlockFlag) |
1524 | 324k | { |
1525 | 324k | WORD32 i_z0, i_z1, i_z2, i_z3; |
1526 | 324k | WORD32 *pi4_scale; |
1527 | | |
1528 | 324k | SET_BIT(u1_top_dc_csbp, i); |
1529 | 324k | SET_BIT(u1_left_dc_csbp, i); |
1530 | | |
1531 | 324k | ai2_dc_coef[0] = 0; |
1532 | 324k | ai2_dc_coef[1] = 0; |
1533 | 324k | ai2_dc_coef[2] = 0; |
1534 | 324k | ai2_dc_coef[3] = 0; |
1535 | | |
1536 | 324k | ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4, |
1537 | 324k | ai2_dc_coef, |
1538 | 324k | pu1_inv_scan); |
1539 | 324k | i_z0 = (ai2_dc_coef[0] + ai2_dc_coef[2]); |
1540 | 324k | i_z1 = (ai2_dc_coef[0] - ai2_dc_coef[2]); |
1541 | 324k | i_z2 = (ai2_dc_coef[1] - ai2_dc_coef[3]); |
1542 | 324k | i_z3 = (ai2_dc_coef[1] + ai2_dc_coef[3]); |
1543 | | |
1544 | | /*-----------------------------------------------------------*/ |
1545 | | /* Scaling and storing the values back */ |
1546 | | /*-----------------------------------------------------------*/ |
1547 | 324k | *pi2_coeff_data++ = ((i_z0 + i_z3) * u4_scale) >> 5; |
1548 | 324k | *pi2_coeff_data++ = ((i_z0 - i_z3) * u4_scale) >> 5; |
1549 | 324k | *pi2_coeff_data++ = ((i_z1 + i_z2) * u4_scale) >> 5; |
1550 | 324k | *pi2_coeff_data++ = ((i_z1 - i_z2) * u4_scale) >> 5; |
1551 | | |
1552 | 324k | ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_data; |
1553 | | |
1554 | 324k | SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,(i+1)); |
1555 | 324k | } |
1556 | 167k | else |
1557 | 167k | { |
1558 | 167k | CLEARBIT(u1_top_dc_csbp, i); |
1559 | 167k | CLEARBIT(u1_left_dc_csbp, i); |
1560 | 167k | } |
1561 | 491k | } |
1562 | | |
1563 | | /*********************************************************************/ |
1564 | | /* Update the DC csbp */ |
1565 | | /*********************************************************************/ |
1566 | 245k | ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x1; |
1567 | 245k | p_curr_ctxt->u1_yuv_dc_csbp &= 0x1; |
1568 | 245k | ps_dec->pu1_left_yuv_dc_csbp[0] |= (u1_left_dc_csbp << 1); |
1569 | 245k | p_curr_ctxt->u1_yuv_dc_csbp |= (u1_top_dc_csbp << 1); |
1570 | 245k | if(u1_cbp == CBPC_ACZERO) |
1571 | 126k | { |
1572 | 126k | *(UWORD32 *)(pu1_top_nnz) = 0; |
1573 | 126k | *(UWORD32 *)(pu1_left_nnz) = 0; |
1574 | 126k | return (0); |
1575 | 126k | } |
1576 | | /*--------------------------------------------------------------------*/ |
1577 | | /* Decode Chroma AC values */ |
1578 | | /*--------------------------------------------------------------------*/ |
1579 | 119k | { |
1580 | 119k | UWORD32 u4_temp; |
1581 | | /*****************************************************************/ |
1582 | | /* U Block residual decoding, check cbp and proceed (subblock=0)*/ |
1583 | | /*****************************************************************/ |
1584 | 119k | u2_chroma_csbp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 2, |
1585 | 119k | CHROMA_AC_CTXCAT, |
1586 | 119k | ps_dec, pu1_top_nnz, |
1587 | 119k | pu1_left_nnz); |
1588 | | |
1589 | 119k | pi2_coeff_block += MB_CHROM_SIZE; |
1590 | | /*****************************************************************/ |
1591 | | /* V Block residual decoding, check cbp and proceed (subblock=1)*/ |
1592 | | /*****************************************************************/ |
1593 | 119k | u4_temp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 2, |
1594 | 119k | CHROMA_AC_CTXCAT, |
1595 | 119k | ps_dec, (pu1_top_nnz + 2), |
1596 | 119k | (pu1_left_nnz + 2)); |
1597 | 119k | u2_chroma_csbp |= (u4_temp << 4); |
1598 | 119k | } |
1599 | | /*********************************************************************/ |
1600 | | /* Update the AC csbp */ |
1601 | | /*********************************************************************/ |
1602 | 119k | ps_cur_mb_info->u2_chroma_csbp = u2_chroma_csbp; |
1603 | 119k | } |
1604 | | |
1605 | 0 | return (0); |
1606 | 245k | } |
1607 | | |