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_RDOPT_H_
12 #define VP9_ENCODER_VP9_RDOPT_H_
14 #include "vp9/encoder/vp9_encoder.h"
22 #define RDCOST(RM, DM, R, D) \
23 (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM))
24 #define QIDX_SKIP_THRESH 115
26 #define MV_COST_WEIGHT 108
27 #define MV_COST_WEIGHT_SUB 120
29 #define INVALID_MV 0x80008000
33 int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex);
35 void vp9_initialize_rd_consts(VP9_COMP *cpi);
37 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex);
39 void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n,
40 unsigned int qstep, int *rate,
43 int vp9_get_switchable_rate(const VP9_COMP *cpi);
45 void vp9_setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
46 const TileInfo *const tile,
47 MV_REFERENCE_FRAME ref_frame,
48 BLOCK_SIZE block_size,
49 int mi_row, int mi_col,
50 int_mv frame_nearest_mv[MAX_REF_FRAMES],
51 int_mv frame_near_mv[MAX_REF_FRAMES],
52 struct buf_2d yv12_mb[4][MAX_MB_PLANE]);
54 const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi,
57 void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
58 int *r, int64_t *d, BLOCK_SIZE bsize,
59 PICK_MODE_CONTEXT *ctx, int64_t best_rd);
61 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
62 const struct TileInfo *const tile,
63 int mi_row, int mi_col,
65 int64_t *returndistortion,
67 PICK_MODE_CONTEXT *ctx,
68 int64_t best_rd_so_far);
70 int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
71 const struct TileInfo *const tile,
72 int mi_row, int mi_col,
74 int64_t *returndistortion,
76 PICK_MODE_CONTEXT *ctx,
77 int64_t best_rd_so_far);
79 void vp9_init_me_luts();
81 void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
82 const struct macroblockd_plane *pd,
83 ENTROPY_CONTEXT t_above[16],
84 ENTROPY_CONTEXT t_left[16]);
86 void vp9_set_rd_speed_thresholds(VP9_COMP *cpi);
88 void vp9_set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi);
90 static INLINE int full_pixel_search(VP9_COMP *cpi, MACROBLOCK *x,
91 BLOCK_SIZE bsize, MV *mvp_full,
92 int step_param, int error_per_bit,
93 const MV *ref_mv, MV *tmp_mv,
94 int var_max, int rd) {
97 if (cpi->sf.search_method == FAST_DIAMOND) {
98 var = vp9_fast_dia_search(x, mvp_full, step_param, error_per_bit, 0,
99 &cpi->fn_ptr[bsize], 1, ref_mv, tmp_mv);
100 if (rd && var < var_max)
101 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, &cpi->fn_ptr[bsize], 1);
102 } else if (cpi->sf.search_method == FAST_HEX) {
103 var = vp9_fast_hex_search(x, mvp_full, step_param, error_per_bit, 0,
104 &cpi->fn_ptr[bsize], 1, ref_mv, tmp_mv);
105 if (rd && var < var_max)
106 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, &cpi->fn_ptr[bsize], 1);
107 } else if (cpi->sf.search_method == HEX) {
108 var = vp9_hex_search(x, mvp_full, step_param, error_per_bit, 1,
109 &cpi->fn_ptr[bsize], 1, ref_mv, tmp_mv);
110 if (rd && var < var_max)
111 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, &cpi->fn_ptr[bsize], 1);
112 } else if (cpi->sf.search_method == SQUARE) {
113 var = vp9_square_search(x, mvp_full, step_param, error_per_bit, 1,
114 &cpi->fn_ptr[bsize], 1, ref_mv, tmp_mv);
115 if (rd && var < var_max)
116 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, &cpi->fn_ptr[bsize], 1);
117 } else if (cpi->sf.search_method == BIGDIA) {
118 var = vp9_bigdia_search(x, mvp_full, step_param, error_per_bit, 1,
119 &cpi->fn_ptr[bsize], 1, ref_mv, tmp_mv);
120 if (rd && var < var_max)
121 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, &cpi->fn_ptr[bsize], 1);
123 int further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
125 var = vp9_full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit,
126 further_steps, 1, &cpi->fn_ptr[bsize],
137 #endif // VP9_ENCODER_VP9_RDOPT_H_