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