Merge "Fix for compile error with RECT_TX without EXT_TX" into nextgenv2
diff --git a/aom_dsp/bitreader.h b/aom_dsp/bitreader.h
index 6092421..d189e74 100644
--- a/aom_dsp/bitreader.h
+++ b/aom_dsp/bitreader.h
@@ -12,45 +12,90 @@
 #ifndef AOM_DSP_BITREADER_H_
 #define AOM_DSP_BITREADER_H_
 
+#include <assert.h>
+
 #include "./aom_config.h"
 #include "aom/aomdx.h"
 #include "aom/aom_integer.h"
+#if CONFIG_ANS
+#include "aom_dsp/ans.h"
+#else
 #include "aom_dsp/dkboolreader.h"
+#endif
 #include "aom_dsp/prob.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#if CONFIG_ANS
+typedef struct AnsDecoder aom_reader;
+#else
 typedef struct aom_dk_reader aom_reader;
+#endif
 
 static INLINE int aom_reader_init(aom_reader *r, const uint8_t *buffer,
                                   size_t size, aom_decrypt_cb decrypt_cb,
                                   void *decrypt_state) {
+#if CONFIG_ANS
+  (void)decrypt_cb;
+  (void)decrypt_state;
+  assert(size <= INT_MAX);
+  return ans_read_init(r, buffer, size);
+#else
   return aom_dk_reader_init(r, buffer, size, decrypt_cb, decrypt_state);
+#endif
 }
 
 static INLINE const uint8_t *aom_reader_find_end(aom_reader *r) {
+#if CONFIG_ANS
+  (void)r;
+  assert(0 && "Use the raw buffer size with ANS");
+  return NULL;
+#else
   return aom_dk_reader_find_end(r);
+#endif
 }
 
 static INLINE int aom_reader_has_error(aom_reader *r) {
+#if CONFIG_ANS
+  return ans_reader_has_error(r);
+#else
   return aom_dk_reader_has_error(r);
+#endif
 }
 
 static INLINE int aom_read(aom_reader *r, int prob) {
+#if CONFIG_ANS
+  return uabs_read(r, prob);
+#else
   return aom_dk_read(r, prob);
+#endif
 }
 
-static INLINE int aom_read_bit(aom_reader *r) { return aom_dk_read_bit(r); }
+static INLINE int aom_read_bit(aom_reader *r) {
+#if CONFIG_ANS
+  return uabs_read_bit(r);  // Non trivial optimization at half probability
+#else
+  return aom_dk_read_bit(r);
+#endif
+}
 
 static INLINE int aom_read_literal(aom_reader *r, int bits) {
+#if CONFIG_ANS
+  return uabs_read_literal(r, bits);
+#else
   return aom_dk_read_literal(r, bits);
+#endif
 }
 
 static INLINE int aom_read_tree(aom_reader *r, const aom_tree_index *tree,
                                 const aom_prob *probs) {
+#if CONFIG_ANS
+  return uabs_read_tree(r, tree, probs);
+#else
   return aom_dk_read_tree(r, tree, probs);
+#endif
 }
 
 #ifdef __cplusplus
diff --git a/av1/av1_cx.mk b/av1/av1_cx.mk
index ecbe2b3..2bb405c 100644
--- a/av1/av1_cx.mk
+++ b/av1/av1_cx.mk
@@ -19,7 +19,6 @@
 AV1_CX_SRCS-yes += av1_cx_iface.c
 
 AV1_CX_SRCS-yes += encoder/bitstream.c
-AV1_CX_SRCS-yes += encoder/bitwriter.h
 AV1_CX_SRCS-yes += encoder/context_tree.c
 AV1_CX_SRCS-yes += encoder/context_tree.h
 AV1_CX_SRCS-yes += encoder/variance_tree.c
diff --git a/av1/av1_dx.mk b/av1/av1_dx.mk
index 1ebf5fb..36eec30 100644
--- a/av1/av1_dx.mk
+++ b/av1/av1_dx.mk
@@ -30,6 +30,5 @@
 AV1_DX_SRCS-yes += decoder/decoder.h
 AV1_DX_SRCS-yes += decoder/dsubexp.c
 AV1_DX_SRCS-yes += decoder/dsubexp.h
-AV1_DX_SRCS-yes += decoder/bitreader.h
 
 AV1_DX_SRCS-yes := $(filter-out $(AV1_DX_SRCS_REMOVE-yes),$(AV1_DX_SRCS-yes))
diff --git a/av1/common/alloccommon.h b/av1/common/alloccommon.h
index ad0b454..0a0c38c 100644
--- a/av1/common/alloccommon.h
+++ b/av1/common/alloccommon.h
@@ -1,11 +1,12 @@
 /*
- *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
  *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
  */
 
 #ifndef AV1_COMMON_ALLOCCOMMON_H_
diff --git a/av1/common/blockd.h b/av1/common/blockd.h
index 4a0466f..94eb089 100644
--- a/av1/common/blockd.h
+++ b/av1/common/blockd.h
@@ -146,7 +146,7 @@
   PREDICTION_MODE as_mode;
   int_mv as_mv[2];  // first, second inter predictor motion vectors
 #if CONFIG_REF_MV
-  int_mv pred_mv_s8[2];
+  int_mv pred_mv[2];
 #endif
 #if CONFIG_EXT_INTER
   int_mv ref_mv[2];
diff --git a/av1/common/mvref_common.h b/av1/common/mvref_common.h
index 24b075b..96646d0 100644
--- a/av1/common/mvref_common.h
+++ b/av1/common/mvref_common.h
@@ -282,7 +282,7 @@
   return block_idx >= 0 && candidate->mbmi.sb_type < BLOCK_8X8
              ? candidate
                    ->bmi[idx_n_column_to_subblock[block_idx][search_col == 0]]
-                   .pred_mv_s8[which_mv]
+                   .pred_mv[which_mv]
              : candidate->mbmi.pred_mv[which_mv];
 }
 #endif
diff --git a/av1/decoder/bitreader.h b/av1/decoder/bitreader.h
deleted file mode 100644
index 4d77664..0000000
--- a/av1/decoder/bitreader.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- *  Copyright (c) 2016 The WebM project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-/* The purpose of this header is to provide compile time pluggable bit reader
- * implementations with a common interface. */
-
-#ifndef AOM10_DECODER_BITREADER_H_
-#define AOM10_DECODER_BITREADER_H_
-
-#include "./aom_config.h"
-
-#if CONFIG_ANS
-#include "aom_dsp/ans.h"
-#include "aom/aomdx.h"  // for av1_decrypt_cb
-#define aom_reader struct AnsDecoder
-#define aom_reader_has_error ans_reader_has_error
-#define aom_read uabs_read
-#define aom_read_bit uabs_read_bit
-#define aom_read_literal uabs_read_literal
-#define aom_read_tree uabs_read_tree
-#else
-#include "aom_dsp/bitreader.h"
-#define aom_reader aom_reader
-#define aom_reader_has_error aom_reader_has_error
-#define aom_read aom_read
-#define aom_read_bit aom_read_bit
-#define aom_read_literal aom_read_literal
-#define aom_read_tree aom_read_tree
-#endif
-
-#endif  // AOM10_DECODER_BITREADER_H_
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 862f94a..6492f62 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -951,7 +951,7 @@
   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
   BLOCK_SIZE bsize = mbmi->sb_type;
   int_mv *pred_mv =
-      (bsize >= BLOCK_8X8) ? mbmi->pred_mv : xd->mi[0]->bmi[block].pred_mv_s8;
+      (bsize >= BLOCK_8X8) ? mbmi->pred_mv : xd->mi[0]->bmi[block].pred_mv;
 #endif
   (void)ref_frame;
 
@@ -1462,8 +1462,8 @@
     }
 
 #if CONFIG_REF_MV
-    mbmi->pred_mv[0].as_int = mi->bmi[3].pred_mv_s8[0].as_int;
-    mbmi->pred_mv[1].as_int = mi->bmi[3].pred_mv_s8[1].as_int;
+    mbmi->pred_mv[0].as_int = mi->bmi[3].pred_mv[0].as_int;
+    mbmi->pred_mv[1].as_int = mi->bmi[3].pred_mv[1].as_int;
 #endif
     mi->mbmi.mode = b_mode;
 
diff --git a/av1/decoder/decodemv.h b/av1/decoder/decodemv.h
index aa17b5b..e916262 100644
--- a/av1/decoder/decodemv.h
+++ b/av1/decoder/decodemv.h
@@ -12,7 +12,7 @@
 #ifndef AV1_DECODER_DECODEMV_H_
 #define AV1_DECODER_DECODEMV_H_
 
-#include "av1/decoder/bitreader.h"
+#include "aom_dsp/bitreader.h"
 
 #include "av1/decoder/decoder.h"
 
diff --git a/av1/decoder/decoder.h b/av1/decoder/decoder.h
index 43fac67..3900b44 100644
--- a/av1/decoder/decoder.h
+++ b/av1/decoder/decoder.h
@@ -15,7 +15,7 @@
 #include "./aom_config.h"
 
 #include "aom/aom_codec.h"
-#include "av1/decoder/bitreader.h"
+#include "aom_dsp/bitreader.h"
 #include "aom_scale/yv12config.h"
 #include "aom_util/aom_thread.h"
 
diff --git a/av1/decoder/dsubexp.h b/av1/decoder/dsubexp.h
index ed88f28..c0d372a 100644
--- a/av1/decoder/dsubexp.h
+++ b/av1/decoder/dsubexp.h
@@ -12,7 +12,7 @@
 #ifndef AV1_DECODER_DSUBEXP_H_
 #define AV1_DECODER_DSUBEXP_H_
 
-#include "av1/decoder/bitreader.h"
+#include "aom_dsp/bitreader.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index c104f35..7636151 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1269,7 +1269,7 @@
 #endif
 #else
 #if CONFIG_REF_MV
-                            &mi->bmi[j].pred_mv_s8[ref].as_mv, is_compound,
+                            &mi->bmi[j].pred_mv[ref].as_mv, is_compound,
 #else
                             &mbmi_ext->ref_mvs[mbmi->ref_frame[ref]][0].as_mv,
 #endif  // CONFIG_REF_MV
diff --git a/av1/encoder/bitwriter.h b/av1/encoder/bitwriter.h
deleted file mode 100644
index 21cc6a3..0000000
--- a/av1/encoder/bitwriter.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- *  Copyright (c) 2016 The WebM project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-/* The purpose of this header is to provide compile time pluggable bit writer
- * implementations with a common interface. */
-
-#ifndef AOM10_ENCODER_BITWRITER_H_
-#define AOM10_ENCODER_BITWRITER_H_
-
-#include "aom_dsp/bitwriter.h"
-
-#endif  // AOM10_ENCODER_BITWRITER_H_
diff --git a/av1/encoder/encodemv.c b/av1/encoder/encodemv.c
index 6e1b87a..ee627bd 100644
--- a/av1/encoder/encodemv.c
+++ b/av1/encoder/encodemv.c
@@ -430,7 +430,7 @@
         if (mi->bmi[i].as_mode == NEWMV)
           inc_mvs(mbmi, mbmi_ext, mi->bmi[i].as_mv,
 #if CONFIG_REF_MV
-                  mi->bmi[i].pred_mv_s8, td->counts->mv);
+                  mi->bmi[i].pred_mv, td->counts->mv);
 #else
                   &td->counts->mv);
 #endif
diff --git a/av1/encoder/ransac.c b/av1/encoder/ransac.c
index 86177a0..0a26396 100644
--- a/av1/encoder/ransac.c
+++ b/av1/encoder/ransac.c
@@ -325,6 +325,68 @@
 typedef void (*DenormalizeFunc)(double *params, double *T1, double *T2);
 typedef int (*FindTransformationFunc)(int points, double *points1,
                                       double *points2, double *params);
+typedef void (*ProjectPointsDoubleFunc)(double *mat, double *points,
+                                        double *proj, const int n,
+                                        const int stride_points,
+                                        const int stride_proj);
+
+static void project_points_double_translation(double *mat, double *points,
+                                              double *proj, const int n,
+                                              const int stride_points,
+                                              const int stride_proj) {
+  int i;
+  for (i = 0; i < n; ++i) {
+    const double x = *(points++), y = *(points++);
+    *(proj++) = x + mat[1];
+    *(proj++) = y + mat[0];
+    points += stride_points - 2;
+    proj += stride_proj - 2;
+  }
+}
+
+static void project_points_double_rotzoom(double *mat, double *points,
+                                          double *proj, const int n,
+                                          const int stride_points,
+                                          const int stride_proj) {
+  int i;
+  for (i = 0; i < n; ++i) {
+    const double x = *(points++), y = *(points++);
+    *(proj++) =  mat[3] * x + mat[2] * y + mat[1];
+    *(proj++) = -mat[2] * x + mat[3] * y + mat[0];
+    points += stride_points - 2;
+    proj += stride_proj - 2;
+  }
+}
+
+static void project_points_double_affine(double *mat, double *points,
+                                         double *proj, const int n,
+                                         const int stride_points,
+                                         const int stride_proj) {
+  int i;
+  for (i = 0; i < n; ++i) {
+    const double x = *(points++), y = *(points++);
+    *(proj++) = mat[3] * x + mat[2] * y + mat[1];
+    *(proj++) = mat[4] * x + mat[5] * y + mat[0];
+    points += stride_points - 2;
+    proj += stride_proj - 2;
+  }
+}
+
+static void project_points_double_homography(double *mat, double *points,
+                                             double *proj, const int n,
+                                             const int stride_points,
+                                             const int stride_proj) {
+  int i;
+  double x, y, Z;
+  for (i = 0; i < n; ++i) {
+    x = *(points++), y = *(points++);
+    Z = 1. / (mat[7] * x + mat[6] * y + 1);
+    *(proj++) = (mat[1] * x + mat[0] * y + mat[3]) * Z;
+    *(proj++) = (mat[2] * x + mat[4] * y + mat[4]) * Z;
+    points += stride_points - 2;
+    proj += stride_proj - 2;
+  }
+}
 
 static int get_rand_indices(int npoints, int minpts, int *indices) {
   int i, j;
@@ -353,7 +415,7 @@
                   const int paramdim, IsDegenerateFunc is_degenerate,
                   NormalizeFunc normalize, DenormalizeFunc denormalize,
                   FindTransformationFunc find_transformation,
-                  ProjectPointsFunc projectpoints, TransformationType type) {
+                  ProjectPointsDoubleFunc projectpoints) {
   static const double INLIER_THRESHOLD_NORMALIZED = 0.1;
   static const double INLIER_THRESHOLD_UNNORMALIZED = 1.0;
   static const double PROBABILITY_REQUIRED = 0.9;
@@ -380,9 +442,8 @@
   double *inlier_set1;
   double *inlier_set2;
   double *corners1;
-  int *corners1_int;
   double *corners2;
-  int *image1_coord;
+  double *image1_coord;
   int *inlier_mask;
 
   double *cnp1, *cnp2;
@@ -406,13 +467,12 @@
   inlier_set1 = (double *)aom_malloc(sizeof(*inlier_set1) * npoints * 2);
   inlier_set2 = (double *)aom_malloc(sizeof(*inlier_set2) * npoints * 2);
   corners1 = (double *)aom_malloc(sizeof(*corners1) * npoints * 2);
-  corners1_int = (int *)aom_malloc(sizeof(*corners1_int) * npoints * 2);
   corners2 = (double *)aom_malloc(sizeof(*corners2) * npoints * 2);
-  image1_coord = (int *)aom_malloc(sizeof(*image1_coord) * npoints * 2);
+  image1_coord = (double *)aom_malloc(sizeof(*image1_coord) * npoints * 2);
   inlier_mask = (int *)aom_malloc(sizeof(*inlier_mask) * npoints);
 
   if (!(best_inlier_set1 && best_inlier_set2 && inlier_set1 && inlier_set2 &&
-        corners1 && corners1_int && corners2 && image1_coord && inlier_mask)) {
+        corners1 && corners2 && image1_coord && inlier_mask)) {
     ret_val = 1;
     goto finish_ransac;
   }
@@ -465,20 +525,11 @@
       continue;
     }
 
-    for (i = 0; i < npoints; ++i) {
-      corners1_int[2 * i] = (int)corners1[i * 2];
-      corners1_int[2 * i + 1] = (int)corners1[i * 2 + 1];
-    }
-
-    av1_integerize_model(params, type, &wm);
-    projectpoints((int16_t *)wm.wmmat, corners1_int, image1_coord, npoints, 2,
-                  2, 0, 0);
+    projectpoints(params, corners1, image1_coord, npoints, 2, 2);
 
     for (i = 0; i < npoints; ++i) {
-      double dx =
-          (image1_coord[i * 2] >> WARPEDPIXEL_PREC_BITS) - corners2[i * 2];
-      double dy = (image1_coord[i * 2 + 1] >> WARPEDPIXEL_PREC_BITS) -
-                  corners2[i * 2 + 1];
+      double dx = image1_coord[i * 2] - corners2[i * 2];
+      double dy = image1_coord[i * 2 + 1] - corners2[i * 2 + 1];
       double distance = sqrt(dx * dx + dy * dy);
 
       inlier_mask[i] = distance < inlier_threshold;
@@ -860,7 +911,7 @@
                 best_params, 3, 2, is_degenerate_translation,
                 NULL,  // normalize_homography,
                 NULL,  // denormalize_rotzoom,
-                find_translation, project_points_translation, TRANSLATION);
+                find_translation, project_points_double_translation);
 }
 
 int ransac_rotzoom(double *matched_points, int npoints, int *number_of_inliers,
@@ -869,7 +920,7 @@
                 best_params, 3, 4, is_degenerate_affine,
                 NULL,  // normalize_homography,
                 NULL,  // denormalize_rotzoom,
-                find_rotzoom, project_points_rotzoom, ROTZOOM);
+                find_rotzoom, project_points_double_rotzoom);
 }
 
 int ransac_affine(double *matched_points, int npoints, int *number_of_inliers,
@@ -878,7 +929,7 @@
                 best_params, 3, 6, is_degenerate_affine,
                 NULL,  // normalize_homography,
                 NULL,  // denormalize_affine,
-                find_affine, project_points_affine, AFFINE);
+                find_affine, project_points_double_affine);
 }
 
 int ransac_homography(double *matched_points, int npoints,
@@ -889,7 +940,7 @@
              best_params, 4, 8, is_degenerate_homography,
              NULL,  // normalize_homography,
              NULL,  // denormalize_homography,
-             find_homography, project_points_homography, HOMOGRAPHY);
+             find_homography, project_points_double_homography);
   if (!result) {
     // normalize so that H33 = 1
     int i;
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 95b74a2..9721abe 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -4264,11 +4264,11 @@
 
 #if CONFIG_REF_MV
   if (mode == NEWMV) {
-    mic->bmi[i].pred_mv_s8[0].as_int = best_ref_mv[0]->as_int;
-    if (is_compound) mic->bmi[i].pred_mv_s8[1].as_int = best_ref_mv[1]->as_int;
+    mic->bmi[i].pred_mv[0].as_int = best_ref_mv[0]->as_int;
+    if (is_compound) mic->bmi[i].pred_mv[1].as_int = best_ref_mv[1]->as_int;
   } else {
-    mic->bmi[i].pred_mv_s8[0].as_int = this_mv[0].as_int;
-    if (is_compound) mic->bmi[i].pred_mv_s8[1].as_int = this_mv[1].as_int;
+    mic->bmi[i].pred_mv[0].as_int = this_mv[0].as_int;
+    if (is_compound) mic->bmi[i].pred_mv[1].as_int = this_mv[1].as_int;
   }
 #endif
 
@@ -5325,13 +5325,13 @@
                 mode_mv[this_mode][ref].as_int;
 #if CONFIG_REF_MV
           bsi->rdstat[i][mode_idx].pred_mv[ref].as_int =
-              mi->bmi[i].pred_mv_s8[ref].as_int;
+              mi->bmi[i].pred_mv[ref].as_int;
           if (num_4x4_blocks_wide > 1)
             bsi->rdstat[i + 1][mode_idx].pred_mv[ref].as_int =
-                mi->bmi[i].pred_mv_s8[ref].as_int;
+                mi->bmi[i].pred_mv[ref].as_int;
           if (num_4x4_blocks_high > 1)
             bsi->rdstat[i + 2][mode_idx].pred_mv[ref].as_int =
-                mi->bmi[i].pred_mv_s8[ref].as_int;
+                mi->bmi[i].pred_mv[ref].as_int;
 #endif
 #if CONFIG_EXT_INTER
           bsi->rdstat[i][mode_idx].ref_mv[ref].as_int =
@@ -5556,9 +5556,9 @@
     if (has_second_ref(mbmi))
       mi->bmi[idx].as_mv[1].as_int = bsi->rdstat[idx][mode_idx].mvs[1].as_int;
 #if CONFIG_REF_MV
-    mi->bmi[idx].pred_mv_s8[0] = bsi->rdstat[idx][mode_idx].pred_mv[0];
+    mi->bmi[idx].pred_mv[0] = bsi->rdstat[idx][mode_idx].pred_mv[0];
     if (has_second_ref(mbmi))
-      mi->bmi[idx].pred_mv_s8[1] = bsi->rdstat[idx][mode_idx].pred_mv[1];
+      mi->bmi[idx].pred_mv[1] = bsi->rdstat[idx][mode_idx].pred_mv[1];
 #endif
 #if CONFIG_EXT_INTER
     mi->bmi[idx].ref_mv[0].as_int = bsi->rdstat[idx][mode_idx].ref_mv[0].as_int;
@@ -10682,8 +10682,8 @@
     mbmi->mv[0].as_int = xd->mi[0]->bmi[3].as_mv[0].as_int;
     mbmi->mv[1].as_int = xd->mi[0]->bmi[3].as_mv[1].as_int;
 #if CONFIG_REF_MV
-    mbmi->pred_mv[0].as_int = xd->mi[0]->bmi[3].pred_mv_s8[0].as_int;
-    mbmi->pred_mv[1].as_int = xd->mi[0]->bmi[3].pred_mv_s8[1].as_int;
+    mbmi->pred_mv[0].as_int = xd->mi[0]->bmi[3].pred_mv[0].as_int;
+    mbmi->pred_mv[1].as_int = xd->mi[0]->bmi[3].pred_mv[1].as_int;
 #endif
   }
 
diff --git a/av1/encoder/subexp.c b/av1/encoder/subexp.c
index aa02e53..0ca5247 100644
--- a/av1/encoder/subexp.c
+++ b/av1/encoder/subexp.c
@@ -8,7 +8,7 @@
  * Media Patent License 1.0 was not distributed with this source code in the
  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
  */
-#include "av1/encoder/bitwriter.h"
+#include "aom_dsp/bitwriter.h"
 
 #include "av1/common/common.h"
 #include "av1/common/entropy.h"
diff --git a/av1/encoder/treewriter.h b/av1/encoder/treewriter.h
index eb7f0a7..a7b38b9 100644
--- a/av1/encoder/treewriter.h
+++ b/av1/encoder/treewriter.h
@@ -17,7 +17,7 @@
 #define tree_writer aom_dk_writer
 #define tree_bit_write aom_dk_write
 #else
-#include "av1/encoder/bitwriter.h"
+#include "aom_dsp/bitwriter.h"
 #define tree_writer aom_writer
 #define tree_bit_write aom_write
 #endif
diff --git a/docs.mk b/docs.mk
index 889d182..0dfc65b 100644
--- a/docs.mk
+++ b/docs.mk
@@ -1,14 +1,16 @@
 ##
-##  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
+## Copyright (c) 2016, Alliance for Open Media. All rights reserved
 ##
-##  Use of this source code is governed by a BSD-style license
-##  that can be found in the LICENSE file in the root of the source
-##  tree. An additional intellectual property rights grant can be found
-##  in the file PATENTS.  All contributing project authors may
-##  be found in the AUTHORS file in the root of the source tree.
+## This source code is subject to the terms of the BSD 2 Clause License and
+## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+## was not distributed with this source code in the LICENSE file, you can
+## obtain it at www.aomedia.org/license/software. If the Alliance for Open
+## Media Patent License 1.0 was not distributed with this source code in the
+## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 ##
 
 
+
 INSTALL_MAPS += docs/%    docs/%
 INSTALL_MAPS += src/%     %
 INSTALL_MAPS += %         %
diff --git a/examples.mk b/examples.mk
index 66ba693..602b2a2 100644
--- a/examples.mk
+++ b/examples.mk
@@ -140,7 +140,7 @@
 simple_encoder.SRCS             += aom_ports/msvc.h
 simple_encoder.GUID              = 4607D299-8A71-4D2C-9B1D-071899B6FBFD
 simple_encoder.DESCRIPTION       = Simplified encoder loop
-EXAMPLES-$(CONFIG_AV1_ENCODER) += lossless_encoder.c
+EXAMPLES-$(CONFIG_AV1_ENCODER)  += lossless_encoder.c
 lossless_encoder.SRCS           += ivfenc.h ivfenc.c
 lossless_encoder.SRCS           += tools_common.h tools_common.c
 lossless_encoder.SRCS           += video_common.h
diff --git a/test/av1_ans_test.cc b/test/ans_test.cc
similarity index 92%
rename from test/av1_ans_test.cc
rename to test/ans_test.cc
index b0cec90..aa0729b 100644
--- a/test/av1_ans_test.cc
+++ b/test/ans_test.cc
@@ -22,6 +22,7 @@
 #include "aom_dsp/ans.h"
 #include "aom_dsp/bitreader.h"
 #include "aom_dsp/bitwriter.h"
+#include "aom_dsp/dkboolreader.h"
 #include "aom_dsp/dkboolwriter.h"
 #include "av1/encoder/treewriter.h"
 #include "test/acm_random.h"
@@ -127,7 +128,7 @@
 
 bool check_aombool(const PvVec &pv_vec, uint8_t *buf) {
   aom_dk_writer w;
-  aom_reader r;
+  aom_dk_reader r;
   aom_dk_start_encode(&w, buf);
 
   std::clock_t start = std::clock();
@@ -137,10 +138,10 @@
   std::clock_t enc_time = std::clock() - start;
   aom_dk_stop_encode(&w);
   bool okay = true;
-  aom_reader_init(&r, buf, w.pos, NULL, NULL);
+  aom_dk_reader_init(&r, buf, w.pos, NULL, NULL);
   start = std::clock();
   for (PvVec::const_iterator it = pv_vec.begin(); it != pv_vec.end(); ++it) {
-    okay &= aom_read(&r, 256 - it->first) == it->second;
+    okay &= aom_dk_read(&r, 256 - it->first) == it->second;
   }
   std::clock_t dec_time = std::clock() - start;
   printf("AOM size %d enc_time %f dec_time %f\n", w.pos,
@@ -276,7 +277,7 @@
 bool check_aomtree(const std::vector<int> &sym_vec, const rans_sym *sym_tab,
                    uint8_t *buf) {
   aom_dk_writer w;
-  aom_reader r;
+  aom_dk_reader r;
   aom_dk_start_encode(&w, buf);
 
   aom_prob probs[kDistinctSyms];
@@ -291,11 +292,11 @@
   }
   std::clock_t enc_time = std::clock() - start;
   aom_dk_stop_encode(&w);
-  aom_reader_init(&r, buf, w.pos, NULL, NULL);
+  aom_dk_reader_init(&r, buf, w.pos, NULL, NULL);
   start = std::clock();
   for (std::vector<int>::const_iterator it = sym_vec.begin();
        it != sym_vec.end(); ++it) {
-    if (aom_read_tree(&r, tree, probs) != *it) return false;
+    if (aom_dk_read_tree(&r, tree, probs) != *it) return false;
   }
   std::clock_t dec_time = std::clock() - start;
   printf("AOMtree size %u enc_time %f dec_time %f\n", w.pos,
@@ -304,7 +305,7 @@
   return true;
 }
 
-class Av1AbsTest : public ::testing::Test {
+class AbsTest : public ::testing::Test {
  protected:
   static void SetUpTestCase() { pv_vec_ = abs_encode_build_vals(kNumBools); }
   virtual void SetUp() { buf_ = new uint8_t[kNumBools / 8]; }
@@ -313,9 +314,9 @@
   static PvVec pv_vec_;
   uint8_t *buf_;
 };
-PvVec Av1AbsTest::pv_vec_;
+PvVec AbsTest::pv_vec_;
 
-class Av1AnsTest : public ::testing::Test {
+class AnsTest : public ::testing::Test {
  protected:
   static void SetUpTestCase() {
     sym_vec_ = ans_encode_build_vals(rans_sym_tab, kNumSyms);
@@ -326,17 +327,15 @@
   static std::vector<int> sym_vec_;
   uint8_t *buf_;
 };
-std::vector<int> Av1AnsTest::sym_vec_;
+std::vector<int> AnsTest::sym_vec_;
 
-TEST_F(Av1AbsTest, Avxbool) { EXPECT_TRUE(check_aombool(pv_vec_, buf_)); }
-TEST_F(Av1AbsTest, Rabs) { EXPECT_TRUE(check_rabs(pv_vec_, buf_)); }
-TEST_F(Av1AbsTest, RabsAsc) { EXPECT_TRUE(check_rabs_asc(pv_vec_, buf_)); }
-TEST_F(Av1AbsTest, Uabs) { EXPECT_TRUE(check_uabs(pv_vec_, buf_)); }
+TEST_F(AbsTest, Avxbool) { EXPECT_TRUE(check_aombool(pv_vec_, buf_)); }
+TEST_F(AbsTest, Rabs) { EXPECT_TRUE(check_rabs(pv_vec_, buf_)); }
+TEST_F(AbsTest, RabsAsc) { EXPECT_TRUE(check_rabs_asc(pv_vec_, buf_)); }
+TEST_F(AbsTest, Uabs) { EXPECT_TRUE(check_uabs(pv_vec_, buf_)); }
 
-TEST_F(Av1AnsTest, Rans) {
-  EXPECT_TRUE(check_rans(sym_vec_, rans_sym_tab, buf_));
-}
-TEST_F(Av1AnsTest, Avxtree) {
+TEST_F(AnsTest, Rans) { EXPECT_TRUE(check_rans(sym_vec_, rans_sym_tab, buf_)); }
+TEST_F(AnsTest, Avxtree) {
   EXPECT_TRUE(check_aomtree(sym_vec_, rans_sym_tab, buf_));
 }
 }  // namespace
diff --git a/test/test.mk b/test/test.mk
index ce9e342..a41efbe 100644
--- a/test/test.mk
+++ b/test/test.mk
@@ -102,7 +102,7 @@
 LIBAOM_TEST_SRCS-yes                   += superframe_test.cc
 LIBAOM_TEST_SRCS-yes                   += tile_independence_test.cc
 ifeq ($(CONFIG_ANS),yes)
-LIBAOM_TEST_SRCS-yes                   += av1_ans_test.cc
+LIBAOM_TEST_SRCS-yes                   += ans_test.cc
 else
 LIBAOM_TEST_SRCS-yes                   += boolcoder_test.cc
 endif