Remove probability model for comp_ref_type

Change-Id: Ib4b83335ba9c61435f774136bc57638d8b88e963
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c
index d264e37..eedbed2 100644
--- a/av1/common/entropymode.c
+++ b/av1/common/entropymode.c
@@ -1405,9 +1405,6 @@
             { AOM_CDF2(2842) } };
 
 #if CONFIG_EXT_COMP_REFS
-static const aom_prob default_comp_ref_type_p[COMP_REF_TYPE_CONTEXTS] = {
-  8, 20, 78, 91, 194
-};
 static const aom_prob
     default_uni_comp_ref_p[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1] = {
       { 88, 30, 28 }, { 218, 97, 105 }, { 254, 180, 196 }
@@ -3300,7 +3297,6 @@
 #endif  // CONFIG_EXT_INTRA_MOD
   av1_copy(fc->comp_inter_cdf, default_comp_inter_cdf);
 #if CONFIG_EXT_COMP_REFS
-  av1_copy(fc->comp_ref_type_prob, default_comp_ref_type_p);
   av1_copy(fc->uni_comp_ref_prob, default_uni_comp_ref_p);
   av1_copy(fc->comp_ref_type_cdf, default_comp_ref_type_cdf);
   av1_copy(fc->uni_comp_ref_cdf, default_uni_comp_ref_cdf);
@@ -3404,10 +3400,6 @@
   const FRAME_COUNTS *counts = &cm->counts;
 
 #if CONFIG_EXT_COMP_REFS
-  for (i = 0; i < COMP_REF_TYPE_CONTEXTS; i++)
-    fc->comp_ref_type_prob[i] = av1_mode_mv_merge_probs(
-        pre_fc->comp_ref_type_prob[i], counts->comp_ref_type[i]);
-
   for (i = 0; i < UNI_COMP_REF_CONTEXTS; i++)
     for (j = 0; j < (UNIDIR_COMP_REFS - 1); j++)
       fc->uni_comp_ref_prob[i][j] = av1_mode_mv_merge_probs(
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index 7487bb6..e24f492 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -161,7 +161,6 @@
   aom_cdf_prob comp_inter_cdf[COMP_INTER_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob single_ref_cdf[REF_CONTEXTS][SINGLE_REFS - 1][CDF_SIZE(2)];
 #if CONFIG_EXT_COMP_REFS
-  aom_prob comp_ref_type_prob[COMP_REF_TYPE_CONTEXTS];
   aom_prob uni_comp_ref_prob[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1];
   aom_cdf_prob comp_ref_type_cdf[COMP_REF_TYPE_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob uni_comp_ref_cdf[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1]
@@ -322,7 +321,9 @@
   unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
 #endif  // CONFIG_ENTROPY_STATS
 #if CONFIG_EXT_COMP_REFS
+#if CONFIG_ENTROPY_STATS
   unsigned int comp_ref_type[COMP_REF_TYPE_CONTEXTS][2];
+#endif  // CONFIG_ENTROPY_STATS
   unsigned int uni_comp_ref[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1][2];
 #endif  // CONFIG_EXT_COMP_REFS
 #if CONFIG_ENTROPY_STATS
diff --git a/av1/common/pred_common.h b/av1/common/pred_common.h
index ccd82a5..73c8f99 100644
--- a/av1/common/pred_common.h
+++ b/av1/common/pred_common.h
@@ -200,11 +200,6 @@
 #if CONFIG_EXT_COMP_REFS
 int av1_get_comp_reference_type_context(const MACROBLOCKD *xd);
 
-static INLINE aom_prob av1_get_comp_reference_type_prob(const AV1_COMMON *cm,
-                                                        const MACROBLOCKD *xd) {
-  return cm->fc->comp_ref_type_prob[av1_get_comp_reference_type_context(xd)];
-}
-
 int av1_get_pred_context_uni_comp_ref_p(const MACROBLOCKD *xd);
 
 static INLINE aom_prob av1_get_pred_prob_uni_comp_ref_p(const AV1_COMMON *cm,
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 4edea3a..3284f1e 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -3133,8 +3133,6 @@
   assert(!memcmp(cm->counts.intra_inter, zero_counts.intra_inter,
                  sizeof(cm->counts.intra_inter)));
 #if CONFIG_EXT_COMP_REFS
-  assert(!memcmp(cm->counts.comp_ref_type, zero_counts.comp_ref_type,
-                 sizeof(cm->counts.comp_ref_type)));
   assert(!memcmp(cm->counts.uni_comp_ref, zero_counts.uni_comp_ref,
                  sizeof(cm->counts.uni_comp_ref)));
 #endif  // CONFIG_EXT_COMP_REFS
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 788e253..45e7a17 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1289,8 +1289,6 @@
   const COMP_REFERENCE_TYPE comp_ref_type =
       (COMP_REFERENCE_TYPE)aom_read_symbol(
           r, xd->tile_ctx->comp_ref_type_cdf[ctx], 2, ACCT_STR);
-  FRAME_COUNTS *counts = xd->counts;
-  if (counts) ++counts->comp_ref_type[ctx][comp_ref_type];
   return comp_ref_type;  // UNIDIR_COMP_REFERENCE or BIDIR_COMP_REFERENCE
 }
 #endif  // CONFIG_EXT_COMP_REFS
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 017ed1e..7bbc201 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -285,6 +285,10 @@
 
   int comp_inter_cost[COMP_INTER_CONTEXTS][2];
   int single_ref_cost[REF_CONTEXTS][SINGLE_REFS - 1][2];
+#if CONFIG_EXT_COMP_REFS
+  int comp_ref_type_cost[COMP_REF_TYPE_CONTEXTS]
+                        [CDF_SIZE(COMP_REFERENCE_TYPES)];
+#endif  // CONFIG_EXT_COMP_REFS
   int inter_compound_mode_cost[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES];
 #if CONFIG_JNT_COMP
   int compound_type_cost[BLOCK_SIZES_ALL][COMPOUND_TYPES - 1];
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index e4b2b62..169d7cd 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -901,8 +901,14 @@
           const COMP_REFERENCE_TYPE comp_ref_type = has_uni_comp_refs(mbmi)
                                                         ? UNIDIR_COMP_REFERENCE
                                                         : BIDIR_COMP_REFERENCE;
+          if (allow_update_cdf) {
+            update_cdf(av1_get_comp_reference_type_cdf(xd), comp_ref_type,
+                       COMP_REFERENCE_TYPES);
+          }
+#if CONFIG_ENTROPY_STATS
           counts->comp_ref_type[av1_get_comp_reference_type_context(xd)]
                                [comp_ref_type]++;
+#endif  // CONFIG_ENTROPY_STATS
 
           if (comp_ref_type == UNIDIR_COMP_REFERENCE) {
             const int bit = (ref0 == BWDREF_FRAME);
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 2213991..59d2d47 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -238,6 +238,13 @@
       }
     }
 
+#if CONFIG_EXT_COMP_REFS
+    for (i = 0; i < REF_CONTEXTS; ++i) {
+      av1_cost_tokens_from_cdf(x->comp_ref_type_cost[i],
+                               fc->comp_ref_type_cdf[i], NULL);
+    }
+#endif  // CONFIG_EXT_COMP_REFS
+
     for (i = 0; i < INTRA_INTER_CONTEXTS; ++i) {
       av1_cost_tokens_from_cdf(x->intra_inter_cost[i], fc->intra_inter_cdf[i],
                                NULL);
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 6cd32e2..d3e321f 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -5892,12 +5892,12 @@
       aom_prob bwdref_comp_p1 = av1_get_pred_prob_comp_bwdref_p1(cm, xd);
 
 #if CONFIG_EXT_COMP_REFS
-      aom_prob comp_ref_type_p = av1_get_comp_reference_type_prob(cm, xd);
+      const int comp_ref_type_ctx = av1_get_comp_reference_type_context(xd);
       unsigned int ref_bicomp_costs[TOTAL_REFS_PER_FRAME] = { 0 };
 
       ref_bicomp_costs[LAST_FRAME] = ref_bicomp_costs[LAST2_FRAME] =
           ref_bicomp_costs[LAST3_FRAME] = ref_bicomp_costs[GOLDEN_FRAME] =
-              base_cost + av1_cost_bit(comp_ref_type_p, 1);
+              base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][1];
       ref_bicomp_costs[BWDREF_FRAME] = ref_bicomp_costs[ALTREF2_FRAME] = 0;
       ref_bicomp_costs[ALTREF_FRAME] = 0;
 
@@ -5932,19 +5932,18 @@
       aom_prob uni_comp_ref_p2 = av1_get_pred_prob_uni_comp_ref_p2(cm, xd);
 
       ref_costs_comp[LAST_FRAME][LAST2_FRAME] =
-          base_cost + av1_cost_bit(comp_ref_type_p, 0) +
+          base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][0] +
           av1_cost_bit(uni_comp_ref_p, 0) + av1_cost_bit(uni_comp_ref_p1, 0);
       ref_costs_comp[LAST_FRAME][LAST3_FRAME] =
-          base_cost + av1_cost_bit(comp_ref_type_p, 0) +
+          base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][0] +
           av1_cost_bit(uni_comp_ref_p, 0) + av1_cost_bit(uni_comp_ref_p1, 1) +
           av1_cost_bit(uni_comp_ref_p2, 0);
       ref_costs_comp[LAST_FRAME][GOLDEN_FRAME] =
-          base_cost + av1_cost_bit(comp_ref_type_p, 0) +
+          base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][0] +
           av1_cost_bit(uni_comp_ref_p, 0) + av1_cost_bit(uni_comp_ref_p1, 1) +
           av1_cost_bit(uni_comp_ref_p2, 1);
-
       ref_costs_comp[BWDREF_FRAME][ALTREF_FRAME] =
-          base_cost + av1_cost_bit(comp_ref_type_p, 0) +
+          base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][0] +
           av1_cost_bit(uni_comp_ref_p, 1);
 
 #else   // !CONFIG_EXT_COMP_REFS