Coverage Report

Created: 2025-10-13 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/ih264d_parse_cabac.c
Line
Count
Source
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
5.23M
{
70
71
5.23M
    decoding_envirnoment_t *ps_cab_env = &ps_dec->s_cab_dec_env;
72
5.23M
    UWORD32 u4_coded_flag;
73
5.23M
    UWORD32 u4_offset, *pu4_buffer;
74
5.23M
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
75
5.23M
    tu_sblk4x4_coeff_data_t *ps_tu_4x4;
76
5.23M
    WORD16 *pi2_coeff_data;
77
5.23M
    WORD32 num_sig_coeffs = 0;
78
79
    /*loading from strcuctures*/
80
81
5.23M
    ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
82
5.23M
    ps_tu_4x4->u2_sig_coeff_map = 0;
83
5.23M
    pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
84
85
5.23M
    u4_offset = ps_bitstrm->u4_ofst;
86
5.23M
    pu4_buffer = ps_bitstrm->pu4_buffer;
87
88
5.23M
    u4_code_int_range = ps_cab_env->u4_code_int_range;
89
5.23M
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
90
91
5.23M
    {
92
93
        /*inilined DecodeDecision_onebin begins*/
94
95
5.23M
        {
96
97
5.23M
            UWORD32 u4_qnt_int_range, u4_int_range_lps;
98
5.23M
            UWORD32 u4_symbol, u1_mps_state;
99
100
5.23M
            UWORD32 table_lookup;
101
5.23M
            const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
102
5.23M
            UWORD32 u4_clz;
103
104
5.23M
            u1_mps_state = (ps_ctxt_coded->u1_mps_state);
105
5.23M
            u4_clz = CLZ(u4_code_int_range);
106
5.23M
            u4_qnt_int_range = u4_code_int_range << u4_clz;
107
5.23M
            u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
108
5.23M
            table_lookup =
109
5.23M
                            pu4_table[(u1_mps_state << 2) + u4_qnt_int_range];
110
5.23M
            u4_int_range_lps = table_lookup & 0xff;
111
5.23M
            u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
112
5.23M
            u4_code_int_range = u4_code_int_range - u4_int_range_lps;
113
5.23M
            u4_symbol = ((u1_mps_state >> 6) & 0x1);
114
5.23M
            u1_mps_state = (table_lookup >> 8) & 0x7F;
115
116
5.23M
            CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, u4_symbol,
117
5.23M
                         u4_int_range_lps, u1_mps_state, table_lookup)
118
119
5.23M
            if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_8)
120
25.8k
            {
121
122
25.8k
                RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst,
123
25.8k
                                    u4_offset, pu4_buffer)
124
25.8k
            }
125
126
5.23M
            ps_ctxt_coded->u1_mps_state = u1_mps_state;
127
5.23M
            u4_coded_flag = u4_symbol;
128
129
            /*inilined DecodeDecision_onebin ends*/
130
131
5.23M
        }
132
133
5.23M
    }
134
135
5.23M
    if(u4_coded_flag)
136
1.03M
    {
137
138
1.03M
        {
139
1.03M
            bin_ctxt_model_t *p_binCtxt_last, *p_binCtxt_last_org;
140
1.03M
            UWORD32 uc_last_coeff_idx;
141
1.03M
            UWORD32 uc_bin;
142
1.03M
            UWORD32 i;
143
1.03M
            WORD32 first_coeff_offset = 0;
144
145
1.03M
            if((u4_ctxcat == CHROMA_AC_CTXCAT) || (u4_ctxcat == LUMA_AC_CTXCAT))
146
168k
            {
147
168k
                first_coeff_offset = 1;
148
168k
            }
149
150
1.03M
            i = 0;
151
1.03M
            if(u4_ctxcat == CHROMA_DC_CTXCAT)
152
142k
            {
153
142k
                uc_last_coeff_idx = 3;
154
142k
            }
155
889k
            else
156
889k
            {
157
889k
                UWORD32 u4_start;
158
889k
                u4_start = (u4_ctxcat & 1) + (u4_ctxcat >> 2);
159
889k
                uc_last_coeff_idx = 15 - u4_start;
160
889k
            }
161
1.03M
            p_binCtxt_last_org = ps_ctxt_sig_coeff
162
1.03M
                            + LAST_COEFF_CTXT_MINUS_SIG_COEFF_CTXT;
163
164
1.03M
            do
165
6.76M
            {
166
167
                /*inilined DecodeDecision_onebin begins*/
168
6.76M
                {
169
170
6.76M
                    UWORD32 u4_qnt_int_range, u4_int_range_lps;
171
6.76M
                    UWORD32 u4_symbol, u1_mps_state;
172
6.76M
                    UWORD32 table_lookup;
173
6.76M
                    const UWORD32 *pu4_table =
174
6.76M
                                    (const UWORD32 *)ps_cab_env->cabac_table;
175
6.76M
                    UWORD32 u4_clz;
176
177
6.76M
                    u1_mps_state = (ps_ctxt_sig_coeff->u1_mps_state);
178
179
6.76M
                    u4_clz = CLZ(u4_code_int_range);
180
181
6.76M
                    u4_qnt_int_range = u4_code_int_range << u4_clz;
182
6.76M
                    u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
183
184
6.76M
                    table_lookup = pu4_table[(u1_mps_state << 2)
185
6.76M
                                    + u4_qnt_int_range];
186
187
6.76M
                    u4_int_range_lps = table_lookup & 0xff;
188
189
6.76M
                    u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
190
6.76M
                    u4_code_int_range = u4_code_int_range - u4_int_range_lps;
191
6.76M
                    u4_symbol = ((u1_mps_state >> 6) & 0x1);
192
6.76M
                    u1_mps_state = (table_lookup >> 8) & 0x7F;
193
194
6.76M
                    CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
195
6.76M
                                 u4_symbol, u4_int_range_lps, u1_mps_state,
196
6.76M
                                 table_lookup)
197
198
6.76M
                    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_14)
199
353k
                    {
200
201
353k
                        UWORD32 read_bits, u4_clz;
202
353k
                        u4_clz = CLZ(u4_code_int_range);
203
353k
                        NEXTBITS(read_bits, (u4_offset + 23), pu4_buffer,
204
353k
                                 u4_clz)
205
353k
                        FLUSHBITS(u4_offset, (u4_clz))
206
353k
                        u4_code_int_range = u4_code_int_range << u4_clz;
207
353k
                        u4_code_int_val_ofst = (u4_code_int_val_ofst << u4_clz)
208
353k
                                        | read_bits;
209
353k
                    }
210
211
6.76M
                    INC_BIN_COUNT(
212
6.76M
                                    ps_cab_env)
213
214
6.76M
                    ps_ctxt_sig_coeff->u1_mps_state = u1_mps_state;
215
6.76M
                    uc_bin = u4_symbol;
216
217
6.76M
                }
218
                /*incrementing pointer to point to the context of the next bin*/
219
6.76M
                ps_ctxt_sig_coeff++;
220
221
                /*inilined DecodeDecision_onebin ends*/
222
223
6.76M
                if(uc_bin)
224
3.03M
                {
225
3.03M
                    num_sig_coeffs++;
226
3.03M
                    SET_BIT(ps_tu_4x4->u2_sig_coeff_map, (i + first_coeff_offset));
227
228
3.03M
                    p_binCtxt_last = p_binCtxt_last_org + i;
229
230
                    /*inilined DecodeDecision_onebin begins*/
231
232
3.03M
                    {
233
234
3.03M
                        UWORD32 u4_qnt_int_range, u4_int_range_lps;
235
3.03M
                        UWORD32 u4_symbol, u1_mps_state;
236
3.03M
                        UWORD32 table_lookup;
237
3.03M
                        const UWORD32 *pu4_table =
238
3.03M
                                        (const UWORD32 *)ps_cab_env->cabac_table;
239
3.03M
                        UWORD32 u4_clz;
240
241
3.03M
                        u1_mps_state = (p_binCtxt_last->u1_mps_state);
242
243
3.03M
                        u4_clz = CLZ(u4_code_int_range);
244
3.03M
                        u4_qnt_int_range = u4_code_int_range << u4_clz;
245
3.03M
                        u4_qnt_int_range = (u4_qnt_int_range >> 29)
246
3.03M
                                        & 0x3;
247
248
3.03M
                        table_lookup = pu4_table[(u1_mps_state << 2)
249
3.03M
                                        + u4_qnt_int_range];
250
3.03M
                        u4_int_range_lps = table_lookup & 0xff;
251
252
3.03M
                        u4_int_range_lps = u4_int_range_lps
253
3.03M
                                        << (23 - u4_clz);
254
255
3.03M
                        u4_code_int_range = u4_code_int_range
256
3.03M
                                        - u4_int_range_lps;
257
3.03M
                        u4_symbol = ((u1_mps_state >> 6) & 0x1);
258
3.03M
                        u1_mps_state = (table_lookup >> 8) & 0x7F;
259
260
3.03M
                        CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
261
3.03M
                                     u4_symbol, u4_int_range_lps,
262
3.03M
                                     u1_mps_state, table_lookup)
263
264
3.03M
                        INC_BIN_COUNT(ps_cab_env)
265
266
3.03M
                        p_binCtxt_last->u1_mps_state = u1_mps_state;
267
3.03M
                        uc_bin = u4_symbol;
268
269
3.03M
                    }
270
271
                    /*inilined DecodeDecision_onebin ends*/
272
3.03M
                    if(uc_bin == 1)
273
990k
                        goto label_read_levels;
274
275
3.03M
                }
276
277
5.77M
                i = i + 1;
278
279
5.77M
            }
280
5.77M
            while(i < uc_last_coeff_idx);
281
282
40.2k
            num_sig_coeffs++;
283
40.2k
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, (i + first_coeff_offset));
284
285
1.03M
            label_read_levels: ;
286
287
1.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
1.03M
            WORD32 i2_abs_lvl;
295
1.03M
            UWORD32 u1_abs_level_equal1 = 1, u1_abs_level_gt1 = 0;
296
297
1.03M
            UWORD32 u4_ctx_inc;
298
1.03M
            UWORD32 ui_prefix;
299
1.03M
        bin_ctxt_model_t *p_ctxt_abs_level;
300
301
302
1.03M
        p_ctxt_abs_level = ps_dec->p_coeff_abs_level_minus1_t[u4_ctxcat];
303
1.03M
        u4_ctx_inc = ((0x51));
304
305
        /*****************************************************/
306
        /* Main Loop runs for no. of Significant coefficient */
307
        /*****************************************************/
308
309
310
1.03M
        do
311
3.07M
            {
312
313
3.07M
                {
314
3.07M
                    INC_SYM_COUNT(&(ps_dec.s_cab_dec_env));
315
316
                    /*****************************************************/
317
                    /* inilining a modified ih264d_decode_bins_unary     */
318
                    /*****************************************************/
319
320
3.07M
                    {
321
3.07M
                        UWORD32 u4_value;
322
3.07M
                        UWORD32 u4_symbol;
323
3.07M
                        bin_ctxt_model_t *ps_bin_ctxt;
324
3.07M
                        UWORD32 u4_ctx_Inc;
325
326
3.07M
                        u4_value = 0;
327
328
3.07M
                        u4_ctx_Inc = u4_ctx_inc & 0xf;
329
3.07M
                        ps_bin_ctxt = p_ctxt_abs_level + u4_ctx_Inc;
330
331
3.07M
                        do
332
5.04M
                        {
333
334
5.04M
                            {
335
336
5.04M
                                UWORD32 u4_qnt_int_range,
337
5.04M
                                                u4_int_range_lps;
338
5.04M
                                UWORD32 u1_mps_state;
339
5.04M
                                UWORD32 table_lookup;
340
5.04M
                                const UWORD32 *pu4_table =
341
5.04M
                                                (const UWORD32 *)ps_cab_env->cabac_table;
342
5.04M
                                UWORD32 u4_clz;
343
344
5.04M
                                u1_mps_state = (ps_bin_ctxt->u1_mps_state);
345
5.04M
                                u4_clz = CLZ(u4_code_int_range);
346
5.04M
                                u4_qnt_int_range = u4_code_int_range
347
5.04M
                                                << u4_clz;
348
5.04M
                                u4_qnt_int_range = (u4_qnt_int_range
349
5.04M
                                                >> 29) & 0x3;
350
5.04M
                                table_lookup = pu4_table[(u1_mps_state << 2)
351
5.04M
                                                + u4_qnt_int_range];
352
5.04M
                                u4_int_range_lps = table_lookup & 0xff;
353
354
5.04M
                                u4_int_range_lps = u4_int_range_lps
355
5.04M
                                                << (23 - u4_clz);
356
5.04M
                                u4_code_int_range = u4_code_int_range
357
5.04M
                                                - u4_int_range_lps;
358
5.04M
                                u4_symbol = ((u1_mps_state >> 6) & 0x1);
359
5.04M
                                u1_mps_state = (table_lookup >> 8) & 0x7F;
360
361
5.04M
                                CHECK_IF_LPS(u4_code_int_range,
362
5.04M
                                             u4_code_int_val_ofst, u4_symbol,
363
5.04M
                                             u4_int_range_lps, u1_mps_state,
364
5.04M
                                             table_lookup)
365
366
5.04M
                                if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
367
89.6k
                                {
368
369
89.6k
                                    RENORM_RANGE_OFFSET(u4_code_int_range,
370
89.6k
                                                        u4_code_int_val_ofst,
371
89.6k
                                                        u4_offset, pu4_buffer)
372
89.6k
                                }
373
374
5.04M
                                INC_BIN_COUNT(ps_cab_env);
375
376
5.04M
                                ps_bin_ctxt->u1_mps_state = u1_mps_state;
377
5.04M
                            }
378
379
5.04M
                            INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
380
381
5.04M
                            u4_value++;
382
5.04M
                            ps_bin_ctxt = p_ctxt_abs_level + (u4_ctx_inc >> 4);
383
384
5.04M
                        }
385
5.04M
                        while(u4_symbol && (u4_value < UCOFF_LEVEL));
386
387
3.07M
                        ui_prefix = u4_value - 1 + u4_symbol;
388
389
3.07M
                    }
390
391
3.07M
                    if(ui_prefix == UCOFF_LEVEL)
392
85.1k
                    {
393
85.1k
                        UWORD32 ui16_sufS = 0;
394
85.1k
                        UWORD32 u1_max_bins;
395
85.1k
                        UWORD32 u4_value;
396
397
85.1k
                        i2_abs_lvl = UCOFF_LEVEL;
398
                        /*inlining ih264d_decode_bypass_bins_unary begins*/
399
400
85.1k
                        {
401
85.1k
                            UWORD32 uc_bin;
402
85.1k
                            UWORD32 bits_to_flush;
403
404
405
85.1k
                            bits_to_flush = 0;
406
                            /*renormalize to ensure there 23 bits more in the u4_code_int_val_ofst*/
407
85.1k
                            {
408
85.1k
                                UWORD32 u4_clz, read_bits;
409
410
85.1k
                                u4_clz = CLZ(u4_code_int_range);
411
85.1k
                                FLUSHBITS(u4_offset, u4_clz)
412
85.1k
                                NEXTBITS(read_bits, u4_offset, pu4_buffer, CABAC_BITS_TO_READ)
413
85.1k
                                u4_code_int_range = u4_code_int_range << u4_clz;
414
85.1k
                                u4_code_int_val_ofst = (u4_code_int_val_ofst
415
85.1k
                                                << u4_clz) | read_bits;
416
417
85.1k
                            }
418
419
85.1k
                            do
420
122k
                            {
421
122k
                                bits_to_flush++;
422
423
122k
                                u4_code_int_range = u4_code_int_range >> 1;
424
425
122k
                                if(u4_code_int_val_ofst >= u4_code_int_range)
426
37.8k
                                {
427
                                    /* S=1 */
428
37.8k
                                    uc_bin = 1;
429
37.8k
                                    u4_code_int_val_ofst -= u4_code_int_range;
430
37.8k
                                }
431
84.7k
                                else
432
84.7k
                                {
433
                                    /* S=0 */
434
84.7k
                                    uc_bin = 0;
435
84.7k
                                }
436
437
122k
                                INC_BIN_COUNT(
438
122k
                                                ps_cab_env);INC_BYPASS_BINS(ps_cab_env);
439
440
122k
                            }
441
122k
                            while(uc_bin && (bits_to_flush < CABAC_BITS_TO_READ));
442
443
85.1k
                            u4_value = (bits_to_flush - 1);
444
445
85.1k
                        }
446
                        /*inlining ih264d_decode_bypass_bins_unary ends*/
447
448
85.1k
                        ui16_sufS = (1 << u4_value);
449
85.1k
                        u1_max_bins = u4_value;
450
451
85.1k
                        if(u4_value > 0)
452
12.4k
                        {
453
454
                            /*inline bypassbins_flc begins*/
455
456
12.4k
                            if(u4_value > 10)
457
593
                            {
458
593
                                UWORD32 u4_clz, read_bits;
459
460
593
                                u4_clz = CLZ(u4_code_int_range);
461
593
                                FLUSHBITS(u4_offset, u4_clz)
462
593
                                NEXTBITS(read_bits, u4_offset, pu4_buffer, CABAC_BITS_TO_READ)
463
593
                                u4_code_int_range = u4_code_int_range << u4_clz;
464
593
                                u4_code_int_val_ofst = (u4_code_int_val_ofst
465
593
                                                << u4_clz) | read_bits;
466
593
                            }
467
468
12.4k
                            {
469
12.4k
                                UWORD32 ui_bins;
470
12.4k
                                UWORD32 uc_bin;
471
12.4k
                                UWORD32 bits_to_flush;
472
473
12.4k
                                ui_bins = 0;
474
12.4k
                                bits_to_flush = 0;
475
476
12.4k
                                do
477
37.3k
                                {
478
37.3k
                                    bits_to_flush++;
479
480
37.3k
                                    u4_code_int_range = u4_code_int_range >> 1;
481
482
37.3k
                                    if(u4_code_int_val_ofst
483
37.3k
                                                    >= u4_code_int_range)
484
18.6k
                                    {
485
                                        /* S=1 */
486
18.6k
                                        uc_bin = 1;
487
18.6k
                                        u4_code_int_val_ofst -=
488
18.6k
                                                        u4_code_int_range;
489
18.6k
                                    }
490
18.6k
                                    else
491
18.6k
                                    {
492
                                        /* S=0 */
493
18.6k
                                        uc_bin = 0;
494
18.6k
                                    }
495
496
37.3k
                                    INC_BIN_COUNT(
497
37.3k
                                                    ps_cab_env);INC_BYPASS_BINS(ps_cab_env);
498
499
37.3k
                                    ui_bins = ((ui_bins << 1) | uc_bin);
500
501
37.3k
                                }
502
37.3k
                                while(bits_to_flush < u1_max_bins);
503
504
12.4k
                                u4_value = ui_bins;
505
12.4k
                            }
506
507
                            /*inline bypassbins_flc ends*/
508
509
12.4k
                        }
510
511
                        //Value of K
512
85.1k
                        ui16_sufS += u4_value;
513
85.1k
                        i2_abs_lvl += ui16_sufS;
514
515
85.1k
                    }
516
2.99M
                    else
517
2.99M
                        i2_abs_lvl = 1 + ui_prefix;
518
519
3.07M
                    if(i2_abs_lvl > 1)
520
499k
                    {
521
499k
                        u1_abs_level_gt1++;
522
499k
                    }
523
3.07M
                    if(!u1_abs_level_gt1)
524
2.42M
                    {
525
2.42M
                        u1_abs_level_equal1++;
526
2.42M
                        u4_ctx_inc = (5 << 4) + MIN(u1_abs_level_equal1, 4);
527
2.42M
                    }
528
658k
                    else
529
658k
                        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
3.07M
                    {
536
3.07M
                        u4_code_int_range = u4_code_int_range >> 1;
537
538
3.07M
                        if(u4_code_int_val_ofst >= (u4_code_int_range))
539
881k
                        {
540
                            /* S=1 */
541
881k
                            u4_code_int_val_ofst -= u4_code_int_range;
542
881k
                            i2_abs_lvl = (-i2_abs_lvl);
543
881k
                        }
544
545
3.07M
                    }
546
3.07M
                    num_sig_coeffs--;
547
3.07M
                    *pi2_coeff_data++ = i2_abs_lvl;
548
3.07M
                }
549
3.07M
            }
550
3.07M
            while(num_sig_coeffs > 0);
551
1.03M
        }
552
1.03M
    }
553
554
5.23M
    if(u4_coded_flag)
555
1.03M
    {
556
1.03M
        WORD32 offset;
557
1.03M
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
558
1.03M
        offset = ALIGN4(offset);
559
1.03M
        ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
560
1.03M
    }
561
562
563
    /*updating structures*/
564
5.23M
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
565
5.23M
    ps_cab_env->u4_code_int_range = u4_code_int_range;
566
5.23M
    ps_bitstrm->u4_ofst = u4_offset;
567
5.23M
    return (u4_coded_flag);
568
5.23M
}
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
214k
{
586
214k
    decoding_envirnoment_t *ps_cab_env = &ps_dec->s_cab_dec_env;
587
214k
    UWORD32 u4_offset, *pu4_buffer;
588
214k
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
589
590
    /* High profile related declarations */
591
214k
    UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
592
214k
    const UWORD8 *pu1_lastcoeff_context_inc =
593
214k
                    (UWORD8 *)gau1_ih264d_lastcoeff_context_inc;
594
214k
    const UWORD8 *pu1_sigcoeff_context_inc;
595
214k
    bin_ctxt_model_t *ps_ctxt_sig_coeff;
596
214k
    WORD32 num_sig_coeffs = 0;
597
214k
    tu_blk8x8_coeff_data_t *ps_tu_8x8;
598
214k
    WORD16 *pi2_coeff_data;
599
600
    /*loading from strcuctures*/
601
602
214k
    ps_tu_8x8 = (tu_blk8x8_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
603
214k
    ps_tu_8x8->au4_sig_coeff_map[0] = 0;
604
214k
    ps_tu_8x8->au4_sig_coeff_map[1] = 0;
605
214k
    pi2_coeff_data = &ps_tu_8x8->ai2_level[0];
606
607
608
214k
    if(!u1_field_coding_flag)
609
176k
    {
610
176k
        pu1_sigcoeff_context_inc =
611
176k
                        (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
176k
        ps_ctxt_sig_coeff = ps_dec->s_high_profile.ps_sigcoeff_8x8_frame;
618
176k
    }
619
38.1k
    else
620
38.1k
    {
621
38.1k
        pu1_sigcoeff_context_inc =
622
38.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
38.1k
        ps_ctxt_sig_coeff = ps_dec->s_high_profile.ps_sigcoeff_8x8_field;
629
38.1k
    }
630
631
    /*loading from strcuctures*/
632
633
214k
    u4_offset = ps_bitstrm->u4_ofst;
634
214k
    pu4_buffer = ps_bitstrm->pu4_buffer;
635
636
214k
    u4_code_int_range = ps_cab_env->u4_code_int_range;
637
214k
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
638
639
214k
    {
640
214k
        {
641
214k
            bin_ctxt_model_t *p_binCtxt_last, *p_binCtxt_last_org,
642
214k
                            *p_ctxt_sig_coeff_org;
643
214k
            UWORD32 uc_last_coeff_idx;
644
214k
            UWORD32 uc_bin;
645
214k
            UWORD32 i;
646
647
214k
            i = 0;
648
649
214k
            uc_last_coeff_idx = 63;
650
651
214k
            p_binCtxt_last_org = ps_ctxt_sig_coeff
652
214k
                            + LAST_COEFF_CTXT_MINUS_SIG_COEFF_CTXT_8X8;
653
654
214k
            p_ctxt_sig_coeff_org = ps_ctxt_sig_coeff;
655
656
214k
            do
657
5.07M
            {
658
                /*inilined DecodeDecision_onebin begins*/
659
5.07M
                {
660
5.07M
                    UWORD32 u4_qnt_int_range, u4_int_range_lps;
661
5.07M
                    UWORD32 u4_symbol, u1_mps_state;
662
5.07M
                    UWORD32 table_lookup;
663
5.07M
                    const UWORD32 *pu4_table =
664
5.07M
                                    (const UWORD32 *)ps_cab_env->cabac_table;
665
5.07M
                    UWORD32 u4_clz;
666
667
5.07M
                    u1_mps_state = (ps_ctxt_sig_coeff->u1_mps_state);
668
669
5.07M
                    u4_clz = CLZ(u4_code_int_range);
670
671
5.07M
                    u4_qnt_int_range = u4_code_int_range << u4_clz;
672
5.07M
                    u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
673
674
5.07M
                    table_lookup = pu4_table[(u1_mps_state << 2)
675
5.07M
                                    + u4_qnt_int_range];
676
677
5.07M
                    u4_int_range_lps = table_lookup & 0xff;
678
679
5.07M
                    u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
680
5.07M
                    u4_code_int_range = u4_code_int_range - u4_int_range_lps;
681
5.07M
                    u4_symbol = ((u1_mps_state >> 6) & 0x1);
682
5.07M
                    u1_mps_state = (table_lookup >> 8) & 0x7F;
683
684
5.07M
                    CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
685
5.07M
                                 u4_symbol, u4_int_range_lps, u1_mps_state,
686
5.07M
                                 table_lookup)
687
688
5.07M
                    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_14)
689
82.5k
                    {
690
82.5k
                        UWORD32 read_bits, u4_clz;
691
82.5k
                        u4_clz = CLZ(u4_code_int_range);
692
82.5k
                        NEXTBITS(read_bits, (u4_offset + 23), pu4_buffer,
693
82.5k
                                 u4_clz)
694
82.5k
                        FLUSHBITS(u4_offset, (u4_clz))
695
82.5k
                        u4_code_int_range = u4_code_int_range << u4_clz;
696
82.5k
                        u4_code_int_val_ofst = (u4_code_int_val_ofst << u4_clz)
697
82.5k
                                        | read_bits;
698
82.5k
                    }
699
700
5.07M
                    ps_ctxt_sig_coeff->u1_mps_state = u1_mps_state;
701
5.07M
                    uc_bin = u4_symbol;
702
5.07M
                }
703
                /*incrementing pointer to point to the context of the next bin*/
704
5.07M
                ps_ctxt_sig_coeff = p_ctxt_sig_coeff_org
705
5.07M
                                + pu1_sigcoeff_context_inc[i + 1];
706
707
                /*inilined DecodeDecision_onebin ends*/
708
5.07M
                if(uc_bin)
709
801k
                {
710
801k
                    num_sig_coeffs++;
711
801k
                    SET_BIT(ps_tu_8x8->au4_sig_coeff_map[i>31], (i > 31 ? i - 32:i));
712
713
801k
                    p_binCtxt_last = p_binCtxt_last_org
714
801k
                                    + pu1_lastcoeff_context_inc[i];
715
716
                    /*inilined DecodeDecision_onebin begins*/
717
718
801k
                    {
719
801k
                        UWORD32 u4_qnt_int_range, u4_int_range_lps;
720
801k
                        UWORD32 u4_symbol, u1_mps_state;
721
801k
                        UWORD32 table_lookup;
722
801k
                        const UWORD32 *pu4_table =
723
801k
                                        (const UWORD32 *)ps_cab_env->cabac_table;
724
801k
                        UWORD32 u4_clz;
725
726
801k
                        u1_mps_state = (p_binCtxt_last->u1_mps_state);
727
728
801k
                        u4_clz = CLZ(u4_code_int_range);
729
801k
                        u4_qnt_int_range = u4_code_int_range << u4_clz;
730
801k
                        u4_qnt_int_range = (u4_qnt_int_range >> 29)
731
801k
                                        & 0x3;
732
733
801k
                        table_lookup = pu4_table[(u1_mps_state << 2)
734
801k
                                        + u4_qnt_int_range];
735
801k
                        u4_int_range_lps = table_lookup & 0xff;
736
737
801k
                        u4_int_range_lps = u4_int_range_lps
738
801k
                                        << (23 - u4_clz);
739
740
801k
                        u4_code_int_range = u4_code_int_range
741
801k
                                        - u4_int_range_lps;
742
801k
                        u4_symbol = ((u1_mps_state >> 6) & 0x1);
743
801k
                        u1_mps_state = (table_lookup >> 8) & 0x7F;
744
745
801k
                        CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
746
801k
                                     u4_symbol, u4_int_range_lps,
747
801k
                                     u1_mps_state, table_lookup)
748
749
801k
                        p_binCtxt_last->u1_mps_state = u1_mps_state;
750
801k
                        uc_bin = u4_symbol;
751
801k
                    }
752
753
                    /*inilined DecodeDecision_onebin ends*/
754
801k
                    if(uc_bin == 1)
755
170k
                        goto label_read_levels;
756
757
801k
                }
758
759
4.90M
                i = i + 1;
760
761
4.90M
            }
762
4.90M
            while(i < uc_last_coeff_idx);
763
764
44.4k
            num_sig_coeffs++;
765
44.4k
            SET_BIT(ps_tu_8x8->au4_sig_coeff_map[i>31], (i > 31 ? i - 32:i));
766
767
214k
            label_read_levels: ;
768
214k
        }
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
214k
            WORD32 i2_abs_lvl;
775
214k
            UWORD32 u1_abs_level_equal1 = 1, u1_abs_level_gt1 = 0;
776
777
214k
            UWORD32 u4_ctx_inc;
778
214k
            UWORD32 ui_prefix;
779
214k
            bin_ctxt_model_t *p_ctxt_abs_level;
780
781
214k
            p_ctxt_abs_level =
782
214k
                            ps_dec->p_coeff_abs_level_minus1_t[LUMA_8X8_CTXCAT];
783
214k
            u4_ctx_inc = ((0x51));
784
785
            /*****************************************************/
786
            /* Main Loop runs for no. of Significant coefficient */
787
            /*****************************************************/
788
214k
            do
789
846k
            {
790
846k
                {
791
792
                    /*****************************************************/
793
                    /* inilining a modified ih264d_decode_bins_unary     */
794
                    /*****************************************************/
795
796
846k
                    {
797
846k
                        UWORD32 u4_value;
798
846k
                        UWORD32 u4_symbol;
799
846k
                        bin_ctxt_model_t *ps_bin_ctxt;
800
846k
                        UWORD32 u4_ctx_Inc;
801
846k
                        u4_value = 0;
802
803
846k
                        u4_ctx_Inc = u4_ctx_inc & 0xf;
804
846k
                        ps_bin_ctxt = p_ctxt_abs_level + u4_ctx_Inc;
805
806
846k
                        do
807
1.29M
                        {
808
1.29M
                            {
809
1.29M
                                UWORD32 u4_qnt_int_range,
810
1.29M
                                                u4_int_range_lps;
811
1.29M
                                UWORD32 u1_mps_state;
812
1.29M
                                UWORD32 table_lookup;
813
1.29M
                                const UWORD32 *pu4_table =
814
1.29M
                                                (const UWORD32 *)ps_cab_env->cabac_table;
815
1.29M
                                UWORD32 u4_clz;
816
817
1.29M
                                u1_mps_state = (ps_bin_ctxt->u1_mps_state);
818
1.29M
                                u4_clz = CLZ(u4_code_int_range);
819
1.29M
                                u4_qnt_int_range = u4_code_int_range
820
1.29M
                                                << u4_clz;
821
1.29M
                                u4_qnt_int_range = (u4_qnt_int_range
822
1.29M
                                                >> 29) & 0x3;
823
1.29M
                                table_lookup = pu4_table[(u1_mps_state << 2)
824
1.29M
                                                + u4_qnt_int_range];
825
1.29M
                                u4_int_range_lps = table_lookup & 0xff;
826
827
1.29M
                                u4_int_range_lps = u4_int_range_lps
828
1.29M
                                                << (23 - u4_clz);
829
1.29M
                                u4_code_int_range = u4_code_int_range
830
1.29M
                                                - u4_int_range_lps;
831
1.29M
                                u4_symbol = ((u1_mps_state >> 6) & 0x1);
832
1.29M
                                u1_mps_state = (table_lookup >> 8) & 0x7F;
833
834
1.29M
                                CHECK_IF_LPS(u4_code_int_range,
835
1.29M
                                             u4_code_int_val_ofst, u4_symbol,
836
1.29M
                                             u4_int_range_lps, u1_mps_state,
837
1.29M
                                             table_lookup)
838
839
1.29M
                                if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
840
31.6k
                                {
841
842
31.6k
                                    RENORM_RANGE_OFFSET(u4_code_int_range,
843
31.6k
                                                        u4_code_int_val_ofst,
844
31.6k
                                                        u4_offset, pu4_buffer)
845
31.6k
                                }
846
847
1.29M
                                ps_bin_ctxt->u1_mps_state = u1_mps_state;
848
1.29M
                            }
849
850
1.29M
                            u4_value++;
851
1.29M
                            ps_bin_ctxt = p_ctxt_abs_level + (u4_ctx_inc >> 4);
852
853
1.29M
                        }
854
1.29M
                        while(u4_symbol && (u4_value < UCOFF_LEVEL));
855
856
846k
                        ui_prefix = u4_value - 1 + u4_symbol;
857
846k
                    }
858
859
846k
                    if(ui_prefix == UCOFF_LEVEL)
860
19.4k
                    {
861
19.4k
                        UWORD32 ui16_sufS = 0;
862
19.4k
                        UWORD32 u1_max_bins;
863
19.4k
                        UWORD32 u4_value;
864
865
19.4k
                        i2_abs_lvl = UCOFF_LEVEL;
866
                        /*inlining ih264d_decode_bypass_bins_unary begins*/
867
868
19.4k
                        {
869
19.4k
                            UWORD32 uc_bin;
870
19.4k
                            UWORD32 bits_to_flush;
871
872
873
19.4k
                            bits_to_flush = 0;
874
                            /*renormalize to ensure there 23 bits more in the u4_code_int_val_ofst*/
875
19.4k
                            {
876
19.4k
                                UWORD32 u4_clz, read_bits;
877
878
19.4k
                                u4_clz = CLZ(u4_code_int_range);
879
19.4k
                                FLUSHBITS(u4_offset, u4_clz)
880
19.4k
                                NEXTBITS(read_bits, u4_offset, pu4_buffer, CABAC_BITS_TO_READ)
881
19.4k
                                u4_code_int_range = u4_code_int_range << u4_clz;
882
19.4k
                                u4_code_int_val_ofst = (u4_code_int_val_ofst
883
19.4k
                                                << u4_clz) | read_bits;
884
19.4k
                            }
885
886
19.4k
                            do
887
40.5k
                            {
888
40.5k
                                bits_to_flush++;
889
890
40.5k
                                u4_code_int_range = u4_code_int_range >> 1;
891
892
40.5k
                                if(u4_code_int_val_ofst >= u4_code_int_range)
893
21.3k
                                {
894
                                    /* S=1 */
895
21.3k
                                    uc_bin = 1;
896
21.3k
                                    u4_code_int_val_ofst -= u4_code_int_range;
897
21.3k
                                }
898
19.1k
                                else
899
19.1k
                                {
900
                                    /* S=0 */
901
19.1k
                                    uc_bin = 0;
902
19.1k
                                }
903
904
40.5k
                            }
905
40.5k
                            while(uc_bin && (bits_to_flush < CABAC_BITS_TO_READ));
906
907
19.4k
                            u4_value = (bits_to_flush - 1);
908
19.4k
                        }
909
                        /*inlining ih264d_decode_bypass_bins_unary ends*/
910
911
19.4k
                        ui16_sufS = (1 << u4_value);
912
19.4k
                        u1_max_bins = u4_value;
913
914
19.4k
                        if(u4_value > 0)
915
4.45k
                        {
916
                            /*inline bypassbins_flc begins*/
917
918
4.45k
                            if(u4_value > 10)
919
703
                            {
920
703
                                UWORD32 u4_clz, read_bits;
921
922
703
                                u4_clz = CLZ(u4_code_int_range);
923
703
                                FLUSHBITS(u4_offset, u4_clz)
924
703
                                NEXTBITS(read_bits, u4_offset, pu4_buffer, CABAC_BITS_TO_READ)
925
703
                                u4_code_int_range = u4_code_int_range << u4_clz;
926
703
                                u4_code_int_val_ofst = (u4_code_int_val_ofst
927
703
                                                << u4_clz) | read_bits;
928
703
                            }
929
930
4.45k
                            {
931
4.45k
                                UWORD32 ui_bins;
932
4.45k
                                UWORD32 uc_bin;
933
4.45k
                                UWORD32 bits_to_flush;
934
935
4.45k
                                ui_bins = 0;
936
4.45k
                                bits_to_flush = 0;
937
938
4.45k
                                do
939
21.0k
                                {
940
21.0k
                                    bits_to_flush++;
941
942
21.0k
                                    u4_code_int_range = u4_code_int_range >> 1;
943
944
21.0k
                                    if(u4_code_int_val_ofst
945
21.0k
                                                    >= u4_code_int_range)
946
7.11k
                                    {
947
                                        /* S=1 */
948
7.11k
                                        uc_bin = 1;
949
7.11k
                                        u4_code_int_val_ofst -=
950
7.11k
                                                        u4_code_int_range;
951
7.11k
                                    }
952
13.9k
                                    else
953
13.9k
                                    {
954
                                        /* S=0 */
955
13.9k
                                        uc_bin = 0;
956
13.9k
                                    }
957
958
21.0k
                                    ui_bins = ((ui_bins << 1) | uc_bin);
959
960
21.0k
                                }
961
21.0k
                                while(bits_to_flush < u1_max_bins);
962
963
4.45k
                                u4_value = ui_bins;
964
4.45k
                            }
965
                            /*inline bypassbins_flc ends*/
966
4.45k
                        }
967
968
                        //Value of K
969
19.4k
                        ui16_sufS += u4_value;
970
19.4k
                        i2_abs_lvl += (WORD32)ui16_sufS;
971
19.4k
                    }
972
826k
                    else
973
826k
                    {
974
826k
                        i2_abs_lvl = 1 + ui_prefix;
975
826k
                    }
976
977
846k
                    if(i2_abs_lvl > 1)
978
121k
                    {
979
121k
                        u1_abs_level_gt1++;
980
121k
                    }
981
846k
                    if(!u1_abs_level_gt1)
982
654k
                    {
983
654k
                        u1_abs_level_equal1++;
984
654k
                        u4_ctx_inc = (5 << 4) + MIN(u1_abs_level_equal1, 4);
985
654k
                    }
986
192k
                    else
987
192k
                    {
988
192k
                        u4_ctx_inc = (5 + MIN(u1_abs_level_gt1, 4)) << 4;
989
192k
                    }
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
846k
                    {
996
846k
                        u4_code_int_range = u4_code_int_range >> 1;
997
998
846k
                        if(u4_code_int_val_ofst >= (u4_code_int_range))
999
275k
                        {
1000
                            /* S=1 */
1001
275k
                            u4_code_int_val_ofst -= u4_code_int_range;
1002
275k
                            i2_abs_lvl = (-i2_abs_lvl);
1003
275k
                        }
1004
846k
                    }
1005
1006
846k
                    *pi2_coeff_data++ = i2_abs_lvl;
1007
846k
                    num_sig_coeffs--;
1008
846k
                }
1009
846k
            }
1010
846k
            while(num_sig_coeffs > 0);
1011
214k
        }
1012
214k
    }
1013
1014
0
    {
1015
214k
        WORD32 offset;
1016
214k
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_8x8;
1017
214k
        offset = ALIGN4(offset);
1018
214k
        ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
1019
214k
    }
1020
1021
    /*updating structures*/
1022
214k
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
1023
214k
    ps_cab_env->u4_code_int_range = u4_code_int_range;
1024
214k
    ps_bitstrm->u4_ofst = u4_offset;
1025
214k
}
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.04M
{
1073
1.04M
    UWORD32 u4_ctxinc, u4_subblock_coded;
1074
1.04M
    UWORD32 u4_top0, u4_top1;
1075
1.04M
    UWORD32 u4_csbp = 0;
1076
1.04M
    UWORD32 u4_idx = 0;
1077
1.04M
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1078
1.04M
    bin_ctxt_model_t * const ps_cbf = ps_dec->p_cbf_t[u4_ctx_cat];
1079
1.04M
    bin_ctxt_model_t *ps_src_bin_ctxt;
1080
1.04M
    bin_ctxt_model_t * const ps_sig_coeff_flag =
1081
1.04M
                    ps_dec->p_significant_coeff_flag_t[u4_ctx_cat];
1082
1083
1.04M
    UWORD8 *pu1_inv_scan = ps_dec->pu1_inv_scan;
1084
1085
    /*------------------------------------------------------*/
1086
    /* Residual 4x4 decoding: SubBlock 0                    */
1087
    /*------------------------------------------------------*/
1088
1.04M
    u4_ctxinc = ((!!pu1_top_nnz[0]) << 1) + (!!pu1_left_nnz[0]);
1089
1090
1.04M
    ps_src_bin_ctxt = ps_cbf + u4_ctxinc;
1091
1092
1.04M
    u4_top0 = ih264d_read_coeff4x4_cabac( ps_bitstrm,
1093
1.04M
                                         u4_ctx_cat, ps_sig_coeff_flag, ps_dec,
1094
1.04M
                                         ps_src_bin_ctxt);
1095
1096
1.04M
    INSERT_BIT(u4_csbp, u4_idx, u4_top0);
1097
1098
    /*------------------------------------------------------*/
1099
    /* Residual 4x4 decoding: SubBlock 1                    */
1100
    /*------------------------------------------------------*/
1101
1.04M
    u4_idx++;
1102
1.04M
    pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1103
1.04M
    u4_ctxinc = ((!!pu1_top_nnz[1]) << 1) + u4_top0;
1104
1105
1.04M
    ps_src_bin_ctxt = ps_cbf + u4_ctxinc;
1106
1107
1.04M
    u4_top1 = ih264d_read_coeff4x4_cabac(ps_bitstrm,
1108
1.04M
                                         u4_ctx_cat, ps_sig_coeff_flag, ps_dec,
1109
1.04M
                                         ps_src_bin_ctxt);
1110
1111
1.04M
    INSERT_BIT(u4_csbp, u4_idx, u4_top1);
1112
1.04M
    pu1_left_nnz[0] = u4_top1;
1113
1114
    /*------------------------------------------------------*/
1115
    /* Residual 4x4 decoding: SubBlock 2                    */
1116
    /*------------------------------------------------------*/
1117
1.04M
    u4_idx += (u4_sub_block_strd - 1);
1118
1.04M
    pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
1119
1.04M
    u4_ctxinc = (u4_top0 << 1) + (!!pu1_left_nnz[1]);
1120
1121
1.04M
    ps_src_bin_ctxt = ps_cbf + u4_ctxinc;
1122
1123
1.04M
    u4_subblock_coded = ih264d_read_coeff4x4_cabac(ps_bitstrm, u4_ctx_cat,
1124
1.04M
                                                   ps_sig_coeff_flag, ps_dec,
1125
1.04M
                                                   ps_src_bin_ctxt);
1126
1127
1.04M
    INSERT_BIT(u4_csbp, u4_idx, u4_subblock_coded);
1128
1.04M
    pu1_top_nnz[0] = u4_subblock_coded;
1129
1130
    /*------------------------------------------------------*/
1131
    /* Residual 4x4 decoding: SubBlock 3                    */
1132
    /*------------------------------------------------------*/
1133
1.04M
    u4_idx++;
1134
1.04M
    pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1135
1.04M
    u4_ctxinc = (u4_top1 << 1) + u4_subblock_coded;
1136
1137
1.04M
    ps_src_bin_ctxt = ps_cbf + u4_ctxinc;
1138
1139
1.04M
    u4_subblock_coded = ih264d_read_coeff4x4_cabac(ps_bitstrm, u4_ctx_cat,
1140
1.04M
                                                   ps_sig_coeff_flag, ps_dec,
1141
1.04M
                                                   ps_src_bin_ctxt);
1142
1143
1.04M
    INSERT_BIT(u4_csbp, u4_idx, u4_subblock_coded);
1144
1.04M
    pu1_top_nnz[1] = pu1_left_nnz[1] = u4_subblock_coded;
1145
1146
1.04M
    return (u4_csbp);
1147
1.04M
}
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
1.64M
{
1165
1.64M
    UWORD8 u1_cbp = ps_cur_mb_info->u1_cbp;
1166
1.64M
    UWORD16 ui16_csbp = 0;
1167
1.64M
    WORD16 *pi2_residual_buf;
1168
1.64M
    UWORD8 uc_ctx_cat;
1169
1.64M
    UWORD8 *pu1_top_nnz = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1170
1.64M
    UWORD8 *pu1_left_nnz = ps_dec->pu1_left_nnz_y;
1171
1.64M
    UWORD8 *pu1_top_nnz_uv = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1172
1.64M
    ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
1173
1.64M
    ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
1174
1.64M
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1175
1.64M
    UWORD32 u4_nbr_avail = ps_dec->u1_mb_ngbr_availablity;
1176
1.64M
    WORD16 *pi2_coeff_block = NULL;
1177
1.64M
    bin_ctxt_model_t *ps_src_bin_ctxt;
1178
1179
1.64M
    UWORD8 u1_top_dc_csbp = (ps_top_ctxt->u1_yuv_dc_csbp) >> 1;
1180
1.64M
    UWORD8 u1_left_dc_csbp = (ps_dec->pu1_left_yuv_dc_csbp[0]) >> 1;
1181
1182
1183
1.64M
    if(!(u4_nbr_avail & TOP_MB_AVAILABLE_MASK))
1184
262k
    {
1185
262k
        if(p_curr_ctxt->u1_mb_type & CAB_INTRA_MASK)
1186
95.3k
        {
1187
95.3k
            *(UWORD32 *)pu1_top_nnz = 0;
1188
95.3k
            u1_top_dc_csbp = 0;
1189
95.3k
            *(UWORD32 *)pu1_top_nnz_uv = 0;
1190
95.3k
        }
1191
167k
        else
1192
167k
        {
1193
167k
            *(UWORD32 *)pu1_top_nnz = 0x01010101;
1194
167k
            u1_top_dc_csbp = 0x3;
1195
167k
            *(UWORD32 *)pu1_top_nnz_uv = 0x01010101;
1196
167k
        }
1197
262k
    }
1198
1.38M
    else
1199
1.38M
    {
1200
1.38M
        UWORD32 *pu4_buf;
1201
1.38M
        UWORD8 *pu1_buf;
1202
1.38M
        pu1_buf = ps_cur_mb_info->ps_top_mb->pu1_nnz_y;
1203
1.38M
        pu4_buf = (UWORD32 *)pu1_buf;
1204
1.38M
        *(UWORD32 *)(pu1_top_nnz) = *pu4_buf;
1205
1206
1.38M
        pu1_buf = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv;
1207
1.38M
        pu4_buf = (UWORD32 *)pu1_buf;
1208
1.38M
        *(UWORD32 *)(pu1_top_nnz_uv) = *pu4_buf;
1209
1210
1.38M
    }
1211
1212
1.64M
    if(!(u4_nbr_avail & LEFT_MB_AVAILABLE_MASK))
1213
136k
    {
1214
136k
        if(p_curr_ctxt->u1_mb_type & CAB_INTRA_MASK)
1215
72.2k
        {
1216
72.2k
            UWORD32 *pu4_buf;
1217
72.2k
            UWORD8 *pu1_buf;
1218
72.2k
            *(UWORD32 *)pu1_left_nnz = 0;
1219
72.2k
            u1_left_dc_csbp = 0;
1220
72.2k
            pu1_buf = ps_dec->pu1_left_nnz_uv;
1221
72.2k
            pu4_buf = (UWORD32 *)pu1_buf;
1222
72.2k
            *pu4_buf = 0;
1223
72.2k
        }
1224
64.4k
        else
1225
64.4k
        {
1226
64.4k
            UWORD32 *pu4_buf;
1227
64.4k
            UWORD8 *pu1_buf;
1228
64.4k
            *(UWORD32 *)pu1_left_nnz = 0x01010101;
1229
64.4k
            u1_left_dc_csbp = 0x3;
1230
64.4k
            pu1_buf = ps_dec->pu1_left_nnz_uv;
1231
64.4k
            pu4_buf = (UWORD32 *)pu1_buf;
1232
64.4k
            *pu4_buf = 0x01010101;
1233
64.4k
        }
1234
136k
    }
1235
1236
1.64M
    uc_ctx_cat = u1_offset ? LUMA_AC_CTXCAT : LUMA_4X4_CTXCAT;
1237
1238
1.64M
    ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6;
1239
1.64M
    ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6;
1240
1.64M
    ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6;
1241
1.64M
    ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6;
1242
    // CHECK_THIS
1243
1.64M
    ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6;
1244
1.64M
    ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6;
1245
1246
1.64M
    if(u1_cbp & 0x0f)
1247
364k
    {
1248
364k
        if(ps_cur_mb_info->u1_tran_form8x8 == 0)
1249
284k
        {
1250
            /*******************************************************************/
1251
            /* Block 0 residual decoding, check cbp and proceed (subblock = 0) */
1252
            /*******************************************************************/
1253
284k
            if(!(u1_cbp & 0x1))
1254
45.7k
            {
1255
45.7k
                *(UWORD16 *)(pu1_top_nnz) = 0;
1256
45.7k
                *(UWORD16 *)(pu1_left_nnz) = 0;
1257
45.7k
            }
1258
238k
            else
1259
238k
            {
1260
238k
                ui16_csbp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 4,
1261
238k
                                                        uc_ctx_cat, ps_dec,
1262
238k
                                                        pu1_top_nnz,
1263
238k
                                                        pu1_left_nnz);
1264
238k
            }
1265
1266
            /*******************************************************************/
1267
            /* Block 1 residual decoding, check cbp and proceed (subblock = 2) */
1268
            /*******************************************************************/
1269
284k
            pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK);
1270
284k
            if(!(u1_cbp & 0x2))
1271
50.1k
            {
1272
50.1k
                *(UWORD16 *)(pu1_top_nnz + 2) = 0;
1273
50.1k
                *(UWORD16 *)(pu1_left_nnz) = 0;
1274
50.1k
            }
1275
234k
            else
1276
234k
            {
1277
234k
                UWORD32 u4_temp = ih264d_cabac_parse_8x8block(pi2_coeff_block,
1278
234k
                                                              4, uc_ctx_cat,
1279
234k
                                                              ps_dec,
1280
234k
                                                              (pu1_top_nnz + 2),
1281
234k
                                                              pu1_left_nnz);
1282
234k
                ui16_csbp |= (u4_temp << 2);
1283
234k
            }
1284
1285
            /*******************************************************************/
1286
            /* Block 2 residual decoding, check cbp and proceed (subblock = 8) */
1287
            /*******************************************************************/
1288
284k
            pi2_coeff_block += (6 * NUM_COEFFS_IN_4x4BLK);
1289
284k
            if(!(u1_cbp & 0x4))
1290
44.7k
            {
1291
44.7k
                *(UWORD16 *)(pu1_top_nnz) = 0;
1292
44.7k
                *(UWORD16 *)(pu1_left_nnz + 2) = 0;
1293
44.7k
            }
1294
239k
            else
1295
239k
            {
1296
239k
                UWORD32 u4_temp = ih264d_cabac_parse_8x8block(
1297
239k
                                pi2_coeff_block, 4, uc_ctx_cat, ps_dec,
1298
239k
                                pu1_top_nnz, (pu1_left_nnz + 2));
1299
239k
                ui16_csbp |= (u4_temp << 8);
1300
239k
            }
1301
1302
            /*******************************************************************/
1303
            /* Block 3 residual decoding, check cbp and proceed (subblock = 10)*/
1304
            /*******************************************************************/
1305
284k
            pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK);
1306
284k
            if(!(u1_cbp & 0x8))
1307
50.5k
            {
1308
50.5k
                *(UWORD16 *)(pu1_top_nnz + 2) = 0;
1309
50.5k
                *(UWORD16 *)(pu1_left_nnz + 2) = 0;
1310
50.5k
            }
1311
233k
            else
1312
233k
            {
1313
233k
                UWORD32 u4_temp = ih264d_cabac_parse_8x8block(
1314
233k
                                pi2_coeff_block, 4, uc_ctx_cat, ps_dec,
1315
233k
                                (pu1_top_nnz + 2), (pu1_left_nnz + 2));
1316
233k
                ui16_csbp |= (u4_temp << 10);
1317
233k
            }
1318
1319
284k
        }
1320
80.0k
        else
1321
80.0k
        {
1322
80.0k
            ui16_csbp = 0;
1323
1324
            /*******************************************************************/
1325
            /* Block 0 residual decoding, check cbp and proceed (subblock = 0) */
1326
            /*******************************************************************/
1327
80.0k
            if(!(u1_cbp & 0x1))
1328
24.6k
            {
1329
24.6k
                *(UWORD16 *)(pu1_top_nnz) = 0;
1330
24.6k
                *(UWORD16 *)(pu1_left_nnz) = 0;
1331
24.6k
            }
1332
55.3k
            else
1333
55.3k
            {
1334
1335
55.3k
                dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1336
1337
55.3k
                ih264d_read_coeff8x8_cabac( ps_bitstrm,
1338
55.3k
                                           ps_dec, ps_cur_mb_info);
1339
1340
55.3k
                pu1_left_nnz[0] = 1;
1341
55.3k
                pu1_left_nnz[1] = 1;
1342
1343
55.3k
                pu1_top_nnz[0] = 1;
1344
55.3k
                pu1_top_nnz[1] = 1;
1345
1346
                /* added to be used by BS computation module */
1347
55.3k
                ui16_csbp |= 0x0033;
1348
55.3k
            }
1349
1350
            /*******************************************************************/
1351
            /* Block 1 residual decoding, check cbp and proceed (subblock = 2) */
1352
            /*******************************************************************/
1353
80.0k
            pi2_coeff_block += 64;
1354
1355
80.0k
            if(!(u1_cbp & 0x2))
1356
26.1k
            {
1357
26.1k
                *(UWORD16 *)(pu1_top_nnz + 2) = 0;
1358
26.1k
                *(UWORD16 *)(pu1_left_nnz) = 0;
1359
26.1k
            }
1360
53.9k
            else
1361
53.9k
            {
1362
1363
1364
53.9k
                dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1365
1366
53.9k
                ih264d_read_coeff8x8_cabac(ps_bitstrm,
1367
53.9k
                                           ps_dec, ps_cur_mb_info);
1368
1369
53.9k
                pu1_left_nnz[0] = 1;
1370
53.9k
                pu1_left_nnz[1] = 1;
1371
1372
53.9k
                pu1_top_nnz[2] = 1;
1373
53.9k
                pu1_top_nnz[3] = 1;
1374
1375
                /* added to be used by BS computation module */
1376
53.9k
                ui16_csbp |= 0x00CC;
1377
1378
53.9k
            }
1379
1380
            /*******************************************************************/
1381
            /* Block 2 residual decoding, check cbp and proceed (subblock = 8) */
1382
            /*******************************************************************/
1383
80.0k
            pi2_coeff_block += 64;
1384
80.0k
            if(!(u1_cbp & 0x4))
1385
25.6k
            {
1386
25.6k
                *(UWORD16 *)(pu1_top_nnz) = 0;
1387
25.6k
                *(UWORD16 *)(pu1_left_nnz + 2) = 0;
1388
25.6k
            }
1389
54.3k
            else
1390
54.3k
            {
1391
1392
54.3k
                dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1393
1394
54.3k
                ih264d_read_coeff8x8_cabac(ps_bitstrm,
1395
54.3k
                                           ps_dec, ps_cur_mb_info);
1396
1397
54.3k
                pu1_left_nnz[2] = 1;
1398
54.3k
                pu1_left_nnz[3] = 1;
1399
1400
54.3k
                pu1_top_nnz[0] = 1;
1401
54.3k
                pu1_top_nnz[1] = 1;
1402
1403
                /* added to be used by BS computation module */
1404
54.3k
                ui16_csbp |= 0x3300;
1405
54.3k
            }
1406
1407
            /*******************************************************************/
1408
            /* Block 3 residual decoding, check cbp and proceed (subblock = 10)*/
1409
            /*******************************************************************/
1410
80.0k
            pi2_coeff_block += 64;
1411
1412
80.0k
            if(!(u1_cbp & 0x8))
1413
29.1k
            {
1414
29.1k
                *(UWORD16 *)(pu1_top_nnz + 2) = 0;
1415
29.1k
                *(UWORD16 *)(pu1_left_nnz + 2) = 0;
1416
29.1k
            }
1417
50.9k
            else
1418
50.9k
            {
1419
1420
50.9k
                dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1421
1422
50.9k
                ih264d_read_coeff8x8_cabac(ps_bitstrm,
1423
50.9k
                                           ps_dec, ps_cur_mb_info);
1424
1425
50.9k
                pu1_left_nnz[2] = 1;
1426
50.9k
                pu1_left_nnz[3] = 1;
1427
1428
50.9k
                pu1_top_nnz[2] = 1;
1429
50.9k
                pu1_top_nnz[3] = 1;
1430
1431
                /* added to be used by BS computation module */
1432
50.9k
                ui16_csbp |= 0xCC00;
1433
50.9k
            }
1434
80.0k
        }
1435
364k
    }
1436
1.28M
    else
1437
1.28M
    {
1438
1.28M
        *(UWORD32 *)(pu1_top_nnz) = 0;
1439
1.28M
        *(UWORD32 *)(pu1_left_nnz) = 0;
1440
1.28M
    }
1441
    /*--------------------------------------------------------------------*/
1442
    /* Store the last row of N values to top row                          */
1443
    /*--------------------------------------------------------------------*/
1444
1.64M
    ps_cur_mb_info->u2_luma_csbp = ui16_csbp;
1445
1.64M
    ps_cur_mb_info->ps_curmb->u2_luma_csbp = ui16_csbp;
1446
1.64M
    {
1447
1.64M
        WORD8 i;
1448
1.64M
        UWORD16 u2_chroma_csbp = 0;
1449
1.64M
        ps_cur_mb_info->u2_chroma_csbp = 0;
1450
1451
1.64M
        u1_cbp >>= 4;
1452
1.64M
        pu1_top_nnz = pu1_top_nnz_uv;
1453
1.64M
        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
1.64M
        if(u1_cbp == CBPC_ALLZERO)
1459
1.52M
        {
1460
1.52M
            ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x1;
1461
1.52M
            *(UWORD32 *)(pu1_top_nnz) = 0;
1462
1.52M
            *(UWORD32 *)(pu1_left_nnz) = 0;
1463
1.52M
            p_curr_ctxt->u1_yuv_dc_csbp &= 0x1;
1464
1.52M
            return (0);
1465
1.52M
        }
1466
1467
        /*--------------------------------------------------------------------*/
1468
        /* Decode Chroma DC values                                            */
1469
        /*--------------------------------------------------------------------*/
1470
376k
        for(i = 0; i < 2; i++)
1471
250k
        {
1472
250k
            UWORD8 uc_a = 1, uc_b = 1;
1473
250k
            UWORD32 u4_ctx_inc;
1474
250k
            UWORD8 uc_codedBlockFlag;
1475
250k
            UWORD8 pu1_inv_scan[4] =
1476
250k
                { 0, 1, 2, 3 };
1477
250k
            WORD32 u4_scale;
1478
250k
            WORD32 i4_mb_inter_inc;
1479
250k
            tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
1480
250k
                            (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
1481
250k
            WORD16 *pi2_coeff_data =
1482
250k
                            (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
1483
250k
            WORD16 ai2_dc_coef[4];
1484
1485
250k
            INC_SYM_COUNT(&(ps_dec->s_cab_dec_env));
1486
250k
            u4_scale = (i) ?
1487
125k
                            (ps_dec->pu2_quant_scale_v[0]
1488
125k
                                            << ps_dec->u1_qp_v_div6) :
1489
250k
                            (ps_dec->pu2_quant_scale_u[0]
1490
125k
                                            << ps_dec->u1_qp_u_div6);
1491
1492
            /*--------------------------------------------------------------------*/
1493
            /* Decode Bitstream to get the DC coeff                               */
1494
            /*--------------------------------------------------------------------*/
1495
250k
            uc_a = (u1_left_dc_csbp >> i) & 0x01;
1496
250k
            uc_b = (u1_top_dc_csbp >> i) & 0x01;
1497
250k
            u4_ctx_inc = (uc_a + (uc_b << 1));
1498
1499
250k
            ps_src_bin_ctxt = (ps_dec->p_cbf_t[CHROMA_DC_CTXCAT]) + u4_ctx_inc;
1500
1501
250k
            uc_codedBlockFlag =
1502
250k
                            ih264d_read_coeff4x4_cabac(ps_bitstrm,
1503
250k
                                            CHROMA_DC_CTXCAT,
1504
250k
                                            ps_dec->p_significant_coeff_flag_t[CHROMA_DC_CTXCAT],
1505
250k
                                            ps_dec, ps_src_bin_ctxt);
1506
1507
250k
            i4_mb_inter_inc = (!((ps_cur_mb_info->ps_curmb->u1_mb_type == I_4x4_MB)
1508
177k
                            || (ps_cur_mb_info->ps_curmb->u1_mb_type == I_16x16_MB)))
1509
250k
                            * 3;
1510
1511
250k
            if(ps_dec->s_high_profile.u1_scaling_present)
1512
74.6k
            {
1513
74.6k
                u4_scale *=
1514
74.6k
                                ps_dec->s_high_profile.i2_scalinglist4x4[i4_mb_inter_inc
1515
74.6k
                                                + 1 + i][0];
1516
1517
74.6k
            }
1518
176k
            else
1519
176k
            {
1520
176k
                u4_scale <<= 4;
1521
176k
            }
1522
1523
250k
            if(uc_codedBlockFlag)
1524
142k
            {
1525
142k
                WORD32 i_z0, i_z1, i_z2, i_z3;
1526
142k
                WORD32 *pi4_scale;
1527
1528
142k
                SET_BIT(u1_top_dc_csbp, i);
1529
142k
                SET_BIT(u1_left_dc_csbp, i);
1530
1531
142k
                ai2_dc_coef[0] = 0;
1532
142k
                ai2_dc_coef[1] = 0;
1533
142k
                ai2_dc_coef[2] = 0;
1534
142k
                ai2_dc_coef[3] = 0;
1535
1536
142k
                ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
1537
142k
                                                 ai2_dc_coef,
1538
142k
                                                 pu1_inv_scan);
1539
142k
                i_z0 = (ai2_dc_coef[0] + ai2_dc_coef[2]);
1540
142k
                i_z1 = (ai2_dc_coef[0] - ai2_dc_coef[2]);
1541
142k
                i_z2 = (ai2_dc_coef[1] - ai2_dc_coef[3]);
1542
142k
                i_z3 = (ai2_dc_coef[1] + ai2_dc_coef[3]);
1543
1544
                /*-----------------------------------------------------------*/
1545
                /* Scaling and storing the values back                       */
1546
                /*-----------------------------------------------------------*/
1547
142k
                *pi2_coeff_data++ = ((i_z0 + i_z3) * u4_scale) >> 5;
1548
142k
                *pi2_coeff_data++ = ((i_z0 - i_z3) * u4_scale) >> 5;
1549
142k
                *pi2_coeff_data++ = ((i_z1 + i_z2) * u4_scale) >> 5;
1550
142k
                *pi2_coeff_data++ = ((i_z1 - i_z2) * u4_scale) >> 5;
1551
1552
142k
                ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_data;
1553
1554
142k
                SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,(i+1));
1555
142k
            }
1556
108k
            else
1557
108k
            {
1558
108k
                CLEARBIT(u1_top_dc_csbp, i);
1559
108k
                CLEARBIT(u1_left_dc_csbp, i);
1560
108k
            }
1561
250k
        }
1562
1563
        /*********************************************************************/
1564
        /*                   Update the DC csbp                              */
1565
        /*********************************************************************/
1566
125k
        ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x1;
1567
125k
        p_curr_ctxt->u1_yuv_dc_csbp &= 0x1;
1568
125k
        ps_dec->pu1_left_yuv_dc_csbp[0] |= (u1_left_dc_csbp << 1);
1569
125k
        p_curr_ctxt->u1_yuv_dc_csbp |= (u1_top_dc_csbp << 1);
1570
125k
        if(u1_cbp == CBPC_ACZERO)
1571
75.2k
        {
1572
75.2k
            *(UWORD32 *)(pu1_top_nnz) = 0;
1573
75.2k
            *(UWORD32 *)(pu1_left_nnz) = 0;
1574
75.2k
            return (0);
1575
75.2k
        }
1576
        /*--------------------------------------------------------------------*/
1577
        /* Decode Chroma AC values                                            */
1578
        /*--------------------------------------------------------------------*/
1579
50.1k
        {
1580
50.1k
            UWORD32 u4_temp;
1581
            /*****************************************************************/
1582
            /* U Block  residual decoding, check cbp and proceed (subblock=0)*/
1583
            /*****************************************************************/
1584
50.1k
            u2_chroma_csbp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 2,
1585
50.1k
            CHROMA_AC_CTXCAT,
1586
50.1k
                                                         ps_dec, pu1_top_nnz,
1587
50.1k
                                                         pu1_left_nnz);
1588
1589
50.1k
            pi2_coeff_block += MB_CHROM_SIZE;
1590
            /*****************************************************************/
1591
            /* V Block  residual decoding, check cbp and proceed (subblock=1)*/
1592
            /*****************************************************************/
1593
50.1k
            u4_temp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 2,
1594
50.1k
            CHROMA_AC_CTXCAT,
1595
50.1k
                                                  ps_dec, (pu1_top_nnz + 2),
1596
50.1k
                                                  (pu1_left_nnz + 2));
1597
50.1k
            u2_chroma_csbp |= (u4_temp << 4);
1598
50.1k
        }
1599
        /*********************************************************************/
1600
        /*                   Update the AC csbp                              */
1601
        /*********************************************************************/
1602
50.1k
        ps_cur_mb_info->u2_chroma_csbp = u2_chroma_csbp;
1603
50.1k
    }
1604
1605
0
    return (0);
1606
125k
}
1607