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 <memory>
13*77c1e3ccSAndroid Build Coastguard Worker
14*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
15*77c1e3ccSAndroid Build Coastguard Worker
16*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/y4m_video_source.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/yuv_video_source.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/ratectrl.h"
22*77c1e3ccSAndroid Build Coastguard Worker
23*77c1e3ccSAndroid Build Coastguard Worker namespace {
24*77c1e3ccSAndroid Build Coastguard Worker
25*77c1e3ccSAndroid Build Coastguard Worker const unsigned int kFrames = 100;
26*77c1e3ccSAndroid Build Coastguard Worker const int kBitrate = 500;
27*77c1e3ccSAndroid Build Coastguard Worker
28*77c1e3ccSAndroid Build Coastguard Worker #define ARF_NOT_SEEN 1000001
29*77c1e3ccSAndroid Build Coastguard Worker #define ARF_SEEN_ONCE 1000000
30*77c1e3ccSAndroid Build Coastguard Worker
31*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
32*77c1e3ccSAndroid Build Coastguard Worker const char *filename;
33*77c1e3ccSAndroid Build Coastguard Worker unsigned int width;
34*77c1e3ccSAndroid Build Coastguard Worker unsigned int height;
35*77c1e3ccSAndroid Build Coastguard Worker unsigned int framerate_num;
36*77c1e3ccSAndroid Build Coastguard Worker unsigned int framerate_den;
37*77c1e3ccSAndroid Build Coastguard Worker unsigned int input_bit_depth;
38*77c1e3ccSAndroid Build Coastguard Worker aom_img_fmt fmt;
39*77c1e3ccSAndroid Build Coastguard Worker aom_bit_depth_t bit_depth;
40*77c1e3ccSAndroid Build Coastguard Worker unsigned int profile;
41*77c1e3ccSAndroid Build Coastguard Worker } TestVideoParam;
42*77c1e3ccSAndroid Build Coastguard Worker
43*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
44*77c1e3ccSAndroid Build Coastguard Worker libaom_test::TestMode mode;
45*77c1e3ccSAndroid Build Coastguard Worker int cpu_used;
46*77c1e3ccSAndroid Build Coastguard Worker } TestEncodeParam;
47*77c1e3ccSAndroid Build Coastguard Worker
48*77c1e3ccSAndroid Build Coastguard Worker const TestVideoParam kTestVectors[] = {
49*77c1e3ccSAndroid Build Coastguard Worker // artificially increase framerate to trigger default check
50*77c1e3ccSAndroid Build Coastguard Worker { "hantro_collage_w352h288.yuv", 352, 288, 5000, 1, 8, AOM_IMG_FMT_I420,
51*77c1e3ccSAndroid Build Coastguard Worker AOM_BITS_8, 0 },
52*77c1e3ccSAndroid Build Coastguard Worker { "hantro_collage_w352h288.yuv", 352, 288, 30, 1, 8, AOM_IMG_FMT_I420,
53*77c1e3ccSAndroid Build Coastguard Worker AOM_BITS_8, 0 },
54*77c1e3ccSAndroid Build Coastguard Worker { "rush_hour_444.y4m", 352, 288, 30, 1, 8, AOM_IMG_FMT_I444, AOM_BITS_8, 1 },
55*77c1e3ccSAndroid Build Coastguard Worker // Add list of profile 2/3 test videos here ...
56*77c1e3ccSAndroid Build Coastguard Worker };
57*77c1e3ccSAndroid Build Coastguard Worker
58*77c1e3ccSAndroid Build Coastguard Worker const TestEncodeParam kEncodeVectors[] = {
59*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_REALTIME_ONLY
60*77c1e3ccSAndroid Build Coastguard Worker { ::libaom_test::kRealTime, 5 },
61*77c1e3ccSAndroid Build Coastguard Worker #else
62*77c1e3ccSAndroid Build Coastguard Worker { ::libaom_test::kRealTime, 5 }, { ::libaom_test::kOnePassGood, 2 },
63*77c1e3ccSAndroid Build Coastguard Worker { ::libaom_test::kOnePassGood, 5 }, { ::libaom_test::kTwoPassGood, 1 },
64*77c1e3ccSAndroid Build Coastguard Worker { ::libaom_test::kTwoPassGood, 2 }, { ::libaom_test::kTwoPassGood, 5 },
65*77c1e3ccSAndroid Build Coastguard Worker #endif
66*77c1e3ccSAndroid Build Coastguard Worker };
67*77c1e3ccSAndroid Build Coastguard Worker
68*77c1e3ccSAndroid Build Coastguard Worker const int kMinArfVectors[] = {
69*77c1e3ccSAndroid Build Coastguard Worker // NOTE: 0 refers to the default built-in logic in:
70*77c1e3ccSAndroid Build Coastguard Worker // av1_rc_get_default_min_gf_interval(...)
71*77c1e3ccSAndroid Build Coastguard Worker 0, 4, 8, 12, 15
72*77c1e3ccSAndroid Build Coastguard Worker };
73*77c1e3ccSAndroid Build Coastguard Worker
74*77c1e3ccSAndroid Build Coastguard Worker class ArfFreqTestLarge
75*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith3Params<TestVideoParam,
76*77c1e3ccSAndroid Build Coastguard Worker TestEncodeParam, int>,
77*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
78*77c1e3ccSAndroid Build Coastguard Worker protected:
ArfFreqTestLarge()79*77c1e3ccSAndroid Build Coastguard Worker ArfFreqTestLarge()
80*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
81*77c1e3ccSAndroid Build Coastguard Worker test_encode_param_(GET_PARAM(2)), min_arf_requested_(GET_PARAM(3)) {}
82*77c1e3ccSAndroid Build Coastguard Worker
83*77c1e3ccSAndroid Build Coastguard Worker ~ArfFreqTestLarge() override = default;
84*77c1e3ccSAndroid Build Coastguard Worker
SetUp()85*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
86*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(test_encode_param_.mode);
87*77c1e3ccSAndroid Build Coastguard Worker if (test_encode_param_.mode != ::libaom_test::kRealTime) {
88*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 25;
89*77c1e3ccSAndroid Build Coastguard Worker } else {
90*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_sz = 1000;
91*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_initial_sz = 500;
92*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_optimal_sz = 600;
93*77c1e3ccSAndroid Build Coastguard Worker }
94*77c1e3ccSAndroid Build Coastguard Worker }
95*77c1e3ccSAndroid Build Coastguard Worker
BeginPassHook(unsigned int)96*77c1e3ccSAndroid Build Coastguard Worker void BeginPassHook(unsigned int) override {
97*77c1e3ccSAndroid Build Coastguard Worker min_run_ = ARF_NOT_SEEN;
98*77c1e3ccSAndroid Build Coastguard Worker run_of_visible_frames_ = 0;
99*77c1e3ccSAndroid Build Coastguard Worker }
100*77c1e3ccSAndroid Build Coastguard Worker
GetNumFramesInPkt(const aom_codec_cx_pkt_t * pkt)101*77c1e3ccSAndroid Build Coastguard Worker int GetNumFramesInPkt(const aom_codec_cx_pkt_t *pkt) {
102*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf);
103*77c1e3ccSAndroid Build Coastguard Worker const uint8_t marker = buffer[pkt->data.frame.sz - 1];
104*77c1e3ccSAndroid Build Coastguard Worker const int mag = ((marker >> 3) & 3) + 1;
105*77c1e3ccSAndroid Build Coastguard Worker int frames = (marker & 0x7) + 1;
106*77c1e3ccSAndroid Build Coastguard Worker const unsigned int index_sz = 2 + mag * frames;
107*77c1e3ccSAndroid Build Coastguard Worker // Check for superframe or not.
108*77c1e3ccSAndroid Build Coastguard Worker // Assume superframe has only one visible frame, the rest being
109*77c1e3ccSAndroid Build Coastguard Worker // invisible. If superframe index is not found, then there is only
110*77c1e3ccSAndroid Build Coastguard Worker // one frame.
111*77c1e3ccSAndroid Build Coastguard Worker if (!((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz &&
112*77c1e3ccSAndroid Build Coastguard Worker buffer[pkt->data.frame.sz - index_sz] == marker)) {
113*77c1e3ccSAndroid Build Coastguard Worker frames = 1;
114*77c1e3ccSAndroid Build Coastguard Worker }
115*77c1e3ccSAndroid Build Coastguard Worker return frames;
116*77c1e3ccSAndroid Build Coastguard Worker }
117*77c1e3ccSAndroid Build Coastguard Worker
FramePktHook(const aom_codec_cx_pkt_t * pkt)118*77c1e3ccSAndroid Build Coastguard Worker void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
119*77c1e3ccSAndroid Build Coastguard Worker if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) return;
120*77c1e3ccSAndroid Build Coastguard Worker const int frames = GetNumFramesInPkt(pkt);
121*77c1e3ccSAndroid Build Coastguard Worker if (frames == 1) {
122*77c1e3ccSAndroid Build Coastguard Worker run_of_visible_frames_++;
123*77c1e3ccSAndroid Build Coastguard Worker } else if (frames == 2) {
124*77c1e3ccSAndroid Build Coastguard Worker if (min_run_ == ARF_NOT_SEEN) {
125*77c1e3ccSAndroid Build Coastguard Worker min_run_ = ARF_SEEN_ONCE;
126*77c1e3ccSAndroid Build Coastguard Worker } else if (min_run_ == ARF_SEEN_ONCE ||
127*77c1e3ccSAndroid Build Coastguard Worker run_of_visible_frames_ < min_run_) {
128*77c1e3ccSAndroid Build Coastguard Worker min_run_ = run_of_visible_frames_;
129*77c1e3ccSAndroid Build Coastguard Worker }
130*77c1e3ccSAndroid Build Coastguard Worker run_of_visible_frames_ = 1;
131*77c1e3ccSAndroid Build Coastguard Worker } else {
132*77c1e3ccSAndroid Build Coastguard Worker min_run_ = 0;
133*77c1e3ccSAndroid Build Coastguard Worker run_of_visible_frames_ = 1;
134*77c1e3ccSAndroid Build Coastguard Worker }
135*77c1e3ccSAndroid Build Coastguard Worker }
136*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)137*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
138*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
139*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
140*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
141*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_COLUMNS, 4);
142*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, test_encode_param_.cpu_used);
143*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_MIN_GF_INTERVAL, min_arf_requested_);
144*77c1e3ccSAndroid Build Coastguard Worker if (test_encode_param_.mode != ::libaom_test::kRealTime) {
145*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
146*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
147*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
148*77c1e3ccSAndroid Build Coastguard Worker }
149*77c1e3ccSAndroid Build Coastguard Worker }
150*77c1e3ccSAndroid Build Coastguard Worker }
151*77c1e3ccSAndroid Build Coastguard Worker
GetMinVisibleRun() const152*77c1e3ccSAndroid Build Coastguard Worker int GetMinVisibleRun() const { return min_run_; }
153*77c1e3ccSAndroid Build Coastguard Worker
GetMinArfDistanceRequested() const154*77c1e3ccSAndroid Build Coastguard Worker int GetMinArfDistanceRequested() const {
155*77c1e3ccSAndroid Build Coastguard Worker if (min_arf_requested_)
156*77c1e3ccSAndroid Build Coastguard Worker return min_arf_requested_;
157*77c1e3ccSAndroid Build Coastguard Worker else
158*77c1e3ccSAndroid Build Coastguard Worker return av1_rc_get_default_min_gf_interval(
159*77c1e3ccSAndroid Build Coastguard Worker test_video_param_.width, test_video_param_.height,
160*77c1e3ccSAndroid Build Coastguard Worker (double)test_video_param_.framerate_num /
161*77c1e3ccSAndroid Build Coastguard Worker test_video_param_.framerate_den);
162*77c1e3ccSAndroid Build Coastguard Worker }
163*77c1e3ccSAndroid Build Coastguard Worker
164*77c1e3ccSAndroid Build Coastguard Worker TestVideoParam test_video_param_;
165*77c1e3ccSAndroid Build Coastguard Worker TestEncodeParam test_encode_param_;
166*77c1e3ccSAndroid Build Coastguard Worker
167*77c1e3ccSAndroid Build Coastguard Worker private:
168*77c1e3ccSAndroid Build Coastguard Worker int min_arf_requested_;
169*77c1e3ccSAndroid Build Coastguard Worker int min_run_;
170*77c1e3ccSAndroid Build Coastguard Worker int run_of_visible_frames_;
171*77c1e3ccSAndroid Build Coastguard Worker };
172*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(ArfFreqTestLarge,MinArfFreqTest)173*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ArfFreqTestLarge, MinArfFreqTest) {
174*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = kBitrate;
175*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_error_resilient = 0;
176*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_profile = test_video_param_.profile;
177*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
178*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_bit_depth = test_video_param_.bit_depth;
179*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
180*77c1e3ccSAndroid Build Coastguard Worker if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
181*77c1e3ccSAndroid Build Coastguard Worker
182*77c1e3ccSAndroid Build Coastguard Worker std::unique_ptr<libaom_test::VideoSource> video;
183*77c1e3ccSAndroid Build Coastguard Worker if (is_extension_y4m(test_video_param_.filename)) {
184*77c1e3ccSAndroid Build Coastguard Worker video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
185*77c1e3ccSAndroid Build Coastguard Worker kFrames));
186*77c1e3ccSAndroid Build Coastguard Worker } else {
187*77c1e3ccSAndroid Build Coastguard Worker video.reset(new libaom_test::YUVVideoSource(
188*77c1e3ccSAndroid Build Coastguard Worker test_video_param_.filename, test_video_param_.fmt,
189*77c1e3ccSAndroid Build Coastguard Worker test_video_param_.width, test_video_param_.height,
190*77c1e3ccSAndroid Build Coastguard Worker test_video_param_.framerate_num, test_video_param_.framerate_den, 0,
191*77c1e3ccSAndroid Build Coastguard Worker kFrames));
192*77c1e3ccSAndroid Build Coastguard Worker }
193*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(video, nullptr);
194*77c1e3ccSAndroid Build Coastguard Worker
195*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
196*77c1e3ccSAndroid Build Coastguard Worker const int min_run = GetMinVisibleRun();
197*77c1e3ccSAndroid Build Coastguard Worker const int min_arf_dist_requested = GetMinArfDistanceRequested();
198*77c1e3ccSAndroid Build Coastguard Worker if (min_run != ARF_NOT_SEEN && min_run != ARF_SEEN_ONCE) {
199*77c1e3ccSAndroid Build Coastguard Worker const int min_arf_dist = min_run + 1;
200*77c1e3ccSAndroid Build Coastguard Worker EXPECT_GE(min_arf_dist, min_arf_dist_requested);
201*77c1e3ccSAndroid Build Coastguard Worker }
202*77c1e3ccSAndroid Build Coastguard Worker }
203*77c1e3ccSAndroid Build Coastguard Worker
204*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_ENCODER
205*77c1e3ccSAndroid Build Coastguard Worker // TODO(angiebird): 25-29 fail in high bitdepth mode.
206*77c1e3ccSAndroid Build Coastguard Worker // TODO(zoeliu): This ArfFreqTest does not work with BWDREF_FRAME, as
207*77c1e3ccSAndroid Build Coastguard Worker // BWDREF_FRAME is also a non-show frame, and the minimum run between two
208*77c1e3ccSAndroid Build Coastguard Worker // consecutive BWDREF_FRAME's may vary between 1 and any arbitrary positive
209*77c1e3ccSAndroid Build Coastguard Worker // number as long as it does not exceed the gf_group interval.
210*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
211*77c1e3ccSAndroid Build Coastguard Worker DISABLED_AV1, ArfFreqTestLarge,
212*77c1e3ccSAndroid Build Coastguard Worker ::testing::Combine(
213*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(
214*77c1e3ccSAndroid Build Coastguard Worker static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)),
215*77c1e3ccSAndroid Build Coastguard Worker ::testing::ValuesIn(kTestVectors), ::testing::ValuesIn(kEncodeVectors),
216*77c1e3ccSAndroid Build Coastguard Worker ::testing::ValuesIn(kMinArfVectors)));
217*77c1e3ccSAndroid Build Coastguard Worker #endif // CONFIG_AV1_ENCODER
218*77c1e3ccSAndroid Build Coastguard Worker } // namespace
219