2 * Copyright (c) 2019, 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.
14 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
15 #include "test/codec_factory.h"
16 #include "test/encode_test_driver.h"
17 #include "test/i420_video_source.h"
18 #include "test/util.h"
22 static const struct GFPyrHeightTestParam
{
23 int gf_min_pyr_height
;
24 int gf_max_pyr_height
;
27 // gf_min_pyr_height = 0
34 // gf_min_pyr_height = 1
40 // gf_min_pyr_height = 2
45 // gf_min_pyr_height = 3
49 // gf_min_pyr_height = 4
52 // gf_min_pyr_height = 5
56 // Compiler may decide to add some padding to the struct above for alignment,
57 // which the gtest may try to print (on error for example). This would cause
58 // valgrind to complain that the padding is uninitialized. To avoid that, we
59 // provide our own function to print the struct.
60 // This also makes '--gtest_list_tests' output more understandable.
61 std::ostream
&operator<<(std::ostream
&os
, const GFPyrHeightTestParam
&p
) {
62 os
<< "GFPyrHeightTestParam { "
63 << "gf_min_pyr_height = " << p
.gf_min_pyr_height
<< ", "
64 << "gf_max_pyr_height = " << p
.gf_max_pyr_height
<< ", "
65 << "psnr_thresh = " << p
.psnr_thresh
<< " }";
69 // Params: encoding mode, rate control mode and GFPyrHeightTestParam object.
71 : public ::libaom_test::CodecTestWith3Params
<
72 libaom_test::TestMode
, aom_rc_mode
, GFPyrHeightTestParam
>,
73 public ::libaom_test::EncoderTest
{
76 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
77 rc_mode_(GET_PARAM(2)) {
78 gf_min_pyr_height_
= GET_PARAM(3).gf_min_pyr_height
;
79 gf_max_pyr_height_
= GET_PARAM(3).gf_max_pyr_height
;
80 psnr_threshold_
= GET_PARAM(3).psnr_thresh
;
82 ~GFPyrHeightTest() override
= default;
84 void SetUp() override
{
85 InitializeConfig(encoding_mode_
);
86 const aom_rational timebase
= { 1, 30 };
87 cfg_
.g_timebase
= timebase
;
89 cfg_
.rc_end_usage
= rc_mode_
;
90 if (rc_mode_
== AOM_VBR
) {
91 cfg_
.rc_target_bitrate
= 200;
93 cfg_
.g_lag_in_frames
= 19;
95 init_flags_
= AOM_CODEC_USE_PSNR
;
98 void BeginPassHook(unsigned int) override
{
103 void PSNRPktHook(const aom_codec_cx_pkt_t
*pkt
) override
{
104 psnr_
+= pkt
->data
.psnr
.psnr
[0];
108 void PreEncodeFrameHook(::libaom_test::VideoSource
*video
,
109 ::libaom_test::Encoder
*encoder
) override
{
110 if (video
->frame() == 0) {
111 encoder
->Control(AOME_SET_CPUUSED
, cpu_used_
);
112 if (rc_mode_
== AOM_Q
) {
113 encoder
->Control(AOME_SET_CQ_LEVEL
, 32);
115 if (encoding_mode_
!= ::libaom_test::kRealTime
) {
116 encoder
->Control(AOME_SET_ENABLEAUTOALTREF
, 1);
117 encoder
->Control(AOME_SET_ARNR_MAXFRAMES
, 7);
118 encoder
->Control(AOME_SET_ARNR_STRENGTH
, 5);
120 encoder
->Control(AV1E_SET_GF_MIN_PYRAMID_HEIGHT
, gf_min_pyr_height_
);
121 encoder
->Control(AV1E_SET_GF_MAX_PYRAMID_HEIGHT
, gf_max_pyr_height_
);
125 double GetAveragePsnr() const {
126 if (nframes_
) return psnr_
/ nframes_
;
130 double GetPsnrThreshold() { return psnr_threshold_
; }
132 ::libaom_test::TestMode encoding_mode_
;
133 aom_rc_mode rc_mode_
;
134 double psnr_threshold_
;
135 int gf_min_pyr_height_
;
136 int gf_max_pyr_height_
;
142 TEST_P(GFPyrHeightTest
, EncodeAndVerifyPSNR
) {
143 libaom_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
144 cfg_
.g_timebase
.den
, cfg_
.g_timebase
.num
,
146 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
147 EXPECT_GT(GetAveragePsnr(), GetPsnrThreshold())
148 << "GF Min Pyramid Height = " << gf_min_pyr_height_
<< ", "
149 << "GF Max Pyramid Height = " << gf_max_pyr_height_
;
152 AV1_INSTANTIATE_TEST_SUITE(GFPyrHeightTest
, NONREALTIME_TEST_MODES
,
153 ::testing::Values(AOM_Q
, AOM_VBR
),
154 ::testing::ValuesIn(kTestParams
));