xref: /aosp_15_r20/external/libavc/encoder/ih264e_cabac_structs.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1*495ae853SAndroid Build Coastguard Worker /******************************************************************************
2*495ae853SAndroid Build Coastguard Worker  *
3*495ae853SAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
4*495ae853SAndroid Build Coastguard Worker  *
5*495ae853SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*495ae853SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*495ae853SAndroid Build Coastguard Worker  * You may obtain a copy of the License at:
8*495ae853SAndroid Build Coastguard Worker  *
9*495ae853SAndroid Build Coastguard Worker  * http://www.apache.org/licenses/LICENSE-2.0
10*495ae853SAndroid Build Coastguard Worker  *
11*495ae853SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*495ae853SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*495ae853SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*495ae853SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*495ae853SAndroid Build Coastguard Worker  * limitations under the License.
16*495ae853SAndroid Build Coastguard Worker  *
17*495ae853SAndroid Build Coastguard Worker  *****************************************************************************
18*495ae853SAndroid Build Coastguard Worker  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*495ae853SAndroid Build Coastguard Worker */
20*495ae853SAndroid Build Coastguard Worker 
21*495ae853SAndroid Build Coastguard Worker /**
22*495ae853SAndroid Build Coastguard Worker *******************************************************************************
23*495ae853SAndroid Build Coastguard Worker * @file
24*495ae853SAndroid Build Coastguard Worker *  ih264e_cabac_structs.h
25*495ae853SAndroid Build Coastguard Worker *
26*495ae853SAndroid Build Coastguard Worker * @brief
27*495ae853SAndroid Build Coastguard Worker *  This file contains structure definitions necessary for cabac encoding
28*495ae853SAndroid Build Coastguard Worker *
29*495ae853SAndroid Build Coastguard Worker * @author
30*495ae853SAndroid Build Coastguard Worker *  ittiam
31*495ae853SAndroid Build Coastguard Worker *
32*495ae853SAndroid Build Coastguard Worker * @remarks
33*495ae853SAndroid Build Coastguard Worker *  none
34*495ae853SAndroid Build Coastguard Worker *
35*495ae853SAndroid Build Coastguard Worker *******************************************************************************
36*495ae853SAndroid Build Coastguard Worker */
37*495ae853SAndroid Build Coastguard Worker 
38*495ae853SAndroid Build Coastguard Worker #ifndef _IH264E_CABAC_STRUCTS_H_
39*495ae853SAndroid Build Coastguard Worker #define _IH264E_CABAC_STRUCTS_H_
40*495ae853SAndroid Build Coastguard Worker 
41*495ae853SAndroid Build Coastguard Worker 
42*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
43*495ae853SAndroid Build Coastguard Worker /* Constant Macros                                                           */
44*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
45*495ae853SAndroid Build Coastguard Worker 
46*495ae853SAndroid Build Coastguard Worker #define CABAC_INIT_IDC 2
47*495ae853SAndroid Build Coastguard Worker 
48*495ae853SAndroid Build Coastguard Worker 
49*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
50*495ae853SAndroid Build Coastguard Worker /* Structures                                                                */
51*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
52*495ae853SAndroid Build Coastguard Worker 
53*495ae853SAndroid Build Coastguard Worker /**
54*495ae853SAndroid Build Coastguard Worker *******************************************************************************
55*495ae853SAndroid Build Coastguard Worker *  @brief     typedef for  context model
56*495ae853SAndroid Build Coastguard Worker *******************************************************************************
57*495ae853SAndroid Build Coastguard Worker */
58*495ae853SAndroid Build Coastguard Worker 
59*495ae853SAndroid Build Coastguard Worker /* bits 0 to 5 :state
60*495ae853SAndroid Build Coastguard Worker    bit 6       :mps */
61*495ae853SAndroid Build Coastguard Worker typedef UWORD8 bin_ctxt_model;
62*495ae853SAndroid Build Coastguard Worker 
63*495ae853SAndroid Build Coastguard Worker /**
64*495ae853SAndroid Build Coastguard Worker *******************************************************************************
65*495ae853SAndroid Build Coastguard Worker *  @brief      MB info for cabac
66*495ae853SAndroid Build Coastguard Worker *******************************************************************************
67*495ae853SAndroid Build Coastguard Worker */
68*495ae853SAndroid Build Coastguard Worker typedef struct
69*495ae853SAndroid Build Coastguard Worker {
70*495ae853SAndroid Build Coastguard Worker     /* Neighbour availability Variables needed to get CtxtInc, for CABAC */
71*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_mb_type; /* !< macroblock type: I/P/B/SI/SP */
72*495ae853SAndroid Build Coastguard Worker 
73*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_cbp; /* !< Coded Block Pattern */
74*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_intrapred_chroma_mode;
75*495ae853SAndroid Build Coastguard Worker 
76*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
77*495ae853SAndroid Build Coastguard Worker     /*               Arrangnment of AC CSBP                                  */
78*495ae853SAndroid Build Coastguard Worker     /*        bits:  b7 b6 b5 b4 b3 b2 b1 b0                                 */
79*495ae853SAndroid Build Coastguard Worker     /*        CSBP:  V1 V0 U1 U0 Y3 Y2 Y1 Y0                                 */
80*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
81*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_yuv_ac_csbp;
82*495ae853SAndroid Build Coastguard Worker 
83*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
84*495ae853SAndroid Build Coastguard Worker     /*               Arrangnment of DC CSBP                                  */
85*495ae853SAndroid Build Coastguard Worker     /*        bits:  b7  b6  b5  b4  b3  b2  b1  b0                          */
86*495ae853SAndroid Build Coastguard Worker     /*        CSBP:   x   x   x   x   x  Vdc Udc Ydc                         */
87*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
88*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_yuv_dc_csbp;
89*495ae853SAndroid Build Coastguard Worker 
90*495ae853SAndroid Build Coastguard Worker     WORD8 i1_ref_idx[4];
91*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_mv[4][4];
92*495ae853SAndroid Build Coastguard Worker 
93*495ae853SAndroid Build Coastguard Worker } mb_info_ctxt_t;
94*495ae853SAndroid Build Coastguard Worker 
95*495ae853SAndroid Build Coastguard Worker 
96*495ae853SAndroid Build Coastguard Worker /**
97*495ae853SAndroid Build Coastguard Worker *******************************************************************************
98*495ae853SAndroid Build Coastguard Worker *  @brief      CSBP info for CABAC
99*495ae853SAndroid Build Coastguard Worker *******************************************************************************
100*495ae853SAndroid Build Coastguard Worker */
101*495ae853SAndroid Build Coastguard Worker typedef struct
102*495ae853SAndroid Build Coastguard Worker {
103*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
104*495ae853SAndroid Build Coastguard Worker     /*               Arrangnment of Luma AC CSBP for leftMb                  */
105*495ae853SAndroid Build Coastguard Worker     /*        bits:  b7 b6 b5 b4 b3 b2 b1 b0                                 */
106*495ae853SAndroid Build Coastguard Worker     /*        CSBP:   X  X  X  X Y3 Y2 Y1 Y0                                 */
107*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
108*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
109*495ae853SAndroid Build Coastguard Worker     /*  Points either to u1_y_ac_csbp_top_mb or  u1_y_ac_csbp_bot_mb         */
110*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
111*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_y_ac_csbp_top_mb;
112*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_y_ac_csbp_bot_mb;
113*495ae853SAndroid Build Coastguard Worker 
114*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
115*495ae853SAndroid Build Coastguard Worker     /*               Arrangnment of Chroma AC CSBP for leftMb                */
116*495ae853SAndroid Build Coastguard Worker     /*        bits:  b7 b6 b5 b4 b3 b2 b1 b0                                 */
117*495ae853SAndroid Build Coastguard Worker     /*        CSBP:   X  X  X  X V1 V0 U1 U0                                 */
118*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
119*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
120*495ae853SAndroid Build Coastguard Worker     /*  Points either to u1_uv_ac_csbp_top_mb or  u1_uv_ac_csbp_bot_mb       */
121*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
122*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_uv_ac_csbp_top_mb;
123*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_uv_ac_csbp_bot_mb;
124*495ae853SAndroid Build Coastguard Worker 
125*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
126*495ae853SAndroid Build Coastguard Worker     /*               Arrangnment of DC CSBP                                  */
127*495ae853SAndroid Build Coastguard Worker     /*        bits:  b7  b6  b5  b4  b3  b2  b1  b0                          */
128*495ae853SAndroid Build Coastguard Worker     /*        CSBP:   x   x   x   x   x  Vdc Udc Ydc                         */
129*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
130*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
131*495ae853SAndroid Build Coastguard Worker     /*  Points either to u1_yuv_dc_csbp_top_mb or  u1_yuv_dc_csbp_bot_mb     */
132*495ae853SAndroid Build Coastguard Worker     /*************************************************************************/
133*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_yuv_dc_csbp_top_mb;
134*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_yuv_dc_csbp_bot_mb;
135*495ae853SAndroid Build Coastguard Worker 
136*495ae853SAndroid Build Coastguard Worker } cab_csbp_t;
137*495ae853SAndroid Build Coastguard Worker 
138*495ae853SAndroid Build Coastguard Worker /**
139*495ae853SAndroid Build Coastguard Worker *******************************************************************************
140*495ae853SAndroid Build Coastguard Worker *  @brief      CABAC Encoding Environment
141*495ae853SAndroid Build Coastguard Worker *******************************************************************************
142*495ae853SAndroid Build Coastguard Worker */
143*495ae853SAndroid Build Coastguard Worker typedef struct
144*495ae853SAndroid Build Coastguard Worker {
145*495ae853SAndroid Build Coastguard Worker     /**
146*495ae853SAndroid Build Coastguard Worker      * cabac interval start L
147*495ae853SAndroid Build Coastguard Worker      */
148*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_code_int_low;
149*495ae853SAndroid Build Coastguard Worker 
150*495ae853SAndroid Build Coastguard Worker     /**
151*495ae853SAndroid Build Coastguard Worker      * cabac interval range R
152*495ae853SAndroid Build Coastguard Worker      */
153*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_code_int_range;
154*495ae853SAndroid Build Coastguard Worker 
155*495ae853SAndroid Build Coastguard Worker     /** bytes_outsanding; number of 0xFF bits that occur during renorm
156*495ae853SAndroid Build Coastguard Worker      *  These  will be accumulated till the carry bit is knwon
157*495ae853SAndroid Build Coastguard Worker      */
158*495ae853SAndroid Build Coastguard Worker     UWORD32  u4_out_standing_bytes;
159*495ae853SAndroid Build Coastguard Worker 
160*495ae853SAndroid Build Coastguard Worker     /** bits generated during renormalization
161*495ae853SAndroid Build Coastguard Worker      *   A byte is put to stream/u4_out_standing_bytes from u4_low(L) when
162*495ae853SAndroid Build Coastguard Worker      *   u4_bits_gen exceeds 8
163*495ae853SAndroid Build Coastguard Worker      */
164*495ae853SAndroid Build Coastguard Worker     UWORD32  u4_bits_gen;
165*495ae853SAndroid Build Coastguard Worker 
166*495ae853SAndroid Build Coastguard Worker } encoding_envirnoment_t;
167*495ae853SAndroid Build Coastguard Worker 
168*495ae853SAndroid Build Coastguard Worker 
169*495ae853SAndroid Build Coastguard Worker /**
170*495ae853SAndroid Build Coastguard Worker *******************************************************************************
171*495ae853SAndroid Build Coastguard Worker *  @brief      CABAC Context structure : Variables to handle Cabac
172*495ae853SAndroid Build Coastguard Worker *******************************************************************************
173*495ae853SAndroid Build Coastguard Worker */
174*495ae853SAndroid Build Coastguard Worker typedef struct
175*495ae853SAndroid Build Coastguard Worker {
176*495ae853SAndroid Build Coastguard Worker 
177*495ae853SAndroid Build Coastguard Worker     /**
178*495ae853SAndroid Build Coastguard Worker      * Base pointer to all the cabac contexts
179*495ae853SAndroid Build Coastguard Worker      */
180*495ae853SAndroid Build Coastguard Worker     bin_ctxt_model au1_cabac_ctxt_table[NUM_CABAC_CTXTS];
181*495ae853SAndroid Build Coastguard Worker 
182*495ae853SAndroid Build Coastguard Worker     /**
183*495ae853SAndroid Build Coastguard Worker      * left csbp
184*495ae853SAndroid Build Coastguard Worker      */
185*495ae853SAndroid Build Coastguard Worker     cab_csbp_t s_lft_csbp;
186*495ae853SAndroid Build Coastguard Worker 
187*495ae853SAndroid Build Coastguard Worker     /**
188*495ae853SAndroid Build Coastguard Worker      * pointer to Bitstream structure
189*495ae853SAndroid Build Coastguard Worker      */
190*495ae853SAndroid Build Coastguard Worker     bitstrm_t *ps_bitstrm;
191*495ae853SAndroid Build Coastguard Worker 
192*495ae853SAndroid Build Coastguard Worker     /**
193*495ae853SAndroid Build Coastguard Worker      * Pointer to mb_info_ctxt_t map_base
194*495ae853SAndroid Build Coastguard Worker      */
195*495ae853SAndroid Build Coastguard Worker     mb_info_ctxt_t *ps_mb_map_ctxt_inc_base;
196*495ae853SAndroid Build Coastguard Worker 
197*495ae853SAndroid Build Coastguard Worker     /**
198*495ae853SAndroid Build Coastguard Worker      * Pointer to encoding_envirnoment_t
199*495ae853SAndroid Build Coastguard Worker      */
200*495ae853SAndroid Build Coastguard Worker     encoding_envirnoment_t s_cab_enc_env;
201*495ae853SAndroid Build Coastguard Worker 
202*495ae853SAndroid Build Coastguard Worker     /* These things need to be updated at each MbLevel */
203*495ae853SAndroid Build Coastguard Worker     /**
204*495ae853SAndroid Build Coastguard Worker      * Prev mb_qp_delta_ctxt
205*495ae853SAndroid Build Coastguard Worker      */
206*495ae853SAndroid Build Coastguard Worker     WORD8 i1_prev_mb_qp_delta_ctxt;
207*495ae853SAndroid Build Coastguard Worker 
208*495ae853SAndroid Build Coastguard Worker     /**
209*495ae853SAndroid Build Coastguard Worker      * Pointer to mb_info_ctxt_t map
210*495ae853SAndroid Build Coastguard Worker      */
211*495ae853SAndroid Build Coastguard Worker     mb_info_ctxt_t *ps_mb_map_ctxt_inc;
212*495ae853SAndroid Build Coastguard Worker 
213*495ae853SAndroid Build Coastguard Worker     /**
214*495ae853SAndroid Build Coastguard Worker      * Pointer to default mb_info_ctxt_t
215*495ae853SAndroid Build Coastguard Worker      */
216*495ae853SAndroid Build Coastguard Worker     mb_info_ctxt_t *ps_def_ctxt_mb_info;
217*495ae853SAndroid Build Coastguard Worker 
218*495ae853SAndroid Build Coastguard Worker     /**
219*495ae853SAndroid Build Coastguard Worker      * Pointer to current mb_info_ctxt_t
220*495ae853SAndroid Build Coastguard Worker      */
221*495ae853SAndroid Build Coastguard Worker     mb_info_ctxt_t *ps_curr_ctxt_mb_info;
222*495ae853SAndroid Build Coastguard Worker 
223*495ae853SAndroid Build Coastguard Worker     /**
224*495ae853SAndroid Build Coastguard Worker      * Pointer to left mb_info_ctxt_t
225*495ae853SAndroid Build Coastguard Worker      */
226*495ae853SAndroid Build Coastguard Worker     mb_info_ctxt_t *ps_left_ctxt_mb_info;
227*495ae853SAndroid Build Coastguard Worker 
228*495ae853SAndroid Build Coastguard Worker     /**
229*495ae853SAndroid Build Coastguard Worker      * Pointer to top mb_info_ctxt_t
230*495ae853SAndroid Build Coastguard Worker      */
231*495ae853SAndroid Build Coastguard Worker     mb_info_ctxt_t *ps_top_ctxt_mb_info;
232*495ae853SAndroid Build Coastguard Worker 
233*495ae853SAndroid Build Coastguard Worker     /**
234*495ae853SAndroid Build Coastguard Worker      * Pointer to csbp structures
235*495ae853SAndroid Build Coastguard Worker      */
236*495ae853SAndroid Build Coastguard Worker     cab_csbp_t *ps_lft_csbp;
237*495ae853SAndroid Build Coastguard Worker     UWORD8 *pu1_left_y_ac_csbp;
238*495ae853SAndroid Build Coastguard Worker     UWORD8 *pu1_left_uv_ac_csbp;
239*495ae853SAndroid Build Coastguard Worker     UWORD8 *pu1_left_yuv_dc_csbp;
240*495ae853SAndroid Build Coastguard Worker 
241*495ae853SAndroid Build Coastguard Worker     /**************************************************************************/
242*495ae853SAndroid Build Coastguard Worker     /*       Ref_idx contexts  are stored in the following way                */
243*495ae853SAndroid Build Coastguard Worker     /*  Array Idx 0,1 for reference indices in Forward direction              */
244*495ae853SAndroid Build Coastguard Worker     /*  Array Idx 2,3 for reference indices in backward direction             */
245*495ae853SAndroid Build Coastguard Worker     /**************************************************************************/
246*495ae853SAndroid Build Coastguard Worker     /**
247*495ae853SAndroid Build Coastguard Worker      * Dimensions for u1_left_ref_ctxt_inc_arr is [2][4] for Mbaff:Top and Bot
248*495ae853SAndroid Build Coastguard Worker      */
249*495ae853SAndroid Build Coastguard Worker     WORD8 i1_left_ref_idx_ctx_inc_arr[2][4];
250*495ae853SAndroid Build Coastguard Worker     WORD8 *pi1_left_ref_idx_ctxt_inc;
251*495ae853SAndroid Build Coastguard Worker 
252*495ae853SAndroid Build Coastguard Worker     /**
253*495ae853SAndroid Build Coastguard Worker      * Dimensions for u1_left_mv_ctxt_inc_arr is [2][4][4] for Mbaff case
254*495ae853SAndroid Build Coastguard Worker      */
255*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_left_mv_ctxt_inc_arr[2][4][4];
256*495ae853SAndroid Build Coastguard Worker     UWORD8 (*pu1_left_mv_ctxt_inc)[4];
257*495ae853SAndroid Build Coastguard Worker 
258*495ae853SAndroid Build Coastguard Worker } cabac_ctxt_t;
259*495ae853SAndroid Build Coastguard Worker 
260*495ae853SAndroid Build Coastguard Worker #endif /* _IH264E_CABAC_STRUCTS_H_ */
261