blob: 5f0134045b5cd19b1014ad91683660e04fe66504 [file] [log] [blame]
Fyodor Kyslov2372d3e2021-11-01 16:11:13 -07001/*
2 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
3 *
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
12#include <memory>
13#include <string>
14#include <unordered_map>
15
16#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
17
18#include "test/codec_factory.h"
19#include "test/encode_test_driver.h"
20#include "test/util.h"
21#include "test/y4m_video_source.h"
22#include "test/yuv_video_source.h"
23
24namespace {
25
26const unsigned int kFrames = 10;
27const int kBitrate = 500;
28
29// List of psnr thresholds for LF settings 0-3
30// keys: video, LF control, aq mode.
31std::unordered_map<std::string,
32 std::unordered_map<int, std::unordered_map<int, double>>>
33 kPsnrThreshold = { { "park_joy_90p_8_420.y4m",
Marco Paniconi64379502021-12-03 00:39:03 -080034 { { 0, { { 0, 35.0 }, { 3, 35.8 } } },
35 { 1, { { 0, 35.1 }, { 3, 35.9 } } },
Marco Paniconi59a7a0d2021-11-04 00:09:01 -070036 { 2, { { 0, 35.1 }, { 3, 36.1 } } },
Fyodor Kyslovd3be91b2021-11-10 19:52:00 -080037 { 3, { { 0, 35.1 }, { 3, 36.1 } } } } },
Fyodor Kyslov2372d3e2021-11-01 16:11:13 -070038 { "paris_352_288_30.y4m",
Fyodor Kyslovd3be91b2021-11-10 19:52:00 -080039 { { 0, { { 0, 35.40 }, { 3, 36.0 } } },
Marco Paniconi59a7a0d2021-11-04 00:09:01 -070040 { 1, { { 0, 35.50 }, { 3, 36.0 } } },
41 { 2, { { 0, 35.50 }, { 3, 36.0 } } },
Fyodor Kyslovd3be91b2021-11-10 19:52:00 -080042 { 3, { { 0, 35.50 }, { 3, 36.0 } } } } },
Fyodor Kyslov2372d3e2021-11-01 16:11:13 -070043 { "niklas_1280_720_30.y4m",
Fyodor Kyslovd3be91b2021-11-10 19:52:00 -080044 { { 0, { { 0, 33.20 }, { 3, 32.90 } } },
Marco Paniconi59a7a0d2021-11-04 00:09:01 -070045 { 1, { { 0, 33.57 }, { 3, 33.22 } } },
Fyodor Kyslovd3be91b2021-11-10 19:52:00 -080046 { 2, { { 0, 33.57 }, { 3, 33.22 } } },
47 { 3, { { 0, 33.45 }, { 3, 33.10 } } } } } };
Fyodor Kyslov2372d3e2021-11-01 16:11:13 -070048
49typedef struct {
50 const char *filename;
51 unsigned int input_bit_depth;
52 aom_img_fmt fmt;
53 aom_bit_depth_t bit_depth;
54 unsigned int profile;
55} TestVideoParam;
56
57std::ostream &operator<<(std::ostream &os, const TestVideoParam &test_arg) {
58 return os << "TestVideoParam { filename:" << test_arg.filename
59 << " input_bit_depth:" << test_arg.input_bit_depth
60 << " fmt:" << test_arg.fmt << " bit_depth:" << test_arg.bit_depth
61 << " profile:" << test_arg.profile << " }";
62}
63
64const TestVideoParam kTestVectors[] = {
65 { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
66 { "paris_352_288_30.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
67 { "niklas_1280_720_30.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
68};
69
70// Params: test video, lf_control, aq mode, threads, tile columns.
71class LFControlEndToEndTest
72 : public ::libaom_test::CodecTestWith5Params<TestVideoParam, int,
73 unsigned int, int, int>,
74 public ::libaom_test::EncoderTest {
75 protected:
76 LFControlEndToEndTest()
77 : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
78 lf_control_(GET_PARAM(2)), psnr_(0.0), nframes_(0),
79 aq_mode_(GET_PARAM(3)), threads_(GET_PARAM(4)),
80 tile_columns_(GET_PARAM(5)) {}
81
82 virtual ~LFControlEndToEndTest() {}
83
84 virtual void SetUp() {
85 InitializeConfig(::libaom_test::kRealTime);
86
87 cfg_.g_threads = threads_;
88 cfg_.rc_buf_sz = 1000;
89 cfg_.rc_buf_initial_sz = 500;
90 cfg_.rc_buf_optimal_sz = 600;
91 cfg_.kf_max_dist = 9999;
92 cfg_.kf_min_dist = 9999;
93 }
94
95 virtual void BeginPassHook(unsigned int) {
96 psnr_ = 0.0;
97 nframes_ = 0;
98 }
99
100 virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
101 psnr_ += pkt->data.psnr.psnr[0];
102 nframes_++;
103 }
104
105 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
106 ::libaom_test::Encoder *encoder) {
107 if (video->frame() == 0) {
108 encoder->Control(AV1E_SET_ENABLE_RESTORATION, 0);
109 encoder->Control(AV1E_SET_ENABLE_OBMC, 0);
110 encoder->Control(AV1E_SET_ENABLE_GLOBAL_MOTION, 0);
111 encoder->Control(AV1E_SET_ENABLE_WARPED_MOTION, 0);
112 encoder->Control(AV1E_SET_DELTAQ_MODE, 0);
113 encoder->Control(AV1E_SET_ENABLE_TPL_MODEL, 0);
114 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
115 encoder->Control(AV1E_SET_TILE_COLUMNS, tile_columns_);
116 encoder->Control(AOME_SET_CPUUSED, 10);
117 encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
118 encoder->Control(AV1E_SET_AQ_MODE, aq_mode_);
119 encoder->Control(AV1E_SET_ROW_MT, 1);
120 encoder->Control(AV1E_SET_ENABLE_CDEF, 1);
121 encoder->Control(AV1E_SET_COEFF_COST_UPD_FREQ, 2);
122 encoder->Control(AV1E_SET_MODE_COST_UPD_FREQ, 2);
123 encoder->Control(AV1E_SET_MV_COST_UPD_FREQ, 2);
124 encoder->Control(AV1E_SET_DV_COST_UPD_FREQ, 2);
125 encoder->Control(AV1E_SET_LOOPFILTER_CONTROL, lf_control_);
126 }
127 }
128
129 double GetAveragePsnr() const {
130 if (nframes_) return psnr_ / nframes_;
131 return 0.0;
132 }
133
134 double GetPsnrThreshold() {
135 return kPsnrThreshold[test_video_param_.filename][lf_control_][aq_mode_];
136 }
137
138 void DoTest() {
139 cfg_.rc_target_bitrate = kBitrate;
140 cfg_.g_error_resilient = 0;
141 cfg_.g_profile = test_video_param_.profile;
142 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
143 cfg_.g_bit_depth = test_video_param_.bit_depth;
144 init_flags_ = AOM_CODEC_USE_PSNR;
145 if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
146
147 std::unique_ptr<libaom_test::VideoSource> video;
148 video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
149 kFrames));
James Zern9dea04e2022-04-28 13:18:36 -0700150 ASSERT_NE(video, nullptr);
Fyodor Kyslov2372d3e2021-11-01 16:11:13 -0700151
152 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
153 const double psnr = GetAveragePsnr();
154 EXPECT_GT(psnr, GetPsnrThreshold())
155 << "loopfilter control = " << lf_control_ << " aq mode = " << aq_mode_;
156 }
157
158 TestVideoParam test_video_param_;
159 int lf_control_;
160
161 private:
162 double psnr_;
163 unsigned int nframes_;
164 unsigned int aq_mode_;
165 int threads_;
166 int tile_columns_;
167};
168
169class LFControlEndToEndTestThreaded : public LFControlEndToEndTest {};
170
171TEST_P(LFControlEndToEndTest, EndtoEndPSNRTest) { DoTest(); }
172
173TEST_P(LFControlEndToEndTestThreaded, EndtoEndPSNRTest) { DoTest(); }
174
Jerome Jiangab963932021-11-15 13:18:52 -0800175TEST(LFControlGetterTest, NullptrInput) {
176 int *lf_level = nullptr;
177 aom_codec_ctx_t encoder;
178 aom_codec_enc_cfg_t cfg;
179 aom_codec_enc_config_default(aom_codec_av1_cx(), &cfg, 1);
180 EXPECT_EQ(aom_codec_enc_init(&encoder, aom_codec_av1_cx(), &cfg, 0),
181 AOM_CODEC_OK);
182 EXPECT_EQ(aom_codec_control(&encoder, AOME_GET_LOOPFILTER_LEVEL, lf_level),
183 AOM_CODEC_INVALID_PARAM);
184 EXPECT_EQ(aom_codec_destroy(&encoder), AOM_CODEC_OK);
185}
186
Fyodor Kyslov2372d3e2021-11-01 16:11:13 -0700187AV1_INSTANTIATE_TEST_SUITE(LFControlEndToEndTest,
188 ::testing::ValuesIn(kTestVectors),
189 ::testing::Range(0, 4),
190 ::testing::Values<unsigned int>(0, 3),
191 ::testing::Values(1), ::testing::Values(1));
192
193AV1_INSTANTIATE_TEST_SUITE(LFControlEndToEndTestThreaded,
194 ::testing::ValuesIn(kTestVectors),
195 ::testing::Range(0, 4),
196 ::testing::Values<unsigned int>(0, 3),
197 ::testing::Range(2, 5), ::testing::Range(2, 5));
198} // namespace