• 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 
12 #ifndef __INC_BLOCKD_H
13 #define __INC_BLOCKD_H
14 
15 void vpx_log(const char *format, ...);
16 
17 #include "vpx_config.h"
18 #include "vpx_scale/yv12config.h"
19 #include "mv.h"
20 #include "treecoder.h"
21 #include "vpx_ports/mem.h"
22 
23 /*#define DCPRED 1*/
24 #define DCPREDSIMTHRESH 0
25 #define DCPREDCNTTHRESH 3
26 
27 #define MB_FEATURE_TREE_PROBS   3
28 #define MAX_MB_SEGMENTS         4
29 
30 #define MAX_REF_LF_DELTAS       4
31 #define MAX_MODE_LF_DELTAS      4
32 
33 /* Segment Feature Masks */
34 #define SEGMENT_DELTADATA   0
35 #define SEGMENT_ABSDATA     1
36 
37 typedef struct
38 {
39     int r, c;
40 } 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 
48 typedef char ENTROPY_CONTEXT;
49 typedef struct
50 {
51     ENTROPY_CONTEXT y1[4];
52     ENTROPY_CONTEXT u[2];
53     ENTROPY_CONTEXT v[2];
54     ENTROPY_CONTEXT y2;
55 } ENTROPY_CONTEXT_PLANES;
56 
57 extern const unsigned char vp8_block2left[25];
58 extern const unsigned char vp8_block2above[25];
59 
60 #define VP8_COMBINEENTROPYCONTEXTS( Dest, A, B) \
61     Dest = (A)+(B);
62 
63 
64 typedef enum
65 {
66     KEY_FRAME = 0,
67     INTER_FRAME = 1
68 } FRAME_TYPE;
69 
70 typedef enum
71 {
72     DC_PRED,            /* average of above and left pixels */
73     V_PRED,             /* vertical prediction */
74     H_PRED,             /* horizontal prediction */
75     TM_PRED,            /* Truemotion prediction */
76     B_PRED,             /* block based prediction, each block has its own prediction mode */
77 
78     NEARESTMV,
79     NEARMV,
80     ZEROMV,
81     NEWMV,
82     SPLITMV,
83 
84     MB_MODE_COUNT
85 } MB_PREDICTION_MODE;
86 
87 /* Macroblock level features */
88 typedef enum
89 {
90     MB_LVL_ALT_Q = 0,               /* Use alternate Quantizer .... */
91     MB_LVL_ALT_LF = 1,              /* Use alternate loop filter value... */
92     MB_LVL_MAX = 2                  /* Number of MB level features supported */
93 
94 } MB_LVL_FEATURES;
95 
96 /* Segment Feature Masks */
97 #define SEGMENT_ALTQ    0x01
98 #define SEGMENT_ALT_LF  0x02
99 
100 #define VP8_YMODES  (B_PRED + 1)
101 #define VP8_UV_MODES (TM_PRED + 1)
102 
103 #define VP8_MVREFS (1 + SPLITMV - NEARESTMV)
104 
105 typedef enum
106 {
107     B_DC_PRED,          /* average of above and left pixels */
108     B_TM_PRED,
109 
110     B_VE_PRED,           /* vertical prediction */
111     B_HE_PRED,           /* horizontal prediction */
112 
113     B_LD_PRED,
114     B_RD_PRED,
115 
116     B_VR_PRED,
117     B_VL_PRED,
118     B_HD_PRED,
119     B_HU_PRED,
120 
121     LEFT4X4,
122     ABOVE4X4,
123     ZERO4X4,
124     NEW4X4,
125 
126     B_MODE_COUNT
127 } B_PREDICTION_MODE;
128 
129 #define VP8_BINTRAMODES (B_HU_PRED + 1)  /* 10 */
130 #define VP8_SUBMVREFS (1 + NEW4X4 - LEFT4X4)
131 
132 /* For keyframes, intra block modes are predicted by the (already decoded)
133    modes for the Y blocks to the left and above us; for interframes, there
134    is a single probability table. */
135 
136 union b_mode_info
137 {
138     B_PREDICTION_MODE as_mode;
139     int_mv mv;
140 };
141 
142 typedef enum
143 {
144     INTRA_FRAME = 0,
145     LAST_FRAME = 1,
146     GOLDEN_FRAME = 2,
147     ALTREF_FRAME = 3,
148     MAX_REF_FRAMES = 4
149 } MV_REFERENCE_FRAME;
150 
151 typedef struct
152 {
153     uint8_t mode, uv_mode;
154     uint8_t ref_frame;
155     uint8_t is_4x4;
156     int_mv mv;
157 
158     uint8_t partitioning;
159     uint8_t mb_skip_coeff;                                /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */
160     uint8_t need_to_clamp_mvs;
161     uint8_t segment_id;                  /* Which set of segmentation parameters should be used for this MB */
162 } MB_MODE_INFO;
163 
164 typedef struct modeinfo
165 {
166     MB_MODE_INFO mbmi;
167     union b_mode_info bmi[16];
168 } MODE_INFO;
169 
170 #if CONFIG_MULTI_RES_ENCODING
171 /* The mb-level information needed to be stored for higher-resolution encoder */
172 typedef struct
173 {
174     MB_PREDICTION_MODE mode;
175     MV_REFERENCE_FRAME ref_frame;
176     int_mv mv;
177     int dissim;    /* dissimilarity level of the macroblock */
178 } LOWER_RES_MB_INFO;
179 
180 /* The frame-level information needed to be stored for higher-resolution
181  *  encoder */
182 typedef struct
183 {
184     FRAME_TYPE frame_type;
185     int is_frame_dropped;
186     /* The frame number of each reference frames */
187     unsigned int low_res_ref_frames[MAX_REF_FRAMES];
188     LOWER_RES_MB_INFO *mb_info;
189 } LOWER_RES_FRAME_INFO;
190 #endif
191 
192 typedef struct blockd
193 {
194     short *qcoeff;
195     short *dqcoeff;
196     unsigned char  *predictor;
197     short *dequant;
198 
199     int offset;
200     char *eob;
201 
202     union b_mode_info bmi;
203 } BLOCKD;
204 
205 typedef void (*vp8_subpix_fn_t)(unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch);
206 
207 typedef struct macroblockd
208 {
209     DECLARE_ALIGNED(16, unsigned char,  predictor[384]);
210     DECLARE_ALIGNED(16, short, qcoeff[400]);
211     DECLARE_ALIGNED(16, short, dqcoeff[400]);
212     DECLARE_ALIGNED(16, char,  eobs[25]);
213 
214     DECLARE_ALIGNED(16, short,  dequant_y1[16]);
215     DECLARE_ALIGNED(16, short,  dequant_y1_dc[16]);
216     DECLARE_ALIGNED(16, short,  dequant_y2[16]);
217     DECLARE_ALIGNED(16, short,  dequant_uv[16]);
218 
219     /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */
220     BLOCKD block[25];
221     int fullpixel_mask;
222 
223     YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */
224     YV12_BUFFER_CONFIG dst;
225 
226     MODE_INFO *mode_info_context;
227     int mode_info_stride;
228 
229     FRAME_TYPE frame_type;
230 
231     int up_available;
232     int left_available;
233 
234     unsigned char *recon_above[3];
235     unsigned char *recon_left[3];
236     int recon_left_stride[2];
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 
277 
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     int corrupted;
286 
287 #if ARCH_X86 || ARCH_X86_64
288     /* This is an intermediate buffer currently used in sub-pixel motion search
289      * to keep a copy of the reference area. This buffer can be used for other
290      * purpose.
291      */
292     DECLARE_ALIGNED(32, unsigned char, y_buf[22*32]);
293 #endif
294 } MACROBLOCKD;
295 
296 
297 extern void vp8_build_block_doffsets(MACROBLOCKD *x);
298 extern void vp8_setup_block_dptrs(MACROBLOCKD *x);
299 
300 #endif  /* __INC_BLOCKD_H */
301