Coverage Report

Created: 2025-07-23 06:28

/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
214M
#define CABAC_BITS 9
51
52
/**
53
*******************************************************************************
54
@brief q format to account for the fractional bits encoded in cabac
55
*******************************************************************************
56
 */
57
1.33G
#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
322M
#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
356M
{
250
356M
    UWORD32 u4_range = ps_cabac->u4_range;
251
356M
    UWORD32 u4_low = ps_cabac->u4_low;
252
356M
    UWORD32 u4_rlps;
253
356M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
356M
    WORD32 state_mps = *pu1_ctxt_model;
255
356M
    WORD32 shift;
256
257
    /* Sanity checks */
258
356M
    ASSERT((bin == 0) || (bin == 1));
259
356M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
356M
    ASSERT(state_mps < 128);
261
262
356M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
101M
    {
264
101M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
101M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
101M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
101M
        if((state_mps & 0x1) ^ bin)
273
24.1M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
24.1M
            u4_low += u4_range;
276
24.1M
            u4_range = u4_rlps;
277
24.1M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
101M
        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
101M
        *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
101M
        GETRANGE(shift, u4_range);
291
101M
        shift = 9 - shift;
292
101M
        u4_low <<= shift;
293
101M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
101M
        ps_cabac->u4_bits_gen += shift;
297
101M
        ps_cabac->u4_range = u4_range;
298
101M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
101M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
8.84M
        {
303
8.84M
            return (ihevce_cabac_put_byte(ps_cabac));
304
8.84M
        }
305
101M
    }
306
254M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
254M
    {
308
        /* increment bits generated based on state and bin encoded */
309
254M
        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
254M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
254M
    }
314
315
347M
    return (IHEVCE_SUCCESS);
316
356M
}
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
61.2M
{
250
61.2M
    UWORD32 u4_range = ps_cabac->u4_range;
251
61.2M
    UWORD32 u4_low = ps_cabac->u4_low;
252
61.2M
    UWORD32 u4_rlps;
253
61.2M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
61.2M
    WORD32 state_mps = *pu1_ctxt_model;
255
61.2M
    WORD32 shift;
256
257
    /* Sanity checks */
258
61.2M
    ASSERT((bin == 0) || (bin == 1));
259
61.2M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
61.2M
    ASSERT(state_mps < 128);
261
262
61.2M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
8.49M
    {
264
8.49M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
8.49M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
8.49M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
8.49M
        if((state_mps & 0x1) ^ bin)
273
2.84M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
2.84M
            u4_low += u4_range;
276
2.84M
            u4_range = u4_rlps;
277
2.84M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
8.49M
        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
8.49M
        *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
8.49M
        GETRANGE(shift, u4_range);
291
8.49M
        shift = 9 - shift;
292
8.49M
        u4_low <<= shift;
293
8.49M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
8.49M
        ps_cabac->u4_bits_gen += shift;
297
8.49M
        ps_cabac->u4_range = u4_range;
298
8.49M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
8.49M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
819k
        {
303
819k
            return (ihevce_cabac_put_byte(ps_cabac));
304
819k
        }
305
8.49M
    }
306
52.7M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
52.7M
    {
308
        /* increment bits generated based on state and bin encoded */
309
52.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
52.7M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
52.7M
    }
314
315
60.4M
    return (IHEVCE_SUCCESS);
316
61.2M
}
ihevce_cabac_tu.c:ihevce_cabac_encode_bin
Line
Count
Source
249
179M
{
250
179M
    UWORD32 u4_range = ps_cabac->u4_range;
251
179M
    UWORD32 u4_low = ps_cabac->u4_low;
252
179M
    UWORD32 u4_rlps;
253
179M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
179M
    WORD32 state_mps = *pu1_ctxt_model;
255
179M
    WORD32 shift;
256
257
    /* Sanity checks */
258
179M
    ASSERT((bin == 0) || (bin == 1));
259
179M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
179M
    ASSERT(state_mps < 128);
261
262
179M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
78.8M
    {
264
78.8M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
78.8M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
78.8M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
78.8M
        if((state_mps & 0x1) ^ bin)
273
19.6M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
19.6M
            u4_low += u4_range;
276
19.6M
            u4_range = u4_rlps;
277
19.6M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
78.8M
        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
78.8M
        *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
78.8M
        GETRANGE(shift, u4_range);
291
78.8M
        shift = 9 - shift;
292
78.8M
        u4_low <<= shift;
293
78.8M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
78.8M
        ps_cabac->u4_bits_gen += shift;
297
78.8M
        ps_cabac->u4_range = u4_range;
298
78.8M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
78.8M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
7.20M
        {
303
7.20M
            return (ihevce_cabac_put_byte(ps_cabac));
304
7.20M
        }
305
78.8M
    }
306
100M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
100M
    {
308
        /* increment bits generated based on state and bin encoded */
309
100M
        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
100M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
100M
    }
314
315
172M
    return (IHEVCE_SUCCESS);
316
179M
}
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
115M
{
250
115M
    UWORD32 u4_range = ps_cabac->u4_range;
251
115M
    UWORD32 u4_low = ps_cabac->u4_low;
252
115M
    UWORD32 u4_rlps;
253
115M
    UWORD8 *pu1_ctxt_model = &ps_cabac->au1_ctxt_models[ctxt_index];
254
115M
    WORD32 state_mps = *pu1_ctxt_model;
255
115M
    WORD32 shift;
256
257
    /* Sanity checks */
258
115M
    ASSERT((bin == 0) || (bin == 1));
259
115M
    ASSERT((ctxt_index >= 0) && (ctxt_index < IHEVC_CAB_CTXT_END));
260
115M
    ASSERT(state_mps < 128);
261
262
115M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
263
14.2M
    {
264
14.2M
        ASSERT((u4_range >= 256) && (u4_range < 512));
265
266
        /* Get the lps range from LUT based on quantized range and state */
267
14.2M
        u4_rlps = gau1_ihevc_cabac_rlps[state_mps >> 1][(u4_range >> 6) & 0x3];
268
269
14.2M
        u4_range -= u4_rlps;
270
271
        /* check if bin is mps or lps */
272
14.2M
        if((state_mps & 0x1) ^ bin)
273
1.64M
        {
274
            /* lps path;  L= L + R; R = RLPS */
275
1.64M
            u4_low += u4_range;
276
1.64M
            u4_range = u4_rlps;
277
1.64M
        }
278
279
        /*Compute bit always to populate the trace*/
280
        /* increment bits generated based on state and bin encoded */
281
14.2M
        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.2M
        *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.2M
        GETRANGE(shift, u4_range);
291
14.2M
        shift = 9 - shift;
292
14.2M
        u4_low <<= shift;
293
14.2M
        u4_range <<= shift;
294
295
        /* bits to be inserted in the bitstream */
296
14.2M
        ps_cabac->u4_bits_gen += shift;
297
14.2M
        ps_cabac->u4_range = u4_range;
298
14.2M
        ps_cabac->u4_low = u4_low;
299
300
        /* generate stream when a byte is ready */
301
14.2M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
302
818k
        {
303
818k
            return (ihevce_cabac_put_byte(ps_cabac));
304
818k
        }
305
14.2M
    }
306
101M
    else /* (CABAC_MODE_COMPUTE_BITS == e_cabac_op_mode) */
307
101M
    {
308
        /* increment bits generated based on state and bin encoded */
309
101M
        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
101M
        *pu1_ctxt_model = gau1_ihevc_next_state[(state_mps << 1) | bin];
313
101M
    }
314
315
114M
    return (IHEVCE_SUCCESS);
316
115M
}
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
287M
{
350
287M
    UWORD32 u4_range = ps_cabac->u4_range;
351
287M
    WORD32 next_byte;
352
287M
    WORD32 error = IHEVCE_SUCCESS;
353
354
287M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
41.3M
    {
356
        /* Sanity checks */
357
41.3M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
41.3M
        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.3M
        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
44.7M
        while(num_bins > 8)
366
3.33M
        {
367
3.33M
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
3.33M
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
3.33M
            ps_cabac->u4_low <<= 8;
374
3.33M
            ps_cabac->u4_low += (next_byte * u4_range);
375
3.33M
            ps_cabac->u4_bits_gen += 8;
376
377
3.33M
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
3.33M
            {
379
                /*  insert the leading byte of low into stream */
380
3.33M
                error |= ihevce_cabac_put_byte(ps_cabac);
381
3.33M
            }
382
3.33M
        }
383
384
        /* Update low with remaining bins and return */
385
41.3M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
41.3M
        ps_cabac->u4_low <<= num_bins;
388
41.3M
        ps_cabac->u4_low += (next_byte * u4_range);
389
41.3M
        ps_cabac->u4_bits_gen += num_bins;
390
391
41.3M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
21.3M
        {
393
            /*  insert the leading byte of low into stream */
394
21.3M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
21.3M
        }
396
41.3M
    }
397
246M
    else
398
246M
    {
399
        /* increment bits generated by num_bins */
400
246M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
246M
    }
402
403
287M
    return (error);
404
287M
}
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
12.5M
{
350
12.5M
    UWORD32 u4_range = ps_cabac->u4_range;
351
12.5M
    WORD32 next_byte;
352
12.5M
    WORD32 error = IHEVCE_SUCCESS;
353
354
12.5M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
1.64M
    {
356
        /* Sanity checks */
357
1.64M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
1.64M
        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.64M
        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.64M
        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.64M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
1.64M
        ps_cabac->u4_low <<= num_bins;
388
1.64M
        ps_cabac->u4_low += (next_byte * u4_range);
389
1.64M
        ps_cabac->u4_bits_gen += num_bins;
390
391
1.64M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
436k
        {
393
            /*  insert the leading byte of low into stream */
394
436k
            error |= ihevce_cabac_put_byte(ps_cabac);
395
436k
        }
396
1.64M
    }
397
10.8M
    else
398
10.8M
    {
399
        /* increment bits generated by num_bins */
400
10.8M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
10.8M
    }
402
403
12.5M
    return (error);
404
12.5M
}
ihevce_cabac_tu.c:ihevce_cabac_encode_bypass_bins
Line
Count
Source
349
60.9M
{
350
60.9M
    UWORD32 u4_range = ps_cabac->u4_range;
351
60.9M
    WORD32 next_byte;
352
60.9M
    WORD32 error = IHEVCE_SUCCESS;
353
354
60.9M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
9.16M
    {
356
        /* Sanity checks */
357
9.16M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
9.16M
        ASSERT((u4_range >= 256) && (u4_range < 512));
359
360
        /*Compute bit always to populate the trace*/
361
        /* increment bits generated by num_bins */
362
9.16M
        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.5M
        while(num_bins > 8)
366
2.36M
        {
367
2.36M
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
2.36M
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
2.36M
            ps_cabac->u4_low <<= 8;
374
2.36M
            ps_cabac->u4_low += (next_byte * u4_range);
375
2.36M
            ps_cabac->u4_bits_gen += 8;
376
377
2.36M
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
2.36M
            {
379
                /*  insert the leading byte of low into stream */
380
2.36M
                error |= ihevce_cabac_put_byte(ps_cabac);
381
2.36M
            }
382
2.36M
        }
383
384
        /* Update low with remaining bins and return */
385
9.16M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
9.16M
        ps_cabac->u4_low <<= num_bins;
388
9.16M
        ps_cabac->u4_low += (next_byte * u4_range);
389
9.16M
        ps_cabac->u4_bits_gen += num_bins;
390
391
9.16M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
4.92M
        {
393
            /*  insert the leading byte of low into stream */
394
4.92M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
4.92M
        }
396
9.16M
    }
397
51.8M
    else
398
51.8M
    {
399
        /* increment bits generated by num_bins */
400
51.8M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
51.8M
    }
402
403
60.9M
    return (error);
404
60.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
214M
{
350
214M
    UWORD32 u4_range = ps_cabac->u4_range;
351
214M
    WORD32 next_byte;
352
214M
    WORD32 error = IHEVCE_SUCCESS;
353
354
214M
    if(CABAC_MODE_ENCODE_BITS == ps_cabac->e_cabac_op_mode)
355
30.5M
    {
356
        /* Sanity checks */
357
30.5M
        ASSERT((num_bins < 33) && (num_bins > 0));
358
30.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
30.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
31.5M
        while(num_bins > 8)
366
967k
        {
367
967k
            num_bins -= 8;
368
369
            /* extract the leading 8 bins */
370
967k
            next_byte = (u4_bins >> num_bins) & 0xff;
371
372
            /*  L = (L << 8) +  (R * next_byte) */
373
967k
            ps_cabac->u4_low <<= 8;
374
967k
            ps_cabac->u4_low += (next_byte * u4_range);
375
967k
            ps_cabac->u4_bits_gen += 8;
376
377
967k
            if(ps_cabac->u4_bits_gen > CABAC_BITS)
378
967k
            {
379
                /*  insert the leading byte of low into stream */
380
967k
                error |= ihevce_cabac_put_byte(ps_cabac);
381
967k
            }
382
967k
        }
383
384
        /* Update low with remaining bins and return */
385
30.5M
        next_byte = (u4_bins & ((1 << num_bins) - 1));
386
387
30.5M
        ps_cabac->u4_low <<= num_bins;
388
30.5M
        ps_cabac->u4_low += (next_byte * u4_range);
389
30.5M
        ps_cabac->u4_bits_gen += num_bins;
390
391
30.5M
        if(ps_cabac->u4_bits_gen > CABAC_BITS)
392
15.9M
        {
393
            /*  insert the leading byte of low into stream */
394
15.9M
            error |= ihevce_cabac_put_byte(ps_cabac);
395
15.9M
        }
396
30.5M
    }
397
183M
    else
398
183M
    {
399
        /* increment bits generated by num_bins */
400
183M
        ps_cabac->u4_bits_estimated_q12 += (num_bins << CABAC_FRAC_BITS_Q);
401
183M
    }
402
403
214M
    return (error);
404
214M
}
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_ */