blob: 053c05571662db184310e72fa00a67fb45090787 [file] [log] [blame]
Jim Bankoski533470c2012-10-29 19:54:06 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jim Bankoski533470c2012-10-29 19:54:06 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -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 */
Yaowu Xu2ab7ff02016-09-02 12:04:54 -070011
Tom Finegan60e653d2018-05-22 11:34:58 -070012#include "config/aom_config.h"
13
Tom Finegan7a07ece2017-02-07 17:14:05 -080014#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
John Koleszar706cafe2013-01-18 11:51:12 -080015#include "test/codec_factory.h"
Jerome Jiangd9603082019-08-14 17:24:17 -070016#include "test/datarate_test.h"
Jim Bankoski533470c2012-10-29 19:54:06 -070017#include "test/encode_test_driver.h"
18#include "test/i420_video_source.h"
John Koleszar706cafe2013-01-18 11:51:12 -080019#include "test/util.h"
Alex Conversef5949fa2014-01-17 13:52:23 -080020#include "test/y4m_video_source.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070021#include "aom/aom_codec.h"
John Koleszar706cafe2013-01-18 11:51:12 -080022
Jerome Jiangd9603082019-08-14 17:24:17 -070023namespace datarate_test {
Jim Bankoski533470c2012-10-29 19:54:06 -070024namespace {
25
Jerome Jiang68486892019-05-03 14:54:30 -070026// Params: test mode, speed, aq mode and index for bitrate array.
clang-format3a826f12016-08-11 17:46:05 -070027class DatarateTestLarge
Jerome Jiang68486892019-05-03 14:54:30 -070028 : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int,
29 unsigned int, int>,
Jerome Jiangd9603082019-08-14 17:24:17 -070030 public DatarateTest {
John Koleszar706cafe2013-01-18 11:51:12 -080031 public:
Jerome Jiangd9603082019-08-14 17:24:17 -070032 DatarateTestLarge() : DatarateTest(GET_PARAM(0)) {
33 set_cpu_used_ = GET_PARAM(2);
34 aq_mode_ = GET_PARAM(3);
35 }
Jim Bankoski6505b072014-03-12 17:20:16 -070036
James Zerncc73e1f2016-08-08 15:09:30 -070037 protected:
Jim Bankoski6505b072014-03-12 17:20:16 -070038 virtual ~DatarateTestLarge() {}
John Koleszar706cafe2013-01-18 11:51:12 -080039
Marco Paniconib26ce8b2013-10-22 11:30:06 -070040 virtual void SetUp() {
41 InitializeConfig();
42 SetMode(GET_PARAM(1));
Marco Paniconib26ce8b2013-10-22 11:30:06 -070043 ResetModel();
44 }
45
Jerome Jiang68486892019-05-03 14:54:30 -070046 virtual void BasicRateTargetingVBRTest() {
47 cfg_.rc_min_quantizer = 0;
48 cfg_.rc_max_quantizer = 63;
49 cfg_.g_error_resilient = 0;
50 cfg_.rc_end_usage = AOM_VBR;
51 cfg_.g_lag_in_frames = 0;
52
53 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
54 288, 30, 1, 0, 140);
55 const int bitrate_array[2] = { 400, 800 };
56 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
57 ResetModel();
58 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Debargha Mukherjeece847da2019-06-12 11:49:56 -070059 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.7)
Jerome Jiang68486892019-05-03 14:54:30 -070060 << " The datarate for the file is lower than target by too much!";
Debargha Mukherjeece847da2019-06-12 11:49:56 -070061 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.3)
Jerome Jiang68486892019-05-03 14:54:30 -070062 << " The datarate for the file is greater than target by too much!";
63 }
64
65 virtual void BasicRateTargetingCBRTest() {
66 cfg_.rc_buf_initial_sz = 500;
67 cfg_.rc_buf_optimal_sz = 500;
68 cfg_.rc_buf_sz = 1000;
69 cfg_.rc_dropframe_thresh = 1;
70 cfg_.rc_min_quantizer = 0;
71 cfg_.rc_max_quantizer = 63;
72 cfg_.rc_end_usage = AOM_CBR;
73 cfg_.g_lag_in_frames = 0;
74
75 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
76 288, 30, 1, 0, 140);
77 const int bitrate_array[2] = { 150, 550 };
78 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
79 ResetModel();
80 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
81 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
82 << " The datarate for the file is lower than target by too much!";
83 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.15)
84 << " The datarate for the file is greater than target by too much!";
85 }
86
Jerome Jiangf7e6b902019-11-25 15:28:23 -080087 virtual void BasicRateTargetingCBRPeriodicKeyFrameTest() {
88 cfg_.rc_buf_initial_sz = 500;
89 cfg_.rc_buf_optimal_sz = 500;
90 cfg_.rc_buf_sz = 1000;
91 cfg_.rc_dropframe_thresh = 1;
92 cfg_.rc_min_quantizer = 0;
93 cfg_.rc_max_quantizer = 63;
94 cfg_.rc_end_usage = AOM_CBR;
95 cfg_.g_lag_in_frames = 0;
96 // Periodic keyframe
97 cfg_.kf_max_dist = 50;
98
99 ::libaom_test::I420VideoSource video("pixel_capture_w320h240.yuv", 320, 240,
100 30, 1, 0, 310);
101 const int bitrate_array[2] = { 150, 550 };
102 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
103 ResetModel();
104 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
105 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
106 << " The datarate for the file is lower than target by too much!";
107 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.15)
108 << " The datarate for the file is greater than target by too much!";
109 }
110
Jerome Jiang95fcd322019-10-16 14:45:40 -0700111 virtual void BasicRateTargetingAQModeOnOffCBRTest() {
112 if (GET_PARAM(4) > 0) return;
113 cfg_.rc_buf_initial_sz = 500;
114 cfg_.rc_buf_optimal_sz = 500;
115 cfg_.rc_buf_sz = 1000;
116 cfg_.rc_dropframe_thresh = 0;
117 cfg_.rc_min_quantizer = 2;
118 cfg_.rc_max_quantizer = 63;
119 cfg_.rc_end_usage = AOM_CBR;
120 cfg_.g_lag_in_frames = 0;
121 cfg_.g_error_resilient = 0;
122 cfg_.g_pass = AOM_RC_ONE_PASS;
123 cfg_.g_usage = AOM_USAGE_REALTIME;
124 cfg_.kf_mode = AOM_KF_DISABLED;
125
126 ::libaom_test::I420VideoSource video("pixel_capture_w320h240.yuv", 320, 240,
127 30, 1, 0, 310);
128 const int bitrate_array[1] = { 60 };
129 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
130 ResetModel();
131 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
132 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
133 << " The datarate for the file is lower than target by too much!";
134 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.15)
135 << " The datarate for the file is greater than target by too much!";
136 }
137
Jerome Jiang68486892019-05-03 14:54:30 -0700138 virtual void BasicRateTargeting444CBRTest() {
139 ::libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140);
140
141 cfg_.g_profile = 1;
142 cfg_.g_timebase = video.timebase();
143
144 cfg_.rc_buf_initial_sz = 500;
145 cfg_.rc_buf_optimal_sz = 500;
146 cfg_.rc_buf_sz = 1000;
147 cfg_.rc_dropframe_thresh = 1;
148 cfg_.rc_min_quantizer = 0;
149 cfg_.rc_max_quantizer = 63;
150 cfg_.rc_end_usage = AOM_CBR;
151
152 const int bitrate_array[2] = { 250, 650 };
153 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
154 ResetModel();
155 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
156 ASSERT_GE(static_cast<double>(cfg_.rc_target_bitrate),
157 effective_datarate_ * 0.85)
158 << " The datarate for the file exceeds the target by too much!";
159 ASSERT_LE(static_cast<double>(cfg_.rc_target_bitrate),
160 effective_datarate_ * 1.15)
161 << " The datarate for the file missed the target!"
162 << cfg_.rc_target_bitrate << " " << effective_datarate_;
163 }
Jerome Jiang3c1f4612019-11-21 14:06:38 -0800164};
165
166// Params: test mode, speed, aq mode.
167class DatarateTestFrameDropLarge
168 : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode, int,
169 unsigned int>,
170 public DatarateTest {
171 public:
172 DatarateTestFrameDropLarge() : DatarateTest(GET_PARAM(0)) {
173 set_cpu_used_ = GET_PARAM(2);
174 aq_mode_ = GET_PARAM(3);
175 }
176
177 protected:
178 virtual ~DatarateTestFrameDropLarge() {}
179
180 virtual void SetUp() {
181 InitializeConfig();
182 SetMode(GET_PARAM(1));
183 ResetModel();
184 }
Jerome Jiang68486892019-05-03 14:54:30 -0700185
186 virtual void ChangingDropFrameThreshTest() {
187 cfg_.rc_buf_initial_sz = 500;
188 cfg_.rc_buf_optimal_sz = 500;
189 cfg_.rc_buf_sz = 1000;
190 cfg_.rc_undershoot_pct = 20;
191 cfg_.rc_undershoot_pct = 20;
192 cfg_.rc_dropframe_thresh = 10;
193 cfg_.rc_min_quantizer = 0;
194 cfg_.rc_max_quantizer = 50;
195 cfg_.rc_end_usage = AOM_CBR;
196 cfg_.rc_target_bitrate = 200;
197 cfg_.g_lag_in_frames = 0;
198 cfg_.g_error_resilient = 1;
199 // TODO(marpan): Investigate datarate target failures with a smaller
200 // keyframe interval (128).
201 cfg_.kf_max_dist = 9999;
202
203 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
204 288, 30, 1, 0, 100);
205
206 const int kDropFrameThreshTestStep = 30;
207 aom_codec_pts_t last_drop = 140;
208 int last_num_drops = 0;
209 for (int i = 40; i < 100; i += kDropFrameThreshTestStep) {
210 cfg_.rc_dropframe_thresh = i;
211 ResetModel();
212 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
213 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
214 << " The datarate for the file is lower than target by too much!";
Fyodor Kyslovf112a352019-11-18 10:41:17 -0800215 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.17)
Jerome Jiang68486892019-05-03 14:54:30 -0700216 << " The datarate for the file is greater than target by too much!";
Jerome Jianga1be2402019-05-15 11:06:26 -0700217 if (last_drop > 0) {
Jerome Jiangfb1ad5d2019-05-13 16:32:44 -0700218 ASSERT_LE(first_drop_, last_drop)
219 << " The first dropped frame for drop_thresh " << i
220 << " > first dropped frame for drop_thresh "
221 << i - kDropFrameThreshTestStep;
Jerome Jianga1be2402019-05-15 11:06:26 -0700222 }
Jerome Jiang446d5d92019-10-28 14:45:23 -0700223 ASSERT_GE(num_drops_, last_num_drops * 0.7)
Jerome Jiang68486892019-05-03 14:54:30 -0700224 << " The number of dropped frames for drop_thresh " << i
225 << " < number of dropped frames for drop_thresh "
226 << i - kDropFrameThreshTestStep;
227 last_drop = first_drop_;
228 last_num_drops = num_drops_;
229 }
230 }
Jerome Jiangd9603082019-08-14 17:24:17 -0700231};
Marco Paniconie078c3d2013-10-02 17:13:59 -0700232
Marco75d55172016-05-25 14:19:01 -0700233// Check basic rate targeting for VBR mode.
James Zerncc73e1f2016-08-08 15:09:30 -0700234TEST_P(DatarateTestLarge, BasicRateTargetingVBR) {
Jerome Jiang68486892019-05-03 14:54:30 -0700235 BasicRateTargetingVBRTest();
Marco75d55172016-05-25 14:19:01 -0700236}
237
Jerome Jiangf7e6b902019-11-25 15:28:23 -0800238// Check basic rate targeting for CBR.
Jerome Jiang68486892019-05-03 14:54:30 -0700239TEST_P(DatarateTestLarge, BasicRateTargetingCBR) {
240 BasicRateTargetingCBRTest();
Marco Paniconie078c3d2013-10-02 17:13:59 -0700241}
242
Jerome Jiangf7e6b902019-11-25 15:28:23 -0800243// Check basic rate targeting for periodic key frame.
244TEST_P(DatarateTestLarge, PeriodicKeyFrameCBR) {
245 BasicRateTargetingCBRPeriodicKeyFrameTest();
246}
247
Marco75d55172016-05-25 14:19:01 -0700248// Check basic rate targeting for CBR.
Jerome Jiang68486892019-05-03 14:54:30 -0700249TEST_P(DatarateTestLarge, BasicRateTargeting444CBR) {
250 BasicRateTargeting444CBRTest();
Alex Conversef5949fa2014-01-17 13:52:23 -0800251}
Alex Conversef5949fa2014-01-17 13:52:23 -0800252
Marco Paniconi1b8b8b02013-12-17 15:45:30 -0800253// Check that (1) the first dropped frame gets earlier and earlier
254// as the drop frame threshold is increased, and (2) that the total number of
255// frame drops does not decrease as we increase frame drop threshold.
256// Use a lower qp-max to force some frame drops.
Jerome Jiang3c1f4612019-11-21 14:06:38 -0800257TEST_P(DatarateTestFrameDropLarge, ChangingDropFrameThresh) {
Jerome Jiang68486892019-05-03 14:54:30 -0700258 ChangingDropFrameThreshTest();
Marco Paniconi1b8b8b02013-12-17 15:45:30 -0800259}
260
Jerome Jiang95fcd322019-10-16 14:45:40 -0700261TEST_P(DatarateTestLarge, BasicRateTargetingAQModeOnOffCBR) {
262 BasicRateTargetingAQModeOnOffCBRTest();
263}
264
Jerome Jiang68486892019-05-03 14:54:30 -0700265class DatarateTestRealtime : public DatarateTestLarge {};
266
Jerome Jiang3c1f4612019-11-21 14:06:38 -0800267class DatarateTestFrameDropRealtime : public DatarateTestFrameDropLarge {};
268
Jerome Jiang88068862019-11-21 15:25:59 -0800269// Params: aq mode.
270class DatarateTestSpeedChangeRealtime
271 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode,
272 unsigned int>,
273 public DatarateTest {
274 public:
275 DatarateTestSpeedChangeRealtime() : DatarateTest(GET_PARAM(0)) {
276 aq_mode_ = GET_PARAM(1);
277 speed_change_test_ = true;
278 }
279
280 protected:
281 virtual ~DatarateTestSpeedChangeRealtime() {}
282
283 virtual void SetUp() {
284 InitializeConfig();
285 SetMode(GET_PARAM(1));
286 ResetModel();
287 }
288
289 virtual void ChangingSpeedTest() {
290 cfg_.rc_buf_initial_sz = 500;
291 cfg_.rc_buf_optimal_sz = 500;
292 cfg_.rc_buf_sz = 1000;
293 cfg_.rc_undershoot_pct = 20;
294 cfg_.rc_undershoot_pct = 20;
295 cfg_.rc_dropframe_thresh = 10;
296 cfg_.rc_min_quantizer = 0;
297 cfg_.rc_max_quantizer = 50;
298 cfg_.rc_end_usage = AOM_CBR;
299 cfg_.rc_target_bitrate = 200;
300 cfg_.g_lag_in_frames = 0;
301 cfg_.g_error_resilient = 1;
302 // TODO(marpan): Investigate datarate target failures with a smaller
303 // keyframe interval (128).
304 cfg_.kf_max_dist = 9999;
305 cfg_.rc_dropframe_thresh = 0;
306 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
307 288, 30, 1, 0, 100);
308
309 ResetModel();
310 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Paul Wilkinsd6673a52019-11-22 11:55:16 +0000311 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.83)
Jerome Jiang88068862019-11-21 15:25:59 -0800312 << " The datarate for the file is lower than target by too much!";
Jerome Jiang8d1a1e42019-12-06 10:24:03 -0800313 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.20)
Jerome Jiang88068862019-11-21 15:25:59 -0800314 << " The datarate for the file is greater than target by too much!";
315 }
316};
317
Jerome Jiang68486892019-05-03 14:54:30 -0700318// Check basic rate targeting for VBR mode.
319TEST_P(DatarateTestRealtime, BasicRateTargetingVBR) {
320 BasicRateTargetingVBRTest();
321}
322
Jerome Jiangf7e6b902019-11-25 15:28:23 -0800323// Check basic rate targeting for CBR.
Jerome Jiang68486892019-05-03 14:54:30 -0700324TEST_P(DatarateTestRealtime, BasicRateTargetingCBR) {
325 BasicRateTargetingCBRTest();
326}
327
Jerome Jiangf7e6b902019-11-25 15:28:23 -0800328// Check basic rate targeting for periodic key frame.
329TEST_P(DatarateTestRealtime, PeriodicKeyFrameCBR) {
330 BasicRateTargetingCBRPeriodicKeyFrameTest();
331}
332
Jerome Jiang68486892019-05-03 14:54:30 -0700333// Check basic rate targeting for CBR.
Jerome Jiang646082b2019-10-18 13:49:49 -0700334TEST_P(DatarateTestRealtime, BasicRateTargeting444CBR) {
Jerome Jiang68486892019-05-03 14:54:30 -0700335 BasicRateTargeting444CBRTest();
336}
337
338// Check that (1) the first dropped frame gets earlier and earlier
339// as the drop frame threshold is increased, and (2) that the total number of
340// frame drops does not decrease as we increase frame drop threshold.
341// Use a lower qp-max to force some frame drops.
Jerome Jiang3c1f4612019-11-21 14:06:38 -0800342TEST_P(DatarateTestFrameDropRealtime, ChangingDropFrameThresh) {
Jerome Jiang68486892019-05-03 14:54:30 -0700343 ChangingDropFrameThreshTest();
344}
Jerome Jiang04d5a632019-05-03 12:03:28 -0700345
Jerome Jiang88068862019-11-21 15:25:59 -0800346TEST_P(DatarateTestSpeedChangeRealtime, ChangingSpeedTest) {
347 ChangingSpeedTest();
348}
349
Yaowu Xuf883b422016-08-30 14:01:10 -0700350AV1_INSTANTIATE_TEST_CASE(DatarateTestLarge,
Jerome Jiang95fcd322019-10-16 14:45:40 -0700351 ::testing::Values(::libaom_test::kRealTime),
Jerome Jiang861fd022019-09-13 14:13:33 -0700352 ::testing::Range(5, 7), ::testing::Values(0, 3),
Jerome Jiang68486892019-05-03 14:54:30 -0700353 ::testing::Values(0, 1));
Jerome Jiang04d5a632019-05-03 12:03:28 -0700354
Jerome Jiang3c1f4612019-11-21 14:06:38 -0800355AV1_INSTANTIATE_TEST_CASE(DatarateTestFrameDropLarge,
356 ::testing::Values(::libaom_test::kRealTime),
357 ::testing::Range(5, 7), ::testing::Values(0, 3));
358
Jerome Jiang68486892019-05-03 14:54:30 -0700359AV1_INSTANTIATE_TEST_CASE(DatarateTestRealtime,
Jerome Jiang04d5a632019-05-03 12:03:28 -0700360 ::testing::Values(::libaom_test::kRealTime),
Jerome Jiang861fd022019-09-13 14:13:33 -0700361 ::testing::Range(7, 9), ::testing::Values(0, 3),
Jerome Jiang68486892019-05-03 14:54:30 -0700362 ::testing::Values(0, 1));
Jerome Jiang04d5a632019-05-03 12:03:28 -0700363
Jerome Jiang3c1f4612019-11-21 14:06:38 -0800364AV1_INSTANTIATE_TEST_CASE(DatarateTestFrameDropRealtime,
365 ::testing::Values(::libaom_test::kRealTime),
366 ::testing::Range(7, 9), ::testing::Values(0, 3));
367
Jerome Jiang88068862019-11-21 15:25:59 -0800368AV1_INSTANTIATE_TEST_CASE(DatarateTestSpeedChangeRealtime,
369 ::testing::Values(::libaom_test::kRealTime),
370 ::testing::Values(0, 3));
371
Jim Bankoski533470c2012-10-29 19:54:06 -0700372} // namespace
Jerome Jiangd9603082019-08-14 17:24:17 -0700373} // namespace datarate_test