Merge "simple_encode*.cc: add missing copyright"
diff --git a/test/frame_size_tests.cc b/test/frame_size_tests.cc
index f66972b..9397af2 100644
--- a/test/frame_size_tests.cc
+++ b/test/frame_size_tests.cc
@@ -7,12 +7,73 @@
  *  in the file PATENTS.  All contributing project authors may
  *  be found in the AUTHORS file in the root of the source tree.
  */
+#include <memory>
+
 #include "third_party/googletest/src/include/gtest/gtest.h"
 #include "test/codec_factory.h"
+#include "test/register_state_check.h"
 #include "test/video_source.h"
 
 namespace {
 
+class EncoderWithExpectedError : public ::libvpx_test::Encoder {
+ public:
+  EncoderWithExpectedError(vpx_codec_enc_cfg_t cfg,
+                           unsigned long deadline,          // NOLINT
+                           const unsigned long init_flags,  // NOLINT
+                           ::libvpx_test::TwopassStatsStore *stats)
+      : ::libvpx_test::Encoder(cfg, deadline, init_flags, stats) {}
+  // This overrides with expected error code.
+  void EncodeFrame(::libvpx_test::VideoSource *video,
+                   const unsigned long frame_flags,  // NOLINT
+                   const vpx_codec_err_t expected_err) {
+    if (video->img()) {
+      EncodeFrameInternal(*video, frame_flags, expected_err);
+    } else {
+      Flush();
+    }
+
+    // Handle twopass stats
+    ::libvpx_test::CxDataIterator iter = GetCxData();
+
+    while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) {
+      if (pkt->kind != VPX_CODEC_STATS_PKT) continue;
+
+      stats_->Append(*pkt);
+    }
+  }
+
+ protected:
+  void EncodeFrameInternal(const ::libvpx_test::VideoSource &video,
+                           const unsigned long frame_flags,  // NOLINT
+                           const vpx_codec_err_t expected_err) {
+    vpx_codec_err_t res;
+    const vpx_image_t *img = video.img();
+
+    // Handle frame resizing
+    if (cfg_.g_w != img->d_w || cfg_.g_h != img->d_h) {
+      cfg_.g_w = img->d_w;
+      cfg_.g_h = img->d_h;
+      res = vpx_codec_enc_config_set(&encoder_, &cfg_);
+      ASSERT_EQ(res, VPX_CODEC_OK) << EncoderError();
+    }
+
+    // Encode the frame
+    API_REGISTER_STATE_CHECK(res = vpx_codec_encode(&encoder_, img, video.pts(),
+                                                    video.duration(),
+                                                    frame_flags, deadline_));
+    ASSERT_EQ(expected_err, res) << EncoderError();
+  }
+
+  virtual vpx_codec_iface_t *CodecInterface() const {
+#if CONFIG_VP9_ENCODER
+    return &vpx_codec_vp9_cx_algo;
+#else
+    return NULL;
+#endif
+  }
+};
+
 class VP9FrameSizeTestsLarge : public ::libvpx_test::EncoderTest,
                                public ::testing::Test {
  protected:
@@ -43,7 +104,67 @@
     }
   }
 
-  int expected_res_;
+  using ::libvpx_test::EncoderTest::RunLoop;
+  virtual void RunLoop(::libvpx_test::VideoSource *video,
+                       const vpx_codec_err_t expected_err) {
+    stats_.Reset();
+
+    ASSERT_TRUE(passes_ == 1 || passes_ == 2);
+    for (unsigned int pass = 0; pass < passes_; pass++) {
+      last_pts_ = 0;
+
+      if (passes_ == 1) {
+        cfg_.g_pass = VPX_RC_ONE_PASS;
+      } else if (pass == 0) {
+        cfg_.g_pass = VPX_RC_FIRST_PASS;
+      } else {
+        cfg_.g_pass = VPX_RC_LAST_PASS;
+      }
+
+      BeginPassHook(pass);
+      std::unique_ptr<EncoderWithExpectedError> encoder(
+          new EncoderWithExpectedError(cfg_, deadline_, init_flags_, &stats_));
+      ASSERT_NE(encoder.get(), nullptr);
+
+      ASSERT_NO_FATAL_FAILURE(video->Begin());
+      encoder->InitEncoder(video);
+      ASSERT_FALSE(::testing::Test::HasFatalFailure());
+      for (bool again = true; again; video->Next()) {
+        again = (video->img() != NULL);
+
+        PreEncodeFrameHook(video, encoder.get());
+        encoder->EncodeFrame(video, frame_flags_, expected_err);
+
+        PostEncodeFrameHook(encoder.get());
+
+        ::libvpx_test::CxDataIterator iter = encoder->GetCxData();
+
+        while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) {
+          pkt = MutateEncoderOutputHook(pkt);
+          again = true;
+          switch (pkt->kind) {
+            case VPX_CODEC_CX_FRAME_PKT:
+              ASSERT_GE(pkt->data.frame.pts, last_pts_);
+              last_pts_ = pkt->data.frame.pts;
+              FramePktHook(pkt);
+              break;
+
+            case VPX_CODEC_PSNR_PKT: PSNRPktHook(pkt); break;
+            case VPX_CODEC_STATS_PKT: StatsPktHook(pkt); break;
+            default: break;
+          }
+        }
+
+        if (!Continue()) break;
+      }
+
+      EndPassHook();
+
+      if (!Continue()) break;
+    }
+  }
+
+  vpx_codec_err_t expected_res_;
 };
 
 TEST_F(VP9FrameSizeTestsLarge, TestInvalidSizes) {
@@ -52,8 +173,8 @@
 #if CONFIG_SIZE_LIMIT
   video.SetSize(DECODE_WIDTH_LIMIT + 16, DECODE_HEIGHT_LIMIT + 16);
   video.set_limit(2);
-  expected_res_ = VPX_CODEC_CORRUPT_FRAME;
-  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+  expected_res_ = VPX_CODEC_MEM_ERROR;
+  ASSERT_NO_FATAL_FAILURE(RunLoop(&video, expected_res_));
 #endif
 }
 
@@ -64,7 +185,7 @@
   video.SetSize(DECODE_WIDTH_LIMIT, DECODE_HEIGHT_LIMIT);
   video.set_limit(2);
   expected_res_ = VPX_CODEC_OK;
-  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+  ASSERT_NO_FATAL_FAILURE(::libvpx_test::EncoderTest::RunLoop(&video));
 #else
 // This test produces a pretty large single frame allocation,  (roughly
 // 25 megabits). The encoder allocates a good number of these frames
@@ -80,7 +201,7 @@
 #endif
   video.set_limit(2);
   expected_res_ = VPX_CODEC_OK;
-  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+  ASSERT_NO_FATAL_FAILURE(::libvpx_test::EncoderTest::RunLoop(&video));
 #endif
 }
 
@@ -90,6 +211,6 @@
   video.SetSize(1, 1);
   video.set_limit(2);
   expected_res_ = VPX_CODEC_OK;
-  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+  ASSERT_NO_FATAL_FAILURE(::libvpx_test::EncoderTest::RunLoop(&video));
 }
 }  // namespace
diff --git a/tools/3D-Reconstruction/MotionEST/Anandan.py b/tools/3D-Reconstruction/MotionEST/Anandan.py
index b8a19a3..b96cd9f 100644
--- a/tools/3D-Reconstruction/MotionEST/Anandan.py
+++ b/tools/3D-Reconstruction/MotionEST/Anandan.py
@@ -122,7 +122,7 @@
           for i, j in {(r, c), (r, c + 1), (r + 1, c), (r + 1, c + 1)}:
             if 0 <= i < last_mvs.shape[0] and 0 <= j < last_mvs.shape[1]:
               init_mvs.append(last_mvs[i, j])
-        #use last matching results as the start postion as current level
+        #use last matching results as the start position as current level
         min_ssd = None
         min_mv = None
         for init_mv in init_mvs:
diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c
index cfd82d3..88178e4 100644
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -7096,7 +7096,7 @@
 }
 
 static void init_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result) {
-  encode_frame_result->show_idx = -1;  // Actual encoding deosn't happen.
+  encode_frame_result->show_idx = -1;  // Actual encoding doesn't happen.
 }
 
 #if !CONFIG_REALTIME_ONLY
diff --git a/vpx/vpx_encoder.h b/vpx/vpx_encoder.h
index 0cd0776..c84d40f 100644
--- a/vpx/vpx_encoder.h
+++ b/vpx/vpx_encoder.h
@@ -633,7 +633,7 @@
   /*!\brief Target bitrate for each spatial layer.
    *
    * These values specify the target coding bitrate to be used for each
-   * spatial layer.
+   * spatial layer. (in kbps)
    */
   unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS];
 
@@ -646,7 +646,7 @@
   /*!\brief Target bitrate for each temporal layer.
    *
    * These values specify the target coding bitrate to be used for each
-   * temporal layer.
+   * temporal layer. (in kbps)
    */
   unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
 
@@ -678,7 +678,7 @@
   /*!\brief Target bitrate for each spatial/temporal layer.
    *
    * These values specify the target coding bitrate to be used for each
-   * spatial/temporal layer.
+   * spatial/temporal layer. (in kbps)
    *
    */
   unsigned int layer_target_bitrate[VPX_MAX_LAYERS];