]> granicus.if.org Git - libvpx/blob - vp10/encoder/rd.h
Merge changes from topic 'rm-loopfilter-count-param'
[libvpx] / vp10 / encoder / 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 VP10_ENCODER_RD_H_
12 #define VP10_ENCODER_RD_H_
13
14 #include <limits.h>
15
16 #include "vp10/common/blockd.h"
17
18 #include "vp10/encoder/block.h"
19 #include "vp10/encoder/context_tree.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define RDDIV_BITS          7
26
27 #define RDCOST(RM, DM, R, D) \
28   (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM))
29 #define QIDX_SKIP_THRESH     115
30
31 #define MV_COST_WEIGHT      108
32 #define MV_COST_WEIGHT_SUB  120
33
34 #define INVALID_MV 0x80008000
35
36 #define MAX_MODES 30
37 #define MAX_REFS  6
38
39 #define RD_THRESH_MAX_FACT 64
40 #define RD_THRESH_INC      1
41
42 // This enumerator type needs to be kept aligned with the mode order in
43 // const MODE_DEFINITION vp10_mode_order[MAX_MODES] used in the rd code.
44 typedef enum {
45   THR_NEARESTMV,
46   THR_NEARESTA,
47   THR_NEARESTG,
48
49   THR_DC,
50
51   THR_NEWMV,
52   THR_NEWA,
53   THR_NEWG,
54
55   THR_NEARMV,
56   THR_NEARA,
57   THR_NEARG,
58
59   THR_ZEROMV,
60   THR_ZEROG,
61   THR_ZEROA,
62
63   THR_COMP_NEARESTLA,
64   THR_COMP_NEARESTGA,
65
66   THR_TM,
67
68   THR_COMP_NEARLA,
69   THR_COMP_NEWLA,
70   THR_COMP_NEARGA,
71   THR_COMP_NEWGA,
72
73   THR_COMP_ZEROLA,
74   THR_COMP_ZEROGA,
75
76   THR_H_PRED,
77   THR_V_PRED,
78   THR_D135_PRED,
79   THR_D207_PRED,
80   THR_D153_PRED,
81   THR_D63_PRED,
82   THR_D117_PRED,
83   THR_D45_PRED,
84 } THR_MODES;
85
86 typedef enum {
87   THR_LAST,
88   THR_GOLD,
89   THR_ALTR,
90   THR_COMP_LA,
91   THR_COMP_GA,
92   THR_INTRA,
93 } THR_MODES_SUB8X8;
94
95 typedef struct RD_OPT {
96   // Thresh_mult is used to set a threshold for the rd score. A higher value
97   // means that we will accept the best mode so far more often. This number
98   // is used in combination with the current block size, and thresh_freq_fact
99   // to pick a threshold.
100   int thresh_mult[MAX_MODES];
101   int thresh_mult_sub8x8[MAX_REFS];
102
103   int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
104
105   int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
106
107   int64_t filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS];
108
109   int RDMULT;
110   int RDDIV;
111 } RD_OPT;
112
113 typedef struct RD_COST {
114   int rate;
115   int64_t dist;
116   int64_t rdcost;
117 } RD_COST;
118
119 // Reset the rate distortion cost values to maximum (invalid) value.
120 void vp10_rd_cost_reset(RD_COST *rd_cost);
121 // Initialize the rate distortion cost values to zero.
122 void vp10_rd_cost_init(RD_COST *rd_cost);
123
124 struct TileInfo;
125 struct TileDataEnc;
126 struct VP10_COMP;
127 struct macroblock;
128
129 int vp10_compute_rd_mult(const struct VP10_COMP *cpi, int qindex);
130
131 void vp10_initialize_rd_consts(struct VP10_COMP *cpi);
132
133 void vp10_initialize_me_consts(struct VP10_COMP *cpi,
134                                MACROBLOCK *x, int qindex);
135
136 void vp10_model_rd_from_var_lapndz(unsigned int var, unsigned int n,
137                                   unsigned int qstep, int *rate,
138                                   int64_t *dist);
139
140 int vp10_get_switchable_rate(const struct VP10_COMP *cpi,
141                             const MACROBLOCKD *const xd);
142
143 int vp10_raster_block_offset(BLOCK_SIZE plane_bsize,
144                             int raster_block, int stride);
145
146 int16_t* vp10_raster_block_offset_int16(BLOCK_SIZE plane_bsize,
147                                        int raster_block, int16_t *base);
148
149 YV12_BUFFER_CONFIG *vp10_get_scaled_ref_frame(const struct VP10_COMP *cpi,
150                                              int ref_frame);
151
152 void vp10_init_me_luts(void);
153
154 void vp10_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 vp10_set_rd_speed_thresholds(struct VP10_COMP *cpi);
160
161 void vp10_set_rd_speed_thresholds_sub8x8(struct VP10_COMP *cpi);
162
163 void vp10_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 vp10_mv_pred(struct VP10_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 vp10_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 vp10_get_intra_cost_penalty(int qindex, int qdelta,
183                                vpx_bit_depth_t bit_depth);
184
185 #ifdef __cplusplus
186 }  // extern "C"
187 #endif
188
189 #endif  // VP10_ENCODER_RD_H_