2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
10 #include "./vpx_config.h"
11 #include "third_party/googletest/src/include/gtest/gtest.h"
12 #include "test/codec_factory.h"
13 #include "test/encode_test_driver.h"
14 #include "test/i420_video_source.h"
15 #include "test/util.h"
16 #include "test/y4m_video_source.h"
17 #include "vpx/vpx_codec.h"
21 class DatarateTestLarge
: public ::libvpx_test::EncoderTest
,
22 public ::libvpx_test::CodecTestWithParam
<libvpx_test::TestMode
> {
24 DatarateTestLarge() : EncoderTest(GET_PARAM(0)) {}
26 virtual ~DatarateTestLarge() {}
29 virtual void SetUp() {
31 SetMode(GET_PARAM(1));
35 virtual void ResetModel() {
37 bits_in_buffer_model_
= cfg_
.rc_target_bitrate
* cfg_
.rc_buf_initial_sz
;
42 denoiser_offon_test_
= 0;
43 denoiser_offon_period_
= -1;
46 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource
*video
,
47 ::libvpx_test::Encoder
*encoder
) {
48 if (video
->frame() == 0)
49 encoder
->Control(VP8E_SET_NOISE_SENSITIVITY
, denoiser_on_
);
51 if (denoiser_offon_test_
) {
52 ASSERT_GT(denoiser_offon_period_
, 0)
53 << "denoiser_offon_period_ is not positive.";
54 if ((video
->frame() + 1) % denoiser_offon_period_
== 0) {
55 // Flip denoiser_on_ periodically
58 encoder
->Control(VP8E_SET_NOISE_SENSITIVITY
, denoiser_on_
);
61 const vpx_rational_t tb
= video
->timebase();
62 timebase_
= static_cast<double>(tb
.num
) / tb
.den
;
66 virtual void FramePktHook(const vpx_codec_cx_pkt_t
*pkt
) {
67 // Time since last timestamp = duration.
68 vpx_codec_pts_t duration
= pkt
->data
.frame
.pts
- last_pts_
;
70 // TODO(jimbankoski): Remove these lines when the issue:
71 // http://code.google.com/p/webm/issues/detail?id=496 is fixed.
72 // For now the codec assumes buffer starts at starting buffer rate
73 // plus one frame's time.
77 // Add to the buffer the bits we'd expect from a constant bitrate server.
78 bits_in_buffer_model_
+= static_cast<int64_t>(
79 duration
* timebase_
* cfg_
.rc_target_bitrate
* 1000);
81 /* Test the buffer model here before subtracting the frame. Do so because
82 * the way the leaky bucket model works in libvpx is to allow the buffer to
83 * empty - and then stop showing frames until we've got enough bits to
84 * show one. As noted in comment below (issue 495), this does not currently
85 * apply to key frames. For now exclude key frames in condition below. */
86 const bool key_frame
= (pkt
->data
.frame
.flags
& VPX_FRAME_IS_KEY
)
89 ASSERT_GE(bits_in_buffer_model_
, 0) << "Buffer Underrun at frame "
90 << pkt
->data
.frame
.pts
;
93 const size_t frame_size_in_bits
= pkt
->data
.frame
.sz
* 8;
95 // Subtract from the buffer the bits associated with a played back frame.
96 bits_in_buffer_model_
-= frame_size_in_bits
;
98 // Update the running total of bits for end of test datarate checks.
99 bits_total_
+= frame_size_in_bits
;
101 // If first drop not set and we have a drop set it to this time.
102 if (!first_drop_
&& duration
> 1)
103 first_drop_
= last_pts_
+ 1;
105 // Update the most recent pts.
106 last_pts_
= pkt
->data
.frame
.pts
;
108 // We update this so that we can calculate the datarate minus the last
109 // frame encoded in the file.
110 bits_in_last_frame_
= frame_size_in_bits
;
115 virtual void EndPassHook(void) {
117 const double file_size_in_kb
= bits_total_
/ 1000.; // bits per kilobit
119 duration_
= (last_pts_
+ 1) * timebase_
;
121 // Effective file datarate includes the time spent prebuffering.
122 effective_datarate_
= (bits_total_
- bits_in_last_frame_
) / 1000.0
123 / (cfg_
.rc_buf_initial_sz
/ 1000.0 + duration_
);
125 file_datarate_
= file_size_in_kb
/ duration_
;
129 vpx_codec_pts_t last_pts_
;
130 int64_t bits_in_buffer_model_
;
133 vpx_codec_pts_t first_drop_
;
136 double file_datarate_
;
137 double effective_datarate_
;
138 size_t bits_in_last_frame_
;
140 int denoiser_offon_test_
;
141 int denoiser_offon_period_
;
144 #if CONFIG_TEMPORAL_DENOISING
145 // Check basic datarate targeting, for a single bitrate, but loop over the
146 // various denoiser settings.
147 TEST_P(DatarateTestLarge
, DenoiserLevels
) {
148 cfg_
.rc_buf_initial_sz
= 500;
149 cfg_
.rc_dropframe_thresh
= 1;
150 cfg_
.rc_max_quantizer
= 56;
151 cfg_
.rc_end_usage
= VPX_CBR
;
152 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
154 for (int j
= 1; j
< 5; ++j
) {
155 // Run over the denoiser levels.
156 // For the temporal denoiser (#if CONFIG_TEMPORAL_DENOISING) the level j
157 // refers to the 4 denoiser modes: denoiserYonly, denoiserOnYUV,
158 // denoiserOnAggressive, and denoiserOnAdaptive.
159 // For the spatial denoiser (if !CONFIG_TEMPORAL_DENOISING), the level j
160 // refers to the blur thresholds: 20, 40, 60 80.
161 // The j = 0 case (denoiser off) is covered in the tests below.
163 cfg_
.rc_target_bitrate
= 300;
165 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
166 ASSERT_GE(cfg_
.rc_target_bitrate
, effective_datarate_
* 0.95)
167 << " The datarate for the file exceeds the target!";
169 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.3)
170 << " The datarate for the file missed the target!";
174 // Check basic datarate targeting, for a single bitrate, when denoiser is off
176 TEST_P(DatarateTestLarge
, DenoiserOffOn
) {
177 cfg_
.rc_buf_initial_sz
= 500;
178 cfg_
.rc_dropframe_thresh
= 1;
179 cfg_
.rc_max_quantizer
= 56;
180 cfg_
.rc_end_usage
= VPX_CBR
;
181 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
183 cfg_
.rc_target_bitrate
= 300;
185 // The denoiser is off by default.
187 // Set the offon test flag.
188 denoiser_offon_test_
= 1;
189 denoiser_offon_period_
= 100;
190 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
191 ASSERT_GE(cfg_
.rc_target_bitrate
, effective_datarate_
* 0.95)
192 << " The datarate for the file exceeds the target!";
193 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.3)
194 << " The datarate for the file missed the target!";
196 #endif // CONFIG_TEMPORAL_DENOISING
198 TEST_P(DatarateTestLarge
, BasicBufferModel
) {
200 cfg_
.rc_buf_initial_sz
= 500;
201 cfg_
.rc_dropframe_thresh
= 1;
202 cfg_
.rc_max_quantizer
= 56;
203 cfg_
.rc_end_usage
= VPX_CBR
;
204 // 2 pass cbr datarate control has a bug hidden by the small # of
205 // frames selected in this encode. The problem is that even if the buffer is
206 // negative we produce a keyframe on a cutscene. Ignoring datarate
208 // TODO(jimbankoski): ( Fix when issue
209 // http://code.google.com/p/webm/issues/detail?id=495 is addressed. )
210 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
213 // There is an issue for low bitrates in real-time mode, where the
214 // effective_datarate slightly overshoots the target bitrate.
215 // This is same the issue as noted about (#495).
216 // TODO(jimbankoski/marpan): Update test to run for lower bitrates (< 100),
217 // when the issue is resolved.
218 for (int i
= 100; i
< 800; i
+= 200) {
219 cfg_
.rc_target_bitrate
= i
;
221 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
222 ASSERT_GE(cfg_
.rc_target_bitrate
, effective_datarate_
* 0.95)
223 << " The datarate for the file exceeds the target!";
225 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.3)
226 << " The datarate for the file missed the target!";
230 TEST_P(DatarateTestLarge
, ChangingDropFrameThresh
) {
232 cfg_
.rc_buf_initial_sz
= 500;
233 cfg_
.rc_max_quantizer
= 36;
234 cfg_
.rc_end_usage
= VPX_CBR
;
235 cfg_
.rc_target_bitrate
= 200;
236 cfg_
.kf_mode
= VPX_KF_DISABLED
;
238 const int frame_count
= 40;
239 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
240 30, 1, 0, frame_count
);
242 // Here we check that the first dropped frame gets earlier and earlier
243 // as the drop frame threshold is increased.
245 const int kDropFrameThreshTestStep
= 30;
246 vpx_codec_pts_t last_drop
= frame_count
;
247 for (int i
= 1; i
< 91; i
+= kDropFrameThreshTestStep
) {
248 cfg_
.rc_dropframe_thresh
= i
;
250 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
251 ASSERT_LE(first_drop_
, last_drop
)
252 << " The first dropped frame for drop_thresh " << i
253 << " > first dropped frame for drop_thresh "
254 << i
- kDropFrameThreshTestStep
;
255 last_drop
= first_drop_
;
259 class DatarateTestVP9Large
: public ::libvpx_test::EncoderTest
,
260 public ::libvpx_test::CodecTestWith2Params
<libvpx_test::TestMode
, int> {
262 DatarateTestVP9Large() : EncoderTest(GET_PARAM(0)) {}
265 virtual ~DatarateTestVP9Large() {}
267 virtual void SetUp() {
269 SetMode(GET_PARAM(1));
270 set_cpu_used_
= GET_PARAM(2);
274 virtual void ResetModel() {
276 bits_in_buffer_model_
= cfg_
.rc_target_bitrate
* cfg_
.rc_buf_initial_sz
;
278 tot_frame_number_
= 0;
281 // Denoiser is off by default.
283 // For testing up to 3 layers.
284 for (int i
= 0; i
< 3; ++i
) {
287 denoiser_offon_test_
= 0;
288 denoiser_offon_period_
= -1;
292 // Frame flags and layer id for temporal layers.
295 // For two layers, test pattern is:
298 // For three layers, test pattern is:
302 // LAST is always update on base/layer 0, GOLDEN is updated on layer 1.
303 // For this 3 layer example, the 2nd enhancement layer (layer 2) does not
304 // update any reference frames.
305 int SetFrameFlags(int frame_num
, int num_temp_layers
) {
307 if (num_temp_layers
== 2) {
308 if (frame_num
% 2 == 0) {
309 // Layer 0: predict from L and ARF, update L.
310 frame_flags
= VP8_EFLAG_NO_REF_GF
| VP8_EFLAG_NO_UPD_GF
|
311 VP8_EFLAG_NO_UPD_ARF
;
313 // Layer 1: predict from L, G and ARF, and update G.
314 frame_flags
= VP8_EFLAG_NO_UPD_ARF
| VP8_EFLAG_NO_UPD_LAST
|
315 VP8_EFLAG_NO_UPD_ENTROPY
;
317 } else if (num_temp_layers
== 3) {
318 if (frame_num
% 4 == 0) {
319 // Layer 0: predict from L and ARF; update L.
320 frame_flags
= VP8_EFLAG_NO_UPD_GF
| VP8_EFLAG_NO_UPD_ARF
|
322 } else if ((frame_num
- 2) % 4 == 0) {
323 // Layer 1: predict from L, G, ARF; update G.
324 frame_flags
= VP8_EFLAG_NO_UPD_ARF
| VP8_EFLAG_NO_UPD_LAST
;
325 } else if ((frame_num
- 1) % 2 == 0) {
326 // Layer 2: predict from L, G, ARF; update none.
327 frame_flags
= VP8_EFLAG_NO_UPD_GF
| VP8_EFLAG_NO_UPD_ARF
|
328 VP8_EFLAG_NO_UPD_LAST
;
334 int SetLayerId(int frame_num
, int num_temp_layers
) {
336 if (num_temp_layers
== 2) {
337 if (frame_num
% 2 == 0) {
342 } else if (num_temp_layers
== 3) {
343 if (frame_num
% 4 == 0) {
345 } else if ((frame_num
- 2) % 4 == 0) {
347 } else if ((frame_num
- 1) % 2 == 0) {
354 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource
*video
,
355 ::libvpx_test::Encoder
*encoder
) {
356 if (video
->frame() == 0)
357 encoder
->Control(VP8E_SET_CPUUSED
, set_cpu_used_
);
359 if (denoiser_offon_test_
) {
360 ASSERT_GT(denoiser_offon_period_
, 0)
361 << "denoiser_offon_period_ is not positive.";
362 if ((video
->frame() + 1) % denoiser_offon_period_
== 0) {
363 // Flip denoiser_on_ periodically
368 encoder
->Control(VP9E_SET_NOISE_SENSITIVITY
, denoiser_on_
);
370 if (cfg_
.ts_number_layers
> 1) {
371 if (video
->frame() == 0) {
372 encoder
->Control(VP9E_SET_SVC
, 1);
374 vpx_svc_layer_id_t layer_id
;
375 layer_id
.spatial_layer_id
= 0;
376 frame_flags_
= SetFrameFlags(video
->frame(), cfg_
.ts_number_layers
);
377 layer_id
.temporal_layer_id
= SetLayerId(video
->frame(),
378 cfg_
.ts_number_layers
);
379 encoder
->Control(VP9E_SET_SVC_LAYER_ID
, &layer_id
);
381 const vpx_rational_t tb
= video
->timebase();
382 timebase_
= static_cast<double>(tb
.num
) / tb
.den
;
387 virtual void FramePktHook(const vpx_codec_cx_pkt_t
*pkt
) {
388 // Time since last timestamp = duration.
389 vpx_codec_pts_t duration
= pkt
->data
.frame
.pts
- last_pts_
;
392 // If first drop not set and we have a drop set it to this time.
394 first_drop_
= last_pts_
+ 1;
395 // Update the number of frame drops.
396 num_drops_
+= static_cast<int>(duration
- 1);
397 // Update counter for total number of frames (#frames input to encoder).
398 // Needed for setting the proper layer_id below.
399 tot_frame_number_
+= static_cast<int>(duration
- 1);
402 int layer
= SetLayerId(tot_frame_number_
, cfg_
.ts_number_layers
);
404 // Add to the buffer the bits we'd expect from a constant bitrate server.
405 bits_in_buffer_model_
+= static_cast<int64_t>(
406 duration
* timebase_
* cfg_
.rc_target_bitrate
* 1000);
408 // Buffer should not go negative.
409 ASSERT_GE(bits_in_buffer_model_
, 0) << "Buffer Underrun at frame "
410 << pkt
->data
.frame
.pts
;
412 const size_t frame_size_in_bits
= pkt
->data
.frame
.sz
* 8;
414 // Update the total encoded bits. For temporal layers, update the cumulative
415 // encoded bits per layer.
416 for (int i
= layer
; i
< static_cast<int>(cfg_
.ts_number_layers
); ++i
) {
417 bits_total_
[i
] += frame_size_in_bits
;
420 // Update the most recent pts.
421 last_pts_
= pkt
->data
.frame
.pts
;
426 virtual void EndPassHook(void) {
427 for (int layer
= 0; layer
< static_cast<int>(cfg_
.ts_number_layers
);
429 duration_
= (last_pts_
+ 1) * timebase_
;
430 if (bits_total_
[layer
]) {
431 // Effective file datarate:
432 effective_datarate_
[layer
] = (bits_total_
[layer
] / 1000.0) / duration_
;
437 vpx_codec_pts_t last_pts_
;
439 int frame_number_
; // Counter for number of non-dropped/encoded frames.
440 int tot_frame_number_
; // Counter for total number of input frames.
441 int64_t bits_total_
[3];
443 double effective_datarate_
[3];
445 int64_t bits_in_buffer_model_
;
446 vpx_codec_pts_t first_drop_
;
449 int denoiser_offon_test_
;
450 int denoiser_offon_period_
;
453 // Check basic rate targeting,
454 TEST_P(DatarateTestVP9Large
, BasicRateTargeting
) {
455 cfg_
.rc_buf_initial_sz
= 500;
456 cfg_
.rc_buf_optimal_sz
= 500;
457 cfg_
.rc_buf_sz
= 1000;
458 cfg_
.rc_dropframe_thresh
= 1;
459 cfg_
.rc_min_quantizer
= 0;
460 cfg_
.rc_max_quantizer
= 63;
461 cfg_
.rc_end_usage
= VPX_CBR
;
462 cfg_
.g_lag_in_frames
= 0;
464 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
466 for (int i
= 150; i
< 800; i
+= 200) {
467 cfg_
.rc_target_bitrate
= i
;
469 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
470 ASSERT_GE(effective_datarate_
[0], cfg_
.rc_target_bitrate
* 0.85)
471 << " The datarate for the file is lower than target by too much!";
472 ASSERT_LE(effective_datarate_
[0], cfg_
.rc_target_bitrate
* 1.15)
473 << " The datarate for the file is greater than target by too much!";
477 // Check basic rate targeting,
478 TEST_P(DatarateTestVP9Large
, BasicRateTargeting444
) {
479 ::libvpx_test::Y4mVideoSource
video("rush_hour_444.y4m", 0, 140);
482 cfg_
.g_timebase
= video
.timebase();
484 cfg_
.rc_buf_initial_sz
= 500;
485 cfg_
.rc_buf_optimal_sz
= 500;
486 cfg_
.rc_buf_sz
= 1000;
487 cfg_
.rc_dropframe_thresh
= 1;
488 cfg_
.rc_min_quantizer
= 0;
489 cfg_
.rc_max_quantizer
= 63;
490 cfg_
.rc_end_usage
= VPX_CBR
;
492 for (int i
= 250; i
< 900; i
+= 200) {
493 cfg_
.rc_target_bitrate
= i
;
495 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
496 ASSERT_GE(static_cast<double>(cfg_
.rc_target_bitrate
),
497 effective_datarate_
[0] * 0.85)
498 << " The datarate for the file exceeds the target by too much!";
499 ASSERT_LE(static_cast<double>(cfg_
.rc_target_bitrate
),
500 effective_datarate_
[0] * 1.15)
501 << " The datarate for the file missed the target!"
502 << cfg_
.rc_target_bitrate
<< " "<< effective_datarate_
;
506 // Check that (1) the first dropped frame gets earlier and earlier
507 // as the drop frame threshold is increased, and (2) that the total number of
508 // frame drops does not decrease as we increase frame drop threshold.
509 // Use a lower qp-max to force some frame drops.
510 TEST_P(DatarateTestVP9Large
, ChangingDropFrameThresh
) {
511 cfg_
.rc_buf_initial_sz
= 500;
512 cfg_
.rc_buf_optimal_sz
= 500;
513 cfg_
.rc_buf_sz
= 1000;
514 cfg_
.rc_undershoot_pct
= 20;
515 cfg_
.rc_undershoot_pct
= 20;
516 cfg_
.rc_dropframe_thresh
= 10;
517 cfg_
.rc_min_quantizer
= 0;
518 cfg_
.rc_max_quantizer
= 50;
519 cfg_
.rc_end_usage
= VPX_CBR
;
520 cfg_
.rc_target_bitrate
= 200;
521 cfg_
.g_lag_in_frames
= 0;
522 // TODO(marpan): Investigate datarate target failures with a smaller keyframe
524 cfg_
.kf_max_dist
= 9999;
526 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
529 const int kDropFrameThreshTestStep
= 30;
530 vpx_codec_pts_t last_drop
= 140;
531 int last_num_drops
= 0;
532 for (int i
= 10; i
< 100; i
+= kDropFrameThreshTestStep
) {
533 cfg_
.rc_dropframe_thresh
= i
;
535 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
536 ASSERT_GE(effective_datarate_
[0], cfg_
.rc_target_bitrate
* 0.85)
537 << " The datarate for the file is lower than target by too much!";
538 ASSERT_LE(effective_datarate_
[0], cfg_
.rc_target_bitrate
* 1.15)
539 << " The datarate for the file is greater than target by too much!";
540 ASSERT_LE(first_drop_
, last_drop
)
541 << " The first dropped frame for drop_thresh " << i
542 << " > first dropped frame for drop_thresh "
543 << i
- kDropFrameThreshTestStep
;
544 ASSERT_GE(num_drops_
, last_num_drops
* 0.85)
545 << " The number of dropped frames for drop_thresh " << i
546 << " < number of dropped frames for drop_thresh "
547 << i
- kDropFrameThreshTestStep
;
548 last_drop
= first_drop_
;
549 last_num_drops
= num_drops_
;
553 // Check basic rate targeting for 2 temporal layers.
554 TEST_P(DatarateTestVP9Large
, BasicRateTargeting2TemporalLayers
) {
555 cfg_
.rc_buf_initial_sz
= 500;
556 cfg_
.rc_buf_optimal_sz
= 500;
557 cfg_
.rc_buf_sz
= 1000;
558 cfg_
.rc_dropframe_thresh
= 1;
559 cfg_
.rc_min_quantizer
= 0;
560 cfg_
.rc_max_quantizer
= 63;
561 cfg_
.rc_end_usage
= VPX_CBR
;
562 cfg_
.g_lag_in_frames
= 0;
564 // 2 Temporal layers, no spatial layers: Framerate decimation (2, 1).
565 cfg_
.ss_number_layers
= 1;
566 cfg_
.ts_number_layers
= 2;
567 cfg_
.ts_rate_decimator
[0] = 2;
568 cfg_
.ts_rate_decimator
[1] = 1;
570 cfg_
.temporal_layering_mode
= VP9E_TEMPORAL_LAYERING_MODE_BYPASS
;
572 if (deadline_
== VPX_DL_REALTIME
)
573 cfg_
.g_error_resilient
= 1;
575 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
577 for (int i
= 200; i
<= 800; i
+= 200) {
578 cfg_
.rc_target_bitrate
= i
;
580 // 60-40 bitrate allocation for 2 temporal layers.
581 cfg_
.layer_target_bitrate
[0] = 60 * cfg_
.rc_target_bitrate
/ 100;
582 cfg_
.layer_target_bitrate
[1] = cfg_
.rc_target_bitrate
;
583 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
584 for (int j
= 0; j
< static_cast<int>(cfg_
.ts_number_layers
); ++j
) {
585 ASSERT_GE(effective_datarate_
[j
], cfg_
.layer_target_bitrate
[j
] * 0.85)
586 << " The datarate for the file is lower than target by too much, "
588 ASSERT_LE(effective_datarate_
[j
], cfg_
.layer_target_bitrate
[j
] * 1.15)
589 << " The datarate for the file is greater than target by too much, "
595 // Check basic rate targeting for 3 temporal layers.
596 TEST_P(DatarateTestVP9Large
, BasicRateTargeting3TemporalLayers
) {
597 cfg_
.rc_buf_initial_sz
= 500;
598 cfg_
.rc_buf_optimal_sz
= 500;
599 cfg_
.rc_buf_sz
= 1000;
600 cfg_
.rc_dropframe_thresh
= 1;
601 cfg_
.rc_min_quantizer
= 0;
602 cfg_
.rc_max_quantizer
= 63;
603 cfg_
.rc_end_usage
= VPX_CBR
;
604 cfg_
.g_lag_in_frames
= 0;
606 // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1).
607 cfg_
.ss_number_layers
= 1;
608 cfg_
.ts_number_layers
= 3;
609 cfg_
.ts_rate_decimator
[0] = 4;
610 cfg_
.ts_rate_decimator
[1] = 2;
611 cfg_
.ts_rate_decimator
[2] = 1;
613 cfg_
.temporal_layering_mode
= VP9E_TEMPORAL_LAYERING_MODE_BYPASS
;
615 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
617 for (int i
= 200; i
<= 800; i
+= 200) {
618 cfg_
.rc_target_bitrate
= i
;
620 // 40-20-40 bitrate allocation for 3 temporal layers.
621 cfg_
.layer_target_bitrate
[0] = 40 * cfg_
.rc_target_bitrate
/ 100;
622 cfg_
.layer_target_bitrate
[1] = 60 * cfg_
.rc_target_bitrate
/ 100;
623 cfg_
.layer_target_bitrate
[2] = cfg_
.rc_target_bitrate
;
624 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
625 for (int j
= 0; j
< static_cast<int>(cfg_
.ts_number_layers
); ++j
) {
626 // TODO(yaowu): Work out more stable rc control strategy and
627 // Adjust the thresholds to be tighter than .75.
628 ASSERT_GE(effective_datarate_
[j
], cfg_
.layer_target_bitrate
[j
] * 0.75)
629 << " The datarate for the file is lower than target by too much, "
631 // TODO(yaowu): Work out more stable rc control strategy and
632 // Adjust the thresholds to be tighter than 1.25.
633 ASSERT_LE(effective_datarate_
[j
], cfg_
.layer_target_bitrate
[j
] * 1.25)
634 << " The datarate for the file is greater than target by too much, "
640 // Check basic rate targeting for 3 temporal layers, with frame dropping.
641 // Only for one (low) bitrate with lower max_quantizer, and somewhat higher
642 // frame drop threshold, to force frame dropping.
643 TEST_P(DatarateTestVP9Large
, BasicRateTargeting3TemporalLayersFrameDropping
) {
644 cfg_
.rc_buf_initial_sz
= 500;
645 cfg_
.rc_buf_optimal_sz
= 500;
646 cfg_
.rc_buf_sz
= 1000;
647 // Set frame drop threshold and rc_max_quantizer to force some frame drops.
648 cfg_
.rc_dropframe_thresh
= 20;
649 cfg_
.rc_max_quantizer
= 45;
650 cfg_
.rc_min_quantizer
= 0;
651 cfg_
.rc_end_usage
= VPX_CBR
;
652 cfg_
.g_lag_in_frames
= 0;
654 // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1).
655 cfg_
.ss_number_layers
= 1;
656 cfg_
.ts_number_layers
= 3;
657 cfg_
.ts_rate_decimator
[0] = 4;
658 cfg_
.ts_rate_decimator
[1] = 2;
659 cfg_
.ts_rate_decimator
[2] = 1;
661 cfg_
.temporal_layering_mode
= VP9E_TEMPORAL_LAYERING_MODE_BYPASS
;
663 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
665 cfg_
.rc_target_bitrate
= 200;
667 // 40-20-40 bitrate allocation for 3 temporal layers.
668 cfg_
.layer_target_bitrate
[0] = 40 * cfg_
.rc_target_bitrate
/ 100;
669 cfg_
.layer_target_bitrate
[1] = 60 * cfg_
.rc_target_bitrate
/ 100;
670 cfg_
.layer_target_bitrate
[2] = cfg_
.rc_target_bitrate
;
671 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
672 for (int j
= 0; j
< static_cast<int>(cfg_
.ts_number_layers
); ++j
) {
673 ASSERT_GE(effective_datarate_
[j
], cfg_
.layer_target_bitrate
[j
] * 0.85)
674 << " The datarate for the file is lower than target by too much, "
676 ASSERT_LE(effective_datarate_
[j
], cfg_
.layer_target_bitrate
[j
] * 1.15)
677 << " The datarate for the file is greater than target by too much, "
679 // Expect some frame drops in this test: for this 200 frames test,
680 // expect at least 10% and not more than 60% drops.
681 ASSERT_GE(num_drops_
, 20);
682 ASSERT_LE(num_drops_
, 130);
686 #if CONFIG_VP9_TEMPORAL_DENOISING
687 // Check basic datarate targeting, for a single bitrate, when denoiser is on.
688 TEST_P(DatarateTestVP9Large
, DenoiserLevels
) {
689 cfg_
.rc_buf_initial_sz
= 500;
690 cfg_
.rc_buf_optimal_sz
= 500;
691 cfg_
.rc_buf_sz
= 1000;
692 cfg_
.rc_dropframe_thresh
= 1;
693 cfg_
.rc_min_quantizer
= 2;
694 cfg_
.rc_max_quantizer
= 56;
695 cfg_
.rc_end_usage
= VPX_CBR
;
696 cfg_
.g_lag_in_frames
= 0;
698 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
701 // For the temporal denoiser (#if CONFIG_VP9_TEMPORAL_DENOISING),
702 // there is only one denoiser mode: denoiserYonly(which is 1),
703 // but may add more modes in the future.
704 cfg_
.rc_target_bitrate
= 300;
706 // Turn on the denoiser.
708 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
709 ASSERT_GE(effective_datarate_
[0], cfg_
.rc_target_bitrate
* 0.85)
710 << " The datarate for the file is lower than target by too much!";
711 ASSERT_LE(effective_datarate_
[0], cfg_
.rc_target_bitrate
* 1.15)
712 << " The datarate for the file is greater than target by too much!";
715 // Check basic datarate targeting, for a single bitrate, when denoiser is off
717 TEST_P(DatarateTestVP9Large
, DenoiserOffOn
) {
718 cfg_
.rc_buf_initial_sz
= 500;
719 cfg_
.rc_buf_optimal_sz
= 500;
720 cfg_
.rc_buf_sz
= 1000;
721 cfg_
.rc_dropframe_thresh
= 1;
722 cfg_
.rc_min_quantizer
= 2;
723 cfg_
.rc_max_quantizer
= 56;
724 cfg_
.rc_end_usage
= VPX_CBR
;
725 cfg_
.g_lag_in_frames
= 0;
727 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
730 // For the temporal denoiser (#if CONFIG_VP9_TEMPORAL_DENOISING),
731 // there is only one denoiser mode: denoiserYonly(which is 1),
732 // but may add more modes in the future.
733 cfg_
.rc_target_bitrate
= 300;
735 // The denoiser is off by default.
737 // Set the offon test flag.
738 denoiser_offon_test_
= 1;
739 denoiser_offon_period_
= 100;
740 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
741 ASSERT_GE(effective_datarate_
[0], cfg_
.rc_target_bitrate
* 0.85)
742 << " The datarate for the file is lower than target by too much!";
743 ASSERT_LE(effective_datarate_
[0], cfg_
.rc_target_bitrate
* 1.15)
744 << " The datarate for the file is greater than target by too much!";
746 #endif // CONFIG_VP9_TEMPORAL_DENOISING
748 class DatarateOnePassCbrSvc
: public ::libvpx_test::EncoderTest
,
749 public ::libvpx_test::CodecTestWith2Params
<libvpx_test::TestMode
, int> {
751 DatarateOnePassCbrSvc() : EncoderTest(GET_PARAM(0)) {}
752 virtual ~DatarateOnePassCbrSvc() {}
754 virtual void SetUp() {
756 SetMode(GET_PARAM(1));
757 speed_setting_
= GET_PARAM(2);
760 virtual void ResetModel() {
762 bits_in_buffer_model_
= cfg_
.rc_target_bitrate
* cfg_
.rc_buf_initial_sz
;
767 mismatch_psnr_
= 0.0;
768 mismatch_nframes_
= 0;
770 virtual void BeginPassHook(unsigned int /*pass*/) {
772 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource
*video
,
773 ::libvpx_test::Encoder
*encoder
) {
774 if (video
->frame() == 0) {
776 for (i
= 0; i
< VPX_MAX_LAYERS
; ++i
) {
777 svc_params_
.max_quantizers
[i
] = 63;
778 svc_params_
.min_quantizers
[i
] = 0;
780 encoder
->Control(VP9E_SET_SVC
, 1);
781 encoder
->Control(VP9E_SET_SVC_PARAMETERS
, &svc_params_
);
782 encoder
->Control(VP8E_SET_CPUUSED
, speed_setting_
);
783 encoder
->Control(VP9E_SET_TILE_COLUMNS
, 0);
784 encoder
->Control(VP8E_SET_MAX_INTRA_BITRATE_PCT
, 300);
785 encoder
->Control(VP9E_SET_TILE_COLUMNS
, (cfg_
.g_threads
>> 1));
787 const vpx_rational_t tb
= video
->timebase();
788 timebase_
= static_cast<double>(tb
.num
) / tb
.den
;
791 virtual void FramePktHook(const vpx_codec_cx_pkt_t
*pkt
) {
792 vpx_codec_pts_t duration
= pkt
->data
.frame
.pts
- last_pts_
;
795 bits_in_buffer_model_
+= static_cast<int64_t>(
796 duration
* timebase_
* cfg_
.rc_target_bitrate
* 1000);
797 const bool key_frame
= (pkt
->data
.frame
.flags
& VPX_FRAME_IS_KEY
)
800 ASSERT_GE(bits_in_buffer_model_
, 0) << "Buffer Underrun at frame "
801 << pkt
->data
.frame
.pts
;
803 const size_t frame_size_in_bits
= pkt
->data
.frame
.sz
* 8;
804 bits_in_buffer_model_
-= frame_size_in_bits
;
805 bits_total_
+= frame_size_in_bits
;
806 if (!first_drop_
&& duration
> 1)
807 first_drop_
= last_pts_
+ 1;
808 last_pts_
= pkt
->data
.frame
.pts
;
809 bits_in_last_frame_
= frame_size_in_bits
;
812 virtual void EndPassHook(void) {
814 const double file_size_in_kb
= bits_total_
/ 1000.; // bits per kilobit
815 duration_
= (last_pts_
+ 1) * timebase_
;
816 file_datarate_
= file_size_in_kb
/ duration_
;
820 virtual void MismatchHook(const vpx_image_t
*img1
,
821 const vpx_image_t
*img2
) {
822 double mismatch_psnr
= compute_psnr(img1
, img2
);
823 mismatch_psnr_
+= mismatch_psnr
;
827 unsigned int GetMismatchFrames() {
828 return mismatch_nframes_
;
831 vpx_codec_pts_t last_pts_
;
832 int64_t bits_in_buffer_model_
;
835 vpx_codec_pts_t first_drop_
;
838 double file_datarate_
;
839 size_t bits_in_last_frame_
;
840 vpx_svc_extra_cfg_t svc_params_
;
842 double mismatch_psnr_
;
843 int mismatch_nframes_
;
845 static void assign_layer_bitrates(vpx_codec_enc_cfg_t
*const enc_cfg
,
846 const vpx_svc_extra_cfg_t
*svc_params
,
849 int temporal_layering_mode
) {
850 int sl
, spatial_layer_target
;
852 float alloc_ratio
[VPX_MAX_LAYERS
] = {0};
853 for (sl
= 0; sl
< spatial_layers
; ++sl
) {
854 if (svc_params
->scaling_factor_den
[sl
] > 0) {
855 alloc_ratio
[sl
] = (float)(svc_params
->scaling_factor_num
[sl
] *
856 1.0 / svc_params
->scaling_factor_den
[sl
]);
857 total
+= alloc_ratio
[sl
];
860 for (sl
= 0; sl
< spatial_layers
; ++sl
) {
861 enc_cfg
->ss_target_bitrate
[sl
] = spatial_layer_target
=
862 (unsigned int)(enc_cfg
->rc_target_bitrate
*
863 alloc_ratio
[sl
] / total
);
864 const int index
= sl
* temporal_layers
;
865 if (temporal_layering_mode
== 3) {
866 enc_cfg
->layer_target_bitrate
[index
] =
867 spatial_layer_target
>> 1;
868 enc_cfg
->layer_target_bitrate
[index
+ 1] =
869 (spatial_layer_target
>> 1) + (spatial_layer_target
>> 2);
870 enc_cfg
->layer_target_bitrate
[index
+ 2] =
871 spatial_layer_target
;
872 } else if (temporal_layering_mode
== 2) {
873 enc_cfg
->layer_target_bitrate
[index
] =
874 spatial_layer_target
* 2 / 3;
875 enc_cfg
->layer_target_bitrate
[index
+ 1] =
876 spatial_layer_target
;
881 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and
882 // 3 temporal layers. Run CIF clip with 1 thread.
883 TEST_P(DatarateOnePassCbrSvc
, OnePassCbrSvc2SpatialLayers
) {
884 cfg_
.rc_buf_initial_sz
= 500;
885 cfg_
.rc_buf_optimal_sz
= 500;
886 cfg_
.rc_buf_sz
= 1000;
887 cfg_
.rc_min_quantizer
= 0;
888 cfg_
.rc_max_quantizer
= 63;
889 cfg_
.rc_end_usage
= VPX_CBR
;
890 cfg_
.g_lag_in_frames
= 0;
891 cfg_
.ss_number_layers
= 2;
892 cfg_
.ts_number_layers
= 3;
893 cfg_
.ts_rate_decimator
[0] = 4;
894 cfg_
.ts_rate_decimator
[1] = 2;
895 cfg_
.ts_rate_decimator
[2] = 1;
896 cfg_
.g_error_resilient
= 1;
898 cfg_
.temporal_layering_mode
= 3;
899 svc_params_
.scaling_factor_num
[0] = 144;
900 svc_params_
.scaling_factor_den
[0] = 288;
901 svc_params_
.scaling_factor_num
[1] = 288;
902 svc_params_
.scaling_factor_den
[1] = 288;
903 cfg_
.rc_dropframe_thresh
= 10;
904 cfg_
.kf_max_dist
= 9999;
905 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
907 // TODO(wonkap/marpan): Check that effective_datarate for each layer hits the
908 // layer target_bitrate.
909 for (int i
= 200; i
<= 800; i
+= 200) {
910 cfg_
.rc_target_bitrate
= i
;
912 assign_layer_bitrates(&cfg_
, &svc_params_
, cfg_
.ss_number_layers
,
913 cfg_
.ts_number_layers
, cfg_
.temporal_layering_mode
);
914 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
915 ASSERT_GE(cfg_
.rc_target_bitrate
, file_datarate_
* 0.85)
916 << " The datarate for the file exceeds the target by too much!";
917 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.15)
918 << " The datarate for the file is lower than the target by too much!";
919 EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
923 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 3
924 // temporal layers. Run CIF clip with 1 thread, and few short key frame periods.
925 TEST_P(DatarateOnePassCbrSvc
, OnePassCbrSvc2SpatialLayersSmallKf
) {
926 cfg_
.rc_buf_initial_sz
= 500;
927 cfg_
.rc_buf_optimal_sz
= 500;
928 cfg_
.rc_buf_sz
= 1000;
929 cfg_
.rc_min_quantizer
= 0;
930 cfg_
.rc_max_quantizer
= 63;
931 cfg_
.rc_end_usage
= VPX_CBR
;
932 cfg_
.g_lag_in_frames
= 0;
933 cfg_
.ss_number_layers
= 2;
934 cfg_
.ts_number_layers
= 3;
935 cfg_
.ts_rate_decimator
[0] = 4;
936 cfg_
.ts_rate_decimator
[1] = 2;
937 cfg_
.ts_rate_decimator
[2] = 1;
938 cfg_
.g_error_resilient
= 1;
940 cfg_
.temporal_layering_mode
= 3;
941 svc_params_
.scaling_factor_num
[0] = 144;
942 svc_params_
.scaling_factor_den
[0] = 288;
943 svc_params_
.scaling_factor_num
[1] = 288;
944 svc_params_
.scaling_factor_den
[1] = 288;
945 cfg_
.rc_dropframe_thresh
= 10;
946 ::libvpx_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
948 cfg_
.rc_target_bitrate
= 400;
949 // For this 3 temporal layer case, pattern repeats every 4 frames, so choose
950 // 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
951 for (int j
= 64; j
<= 67; j
++) {
952 cfg_
.kf_max_dist
= j
;
954 assign_layer_bitrates(&cfg_
, &svc_params_
, cfg_
.ss_number_layers
,
955 cfg_
.ts_number_layers
, cfg_
.temporal_layering_mode
);
956 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
957 ASSERT_GE(cfg_
.rc_target_bitrate
, file_datarate_
* 0.85)
958 << " The datarate for the file exceeds the target by too much!";
959 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.15)
960 << " The datarate for the file is lower than the target by too much!";
961 EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
965 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and
966 // 3 temporal layers. Run HD clip with 4 threads.
967 TEST_P(DatarateOnePassCbrSvc
, OnePassCbrSvc2SpatialLayers4threads
) {
968 cfg_
.rc_buf_initial_sz
= 500;
969 cfg_
.rc_buf_optimal_sz
= 500;
970 cfg_
.rc_buf_sz
= 1000;
971 cfg_
.rc_min_quantizer
= 0;
972 cfg_
.rc_max_quantizer
= 63;
973 cfg_
.rc_end_usage
= VPX_CBR
;
974 cfg_
.g_lag_in_frames
= 0;
975 cfg_
.ss_number_layers
= 2;
976 cfg_
.ts_number_layers
= 3;
977 cfg_
.ts_rate_decimator
[0] = 4;
978 cfg_
.ts_rate_decimator
[1] = 2;
979 cfg_
.ts_rate_decimator
[2] = 1;
980 cfg_
.g_error_resilient
= 1;
982 cfg_
.temporal_layering_mode
= 3;
983 svc_params_
.scaling_factor_num
[0] = 144;
984 svc_params_
.scaling_factor_den
[0] = 288;
985 svc_params_
.scaling_factor_num
[1] = 288;
986 svc_params_
.scaling_factor_den
[1] = 288;
987 cfg_
.rc_dropframe_thresh
= 10;
988 cfg_
.kf_max_dist
= 9999;
989 ::libvpx_test::I420VideoSource
video("niklas_1280_720_30.y4m", 1280, 720,
991 cfg_
.rc_target_bitrate
= 800;
993 assign_layer_bitrates(&cfg_
, &svc_params_
, cfg_
.ss_number_layers
,
994 cfg_
.ts_number_layers
, cfg_
.temporal_layering_mode
);
995 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
996 ASSERT_GE(cfg_
.rc_target_bitrate
, file_datarate_
* 0.85)
997 << " The datarate for the file exceeds the target by too much!";
998 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.15)
999 << " The datarate for the file is lower than the target by too much!";
1000 EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
1003 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
1004 // 3 temporal layers. Run CIF clip with 1 thread.
1005 TEST_P(DatarateOnePassCbrSvc
, OnePassCbrSvc3SpatialLayers
) {
1006 cfg_
.rc_buf_initial_sz
= 500;
1007 cfg_
.rc_buf_optimal_sz
= 500;
1008 cfg_
.rc_buf_sz
= 1000;
1009 cfg_
.rc_min_quantizer
= 0;
1010 cfg_
.rc_max_quantizer
= 63;
1011 cfg_
.rc_end_usage
= VPX_CBR
;
1012 cfg_
.g_lag_in_frames
= 0;
1013 cfg_
.ss_number_layers
= 3;
1014 cfg_
.ts_number_layers
= 3;
1015 cfg_
.ts_rate_decimator
[0] = 4;
1016 cfg_
.ts_rate_decimator
[1] = 2;
1017 cfg_
.ts_rate_decimator
[2] = 1;
1018 cfg_
.g_error_resilient
= 1;
1020 cfg_
.temporal_layering_mode
= 3;
1021 svc_params_
.scaling_factor_num
[0] = 72;
1022 svc_params_
.scaling_factor_den
[0] = 288;
1023 svc_params_
.scaling_factor_num
[1] = 144;
1024 svc_params_
.scaling_factor_den
[1] = 288;
1025 svc_params_
.scaling_factor_num
[2] = 288;
1026 svc_params_
.scaling_factor_den
[2] = 288;
1027 cfg_
.rc_dropframe_thresh
= 10;
1028 cfg_
.kf_max_dist
= 9999;
1029 ::libvpx_test::I420VideoSource
video("niklas_1280_720_30.y4m", 1280, 720,
1031 cfg_
.rc_target_bitrate
= 800;
1033 assign_layer_bitrates(&cfg_
, &svc_params_
, cfg_
.ss_number_layers
,
1034 cfg_
.ts_number_layers
, cfg_
.temporal_layering_mode
);
1035 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
1036 ASSERT_GE(cfg_
.rc_target_bitrate
, file_datarate_
* 0.85)
1037 << " The datarate for the file exceeds the target by too much!";
1038 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.22)
1039 << " The datarate for the file is lower than the target by too much!";
1040 EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
1043 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3
1044 // temporal layers. Run CIF clip with 1 thread, and few short key frame periods.
1045 TEST_P(DatarateOnePassCbrSvc
, OnePassCbrSvc3SpatialLayersSmallKf
) {
1046 cfg_
.rc_buf_initial_sz
= 500;
1047 cfg_
.rc_buf_optimal_sz
= 500;
1048 cfg_
.rc_buf_sz
= 1000;
1049 cfg_
.rc_min_quantizer
= 0;
1050 cfg_
.rc_max_quantizer
= 63;
1051 cfg_
.rc_end_usage
= VPX_CBR
;
1052 cfg_
.g_lag_in_frames
= 0;
1053 cfg_
.ss_number_layers
= 3;
1054 cfg_
.ts_number_layers
= 3;
1055 cfg_
.ts_rate_decimator
[0] = 4;
1056 cfg_
.ts_rate_decimator
[1] = 2;
1057 cfg_
.ts_rate_decimator
[2] = 1;
1058 cfg_
.g_error_resilient
= 1;
1060 cfg_
.temporal_layering_mode
= 3;
1061 svc_params_
.scaling_factor_num
[0] = 72;
1062 svc_params_
.scaling_factor_den
[0] = 288;
1063 svc_params_
.scaling_factor_num
[1] = 144;
1064 svc_params_
.scaling_factor_den
[1] = 288;
1065 svc_params_
.scaling_factor_num
[2] = 288;
1066 svc_params_
.scaling_factor_den
[2] = 288;
1067 cfg_
.rc_dropframe_thresh
= 10;
1068 ::libvpx_test::I420VideoSource
video("niklas_1280_720_30.y4m", 1280, 720,
1070 cfg_
.rc_target_bitrate
= 800;
1071 // For this 3 temporal layer case, pattern repeats every 4 frames, so choose
1072 // 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
1073 for (int j
= 32; j
<= 35; j
++) {
1074 cfg_
.kf_max_dist
= j
;
1076 assign_layer_bitrates(&cfg_
, &svc_params_
, cfg_
.ss_number_layers
,
1077 cfg_
.ts_number_layers
, cfg_
.temporal_layering_mode
);
1078 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
1079 ASSERT_GE(cfg_
.rc_target_bitrate
, file_datarate_
* 0.85)
1080 << " The datarate for the file exceeds the target by too much!";
1081 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.30)
1082 << " The datarate for the file is lower than the target by too much!";
1083 EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
1087 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
1088 // 3 temporal layers. Run HD clip with 4 threads.
1089 TEST_P(DatarateOnePassCbrSvc
, OnePassCbrSvc3SpatialLayers4threads
) {
1090 cfg_
.rc_buf_initial_sz
= 500;
1091 cfg_
.rc_buf_optimal_sz
= 500;
1092 cfg_
.rc_buf_sz
= 1000;
1093 cfg_
.rc_min_quantizer
= 0;
1094 cfg_
.rc_max_quantizer
= 63;
1095 cfg_
.rc_end_usage
= VPX_CBR
;
1096 cfg_
.g_lag_in_frames
= 0;
1097 cfg_
.ss_number_layers
= 3;
1098 cfg_
.ts_number_layers
= 3;
1099 cfg_
.ts_rate_decimator
[0] = 4;
1100 cfg_
.ts_rate_decimator
[1] = 2;
1101 cfg_
.ts_rate_decimator
[2] = 1;
1102 cfg_
.g_error_resilient
= 1;
1104 cfg_
.temporal_layering_mode
= 3;
1105 svc_params_
.scaling_factor_num
[0] = 72;
1106 svc_params_
.scaling_factor_den
[0] = 288;
1107 svc_params_
.scaling_factor_num
[1] = 144;
1108 svc_params_
.scaling_factor_den
[1] = 288;
1109 svc_params_
.scaling_factor_num
[2] = 288;
1110 svc_params_
.scaling_factor_den
[2] = 288;
1111 cfg_
.rc_dropframe_thresh
= 10;
1112 cfg_
.kf_max_dist
= 9999;
1113 ::libvpx_test::I420VideoSource
video("niklas_1280_720_30.y4m", 1280, 720,
1115 cfg_
.rc_target_bitrate
= 800;
1117 assign_layer_bitrates(&cfg_
, &svc_params_
, cfg_
.ss_number_layers
,
1118 cfg_
.ts_number_layers
, cfg_
.temporal_layering_mode
);
1119 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
1120 ASSERT_GE(cfg_
.rc_target_bitrate
, file_datarate_
* 0.85)
1121 << " The datarate for the file exceeds the target by too much!";
1122 ASSERT_LE(cfg_
.rc_target_bitrate
, file_datarate_
* 1.22)
1123 << " The datarate for the file is lower than the target by too much!";
1124 EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
1127 VP8_INSTANTIATE_TEST_CASE(DatarateTestLarge
, ALL_TEST_MODES
);
1128 VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9Large
,
1129 ::testing::Values(::libvpx_test::kOnePassGood
,
1130 ::libvpx_test::kRealTime
),
1131 ::testing::Range(2, 9));
1132 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvc
,
1133 ::testing::Values(::libvpx_test::kRealTime
),
1134 ::testing::Range(5, 9));