blob: 5396becf4a8d4b5a21f51ba6edaf6efab9c0db5c [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() {
Wan-Teh Changfddea512021-02-18 17:08:38 -080034 InitializeConfig(encoding_mode_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070035 if (encoding_mode_ != ::libaom_test::kRealTime) {
Alex Converse340e7432014-06-26 16:16:38 -070036 cfg_.g_lag_in_frames = 25;
Alex Converse340e7432014-06-26 16:16:38 -070037 }
Jim Bankoskib0520b62013-07-02 14:14:16 -070038 }
39
clang-format3a826f12016-08-11 17:46:05 -070040 virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_ = kMaxPSNR; }
Alex Conversea869e622014-06-26 16:19:40 -070041
Yaowu Xuc27fc142016-08-22 16:08:15 -070042 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
43 ::libaom_test::Encoder *encoder) {
Yunqing Wang51b282d2018-10-01 16:25:34 -070044 if (video->frame() == 0) {
Yaowu Xuf883b422016-08-30 14:01:10 -070045 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
46 encoder->Control(AV1E_SET_TUNE_CONTENT, tune_content_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070047 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yaowu Xuf883b422016-08-30 14:01:10 -070048 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
49 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
50 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
Alex Converse340e7432014-06-26 16:16:38 -070051 }
Jim Bankoskib0520b62013-07-02 14:14:16 -070052 }
53 }
54
Yaowu Xuf883b422016-08-30 14:01:10 -070055 virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
clang-format3a826f12016-08-11 17:46:05 -070056 if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0];
Alex Conversea869e622014-06-26 16:19:40 -070057 }
58
James Zernb5818b72016-08-09 20:32:51 -070059 void TestQ0();
60 void TestScreencastQ0();
61 void TestTuneScreen();
62 void TestEncodeHighBitrate();
63 void TestLowBitrate();
64
Yaowu Xuc27fc142016-08-22 16:08:15 -070065 ::libaom_test::TestMode encoding_mode_;
Jim Bankoskib0520b62013-07-02 14:14:16 -070066 int set_cpu_used_;
Alex Conversea869e622014-06-26 16:19:40 -070067 double min_psnr_;
Alex Converse99178422016-03-15 15:04:14 -070068 int tune_content_;
Jim Bankoskib0520b62013-07-02 14:14:16 -070069};
70
James Zernb5818b72016-08-09 20:32:51 -070071void CpuSpeedTest::TestQ0() {
Jim Bankoskib0520b62013-07-02 14:14:16 -070072 // 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.
Jim Bankoskib0520b62013-07-02 14:14:16 -070076 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su68f2b412016-03-15 09:28:16 -070077 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoskib0520b62013-07-02 14:14:16 -070078 cfg_.rc_target_bitrate = 400;
79 cfg_.rc_max_quantizer = 0;
80 cfg_.rc_min_quantizer = 0;
81
Yaowu Xuc27fc142016-08-22 16:08:15 -070082 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
Debargha Mukherjeea5c4dcb2016-05-06 17:23:01 -070083 10);
Jim Bankoskib0520b62013-07-02 14:14:16 -070084
Yaowu Xuf883b422016-08-30 14:01:10 -070085 init_flags_ = AOM_CODEC_USE_PSNR;
Alex Conversea869e622014-06-26 16:19:40 -070086
Jim Bankoskib0520b62013-07-02 14:14:16 -070087 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Alex Conversea869e622014-06-26 16:19:40 -070088 EXPECT_GE(min_psnr_, kMaxPSNR);
Jim Bankoskib0520b62013-07-02 14:14:16 -070089}
90
James Zernb5818b72016-08-09 20:32:51 -070091void CpuSpeedTest::TestScreencastQ0() {
Yaowu Xu3ccca4b2017-05-08 14:25:48 -070092 ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
Alex Converse5d088122014-06-26 16:21:14 -070093 cfg_.g_timebase = video.timebase();
94 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su68f2b412016-03-15 09:28:16 -070095 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Alex Converse5d088122014-06-26 16:21:14 -070096 cfg_.rc_target_bitrate = 400;
97 cfg_.rc_max_quantizer = 0;
98 cfg_.rc_min_quantizer = 0;
99
Yaowu Xuf883b422016-08-30 14:01:10 -0700100 init_flags_ = AOM_CODEC_USE_PSNR;
Alex Converse5d088122014-06-26 16:21:14 -0700101
102 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
103 EXPECT_GE(min_psnr_, kMaxPSNR);
104}
Jim Bankoskib0520b62013-07-02 14:14:16 -0700105
James Zernb5818b72016-08-09 20:32:51 -0700106void CpuSpeedTest::TestTuneScreen() {
Yaowu Xu3ccca4b2017-05-08 14:25:48 -0700107 ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
Alex Converse99178422016-03-15 15:04:14 -0700108 cfg_.g_timebase = video.timebase();
109 cfg_.rc_2pass_vbr_minsection_pct = 5;
110 cfg_.rc_2pass_vbr_minsection_pct = 2000;
111 cfg_.rc_target_bitrate = 2000;
112 cfg_.rc_max_quantizer = 63;
113 cfg_.rc_min_quantizer = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -0700114 tune_content_ = AOM_CONTENT_SCREEN;
Alex Converse99178422016-03-15 15:04:14 -0700115
Yaowu Xuf883b422016-08-30 14:01:10 -0700116 init_flags_ = AOM_CODEC_USE_PSNR;
Alex Converse99178422016-03-15 15:04:14 -0700117
118 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
119}
120
James Zernb5818b72016-08-09 20:32:51 -0700121void CpuSpeedTest::TestEncodeHighBitrate() {
Jim Bankoskib0520b62013-07-02 14:14:16 -0700122 // Validate that this non multiple of 64 wide clip encodes and decodes
123 // without a mismatch when passing in a very low max q. This pushes
124 // the encoder to producing lots of big partitions which will likely
125 // extend into the border and test the border condition.
Jim Bankoskib0520b62013-07-02 14:14:16 -0700126 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su68f2b412016-03-15 09:28:16 -0700127 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoskib0520b62013-07-02 14:14:16 -0700128 cfg_.rc_target_bitrate = 12000;
129 cfg_.rc_max_quantizer = 10;
130 cfg_.rc_min_quantizer = 0;
131
Yaowu Xuc27fc142016-08-22 16:08:15 -0700132 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
Debargha Mukherjeea5c4dcb2016-05-06 17:23:01 -0700133 10);
Jim Bankoskib0520b62013-07-02 14:14:16 -0700134
135 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
136}
James Zern99df92d2014-07-01 18:22:30 -0700137
James Zernb5818b72016-08-09 20:32:51 -0700138void CpuSpeedTest::TestLowBitrate() {
Jim Bankoskib0520b62013-07-02 14:14:16 -0700139 // Validate that this clip encodes and decodes without a mismatch
140 // when passing in a very high min q. This pushes the encoder to producing
141 // lots of small partitions which might will test the other condition.
Jim Bankoskib0520b62013-07-02 14:14:16 -0700142 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su68f2b412016-03-15 09:28:16 -0700143 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoskib0520b62013-07-02 14:14:16 -0700144 cfg_.rc_target_bitrate = 200;
145 cfg_.rc_min_quantizer = 40;
146
Yaowu Xuc27fc142016-08-22 16:08:15 -0700147 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
Debargha Mukherjeea5c4dcb2016-05-06 17:23:01 -0700148 10);
Jim Bankoskib0520b62013-07-02 14:14:16 -0700149
150 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
151}
152
James Zernb5818b72016-08-09 20:32:51 -0700153TEST_P(CpuSpeedTest, TestQ0) { TestQ0(); }
154TEST_P(CpuSpeedTest, TestScreencastQ0) { TestScreencastQ0(); }
155TEST_P(CpuSpeedTest, TestTuneScreen) { TestTuneScreen(); }
156TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
157TEST_P(CpuSpeedTest, TestLowBitrate) { TestLowBitrate(); }
158
159class CpuSpeedTestLarge : public CpuSpeedTest {};
160
161TEST_P(CpuSpeedTestLarge, TestQ0) { TestQ0(); }
162TEST_P(CpuSpeedTestLarge, TestScreencastQ0) { TestScreencastQ0(); }
163TEST_P(CpuSpeedTestLarge, TestTuneScreen) { TestTuneScreen(); }
164TEST_P(CpuSpeedTestLarge, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
165TEST_P(CpuSpeedTestLarge, TestLowBitrate) { TestLowBitrate(); }
166
chiyotsai9dfac722020-07-07 17:43:02 -0700167AV1_INSTANTIATE_TEST_SUITE(CpuSpeedTest,
168 ::testing::Values(::libaom_test::kTwoPassGood,
169 ::libaom_test::kOnePassGood),
170 ::testing::Range(1, 3));
171AV1_INSTANTIATE_TEST_SUITE(CpuSpeedTestLarge,
172 ::testing::Values(::libaom_test::kTwoPassGood,
173 ::libaom_test::kOnePassGood),
174 ::testing::Range(0, 1));
Jim Bankoskib0520b62013-07-02 14:14:16 -0700175} // namespace