OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef VP9_ENCODER_VP9_RDOPT_H_ | 11 #ifndef VP9_ENCODER_VP9_RDOPT_H_ |
12 #define VP9_ENCODER_VP9_RDOPT_H_ | 12 #define VP9_ENCODER_VP9_RDOPT_H_ |
13 | 13 |
14 #include "vp9/encoder/vp9_encoder.h" | 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" |
15 | 20 |
16 #ifdef __cplusplus | 21 #ifdef __cplusplus |
17 extern "C" { | 22 extern "C" { |
18 #endif | 23 #endif |
19 | 24 |
20 #define RDDIV_BITS 7 | 25 #define RDDIV_BITS 7 |
21 | 26 |
22 #define RDCOST(RM, DM, R, D) \ | 27 #define RDCOST(RM, DM, R, D) \ |
23 (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM)) | 28 (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM)) |
24 #define QIDX_SKIP_THRESH 115 | 29 #define QIDX_SKIP_THRESH 115 |
25 | 30 |
26 #define MV_COST_WEIGHT 108 | 31 #define MV_COST_WEIGHT 108 |
27 #define MV_COST_WEIGHT_SUB 120 | 32 #define MV_COST_WEIGHT_SUB 120 |
28 | 33 |
29 #define INVALID_MV 0x80008000 | 34 #define INVALID_MV 0x80008000 |
30 | 35 |
| 36 #define MAX_MODES 30 |
| 37 #define MAX_REFS 6 |
| 38 |
| 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. |
| 41 typedef enum { |
| 42 THR_NEARESTMV, |
| 43 THR_NEARESTA, |
| 44 THR_NEARESTG, |
| 45 |
| 46 THR_DC, |
| 47 |
| 48 THR_NEWMV, |
| 49 THR_NEWA, |
| 50 THR_NEWG, |
| 51 |
| 52 THR_NEARMV, |
| 53 THR_NEARA, |
| 54 THR_COMP_NEARESTLA, |
| 55 THR_COMP_NEARESTGA, |
| 56 |
| 57 THR_TM, |
| 58 |
| 59 THR_COMP_NEARLA, |
| 60 THR_COMP_NEWLA, |
| 61 THR_NEARG, |
| 62 THR_COMP_NEARGA, |
| 63 THR_COMP_NEWGA, |
| 64 |
| 65 THR_ZEROMV, |
| 66 THR_ZEROG, |
| 67 THR_ZEROA, |
| 68 THR_COMP_ZEROLA, |
| 69 THR_COMP_ZEROGA, |
| 70 |
| 71 THR_H_PRED, |
| 72 THR_V_PRED, |
| 73 THR_D135_PRED, |
| 74 THR_D207_PRED, |
| 75 THR_D153_PRED, |
| 76 THR_D63_PRED, |
| 77 THR_D117_PRED, |
| 78 THR_D45_PRED, |
| 79 } THR_MODES; |
| 80 |
| 81 typedef enum { |
| 82 THR_LAST, |
| 83 THR_GOLD, |
| 84 THR_ALTR, |
| 85 THR_COMP_LA, |
| 86 THR_COMP_GA, |
| 87 THR_INTRA, |
| 88 } THR_MODES_SUB8X8; |
| 89 |
| 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]; |
| 97 |
| 98 int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES]; |
| 99 int thresh_freq_fact[BLOCK_SIZES][MAX_MODES]; |
| 100 |
| 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 // FIXME(rbultje) can this overflow? |
| 105 int tx_select_threshes[MAX_REF_FRAMES][TX_MODES]; |
| 106 |
| 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]; |
| 110 int64_t mask_filter; |
| 111 |
| 112 int RDMULT; |
| 113 int RDDIV; |
| 114 } RD_OPT; |
| 115 |
| 116 |
31 struct TileInfo; | 117 struct TileInfo; |
| 118 struct VP9_COMP; |
| 119 struct macroblock; |
32 | 120 |
33 int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex); | 121 int vp9_compute_rd_mult(const struct VP9_COMP *cpi, int qindex); |
34 | 122 |
35 void vp9_initialize_rd_consts(VP9_COMP *cpi); | 123 void vp9_initialize_rd_consts(struct VP9_COMP *cpi); |
36 | 124 |
37 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex); | 125 void vp9_initialize_me_consts(struct VP9_COMP *cpi, int qindex); |
38 | 126 |
39 void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n, | 127 void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n, |
40 unsigned int qstep, int *rate, | 128 unsigned int qstep, int *rate, |
41 int64_t *dist); | 129 int64_t *dist); |
42 | 130 |
43 int vp9_get_switchable_rate(const VP9_COMP *cpi); | 131 int vp9_get_switchable_rate(const struct VP9_COMP *cpi); |
44 | 132 |
45 void vp9_setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, | 133 void vp9_setup_buffer_inter(struct VP9_COMP *cpi, struct macroblock *x, |
46 const TileInfo *const tile, | 134 const TileInfo *const tile, |
47 MV_REFERENCE_FRAME ref_frame, | 135 MV_REFERENCE_FRAME ref_frame, |
48 BLOCK_SIZE block_size, | 136 BLOCK_SIZE block_size, |
49 int mi_row, int mi_col, | 137 int mi_row, int mi_col, |
50 int_mv frame_nearest_mv[MAX_REF_FRAMES], | 138 int_mv frame_nearest_mv[MAX_REF_FRAMES], |
51 int_mv frame_near_mv[MAX_REF_FRAMES], | 139 int_mv frame_near_mv[MAX_REF_FRAMES], |
52 struct buf_2d yv12_mb[4][MAX_MB_PLANE]); | 140 struct buf_2d yv12_mb[4][MAX_MB_PLANE]); |
53 | 141 |
54 const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi, | 142 const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const struct VP9_COMP *cpi, |
55 int ref_frame); | 143 int ref_frame); |
56 | 144 |
57 void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, | 145 void vp9_rd_pick_intra_mode_sb(struct VP9_COMP *cpi, struct macroblock *x, |
58 int *r, int64_t *d, BLOCK_SIZE bsize, | 146 int *r, int64_t *d, BLOCK_SIZE bsize, |
59 PICK_MODE_CONTEXT *ctx, int64_t best_rd); | 147 PICK_MODE_CONTEXT *ctx, int64_t best_rd); |
60 | 148 |
61 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, | 149 int64_t vp9_rd_pick_inter_mode_sb(struct VP9_COMP *cpi, struct macroblock *x, |
62 const struct TileInfo *const tile, | 150 const struct TileInfo *const tile, |
63 int mi_row, int mi_col, | 151 int mi_row, int mi_col, |
64 int *returnrate, | 152 int *returnrate, |
65 int64_t *returndistortion, | 153 int64_t *returndistortion, |
66 BLOCK_SIZE bsize, | 154 BLOCK_SIZE bsize, |
67 PICK_MODE_CONTEXT *ctx, | 155 PICK_MODE_CONTEXT *ctx, |
68 int64_t best_rd_so_far); | 156 int64_t best_rd_so_far); |
69 | 157 |
70 int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, | 158 int64_t vp9_rd_pick_inter_mode_sub8x8(struct VP9_COMP *cpi, |
| 159 struct macroblock *x, |
71 const struct TileInfo *const tile, | 160 const struct TileInfo *const tile, |
72 int mi_row, int mi_col, | 161 int mi_row, int mi_col, |
73 int *returnrate, | 162 int *returnrate, |
74 int64_t *returndistortion, | 163 int64_t *returndistortion, |
75 BLOCK_SIZE bsize, | 164 BLOCK_SIZE bsize, |
76 PICK_MODE_CONTEXT *ctx, | 165 PICK_MODE_CONTEXT *ctx, |
77 int64_t best_rd_so_far); | 166 int64_t best_rd_so_far); |
78 | 167 |
79 void vp9_init_me_luts(); | 168 void vp9_init_me_luts(); |
80 | 169 |
81 void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size, | 170 void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size, |
82 const struct macroblockd_plane *pd, | 171 const struct macroblockd_plane *pd, |
83 ENTROPY_CONTEXT t_above[16], | 172 ENTROPY_CONTEXT t_above[16], |
84 ENTROPY_CONTEXT t_left[16]); | 173 ENTROPY_CONTEXT t_left[16]); |
85 | 174 |
86 void vp9_set_rd_speed_thresholds(VP9_COMP *cpi); | 175 void vp9_set_rd_speed_thresholds(struct VP9_COMP *cpi); |
87 | 176 |
88 void vp9_set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi); | 177 void vp9_set_rd_speed_thresholds_sub8x8(struct VP9_COMP *cpi); |
89 | 178 |
90 static INLINE int full_pixel_search(VP9_COMP *cpi, MACROBLOCK *x, | 179 static INLINE int rd_less_than_thresh(int64_t best_rd, int thresh, |
91 BLOCK_SIZE bsize, MV *mvp_full, | 180 int thresh_fact) { |
92 int step_param, int error_per_bit, | 181 return best_rd < ((int64_t)thresh * thresh_fact >> 5) || thresh == INT_MAX; |
93 const MV *ref_mv, MV *tmp_mv, | |
94 int var_max, int rd) { | |
95 int var = 0; | |
96 | |
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); | |
122 } else { | |
123 int further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; | |
124 | |
125 var = vp9_full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit, | |
126 further_steps, 1, &cpi->fn_ptr[bsize], | |
127 ref_mv, tmp_mv); | |
128 } | |
129 | |
130 return var; | |
131 } | 182 } |
132 | 183 |
133 #ifdef __cplusplus | 184 #ifdef __cplusplus |
134 } // extern "C" | 185 } // extern "C" |
135 #endif | 186 #endif |
136 | 187 |
137 #endif // VP9_ENCODER_VP9_RDOPT_H_ | 188 #endif // VP9_ENCODER_VP9_RDOPT_H_ |
OLD | NEW |