Sync enc/dec for tempmv_signaling

* Change ref parameter to use LAST FRAME instead of
 previous frame, which makes it consistent in
 enc/dec for tempmv_signaling.

BUG=aomedia:511

Change-Id: I02f1101623b7b3b09cd4d3f2977e9503b95818ec
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 8e8d82d..47bc183 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -4134,11 +4134,17 @@
 #if CONFIG_PALETTE
     cm->allow_screen_content_tools = aom_rb_read_bit(rb);
 #endif  // CONFIG_PALETTE
+#if CONFIG_TEMPMV_SIGNALING
+    cm->use_prev_frame_mvs = 0;
+#endif
   } else {
     cm->intra_only = cm->show_frame ? 0 : aom_rb_read_bit(rb);
 #if CONFIG_PALETTE
     if (cm->intra_only) cm->allow_screen_content_tools = aom_rb_read_bit(rb);
 #endif  // CONFIG_PALETTE
+#if CONFIG_TEMPMV_SIGNALING
+    if (cm->intra_only || cm->error_resilient_mode) cm->use_prev_frame_mvs = 0;
+#endif
     if (cm->error_resilient_mode) {
       cm->reset_frame_context = RESET_FRAME_CONTEXT_ALL;
     } else {
@@ -4952,13 +4958,17 @@
   cm->setup_mi(cm);
 
 #if CONFIG_TEMPMV_SIGNALING
-  if (cm->use_prev_frame_mvs) {
-    RefBuffer *last_fb_ref_buf = &cm->frame_refs[LAST_FRAME - LAST_FRAME];
-    cm->prev_frame = &cm->buffer_pool->frame_bufs[last_fb_ref_buf->idx];
-    assert(!cm->error_resilient_mode &&
-           cm->width == last_fb_ref_buf->buf->y_width &&
-           cm->height == last_fb_ref_buf->buf->y_height &&
-           !cm->prev_frame->intra_only);
+  RefBuffer *last_ref_buf = &cm->frame_refs[LAST_FRAME - LAST_FRAME];
+  if (last_ref_buf->idx != INVALID_IDX) {
+    cm->prev_frame = &cm->buffer_pool->frame_bufs[last_ref_buf->idx];
+    if (cm->use_prev_frame_mvs) {
+      assert(!cm->error_resilient_mode &&
+             cm->width == last_ref_buf->buf->y_width &&
+             cm->height == last_ref_buf->buf->y_height &&
+             !cm->prev_frame->intra_only);
+    }
+  } else {
+    assert(cm->use_prev_frame_mvs == 0);
   }
 #else
   cm->use_prev_frame_mvs =
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 0ccb4b3..1bd5b44 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -5328,6 +5328,8 @@
                               cm->width == cm->prev_frame->buf.y_width &&
                               cm->height == cm->prev_frame->buf.y_height &&
                               !cm->intra_only && !cm->prev_frame->intra_only;
+  } else {
+    cm->use_prev_frame_mvs = 0;
   }
 #else
   cm->use_prev_frame_mvs =