Coverage Report

Created: 2026-01-10 06:44

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