blob: 083f4022f493672db2379483b845bae4df01a582 [file] [log] [blame]
Debargha Mukherjee98526432015-04-01 16:39:06 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Debargha Mukherjee98526432015-04-01 16:39:06 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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.
Johann123e8a62017-12-28 14:40:49 -080010 */
Debargha Mukherjee98526432015-04-01 16:39:06 -070011
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Jingning Han097d59c2015-07-29 14:51:36 -070013
Debargha Mukherjee98526432015-04-01 16:39:06 -070014#include "test/codec_factory.h"
15#include "test/encode_test_driver.h"
Jingning Han097d59c2015-07-29 14:51:36 -070016#include "test/util.h"
Debargha Mukherjee98526432015-04-01 16:39:06 -070017#include "test/y4m_video_source.h"
18#include "test/yuv_video_source.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070019#include "av1/encoder/ratectrl.h"
Debargha Mukherjee98526432015-04-01 16:39:06 -070020
21namespace {
22
23const unsigned int kFrames = 100;
24const int kBitrate = 500;
25
clang-format3a826f12016-08-11 17:46:05 -070026#define ARF_NOT_SEEN 1000001
27#define ARF_SEEN_ONCE 1000000
Debargha Mukherjee98526432015-04-01 16:39:06 -070028
29typedef struct {
30 const char *filename;
31 unsigned int width;
32 unsigned int height;
33 unsigned int framerate_num;
34 unsigned int framerate_den;
35 unsigned int input_bit_depth;
Yaowu Xuf883b422016-08-30 14:01:10 -070036 aom_img_fmt fmt;
37 aom_bit_depth_t bit_depth;
Debargha Mukherjee98526432015-04-01 16:39:06 -070038 unsigned int profile;
39} TestVideoParam;
40
41typedef struct {
Yaowu Xuc27fc142016-08-22 16:08:15 -070042 libaom_test::TestMode mode;
Debargha Mukherjee98526432015-04-01 16:39:06 -070043 int cpu_used;
44} TestEncodeParam;
45
46const TestVideoParam kTestVectors[] = {
47 // artificially increase framerate to trigger default check
Yaowu Xuf883b422016-08-30 14:01:10 -070048 { "hantro_collage_w352h288.yuv", 352, 288, 5000, 1, 8, AOM_IMG_FMT_I420,
49 AOM_BITS_8, 0 },
50 { "hantro_collage_w352h288.yuv", 352, 288, 30, 1, 8, AOM_IMG_FMT_I420,
51 AOM_BITS_8, 0 },
52 { "rush_hour_444.y4m", 352, 288, 30, 1, 8, AOM_IMG_FMT_I444, AOM_BITS_8, 1 },
Yaowu Xud3e7c682017-12-21 14:08:25 -080053 // Add list of profile 2/3 test videos here ...
Debargha Mukherjee98526432015-04-01 16:39:06 -070054};
55
56const TestEncodeParam kEncodeVectors[] = {
Yaowu Xuc27fc142016-08-22 16:08:15 -070057 { ::libaom_test::kOnePassGood, 2 }, { ::libaom_test::kOnePassGood, 5 },
58 { ::libaom_test::kTwoPassGood, 1 }, { ::libaom_test::kTwoPassGood, 2 },
59 { ::libaom_test::kTwoPassGood, 5 }, { ::libaom_test::kRealTime, 5 },
Debargha Mukherjee98526432015-04-01 16:39:06 -070060};
61
62const int kMinArfVectors[] = {
63 // NOTE: 0 refers to the default built-in logic in:
Yaowu Xuf883b422016-08-30 14:01:10 -070064 // av1_rc_get_default_min_gf_interval(...)
Debargha Mukherjee98526432015-04-01 16:39:06 -070065 0, 4, 8, 12, 15
66};
67
68int is_extension_y4m(const char *filename) {
69 const char *dot = strrchr(filename, '.');
70 if (!dot || dot == filename)
71 return 0;
72 else
73 return !strcmp(dot, ".y4m");
74}
75
hui sua3a1b2d2015-11-02 15:47:55 -080076class ArfFreqTestLarge
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020077 : public ::libaom_test::CodecTestWith3Params<TestVideoParam,
78 TestEncodeParam, int>,
79 public ::libaom_test::EncoderTest {
Debargha Mukherjee98526432015-04-01 16:39:06 -070080 protected:
hui sua3a1b2d2015-11-02 15:47:55 -080081 ArfFreqTestLarge()
clang-format3a826f12016-08-11 17:46:05 -070082 : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
83 test_encode_param_(GET_PARAM(2)), min_arf_requested_(GET_PARAM(3)) {}
Debargha Mukherjee98526432015-04-01 16:39:06 -070084
hui sua3a1b2d2015-11-02 15:47:55 -080085 virtual ~ArfFreqTestLarge() {}
Debargha Mukherjee98526432015-04-01 16:39:06 -070086
87 virtual void SetUp() {
88 InitializeConfig();
89 SetMode(test_encode_param_.mode);
Yaowu Xuc27fc142016-08-22 16:08:15 -070090 if (test_encode_param_.mode != ::libaom_test::kRealTime) {
Debargha Mukherjee98526432015-04-01 16:39:06 -070091 cfg_.g_lag_in_frames = 25;
Yaowu Xuf883b422016-08-30 14:01:10 -070092 cfg_.rc_end_usage = AOM_VBR;
Debargha Mukherjee98526432015-04-01 16:39:06 -070093 } else {
94 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070095 cfg_.rc_end_usage = AOM_CBR;
Debargha Mukherjee98526432015-04-01 16:39:06 -070096 cfg_.rc_buf_sz = 1000;
97 cfg_.rc_buf_initial_sz = 500;
98 cfg_.rc_buf_optimal_sz = 600;
99 }
Debargha Mukherjee98526432015-04-01 16:39:06 -0700100 }
101
102 virtual void BeginPassHook(unsigned int) {
Debargha Mukherjee3c524482015-07-10 09:49:17 -0700103 min_run_ = ARF_NOT_SEEN;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700104 run_of_visible_frames_ = 0;
105 }
106
Yaowu Xuf883b422016-08-30 14:01:10 -0700107 int GetNumFramesInPkt(const aom_codec_cx_pkt_t *pkt) {
clang-format3a826f12016-08-11 17:46:05 -0700108 const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf);
Debargha Mukherjee98526432015-04-01 16:39:06 -0700109 const uint8_t marker = buffer[pkt->data.frame.sz - 1];
110 const int mag = ((marker >> 3) & 3) + 1;
111 int frames = (marker & 0x7) + 1;
clang-format3a826f12016-08-11 17:46:05 -0700112 const unsigned int index_sz = 2 + mag * frames;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700113 // Check for superframe or not.
114 // Assume superframe has only one visible frame, the rest being
115 // invisible. If superframe index is not found, then there is only
116 // one frame.
clang-format3a826f12016-08-11 17:46:05 -0700117 if (!((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz &&
Debargha Mukherjee98526432015-04-01 16:39:06 -0700118 buffer[pkt->data.frame.sz - index_sz] == marker)) {
119 frames = 1;
120 }
121 return frames;
122 }
123
Yaowu Xuf883b422016-08-30 14:01:10 -0700124 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
125 if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) return;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700126 const int frames = GetNumFramesInPkt(pkt);
127 if (frames == 1) {
128 run_of_visible_frames_++;
129 } else if (frames == 2) {
Debargha Mukherjee3c524482015-07-10 09:49:17 -0700130 if (min_run_ == ARF_NOT_SEEN) {
131 min_run_ = ARF_SEEN_ONCE;
132 } else if (min_run_ == ARF_SEEN_ONCE ||
133 run_of_visible_frames_ < min_run_) {
134 min_run_ = run_of_visible_frames_;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700135 }
136 run_of_visible_frames_ = 1;
137 } else {
Debargha Mukherjee3c524482015-07-10 09:49:17 -0700138 min_run_ = 0;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700139 run_of_visible_frames_ = 1;
140 }
141 }
142
Yaowu Xuc27fc142016-08-22 16:08:15 -0700143 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
144 ::libaom_test::Encoder *encoder) {
Debargha Mukherjee98526432015-04-01 16:39:06 -0700145 if (video->frame() == 0) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700146 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
147 encoder->Control(AV1E_SET_TILE_COLUMNS, 4);
148 encoder->Control(AOME_SET_CPUUSED, test_encode_param_.cpu_used);
149 encoder->Control(AV1E_SET_MIN_GF_INTERVAL, min_arf_requested_);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700150 if (test_encode_param_.mode != ::libaom_test::kRealTime) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700151 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
152 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
153 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
Debargha Mukherjee98526432015-04-01 16:39:06 -0700154 }
155 }
156 }
157
clang-format3a826f12016-08-11 17:46:05 -0700158 int GetMinVisibleRun() const { return min_run_; }
Debargha Mukherjee98526432015-04-01 16:39:06 -0700159
160 int GetMinArfDistanceRequested() const {
161 if (min_arf_requested_)
162 return min_arf_requested_;
163 else
Yaowu Xuf883b422016-08-30 14:01:10 -0700164 return av1_rc_get_default_min_gf_interval(
Debargha Mukherjee98526432015-04-01 16:39:06 -0700165 test_video_param_.width, test_video_param_.height,
166 (double)test_video_param_.framerate_num /
clang-format3a826f12016-08-11 17:46:05 -0700167 test_video_param_.framerate_den);
Debargha Mukherjee98526432015-04-01 16:39:06 -0700168 }
169
170 TestVideoParam test_video_param_;
171 TestEncodeParam test_encode_param_;
172
173 private:
174 int min_arf_requested_;
Debargha Mukherjee3c524482015-07-10 09:49:17 -0700175 int min_run_;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700176 int run_of_visible_frames_;
177};
178
hui sua3a1b2d2015-11-02 15:47:55 -0800179TEST_P(ArfFreqTestLarge, MinArfFreqTest) {
Debargha Mukherjee98526432015-04-01 16:39:06 -0700180 cfg_.rc_target_bitrate = kBitrate;
181 cfg_.g_error_resilient = 0;
182 cfg_.g_profile = test_video_param_.profile;
183 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
184 cfg_.g_bit_depth = test_video_param_.bit_depth;
Yaowu Xuf883b422016-08-30 14:01:10 -0700185 init_flags_ = AOM_CODEC_USE_PSNR;
186 if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700187
Yaowu Xuc27fc142016-08-22 16:08:15 -0700188 testing::internal::scoped_ptr<libaom_test::VideoSource> video;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700189 if (is_extension_y4m(test_video_param_.filename)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700190 video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
clang-format3a826f12016-08-11 17:46:05 -0700191 kFrames));
Debargha Mukherjee98526432015-04-01 16:39:06 -0700192 } else {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700193 video.reset(new libaom_test::YUVVideoSource(
clang-format3a826f12016-08-11 17:46:05 -0700194 test_video_param_.filename, test_video_param_.fmt,
195 test_video_param_.width, test_video_param_.height,
196 test_video_param_.framerate_num, test_video_param_.framerate_den, 0,
197 kFrames));
Debargha Mukherjee98526432015-04-01 16:39:06 -0700198 }
199
Alex Converse12ca90d2016-07-21 11:38:27 -0700200 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
Debargha Mukherjee3c524482015-07-10 09:49:17 -0700201 const int min_run = GetMinVisibleRun();
Debargha Mukherjee98526432015-04-01 16:39:06 -0700202 const int min_arf_dist_requested = GetMinArfDistanceRequested();
Debargha Mukherjee3c524482015-07-10 09:49:17 -0700203 if (min_run != ARF_NOT_SEEN && min_run != ARF_SEEN_ONCE) {
204 const int min_arf_dist = min_run + 1;
Debargha Mukherjee98526432015-04-01 16:39:06 -0700205 EXPECT_GE(min_arf_dist, min_arf_dist_requested);
206 }
Debargha Mukherjee98526432015-04-01 16:39:06 -0700207}
208
Yaowu Xuf883b422016-08-30 14:01:10 -0700209#if CONFIG_AV1_ENCODER
Yaowu Xu7c514e22015-09-28 15:55:46 -0700210// TODO(angiebird): 25-29 fail in high bitdepth mode.
Zoe Liu52012802016-06-16 09:41:30 -0700211// TODO(zoeliu): This ArfFreqTest does not work with BWDREF_FRAME, as
212// BWDREF_FRAME is also a non-show frame, and the minimum run between two
213// consecutive BWDREF_FRAME's may vary between 1 and any arbitrary positive
214// number as long as it does not exceed the gf_group interval.
Yaowu Xu7c514e22015-09-28 15:55:46 -0700215INSTANTIATE_TEST_CASE_P(
Yaowu Xuf883b422016-08-30 14:01:10 -0700216 DISABLED_AV1, ArfFreqTestLarge,
Yaowu Xu7c514e22015-09-28 15:55:46 -0700217 ::testing::Combine(
Yaowu Xuf883b422016-08-30 14:01:10 -0700218 ::testing::Values(
219 static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)),
clang-format3a826f12016-08-11 17:46:05 -0700220 ::testing::ValuesIn(kTestVectors), ::testing::ValuesIn(kEncodeVectors),
Yaowu Xu7c514e22015-09-28 15:55:46 -0700221 ::testing::ValuesIn(kMinArfVectors)));
Yaowu Xuf883b422016-08-30 14:01:10 -0700222#endif // CONFIG_AV1_ENCODER
Debargha Mukherjee98526432015-04-01 16:39:06 -0700223} // namespace