1/* 2 * Copyright (c) 2013 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#include "./vpx_config.h" 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#include "test/y4m_video_source.h" 17 18namespace { 19 20const int kMaxPsnr = 100; 21 22class LosslessTestLarge : public ::libvpx_test::EncoderTest, 23 public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { 24 protected: 25 LosslessTestLarge() 26 : EncoderTest(GET_PARAM(0)), 27 psnr_(kMaxPsnr), 28 nframes_(0), 29 encoding_mode_(GET_PARAM(1)) { 30 } 31 32 virtual ~LosslessTestLarge() {} 33 34 virtual void SetUp() { 35 InitializeConfig(); 36 SetMode(encoding_mode_); 37 } 38 39 virtual void BeginPassHook(unsigned int /*pass*/) { 40 psnr_ = kMaxPsnr; 41 nframes_ = 0; 42 } 43 44 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { 45 if (pkt->data.psnr.psnr[0] < psnr_) 46 psnr_= pkt->data.psnr.psnr[0]; 47 } 48 49 double GetMinPsnr() const { 50 return psnr_; 51 } 52 53 private: 54 double psnr_; 55 unsigned int nframes_; 56 libvpx_test::TestMode encoding_mode_; 57}; 58 59TEST_P(LosslessTestLarge, TestLossLessEncoding) { 60 const vpx_rational timebase = { 33333333, 1000000000 }; 61 cfg_.g_timebase = timebase; 62 cfg_.rc_target_bitrate = 2000; 63 cfg_.g_lag_in_frames = 25; 64 cfg_.rc_min_quantizer = 0; 65 cfg_.rc_max_quantizer = 0; 66 67 init_flags_ = VPX_CODEC_USE_PSNR; 68 69 // intentionally changed the dimension for better testing coverage 70 libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, 71 timebase.den, timebase.num, 0, 10); 72 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 73 const double psnr_lossless = GetMinPsnr(); 74 EXPECT_GE(psnr_lossless, kMaxPsnr); 75} 76 77TEST_P(LosslessTestLarge, TestLossLessEncoding444) { 78 libvpx_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 10); 79 80 cfg_.g_profile = 1; 81 cfg_.g_timebase = video.timebase(); 82 cfg_.rc_target_bitrate = 2000; 83 cfg_.g_lag_in_frames = 25; 84 cfg_.rc_min_quantizer = 0; 85 cfg_.rc_max_quantizer = 0; 86 87 init_flags_ = VPX_CODEC_USE_PSNR; 88 89 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 90 const double psnr_lossless = GetMinPsnr(); 91 EXPECT_GE(psnr_lossless, kMaxPsnr); 92} 93 94VP9_INSTANTIATE_TEST_CASE(LosslessTestLarge, ALL_TEST_MODES); 95} // namespace 96