shithub: libvpx

Download patch

ref: b683eecf6dfe9fc947394df6f0e047e2fcbea43e
parent: 6fd7dd1a703b922a5f200c4e1962be5b81c73af0
author: John Koleszar <jkoleszar@google.com>
date: Thu Feb 21 05:38:27 EST 2013

Test upscaling as well as downscaling

Fixes a bug in vp9_set_internal_size() that prevented returning to
the unscaled state. Updated the ResizeInternalTest to scale both
down and up. Added a check that all frames are within 2.5% of the
quality of the initial keyframe.

Change-Id: I3b7ef17cdac144ed05b9148dce6badfa75cff5c8

--- a/test/resize_test.cc
+++ b/test/resize_test.cc
@@ -101,7 +101,7 @@
 
 class ResizeInternalTest : public ResizeTest {
  protected:
-  ResizeInternalTest() : ResizeTest() {}
+  ResizeInternalTest() : ResizeTest(), frame0_psnr_(0.0) {}
 
   virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
                                   libvpx_test::Encoder *encoder) {
@@ -109,19 +109,33 @@
       struct vpx_scaling_mode mode = {VP8E_FOURFIVE, VP8E_THREEFIVE};
       encoder->Control(VP8E_SET_SCALEMODE, &mode);
     }
+    if (video->frame() == 6) {
+      struct vpx_scaling_mode mode = {VP8E_NORMAL, VP8E_NORMAL};
+      encoder->Control(VP8E_SET_SCALEMODE, &mode);
+    }
   }
+
+  virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
+    if (!frame0_psnr_)
+      frame0_psnr_ = pkt->data.psnr.psnr[0];
+    ASSERT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 0.025*frame0_psnr_);
+  }
+
+  double frame0_psnr_;
 };
 
 TEST_P(ResizeInternalTest, TestInternalResizeWorks) {
   ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
-                                       30, 1, 0, 6);
-  cfg_.rc_target_bitrate = 5000;
+                                       30, 1, 0, 10);
+  init_flags_ = VPX_CODEC_USE_PSNR;
+  // q picked such that initial keyframe on this clip is ~30dB PSNR
+  cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = 48;
   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) {
+    if (pts >= 3 && pts < 6) {
       ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width";
       ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height";
     } else {
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -4123,19 +4123,18 @@
   VP9_COMP *cpi = (VP9_COMP *) comp;
   VP9_COMMON *cm = &cpi->common;
 
-  if (horiz_mode <= ONETWO)
-    cm->horiz_scale = horiz_mode;
-  else
+  if (horiz_mode > ONETWO)
     return -1;
 
-  if (vert_mode <= ONETWO)
-    cm->vert_scale = vert_mode;
-  else
+  if (vert_mode > ONETWO)
     return -1;
 
-  if (cm->horiz_scale != NORMAL || cm->vert_scale != NORMAL) {
+  if (cm->horiz_scale != horiz_mode || cm->vert_scale != vert_mode) {
     int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
     int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
+
+    cm->horiz_scale = horiz_mode;
+    cm->vert_scale = vert_mode;
 
     Scale2Ratio(cm->horiz_scale, &hr, &hs);
     Scale2Ratio(cm->vert_scale, &vr, &vs);