ref: 9a4984824533284b055cded2edeeb77049e00823
parent: ef3cb03d8b2c73fad6743315d25b03935ed544c2
author: Angie Chiang <angiebird@google.com>
date: Thu Jan 24 10:44:41 EST 2019
Add find_best_ref_mv_mode() This function compute the rd cost for each mv_mode and return the one with minimum rd cost. eval_mv_mode() Evaluate the rd cost for a given mv_mode. Change-Id: Ia1b3ec7e1dd538e443e1bc79f2cab352408cd0a0
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -6097,9 +6097,9 @@
return invalid_mv;
}
-int_mv get_mv_from_mv_mode(int mv_mode, VP9_COMP *cpi, TplDepFrame *tpl_frame,
- int rf_idx, BLOCK_SIZE bsize, int mi_row,
- int mi_col) {
+static int_mv get_mv_from_mv_mode(int mv_mode, VP9_COMP *cpi,
+ TplDepFrame *tpl_frame, int rf_idx,
+ BLOCK_SIZE bsize, int mi_row, int mi_col) {
int_mv mv;
switch (mv_mode) {
case ZERO_MV_MODE:
@@ -6123,17 +6123,17 @@
return mv;
}
-double get_mv_dist(int mv_mode, VP9_COMP *cpi, MACROBLOCKD *xd,
- GF_PICTURE *gf_picture, int frame_idx,
- TplDepFrame *tpl_frame, int rf_idx, BLOCK_SIZE bsize,
- int mi_row, int mi_col) {
- MV mv = get_mv_from_mv_mode(mv_mode, cpi, tpl_frame, rf_idx, bsize, mi_row,
- mi_col)
- .as_mv;
- MV full_mv = get_full_mv(&mv);
+static double get_mv_dist(int mv_mode, VP9_COMP *cpi, MACROBLOCKD *xd,
+ GF_PICTURE *gf_picture, int frame_idx,
+ TplDepFrame *tpl_frame, int rf_idx, BLOCK_SIZE bsize,
+ int mi_row, int mi_col, int_mv *mv) {
uint32_t sse;
struct buf_2d src;
struct buf_2d pre;
+ MV full_mv;
+ *mv = get_mv_from_mv_mode(mv_mode, cpi, tpl_frame, rf_idx, bsize, mi_row,
+ mi_col);
+ full_mv = get_full_mv(&mv->as_mv);
get_block_src_pred_buf(xd, gf_picture, frame_idx, rf_idx, mi_row, mi_col,
&src, &pre);
// TODO(angiebird): Consider subpixel when computing the sse.
@@ -6140,6 +6140,58 @@
cpi->fn_ptr[bsize].vf(src.buf, src.stride, get_buf_from_mv(&pre, &full_mv),
pre.stride, &sse);
return (double)sse;
+}
+
+static double get_mv_cost(int mv_mode) {
+ // TODO(angiebird): Implement this function.
+ (void)mv_mode;
+ return 0;
+}
+
+static double rd_cost(int rdmult, int rddiv, double rate, double dist) {
+ return (rate * rdmult) / (1 << 9) + dist * (1 << rddiv);
+}
+
+static double eval_mv_mode(int mv_mode, VP9_COMP *cpi, MACROBLOCK *x,
+ GF_PICTURE *gf_picture, int frame_idx,
+ TplDepFrame *tpl_frame, int rf_idx, BLOCK_SIZE bsize,
+ int mi_row, int mi_col, int_mv *mv) {
+ MACROBLOCKD *xd = &x->e_mbd;
+ double mv_dist = get_mv_dist(mv_mode, cpi, xd, gf_picture, frame_idx,
+ tpl_frame, rf_idx, bsize, mi_row, mi_col, mv);
+ double mv_cost = get_mv_cost(mv_mode);
+ return rd_cost(x->rdmult, x->rddiv, mv_cost, mv_dist);
+}
+
+int find_best_ref_mv_mode(VP9_COMP *cpi, MACROBLOCK *x, GF_PICTURE *gf_picture,
+ int frame_idx, TplDepFrame *tpl_frame, int rf_idx,
+ BLOCK_SIZE bsize, int mi_row, int mi_col, double *rd,
+ int_mv *mv) {
+ int best_mv_mode = ZERO_MV_MODE;
+ int update = 0;
+ int mv_mode;
+ for (mv_mode = 0; mv_mode < MAX_MV_MODE; ++mv_mode) {
+ double this_rd;
+ int_mv this_mv;
+ if (mv_mode == NEW_MV_MODE) {
+ continue;
+ }
+ this_rd = eval_mv_mode(mv_mode, cpi, x, gf_picture, frame_idx, tpl_frame,
+ rf_idx, bsize, mi_row, mi_col, &this_mv);
+ if (update == 0) {
+ *rd = this_rd;
+ *mv = this_mv;
+ best_mv_mode = mv_mode;
+ update = 1;
+ } else {
+ if (this_rd < *rd) {
+ *rd = this_rd;
+ *mv = this_mv;
+ best_mv_mode = mv_mode;
+ }
+ }
+ }
+ return best_mv_mode;
}
static double get_feature_score(uint8_t *buf, ptrdiff_t stride, int rows,
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -320,6 +320,7 @@
double mv_dist_sum[3];
double mv_cost_sum[3];
int_mv *pyramid_mv_arr[3][SQUARE_BLOCK_SIZES];
+ int *mv_mode_arr[3];
#endif
} TplDepFrame;