From 9d5bc18b099ea9115fde340e1db49536fa621318 Mon Sep 17 00:00:00 2001 From: Cheng Chen Date: Mon, 10 Feb 2020 16:13:58 -0800 Subject: [PATCH] Set mv to zero if the second ref does not exist Change-Id: I94b936c2642981eccdff073fc71c12e2dccb7909 --- vp9/encoder/vp9_encodeframe.c | 3 +++ vp9/encoder/vp9_rdopt.c | 7 +++++++ vp9/simple_encode.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index f9a64f3..3e83a26 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -3847,6 +3847,9 @@ static void assign_motion_vector_info(const int block_width_4x4, const int col_4x4 = col_start_4x4 + j; const int unit_index = row_4x4 * num_unit_cols + col_4x4; if (row_4x4 >= num_unit_rows || col_4x4 >= num_unit_cols) continue; + if (source_ref_frame[1] == NONE) { + assert(source_mv[1]->row == 0 && source_mv[1]->col == 0); + } motion_vector_info[unit_index].ref_frame[0] = source_ref_frame[0]; motion_vector_info[unit_index].ref_frame[1] = source_ref_frame[1]; motion_vector_info[unit_index].mv[0].as_mv.row = source_mv[0]->row; diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index fa7472c..39b99d5 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -4733,6 +4733,13 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, TileDataEnc *tile_data, mi->mv[0].as_int = xd->mi[0]->bmi[3].as_mv[0].as_int; mi->mv[1].as_int = xd->mi[0]->bmi[3].as_mv[1].as_int; } + // If the second reference does not exist, set the corresponding mv to zero. + if (mi->ref_frame[1] == NONE) { + mi->mv[1].as_int = 0; + for (i = 0; i < 4; ++i) { + mi->bmi[i].as_mv[1].as_int = 0; + } + } for (i = 0; i < REFERENCE_MODES; ++i) { if (best_pred_rd[i] == INT64_MAX) diff --git a/vp9/simple_encode.h b/vp9/simple_encode.h index 148f898..60f405e 100644 --- a/vp9/simple_encode.h +++ b/vp9/simple_encode.h @@ -59,8 +59,10 @@ struct MotionVectorInfo { // or kAltRefFrame. RefFrameType ref_frame[2]; // The row offset of motion vectors in the unit of pixel. + // If the second motion vector does not exist, the value is 0. double mv_row[2]; // The column offset of motion vectors in the unit of pixel. + // If the second motion vector does not exist, the value is 0. double mv_column[2]; }; -- 2.7.4