1 /*
2 * Copyright (c) 2022, 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 <ostream>
14
15 #include "gtest/gtest.h"
16
17 #include "test/codec_factory.h"
18 #include "test/encode_test_driver.h"
19 #include "test/util.h"
20 #include "test/y4m_video_source.h"
21 #include "test/yuv_video_source.h"
22
23 namespace {
24
25 const unsigned int kFrames = 20;
26 const int kBitrate = 500;
27 typedef struct {
28 const char *filename;
29 unsigned int input_bit_depth;
30 aom_img_fmt fmt;
31 aom_bit_depth_t bit_depth;
32 unsigned int profile;
33 } TestVideoParam;
34
operator <<(std::ostream & os,const TestVideoParam & test_arg)35 std::ostream &operator<<(std::ostream &os, const TestVideoParam &test_arg) {
36 return os << "TestVideoParam { filename:" << test_arg.filename
37 << " input_bit_depth:" << test_arg.input_bit_depth
38 << " fmt:" << test_arg.fmt << " bit_depth:" << test_arg.bit_depth
39 << " profile:" << test_arg.profile << " }";
40 }
41
42 const TestVideoParam kTestVectors[] = {
43 { "niklas_1280_720_30.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
44 { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
45 };
46
47 // Params: test video, speed, aq mode, threads, tile columns.
48 class AllIntraEndToEndTest
49 : public ::libaom_test::CodecTestWith6Params<TestVideoParam, int, int, int,
50 int, int>,
51 public ::libaom_test::EncoderTest {
52 protected:
AllIntraEndToEndTest()53 AllIntraEndToEndTest()
54 : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
55 cpu_used_(GET_PARAM(2)), psnr_(0.0), nframes_(0),
56 deltaq_mode_(GET_PARAM(3)), threads_(GET_PARAM(4)),
57 tile_columns_(GET_PARAM(5)), enable_tx_size_search_(GET_PARAM(6)) {}
58
59 ~AllIntraEndToEndTest() override = default;
60
SetUp()61 void SetUp() override {
62 InitializeConfig(::libaom_test::kAllIntra);
63 cfg_.g_threads = threads_;
64 }
65
BeginPassHook(unsigned int)66 void BeginPassHook(unsigned int) override {
67 psnr_ = 0.0;
68 nframes_ = 0;
69 }
70
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)71 void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
72 psnr_ += pkt->data.psnr.psnr[0];
73 nframes_++;
74 }
75
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)76 void PreEncodeFrameHook(::libaom_test::VideoSource *video,
77 ::libaom_test::Encoder *encoder) override {
78 if (video->frame() == 0) {
79 encoder->Control(AV1E_SET_ROW_MT, 1);
80 encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
81 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
82 encoder->Control(AV1E_SET_TILE_COLUMNS, tile_columns_);
83 encoder->Control(AOME_SET_CPUUSED, cpu_used_);
84 encoder->Control(AV1E_SET_DELTAQ_MODE, deltaq_mode_);
85 encoder->Control(AV1E_SET_ENABLE_TX_SIZE_SEARCH, enable_tx_size_search_);
86 }
87 }
88
GetAveragePsnr() const89 double GetAveragePsnr() const {
90 if (nframes_) return psnr_ / nframes_;
91 return 0.0;
92 }
93
DoTest()94 void DoTest() {
95 cfg_.rc_target_bitrate = kBitrate;
96 cfg_.g_error_resilient = 0;
97 cfg_.g_profile = test_video_param_.profile;
98 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
99 cfg_.g_bit_depth = test_video_param_.bit_depth;
100 init_flags_ = AOM_CODEC_USE_PSNR;
101 if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
102
103 std::unique_ptr<libaom_test::VideoSource> video;
104 if (is_extension_y4m(test_video_param_.filename))
105 video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
106 kFrames));
107 else
108 video.reset(new libaom_test::YUVVideoSource(test_video_param_.filename,
109 test_video_param_.fmt, 352,
110 288, 30, 1, 0, kFrames));
111 ASSERT_NE(video, nullptr);
112
113 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
114 }
115
116 TestVideoParam test_video_param_;
117 int cpu_used_;
118
119 private:
120 double psnr_;
121 unsigned int nframes_;
122 unsigned int deltaq_mode_;
123 int threads_;
124 int tile_columns_;
125 int enable_tx_size_search_;
126 };
127
128 using AllIntraEndToEndTestLarge = AllIntraEndToEndTest;
129 using AllIntraEndToEndTestLarge2 = AllIntraEndToEndTestLarge;
130
TEST_P(AllIntraEndToEndTest,EndToEndNoFailure)131 TEST_P(AllIntraEndToEndTest, EndToEndNoFailure) { DoTest(); }
TEST_P(AllIntraEndToEndTestLarge,EndToEndNoFailure)132 TEST_P(AllIntraEndToEndTestLarge, EndToEndNoFailure) { DoTest(); }
TEST_P(AllIntraEndToEndTestLarge2,EndToEndNoFailure)133 TEST_P(AllIntraEndToEndTestLarge2, EndToEndNoFailure) { DoTest(); }
134
135 AV1_INSTANTIATE_TEST_SUITE(AllIntraEndToEndTest,
136 ::testing::ValuesIn(kTestVectors),
137 ::testing::Range(6, 9), ::testing::Values(0, 3),
138 ::testing::Values(1), ::testing::Values(1),
139 ::testing::Values(0, 1));
140
141 AV1_INSTANTIATE_TEST_SUITE(AllIntraEndToEndTestLarge,
142 ::testing::ValuesIn(kTestVectors),
143 ::testing::Range(6, 9), ::testing::Values(1, 2),
144 ::testing::Values(1), ::testing::Values(1),
145 ::testing::Values(0, 1));
146
147 AV1_INSTANTIATE_TEST_SUITE(AllIntraEndToEndTestLarge2,
148 ::testing::ValuesIn(kTestVectors),
149 ::testing::Values(5), ::testing::Range(0, 4),
150 ::testing::Values(1), ::testing::Values(1),
151 ::testing::Values(0, 1));
152
153 INSTANTIATE_TEST_SUITE_P(
154 AV1MultiThreaded, AllIntraEndToEndTest,
155 ::testing::Combine(
156 ::testing::Values(
157 static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)),
158 ::testing::ValuesIn(kTestVectors), ::testing::Range(6, 9),
159 ::testing::Values(0, 3), ::testing::Values(6), ::testing::Values(1),
160 ::testing::Values(0, 1)));
161
162 INSTANTIATE_TEST_SUITE_P(
163 AV1MultiThreaded, AllIntraEndToEndTestLarge,
164 ::testing::Combine(
165 ::testing::Values(
166 static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)),
167 ::testing::ValuesIn(kTestVectors), ::testing::Range(6, 9),
168 ::testing::Values(1, 2), ::testing::Values(6), ::testing::Values(1),
169 ::testing::Values(0, 1)));
170
171 INSTANTIATE_TEST_SUITE_P(
172 AV1MultiThreaded, AllIntraEndToEndTestLarge2,
173 ::testing::Combine(
174 ::testing::Values(
175 static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)),
176 ::testing::ValuesIn(kTestVectors), ::testing::Values(5),
177 ::testing::Range(0, 4), ::testing::Values(6), ::testing::Values(1),
178 ::testing::Values(0, 1)));
179
180 } // namespace
181