Separate ref frame mvs control from prev_frame_mvs

The control of using reference frame motion vector is a separate
factor from the existence of previous frame motion vectors. This
commit decouples these two, such that the encoder can control the
use of reference motion vector. When it is used, one can further
identify if the previous frame exists or not, then to decide if
need to force use_prev_frame_mvs to be zero.

This solves the issue where the previous frame mvs is set to be
0 and it accidentally shuts off the access to all other existing
referece frames mvs in the mfmv system. It brings back the coding
performance gains to normal.

Change-Id: I2531f73e55582a9bb5b3e0ff47e361a199ec8082
diff --git a/av1/common/mvref_common.c b/av1/common/mvref_common.c
index 3b41f58..5c18f17 100644
--- a/av1/common/mvref_common.c
+++ b/av1/common/mvref_common.c
@@ -720,7 +720,7 @@
     ref_mv_stack[idx].weight += REF_CAT_LEVEL;
 
 #if CONFIG_MFMV
-  if (cm->use_prev_frame_mvs) {
+  if (cm->use_ref_frame_mvs) {
     int blk_row, blk_col;
     int coll_blk_count = 0;
     int voffset = AOMMAX(mi_size_high[BLOCK_8X8], xd->n8_h);
diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h
index 8a470c6..ddc7208 100644
--- a/av1/common/onyxc_int.h
+++ b/av1/common/onyxc_int.h
@@ -350,6 +350,8 @@
   // Whether to use previous frame's motion vectors for prediction.
   int use_prev_frame_mvs;
 
+  int use_ref_frame_mvs;
+
   // Persistent mb segment id map used in prediction.
   int seg_map_idx;
   int prev_seg_map_idx;
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 73a38b7..29ef567 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -3094,9 +3094,12 @@
       cm->interp_filter = read_frame_interp_filter(rb);
 #if CONFIG_TEMPMV_SIGNALING
       if (frame_might_use_prev_frame_mvs(cm))
-        cm->use_prev_frame_mvs = aom_rb_read_bit(rb);
+        cm->use_ref_frame_mvs = aom_rb_read_bit(rb);
       else
-        cm->use_prev_frame_mvs = 0;
+        cm->use_ref_frame_mvs = 0;
+
+      cm->use_prev_frame_mvs =
+          cm->use_ref_frame_mvs && frame_can_use_prev_frame_mvs(cm);
 #endif
       for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
         RefBuffer *const ref_buf = &cm->frame_refs[i];
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 9a2b852..03ab38e 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -3939,9 +3939,8 @@
       fix_interp_filter(cm, cpi->td.counts);
       write_frame_interp_filter(cm->interp_filter, wb);
 #if CONFIG_TEMPMV_SIGNALING
-      if (frame_might_use_prev_frame_mvs(cm)) {
-        aom_wb_write_bit(wb, cm->use_prev_frame_mvs);
-      }
+      if (frame_might_use_prev_frame_mvs(cm))
+        aom_wb_write_bit(wb, cm->use_ref_frame_mvs);
 #endif
     }
   }
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index cfce8d2..0dab68d 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -5223,8 +5223,9 @@
 #if CONFIG_TEMPMV_SIGNALING
   // frame type has been decided outside of this function call
   cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only;
-  cm->use_prev_frame_mvs =
+  cm->use_ref_frame_mvs =
       !cpi->oxcf.disable_tempmv && !cm->cur_frame->intra_only;
+  cm->use_prev_frame_mvs = cm->use_ref_frame_mvs;
 #endif
 
   // Reset the frame packet stamp index.