xref: /aosp_15_r20/external/libaom/test/cpu_speed_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3  *
4  * 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.
10  */
11 
12 #include "gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/i420_video_source.h"
16 #include "test/util.h"
17 #include "test/y4m_video_source.h"
18 
19 namespace {
20 
21 const int kMaxPSNR = 100;
22 
23 class CpuSpeedTest
24     : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
25       public ::libaom_test::EncoderTest {
26  protected:
CpuSpeedTest()27   CpuSpeedTest()
28       : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
29         set_cpu_used_(GET_PARAM(2)), min_psnr_(kMaxPSNR),
30         tune_content_(AOM_CONTENT_DEFAULT) {}
31   ~CpuSpeedTest() override = default;
32 
SetUp()33   void SetUp() override {
34     InitializeConfig(encoding_mode_);
35     if (encoding_mode_ != ::libaom_test::kRealTime) {
36       cfg_.g_lag_in_frames = 25;
37     }
38   }
39 
BeginPassHook(unsigned int)40   void BeginPassHook(unsigned int /*pass*/) override { min_psnr_ = kMaxPSNR; }
41 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)42   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
43                           ::libaom_test::Encoder *encoder) override {
44     if (video->frame() == 0) {
45       encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
46       encoder->Control(AV1E_SET_TUNE_CONTENT, tune_content_);
47       if (encoding_mode_ != ::libaom_test::kRealTime) {
48         encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
49         encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
50         encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
51       }
52     }
53   }
54 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)55   void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
56     if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0];
57   }
58 
59   void TestQ0();
60   void TestScreencastQ0();
61   void TestTuneScreen();
62   void TestEncodeHighBitrate();
63   void TestLowBitrate();
64 
65   ::libaom_test::TestMode encoding_mode_;
66   int set_cpu_used_;
67   double min_psnr_;
68   int tune_content_;
69 };
70 
TestQ0()71 void 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_maxsection_pct = 2000;
78   cfg_.rc_target_bitrate = 400;
79   cfg_.rc_max_quantizer = 0;
80   cfg_.rc_min_quantizer = 0;
81 
82   ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
83                                        10);
84 
85   init_flags_ = AOM_CODEC_USE_PSNR;
86 
87   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
88   EXPECT_GE(min_psnr_, kMaxPSNR);
89 }
90 
TestScreencastQ0()91 void CpuSpeedTest::TestScreencastQ0() {
92   ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
93   cfg_.g_timebase = video.timebase();
94   cfg_.rc_2pass_vbr_minsection_pct = 5;
95   cfg_.rc_2pass_vbr_maxsection_pct = 2000;
96   cfg_.rc_target_bitrate = 400;
97   cfg_.rc_max_quantizer = 0;
98   cfg_.rc_min_quantizer = 0;
99 
100   init_flags_ = AOM_CODEC_USE_PSNR;
101 
102   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
103   EXPECT_GE(min_psnr_, kMaxPSNR);
104 }
105 
TestTuneScreen()106 void CpuSpeedTest::TestTuneScreen() {
107   ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
108   cfg_.g_timebase = video.timebase();
109   cfg_.rc_2pass_vbr_minsection_pct = 5;
110   cfg_.rc_2pass_vbr_maxsection_pct = 2000;
111   cfg_.rc_target_bitrate = 2000;
112   cfg_.rc_max_quantizer = 63;
113   cfg_.rc_min_quantizer = 0;
114   tune_content_ = AOM_CONTENT_SCREEN;
115 
116   init_flags_ = AOM_CODEC_USE_PSNR;
117 
118   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
119 }
120 
TestEncodeHighBitrate()121 void CpuSpeedTest::TestEncodeHighBitrate() {
122   // 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.
126   cfg_.rc_2pass_vbr_minsection_pct = 5;
127   cfg_.rc_2pass_vbr_maxsection_pct = 2000;
128   cfg_.rc_target_bitrate = 12000;
129   cfg_.rc_max_quantizer = 10;
130   cfg_.rc_min_quantizer = 0;
131 
132   ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
133                                        10);
134 
135   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
136 }
137 
TestLowBitrate()138 void CpuSpeedTest::TestLowBitrate() {
139   // 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.
142   cfg_.rc_2pass_vbr_minsection_pct = 5;
143   cfg_.rc_2pass_vbr_maxsection_pct = 2000;
144   cfg_.rc_target_bitrate = 200;
145   cfg_.rc_min_quantizer = 40;
146 
147   ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
148                                        10);
149 
150   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
151 }
152 
TEST_P(CpuSpeedTest,TestQ0)153 TEST_P(CpuSpeedTest, TestQ0) { TestQ0(); }
TEST_P(CpuSpeedTest,TestScreencastQ0)154 TEST_P(CpuSpeedTest, TestScreencastQ0) { TestScreencastQ0(); }
TEST_P(CpuSpeedTest,TestTuneScreen)155 TEST_P(CpuSpeedTest, TestTuneScreen) { TestTuneScreen(); }
TEST_P(CpuSpeedTest,TestEncodeHighBitrate)156 TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
TEST_P(CpuSpeedTest,TestLowBitrate)157 TEST_P(CpuSpeedTest, TestLowBitrate) { TestLowBitrate(); }
158 
159 class CpuSpeedTestLarge : public CpuSpeedTest {};
160 
TEST_P(CpuSpeedTestLarge,TestQ0)161 TEST_P(CpuSpeedTestLarge, TestQ0) { TestQ0(); }
TEST_P(CpuSpeedTestLarge,TestScreencastQ0)162 TEST_P(CpuSpeedTestLarge, TestScreencastQ0) { TestScreencastQ0(); }
TEST_P(CpuSpeedTestLarge,TestTuneScreen)163 TEST_P(CpuSpeedTestLarge, TestTuneScreen) { TestTuneScreen(); }
TEST_P(CpuSpeedTestLarge,TestEncodeHighBitrate)164 TEST_P(CpuSpeedTestLarge, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
TEST_P(CpuSpeedTestLarge,TestLowBitrate)165 TEST_P(CpuSpeedTestLarge, TestLowBitrate) { TestLowBitrate(); }
166 
167 AV1_INSTANTIATE_TEST_SUITE(CpuSpeedTest,
168                            ::testing::Values(::libaom_test::kTwoPassGood,
169                                              ::libaom_test::kOnePassGood),
170                            ::testing::Range(1, 3));
171 AV1_INSTANTIATE_TEST_SUITE(CpuSpeedTestLarge,
172                            ::testing::Values(::libaom_test::kTwoPassGood,
173                                              ::libaom_test::kOnePassGood),
174                            ::testing::Range(0, 1));
175 }  // namespace
176