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