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)),
29 min_psnr_(kMaxPSNR) {}
30 virtual ~CpuSpeedTest() {}
32 virtual void SetUp() {
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;
39 cfg_.g_lag_in_frames = 0;
40 cfg_.rc_end_usage = VPX_CBR;
44 virtual void BeginPassHook(unsigned int /*pass*/) {
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);
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];
66 ::libvpx_test::TestMode encoding_mode_;
71 TEST_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;
82 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
85 init_flags_ = VPX_CODEC_USE_PSNR;
87 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
88 EXPECT_GE(min_psnr_, kMaxPSNR);
91 TEST_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;
100 init_flags_ = VPX_CODEC_USE_PSNR;
102 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
103 EXPECT_GE(min_psnr_, kMaxPSNR);
106 TEST_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;
117 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
120 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
123 TEST_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;
132 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
135 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
138 VP9_INSTANTIATE_TEST_CASE(
140 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
141 ::libvpx_test::kRealTime),
142 ::testing::Range(0, 9));