]> granicus.if.org Git - libvpx/commitdiff
Added two new skip experiments.
authorPaul Wilkins <paulwilkins@google.com>
Mon, 1 Jul 2013 15:27:12 +0000 (16:27 +0100)
committerPaul Wilkins <paulwilkins@google.com>
Wed, 3 Jul 2013 15:56:06 +0000 (16:56 +0100)
sf->unused_mode_skip_lvl. Tests modes as normal for all
sizes at or below the given level. At larger sizes it skips
all modes that were not chosen at any smaller size.
Hence setting BLOCK_SIZE_SB64X64 is in effect off.
Setting BLOCK_SIZE_AB4X4 will only consider modes that
were chosen for one or more 4x4 blocks at larger sizes.

sf->reference_masking.
Do a test encode of the NONE partition at one size and create
a reference frame mask based on the best rd choice. In the
full search only allow this reference frame.
Currently it is testing 64x64 and repeats this in the full search.
This does not work well with Jim's Partition code just now and
is disabled by default.

Change-Id: I8f8c52d2ef4a0c08100150b0ea4155d1aaab93dd

vp9/encoder/vp9_encodeframe.c
vp9/encoder/vp9_onyx_if.c
vp9/encoder/vp9_onyx_int.h
vp9/encoder/vp9_rdopt.c

index 6a2177b6905b2a18ace3ffa85512f18ed1cd3aa5..3b17c367fb909b0b2000e9b58df06da64790224a 100644 (file)
@@ -1573,6 +1573,58 @@ static void rd_pick_partition(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row,
   }
 }
 
+// Examines 64x64 block and chooses a best reference frame
+static void rd_pick_reference_frame(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row,
+                                    int mi_col, int *rate, int64_t *dist) {
+  VP9_COMMON * const cm = &cpi->common;
+  MACROBLOCK * const x = &cpi->mb;
+  MACROBLOCKD * const xd = &x->e_mbd;
+  int bsl = b_width_log2(BLOCK_SIZE_SB64X64), bs = 1 << bsl;
+  int ms = bs / 2;
+  ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE];
+  PARTITION_CONTEXT sl[8], sa[8];
+  int pl;
+  int r;
+  int64_t d;
+
+  save_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_SIZE_SB64X64);
+
+  // Default is non mask (all reference frames allowed.
+  cpi->ref_frame_mask = 0;
+
+  // Do RD search for 64x64.
+  if ((mi_row + (ms >> 1) < cm->mi_rows) &&
+      (mi_col + (ms >> 1) < cm->mi_cols)) {
+    cpi->set_ref_frame_mask = 1;
+    pick_sb_modes(cpi, mi_row, mi_col, tp, &r, &d, BLOCK_SIZE_SB64X64,
+                  get_block_context(x, BLOCK_SIZE_SB64X64));
+    set_partition_seg_context(cm, xd, mi_row, mi_col);
+    pl = partition_plane_context(xd, BLOCK_SIZE_SB64X64);
+    r += x->partition_cost[pl][PARTITION_NONE];
+
+    *(get_sb_partitioning(x, BLOCK_SIZE_SB64X64)) = BLOCK_SIZE_SB64X64;
+    cpi->set_ref_frame_mask = 0;
+  }
+
+  *rate = r;
+  *dist = d;
+  // RDCOST(x->rdmult, x->rddiv, r, d)
+
+  restore_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_SIZE_SB64X64);
+
+  /*if (srate < INT_MAX && sdist < INT_MAX)
+    encode_sb(cpi, tp, mi_row, mi_col, 1, BLOCK_SIZE_SB64X64);
+
+  if (bsize == BLOCK_SIZE_SB64X64) {
+    assert(tp_orig < *tp);
+    assert(srate < INT_MAX);
+    assert(sdist < INT_MAX);
+  } else {
+    assert(tp_orig == *tp);
+  }
+  */
+}
+
 static void encode_sb_row(VP9_COMP *cpi, int mi_row, TOKENEXTRA **tp,
                           int *totalrate) {
   VP9_COMMON * const cm = &cpi->common;
@@ -1587,6 +1639,19 @@ static void encode_sb_row(VP9_COMP *cpi, int mi_row, TOKENEXTRA **tp,
       mi_col += 64 / MI_SIZE) {
     int dummy_rate;
     int64_t dummy_dist;
+
+    // Initialize a mask of modes that we will not consider;
+    // cpi->unused_mode_skip_mask = 0x0000000AAE17F800 (test no golden)
+    if (cpi->common.frame_type == KEY_FRAME)
+      cpi->unused_mode_skip_mask = 0;
+    else
+      cpi->unused_mode_skip_mask = 0xFFFFFFFFFFFFFE00;
+
+    if (cpi->sf.reference_masking) {
+      rd_pick_reference_frame(cpi, tp, mi_row, mi_col,
+                              &dummy_rate, &dummy_dist);
+    }
+
     if (cpi->sf.partition_by_variance || cpi->sf.use_lastframe_partitioning ||
         cpi->sf.use_one_partition_size_always ) {
       const int idx_str = cm->mode_info_stride * mi_row + mi_col;
index af257048ce493bf83c6133616efe0433d25fcc8b..6fa9f8e5e89536786fa9a0f36ba47f90def8daab 100644 (file)
@@ -704,6 +704,7 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
   sf->tx_size_search_method = USE_FULL_RD;
   sf->use_8tap_always = 0;
   sf->use_avoid_tested_higherror = 0;
+  sf->reference_masking = 0;
   sf->skip_lots_of_modes = 0;
   sf->adjust_thresholds_by_speed = 0;
   sf->partition_by_variance = 0;
@@ -719,6 +720,10 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
   sf->disable_splitmv = 0;
   sf->conditional_oblique_intramodes = 0;
 
+  // Skip any mode not chosen at size < X for all sizes > X
+  // Hence BLOCK_SIZE_SB64X64 (skip is off)
+  sf->unused_mode_skip_lvl = BLOCK_SIZE_SB64X64;
+
 #if CONFIG_MULTIPLE_ARF
   // Switch segmentation off.
   sf->static_segmentation = 0;
@@ -741,7 +746,6 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
       sf->auto_mv_step_size = 1;
       sf->use_avoid_tested_higherror = 1;
       sf->adaptive_rd_thresh = 1;
-
       if (speed == 1) {
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
         sf->less_rectangular_check  = 1;
@@ -756,19 +760,22 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
         sf->use_square_partition_only = !(cpi->common.frame_type == KEY_FRAME ||
                                    cpi->common.intra_only ||
                                    cpi->common.show_frame == 0);
+        sf->unused_mode_skip_lvl = BLOCK_SIZE_SB32X32;
       }
       if (speed == 2) {
         sf->adjust_thresholds_by_speed = 1;
         sf->less_rectangular_check  = 1;
         sf->use_square_partition_only = 1;
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
-        sf->reduce_first_step_size = 1;
-        sf->optimize_coefficients = 0;
         sf->use_lastframe_partitioning = 1;
         sf->adjust_partitioning_from_last_frame = 1;
         sf->last_partitioning_redo_frequency = 3;
         sf->tx_size_search_method = USE_LARGESTALL;
         sf->conditional_oblique_intramodes = 1;
+        sf->unused_mode_skip_lvl = BLOCK_SIZE_SB32X32;
+        sf->reduce_first_step_size = 1;
+        sf->optimize_coefficients = 0;
+        // sf->reference_masking = 1;
       }
       if (speed == 3) {
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
index d325896b356e5606a2c1ed79c253bd0d149507a1..96a55b9483ec1502ede12f3add8f97f854788540 100644 (file)
@@ -235,6 +235,8 @@ typedef struct {
   int use_one_partition_size_always;
   int less_rectangular_check;
   int use_square_partition_only;
+  int unused_mode_skip_lvl;
+  int reference_masking;
   BLOCK_SIZE_TYPE always_this_block_size;
   int use_partitions_greater_than;
   BLOCK_SIZE_TYPE greater_than_block_size;
@@ -343,6 +345,9 @@ typedef struct VP9_COMP {
   unsigned int mode_check_freq[MAX_MODES];
   unsigned int mode_test_hit_counts[MAX_MODES];
   unsigned int mode_chosen_counts[MAX_MODES];
+  int64_t unused_mode_skip_mask;
+  int ref_frame_mask;
+  int set_ref_frame_mask;
 
   int rd_thresh_mult[MAX_MODES];
   int rd_baseline_thresh[BLOCK_SIZE_TYPES][MAX_MODES];
index 06f90d6cb958847d933b411e183f6127fcc5a0b2..a3710f45fdf21a05684c1409bed9c0e0cb27f69b 100644 (file)
@@ -3002,6 +3002,19 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
     for (i = 0; i < NB_TXFM_MODES; ++i)
       txfm_cache[i] = INT64_MAX;
 
+    this_mode = vp9_mode_order[mode_index].mode;
+    ref_frame = vp9_mode_order[mode_index].ref_frame;
+
+    // Slip modes that have been masked off but always consider first mode.
+    if ( mode_index && (bsize > cpi->sf.unused_mode_skip_lvl) &&
+         (cpi->unused_mode_skip_mask & (1 << mode_index)) )
+      continue;
+
+    // Skip if the current refernce frame has been masked off
+    if (cpi->sf.reference_masking && !cpi->set_ref_frame_mask &&
+        (cpi->ref_frame_mask & (1 << ref_frame)))
+      continue;
+
     // Test best rd so far against threshold for trying this mode.
     if ((best_rd < ((cpi->rd_threshes[bsize][mode_index] *
                      cpi->rd_thresh_freq_fact[bsize][mode_index]) >> 4)) ||
@@ -3015,8 +3028,6 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
       continue;
 
     x->skip = 0;
-    this_mode = vp9_mode_order[mode_index].mode;
-    ref_frame = vp9_mode_order[mode_index].ref_frame;
 
     if (cpi->sf.use_avoid_tested_higherror && bsize >= BLOCK_SIZE_SB8X8) {
       if (!(ref_frame_mask & (1 << ref_frame))) {
@@ -3523,6 +3534,19 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
     if (x->skip && !mode_excluded)
       break;
   }
+
+  // If indicated then mark the index of the chosen mode to be inspected at
+  // other block sizes.
+  if (bsize <= cpi->sf.unused_mode_skip_lvl) {
+    cpi->unused_mode_skip_mask = cpi->unused_mode_skip_mask &
+                                 (~((int64_t)1 << best_mode_index));
+  }
+
+  // If we are using reference masking and the set mask flag is set then
+  // create the reference frame mask.
+  if (cpi->sf.reference_masking && cpi->set_ref_frame_mask)
+    cpi->ref_frame_mask = ~(1 << vp9_mode_order[best_mode_index].ref_frame);
+
   // Flag all modes that have a distortion thats > 2x the best we found at
   // this level.
   for (mode_index = 0; mode_index < MB_MODE_COUNT; ++mode_index) {