shithub: libvpx

Download patch

ref: a43ff15399e6c841bffa32a7c191d6885772b22a
parent: 44db42c1142d9e893f0e07f3ac00d16b4c6c0532
author: Deb Mukherjee <[email protected]>
date: Mon Jun 10 08:00:43 EDT 2013

New probs for filters/tx_size and a few others

* New probs for subpel filters/tx_count
* Makes a change to not reset to defaults for the tx_size
probs if an intermediate frame reverts to using a fixed tx_size.
* A few updates to the parameters for backward adaptation for mode/mv
* some cosmetic cleanups

derf300: +0.06%

Change-Id: I22994d659bc31ca7a4fc8820fde24001e64a2920

--- a/vp9/common/vp9_coefupdateprobs.h
+++ b/vp9/common/vp9_coefupdateprobs.h
@@ -14,8 +14,6 @@
 /* Update probabilities for the nodes in the token entropy tree.
    Generated file included by vp9_entropy.c */
 
-#define VP9_DEF_UPDATE_PROB 252
-
 static const vp9_prob vp9_coef_update_prob[UNCONSTRAINED_NODES] = {
   252, 252, 252,
 };
--- a/vp9/common/vp9_entropymode.c
+++ b/vp9/common/vp9_entropymode.c
@@ -149,36 +149,21 @@
   { 238, 247 }
 };
 
-#if TX_SIZE_CONTEXTS == 2
 const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_CONTEXTS]
                                           [TX_SIZE_MAX_SB - 1] = {
-  { 16, 32, 64, },
-  { 16, 32, 64, },
+  { 3, 136, 37, },
+  { 5, 52, 13, },
 };
 const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_CONTEXTS]
                                           [TX_SIZE_MAX_SB - 2] = {
-  { 32, 64, },
-  { 32, 64, },
+  { 20, 152, },
+  { 15, 101, },
 };
 const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_CONTEXTS]
                                         [TX_SIZE_MAX_SB - 3] = {
-  { 64, },
-  { 64, },
+  { 100, },
+  { 66, },
 };
-#else
-const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_CONTEXTS]
-                                          [TX_SIZE_MAX_SB - 1] = {
-  { 16, 32, 64, },
-};
-const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_CONTEXTS]
-                                          [TX_SIZE_MAX_SB - 2] = {
-  { 32, 64, },
-};
-const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_CONTEXTS]
-                                        [TX_SIZE_MAX_SB - 3] = {
-  { 64, },
-};
-#endif
 
 void tx_counts_to_branch_counts_32x32(unsigned int *tx_count_32x32p,
                                       unsigned int (*ct_32x32p)[2]) {
@@ -254,7 +239,10 @@
 const int vp9_switchable_interp_map[SWITCHABLE+1] = {1, 0, 2, -1, -1};
 const vp9_prob vp9_switchable_interp_prob [VP9_SWITCHABLE_FILTERS+1]
                                           [VP9_SWITCHABLE_FILTERS-1] = {
-  {248, 192}, { 32, 248}, { 32,  32}, {192, 160}
+  { 235, 162, },
+  { 36, 255, },
+  { 34, 3, },
+  { 149, 144, },
 };
 
 // Indicates if the filter is interpolating or non-interpolating
@@ -324,7 +312,7 @@
 }
 
 #define MODE_COUNT_SAT 20
-#define MODE_MAX_UPDATE_FACTOR 144
+#define MODE_MAX_UPDATE_FACTOR 128
 static int update_mode_ct(vp9_prob pre_prob, vp9_prob prob,
                           unsigned int branch_ct[2]) {
   int factor, count = branch_ct[0] + branch_ct[1];
--- a/vp9/common/vp9_entropymode.h
+++ b/vp9/common/vp9_entropymode.h
@@ -17,6 +17,8 @@
 #define SUBMVREF_COUNT 5
 #define TX_SIZE_CONTEXTS 2
 
+#define VP9_MODE_UPDATE_PROB  252
+
 // #define MODE_STATS
 
 extern int vp9_mv_cont(const int_mv *l, const int_mv *a);
--- a/vp9/common/vp9_entropymv.c
+++ b/vp9/common/vp9_entropymv.c
@@ -14,8 +14,8 @@
 
 //#define MV_COUNT_TESTING
 
-#define MV_COUNT_SAT 16
-#define MV_MAX_UPDATE_FACTOR 160
+#define MV_COUNT_SAT 20
+#define MV_MAX_UPDATE_FACTOR 128
 
 /* Integer pel reference mv threshold for use of high-precision 1/8 mv */
 #define COMPANDED_MVREF_THRESH    8
--- a/vp9/common/vp9_entropymv.h
+++ b/vp9/common/vp9_entropymv.h
@@ -24,7 +24,7 @@
 void vp9_adapt_nmv_probs(struct VP9Common *cm, int usehp);
 int vp9_use_nmv_hp(const MV *ref);
 
-#define VP9_NMV_UPDATE_PROB  255
+#define VP9_NMV_UPDATE_PROB  252
 
 //#define MV_GROUP_UPDATE
 
--- a/vp9/common/vp9_pred_common.c
+++ b/vp9/common/vp9_pred_common.c
@@ -349,7 +349,6 @@
     }
 
     case PRED_TX_SIZE: {
-#if TX_SIZE_CONTEXTS == 2
       int above_context, left_context;
       int max_tx_size;
       if (mi->mbmi.sb_type < BLOCK_SIZE_SB8X8)
@@ -376,9 +375,6 @@
         above_context = left_context;
       }
       pred_context = (above_context + left_context > max_tx_size);
-#else
-      pred_context = 0;
-#endif
       break;
     }
 
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -307,7 +307,7 @@
   int i, j;
   for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j)
     for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) {
-      if (vp9_read(r, VP9_DEF_UPDATE_PROB)) {
+      if (vp9_read(r, VP9_MODE_UPDATE_PROB)) {
         cm->fc.switchable_interp_prob[j][i] =
             // vp9_read_prob(r);
             vp9_read_prob_diff_update(r, cm->fc.switchable_interp_prob[j][i]);
@@ -319,7 +319,7 @@
   int i, j;
   for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
     for (j = 0; j < VP9_INTER_MODES - 1; ++j) {
-      if (vp9_read(r, VP9_DEF_UPDATE_PROB)) {
+      if (vp9_read(r, VP9_MODE_UPDATE_PROB)) {
         // cm->fc.inter_mode_probs[i][j] = vp9_read_prob(r);
         cm->fc.inter_mode_probs[i][j] =
             vp9_read_prob_diff_update(r, cm->fc.inter_mode_probs[i][j]);
@@ -348,7 +348,7 @@
       read_switchable_interp_probs(cm, r);
 
     for (i = 0; i < INTRA_INTER_CONTEXTS; i++) {
-      if (vp9_read(r, VP9_DEF_UPDATE_PROB))
+      if (vp9_read(r, VP9_MODE_UPDATE_PROB))
         cm->fc.intra_inter_prob[i] =
             vp9_read_prob_diff_update(r, cm->fc.intra_inter_prob[i]);
     }
@@ -357,7 +357,7 @@
       cm->comp_pred_mode = read_comp_pred_mode(r);
       if (cm->comp_pred_mode == HYBRID_PREDICTION)
         for (i = 0; i < COMP_INTER_CONTEXTS; i++)
-          if (vp9_read(r, VP9_DEF_UPDATE_PROB))
+          if (vp9_read(r, VP9_MODE_UPDATE_PROB))
             cm->fc.comp_inter_prob[i] =
                 vp9_read_prob_diff_update(r, cm->fc.comp_inter_prob[i]);
     } else {
@@ -366,10 +366,10 @@
 
     if (cm->comp_pred_mode != COMP_PREDICTION_ONLY)
       for (i = 0; i < REF_CONTEXTS; i++) {
-        if (vp9_read(r, VP9_DEF_UPDATE_PROB))
+        if (vp9_read(r, VP9_MODE_UPDATE_PROB))
           cm->fc.single_ref_prob[i][0] =
               vp9_read_prob_diff_update(r, cm->fc.single_ref_prob[i][0]);
-        if (vp9_read(r, VP9_DEF_UPDATE_PROB))
+        if (vp9_read(r, VP9_MODE_UPDATE_PROB))
           cm->fc.single_ref_prob[i][1] =
               vp9_read_prob_diff_update(r, cm->fc.single_ref_prob[i][1]);
       }
@@ -376,7 +376,7 @@
 
     if (cm->comp_pred_mode != SINGLE_PREDICTION_ONLY)
       for (i = 0; i < REF_CONTEXTS; i++)
-        if (vp9_read(r, VP9_DEF_UPDATE_PROB))
+        if (vp9_read(r, VP9_MODE_UPDATE_PROB))
           cm->fc.comp_ref_prob[i] =
               vp9_read_prob_diff_update(r, cm->fc.comp_ref_prob[i]);
 
@@ -383,7 +383,7 @@
     // VP9_INTRA_MODES
     for (j = 0; j < BLOCK_SIZE_GROUPS; j++) {
       for (i = 0; i < VP9_INTRA_MODES - 1; ++i) {
-        if (vp9_read(r, VP9_DEF_UPDATE_PROB)) {
+        if (vp9_read(r, VP9_MODE_UPDATE_PROB)) {
           cm->fc.y_mode_prob[j][i] =
               vp9_read_prob_diff_update(r, cm->fc.y_mode_prob[j][i]);
         }
@@ -391,7 +391,7 @@
     }
     for (j = 0; j < NUM_PARTITION_CONTEXTS; ++j) {
       for (i = 0; i < PARTITION_TYPES - 1; ++i) {
-        if (vp9_read(r, VP9_DEF_UPDATE_PROB)) {
+        if (vp9_read(r, VP9_MODE_UPDATE_PROB)) {
           cm->fc.partition_prob[INTER_FRAME][j][i] =
               vp9_read_prob_diff_update(r,
                   cm->fc.partition_prob[INTER_FRAME][j][i]);
@@ -797,7 +797,7 @@
   // TODO(jkoleszar): does this clear more than MBSKIP_CONTEXTS? Maybe remove.
   // vpx_memset(cm->fc.mbskip_probs, 0, sizeof(cm->fc.mbskip_probs));
   for (k = 0; k < MBSKIP_CONTEXTS; ++k) {
-    if (vp9_read(r, VP9_DEF_UPDATE_PROB)) {
+    if (vp9_read(r, VP9_MODE_UPDATE_PROB)) {
       cm->fc.mbskip_probs[k] =
           vp9_read_prob_diff_update(r, cm->fc.mbskip_probs[k]);
     }
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -61,7 +61,7 @@
       int i, j;
       for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
         for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j) {
-          if (vp9_read(r, VP9_DEF_UPDATE_PROB))
+          if (vp9_read(r, VP9_MODE_UPDATE_PROB))
             pc->fc.tx_probs_8x8p[i][j] =
                 vp9_read_prob_diff_update(r, pc->fc.tx_probs_8x8p[i][j]);
         }
@@ -68,7 +68,7 @@
       }
       for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
         for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j) {
-          if (vp9_read(r, VP9_DEF_UPDATE_PROB))
+          if (vp9_read(r, VP9_MODE_UPDATE_PROB))
             pc->fc.tx_probs_16x16p[i][j] =
                 vp9_read_prob_diff_update(r, pc->fc.tx_probs_16x16p[i][j]);
         }
@@ -75,18 +75,11 @@
       }
       for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
         for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j) {
-          if (vp9_read(r, VP9_DEF_UPDATE_PROB))
+          if (vp9_read(r, VP9_MODE_UPDATE_PROB))
             pc->fc.tx_probs_32x32p[i][j] =
                 vp9_read_prob_diff_update(r, pc->fc.tx_probs_32x32p[i][j]);
         }
       }
-    } else {
-      vpx_memcpy(pc->fc.tx_probs_8x8p, vp9_default_tx_probs_8x8p,
-                 sizeof(vp9_default_tx_probs_8x8p));
-      vpx_memcpy(pc->fc.tx_probs_16x16p, vp9_default_tx_probs_16x16p,
-                 sizeof(vp9_default_tx_probs_16x16p));
-      vpx_memcpy(pc->fc.tx_probs_32x32p, vp9_default_tx_probs_32x32p,
-                 sizeof(vp9_default_tx_probs_32x32p));
     }
   }
 }
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -55,6 +55,8 @@
 int64_t tx_count_32x32p_stats[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB];
 int64_t tx_count_16x16p_stats[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 1];
 int64_t tx_count_8x8p_stats[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 2];
+int64_t switchable_interp_stats[VP9_SWITCHABLE_FILTERS+1]
+                               [VP9_SWITCHABLE_FILTERS];
 
 void init_tx_count_stats() {
   vp9_zero(tx_count_32x32p_stats);
@@ -62,6 +64,10 @@
   vp9_zero(tx_count_8x8p_stats);
 }
 
+void init_switchable_interp_stats() {
+  vp9_zero(switchable_interp_stats);
+}
+
 static void update_tx_count_stats(VP9_COMMON *cm) {
   int i, j;
   for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
@@ -81,6 +87,14 @@
   }
 }
 
+static void update_switchable_interp_stats(VP9_COMMON *cm) {
+  int i, j;
+  for (i = 0; i < VP9_SWITCHABLE_FILTERS+1; ++i)
+    for (j = 0; j < VP9_SWITCHABLE_FILTERS; ++j) {
+      switchable_interp_stats[i][j] += cm->fc.switchable_interp_count[i][j];
+    }
+}
+
 void write_tx_count_stats() {
   int i, j;
   FILE *fp = fopen("tx_count.bin", "wb");
@@ -120,6 +134,25 @@
   }
   printf("};\n");
 }
+
+void write_switchable_interp_stats() {
+  int i, j;
+  FILE *fp = fopen("switchable_interp.bin", "wb");
+  fwrite(switchable_interp_stats, sizeof(switchable_interp_stats), 1, fp);
+  fclose(fp);
+
+  printf(
+      "vp9_default_switchable_filter_count[VP9_SWITCHABLE_FILTERS+1]"
+      "[VP9_SWITCHABLE_FILTERS] = {\n");
+  for (i = 0; i < VP9_SWITCHABLE_FILTERS+1; i++) {
+    printf("  { ");
+    for (j = 0; j < VP9_SWITCHABLE_FILTERS; j++) {
+      printf("%"PRId64", ", switchable_interp_stats[i][j]);
+    }
+    printf("},\n");
+  }
+  printf("};\n");
+}
 #endif
 
 static int update_bits[255];
@@ -387,7 +420,7 @@
   n--;
 
   for (i = 0; i < n; ++i) {
-    vp9_cond_prob_diff_update(w, &Pcur[i], VP9_DEF_UPDATE_PROB, bct[i]);
+    vp9_cond_prob_diff_update(w, &Pcur[i], VP9_MODE_UPDATE_PROB, bct[i]);
   }
 }
 
@@ -411,11 +444,7 @@
 
   for (k = 0; k < MBSKIP_CONTEXTS; ++k) {
     vp9_cond_prob_diff_update(bc, &pc->fc.mbskip_probs[k],
-                              VP9_DEF_UPDATE_PROB, pc->fc.mbskip_count[k]);
-    /*
-    pc->fc.mbskip_probs[k] = get_binary_prob(pc->fc.mbskip_count[k][0],
-                                                  pc->fc.mbskip_count[k][1]);
-                                                  */
+                              VP9_MODE_UPDATE_PROB, pc->fc.mbskip_count[k]);
   }
 }
 
@@ -423,8 +452,9 @@
   write_token(bc, vp9_intra_mode_tree, p, vp9_intra_mode_encodings + m);
 }
 
-static void update_switchable_interp_probs(VP9_COMMON *const pc,
+static void update_switchable_interp_probs(VP9_COMP *const cpi,
                                            vp9_writer* const bc) {
+  VP9_COMMON *const pc = &cpi->common;
   unsigned int branch_ct[VP9_SWITCHABLE_FILTERS + 1]
                         [VP9_SWITCHABLE_FILTERS - 1][2];
   vp9_prob new_prob[VP9_SWITCHABLE_FILTERS + 1][VP9_SWITCHABLE_FILTERS - 1];
@@ -437,12 +467,14 @@
   }
   for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j) {
     for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) {
-      // vp9_cond_prob_update(bc, &pc->fc.switchable_interp_prob[j][i],
-      //                      VP9_DEF_UPDATE_PROB, branch_ct[j][i]);
       vp9_cond_prob_diff_update(bc, &pc->fc.switchable_interp_prob[j][i],
-                                VP9_DEF_UPDATE_PROB, branch_ct[j][i]);
+                                VP9_MODE_UPDATE_PROB, branch_ct[j][i]);
     }
   }
+#ifdef MODE_STATS
+  if (!cpi->dummy_packing)
+    update_switchable_interp_stats(pc);
+#endif
 }
 
 static void update_inter_mode_probs(VP9_COMMON *pc, vp9_writer* const bc) {
@@ -451,11 +483,8 @@
   for (i = 0; i < INTER_MODE_CONTEXTS; i++) {
     for (j = 0; j < VP9_INTER_MODES - 1; j++) {
       vp9_cond_prob_diff_update(bc, &pc->fc.inter_mode_probs[i][j],
-                                VP9_DEF_UPDATE_PROB,
+                                VP9_MODE_UPDATE_PROB,
                                 pc->fc.inter_mode_counts[i][j]);
-      // vp9_cond_prob_update(
-      //     bc, &pc->fc.inter_mode_probs[i][j],
-      //     VP9_DEF_UPDATE_PROB, pc->fc.inter_mode_counts[i][j]);
     }
   }
 }
@@ -1309,7 +1338,7 @@
                                      ct_8x8p);
       for (j = 0; j < TX_SIZE_MAX_SB - 3; j++) {
         vp9_cond_prob_diff_update(w, &cm->fc.tx_probs_8x8p[i][j],
-                                  VP9_DEF_UPDATE_PROB, ct_8x8p[j]);
+                                  VP9_MODE_UPDATE_PROB, ct_8x8p[j]);
       }
     }
     for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
@@ -1317,7 +1346,7 @@
                                        ct_16x16p);
       for (j = 0; j < TX_SIZE_MAX_SB - 2; j++) {
         vp9_cond_prob_diff_update(w, &cm->fc.tx_probs_16x16p[i][j],
-                                  VP9_DEF_UPDATE_PROB, ct_16x16p[j]);
+                                  VP9_MODE_UPDATE_PROB, ct_16x16p[j]);
       }
     }
     for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
@@ -1325,19 +1354,13 @@
                                        ct_32x32p);
       for (j = 0; j < TX_SIZE_MAX_SB - 1; j++) {
         vp9_cond_prob_diff_update(w, &cm->fc.tx_probs_32x32p[i][j],
-                                  VP9_DEF_UPDATE_PROB, ct_32x32p[j]);
+                                  VP9_MODE_UPDATE_PROB, ct_32x32p[j]);
       }
     }
 #ifdef MODE_STATS
-    update_tx_count_stats(cm);
+    if (!cpi->dummy_packing)
+      update_tx_count_stats(cm);
 #endif
-  } else {
-    vpx_memcpy(cm->fc.tx_probs_32x32p, vp9_default_tx_probs_32x32p,
-               sizeof(vp9_default_tx_probs_32x32p));
-    vpx_memcpy(cm->fc.tx_probs_16x16p, vp9_default_tx_probs_16x16p,
-               sizeof(vp9_default_tx_probs_16x16p));
-    vpx_memcpy(cm->fc.tx_probs_8x8p, vp9_default_tx_probs_8x8p,
-               sizeof(vp9_default_tx_probs_8x8p));
   }
 }
 
@@ -1635,11 +1658,12 @@
     vp9_zero(cpi->common.fc.inter_mode_counts);
 
     if (pc->mcomp_filter_type == SWITCHABLE)
-      update_switchable_interp_probs(pc, &header_bc);
+      update_switchable_interp_probs(cpi, &header_bc);
 
     for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
       vp9_cond_prob_diff_update(&header_bc, &pc->fc.intra_inter_prob[i],
-                                VP9_DEF_UPDATE_PROB, cpi->intra_inter_count[i]);
+                                VP9_MODE_UPDATE_PROB,
+                                cpi->intra_inter_count[i]);
 
     if (pc->allow_comp_inter_inter) {
       const int comp_pred_mode = cpi->common.comp_pred_mode;
@@ -1652,7 +1676,7 @@
         if (use_hybrid_pred) {
           for (i = 0; i < COMP_INTER_CONTEXTS; i++)
             vp9_cond_prob_diff_update(&header_bc, &pc->fc.comp_inter_prob[i],
-                                      VP9_DEF_UPDATE_PROB,
+                                      VP9_MODE_UPDATE_PROB,
                                       cpi->comp_inter_count[i]);
         }
       }
@@ -1661,10 +1685,10 @@
     if (pc->comp_pred_mode != COMP_PREDICTION_ONLY) {
       for (i = 0; i < REF_CONTEXTS; i++) {
         vp9_cond_prob_diff_update(&header_bc, &pc->fc.single_ref_prob[i][0],
-                                  VP9_DEF_UPDATE_PROB,
+                                  VP9_MODE_UPDATE_PROB,
                                   cpi->single_ref_count[i][0]);
         vp9_cond_prob_diff_update(&header_bc, &pc->fc.single_ref_prob[i][1],
-                                  VP9_DEF_UPDATE_PROB,
+                                  VP9_MODE_UPDATE_PROB,
                                   cpi->single_ref_count[i][1]);
       }
     }
@@ -1672,7 +1696,7 @@
     if (pc->comp_pred_mode != SINGLE_PREDICTION_ONLY) {
       for (i = 0; i < REF_CONTEXTS; i++)
         vp9_cond_prob_diff_update(&header_bc, &pc->fc.comp_ref_prob[i],
-                                  VP9_DEF_UPDATE_PROB,
+                                  VP9_MODE_UPDATE_PROB,
                                   cpi->comp_ref_count[i]);
     }
 
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -110,6 +110,8 @@
 #ifdef MODE_STATS
 extern void init_tx_count_stats();
 extern void write_tx_count_stats();
+extern void init_switchable_interp_stats();
+extern void write_switchable_interp_stats();
 #endif
 
 #ifdef SPEEDSTATS
@@ -1293,6 +1295,7 @@
 #endif
 #ifdef MODE_STATS
   init_tx_count_stats();
+  init_switchable_interp_stats();
 #endif
 
   /*Initialize the feed-forward activity masking.*/
@@ -1543,8 +1546,10 @@
       print_nmvstats();
 #endif
 #ifdef MODE_STATS
-    if (cpi->pass != 1)
+    if (cpi->pass != 1) {
       write_tx_count_stats();
+      write_switchable_interp_stats();
+    }
 #endif
 
 #if CONFIG_INTERNAL_STATS