shithub: libvpx

Download patch

ref: 353642bc53de23e3e51940960c8c2b8f6602566e
parent: 9a27b627b8f24bab9c802533b8a01ee0470df9ce
author: Scott LaVarnway <slavarnway@google.com>
date: Wed May 29 12:42:23 EDT 2013

Moved use_prev_in_find_mv_refs check to frame level

This patch checks at the frame level to see if the previous
mode info context can be used.  This patch eliminates the
flag check that was done for every mode and removes another
check that was done prior to every vp9_find_mv_refs().

Change-Id: I9da5e18b7e7e28f8b1f90d527cad087073df2d73

--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -786,5 +786,4 @@
   *x = (raster_mb & (tx_cols - 1)) << (txwl);
   *y = raster_mb >> tx_cols_lg2 << (txwl);
 }
-
 #endif  // VP9_COMMON_VP9_BLOCKD_H_
--- a/vp9/common/vp9_findnearmv.c
+++ b/vp9/common/vp9_findnearmv.c
@@ -61,18 +61,12 @@
   int_mv mv_list[MAX_MV_REF_CANDIDATES];
   MODE_INFO *mi = xd->mode_info_context;
   MB_MODE_INFO *const mbmi = &mi->mbmi;
-  int use_prev_in_find_mv_refs;
 
   assert(ref_idx == 0 || ref_idx == 1);
   assert(MAX_MV_REF_CANDIDATES == 2);  // makes code here slightly easier
 
-  use_prev_in_find_mv_refs = cm->width == cm->last_width &&
-                             cm->height == cm->last_height &&
-                             !cm->error_resilient_mode &&
-                             cm->last_show_frame;
   vp9_find_mv_refs_idx(cm, xd, xd->mode_info_context,
-                       use_prev_in_find_mv_refs ?
-                           xd->prev_mode_info_context : NULL,
+                       xd->prev_mode_info_context,
                        ref_idx ? mbmi->second_ref_frame : mbmi->ref_frame,
                        mv_list, cm->ref_frame_sign_bias, block_idx);
 
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -333,4 +333,15 @@
 static int get_token_alloc(int mb_rows, int mb_cols) {
   return mb_rows * mb_cols * (48 * 16 + 4);
 }
+
+static void set_prev_mi(VP9_COMMON *cm) {
+  const int use_prev_in_find_mv_refs = cm->width == cm->last_width &&
+                                       cm->height == cm->last_height &&
+                                       !cm->error_resilient_mode &&
+                                       cm->last_show_frame;
+  // Special case: set prev_mi to NULL when the previous mode info
+  // context cannot be used.
+  cm->prev_mi = use_prev_in_find_mv_refs ?
+                  cm->prev_mip + cm->mode_info_stride + 1 : NULL;
+}
 #endif  // VP9_COMMON_VP9_ONYXC_INT_H_
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -531,11 +531,6 @@
   int bw = 1 << b_width_log2(bsize);
   int bh = 1 << b_height_log2(bsize);
 
-  const int use_prev_in_find_mv_refs = cm->width == cm->last_width &&
-                                       cm->height == cm->last_height &&
-                                       !cm->error_resilient_mode &&
-                                       cm->last_show_frame;
-
   int mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, mb_to_bottom_edge;
   int j, idx, idy;
 
@@ -582,10 +577,8 @@
         printf("%d %d\n", xd->mode_info_context->mbmi.mv[0].as_mv.row,
                xd->mode_info_context->mbmi.mv[0].as_mv.col);
 #endif
-      vp9_find_mv_refs(cm, xd, mi, use_prev_in_find_mv_refs ?
-                       xd->prev_mode_info_context : NULL,
-                       ref_frame, mbmi->ref_mvs[ref_frame],
-                       cm->ref_frame_sign_bias);
+      vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context, ref_frame,
+                       mbmi->ref_mvs[ref_frame], cm->ref_frame_sign_bias);
 
       vp9_mv_ref_probs(cm, mv_ref_p, mbmi->mb_mode_context[ref_frame]);
 
@@ -636,9 +629,7 @@
       if (mbmi->second_ref_frame > 0) {
         const MV_REFERENCE_FRAME second_ref_frame = mbmi->second_ref_frame;
 
-        vp9_find_mv_refs(cm, xd, mi,
-                         use_prev_in_find_mv_refs ?
-                         xd->prev_mode_info_context : NULL,
+        vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context,
                          second_ref_frame, mbmi->ref_mvs[second_ref_frame],
                          cm->ref_frame_sign_bias);
 
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -403,7 +403,10 @@
 
   xd->mode_info_context = cm->mi + mi_idx;
   xd->mode_info_context->mbmi.sb_type = bsize;
-  xd->prev_mode_info_context = cm->prev_mi + mi_idx;
+  // Special case: if prev_mi is NULL, the previous mode info context
+  // cannot be used.
+  xd->prev_mode_info_context = cm->prev_mi ?
+                                 cm->prev_mi + mi_idx : NULL;
 
   for (i = 0; i < MAX_MB_PLANE; i++) {
     xd->plane[i].above_context = cm->above_context[i] +
@@ -1098,6 +1101,8 @@
   // clear out the coeff buffer
   for (i = 0; i < MAX_MB_PLANE; ++i)
     vp9_zero(xd->plane[i].qcoeff);
+
+  set_prev_mi(pc);
 
   vp9_decode_mode_mvs_init(pbi, &header_bc);
 
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -551,7 +551,10 @@
   x->partition_info          = x->pi + idx_str;
   xd->mode_info_context      = cm->mi + idx_str;
   mbmi = &xd->mode_info_context->mbmi;
-  xd->prev_mode_info_context = cm->prev_mi + idx_str;
+  // Special case: if prev_mi is NULL, the previous mode info context
+  // cannot be used.
+  xd->prev_mode_info_context = cm->prev_mi ?
+                                 cm->prev_mi + idx_str : NULL;
 
   // Set up destination pointers
   setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col);
@@ -1201,6 +1204,8 @@
   vpx_memset(cpi->txfm_count_8x8p, 0, sizeof(cpi->txfm_count_8x8p));
   vpx_memset(cpi->rd_tx_select_diff, 0, sizeof(cpi->rd_tx_select_diff));
   vpx_memset(cpi->rd_tx_select_threshes, 0, sizeof(cpi->rd_tx_select_threshes));
+
+  set_prev_mi(cm);
 
   {
     struct vpx_usec_timer  emr_timer;
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -3545,6 +3545,8 @@
                cm->mode_info_stride * (cm->mi_rows + 1) *
                sizeof(MODE_INFO));
   }
+  // restore prev_mi
+  cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1;
 }
 
 static void Pass2Encode(VP9_COMP *cpi, unsigned long *size,
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -1751,7 +1751,6 @@
   YV12_BUFFER_CONFIG *yv12 = &cm->yv12_fb[cpi->common.ref_frame_map[idx]];
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
-  int use_prev_in_find_mv_refs;
 
   // set up scaling factors
   scale[frame_type] = cpi->common.active_ref_scale[frame_type - 1];
@@ -1768,11 +1767,8 @@
                    &scale[frame_type], &scale[frame_type]);
 
   // Gets an initial list of candidate vectors from neighbours and orders them
-  use_prev_in_find_mv_refs = cm->width == cm->last_width &&
-                             cm->height == cm->last_height &&
-                             !cpi->common.error_resilient_mode;
   vp9_find_mv_refs(&cpi->common, xd, xd->mode_info_context,
-                   use_prev_in_find_mv_refs ? xd->prev_mode_info_context : NULL,
+                   xd->prev_mode_info_context,
                    frame_type,
                    mbmi->ref_mvs[frame_type],
                    cpi->common.ref_frame_sign_bias);
--