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"
25 class DatarateOnePassCbrSvc : public OnePassCbrSvc {
27 explicit DatarateOnePassCbrSvc(const ::libvpx_test::CodecFactory *codec)
28 : OnePassCbrSvc(codec) {
29 inter_layer_pred_mode_ = 0;
33 virtual ~DatarateOnePassCbrSvc() {}
35 virtual void ResetModel() {
39 mismatch_nframes_ = 0;
42 base_speed_setting_ = 5;
43 spatial_layer_id_ = 0;
44 temporal_layer_id_ = 0;
46 memset(bits_in_buffer_model_, 0, sizeof(bits_in_buffer_model_));
47 memset(bits_total_, 0, sizeof(bits_total_));
48 memset(layer_target_avg_bandwidth_, 0, sizeof(layer_target_avg_bandwidth_));
49 dynamic_drop_layer_ = false;
50 change_bitrate_ = false;
54 superframe_count_ = -1;
55 key_frame_spacing_ = 9999;
56 num_nonref_frames_ = 0;
60 insert_layer_sync_ = 0;
61 layer_sync_on_base_ = 0;
62 force_intra_only_frame_ = 0;
63 superframe_has_intra_only_ = 0;
64 use_post_encode_drop_ = 0;
65 denoiser_off_on_ = false;
66 denoiser_enable_layers_ = false;
68 virtual void BeginPassHook(unsigned int /*pass*/) {}
70 // Example pattern for spatial layers and 2 temporal layers used in the
71 // bypass/flexible mode. The pattern corresponds to the pattern
72 // VP9E_TEMPORAL_LAYERING_MODE_0101 (temporal_layering_mode == 2) used in
73 // non-flexible mode, except that we disable inter-layer prediction.
74 void set_frame_flags_bypass_mode(
75 int tl, int num_spatial_layers, int is_key_frame,
76 vpx_svc_ref_frame_config_t *ref_frame_config) {
77 for (int sl = 0; sl < num_spatial_layers; ++sl)
78 ref_frame_config->update_buffer_slot[sl] = 0;
80 for (int sl = 0; sl < num_spatial_layers; ++sl) {
82 ref_frame_config->lst_fb_idx[sl] = sl;
85 ref_frame_config->lst_fb_idx[sl] = sl - 1;
86 ref_frame_config->gld_fb_idx[sl] = sl;
88 ref_frame_config->gld_fb_idx[sl] = sl - 1;
91 ref_frame_config->gld_fb_idx[sl] = 0;
93 ref_frame_config->alt_fb_idx[sl] = 0;
95 ref_frame_config->lst_fb_idx[sl] = sl;
96 ref_frame_config->gld_fb_idx[sl] =
97 VPXMIN(REF_FRAMES - 1, num_spatial_layers + sl - 1);
98 ref_frame_config->alt_fb_idx[sl] =
99 VPXMIN(REF_FRAMES - 1, num_spatial_layers + sl);
103 ref_frame_config->reference_last[sl] = 1;
104 ref_frame_config->reference_golden[sl] = 0;
105 ref_frame_config->reference_alt_ref[sl] = 0;
106 ref_frame_config->update_buffer_slot[sl] |=
107 1 << ref_frame_config->lst_fb_idx[sl];
110 ref_frame_config->reference_last[sl] = 1;
111 ref_frame_config->reference_golden[sl] = 0;
112 ref_frame_config->reference_alt_ref[sl] = 0;
113 ref_frame_config->update_buffer_slot[sl] |=
114 1 << ref_frame_config->gld_fb_idx[sl];
116 ref_frame_config->reference_last[sl] = 1;
117 ref_frame_config->reference_golden[sl] = 0;
118 ref_frame_config->reference_alt_ref[sl] = 0;
119 ref_frame_config->update_buffer_slot[sl] |=
120 1 << ref_frame_config->lst_fb_idx[sl];
123 } else if (tl == 1) {
125 ref_frame_config->reference_last[sl] = 1;
126 ref_frame_config->reference_golden[sl] = 0;
127 ref_frame_config->reference_alt_ref[sl] = 0;
128 ref_frame_config->update_buffer_slot[sl] |=
129 1 << ref_frame_config->alt_fb_idx[sl];
131 ref_frame_config->reference_last[sl] = 1;
132 ref_frame_config->reference_golden[sl] = 0;
133 ref_frame_config->reference_alt_ref[sl] = 0;
134 ref_frame_config->update_buffer_slot[sl] |=
135 1 << ref_frame_config->alt_fb_idx[sl];
141 void CheckLayerRateTargeting(int num_spatial_layers, int num_temporal_layers,
142 double thresh_overshoot,
143 double thresh_undershoot) const {
144 for (int sl = 0; sl < num_spatial_layers; ++sl)
145 for (int tl = 0; tl < num_temporal_layers; ++tl) {
146 const int layer = sl * num_temporal_layers + tl;
147 ASSERT_GE(cfg_.layer_target_bitrate[layer],
148 file_datarate_[layer] * thresh_overshoot)
149 << " The datarate for the file exceeds the target by too much!";
150 ASSERT_LE(cfg_.layer_target_bitrate[layer],
151 file_datarate_[layer] * thresh_undershoot)
152 << " The datarate for the file is lower than the target by too "
157 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
158 ::libvpx_test::Encoder *encoder) {
159 PreEncodeFrameHookSetup(video, encoder);
161 if (video->frame() == 0) {
162 if (force_intra_only_frame_) {
163 // Decoder sets the color_space for Intra-only frames
164 // to BT_601 (see line 1810 in vp9_decodeframe.c).
165 // So set it here in these tess to avoid encoder-decoder
166 // mismatch check on color space setting.
167 encoder->Control(VP9E_SET_COLOR_SPACE, VPX_CS_BT_601);
169 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_);
170 encoder->Control(VP9E_SET_TUNE_CONTENT, tune_content_);
171 encoder->Control(VP9E_SET_SVC_INTER_LAYER_PRED, inter_layer_pred_mode_);
173 if (layer_framedrop_) {
174 vpx_svc_frame_drop_t svc_drop_frame;
175 svc_drop_frame.framedrop_mode = LAYER_DROP;
176 for (int i = 0; i < number_spatial_layers_; i++)
177 svc_drop_frame.framedrop_thresh[i] = 30;
178 svc_drop_frame.max_consec_drop = 30;
179 encoder->Control(VP9E_SET_SVC_FRAME_DROP_LAYER, &svc_drop_frame);
182 if (use_post_encode_drop_) {
183 encoder->Control(VP9E_SET_POSTENCODE_DROP, use_post_encode_drop_);
187 if (denoiser_off_on_) {
188 encoder->Control(VP9E_SET_AQ_MODE, 3);
189 // Set inter_layer_pred to INTER_LAYER_PRED_OFF_NONKEY (K-SVC).
190 encoder->Control(VP9E_SET_SVC_INTER_LAYER_PRED, 2);
191 if (!denoiser_enable_layers_) {
192 if (video->frame() == 0)
193 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 0);
194 else if (video->frame() == 100)
195 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 1);
197 // Cumulative bitrates for top spatial layers, for
198 // 3 temporal layers.
199 if (video->frame() == 0) {
200 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 0);
201 // Change layer bitrates to set top spatial layer to 0.
202 // This is for 3 spatial 3 temporal layers.
203 // This will trigger skip encoding/dropping of top spatial layer.
204 cfg_.rc_target_bitrate -= cfg_.layer_target_bitrate[8];
205 for (int i = 0; i < 3; i++)
206 bitrate_sl3_[i] = cfg_.layer_target_bitrate[i + 6];
207 cfg_.layer_target_bitrate[6] = 0;
208 cfg_.layer_target_bitrate[7] = 0;
209 cfg_.layer_target_bitrate[8] = 0;
210 encoder->Config(&cfg_);
211 } else if (video->frame() == 100) {
212 // Change layer bitrates to non-zero on top spatial layer.
213 // This will trigger skip encoding of top spatial layer
214 // on key frame (period = 100).
215 for (int i = 0; i < 3; i++)
216 cfg_.layer_target_bitrate[i + 6] = bitrate_sl3_[i];
217 cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[8];
218 encoder->Config(&cfg_);
219 } else if (video->frame() == 120) {
220 // Enable denoiser and top spatial layer after key frame (period is
222 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 1);
227 if (update_pattern_ && video->frame() >= 100) {
228 vpx_svc_layer_id_t layer_id;
229 if (video->frame() == 100) {
230 cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS;
231 encoder->Config(&cfg_);
233 // Set layer id since the pattern changed.
234 layer_id.spatial_layer_id = 0;
235 layer_id.temporal_layer_id = (video->frame() % 2 != 0);
236 temporal_layer_id_ = layer_id.temporal_layer_id;
237 for (int i = 0; i < number_spatial_layers_; i++)
238 layer_id.temporal_layer_id_per_spatial[i] = temporal_layer_id_;
239 encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id);
240 set_frame_flags_bypass_mode(layer_id.temporal_layer_id,
241 number_spatial_layers_, 0, &ref_frame_config);
242 encoder->Control(VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config);
245 if (change_bitrate_ && video->frame() == 200) {
246 duration_ = (last_pts_ + 1) * timebase_;
247 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
248 for (int tl = 0; tl < number_temporal_layers_; ++tl) {
249 const int layer = sl * number_temporal_layers_ + tl;
250 const double file_size_in_kb = bits_total_[layer] / 1000.;
251 file_datarate_[layer] = file_size_in_kb / duration_;
255 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_,
258 memset(file_datarate_, 0, sizeof(file_datarate_));
259 memset(bits_total_, 0, sizeof(bits_total_));
260 int64_t bits_in_buffer_model_tmp[VPX_MAX_LAYERS];
261 last_pts_ref_ = last_pts_;
262 // Set new target bitarate.
263 cfg_.rc_target_bitrate = cfg_.rc_target_bitrate >> 1;
264 // Buffer level should not reset on dynamic bitrate change.
265 memcpy(bits_in_buffer_model_tmp, bits_in_buffer_model_,
266 sizeof(bits_in_buffer_model_));
267 AssignLayerBitrates();
268 memcpy(bits_in_buffer_model_, bits_in_buffer_model_tmp,
269 sizeof(bits_in_buffer_model_));
271 // Change config to update encoder with new bitrate configuration.
272 encoder->Config(&cfg_);
275 if (dynamic_drop_layer_) {
276 // TODO(jian): Disable AQ Mode for this test for now.
277 encoder->Control(VP9E_SET_AQ_MODE, 0);
278 if (video->frame() == 0) {
279 // Change layer bitrates to set top layers to 0. This will trigger skip
280 // encoding/dropping of top two spatial layers.
281 cfg_.rc_target_bitrate -=
282 (cfg_.layer_target_bitrate[1] + cfg_.layer_target_bitrate[2]);
283 middle_bitrate_ = cfg_.layer_target_bitrate[1];
284 top_bitrate_ = cfg_.layer_target_bitrate[2];
285 cfg_.layer_target_bitrate[1] = 0;
286 cfg_.layer_target_bitrate[2] = 0;
287 encoder->Config(&cfg_);
288 } else if (video->frame() == 50) {
289 // Change layer bitrates to non-zero on two top spatial layers.
290 // This will trigger skip encoding of top two spatial layers.
291 cfg_.layer_target_bitrate[1] = middle_bitrate_;
292 cfg_.layer_target_bitrate[2] = top_bitrate_;
293 cfg_.rc_target_bitrate +=
294 cfg_.layer_target_bitrate[2] + cfg_.layer_target_bitrate[1];
295 encoder->Config(&cfg_);
296 } else if (video->frame() == 100) {
297 // Change layer bitrates to set top layers to 0. This will trigger skip
298 // encoding/dropping of top two spatial layers.
299 cfg_.rc_target_bitrate -=
300 (cfg_.layer_target_bitrate[1] + cfg_.layer_target_bitrate[2]);
301 middle_bitrate_ = cfg_.layer_target_bitrate[1];
302 top_bitrate_ = cfg_.layer_target_bitrate[2];
303 cfg_.layer_target_bitrate[1] = 0;
304 cfg_.layer_target_bitrate[2] = 0;
305 encoder->Config(&cfg_);
306 } else if (video->frame() == 150) {
307 // Change layer bitrate on second layer to non-zero to start
308 // encoding it again.
309 cfg_.layer_target_bitrate[1] = middle_bitrate_;
310 cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[1];
311 encoder->Config(&cfg_);
312 } else if (video->frame() == 200) {
313 // Change layer bitrate on top layer to non-zero to start
314 // encoding it again.
315 cfg_.layer_target_bitrate[2] = top_bitrate_;
316 cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[2];
317 encoder->Config(&cfg_);
321 if (force_key_test_ && force_key_) frame_flags_ = VPX_EFLAG_FORCE_KF;
323 if (insert_layer_sync_) {
324 vpx_svc_spatial_layer_sync_t svc_layer_sync;
325 svc_layer_sync.base_layer_intra_only = 0;
326 for (int i = 0; i < number_spatial_layers_; i++)
327 svc_layer_sync.spatial_layer_sync[i] = 0;
328 if (force_intra_only_frame_) {
329 superframe_has_intra_only_ = 0;
330 if (video->frame() == 0) {
331 svc_layer_sync.base_layer_intra_only = 1;
332 svc_layer_sync.spatial_layer_sync[0] = 1;
333 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
334 superframe_has_intra_only_ = 1;
335 } else if (video->frame() == 100) {
336 svc_layer_sync.base_layer_intra_only = 1;
337 svc_layer_sync.spatial_layer_sync[0] = 1;
338 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
339 superframe_has_intra_only_ = 1;
342 layer_sync_on_base_ = 0;
343 if (video->frame() == 150) {
344 svc_layer_sync.spatial_layer_sync[1] = 1;
345 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
346 } else if (video->frame() == 240) {
347 svc_layer_sync.spatial_layer_sync[2] = 1;
348 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
349 } else if (video->frame() == 320) {
350 svc_layer_sync.spatial_layer_sync[0] = 1;
351 layer_sync_on_base_ = 1;
352 encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
357 const vpx_rational_t tb = video->timebase();
358 timebase_ = static_cast<double>(tb.num) / tb.den;
362 vpx_codec_err_t parse_superframe_index(const uint8_t *data, size_t data_sz,
363 uint32_t sizes[8], int *count) {
365 marker = *(data + data_sz - 1);
367 if ((marker & 0xe0) == 0xc0) {
368 const uint32_t frames = (marker & 0x7) + 1;
369 const uint32_t mag = ((marker >> 3) & 0x3) + 1;
370 const size_t index_sz = 2 + mag * frames;
371 // This chunk is marked as having a superframe index but doesn't have
372 // enough data for it, thus it's an invalid superframe index.
373 if (data_sz < index_sz) return VPX_CODEC_CORRUPT_FRAME;
375 const uint8_t marker2 = *(data + data_sz - index_sz);
376 // This chunk is marked as having a superframe index but doesn't have
377 // the matching marker byte at the front of the index therefore it's an
379 if (marker != marker2) return VPX_CODEC_CORRUPT_FRAME;
383 const uint8_t *x = &data[data_sz - index_sz + 1];
384 for (i = 0; i < frames; ++i) {
385 uint32_t this_sz = 0;
387 for (j = 0; j < mag; ++j) this_sz |= (*x++) << (j * 8);
396 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
397 uint32_t sizes[8] = { 0 };
398 uint32_t sizes_parsed[8] = { 0 };
400 int num_layers_encoded = 0;
401 last_pts_ = pkt->data.frame.pts;
402 const bool key_frame =
403 (pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
405 // For test that inserts layer sync frames: requesting a layer_sync on
406 // the base layer must force key frame. So if any key frame occurs after
407 // first superframe it must due to layer sync on base spatial layer.
408 if (superframe_count_ > 0 && insert_layer_sync_ &&
409 !force_intra_only_frame_) {
410 ASSERT_EQ(layer_sync_on_base_, 1);
412 temporal_layer_id_ = 0;
413 superframe_count_ = 0;
415 parse_superframe_index(static_cast<const uint8_t *>(pkt->data.frame.buf),
416 pkt->data.frame.sz, sizes_parsed, &count);
417 // Count may be less than number of spatial layers because of frame drops.
418 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
419 if (pkt->data.frame.spatial_layer_encoded[sl]) {
420 sizes[sl] = sizes_parsed[num_layers_encoded];
421 num_layers_encoded++;
424 // For superframe with Intra-only count will be +1 larger
425 // because of no-show frame.
426 if (force_intra_only_frame_ && superframe_has_intra_only_)
427 ASSERT_EQ(count, num_layers_encoded + 1);
429 ASSERT_EQ(count, num_layers_encoded);
431 // In the constrained frame drop mode, if a given spatial is dropped all
432 // upper layers must be dropped too.
433 if (!layer_framedrop_) {
434 int num_layers_dropped = 0;
435 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
436 if (!pkt->data.frame.spatial_layer_encoded[sl]) {
437 // Check that all upper layers are dropped.
438 num_layers_dropped++;
439 for (int sl2 = sl + 1; sl2 < number_spatial_layers_; ++sl2)
440 ASSERT_EQ(pkt->data.frame.spatial_layer_encoded[sl2], 0);
443 if (num_layers_dropped == number_spatial_layers_ - 1)
448 // Keep track of number of non-reference frames, needed for mismatch check.
449 // Non-reference frames are top spatial and temporal layer frames,
451 if (temporal_layer_id_ == number_temporal_layers_ - 1 &&
452 temporal_layer_id_ > 0 &&
453 pkt->data.frame.spatial_layer_encoded[number_spatial_layers_ - 1])
454 num_nonref_frames_++;
455 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
456 sizes[sl] = sizes[sl] << 3;
457 // Update the total encoded bits per layer.
458 // For temporal layers, update the cumulative encoded bits per layer.
459 for (int tl = temporal_layer_id_; tl < number_temporal_layers_; ++tl) {
460 const int layer = sl * number_temporal_layers_ + tl;
461 bits_total_[layer] += static_cast<int64_t>(sizes[sl]);
462 // Update the per-layer buffer level with the encoded frame size.
463 bits_in_buffer_model_[layer] -= static_cast<int64_t>(sizes[sl]);
464 // There should be no buffer underrun, except on the base
465 // temporal layer, since there may be key frames there.
466 // Fo short key frame spacing, buffer can underrun on individual frames.
467 if (!key_frame && tl > 0 && key_frame_spacing_ < 100) {
468 ASSERT_GE(bits_in_buffer_model_[layer], 0)
469 << "Buffer Underrun at frame " << pkt->data.frame.pts;
473 ASSERT_EQ(pkt->data.frame.width[sl],
474 top_sl_width_ * svc_params_.scaling_factor_num[sl] /
475 svc_params_.scaling_factor_den[sl]);
477 ASSERT_EQ(pkt->data.frame.height[sl],
478 top_sl_height_ * svc_params_.scaling_factor_num[sl] /
479 svc_params_.scaling_factor_den[sl]);
483 virtual void EndPassHook(void) {
484 if (change_bitrate_) last_pts_ = last_pts_ - last_pts_ref_;
485 duration_ = (last_pts_ + 1) * timebase_;
486 for (int sl = 0; sl < number_spatial_layers_; ++sl) {
487 for (int tl = 0; tl < number_temporal_layers_; ++tl) {
488 const int layer = sl * number_temporal_layers_ + tl;
489 const double file_size_in_kb = bits_total_[layer] / 1000.;
490 file_datarate_[layer] = file_size_in_kb / duration_;
495 virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) {
496 double mismatch_psnr = compute_psnr(img1, img2);
497 mismatch_psnr_ += mismatch_psnr;
501 unsigned int GetMismatchFrames() { return mismatch_nframes_; }
502 unsigned int GetNonRefFrames() { return num_nonref_frames_; }
504 vpx_codec_pts_t last_pts_;
506 int64_t bits_total_[VPX_MAX_LAYERS];
508 double file_datarate_[VPX_MAX_LAYERS];
509 size_t bits_in_last_frame_;
510 double mismatch_psnr_;
513 int spatial_layer_id_;
514 bool dynamic_drop_layer_;
515 unsigned int top_sl_width_;
516 unsigned int top_sl_height_;
517 vpx_svc_ref_frame_config_t ref_frame_config;
519 bool change_bitrate_;
520 vpx_codec_pts_t last_pts_ref_;
523 int key_frame_spacing_;
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;
559 unsigned int num_nonref_frames_;
560 unsigned int mismatch_nframes_;
563 // Params: speed setting.
564 class DatarateOnePassCbrSvcSingleBR
565 : public DatarateOnePassCbrSvc,
566 public ::libvpx_test::CodecTestWithParam<int> {
568 DatarateOnePassCbrSvcSingleBR() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
569 memset(&svc_params_, 0, sizeof(svc_params_));
571 virtual ~DatarateOnePassCbrSvcSingleBR() {}
574 virtual void SetUp() {
576 SetMode(::libvpx_test::kRealTime);
577 speed_setting_ = GET_PARAM(1);
582 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 1
583 // temporal layer, with screen content mode on and same speed setting for all
585 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL1TLScreenContent1) {
587 cfg_.rc_buf_initial_sz = 500;
588 cfg_.rc_buf_optimal_sz = 500;
589 cfg_.rc_buf_sz = 1000;
590 cfg_.rc_min_quantizer = 0;
591 cfg_.rc_max_quantizer = 63;
593 cfg_.rc_dropframe_thresh = 10;
594 cfg_.kf_max_dist = 9999;
596 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
597 top_sl_width_ = 1280;
598 top_sl_height_ = 720;
599 cfg_.rc_target_bitrate = 500;
602 AssignLayerBitrates();
603 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
604 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
606 #if CONFIG_VP9_DECODER
607 // The non-reference frames are expected to be mismatched frames as the
608 // encoder will avoid loopfilter on these frames.
609 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
613 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
614 // 3 temporal layers, with force key frame after frame drop
615 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLForceKey) {
617 cfg_.rc_buf_initial_sz = 500;
618 cfg_.rc_buf_optimal_sz = 500;
619 cfg_.rc_buf_sz = 1000;
620 cfg_.rc_min_quantizer = 0;
621 cfg_.rc_max_quantizer = 63;
623 cfg_.rc_dropframe_thresh = 30;
624 cfg_.kf_max_dist = 9999;
625 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
628 top_sl_height_ = 480;
629 cfg_.rc_target_bitrate = 100;
631 AssignLayerBitrates();
632 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
633 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
635 #if CONFIG_VP9_DECODER
636 // The non-reference frames are expected to be mismatched frames as the
637 // encoder will avoid loopfilter on these frames.
638 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
642 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
643 // 2 temporal layers, with a change on the fly from the fixed SVC pattern to one
644 // generate via SVC_SET_REF_FRAME_CONFIG. The new pattern also disables
645 // inter-layer prediction.
646 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL2TLDynamicPatternChange) {
648 cfg_.rc_buf_initial_sz = 500;
649 cfg_.rc_buf_optimal_sz = 500;
650 cfg_.rc_buf_sz = 1000;
651 cfg_.rc_min_quantizer = 0;
652 cfg_.rc_max_quantizer = 63;
654 cfg_.rc_dropframe_thresh = 30;
655 cfg_.kf_max_dist = 9999;
656 // Change SVC pattern on the fly.
658 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
661 top_sl_height_ = 480;
662 cfg_.rc_target_bitrate = 800;
664 AssignLayerBitrates();
665 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
666 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
668 #if CONFIG_VP9_DECODER
669 // The non-reference frames are expected to be mismatched frames as the
670 // encoder will avoid loopfilter on these frames.
671 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
675 // Check basic rate targeting for 1 pass CBR SVC with 3 spatial and 3 temporal
676 // layers, for inter_layer_pred=OffKey (K-SVC) and on the fly switching
677 // of denoiser from off to on (on at frame = 100). Key frame period is set to
678 // 1000 so denoise is enabled on non-key.
679 TEST_P(DatarateOnePassCbrSvcSingleBR,
680 OnePassCbrSvc3SL3TL_DenoiserOffOnFixedLayers) {
682 cfg_.rc_buf_initial_sz = 500;
683 cfg_.rc_buf_optimal_sz = 500;
684 cfg_.rc_buf_sz = 1000;
685 cfg_.rc_min_quantizer = 0;
686 cfg_.rc_max_quantizer = 63;
688 cfg_.rc_dropframe_thresh = 30;
689 cfg_.kf_max_dist = 1000;
690 ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", 1280,
692 top_sl_width_ = 1280;
693 top_sl_height_ = 720;
694 cfg_.rc_target_bitrate = 1000;
696 denoiser_off_on_ = true;
697 denoiser_enable_layers_ = false;
698 AssignLayerBitrates();
699 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
700 // Don't check rate targeting on two top spatial layer since they will be
701 // skipped for part of the sequence.
702 CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
704 #if CONFIG_VP9_DECODER
705 // The non-reference frames are expected to be mismatched frames as the
706 // encoder will avoid loopfilter on these frames.
707 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
711 // Check basic rate targeting for 1 pass CBR SVC with 3 spatial and 3 temporal
712 // layers, for inter_layer_pred=OffKey (K-SVC) and on the fly switching
713 // of denoiser from off to on, for dynamic layers. Start at 2 spatial layers
714 // and enable 3rd spatial layer at frame = 100. Use periodic key frame with
715 // period 100 so enabling of spatial layer occurs at key frame. Enable denoiser
716 // at frame > 100, after the key frame sync.
717 TEST_P(DatarateOnePassCbrSvcSingleBR,
718 OnePassCbrSvc3SL3TL_DenoiserOffOnEnableLayers) {
720 cfg_.rc_buf_initial_sz = 500;
721 cfg_.rc_buf_optimal_sz = 500;
722 cfg_.rc_buf_sz = 1000;
723 cfg_.rc_min_quantizer = 0;
724 cfg_.rc_max_quantizer = 63;
726 cfg_.rc_dropframe_thresh = 0;
727 cfg_.kf_max_dist = 100;
728 ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", 1280,
730 top_sl_width_ = 1280;
731 top_sl_height_ = 720;
732 cfg_.rc_target_bitrate = 1000;
734 denoiser_off_on_ = true;
735 denoiser_enable_layers_ = true;
736 AssignLayerBitrates();
737 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
738 // Don't check rate targeting on two top spatial layer since they will be
739 // skipped for part of the sequence.
740 CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
742 #if CONFIG_VP9_DECODER
743 // The non-reference frames are expected to be mismatched frames as the
744 // encoder will avoid loopfilter on these frames.
745 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
749 // Check basic rate targeting for 1 pass CBR SVC with 3 spatial layers and on
750 // the fly switching to 1 and then 2 and back to 3 spatial layers. This switch
751 // is done by setting spatial layer bitrates to 0, and then back to non-zero,
752 // during the sequence.
753 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL_DisableEnableLayers) {
755 cfg_.rc_buf_initial_sz = 500;
756 cfg_.rc_buf_optimal_sz = 500;
757 cfg_.rc_buf_sz = 1000;
758 cfg_.rc_min_quantizer = 0;
759 cfg_.rc_max_quantizer = 63;
761 cfg_.temporal_layering_mode = 0;
762 cfg_.rc_dropframe_thresh = 30;
763 cfg_.kf_max_dist = 9999;
764 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
767 top_sl_height_ = 480;
768 cfg_.rc_target_bitrate = 800;
770 dynamic_drop_layer_ = true;
771 AssignLayerBitrates();
772 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
773 // Don't check rate targeting on two top spatial layer since they will be
774 // skipped for part of the sequence.
775 CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
777 #if CONFIG_VP9_DECODER
778 // The non-reference frames are expected to be mismatched frames as the
779 // encoder will avoid loopfilter on these frames.
780 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
784 // Run SVC encoder for 1 temporal layer, 2 spatial layers, with spatial
786 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL1TL5x5MultipleRuns) {
787 cfg_.rc_buf_initial_sz = 500;
788 cfg_.rc_buf_optimal_sz = 500;
789 cfg_.rc_buf_sz = 1000;
790 cfg_.rc_min_quantizer = 0;
791 cfg_.rc_max_quantizer = 63;
792 cfg_.rc_end_usage = VPX_CBR;
793 cfg_.g_lag_in_frames = 0;
794 cfg_.ss_number_layers = 2;
795 cfg_.ts_number_layers = 1;
796 cfg_.ts_rate_decimator[0] = 1;
797 cfg_.g_error_resilient = 1;
799 cfg_.temporal_layering_mode = 0;
800 svc_params_.scaling_factor_num[0] = 256;
801 svc_params_.scaling_factor_den[0] = 1280;
802 svc_params_.scaling_factor_num[1] = 1280;
803 svc_params_.scaling_factor_den[1] = 1280;
804 cfg_.rc_dropframe_thresh = 10;
805 cfg_.kf_max_dist = 999999;
806 cfg_.kf_min_dist = 0;
807 cfg_.ss_target_bitrate[0] = 300;
808 cfg_.ss_target_bitrate[1] = 1400;
809 cfg_.layer_target_bitrate[0] = 300;
810 cfg_.layer_target_bitrate[1] = 1400;
811 cfg_.rc_target_bitrate = 1700;
812 number_spatial_layers_ = cfg_.ss_number_layers;
813 number_temporal_layers_ = cfg_.ts_number_layers;
815 layer_target_avg_bandwidth_[0] = cfg_.layer_target_bitrate[0] * 1000 / 30;
816 bits_in_buffer_model_[0] =
817 cfg_.layer_target_bitrate[0] * cfg_.rc_buf_initial_sz;
818 layer_target_avg_bandwidth_[1] = cfg_.layer_target_bitrate[1] * 1000 / 30;
819 bits_in_buffer_model_[1] =
820 cfg_.layer_target_bitrate[1] * cfg_.rc_buf_initial_sz;
821 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
822 top_sl_width_ = 1280;
823 top_sl_height_ = 720;
824 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
825 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
827 #if CONFIG_VP9_DECODER
828 // The non-reference frames are expected to be mismatched frames as the
829 // encoder will avoid loopfilter on these frames.
830 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
834 // Params: speed setting and index for bitrate array.
835 class DatarateOnePassCbrSvcMultiBR
836 : public DatarateOnePassCbrSvc,
837 public ::libvpx_test::CodecTestWith2Params<int, int> {
839 DatarateOnePassCbrSvcMultiBR() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
840 memset(&svc_params_, 0, sizeof(svc_params_));
842 virtual ~DatarateOnePassCbrSvcMultiBR() {}
845 virtual void SetUp() {
847 SetMode(::libvpx_test::kRealTime);
848 speed_setting_ = GET_PARAM(1);
853 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and
854 // 3 temporal layers. Run CIF clip with 1 thread.
855 TEST_P(DatarateOnePassCbrSvcMultiBR, OnePassCbrSvc2SL3TL) {
857 cfg_.rc_buf_initial_sz = 500;
858 cfg_.rc_buf_optimal_sz = 500;
859 cfg_.rc_buf_sz = 1000;
860 cfg_.rc_min_quantizer = 0;
861 cfg_.rc_max_quantizer = 63;
863 cfg_.rc_dropframe_thresh = 30;
864 cfg_.kf_max_dist = 9999;
865 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
868 top_sl_height_ = 480;
869 const int bitrates[3] = { 200, 400, 600 };
870 // TODO(marpan): Check that effective_datarate for each layer hits the
871 // layer target_bitrate.
872 cfg_.rc_target_bitrate = bitrates[GET_PARAM(2)];
874 AssignLayerBitrates();
875 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
876 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.75,
878 #if CONFIG_VP9_DECODER
879 // The non-reference frames are expected to be mismatched frames as the
880 // encoder will avoid loopfilter on these frames.
881 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
885 // Params: speed setting, layer framedrop control and index for bitrate array.
886 class DatarateOnePassCbrSvcFrameDropMultiBR
887 : public DatarateOnePassCbrSvc,
888 public ::libvpx_test::CodecTestWith3Params<int, int, int> {
890 DatarateOnePassCbrSvcFrameDropMultiBR()
891 : DatarateOnePassCbrSvc(GET_PARAM(0)) {
892 memset(&svc_params_, 0, sizeof(svc_params_));
894 virtual ~DatarateOnePassCbrSvcFrameDropMultiBR() {}
897 virtual void SetUp() {
899 SetMode(::libvpx_test::kRealTime);
900 speed_setting_ = GET_PARAM(1);
905 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and
906 // 3 temporal layers. Run HD clip with 4 threads.
907 TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, OnePassCbrSvc2SL3TL4Threads) {
909 cfg_.rc_buf_initial_sz = 500;
910 cfg_.rc_buf_optimal_sz = 500;
911 cfg_.rc_buf_sz = 1000;
912 cfg_.rc_min_quantizer = 0;
913 cfg_.rc_max_quantizer = 63;
915 cfg_.rc_dropframe_thresh = 30;
916 cfg_.kf_max_dist = 9999;
917 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
918 top_sl_width_ = 1280;
919 top_sl_height_ = 720;
920 layer_framedrop_ = 0;
921 const int bitrates[3] = { 200, 400, 600 };
922 cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
924 layer_framedrop_ = GET_PARAM(2);
925 AssignLayerBitrates();
926 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
927 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.65,
929 #if CONFIG_VP9_DECODER
930 // The non-reference frames are expected to be mismatched frames as the
931 // encoder will avoid loopfilter on these frames.
932 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
936 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
937 // 3 temporal layers. Run HD clip with 4 threads.
938 TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, OnePassCbrSvc3SL3TL4Threads) {
940 cfg_.rc_buf_initial_sz = 500;
941 cfg_.rc_buf_optimal_sz = 500;
942 cfg_.rc_buf_sz = 1000;
943 cfg_.rc_min_quantizer = 0;
944 cfg_.rc_max_quantizer = 63;
946 cfg_.rc_dropframe_thresh = 30;
947 cfg_.kf_max_dist = 9999;
948 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
949 top_sl_width_ = 1280;
950 top_sl_height_ = 720;
951 layer_framedrop_ = 0;
952 const int bitrates[3] = { 200, 400, 600 };
953 cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
955 layer_framedrop_ = GET_PARAM(2);
956 AssignLayerBitrates();
957 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
958 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.58,
960 #if CONFIG_VP9_DECODER
961 // The non-reference frames are expected to be mismatched frames as the
962 // encoder will avoid loopfilter on these frames.
963 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
967 // Params: speed setting, inter-layer prediction mode.
968 class DatarateOnePassCbrSvcInterLayerPredSingleBR
969 : public DatarateOnePassCbrSvc,
970 public ::libvpx_test::CodecTestWith2Params<int, int> {
972 DatarateOnePassCbrSvcInterLayerPredSingleBR()
973 : DatarateOnePassCbrSvc(GET_PARAM(0)) {
974 memset(&svc_params_, 0, sizeof(svc_params_));
976 virtual ~DatarateOnePassCbrSvcInterLayerPredSingleBR() {}
979 virtual void SetUp() {
981 SetMode(::libvpx_test::kRealTime);
982 speed_setting_ = GET_PARAM(1);
983 inter_layer_pred_mode_ = GET_PARAM(2);
988 // Check basic rate targeting with different inter-layer prediction modes for 1
989 // pass CBR SVC: 3 spatial layers and 3 temporal layers. Run CIF clip with 1
991 TEST_P(DatarateOnePassCbrSvcInterLayerPredSingleBR, OnePassCbrSvc3SL3TL) {
993 cfg_.rc_buf_initial_sz = 500;
994 cfg_.rc_buf_optimal_sz = 500;
995 cfg_.rc_buf_sz = 1000;
996 cfg_.rc_min_quantizer = 0;
997 cfg_.rc_max_quantizer = 63;
999 cfg_.temporal_layering_mode = 3;
1000 cfg_.rc_dropframe_thresh = 30;
1001 cfg_.kf_max_dist = 9999;
1002 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1004 top_sl_width_ = 640;
1005 top_sl_height_ = 480;
1006 cfg_.rc_target_bitrate = 800;
1008 AssignLayerBitrates();
1009 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1010 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1012 #if CONFIG_VP9_DECODER
1013 // The non-reference frames are expected to be mismatched frames as the
1014 // encoder will avoid loopfilter on these frames.
1015 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1019 // Check rate targeting with different inter-layer prediction modes for 1 pass
1020 // CBR SVC: 3 spatial layers and 3 temporal layers, changing the target bitrate
1021 // at the middle of encoding.
1022 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLDynamicBitrateChange) {
1024 cfg_.rc_buf_initial_sz = 500;
1025 cfg_.rc_buf_optimal_sz = 500;
1026 cfg_.rc_buf_sz = 1000;
1027 cfg_.rc_min_quantizer = 0;
1028 cfg_.rc_max_quantizer = 63;
1030 cfg_.rc_dropframe_thresh = 30;
1031 cfg_.kf_max_dist = 9999;
1032 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1034 top_sl_width_ = 640;
1035 top_sl_height_ = 480;
1036 cfg_.rc_target_bitrate = 800;
1038 change_bitrate_ = true;
1039 AssignLayerBitrates();
1040 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1041 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1043 #if CONFIG_VP9_DECODER
1044 // The non-reference frames are expected to be mismatched frames as the
1045 // encoder will avoid loopfilter on these frames.
1046 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1050 #if CONFIG_VP9_TEMPORAL_DENOISING
1051 // Params: speed setting, noise sensitivity and index for bitrate array.
1052 class DatarateOnePassCbrSvcDenoiser
1053 : public DatarateOnePassCbrSvc,
1054 public ::libvpx_test::CodecTestWith3Params<int, int, int> {
1056 DatarateOnePassCbrSvcDenoiser() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
1057 memset(&svc_params_, 0, sizeof(svc_params_));
1059 virtual ~DatarateOnePassCbrSvcDenoiser() {}
1062 virtual void SetUp() {
1064 SetMode(::libvpx_test::kRealTime);
1065 speed_setting_ = GET_PARAM(1);
1070 // Check basic rate targeting for 1 pass CBR SVC with denoising.
1071 // 2 spatial layers and 3 temporal layer. Run HD clip with 2 threads.
1072 TEST_P(DatarateOnePassCbrSvcDenoiser, OnePassCbrSvc2SL3TLDenoiserOn) {
1074 cfg_.rc_buf_initial_sz = 500;
1075 cfg_.rc_buf_optimal_sz = 500;
1076 cfg_.rc_buf_sz = 1000;
1077 cfg_.rc_min_quantizer = 0;
1078 cfg_.rc_max_quantizer = 63;
1080 cfg_.rc_dropframe_thresh = 30;
1081 cfg_.kf_max_dist = 9999;
1082 number_spatial_layers_ = cfg_.ss_number_layers;
1083 number_temporal_layers_ = cfg_.ts_number_layers;
1084 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1086 top_sl_width_ = 640;
1087 top_sl_height_ = 480;
1088 const int bitrates[3] = { 600, 800, 1000 };
1089 // TODO(marpan): Check that effective_datarate for each layer hits the
1090 // layer target_bitrate.
1091 // For SVC, noise_sen = 1 means denoising only the top spatial layer
1092 // noise_sen = 2 means denoising the two top spatial layers.
1093 cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
1095 denoiser_on_ = GET_PARAM(2);
1096 AssignLayerBitrates();
1097 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1098 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1100 #if CONFIG_VP9_DECODER
1101 // The non-reference frames are expected to be mismatched frames as the
1102 // encoder will avoid loopfilter on these frames.
1103 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1108 // Params: speed setting, key frame dist.
1109 class DatarateOnePassCbrSvcSmallKF
1110 : public DatarateOnePassCbrSvc,
1111 public ::libvpx_test::CodecTestWith2Params<int, int> {
1113 DatarateOnePassCbrSvcSmallKF() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
1114 memset(&svc_params_, 0, sizeof(svc_params_));
1116 virtual ~DatarateOnePassCbrSvcSmallKF() {}
1119 virtual void SetUp() {
1121 SetMode(::libvpx_test::kRealTime);
1122 speed_setting_ = GET_PARAM(1);
1127 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3
1128 // temporal layers. Run CIF clip with 1 thread, and few short key frame periods.
1129 TEST_P(DatarateOnePassCbrSvcSmallKF, OnePassCbrSvc3SL3TLSmallKf) {
1131 cfg_.rc_buf_initial_sz = 500;
1132 cfg_.rc_buf_optimal_sz = 500;
1133 cfg_.rc_buf_sz = 1000;
1134 cfg_.rc_min_quantizer = 0;
1135 cfg_.rc_max_quantizer = 63;
1137 cfg_.rc_dropframe_thresh = 10;
1138 cfg_.rc_target_bitrate = 800;
1139 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1141 top_sl_width_ = 640;
1142 top_sl_height_ = 480;
1143 // For this 3 temporal layer case, pattern repeats every 4 frames, so choose
1144 // 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
1145 const int kf_dist = GET_PARAM(2);
1146 cfg_.kf_max_dist = kf_dist;
1147 key_frame_spacing_ = kf_dist;
1149 AssignLayerBitrates();
1150 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1151 // TODO(jianj): webm:1554
1152 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.70,
1154 #if CONFIG_VP9_DECODER
1155 // The non-reference frames are expected to be mismatched frames as the
1156 // encoder will avoid loopfilter on these frames.
1157 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1161 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 3
1162 // temporal layers. Run CIF clip with 1 thread, and few short key frame periods.
1163 TEST_P(DatarateOnePassCbrSvcSmallKF, OnePassCbrSvc2SL3TLSmallKf) {
1165 cfg_.rc_buf_initial_sz = 500;
1166 cfg_.rc_buf_optimal_sz = 500;
1167 cfg_.rc_buf_sz = 1000;
1168 cfg_.rc_min_quantizer = 0;
1169 cfg_.rc_max_quantizer = 63;
1171 cfg_.rc_dropframe_thresh = 10;
1172 cfg_.rc_target_bitrate = 400;
1173 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1175 top_sl_width_ = 640;
1176 top_sl_height_ = 480;
1177 // For this 3 temporal layer case, pattern repeats every 4 frames, so choose
1178 // 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
1179 const int kf_dist = GET_PARAM(2) + 32;
1180 cfg_.kf_max_dist = kf_dist;
1181 key_frame_spacing_ = kf_dist;
1183 AssignLayerBitrates();
1184 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1185 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1187 #if CONFIG_VP9_DECODER
1188 // The non-reference frames are expected to be mismatched frames as the
1189 // encoder will avoid loopfilter on these frames.
1190 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1194 // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3
1195 // temporal layers. Run VGA clip with 1 thread, and place layer sync frames:
1196 // one at middle layer first, then another one for top layer, and another
1197 // insert for base spatial layer (which forces key frame).
1198 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLSyncFrames) {
1200 cfg_.rc_buf_initial_sz = 500;
1201 cfg_.rc_buf_optimal_sz = 500;
1202 cfg_.rc_buf_sz = 1000;
1203 cfg_.rc_min_quantizer = 0;
1204 cfg_.rc_max_quantizer = 63;
1206 cfg_.kf_max_dist = 9999;
1207 cfg_.rc_dropframe_thresh = 10;
1208 cfg_.rc_target_bitrate = 400;
1209 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1211 top_sl_width_ = 640;
1212 top_sl_height_ = 480;
1214 insert_layer_sync_ = 1;
1215 AssignLayerBitrates();
1216 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1217 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
1219 #if CONFIG_VP9_DECODER
1220 // The non-reference frames are expected to be mismatched frames as the
1221 // encoder will avoid loopfilter on these frames.
1222 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1226 // Run SVC encoder for 3 spatial layers, 1 temporal layer, with
1227 // intra-only frame as sync frame on base spatial layer.
1228 // Intra_only is inserted at start and in middle of sequence.
1229 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL1TLSyncWithIntraOnly) {
1231 cfg_.rc_buf_initial_sz = 500;
1232 cfg_.rc_buf_optimal_sz = 500;
1233 cfg_.rc_buf_sz = 1000;
1234 cfg_.rc_min_quantizer = 0;
1235 cfg_.rc_max_quantizer = 63;
1237 cfg_.rc_dropframe_thresh = 30;
1238 cfg_.kf_max_dist = 9999;
1239 cfg_.rc_target_bitrate = 400;
1240 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1242 top_sl_width_ = 640;
1243 top_sl_height_ = 480;
1245 insert_layer_sync_ = 1;
1246 // Use intra_only frame for sync on base layer.
1247 force_intra_only_frame_ = 1;
1248 AssignLayerBitrates();
1249 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1250 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
1252 #if CONFIG_VP9_DECODER
1253 // The non-reference frames are expected to be mismatched frames as the
1254 // encoder will avoid loopfilter on these frames.
1255 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1259 // Run SVC encoder for 2 quality layers (same resolution different,
1260 // bitrates), 1 temporal layer, with screen content mode.
1261 TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2QL1TLScreen) {
1262 cfg_.rc_buf_initial_sz = 500;
1263 cfg_.rc_buf_optimal_sz = 500;
1264 cfg_.rc_buf_sz = 1000;
1265 cfg_.rc_min_quantizer = 0;
1266 cfg_.rc_max_quantizer = 56;
1267 cfg_.rc_end_usage = VPX_CBR;
1268 cfg_.g_lag_in_frames = 0;
1269 cfg_.ss_number_layers = 2;
1270 cfg_.ts_number_layers = 1;
1271 cfg_.ts_rate_decimator[0] = 1;
1272 cfg_.temporal_layering_mode = 0;
1273 cfg_.g_error_resilient = 1;
1275 svc_params_.scaling_factor_num[0] = 1;
1276 svc_params_.scaling_factor_den[0] = 1;
1277 svc_params_.scaling_factor_num[1] = 1;
1278 svc_params_.scaling_factor_den[1] = 1;
1279 cfg_.rc_dropframe_thresh = 30;
1280 cfg_.kf_max_dist = 9999;
1281 number_spatial_layers_ = cfg_.ss_number_layers;
1282 number_temporal_layers_ = cfg_.ts_number_layers;
1283 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
1285 top_sl_width_ = 640;
1286 top_sl_height_ = 480;
1289 // Set the layer bitrates, for 2 spatial layers, 1 temporal.
1290 cfg_.rc_target_bitrate = 400;
1291 cfg_.ss_target_bitrate[0] = 100;
1292 cfg_.ss_target_bitrate[1] = 300;
1293 cfg_.layer_target_bitrate[0] = 100;
1294 cfg_.layer_target_bitrate[1] = 300;
1295 for (int sl = 0; sl < 2; ++sl) {
1296 float layer_framerate = 30.0;
1297 layer_target_avg_bandwidth_[sl] = static_cast<int>(
1298 cfg_.layer_target_bitrate[sl] * 1000.0 / layer_framerate);
1299 bits_in_buffer_model_[sl] =
1300 cfg_.layer_target_bitrate[sl] * cfg_.rc_buf_initial_sz;
1302 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1303 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
1305 #if CONFIG_VP9_DECODER
1306 // The non-reference frames are expected to be mismatched frames as the
1307 // encoder will avoid loopfilter on these frames.
1308 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1312 // Params: speed setting.
1313 class DatarateOnePassCbrSvcPostencodeDrop
1314 : public DatarateOnePassCbrSvc,
1315 public ::libvpx_test::CodecTestWithParam<int> {
1317 DatarateOnePassCbrSvcPostencodeDrop() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
1318 memset(&svc_params_, 0, sizeof(svc_params_));
1320 virtual ~DatarateOnePassCbrSvcPostencodeDrop() {}
1323 virtual void SetUp() {
1325 SetMode(::libvpx_test::kRealTime);
1326 speed_setting_ = GET_PARAM(1);
1331 // Run SVC encoder for 2 quality layers (same resolution different,
1332 // bitrates), 1 temporal layer, with screen content mode.
1333 TEST_P(DatarateOnePassCbrSvcPostencodeDrop, OnePassCbrSvc2QL1TLScreen) {
1334 cfg_.rc_buf_initial_sz = 200;
1335 cfg_.rc_buf_optimal_sz = 200;
1336 cfg_.rc_buf_sz = 400;
1337 cfg_.rc_min_quantizer = 0;
1338 cfg_.rc_max_quantizer = 52;
1339 cfg_.rc_end_usage = VPX_CBR;
1340 cfg_.g_lag_in_frames = 0;
1341 cfg_.ss_number_layers = 2;
1342 cfg_.ts_number_layers = 1;
1343 cfg_.ts_rate_decimator[0] = 1;
1344 cfg_.temporal_layering_mode = 0;
1345 cfg_.g_error_resilient = 1;
1347 svc_params_.scaling_factor_num[0] = 1;
1348 svc_params_.scaling_factor_den[0] = 1;
1349 svc_params_.scaling_factor_num[1] = 1;
1350 svc_params_.scaling_factor_den[1] = 1;
1351 cfg_.rc_dropframe_thresh = 30;
1352 cfg_.kf_max_dist = 9999;
1353 number_spatial_layers_ = cfg_.ss_number_layers;
1354 number_temporal_layers_ = cfg_.ts_number_layers;
1355 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
1357 top_sl_width_ = 352;
1358 top_sl_height_ = 288;
1360 base_speed_setting_ = speed_setting_;
1362 use_post_encode_drop_ = 1;
1363 // Set the layer bitrates, for 2 spatial layers, 1 temporal.
1364 cfg_.rc_target_bitrate = 400;
1365 cfg_.ss_target_bitrate[0] = 100;
1366 cfg_.ss_target_bitrate[1] = 300;
1367 cfg_.layer_target_bitrate[0] = 100;
1368 cfg_.layer_target_bitrate[1] = 300;
1369 for (int sl = 0; sl < 2; ++sl) {
1370 float layer_framerate = 30.0;
1371 layer_target_avg_bandwidth_[sl] = static_cast<int>(
1372 cfg_.layer_target_bitrate[sl] * 1000.0 / layer_framerate);
1373 bits_in_buffer_model_[sl] =
1374 cfg_.layer_target_bitrate[sl] * cfg_.rc_buf_initial_sz;
1376 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1377 CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
1379 #if CONFIG_VP9_DECODER
1380 // The non-reference frames are expected to be mismatched frames as the
1381 // encoder will avoid loopfilter on these frames.
1382 EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
1386 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcSingleBR,
1387 ::testing::Range(5, 10));
1389 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcPostencodeDrop,
1390 ::testing::Range(4, 5));
1392 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcInterLayerPredSingleBR,
1393 ::testing::Range(5, 10), ::testing::Range(0, 3));
1395 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcMultiBR, ::testing::Range(5, 10),
1396 ::testing::Range(0, 3));
1398 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcFrameDropMultiBR,
1399 ::testing::Range(5, 10), ::testing::Range(0, 2),
1400 ::testing::Range(0, 3));
1402 #if CONFIG_VP9_TEMPORAL_DENOISING
1403 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcDenoiser,
1404 ::testing::Range(5, 10), ::testing::Range(1, 3),
1405 ::testing::Range(0, 3));
1408 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcSmallKF, ::testing::Range(5, 10),
1409 ::testing::Range(32, 36));
1411 } // namespace svc_test