vp9_lossless_test.cc revision 9b35249446b07f40ac5fcc3205f2c048616efacc
1/* 2 Copyright (c) 2012 The WebM project authors. All Rights Reserved. 3 4 Use of this source code is governed by a BSD-style license 5 that can be found in the LICENSE file in the root of the source 6 tree. An additional intellectual property rights grant can be found 7 in the file PATENTS. All contributing project authors may 8 be found in the AUTHORS file in the root of the source tree. 9*/ 10 11#include "third_party/googletest/src/include/gtest/gtest.h" 12#include "test/codec_factory.h" 13#include "test/encode_test_driver.h" 14#include "test/i420_video_source.h" 15#include "test/util.h" 16 17namespace { 18 19const int kMaxPsnr = 100; 20 21class LossLessTest : public ::libvpx_test::EncoderTest, 22 public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { 23 protected: 24 LossLessTest() : EncoderTest(GET_PARAM(0)), 25 psnr_(kMaxPsnr), 26 nframes_(0), 27 encoding_mode_(GET_PARAM(1)) { 28 } 29 30 virtual ~LossLessTest() {} 31 32 virtual void SetUp() { 33 InitializeConfig(); 34 SetMode(encoding_mode_); 35 } 36 37 virtual void BeginPassHook(unsigned int /*pass*/) { 38 psnr_ = kMaxPsnr; 39 nframes_ = 0; 40 } 41 42 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { 43 if (pkt->data.psnr.psnr[0] < psnr_) 44 psnr_= pkt->data.psnr.psnr[0]; 45 } 46 47 double GetMinPsnr() const { 48 return psnr_; 49 } 50 51 private: 52 double psnr_; 53 unsigned int nframes_; 54 libvpx_test::TestMode encoding_mode_; 55}; 56 57TEST_P(LossLessTest, TestLossLessEncoding) { 58 const vpx_rational timebase = { 33333333, 1000000000 }; 59 cfg_.g_timebase = timebase; 60 cfg_.rc_target_bitrate = 2000; 61 cfg_.g_lag_in_frames = 25; 62 cfg_.rc_min_quantizer = 0; 63 cfg_.rc_max_quantizer = 0; 64 65 init_flags_ = VPX_CODEC_USE_PSNR; 66 67 // intentionally changed the dimension for better testing coverage 68 libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, 69 timebase.den, timebase.num, 0, 30); 70 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 71 const double psnr_lossless = GetMinPsnr(); 72 EXPECT_GE(psnr_lossless, kMaxPsnr); 73} 74VP9_INSTANTIATE_TEST_CASE(LossLessTest, ALL_TEST_MODES); 75} // namespace 76