2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #include "third_party/googletest/src/googletest/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"
21 const int kMaxPSNR
= 100;
24 : public ::libaom_test::CodecTestWith2Params
<libaom_test::TestMode
, int>,
25 public ::libaom_test::EncoderTest
{
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 virtual ~CpuSpeedTest() {}
33 virtual void SetUp() {
35 SetMode(encoding_mode_
);
36 if (encoding_mode_
!= ::libaom_test::kRealTime
) {
37 cfg_
.g_lag_in_frames
= 25;
38 cfg_
.rc_end_usage
= AOM_VBR
;
40 cfg_
.g_lag_in_frames
= 0;
41 cfg_
.rc_end_usage
= AOM_CBR
;
45 virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_
= kMaxPSNR
; }
47 virtual void PreEncodeFrameHook(::libaom_test::VideoSource
*video
,
48 ::libaom_test::Encoder
*encoder
) {
49 if (video
->frame() == 1) {
50 encoder
->Control(AOME_SET_CPUUSED
, set_cpu_used_
);
51 encoder
->Control(AV1E_SET_TUNE_CONTENT
, tune_content_
);
52 if (encoding_mode_
!= ::libaom_test::kRealTime
) {
53 encoder
->Control(AOME_SET_ENABLEAUTOALTREF
, 1);
54 encoder
->Control(AOME_SET_ARNR_MAXFRAMES
, 7);
55 encoder
->Control(AOME_SET_ARNR_STRENGTH
, 5);
60 virtual void PSNRPktHook(const aom_codec_cx_pkt_t
*pkt
) {
61 if (pkt
->data
.psnr
.psnr
[0] < min_psnr_
) min_psnr_
= pkt
->data
.psnr
.psnr
[0];
65 void TestScreencastQ0();
66 void TestTuneScreen();
67 void TestEncodeHighBitrate();
68 void TestLowBitrate();
70 ::libaom_test::TestMode encoding_mode_
;
76 void CpuSpeedTest::TestQ0() {
77 // Validate that this non multiple of 64 wide clip encodes and decodes
78 // without a mismatch when passing in a very low max q. This pushes
79 // the encoder to producing lots of big partitions which will likely
80 // extend into the border and test the border condition.
81 cfg_
.rc_2pass_vbr_minsection_pct
= 5;
82 cfg_
.rc_2pass_vbr_maxsection_pct
= 2000;
83 cfg_
.rc_target_bitrate
= 400;
84 cfg_
.rc_max_quantizer
= 0;
85 cfg_
.rc_min_quantizer
= 0;
87 ::libaom_test::I420VideoSource
video("hantro_odd.yuv", 208, 144, 30, 1, 0,
90 init_flags_
= AOM_CODEC_USE_PSNR
;
92 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
93 EXPECT_GE(min_psnr_
, kMaxPSNR
);
96 void CpuSpeedTest::TestScreencastQ0() {
97 ::libaom_test::Y4mVideoSource
video("screendata.y4m", 0, 3);
98 cfg_
.g_timebase
= video
.timebase();
99 cfg_
.rc_2pass_vbr_minsection_pct
= 5;
100 cfg_
.rc_2pass_vbr_maxsection_pct
= 2000;
101 cfg_
.rc_target_bitrate
= 400;
102 cfg_
.rc_max_quantizer
= 0;
103 cfg_
.rc_min_quantizer
= 0;
105 init_flags_
= AOM_CODEC_USE_PSNR
;
107 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
108 EXPECT_GE(min_psnr_
, kMaxPSNR
);
111 void CpuSpeedTest::TestTuneScreen() {
112 ::libaom_test::Y4mVideoSource
video("screendata.y4m", 0, 3);
113 cfg_
.g_timebase
= video
.timebase();
114 cfg_
.rc_2pass_vbr_minsection_pct
= 5;
115 cfg_
.rc_2pass_vbr_minsection_pct
= 2000;
116 cfg_
.rc_target_bitrate
= 2000;
117 cfg_
.rc_max_quantizer
= 63;
118 cfg_
.rc_min_quantizer
= 0;
119 tune_content_
= AOM_CONTENT_SCREEN
;
121 init_flags_
= AOM_CODEC_USE_PSNR
;
123 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
126 void CpuSpeedTest::TestEncodeHighBitrate() {
127 // Validate that this non multiple of 64 wide clip encodes and decodes
128 // without a mismatch when passing in a very low max q. This pushes
129 // the encoder to producing lots of big partitions which will likely
130 // extend into the border and test the border condition.
131 cfg_
.rc_2pass_vbr_minsection_pct
= 5;
132 cfg_
.rc_2pass_vbr_maxsection_pct
= 2000;
133 cfg_
.rc_target_bitrate
= 12000;
134 cfg_
.rc_max_quantizer
= 10;
135 cfg_
.rc_min_quantizer
= 0;
137 ::libaom_test::I420VideoSource
video("hantro_odd.yuv", 208, 144, 30, 1, 0,
140 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
143 void CpuSpeedTest::TestLowBitrate() {
144 // Validate that this clip encodes and decodes without a mismatch
145 // when passing in a very high min q. This pushes the encoder to producing
146 // lots of small partitions which might will test the other condition.
147 cfg_
.rc_2pass_vbr_minsection_pct
= 5;
148 cfg_
.rc_2pass_vbr_maxsection_pct
= 2000;
149 cfg_
.rc_target_bitrate
= 200;
150 cfg_
.rc_min_quantizer
= 40;
152 ::libaom_test::I420VideoSource
video("hantro_odd.yuv", 208, 144, 30, 1, 0,
155 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
158 TEST_P(CpuSpeedTest
, TestQ0
) { TestQ0(); }
159 TEST_P(CpuSpeedTest
, TestScreencastQ0
) { TestScreencastQ0(); }
160 TEST_P(CpuSpeedTest
, TestTuneScreen
) { TestTuneScreen(); }
161 TEST_P(CpuSpeedTest
, TestEncodeHighBitrate
) { TestEncodeHighBitrate(); }
162 TEST_P(CpuSpeedTest
, TestLowBitrate
) { TestLowBitrate(); }
164 class CpuSpeedTestLarge
: public CpuSpeedTest
{};
166 TEST_P(CpuSpeedTestLarge
, TestQ0
) { TestQ0(); }
167 TEST_P(CpuSpeedTestLarge
, TestScreencastQ0
) { TestScreencastQ0(); }
168 TEST_P(CpuSpeedTestLarge
, TestTuneScreen
) { TestTuneScreen(); }
169 TEST_P(CpuSpeedTestLarge
, TestEncodeHighBitrate
) { TestEncodeHighBitrate(); }
170 TEST_P(CpuSpeedTestLarge
, TestLowBitrate
) { TestLowBitrate(); }
172 AV1_INSTANTIATE_TEST_CASE(CpuSpeedTest
,
173 ::testing::Values(::libaom_test::kTwoPassGood
,
174 ::libaom_test::kOnePassGood
),
175 ::testing::Range(1, 3));
176 AV1_INSTANTIATE_TEST_CASE(CpuSpeedTestLarge
,
177 ::testing::Values(::libaom_test::kTwoPassGood
,
178 ::libaom_test::kOnePassGood
),
179 ::testing::Range(0, 1));