1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
13*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
14*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
15*77c1e3ccSAndroid Build Coastguard Worker #include "test/i420_video_source.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "test/y4m_video_source.h"
18*77c1e3ccSAndroid Build Coastguard Worker
19*77c1e3ccSAndroid Build Coastguard Worker namespace {
20*77c1e3ccSAndroid Build Coastguard Worker
21*77c1e3ccSAndroid Build Coastguard Worker const int kMaxPSNR = 100;
22*77c1e3ccSAndroid Build Coastguard Worker
23*77c1e3ccSAndroid Build Coastguard Worker class CpuSpeedTest
24*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
25*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
26*77c1e3ccSAndroid Build Coastguard Worker protected:
CpuSpeedTest()27*77c1e3ccSAndroid Build Coastguard Worker CpuSpeedTest()
28*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
29*77c1e3ccSAndroid Build Coastguard Worker set_cpu_used_(GET_PARAM(2)), min_psnr_(kMaxPSNR),
30*77c1e3ccSAndroid Build Coastguard Worker tune_content_(AOM_CONTENT_DEFAULT) {}
31*77c1e3ccSAndroid Build Coastguard Worker ~CpuSpeedTest() override = default;
32*77c1e3ccSAndroid Build Coastguard Worker
SetUp()33*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
34*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(encoding_mode_);
35*77c1e3ccSAndroid Build Coastguard Worker if (encoding_mode_ != ::libaom_test::kRealTime) {
36*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 25;
37*77c1e3ccSAndroid Build Coastguard Worker }
38*77c1e3ccSAndroid Build Coastguard Worker }
39*77c1e3ccSAndroid Build Coastguard Worker
BeginPassHook(unsigned int)40*77c1e3ccSAndroid Build Coastguard Worker void BeginPassHook(unsigned int /*pass*/) override { min_psnr_ = kMaxPSNR; }
41*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)42*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
43*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
44*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
45*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
46*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TUNE_CONTENT, tune_content_);
47*77c1e3ccSAndroid Build Coastguard Worker if (encoding_mode_ != ::libaom_test::kRealTime) {
48*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
49*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
50*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
51*77c1e3ccSAndroid Build Coastguard Worker }
52*77c1e3ccSAndroid Build Coastguard Worker }
53*77c1e3ccSAndroid Build Coastguard Worker }
54*77c1e3ccSAndroid Build Coastguard Worker
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)55*77c1e3ccSAndroid Build Coastguard Worker void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
56*77c1e3ccSAndroid Build Coastguard Worker if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0];
57*77c1e3ccSAndroid Build Coastguard Worker }
58*77c1e3ccSAndroid Build Coastguard Worker
59*77c1e3ccSAndroid Build Coastguard Worker void TestQ0();
60*77c1e3ccSAndroid Build Coastguard Worker void TestScreencastQ0();
61*77c1e3ccSAndroid Build Coastguard Worker void TestTuneScreen();
62*77c1e3ccSAndroid Build Coastguard Worker void TestEncodeHighBitrate();
63*77c1e3ccSAndroid Build Coastguard Worker void TestLowBitrate();
64*77c1e3ccSAndroid Build Coastguard Worker
65*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::TestMode encoding_mode_;
66*77c1e3ccSAndroid Build Coastguard Worker int set_cpu_used_;
67*77c1e3ccSAndroid Build Coastguard Worker double min_psnr_;
68*77c1e3ccSAndroid Build Coastguard Worker int tune_content_;
69*77c1e3ccSAndroid Build Coastguard Worker };
70*77c1e3ccSAndroid Build Coastguard Worker
TestQ0()71*77c1e3ccSAndroid Build Coastguard Worker void CpuSpeedTest::TestQ0() {
72*77c1e3ccSAndroid Build Coastguard Worker // Validate that this non multiple of 64 wide clip encodes and decodes
73*77c1e3ccSAndroid Build Coastguard Worker // without a mismatch when passing in a very low max q. This pushes
74*77c1e3ccSAndroid Build Coastguard Worker // the encoder to producing lots of big partitions which will likely
75*77c1e3ccSAndroid Build Coastguard Worker // extend into the border and test the border condition.
76*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_minsection_pct = 5;
77*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_maxsection_pct = 2000;
78*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 400;
79*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 0;
80*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 0;
81*77c1e3ccSAndroid Build Coastguard Worker
82*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
83*77c1e3ccSAndroid Build Coastguard Worker 10);
84*77c1e3ccSAndroid Build Coastguard Worker
85*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
86*77c1e3ccSAndroid Build Coastguard Worker
87*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
88*77c1e3ccSAndroid Build Coastguard Worker EXPECT_GE(min_psnr_, kMaxPSNR);
89*77c1e3ccSAndroid Build Coastguard Worker }
90*77c1e3ccSAndroid Build Coastguard Worker
TestScreencastQ0()91*77c1e3ccSAndroid Build Coastguard Worker void CpuSpeedTest::TestScreencastQ0() {
92*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
93*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_timebase = video.timebase();
94*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_minsection_pct = 5;
95*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_maxsection_pct = 2000;
96*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 400;
97*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 0;
98*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 0;
99*77c1e3ccSAndroid Build Coastguard Worker
100*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
101*77c1e3ccSAndroid Build Coastguard Worker
102*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
103*77c1e3ccSAndroid Build Coastguard Worker EXPECT_GE(min_psnr_, kMaxPSNR);
104*77c1e3ccSAndroid Build Coastguard Worker }
105*77c1e3ccSAndroid Build Coastguard Worker
TestTuneScreen()106*77c1e3ccSAndroid Build Coastguard Worker void CpuSpeedTest::TestTuneScreen() {
107*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
108*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_timebase = video.timebase();
109*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_minsection_pct = 5;
110*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_maxsection_pct = 2000;
111*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 2000;
112*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 63;
113*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 0;
114*77c1e3ccSAndroid Build Coastguard Worker tune_content_ = AOM_CONTENT_SCREEN;
115*77c1e3ccSAndroid Build Coastguard Worker
116*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
117*77c1e3ccSAndroid Build Coastguard Worker
118*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
119*77c1e3ccSAndroid Build Coastguard Worker }
120*77c1e3ccSAndroid Build Coastguard Worker
TestEncodeHighBitrate()121*77c1e3ccSAndroid Build Coastguard Worker void CpuSpeedTest::TestEncodeHighBitrate() {
122*77c1e3ccSAndroid Build Coastguard Worker // Validate that this non multiple of 64 wide clip encodes and decodes
123*77c1e3ccSAndroid Build Coastguard Worker // without a mismatch when passing in a very low max q. This pushes
124*77c1e3ccSAndroid Build Coastguard Worker // the encoder to producing lots of big partitions which will likely
125*77c1e3ccSAndroid Build Coastguard Worker // extend into the border and test the border condition.
126*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_minsection_pct = 5;
127*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_maxsection_pct = 2000;
128*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 12000;
129*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 10;
130*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 0;
131*77c1e3ccSAndroid Build Coastguard Worker
132*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
133*77c1e3ccSAndroid Build Coastguard Worker 10);
134*77c1e3ccSAndroid Build Coastguard Worker
135*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
136*77c1e3ccSAndroid Build Coastguard Worker }
137*77c1e3ccSAndroid Build Coastguard Worker
TestLowBitrate()138*77c1e3ccSAndroid Build Coastguard Worker void CpuSpeedTest::TestLowBitrate() {
139*77c1e3ccSAndroid Build Coastguard Worker // Validate that this clip encodes and decodes without a mismatch
140*77c1e3ccSAndroid Build Coastguard Worker // when passing in a very high min q. This pushes the encoder to producing
141*77c1e3ccSAndroid Build Coastguard Worker // lots of small partitions which might will test the other condition.
142*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_minsection_pct = 5;
143*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_maxsection_pct = 2000;
144*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 200;
145*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 40;
146*77c1e3ccSAndroid Build Coastguard Worker
147*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
148*77c1e3ccSAndroid Build Coastguard Worker 10);
149*77c1e3ccSAndroid Build Coastguard Worker
150*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
151*77c1e3ccSAndroid Build Coastguard Worker }
152*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(CpuSpeedTest,TestQ0)153*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTest, TestQ0) { TestQ0(); }
TEST_P(CpuSpeedTest,TestScreencastQ0)154*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTest, TestScreencastQ0) { TestScreencastQ0(); }
TEST_P(CpuSpeedTest,TestTuneScreen)155*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTest, TestTuneScreen) { TestTuneScreen(); }
TEST_P(CpuSpeedTest,TestEncodeHighBitrate)156*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
TEST_P(CpuSpeedTest,TestLowBitrate)157*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTest, TestLowBitrate) { TestLowBitrate(); }
158*77c1e3ccSAndroid Build Coastguard Worker
159*77c1e3ccSAndroid Build Coastguard Worker class CpuSpeedTestLarge : public CpuSpeedTest {};
160*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(CpuSpeedTestLarge,TestQ0)161*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTestLarge, TestQ0) { TestQ0(); }
TEST_P(CpuSpeedTestLarge,TestScreencastQ0)162*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTestLarge, TestScreencastQ0) { TestScreencastQ0(); }
TEST_P(CpuSpeedTestLarge,TestTuneScreen)163*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTestLarge, TestTuneScreen) { TestTuneScreen(); }
TEST_P(CpuSpeedTestLarge,TestEncodeHighBitrate)164*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTestLarge, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
TEST_P(CpuSpeedTestLarge,TestLowBitrate)165*77c1e3ccSAndroid Build Coastguard Worker TEST_P(CpuSpeedTestLarge, TestLowBitrate) { TestLowBitrate(); }
166*77c1e3ccSAndroid Build Coastguard Worker
167*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(CpuSpeedTest,
168*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kTwoPassGood,
169*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::kOnePassGood),
170*77c1e3ccSAndroid Build Coastguard Worker ::testing::Range(1, 3));
171*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(CpuSpeedTestLarge,
172*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kTwoPassGood,
173*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::kOnePassGood),
174*77c1e3ccSAndroid Build Coastguard Worker ::testing::Range(0, 1));
175*77c1e3ccSAndroid Build Coastguard Worker } // namespace
176