Bug 1882465 - Update .hg-annotate-ignore-revs and .git-blame-ignore-revs to reflect...
[gecko.git] / third_party / aom / test / gf_pyr_height_test.cc
blob0996d80c254baa82dda2af24bb4973ea70cea0dd
1 /*
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.
12 #include <ostream>
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"
20 namespace {
22 static const struct GFPyrHeightTestParam {
23 int gf_min_pyr_height;
24 int gf_max_pyr_height;
25 double psnr_thresh;
26 } kTestParams[] = {
27 // gf_min_pyr_height = 0
28 { 0, 0, 32.30 },
29 { 0, 1, 33.90 },
30 { 0, 2, 34.00 },
31 { 0, 3, 34.20 },
32 { 0, 4, 34.30 },
33 { 0, 5, 34.35 },
34 // gf_min_pyr_height = 1
35 { 1, 1, 33.90 },
36 { 1, 2, 34.00 },
37 { 1, 3, 34.20 },
38 { 1, 4, 34.30 },
39 { 1, 5, 34.35 },
40 // gf_min_pyr_height = 2
41 { 2, 2, 34.00 },
42 { 2, 3, 34.20 },
43 { 2, 4, 34.30 },
44 { 2, 5, 34.35 },
45 // gf_min_pyr_height = 3
46 { 3, 3, 34.20 },
47 { 3, 4, 34.30 },
48 { 3, 5, 34.35 },
49 // gf_min_pyr_height = 4
50 { 4, 4, 34.30 },
51 { 4, 5, 34.35 },
52 // gf_min_pyr_height = 5
53 { 5, 5, 34.35 },
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 << " }";
66 return os;
69 // Params: encoding mode, rate control mode and GFPyrHeightTestParam object.
70 class GFPyrHeightTest
71 : public ::libaom_test::CodecTestWith3Params<
72 libaom_test::TestMode, aom_rc_mode, GFPyrHeightTestParam>,
73 public ::libaom_test::EncoderTest {
74 protected:
75 GFPyrHeightTest()
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;
88 cpu_used_ = 4;
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;
94 cfg_.g_threads = 0;
95 init_flags_ = AOM_CODEC_USE_PSNR;
98 void BeginPassHook(unsigned int) override {
99 psnr_ = 0.0;
100 nframes_ = 0;
103 void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
104 psnr_ += pkt->data.psnr.psnr[0];
105 nframes_++;
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_;
127 return 0.0;
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_;
137 int cpu_used_;
138 int nframes_;
139 double psnr_;
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,
145 0, 32);
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));
155 } // namespace