2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
11 #ifndef VP9_ENCODER_VP9_RD_H_
12 #define VP9_ENCODER_VP9_RD_H_
16 #include "vp9/common/vp9_blockd.h"
18 #include "vp9/encoder/vp9_block.h"
19 #include "vp9/encoder/vp9_context_tree.h"
27 #define RDCOST(RM, DM, R, D) \
28 (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM))
29 #define QIDX_SKIP_THRESH 115
31 #define MV_COST_WEIGHT 108
32 #define MV_COST_WEIGHT_SUB 120
34 #define INVALID_MV 0x80008000
39 // This enumerator type needs to be kept aligned with the mode order in
40 // const MODE_DEFINITION vp9_mode_order[MAX_MODES] used in the rd code.
90 typedef struct RD_OPT {
91 // Thresh_mult is used to set a threshold for the rd score. A higher value
92 // means that we will accept the best mode so far more often. This number
93 // is used in combination with the current block size, and thresh_freq_fact
94 // to pick a threshold.
95 int thresh_mult[MAX_MODES];
96 int thresh_mult_sub8x8[MAX_REFS];
98 int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
99 int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
101 int64_t comp_pred_diff[REFERENCE_MODES];
102 int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
103 int64_t tx_select_diff[TX_MODES];
104 // TODO(agrange): can this overflow?
105 int tx_select_threshes[MAX_REF_FRAMES][TX_MODES];
107 int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];
108 int64_t filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS];
109 int64_t filter_cache[SWITCHABLE_FILTER_CONTEXTS];
120 int vp9_compute_rd_mult(const struct VP9_COMP *cpi, int qindex);
122 void vp9_initialize_rd_consts(struct VP9_COMP *cpi);
124 void vp9_initialize_me_consts(struct VP9_COMP *cpi, int qindex);
126 void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n,
127 unsigned int qstep, int *rate,
130 int vp9_get_switchable_rate(const struct VP9_COMP *cpi);
132 const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const struct VP9_COMP *cpi,
135 void vp9_init_me_luts();
137 void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
138 const struct macroblockd_plane *pd,
139 ENTROPY_CONTEXT t_above[16],
140 ENTROPY_CONTEXT t_left[16]);
142 void vp9_set_rd_speed_thresholds(struct VP9_COMP *cpi);
144 void vp9_set_rd_speed_thresholds_sub8x8(struct VP9_COMP *cpi);
146 static INLINE int rd_less_than_thresh(int64_t best_rd, int thresh,
148 return best_rd < ((int64_t)thresh * thresh_fact >> 5) || thresh == INT_MAX;
151 void vp9_mv_pred(struct VP9_COMP *cpi, MACROBLOCK *x,
152 uint8_t *ref_y_buffer, int ref_y_stride,
153 int ref_frame, BLOCK_SIZE block_size);
155 void vp9_setup_pred_block(const MACROBLOCKD *xd,
156 struct buf_2d dst[MAX_MB_PLANE],
157 const YV12_BUFFER_CONFIG *src,
158 int mi_row, int mi_col,
159 const struct scale_factors *scale,
160 const struct scale_factors *scale_uv);
165 #endif // VP9_ENCODER_VP9_RD_H_