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_structs.h
25  *
26  * @brief
27  *  This file contains cabac related structure definitions.
28  *
29  * @author
30  *  Doney Alex
31  *
32  * @remarks
33  *  none
34  *
35  *******************************************************************************
36  */
37 
38 #ifndef IH264E_CABAC_STRUCTS_H_
39 #define IH264E_CABAC_STRUCTS_H_
40 
41 
42 
43 #define CABAC_INIT_IDC 2
44 
45 
46 /**
47  ******************************************************************************
48  *  @brief     typedef for  context model
49  ******************************************************************************
50  */
51 
52 /* bits 0 to 5 :state
53    bit 6       :mps */
54 typedef UWORD8 bin_ctxt_model;
55 
56 /**
57  ******************************************************************************
58  *  @brief      MB info for cabac
59  ******************************************************************************
60  */
61 typedef struct
62 {
63     /* Neighbour availability Variables needed to get CtxtInc, for CABAC */
64     UWORD8 u1_mb_type; /* !< macroblock type: I/P/B/SI/SP */
65 
66     UWORD8 u1_cbp; /* !< Coded Block Pattern */
67     UWORD8 u1_intrapred_chroma_mode;
68 
69     /*************************************************************************/
70     /*               Arrangnment of AC CSBP                                  */
71     /*        bits:  b7 b6 b5 b4 b3 b2 b1 b0                                 */
72     /*        CSBP:  V1 V0 U1 U0 Y3 Y2 Y1 Y0                                 */
73     /*************************************************************************/
74     UWORD8 u1_yuv_ac_csbp;
75     /*************************************************************************/
76     /*               Arrangnment of DC CSBP                                  */
77     /*        bits:  b7  b6  b5  b4  b3  b2  b1  b0                          */
78     /*        CSBP:   x   x   x   x   x  Vdc Udc Ydc                         */
79     /*************************************************************************/
80     UWORD8 u1_yuv_dc_csbp;
81 
82     WORD8 i1_ref_idx[4];
83     UWORD8 u1_mv[4][4];
84 } mb_info_ctxt_t;
85 
86 
87 /**
88  ******************************************************************************
89  *  @brief      CSBP info for CABAC
90  ******************************************************************************
91  */
92 typedef struct
93 {
94     /*************************************************************************/
95     /*               Arrangnment of Luma AC CSBP for leftMb                  */
96     /*        bits:  b7 b6 b5 b4 b3 b2 b1 b0                                 */
97     /*        CSBP:   X  X  X  X Y3 Y2 Y1 Y0                                 */
98     /*************************************************************************/
99     /*************************************************************************/
100     /*  Points either to u1_y_ac_csbp_top_mb or  u1_y_ac_csbp_bot_mb         */
101     /*************************************************************************/
102     UWORD8 u1_y_ac_csbp_top_mb;
103     UWORD8 u1_y_ac_csbp_bot_mb;
104 
105     /*************************************************************************/
106     /*               Arrangnment of Chroma AC CSBP for leftMb                */
107     /*        bits:  b7 b6 b5 b4 b3 b2 b1 b0                                 */
108     /*        CSBP:   X  X  X  X V1 V0 U1 U0                                 */
109     /*************************************************************************/
110     /*************************************************************************/
111     /*  Points either to u1_uv_ac_csbp_top_mb or  u1_uv_ac_csbp_bot_mb       */
112     /*************************************************************************/
113     UWORD8 u1_uv_ac_csbp_top_mb;
114     UWORD8 u1_uv_ac_csbp_bot_mb;
115 
116     /*************************************************************************/
117     /*               Arrangnment of DC CSBP                                  */
118     /*        bits:  b7  b6  b5  b4  b3  b2  b1  b0                          */
119     /*        CSBP:   x   x   x   x   x  Vdc Udc Ydc                         */
120     /*************************************************************************/
121     /*************************************************************************/
122     /*  Points either to u1_yuv_dc_csbp_top_mb or  u1_yuv_dc_csbp_bot_mb     */
123     /*************************************************************************/
124     UWORD8 u1_yuv_dc_csbp_top_mb;
125     UWORD8 u1_yuv_dc_csbp_bot_mb;
126 } cab_csbp_t;
127 
128 /**
129  ******************************************************************************
130  *  @brief      CABAC Encoding Environment
131  ******************************************************************************
132  */
133 
134 typedef struct
135 {
136     /** cabac interval start L  */
137     UWORD32 u4_code_int_low;
138 
139     /** cabac interval range R  */
140     UWORD32 u4_code_int_range;
141 
142     /** bytes_outsanding; number of 0xFF bits that occur during renorm
143     *  These  will be accumulated till the carry bit is knwon
144     */
145     UWORD32  u4_out_standing_bytes;
146 
147     /** bits generated during renormalization
148     *   A byte is put to stream/u4_out_standing_bytes from u4_low(L) when
149     *   u4_bits_gen exceeds 8
150     */
151     UWORD32  u4_bits_gen;
152 } encoding_envirnoment_t;
153 
154 
155 /**
156  ******************************************************************************
157  *  @brief      CABAC Context structure : Variables to handle Cabac
158  ******************************************************************************
159  */
160 typedef struct
161 {
162 
163     /*  Base pointer to all the cabac contexts  */
164     bin_ctxt_model au1_cabac_ctxt_table[NUM_CABAC_CTXTS];
165 
166 
167     cab_csbp_t s_lft_csbp;
168 
169     /**
170      * pointer to Bitstream structure
171      */
172     bitstrm_t *ps_bitstrm;
173 
174     /* Pointer to mb_info_ctxt_t map_base */
175     mb_info_ctxt_t *ps_mb_map_ctxt_inc_base;
176 
177     /* Pointer to encoding_envirnoment_t */
178     encoding_envirnoment_t s_cab_enc_env;
179 
180     /* These things need to be updated at each MbLevel */
181 
182     /* Prev ps_mb_qp_delta_ctxt */
183     WORD8 i1_prevps_mb_qp_delta_ctxt;
184 
185     /* Pointer to mb_info_ctxt_t map */
186     mb_info_ctxt_t *ps_mb_map_ctxt_inc;
187 
188     /* Pointer to default mb_info_ctxt_t */
189     mb_info_ctxt_t *ps_def_ctxt_mb_info;
190 
191     /* Pointer to current mb_info_ctxt_t */
192     mb_info_ctxt_t *ps_curr_ctxt_mb_info;
193 
194     /* Pointer to left mb_info_ctxt_t */
195     mb_info_ctxt_t *ps_left_ctxt_mb_info;
196 
197     /* Pointer to top mb_info_ctxt_t  */
198     mb_info_ctxt_t *ps_top_ctxt_mb_info;
199 
200     /* Poniter to left csbp structure */
201     cab_csbp_t *ps_lft_csbp;
202     UWORD8 *pu1_left_y_ac_csbp;
203     UWORD8 *pu1_left_uv_ac_csbp;
204     UWORD8 *pu1_left_yuv_dc_csbp;
205 
206     /***************************************************************************/
207     /*       Ref_idx contexts  are stored in the following way                 */
208     /*  Array Idx 0,1 for reference indices in Forward direction               */
209     /*  Array Idx 2,3 for reference indices in backward direction              */
210     /***************************************************************************/
211     /* Dimensions for u1_left_ref_ctxt_inc_arr is [2][4] for Mbaff:Top and Bot */
212     WORD8 i1_left_ref_idx_ctx_inc_arr[2][4];
213     WORD8 *pi1_left_ref_idx_ctxt_inc;
214 
215     /* Dimensions for u1_left_mv_ctxt_inc_arr is [2][4][4] for Mbaff case */
216     UWORD8 u1_left_mv_ctxt_inc_arr[2][4][4];
217     UWORD8 (*pu1_left_mv_ctxt_inc)[4];
218 
219 } cabac_ctxt_t;
220 
221 #endif /* IH264E_CABAC_STRUCTS_H_ */
222