Coverage Report

Created: 2025-07-11 06:43

/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
219M
#define CABAC_BITS 9
51
52
/**
53
*******************************************************************************
54
@brief q format to account for the fractional bits encoded in cabac
55
*******************************************************************************
56
 */
57
1.45G
#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
351M
#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
382M
{
250
382M
    UWORD32 u4_range = ps_cabac->u4_range;
251
382M
    UWORD32 u4_low = ps_cabac->u4_low;
252
382M
    UWORD32 u4_rlps;
253
382M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
382M
    WORD32 state_mps = *pu1_ctxt_model;
255
382M
    WORD32 shift;
256
257
    /* Sanity checks */
258
382M
    ASSERT((bin == 0) || (bin == 1));
259
382M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
382M
    ASSERT(state_mps < 128);
261
262
382M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
105M
    {
264
105M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
105M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
105M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
105M
        if((state_mps & 0x1) ^ bin)
273
25.5M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
25.5M
            u4_low += u4_range;
276
25.5M
            u4_range = u4_rlps;
277
25.5M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
105M
        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
105M
        *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
105M
        GETRANGE(shift, u4_range);
291
105M
        shift = 9 - shift;
292
105M
        u4_low <<= shift;
293
105M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
105M
        ps_cabac->u4_bits_gen += shift;
297
105M
        ps_cabac->u4_range = u4_range;
298
105M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
105M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
9.26M
        {
303
9.26M
            return (ihevce_cabac_put_byte(ps_cabac));
304
9.26M
        }
305
105M
    }
306
277M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
277M
    {
308
        /* increment bits generated based on state and bin encoded */
309
277M
        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
277M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
277M
    }
314
315
373M
    return (IHEVCE_SUCCESS);
316
382M
}
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
67.0M
{
250
67.0M
    UWORD32 u4_range = ps_cabac->u4_range;
251
67.0M
    UWORD32 u4_low = ps_cabac->u4_low;
252
67.0M
    UWORD32 u4_rlps;
253
67.0M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
67.0M
    WORD32 state_mps = *pu1_ctxt_model;
255
67.0M
    WORD32 shift;
256
257
    /* Sanity checks */
258
67.0M
    ASSERT((bin == 0) || (bin == 1));
259
67.0M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
67.0M
    ASSERT(state_mps < 128);
261
262
67.0M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
9.18M
    {
264
9.18M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
9.18M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
9.18M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
9.18M
        if((state_mps & 0x1) ^ bin)
273
3.11M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
3.11M
            u4_low += u4_range;
276
3.11M
            u4_range = u4_rlps;
277
3.11M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
9.18M
        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
9.18M
        *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
9.18M
        GETRANGE(shift, u4_range);
291
9.18M
        shift = 9 - shift;
292
9.18M
        u4_low <<= shift;
293
9.18M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
9.18M
        ps_cabac->u4_bits_gen += shift;
297
9.18M
        ps_cabac->u4_range = u4_range;
298
9.18M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
9.18M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
886k
        {
303
886k
            return (ihevce_cabac_put_byte(ps_cabac));
304
886k
        }
305
9.18M
    }
306
57.8M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
57.8M
    {
308
        /* increment bits generated based on state and bin encoded */
309
57.8M
        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
57.8M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
57.8M
    }
314
315
66.1M
    return (IHEVCE_SUCCESS);
316
67.0M
}
ihevce_cabac_tu.c:ihevce_cabac_encode_bin
Line
Count
Source
249
190M
{
250
190M
    UWORD32 u4_range = ps_cabac->u4_range;
251
190M
    UWORD32 u4_low = ps_cabac->u4_low;
252
190M
    UWORD32 u4_rlps;
253
190M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
190M
    WORD32 state_mps = *pu1_ctxt_model;
255
190M
    WORD32 shift;
256
257
    /* Sanity checks */
258
190M
    ASSERT((bin == 0) || (bin == 1));
259
190M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
190M
    ASSERT(state_mps < 128);
261
262
190M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
81.3M
    {
264
81.3M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
81.3M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
81.3M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
81.3M
        if((state_mps & 0x1) ^ bin)
273
20.6M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
20.6M
            u4_low += u4_range;
276
20.6M
            u4_range = u4_rlps;
277
20.6M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
81.3M
        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
81.3M
        *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
81.3M
        GETRANGE(shift, u4_range);
291
81.3M
        shift = 9 - shift;
292
81.3M
        u4_low <<= shift;
293
81.3M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
81.3M
        ps_cabac->u4_bits_gen += shift;
297
81.3M
        ps_cabac->u4_range = u4_range;
298
81.3M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
81.3M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
7.52M
        {
303
7.52M
            return (ihevce_cabac_put_byte(ps_cabac));
304
7.52M
        }
305
81.3M
    }
306
109M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
109M
    {
308
        /* increment bits generated based on state and bin encoded */
309
109M
        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
109M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
109M
    }
314
315
183M
    return (IHEVCE_SUCCESS);
316
190M
}
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
124M
{
250
124M
    UWORD32 u4_range = ps_cabac->u4_range;
251
124M
    UWORD32 u4_low = ps_cabac->u4_low;
252
124M
    UWORD32 u4_rlps;
253
124M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
124M
    WORD32 state_mps = *pu1_ctxt_model;
255
124M
    WORD32 shift;
256
257
    /* Sanity checks */
258
124M
    ASSERT((bin == 0) || (bin == 1));
259
124M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
124M
    ASSERT(state_mps < 128);
261
262
124M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
14.5M
    {
264
14.5M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
14.5M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
14.5M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
14.5M
        if((state_mps & 0x1) ^ bin)
273
1.78M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
1.78M
            u4_low += u4_range;
276
1.78M
            u4_range = u4_rlps;
277
1.78M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
14.5M
        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
14.5M
        *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
14.5M
        GETRANGE(shift, u4_range);
291
14.5M
        shift = 9 - shift;
292
14.5M
        u4_low <<= shift;
293
14.5M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
14.5M
        ps_cabac->u4_bits_gen += shift;
297
14.5M
        ps_cabac->u4_range = u4_range;
298
14.5M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
14.5M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
860k
        {
303
860k
            return (ihevce_cabac_put_byte(ps_cabac));
304
860k
        }
305
14.5M
    }
306
110M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
110M
    {
308
        /* increment bits generated based on state and bin encoded */
309
110M
        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
110M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
110M
    }
314
315
124M
    return (IHEVCE_SUCCESS);
316
124M
}
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
315M
{
350
315M
    UWORD32 u4_range = ps_cabac->u4_range;
351
315M
    WORD32 next_byte;
352
315M
    WORD32 error = IHEVCE_SUCCESS;
353
354
315M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
41.8M
    {
356
        /* Sanity checks */
357
41.8M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
41.8M
        ASSERT((u4_range >= 256) && (u4_range < 512));
359
360
        /*Compute bit always to populate the trace*/
361
        /* increment bits generated by num_bins */
362
41.8M
        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
45.1M
        while(num_bins > 8)
366
3.26M
        {
367
3.26M
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
3.26M
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
3.26M
            ps_cabac->u4_low <<= 8;
374
3.26M
            ps_cabac->u4_low += (next_byte * u4_range);
375
3.26M
            ps_cabac->u4_bits_gen += 8;
376
377
3.26M
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
3.26M
            {
379
                /*  insert the leading byte of low into stream */
380
3.26M
                error |= ihevce_cabac_put_byte(ps_cabac);
381
3.26M
            }
382
3.26M
        }
383
384
        /* Update low with remaining bins and return */
385
41.8M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
41.8M
        ps_cabac->u4_low <<= num_bins;
388
41.8M
        ps_cabac->u4_low += (next_byte * u4_range);
389
41.8M
        ps_cabac->u4_bits_gen += num_bins;
390
391
41.8M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
21.2M
        {
393
            /*  insert the leading byte of low into stream */
394
21.2M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
21.2M
        }
396
41.8M
    }
397
274M
    else
398
274M
    {
399
        /* increment bits generated by num_bins */
400
274M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
274M
    }
402
403
315M
    return (error);
404
315M
}
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
13.2M
{
350
13.2M
    UWORD32 u4_range = ps_cabac->u4_range;
351
13.2M
    WORD32 next_byte;
352
13.2M
    WORD32 error = IHEVCE_SUCCESS;
353
354
13.2M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
1.72M
    {
356
        /* Sanity checks */
357
1.72M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
1.72M
        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.72M
        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.72M
        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.72M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
1.72M
        ps_cabac->u4_low <<= num_bins;
388
1.72M
        ps_cabac->u4_low += (next_byte * u4_range);
389
1.72M
        ps_cabac->u4_bits_gen += num_bins;
390
391
1.72M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
453k
        {
393
            /*  insert the leading byte of low into stream */
394
453k
            error |= ihevce_cabac_put_byte(ps_cabac);
395
453k
        }
396
1.72M
    }
397
11.5M
    else
398
11.5M
    {
399
        /* increment bits generated by num_bins */
400
11.5M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
11.5M
    }
402
403
13.2M
    return (error);
404
13.2M
}
ihevce_cabac_tu.c:ihevce_cabac_encode_bypass_bins
Line
Count
Source
349
65.9M
{
350
65.9M
    UWORD32 u4_range = ps_cabac->u4_range;
351
65.9M
    WORD32 next_byte;
352
65.9M
    WORD32 error = IHEVCE_SUCCESS;
353
354
65.9M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
8.93M
    {
356
        /* Sanity checks */
357
8.93M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
8.93M
        ASSERT((u4_range >= 256) && (u4_range < 512));
359
360
        /*Compute bit always to populate the trace*/
361
        /* increment bits generated by num_bins */
362
8.93M
        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
11.3M
        while(num_bins > 8)
366
2.42M
        {
367
2.42M
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
2.42M
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
2.42M
            ps_cabac->u4_low <<= 8;
374
2.42M
            ps_cabac->u4_low += (next_byte * u4_range);
375
2.42M
            ps_cabac->u4_bits_gen += 8;
376
377
2.42M
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
2.42M
            {
379
                /*  insert the leading byte of low into stream */
380
2.42M
                error |= ihevce_cabac_put_byte(ps_cabac);
381
2.42M
            }
382
2.42M
        }
383
384
        /* Update low with remaining bins and return */
385
8.93M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
8.93M
        ps_cabac->u4_low <<= num_bins;
388
8.93M
        ps_cabac->u4_low += (next_byte * u4_range);
389
8.93M
        ps_cabac->u4_bits_gen += num_bins;
390
391
8.93M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
4.79M
        {
393
            /*  insert the leading byte of low into stream */
394
4.79M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
4.79M
        }
396
8.93M
    }
397
57.0M
    else
398
57.0M
    {
399
        /* increment bits generated by num_bins */
400
57.0M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
57.0M
    }
402
403
65.9M
    return (error);
404
65.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
236M
{
350
236M
    UWORD32 u4_range = ps_cabac->u4_range;
351
236M
    WORD32 next_byte;
352
236M
    WORD32 error = IHEVCE_SUCCESS;
353
354
236M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
31.1M
    {
356
        /* Sanity checks */
357
31.1M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
31.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
31.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
32.0M
        while(num_bins > 8)
366
842k
        {
367
842k
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
842k
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
842k
            ps_cabac->u4_low <<= 8;
374
842k
            ps_cabac->u4_low += (next_byte * u4_range);
375
842k
            ps_cabac->u4_bits_gen += 8;
376
377
842k
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
842k
            {
379
                /*  insert the leading byte of low into stream */
380
842k
                error |= ihevce_cabac_put_byte(ps_cabac);
381
842k
            }
382
842k
        }
383
384
        /* Update low with remaining bins and return */
385
31.1M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
31.1M
        ps_cabac->u4_low <<= num_bins;
388
31.1M
        ps_cabac->u4_low += (next_byte * u4_range);
389
31.1M
        ps_cabac->u4_bits_gen += num_bins;
390
391
31.1M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
16.0M
        {
393
            /*  insert the leading byte of low into stream */
394
16.0M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
16.0M
        }
396
31.1M
    }
397
205M
    else
398
205M
    {
399
        /* increment bits generated by num_bins */
400
205M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
205M
    }
402
403
236M
    return (error);
404
236M
}
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_ */