]> granicus.if.org Git - libvpx/commitdiff
Adds a test for the VP8E_SET_SCALEMODE control
authorJohn Koleszar <jkoleszar@google.com>
Wed, 6 Feb 2013 20:44:20 +0000 (12:44 -0800)
committerJohn Koleszar <jkoleszar@google.com>
Fri, 8 Feb 2013 20:20:30 +0000 (12:20 -0800)
Tests that the external interface to set the internal codec scaling
works as expected. Also updates the test to pull the height from
the decoded frame size rather than parsing the keyframe header,
in anticipation of allowing resolution changes on non-keyframes.

Change-Id: I3ed92117d8e5288fbbd1e7b618f2f233d0fe2c17

test/encode_test_driver.cc
test/encode_test_driver.h
test/resize_test.cc
vp9/encoder/vp9_onyx_if.c

index b2b6e0d6d40bbda3f9cc11bf06bad51075a8636c..39d154b139b75a728918aa9820f5f747d9445bfd 100644 (file)
@@ -201,6 +201,8 @@ void EncoderTest::RunLoop(VideoSource *video) {
             MismatchHook(img_enc, img_dec);
           }
         }
+        if (img_dec)
+          DecompressedFrameHook(*img_dec, video->pts());
       }
       if (!Continue())
         break;
index 0944dc2c65fd473f2d94352f385e9c34b8b1810a..35082a7fdac2e42729595e0ca317eb8ecb496a7b 100644 (file)
@@ -117,6 +117,11 @@ class Encoder {
     ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
   }
 
+  void Control(int ctrl_id, struct vpx_scaling_mode *arg) {
+    const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
+    ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
+  }
+
   void set_deadline(unsigned long deadline) {
     deadline_ = deadline;
   }
@@ -194,6 +199,10 @@ class EncoderTest {
   virtual void MismatchHook(const vpx_image_t *img1,
                             const vpx_image_t *img2);
 
+  // Hook to be called on every decompressed frame.
+  virtual void DecompressedFrameHook(const vpx_image_t& img,
+                                     vpx_codec_pts_t pts) {}
+
   bool                 abort_;
   vpx_codec_enc_cfg_t  cfg_;
   unsigned int         passes_;
index 0ce8940a373b656ae419769ef320e15fbcb3ba4a..5e9234c38f4ff7fe4388b11e23bb0311e46c4d4b 100644 (file)
@@ -12,6 +12,7 @@
 #include "third_party/googletest/src/include/gtest/gtest.h"
 #include "test/codec_factory.h"
 #include "test/encode_test_driver.h"
+#include "test/i420_video_source.h"
 #include "test/video_source.h"
 #include "test/util.h"
 
@@ -73,15 +74,9 @@ class ResizeTest : public ::libvpx_test::EncoderTest,
     return !HasFatalFailure() && !abort_;
   }
 
-  virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
-    if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) {
-      const unsigned char *buf =
-          reinterpret_cast<const unsigned char *>(pkt->data.frame.buf);
-      const unsigned int w = (buf[6] | (buf[7] << 8)) & 0x3fff;
-      const unsigned int h = (buf[8] | (buf[9] << 8)) & 0x3fff;
-
-      frame_info_list_.push_back(FrameInfo(pkt->data.frame.pts, w, h));
-    }
+  virtual void DecompressedFrameHook(const vpx_image_t &img,
+                                     vpx_codec_pts_t pts) {
+    frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h));
   }
 
   std::vector< FrameInfo > frame_info_list_;
@@ -104,5 +99,38 @@ TEST_P(ResizeTest, TestExternalResizeWorks) {
   }
 }
 
+class ResizeInternalTest : public ResizeTest {
+ protected:
+  ResizeInternalTest() : ResizeTest() {}
+
+  virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
+                                  libvpx_test::Encoder *encoder) {
+    if (video->frame() == 3) {
+      struct vpx_scaling_mode mode = {VP8E_FOURFIVE, VP8E_THREEFIVE};
+      encoder->Control(VP8E_SET_SCALEMODE, &mode);
+    }
+  }
+};
+
+TEST_P(ResizeInternalTest, TestInternalResizeWorks) {
+  ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
+                                       30, 1, 0, 5);
+  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+
+  for (std::vector<FrameInfo>::iterator info = frame_info_list_.begin();
+       info != frame_info_list_.end(); ++info) {
+    const vpx_codec_pts_t pts = info->pts;
+    if (pts >= 3) {
+      ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width";
+      ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height";
+    } else {
+      EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width";
+      EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height";
+    }
+  }
+}
+
 VP8_INSTANTIATE_TEST_CASE(ResizeTest, ONE_PASS_TEST_MODES);
+VP9_INSTANTIATE_TEST_CASE(ResizeInternalTest,
+                          ::testing::Values(::libvpx_test::kOnePassBest));
 }  // namespace
index 1bbf95468f52b31161e7156f7957de1493c08421..db6e03e0626f6cc6150a3fde8a48fefdc43c3efe 100644 (file)
@@ -4205,15 +4205,16 @@ int vp9_set_internal_size(VP9_PTR comp,
   VP9_COMP *cpi = (VP9_COMP *) comp;
 
   if (horiz_mode <= ONETWO)
-    cpi->common.horiz_scale = horiz_mode;
+    cpi->horiz_scale = horiz_mode;
   else
     return -1;
 
   if (vert_mode <= ONETWO)
-    cpi->common.vert_scale  = vert_mode;
+    cpi->vert_scale = vert_mode;
   else
     return -1;
 
+  vp9_change_config(comp, &cpi->oxcf);
   return 0;
 }