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#include "third_party/googletest/src/include/gtest/gtest.h" 11#include "test/codec_factory.h" 12#include "test/encode_test_driver.h" 13#include "test/i420_video_source.h" 14#include "test/util.h" 15#include "test/y4m_video_source.h" 16 17namespace { 18 19const int kMaxPSNR = 100; 20 21class CpuSpeedTest 22 : public ::libvpx_test::EncoderTest, 23 public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> { 24 protected: 25 CpuSpeedTest() 26 : EncoderTest(GET_PARAM(0)), 27 encoding_mode_(GET_PARAM(1)), 28 set_cpu_used_(GET_PARAM(2)), 29 min_psnr_(kMaxPSNR) {} 30 virtual ~CpuSpeedTest() {} 31 32 virtual void SetUp() { 33 InitializeConfig(); 34 SetMode(encoding_mode_); 35 if (encoding_mode_ != ::libvpx_test::kRealTime) { 36 cfg_.g_lag_in_frames = 25; 37 cfg_.rc_end_usage = VPX_VBR; 38 } else { 39 cfg_.g_lag_in_frames = 0; 40 cfg_.rc_end_usage = VPX_CBR; 41 } 42 } 43 44 virtual void BeginPassHook(unsigned int /*pass*/) { 45 min_psnr_ = kMaxPSNR; 46 } 47 48 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, 49 ::libvpx_test::Encoder *encoder) { 50 if (video->frame() == 1) { 51 encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); 52 if (encoding_mode_ != ::libvpx_test::kRealTime) { 53 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); 54 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7); 55 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5); 56 encoder->Control(VP8E_SET_ARNR_TYPE, 3); 57 } 58 } 59 } 60 61 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { 62 if (pkt->data.psnr.psnr[0] < min_psnr_) 63 min_psnr_ = pkt->data.psnr.psnr[0]; 64 } 65 66 ::libvpx_test::TestMode encoding_mode_; 67 int set_cpu_used_; 68 double min_psnr_; 69}; 70 71TEST_P(CpuSpeedTest, TestQ0) { 72 // Validate that this non multiple of 64 wide clip encodes and decodes 73 // without a mismatch when passing in a very low max q. This pushes 74 // the encoder to producing lots of big partitions which will likely 75 // extend into the border and test the border condition. 76 cfg_.rc_2pass_vbr_minsection_pct = 5; 77 cfg_.rc_2pass_vbr_minsection_pct = 2000; 78 cfg_.rc_target_bitrate = 400; 79 cfg_.rc_max_quantizer = 0; 80 cfg_.rc_min_quantizer = 0; 81 82 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, 83 20); 84 85 init_flags_ = VPX_CODEC_USE_PSNR; 86 87 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 88 EXPECT_GE(min_psnr_, kMaxPSNR); 89} 90 91TEST_P(CpuSpeedTest, TestScreencastQ0) { 92 ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25); 93 cfg_.g_timebase = video.timebase(); 94 cfg_.rc_2pass_vbr_minsection_pct = 5; 95 cfg_.rc_2pass_vbr_minsection_pct = 2000; 96 cfg_.rc_target_bitrate = 400; 97 cfg_.rc_max_quantizer = 0; 98 cfg_.rc_min_quantizer = 0; 99 100 init_flags_ = VPX_CODEC_USE_PSNR; 101 102 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 103 EXPECT_GE(min_psnr_, kMaxPSNR); 104} 105 106TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { 107 // Validate that this non multiple of 64 wide clip encodes and decodes 108 // without a mismatch when passing in a very low max q. This pushes 109 // the encoder to producing lots of big partitions which will likely 110 // extend into the border and test the border condition. 111 cfg_.rc_2pass_vbr_minsection_pct = 5; 112 cfg_.rc_2pass_vbr_minsection_pct = 2000; 113 cfg_.rc_target_bitrate = 12000; 114 cfg_.rc_max_quantizer = 10; 115 cfg_.rc_min_quantizer = 0; 116 117 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, 118 20); 119 120 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 121} 122 123TEST_P(CpuSpeedTest, TestLowBitrate) { 124 // Validate that this clip encodes and decodes without a mismatch 125 // when passing in a very high min q. This pushes the encoder to producing 126 // lots of small partitions which might will test the other condition. 127 cfg_.rc_2pass_vbr_minsection_pct = 5; 128 cfg_.rc_2pass_vbr_minsection_pct = 2000; 129 cfg_.rc_target_bitrate = 200; 130 cfg_.rc_min_quantizer = 40; 131 132 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, 133 20); 134 135 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 136} 137 138VP9_INSTANTIATE_TEST_CASE( 139 CpuSpeedTest, 140 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood, 141 ::libvpx_test::kRealTime), 142 ::testing::Range(0, 9)); 143 144VP10_INSTANTIATE_TEST_CASE( 145 CpuSpeedTest, 146 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood), 147 ::testing::Range(0, 3)); 148} // namespace 149