2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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.
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"
19 const int kMaxPSNR = 100;
22 : public ::libvpx_test::EncoderTest,
23 public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
26 : EncoderTest(GET_PARAM(0)),
27 encoding_mode_(GET_PARAM(1)),
28 set_cpu_used_(GET_PARAM(2)),
30 tune_content_(VP9E_CONTENT_DEFAULT) {}
31 virtual ~CpuSpeedTest() {}
33 virtual void SetUp() {
35 SetMode(encoding_mode_);
36 if (encoding_mode_ != ::libvpx_test::kRealTime) {
37 cfg_.g_lag_in_frames = 25;
38 cfg_.rc_end_usage = VPX_VBR;
40 cfg_.g_lag_in_frames = 0;
41 cfg_.rc_end_usage = VPX_CBR;
45 virtual void BeginPassHook(unsigned int /*pass*/) {
49 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
50 ::libvpx_test::Encoder *encoder) {
51 if (video->frame() == 1) {
52 encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
53 encoder->Control(VP9E_SET_TUNE_CONTENT, VP9E_CONTENT_SCREEN);
54 if (encoding_mode_ != ::libvpx_test::kRealTime) {
55 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
56 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
57 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
58 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
63 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
64 if (pkt->data.psnr.psnr[0] < min_psnr_)
65 min_psnr_ = pkt->data.psnr.psnr[0];
68 ::libvpx_test::TestMode encoding_mode_;
74 TEST_P(CpuSpeedTest, TestQ0) {
75 // Validate that this non multiple of 64 wide clip encodes and decodes
76 // without a mismatch when passing in a very low max q. This pushes
77 // the encoder to producing lots of big partitions which will likely
78 // extend into the border and test the border condition.
79 cfg_.rc_2pass_vbr_minsection_pct = 5;
80 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
81 cfg_.rc_target_bitrate = 400;
82 cfg_.rc_max_quantizer = 0;
83 cfg_.rc_min_quantizer = 0;
85 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
88 init_flags_ = VPX_CODEC_USE_PSNR;
90 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
91 EXPECT_GE(min_psnr_, kMaxPSNR);
94 TEST_P(CpuSpeedTest, TestScreencastQ0) {
95 ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
96 cfg_.g_timebase = video.timebase();
97 cfg_.rc_2pass_vbr_minsection_pct = 5;
98 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
99 cfg_.rc_target_bitrate = 400;
100 cfg_.rc_max_quantizer = 0;
101 cfg_.rc_min_quantizer = 0;
103 init_flags_ = VPX_CODEC_USE_PSNR;
105 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
106 EXPECT_GE(min_psnr_, kMaxPSNR);
109 TEST_P(CpuSpeedTest, TestTuneScreen) {
110 ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
111 cfg_.g_timebase = video.timebase();
112 cfg_.rc_2pass_vbr_minsection_pct = 5;
113 cfg_.rc_2pass_vbr_minsection_pct = 2000;
114 cfg_.rc_target_bitrate = 2000;
115 cfg_.rc_max_quantizer = 63;
116 cfg_.rc_min_quantizer = 0;
117 tune_content_ = VP9E_CONTENT_SCREEN;
119 init_flags_ = VPX_CODEC_USE_PSNR;
121 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
124 TEST_P(CpuSpeedTest, TestEncodeHighBitrate) {
125 // Validate that this non multiple of 64 wide clip encodes and decodes
126 // without a mismatch when passing in a very low max q. This pushes
127 // the encoder to producing lots of big partitions which will likely
128 // extend into the border and test the border condition.
129 cfg_.rc_2pass_vbr_minsection_pct = 5;
130 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
131 cfg_.rc_target_bitrate = 12000;
132 cfg_.rc_max_quantizer = 10;
133 cfg_.rc_min_quantizer = 0;
135 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
138 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
141 TEST_P(CpuSpeedTest, TestLowBitrate) {
142 // Validate that this clip encodes and decodes without a mismatch
143 // when passing in a very high min q. This pushes the encoder to producing
144 // lots of small partitions which might will test the other condition.
145 cfg_.rc_2pass_vbr_minsection_pct = 5;
146 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
147 cfg_.rc_target_bitrate = 200;
148 cfg_.rc_min_quantizer = 40;
150 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
153 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
156 VP9_INSTANTIATE_TEST_CASE(
158 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
159 ::libvpx_test::kRealTime),
160 ::testing::Range(0, 9));
162 VP10_INSTANTIATE_TEST_CASE(
164 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood),
165 ::testing::Range(0, 3));