ref: e3fae047856e622ffd04330f935cbdebdd625aa5
parent: 36f42a3769e6f15ca4b9bd64d1bc26311ef588a5
author: Angie Chiang <angiebird@google.com>
date: Wed Feb 6 08:52:48 EST 2019
Use mv_mode_arr to decide the newmv discount place Change-Id: I98c32aba4c9e81380b588dcdbfa991468487ce73
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -6040,11 +6040,6 @@
#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 @@
int64_t recon_error, sse;
#if CONFIG_NON_GREEDY_MV
int square_block_idx;
+ int rf_idx;
#endif
// Setup scaling factor
@@ -6676,6 +6672,13 @@
++square_block_idx) {
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
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -304,6 +304,12 @@
#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 {
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -2538,8 +2538,35 @@
// 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) ||
@@ -2546,6 +2573,7 @@
(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 @@
// 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 @@
//
// 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]]));