Coverage Report

Created: 2026-04-12 06:59

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