xref: /aosp_15_r20/external/libavc/encoder/ih264e_cabac.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1 /******************************************************************************
2  *
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 /**
22 *******************************************************************************
23 * @file
24 *  ih264e_cabac.h
25 *
26 * @brief
27 *  This file contains declarations necessary for cabac encoding
28 *
29 * @author
30 *  ittiam
31 *
32 * @remarks
33 *  none
34 *
35 *******************************************************************************
36 */
37 
38 #ifndef _IH264E_CABAC_H_
39 #define _IH264E_CABAC_H_
40 
41 /*****************************************************************************/
42 /* Macros                                                                    */
43 /*****************************************************************************/
44 
45 /**
46 *******************************************************************************
47 *  @brief Bit precision of cabac engine;
48 *******************************************************************************
49 */
50 #define CABAC_BITS  9
51 
52 /**
53 *******************************************************************************
54 *  @macro Reverse bits in an unsigned integer
55 *******************************************************************************
56 */
57 #define REV(u4_input, u4_output)                 \
58 {                                                \
59     UWORD32 u4_temp = (u4_input);                \
60     WORD8 i;                                     \
61     u4_output = 0;                               \
62     for (i = 0; i < 32; i++)                     \
63     {                                            \
64         u4_output = (u4_output << 1) +           \
65                         ((u4_temp >> i) & 0x01); \
66     }                                            \
67 }
68 
69 /**
70 *******************************************************************************
71 *! Bit manipulation macros
72 *******************************************************************************
73 */
74 #define SETBIT(a, i)   ((a) |= (1 << (i)))
75 #define CLEARBIT(a, i) ((a) &= ~(1 << (i)))
76 
77 /**
78 *******************************************************************************
79 *! Cabac module expect atlesat MIN_STREAM_SIZE_MB bytes left in stream buffer
80 *! for encoding an MB
81 *******************************************************************************
82 */
83 #define MIN_STREAM_SIZE_MB   1024
84 
85 
86 /*****************************************************************************/
87 /* Function Declarations                                                     */
88 /*****************************************************************************/
89 
90 void ih264e_init_cabac_table(entropy_ctxt_t *ps_ent_ctxt);
91 
92 void ih264e_init_cabac_ctxt(entropy_ctxt_t *ps_ent_ctxt);
93 
94 UWORD32 ih264e_cabac_UEGk0_binarization(WORD16 i2_sufs, WORD8 *pi1_bins_len);
95 
96 void ih264e_get_cabac_context(entropy_ctxt_t *ps_ent_ctxt, WORD32 u4_mb_type);
97 
98 IH264E_ERROR_T ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt);
99 
100 IH264E_ERROR_T ih264e_cabac_put_byte(cabac_ctxt_t *ps_cabac_ctxt);
101 
102 void ih264e_cabac_encode_bin(cabac_ctxt_t *ps_cabac, WORD32 bin,
103                              bin_ctxt_model *pu1_bin_ctxts);
104 
105 void ih264e_encode_decision_bins(UWORD32 u4_bins, WORD8 i1_bins_len,
106                                  UWORD32 u4_ctx_inc, WORD8 i1_valid_len,
107                                  bin_ctxt_model *pu1_bin_ctxt_type,
108                                  cabac_ctxt_t *ps_cabac);
109 
110 void ih264e_cabac_encode_terminate(cabac_ctxt_t *ps_cabac, WORD32 term_bin);
111 
112 void ih264e_cabac_encode_bypass_bin(cabac_ctxt_t *ps_cabac, WORD32 bin);
113 
114 void ih264e_cabac_encode_bypass_bins(cabac_ctxt_t *ps_cabac, UWORD32 u4_bins,
115                                      WORD32 num_bins);
116 
117 IH264E_ERROR_T ih264e_write_islice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt);
118 
119 IH264E_ERROR_T ih264e_write_pslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt);
120 
121 IH264E_ERROR_T ih264e_write_bslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt);
122 
123 #endif /* _IH264E_CABAC_H_ */
124