1 /* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 12 #ifndef __INC_BLOCKD_H 13 #define __INC_BLOCKD_H 14 15 void vpx_log(const char *format, ...); 16 17 #include "vpx_ports/config.h" 18 #include "vpx_scale/yv12config.h" 19 #include "mv.h" 20 #include "treecoder.h" 21 #include "subpixel.h" 22 #include "vpx_ports/mem.h" 23 24 #define TRUE 1 25 #define FALSE 0 26 27 /*#define DCPRED 1*/ 28 #define DCPREDSIMTHRESH 0 29 #define DCPREDCNTTHRESH 3 30 31 #define Y1CONTEXT 0 32 #define UCONTEXT 1 33 #define VCONTEXT 2 34 #define Y2CONTEXT 3 35 36 #define MB_FEATURE_TREE_PROBS 3 37 #define MAX_MB_SEGMENTS 4 38 39 #define MAX_REF_LF_DELTAS 4 40 #define MAX_MODE_LF_DELTAS 4 41 42 /* Segment Feature Masks */ 43 #define SEGMENT_DELTADATA 0 44 #define SEGMENT_ABSDATA 1 45 46 typedef struct 47 { 48 int r, c; 49 } POS; 50 51 52 typedef char ENTROPY_CONTEXT; 53 typedef struct 54 { 55 ENTROPY_CONTEXT y1[4]; 56 ENTROPY_CONTEXT u[2]; 57 ENTROPY_CONTEXT v[2]; 58 ENTROPY_CONTEXT y2; 59 } ENTROPY_CONTEXT_PLANES; 60 61 extern const int vp8_block2type[25]; 62 63 extern const unsigned char vp8_block2left[25]; 64 extern const unsigned char vp8_block2above[25]; 65 66 #define VP8_COMBINEENTROPYCONTEXTS( Dest, A, B) \ 67 Dest = ((A)!=0) + ((B)!=0); 68 69 70 typedef enum 71 { 72 KEY_FRAME = 0, 73 INTER_FRAME = 1 74 } FRAME_TYPE; 75 76 typedef enum 77 { 78 DC_PRED, /* average of above and left pixels */ 79 V_PRED, /* vertical prediction */ 80 H_PRED, /* horizontal prediction */ 81 TM_PRED, /* Truemotion prediction */ 82 B_PRED, /* block based prediction, each block has its own prediction mode */ 83 84 NEARESTMV, 85 NEARMV, 86 ZEROMV, 87 NEWMV, 88 SPLITMV, 89 90 MB_MODE_COUNT 91 } MB_PREDICTION_MODE; 92 93 /* Macroblock level features */ 94 typedef enum 95 { 96 MB_LVL_ALT_Q = 0, /* Use alternate Quantizer .... */ 97 MB_LVL_ALT_LF = 1, /* Use alternate loop filter value... */ 98 MB_LVL_MAX = 2 /* Number of MB level features supported */ 99 100 } MB_LVL_FEATURES; 101 102 /* Segment Feature Masks */ 103 #define SEGMENT_ALTQ 0x01 104 #define SEGMENT_ALT_LF 0x02 105 106 #define VP8_YMODES (B_PRED + 1) 107 #define VP8_UV_MODES (TM_PRED + 1) 108 109 #define VP8_MVREFS (1 + SPLITMV - NEARESTMV) 110 111 typedef enum 112 { 113 B_DC_PRED, /* average of above and left pixels */ 114 B_TM_PRED, 115 116 B_VE_PRED, /* vertical prediction */ 117 B_HE_PRED, /* horizontal prediction */ 118 119 B_LD_PRED, 120 B_RD_PRED, 121 122 B_VR_PRED, 123 B_VL_PRED, 124 B_HD_PRED, 125 B_HU_PRED, 126 127 LEFT4X4, 128 ABOVE4X4, 129 ZERO4X4, 130 NEW4X4, 131 132 B_MODE_COUNT 133 } B_PREDICTION_MODE; 134 135 #define VP8_BINTRAMODES (B_HU_PRED + 1) /* 10 */ 136 #define VP8_SUBMVREFS (1 + NEW4X4 - LEFT4X4) 137 138 /* For keyframes, intra block modes are predicted by the (already decoded) 139 modes for the Y blocks to the left and above us; for interframes, there 140 is a single probability table. */ 141 142 typedef struct 143 { 144 B_PREDICTION_MODE mode; 145 union 146 { 147 int as_int; 148 MV as_mv; 149 } mv; 150 } B_MODE_INFO; 151 152 153 typedef enum 154 { 155 INTRA_FRAME = 0, 156 LAST_FRAME = 1, 157 GOLDEN_FRAME = 2, 158 ALTREF_FRAME = 3, 159 MAX_REF_FRAMES = 4 160 } MV_REFERENCE_FRAME; 161 162 typedef struct 163 { 164 MB_PREDICTION_MODE mode, uv_mode; 165 MV_REFERENCE_FRAME ref_frame; 166 union 167 { 168 int as_int; 169 MV as_mv; 170 } mv; 171 172 unsigned char partitioning; 173 unsigned char mb_skip_coeff; /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */ 174 unsigned char dc_diff; 175 unsigned char need_to_clamp_mvs; 176 177 unsigned char segment_id; /* Which set of segmentation parameters should be used for this MB */ 178 179 unsigned char force_no_skip; /* encoder only */ 180 } MB_MODE_INFO; 181 182 183 typedef struct 184 { 185 MB_MODE_INFO mbmi; 186 B_MODE_INFO bmi[16]; 187 } MODE_INFO; 188 189 190 typedef struct 191 { 192 short *qcoeff; 193 short *dqcoeff; 194 unsigned char *predictor; 195 short *diff; 196 short *reference; 197 198 short *dequant; 199 200 /* 16 Y blocks, 4 U blocks, 4 V blocks each with 16 entries */ 201 unsigned char **base_pre; 202 int pre; 203 int pre_stride; 204 205 unsigned char **base_dst; 206 int dst; 207 int dst_stride; 208 209 int eob; 210 211 B_MODE_INFO bmi; 212 213 } BLOCKD; 214 215 typedef struct 216 { 217 DECLARE_ALIGNED(16, short, diff[400]); /* from idct diff */ 218 DECLARE_ALIGNED(16, unsigned char, predictor[384]); 219 /* not used DECLARE_ALIGNED(16, short, reference[384]); */ 220 DECLARE_ALIGNED(16, short, qcoeff[400]); 221 DECLARE_ALIGNED(16, short, dqcoeff[400]); 222 DECLARE_ALIGNED(16, char, eobs[25]); 223 224 /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */ 225 BLOCKD block[25]; 226 227 YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */ 228 YV12_BUFFER_CONFIG dst; 229 230 MODE_INFO *mode_info_context; 231 int mode_info_stride; 232 233 FRAME_TYPE frame_type; 234 235 int up_available; 236 int left_available; 237 238 /* Y,U,V,Y2 */ 239 ENTROPY_CONTEXT_PLANES *above_context; 240 ENTROPY_CONTEXT_PLANES *left_context; 241 242 /* 0 indicates segmentation at MB level is not enabled. Otherwise the individual bits indicate which features are active. */ 243 unsigned char segmentation_enabled; 244 245 /* 0 (do not update) 1 (update) the macroblock segmentation map. */ 246 unsigned char update_mb_segmentation_map; 247 248 /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */ 249 unsigned char update_mb_segmentation_data; 250 251 /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */ 252 unsigned char mb_segement_abs_delta; 253 254 /* Per frame flags that define which MB level features (such as quantizer or loop filter level) */ 255 /* are enabled and when enabled the proabilities used to decode the per MB flags in MB_MODE_INFO */ 256 vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS]; /* Probability Tree used to code Segment number */ 257 258 signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS]; /* Segment parameters */ 259 260 /* mode_based Loop filter adjustment */ 261 unsigned char mode_ref_lf_delta_enabled; 262 unsigned char mode_ref_lf_delta_update; 263 264 /* Delta values have the range +/- MAX_LOOP_FILTER */ 265 signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */ 266 signed char ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */ 267 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */ 268 signed char mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */ 269 270 /* Distance of MB away from frame edges */ 271 int mb_to_left_edge; 272 int mb_to_right_edge; 273 int mb_to_top_edge; 274 int mb_to_bottom_edge; 275 276 unsigned int frames_since_golden; 277 unsigned int frames_till_alt_ref_frame; 278 vp8_subpix_fn_t subpixel_predict; 279 vp8_subpix_fn_t subpixel_predict8x4; 280 vp8_subpix_fn_t subpixel_predict8x8; 281 vp8_subpix_fn_t subpixel_predict16x16; 282 283 void *current_bc; 284 285 #if CONFIG_RUNTIME_CPU_DETECT 286 struct VP8_COMMON_RTCD *rtcd; 287 #endif 288 } MACROBLOCKD; 289 290 291 extern void vp8_build_block_doffsets(MACROBLOCKD *x); 292 extern void vp8_setup_block_dptrs(MACROBLOCKD *x); 293 294 #endif /* __INC_BLOCKD_H */ 295