Coverage Report

Created: 2026-10-28 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/decoder/ihevcd_parse_residual.c
Line
Count
Source
1
/******************************************************************************
2
*
3
* Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
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
/**
19
*******************************************************************************
20
* @file
21
*  ihevcd_parse_residual.c
22
*
23
* @brief
24
*  Contains functions for parsing residual data at TU level
25
*
26
* @author
27
*  Harish
28
*
29
* @par List of Functions:
30
*
31
* @remarks
32
*  None
33
*
34
*******************************************************************************
35
*/
36
/*****************************************************************************/
37
/* File Includes                                                             */
38
/*****************************************************************************/
39
#include <stdio.h>
40
#include <stddef.h>
41
#include <stdlib.h>
42
#include <string.h>
43
#include <assert.h>
44
45
#include "ihevc_typedefs.h"
46
#include "iv.h"
47
#include "ivd.h"
48
#include "ihevcd_cxa.h"
49
50
#include "ihevc_defs.h"
51
#include "ihevc_debug.h"
52
#include "ihevc_structs.h"
53
#include "ihevc_macros.h"
54
#include "ihevc_platform_macros.h"
55
56
#include "ihevc_common_tables.h"
57
#include "ihevc_error.h"
58
#include "ihevc_cabac_tables.h"
59
60
#include "ihevcd_trace.h"
61
#include "ihevcd_defs.h"
62
#include "ihevcd_function_selector.h"
63
#include "ihevcd_structs.h"
64
#include "ihevcd_error.h"
65
#include "ihevcd_nal.h"
66
#include "ihevcd_bitstream.h"
67
#include "ihevcd_utils.h"
68
#include "ihevcd_parse_residual.h"
69
#include "ihevcd_cabac.h"
70
71
/**
72
  *****************************************************************************
73
  * @brief  returns context increment for sig coeff based on csbf neigbour
74
  *         flags (bottom and right) and current coeff postion in 4x4 block
75
  *         See section 9.3.3.1.4 for details on this context increment
76
  *
77
  * input   : neigbour csbf flags(bit0:rightcsbf, bit1:bottom csbf)
78
  *           coeff idx in raster order (0-15)
79
  *
80
  * output  : context increment for sig coeff flag
81
  *
82
  *****************************************************************************
83
  */
84
const UWORD8 gau1_ihevcd_sigcoeff_ctxtinc[3][4][16] =
85
{
86
87
    {
88
        /* nbr csbf = 0:  sigCtx = (xP+yP == 0) ? 2 : (xP+yP < 3) ? 1: 0 */
89
        { 2,    1,    1,    1,    1,    1,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
90
        /* nbr csbf = 1:  sigCtx = (yP == 0) ? 2 : (yP == 1) ? 1: 0      */
91
        { 2,    1,    2,    0,    1,    2,    0,    0,    1,    2,    0,    0,    1,    0,    0,    0 },
92
        /* nbr csbf = 2:  sigCtx = (xP == 0) ? 2 : (xP == 1) ? 1: 0      */
93
        { 2,    2,    1,    2,    1,    0,    2,    1,    0,    0,    1,    0,    0,    0,    0,    0 },
94
        /* nbr csbf = 3:  sigCtx = 2                                     */
95
        { 2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2 },
96
    },
97
    {
98
        /* nbr csbf = 0:  sigCtx = (xP+yP == 0) ? 2 : (xP+yP < 3) ? 1: 0 */
99
        { 2,    1,    1,    0,    1,    1,    0,    0,    1,    0,    0,    0,    0,    0,    0,    0 },
100
        /* nbr csbf = 1:  sigCtx = (yP == 0) ? 2 : (yP == 1) ? 1: 0      */
101
        { 2,    2,    2,    2,    1,    1,    1,    1,    0,    0,    0,    0,    0,    0,    0,    0 },
102
        /* nbr csbf = 2:  sigCtx = (xP == 0) ? 2 : (xP == 1) ? 1: 0      */
103
        { 2,    1,    0,    0,    2,    1,    0,    0,    2,    1,    0,    0,    2,    1,    0,    0 },
104
        /* nbr csbf = 3:  sigCtx = 2                                     */
105
        { 2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2 },
106
    },
107
    {
108
        /* nbr csbf = 0:  sigCtx = (xP+yP == 0) ? 2 : (xP+yP < 3) ? 1: 0 */
109
        { 2,    1,    1,    0,    1,    1,    0,    0,    1,    0,    0,    0,    0,    0,    0,    0 },
110
        /* nbr csbf = 1:  sigCtx = (yP == 0) ? 2 : (yP == 1) ? 1: 0      */
111
        { 2,    1,    0,    0,    2,    1,    0,    0,    2,    1,    0,    0,    2,    1,    0,    0 },
112
        /* nbr csbf = 2:  sigCtx = (xP == 0) ? 2 : (xP == 1) ? 1: 0      */
113
        { 2,    2,    2,    2,    1,    1,    1,    1,    0,    0,    0,    0,    0,    0,    0,    0 },
114
        /* nbr csbf = 3:  sigCtx = 2                                     */
115
        { 2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2 },
116
    },
117
118
119
};
120
121
122
123
/**
124
  *****************************************************************************
125
  * @brief  returns context increment for sig coeff for 4x4 tranform size as
126
  *         per Table 9-39 in section 9.3.3.1.4
127
  *
128
  * input   : coeff idx in raster order (0-15)
129
  *
130
  * output  : context increment for sig coeff flag
131
  *
132
  *****************************************************************************
133
  */
134
const UWORD8 gau1_ihevcd_sigcoeff_ctxtinc_tr4[3][16] =
135
{
136
    /* Upright diagonal scan */
137
    {
138
        0,    2,    1,    6,
139
        3,    4,    7,    6,
140
        4,    5,    7,    8,
141
        5,    8,    8,    8,
142
    },
143
    /* Horizontal scan */
144
    {
145
        0,    1,    4,    5,
146
        2,    3,    4,    5,
147
        6,    6,    8,    8,
148
        7,    7,    8,    8,
149
    },
150
    /* Vertical scan */
151
    {
152
        0,    2,    6,    7,
153
        1,    3,    6,    7,
154
        4,    4,    8,    8,
155
        5,    5,    8,    8,
156
    },
157
};
158
159
160
/**
161
*******************************************************************************
162
*
163
* @brief
164
*  Parses Residual coding
165
*
166
* @par Description:
167
*  Parses Residual coding as per  Section:7.3.13
168
*
169
* @param[in] ps_codec
170
*  Pointer to codec context
171
*
172
* @returns  error code from IHEVCD_ERROR_T
173
*
174
* @remarks
175
*
176
*
177
*******************************************************************************
178
*/
179
180
WORD32 ihevcd_parse_residual_coding(codec_t *ps_codec,
181
                                    WORD32 x0, WORD32 y0,
182
                                    WORD32 log2_trafo_size,
183
                                    WORD32 c_idx,
184
                                    WORD32 intra_pred_mode)
185
10.3M
{
186
10.3M
    IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
187
10.3M
    WORD32 transform_skip_flag;
188
10.3M
#ifdef ENABLE_MAIN_REXT_PROFILE
189
10.3M
    WORD32 explicit_rdpcm_flag, explicit_rdpcm_dir;
190
10.3M
#endif
191
10.3M
    WORD32 value;
192
10.3M
    sps_t *ps_sps;
193
10.3M
    pps_t *ps_pps;
194
10.3M
    WORD32 last_scan_pos, last_sub_blk;
195
10.3M
    bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm;
196
10.3M
    WORD32 last_significant_coeff_x_prefix, last_significant_coeff_y_prefix;
197
10.3M
    WORD32 last_significant_coeff_x, last_significant_coeff_y;
198
10.3M
    const UWORD8 *pu1_scan_blk = NULL, *pu1_scan_coeff;
199
10.3M
    WORD32 scan_idx;
200
10.3M
    WORD32 i;
201
10.3M
    WORD32 sign_data_hiding_flag;
202
10.3M
    cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac;
203
10.3M
    WORD32 gt1_ctxt = 1;
204
10.3M
    WORD32 c_max;
205
10.3M
    UWORD16 au2_csbf[9];
206
10.3M
    tu_sblk_coeff_data_t *ps_tu_sblk_coeff_data;
207
10.3M
    WORD8 *pi1_num_coded_subblks;
208
10.3M
    WORD32 num_subblks;
209
10.3M
    WORD32 sig_coeff_base_ctxt, abs_gt1_base_ctxt;
210
10.3M
    UNUSED(x0);
211
10.3M
    UNUSED(y0);
212
10.3M
    ps_sps = ps_codec->s_parse.ps_sps;
213
10.3M
    ps_pps = ps_codec->s_parse.ps_pps;
214
215
10.3M
    sign_data_hiding_flag = ps_pps->i1_sign_data_hiding_flag;
216
10.3M
    transform_skip_flag = 0;
217
10.3M
#ifdef ENABLE_MAIN_REXT_PROFILE
218
10.3M
    explicit_rdpcm_flag = 0;
219
10.3M
    explicit_rdpcm_dir = 0;
220
10.3M
#endif
221
10.3M
    if(ps_pps->i1_transform_skip_enabled_flag &&
222
6.91M
       !ps_codec->s_parse.s_cu.i4_cu_transquant_bypass &&
223
6.74M
#ifdef ENABLE_MAIN_REXT_PROFILE
224
6.74M
       (log2_trafo_size <= ps_pps->i1_log2_max_transform_skip_block_size_minus2 + 2)
225
#else
226
       (log2_trafo_size == 2)
227
#endif
228
10.3M
       )
229
2.92M
    {
230
2.92M
        WORD32 ctxt_idx;
231
232
2.92M
        if(!c_idx)
233
1.63M
        {
234
1.63M
            ctxt_idx = IHEVC_CAB_TFM_SKIP0;
235
1.63M
        }
236
1.28M
        else
237
1.28M
        {
238
1.28M
            ctxt_idx = IHEVC_CAB_TFM_SKIP12;
239
1.28M
        }
240
2.92M
        TRACE_CABAC_CTXT("transform_skip_flag", ps_cabac->u4_range, ctxt_idx);
241
2.92M
        value = ihevcd_cabac_decode_bin(ps_cabac,
242
2.92M
                                        ps_bitstrm,
243
2.92M
                                        ctxt_idx);
244
2.92M
        AEV_TRACE("transform_skip_flag", value, ps_cabac->u4_range);
245
2.92M
        transform_skip_flag = value;
246
2.92M
    }
247
248
10.3M
#ifdef ENABLE_MAIN_REXT_PROFILE
249
10.3M
    if(PRED_MODE_INTER == ps_codec->s_parse.s_cu.i4_pred_mode
250
379k
                    && ps_sps->i1_explicit_rdpcm_enabled_flag
251
3.57k
                    && (transform_skip_flag || ps_codec->s_parse.s_cu.i4_cu_transquant_bypass))
252
253
2.63k
    {
254
2.63k
        WORD32 ctxt_idx = IHEVC_CAB_EXPLICIT_RDPCM_FLAG + (c_idx != 0);
255
2.63k
        TRACE_CABAC_CTXT("explicit_rdpcm_flag", ps_cabac->u4_range, ctxt_idx);
256
2.63k
        value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx);
257
2.63k
        AEV_TRACE("explicit_rdpcm_flag", value, ps_cabac->u4_range);
258
2.63k
        explicit_rdpcm_flag = value;
259
260
2.63k
        if(explicit_rdpcm_flag)
261
1.76k
        {
262
1.76k
            ctxt_idx = IHEVC_CAB_EXPLICIT_RDPCM_DIR + (c_idx != 0);
263
1.76k
            TRACE_CABAC_CTXT("explicit_rdpcm_dir_flag", ps_cabac->u4_range, ctxt_idx);
264
1.76k
            value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx);
265
1.76k
            AEV_TRACE("explicit_rdpcm_dir_flag", value, ps_cabac->u4_range);
266
1.76k
            explicit_rdpcm_dir = value;
267
1.76k
        }
268
2.63k
    }
269
10.3M
#endif
270
271
    /* code the last_coeff_x_prefix as tunary binarized code */
272
10.3M
    {
273
10.3M
        WORD32 ctxt_idx_x, ctxt_idx_y, ctx_shift;
274
10.3M
        WORD32 ctx_offset;
275
10.3M
        c_max = (log2_trafo_size << 1) - 1;
276
277
10.3M
        if(!c_idx)
278
5.87M
        {
279
5.87M
            ctx_offset = (3 * (log2_trafo_size - 2)) + ((log2_trafo_size - 1) >> 2);
280
5.87M
            ctxt_idx_x = IHEVC_CAB_COEFFX_PREFIX + ctx_offset;
281
5.87M
            ctxt_idx_y = IHEVC_CAB_COEFFY_PREFIX + ctx_offset;
282
5.87M
            ctx_shift  = (log2_trafo_size + 1) >> 2;
283
5.87M
        }
284
4.48M
        else
285
4.48M
        {
286
4.48M
            ctxt_idx_x = IHEVC_CAB_COEFFX_PREFIX + 15;
287
4.48M
            ctxt_idx_y = IHEVC_CAB_COEFFY_PREFIX + 15;
288
4.48M
            ctx_shift  = log2_trafo_size  - 2;
289
4.48M
        }
290
291
10.3M
        TRACE_CABAC_CTXT("last_coeff_x_prefix", ps_cabac->u4_range, ctxt_idx_x);
292
10.3M
        last_significant_coeff_x_prefix = ihevcd_cabac_decode_bins_tunary(ps_cabac,
293
10.3M
                                                                          ps_bitstrm,
294
10.3M
                                                                          c_max,
295
10.3M
                                                                          ctxt_idx_x,
296
10.3M
                                                                          ctx_shift,
297
10.3M
                                                                          c_max);
298
299
10.3M
        AEV_TRACE("last_coeff_x_prefix", last_significant_coeff_x_prefix, ps_cabac->u4_range);
300
301
10.3M
        TRACE_CABAC_CTXT("last_coeff_y_prefix", ps_cabac->u4_range, ctxt_idx_y);
302
10.3M
        last_significant_coeff_y_prefix = ihevcd_cabac_decode_bins_tunary(ps_cabac,
303
10.3M
                                                                          ps_bitstrm,
304
10.3M
                                                                          c_max,
305
10.3M
                                                                          ctxt_idx_y,
306
10.3M
                                                                          ctx_shift,
307
10.3M
                                                                          c_max);
308
309
10.3M
        AEV_TRACE("last_coeff_y_prefix", last_significant_coeff_y_prefix, ps_cabac->u4_range);
310
311
312
10.3M
        last_significant_coeff_x = last_significant_coeff_x_prefix;
313
10.3M
        if(last_significant_coeff_x_prefix > 3)
314
1.29M
        {
315
1.29M
            WORD32 suf_length = ((last_significant_coeff_x_prefix - 2) >> 1);
316
317
1.29M
            value = ihevcd_cabac_decode_bypass_bins(ps_cabac,
318
1.29M
                                                    ps_bitstrm,
319
1.29M
                                                    suf_length);
320
321
1.29M
            AEV_TRACE("last_coeff_x_suffix", value, ps_cabac->u4_range);
322
323
324
1.29M
            last_significant_coeff_x =
325
1.29M
                            (1 << ((last_significant_coeff_x_prefix >> 1) - 1)) *
326
1.29M
                            (2 + (last_significant_coeff_x_prefix & 1)) + value;
327
1.29M
        }
328
329
330
10.3M
        last_significant_coeff_y = last_significant_coeff_y_prefix;
331
10.3M
        if(last_significant_coeff_y_prefix > 3)
332
1.27M
        {
333
1.27M
            WORD32 suf_length = ((last_significant_coeff_y_prefix - 2) >> 1);
334
1.27M
            value = ihevcd_cabac_decode_bypass_bins(ps_cabac,
335
1.27M
                                                    ps_bitstrm,
336
1.27M
                                                    suf_length);
337
338
1.27M
            AEV_TRACE("last_coeff_y_suffix", value, ps_cabac->u4_range);
339
1.27M
            last_significant_coeff_y =
340
1.27M
                            (1 << ((last_significant_coeff_y_prefix >> 1) - 1)) *
341
1.27M
                            (2 + (last_significant_coeff_y_prefix & 1)) + value;
342
1.27M
        }
343
344
10.3M
    }
345
346
    /* Choose a scan matrix based on intra flag, intra pred mode, transform size
347
     and luma/chroma */
348
10.3M
    scan_idx = SCAN_DIAG_UPRIGHT;
349
10.3M
    if(PRED_MODE_INTRA == ps_codec->s_parse.s_cu.i4_pred_mode)
350
9.97M
    {
351
9.97M
        int is_YUV444 = ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444;
352
9.97M
        if((2 == log2_trafo_size) || ((3 == log2_trafo_size) && (0 == c_idx || is_YUV444)))
353
5.95M
        {
354
5.95M
            if((6 <= intra_pred_mode) &&
355
2.33M
               (14 >= intra_pred_mode))
356
550k
            {
357
550k
                scan_idx = SCAN_VERT;
358
550k
            }
359
5.39M
            else if((22 <= intra_pred_mode) &&
360
1.38M
                    (30 >= intra_pred_mode))
361
1.08M
            {
362
1.08M
                scan_idx = SCAN_HORZ;
363
1.08M
            }
364
5.95M
        }
365
9.97M
    }
366
367
    /* In case the scan is vertical, then swap  X and Y positions */
368
10.3M
    if(SCAN_VERT == scan_idx)
369
550k
    {
370
550k
        SWAP(last_significant_coeff_x, last_significant_coeff_y);
371
550k
    }
372
373
10.3M
    {
374
10.3M
        WORD8 *pi1_scan_idx;
375
10.3M
        WORD8 *pi1_buf = (WORD8 *)ps_codec->s_parse.pv_tu_coeff_data;
376
377
        /* First WORD8 gives number of coded subblocks */
378
10.3M
        pi1_num_coded_subblks = pi1_buf++;
379
380
        /* Set number of coded subblocks in the current TU to zero */
381
        /* This will be updated later */
382
10.3M
        *pi1_num_coded_subblks = 0;
383
384
10.3M
        pi1_scan_idx = pi1_buf++;
385
10.3M
#ifdef ENABLE_MAIN_REXT_PROFILE
386
        /* Second WORD8 gives (explicit_rdpcm_dir << 5) | (explicit_rdpcm_flag << 4) | (scan idx << 1) | trans_skip */
387
10.3M
        *pi1_scan_idx = (explicit_rdpcm_dir << 5) | (explicit_rdpcm_flag << 4) | (scan_idx << 1)
388
10.3M
                        | transform_skip_flag;
389
#else
390
        /* Second WORD8 gives (scan idx << 1) | trans_skip */
391
        *pi1_scan_idx = (scan_idx << 1) | transform_skip_flag;
392
#endif
393
394
        /* Store the incremented pointer in pv_tu_coeff_data */
395
10.3M
        ps_codec->s_parse.pv_tu_coeff_data = pi1_buf;
396
397
10.3M
    }
398
    /**
399
     * Given last_significant_coeff_y and last_significant_coeff_x find last sub block
400
     * This is done by ignoring lower two bits of last_significant_coeff_y and last_significant_coeff_x
401
     * and using scan matrix for lookup
402
     */
403
404
    /* If transform is 4x4, last_sub_blk is zero */
405
10.3M
    last_sub_blk = 0;
406
407
    /* If transform is larger than 4x4, then based on scan_idx and transform size, choose a scan table */
408
409
10.3M
    if(log2_trafo_size > 2)
410
5.26M
    {
411
5.26M
        WORD32 scan_pos;
412
5.26M
        WORD32 scan_mat_size;
413
5.26M
        pu1_scan_blk = (UWORD8 *)gapv_ihevc_scan[scan_idx * 3 + (log2_trafo_size - 2 - 1)];
414
415
416
        /* Divide the current transform to 4x4 subblocks and count number of 4x4 in the first row */
417
        /* This will be size of scan matrix to be used for subblock scanning */
418
5.26M
        scan_mat_size = 1 << (log2_trafo_size - 2);
419
5.26M
        scan_pos = ((last_significant_coeff_y >> 2) * scan_mat_size) +
420
5.26M
                        (last_significant_coeff_x >> 2);
421
422
5.26M
        last_sub_blk = pu1_scan_blk[scan_pos];
423
5.26M
    }
424
10.3M
    pu1_scan_coeff  = &gau1_ihevc_scan4x4[scan_idx][0];
425
426
10.3M
    {
427
10.3M
        WORD32 scan_pos;
428
429
10.3M
        scan_pos = ((last_significant_coeff_y & 3) << 2) +
430
10.3M
                        (last_significant_coeff_x & 3);
431
432
10.3M
        last_scan_pos = pu1_scan_coeff[scan_pos];
433
10.3M
    }
434
10.3M
    if(log2_trafo_size > 2)
435
5.26M
        pu1_scan_blk = (UWORD8 *)gapv_ihevc_invscan[scan_idx * 3 + (log2_trafo_size - 2 - 1)];
436
10.3M
    pu1_scan_coeff  = &gau1_ihevc_invscan4x4[scan_idx][0];
437
438
    /* Set CSBF array to zero */
439
10.3M
    {
440
10.3M
        UWORD32 *pu4_csbf;
441
10.3M
        pu4_csbf = (void *)au2_csbf;
442
10.3M
        *pu4_csbf++ = 0;
443
10.3M
        *pu4_csbf++ = 0;
444
10.3M
        *pu4_csbf++ = 0;
445
10.3M
        *pu4_csbf = 0;
446
        /* To avoid a check for y pos, 9th WORD16 in the array is set to zero */
447
10.3M
        au2_csbf[8] = 0;
448
10.3M
    }
449
450
    /*************************************************************************/
451
    /* derive base context index for sig coeff as per section 9.3.3.1.4      */
452
    /* TODO; convert to look up based on luma/chroma, scan type and tfr size */
453
    /*************************************************************************/
454
10.3M
    if(!c_idx)
455
5.87M
    {
456
5.87M
        sig_coeff_base_ctxt = IHEVC_CAB_COEFF_FLAG;
457
5.87M
        abs_gt1_base_ctxt = IHEVC_CAB_COEFABS_GRTR1_FLAG;
458
459
5.87M
        if(3 == log2_trafo_size)
460
1.10M
        {
461
            /* 8x8 transform size */
462
1.10M
            sig_coeff_base_ctxt += (scan_idx == SCAN_DIAG_UPRIGHT) ? 9 : 15;
463
1.10M
        }
464
4.77M
        else  if(3 < log2_trafo_size)
465
1.99M
        {
466
            /* larger transform sizes */
467
1.99M
            sig_coeff_base_ctxt += 21;
468
1.99M
        }
469
5.87M
    }
470
4.48M
    else
471
4.48M
    {
472
        /* chroma context initializations */
473
4.48M
        sig_coeff_base_ctxt = IHEVC_CAB_COEFF_FLAG + 27;
474
4.48M
        abs_gt1_base_ctxt = IHEVC_CAB_COEFABS_GRTR1_FLAG + 16;
475
476
4.48M
        if(3 == log2_trafo_size)
477
745k
        {
478
            /* 8x8 transform size */
479
745k
            sig_coeff_base_ctxt += 9;
480
745k
        }
481
3.73M
        else  if(3 < log2_trafo_size)
482
1.42M
        {
483
            /* larger transform sizes */
484
1.42M
            sig_coeff_base_ctxt += 12;
485
1.42M
        }
486
4.48M
    }
487
10.3M
    num_subblks = 0;
488
    /* Parse each 4x4 subblocks */
489
29.8M
    for(i = last_sub_blk; i >= 0; i--)
490
19.5M
    {
491
19.5M
        WORD32 sub_blk_pos;
492
19.5M
        WORD32 infer_sig_coeff_flag;
493
19.5M
        WORD32 cur_csbf;
494
495
19.5M
        WORD32 n;
496
19.5M
        WORD32 num_coeff;
497
        /* Sig coeff map for 16 entries in raster scan order. Upper 16 bits are used.
498
         * MSB gives sig coeff flag for 0th coeff and so on
499
         * UWORD16 would have been enough but kept as UWORD32 for code optimizations
500
         * In arm unnecessary masking operations are saved
501
         */
502
19.5M
        UWORD32 u4_sig_coeff_map_raster;
503
19.5M
        WORD32 sign_hidden;
504
505
        /* Sig coeff map in scan order */
506
19.5M
        UWORD32 u4_sig_coeff_map;
507
19.5M
        WORD32 coeff_abs_level_greater2_flag;
508
19.5M
        UWORD32 u4_coeff_abs_level_greater1_map;
509
19.5M
        UWORD32 u4_coeff_abs_level_greater2_map;
510
19.5M
        UWORD32 u4_coeff_sign_map;
511
19.5M
        WORD32 first_sig_scan_pos, last_sig_scan_pos, num_greater1_flag, first_greater1_scan_pos;
512
19.5M
        WORD32  num_sig_coeff, sum_abs_level;
513
19.5M
        WORD32 nbr_csbf;
514
515
516
19.5M
        WORD32 ctxt_set;
517
19.5M
        WORD32 rice_param;
518
19.5M
        WORD32 xs, ys;
519
520
19.5M
#ifdef ENABLE_MAIN_REXT_PROFILE
521
19.5M
        WORD8 i1_update_stats = ps_sps->i1_persistent_rice_adaptation_enabled_flag;
522
19.5M
#endif
523
524
19.5M
        sub_blk_pos  = 0;
525
19.5M
        if(i && (log2_trafo_size > 2))
526
9.16M
            sub_blk_pos = pu1_scan_blk[i];
527
528
        /* Get xs and ys from scan position */
529
        /* This is needed for context modelling of significant coeff flag */
530
19.5M
        xs = sub_blk_pos & ((1 << (log2_trafo_size - 2)) - 1);
531
19.5M
        ys = sub_blk_pos >> (log2_trafo_size - 2);
532
533
534
        /* Check if neighbor subblocks are coded */
535
19.5M
        {
536
537
19.5M
            nbr_csbf = 0;
538
539
            /* Get Bottom sub blocks CSBF */
540
19.5M
            nbr_csbf |= (au2_csbf[ys + 1] >> xs) & 1;
541
19.5M
            nbr_csbf <<= 1;
542
543
            /* Get Right sub blocks CSBF */
544
            /* Even if xs is equal to (1 << (log2_trafo_size - 2 )) - 1,
545
               since au2_csbf is set to zero at the beginning, csbf for
546
               neighbor will be read as 0 */
547
548
19.5M
            nbr_csbf |= (au2_csbf[ys] >> (xs + 1)) & 1;
549
550
551
19.5M
        }
552
19.5M
        cur_csbf = 0;
553
554
        /* DC coeff is inferred, only if coded_sub_block is explicitly parsed as 1 */
555
        /* i.e. it is not inferred for first and last subblock */
556
19.5M
        infer_sig_coeff_flag = 0;
557
19.5M
        if((i < last_sub_blk) && (i > 0))
558
7.18M
        {
559
7.18M
            WORD32 ctxt_idx  = IHEVC_CAB_CODED_SUBLK_IDX;
560
561
            /* ctxt based on right / bottom avail csbf, section 9.3.3.1.3 */
562
7.18M
            ctxt_idx += (nbr_csbf) ? 1 : 0;
563
564
            /* Ctxt based on luma or chroma */
565
7.18M
            ctxt_idx += c_idx  ? 2 : 0;
566
7.18M
            TRACE_CABAC_CTXT("coded_sub_block_flag", ps_cabac->u4_range, ctxt_idx);
567
7.18M
            IHEVCD_CABAC_DECODE_BIN(cur_csbf, ps_cabac, ps_bitstrm, ctxt_idx);
568
7.18M
            AEV_TRACE("coded_sub_block_flag", cur_csbf, ps_cabac->u4_range);
569
570
7.18M
            infer_sig_coeff_flag = 1;
571
7.18M
        }
572
12.3M
        else /* if((i == last_sub_blk) || (sub_blk_pos == 0)) */
573
12.3M
        {
574
            /* CSBF is set to 1 for first and last subblock */
575
            /* Note for these subblocks sig_coeff_map is not inferred but instead parsed */
576
12.3M
            cur_csbf = 1;
577
12.3M
        }
578
579
        /* Set current sub blocks CSBF */
580
19.5M
        {
581
19.5M
            UWORD32 u4_mask = 1 << xs;
582
19.5M
            if(cur_csbf)
583
15.2M
                au2_csbf[ys] |= u4_mask;
584
4.32M
            else
585
4.32M
                au2_csbf[ys] &= ~u4_mask;
586
587
19.5M
        }
588
589
        /* If current subblock is not coded, proceed to the next subblock */
590
19.5M
        if(0 == cur_csbf)
591
4.32M
            continue;
592
593
15.2M
        n = 15;
594
15.2M
        u4_sig_coeff_map_raster = 0;
595
15.2M
        u4_sig_coeff_map = 0;
596
15.2M
        num_coeff = 0;
597
15.2M
        if(i == last_sub_blk)
598
10.3M
        {
599
10.3M
            WORD32 pos = ((last_significant_coeff_y & 3) << 2) +
600
10.3M
                            (last_significant_coeff_x & 3);
601
10.3M
            n = (last_scan_pos - 1);
602
            /* Set Significant coeff map for last significant coeff flag as 1 */
603
10.3M
            u4_sig_coeff_map_raster = 1 << pos;
604
10.3M
            u4_sig_coeff_map = 1 << last_scan_pos;
605
10.3M
            num_coeff = 1;
606
10.3M
        }
607
608
132M
        for(; n >= 0; n--)
609
117M
        {
610
117M
            WORD32 significant_coeff_flag;
611
612
117M
            if((n > 0 || !infer_sig_coeff_flag))
613
116M
            {
614
                //WORD32 coeff_pos;
615
116M
                WORD32 sig_ctxinc;
616
116M
                WORD32 ctxt_idx;
617
618
                /* Coefficient position is needed for deriving context index for significant_coeff_flag */
619
                //coeff_pos = pu1_scan_coeff[n];
620
                /* derive the context inc as per section 9.3.3.1.4 */
621
116M
                sig_ctxinc = 0;
622
116M
#ifdef ENABLE_MAIN_REXT_PROFILE
623
116M
                if(ps_sps->i1_transform_skip_context_enabled_flag
624
111k
                                && (ps_codec->s_parse.s_cu.i4_cu_transquant_bypass
625
78.1k
                                                || transform_skip_flag))
626
66.1k
                {
627
66.1k
                    sig_coeff_base_ctxt = IHEVC_CAB_COEFF_FLAG;
628
66.1k
                    sig_coeff_base_ctxt += (0 == c_idx) ? 42 : 43;
629
66.1k
                }
630
116M
                else if(2 == log2_trafo_size)
631
#else
632
                if(2 == log2_trafo_size)
633
#endif
634
29.4M
                {
635
636
                    /* 4x4 transform size increment uses lookup */
637
29.4M
                    sig_ctxinc = gau1_ihevcd_sigcoeff_ctxtinc_tr4[scan_idx][n];
638
29.4M
                }
639
87.3M
                else if(n || i)
640
84.0M
                {
641
                    /* ctxt for AC coeff depends on curpos and neigbour csbf */
642
84.0M
                    sig_ctxinc = gau1_ihevcd_sigcoeff_ctxtinc[scan_idx][nbr_csbf][n];
643
644
                    /* based on luma subblock pos */
645
84.0M
                    sig_ctxinc += (i && (!c_idx)) ? 3 : 0;
646
647
84.0M
                }
648
3.34M
                else
649
3.34M
                {
650
                    /* DC coeff has fixed context for luma and chroma */
651
3.34M
                    sig_coeff_base_ctxt = (0 == c_idx) ? IHEVC_CAB_COEFF_FLAG :
652
3.34M
                                                         (IHEVC_CAB_COEFF_FLAG + 27);
653
3.34M
                }
654
655
116M
                ctxt_idx = sig_ctxinc + sig_coeff_base_ctxt;
656
116M
                TRACE_CABAC_CTXT("significant_coeff_flag", ps_cabac->u4_range, ctxt_idx);
657
116M
                IHEVCD_CABAC_DECODE_BIN(significant_coeff_flag, ps_cabac,
658
116M
                                        ps_bitstrm,
659
116M
                                        ctxt_idx);
660
116M
                AEV_TRACE("significant_coeff_flag", significant_coeff_flag, ps_cabac->u4_range);
661
662
663
                /* If at least one non-zero coeff is signalled then do not infer sig coeff map */
664
                /* for (0,0) coeff in the current sub block */
665
116M
                if(significant_coeff_flag)
666
51.2M
                    infer_sig_coeff_flag = 0;
667
668
//                u4_sig_coeff_map_raster |= significant_coeff_flag
669
//                              << coeff_pos;
670
116M
                u4_sig_coeff_map |= significant_coeff_flag << n;
671
116M
                num_coeff += significant_coeff_flag;
672
116M
            }
673
674
675
117M
        }
676
        /*********************************************************************/
677
        /* If infer_sig_coeff_flag is 1 then treat the 0th coeff as non zero */
678
        /* If infer_sig_coeff_flag is zero, then last significant_coeff_flag */
679
        /* is parsed in the above loop                                       */
680
        /*********************************************************************/
681
15.2M
        if(infer_sig_coeff_flag)
682
630k
        {
683
630k
            u4_sig_coeff_map_raster |= 1;
684
630k
            u4_sig_coeff_map |= 1;
685
630k
            num_coeff++;
686
630k
        }
687
688
        /*********************************************************************/
689
        /* First subblock does not get an explicit csbf. It is assumed to    */
690
        /* be 1. For this subblock there is chance of getting all            */
691
        /* sig_coeff_flags to be zero. In such a case proceed to the next    */
692
        /* subblock(which is end of parsing for the current transform block) */
693
        /*********************************************************************/
694
695
15.2M
        if(0 == num_coeff)
696
411k
            continue;
697
698
        /* Increment number of coded subblocks for the current TU */
699
14.7M
        num_subblks++;
700
701
        /* Set sig coeff map and subblock position */
702
14.7M
        ps_tu_sblk_coeff_data = (tu_sblk_coeff_data_t *)ps_codec->s_parse.pv_tu_coeff_data;
703
14.7M
        ps_tu_sblk_coeff_data->u2_sig_coeff_map = u4_sig_coeff_map;
704
14.7M
        ps_tu_sblk_coeff_data->u2_subblk_pos = (ys << 8) | xs;
705
706
14.7M
        first_sig_scan_pos = 16;
707
14.7M
        last_sig_scan_pos = -1;
708
14.7M
        num_greater1_flag = 0;
709
14.7M
        first_greater1_scan_pos = -1;
710
14.7M
        u4_coeff_abs_level_greater1_map = 0;
711
712
713
        /* context set based on luma subblock pos */
714
14.7M
        ctxt_set = (i && (!c_idx)) ? 2 : 0;
715
716
        /* See section 9.3.3.1.5           */
717
14.7M
        ctxt_set += (0 == gt1_ctxt) ? 1 : 0;
718
719
14.7M
        gt1_ctxt = 1;
720
        /* Instead of initializing n to 15, set it to 31-CLZ(sig coeff map) */
721
14.7M
        {
722
14.7M
            UWORD32 u4_sig_coeff_map_shift;
723
14.7M
            UWORD32 clz;
724
14.7M
            clz = CLZ(u4_sig_coeff_map);
725
14.7M
            n = 31 - clz;
726
14.7M
            u4_sig_coeff_map_shift = u4_sig_coeff_map << clz;
727
            /* For loop for n changed to do while to break early if sig_coeff_map_shift becomes zero */
728
14.7M
            do
729
51.6M
            {
730
                //WORD32 coeff_pos;
731
51.6M
                WORD32 ctxt_idx;
732
733
                //TODO: Scan lookup will be removed later and instead u4_sig_coeff_map will be used
734
                //coeff_pos = pu1_scan_coeff[n];
735
736
51.6M
                if((u4_sig_coeff_map_shift >> 31) & 1)
737
51.6M
                {
738
739
                    /* abs_level_greater1_flag is sent for only first 8 non-zero levels in a subblock */
740
51.6M
                    if(num_greater1_flag < 8)
741
49.3M
                    {
742
49.3M
                        WORD32 coeff_abs_level_greater1_flag;
743
744
49.3M
                        ctxt_idx = (ctxt_set * 4) + abs_gt1_base_ctxt + gt1_ctxt;
745
746
49.3M
                        TRACE_CABAC_CTXT("coeff_abs_level_greater1_flag", ps_cabac->u4_range, ctxt_idx);
747
49.3M
                        IHEVCD_CABAC_DECODE_BIN(coeff_abs_level_greater1_flag, ps_cabac, ps_bitstrm, ctxt_idx);
748
49.3M
                        AEV_TRACE("coeff_abs_level_greater1_flag", coeff_abs_level_greater1_flag, ps_cabac->u4_range);
749
750
49.3M
                        u4_coeff_abs_level_greater1_map |= coeff_abs_level_greater1_flag << n;
751
49.3M
                        num_greater1_flag++;
752
753
                        /* first_greater1_scan_pos is obtained using CLZ on u4_coeff_abs_level_greater1_map*/
754
                        /*  outside the loop instead of the following check inside the loop                */
755
                        /* if( coeff_abs_level_greater1_flag && first_greater1_scan_pos == -1) */
756
                        /*    first_greater1_scan_pos = n;                                     */
757
758
49.3M
                        if(coeff_abs_level_greater1_flag)
759
11.6M
                        {
760
11.6M
                            gt1_ctxt = 0;
761
11.6M
                        }
762
37.6M
                        else if(gt1_ctxt && (gt1_ctxt < 3))
763
17.9M
                        {
764
17.9M
                            gt1_ctxt++;
765
17.9M
                        }
766
767
49.3M
                    }
768
2.29M
                    else
769
2.29M
                        break;
770
771
                    /* instead of computing last and first significan scan position using checks below */
772
                    /* They are computed outside the loop using CLZ and CTZ on sig_coeff_map */
773
                    /* if(last_sig_scan_pos == -1)                          */
774
                    /*    last_sig_scan_pos = n;                            */
775
                    /*  first_sig_scan_pos = n;                             */
776
51.6M
                }
777
49.3M
                u4_sig_coeff_map_shift <<= 1;
778
49.3M
                n--;
779
                /* If there are zero coeffs, then shift by as many zero coeffs and decrement n */
780
49.3M
                clz = CLZ(u4_sig_coeff_map_shift);
781
49.3M
                u4_sig_coeff_map_shift <<= clz;
782
49.3M
                n -= (WORD32)clz;
783
49.3M
            }while(u4_sig_coeff_map_shift);
784
14.7M
        }
785
        /* At this level u4_sig_coeff_map is non-zero i.e. has atleast one non-zero coeff */
786
14.7M
        last_sig_scan_pos = (31 - CLZ(u4_sig_coeff_map));
787
14.7M
        first_sig_scan_pos = CTZ(u4_sig_coeff_map);
788
789
14.7M
        if(ps_codec->s_parse.s_cu.i4_cu_transquant_bypass
790
13.5M
#ifdef ENABLE_MAIN_REXT_PROFILE
791
13.5M
                        || explicit_rdpcm_flag
792
13.5M
#endif
793
13.5M
                        || (PRED_MODE_INTRA == ps_codec->s_parse.s_cu.i4_pred_mode
794
13.0M
#ifdef ENABLE_MAIN_REXT_PROFILE
795
13.0M
                                        && ps_sps->i1_implicit_rdpcm_enabled_flag
796
#else
797
                                        && 0
798
#endif
799
89.2k
                                        && transform_skip_flag
800
12.3k
                                        && (intra_pred_mode == 10 || intra_pred_mode == 26)))
801
1.28M
        {
802
1.28M
            sign_hidden = 0;
803
1.28M
        }
804
13.4M
        else
805
13.4M
        {
806
13.4M
            sign_hidden = ((last_sig_scan_pos - first_sig_scan_pos) > 3);
807
13.4M
        }
808
809
14.7M
        u4_coeff_abs_level_greater2_map = 0;
810
811
14.7M
        if(u4_coeff_abs_level_greater1_map)
812
4.62M
        {
813
            /* Check if the first level > 1 is greater than 2 */
814
4.62M
            WORD32 ctxt_idx;
815
4.62M
            first_greater1_scan_pos = (31 - CLZ(u4_coeff_abs_level_greater1_map));
816
817
818
4.62M
            ctxt_idx = IHEVC_CAB_COEFABS_GRTR2_FLAG;
819
820
4.62M
            ctxt_idx += (!c_idx) ? ctxt_set : (ctxt_set + 4);
821
4.62M
            TRACE_CABAC_CTXT("coeff_abs_level_greater2_flag", ps_cabac->u4_range, ctxt_idx);
822
4.62M
            IHEVCD_CABAC_DECODE_BIN(coeff_abs_level_greater2_flag, ps_cabac, ps_bitstrm, ctxt_idx);
823
4.62M
            AEV_TRACE("coeff_abs_level_greater2_flag", coeff_abs_level_greater2_flag, ps_cabac->u4_range);
824
4.62M
            u4_coeff_abs_level_greater2_map = coeff_abs_level_greater2_flag << first_greater1_scan_pos;
825
4.62M
        }
826
827
828
14.7M
        u4_coeff_sign_map = 0;
829
830
        /* Parse sign flags */
831
14.7M
        if(!sign_data_hiding_flag || !sign_hidden)
832
10.2M
        {
833
10.2M
            IHEVCD_CABAC_DECODE_BYPASS_BINS(value, ps_cabac, ps_bitstrm, num_coeff);
834
10.2M
            AEV_TRACE("sign_flags", value, ps_cabac->u4_range);
835
10.2M
            u4_coeff_sign_map = (UWORD32)value << (32 - num_coeff);
836
10.2M
        }
837
4.53M
        else
838
4.53M
        {
839
4.53M
            IHEVCD_CABAC_DECODE_BYPASS_BINS(value, ps_cabac, ps_bitstrm, (num_coeff - 1));
840
4.53M
            AEV_TRACE("sign_flags", value, ps_cabac->u4_range);
841
4.53M
            u4_coeff_sign_map = (UWORD32)value << (32 - (num_coeff - 1));
842
4.53M
        }
843
844
14.7M
        num_sig_coeff = 0;
845
14.7M
        sum_abs_level = 0;
846
847
14.7M
#ifdef ENABLE_MAIN_REXT_PROFILE
848
14.7M
        WORD32 sb_type = 2 * (c_idx == 0 ? 1 : 0);
849
14.7M
        if(ps_sps->i1_persistent_rice_adaptation_enabled_flag)
850
129k
        {
851
129k
            if(!(transform_skip_flag == 0 && ps_codec->s_parse.s_cu.i4_cu_transquant_bypass == 0))
852
32.0k
            {
853
32.0k
                sb_type += 1;
854
32.0k
            }
855
129k
            rice_param = ps_cabac->ai4_rice_stat_coeff[sb_type] / 4;
856
129k
        }
857
14.6M
        else
858
14.6M
#endif
859
14.6M
        {
860
14.6M
            rice_param = 0;
861
14.6M
        }
862
14.7M
        {
863
14.7M
            UWORD32 clz;
864
14.7M
            UWORD32 u4_sig_coeff_map_shift;
865
14.7M
            clz = CLZ(u4_sig_coeff_map);
866
14.7M
            n = 31 - clz;
867
14.7M
            u4_sig_coeff_map_shift = u4_sig_coeff_map << clz;
868
            /* For loop for n changed to do while to break early if sig_coeff_map_shift becomes zero */
869
14.7M
            do
870
62.2M
            {
871
872
62.2M
                if((u4_sig_coeff_map_shift >> 31) & 1)
873
62.2M
                {
874
62.2M
                    WORD32 base_lvl;
875
62.2M
                    WORD32 coeff_abs_level_remaining;
876
62.2M
                    WORD32 level;
877
62.2M
                    base_lvl = 1;
878
879
                    /* Update base_lvl if it is greater than 1 */
880
62.2M
                    if((u4_coeff_abs_level_greater1_map >> n) & 1)
881
11.6M
                        base_lvl++;
882
883
                    /* Update base_lvl if it is greater than 2 */
884
62.2M
                    if((u4_coeff_abs_level_greater2_map >> n) & 1)
885
1.44M
                        base_lvl++;
886
887
                    /* If level is greater than 3/2/1 based on the greater1 and greater2 maps,
888
                     * decode remaining level (level - base_lvl) will be signalled as bypass bins
889
                     */
890
62.2M
                    coeff_abs_level_remaining = 0;
891
62.2M
                    if(base_lvl == ((num_sig_coeff < 8) ? ((n == first_greater1_scan_pos) ? 3 : 2) : 1))
892
21.3M
                    {
893
21.3M
                        UWORD32 u4_prefix;
894
21.3M
                        WORD32 bin;
895
896
21.3M
                        u4_prefix = 0;
897
898
21.3M
                        do
899
32.1M
                        {
900
32.1M
                            IHEVCD_CABAC_DECODE_BYPASS_BIN(bin, ps_cabac, ps_bitstrm);
901
32.1M
                            u4_prefix++;
902
903
32.1M
                            if((WORD32)u4_prefix == 19 - rice_param)
904
202k
                            {
905
202k
                                bin = 1;
906
202k
                                break;
907
202k
                            }
908
909
32.1M
                        }while(bin);
910
911
21.3M
                        u4_prefix = u4_prefix - 1;
912
21.3M
                        if(u4_prefix < 3)
913
20.2M
                        {
914
20.2M
                            UWORD32 u4_suffix;
915
916
20.2M
                            coeff_abs_level_remaining = (u4_prefix << rice_param);
917
20.2M
                            if(rice_param)
918
2.47M
                            {
919
2.47M
                                IHEVCD_CABAC_DECODE_BYPASS_BINS(u4_suffix, ps_cabac, ps_bitstrm, rice_param);
920
921
2.47M
                                coeff_abs_level_remaining |= u4_suffix;
922
2.47M
                            }
923
20.2M
                        }
924
1.14M
                        else
925
1.14M
                        {
926
1.14M
                            UWORD32 u4_suffix;
927
1.14M
                            UWORD32 u4_numbins;
928
929
                            //u4_prefix = CLIP3(u4_prefix, 0, 19 - rice_param);
930
931
1.14M
                            u4_numbins = (u4_prefix - 3 + rice_param);
932
1.14M
                            coeff_abs_level_remaining = (((1 << (u4_prefix - 3)) + 3 - 1) << rice_param);
933
1.14M
                            if(u4_numbins)
934
858k
                            {
935
858k
                                IHEVCD_CABAC_DECODE_BYPASS_BINS(u4_suffix, ps_cabac, ps_bitstrm, u4_numbins);
936
858k
                                coeff_abs_level_remaining += u4_suffix;
937
858k
                            }
938
1.14M
                        }
939
940
941
21.3M
                        AEV_TRACE("coeff_abs_level_remaining", coeff_abs_level_remaining, ps_cabac->u4_range);
942
21.3M
                        base_lvl += coeff_abs_level_remaining;
943
944
21.3M
#ifdef ENABLE_MAIN_REXT_PROFILE
945
21.3M
                        if(i1_update_stats)
946
67.3k
                        {
947
67.3k
                            if(coeff_abs_level_remaining
948
67.3k
                                            >= (3 << (ps_cabac->ai4_rice_stat_coeff[sb_type] / 4)))
949
2.26k
                            {
950
2.26k
                                ps_cabac->ai4_rice_stat_coeff[sb_type]++;
951
2.26k
                            }
952
65.1k
                            else if((2 * coeff_abs_level_remaining
953
65.1k
                                            < (1 << (ps_cabac->ai4_rice_stat_coeff[sb_type] / 4)))
954
59.7k
                                            && ps_cabac->ai4_rice_stat_coeff[sb_type] > 0)
955
1.73k
                            {
956
1.73k
                                ps_cabac->ai4_rice_stat_coeff[sb_type]--;
957
1.73k
                            }
958
67.3k
                            i1_update_stats = 0;
959
67.3k
                        }
960
21.3M
#endif
961
21.3M
                    }
962
963
                    /* update the rice param based on coeff level */
964
62.2M
                    if(base_lvl > (3 << rice_param))
965
1.91M
                    {
966
1.91M
#ifdef ENABLE_MAIN_REXT_PROFILE
967
1.91M
                        if(ps_sps->i1_persistent_rice_adaptation_enabled_flag)
968
14.1k
                        {
969
14.1k
                            rice_param += 1;
970
14.1k
                        }
971
1.90M
                        else
972
1.90M
#endif
973
1.90M
                        {
974
1.90M
                            rice_param = MIN((rice_param + 1), 4);
975
1.90M
                        }
976
1.91M
                    }
977
978
                    /* Compute absolute level */
979
62.2M
                    level = base_lvl;
980
981
                    /* Update level with the sign */
982
62.2M
                    if((u4_coeff_sign_map >> 31) & 1)
983
12.9M
                        level = -level;
984
985
62.2M
                    u4_coeff_sign_map <<= 1;
986
                    /* Update sign in case sign is hidden */
987
62.2M
                    if(sign_data_hiding_flag && sign_hidden)
988
34.3M
                    {
989
34.3M
                        sum_abs_level += base_lvl;
990
991
34.3M
                        if(n == first_sig_scan_pos && ((sum_abs_level % 2) == 1))
992
1.84M
                            level = -level;
993
34.3M
                    }
994
995
                    /* Store the resulting level in non-zero level array */
996
62.2M
                    ps_tu_sblk_coeff_data->ai2_level[num_sig_coeff++] = level;
997
                    //AEV_TRACE("level", level, 0);
998
62.2M
                }
999
62.2M
                u4_sig_coeff_map_shift <<= 1;
1000
62.2M
                n--;
1001
                /* If there are zero coeffs, then shift by as many zero coeffs and decrement n */
1002
62.2M
                clz = CLZ(u4_sig_coeff_map_shift);
1003
62.2M
                u4_sig_coeff_map_shift <<= clz;
1004
62.2M
                n -= (WORD32)clz;
1005
1006
1007
62.2M
            }while(u4_sig_coeff_map_shift);
1008
14.7M
        }
1009
1010
        /* Increment the pv_tu_sblk_coeff_data */
1011
14.7M
        {
1012
14.7M
            UWORD8 *pu1_buf = (UWORD8 *)ps_codec->s_parse.pv_tu_coeff_data;
1013
14.7M
            pu1_buf += sizeof(tu_sblk_coeff_data_t) - SUBBLK_COEFF_CNT * sizeof(WORD16);
1014
14.7M
            pu1_buf += num_coeff * sizeof(WORD16);
1015
14.7M
            ps_codec->s_parse.pv_tu_coeff_data = pu1_buf;
1016
1017
14.7M
        }
1018
1019
14.7M
    }
1020
    /* Set number of coded sub blocks in the current TU */
1021
10.3M
    *pi1_num_coded_subblks = num_subblks;
1022
1023
10.3M
    return ret;
1024
10.3M
}