blob: 2893e9380b347699ac3b85cb4da1e49d3e9b4231 [file] [log] [blame]
James Zern429743c2012-08-07 17:12:10 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
James Zern429743c2012-08-07 17:12:10 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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.
James Zern429743c2012-08-07 17:12:10 -070010 */
Yaowu Xubde4ac82016-11-28 15:26:06 -080011
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
John Koleszar706cafe2013-01-18 11:51:12 -080013#include "test/codec_factory.h"
James Zern429743c2012-08-07 17:12:10 -070014#include "test/encode_test_driver.h"
15#include "test/i420_video_source.h"
John Koleszar706cafe2013-01-18 11:51:12 -080016#include "test/util.h"
James Zern429743c2012-08-07 17:12:10 -070017namespace {
Aasaipriya Chandran62a6c262020-06-30 14:43:20 +053018typedef 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
27static 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 },
Aasaipriya Chandran62a6c262020-06-30 14:43:20 +053034};
35
36std::ostream &operator<<(std::ostream &os, const AltRefTestParams &test_arg) {
37 return os << "AltRefTestParams { min_kf_dist:" << test_arg.min_kf_dist
38 << " max_kf_dist:" << test_arg.max_kf_dist
39 << " min_gf_interval:" << test_arg.min_gf_interval
40 << " max_gf_interval:" << test_arg.max_gf_interval
41 << " lag_in_frames:" << test_arg.lag_in_frames
42 << " encoding_mode:" << test_arg.encoding_mode << " }";
43}
44
45// This class is used to check the presence of altref frame.
46class AltRefFramePresenceTestLarge
47 : public ::libaom_test::CodecTestWith2Params<AltRefTestParams, aom_rc_mode>,
48 public ::libaom_test::EncoderTest {
49 protected:
50 AltRefFramePresenceTestLarge()
51 : EncoderTest(GET_PARAM(0)), altref_test_params_(GET_PARAM(1)),
52 rc_end_usage_(GET_PARAM(2)) {
53 is_arf_frame_present_ = 0;
54 }
55 virtual ~AltRefFramePresenceTestLarge() {}
56
57 virtual void SetUp() {
58 InitializeConfig();
59 SetMode(altref_test_params_.encoding_mode);
60 const aom_rational timebase = { 1, 30 };
61 cfg_.g_timebase = timebase;
62 cfg_.rc_end_usage = rc_end_usage_;
63 cfg_.g_threads = 1;
64 cfg_.kf_min_dist = altref_test_params_.min_kf_dist;
65 cfg_.kf_max_dist = altref_test_params_.max_kf_dist;
66 cfg_.g_lag_in_frames = altref_test_params_.lag_in_frames;
67 }
68
69 virtual bool DoDecode() const { return 1; }
70
71 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
72 ::libaom_test::Encoder *encoder) {
73 if (video->frame() == 0) {
74 encoder->Control(AOME_SET_CPUUSED, 5);
75 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
76 encoder->Control(AV1E_SET_MIN_GF_INTERVAL,
77 altref_test_params_.min_gf_interval);
78 encoder->Control(AV1E_SET_MAX_GF_INTERVAL,
79 altref_test_params_.max_gf_interval);
80 }
81 }
82
83 virtual bool HandleDecodeResult(const aom_codec_err_t res_dec,
84 libaom_test::Decoder *decoder) {
85 EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
86 if (is_arf_frame_present_ != 1 && AOM_CODEC_OK == res_dec) {
87 aom_codec_ctx_t *ctx_dec = decoder->GetDecoder();
88 AOM_CODEC_CONTROL_TYPECHECKED(ctx_dec, AOMD_GET_ALTREF_PRESENT,
89 &is_arf_frame_present_);
90 }
91 return AOM_CODEC_OK == res_dec;
92 }
93
94 const AltRefTestParams altref_test_params_;
95 int is_arf_frame_present_;
96 aom_rc_mode rc_end_usage_;
97};
98
99TEST_P(AltRefFramePresenceTestLarge, AltRefFrameEncodePresenceTest) {
100 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
101 cfg_.g_timebase.den, cfg_.g_timebase.num,
102 0, 100);
103 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
104 ASSERT_EQ(is_arf_frame_present_, 1);
105}
106
107AV1_INSTANTIATE_TEST_SUITE(AltRefFramePresenceTestLarge,
108 ::testing::ValuesIn(TestParams),
109 ::testing::Values(AOM_Q, AOM_VBR, AOM_CBR, AOM_CQ));
110
Mufaddal Chakera52c03352020-07-22 10:02:39 +0530111typedef struct {
112 const ::libaom_test::TestMode encoding_mode;
113 const unsigned int min_gf_interval;
114 const unsigned int max_gf_interval;
115} gfIntervalParam;
116
117const gfIntervalParam gfTestParams[] = {
118 // single pass
119 { ::libaom_test::kOnePassGood, 0, 6 },
120 { ::libaom_test::kOnePassGood, 0, 8 },
121 { ::libaom_test::kOnePassGood, 5, 10 },
122 { ::libaom_test::kOnePassGood, 8, 16 },
123 { ::libaom_test::kOnePassGood, 16, 16 },
Mufaddal Chakera52c03352020-07-22 10:02:39 +0530124};
125
126// This class is used to test if the gf interval bounds configured by the user
127// are respected by the encoder.
128class GoldenFrameIntervalTestLarge
129 : public ::libaom_test::CodecTestWith2Params<gfIntervalParam, aom_rc_mode>,
130 public ::libaom_test::EncoderTest {
131 protected:
132 GoldenFrameIntervalTestLarge()
133 : EncoderTest(GET_PARAM(0)), gf_interval_param_(GET_PARAM(1)),
134 rc_end_usage_(GET_PARAM(2)) {
135 baseline_gf_interval_ = -1;
136 limit_ = 60;
137 frame_num_ = 0;
138 }
139 virtual ~GoldenFrameIntervalTestLarge() {}
140
141 virtual void SetUp() {
142 InitializeConfig();
143 SetMode(gf_interval_param_.encoding_mode);
144 const aom_rational timebase = { 1, 30 };
145 cfg_.g_timebase = timebase;
146 cfg_.rc_end_usage = rc_end_usage_;
147 cfg_.g_threads = 1;
148 // kf_min_dist is equal to kf_max_dist to make sure that there are no scene
149 // cuts due to which the min_gf_interval may not be respected.
150 cfg_.kf_min_dist = limit_;
151 cfg_.kf_max_dist = limit_;
152 cfg_.g_limit = limit_;
153 cfg_.g_lag_in_frames = 35;
154 cfg_.rc_target_bitrate = 1000;
155 }
156
157 virtual bool DoDecode() const { return 1; }
158
159 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
160 ::libaom_test::Encoder *encoder) {
161 if (video->frame() == 0) {
162 encoder->Control(AOME_SET_CPUUSED, 5);
163 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
164 encoder->Control(AV1E_SET_MIN_GF_INTERVAL,
165 gf_interval_param_.min_gf_interval);
166 encoder->Control(AV1E_SET_MAX_GF_INTERVAL,
167 gf_interval_param_.max_gf_interval);
168 }
169 if (frame_num_ > 0) {
170 encoder->Control(AV1E_GET_BASELINE_GF_INTERVAL, &baseline_gf_interval_);
171 ASSERT_LE(baseline_gf_interval_, (int)gf_interval_param_.max_gf_interval);
172 if ((frame_num_ + (int)gf_interval_param_.min_gf_interval) <= limit_) {
173 ASSERT_GE(baseline_gf_interval_,
174 (int)gf_interval_param_.min_gf_interval);
175 }
176 }
177 }
178
179 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
180 (void)pkt;
181 ++frame_num_;
182 }
183
184 const gfIntervalParam gf_interval_param_;
185 int baseline_gf_interval_;
186 int limit_;
187 int frame_num_;
188 aom_rc_mode rc_end_usage_;
189};
190
191TEST_P(GoldenFrameIntervalTestLarge, GoldenFrameIntervalTest) {
192 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
193 cfg_.g_timebase.den, cfg_.g_timebase.num,
194 0, limit_);
195 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
196}
197
198AV1_INSTANTIATE_TEST_SUITE(GoldenFrameIntervalTestLarge,
199 ::testing::ValuesIn(gfTestParams),
200 ::testing::Values(AOM_Q, AOM_VBR, AOM_CQ, AOM_CBR));
201
James Zern429743c2012-08-07 17:12:10 -0700202} // namespace