]> granicus.if.org Git - libvpx/blob - vp9/encoder/vp9_rd.h
Short circuit flat blocks when coding screen content at realtime speed.
[libvpx] / vp9 / encoder / vp9_rd.h
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 VP9_ENCODER_VP9_RD_H_
12 #define VP9_ENCODER_VP9_RD_H_
13
14 #include <limits.h>
15
16 #include "vp9/common/vp9_blockd.h"
17
18 #include "vp9/encoder/vp9_block.h"
19 #include "vp9/encoder/vp9_context_tree.h"
20 #include "vp9/encoder/vp9_cost.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #define RDDIV_BITS          7
27
28 #define RDCOST(RM, DM, R, D) \
29   (ROUND_POWER_OF_TWO(((int64_t)R) * (RM), VP9_PROB_COST_SHIFT) + (D << DM))
30 #define QIDX_SKIP_THRESH     115
31
32 #define MV_COST_WEIGHT      108
33 #define MV_COST_WEIGHT_SUB  120
34
35 #define INVALID_MV 0x80008000
36
37 #define MAX_MODES 30
38 #define MAX_REFS  6
39
40 #define RD_THRESH_MAX_FACT 64
41 #define RD_THRESH_INC      1
42
43 // This enumerator type needs to be kept aligned with the mode order in
44 // const MODE_DEFINITION vp9_mode_order[MAX_MODES] used in the rd code.
45 typedef enum {
46   THR_NEARESTMV,
47   THR_NEARESTA,
48   THR_NEARESTG,
49
50   THR_DC,
51
52   THR_NEWMV,
53   THR_NEWA,
54   THR_NEWG,
55
56   THR_NEARMV,
57   THR_NEARA,
58   THR_NEARG,
59
60   THR_ZEROMV,
61   THR_ZEROG,
62   THR_ZEROA,
63
64   THR_COMP_NEARESTLA,
65   THR_COMP_NEARESTGA,
66
67   THR_TM,
68
69   THR_COMP_NEARLA,
70   THR_COMP_NEWLA,
71   THR_COMP_NEARGA,
72   THR_COMP_NEWGA,
73
74   THR_COMP_ZEROLA,
75   THR_COMP_ZEROGA,
76
77   THR_H_PRED,
78   THR_V_PRED,
79   THR_D135_PRED,
80   THR_D207_PRED,
81   THR_D153_PRED,
82   THR_D63_PRED,
83   THR_D117_PRED,
84   THR_D45_PRED,
85 } THR_MODES;
86
87 typedef enum {
88   THR_LAST,
89   THR_GOLD,
90   THR_ALTR,
91   THR_COMP_LA,
92   THR_COMP_GA,
93   THR_INTRA,
94 } THR_MODES_SUB8X8;
95
96 typedef struct RD_OPT {
97   // Thresh_mult is used to set a threshold for the rd score. A higher value
98   // means that we will accept the best mode so far more often. This number
99   // is used in combination with the current block size, and thresh_freq_fact
100   // to pick a threshold.
101   int thresh_mult[MAX_MODES];
102   int thresh_mult_sub8x8[MAX_REFS];
103
104   int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
105
106   int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
107
108   int64_t filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS];
109
110   int RDMULT;
111   int RDDIV;
112 } RD_OPT;
113
114 typedef struct RD_COST {
115   int rate;
116   int64_t dist;
117   int64_t rdcost;
118 } RD_COST;
119
120 // Reset the rate distortion cost values to maximum (invalid) value.
121 void vp9_rd_cost_reset(RD_COST *rd_cost);
122 // Initialize the rate distortion cost values to zero.
123 void vp9_rd_cost_init(RD_COST *rd_cost);
124
125 struct TileInfo;
126 struct TileDataEnc;
127 struct VP9_COMP;
128 struct macroblock;
129
130 int vp9_compute_rd_mult(const struct VP9_COMP *cpi, int qindex);
131
132 void vp9_initialize_rd_consts(struct VP9_COMP *cpi);
133
134 void vp9_initialize_me_consts(struct VP9_COMP *cpi, MACROBLOCK *x, int qindex);
135
136 void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n,
137                                   unsigned int qstep, int *rate,
138                                   int64_t *dist);
139
140 int vp9_get_switchable_rate(const struct VP9_COMP *cpi,
141                             const MACROBLOCKD *const xd);
142
143 int vp9_raster_block_offset(BLOCK_SIZE plane_bsize,
144                             int raster_block, int stride);
145
146 int16_t* vp9_raster_block_offset_int16(BLOCK_SIZE plane_bsize,
147                                        int raster_block, int16_t *base);
148
149 YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const struct VP9_COMP *cpi,
150                                              int ref_frame);
151
152 void vp9_init_me_luts(void);
153
154 void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
155                               const struct macroblockd_plane *pd,
156                               ENTROPY_CONTEXT t_above[16],
157                               ENTROPY_CONTEXT t_left[16]);
158
159 void vp9_set_rd_speed_thresholds(struct VP9_COMP *cpi);
160
161 void vp9_set_rd_speed_thresholds_sub8x8(struct VP9_COMP *cpi);
162
163 void vp9_update_rd_thresh_fact(int (*fact)[MAX_MODES], int rd_thresh,
164                                int bsize, int best_mode_index);
165
166 static INLINE int rd_less_than_thresh(int64_t best_rd, int thresh,
167                                       int thresh_fact) {
168     return best_rd < ((int64_t)thresh * thresh_fact >> 5) || thresh == INT_MAX;
169 }
170
171 void vp9_mv_pred(struct VP9_COMP *cpi, MACROBLOCK *x,
172                  uint8_t *ref_y_buffer, int ref_y_stride,
173                  int ref_frame, BLOCK_SIZE block_size);
174
175 void vp9_setup_pred_block(const MACROBLOCKD *xd,
176                           struct buf_2d dst[MAX_MB_PLANE],
177                           const YV12_BUFFER_CONFIG *src,
178                           int mi_row, int mi_col,
179                           const struct scale_factors *scale,
180                           const struct scale_factors *scale_uv);
181
182 int vp9_get_intra_cost_penalty(int qindex, int qdelta,
183                                vpx_bit_depth_t bit_depth);
184
185 unsigned int vp9_get_sby_perpixel_variance(struct VP9_COMP *cpi,
186                                            const struct buf_2d *ref,
187                                            BLOCK_SIZE bs);
188 #if CONFIG_VP9_HIGHBITDEPTH
189 unsigned int vp9_high_get_sby_perpixel_variance(struct VP9_COMP *cpi,
190                                                 const struct buf_2d *ref,
191                                                 BLOCK_SIZE bs, int bd);
192 #endif
193
194 #ifdef __cplusplus
195 }  // extern "C"
196 #endif
197
198 #endif  // VP9_ENCODER_VP9_RD_H_