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