blob: 8ea3e696502d951caca27e714c84a0891316b489 [file] [log] [blame]
Jim Bankoskib0520b62013-07-02 14:14:16 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jim Bankoskib0520b62013-07-02 14:14:16 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Johann123e8a62017-12-28 14:40:49 -080010 */
Yaowu Xu2ab7ff02016-09-02 12:04:54 -070011
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Jim Bankoskib0520b62013-07-02 14:14:16 -070013#include "test/codec_factory.h"
14#include "test/encode_test_driver.h"
15#include "test/i420_video_source.h"
16#include "test/util.h"
Alex Converse5d088122014-06-26 16:21:14 -070017#include "test/y4m_video_source.h"
Jim Bankoskib0520b62013-07-02 14:14:16 -070018
19namespace {
20
Alex Conversea869e622014-06-26 16:19:40 -070021const int kMaxPSNR = 100;
22
James Zern99df92d2014-07-01 18:22:30 -070023class CpuSpeedTest
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020024 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
25 public ::libaom_test::EncoderTest {
Jim Bankoskib0520b62013-07-02 14:14:16 -070026 protected:
Alex Converse340e7432014-06-26 16:16:38 -070027 CpuSpeedTest()
clang-format3a826f12016-08-11 17:46:05 -070028 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
29 set_cpu_used_(GET_PARAM(2)), min_psnr_(kMaxPSNR),
Yaowu Xuf883b422016-08-30 14:01:10 -070030 tune_content_(AOM_CONTENT_DEFAULT) {}
Alex Converse6207a382014-03-12 14:51:42 -070031 virtual ~CpuSpeedTest() {}
Jim Bankoskib0520b62013-07-02 14:14:16 -070032
33 virtual void SetUp() {
34 InitializeConfig();
Alex Converse340e7432014-06-26 16:16:38 -070035 SetMode(encoding_mode_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070036 if (encoding_mode_ != ::libaom_test::kRealTime) {
Alex Converse340e7432014-06-26 16:16:38 -070037 cfg_.g_lag_in_frames = 25;
Yaowu Xuf883b422016-08-30 14:01:10 -070038 cfg_.rc_end_usage = AOM_VBR;
Alex Converse340e7432014-06-26 16:16:38 -070039 } else {
40 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070041 cfg_.rc_end_usage = AOM_CBR;
Alex Converse340e7432014-06-26 16:16:38 -070042 }
Jim Bankoskib0520b62013-07-02 14:14:16 -070043 }
44
clang-format3a826f12016-08-11 17:46:05 -070045 virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_ = kMaxPSNR; }
Alex Conversea869e622014-06-26 16:19:40 -070046
Yaowu Xuc27fc142016-08-22 16:08:15 -070047 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
48 ::libaom_test::Encoder *encoder) {
Jim Bankoskib0520b62013-07-02 14:14:16 -070049 if (video->frame() == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -070050 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
51 encoder->Control(AV1E_SET_TUNE_CONTENT, tune_content_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070052 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yaowu Xuf883b422016-08-30 14:01:10 -070053 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
54 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
55 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
Alex Converse340e7432014-06-26 16:16:38 -070056 }
Jim Bankoskib0520b62013-07-02 14:14:16 -070057 }
58 }
59
Yaowu Xuf883b422016-08-30 14:01:10 -070060 virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
clang-format3a826f12016-08-11 17:46:05 -070061 if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0];
Alex Conversea869e622014-06-26 16:19:40 -070062 }
63
James Zernb5818b72016-08-09 20:32:51 -070064 void TestQ0();
65 void TestScreencastQ0();
66 void TestTuneScreen();
67 void TestEncodeHighBitrate();
68 void TestLowBitrate();
69
Yaowu Xuc27fc142016-08-22 16:08:15 -070070 ::libaom_test::TestMode encoding_mode_;
Jim Bankoskib0520b62013-07-02 14:14:16 -070071 int set_cpu_used_;
Alex Conversea869e622014-06-26 16:19:40 -070072 double min_psnr_;
Alex Converse99178422016-03-15 15:04:14 -070073 int tune_content_;
Jim Bankoskib0520b62013-07-02 14:14:16 -070074};
75
James Zernb5818b72016-08-09 20:32:51 -070076void CpuSpeedTest::TestQ0() {
Jim Bankoskib0520b62013-07-02 14:14:16 -070077 // Validate that this non multiple of 64 wide clip encodes and decodes
78 // without a mismatch when passing in a very low max q. This pushes
79 // the encoder to producing lots of big partitions which will likely
80 // extend into the border and test the border condition.
Jim Bankoskib0520b62013-07-02 14:14:16 -070081 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su68f2b412016-03-15 09:28:16 -070082 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoskib0520b62013-07-02 14:14:16 -070083 cfg_.rc_target_bitrate = 400;
84 cfg_.rc_max_quantizer = 0;
85 cfg_.rc_min_quantizer = 0;
86
Yaowu Xuc27fc142016-08-22 16:08:15 -070087 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
Debargha Mukherjeea5c4dcb2016-05-06 17:23:01 -070088 10);
Jim Bankoskib0520b62013-07-02 14:14:16 -070089
Yaowu Xuf883b422016-08-30 14:01:10 -070090 init_flags_ = AOM_CODEC_USE_PSNR;
Alex Conversea869e622014-06-26 16:19:40 -070091
Jim Bankoskib0520b62013-07-02 14:14:16 -070092 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Alex Conversea869e622014-06-26 16:19:40 -070093 EXPECT_GE(min_psnr_, kMaxPSNR);
Jim Bankoskib0520b62013-07-02 14:14:16 -070094}
95
James Zernb5818b72016-08-09 20:32:51 -070096void CpuSpeedTest::TestScreencastQ0() {
Yaowu Xu3ccca4b2017-05-08 14:25:48 -070097 ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
Alex Converse5d088122014-06-26 16:21:14 -070098 cfg_.g_timebase = video.timebase();
99 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su68f2b412016-03-15 09:28:16 -0700100 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Alex Converse5d088122014-06-26 16:21:14 -0700101 cfg_.rc_target_bitrate = 400;
102 cfg_.rc_max_quantizer = 0;
103 cfg_.rc_min_quantizer = 0;
104
Yaowu Xuf883b422016-08-30 14:01:10 -0700105 init_flags_ = AOM_CODEC_USE_PSNR;
Alex Converse5d088122014-06-26 16:21:14 -0700106
107 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
108 EXPECT_GE(min_psnr_, kMaxPSNR);
109}
Jim Bankoskib0520b62013-07-02 14:14:16 -0700110
James Zernb5818b72016-08-09 20:32:51 -0700111void CpuSpeedTest::TestTuneScreen() {
Yaowu Xu3ccca4b2017-05-08 14:25:48 -0700112 ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
Alex Converse99178422016-03-15 15:04:14 -0700113 cfg_.g_timebase = video.timebase();
114 cfg_.rc_2pass_vbr_minsection_pct = 5;
115 cfg_.rc_2pass_vbr_minsection_pct = 2000;
116 cfg_.rc_target_bitrate = 2000;
117 cfg_.rc_max_quantizer = 63;
118 cfg_.rc_min_quantizer = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -0700119 tune_content_ = AOM_CONTENT_SCREEN;
Alex Converse99178422016-03-15 15:04:14 -0700120
Yaowu Xuf883b422016-08-30 14:01:10 -0700121 init_flags_ = AOM_CODEC_USE_PSNR;
Alex Converse99178422016-03-15 15:04:14 -0700122
123 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
124}
125
James Zernb5818b72016-08-09 20:32:51 -0700126void CpuSpeedTest::TestEncodeHighBitrate() {
Jim Bankoskib0520b62013-07-02 14:14:16 -0700127 // Validate that this non multiple of 64 wide clip encodes and decodes
128 // without a mismatch when passing in a very low max q. This pushes
129 // the encoder to producing lots of big partitions which will likely
130 // extend into the border and test the border condition.
Jim Bankoskib0520b62013-07-02 14:14:16 -0700131 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su68f2b412016-03-15 09:28:16 -0700132 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoskib0520b62013-07-02 14:14:16 -0700133 cfg_.rc_target_bitrate = 12000;
134 cfg_.rc_max_quantizer = 10;
135 cfg_.rc_min_quantizer = 0;
136
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
Debargha Mukherjeea5c4dcb2016-05-06 17:23:01 -0700138 10);
Jim Bankoskib0520b62013-07-02 14:14:16 -0700139
140 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
141}
James Zern99df92d2014-07-01 18:22:30 -0700142
James Zernb5818b72016-08-09 20:32:51 -0700143void CpuSpeedTest::TestLowBitrate() {
Jim Bankoskib0520b62013-07-02 14:14:16 -0700144 // Validate that this clip encodes and decodes without a mismatch
145 // when passing in a very high min q. This pushes the encoder to producing
146 // lots of small partitions which might will test the other condition.
Jim Bankoskib0520b62013-07-02 14:14:16 -0700147 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su68f2b412016-03-15 09:28:16 -0700148 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoskib0520b62013-07-02 14:14:16 -0700149 cfg_.rc_target_bitrate = 200;
150 cfg_.rc_min_quantizer = 40;
151
Yaowu Xuc27fc142016-08-22 16:08:15 -0700152 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
Debargha Mukherjeea5c4dcb2016-05-06 17:23:01 -0700153 10);
Jim Bankoskib0520b62013-07-02 14:14:16 -0700154
155 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
156}
157
James Zernb5818b72016-08-09 20:32:51 -0700158TEST_P(CpuSpeedTest, TestQ0) { TestQ0(); }
159TEST_P(CpuSpeedTest, TestScreencastQ0) { TestScreencastQ0(); }
160TEST_P(CpuSpeedTest, TestTuneScreen) { TestTuneScreen(); }
161TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
162TEST_P(CpuSpeedTest, TestLowBitrate) { TestLowBitrate(); }
163
164class CpuSpeedTestLarge : public CpuSpeedTest {};
165
166TEST_P(CpuSpeedTestLarge, TestQ0) { TestQ0(); }
167TEST_P(CpuSpeedTestLarge, TestScreencastQ0) { TestScreencastQ0(); }
168TEST_P(CpuSpeedTestLarge, TestTuneScreen) { TestTuneScreen(); }
169TEST_P(CpuSpeedTestLarge, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
170TEST_P(CpuSpeedTestLarge, TestLowBitrate) { TestLowBitrate(); }
171
Yaowu Xuf883b422016-08-30 14:01:10 -0700172AV1_INSTANTIATE_TEST_CASE(CpuSpeedTest,
173 ::testing::Values(::libaom_test::kTwoPassGood,
174 ::libaom_test::kOnePassGood),
175 ::testing::Range(1, 3));
176AV1_INSTANTIATE_TEST_CASE(CpuSpeedTestLarge,
177 ::testing::Values(::libaom_test::kTwoPassGood,
178 ::libaom_test::kOnePassGood),
179 ::testing::Range(0, 1));
Jim Bankoskib0520b62013-07-02 14:14:16 -0700180} // namespace