michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #ifndef __INC_BLOCKD_H michael@0: #define __INC_BLOCKD_H michael@0: michael@0: void vpx_log(const char *format, ...); michael@0: michael@0: #include "vpx_config.h" michael@0: #include "vpx_scale/yv12config.h" michael@0: #include "mv.h" michael@0: #include "treecoder.h" michael@0: #include "vpx_ports/mem.h" michael@0: michael@0: /*#define DCPRED 1*/ michael@0: #define DCPREDSIMTHRESH 0 michael@0: #define DCPREDCNTTHRESH 3 michael@0: michael@0: #define MB_FEATURE_TREE_PROBS 3 michael@0: #define MAX_MB_SEGMENTS 4 michael@0: michael@0: #define MAX_REF_LF_DELTAS 4 michael@0: #define MAX_MODE_LF_DELTAS 4 michael@0: michael@0: /* Segment Feature Masks */ michael@0: #define SEGMENT_DELTADATA 0 michael@0: #define SEGMENT_ABSDATA 1 michael@0: michael@0: typedef struct michael@0: { michael@0: int r, c; michael@0: } POS; michael@0: michael@0: #define PLANE_TYPE_Y_NO_DC 0 michael@0: #define PLANE_TYPE_Y2 1 michael@0: #define PLANE_TYPE_UV 2 michael@0: #define PLANE_TYPE_Y_WITH_DC 3 michael@0: michael@0: michael@0: typedef char ENTROPY_CONTEXT; michael@0: typedef struct michael@0: { michael@0: ENTROPY_CONTEXT y1[4]; michael@0: ENTROPY_CONTEXT u[2]; michael@0: ENTROPY_CONTEXT v[2]; michael@0: ENTROPY_CONTEXT y2; michael@0: } ENTROPY_CONTEXT_PLANES; michael@0: michael@0: extern const unsigned char vp8_block2left[25]; michael@0: extern const unsigned char vp8_block2above[25]; michael@0: michael@0: #define VP8_COMBINEENTROPYCONTEXTS( Dest, A, B) \ michael@0: Dest = (A)+(B); michael@0: michael@0: michael@0: typedef enum michael@0: { michael@0: KEY_FRAME = 0, michael@0: INTER_FRAME = 1 michael@0: } FRAME_TYPE; michael@0: michael@0: typedef enum michael@0: { michael@0: DC_PRED, /* average of above and left pixels */ michael@0: V_PRED, /* vertical prediction */ michael@0: H_PRED, /* horizontal prediction */ michael@0: TM_PRED, /* Truemotion prediction */ michael@0: B_PRED, /* block based prediction, each block has its own prediction mode */ michael@0: michael@0: NEARESTMV, michael@0: NEARMV, michael@0: ZEROMV, michael@0: NEWMV, michael@0: SPLITMV, michael@0: michael@0: MB_MODE_COUNT michael@0: } MB_PREDICTION_MODE; michael@0: michael@0: /* Macroblock level features */ michael@0: typedef enum michael@0: { michael@0: MB_LVL_ALT_Q = 0, /* Use alternate Quantizer .... */ michael@0: MB_LVL_ALT_LF = 1, /* Use alternate loop filter value... */ michael@0: MB_LVL_MAX = 2 /* Number of MB level features supported */ michael@0: michael@0: } MB_LVL_FEATURES; michael@0: michael@0: /* Segment Feature Masks */ michael@0: #define SEGMENT_ALTQ 0x01 michael@0: #define SEGMENT_ALT_LF 0x02 michael@0: michael@0: #define VP8_YMODES (B_PRED + 1) michael@0: #define VP8_UV_MODES (TM_PRED + 1) michael@0: michael@0: #define VP8_MVREFS (1 + SPLITMV - NEARESTMV) michael@0: michael@0: typedef enum michael@0: { michael@0: B_DC_PRED, /* average of above and left pixels */ michael@0: B_TM_PRED, michael@0: michael@0: B_VE_PRED, /* vertical prediction */ michael@0: B_HE_PRED, /* horizontal prediction */ michael@0: michael@0: B_LD_PRED, michael@0: B_RD_PRED, michael@0: michael@0: B_VR_PRED, michael@0: B_VL_PRED, michael@0: B_HD_PRED, michael@0: B_HU_PRED, michael@0: michael@0: LEFT4X4, michael@0: ABOVE4X4, michael@0: ZERO4X4, michael@0: NEW4X4, michael@0: michael@0: B_MODE_COUNT michael@0: } B_PREDICTION_MODE; michael@0: michael@0: #define VP8_BINTRAMODES (B_HU_PRED + 1) /* 10 */ michael@0: #define VP8_SUBMVREFS (1 + NEW4X4 - LEFT4X4) michael@0: michael@0: /* For keyframes, intra block modes are predicted by the (already decoded) michael@0: modes for the Y blocks to the left and above us; for interframes, there michael@0: is a single probability table. */ michael@0: michael@0: union b_mode_info michael@0: { michael@0: B_PREDICTION_MODE as_mode; michael@0: int_mv mv; michael@0: }; michael@0: michael@0: typedef enum michael@0: { michael@0: INTRA_FRAME = 0, michael@0: LAST_FRAME = 1, michael@0: GOLDEN_FRAME = 2, michael@0: ALTREF_FRAME = 3, michael@0: MAX_REF_FRAMES = 4 michael@0: } MV_REFERENCE_FRAME; michael@0: michael@0: typedef struct michael@0: { michael@0: uint8_t mode, uv_mode; michael@0: uint8_t ref_frame; michael@0: uint8_t is_4x4; michael@0: int_mv mv; michael@0: michael@0: uint8_t partitioning; michael@0: uint8_t mb_skip_coeff; /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */ michael@0: uint8_t need_to_clamp_mvs; michael@0: uint8_t segment_id; /* Which set of segmentation parameters should be used for this MB */ michael@0: } MB_MODE_INFO; michael@0: michael@0: typedef struct modeinfo michael@0: { michael@0: MB_MODE_INFO mbmi; michael@0: union b_mode_info bmi[16]; michael@0: } MODE_INFO; michael@0: michael@0: #if CONFIG_MULTI_RES_ENCODING michael@0: /* The mb-level information needed to be stored for higher-resolution encoder */ michael@0: typedef struct michael@0: { michael@0: MB_PREDICTION_MODE mode; michael@0: MV_REFERENCE_FRAME ref_frame; michael@0: int_mv mv; michael@0: int dissim; /* dissimilarity level of the macroblock */ michael@0: } LOWER_RES_MB_INFO; michael@0: michael@0: /* The frame-level information needed to be stored for higher-resolution michael@0: * encoder */ michael@0: typedef struct michael@0: { michael@0: FRAME_TYPE frame_type; michael@0: int is_frame_dropped; michael@0: /* The frame number of each reference frames */ michael@0: unsigned int low_res_ref_frames[MAX_REF_FRAMES]; michael@0: LOWER_RES_MB_INFO *mb_info; michael@0: } LOWER_RES_FRAME_INFO; michael@0: #endif michael@0: michael@0: typedef struct blockd michael@0: { michael@0: short *qcoeff; michael@0: short *dqcoeff; michael@0: unsigned char *predictor; michael@0: short *dequant; michael@0: michael@0: int offset; michael@0: char *eob; michael@0: michael@0: union b_mode_info bmi; michael@0: } BLOCKD; michael@0: michael@0: typedef void (*vp8_subpix_fn_t)(unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch); michael@0: michael@0: typedef struct macroblockd michael@0: { michael@0: DECLARE_ALIGNED(16, unsigned char, predictor[384]); michael@0: DECLARE_ALIGNED(16, short, qcoeff[400]); michael@0: DECLARE_ALIGNED(16, short, dqcoeff[400]); michael@0: DECLARE_ALIGNED(16, char, eobs[25]); michael@0: michael@0: DECLARE_ALIGNED(16, short, dequant_y1[16]); michael@0: DECLARE_ALIGNED(16, short, dequant_y1_dc[16]); michael@0: DECLARE_ALIGNED(16, short, dequant_y2[16]); michael@0: DECLARE_ALIGNED(16, short, dequant_uv[16]); michael@0: michael@0: /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */ michael@0: BLOCKD block[25]; michael@0: int fullpixel_mask; michael@0: michael@0: YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */ michael@0: YV12_BUFFER_CONFIG dst; michael@0: michael@0: MODE_INFO *mode_info_context; michael@0: int mode_info_stride; michael@0: michael@0: FRAME_TYPE frame_type; michael@0: michael@0: int up_available; michael@0: int left_available; michael@0: michael@0: unsigned char *recon_above[3]; michael@0: unsigned char *recon_left[3]; michael@0: int recon_left_stride[2]; michael@0: michael@0: /* Y,U,V,Y2 */ michael@0: ENTROPY_CONTEXT_PLANES *above_context; michael@0: ENTROPY_CONTEXT_PLANES *left_context; michael@0: michael@0: /* 0 indicates segmentation at MB level is not enabled. Otherwise the individual bits indicate which features are active. */ michael@0: unsigned char segmentation_enabled; michael@0: michael@0: /* 0 (do not update) 1 (update) the macroblock segmentation map. */ michael@0: unsigned char update_mb_segmentation_map; michael@0: michael@0: /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */ michael@0: unsigned char update_mb_segmentation_data; michael@0: michael@0: /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */ michael@0: unsigned char mb_segement_abs_delta; michael@0: michael@0: /* Per frame flags that define which MB level features (such as quantizer or loop filter level) */ michael@0: /* are enabled and when enabled the proabilities used to decode the per MB flags in MB_MODE_INFO */ michael@0: vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS]; /* Probability Tree used to code Segment number */ michael@0: michael@0: signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS]; /* Segment parameters */ michael@0: michael@0: /* mode_based Loop filter adjustment */ michael@0: unsigned char mode_ref_lf_delta_enabled; michael@0: unsigned char mode_ref_lf_delta_update; michael@0: michael@0: /* Delta values have the range +/- MAX_LOOP_FILTER */ michael@0: signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */ michael@0: signed char ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */ michael@0: signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */ michael@0: signed char mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */ michael@0: michael@0: /* Distance of MB away from frame edges */ michael@0: int mb_to_left_edge; michael@0: int mb_to_right_edge; michael@0: int mb_to_top_edge; michael@0: int mb_to_bottom_edge; michael@0: michael@0: michael@0: michael@0: vp8_subpix_fn_t subpixel_predict; michael@0: vp8_subpix_fn_t subpixel_predict8x4; michael@0: vp8_subpix_fn_t subpixel_predict8x8; michael@0: vp8_subpix_fn_t subpixel_predict16x16; michael@0: michael@0: void *current_bc; michael@0: michael@0: int corrupted; michael@0: michael@0: #if ARCH_X86 || ARCH_X86_64 michael@0: /* This is an intermediate buffer currently used in sub-pixel motion search michael@0: * to keep a copy of the reference area. This buffer can be used for other michael@0: * purpose. michael@0: */ michael@0: DECLARE_ALIGNED(32, unsigned char, y_buf[22*32]); michael@0: #endif michael@0: } MACROBLOCKD; michael@0: michael@0: michael@0: extern void vp8_build_block_doffsets(MACROBLOCKD *x); michael@0: extern void vp8_setup_block_dptrs(MACROBLOCKD *x); michael@0: michael@0: #endif /* __INC_BLOCKD_H */