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/svc_test.h"
16 #include "test/util.h"
17 #include "test/y4m_video_source.h"
18 #include "vp9/common/vp9_onyxc_int.h"
19 #include "vpx/vpx_codec.h"
20 #include "vpx_ports/bitops.h"
24 class DatarateOnePassCbrSvc : public ::svc_test::OnePassCbrSvc {
26 explicit DatarateOnePassCbrSvc(const ::libvpx_test::CodecFactory *codec)
27 : OnePassCbrSvc(codec) {
28 inter_layer_pred_mode_ = 0;
32 virtual ~DatarateOnePassCbrSvc() {}
34 virtual void ResetModel() {
38 mismatch_nframes_ = 0;
41 base_speed_setting_ = 5;
42 spatial_layer_id_ = 0;
43 temporal_layer_id_ = 0;
45 memset(bits_in_buffer_model_, 0, sizeof(bits_in_buffer_model_));
46 memset(bits_total_, 0, sizeof(bits_total_));
47 memset(layer_target_avg_bandwidth_, 0, sizeof(layer_target_avg_bandwidth_));
48 dynamic_drop_layer_ = false;
49 change_bitrate_ = false;
53 superframe_count_ = -1;
54 key_frame_spacing_ = 9999;
55 num_nonref_frames_ = 0;
59 insert_layer_sync_ = 0;
60 layer_sync_on_base_ = 0;
61 force_intra_only_frame_ = 0;
62 superframe_has_intra_only_ = 0;
63 use_post_encode_drop_ = 0;
64 denoiser_off_on_ = false;
65 denoiser_enable_layers_ = false;
67 virtual void BeginPassHook(unsigned int /*pass*/) {}
69 // Example pattern for spatial layers and 2 temporal layers used in the
70 // bypass/flexible mode. The pattern corresponds to the pattern
71 // VP9E_TEMPORAL_LAYERING_MODE_0101 (temporal_layering_mode == 2) used in
72 // non-flexible mode, except that we disable inter-layer prediction.
73 void set_frame_flags_bypass_mode(
74 int tl, int num_spatial_layers, int is_key_frame,
75 vpx_svc_ref_frame_config_t *ref_frame_config) {
76 for (int sl = 0; sl < num_spatial_layers; ++sl)
77 ref_frame_config->update_buffer_slot[sl] = 0;
79 for (int sl = 0; sl < num_spatial_layers; ++sl) {
81 ref_frame_config->lst_fb_idx[sl] = sl;
84 ref_frame_config->lst_fb_idx[sl] = sl - 1;
85 ref_frame_config->gld_fb_idx[sl] = sl;
87 ref_frame_config->gld_fb_idx[sl] = sl - 1;
90 ref_frame_config->gld_fb_idx[sl] = 0;
92 ref_frame_config->alt_fb_idx[sl] = 0;
94 ref_frame_config->lst_fb_idx[sl] = sl;
95 ref_frame_config->gld_fb_idx[sl] =
96 VPXMIN(REF_FRAMES - 1, num_spatial_layers + sl - 1);
97 ref_frame_config->alt_fb_idx[sl] =
98 VPXMIN(REF_FRAMES - 1, num_spatial_layers + sl);
102 ref_frame_config->reference_last[sl] = 1;
103 ref_frame_config->reference_golden[sl] = 0;
104 ref_frame_config->reference_alt_ref[sl] = 0;
105 ref_frame_config->update_buffer_slot[sl] |=
106 1 << ref_frame_config->lst_fb_idx[sl];
109 ref_frame_config->reference_last[sl] = 1;
110 ref_frame_config->reference_golden[sl] = 0;
111 ref_frame_config->reference_alt_ref[sl] = 0;
112 ref_frame_config->update_buffer_slot[sl] |=
113 1 << ref_frame_config->gld_fb_idx[sl];
115 ref_frame_config->reference_last[sl] = 1;
116 ref_frame_config->reference_golden[sl] = 0;
117 ref_frame_config->reference_alt_ref[sl] = 0;
118 ref_frame_config->update_buffer_slot[sl] |=
119 1 << ref_frame_config->lst_fb_idx[sl];
122 } else if (tl == 1) {
124 ref_frame_config->reference_last[sl] = 1;
125 ref_frame_config->reference_golden[sl] = 0;
126 ref_frame_config->reference_alt_ref[sl] = 0;
127 ref_frame_config->update_buffer_slot[sl] |=
128 1 << ref_frame_config->alt_fb_idx[sl];
130 ref_frame_config->reference_last[sl] = 1;
131 ref_frame_config->reference_golden[sl] = 0;
132 ref_frame_config->reference_alt_ref[sl] = 0;
133 ref_frame_config->update_buffer_slot[sl] |=
134 1 << ref_frame_config->alt_fb_idx[sl];
140 void CheckLayerRateTargeting(int num_spatial_layers, int num_temporal_layers,
141 double thresh_overshoot,
142 double thresh_undershoot) const {
143 for (int sl = 0; sl < num_spatial_layers; ++sl)
144 for (int tl = 0; tl < num_temporal_layers; ++tl) {
145 const int layer = sl * num_temporal_layers + tl;
146 ASSERT_GE(cfg_.layer_target_bitrate[layer],
147 file_datarate_[layer] * thresh_overshoot)
148 << " The datarate for the file exceeds the target by too much!";
149 ASSERT_LE(cfg_.layer_target_bitrate[layer],
150 file_datarate_[layer] * thresh_undershoot)
151 << " The datarate for the file is lower than the target by too "
156 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
157 ::libvpx_test::Encoder *encoder) {
158 PreEncodeFrameHookSetup(video, encoder);
160 if (video->frame() == 0) {
161 if (force_intra_only_frame_) {
162 // Decoder sets the color_space for Intra-only frames
163 // to BT_601 (see line 1810 in vp9_decodeframe.c).
164 // So set it here in these tess to avoid encoder-decoder
165 // mismatch check on color space setting.
166 encoder->Control(VP9E_SET_COLOR_SPACE, VPX_CS_BT_601);
168 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_);
169 encoder->Control(VP9E_SET_TUNE_CONTENT, tune_content_);
170 encoder->Control(VP9E_SET_SVC_INTER_LAYER_PRED, inter_layer_pred_mode_);
172 if (layer_framedrop_) {
173 vpx_svc_frame_drop_t svc_drop_frame;
174 svc_drop_frame.framedrop_mode = LAYER_DROP;
175 for (int i = 0; i < number_spatial_layers_; i++)
176 svc_drop_frame.framedrop_thresh[i] = 30;
177 svc_drop_frame.max_consec_drop = 30;
178 encoder->Control(VP9E_SET_SVC_FRAME_DROP_LAYER, &svc_drop_frame);
181 if (use_post_encode_drop_) {
182 encoder->Control(VP9E_SET_POSTENCODE_DROP, use_post_encode_drop_);
186 if (denoiser_off_on_) {
187 encoder->Control(VP9E_SET_AQ_MODE, 3);
188 // Set inter_layer_pred to INTER_LAYER_PRED_OFF_NONKEY (K-SVC).
189 encoder->Control(VP9E_SET_SVC_INTER_LAYER_PRED, 2);
190 if (!denoiser_enable_layers_) {
191 if (video->frame() == 0)
192 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 0);
193 else if (video->frame() == 100)
194 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 1);
196 // Cumulative bitrates for top spatial layers, for
197 // 3 temporal layers.
198 if (video->frame() == 0) {
199 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 0);
200 // Change layer bitrates to set top spatial layer to 0.
201 // This is for 3 spatial 3 temporal layers.
202 // This will trigger skip encoding/dropping of top spatial layer.
203 cfg_.rc_target_bitrate -= cfg_.layer_target_bitrate[8];
204 for (int i = 0; i < 3; i++)
205 bitrate_sl3_[i] = cfg_.layer_target_bitrate[i + 6];
206 cfg_.layer_target_bitrate[6] = 0;
207 cfg_.layer_target_bitrate[7] = 0;
208 cfg_.layer_target_bitrate[8] = 0;
209 encoder->Config(&cfg_);
210 } else if (video->frame() == 100) {
211 // Change layer bitrates to non-zero on top spatial layer.
212 // This will trigger skip encoding of top spatial layer
213 // on key frame (period = 100).
214 for (int i = 0; i < 3; i++)
215 cfg_.layer_target_bitrate[i + 6] = bitrate_sl3_[i];
216 cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[8];
217 encoder->Config(&cfg_);
218 } else if (video->frame() == 120) {
219 // Enable denoiser and top spatial layer after key frame (period is
221 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 1);
226 if (update_pattern_ && video->frame() >= 100) {
227 vpx_svc_layer_id_t layer_id;
228 if (video->frame() == 100) {
229 cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS;
230 encoder->Config(&cfg_);
232 // Set layer id since the pattern changed.
233 layer_id.spatial_layer_id = 0;
234 layer_id.temporal_layer_id = (video->frame() % 2 != 0);
235 temporal_layer_id_ = layer_id.temporal_layer_id;
236 for (int i = 0; i < number_spatial_layers_; i++)
237 layer_id.temporal_layer_id_per_spatial[i] = temporal_layer_id_;
238 encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id);
239 set_frame_flags_bypass_mode(layer_id.temporal_layer_id,
240 number_spatial_layers_, 0, &ref_frame_config);
241 encoder->Control(VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config);
244 if (change_bitrate_ && video->frame() == 200) {
245 duration_ = (last_pts_ + 1) * timebase_;
246 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
247 for (int tl = 0; tl < number_temporal_layers_; ++tl) {
248 const int layer = sl * number_temporal_layers_ + tl;
249 const double file_size_in_kb = bits_total_[layer] / 1000.;
250 file_datarate_[layer] = file_size_in_kb / duration_;
254 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_,
257 memset(file_datarate_, 0, sizeof(file_datarate_));
258 memset(bits_total_, 0, sizeof(bits_total_));
259 int64_t bits_in_buffer_model_tmp[VPX_MAX_LAYERS];
260 last_pts_ref_ = last_pts_;
261 // Set new target bitarate.
262 cfg_.rc_target_bitrate = cfg_.rc_target_bitrate >> 1;
263 // Buffer level should not reset on dynamic bitrate change.
264 memcpy(bits_in_buffer_model_tmp, bits_in_buffer_model_,
265 sizeof(bits_in_buffer_model_));
266 AssignLayerBitrates();
267 memcpy(bits_in_buffer_model_, bits_in_buffer_model_tmp,
268 sizeof(bits_in_buffer_model_));
270 // Change config to update encoder with new bitrate configuration.
271 encoder->Config(&cfg_);
274 if (dynamic_drop_layer_) {
275 // TODO(jian): Disable AQ Mode for this test for now.
276 encoder->Control(VP9E_SET_AQ_MODE, 0);
277 if (video->frame() == 0) {
278 // Change layer bitrates to set top layers to 0. This will trigger skip
279 // encoding/dropping of top two spatial layers.
280 cfg_.rc_target_bitrate -=
281 (cfg_.layer_target_bitrate[1] + cfg_.layer_target_bitrate[2]);
282 middle_bitrate_ = cfg_.layer_target_bitrate[1];
283 top_bitrate_ = cfg_.layer_target_bitrate[2];
284 cfg_.layer_target_bitrate[1] = 0;
285 cfg_.layer_target_bitrate[2] = 0;
286 encoder->Config(&cfg_);
287 } else if (video->frame() == 50) {
288 // Change layer bitrates to non-zero on two top spatial layers.
289 // This will trigger skip encoding of top two spatial layers.
290 cfg_.layer_target_bitrate[1] = middle_bitrate_;
291 cfg_.layer_target_bitrate[2] = top_bitrate_;
292 cfg_.rc_target_bitrate +=
293 cfg_.layer_target_bitrate[2] + cfg_.layer_target_bitrate[1];
294 encoder->Config(&cfg_);
295 } else if (video->frame() == 100) {
296 // Change layer bitrates to set top layers to 0. This will trigger skip
297 // encoding/dropping of top two spatial layers.
298 cfg_.rc_target_bitrate -=
299 (cfg_.layer_target_bitrate[1] + cfg_.layer_target_bitrate[2]);
300 middle_bitrate_ = cfg_.layer_target_bitrate[1];
301 top_bitrate_ = cfg_.layer_target_bitrate[2];
302 cfg_.layer_target_bitrate[1] = 0;
303 cfg_.layer_target_bitrate[2] = 0;
304 encoder->Config(&cfg_);
305 } else if (video->frame() == 150) {
306 // Change layer bitrate on second layer to non-zero to start
307 // encoding it again.
308 cfg_.layer_target_bitrate[1] = middle_bitrate_;
309 cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[1];
310 encoder->Config(&cfg_);
311 } else if (video->frame() == 200) {
312 // Change layer bitrate on top layer to non-zero to start
313 // encoding it again.
314 cfg_.layer_target_bitrate[2] = top_bitrate_;
315 cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[2];
316 encoder->Config(&cfg_);
320 if (force_key_test_ && force_key_) frame_flags_ = VPX_EFLAG_FORCE_KF;
322 if (insert_layer_sync_) {
323 vpx_svc_spatial_layer_sync_t svc_layer_sync;
324 svc_layer_sync.base_layer_intra_only = 0;
325 for (int i = 0; i < number_spatial_layers_; i++)
326 svc_layer_sync.spatial_layer_sync[i] = 0;
327 if (force_intra_only_frame_) {
328 superframe_has_intra_only_ = 0;
329 if (video->frame() == 0) {
330 svc_layer_sync.base_layer_intra_only = 1;
331 svc_layer_sync.spatial_layer_sync[0] = 1;
332 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
333 superframe_has_intra_only_ = 1;
334 } else if (video->frame() == 100) {
335 svc_layer_sync.base_layer_intra_only = 1;
336 svc_layer_sync.spatial_layer_sync[0] = 1;
337 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
338 superframe_has_intra_only_ = 1;
341 layer_sync_on_base_ = 0;
342 if (video->frame() == 150) {
343 svc_layer_sync.spatial_layer_sync[1] = 1;
344 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
345 } else if (video->frame() == 240) {
346 svc_layer_sync.spatial_layer_sync[2] = 1;
347 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
348 } else if (video->frame() == 320) {
349 svc_layer_sync.spatial_layer_sync[0] = 1;
350 layer_sync_on_base_ = 1;
351 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
356 const vpx_rational_t tb = video->timebase();
357 timebase_ = static_cast<double>(tb.num) / tb.den;
361 vpx_codec_err_t parse_superframe_index(const uint8_t *data, size_t data_sz,
362 uint32_t sizes[8], int *count) {
364 marker = *(data + data_sz - 1);
366 if ((marker & 0xe0) == 0xc0) {
367 const uint32_t frames = (marker & 0x7) + 1;
368 const uint32_t mag = ((marker >> 3) & 0x3) + 1;
369 const size_t index_sz = 2 + mag * frames;
370 // This chunk is marked as having a superframe index but doesn't have
371 // enough data for it, thus it's an invalid superframe index.
372 if (data_sz < index_sz) return VPX_CODEC_CORRUPT_FRAME;
374 const uint8_t marker2 = *(data + data_sz - index_sz);
375 // This chunk is marked as having a superframe index but doesn't have
376 // the matching marker byte at the front of the index therefore it's an
378 if (marker != marker2) return VPX_CODEC_CORRUPT_FRAME;
382 const uint8_t *x = &data[data_sz - index_sz + 1];
383 for (i = 0; i < frames; ++i) {
384 uint32_t this_sz = 0;
386 for (j = 0; j < mag; ++j) this_sz |= (*x++) << (j * 8);
395 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
396 uint32_t sizes[8] = { 0 };
397 uint32_t sizes_parsed[8] = { 0 };
399 int num_layers_encoded = 0;
400 last_pts_ = pkt->data.frame.pts;
401 const bool key_frame =
402 (pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
404 // For test that inserts layer sync frames: requesting a layer_sync on
405 // the base layer must force key frame. So if any key frame occurs after
406 // first superframe it must due to layer sync on base spatial layer.
407 if (superframe_count_ > 0 && insert_layer_sync_ &&
408 !force_intra_only_frame_) {
409 ASSERT_EQ(layer_sync_on_base_, 1);
411 temporal_layer_id_ = 0;
412 superframe_count_ = 0;
414 parse_superframe_index(static_cast<const uint8_t *>(pkt->data.frame.buf),
415 pkt->data.frame.sz, sizes_parsed, &count);
416 // Count may be less than number of spatial layers because of frame drops.
417 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
418 if (pkt->data.frame.spatial_layer_encoded[sl]) {
419 sizes[sl] = sizes_parsed[num_layers_encoded];
420 num_layers_encoded++;
423 // For superframe with Intra-only count will be +1 larger
424 // because of no-show frame.
425 if (force_intra_only_frame_ && superframe_has_intra_only_)
426 ASSERT_EQ(count, num_layers_encoded + 1);
428 ASSERT_EQ(count, num_layers_encoded);
430 // In the constrained frame drop mode, if a given spatial is dropped all
431 // upper layers must be dropped too.
432 if (!layer_framedrop_) {
433 int num_layers_dropped = 0;
434 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
435 if (!pkt->data.frame.spatial_layer_encoded[sl]) {
436 // Check that all upper layers are dropped.
437 num_layers_dropped++;
438 for (int sl2 = sl + 1; sl2 < number_spatial_layers_; ++sl2)
439 ASSERT_EQ(pkt->data.frame.spatial_layer_encoded[sl2], 0);
442 if (num_layers_dropped == number_spatial_layers_ - 1)
447 // Keep track of number of non-reference frames, needed for mismatch check.
448 // Non-reference frames are top spatial and temporal layer frames,
450 if (temporal_layer_id_ == number_temporal_layers_ - 1 &&
451 temporal_layer_id_ > 0 &&
452 pkt->data.frame.spatial_layer_encoded[number_spatial_layers_ - 1])
453 num_nonref_frames_++;
454 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
455 sizes[sl] = sizes[sl] << 3;
456 // Update the total encoded bits per layer.
457 // For temporal layers, update the cumulative encoded bits per layer.
458 for (int tl = temporal_layer_id_; tl < number_temporal_layers_; ++tl) {
459 const int layer = sl * number_temporal_layers_ + tl;
460 bits_total_[layer] += static_cast<int64_t>(sizes[sl]);
461 // Update the per-layer buffer level with the encoded frame size.
462 bits_in_buffer_model_[layer] -= static_cast<int64_t>(sizes[sl]);
463 // There should be no buffer underrun, except on the base
464 // temporal layer, since there may be key frames there.
465 // Fo short key frame spacing, buffer can underrun on individual frames.
466 if (!key_frame && tl > 0 && key_frame_spacing_ < 100) {
467 ASSERT_GE(bits_in_buffer_model_[layer], 0)
468 << "Buffer Underrun at frame " << pkt->data.frame.pts;
472 ASSERT_EQ(pkt->data.frame.width[sl],
473 top_sl_width_ * svc_params_.scaling_factor_num[sl] /
474 svc_params_.scaling_factor_den[sl]);
476 ASSERT_EQ(pkt->data.frame.height[sl],
477 top_sl_height_ * svc_params_.scaling_factor_num[sl] /
478 svc_params_.scaling_factor_den[sl]);
482 virtual void EndPassHook(void) {
483 if (change_bitrate_) last_pts_ = last_pts_ - last_pts_ref_;
484 duration_ = (last_pts_ + 1) * timebase_;
485 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
486 for (int tl = 0; tl < number_temporal_layers_; ++tl) {
487 const int layer = sl * number_temporal_layers_ + tl;
488 const double file_size_in_kb = bits_total_[layer] / 1000.;
489 file_datarate_[layer] = file_size_in_kb / duration_;
494 virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) {
495 double mismatch_psnr = compute_psnr(img1, img2);
496 mismatch_psnr_ += mismatch_psnr;
500 unsigned int GetMismatchFrames() { return mismatch_nframes_; }
502 vpx_codec_pts_t last_pts_;
504 int64_t bits_total_[VPX_MAX_LAYERS];
506 double file_datarate_[VPX_MAX_LAYERS];
507 size_t bits_in_last_frame_;
508 double mismatch_psnr_;
509 int mismatch_nframes_;
512 int spatial_layer_id_;
513 bool dynamic_drop_layer_;
514 unsigned int top_sl_width_;
515 unsigned int top_sl_height_;
516 vpx_svc_ref_frame_config_t ref_frame_config;
518 bool change_bitrate_;
519 vpx_codec_pts_t last_pts_ref_;
522 int key_frame_spacing_;
523 unsigned int num_nonref_frames_;
524 int layer_framedrop_;
527 int inter_layer_pred_mode_;
528 int insert_layer_sync_;
529 int layer_sync_on_base_;
530 int force_intra_only_frame_;
531 int superframe_has_intra_only_;
532 int use_post_encode_drop_;
534 // Denoiser switched on the fly.
535 bool denoiser_off_on_;
536 // Top layer enabled on the fly.
537 bool denoiser_enable_layers_;
540 virtual void SetConfig(const int num_temporal_layer) {
541 cfg_.rc_end_usage = VPX_CBR;
542 cfg_.g_lag_in_frames = 0;
543 cfg_.g_error_resilient = 1;
544 if (num_temporal_layer == 3) {
545 cfg_.ts_rate_decimator[0] = 4;
546 cfg_.ts_rate_decimator[1] = 2;
547 cfg_.ts_rate_decimator[2] = 1;
548 cfg_.temporal_layering_mode = 3;
549 } else if (num_temporal_layer == 2) {
550 cfg_.ts_rate_decimator[0] = 2;
551 cfg_.ts_rate_decimator[1] = 1;
552 cfg_.temporal_layering_mode = 2;
553 } else if (num_temporal_layer == 1) {
554 cfg_.ts_rate_decimator[0] = 1;
555 cfg_.temporal_layering_mode = 0;
560 // Params: speed setting.
561 class DatarateOnePassCbrSvcSingleBR
562 : public DatarateOnePassCbrSvc,
563 public ::libvpx_test::CodecTestWithParam<int> {
565 DatarateOnePassCbrSvcSingleBR() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
566 memset(&svc_params_, 0, sizeof(svc_params_));
568 virtual ~DatarateOnePassCbrSvcSingleBR() {}
571 virtual void SetUp() {
573 SetMode(::libvpx_test::kRealTime);
574 speed_setting_ = GET_PARAM(1);
579 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 1
580 // temporal layer, with screen content mode on and same speed setting for all
582 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL1TLScreenContent1) {
584 cfg_.rc_buf_initial_sz = 500;
585 cfg_.rc_buf_optimal_sz = 500;
586 cfg_.rc_buf_sz = 1000;
587 cfg_.rc_min_quantizer = 0;
588 cfg_.rc_max_quantizer = 63;
590 cfg_.rc_dropframe_thresh = 10;
591 cfg_.kf_max_dist = 9999;
593 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
594 top_sl_width_ = 1280;
595 top_sl_height_ = 720;
596 cfg_.rc_target_bitrate = 500;
599 AssignLayerBitrates();
600 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
601 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
603 #if CONFIG_VP9_DECODER
604 // The non-reference frames are expected to be mismatched frames as the
605 // encoder will avoid loopfilter on these frames.
606 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
610 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
611 // 3 temporal layers, with force key frame after frame drop
612 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLForceKey) {
614 cfg_.rc_buf_initial_sz = 500;
615 cfg_.rc_buf_optimal_sz = 500;
616 cfg_.rc_buf_sz = 1000;
617 cfg_.rc_min_quantizer = 0;
618 cfg_.rc_max_quantizer = 63;
620 cfg_.rc_dropframe_thresh = 30;
621 cfg_.kf_max_dist = 9999;
622 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
625 top_sl_height_ = 480;
626 cfg_.rc_target_bitrate = 100;
628 AssignLayerBitrates();
629 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
630 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
632 #if CONFIG_VP9_DECODER
633 // The non-reference frames are expected to be mismatched frames as the
634 // encoder will avoid loopfilter on these frames.
635 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
639 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
640 // 2 temporal layers, with a change on the fly from the fixed SVC pattern to one
641 // generate via SVC_SET_REF_FRAME_CONFIG. The new pattern also disables
642 // inter-layer prediction.
643 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL2TLDynamicPatternChange) {
645 cfg_.rc_buf_initial_sz = 500;
646 cfg_.rc_buf_optimal_sz = 500;
647 cfg_.rc_buf_sz = 1000;
648 cfg_.rc_min_quantizer = 0;
649 cfg_.rc_max_quantizer = 63;
651 cfg_.rc_dropframe_thresh = 30;
652 cfg_.kf_max_dist = 9999;
653 // Change SVC pattern on the fly.
655 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
658 top_sl_height_ = 480;
659 cfg_.rc_target_bitrate = 800;
661 AssignLayerBitrates();
662 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
663 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
665 #if CONFIG_VP9_DECODER
666 // The non-reference frames are expected to be mismatched frames as the
667 // encoder will avoid loopfilter on these frames.
668 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
672 // Check basic rate targeting for 1 pass CBR SVC with 3 spatial and 3 temporal
673 // layers, for inter_layer_pred=OffKey (K-SVC) and on the fly switching
674 // of denoiser from off to on (on at frame = 100). Key frame period is set to
675 // 1000 so denoise is enabled on non-key.
676 TEST_P(DatarateOnePassCbrSvcSingleBR,
677 OnePassCbrSvc3SL3TL_DenoiserOffOnFixedLayers) {
679 cfg_.rc_buf_initial_sz = 500;
680 cfg_.rc_buf_optimal_sz = 500;
681 cfg_.rc_buf_sz = 1000;
682 cfg_.rc_min_quantizer = 0;
683 cfg_.rc_max_quantizer = 63;
685 cfg_.rc_dropframe_thresh = 30;
686 cfg_.kf_max_dist = 1000;
687 ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", 1280,
689 top_sl_width_ = 1280;
690 top_sl_height_ = 720;
691 cfg_.rc_target_bitrate = 1000;
693 denoiser_off_on_ = true;
694 denoiser_enable_layers_ = false;
695 AssignLayerBitrates();
696 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
697 // Don't check rate targeting on two top spatial layer since they will be
698 // skipped for part of the sequence.
699 CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
701 #if CONFIG_VP9_DECODER
702 // The non-reference frames are expected to be mismatched frames as the
703 // encoder will avoid loopfilter on these frames.
704 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
708 // Check basic rate targeting for 1 pass CBR SVC with 3 spatial and 3 temporal
709 // layers, for inter_layer_pred=OffKey (K-SVC) and on the fly switching
710 // of denoiser from off to on, for dynamic layers. Start at 2 spatial layers
711 // and enable 3rd spatial layer at frame = 100. Use periodic key frame with
712 // period 100 so enabling of spatial layer occurs at key frame. Enable denoiser
713 // at frame > 100, after the key frame sync.
714 TEST_P(DatarateOnePassCbrSvcSingleBR,
715 OnePassCbrSvc3SL3TL_DenoiserOffOnEnableLayers) {
717 cfg_.rc_buf_initial_sz = 500;
718 cfg_.rc_buf_optimal_sz = 500;
719 cfg_.rc_buf_sz = 1000;
720 cfg_.rc_min_quantizer = 0;
721 cfg_.rc_max_quantizer = 63;
723 cfg_.rc_dropframe_thresh = 0;
724 cfg_.kf_max_dist = 100;
725 ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", 1280,
727 top_sl_width_ = 1280;
728 top_sl_height_ = 720;
729 cfg_.rc_target_bitrate = 1000;
731 denoiser_off_on_ = true;
732 denoiser_enable_layers_ = true;
733 AssignLayerBitrates();
734 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
735 // Don't check rate targeting on two top spatial layer since they will be
736 // skipped for part of the sequence.
737 CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
739 #if CONFIG_VP9_DECODER
740 // The non-reference frames are expected to be mismatched frames as the
741 // encoder will avoid loopfilter on these frames.
742 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
746 // Check basic rate targeting for 1 pass CBR SVC with 3 spatial layers and on
747 // the fly switching to 1 and then 2 and back to 3 spatial layers. This switch
748 // is done by setting spatial layer bitrates to 0, and then back to non-zero,
749 // during the sequence.
750 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL_DisableEnableLayers) {
752 cfg_.rc_buf_initial_sz = 500;
753 cfg_.rc_buf_optimal_sz = 500;
754 cfg_.rc_buf_sz = 1000;
755 cfg_.rc_min_quantizer = 0;
756 cfg_.rc_max_quantizer = 63;
758 cfg_.temporal_layering_mode = 0;
759 cfg_.rc_dropframe_thresh = 30;
760 cfg_.kf_max_dist = 9999;
761 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
764 top_sl_height_ = 480;
765 cfg_.rc_target_bitrate = 800;
767 dynamic_drop_layer_ = true;
768 AssignLayerBitrates();
769 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
770 // Don't check rate targeting on two top spatial layer since they will be
771 // skipped for part of the sequence.
772 CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
774 #if CONFIG_VP9_DECODER
775 // The non-reference frames are expected to be mismatched frames as the
776 // encoder will avoid loopfilter on these frames.
777 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
781 // Run SVC encoder for 1 temporal layer, 2 spatial layers, with spatial
783 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL1TL5x5MultipleRuns) {
784 cfg_.rc_buf_initial_sz = 500;
785 cfg_.rc_buf_optimal_sz = 500;
786 cfg_.rc_buf_sz = 1000;
787 cfg_.rc_min_quantizer = 0;
788 cfg_.rc_max_quantizer = 63;
789 cfg_.rc_end_usage = VPX_CBR;
790 cfg_.g_lag_in_frames = 0;
791 cfg_.ss_number_layers = 2;
792 cfg_.ts_number_layers = 1;
793 cfg_.ts_rate_decimator[0] = 1;
794 cfg_.g_error_resilient = 1;
796 cfg_.temporal_layering_mode = 0;
797 svc_params_.scaling_factor_num[0] = 256;
798 svc_params_.scaling_factor_den[0] = 1280;
799 svc_params_.scaling_factor_num[1] = 1280;
800 svc_params_.scaling_factor_den[1] = 1280;
801 cfg_.rc_dropframe_thresh = 10;
802 cfg_.kf_max_dist = 999999;
803 cfg_.kf_min_dist = 0;
804 cfg_.ss_target_bitrate[0] = 300;
805 cfg_.ss_target_bitrate[1] = 1400;
806 cfg_.layer_target_bitrate[0] = 300;
807 cfg_.layer_target_bitrate[1] = 1400;
808 cfg_.rc_target_bitrate = 1700;
809 number_spatial_layers_ = cfg_.ss_number_layers;
810 number_temporal_layers_ = cfg_.ts_number_layers;
812 layer_target_avg_bandwidth_[0] = cfg_.layer_target_bitrate[0] * 1000 / 30;
813 bits_in_buffer_model_[0] =
814 cfg_.layer_target_bitrate[0] * cfg_.rc_buf_initial_sz;
815 layer_target_avg_bandwidth_[1] = cfg_.layer_target_bitrate[1] * 1000 / 30;
816 bits_in_buffer_model_[1] =
817 cfg_.layer_target_bitrate[1] * cfg_.rc_buf_initial_sz;
818 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
819 top_sl_width_ = 1280;
820 top_sl_height_ = 720;
821 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
822 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
824 #if CONFIG_VP9_DECODER
825 // The non-reference frames are expected to be mismatched frames as the
826 // encoder will avoid loopfilter on these frames.
827 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
831 // Params: speed setting and index for bitrate array.
832 class DatarateOnePassCbrSvcMultiBR
833 : public DatarateOnePassCbrSvc,
834 public ::libvpx_test::CodecTestWith2Params<int, int> {
836 DatarateOnePassCbrSvcMultiBR() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
837 memset(&svc_params_, 0, sizeof(svc_params_));
839 virtual ~DatarateOnePassCbrSvcMultiBR() {}
842 virtual void SetUp() {
844 SetMode(::libvpx_test::kRealTime);
845 speed_setting_ = GET_PARAM(1);
850 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and
851 // 3 temporal layers. Run CIF clip with 1 thread.
852 TEST_P(DatarateOnePassCbrSvcMultiBR, OnePassCbrSvc2SL3TL) {
854 cfg_.rc_buf_initial_sz = 500;
855 cfg_.rc_buf_optimal_sz = 500;
856 cfg_.rc_buf_sz = 1000;
857 cfg_.rc_min_quantizer = 0;
858 cfg_.rc_max_quantizer = 63;
860 cfg_.rc_dropframe_thresh = 30;
861 cfg_.kf_max_dist = 9999;
862 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
865 top_sl_height_ = 480;
866 const int bitrates[3] = { 200, 400, 600 };
867 // TODO(marpan): Check that effective_datarate for each layer hits the
868 // layer target_bitrate.
869 cfg_.rc_target_bitrate = bitrates[GET_PARAM(2)];
871 AssignLayerBitrates();
872 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
873 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.75,
875 #if CONFIG_VP9_DECODER
876 // The non-reference frames are expected to be mismatched frames as the
877 // encoder will avoid loopfilter on these frames.
878 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
882 // Params: speed setting, layer framedrop control and index for bitrate array.
883 class DatarateOnePassCbrSvcFrameDropMultiBR
884 : public DatarateOnePassCbrSvc,
885 public ::libvpx_test::CodecTestWith3Params<int, int, int> {
887 DatarateOnePassCbrSvcFrameDropMultiBR()
888 : DatarateOnePassCbrSvc(GET_PARAM(0)) {
889 memset(&svc_params_, 0, sizeof(svc_params_));
891 virtual ~DatarateOnePassCbrSvcFrameDropMultiBR() {}
894 virtual void SetUp() {
896 SetMode(::libvpx_test::kRealTime);
897 speed_setting_ = GET_PARAM(1);
902 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and
903 // 3 temporal layers. Run HD clip with 4 threads.
904 TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, OnePassCbrSvc2SL3TL4Threads) {
906 cfg_.rc_buf_initial_sz = 500;
907 cfg_.rc_buf_optimal_sz = 500;
908 cfg_.rc_buf_sz = 1000;
909 cfg_.rc_min_quantizer = 0;
910 cfg_.rc_max_quantizer = 63;
912 cfg_.rc_dropframe_thresh = 30;
913 cfg_.kf_max_dist = 9999;
914 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
915 top_sl_width_ = 1280;
916 top_sl_height_ = 720;
917 layer_framedrop_ = 0;
918 const int bitrates[3] = { 200, 400, 600 };
919 cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
921 layer_framedrop_ = GET_PARAM(2);
922 AssignLayerBitrates();
923 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
924 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.65,
926 #if CONFIG_VP9_DECODER
927 // The non-reference frames are expected to be mismatched frames as the
928 // encoder will avoid loopfilter on these frames.
929 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
933 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
934 // 3 temporal layers. Run HD clip with 4 threads.
935 TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, OnePassCbrSvc3SL3TL4Threads) {
937 cfg_.rc_buf_initial_sz = 500;
938 cfg_.rc_buf_optimal_sz = 500;
939 cfg_.rc_buf_sz = 1000;
940 cfg_.rc_min_quantizer = 0;
941 cfg_.rc_max_quantizer = 63;
943 cfg_.rc_dropframe_thresh = 30;
944 cfg_.kf_max_dist = 9999;
945 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
946 top_sl_width_ = 1280;
947 top_sl_height_ = 720;
948 layer_framedrop_ = 0;
949 const int bitrates[3] = { 200, 400, 600 };
950 cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
952 layer_framedrop_ = GET_PARAM(2);
953 AssignLayerBitrates();
954 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
955 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.58,
957 #if CONFIG_VP9_DECODER
958 // The non-reference frames are expected to be mismatched frames as the
959 // encoder will avoid loopfilter on these frames.
960 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
964 // Params: speed setting, inter-layer prediction mode.
965 class DatarateOnePassCbrSvcInterLayerPredSingleBR
966 : public DatarateOnePassCbrSvc,
967 public ::libvpx_test::CodecTestWith2Params<int, int> {
969 DatarateOnePassCbrSvcInterLayerPredSingleBR()
970 : DatarateOnePassCbrSvc(GET_PARAM(0)) {
971 memset(&svc_params_, 0, sizeof(svc_params_));
973 virtual ~DatarateOnePassCbrSvcInterLayerPredSingleBR() {}
976 virtual void SetUp() {
978 SetMode(::libvpx_test::kRealTime);
979 speed_setting_ = GET_PARAM(1);
980 inter_layer_pred_mode_ = GET_PARAM(2);
985 // Check basic rate targeting with different inter-layer prediction modes for 1
986 // pass CBR SVC: 3 spatial layers and 3 temporal layers. Run CIF clip with 1
988 TEST_P(DatarateOnePassCbrSvcInterLayerPredSingleBR, OnePassCbrSvc3SL3TL) {
990 cfg_.rc_buf_initial_sz = 500;
991 cfg_.rc_buf_optimal_sz = 500;
992 cfg_.rc_buf_sz = 1000;
993 cfg_.rc_min_quantizer = 0;
994 cfg_.rc_max_quantizer = 63;
996 cfg_.temporal_layering_mode = 3;
997 cfg_.rc_dropframe_thresh = 30;
998 cfg_.kf_max_dist = 9999;
999 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1001 top_sl_width_ = 640;
1002 top_sl_height_ = 480;
1003 cfg_.rc_target_bitrate = 800;
1005 AssignLayerBitrates();
1006 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1007 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1009 #if CONFIG_VP9_DECODER
1010 // The non-reference frames are expected to be mismatched frames as the
1011 // encoder will avoid loopfilter on these frames.
1012 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1016 // Check rate targeting with different inter-layer prediction modes for 1 pass
1017 // CBR SVC: 3 spatial layers and 3 temporal layers, changing the target bitrate
1018 // at the middle of encoding.
1019 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLDynamicBitrateChange) {
1021 cfg_.rc_buf_initial_sz = 500;
1022 cfg_.rc_buf_optimal_sz = 500;
1023 cfg_.rc_buf_sz = 1000;
1024 cfg_.rc_min_quantizer = 0;
1025 cfg_.rc_max_quantizer = 63;
1027 cfg_.rc_dropframe_thresh = 30;
1028 cfg_.kf_max_dist = 9999;
1029 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1031 top_sl_width_ = 640;
1032 top_sl_height_ = 480;
1033 cfg_.rc_target_bitrate = 800;
1035 change_bitrate_ = true;
1036 AssignLayerBitrates();
1037 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1038 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1040 #if CONFIG_VP9_DECODER
1041 // The non-reference frames are expected to be mismatched frames as the
1042 // encoder will avoid loopfilter on these frames.
1043 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1047 #if CONFIG_VP9_TEMPORAL_DENOISING
1048 // Params: speed setting, noise sensitivity and index for bitrate array.
1049 class DatarateOnePassCbrSvcDenoiser
1050 : public DatarateOnePassCbrSvc,
1051 public ::libvpx_test::CodecTestWith3Params<int, int, int> {
1053 DatarateOnePassCbrSvcDenoiser() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
1054 memset(&svc_params_, 0, sizeof(svc_params_));
1056 virtual ~DatarateOnePassCbrSvcDenoiser() {}
1059 virtual void SetUp() {
1061 SetMode(::libvpx_test::kRealTime);
1062 speed_setting_ = GET_PARAM(1);
1067 // Check basic rate targeting for 1 pass CBR SVC with denoising.
1068 // 2 spatial layers and 3 temporal layer. Run HD clip with 2 threads.
1069 TEST_P(DatarateOnePassCbrSvcDenoiser, OnePassCbrSvc2SL3TLDenoiserOn) {
1071 cfg_.rc_buf_initial_sz = 500;
1072 cfg_.rc_buf_optimal_sz = 500;
1073 cfg_.rc_buf_sz = 1000;
1074 cfg_.rc_min_quantizer = 0;
1075 cfg_.rc_max_quantizer = 63;
1077 cfg_.rc_dropframe_thresh = 30;
1078 cfg_.kf_max_dist = 9999;
1079 number_spatial_layers_ = cfg_.ss_number_layers;
1080 number_temporal_layers_ = cfg_.ts_number_layers;
1081 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1083 top_sl_width_ = 640;
1084 top_sl_height_ = 480;
1085 const int bitrates[3] = { 600, 800, 1000 };
1086 // TODO(marpan): Check that effective_datarate for each layer hits the
1087 // layer target_bitrate.
1088 // For SVC, noise_sen = 1 means denoising only the top spatial layer
1089 // noise_sen = 2 means denoising the two top spatial layers.
1090 cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
1092 denoiser_on_ = GET_PARAM(2);
1093 AssignLayerBitrates();
1094 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1095 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1097 #if CONFIG_VP9_DECODER
1098 // The non-reference frames are expected to be mismatched frames as the
1099 // encoder will avoid loopfilter on these frames.
1100 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1105 // Params: speed setting, key frame dist.
1106 class DatarateOnePassCbrSvcSmallKF
1107 : public DatarateOnePassCbrSvc,
1108 public ::libvpx_test::CodecTestWith2Params<int, int> {
1110 DatarateOnePassCbrSvcSmallKF() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
1111 memset(&svc_params_, 0, sizeof(svc_params_));
1113 virtual ~DatarateOnePassCbrSvcSmallKF() {}
1116 virtual void SetUp() {
1118 SetMode(::libvpx_test::kRealTime);
1119 speed_setting_ = GET_PARAM(1);
1124 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3
1125 // temporal layers. Run CIF clip with 1 thread, and few short key frame periods.
1126 TEST_P(DatarateOnePassCbrSvcSmallKF, OnePassCbrSvc3SL3TLSmallKf) {
1128 cfg_.rc_buf_initial_sz = 500;
1129 cfg_.rc_buf_optimal_sz = 500;
1130 cfg_.rc_buf_sz = 1000;
1131 cfg_.rc_min_quantizer = 0;
1132 cfg_.rc_max_quantizer = 63;
1134 cfg_.rc_dropframe_thresh = 10;
1135 cfg_.rc_target_bitrate = 800;
1136 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1138 top_sl_width_ = 640;
1139 top_sl_height_ = 480;
1140 // For this 3 temporal layer case, pattern repeats every 4 frames, so choose
1141 // 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
1142 const int kf_dist = GET_PARAM(2);
1143 cfg_.kf_max_dist = kf_dist;
1144 key_frame_spacing_ = kf_dist;
1146 AssignLayerBitrates();
1147 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1148 // TODO(jianj): webm:1554
1149 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.70,
1151 #if CONFIG_VP9_DECODER
1152 // The non-reference frames are expected to be mismatched frames as the
1153 // encoder will avoid loopfilter on these frames.
1154 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1158 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 3
1159 // temporal layers. Run CIF clip with 1 thread, and few short key frame periods.
1160 TEST_P(DatarateOnePassCbrSvcSmallKF, OnePassCbrSvc2SL3TLSmallKf) {
1162 cfg_.rc_buf_initial_sz = 500;
1163 cfg_.rc_buf_optimal_sz = 500;
1164 cfg_.rc_buf_sz = 1000;
1165 cfg_.rc_min_quantizer = 0;
1166 cfg_.rc_max_quantizer = 63;
1168 cfg_.rc_dropframe_thresh = 10;
1169 cfg_.rc_target_bitrate = 400;
1170 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1172 top_sl_width_ = 640;
1173 top_sl_height_ = 480;
1174 // For this 3 temporal layer case, pattern repeats every 4 frames, so choose
1175 // 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
1176 const int kf_dist = GET_PARAM(2) + 32;
1177 cfg_.kf_max_dist = kf_dist;
1178 key_frame_spacing_ = kf_dist;
1180 AssignLayerBitrates();
1181 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1182 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1184 #if CONFIG_VP9_DECODER
1185 // The non-reference frames are expected to be mismatched frames as the
1186 // encoder will avoid loopfilter on these frames.
1187 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1191 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3
1192 // temporal layers. Run VGA clip with 1 thread, and place layer sync frames:
1193 // one at middle layer first, then another one for top layer, and another
1194 // insert for base spatial layer (which forces key frame).
1195 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLSyncFrames) {
1197 cfg_.rc_buf_initial_sz = 500;
1198 cfg_.rc_buf_optimal_sz = 500;
1199 cfg_.rc_buf_sz = 1000;
1200 cfg_.rc_min_quantizer = 0;
1201 cfg_.rc_max_quantizer = 63;
1203 cfg_.kf_max_dist = 9999;
1204 cfg_.rc_dropframe_thresh = 10;
1205 cfg_.rc_target_bitrate = 400;
1206 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1208 top_sl_width_ = 640;
1209 top_sl_height_ = 480;
1211 insert_layer_sync_ = 1;
1212 AssignLayerBitrates();
1213 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1214 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1216 #if CONFIG_VP9_DECODER
1217 // The non-reference frames are expected to be mismatched frames as the
1218 // encoder will avoid loopfilter on these frames.
1219 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1223 // Run SVC encoder for 3 spatial layers, 1 temporal layer, with
1224 // intra-only frame as sync frame on base spatial layer.
1225 // Intra_only is inserted at start and in middle of sequence.
1226 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL1TLSyncWithIntraOnly) {
1228 cfg_.rc_buf_initial_sz = 500;
1229 cfg_.rc_buf_optimal_sz = 500;
1230 cfg_.rc_buf_sz = 1000;
1231 cfg_.rc_min_quantizer = 0;
1232 cfg_.rc_max_quantizer = 63;
1234 cfg_.rc_dropframe_thresh = 30;
1235 cfg_.kf_max_dist = 9999;
1236 cfg_.rc_target_bitrate = 400;
1237 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1239 top_sl_width_ = 640;
1240 top_sl_height_ = 480;
1242 insert_layer_sync_ = 1;
1243 // Use intra_only frame for sync on base layer.
1244 force_intra_only_frame_ = 1;
1245 AssignLayerBitrates();
1246 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1247 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
1249 #if CONFIG_VP9_DECODER
1250 // The non-reference frames are expected to be mismatched frames as the
1251 // encoder will avoid loopfilter on these frames.
1252 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1256 // Run SVC encoder for 2 quality layers (same resolution different,
1257 // bitrates), 1 temporal layer, with screen content mode.
1258 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2QL1TLScreen) {
1259 cfg_.rc_buf_initial_sz = 500;
1260 cfg_.rc_buf_optimal_sz = 500;
1261 cfg_.rc_buf_sz = 1000;
1262 cfg_.rc_min_quantizer = 0;
1263 cfg_.rc_max_quantizer = 56;
1264 cfg_.rc_end_usage = VPX_CBR;
1265 cfg_.g_lag_in_frames = 0;
1266 cfg_.ss_number_layers = 2;
1267 cfg_.ts_number_layers = 1;
1268 cfg_.ts_rate_decimator[0] = 1;
1269 cfg_.temporal_layering_mode = 0;
1270 cfg_.g_error_resilient = 1;
1272 svc_params_.scaling_factor_num[0] = 1;
1273 svc_params_.scaling_factor_den[0] = 1;
1274 svc_params_.scaling_factor_num[1] = 1;
1275 svc_params_.scaling_factor_den[1] = 1;
1276 cfg_.rc_dropframe_thresh = 30;
1277 cfg_.kf_max_dist = 9999;
1278 number_spatial_layers_ = cfg_.ss_number_layers;
1279 number_temporal_layers_ = cfg_.ts_number_layers;
1280 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1282 top_sl_width_ = 640;
1283 top_sl_height_ = 480;
1286 // Set the layer bitrates, for 2 spatial layers, 1 temporal.
1287 cfg_.rc_target_bitrate = 400;
1288 cfg_.ss_target_bitrate[0] = 100;
1289 cfg_.ss_target_bitrate[1] = 300;
1290 cfg_.layer_target_bitrate[0] = 100;
1291 cfg_.layer_target_bitrate[1] = 300;
1292 for (int sl = 0; sl < 2; ++sl) {
1293 float layer_framerate = 30.0;
1294 layer_target_avg_bandwidth_[sl] = static_cast<int>(
1295 cfg_.layer_target_bitrate[sl] * 1000.0 / layer_framerate);
1296 bits_in_buffer_model_[sl] =
1297 cfg_.layer_target_bitrate[sl] * cfg_.rc_buf_initial_sz;
1299 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1300 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
1302 #if CONFIG_VP9_DECODER
1303 // The non-reference frames are expected to be mismatched frames as the
1304 // encoder will avoid loopfilter on these frames.
1305 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1309 // Params: speed setting.
1310 class DatarateOnePassCbrSvcPostencodeDrop
1311 : public DatarateOnePassCbrSvc,
1312 public ::libvpx_test::CodecTestWithParam<int> {
1314 DatarateOnePassCbrSvcPostencodeDrop() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
1315 memset(&svc_params_, 0, sizeof(svc_params_));
1317 virtual ~DatarateOnePassCbrSvcPostencodeDrop() {}
1320 virtual void SetUp() {
1322 SetMode(::libvpx_test::kRealTime);
1323 speed_setting_ = GET_PARAM(1);
1328 // Run SVC encoder for 2 quality layers (same resolution different,
1329 // bitrates), 1 temporal layer, with screen content mode.
1330 TEST_P(DatarateOnePassCbrSvcPostencodeDrop, OnePassCbrSvc2QL1TLScreen) {
1331 cfg_.rc_buf_initial_sz = 200;
1332 cfg_.rc_buf_optimal_sz = 200;
1333 cfg_.rc_buf_sz = 400;
1334 cfg_.rc_min_quantizer = 0;
1335 cfg_.rc_max_quantizer = 52;
1336 cfg_.rc_end_usage = VPX_CBR;
1337 cfg_.g_lag_in_frames = 0;
1338 cfg_.ss_number_layers = 2;
1339 cfg_.ts_number_layers = 1;
1340 cfg_.ts_rate_decimator[0] = 1;
1341 cfg_.temporal_layering_mode = 0;
1342 cfg_.g_error_resilient = 1;
1344 svc_params_.scaling_factor_num[0] = 1;
1345 svc_params_.scaling_factor_den[0] = 1;
1346 svc_params_.scaling_factor_num[1] = 1;
1347 svc_params_.scaling_factor_den[1] = 1;
1348 cfg_.rc_dropframe_thresh = 30;
1349 cfg_.kf_max_dist = 9999;
1350 number_spatial_layers_ = cfg_.ss_number_layers;
1351 number_temporal_layers_ = cfg_.ts_number_layers;
1352 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
1354 top_sl_width_ = 352;
1355 top_sl_height_ = 288;
1357 base_speed_setting_ = speed_setting_;
1359 use_post_encode_drop_ = 1;
1360 // Set the layer bitrates, for 2 spatial layers, 1 temporal.
1361 cfg_.rc_target_bitrate = 400;
1362 cfg_.ss_target_bitrate[0] = 100;
1363 cfg_.ss_target_bitrate[1] = 300;
1364 cfg_.layer_target_bitrate[0] = 100;
1365 cfg_.layer_target_bitrate[1] = 300;
1366 for (int sl = 0; sl < 2; ++sl) {
1367 float layer_framerate = 30.0;
1368 layer_target_avg_bandwidth_[sl] = static_cast<int>(
1369 cfg_.layer_target_bitrate[sl] * 1000.0 / layer_framerate);
1370 bits_in_buffer_model_[sl] =
1371 cfg_.layer_target_bitrate[sl] * cfg_.rc_buf_initial_sz;
1373 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1374 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
1376 #if CONFIG_VP9_DECODER
1377 // The non-reference frames are expected to be mismatched frames as the
1378 // encoder will avoid loopfilter on these frames.
1379 EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
1383 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcSingleBR,
1384 ::testing::Range(5, 10));
1386 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcPostencodeDrop,
1387 ::testing::Range(4, 5));
1389 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcInterLayerPredSingleBR,
1390 ::testing::Range(5, 10), ::testing::Range(0, 3));
1392 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcMultiBR, ::testing::Range(5, 10),
1393 ::testing::Range(0, 3));
1395 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcFrameDropMultiBR,
1396 ::testing::Range(5, 10), ::testing::Range(0, 2),
1397 ::testing::Range(0, 3));
1399 #if CONFIG_VP9_TEMPORAL_DENOISING
1400 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcDenoiser,
1401 ::testing::Range(5, 10), ::testing::Range(1, 3),
1402 ::testing::Range(0, 3));
1405 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcSmallKF, ::testing::Range(5, 10),
1406 ::testing::Range(32, 36));