shithub: libvpx

Download patch

ref: 14ee2805a3b2e9c51d677d834326256b1ada1690
parent: 7feede986917eca0ab18ba72be1502a88abc54ac
author: Yunqing Wang <[email protected]>
date: Wed Sep 24 06:24:18 EDT 2014

Refactor encode_rd_sb_row function

Simplified the code and removed some code that was not used anymore.
This patch didn't change encoding result.

Change-Id: I7e54a74c8f35a6726dfc8a1c55b337448b7ea124

--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -2456,9 +2456,15 @@
        mi_col += MI_BLOCK_SIZE) {
     int dummy_rate;
     int64_t dummy_dist;
-
     int i;
 
+    const int idx_str = cm->mi_stride * mi_row + mi_col;
+    MODE_INFO *mi = cm->mi + idx_str;
+    MODE_INFO *prev_mi = NULL;
+
+    if (cm->frame_type != KEY_FRAME)
+      prev_mi = (cm->prev_mip + cm->mi_stride + 1 + idx_str)->src_mi;
+
     if (sf->adaptive_pred_interp_filter) {
       for (i = 0; i < 64; ++i)
         cpi->leaf_tree[i].pred_interp_filter = SWITCHABLE;
@@ -2477,71 +2483,44 @@
     // TODO(yunqingwang): use_lastframe_partitioning is no longer used in good-
     // quality encoding. Need to evaluate it in real-time encoding later to
     // decide if it can be removed too. And then, do the code cleanup.
-    if ((sf->partition_search_type == SEARCH_PARTITION &&
-         sf->use_lastframe_partitioning) ||
-         sf->partition_search_type == FIXED_PARTITION ||
-         sf->partition_search_type == VAR_BASED_PARTITION ||
-         sf->partition_search_type == VAR_BASED_FIXED_PARTITION) {
-      const int idx_str = cm->mi_stride * mi_row + mi_col;
-      MODE_INFO *mi = cm->mi + idx_str;
-      MODE_INFO *prev_mi = (cm->prev_mip + cm->mi_stride + 1 + idx_str)->src_mi;
-      cpi->mb.source_variance = UINT_MAX;
-      if (sf->partition_search_type == FIXED_PARTITION) {
-        set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64);
-        set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col,
-                               sf->always_this_block_size);
+    cpi->mb.source_variance = UINT_MAX;
+    if (sf->partition_search_type == FIXED_PARTITION) {
+      set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64);
+      set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col,
+                             sf->always_this_block_size);
+      rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64,
+                       &dummy_rate, &dummy_dist, 1, cpi->pc_root);
+    } else if ((sf->use_lastframe_partitioning && cpi->skippable_frame) ||
+               sf->partition_search_type == VAR_BASED_FIXED_PARTITION) {
+      BLOCK_SIZE bsize;
+      set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64);
+      bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col);
+      set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize);
+      rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64,
+                       &dummy_rate, &dummy_dist, 1, cpi->pc_root);
+    } else if (sf->partition_search_type == VAR_BASED_PARTITION) {
+      choose_partitioning(cpi, tile, mi_row, mi_col);
+      rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64,
+                       &dummy_rate, &dummy_dist, 1, cpi->pc_root);
+    } else if (sf->partition_search_type == SEARCH_PARTITION &&
+               sf->use_lastframe_partitioning &&
+               (cpi->rc.frames_since_key %
+                   sf->last_partitioning_redo_frequency) &&
+               cm->prev_mi &&
+               cm->show_frame &&
+               cm->frame_type != KEY_FRAME &&
+               !cpi->rc.is_src_frame_alt_ref &&
+               ((sf->use_lastframe_partitioning !=
+                   LAST_FRAME_PARTITION_LOW_MOTION) ||
+                   !sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))) {
+      if (sf->constrain_copy_partition &&
+          sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))
+        constrain_copy_partitioning(cpi, tile, mi, prev_mi,
+                                    mi_row, mi_col, BLOCK_16X16);
+      else
+        copy_partitioning(cm, mi, prev_mi);
         rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64,
                          &dummy_rate, &dummy_dist, 1, cpi->pc_root);
-      } else if (cpi->skippable_frame ||
-                 sf->partition_search_type == VAR_BASED_FIXED_PARTITION) {
-        BLOCK_SIZE bsize;
-        set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64);
-        bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col);
-        set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize);
-        rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64,
-                         &dummy_rate, &dummy_dist, 1, cpi->pc_root);
-      } else if (sf->partition_search_type == VAR_BASED_PARTITION) {
-        choose_partitioning(cpi, tile, mi_row, mi_col);
-        rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64,
-                         &dummy_rate, &dummy_dist, 1, cpi->pc_root);
-      } else {
-        GF_GROUP * gf_grp = &cpi->twopass.gf_group;
-        int last_was_mid_sequence_overlay = 0;
-        if ((cpi->oxcf.pass == 2) && (gf_grp->index)) {
-          if (gf_grp->update_type[gf_grp->index - 1] == OVERLAY_UPDATE)
-            last_was_mid_sequence_overlay = 1;
-        }
-        if ((cpi->rc.frames_since_key
-            % sf->last_partitioning_redo_frequency) == 0
-            || last_was_mid_sequence_overlay
-            || cm->prev_mi == 0
-            || cm->show_frame == 0
-            || cm->frame_type == KEY_FRAME
-            || cpi->rc.is_src_frame_alt_ref
-            || ((sf->use_lastframe_partitioning ==
-                 LAST_FRAME_PARTITION_LOW_MOTION) &&
-                 sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))) {
-          // If required set upper and lower partition size limits
-          if (sf->auto_min_max_partition_size) {
-            set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64);
-            rd_auto_partition_range(cpi, tile, mi_row, mi_col,
-                                    &sf->min_partition_size,
-                                    &sf->max_partition_size);
-          }
-          rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64,
-                            &dummy_rate, &dummy_dist, INT64_MAX,
-                            cpi->pc_root);
-        } else {
-          if (sf->constrain_copy_partition &&
-              sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))
-            constrain_copy_partitioning(cpi, tile, mi, prev_mi,
-                                        mi_row, mi_col, BLOCK_16X16);
-          else
-            copy_partitioning(cm, mi, prev_mi);
-          rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64,
-                           &dummy_rate, &dummy_dist, 1, cpi->pc_root);
-        }
-      }
     } else {
       // If required set upper and lower partition size limits
       if (sf->auto_min_max_partition_size) {
@@ -2551,7 +2530,8 @@
                                 &sf->max_partition_size);
       }
       rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64,
-                        &dummy_rate, &dummy_dist, INT64_MAX, cpi->pc_root);
+                        &dummy_rate, &dummy_dist, INT64_MAX,
+                        cpi->pc_root);
     }
   }
 }