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