Merge "Further changes to new-quant tables" into nextgenv2
diff --git a/av1/common/entropymv.c b/av1/common/entropymv.c
index b1547ef..34918b3 100644
--- a/av1/common/entropymv.c
+++ b/av1/common/entropymv.c
@@ -42,12 +42,7 @@
                                                                4,  -2, -3 };
 
 static const nmv_context default_nmv_context = {
-#if CONFIG_REF_MV
-  { 1, 64, 96 },
-  128,
-#else
   { 32, 64, 96 },
-#endif
   { {
         // Vertical component
         128,                                                   // sign
@@ -175,11 +170,6 @@
 void av1_inc_mv(const MV *mv, nmv_context_counts *counts, const int usehp) {
   if (counts != NULL) {
     const MV_JOINT_TYPE j = av1_get_mv_joint(mv);
-
-#if CONFIG_REF_MV
-    ++counts->zero_rmv[j == MV_JOINT_ZERO];
-    if (j == MV_JOINT_ZERO) return;
-#endif
     ++counts->joints[j];
 
     if (mv_joint_vertical(j))
@@ -202,8 +192,6 @@
 
     aom_tree_merge_probs(av1_mv_joint_tree, pre_fc->joints, counts->joints,
                          fc->joints);
-    fc->zero_rmv = av1_mode_mv_merge_probs(pre_fc->zero_rmv, counts->zero_rmv);
-
     for (i = 0; i < 2; ++i) {
       nmv_component *comp = &fc->comps[i];
       const nmv_component *pre_comp = &pre_fc->comps[i];
diff --git a/av1/common/entropymv.h b/av1/common/entropymv.h
index f1d997d..f97dd85 100644
--- a/av1/common/entropymv.h
+++ b/av1/common/entropymv.h
@@ -95,9 +95,6 @@
 
 typedef struct {
   aom_prob joints[MV_JOINTS - 1];
-#if CONFIG_REF_MV
-  aom_prob zero_rmv;
-#endif
   nmv_component comps[2];
 } nmv_context;
 
@@ -124,9 +121,6 @@
 
 typedef struct {
   unsigned int joints[MV_JOINTS];
-#if CONFIG_REF_MV
-  unsigned int zero_rmv[2];
-#endif
   nmv_component_counts comps[2];
 } nmv_context_counts;
 
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index cc5d640..a3c751c 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -197,10 +197,6 @@
 
   update_mv_probs(ctx->joints, MV_JOINTS - 1, r);
 
-#if CONFIG_REF_MV
-  av1_diff_update_prob(r, &ctx->zero_rmv);
-#endif
-
   for (i = 0; i < 2; ++i) {
     nmv_component *const comp_ctx = &ctx->comps[i];
     update_mv_probs(&comp_ctx->sign, 1, r);
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index c6152e3..dab1008 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -686,35 +686,12 @@
 }
 
 static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
-#if CONFIG_REF_MV
-                           int is_compound,
-#endif
                            const nmv_context *ctx, nmv_context_counts *counts,
                            int allow_hp) {
   MV_JOINT_TYPE joint_type;
   const int use_hp = allow_hp && av1_use_mv_hp(ref);
   MV diff = { 0, 0 };
-
-#if CONFIG_REF_MV && !CONFIG_EXT_INTER
-  if (is_compound) {
-    int is_zero_rmv = aom_read(r, ctx->zero_rmv);
-    if (is_zero_rmv) {
-      joint_type = MV_JOINT_ZERO;
-    } else {
-      joint_type =
-          (MV_JOINT_TYPE)aom_read_tree(r, av1_mv_joint_tree, ctx->joints);
-    }
-  } else {
-    joint_type =
-        (MV_JOINT_TYPE)aom_read_tree(r, av1_mv_joint_tree, ctx->joints);
-  }
-#else
   joint_type = (MV_JOINT_TYPE)aom_read_tree(r, av1_mv_joint_tree, ctx->joints);
-#endif
-
-#if CONFIG_REF_MV && CONFIG_EXT_INTER
-  (void)is_compound;
-#endif
 
   if (mv_joint_vertical(joint_type))
     diff.row = read_mv_component(r, &ctx->comps[0], use_hp);
@@ -971,8 +948,8 @@
                         mbmi->ref_mv_idx);
         nmv_context_counts *const mv_counts =
             counts ? &counts->mv[nmv_ctx] : NULL;
-        read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, is_compound,
-                &cm->fc->nmvc[nmv_ctx], mv_counts, allow_hp);
+        read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc[nmv_ctx],
+                mv_counts, allow_hp);
 #else
         read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc, mv_counts,
                 allow_hp);
@@ -1038,8 +1015,8 @@
                         mbmi->ref_mv_idx);
         nmv_context_counts *const mv_counts =
             counts ? &counts->mv[nmv_ctx] : NULL;
-        read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, is_compound,
-                &cm->fc->nmvc[nmv_ctx], mv_counts, allow_hp);
+        read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc[nmv_ctx],
+                mv_counts, allow_hp);
 #else
         read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc, mv_counts,
                 allow_hp);
@@ -1080,8 +1057,8 @@
                                 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
       nmv_context_counts *const mv_counts =
           counts ? &counts->mv[nmv_ctx] : NULL;
-      read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, is_compound,
-              &cm->fc->nmvc[nmv_ctx], mv_counts, allow_hp);
+      read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, &cm->fc->nmvc[nmv_ctx],
+              mv_counts, allow_hp);
 #else
       nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
       read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, &cm->fc->nmvc, mv_counts,
@@ -1101,8 +1078,8 @@
       nmv_context_counts *const mv_counts =
           counts ? &counts->mv[nmv_ctx] : NULL;
       mv[0].as_int = nearest_mv[0].as_int;
-      read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, is_compound,
-              &cm->fc->nmvc[nmv_ctx], mv_counts, allow_hp);
+      read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, &cm->fc->nmvc[nmv_ctx],
+              mv_counts, allow_hp);
 #else
       nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
       mv[0].as_int = nearest_mv[0].as_int;
@@ -1122,8 +1099,8 @@
       nmv_context_counts *const mv_counts =
           counts ? &counts->mv[nmv_ctx] : NULL;
       mv[0].as_int = near_mv[0].as_int;
-      read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, is_compound,
-              &cm->fc->nmvc[nmv_ctx], mv_counts, allow_hp);
+      read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, &cm->fc->nmvc[nmv_ctx],
+              mv_counts, allow_hp);
 #else
       nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
       mv[0].as_int = near_mv[0].as_int;
@@ -1143,8 +1120,8 @@
                                 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
       nmv_context_counts *const mv_counts =
           counts ? &counts->mv[nmv_ctx] : NULL;
-      read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, is_compound,
-              &cm->fc->nmvc[nmv_ctx], mv_counts, allow_hp);
+      read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, &cm->fc->nmvc[nmv_ctx],
+              mv_counts, allow_hp);
 #else
       nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
       read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, &cm->fc->nmvc, mv_counts,
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index e3b4e37..2156032 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -116,8 +116,6 @@
   int *nmvcost_hp[NMV_CONTEXTS][2];
   int **mv_cost_stack[NMV_CONTEXTS];
   int *nmvjointsadcost;
-  int zero_rmv_cost[NMV_CONTEXTS][2];
-  int comp_rmv_cost[2];
 #else
   int nmvjointcost[MV_JOINTS];
   int *nmvcost[2];
diff --git a/av1/encoder/encodemv.c b/av1/encoder/encodemv.c
index bcd9b11..13c8d87 100644
--- a/av1/encoder/encodemv.c
+++ b/av1/encoder/encodemv.c
@@ -164,8 +164,6 @@
     write_mv_update(av1_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS,
                     w);
 
-    av1_cond_prob_diff_update(w, &mvc->zero_rmv, counts->zero_rmv);
-
     for (i = 0; i < 2; ++i) {
       nmv_component *comp = &mvc->comps[i];
       nmv_component_counts *comp_counts = &counts->comps[i];
@@ -242,20 +240,9 @@
   const MV diff = { mv->row - ref->row, mv->col - ref->col };
   const MV_JOINT_TYPE j = av1_get_mv_joint(&diff);
   usehp = usehp && av1_use_mv_hp(ref);
-
-#if CONFIG_REF_MV && !CONFIG_EXT_INTER
-  if (is_compound) {
-    aom_write(w, (j == MV_JOINT_ZERO), mvctx->zero_rmv);
-    if (j == MV_JOINT_ZERO) return;
-  } else {
-    if (j == MV_JOINT_ZERO) assert(0);
-  }
-#endif
-
-#if CONFIG_REF_MV && CONFIG_EXT_INTER
+#if CONFIG_REF_MV
   (void)is_compound;
 #endif
-
   av1_write_token(w, av1_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]);
   if (mv_joint_vertical(j))
     encode_mv_component(w, diff.row, &mvctx->comps[0], usehp);
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 4d157ff..007f992 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -346,9 +346,6 @@
   x->nmvjointcost = x->nmv_vec_cost[nmv_ctx];
   x->mvsadcost = x->mvcost;
   x->nmvjointsadcost = x->nmvjointcost;
-
-  x->nmv_vec_cost[nmv_ctx][MV_JOINT_ZERO] =
-      x->zero_rmv_cost[nmv_ctx][1] - x->zero_rmv_cost[nmv_ctx][0];
 }
 #endif
 
@@ -372,21 +369,11 @@
     int nmv_ctx;
 
     for (nmv_ctx = 0; nmv_ctx < NMV_CONTEXTS; ++nmv_ctx) {
-      aom_prob tmp_prob = cm->fc->nmvc[nmv_ctx].joints[MV_JOINT_ZERO];
-      cm->fc->nmvc[nmv_ctx].joints[MV_JOINT_ZERO] = 1;
-
       av1_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);
-      cm->fc->nmvc[nmv_ctx].joints[MV_JOINT_ZERO] = tmp_prob;
-
-      x->nmv_vec_cost[nmv_ctx][MV_JOINT_ZERO] = 0;
-      x->zero_rmv_cost[nmv_ctx][0] =
-          av1_cost_bit(cm->fc->nmvc[nmv_ctx].zero_rmv, 0);
-      x->zero_rmv_cost[nmv_ctx][1] =
-          av1_cost_bit(cm->fc->nmvc[nmv_ctx].zero_rmv, 1);
     }
     x->mvcost = x->mv_cost_stack[0];
     x->nmvjointcost = x->nmv_vec_cost[0];
diff --git a/test/decode_to_md5.sh b/test/decode_to_md5.sh
index fbed152..9e557d3 100755
--- a/test/decode_to_md5.sh
+++ b/test/decode_to_md5.sh
@@ -16,10 +16,9 @@
 . $(dirname $0)/tools_common.sh
 
 # Environment check: Make sure input is available:
-#   $VP8_IVF_FILE and $AV1_IVF_FILE are required.
+#   $AOM_IVF_FILE and $AV1_IVF_FILE are required.
 decode_to_md5_verify_environment() {
-  if [ ! -e "${VP8_IVF_FILE}" ] || [ ! -e "${AV1_IVF_FILE}" ]; then
-    echo "Libaom test data must exist in LIBVPX_TEST_DATA_PATH."
+  if [ "$(av1_encode_available)" != "yes" ] && [ ! -e "${AV1_IVF_FILE}" ]; then
     return 1
   fi
 }
@@ -49,25 +48,20 @@
   [ "${actual_md5}" = "${expected_md5}" ] || return 1
 }
 
-decode_to_md5_vp8() {
-  # expected MD5 sum for the last frame.
-  local expected_md5="56794d911b02190212bca92f88ad60c6"
-
-  if [ "$(vp8_decode_available)" = "yes" ]; then
-    decode_to_md5 "${VP8_IVF_FILE}" "vp8" "${expected_md5}"
-  fi
-}
-
 decode_to_md5_av1() {
   # expected MD5 sum for the last frame.
-  local expected_md5="2952c0eae93f3dadd1aa84c50d3fd6d2"
+  local expected_md5="fef4c2a45fb89ef5f3a156d4a59aadc0"
+  local file="${AV1_IVF_FILE}"
 
   if [ "$(av1_decode_available)" = "yes" ]; then
-    decode_to_md5 "${AV1_IVF_FILE}" "av1" "${expected_md5}"
+    if [ ! -e "${AV1_IVF_FILE}" ]; then
+      file="${AOM_TEST_OUTPUT_DIR}/test_encode.ivf"
+      encode_yuv_raw_input_av1 "${file}" --ivf
+    fi
+    decode_to_md5 "${file}" "av1" "${expected_md5}"
   fi
 }
 
-decode_to_md5_tests="decode_to_md5_vp8
-                     decode_to_md5_av1"
+decode_to_md5_tests="decode_to_md5_av1"
 
 run_tests decode_to_md5_verify_environment "${decode_to_md5_tests}"
diff --git a/test/decode_with_drops.sh b/test/decode_with_drops.sh
index 00a9dc7..5978312 100755
--- a/test/decode_with_drops.sh
+++ b/test/decode_with_drops.sh
@@ -16,10 +16,9 @@
 . $(dirname $0)/tools_common.sh
 
 # Environment check: Make sure input is available:
-#   $VP8_IVF_FILE and $AV1_IVF_FILE are required.
+#   $AOM_IVF_FILE and $AV1_IVF_FILE are required.
 decode_with_drops_verify_environment() {
-  if [ ! -e "${VP8_IVF_FILE}" ] || [ ! -e "${AV1_IVF_FILE}" ]; then
-    echo "Libaom test data must exist in LIBVPX_TEST_DATA_PATH."
+  if [ "$(av1_encode_available)" != "yes" ] && [ ! -e "${AV1_IVF_FILE}" ]; then
     return 1
   fi
 }
@@ -45,35 +44,24 @@
   [ -e "${output_file}" ] || return 1
 }
 
-# Decodes $VP8_IVF_FILE while dropping frames, twice: once in sequence mode,
-# and once in pattern mode.
-# Note: This test assumes that $VP8_IVF_FILE has exactly 29 frames, and could
-# break if the file is modified.
-decode_with_drops_vp8() {
-  if [ "$(vp8_decode_available)" = "yes" ]; then
-    # Test sequence mode: Drop frames 2-28.
-    decode_with_drops "${VP8_IVF_FILE}" "vp8" "2-28"
-
-    # Test pattern mode: Drop 3 of every 4 frames.
-    decode_with_drops "${VP8_IVF_FILE}" "vp8" "3/4"
-  fi
-}
 
 # Decodes $AV1_IVF_FILE while dropping frames, twice: once in sequence mode,
 # and once in pattern mode.
-# Note: This test assumes that $AV1_IVF_FILE has exactly 20 frames, and could
-# break if the file is modified.
 decode_with_drops_av1() {
   if [ "$(av1_decode_available)" = "yes" ]; then
-    # Test sequence mode: Drop frames 2-28.
-    decode_with_drops "${AV1_IVF_FILE}" "av1" "2-19"
+    local file="${AV1_IVF_FILE}"
+    if [ ! -e "${AV1_IVF_FILE}" ]; then
+      file="${AOM_TEST_OUTPUT_DIR}/test_encode.ivf"
+      encode_yuv_raw_input_av1 "${file}" --ivf
+    fi
+    # Drop frames 2 and 3.
+    decode_with_drops "${file}" "av1" "2-3"
 
     # Test pattern mode: Drop 3 of every 4 frames.
-    decode_with_drops "${AV1_IVF_FILE}" "av1" "3/4"
+    decode_with_drops "${file}" "av1" "3/4"
   fi
 }
 
-decode_with_drops_tests="decode_with_drops_vp8
-                         decode_with_drops_av1"
+decode_with_drops_tests="decode_with_drops_av1"
 
 run_tests decode_with_drops_verify_environment "${decode_with_drops_tests}"