Coverage Report

Created: 2026-01-10 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/encoder/ihevce_cabac.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2018 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
******************************************************************************
23
*
24
* @file ihevce_cabac.h
25
*
26
* @brief
27
*  This file contains encoder cabac engine related structures and
28
*  interface prototypes
29
*
30
* @author
31
*  ittiam
32
*
33
******************************************************************************
34
*/
35
36
#ifndef _IHEVCE_CABAC_H_
37
#define _IHEVCE_CABAC_H_
38
39
#include "ihevc_debug.h"
40
#include "ihevc_macros.h"
41
42
/*****************************************************************************/
43
/* Constant Macros                                                           */
44
/*****************************************************************************/
45
/**
46
*******************************************************************************
47
@brief Bit precision of cabac engine;
48
*******************************************************************************
49
 */
50
140M
#define CABAC_BITS 9
51
52
/**
53
*******************************************************************************
54
@brief q format to account for the fractional bits encoded in cabac
55
*******************************************************************************
56
 */
57
445M
#define CABAC_FRAC_BITS_Q 12
58
59
/**
60
*******************************************************************************
61
@brief Enables bit-efficient chroma cbf signalling by peeking into cbfs of
62
       children nodes
63
*******************************************************************************
64
 */
65
#define CABAC_BIT_EFFICIENT_CHROMA_PARENT_CBF 1
66
67
/*****************************************************************************/
68
/* Function Macros                                                           */
69
/*****************************************************************************/
70
71
/**
72
*******************************************************************************
73
@brief converts floating point number to CABAC_FRAC_BITS_Q q format and
74
       rounds the results to 16 bit integer
75
*******************************************************************************
76
 */
77
32.4M
#define ROUND_Q12(x) ((UWORD16)(((x) * (1 << CABAC_FRAC_BITS_Q)) + 0.5))
78
79
/*****************************************************************************/
80
/* Enums                                                                     */
81
/*****************************************************************************/
82
83
/**
84
*******************************************************************************
85
@brief Enums for controlling the operating mode of cabac engine
86
*******************************************************************************
87
 */
88
typedef enum
89
{
90
    /** in this mode, bits are encoded in the bit stream buffer */
91
    CABAC_MODE_ENCODE_BITS = 0,
92
93
    /** in this mode, only num bits gen are computed but not put in the stream */
94
    CABAC_MODE_COMPUTE_BITS = 1
95
96
} CABAC_OP_MODE;
97
98
/*****************************************************************************/
99
/* Structures                                                                */
100
/*****************************************************************************/
101
102
/**
103
******************************************************************************
104
 *  @brief      Cabac context for encoder
105
******************************************************************************
106
 */
107
typedef struct cab_ctxt
108
{
109
    /**
110
     * indicates if cabac encode works in put bits mode or bit compute mode
111
     * In puts bits mode, bitstream and cabac engine fields L,R etc are used
112
     * In bit compute mode, bitstream and cabac engine fields are not used
113
     */
114
    CABAC_OP_MODE e_cabac_op_mode;
115
116
    /**
117
     * total bits estimated (for a cu) when mode is CABAC_MODE_COMPUTE_BITS
118
     * This is in q12 format to account for the fractional bits as well
119
     */
120
    UWORD32 u4_bits_estimated_q12;
121
122
    /**
123
     * total texture bits estimated (for a cu) when mode is CABAC_MODE_COMPUTE_BITS
124
     * This is in q12 format to account for the fractional bits as well
125
     */
126
    UWORD32 u4_texture_bits_estimated_q12;
127
128
    /**
129
     * total header bits estimated (for a cu) when mode is CABAC_MODE_COMPUTE_BITS
130
     * This is in q12 format to account for the fractional bits as well
131
     */
132
    UWORD32 u4_header_bits_estimated_q12;
133
134
    UWORD32 u4_cbf_bits_q12;
135
136
    UWORD32 u4_true_tu_split_flag_q12;
137
    /*********************************************************************/
138
    /*  CABAC ENGINE related fields; not used in CABAC_MODE_COMPUTE_BITS */
139
    /*********************************************************************/
140
    /** cabac interval range R  */
141
    UWORD32 u4_range;
142
143
    /** cabac interval start L  */
144
    UWORD32 u4_low;
145
146
    /** bits generated during renormalization
147
     *  A byte is put to stream/u4_out_standing_bytes from u4_low(L) when
148
     *  u4_bits_gen exceeds 8
149
     */
150
    UWORD32 u4_bits_gen;
151
152
    /** bytes_outsanding; number of 0xFF bits that occur during renorm
153
     *  These  will be accumulated till the carry bit is knwon
154
     */
155
    UWORD32 u4_out_standing_bytes;
156
157
    /*************************************************************************/
158
    /*  OUTPUT Bitstream related fields; not used in CABAC_MODE_COMPUTE_BITS */
159
    /*************************************************************************/
160
    /** points to start of stream buffer.    */
161
    UWORD8 *pu1_strm_buffer;
162
163
    /**
164
     *  max bitstream size (in bytes).
165
     *  Encoded stream shall not exceed this size.
166
     */
167
    UWORD32 u4_max_strm_size;
168
169
    /**
170
    `*  byte offset (w.r.t pu1_strm_buffer) where next byte would be written
171
     *  Bitstream engine makes sure it would not corrupt data beyond
172
     *  u4_max_strm_size bytes
173
     */
174
    UWORD32 u4_strm_buf_offset;
175
176
    /**
177
     *  signifies the number of consecutive zero bytes propogated from previous
178
     *  word. It is used for emulation prevention byte insertion in the stream
179
     */
180
    WORD32 i4_zero_bytes_run;
181
182
    /*********************************************************************/
183
    /*  CABAC context models                                             */
184
    /*********************************************************************/
185
    /** All Context models stored in packed form pState[bits6-1] | MPS[bit0] */
186
    UWORD8 au1_ctxt_models[IHEVC_CAB_CTXT_END];
187
188
    /**
189
     *Cabac context for start of every row which is same as top right ctxt
190
     */
191
    UWORD8 au1_ctxt_models_top_right[IHEVC_CAB_CTXT_END];
192
193
    /**
194
     * copy of enable entropy coding sync flag in pps
195
     */
196
    WORD8 i1_entropy_coding_sync_enabled_flag;
197
198
    /**
199
     * store the bitstream offset from which first slice data is generated by cabac
200
     */
201
    UWORD32 u4_first_slice_start_offset;
202
203
} cab_ctxt_t;
204
205
/*****************************************************************************/
206
/* Globals                                                                   */
207
/*****************************************************************************/
208
extern UWORD16 gau2_ihevce_cabac_bin_to_bits[64 * 2];
209
210
/*****************************************************************************/
211
/* Extern Function Declarations                                              */
212
/*****************************************************************************/
213
WORD32
214
    ihevce_cabac_reset(cab_ctxt_t *ps_cabac, bitstrm_t *ps_bitstrm, CABAC_OP_MODE e_cabac_op_mode);
215
216
WORD32 ihevce_cabac_init(
217
    cab_ctxt_t *ps_cabac,
218
    bitstrm_t *ps_bitstrm,
219
    WORD32 slice_qp,
220
    WORD32 cabac_init_idc,
221
    CABAC_OP_MODE e_cabac_op_mode);
222
223
WORD32 ihevce_cabac_put_byte(cab_ctxt_t *ps_cabac);
224
225
/**
226
******************************************************************************
227
*
228
*  @brief Codes a bin based on probablilty and mps packed context model
229
*
230
*  @par   Description
231
*  1. Apart from encoding bin, context model is updated as per state transition
232
*  2. Range and Low renormalization is done based on bin and original state
233
*  3. After renorm bistream is updated (if required)
234
*
235
*  @param[inout]   ps_cabac
236
*  pointer to cabac context (handle)
237
*
238
*  @param[in]   bin
239
*  bin(boolean) to be encoded
240
*
241
*  @param[in]   ctxt_index
242
*  index of cabac context model containing pState[bits6-1] | MPS[bit0]
243
*
244
*  @return      success or failure error code
245
*
246
******************************************************************************
247
*/
248
static INLINE WORD32 ihevce_cabac_encode_bin(cab_ctxt_t *ps_cabac, WORD32 bin, WORD32 ctxt_index)
249
198M
{
250
198M
    UWORD32 u4_range = ps_cabac->u4_range;
251
198M
    UWORD32 u4_low = ps_cabac->u4_low;
252
198M
    UWORD32 u4_rlps;
253
198M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
198M
    WORD32 state_mps = *pu1_ctxt_model;
255
198M
    WORD32 shift;
256
257
    /* Sanity checks */
258
198M
    ASSERT((bin == 0) || (bin == 1));
259
198M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
198M
    ASSERT(state_mps < 128);
261
262
198M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
68.9M
    {
264
68.9M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
68.9M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
68.9M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
68.9M
        if((state_mps & 0x1) ^ bin)
273
12.9M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
12.9M
            u4_low += u4_range;
276
12.9M
            u4_range = u4_rlps;
277
12.9M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
68.9M
        ps_cabac->u4_bits_estimated_q12 += gau2_ihevce_cabac_bin_to_bits[state_mps ^ bin];
282
283
        /* update the context model from state transition LUT */
284
68.9M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
285
286
        /*****************************************************************/
287
        /* Renormalization; calculate bits generated based on range(R)   */
288
        /* Note : 6 <= R < 512; R is 2 only for terminating encode       */
289
        /*****************************************************************/
290
68.9M
        GETRANGE(shift, u4_range);
291
68.9M
        shift = 9 - shift;
292
68.9M
        u4_low <<= shift;
293
68.9M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
68.9M
        ps_cabac->u4_bits_gen += shift;
297
68.9M
        ps_cabac->u4_range = u4_range;
298
68.9M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
68.9M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
5.22M
        {
303
5.22M
            return (ihevce_cabac_put_byte(ps_cabac));
304
5.22M
        }
305
68.9M
    }
306
129M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
129M
    {
308
        /* increment bits generated based on state and bin encoded */
309
129M
        ps_cabac->u4_bits_estimated_q12 += gau2_ihevce_cabac_bin_to_bits[state_mps ^ bin];
310
311
        /* update the context model from state transition LUT */
312
129M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
129M
    }
314
315
192M
    return (IHEVCE_SUCCESS);
316
198M
}
Unexecuted instantiation: ihevce_entropy_cod.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_entropy_interface.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_error_check.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_frame_process_utils.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_global_tables.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_hle_interface.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_hle_q_func.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_memory_init.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_tile_interface.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_interface.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_refine.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_search_algo.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_subpel.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_utils.c:ihevce_cabac_encode_bin
ihevce_cabac_cu_pu.c:ihevce_cabac_encode_bin
Line
Count
Source
249
16.0M
{
250
16.0M
    UWORD32 u4_range = ps_cabac->u4_range;
251
16.0M
    UWORD32 u4_low = ps_cabac->u4_low;
252
16.0M
    UWORD32 u4_rlps;
253
16.0M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
16.0M
    WORD32 state_mps = *pu1_ctxt_model;
255
16.0M
    WORD32 shift;
256
257
    /* Sanity checks */
258
16.0M
    ASSERT((bin == 0) || (bin == 1));
259
16.0M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
16.0M
    ASSERT(state_mps < 128);
261
262
16.0M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
3.31M
    {
264
3.31M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
3.31M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
3.31M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
3.31M
        if((state_mps & 0x1) ^ bin)
273
774k
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
774k
            u4_low += u4_range;
276
774k
            u4_range = u4_rlps;
277
774k
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
3.31M
        ps_cabac->u4_bits_estimated_q12 += gau2_ihevce_cabac_bin_to_bits[state_mps ^ bin];
282
283
        /* update the context model from state transition LUT */
284
3.31M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
285
286
        /*****************************************************************/
287
        /* Renormalization; calculate bits generated based on range(R)   */
288
        /* Note : 6 <= R < 512; R is 2 only for terminating encode       */
289
        /*****************************************************************/
290
3.31M
        GETRANGE(shift, u4_range);
291
3.31M
        shift = 9 - shift;
292
3.31M
        u4_low <<= shift;
293
3.31M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
3.31M
        ps_cabac->u4_bits_gen += shift;
297
3.31M
        ps_cabac->u4_range = u4_range;
298
3.31M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
3.31M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
275k
        {
303
275k
            return (ihevce_cabac_put_byte(ps_cabac));
304
275k
        }
305
3.31M
    }
306
12.7M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
12.7M
    {
308
        /* increment bits generated based on state and bin encoded */
309
12.7M
        ps_cabac->u4_bits_estimated_q12 += gau2_ihevce_cabac_bin_to_bits[state_mps ^ bin];
310
311
        /* update the context model from state transition LUT */
312
12.7M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
12.7M
    }
314
315
15.7M
    return (IHEVCE_SUCCESS);
316
16.0M
}
ihevce_cabac_tu.c:ihevce_cabac_encode_bin
Line
Count
Source
249
86.7M
{
250
86.7M
    UWORD32 u4_range = ps_cabac->u4_range;
251
86.7M
    UWORD32 u4_low = ps_cabac->u4_low;
252
86.7M
    UWORD32 u4_rlps;
253
86.7M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
86.7M
    WORD32 state_mps = *pu1_ctxt_model;
255
86.7M
    WORD32 shift;
256
257
    /* Sanity checks */
258
86.7M
    ASSERT((bin == 0) || (bin == 1));
259
86.7M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
86.7M
    ASSERT(state_mps < 128);
261
262
86.7M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
54.7M
    {
264
54.7M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
54.7M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
54.7M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
54.7M
        if((state_mps & 0x1) ^ bin)
273
11.3M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
11.3M
            u4_low += u4_range;
276
11.3M
            u4_range = u4_rlps;
277
11.3M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
54.7M
        ps_cabac->u4_bits_estimated_q12 += gau2_ihevce_cabac_bin_to_bits[state_mps ^ bin];
282
283
        /* update the context model from state transition LUT */
284
54.7M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
285
286
        /*****************************************************************/
287
        /* Renormalization; calculate bits generated based on range(R)   */
288
        /* Note : 6 <= R < 512; R is 2 only for terminating encode       */
289
        /*****************************************************************/
290
54.7M
        GETRANGE(shift, u4_range);
291
54.7M
        shift = 9 - shift;
292
54.7M
        u4_low <<= shift;
293
54.7M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
54.7M
        ps_cabac->u4_bits_gen += shift;
297
54.7M
        ps_cabac->u4_range = u4_range;
298
54.7M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
54.7M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
4.50M
        {
303
4.50M
            return (ihevce_cabac_put_byte(ps_cabac));
304
4.50M
        }
305
54.7M
    }
306
32.0M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
32.0M
    {
308
        /* increment bits generated based on state and bin encoded */
309
32.0M
        ps_cabac->u4_bits_estimated_q12 += gau2_ihevce_cabac_bin_to_bits[state_mps ^ bin];
310
311
        /* update the context model from state transition LUT */
312
32.0M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
32.0M
    }
314
315
82.2M
    return (IHEVCE_SUCCESS);
316
86.7M
}
Unexecuted instantiation: ihevce_coarse_me_pass.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_common_utils.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_decomp_pre_intra_pass.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_enc_loop_pass.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_enc_loop_utils.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_enc_sbh_funcs.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_enc_subpel_gen.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_encode_header.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_encode_header_sei_vui.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_frame_process.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_function_selector.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_had_satd.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_inter_pred.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_ipe_pass.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_me_pass.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_multi_thrd_funcs.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_mv_pred.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_mv_pred_merge.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_nbr_avail.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_recur_bracketing.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_sao.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_stasino_helpers.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_sub_pic_rc.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_tu_tree_selector.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_coarse.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_err_compute.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_fullpel.c:ihevce_cabac_encode_bin
Unexecuted instantiation: hme_globals.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_bs_compute_ctb.c:ihevce_cabac_encode_bin
ihevce_cabac.c:ihevce_cabac_encode_bin
Line
Count
Source
249
95.2M
{
250
95.2M
    UWORD32 u4_range = ps_cabac->u4_range;
251
95.2M
    UWORD32 u4_low = ps_cabac->u4_low;
252
95.2M
    UWORD32 u4_rlps;
253
95.2M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
95.2M
    WORD32 state_mps = *pu1_ctxt_model;
255
95.2M
    WORD32 shift;
256
257
    /* Sanity checks */
258
95.2M
    ASSERT((bin == 0) || (bin == 1));
259
95.2M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
95.2M
    ASSERT(state_mps < 128);
261
262
95.2M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
10.9M
    {
264
10.9M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
10.9M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
10.9M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
10.9M
        if((state_mps & 0x1) ^ bin)
273
826k
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
826k
            u4_low += u4_range;
276
826k
            u4_range = u4_rlps;
277
826k
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
10.9M
        ps_cabac->u4_bits_estimated_q12 += gau2_ihevce_cabac_bin_to_bits[state_mps ^ bin];
282
283
        /* update the context model from state transition LUT */
284
10.9M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
285
286
        /*****************************************************************/
287
        /* Renormalization; calculate bits generated based on range(R)   */
288
        /* Note : 6 <= R < 512; R is 2 only for terminating encode       */
289
        /*****************************************************************/
290
10.9M
        GETRANGE(shift, u4_range);
291
10.9M
        shift = 9 - shift;
292
10.9M
        u4_low <<= shift;
293
10.9M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
10.9M
        ps_cabac->u4_bits_gen += shift;
297
10.9M
        ps_cabac->u4_range = u4_range;
298
10.9M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
10.9M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
448k
        {
303
448k
            return (ihevce_cabac_put_byte(ps_cabac));
304
448k
        }
305
10.9M
    }
306
84.3M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
84.3M
    {
308
        /* increment bits generated based on state and bin encoded */
309
84.3M
        ps_cabac->u4_bits_estimated_q12 += gau2_ihevce_cabac_bin_to_bits[state_mps ^ bin];
310
311
        /* update the context model from state transition LUT */
312
84.3M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
84.3M
    }
314
315
94.8M
    return (IHEVCE_SUCCESS);
316
95.2M
}
Unexecuted instantiation: ihevce_cabac_rdo.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_deblk.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_enc_cu_recursion.c:ihevce_cabac_encode_bin
Unexecuted instantiation: ihevce_enc_loop_inter_mode_sifter.c:ihevce_cabac_encode_bin
317
318
WORD32 ihevce_cabac_encode_bypass_bin(cab_ctxt_t *ps_cabac, WORD32 bin);
319
320
WORD32
321
    ihevce_cabac_encode_terminate(cab_ctxt_t *ps_cabac, WORD32 term_bin, WORD32 i4_end_of_sub_strm);
322
323
/**
324
******************************************************************************
325
*
326
*  @brief Encodes a series of bypass bins (FLC bypass bins)
327
*
328
*  @par   Description
329
*  This function is more optimal than calling ihevce_cabac_encode_bypass_bin()
330
*  in a loop as cabac low, renorm and generating the stream (8bins at a time)
331
*  can be done in one operation
332
*
333
*  @param[inout]ps_cabac
334
*   pointer to cabac context (handle)
335
*
336
*  @param[in]   u4_sym
337
*   syntax element to be coded (as FLC bins)
338
*
339
*  @param[in]   num_bins
340
*   This is the FLC length for u4_sym
341
*
342
*
343
*  @return      success or failure error code
344
*
345
******************************************************************************
346
*/
347
static INLINE WORD32
348
    ihevce_cabac_encode_bypass_bins(cab_ctxt_t *ps_cabac, UWORD32 u4_bins, WORD32 num_bins)
349
124M
{
350
124M
    UWORD32 u4_range = ps_cabac->u4_range;
351
124M
    WORD32 next_byte;
352
124M
    WORD32 error = IHEVCE_SUCCESS;
353
354
124M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
28.1M
    {
356
        /* Sanity checks */
357
28.1M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
28.1M
        ASSERT((u4_range >= 256) && (u4_range < 512));
359
360
        /*Compute bit always to populate the trace*/
361
        /* increment bits generated by num_bins */
362
28.1M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
363
364
        /* Encode 8bins at a time and put in the bit-stream */
365
30.2M
        while(num_bins > 8)
366
2.17M
        {
367
2.17M
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
2.17M
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
2.17M
            ps_cabac->u4_low <<= 8;
374
2.17M
            ps_cabac->u4_low += (next_byte * u4_range);
375
2.17M
            ps_cabac->u4_bits_gen += 8;
376
377
2.17M
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
2.17M
            {
379
                /*  insert the leading byte of low into stream */
380
2.17M
                error |= ihevce_cabac_put_byte(ps_cabac);
381
2.17M
            }
382
2.17M
        }
383
384
        /* Update low with remaining bins and return */
385
28.1M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
28.1M
        ps_cabac->u4_low <<= num_bins;
388
28.1M
        ps_cabac->u4_low += (next_byte * u4_range);
389
28.1M
        ps_cabac->u4_bits_gen += num_bins;
390
391
28.1M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
13.1M
        {
393
            /*  insert the leading byte of low into stream */
394
13.1M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
13.1M
        }
396
28.1M
    }
397
96.6M
    else
398
96.6M
    {
399
        /* increment bits generated by num_bins */
400
96.6M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
96.6M
    }
402
403
124M
    return (error);
404
124M
}
Unexecuted instantiation: ihevce_entropy_cod.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_entropy_interface.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_error_check.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_frame_process_utils.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_global_tables.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_hle_interface.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_hle_q_func.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_memory_init.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_tile_interface.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_interface.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_refine.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_search_algo.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_subpel.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_utils.c:ihevce_cabac_encode_bypass_bins
ihevce_cabac_cu_pu.c:ihevce_cabac_encode_bypass_bins
Line
Count
Source
349
4.64M
{
350
4.64M
    UWORD32 u4_range = ps_cabac->u4_range;
351
4.64M
    WORD32 next_byte;
352
4.64M
    WORD32 error = IHEVCE_SUCCESS;
353
354
4.64M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
1.15M
    {
356
        /* Sanity checks */
357
1.15M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
1.15M
        ASSERT((u4_range >= 256) && (u4_range < 512));
359
360
        /*Compute bit always to populate the trace*/
361
        /* increment bits generated by num_bins */
362
1.15M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
363
364
        /* Encode 8bins at a time and put in the bit-stream */
365
1.15M
        while(num_bins > 8)
366
0
        {
367
0
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
0
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
0
            ps_cabac->u4_low <<= 8;
374
0
            ps_cabac->u4_low += (next_byte * u4_range);
375
0
            ps_cabac->u4_bits_gen += 8;
376
377
0
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
0
            {
379
                /*  insert the leading byte of low into stream */
380
0
                error |= ihevce_cabac_put_byte(ps_cabac);
381
0
            }
382
0
        }
383
384
        /* Update low with remaining bins and return */
385
1.15M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
1.15M
        ps_cabac->u4_low <<= num_bins;
388
1.15M
        ps_cabac->u4_low += (next_byte * u4_range);
389
1.15M
        ps_cabac->u4_bits_gen += num_bins;
390
391
1.15M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
353k
        {
393
            /*  insert the leading byte of low into stream */
394
353k
            error |= ihevce_cabac_put_byte(ps_cabac);
395
353k
        }
396
1.15M
    }
397
3.49M
    else
398
3.49M
    {
399
        /* increment bits generated by num_bins */
400
3.49M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
3.49M
    }
402
403
4.64M
    return (error);
404
4.64M
}
ihevce_cabac_tu.c:ihevce_cabac_encode_bypass_bins
Line
Count
Source
349
26.9M
{
350
26.9M
    UWORD32 u4_range = ps_cabac->u4_range;
351
26.9M
    WORD32 next_byte;
352
26.9M
    WORD32 error = IHEVCE_SUCCESS;
353
354
26.9M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
5.38M
    {
356
        /* Sanity checks */
357
5.38M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
5.38M
        ASSERT((u4_range >= 256) && (u4_range < 512));
359
360
        /*Compute bit always to populate the trace*/
361
        /* increment bits generated by num_bins */
362
5.38M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
363
364
        /* Encode 8bins at a time and put in the bit-stream */
365
7.17M
        while(num_bins > 8)
366
1.79M
        {
367
1.79M
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
1.79M
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
1.79M
            ps_cabac->u4_low <<= 8;
374
1.79M
            ps_cabac->u4_low += (next_byte * u4_range);
375
1.79M
            ps_cabac->u4_bits_gen += 8;
376
377
1.79M
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
1.79M
            {
379
                /*  insert the leading byte of low into stream */
380
1.79M
                error |= ihevce_cabac_put_byte(ps_cabac);
381
1.79M
            }
382
1.79M
        }
383
384
        /* Update low with remaining bins and return */
385
5.38M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
5.38M
        ps_cabac->u4_low <<= num_bins;
388
5.38M
        ps_cabac->u4_low += (next_byte * u4_range);
389
5.38M
        ps_cabac->u4_bits_gen += num_bins;
390
391
5.38M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
2.92M
        {
393
            /*  insert the leading byte of low into stream */
394
2.92M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
2.92M
        }
396
5.38M
    }
397
21.5M
    else
398
21.5M
    {
399
        /* increment bits generated by num_bins */
400
21.5M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
21.5M
    }
402
403
26.9M
    return (error);
404
26.9M
}
Unexecuted instantiation: ihevce_coarse_me_pass.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_common_utils.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_decomp_pre_intra_pass.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_enc_loop_pass.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_enc_loop_utils.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_enc_sbh_funcs.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_enc_subpel_gen.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_encode_header.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_encode_header_sei_vui.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_frame_process.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_function_selector.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_had_satd.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_inter_pred.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_ipe_pass.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_me_pass.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_multi_thrd_funcs.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_mv_pred.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_mv_pred_merge.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_nbr_avail.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_recur_bracketing.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_sao.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_stasino_helpers.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_sub_pic_rc.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_tu_tree_selector.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_coarse.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_err_compute.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_fullpel.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: hme_globals.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_bs_compute_ctb.c:ihevce_cabac_encode_bypass_bins
ihevce_cabac.c:ihevce_cabac_encode_bypass_bins
Line
Count
Source
349
93.0M
{
350
93.0M
    UWORD32 u4_range = ps_cabac->u4_range;
351
93.0M
    WORD32 next_byte;
352
93.0M
    WORD32 error = IHEVCE_SUCCESS;
353
354
93.0M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
21.5M
    {
356
        /* Sanity checks */
357
21.5M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
21.5M
        ASSERT((u4_range >= 256) && (u4_range < 512));
359
360
        /*Compute bit always to populate the trace*/
361
        /* increment bits generated by num_bins */
362
21.5M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
363
364
        /* Encode 8bins at a time and put in the bit-stream */
365
21.9M
        while(num_bins > 8)
366
380k
        {
367
380k
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
380k
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
380k
            ps_cabac->u4_low <<= 8;
374
380k
            ps_cabac->u4_low += (next_byte * u4_range);
375
380k
            ps_cabac->u4_bits_gen += 8;
376
377
380k
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
380k
            {
379
                /*  insert the leading byte of low into stream */
380
380k
                error |= ihevce_cabac_put_byte(ps_cabac);
381
380k
            }
382
380k
        }
383
384
        /* Update low with remaining bins and return */
385
21.5M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
21.5M
        ps_cabac->u4_low <<= num_bins;
388
21.5M
        ps_cabac->u4_low += (next_byte * u4_range);
389
21.5M
        ps_cabac->u4_bits_gen += num_bins;
390
391
21.5M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
9.91M
        {
393
            /*  insert the leading byte of low into stream */
394
9.91M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
9.91M
        }
396
21.5M
    }
397
71.5M
    else
398
71.5M
    {
399
        /* increment bits generated by num_bins */
400
71.5M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
71.5M
    }
402
403
93.0M
    return (error);
404
93.0M
}
Unexecuted instantiation: ihevce_cabac_rdo.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_deblk.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_enc_cu_recursion.c:ihevce_cabac_encode_bypass_bins
Unexecuted instantiation: ihevce_enc_loop_inter_mode_sifter.c:ihevce_cabac_encode_bypass_bins
405
406
WORD32 ihevce_cabac_encode_tunary(
407
    cab_ctxt_t *ps_cabac,
408
    WORD32 sym,
409
    WORD32 c_max,
410
    WORD32 ctxt_index,
411
    WORD32 ctxt_shift,
412
    WORD32 ctxt_inc_max);
413
414
WORD32 ihevce_cabac_encode_tunary_bypass(cab_ctxt_t *ps_cabac, WORD32 sym, WORD32 c_max);
415
416
WORD32 ihevce_cabac_encode_egk(cab_ctxt_t *ps_cabac, UWORD32 u4_sym, WORD32 k);
417
418
WORD32 ihevce_cabac_encode_trunc_rice(
419
    cab_ctxt_t *ps_cabac, UWORD32 u4_sym, WORD32 c_rice_param, WORD32 c_rice_max);
420
421
WORD32 ihevce_cabac_flush(cab_ctxt_t *ps_cabac, WORD32 i4_end_of_sub_strm);
422
423
WORD32 ihevce_cabac_ctxt_backup(cab_ctxt_t *ps_cabac);
424
425
WORD32 ihevce_cabac_ctxt_row_init(cab_ctxt_t *ps_cabac);
426
427
#endif /* _IHEVCE_CABAC_H_ */