Merge changes I2aa2a545,I63932eda,Ie3694ecd

* changes:
  ssim: Add missing statics and consts
  psnrhvs: Add missing consts and static consts.
  ssim: Replace unsigned long with uint32_t.
diff --git a/vp9/common/vp9_mfqe.c b/vp9/common/vp9_mfqe.c
index bebb37e..6d560f4 100644
--- a/vp9/common/vp9_mfqe.c
+++ b/vp9/common/vp9_mfqe.c
@@ -120,8 +120,8 @@
                 dst + dst_stride * 16 + 16, dst_stride);
 }
 
-void copy_mem64x64(const uint8_t *src, int src_stride,
-                   uint8_t *dst, int dst_stride) {
+static void copy_mem64x64(const uint8_t *src, int src_stride,
+                          uint8_t *dst, int dst_stride) {
   copy_mem32x32(src, src_stride, dst, dst_stride);
   copy_mem32x32(src + 32, src_stride, dst + 32, dst_stride);
   copy_mem32x32(src + src_stride * 32, src_stride,
diff --git a/vp9/common/vp9_systemdependent.h b/vp9/common/vp9_systemdependent.h
index fc77762..e4178b2 100644
--- a/vp9/common/vp9_systemdependent.h
+++ b/vp9/common/vp9_systemdependent.h
@@ -33,16 +33,6 @@
 #define vp9_clear_system_state()
 #endif
 
-#if defined(_MSC_VER) && _MSC_VER < 1800
-// round is not defined in MSVC before VS2013.
-static INLINE int round(double x) {
-  if (x < 0)
-    return (int)ceil(x - 0.5);
-  else
-    return (int)floor(x + 0.5);
-}
-#endif
-
 // use GNU builtins where available.
 #if defined(__GNUC__) && \
     ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.c b/vp9/encoder/vp9_aq_cyclicrefresh.c
index b619063..a13f0c0 100644
--- a/vp9/encoder/vp9_aq_cyclicrefresh.c
+++ b/vp9/encoder/vp9_aq_cyclicrefresh.c
@@ -459,7 +459,10 @@
   cr->time_for_refresh = 0;
   // Use larger delta-qp (increase rate_ratio_qdelta) for first few (~4)
   // periods of the refresh cycle, after a key frame.
-  if (rc->frames_since_key <  4 * cr->percent_refresh)
+  // Account for larger interval on base layer for temporal layers.
+  if (cr->percent_refresh > 0 &&
+      rc->frames_since_key <  (4 * cpi->svc.number_temporal_layers) *
+      (100 / cr->percent_refresh))
     cr->rate_ratio_qdelta = 3.0;
   else
     cr->rate_ratio_qdelta = 2.0;
diff --git a/vp9/encoder/vp9_denoiser.c b/vp9/encoder/vp9_denoiser.c
index f1d7379..1f9a28c 100644
--- a/vp9/encoder/vp9_denoiser.c
+++ b/vp9/encoder/vp9_denoiser.c
@@ -63,10 +63,6 @@
   }
 }
 
-int total_adj_strong_thresh(BLOCK_SIZE bs, int increase_denoising) {
-  return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
-}
-
 static int total_adj_weak_thresh(BLOCK_SIZE bs, int increase_denoising) {
   return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
 }
diff --git a/vp9/encoder/vp9_denoiser.h b/vp9/encoder/vp9_denoiser.h
index 8eb5da1..b2af792 100644
--- a/vp9/encoder/vp9_denoiser.h
+++ b/vp9/encoder/vp9_denoiser.h
@@ -57,7 +57,12 @@
                        int border);
 
 #if CONFIG_VP9_TEMPORAL_DENOISING
-int total_adj_strong_thresh(BLOCK_SIZE bs, int increase_denoising);
+// This function is used by both c and sse2 denoiser implementations.
+// Define it as a static function within the scope where vp9_denoiser.h
+// is referenced.
+static int total_adj_strong_thresh(BLOCK_SIZE bs, int increase_denoising) {
+  return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
+}
 #endif
 
 void vp9_denoiser_free(VP9_DENOISER *denoiser);
diff --git a/vpx_ports/msvc.h b/vpx_ports/msvc.h
index 43a36e7..cab7740 100644
--- a/vpx_ports/msvc.h
+++ b/vpx_ports/msvc.h
@@ -18,5 +18,15 @@
 #  define snprintf _snprintf
 # endif  // _MSC_VER < 1900
 
+#if _MSC_VER < 1800  // VS2013 provides round
+#include <math.h>
+static INLINE double round(double x) {
+  if (x < 0)
+    return ceil(x - 0.5);
+  else
+    return floor(x + 0.5);
+}
+#endif  // _MSC_VER < 1800
+
 #endif  // _MSC_VER
 #endif  // VPX_PORTS_MSVC_H_
diff --git a/vpx_ports/x86.h b/vpx_ports/x86.h
index 0fef6a5..5da346e 100644
--- a/vpx_ports/x86.h
+++ b/vpx_ports/x86.h
@@ -136,7 +136,7 @@
 #define xgetbv() 0U  // no AVX for older x64 or unrecognized toolchains.
 #endif
 
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) && _MSC_VER >= 1700
 #include <windows.h>
 #if WINAPI_FAMILY_PARTITION(WINAPI_FAMILY_APP)
 #define getenv(x) NULL