1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3 *
4 * 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.
10 */
11
12 #include "config/aom_config.h"
13
14 #include "gtest/gtest.h"
15 #include "test/acm_random.h"
16 #include "test/codec_factory.h"
17 #include "test/datarate_test.h"
18 #include "test/encode_test_driver.h"
19 #include "test/i420_video_source.h"
20 #include "test/util.h"
21 #include "test/y4m_video_source.h"
22 #include "aom/aom_codec.h"
23
24 namespace datarate_test {
25 namespace {
26
27 // Params: test mode, speed, aq mode and index for bitrate array.
28 class DatarateTestLarge
29 : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int,
30 unsigned int, int>,
31 public DatarateTest {
32 public:
DatarateTestLarge()33 DatarateTestLarge() : DatarateTest(GET_PARAM(0)) {
34 set_cpu_used_ = GET_PARAM(2);
35 aq_mode_ = GET_PARAM(3);
36 }
37
38 protected:
39 ~DatarateTestLarge() override = default;
40
SetUp()41 void SetUp() override {
42 InitializeConfig(GET_PARAM(1));
43 ResetModel();
44 }
45
BasicRateTargetingVBRTest()46 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));
59 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.7)
60 << " The datarate for the file is lower than target by too much!";
61 // FIXME(jingning): Lower this test threshold after vbr mode can render
62 // sufficiently accurate bit rate.
63 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.45)
64 << " The datarate for the file is greater than target by too much!";
65 }
66
BasicRateTargetingCBRTest()67 virtual void BasicRateTargetingCBRTest() {
68 cfg_.rc_buf_initial_sz = 500;
69 cfg_.rc_buf_optimal_sz = 500;
70 cfg_.rc_buf_sz = 1000;
71 cfg_.rc_dropframe_thresh = 1;
72 cfg_.rc_min_quantizer = 0;
73 cfg_.rc_max_quantizer = 63;
74 cfg_.rc_end_usage = AOM_CBR;
75 cfg_.g_lag_in_frames = 0;
76
77 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
78 288, 30, 1, 0, 140);
79 const int bitrate_array[2] = { 150, 550 };
80 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
81 ResetModel();
82 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
83 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
84 << " The datarate for the file is lower than target by too much!";
85 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.19)
86 << " The datarate for the file is greater than target by too much!";
87 }
88
BasicRateTargetingCBRSpikeTest()89 virtual void BasicRateTargetingCBRSpikeTest() {
90 cfg_.rc_buf_initial_sz = 500;
91 cfg_.rc_buf_optimal_sz = 500;
92 cfg_.rc_buf_sz = 1000;
93 cfg_.rc_dropframe_thresh = 0;
94 cfg_.rc_min_quantizer = 2;
95 cfg_.rc_max_quantizer = 56;
96 cfg_.rc_end_usage = AOM_CBR;
97 cfg_.g_lag_in_frames = 0;
98 cfg_.kf_max_dist = 3000;
99 cfg_.kf_min_dist = 3000;
100
101 ::libaom_test::I420VideoSource video("desktopqvga2.320_240.yuv", 320, 240,
102 30, 1, 0, 800);
103 const int bitrate_array[2] = { 100, 200 };
104 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
105 ResetModel();
106 max_perc_spike_ = 3.0;
107 max_perc_spike_high_ = 8.0;
108 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
109 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
110 << " The datarate for the file is lower than target by too much!";
111 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.19)
112 << " The datarate for the file is greater than target by too much!";
113 ASSERT_LE(num_spikes_, 10);
114 ASSERT_LT(num_spikes_high_, 1);
115 }
116
BasicRateTargetingCBRDynamicBitrateTest()117 virtual void BasicRateTargetingCBRDynamicBitrateTest() {
118 cfg_.rc_buf_initial_sz = 500;
119 cfg_.rc_buf_optimal_sz = 500;
120 cfg_.rc_buf_sz = 1000;
121 cfg_.rc_dropframe_thresh = 0;
122 cfg_.rc_min_quantizer = 2;
123 cfg_.rc_max_quantizer = 56;
124 cfg_.rc_end_usage = AOM_CBR;
125 cfg_.g_lag_in_frames = 0;
126 cfg_.kf_max_dist = 3000;
127 cfg_.kf_min_dist = 3000;
128
129 ::libaom_test::I420VideoSource video("desktop1.320_180.yuv", 320, 180, 30,
130 1, 0, 800);
131 const int bitrate_array[2] = { 100, 200 };
132 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
133 ResetModel();
134 target_bitrate_update_[0] = cfg_.rc_target_bitrate;
135 target_bitrate_update_[1] = static_cast<int>(1.3 * cfg_.rc_target_bitrate);
136 target_bitrate_update_[2] = static_cast<int>(0.7 * cfg_.rc_target_bitrate);
137 frame_update_bitrate_ = 250;
138 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
139 for (int i = 0; i < 3; i++) {
140 ASSERT_GE(effective_datarate_dynamic_[i],
141 target_bitrate_update_[i] * 0.85)
142 << " The datarate for the file is lower than target by too much!";
143 ASSERT_LE(effective_datarate_dynamic_[i],
144 target_bitrate_update_[i] * 1.20)
145 << " The datarate for the file is greater than target by too much!";
146 }
147 }
148
BasicRateTargetingMultiThreadCBRTest()149 virtual void BasicRateTargetingMultiThreadCBRTest() {
150 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30,
151 1, 0, 400);
152 cfg_.rc_buf_initial_sz = 500;
153 cfg_.rc_buf_optimal_sz = 500;
154 cfg_.rc_buf_sz = 1000;
155 cfg_.rc_dropframe_thresh = 1;
156 cfg_.rc_min_quantizer = 0;
157 cfg_.rc_max_quantizer = 63;
158 cfg_.rc_end_usage = AOM_CBR;
159 cfg_.g_lag_in_frames = 0;
160 cfg_.g_threads = 4;
161
162 const int bitrate_array[2] = { 250, 650 };
163 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
164 ResetModel();
165 tile_columns_ = 2;
166 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
167 ASSERT_GE(static_cast<double>(cfg_.rc_target_bitrate),
168 effective_datarate_ * 0.85)
169 << " The datarate for the file exceeds the target by too much!";
170 ASSERT_LE(static_cast<double>(cfg_.rc_target_bitrate),
171 effective_datarate_ * 1.15)
172 << " The datarate for the file missed the target!"
173 << cfg_.rc_target_bitrate << " " << effective_datarate_;
174 }
175
ErrorResilienceOnSceneCuts()176 virtual void ErrorResilienceOnSceneCuts() {
177 if (GET_PARAM(4) > 0) return;
178 cfg_.rc_buf_initial_sz = 500;
179 cfg_.rc_buf_optimal_sz = 500;
180 cfg_.rc_buf_sz = 1000;
181 cfg_.rc_dropframe_thresh = 0;
182 cfg_.g_error_resilient = 1;
183 cfg_.rc_min_quantizer = 0;
184 cfg_.rc_max_quantizer = 63;
185 cfg_.rc_end_usage = AOM_CBR;
186 cfg_.g_lag_in_frames = 0;
187
188 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
189 288, 30, 1, 0, 300);
190 cfg_.rc_target_bitrate = 500;
191 ResetModel();
192 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
193 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
194 << " The datarate for the file is lower than target by too much!";
195 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.15)
196 << " The datarate for the file is greater than target by too much!";
197 }
198
BasicRateTargetingCBRPeriodicKeyFrameTest()199 virtual void BasicRateTargetingCBRPeriodicKeyFrameTest() {
200 cfg_.rc_buf_initial_sz = 500;
201 cfg_.rc_buf_optimal_sz = 500;
202 cfg_.rc_buf_sz = 1000;
203 cfg_.rc_dropframe_thresh = 1;
204 cfg_.rc_min_quantizer = 0;
205 cfg_.rc_max_quantizer = 63;
206 cfg_.rc_end_usage = AOM_CBR;
207 cfg_.g_lag_in_frames = 0;
208 // Periodic keyframe
209 cfg_.kf_max_dist = 50;
210
211 ::libaom_test::I420VideoSource video("pixel_capture_w320h240.yuv", 320, 240,
212 30, 1, 0, 310);
213 const int bitrate_array[2] = { 150, 550 };
214 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
215 ResetModel();
216 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
217 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
218 << " The datarate for the file is lower than target by too much!";
219 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.15)
220 << " The datarate for the file is greater than target by too much!";
221 }
222
CBRPeriodicKeyFrameOnSceneCuts()223 virtual void CBRPeriodicKeyFrameOnSceneCuts() {
224 if (GET_PARAM(4) > 0) return;
225 cfg_.rc_buf_initial_sz = 500;
226 cfg_.rc_buf_optimal_sz = 500;
227 cfg_.rc_buf_sz = 1000;
228 cfg_.rc_dropframe_thresh = 0;
229 cfg_.rc_min_quantizer = 0;
230 cfg_.rc_max_quantizer = 63;
231 cfg_.rc_end_usage = AOM_CBR;
232 cfg_.g_lag_in_frames = 0;
233 // Periodic keyframe
234 cfg_.kf_max_dist = 30;
235 cfg_.kf_min_dist = 30;
236
237 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
238 288, 30, 1, 0, 300);
239 cfg_.rc_target_bitrate = 500;
240 ResetModel();
241 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
242 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
243 << " The datarate for the file is lower than target by too much!";
244 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.3)
245 << " The datarate for the file is greater than target by too much!";
246 }
247
BasicRateTargetingAQModeOnOffCBRTest()248 virtual void BasicRateTargetingAQModeOnOffCBRTest() {
249 if (GET_PARAM(4) > 0) return;
250 cfg_.rc_buf_initial_sz = 500;
251 cfg_.rc_buf_optimal_sz = 500;
252 cfg_.rc_buf_sz = 1000;
253 cfg_.rc_dropframe_thresh = 0;
254 cfg_.rc_min_quantizer = 2;
255 cfg_.rc_max_quantizer = 63;
256 cfg_.rc_end_usage = AOM_CBR;
257 cfg_.g_lag_in_frames = 0;
258 cfg_.g_error_resilient = 0;
259 cfg_.g_pass = AOM_RC_ONE_PASS;
260 cfg_.g_usage = AOM_USAGE_REALTIME;
261 cfg_.kf_mode = AOM_KF_DISABLED;
262
263 ::libaom_test::I420VideoSource video("pixel_capture_w320h240.yuv", 320, 240,
264 30, 1, 0, 310);
265 cfg_.rc_target_bitrate = 60;
266 ResetModel();
267 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
268 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
269 << " The datarate for the file is lower than target by too much!";
270 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.15)
271 << " The datarate for the file is greater than target by too much!";
272 }
273
BasicRateTargeting444CBRScreenTest()274 virtual void BasicRateTargeting444CBRScreenTest() {
275 ::libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140);
276
277 cfg_.g_profile = 1;
278 cfg_.g_timebase = video.timebase();
279
280 cfg_.rc_buf_initial_sz = 500;
281 cfg_.rc_buf_optimal_sz = 500;
282 cfg_.rc_buf_sz = 1000;
283 cfg_.rc_dropframe_thresh = 1;
284 cfg_.rc_min_quantizer = 0;
285 cfg_.rc_max_quantizer = 63;
286 cfg_.rc_end_usage = AOM_CBR;
287
288 const int bitrate_array[2] = { 250, 650 };
289 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
290 ResetModel();
291 screen_mode_ = true;
292 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
293 ASSERT_GE(static_cast<double>(cfg_.rc_target_bitrate),
294 effective_datarate_ * 0.85)
295 << " The datarate for the file exceeds the target by too much!";
296 ASSERT_LE(static_cast<double>(cfg_.rc_target_bitrate),
297 effective_datarate_ * 1.15)
298 << " The datarate for the file missed the target!"
299 << cfg_.rc_target_bitrate << " " << effective_datarate_;
300 }
301
BasicRateTargetingSuperresCBR()302 virtual void BasicRateTargetingSuperresCBR() {
303 ::libaom_test::I420VideoSource video("desktopqvga2.320_240.yuv", 320, 240,
304 30, 1, 0, 800);
305
306 cfg_.g_profile = 0;
307 cfg_.g_timebase = video.timebase();
308
309 cfg_.rc_buf_initial_sz = 500;
310 cfg_.rc_buf_optimal_sz = 500;
311 cfg_.rc_buf_sz = 1000;
312 cfg_.rc_dropframe_thresh = 1;
313 cfg_.rc_min_quantizer = 0;
314 cfg_.rc_max_quantizer = 63;
315 cfg_.rc_end_usage = AOM_CBR;
316
317 cfg_.rc_superres_mode = AOM_SUPERRES_FIXED;
318 cfg_.rc_superres_denominator = 16;
319 cfg_.rc_superres_kf_denominator = 16;
320
321 const int bitrate_array[2] = { 250, 650 };
322 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
323 ResetModel();
324 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
325 ASSERT_GE(static_cast<double>(cfg_.rc_target_bitrate),
326 effective_datarate_ * 0.85)
327 << " The datarate for the file exceeds the target by too much!";
328 ASSERT_LE(static_cast<double>(cfg_.rc_target_bitrate),
329 effective_datarate_ * 1.15)
330 << " The datarate for the file missed the target!"
331 << cfg_.rc_target_bitrate << " " << effective_datarate_;
332 }
333
BasicRateTargetingSuperresCBRMultiThreads()334 virtual void BasicRateTargetingSuperresCBRMultiThreads() {
335 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30,
336 1, 0, 400);
337
338 cfg_.g_profile = 0;
339 cfg_.g_timebase = video.timebase();
340
341 cfg_.rc_buf_initial_sz = 500;
342 cfg_.rc_buf_optimal_sz = 500;
343 cfg_.rc_buf_sz = 1000;
344 cfg_.rc_dropframe_thresh = 1;
345 cfg_.rc_min_quantizer = 0;
346 cfg_.rc_max_quantizer = 63;
347 cfg_.rc_end_usage = AOM_CBR;
348 cfg_.g_threads = 2;
349
350 cfg_.rc_superres_mode = AOM_SUPERRES_FIXED;
351 cfg_.rc_superres_denominator = 16;
352 cfg_.rc_superres_kf_denominator = 16;
353
354 const int bitrate_array[2] = { 250, 650 };
355 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
356 ResetModel();
357 tile_columns_ = 1;
358 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
359 ASSERT_GE(static_cast<double>(cfg_.rc_target_bitrate),
360 effective_datarate_ * 0.85)
361 << " The datarate for the file exceeds the target by too much!";
362 ASSERT_LE(static_cast<double>(cfg_.rc_target_bitrate),
363 effective_datarate_ * 1.15)
364 << " The datarate for the file missed the target!"
365 << cfg_.rc_target_bitrate << " " << effective_datarate_;
366 }
367 };
368
369 // Params: test mode, speed, aq mode.
370 class DatarateTestFrameDropLarge
371 : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode, int,
372 unsigned int>,
373 public DatarateTest {
374 public:
DatarateTestFrameDropLarge()375 DatarateTestFrameDropLarge() : DatarateTest(GET_PARAM(0)) {
376 set_cpu_used_ = GET_PARAM(2);
377 aq_mode_ = GET_PARAM(3);
378 }
379
380 protected:
381 ~DatarateTestFrameDropLarge() override = default;
382
SetUp()383 void SetUp() override {
384 InitializeConfig(GET_PARAM(1));
385 ResetModel();
386 }
387
ChangingDropFrameThreshTest()388 virtual void ChangingDropFrameThreshTest() {
389 cfg_.rc_buf_initial_sz = 500;
390 cfg_.rc_buf_optimal_sz = 500;
391 cfg_.rc_buf_sz = 1000;
392 cfg_.rc_undershoot_pct = 20;
393 cfg_.rc_undershoot_pct = 20;
394 cfg_.rc_dropframe_thresh = 10;
395 cfg_.rc_min_quantizer = 0;
396 cfg_.rc_max_quantizer = 50;
397 cfg_.rc_end_usage = AOM_CBR;
398 cfg_.rc_target_bitrate = 200;
399 cfg_.g_lag_in_frames = 0;
400 cfg_.g_error_resilient = 1;
401 // TODO(marpan): Investigate datarate target failures with a smaller
402 // keyframe interval (128).
403 cfg_.kf_max_dist = 9999;
404
405 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
406 288, 30, 1, 0, 100);
407
408 const int kDropFrameThreshTestStep = 30;
409 aom_codec_pts_t last_drop = 140;
410 int last_num_drops = 0;
411 for (int i = 40; i < 100; i += kDropFrameThreshTestStep) {
412 cfg_.rc_dropframe_thresh = i;
413 ResetModel();
414 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
415 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
416 << " The datarate for the file is lower than target by too much!";
417 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.40)
418 << " The datarate for the file is greater than target by too much!";
419 if (last_drop > 0) {
420 ASSERT_LE(first_drop_, last_drop)
421 << " The first dropped frame for drop_thresh " << i
422 << " > first dropped frame for drop_thresh "
423 << i - kDropFrameThreshTestStep;
424 }
425 ASSERT_GE(num_drops_, last_num_drops * 0.7)
426 << " The number of dropped frames for drop_thresh " << i
427 << " < number of dropped frames for drop_thresh "
428 << i - kDropFrameThreshTestStep;
429 last_drop = first_drop_;
430 last_num_drops = num_drops_;
431 }
432 }
433 };
434
435 // Check basic rate targeting for VBR mode.
TEST_P(DatarateTestLarge,BasicRateTargetingVBR)436 TEST_P(DatarateTestLarge, BasicRateTargetingVBR) {
437 BasicRateTargetingVBRTest();
438 }
439
440 // Check basic rate targeting for CBR.
TEST_P(DatarateTestLarge,BasicRateTargetingCBR)441 TEST_P(DatarateTestLarge, BasicRateTargetingCBR) {
442 BasicRateTargetingCBRTest();
443 }
444
445 // Check basic rate targeting for CBR, with 4 threads
TEST_P(DatarateTestLarge,BasicRateTargetingMultiThreadCBR)446 TEST_P(DatarateTestLarge, BasicRateTargetingMultiThreadCBR) {
447 BasicRateTargetingMultiThreadCBRTest();
448 }
449
450 // Check basic rate targeting for periodic key frame.
TEST_P(DatarateTestLarge,PeriodicKeyFrameCBR)451 TEST_P(DatarateTestLarge, PeriodicKeyFrameCBR) {
452 BasicRateTargetingCBRPeriodicKeyFrameTest();
453 }
454
455 // Check basic rate targeting for periodic key frame, aligned with scene change.
TEST_P(DatarateTestLarge,PeriodicKeyFrameCBROnSceneCuts)456 TEST_P(DatarateTestLarge, PeriodicKeyFrameCBROnSceneCuts) {
457 CBRPeriodicKeyFrameOnSceneCuts();
458 }
459
460 // Check basic rate targeting with error resilience on for scene cuts.
TEST_P(DatarateTestLarge,ErrorResilienceOnSceneCuts)461 TEST_P(DatarateTestLarge, ErrorResilienceOnSceneCuts) {
462 ErrorResilienceOnSceneCuts();
463 }
464
465 // Check basic rate targeting for CBR, for 444 input screen mode.
466 #if defined(CONFIG_MAX_DECODE_PROFILE) && CONFIG_MAX_DECODE_PROFILE < 1
TEST_P(DatarateTestLarge,DISABLED_BasicRateTargeting444CBRScreen)467 TEST_P(DatarateTestLarge, DISABLED_BasicRateTargeting444CBRScreen) {
468 #else
469 TEST_P(DatarateTestLarge, BasicRateTargeting444CBRScreen) {
470 #endif
471 BasicRateTargeting444CBRScreenTest();
472 }
473
474 // Check basic rate targeting for Superres mode with CBR.
475 TEST_P(DatarateTestLarge, BasicRateTargetingSuperresCBR) {
476 BasicRateTargetingSuperresCBR();
477 }
478
479 // Check basic rate targeting for Superres mode with CBR and multi-threads.
480 TEST_P(DatarateTestLarge, BasicRateTargetingSuperresCBRMultiThreads) {
481 BasicRateTargetingSuperresCBRMultiThreads();
482 }
483
484 // Check that (1) the first dropped frame gets earlier and earlier
485 // as the drop frame threshold is increased, and (2) that the total number of
486 // frame drops does not decrease as we increase frame drop threshold.
487 // Use a lower qp-max to force some frame drops.
488 TEST_P(DatarateTestFrameDropLarge, ChangingDropFrameThresh) {
489 ChangingDropFrameThreshTest();
490 }
491
492 TEST_P(DatarateTestLarge, BasicRateTargetingAQModeOnOffCBR) {
493 BasicRateTargetingAQModeOnOffCBRTest();
494 }
495
496 class DatarateTestRealtime : public DatarateTestLarge {};
497
498 class DatarateTestFrameDropRealtime : public DatarateTestFrameDropLarge {};
499
500 // Params: aq mode.
501 class DatarateTestSpeedChangeRealtime
502 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode,
503 unsigned int>,
504 public DatarateTest {
505 public:
506 DatarateTestSpeedChangeRealtime() : DatarateTest(GET_PARAM(0)) {
507 aq_mode_ = GET_PARAM(1);
508 speed_change_test_ = true;
509 }
510
511 protected:
512 ~DatarateTestSpeedChangeRealtime() override = default;
513
514 void SetUp() override {
515 InitializeConfig(GET_PARAM(1));
516 ResetModel();
517 }
518
519 virtual void ChangingSpeedTest() {
520 cfg_.rc_buf_initial_sz = 500;
521 cfg_.rc_buf_optimal_sz = 500;
522 cfg_.rc_buf_sz = 1000;
523 cfg_.rc_undershoot_pct = 20;
524 cfg_.rc_undershoot_pct = 20;
525 cfg_.rc_dropframe_thresh = 10;
526 cfg_.rc_min_quantizer = 0;
527 cfg_.rc_max_quantizer = 50;
528 cfg_.rc_end_usage = AOM_CBR;
529 cfg_.rc_target_bitrate = 200;
530 cfg_.g_lag_in_frames = 0;
531 cfg_.g_error_resilient = 1;
532 // TODO(marpan): Investigate datarate target failures with a smaller
533 // keyframe interval (128).
534 cfg_.kf_max_dist = 9999;
535 cfg_.rc_dropframe_thresh = 0;
536 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
537 288, 30, 1, 0, 100);
538
539 ResetModel();
540 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
541 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.83)
542 << " The datarate for the file is lower than target by too much!";
543 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.35)
544 << " The datarate for the file is greater than target by too much!";
545 }
546 };
547
548 // Check basic rate targeting for VBR mode.
549 TEST_P(DatarateTestRealtime, BasicRateTargetingVBR) {
550 BasicRateTargetingVBRTest();
551 }
552
553 // Check basic rate targeting for CBR.
554 TEST_P(DatarateTestRealtime, BasicRateTargetingCBR) {
555 BasicRateTargetingCBRTest();
556 }
557
558 // Check basic rate targeting for CBR. Use a longer clip,
559 // and verify #encode size spikes above threshold.
560 TEST_P(DatarateTestRealtime, BasicRateTargetingCBRSpike) {
561 BasicRateTargetingCBRSpikeTest();
562 }
563
564 // Check basic rate targeting for CBR. Use a longer clip,
565 // and verify encoder can respnd and hit new bitrates updated
566 // within the stream.
567 TEST_P(DatarateTestRealtime, BasicRateTargetingCBRDynamicBitrate) {
568 BasicRateTargetingCBRDynamicBitrateTest();
569 }
570
571 // Check basic rate targeting for CBR, with 4 threads
572 TEST_P(DatarateTestRealtime, BasicRateTargetingMultiThreadCBR) {
573 BasicRateTargetingMultiThreadCBRTest();
574 }
575
576 // Check basic rate targeting for periodic key frame.
577 TEST_P(DatarateTestRealtime, PeriodicKeyFrameCBR) {
578 BasicRateTargetingCBRPeriodicKeyFrameTest();
579 }
580
581 // Check basic rate targeting for periodic key frame, aligned with scene change.
582 TEST_P(DatarateTestRealtime, PeriodicKeyFrameCBROnSceneCuts) {
583 CBRPeriodicKeyFrameOnSceneCuts();
584 }
585
586 // Check basic rate targeting with error resilience on for scene cuts.
587 TEST_P(DatarateTestRealtime, ErrorResilienceOnSceneCuts) {
588 ErrorResilienceOnSceneCuts();
589 }
590
591 // Check basic rate targeting for CBR for 444 screen mode.
592 #if defined(CONFIG_MAX_DECODE_PROFILE) && CONFIG_MAX_DECODE_PROFILE < 1
593 TEST_P(DatarateTestRealtime, DISABLED_BasicRateTargeting444CBRScreen) {
594 #else
595 TEST_P(DatarateTestRealtime, BasicRateTargeting444CBRScreen) {
596 #endif
597 BasicRateTargeting444CBRScreenTest();
598 }
599
600 // Check basic rate targeting for Superres mode with CBR.
601 TEST_P(DatarateTestRealtime, BasicRateTargetingSuperresCBR) {
602 BasicRateTargetingSuperresCBR();
603 }
604
605 // Check basic rate targeting for Superres mode with CBR and multi-threads.
606 TEST_P(DatarateTestRealtime, BasicRateTargetingSuperresCBRMultiThreads) {
607 BasicRateTargetingSuperresCBRMultiThreads();
608 }
609
610 // Check that (1) the first dropped frame gets earlier and earlier
611 // as the drop frame threshold is increased, and (2) that the total number of
612 // frame drops does not decrease as we increase frame drop threshold.
613 // Use a lower qp-max to force some frame drops.
614 TEST_P(DatarateTestFrameDropRealtime, ChangingDropFrameThresh) {
615 ChangingDropFrameThreshTest();
616 }
617
618 TEST_P(DatarateTestSpeedChangeRealtime, ChangingSpeedTest) {
619 ChangingSpeedTest();
620 }
621
622 class DatarateTestSetFrameQpRealtime
623 : public DatarateTest,
624 public ::testing::TestWithParam<const libaom_test::AV1CodecFactory *> {
625 public:
626 DatarateTestSetFrameQpRealtime() : DatarateTest(GetParam()), frame_(0) {}
627
628 protected:
629 ~DatarateTestSetFrameQpRealtime() override = default;
630
631 void SetUp() override {
632 InitializeConfig(libaom_test::kRealTime);
633 ResetModel();
634 }
635
636 void PreEncodeFrameHook(::libaom_test::VideoSource *video,
637 ::libaom_test::Encoder *encoder) override {
638 set_cpu_used_ = 7;
639 DatarateTest::PreEncodeFrameHook(video, encoder);
640 frame_qp_ = rnd_.PseudoUniform(63);
641 encoder->Control(AV1E_SET_QUANTIZER_ONE_PASS, frame_qp_);
642 frame_++;
643 }
644
645 void PostEncodeFrameHook(::libaom_test::Encoder *encoder) override {
646 if (frame_ >= total_frames_) return;
647 int qp = 0;
648 encoder->Control(AOME_GET_LAST_QUANTIZER_64, &qp);
649 ASSERT_EQ(qp, frame_qp_);
650 }
651
652 protected:
653 int total_frames_;
654
655 private:
656 int frame_qp_;
657 int frame_;
658 libaom_test::ACMRandom rnd_;
659 };
660
661 TEST_P(DatarateTestSetFrameQpRealtime, SetFrameQpOnePass) {
662 cfg_.rc_buf_initial_sz = 500;
663 cfg_.rc_buf_optimal_sz = 500;
664 cfg_.rc_buf_sz = 1000;
665 cfg_.rc_undershoot_pct = 20;
666 cfg_.rc_undershoot_pct = 20;
667 cfg_.rc_min_quantizer = 0;
668 cfg_.rc_max_quantizer = 50;
669 cfg_.rc_end_usage = AOM_CBR;
670 cfg_.rc_target_bitrate = 200;
671 cfg_.g_lag_in_frames = 0;
672 cfg_.g_error_resilient = 1;
673 cfg_.kf_max_dist = 9999;
674 cfg_.rc_dropframe_thresh = 0;
675
676 total_frames_ = 100;
677 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
678 30, 1, 0, 100);
679
680 ResetModel();
681 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
682 }
683
684 AV1_INSTANTIATE_TEST_SUITE(DatarateTestLarge,
685 ::testing::Values(::libaom_test::kRealTime),
686 ::testing::Range(5, 7), ::testing::Values(0, 3),
687 ::testing::Values(0, 1));
688
689 AV1_INSTANTIATE_TEST_SUITE(DatarateTestFrameDropLarge,
690 ::testing::Values(::libaom_test::kRealTime),
691 ::testing::Range(5, 7), ::testing::Values(0, 3));
692
693 AV1_INSTANTIATE_TEST_SUITE(DatarateTestRealtime,
694 ::testing::Values(::libaom_test::kRealTime),
695 ::testing::Range(7, 12), ::testing::Values(0, 3),
696 ::testing::Values(0, 1));
697
698 AV1_INSTANTIATE_TEST_SUITE(DatarateTestFrameDropRealtime,
699 ::testing::Values(::libaom_test::kRealTime),
700 ::testing::Range(7, 12), ::testing::Values(0, 3));
701
702 AV1_INSTANTIATE_TEST_SUITE(DatarateTestSpeedChangeRealtime,
703 ::testing::Values(::libaom_test::kRealTime),
704 ::testing::Values(0, 3));
705
706 INSTANTIATE_TEST_SUITE_P(
707 AV1, DatarateTestSetFrameQpRealtime,
708 ::testing::Values(
709 static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)));
710
711 } // namespace
712 } // namespace datarate_test
713