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