From e3fae047856e622ffd04330f935cbdebdd625aa5 Mon Sep 17 00:00:00 2001 From: Angie Chiang Date: Wed, 6 Feb 2019 13:52:48 -0800 Subject: [PATCH] Use mv_mode_arr to decide the newmv discount place Change-Id: I98c32aba4c9e81380b588dcdbfa991468487ce73 --- vp9/encoder/vp9_encoder.c | 13 ++++++++----- vp9/encoder/vp9_encoder.h | 6 ++++++ vp9/encoder/vp9_rdopt.c | 39 ++++++++++++++++++++++++++++++++++----- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index a5da54283..c69f581d6 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -6040,11 +6040,6 @@ static int get_block_src_pred_buf(MACROBLOCKD *xd, GF_PICTURE *gf_picture, #define kMvPreCheckLines 5 #define kMvPreCheckSize 15 -#define ZERO_MV_MODE 0 -#define NEW_MV_MODE 1 -#define NEAREST_MV_MODE 2 -#define NEAR_MV_MODE 3 -#define MAX_MV_MODE 4 #define MV_REF_POS_NUM 3 POSITION mv_ref_pos[MV_REF_POS_NUM] = { @@ -6631,6 +6626,7 @@ static void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, int64_t recon_error, sse; #if CONFIG_NON_GREEDY_MV int square_block_idx; + int rf_idx; #endif // Setup scaling factor @@ -6677,6 +6673,13 @@ static void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, BLOCK_SIZE square_bsize = square_block_idx_to_bsize(square_block_idx); build_motion_field(cpi, xd, frame_idx, ref_frame, square_bsize); } + for (rf_idx = 0; rf_idx < 3; ++rf_idx) { + int ref_frame_idx = gf_picture[frame_idx].ref_frame[rf_idx]; + if (ref_frame_idx != -1) { + predict_mv_mode_arr(cpi, x, gf_picture, frame_idx, tpl_frame, rf_idx, + bsize); + } + } #endif for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) { diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index 485328321..e543ae70b 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -304,6 +304,12 @@ typedef struct TplDepStats { #if CONFIG_NON_GREEDY_MV #define SQUARE_BLOCK_SIZES 4 + +#define ZERO_MV_MODE 0 +#define NEW_MV_MODE 1 +#define NEAREST_MV_MODE 2 +#define NEAR_MV_MODE 3 +#define MAX_MV_MODE 4 #endif typedef struct TplDepFrame { diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 6f07269d4..87b7f1a7d 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -2538,14 +2538,42 @@ static INLINE void restore_dst_buf(MACROBLOCKD *xd, // visual quality. static int discount_newmv_test(const VP9_COMP *cpi, int this_mode, int_mv this_mv, - int_mv (*mode_mv)[MAX_REF_FRAMES], - int ref_frame) { + int_mv (*mode_mv)[MAX_REF_FRAMES], int ref_frame, + int mi_row, int mi_col, BLOCK_SIZE bsize) { +#if CONFIG_NON_GREEDY_MV + (void)mode_mv; + (void)this_mv; + if (this_mode == NEWMV && bsize >= BLOCK_8X8) { + const int gf_group_idx = cpi->twopass.gf_group.index; + const int gf_rf_idx = ref_frame_to_gf_rf_idx(ref_frame); + const TplDepFrame tpl_frame = cpi->tpl_stats[gf_group_idx]; + const int tpl_block_mi_h = num_8x8_blocks_high_lookup[cpi->tpl_bsize]; + const int tpl_block_mi_w = num_8x8_blocks_wide_lookup[cpi->tpl_bsize]; + const int tpl_mi_row = mi_row - (mi_row % tpl_block_mi_h); + const int tpl_mi_col = mi_col - (mi_col % tpl_block_mi_w); + const int mv_mode = + tpl_frame + .mv_mode_arr[gf_rf_idx][tpl_mi_row * tpl_frame.stride + tpl_mi_col]; + if (mv_mode == NEW_MV_MODE) { + // TODO(angiebird): Compare this_mv with the motion field. + return 1; + } else { + return 0; + } + } else { + return 0; + } +#else + (void)mi_row; + (void)mi_col; + (void)bsize; return (!cpi->rc.is_src_frame_alt_ref && (this_mode == NEWMV) && (this_mv.as_int != 0) && ((mode_mv[NEARESTMV][ref_frame].as_int == 0) || (mode_mv[NEARESTMV][ref_frame].as_int == INVALID_MV)) && ((mode_mv[NEARMV][ref_frame].as_int == 0) || (mode_mv[NEARMV][ref_frame].as_int == INVALID_MV))); +#endif } static int64_t handle_inter_mode( @@ -2658,7 +2686,8 @@ static int64_t handle_inter_mode( // under certain circumstances where we want to help initiate a weak // motion field, where the distortion gain for a single block may not // be enough to overcome the cost of a new mv. - if (discount_newmv_test(cpi, this_mode, tmp_mv, mode_mv, refs[0])) { + if (discount_newmv_test(cpi, this_mode, tmp_mv, mode_mv, refs[0], mi_row, + mi_col, bsize)) { *rate2 += VPXMAX((rate_mv / NEW_MV_DISCOUNT_FACTOR), 1); } else { *rate2 += rate_mv; @@ -2691,8 +2720,8 @@ static int64_t handle_inter_mode( // // Under some circumstances we discount the cost of new mv mode to encourage // initiation of a motion field. - if (discount_newmv_test(cpi, this_mode, frame_mv[refs[0]], mode_mv, - refs[0])) { + if (discount_newmv_test(cpi, this_mode, frame_mv[refs[0]], mode_mv, refs[0], + mi_row, mi_col, bsize)) { *rate2 += VPXMIN(cost_mv_ref(cpi, this_mode, mbmi_ext->mode_context[refs[0]]), cost_mv_ref(cpi, NEARESTMV, mbmi_ext->mode_context[refs[0]])); -- 2.40.0