xref: /aosp_15_r20/external/libaom/test/horz_superres_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2018, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include <memory>
13*77c1e3ccSAndroid Build Coastguard Worker #include <ostream>
14*77c1e3ccSAndroid Build Coastguard Worker #include <tuple>
15*77c1e3ccSAndroid Build Coastguard Worker 
16*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
17*77c1e3ccSAndroid Build Coastguard Worker 
18*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/encoder.h"
19*77c1e3ccSAndroid Build Coastguard Worker 
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "test/y4m_video_source.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "test/yuv_video_source.h"
25*77c1e3ccSAndroid Build Coastguard Worker 
26*77c1e3ccSAndroid Build Coastguard Worker namespace {
27*77c1e3ccSAndroid Build Coastguard Worker 
28*77c1e3ccSAndroid Build Coastguard Worker using std::make_tuple;
29*77c1e3ccSAndroid Build Coastguard Worker using std::tuple;
30*77c1e3ccSAndroid Build Coastguard Worker 
31*77c1e3ccSAndroid Build Coastguard Worker /* TESTING PARAMETERS */
32*77c1e3ccSAndroid Build Coastguard Worker 
33*77c1e3ccSAndroid Build Coastguard Worker const int kBitrate = 40;
34*77c1e3ccSAndroid Build Coastguard Worker 
35*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
36*77c1e3ccSAndroid Build Coastguard Worker   const char *filename;
37*77c1e3ccSAndroid Build Coastguard Worker   aom_img_fmt fmt;
38*77c1e3ccSAndroid Build Coastguard Worker   aom_bit_depth_t bit_depth;
39*77c1e3ccSAndroid Build Coastguard Worker   unsigned int profile;
40*77c1e3ccSAndroid Build Coastguard Worker   unsigned int limit;
41*77c1e3ccSAndroid Build Coastguard Worker   unsigned int screen_content;
42*77c1e3ccSAndroid Build Coastguard Worker   double psnr_threshold;   // used by modes other than AOM_SUPERRES_AUTO
43*77c1e3ccSAndroid Build Coastguard Worker   double psnr_threshold2;  // used by AOM_SUPERRES_AUTO
44*77c1e3ccSAndroid Build Coastguard Worker } TestVideoParam;
45*77c1e3ccSAndroid Build Coastguard Worker 
operator <<(std::ostream & os,const TestVideoParam & test_arg)46*77c1e3ccSAndroid Build Coastguard Worker std::ostream &operator<<(std::ostream &os, const TestVideoParam &test_arg) {
47*77c1e3ccSAndroid Build Coastguard Worker   return os << "TestVideoParam { filename:" << test_arg.filename
48*77c1e3ccSAndroid Build Coastguard Worker             << " fmt:" << test_arg.fmt << " bit_depth:" << test_arg.bit_depth
49*77c1e3ccSAndroid Build Coastguard Worker             << " profile:" << test_arg.profile << " limit:" << test_arg.limit
50*77c1e3ccSAndroid Build Coastguard Worker             << " screen_content:" << test_arg.screen_content
51*77c1e3ccSAndroid Build Coastguard Worker             << " psnr_threshold:" << test_arg.psnr_threshold << " }";
52*77c1e3ccSAndroid Build Coastguard Worker }
53*77c1e3ccSAndroid Build Coastguard Worker 
54*77c1e3ccSAndroid Build Coastguard Worker const TestVideoParam kTestVideoVectors[] = {
55*77c1e3ccSAndroid Build Coastguard Worker   { "park_joy_90p_8_420.y4m", AOM_IMG_FMT_I420, AOM_BITS_8, 0, 5, 0, 25.3,
56*77c1e3ccSAndroid Build Coastguard Worker     44.7 },
57*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
58*77c1e3ccSAndroid Build Coastguard Worker   { "park_joy_90p_10_444.y4m", AOM_IMG_FMT_I44416, AOM_BITS_10, 1, 5, 0, 27.0,
59*77c1e3ccSAndroid Build Coastguard Worker     46.8 },
60*77c1e3ccSAndroid Build Coastguard Worker #endif
61*77c1e3ccSAndroid Build Coastguard Worker   { "screendata.y4m", AOM_IMG_FMT_I420, AOM_BITS_8, 0, 4, 1, 23.0, 52.5 },
62*77c1e3ccSAndroid Build Coastguard Worker   // Image coding (single frame).
63*77c1e3ccSAndroid Build Coastguard Worker   { "niklas_1280_720_30.y4m", AOM_IMG_FMT_I420, AOM_BITS_8, 0, 1, 0, 32.0,
64*77c1e3ccSAndroid Build Coastguard Worker     49.0 },
65*77c1e3ccSAndroid Build Coastguard Worker };
66*77c1e3ccSAndroid Build Coastguard Worker 
67*77c1e3ccSAndroid Build Coastguard Worker // Modes with extra params have their own tests.
68*77c1e3ccSAndroid Build Coastguard Worker const aom_superres_mode kSuperresModesWithoutParams[] = { AOM_SUPERRES_RANDOM,
69*77c1e3ccSAndroid Build Coastguard Worker                                                           AOM_SUPERRES_AUTO };
70*77c1e3ccSAndroid Build Coastguard Worker 
71*77c1e3ccSAndroid Build Coastguard Worker // Superres denominators and superres kf denominators to be tested
72*77c1e3ccSAndroid Build Coastguard Worker typedef tuple<int, int> SuperresDenominatorPair;
73*77c1e3ccSAndroid Build Coastguard Worker const SuperresDenominatorPair kSuperresDenominators[] = {
74*77c1e3ccSAndroid Build Coastguard Worker   make_tuple(16, 9),  make_tuple(13, 11), make_tuple(9, 9),
75*77c1e3ccSAndroid Build Coastguard Worker   make_tuple(13, 13), make_tuple(11, 16), make_tuple(8, 16),
76*77c1e3ccSAndroid Build Coastguard Worker   make_tuple(16, 8),  make_tuple(8, 8),   make_tuple(9, 14),
77*77c1e3ccSAndroid Build Coastguard Worker };
78*77c1e3ccSAndroid Build Coastguard Worker 
79*77c1e3ccSAndroid Build Coastguard Worker // Superres q thresholds and superres kf q thresholds to be tested
80*77c1e3ccSAndroid Build Coastguard Worker typedef tuple<int, int> SuperresQThresholdPair;
81*77c1e3ccSAndroid Build Coastguard Worker const SuperresQThresholdPair kSuperresQThresholds[] = {
82*77c1e3ccSAndroid Build Coastguard Worker   make_tuple(63, 63), make_tuple(63, 41), make_tuple(17, 63),
83*77c1e3ccSAndroid Build Coastguard Worker   make_tuple(41, 11), make_tuple(1, 37),  make_tuple(11, 11),
84*77c1e3ccSAndroid Build Coastguard Worker   make_tuple(1, 1),   make_tuple(17, 29), make_tuple(29, 11),
85*77c1e3ccSAndroid Build Coastguard Worker };
86*77c1e3ccSAndroid Build Coastguard Worker 
87*77c1e3ccSAndroid Build Coastguard Worker /* END (TESTING PARAMETERS) */
88*77c1e3ccSAndroid Build Coastguard Worker 
89*77c1e3ccSAndroid Build Coastguard Worker // Test parameter list:
90*77c1e3ccSAndroid Build Coastguard Worker //  <[needed for EncoderTest], test_video_param_, superres_mode_>
91*77c1e3ccSAndroid Build Coastguard Worker typedef tuple<const libaom_test::CodecFactory *, TestVideoParam,
92*77c1e3ccSAndroid Build Coastguard Worker               aom_superres_mode>
93*77c1e3ccSAndroid Build Coastguard Worker     HorzSuperresTestParam;
94*77c1e3ccSAndroid Build Coastguard Worker 
95*77c1e3ccSAndroid Build Coastguard Worker class HorzSuperresEndToEndTest
96*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<HorzSuperresTestParam>,
97*77c1e3ccSAndroid Build Coastguard Worker       public ::libaom_test::EncoderTest {
98*77c1e3ccSAndroid Build Coastguard Worker  protected:
HorzSuperresEndToEndTest()99*77c1e3ccSAndroid Build Coastguard Worker   HorzSuperresEndToEndTest()
100*77c1e3ccSAndroid Build Coastguard Worker       : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
101*77c1e3ccSAndroid Build Coastguard Worker         superres_mode_(GET_PARAM(2)), psnr_(0.0), frame_count_(0) {}
102*77c1e3ccSAndroid Build Coastguard Worker 
103*77c1e3ccSAndroid Build Coastguard Worker   ~HorzSuperresEndToEndTest() override = default;
104*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()105*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
106*77c1e3ccSAndroid Build Coastguard Worker     InitializeConfig(::libaom_test::kTwoPassGood);
107*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_lag_in_frames = 5;
108*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_end_usage = AOM_Q;
109*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_target_bitrate = kBitrate;
110*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_error_resilient = 0;
111*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_profile = test_video_param_.profile;
112*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_input_bit_depth = (unsigned int)test_video_param_.bit_depth;
113*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_bit_depth = test_video_param_.bit_depth;
114*77c1e3ccSAndroid Build Coastguard Worker     init_flags_ = AOM_CODEC_USE_PSNR;
115*77c1e3ccSAndroid Build Coastguard Worker     if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
116*77c1e3ccSAndroid Build Coastguard Worker 
117*77c1e3ccSAndroid Build Coastguard Worker     // Set superres parameters
118*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_superres_mode = superres_mode_;
119*77c1e3ccSAndroid Build Coastguard Worker   }
120*77c1e3ccSAndroid Build Coastguard Worker 
BeginPassHook(unsigned int)121*77c1e3ccSAndroid Build Coastguard Worker   void BeginPassHook(unsigned int) override {
122*77c1e3ccSAndroid Build Coastguard Worker     psnr_ = 0.0;
123*77c1e3ccSAndroid Build Coastguard Worker     frame_count_ = 0;
124*77c1e3ccSAndroid Build Coastguard Worker   }
125*77c1e3ccSAndroid Build Coastguard Worker 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)126*77c1e3ccSAndroid Build Coastguard Worker   void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
127*77c1e3ccSAndroid Build Coastguard Worker     psnr_ += pkt->data.psnr.psnr[0];
128*77c1e3ccSAndroid Build Coastguard Worker     frame_count_++;
129*77c1e3ccSAndroid Build Coastguard Worker   }
130*77c1e3ccSAndroid Build Coastguard Worker 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)131*77c1e3ccSAndroid Build Coastguard Worker   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
132*77c1e3ccSAndroid Build Coastguard Worker                           ::libaom_test::Encoder *encoder) override {
133*77c1e3ccSAndroid Build Coastguard Worker     if (video->frame() == 0) {
134*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
135*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_TILE_COLUMNS, 4);
136*77c1e3ccSAndroid Build Coastguard Worker 
137*77c1e3ccSAndroid Build Coastguard Worker       // Set cpu-used = 8 for speed
138*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_CPUUSED, 8);
139*77c1e3ccSAndroid Build Coastguard Worker 
140*77c1e3ccSAndroid Build Coastguard Worker       // Test screen coding tools
141*77c1e3ccSAndroid Build Coastguard Worker       if (test_video_param_.screen_content)
142*77c1e3ccSAndroid Build Coastguard Worker         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN);
143*77c1e3ccSAndroid Build Coastguard Worker       else
144*77c1e3ccSAndroid Build Coastguard Worker         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
145*77c1e3ccSAndroid Build Coastguard Worker 
146*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
147*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
148*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
149*77c1e3ccSAndroid Build Coastguard Worker     }
150*77c1e3ccSAndroid Build Coastguard Worker   }
151*77c1e3ccSAndroid Build Coastguard Worker 
GetAveragePsnr() const152*77c1e3ccSAndroid Build Coastguard Worker   double GetAveragePsnr() const {
153*77c1e3ccSAndroid Build Coastguard Worker     if (frame_count_) return psnr_ / frame_count_;
154*77c1e3ccSAndroid Build Coastguard Worker     return 0.0;
155*77c1e3ccSAndroid Build Coastguard Worker   }
156*77c1e3ccSAndroid Build Coastguard Worker 
DoTest()157*77c1e3ccSAndroid Build Coastguard Worker   void DoTest() {
158*77c1e3ccSAndroid Build Coastguard Worker     std::unique_ptr<libaom_test::VideoSource> video;
159*77c1e3ccSAndroid Build Coastguard Worker     video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
160*77c1e3ccSAndroid Build Coastguard Worker                                                 test_video_param_.limit));
161*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(video, nullptr);
162*77c1e3ccSAndroid Build Coastguard Worker 
163*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
164*77c1e3ccSAndroid Build Coastguard Worker     const double psnr_thresh = (superres_mode_ == AOM_SUPERRES_AUTO)
165*77c1e3ccSAndroid Build Coastguard Worker                                    ? test_video_param_.psnr_threshold2
166*77c1e3ccSAndroid Build Coastguard Worker                                    : test_video_param_.psnr_threshold;
167*77c1e3ccSAndroid Build Coastguard Worker     const double psnr = GetAveragePsnr();
168*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_GT(psnr, psnr_thresh);
169*77c1e3ccSAndroid Build Coastguard Worker 
170*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(test_video_param_.limit, frame_count_);
171*77c1e3ccSAndroid Build Coastguard Worker   }
172*77c1e3ccSAndroid Build Coastguard Worker 
173*77c1e3ccSAndroid Build Coastguard Worker   TestVideoParam test_video_param_;
174*77c1e3ccSAndroid Build Coastguard Worker   aom_superres_mode superres_mode_;
175*77c1e3ccSAndroid Build Coastguard Worker 
176*77c1e3ccSAndroid Build Coastguard Worker  private:
177*77c1e3ccSAndroid Build Coastguard Worker   double psnr_;
178*77c1e3ccSAndroid Build Coastguard Worker   unsigned int frame_count_;
179*77c1e3ccSAndroid Build Coastguard Worker };
180*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(HorzSuperresEndToEndTest,HorzSuperresEndToEndPSNRTest)181*77c1e3ccSAndroid Build Coastguard Worker TEST_P(HorzSuperresEndToEndTest, HorzSuperresEndToEndPSNRTest) { DoTest(); }
182*77c1e3ccSAndroid Build Coastguard Worker 
183*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(HorzSuperresEndToEndTest,
184*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::ValuesIn(kTestVideoVectors),
185*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::ValuesIn(kSuperresModesWithoutParams));
186*77c1e3ccSAndroid Build Coastguard Worker 
187*77c1e3ccSAndroid Build Coastguard Worker // Test parameter list:
188*77c1e3ccSAndroid Build Coastguard Worker //  <[needed for EncoderTest], test_video_param_, tuple(superres_denom_,
189*77c1e3ccSAndroid Build Coastguard Worker //  superres_kf_denom_)>
190*77c1e3ccSAndroid Build Coastguard Worker typedef tuple<const libaom_test::CodecFactory *, TestVideoParam,
191*77c1e3ccSAndroid Build Coastguard Worker               SuperresDenominatorPair>
192*77c1e3ccSAndroid Build Coastguard Worker     HorzSuperresFixedTestParam;
193*77c1e3ccSAndroid Build Coastguard Worker 
194*77c1e3ccSAndroid Build Coastguard Worker class HorzSuperresFixedEndToEndTest
195*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<HorzSuperresFixedTestParam>,
196*77c1e3ccSAndroid Build Coastguard Worker       public ::libaom_test::EncoderTest {
197*77c1e3ccSAndroid Build Coastguard Worker  protected:
HorzSuperresFixedEndToEndTest()198*77c1e3ccSAndroid Build Coastguard Worker   HorzSuperresFixedEndToEndTest()
199*77c1e3ccSAndroid Build Coastguard Worker       : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
200*77c1e3ccSAndroid Build Coastguard Worker         superres_mode_(AOM_SUPERRES_FIXED), psnr_(0.0), frame_count_(0) {
201*77c1e3ccSAndroid Build Coastguard Worker     SuperresDenominatorPair denoms = GET_PARAM(2);
202*77c1e3ccSAndroid Build Coastguard Worker     superres_denom_ = std::get<0>(denoms);
203*77c1e3ccSAndroid Build Coastguard Worker     superres_kf_denom_ = std::get<1>(denoms);
204*77c1e3ccSAndroid Build Coastguard Worker   }
205*77c1e3ccSAndroid Build Coastguard Worker 
206*77c1e3ccSAndroid Build Coastguard Worker   ~HorzSuperresFixedEndToEndTest() override = default;
207*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()208*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
209*77c1e3ccSAndroid Build Coastguard Worker     InitializeConfig(::libaom_test::kTwoPassGood);
210*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_lag_in_frames = 5;
211*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_end_usage = AOM_VBR;
212*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_target_bitrate = kBitrate;
213*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_error_resilient = 0;
214*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_profile = test_video_param_.profile;
215*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_input_bit_depth = (unsigned int)test_video_param_.bit_depth;
216*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_bit_depth = test_video_param_.bit_depth;
217*77c1e3ccSAndroid Build Coastguard Worker     init_flags_ = AOM_CODEC_USE_PSNR;
218*77c1e3ccSAndroid Build Coastguard Worker     if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
219*77c1e3ccSAndroid Build Coastguard Worker 
220*77c1e3ccSAndroid Build Coastguard Worker     // Set superres parameters
221*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_superres_mode = superres_mode_;
222*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_superres_denominator = superres_denom_;
223*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_superres_kf_denominator = superres_kf_denom_;
224*77c1e3ccSAndroid Build Coastguard Worker   }
225*77c1e3ccSAndroid Build Coastguard Worker 
BeginPassHook(unsigned int)226*77c1e3ccSAndroid Build Coastguard Worker   void BeginPassHook(unsigned int) override {
227*77c1e3ccSAndroid Build Coastguard Worker     psnr_ = 0.0;
228*77c1e3ccSAndroid Build Coastguard Worker     frame_count_ = 0;
229*77c1e3ccSAndroid Build Coastguard Worker   }
230*77c1e3ccSAndroid Build Coastguard Worker 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)231*77c1e3ccSAndroid Build Coastguard Worker   void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
232*77c1e3ccSAndroid Build Coastguard Worker     psnr_ += pkt->data.psnr.psnr[0];
233*77c1e3ccSAndroid Build Coastguard Worker     frame_count_++;
234*77c1e3ccSAndroid Build Coastguard Worker   }
235*77c1e3ccSAndroid Build Coastguard Worker 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)236*77c1e3ccSAndroid Build Coastguard Worker   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
237*77c1e3ccSAndroid Build Coastguard Worker                           ::libaom_test::Encoder *encoder) override {
238*77c1e3ccSAndroid Build Coastguard Worker     if (video->frame() == 0) {
239*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
240*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_TILE_COLUMNS, 4);
241*77c1e3ccSAndroid Build Coastguard Worker 
242*77c1e3ccSAndroid Build Coastguard Worker       // Set cpu-used = 8 for speed
243*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_CPUUSED, 8);
244*77c1e3ccSAndroid Build Coastguard Worker 
245*77c1e3ccSAndroid Build Coastguard Worker       // Test screen coding tools
246*77c1e3ccSAndroid Build Coastguard Worker       if (test_video_param_.screen_content)
247*77c1e3ccSAndroid Build Coastguard Worker         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN);
248*77c1e3ccSAndroid Build Coastguard Worker       else
249*77c1e3ccSAndroid Build Coastguard Worker         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
250*77c1e3ccSAndroid Build Coastguard Worker 
251*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
252*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
253*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
254*77c1e3ccSAndroid Build Coastguard Worker     }
255*77c1e3ccSAndroid Build Coastguard Worker   }
256*77c1e3ccSAndroid Build Coastguard Worker 
GetAveragePsnr() const257*77c1e3ccSAndroid Build Coastguard Worker   double GetAveragePsnr() const {
258*77c1e3ccSAndroid Build Coastguard Worker     if (frame_count_) return psnr_ / frame_count_;
259*77c1e3ccSAndroid Build Coastguard Worker     return 0.0;
260*77c1e3ccSAndroid Build Coastguard Worker   }
261*77c1e3ccSAndroid Build Coastguard Worker 
DoTest()262*77c1e3ccSAndroid Build Coastguard Worker   void DoTest() {
263*77c1e3ccSAndroid Build Coastguard Worker     std::unique_ptr<libaom_test::VideoSource> video;
264*77c1e3ccSAndroid Build Coastguard Worker     video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
265*77c1e3ccSAndroid Build Coastguard Worker                                                 test_video_param_.limit));
266*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(video, nullptr);
267*77c1e3ccSAndroid Build Coastguard Worker 
268*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
269*77c1e3ccSAndroid Build Coastguard Worker     const double psnr = GetAveragePsnr();
270*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_GT(psnr, test_video_param_.psnr_threshold)
271*77c1e3ccSAndroid Build Coastguard Worker         << "superres_mode_ = " << superres_mode_
272*77c1e3ccSAndroid Build Coastguard Worker         << ", superres_denom_ = " << superres_denom_
273*77c1e3ccSAndroid Build Coastguard Worker         << ", superres_kf_denom_ = " << superres_kf_denom_;
274*77c1e3ccSAndroid Build Coastguard Worker 
275*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(test_video_param_.limit, frame_count_)
276*77c1e3ccSAndroid Build Coastguard Worker         << "superres_mode_ = " << superres_mode_
277*77c1e3ccSAndroid Build Coastguard Worker         << ", superres_denom_ = " << superres_denom_
278*77c1e3ccSAndroid Build Coastguard Worker         << ", superres_kf_denom_ = " << superres_kf_denom_;
279*77c1e3ccSAndroid Build Coastguard Worker   }
280*77c1e3ccSAndroid Build Coastguard Worker 
281*77c1e3ccSAndroid Build Coastguard Worker   TestVideoParam test_video_param_;
282*77c1e3ccSAndroid Build Coastguard Worker   aom_superres_mode superres_mode_;
283*77c1e3ccSAndroid Build Coastguard Worker   int superres_denom_;
284*77c1e3ccSAndroid Build Coastguard Worker   int superres_kf_denom_;
285*77c1e3ccSAndroid Build Coastguard Worker 
286*77c1e3ccSAndroid Build Coastguard Worker  private:
287*77c1e3ccSAndroid Build Coastguard Worker   double psnr_;
288*77c1e3ccSAndroid Build Coastguard Worker   unsigned int frame_count_;
289*77c1e3ccSAndroid Build Coastguard Worker };
290*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(HorzSuperresFixedEndToEndTest,HorzSuperresFixedTestParam)291*77c1e3ccSAndroid Build Coastguard Worker TEST_P(HorzSuperresFixedEndToEndTest, HorzSuperresFixedTestParam) { DoTest(); }
292*77c1e3ccSAndroid Build Coastguard Worker 
293*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(HorzSuperresFixedEndToEndTest,
294*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::ValuesIn(kTestVideoVectors),
295*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::ValuesIn(kSuperresDenominators));
296*77c1e3ccSAndroid Build Coastguard Worker 
297*77c1e3ccSAndroid Build Coastguard Worker // Test parameter list:
298*77c1e3ccSAndroid Build Coastguard Worker //  <[needed for EncoderTest], test_video_param_,
299*77c1e3ccSAndroid Build Coastguard Worker //  tuple(superres_qthresh_,superres_kf_qthresh_)>
300*77c1e3ccSAndroid Build Coastguard Worker typedef tuple<const libaom_test::CodecFactory *, TestVideoParam,
301*77c1e3ccSAndroid Build Coastguard Worker               SuperresQThresholdPair>
302*77c1e3ccSAndroid Build Coastguard Worker     HorzSuperresQThreshTestParam;
303*77c1e3ccSAndroid Build Coastguard Worker 
304*77c1e3ccSAndroid Build Coastguard Worker class HorzSuperresQThreshEndToEndTest
305*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<HorzSuperresQThreshTestParam>,
306*77c1e3ccSAndroid Build Coastguard Worker       public ::libaom_test::EncoderTest {
307*77c1e3ccSAndroid Build Coastguard Worker  protected:
HorzSuperresQThreshEndToEndTest()308*77c1e3ccSAndroid Build Coastguard Worker   HorzSuperresQThreshEndToEndTest()
309*77c1e3ccSAndroid Build Coastguard Worker       : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
310*77c1e3ccSAndroid Build Coastguard Worker         superres_mode_(AOM_SUPERRES_QTHRESH), psnr_(0.0), frame_count_(0) {
311*77c1e3ccSAndroid Build Coastguard Worker     SuperresQThresholdPair qthresholds = GET_PARAM(2);
312*77c1e3ccSAndroid Build Coastguard Worker     superres_qthresh_ = std::get<0>(qthresholds);
313*77c1e3ccSAndroid Build Coastguard Worker     superres_kf_qthresh_ = std::get<1>(qthresholds);
314*77c1e3ccSAndroid Build Coastguard Worker   }
315*77c1e3ccSAndroid Build Coastguard Worker 
316*77c1e3ccSAndroid Build Coastguard Worker   ~HorzSuperresQThreshEndToEndTest() override = default;
317*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()318*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
319*77c1e3ccSAndroid Build Coastguard Worker     InitializeConfig(::libaom_test::kTwoPassGood);
320*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_lag_in_frames = 5;
321*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_end_usage = AOM_VBR;
322*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_target_bitrate = kBitrate;
323*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_error_resilient = 0;
324*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_profile = test_video_param_.profile;
325*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_input_bit_depth = (unsigned int)test_video_param_.bit_depth;
326*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_bit_depth = test_video_param_.bit_depth;
327*77c1e3ccSAndroid Build Coastguard Worker     init_flags_ = AOM_CODEC_USE_PSNR;
328*77c1e3ccSAndroid Build Coastguard Worker     if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
329*77c1e3ccSAndroid Build Coastguard Worker 
330*77c1e3ccSAndroid Build Coastguard Worker     // Set superres parameters
331*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_superres_mode = superres_mode_;
332*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_superres_qthresh = superres_qthresh_;
333*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_superres_kf_qthresh = superres_kf_qthresh_;
334*77c1e3ccSAndroid Build Coastguard Worker   }
335*77c1e3ccSAndroid Build Coastguard Worker 
BeginPassHook(unsigned int)336*77c1e3ccSAndroid Build Coastguard Worker   void BeginPassHook(unsigned int) override {
337*77c1e3ccSAndroid Build Coastguard Worker     psnr_ = 0.0;
338*77c1e3ccSAndroid Build Coastguard Worker     frame_count_ = 0;
339*77c1e3ccSAndroid Build Coastguard Worker   }
340*77c1e3ccSAndroid Build Coastguard Worker 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)341*77c1e3ccSAndroid Build Coastguard Worker   void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
342*77c1e3ccSAndroid Build Coastguard Worker     psnr_ += pkt->data.psnr.psnr[0];
343*77c1e3ccSAndroid Build Coastguard Worker     frame_count_++;
344*77c1e3ccSAndroid Build Coastguard Worker   }
345*77c1e3ccSAndroid Build Coastguard Worker 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)346*77c1e3ccSAndroid Build Coastguard Worker   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
347*77c1e3ccSAndroid Build Coastguard Worker                           ::libaom_test::Encoder *encoder) override {
348*77c1e3ccSAndroid Build Coastguard Worker     if (video->frame() == 0) {
349*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
350*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_TILE_COLUMNS, 0);
351*77c1e3ccSAndroid Build Coastguard Worker 
352*77c1e3ccSAndroid Build Coastguard Worker       // Set cpu-used = 8 for speed
353*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_CPUUSED, 8);
354*77c1e3ccSAndroid Build Coastguard Worker 
355*77c1e3ccSAndroid Build Coastguard Worker       // Test screen coding tools
356*77c1e3ccSAndroid Build Coastguard Worker       if (test_video_param_.screen_content)
357*77c1e3ccSAndroid Build Coastguard Worker         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN);
358*77c1e3ccSAndroid Build Coastguard Worker       else
359*77c1e3ccSAndroid Build Coastguard Worker         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
360*77c1e3ccSAndroid Build Coastguard Worker 
361*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
362*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
363*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
364*77c1e3ccSAndroid Build Coastguard Worker     }
365*77c1e3ccSAndroid Build Coastguard Worker   }
366*77c1e3ccSAndroid Build Coastguard Worker 
GetAveragePsnr() const367*77c1e3ccSAndroid Build Coastguard Worker   double GetAveragePsnr() const {
368*77c1e3ccSAndroid Build Coastguard Worker     if (frame_count_) return psnr_ / frame_count_;
369*77c1e3ccSAndroid Build Coastguard Worker     return 0.0;
370*77c1e3ccSAndroid Build Coastguard Worker   }
371*77c1e3ccSAndroid Build Coastguard Worker 
DoTest()372*77c1e3ccSAndroid Build Coastguard Worker   void DoTest() {
373*77c1e3ccSAndroid Build Coastguard Worker     std::unique_ptr<libaom_test::VideoSource> video;
374*77c1e3ccSAndroid Build Coastguard Worker     video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
375*77c1e3ccSAndroid Build Coastguard Worker                                                 test_video_param_.limit));
376*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(video, nullptr);
377*77c1e3ccSAndroid Build Coastguard Worker 
378*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
379*77c1e3ccSAndroid Build Coastguard Worker     const double psnr = GetAveragePsnr();
380*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_GT(psnr, test_video_param_.psnr_threshold)
381*77c1e3ccSAndroid Build Coastguard Worker         << "superres_mode_ = " << superres_mode_
382*77c1e3ccSAndroid Build Coastguard Worker         << ", superres_qthresh_ = " << superres_qthresh_
383*77c1e3ccSAndroid Build Coastguard Worker         << ", superres_kf_qthresh_ = " << superres_kf_qthresh_;
384*77c1e3ccSAndroid Build Coastguard Worker 
385*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(test_video_param_.limit, frame_count_)
386*77c1e3ccSAndroid Build Coastguard Worker         << "superres_mode_ = " << superres_mode_
387*77c1e3ccSAndroid Build Coastguard Worker         << ", superres_qthresh_ = " << superres_qthresh_
388*77c1e3ccSAndroid Build Coastguard Worker         << ", superres_kf_qthresh_ = " << superres_kf_qthresh_;
389*77c1e3ccSAndroid Build Coastguard Worker   }
390*77c1e3ccSAndroid Build Coastguard Worker 
391*77c1e3ccSAndroid Build Coastguard Worker   TestVideoParam test_video_param_;
392*77c1e3ccSAndroid Build Coastguard Worker   aom_superres_mode superres_mode_;
393*77c1e3ccSAndroid Build Coastguard Worker   int superres_qthresh_;
394*77c1e3ccSAndroid Build Coastguard Worker   int superres_kf_qthresh_;
395*77c1e3ccSAndroid Build Coastguard Worker 
396*77c1e3ccSAndroid Build Coastguard Worker  private:
397*77c1e3ccSAndroid Build Coastguard Worker   double psnr_;
398*77c1e3ccSAndroid Build Coastguard Worker   unsigned int frame_count_;
399*77c1e3ccSAndroid Build Coastguard Worker };
400*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(HorzSuperresQThreshEndToEndTest,HorzSuperresQThreshEndToEndPSNRTest)401*77c1e3ccSAndroid Build Coastguard Worker TEST_P(HorzSuperresQThreshEndToEndTest, HorzSuperresQThreshEndToEndPSNRTest) {
402*77c1e3ccSAndroid Build Coastguard Worker   DoTest();
403*77c1e3ccSAndroid Build Coastguard Worker }
404*77c1e3ccSAndroid Build Coastguard Worker 
405*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(HorzSuperresQThreshEndToEndTest,
406*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::ValuesIn(kTestVideoVectors),
407*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::ValuesIn(kSuperresQThresholds));
408*77c1e3ccSAndroid Build Coastguard Worker 
409*77c1e3ccSAndroid Build Coastguard Worker }  // namespace
410