Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 10 | */ |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 11 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 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" |
Alex Converse | 5d08812 | 2014-06-26 16:21:14 -0700 | [diff] [blame] | 17 | #include "test/y4m_video_source.h" |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 18 | |
| 19 | namespace { |
| 20 | |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 21 | const int kMaxPSNR = 100; |
| 22 | |
James Zern | 99df92d | 2014-07-01 18:22:30 -0700 | [diff] [blame] | 23 | class CpuSpeedTest |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 24 | : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>, |
| 25 | public ::libaom_test::EncoderTest { |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 26 | protected: |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 27 | CpuSpeedTest() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 28 | : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), |
| 29 | set_cpu_used_(GET_PARAM(2)), min_psnr_(kMaxPSNR), |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 30 | tune_content_(AOM_CONTENT_DEFAULT) {} |
Alex Converse | 6207a38 | 2014-03-12 14:51:42 -0700 | [diff] [blame] | 31 | virtual ~CpuSpeedTest() {} |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 32 | |
| 33 | virtual void SetUp() { |
Wan-Teh Chang | fddea51 | 2021-02-18 17:08:38 -0800 | [diff] [blame] | 34 | InitializeConfig(encoding_mode_); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 35 | if (encoding_mode_ != ::libaom_test::kRealTime) { |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 36 | cfg_.g_lag_in_frames = 25; |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 37 | } |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 38 | } |
| 39 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 40 | virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_ = kMaxPSNR; } |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 41 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 43 | ::libaom_test::Encoder *encoder) { |
Yunqing Wang | 51b282d | 2018-10-01 16:25:34 -0700 | [diff] [blame] | 44 | if (video->frame() == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | encoder->Control(AOME_SET_CPUUSED, set_cpu_used_); |
| 46 | encoder->Control(AV1E_SET_TUNE_CONTENT, tune_content_); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | if (encoding_mode_ != ::libaom_test::kRealTime) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 48 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 49 | encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7); |
| 50 | encoder->Control(AOME_SET_ARNR_STRENGTH, 5); |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 51 | } |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 55 | virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 56 | if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0]; |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 57 | } |
| 58 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 59 | void TestQ0(); |
| 60 | void TestScreencastQ0(); |
| 61 | void TestTuneScreen(); |
| 62 | void TestEncodeHighBitrate(); |
| 63 | void TestLowBitrate(); |
| 64 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | ::libaom_test::TestMode encoding_mode_; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 66 | int set_cpu_used_; |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 67 | double min_psnr_; |
Alex Converse | 9917842 | 2016-03-15 15:04:14 -0700 | [diff] [blame] | 68 | int tune_content_; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 71 | void CpuSpeedTest::TestQ0() { |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 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. |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 76 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | 68f2b41 | 2016-03-15 09:28:16 -0700 | [diff] [blame] | 77 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 78 | cfg_.rc_target_bitrate = 400; |
| 79 | cfg_.rc_max_quantizer = 0; |
| 80 | cfg_.rc_min_quantizer = 0; |
| 81 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 82 | ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, |
Debargha Mukherjee | a5c4dcb | 2016-05-06 17:23:01 -0700 | [diff] [blame] | 83 | 10); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 84 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 85 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 86 | |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 87 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 88 | EXPECT_GE(min_psnr_, kMaxPSNR); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 89 | } |
| 90 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 91 | void CpuSpeedTest::TestScreencastQ0() { |
Yaowu Xu | 3ccca4b | 2017-05-08 14:25:48 -0700 | [diff] [blame] | 92 | ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3); |
Alex Converse | 5d08812 | 2014-06-26 16:21:14 -0700 | [diff] [blame] | 93 | cfg_.g_timebase = video.timebase(); |
| 94 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | 68f2b41 | 2016-03-15 09:28:16 -0700 | [diff] [blame] | 95 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Alex Converse | 5d08812 | 2014-06-26 16:21:14 -0700 | [diff] [blame] | 96 | cfg_.rc_target_bitrate = 400; |
| 97 | cfg_.rc_max_quantizer = 0; |
| 98 | cfg_.rc_min_quantizer = 0; |
| 99 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 100 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | 5d08812 | 2014-06-26 16:21:14 -0700 | [diff] [blame] | 101 | |
| 102 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 103 | EXPECT_GE(min_psnr_, kMaxPSNR); |
| 104 | } |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 105 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 106 | void CpuSpeedTest::TestTuneScreen() { |
Yaowu Xu | 3ccca4b | 2017-05-08 14:25:48 -0700 | [diff] [blame] | 107 | ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3); |
Alex Converse | 9917842 | 2016-03-15 15:04:14 -0700 | [diff] [blame] | 108 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 114 | tune_content_ = AOM_CONTENT_SCREEN; |
Alex Converse | 9917842 | 2016-03-15 15:04:14 -0700 | [diff] [blame] | 115 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 116 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | 9917842 | 2016-03-15 15:04:14 -0700 | [diff] [blame] | 117 | |
| 118 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 119 | } |
| 120 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 121 | void CpuSpeedTest::TestEncodeHighBitrate() { |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 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. |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 126 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | 68f2b41 | 2016-03-15 09:28:16 -0700 | [diff] [blame] | 127 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 128 | cfg_.rc_target_bitrate = 12000; |
| 129 | cfg_.rc_max_quantizer = 10; |
| 130 | cfg_.rc_min_quantizer = 0; |
| 131 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 132 | ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, |
Debargha Mukherjee | a5c4dcb | 2016-05-06 17:23:01 -0700 | [diff] [blame] | 133 | 10); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 134 | |
| 135 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 136 | } |
James Zern | 99df92d | 2014-07-01 18:22:30 -0700 | [diff] [blame] | 137 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 138 | void CpuSpeedTest::TestLowBitrate() { |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 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. |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 142 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | 68f2b41 | 2016-03-15 09:28:16 -0700 | [diff] [blame] | 143 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 144 | cfg_.rc_target_bitrate = 200; |
| 145 | cfg_.rc_min_quantizer = 40; |
| 146 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 147 | ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, |
Debargha Mukherjee | a5c4dcb | 2016-05-06 17:23:01 -0700 | [diff] [blame] | 148 | 10); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 149 | |
| 150 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 151 | } |
| 152 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 153 | TEST_P(CpuSpeedTest, TestQ0) { TestQ0(); } |
| 154 | TEST_P(CpuSpeedTest, TestScreencastQ0) { TestScreencastQ0(); } |
| 155 | TEST_P(CpuSpeedTest, TestTuneScreen) { TestTuneScreen(); } |
| 156 | TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { TestEncodeHighBitrate(); } |
| 157 | TEST_P(CpuSpeedTest, TestLowBitrate) { TestLowBitrate(); } |
| 158 | |
| 159 | class CpuSpeedTestLarge : public CpuSpeedTest {}; |
| 160 | |
| 161 | TEST_P(CpuSpeedTestLarge, TestQ0) { TestQ0(); } |
| 162 | TEST_P(CpuSpeedTestLarge, TestScreencastQ0) { TestScreencastQ0(); } |
| 163 | TEST_P(CpuSpeedTestLarge, TestTuneScreen) { TestTuneScreen(); } |
| 164 | TEST_P(CpuSpeedTestLarge, TestEncodeHighBitrate) { TestEncodeHighBitrate(); } |
| 165 | TEST_P(CpuSpeedTestLarge, TestLowBitrate) { TestLowBitrate(); } |
| 166 | |
chiyotsai | 9dfac72 | 2020-07-07 17:43:02 -0700 | [diff] [blame] | 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)); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 175 | } // namespace |