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. |
| 10 | */ |
| 11 | |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 12 | #include "third_party/googletest/src/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" |
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 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | : public ::libaom_test::EncoderTest, |
| 25 | public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> { |
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() { |
| 34 | InitializeConfig(); |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 35 | SetMode(encoding_mode_); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | if (encoding_mode_ != ::libaom_test::kRealTime) { |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 37 | cfg_.g_lag_in_frames = 25; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 38 | cfg_.rc_end_usage = AOM_VBR; |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 39 | } else { |
| 40 | cfg_.g_lag_in_frames = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 41 | cfg_.rc_end_usage = AOM_CBR; |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 42 | } |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 43 | } |
| 44 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 45 | virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_ = kMaxPSNR; } |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 46 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 48 | ::libaom_test::Encoder *encoder) { |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 49 | if (video->frame() == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 50 | encoder->Control(AOME_SET_CPUUSED, set_cpu_used_); |
| 51 | encoder->Control(AV1E_SET_TUNE_CONTENT, tune_content_); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 52 | if (encoding_mode_ != ::libaom_test::kRealTime) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 53 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 54 | encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7); |
| 55 | encoder->Control(AOME_SET_ARNR_STRENGTH, 5); |
| 56 | encoder->Control(AOME_SET_ARNR_TYPE, 3); |
Alex Converse | 340e743 | 2014-06-26 16:16:38 -0700 | [diff] [blame] | 57 | } |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 61 | virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 62 | 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] | 63 | } |
| 64 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 65 | void TestQ0(); |
| 66 | void TestScreencastQ0(); |
| 67 | void TestTuneScreen(); |
| 68 | void TestEncodeHighBitrate(); |
| 69 | void TestLowBitrate(); |
| 70 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 71 | ::libaom_test::TestMode encoding_mode_; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 72 | int set_cpu_used_; |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 73 | double min_psnr_; |
Alex Converse | 9917842 | 2016-03-15 15:04:14 -0700 | [diff] [blame] | 74 | int tune_content_; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 77 | void CpuSpeedTest::TestQ0() { |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 78 | // Validate that this non multiple of 64 wide clip encodes and decodes |
| 79 | // without a mismatch when passing in a very low max q. This pushes |
| 80 | // the encoder to producing lots of big partitions which will likely |
| 81 | // extend into the border and test the border condition. |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 82 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | 68f2b41 | 2016-03-15 09:28:16 -0700 | [diff] [blame] | 83 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 84 | cfg_.rc_target_bitrate = 400; |
| 85 | cfg_.rc_max_quantizer = 0; |
| 86 | cfg_.rc_min_quantizer = 0; |
| 87 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 88 | ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, |
Debargha Mukherjee | a5c4dcb | 2016-05-06 17:23:01 -0700 | [diff] [blame] | 89 | 10); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 90 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 91 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 92 | |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 93 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
Alex Converse | a869e62 | 2014-06-26 16:19:40 -0700 | [diff] [blame] | 94 | EXPECT_GE(min_psnr_, kMaxPSNR); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 95 | } |
| 96 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 97 | void CpuSpeedTest::TestScreencastQ0() { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 98 | ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 10); |
Alex Converse | 5d08812 | 2014-06-26 16:21:14 -0700 | [diff] [blame] | 99 | cfg_.g_timebase = video.timebase(); |
| 100 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | 68f2b41 | 2016-03-15 09:28:16 -0700 | [diff] [blame] | 101 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Alex Converse | 5d08812 | 2014-06-26 16:21:14 -0700 | [diff] [blame] | 102 | cfg_.rc_target_bitrate = 400; |
| 103 | cfg_.rc_max_quantizer = 0; |
| 104 | cfg_.rc_min_quantizer = 0; |
| 105 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 106 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | 5d08812 | 2014-06-26 16:21:14 -0700 | [diff] [blame] | 107 | |
| 108 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 109 | EXPECT_GE(min_psnr_, kMaxPSNR); |
| 110 | } |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 111 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 112 | void CpuSpeedTest::TestTuneScreen() { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 113 | ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 10); |
Alex Converse | 9917842 | 2016-03-15 15:04:14 -0700 | [diff] [blame] | 114 | cfg_.g_timebase = video.timebase(); |
| 115 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
| 116 | cfg_.rc_2pass_vbr_minsection_pct = 2000; |
| 117 | cfg_.rc_target_bitrate = 2000; |
| 118 | cfg_.rc_max_quantizer = 63; |
| 119 | cfg_.rc_min_quantizer = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 120 | tune_content_ = AOM_CONTENT_SCREEN; |
Alex Converse | 9917842 | 2016-03-15 15:04:14 -0700 | [diff] [blame] | 121 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 122 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | 9917842 | 2016-03-15 15:04:14 -0700 | [diff] [blame] | 123 | |
| 124 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 125 | } |
| 126 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 127 | void CpuSpeedTest::TestEncodeHighBitrate() { |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 128 | // Validate that this non multiple of 64 wide clip encodes and decodes |
| 129 | // without a mismatch when passing in a very low max q. This pushes |
| 130 | // the encoder to producing lots of big partitions which will likely |
| 131 | // extend into the border and test the border condition. |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 132 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | 68f2b41 | 2016-03-15 09:28:16 -0700 | [diff] [blame] | 133 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 134 | cfg_.rc_target_bitrate = 12000; |
| 135 | cfg_.rc_max_quantizer = 10; |
| 136 | cfg_.rc_min_quantizer = 0; |
| 137 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 138 | ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, |
Debargha Mukherjee | a5c4dcb | 2016-05-06 17:23:01 -0700 | [diff] [blame] | 139 | 10); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 140 | |
| 141 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 142 | } |
James Zern | 99df92d | 2014-07-01 18:22:30 -0700 | [diff] [blame] | 143 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 144 | void CpuSpeedTest::TestLowBitrate() { |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 145 | // Validate that this clip encodes and decodes without a mismatch |
| 146 | // when passing in a very high min q. This pushes the encoder to producing |
| 147 | // lots of small partitions which might will test the other condition. |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 148 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | 68f2b41 | 2016-03-15 09:28:16 -0700 | [diff] [blame] | 149 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 150 | cfg_.rc_target_bitrate = 200; |
| 151 | cfg_.rc_min_quantizer = 40; |
| 152 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 153 | ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, |
Debargha Mukherjee | a5c4dcb | 2016-05-06 17:23:01 -0700 | [diff] [blame] | 154 | 10); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 155 | |
| 156 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 157 | } |
| 158 | |
James Zern | b5818b7 | 2016-08-09 20:32:51 -0700 | [diff] [blame] | 159 | TEST_P(CpuSpeedTest, TestQ0) { TestQ0(); } |
| 160 | TEST_P(CpuSpeedTest, TestScreencastQ0) { TestScreencastQ0(); } |
| 161 | TEST_P(CpuSpeedTest, TestTuneScreen) { TestTuneScreen(); } |
| 162 | TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { TestEncodeHighBitrate(); } |
| 163 | TEST_P(CpuSpeedTest, TestLowBitrate) { TestLowBitrate(); } |
| 164 | |
| 165 | class CpuSpeedTestLarge : public CpuSpeedTest {}; |
| 166 | |
| 167 | TEST_P(CpuSpeedTestLarge, TestQ0) { TestQ0(); } |
| 168 | TEST_P(CpuSpeedTestLarge, TestScreencastQ0) { TestScreencastQ0(); } |
| 169 | TEST_P(CpuSpeedTestLarge, TestTuneScreen) { TestTuneScreen(); } |
| 170 | TEST_P(CpuSpeedTestLarge, TestEncodeHighBitrate) { TestEncodeHighBitrate(); } |
| 171 | TEST_P(CpuSpeedTestLarge, TestLowBitrate) { TestLowBitrate(); } |
| 172 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 173 | AV1_INSTANTIATE_TEST_CASE(CpuSpeedTest, |
| 174 | ::testing::Values(::libaom_test::kTwoPassGood, |
| 175 | ::libaom_test::kOnePassGood), |
| 176 | ::testing::Range(1, 3)); |
| 177 | AV1_INSTANTIATE_TEST_CASE(CpuSpeedTestLarge, |
| 178 | ::testing::Values(::libaom_test::kTwoPassGood, |
| 179 | ::libaom_test::kOnePassGood), |
| 180 | ::testing::Range(0, 1)); |
Jim Bankoski | b0520b6 | 2013-07-02 14:14:16 -0700 | [diff] [blame] | 181 | } // namespace |