]> granicus.if.org Git - libvpx/commitdiff
Port "Better workaround for Bug 1089." to vp10 (nextgenv2).
authorAlex Converse <aconverse@google.com>
Wed, 17 Feb 2016 22:24:46 +0000 (14:24 -0800)
committerAlex Converse <aconverse@google.com>
Mon, 22 Feb 2016 18:19:03 +0000 (10:19 -0800)
Don't initialize first pass costs for a number of symbols where first
pass probabilities aren't initialized.

As a side effect, an illegal read in the ANS experiment is fixed.

https://bugs.chromium.org/p/webm/issues/detail?id=1089

Change-Id: I97438c357bd88f52f5a15c697031cf0c3cc8f510

vp10/common/entropy.c
vp10/encoder/cost.c
vp10/encoder/cost.h
vp10/encoder/rd.c

index f60bcf5d4b7b1eb44b15f1977faae2ce03dce0c3..8c7e27a9bc471ace02b2f4b271be494247621a31 100644 (file)
@@ -1023,10 +1023,8 @@ static const vp10_coeff_probs_model default_coef_probs_32x32[PLANE_TYPES] = {
 };
 
 static void extend_to_full_distribution(vpx_prob *probs, vpx_prob p) {
-  // TODO(aconverse): model[PIVOT_NODE] should never be zero.
-  // https://code.google.com/p/webm/issues/detail?id=1089
-  memcpy(probs, vp10_pareto8_full[p == 0 ? 254 : p - 1],
-         MODEL_NODES * sizeof(vpx_prob));
+  assert(p != 0);
+  memcpy(probs, vp10_pareto8_full[p - 1], MODEL_NODES * sizeof(vpx_prob));
 }
 
 void vp10_model_to_full_probs(const vpx_prob *model, vpx_prob *full) {
index 7e33edf19b5c79a9ee715beb7a3de95c828ec974..0ed41405ec4e6f629c1fd10b308aa51c133e79ae 100644 (file)
@@ -13,9 +13,8 @@
 #include "vp10/common/entropy.h"
 
 /* round(-log2(i/256.) * (1 << VP9_PROB_COST_SHIFT))
-   Begins and ends with a bogus entry to satisfy use of prob=0 in the firstpass.
-   https://code.google.com/p/webm/issues/detail?id=1089 */
-const uint16_t vp10_prob_cost[257] = {
+   Begins with a bogus entry for simpler addressing. */
+const uint16_t vp10_prob_cost[256] = {
     4096, 4096, 3584, 3284, 3072, 2907, 2772, 2659, 2560, 2473, 2395, 2325,
     2260, 2201, 2147, 2096, 2048, 2003, 1961, 1921, 1883, 1847, 1813, 1780,
     1748, 1718, 1689, 1661, 1635, 1609, 1584, 1559, 1536, 1513, 1491, 1470,
@@ -37,13 +36,14 @@ const uint16_t vp10_prob_cost[257] = {
     125,  122,  119,  115,  112,  109,  105,  102,  99,   95,   92,   89,
     86,   82,   79,   76,   73,   70,   66,   63,   60,   57,   54,   51,
     48,   45,   42,   38,   35,   32,   29,   26,   23,   20,   18,   15,
-    12,   9,    6,    3,     3};
+    12,   9,    6,    3};
 
 static void cost(int *costs, vpx_tree tree, const vpx_prob *probs,
                  int i, int c) {
   const vpx_prob prob = probs[i / 2];
   int b;
 
+  assert(prob != 0);
   for (b = 0; b <= 1; ++b) {
     const int cc = c + vp10_cost_bit(prob, b);
     const vpx_tree_index ii = tree[i + b];
index d4a9efb81306ba9fbc2cdadedd60b978ef47501d..56d91001f2a72be7eb4cd36d698fb0587b8f58c5 100644 (file)
@@ -18,7 +18,7 @@
 extern "C" {
 #endif
 
-extern const uint16_t vp10_prob_cost[257];
+extern const uint16_t vp10_prob_cost[256];
 
 // The factor to scale from cost in bits to cost in vp10_prob_cost units.
 #define VP9_PROB_COST_SHIFT 9
index 299b7612b4dc90d04af8b5781f52a0195c68360b..044ced1a33bc0f06052892806741d2cea992810d 100644 (file)
@@ -361,84 +361,87 @@ void vp10_initialize_rd_consts(VP10_COMP *cpi) {
 
   set_block_thresholds(cm, rd);
 
-  fill_token_costs(x->token_costs, cm->fc->coef_probs);
-
-  if (cpi->sf.partition_search_type != VAR_BASED_PARTITION ||
-      cm->frame_type == KEY_FRAME) {
-    for (i = 0; i < PARTITION_CONTEXTS; ++i)
-      vp10_cost_tokens(cpi->partition_cost[i], cm->fc->partition_prob[i],
-                      vp10_partition_tree);
-  }
-
-  fill_mode_costs(cpi);
-
   if (!frame_is_intra_only(cm)) {
 #if CONFIG_REF_MV
     int nmv_ctx;
     for (nmv_ctx = 0; nmv_ctx < NMV_CONTEXTS; ++nmv_ctx) {
-      vp10_build_nmv_cost_table(x->nmv_vec_cost[nmv_ctx],
-                                cm->allow_high_precision_mv ?
-                                  x->nmvcost_hp[nmv_ctx] : x->nmvcost[nmv_ctx],
-                                &cm->fc->nmvc[nmv_ctx],
-                                cm->allow_high_precision_mv);
+      vp10_build_nmv_cost_table(
+          x->nmv_vec_cost[nmv_ctx],
+          cm->allow_high_precision_mv ? x->nmvcost_hp[nmv_ctx]
+                                      : x->nmvcost[nmv_ctx],
+          &cm->fc->nmvc[nmv_ctx], cm->allow_high_precision_mv);
     }
     x->mvcost = x->mv_cost_stack[0];
     x->nmvjointcost = x->nmv_vec_cost[0];
     x->mvsadcost = x->mvcost;
     x->nmvjointsadcost = x->nmvjointcost;
 #else
-    vp10_build_nmv_cost_table(x->nmvjointcost,
-                             cm->allow_high_precision_mv ? x->nmvcost_hp
-                                                         : x->nmvcost,
-                             &cm->fc->nmvc, cm->allow_high_precision_mv);
+    vp10_build_nmv_cost_table(
+        x->nmvjointcost,
+        cm->allow_high_precision_mv ? x->nmvcost_hp : x->nmvcost, &cm->fc->nmvc,
+        cm->allow_high_precision_mv);
 #endif
+  }
+  if (cpi->oxcf.pass != 1) {
+    fill_token_costs(x->token_costs, cm->fc->coef_probs);
+
+    if (cpi->sf.partition_search_type != VAR_BASED_PARTITION ||
+        cm->frame_type == KEY_FRAME) {
+      for (i = 0; i < PARTITION_CONTEXTS; ++i)
+        vp10_cost_tokens(cpi->partition_cost[i], cm->fc->partition_prob[i],
+                         vp10_partition_tree);
+    }
+
+    fill_mode_costs(cpi);
 
+    if (!frame_is_intra_only(cm)) {
 #if CONFIG_REF_MV
-    for (i = 0; i < NEWMV_MODE_CONTEXTS; ++i) {
-      cpi->newmv_mode_cost[i][0] = vp10_cost_bit(cm->fc->newmv_prob[i], 0);
-      cpi->newmv_mode_cost[i][1] = vp10_cost_bit(cm->fc->newmv_prob[i], 1);
-    }
+      for (i = 0; i < NEWMV_MODE_CONTEXTS; ++i) {
+        cpi->newmv_mode_cost[i][0] = vp10_cost_bit(cm->fc->newmv_prob[i], 0);
+        cpi->newmv_mode_cost[i][1] = vp10_cost_bit(cm->fc->newmv_prob[i], 1);
+      }
 
-    for (i = 0; i < ZEROMV_MODE_CONTEXTS; ++i) {
-      cpi->zeromv_mode_cost[i][0] = vp10_cost_bit(cm->fc->zeromv_prob[i], 0);
-      cpi->zeromv_mode_cost[i][1] = vp10_cost_bit(cm->fc->zeromv_prob[i], 1);
-    }
+      for (i = 0; i < ZEROMV_MODE_CONTEXTS; ++i) {
+        cpi->zeromv_mode_cost[i][0] = vp10_cost_bit(cm->fc->zeromv_prob[i], 0);
+        cpi->zeromv_mode_cost[i][1] = vp10_cost_bit(cm->fc->zeromv_prob[i], 1);
+      }
 
-    for (i = 0; i < REFMV_MODE_CONTEXTS; ++i) {
-      cpi->refmv_mode_cost[i][0] = vp10_cost_bit(cm->fc->refmv_prob[i], 0);
-      cpi->refmv_mode_cost[i][1] = vp10_cost_bit(cm->fc->refmv_prob[i], 1);
-    }
+      for (i = 0; i < REFMV_MODE_CONTEXTS; ++i) {
+        cpi->refmv_mode_cost[i][0] = vp10_cost_bit(cm->fc->refmv_prob[i], 0);
+        cpi->refmv_mode_cost[i][1] = vp10_cost_bit(cm->fc->refmv_prob[i], 1);
+      }
 
-    for (i = 0; i < DRL_MODE_CONTEXTS; ++i) {
-      cpi->drl_mode_cost0[i][0] = vp10_cost_bit(cm->fc->drl_prob0[i], 0);
-      cpi->drl_mode_cost0[i][1] = vp10_cost_bit(cm->fc->drl_prob0[i], 1);
-    }
+      for (i = 0; i < DRL_MODE_CONTEXTS; ++i) {
+        cpi->drl_mode_cost0[i][0] = vp10_cost_bit(cm->fc->drl_prob0[i], 0);
+        cpi->drl_mode_cost0[i][1] = vp10_cost_bit(cm->fc->drl_prob0[i], 1);
+      }
 
-    for (i = 0; i < DRL_MODE_CONTEXTS; ++i) {
-      cpi->drl_mode_cost1[i][0] = vp10_cost_bit(cm->fc->drl_prob1[i], 0);
-      cpi->drl_mode_cost1[i][1] = vp10_cost_bit(cm->fc->drl_prob1[i], 1);
-    }
+      for (i = 0; i < DRL_MODE_CONTEXTS; ++i) {
+        cpi->drl_mode_cost1[i][0] = vp10_cost_bit(cm->fc->drl_prob1[i], 0);
+        cpi->drl_mode_cost1[i][1] = vp10_cost_bit(cm->fc->drl_prob1[i], 1);
+      }
 #if CONFIG_EXT_INTER
-    cpi->new2mv_mode_cost[0] = vp10_cost_bit(cm->fc->new2mv_prob, 0);
-    cpi->new2mv_mode_cost[1] = vp10_cost_bit(cm->fc->new2mv_prob, 1);
+      cpi->new2mv_mode_cost[0] = vp10_cost_bit(cm->fc->new2mv_prob, 0);
+      cpi->new2mv_mode_cost[1] = vp10_cost_bit(cm->fc->new2mv_prob, 1);
 #endif  // CONFIG_EXT_INTER
 #else
-    for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
-      vp10_cost_tokens((int *)cpi->inter_mode_cost[i],
-                      cm->fc->inter_mode_probs[i], vp10_inter_mode_tree);
+      for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
+        vp10_cost_tokens((int *)cpi->inter_mode_cost[i],
+                         cm->fc->inter_mode_probs[i], vp10_inter_mode_tree);
 #endif
 #if CONFIG_EXT_INTER
-    for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
-      vp10_cost_tokens((int *)cpi->inter_compound_mode_cost[i],
-                       cm->fc->inter_compound_mode_probs[i],
-                       vp10_inter_compound_mode_tree);
+      for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
+        vp10_cost_tokens((int *)cpi->inter_compound_mode_cost[i],
+                         cm->fc->inter_compound_mode_probs[i],
+                         vp10_inter_compound_mode_tree);
 #endif  // CONFIG_EXT_INTER
 #if CONFIG_OBMC
-    for (i = BLOCK_8X8; i < BLOCK_SIZES; i++) {
-      cpi->obmc_cost[i][0] = vp10_cost_bit(cm->fc->obmc_prob[i], 0);
-      cpi->obmc_cost[i][1] = vp10_cost_bit(cm->fc->obmc_prob[i], 1);
-    }
+      for (i = BLOCK_8X8; i < BLOCK_SIZES; i++) {
+        cpi->obmc_cost[i][0] = vp10_cost_bit(cm->fc->obmc_prob[i], 0);
+        cpi->obmc_cost[i][1] = vp10_cost_bit(cm->fc->obmc_prob[i], 1);
+      }
 #endif  // CONFIG_OBMC
+    }
   }
 }