xref: /aosp_15_r20/external/libaom/test/altref_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2016, 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 "gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/i420_video_source.h"
16 #include "test/util.h"
17 namespace {
18 typedef struct {
19   const unsigned int min_kf_dist;
20   const unsigned int max_kf_dist;
21   const unsigned int min_gf_interval;
22   const unsigned int max_gf_interval;
23   const unsigned int lag_in_frames;
24   libaom_test::TestMode encoding_mode;
25 } AltRefTestParams;
26 
27 static const AltRefTestParams TestParams[] = {
28   { 0, 10, 4, 8, 10, ::libaom_test::kOnePassGood },
29   { 0, 30, 8, 12, 16, ::libaom_test::kOnePassGood },
30   { 30, 30, 12, 16, 25, ::libaom_test::kOnePassGood },
31   { 0, 60, 12, 20, 25, ::libaom_test::kOnePassGood },
32   { 60, 60, 16, 28, 30, ::libaom_test::kOnePassGood },
33   { 0, 100, 16, 32, 35, ::libaom_test::kOnePassGood },
34   { 0, 10, 4, 8, 10, ::libaom_test::kTwoPassGood },
35   { 0, 30, 8, 12, 16, ::libaom_test::kTwoPassGood },
36   { 30, 30, 12, 16, 25, ::libaom_test::kTwoPassGood },
37   { 0, 60, 16, 24, 25, ::libaom_test::kTwoPassGood },
38   { 60, 60, 20, 28, 30, ::libaom_test::kTwoPassGood },
39   { 0, 100, 24, 32, 35, ::libaom_test::kTwoPassGood },
40 };
41 
operator <<(std::ostream & os,const AltRefTestParams & test_arg)42 std::ostream &operator<<(std::ostream &os, const AltRefTestParams &test_arg) {
43   return os << "AltRefTestParams { min_kf_dist:" << test_arg.min_kf_dist
44             << " max_kf_dist:" << test_arg.max_kf_dist
45             << " min_gf_interval:" << test_arg.min_gf_interval
46             << " max_gf_interval:" << test_arg.max_gf_interval
47             << " lag_in_frames:" << test_arg.lag_in_frames
48             << " encoding_mode:" << test_arg.encoding_mode << " }";
49 }
50 
51 // This class is used to check the presence of altref frame.
52 class AltRefFramePresenceTestLarge
53     : public ::libaom_test::CodecTestWith2Params<AltRefTestParams, aom_rc_mode>,
54       public ::libaom_test::EncoderTest {
55  protected:
AltRefFramePresenceTestLarge()56   AltRefFramePresenceTestLarge()
57       : EncoderTest(GET_PARAM(0)), altref_test_params_(GET_PARAM(1)),
58         rc_end_usage_(GET_PARAM(2)) {
59     is_arf_frame_present_ = 0;
60   }
61   ~AltRefFramePresenceTestLarge() override = default;
62 
SetUp()63   void SetUp() override {
64     InitializeConfig(altref_test_params_.encoding_mode);
65     const aom_rational timebase = { 1, 30 };
66     cfg_.g_timebase = timebase;
67     cfg_.rc_end_usage = rc_end_usage_;
68     cfg_.g_threads = 1;
69     cfg_.kf_min_dist = altref_test_params_.min_kf_dist;
70     cfg_.kf_max_dist = altref_test_params_.max_kf_dist;
71     cfg_.g_lag_in_frames = altref_test_params_.lag_in_frames;
72   }
73 
DoDecode() const74   bool DoDecode() const override { return true; }
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(AOME_SET_CPUUSED, 5);
80       encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
81       encoder->Control(AV1E_SET_MIN_GF_INTERVAL,
82                        altref_test_params_.min_gf_interval);
83       encoder->Control(AV1E_SET_MAX_GF_INTERVAL,
84                        altref_test_params_.max_gf_interval);
85     }
86   }
87 
HandleDecodeResult(const aom_codec_err_t res_dec,libaom_test::Decoder * decoder)88   bool HandleDecodeResult(const aom_codec_err_t res_dec,
89                           libaom_test::Decoder *decoder) override {
90     EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
91     if (is_arf_frame_present_ != 1 && AOM_CODEC_OK == res_dec) {
92       aom_codec_ctx_t *ctx_dec = decoder->GetDecoder();
93       AOM_CODEC_CONTROL_TYPECHECKED(ctx_dec, AOMD_GET_ALTREF_PRESENT,
94                                     &is_arf_frame_present_);
95     }
96     return AOM_CODEC_OK == res_dec;
97   }
98 
99   const AltRefTestParams altref_test_params_;
100   int is_arf_frame_present_;
101   aom_rc_mode rc_end_usage_;
102 };
103 
TEST_P(AltRefFramePresenceTestLarge,AltRefFrameEncodePresenceTest)104 TEST_P(AltRefFramePresenceTestLarge, AltRefFrameEncodePresenceTest) {
105   libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
106                                      cfg_.g_timebase.den, cfg_.g_timebase.num,
107                                      0, 100);
108   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
109   ASSERT_EQ(is_arf_frame_present_, 1);
110 }
111 
112 AV1_INSTANTIATE_TEST_SUITE(AltRefFramePresenceTestLarge,
113                            ::testing::ValuesIn(TestParams),
114                            ::testing::Values(AOM_Q, AOM_VBR, AOM_CBR, AOM_CQ));
115 
116 typedef struct {
117   const ::libaom_test::TestMode encoding_mode;
118   const unsigned int min_gf_interval;
119   const unsigned int max_gf_interval;
120 } gfIntervalParam;
121 
122 const gfIntervalParam gfTestParams[] = {
123   // single pass
124   { ::libaom_test::kOnePassGood, 0, 6 },
125   { ::libaom_test::kOnePassGood, 0, 8 },
126   { ::libaom_test::kOnePassGood, 5, 10 },
127   { ::libaom_test::kOnePassGood, 8, 16 },
128   { ::libaom_test::kOnePassGood, 16, 16 },
129 
130   // two pass
131   { ::libaom_test::kTwoPassGood, 0, 6 },
132   { ::libaom_test::kTwoPassGood, 0, 8 },
133   { ::libaom_test::kTwoPassGood, 5, 10 },
134   { ::libaom_test::kTwoPassGood, 8, 16 },
135   { ::libaom_test::kTwoPassGood, 16, 32 },
136   { ::libaom_test::kTwoPassGood, 20, 32 },
137 };
138 
139 // This class is used to test if the gf interval bounds configured by the user
140 // are respected by the encoder.
141 class GoldenFrameIntervalTestLarge
142     : public ::libaom_test::CodecTestWith2Params<gfIntervalParam, aom_rc_mode>,
143       public ::libaom_test::EncoderTest {
144  protected:
GoldenFrameIntervalTestLarge()145   GoldenFrameIntervalTestLarge()
146       : EncoderTest(GET_PARAM(0)), gf_interval_param_(GET_PARAM(1)),
147         rc_end_usage_(GET_PARAM(2)) {
148     baseline_gf_interval_ = -1;
149     limit_ = 60;
150     frame_num_ = 0;
151   }
152   ~GoldenFrameIntervalTestLarge() override = default;
153 
SetUp()154   void SetUp() override {
155     InitializeConfig(gf_interval_param_.encoding_mode);
156     const aom_rational timebase = { 1, 30 };
157     cfg_.g_timebase = timebase;
158     cfg_.rc_end_usage = rc_end_usage_;
159     cfg_.g_threads = 1;
160     // kf_min_dist is equal to kf_max_dist to make sure that there are no scene
161     // cuts due to which the min_gf_interval may not be respected.
162     cfg_.kf_min_dist = limit_;
163     cfg_.kf_max_dist = limit_;
164     cfg_.g_limit = limit_;
165     cfg_.g_lag_in_frames = 35;
166     cfg_.rc_target_bitrate = 1000;
167   }
168 
DoDecode() const169   bool DoDecode() const override { return true; }
170 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)171   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
172                           ::libaom_test::Encoder *encoder) override {
173     if (video->frame() == 0) {
174       encoder->Control(AOME_SET_CPUUSED, 5);
175       encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
176       encoder->Control(AV1E_SET_MIN_GF_INTERVAL,
177                        gf_interval_param_.min_gf_interval);
178       encoder->Control(AV1E_SET_MAX_GF_INTERVAL,
179                        gf_interval_param_.max_gf_interval);
180     }
181     if (frame_num_ > 0) {
182       encoder->Control(AV1E_GET_BASELINE_GF_INTERVAL, &baseline_gf_interval_);
183       ASSERT_LE(baseline_gf_interval_,
184                 (int)gf_interval_param_.max_gf_interval + 1);
185       if ((frame_num_ + (int)gf_interval_param_.min_gf_interval) <= limit_) {
186         ASSERT_GE(baseline_gf_interval_,
187                   (int)gf_interval_param_.min_gf_interval);
188       }
189     }
190   }
191 
FramePktHook(const aom_codec_cx_pkt_t * pkt)192   void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
193     (void)pkt;
194     ++frame_num_;
195   }
196 
197   const gfIntervalParam gf_interval_param_;
198   int baseline_gf_interval_;
199   int limit_;
200   int frame_num_;
201   aom_rc_mode rc_end_usage_;
202 };
203 
TEST_P(GoldenFrameIntervalTestLarge,GoldenFrameIntervalTest)204 TEST_P(GoldenFrameIntervalTestLarge, GoldenFrameIntervalTest) {
205   libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
206                                      cfg_.g_timebase.den, cfg_.g_timebase.num,
207                                      0, limit_);
208   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
209 }
210 
211 AV1_INSTANTIATE_TEST_SUITE(GoldenFrameIntervalTestLarge,
212                            ::testing::ValuesIn(gfTestParams),
213                            ::testing::Values(AOM_Q, AOM_VBR, AOM_CQ, AOM_CBR));
214 
215 }  // namespace
216