svc_datarate_test.cc (108405B)
1 /* 2 * Copyright (c) 2019, Alliance for Open Media. All rights reserved. 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #include <climits> 13 #include <vector> 14 #include "config/aom_config.h" 15 #include "gtest/gtest.h" 16 #include "test/codec_factory.h" 17 #include "test/datarate_test.h" 18 #include "test/encode_test_driver.h" 19 #include "test/i420_video_source.h" 20 #include "test/util.h" 21 #include "test/y4m_video_source.h" 22 #include "aom/aom_codec.h" 23 #include "av1/common/enums.h" 24 #include "av1/encoder/encoder.h" 25 26 namespace datarate_test { 27 namespace { 28 29 struct FrameInfo { 30 FrameInfo(aom_codec_pts_t _pts, unsigned int _w, unsigned int _h) 31 : pts(_pts), w(_w), h(_h) {} 32 33 aom_codec_pts_t pts; 34 unsigned int w; 35 unsigned int h; 36 }; 37 38 void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, 39 unsigned int initial_h, unsigned int *w, 40 unsigned int *h, int resize_pattern) { 41 *w = initial_w; 42 *h = initial_h; 43 if (resize_pattern == 1) { 44 if (frame < 50) { 45 *w = initial_w / 4; 46 *h = initial_h / 4; 47 } else if (frame < 100) { 48 *w = initial_w / 2; 49 *h = initial_h / 2; 50 } else if (frame < 150) { 51 *w = initial_w; 52 *h = initial_h; 53 } else if (frame < 200) { 54 *w = initial_w / 4; 55 *h = initial_h / 4; 56 } else if (frame < 250) { 57 *w = initial_w / 2; 58 *h = initial_h / 2; 59 } 60 } else if (resize_pattern == 2) { 61 if (frame < 50) { 62 *w = initial_w / 2; 63 *h = initial_h / 2; 64 } else if (frame < 100) { 65 *w = initial_w / 4; 66 *h = initial_h / 4; 67 } else if (frame < 150) { 68 *w = initial_w; 69 *h = initial_h; 70 } else if (frame < 200) { 71 *w = initial_w / 2; 72 *h = initial_h / 2; 73 } else if (frame < 250) { 74 *w = initial_w / 4; 75 *h = initial_h / 4; 76 } 77 } 78 } 79 80 class ResizingVideoSource : public ::libaom_test::DummyVideoSource { 81 public: 82 explicit ResizingVideoSource(int external_resize_pattern, int width, 83 int height) { 84 external_resize_pattern_ = external_resize_pattern; 85 top_width_ = width; 86 top_height_ = height; 87 SetSize(top_width_, top_height_); 88 limit_ = 300; 89 } 90 ~ResizingVideoSource() override = default; 91 92 protected: 93 void Next() override { 94 ++frame_; 95 unsigned int width = 0; 96 unsigned int height = 0; 97 libaom_test::ACMRandom rnd(libaom_test::ACMRandom::DeterministicSeed()); 98 ScaleForFrameNumber(frame_, top_width_, top_height_, &width, &height, 99 external_resize_pattern_); 100 SetSize(width, height); 101 FillFrame(); 102 unsigned char *image = img_->planes[0]; 103 for (size_t i = 0; i < raw_sz_; ++i) { 104 image[i] = rnd.Rand8(); 105 } 106 } 107 108 private: 109 int external_resize_pattern_; 110 // top_width_/height_ is the configured resolution when codec is created. 111 int top_width_; 112 int top_height_; 113 }; 114 115 class DatarateTestSVC 116 : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int, 117 unsigned int, int>, 118 public DatarateTest { 119 public: 120 DatarateTestSVC() : DatarateTest(GET_PARAM(0)) { 121 set_cpu_used_ = GET_PARAM(2); 122 aq_mode_ = GET_PARAM(3); 123 } 124 125 protected: 126 void SetUp() override { 127 InitializeConfig(GET_PARAM(1)); 128 ResetModel(); 129 } 130 131 void SetUpCbr() { 132 cfg_.rc_buf_initial_sz = 500; 133 cfg_.rc_buf_optimal_sz = 500; 134 cfg_.rc_buf_sz = 1000; 135 cfg_.rc_dropframe_thresh = 0; 136 cfg_.rc_min_quantizer = 0; 137 cfg_.rc_max_quantizer = 63; 138 cfg_.rc_end_usage = AOM_CBR; 139 cfg_.g_lag_in_frames = 0; 140 } 141 142 void SetTargetBitratesFor1SL1TL() { 143 number_temporal_layers_ = 1; 144 number_spatial_layers_ = 1; 145 target_layer_bitrate_[0] = cfg_.rc_target_bitrate; 146 } 147 148 void SetTargetBitratesFor1SL2TL() { 149 number_temporal_layers_ = 2; 150 number_spatial_layers_ = 1; 151 target_layer_bitrate_[0] = 60 * cfg_.rc_target_bitrate / 100; 152 target_layer_bitrate_[1] = cfg_.rc_target_bitrate; 153 } 154 155 void SetTargetBitratesFor1SL3TL() { 156 number_temporal_layers_ = 3; 157 number_spatial_layers_ = 1; 158 target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100; 159 target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100; 160 target_layer_bitrate_[2] = cfg_.rc_target_bitrate; 161 } 162 163 void SetTargetBitratesFor2SL1TL() { 164 number_temporal_layers_ = 1; 165 number_spatial_layers_ = 2; 166 target_layer_bitrate_[0] = 2 * cfg_.rc_target_bitrate / 4; 167 target_layer_bitrate_[1] = 2 * cfg_.rc_target_bitrate / 4; 168 } 169 170 void SetTargetBitratesFor3SL1TL() { 171 number_temporal_layers_ = 1; 172 number_spatial_layers_ = 3; 173 target_layer_bitrate_[0] = 1 * cfg_.rc_target_bitrate / 8; 174 target_layer_bitrate_[1] = 3 * cfg_.rc_target_bitrate / 8; 175 target_layer_bitrate_[2] = 4 * cfg_.rc_target_bitrate / 8; 176 } 177 178 void SetTargetBitratesFor3SL3TL() { 179 number_temporal_layers_ = 3; 180 number_spatial_layers_ = 3; 181 // SL0 182 const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8; 183 target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100; 184 target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100; 185 target_layer_bitrate_[2] = bitrate_sl0; 186 // SL1 187 const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8; 188 target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100; 189 target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100; 190 target_layer_bitrate_[5] = bitrate_sl1; 191 // SL2 192 const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8; 193 target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100; 194 target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100; 195 target_layer_bitrate_[8] = bitrate_sl2; 196 } 197 198 void DecompressedFrameHook(const aom_image_t &img, 199 aom_codec_pts_t pts) override { 200 frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h)); 201 ++decoded_nframes_; 202 } 203 204 std::vector<FrameInfo> frame_info_list_; 205 206 int GetNumSpatialLayers() override { return number_spatial_layers_; } 207 208 void ResetModel() override { 209 DatarateTest::ResetModel(); 210 layer_frame_cnt_ = 0; 211 superframe_cnt_ = 0; 212 number_temporal_layers_ = 1; 213 number_spatial_layers_ = 1; 214 for (int i = 0; i < AOM_MAX_LAYERS; i++) { 215 target_layer_bitrate_[i] = 0; 216 effective_datarate_tl[i] = 0.0; 217 } 218 memset(&layer_id_, 0, sizeof(aom_svc_layer_id_t)); 219 memset(&svc_params_, 0, sizeof(aom_svc_params_t)); 220 memset(&ref_frame_config_, 0, sizeof(aom_svc_ref_frame_config_t)); 221 memset(&ref_frame_comp_pred_, 0, sizeof(aom_svc_ref_frame_comp_pred_t)); 222 drop_frames_ = 0; 223 for (int i = 0; i < 1000; i++) drop_frames_list_[i] = 1000; 224 decoded_nframes_ = 0; 225 mismatch_nframes_ = 0; 226 mismatch_psnr_ = 0.0; 227 set_frame_level_er_ = 0; 228 multi_ref_ = 0; 229 use_fixed_mode_svc_ = 0; 230 comp_pred_ = 0; 231 dynamic_enable_disable_mode_ = 0; 232 intra_only_ = 0; 233 intra_only_single_layer_ = false; 234 frame_to_start_decoding_ = 0; 235 layer_to_decode_ = 0; 236 frame_sync_ = 0; 237 current_video_frame_ = 0; 238 screen_mode_ = 0; 239 rps_mode_ = 0; 240 rps_recovery_frame_ = 0; 241 user_define_frame_qp_ = 0; 242 set_speed_per_layer_ = false; 243 simulcast_mode_ = false; 244 use_last_as_scaled_ = false; 245 use_last_as_scaled_single_ref_ = false; 246 external_resize_dynamic_drop_layer_ = false; 247 external_resize_pattern_ = 0; 248 dynamic_tl_ = false; 249 dynamic_scale_factors_ = false; 250 } 251 252 void PreEncodeFrameHook(::libaom_test::VideoSource *video, 253 ::libaom_test::Encoder *encoder) override { 254 int spatial_layer_id = 0; 255 current_video_frame_ = video->frame(); 256 257 // One-time initialization only done on the first frame. 258 if (video->frame() == 0 && layer_frame_cnt_ == 0) { 259 initialize_svc(number_temporal_layers_, number_spatial_layers_, 260 &svc_params_); 261 if (dynamic_enable_disable_mode_ == 1) { 262 svc_params_.layer_target_bitrate[2] = 0; 263 cfg_.rc_target_bitrate -= target_layer_bitrate_[2]; 264 } 265 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 266 // TODO(aomedia:3032): Configure KSVC in fixed mode. 267 encoder->Control(AV1E_SET_ENABLE_ORDER_HINT, 0); 268 encoder->Control(AV1E_SET_ENABLE_TPL_MODEL, 0); 269 encoder->Control(AV1E_SET_DELTAQ_MODE, 0); 270 if (cfg_.g_threads > 1) { 271 if (auto_tiles_) { 272 encoder->Control(AV1E_SET_AUTO_TILES, 1); 273 } else { 274 encoder->Control(AV1E_SET_TILE_COLUMNS, tile_columns_); 275 encoder->Control(AV1E_SET_TILE_ROWS, tile_rows_); 276 } 277 encoder->Control(AV1E_SET_ROW_MT, 1); 278 } 279 if (screen_mode_) { 280 encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN); 281 } 282 encoder->Control(AV1E_SET_POSTENCODE_DROP_RTC, 1); 283 // We want to force external resize on the very first frame. 284 // Turn off frame-dropping. 285 if (external_resize_dynamic_drop_layer_) { 286 encoder->Control(AV1E_SET_POSTENCODE_DROP_RTC, 0); 287 DatarateTest::PreEncodeFrameHook(video, encoder); 288 video->Next(); 289 } 290 } 291 if (number_spatial_layers_ == 2) { 292 spatial_layer_id = (layer_frame_cnt_ % 2 == 0) ? 0 : 1; 293 } else if (number_spatial_layers_ == 3) { 294 spatial_layer_id = (layer_frame_cnt_ % 3 == 0) ? 0 295 : ((layer_frame_cnt_ - 1) % 3 == 0) ? 1 296 : 2; 297 } 298 // Set the reference/update flags, layer_id, and reference_map 299 // buffer index. 300 frame_flags_ = set_layer_pattern( 301 video->frame(), &layer_id_, &ref_frame_config_, &ref_frame_comp_pred_, 302 spatial_layer_id, multi_ref_, comp_pred_, 303 (video->frame() % cfg_.kf_max_dist) == 0, dynamic_enable_disable_mode_, 304 rps_mode_, rps_recovery_frame_, simulcast_mode_, use_last_as_scaled_, 305 use_last_as_scaled_single_ref_); 306 if (intra_only_ == 1 && frame_sync_ > 0) { 307 // Set an Intra-only frame on SL0 at frame_sync_. 308 // In order to allow decoding to start on SL0 in mid-sequence we need to 309 // set and refresh all the slots used on SL0 stream, which is 0 and 3 310 // for this test pattern. The other slots (1, 2, 4, 5) are used for the 311 // SL > 0 layers and these slotes are not refreshed on frame_sync_, so 312 // temporal prediction for the top layers can continue. 313 if (spatial_layer_id == 0 && video->frame() == frame_sync_) { 314 ref_frame_config_.ref_idx[0] = 0; 315 ref_frame_config_.ref_idx[3] = 3; 316 ref_frame_config_.refresh[0] = 1; 317 ref_frame_config_.refresh[3] = 1; 318 for (int i = 0; i < INTER_REFS_PER_FRAME; i++) 319 ref_frame_config_.reference[i] = 0; 320 } 321 } 322 if (intra_only_ && video->frame() == 50 && spatial_layer_id == 1) { 323 // Force an intra_only frame here, for SL1. 324 for (int i = 0; i < INTER_REFS_PER_FRAME; i++) 325 ref_frame_config_.reference[i] = 0; 326 } 327 encoder->Control(AV1E_SET_SVC_LAYER_ID, &layer_id_); 328 // The SET_SVC_REF_FRAME_CONFIG and AV1E_SET_SVC_REF_FRAME_COMP_PRED api is 329 // for the flexible SVC mode (i.e., use_fixed_mode_svc == 0). 330 if (!use_fixed_mode_svc_) { 331 encoder->Control(AV1E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config_); 332 encoder->Control(AV1E_SET_SVC_REF_FRAME_COMP_PRED, &ref_frame_comp_pred_); 333 } 334 if (set_speed_per_layer_) { 335 int speed_per_layer = 10; 336 if (layer_id_.spatial_layer_id == 0) { 337 // For for base SL0,TL0: use the speed the test loops over. 338 if (layer_id_.temporal_layer_id == 1) speed_per_layer = 7; 339 if (layer_id_.temporal_layer_id == 2) speed_per_layer = 8; 340 } else if (layer_id_.spatial_layer_id == 1) { 341 if (layer_id_.temporal_layer_id == 0) speed_per_layer = 7; 342 if (layer_id_.temporal_layer_id == 1) speed_per_layer = 8; 343 if (layer_id_.temporal_layer_id == 2) speed_per_layer = 9; 344 } else if (layer_id_.spatial_layer_id == 2) { 345 if (layer_id_.temporal_layer_id == 0) speed_per_layer = 8; 346 if (layer_id_.temporal_layer_id == 1) speed_per_layer = 9; 347 if (layer_id_.temporal_layer_id == 2) speed_per_layer = 10; 348 } 349 encoder->Control(AOME_SET_CPUUSED, speed_per_layer); 350 } 351 if (set_frame_level_er_) { 352 int mode = 353 (layer_id_.spatial_layer_id > 0 || layer_id_.temporal_layer_id > 0); 354 encoder->Control(AV1E_SET_ERROR_RESILIENT_MODE, mode); 355 } 356 if (dynamic_enable_disable_mode_ == 1) { 357 if (layer_frame_cnt_ == 300 && spatial_layer_id == 0) { 358 // Enable: set top spatial layer bitrate back to non-zero. 359 svc_params_.layer_target_bitrate[2] = target_layer_bitrate_[2]; 360 cfg_.rc_target_bitrate += target_layer_bitrate_[2]; 361 encoder->Config(&cfg_); 362 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 363 } 364 } else if (dynamic_enable_disable_mode_ == 2) { 365 if (layer_frame_cnt_ == 300 && spatial_layer_id == 0) { 366 // Disable top spatial layer mid-stream. 367 svc_params_.layer_target_bitrate[2] = 0; 368 cfg_.rc_target_bitrate -= target_layer_bitrate_[2]; 369 encoder->Config(&cfg_); 370 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 371 } else if (layer_frame_cnt_ == 600 && spatial_layer_id == 0) { 372 // Enable top spatial layer mid-stream. 373 svc_params_.layer_target_bitrate[2] = target_layer_bitrate_[2]; 374 cfg_.rc_target_bitrate += target_layer_bitrate_[2]; 375 encoder->Config(&cfg_); 376 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 377 } 378 } 379 if (external_resize_dynamic_drop_layer_) { 380 frame_flags_ = 0; 381 for (int i = 0; i < 9; ++i) { 382 svc_params_.min_quantizers[i] = 20; 383 svc_params_.max_quantizers[i] = 56; 384 } 385 if (layer_id_.spatial_layer_id == 0 && 386 (video->frame() == 1 || video->frame() == 150)) { 387 for (int i = 0; i < 9; ++i) { 388 bitrate_layer_[i] = svc_params_.layer_target_bitrate[i]; 389 } 390 if (external_resize_pattern_ == 1) { 391 // Input size is 1/4. 2 top spatial layers are dropped. 392 // This will trigger skip encoding/dropping of two top spatial layers. 393 cfg_.rc_target_bitrate -= svc_params_.layer_target_bitrate[5] + 394 svc_params_.layer_target_bitrate[8]; 395 for (int i = 3; i < 9; ++i) { 396 svc_params_.layer_target_bitrate[i] = 0; 397 } 398 for (int sl = 0; sl < 3; sl++) { 399 svc_params_.scaling_factor_num[sl] = 1; 400 svc_params_.scaling_factor_den[sl] = 1; 401 } 402 } else if (external_resize_pattern_ == 2) { 403 // Input size is 1/2. Top spatial layer is dropped. 404 // This will trigger skip encoding/dropping of top spatial layer. 405 cfg_.rc_target_bitrate -= svc_params_.layer_target_bitrate[8]; 406 for (int i = 6; i < 9; ++i) { 407 svc_params_.layer_target_bitrate[i] = 0; 408 } 409 svc_params_.scaling_factor_num[0] = 1; 410 svc_params_.scaling_factor_den[0] = 2; 411 svc_params_.scaling_factor_num[1] = 1; 412 svc_params_.scaling_factor_den[1] = 1; 413 svc_params_.scaling_factor_num[2] = 1; 414 svc_params_.scaling_factor_den[2] = 1; 415 } 416 encoder->Config(&cfg_); 417 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 418 } else if (layer_id_.spatial_layer_id == 0 && 419 (video->frame() == 50 || video->frame() == 200)) { 420 if (external_resize_pattern_ == 1) { 421 // Input size is 1/2. Change layer bitrates to set top layer to 0. 422 // This will trigger skip encoding/dropping of top spatial layer. 423 cfg_.rc_target_bitrate += bitrate_layer_[5]; 424 for (int i = 3; i < 6; ++i) { 425 svc_params_.layer_target_bitrate[i] = bitrate_layer_[i]; 426 } 427 svc_params_.scaling_factor_num[0] = 1; 428 svc_params_.scaling_factor_den[0] = 2; 429 svc_params_.scaling_factor_num[1] = 1; 430 svc_params_.scaling_factor_den[1] = 1; 431 svc_params_.scaling_factor_num[2] = 1; 432 svc_params_.scaling_factor_den[2] = 1; 433 } else if (external_resize_pattern_ == 2) { 434 // Input size is 1/4. Change layer bitrates to set two top layers to 435 // 0. This will trigger skip encoding/dropping of two top spatial 436 // layers. 437 cfg_.rc_target_bitrate -= bitrate_layer_[5]; 438 for (int i = 3; i < 6; ++i) { 439 svc_params_.layer_target_bitrate[i] = 0; 440 } 441 for (int sl = 0; sl < 3; sl++) { 442 svc_params_.scaling_factor_num[sl] = 1; 443 svc_params_.scaling_factor_den[sl] = 1; 444 } 445 } 446 encoder->Config(&cfg_); 447 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 448 } else if (layer_id_.spatial_layer_id == 0 && 449 (video->frame() == 100 || video->frame() == 250)) { 450 // Input is original size. Change layer bitrates to nonzero for all 451 // layers. 452 cfg_.rc_target_bitrate = 453 bitrate_layer_[2] + bitrate_layer_[5] + bitrate_layer_[8]; 454 for (int i = 0; i < 9; ++i) { 455 svc_params_.layer_target_bitrate[i] = bitrate_layer_[i]; 456 } 457 svc_params_.scaling_factor_num[0] = 1; 458 svc_params_.scaling_factor_den[0] = 4; 459 svc_params_.scaling_factor_num[1] = 1; 460 svc_params_.scaling_factor_den[1] = 2; 461 svc_params_.scaling_factor_num[2] = 1; 462 svc_params_.scaling_factor_den[2] = 1; 463 encoder->Config(&cfg_); 464 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 465 } 466 } else if (dynamic_tl_) { 467 if (video->frame() == 100) { 468 // Enable 3 temporal layers. 469 svc_params_.number_temporal_layers = 3; 470 number_temporal_layers_ = 3; 471 svc_params_.layer_target_bitrate[0] = 60 * cfg_.rc_target_bitrate / 100; 472 svc_params_.layer_target_bitrate[1] = 80 * cfg_.rc_target_bitrate / 100; 473 svc_params_.layer_target_bitrate[2] = cfg_.rc_target_bitrate; 474 svc_params_.framerate_factor[0] = 4; 475 svc_params_.framerate_factor[1] = 2; 476 svc_params_.framerate_factor[2] = 1; 477 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 478 } else if (video->frame() == 200) { 479 // Go back to 1 temporal layer. 480 svc_params_.number_temporal_layers = 1; 481 number_temporal_layers_ = 1; 482 svc_params_.layer_target_bitrate[0] = cfg_.rc_target_bitrate; 483 svc_params_.framerate_factor[0] = 1; 484 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 485 } 486 } else if (dynamic_scale_factors_) { 487 if (layer_id_.spatial_layer_id == 0 && video->frame() == 0) { 488 // Change layer bitrates to set top layer to 0. 489 // This will trigger skip encoding/dropping of top spatial layer. 490 // Set scale factors to 1/2 on top layer. 491 bitrate_layer_[2] = svc_params_.layer_target_bitrate[2]; 492 cfg_.rc_target_bitrate -= bitrate_layer_[2]; 493 svc_params_.layer_target_bitrate[2] = 0; 494 svc_params_.scaling_factor_num[0] = 1; 495 svc_params_.scaling_factor_den[0] = 4; 496 svc_params_.scaling_factor_num[1] = 1; 497 svc_params_.scaling_factor_den[1] = 2; 498 svc_params_.scaling_factor_num[2] = 1; 499 svc_params_.scaling_factor_den[2] = 2; 500 encoder->Config(&cfg_); 501 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 502 } else if (layer_id_.spatial_layer_id == 0 && video->frame() == 30) { 503 // Go back nonzero bitrate and set scale factors to 1/1 on top layer. 504 svc_params_.layer_target_bitrate[2] = bitrate_layer_[2]; 505 cfg_.rc_target_bitrate += svc_params_.layer_target_bitrate[2]; 506 svc_params_.scaling_factor_num[2] = 1; 507 svc_params_.scaling_factor_den[2] = 1; 508 encoder->Config(&cfg_); 509 encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_); 510 } 511 } 512 layer_frame_cnt_++; 513 DatarateTest::PreEncodeFrameHook(video, encoder); 514 if (user_define_frame_qp_) { 515 frame_qp_ = rnd_.PseudoUniform(63); 516 encoder->Control(AV1E_SET_QUANTIZER_ONE_PASS, frame_qp_); 517 } 518 } 519 520 void PostEncodeFrameHook(::libaom_test::Encoder *encoder) override { 521 int num_operating_points; 522 encoder->Control(AV1E_GET_NUM_OPERATING_POINTS, &num_operating_points); 523 ASSERT_EQ(num_operating_points, 524 number_temporal_layers_ * number_spatial_layers_); 525 526 if (user_define_frame_qp_) { 527 if (current_video_frame_ >= static_cast<unsigned int>(total_frame_)) 528 return; 529 int qp; 530 encoder->Control(AOME_GET_LAST_QUANTIZER_64, &qp); 531 ASSERT_EQ(qp, frame_qp_); 532 } 533 } 534 535 void FramePktHook(const aom_codec_cx_pkt_t *pkt) override { 536 const size_t frame_size_in_bits = pkt->data.frame.sz * 8; 537 // Update the layer cumulative bitrate. 538 for (int i = layer_id_.temporal_layer_id; i < number_temporal_layers_; 539 i++) { 540 int layer = layer_id_.spatial_layer_id * number_temporal_layers_ + i; 541 effective_datarate_tl[layer] += 1.0 * frame_size_in_bits; 542 } 543 if (layer_id_.spatial_layer_id == number_spatial_layers_ - 1) { 544 last_pts_ = pkt->data.frame.pts; 545 superframe_cnt_++; 546 } 547 // For simulcast mode: verify that for first frame to start decoding, 548 // for SL > 0, are Intra-only frames (not Key), whereas SL0 is Key. 549 if (simulcast_mode_ && superframe_cnt_ == (int)frame_to_start_decoding_) { 550 if (layer_id_.spatial_layer_id > 0) { 551 EXPECT_NE(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY); 552 } else if (layer_id_.spatial_layer_id == 0) { 553 EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY); 554 } 555 } 556 if (external_resize_dynamic_drop_layer_) { 557 // No key frame is needed for these encoding patterns, except at the 558 // very first frame. 559 if (layer_frame_cnt_ > 1) { 560 EXPECT_NE(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY); 561 } 562 } 563 } 564 565 void EndPassHook() override { 566 duration_ = ((last_pts_ + 1) * timebase_); 567 for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) { 568 effective_datarate_tl[i] = (effective_datarate_tl[i] / 1000) / duration_; 569 } 570 } 571 572 bool DoDecode() const override { 573 if (drop_frames_ > 0) { 574 for (unsigned int i = 0; i < drop_frames_; ++i) { 575 if (drop_frames_list_[i] == (unsigned int)superframe_cnt_) { 576 std::cout << " Skipping decoding frame: " 577 << drop_frames_list_[i] << "\n"; 578 return false; 579 } 580 } 581 } else if (intra_only_ == 1) { 582 // Only start decoding at frames_to_start_decoding_. 583 if (current_video_frame_ < frame_to_start_decoding_) return false; 584 // Only decode base layer for 3SL, for layer_to_decode_ = 0. 585 if (layer_to_decode_ == 0 && frame_sync_ > 0 && 586 (layer_frame_cnt_ - 1) % 3 != 0) 587 return false; 588 } else if (simulcast_mode_) { 589 // Only start decoding at frames_to_start_decoding_ and only 590 // for top spatial layer SL2 (layer_to_decode_). 591 if (current_video_frame_ < frame_to_start_decoding_) return false; 592 if (layer_id_.spatial_layer_id < (int)layer_to_decode_) return false; 593 } 594 return true; 595 } 596 597 void MismatchHook(const aom_image_t *img1, const aom_image_t *img2) override { 598 double mismatch_psnr = compute_psnr(img1, img2); 599 mismatch_psnr_ += mismatch_psnr; 600 ++mismatch_nframes_; 601 } 602 603 unsigned int GetMismatchFrames() { return mismatch_nframes_; } 604 unsigned int GetDecodedFrames() { return decoded_nframes_; } 605 606 static void ref_config_rps(aom_svc_ref_frame_config_t *ref_frame_config, 607 int frame_cnt, int rps_recovery_frame) { 608 // Pattern of 3 references with (ALTREF and GOLDEN) trailing 609 // LAST by 4 and 8 frame, with some switching logic to 610 // only predict from longer-term reference. 611 int last_idx = 0; 612 int last_idx_refresh = 0; 613 int gld_idx = 0; 614 int alt_ref_idx = 0; 615 const int lag_alt = 4; 616 const int lag_gld = 8; 617 const int sh = 8; // slots 0 - 7. 618 // Moving index slot for last: 0 - (sh - 1) 619 if (frame_cnt > 1) last_idx = (frame_cnt - 1) % sh; 620 // Moving index for refresh of last: one ahead for next frame. 621 last_idx_refresh = frame_cnt % sh; 622 // Moving index for gld_ref, lag behind current by lag_gld 623 if (frame_cnt > lag_gld) gld_idx = (frame_cnt - lag_gld) % sh; 624 // Moving index for alt_ref, lag behind LAST by lag_alt frames. 625 if (frame_cnt > lag_alt) alt_ref_idx = (frame_cnt - lag_alt) % sh; 626 // Set the ref_idx. 627 // Default all references (7) to slot for last. 628 // LAST_FRAME (0), LAST2_FRAME(1), LAST3_FRAME(2), GOLDEN_FRAME(3), 629 // BWDREF_FRAME(4), ALTREF2_FRAME(5), ALTREF_FRAME(6). 630 for (int i = 0; i < INTER_REFS_PER_FRAME; i++) 631 ref_frame_config->ref_idx[i] = last_idx; 632 // Set the ref_idx for the relevant references. 633 ref_frame_config->ref_idx[0] = last_idx; 634 ref_frame_config->ref_idx[1] = last_idx_refresh; 635 ref_frame_config->ref_idx[3] = gld_idx; 636 ref_frame_config->ref_idx[6] = alt_ref_idx; 637 // Refresh this slot, which will become LAST on next frame. 638 ref_frame_config->refresh[last_idx_refresh] = 1; 639 // Reference LAST, ALTREF, and GOLDEN 640 ref_frame_config->reference[0] = 1; 641 ref_frame_config->reference[6] = 1; 642 ref_frame_config->reference[3] = 1; 643 if (frame_cnt == rps_recovery_frame) { 644 // Switch to only reference GOLDEN at recovery_frame. 645 ref_frame_config->reference[0] = 0; 646 ref_frame_config->reference[6] = 0; 647 ref_frame_config->reference[3] = 1; 648 } else if (frame_cnt > rps_recovery_frame && 649 frame_cnt < rps_recovery_frame + 8) { 650 // Go back to predicting from LAST, and after 651 // 8 frames (GOLDEN is 8 frames aways) go back 652 // to predicting off GOLDEN and ALTREF. 653 ref_frame_config->reference[0] = 1; 654 ref_frame_config->reference[6] = 0; 655 ref_frame_config->reference[3] = 0; 656 } 657 } 658 659 // Simulcast mode for 3 spatial and 3 temporal layers. 660 // No inter-layer predicton, only prediction is temporal and single 661 // reference (LAST). 662 // No overlap in buffer slots between spatial layers. So for example, 663 // SL0 only uses slots 0 and 1. 664 // SL1 only uses slots 2 and 3. 665 // SL2 only uses slots 4 and 5. 666 // All 7 references for each inter-frame must only access buffer slots 667 // for that spatial layer. 668 // On key (super)frames: SL1 and SL2 must have no references set 669 // and must refresh all the slots for that layer only (so 2 and 3 670 // for SL1, 4 and 5 for SL2). The base SL0 will be labelled internally 671 // as a Key frame (refresh all slots). SL1/SL2 will be labelled 672 // internally as Intra-only frames that allow that stream to be decoded. 673 // These conditions will allow for each spatial stream to be 674 // independently decodeable. 675 static void ref_config_simulcast3SL3TL( 676 aom_svc_ref_frame_config_t *ref_frame_config, 677 aom_svc_layer_id_t *layer_id, int is_key_frame, int superframe_cnt) { 678 int i; 679 // Initialize all references to 0 (don't use reference). 680 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 681 ref_frame_config->reference[i] = 0; 682 // Initialize as no refresh/update for all slots. 683 for (i = 0; i < REF_FRAMES; i++) ref_frame_config->refresh[i] = 0; 684 for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->ref_idx[i] = 0; 685 686 if (is_key_frame) { 687 if (layer_id->spatial_layer_id == 0) { 688 // Assign LAST/GOLDEN to slot 0/1. 689 // Refesh slots 0 and 1 for SL0. 690 // SL0: this will get set to KEY frame internally. 691 ref_frame_config->ref_idx[0] = 0; 692 ref_frame_config->ref_idx[3] = 1; 693 ref_frame_config->refresh[0] = 1; 694 ref_frame_config->refresh[1] = 1; 695 } else if (layer_id->spatial_layer_id == 1) { 696 // Assign LAST/GOLDEN to slot 2/3. 697 // Refesh slots 2 and 3 for SL1. 698 // This will get set to Intra-only frame internally. 699 ref_frame_config->ref_idx[0] = 2; 700 ref_frame_config->ref_idx[3] = 3; 701 ref_frame_config->refresh[2] = 1; 702 ref_frame_config->refresh[3] = 1; 703 } else if (layer_id->spatial_layer_id == 2) { 704 // Assign LAST/GOLDEN to slot 4/5. 705 // Refresh slots 4 and 5 for SL2. 706 // This will get set to Intra-only frame internally. 707 ref_frame_config->ref_idx[0] = 4; 708 ref_frame_config->ref_idx[3] = 5; 709 ref_frame_config->refresh[4] = 1; 710 ref_frame_config->refresh[5] = 1; 711 } 712 } else if (superframe_cnt % 4 == 0) { 713 // Base temporal layer: TL0 714 layer_id->temporal_layer_id = 0; 715 if (layer_id->spatial_layer_id == 0) { // SL0 716 // Reference LAST. Assign all references to either slot 717 // 0 or 1. Here we assign LAST to slot 0, all others to 1. 718 // Update slot 0 (LAST). 719 ref_frame_config->reference[0] = 1; 720 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 721 ref_frame_config->ref_idx[i] = 1; 722 ref_frame_config->ref_idx[0] = 0; 723 ref_frame_config->refresh[0] = 1; 724 } else if (layer_id->spatial_layer_id == 1) { // SL1 725 // Reference LAST. Assign all references to either slot 726 // 2 or 3. Here we assign LAST to slot 2, all others to 3. 727 // Update slot 2 (LAST). 728 ref_frame_config->reference[0] = 1; 729 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 730 ref_frame_config->ref_idx[i] = 3; 731 ref_frame_config->ref_idx[0] = 2; 732 ref_frame_config->refresh[2] = 1; 733 } else if (layer_id->spatial_layer_id == 2) { // SL2 734 // Reference LAST. Assign all references to either slot 735 // 4 or 5. Here we assign LAST to slot 4, all others to 5. 736 // Update slot 4 (LAST). 737 ref_frame_config->reference[0] = 1; 738 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 739 ref_frame_config->ref_idx[i] = 5; 740 ref_frame_config->ref_idx[0] = 4; 741 ref_frame_config->refresh[4] = 1; 742 } 743 } else if ((superframe_cnt - 1) % 4 == 0) { 744 // First top temporal enhancement layer: TL2 745 layer_id->temporal_layer_id = 2; 746 if (layer_id->spatial_layer_id == 0) { // SL0 747 // Reference LAST (slot 0). Assign other references to slot 1. 748 // No update/refresh on any slots. 749 ref_frame_config->reference[0] = 1; 750 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 751 ref_frame_config->ref_idx[i] = 1; 752 ref_frame_config->ref_idx[0] = 0; 753 } else if (layer_id->spatial_layer_id == 1) { // SL1 754 // Reference LAST (slot 2). Assign other references to slot 3. 755 // No update/refresh on any slots. 756 ref_frame_config->reference[0] = 1; 757 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 758 ref_frame_config->ref_idx[i] = 3; 759 ref_frame_config->ref_idx[0] = 2; 760 } else if (layer_id->spatial_layer_id == 2) { // SL2 761 // Reference LAST (slot 4). Assign other references to slot 4. 762 // No update/refresh on any slots. 763 ref_frame_config->reference[0] = 1; 764 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 765 ref_frame_config->ref_idx[i] = 5; 766 ref_frame_config->ref_idx[0] = 4; 767 } 768 } else if ((superframe_cnt - 2) % 4 == 0) { 769 // Middle temporal enhancement layer: TL1 770 layer_id->temporal_layer_id = 1; 771 if (layer_id->spatial_layer_id == 0) { // SL0 772 // Reference LAST (slot 0). 773 // Set GOLDEN to slot 1 and update slot 1. 774 // This will be used as reference for next TL2. 775 ref_frame_config->reference[0] = 1; 776 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 777 ref_frame_config->ref_idx[i] = 1; 778 ref_frame_config->ref_idx[0] = 0; 779 ref_frame_config->refresh[1] = 1; 780 } else if (layer_id->spatial_layer_id == 1) { // SL1 781 // Reference LAST (slot 2). 782 // Set GOLDEN to slot 3 and update slot 3. 783 // This will be used as reference for next TL2. 784 ref_frame_config->reference[0] = 1; 785 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 786 ref_frame_config->ref_idx[i] = 3; 787 ref_frame_config->ref_idx[0] = 2; 788 ref_frame_config->refresh[3] = 1; 789 } else if (layer_id->spatial_layer_id == 2) { // SL2 790 // Reference LAST (slot 4). 791 // Set GOLDEN to slot 5 and update slot 5. 792 // This will be used as reference for next TL2. 793 ref_frame_config->reference[0] = 1; 794 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 795 ref_frame_config->ref_idx[i] = 5; 796 ref_frame_config->ref_idx[0] = 4; 797 ref_frame_config->refresh[5] = 1; 798 } 799 } else if ((superframe_cnt - 3) % 4 == 0) { 800 // Second top temporal enhancement layer: TL2 801 layer_id->temporal_layer_id = 2; 802 if (layer_id->spatial_layer_id == 0) { // SL0 803 // Reference LAST (slot 1). Assign other references to slot 0. 804 // No update/refresh on any slots. 805 ref_frame_config->reference[0] = 1; 806 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 807 ref_frame_config->ref_idx[i] = 0; 808 ref_frame_config->ref_idx[0] = 1; 809 } else if (layer_id->spatial_layer_id == 1) { // SL1 810 // Reference LAST (slot 3). Assign other references to slot 2. 811 // No update/refresh on any slots. 812 ref_frame_config->reference[0] = 1; 813 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 814 ref_frame_config->ref_idx[i] = 2; 815 ref_frame_config->ref_idx[0] = 3; 816 } else if (layer_id->spatial_layer_id == 2) { // SL2 817 // Reference LAST (slot 5). Assign other references to slot 4. 818 // No update/refresh on any slots. 819 ref_frame_config->reference[0] = 1; 820 for (i = 0; i < INTER_REFS_PER_FRAME; i++) 821 ref_frame_config->ref_idx[i] = 4; 822 ref_frame_config->ref_idx[0] = 5; 823 } 824 } 825 } 826 827 // 3 spatial and 3 temporal layer. 828 // Overlap in the buffer slot updates: the slots 3 and 4 updated by 829 // first TL2 are reused for update in TL1 superframe. 830 static void ref_config_3SL3TL(aom_svc_ref_frame_config_t *ref_frame_config, 831 aom_svc_layer_id_t *layer_id, int is_key_frame, 832 int superframe_cnt) { 833 if (superframe_cnt % 4 == 0) { 834 // Base temporal layer. 835 layer_id->temporal_layer_id = 0; 836 if (layer_id->spatial_layer_id == 0) { 837 // Reference LAST, update LAST. 838 // Set all buffer_idx to 0. 839 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 840 ref_frame_config->refresh[0] = 1; 841 } else if (layer_id->spatial_layer_id == 1) { 842 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1, 843 // GOLDEN (and all other refs) to slot 0. 844 // Update slot 1 (LAST). 845 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 846 ref_frame_config->ref_idx[0] = 1; 847 ref_frame_config->refresh[1] = 1; 848 } else if (layer_id->spatial_layer_id == 2) { 849 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2, 850 // GOLDEN (and all other refs) to slot 1. 851 // Update slot 2 (LAST). 852 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 1; 853 ref_frame_config->ref_idx[0] = 2; 854 ref_frame_config->refresh[2] = 1; 855 } 856 } else if ((superframe_cnt - 1) % 4 == 0) { 857 // First top temporal enhancement layer. 858 layer_id->temporal_layer_id = 2; 859 if (layer_id->spatial_layer_id == 0) { 860 // Reference LAST (slot 0). 861 // Set GOLDEN to slot 3 and update slot 3. 862 // Set all other buffer_idx to slot 0. 863 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 864 ref_frame_config->ref_idx[3] = 3; 865 ref_frame_config->refresh[3] = 1; 866 } else if (layer_id->spatial_layer_id == 1) { 867 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1, 868 // GOLDEN (and all other refs) to slot 3. 869 // Set LAST2 to slot 4 and Update slot 4. 870 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 3; 871 ref_frame_config->ref_idx[0] = 1; 872 ref_frame_config->ref_idx[1] = 4; 873 ref_frame_config->refresh[4] = 1; 874 } else if (layer_id->spatial_layer_id == 2) { 875 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2, 876 // GOLDEN (and all other refs) to slot 4. 877 // No update. 878 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 4; 879 ref_frame_config->ref_idx[0] = 2; 880 } 881 } else if ((superframe_cnt - 2) % 4 == 0) { 882 // Middle temporal enhancement layer. 883 layer_id->temporal_layer_id = 1; 884 if (layer_id->spatial_layer_id == 0) { 885 // Reference LAST. 886 // Set all buffer_idx to 0. 887 // Set GOLDEN to slot 3 and update slot 3. 888 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 889 ref_frame_config->ref_idx[3] = 3; 890 ref_frame_config->refresh[3] = 1; 891 } else if (layer_id->spatial_layer_id == 1) { 892 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1, 893 // GOLDEN (and all other refs) to slot 3. 894 // Set LAST2 to slot 4 and update slot 4. 895 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 3; 896 ref_frame_config->ref_idx[0] = 1; 897 ref_frame_config->ref_idx[2] = 4; 898 ref_frame_config->refresh[4] = 1; 899 } else if (layer_id->spatial_layer_id == 2) { 900 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2, 901 // GOLDEN (and all other refs) to slot 4. 902 // Set LAST2 to slot 5 and update slot 5. 903 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 4; 904 ref_frame_config->ref_idx[0] = 2; 905 ref_frame_config->ref_idx[2] = 5; 906 ref_frame_config->refresh[5] = 1; 907 } 908 } else if ((superframe_cnt - 3) % 4 == 0) { 909 // Second top temporal enhancement layer. 910 layer_id->temporal_layer_id = 2; 911 if (layer_id->spatial_layer_id == 0) { 912 // Set LAST to slot 3 and reference LAST. 913 // Set GOLDEN to slot 3 and update slot 3. 914 // Set all other buffer_idx to 0. 915 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 916 ref_frame_config->ref_idx[0] = 3; 917 ref_frame_config->ref_idx[3] = 3; 918 ref_frame_config->refresh[3] = 1; 919 } else if (layer_id->spatial_layer_id == 1) { 920 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 4, 921 // GOLDEN to slot 3. Set LAST2 to slot 4 and update slot 4. 922 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 923 ref_frame_config->ref_idx[0] = 4; 924 ref_frame_config->ref_idx[3] = 3; 925 ref_frame_config->ref_idx[1] = 4; 926 ref_frame_config->refresh[4] = 1; 927 } else if (layer_id->spatial_layer_id == 2) { 928 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 5, 929 // GOLDEN to slot 4. No update. 930 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 931 ref_frame_config->ref_idx[0] = 5; 932 ref_frame_config->ref_idx[3] = 4; 933 } 934 } 935 if (layer_id->spatial_layer_id > 0) { 936 // Always reference GOLDEN (inter-layer prediction). 937 ref_frame_config->reference[3] = 1; 938 if (is_key_frame && layer_id->spatial_layer_id > 0) { 939 // On superframes whose base is key: remove LAST since GOLDEN 940 // is used as reference. 941 ref_frame_config->reference[0] = 0; 942 } 943 } 944 } 945 946 void CheckDatarate(double low_factor, double high_factor, 947 int num_layers_to_check = -1) { 948 if (num_layers_to_check < 0) { 949 num_layers_to_check = number_temporal_layers_ * number_spatial_layers_; 950 } 951 for (int i = 0; i < num_layers_to_check; i++) { 952 ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * low_factor) 953 << " The datarate for the file is lower than target by too much!"; 954 ASSERT_LE(effective_datarate_tl[i], 955 target_layer_bitrate_[i] * high_factor) 956 << " The datarate for the file is greater than target by too much!"; 957 } 958 } 959 // Layer pattern configuration. 960 virtual int set_layer_pattern( 961 int frame_cnt, aom_svc_layer_id_t *layer_id, 962 aom_svc_ref_frame_config_t *ref_frame_config, 963 aom_svc_ref_frame_comp_pred_t *ref_frame_comp_pred, int spatial_layer, 964 int multi_ref, int comp_pred, int is_key_frame, 965 int dynamic_enable_disable_mode, int rps_mode, int rps_recovery_frame, 966 int simulcast_mode, bool use_last_as_scaled, 967 bool use_last_as_scaled_single_ref) { 968 int lag_index = 0; 969 int base_count = frame_cnt >> 2; 970 layer_id->spatial_layer_id = spatial_layer; 971 // Set the reference map buffer idx for the 7 references: 972 // LAST_FRAME (0), LAST2_FRAME(1), LAST3_FRAME(2), GOLDEN_FRAME(3), 973 // BWDREF_FRAME(4), ALTREF2_FRAME(5), ALTREF_FRAME(6). 974 for (int i = 0; i < INTER_REFS_PER_FRAME; i++) { 975 ref_frame_config->ref_idx[i] = i; 976 ref_frame_config->reference[i] = 0; 977 } 978 for (int i = 0; i < REF_FRAMES; i++) ref_frame_config->refresh[i] = 0; 979 if (comp_pred) { 980 ref_frame_comp_pred->use_comp_pred[0] = 1; // GOLDEN_LAST 981 ref_frame_comp_pred->use_comp_pred[1] = 1; // LAST2_LAST 982 ref_frame_comp_pred->use_comp_pred[2] = 1; // ALTREF_LAST 983 } 984 // Set layer_flags to 0 when using ref_frame_config->reference. 985 int layer_flags = 0; 986 // Always reference LAST. 987 ref_frame_config->reference[0] = 1; 988 if (number_temporal_layers_ == 1 && number_spatial_layers_ == 1) { 989 layer_id->temporal_layer_id = 0; 990 ref_frame_config->refresh[0] = 1; 991 if (rps_mode) 992 ref_config_rps(ref_frame_config, frame_cnt, rps_recovery_frame); 993 if (intra_only_single_layer_) { 994 // This repros the crash in Bug: 363016123. 995 ref_frame_config->ref_idx[0] = 0; 996 ref_frame_config->ref_idx[3] = 1; 997 ref_frame_config->ref_idx[6] = 2; 998 if (frame_cnt == 1) { 999 for (int i = 0; i < INTER_REFS_PER_FRAME; i++) 1000 ref_frame_config->reference[i] = 0; 1001 } 1002 } 1003 } 1004 if (number_temporal_layers_ == 2 && number_spatial_layers_ == 1) { 1005 // 2-temporal layer. 1006 // 1 3 5 1007 // 0 2 4 1008 // Keep golden fixed at slot 3. 1009 base_count = frame_cnt >> 1; 1010 ref_frame_config->ref_idx[3] = 3; 1011 // Cyclically refresh slots 5, 6, 7, for lag alt ref. 1012 lag_index = 5; 1013 if (base_count > 0) { 1014 lag_index = 5 + (base_count % 3); 1015 if (frame_cnt % 2 != 0) lag_index = 5 + ((base_count + 1) % 3); 1016 } 1017 // Set the altref slot to lag_index. 1018 ref_frame_config->ref_idx[6] = lag_index; 1019 if (frame_cnt % 2 == 0) { 1020 layer_id->temporal_layer_id = 0; 1021 // Update LAST on layer 0, reference LAST. 1022 ref_frame_config->refresh[0] = 1; 1023 ref_frame_config->reference[0] = 1; 1024 // Refresh lag_index slot, needed for lagging golen. 1025 ref_frame_config->refresh[lag_index] = 1; 1026 // Refresh GOLDEN every x base layer frames. 1027 if (base_count % 32 == 0) ref_frame_config->refresh[3] = 1; 1028 } else { 1029 layer_id->temporal_layer_id = 1; 1030 // No updates on layer 1, reference LAST (TL0). 1031 ref_frame_config->reference[0] = 1; 1032 } 1033 // Always reference golden and altref on TL0. 1034 if (layer_id->temporal_layer_id == 0) { 1035 ref_frame_config->reference[3] = 1; 1036 ref_frame_config->reference[6] = 1; 1037 } 1038 } else if (number_temporal_layers_ == 3 && number_spatial_layers_ == 1) { 1039 // 3-layer: 1040 // 1 3 5 7 1041 // 2 6 1042 // 0 4 8 1043 if (multi_ref) { 1044 // Keep golden fixed at slot 3. 1045 ref_frame_config->ref_idx[3] = 3; 1046 // Cyclically refresh slots 4, 5, 6, 7, for lag altref. 1047 lag_index = 4 + (base_count % 4); 1048 // Set the altref slot to lag_index. 1049 ref_frame_config->ref_idx[6] = lag_index; 1050 } 1051 if (frame_cnt % 4 == 0) { 1052 // Base layer. 1053 layer_id->temporal_layer_id = 0; 1054 // Update LAST on layer 0, reference LAST and GF. 1055 ref_frame_config->refresh[0] = 1; 1056 ref_frame_config->reference[3] = 1; 1057 if (multi_ref) { 1058 // Refresh GOLDEN every x ~10 base layer frames. 1059 if (base_count % 10 == 0) ref_frame_config->refresh[3] = 1; 1060 // Refresh lag_index slot, needed for lagging altref. 1061 ref_frame_config->refresh[lag_index] = 1; 1062 } 1063 } else if ((frame_cnt - 1) % 4 == 0) { 1064 layer_id->temporal_layer_id = 2; 1065 // First top layer: no updates, only reference LAST (TL0). 1066 } else if ((frame_cnt - 2) % 4 == 0) { 1067 layer_id->temporal_layer_id = 1; 1068 // Middle layer (TL1): update LAST2, only reference LAST (TL0). 1069 ref_frame_config->refresh[1] = 1; 1070 } else if ((frame_cnt - 3) % 4 == 0) { 1071 layer_id->temporal_layer_id = 2; 1072 // Second top layer: no updates, only reference LAST. 1073 // Set buffer idx for LAST to slot 1, since that was the slot 1074 // updated in previous frame. So LAST is TL1 frame. 1075 ref_frame_config->ref_idx[0] = 1; 1076 ref_frame_config->ref_idx[1] = 0; 1077 } 1078 if (multi_ref) { 1079 // Every frame can reference GOLDEN AND ALTREF. 1080 ref_frame_config->reference[3] = 1; 1081 ref_frame_config->reference[6] = 1; 1082 } 1083 } else if (number_temporal_layers_ == 1 && number_spatial_layers_ == 2) { 1084 layer_id->temporal_layer_id = 0; 1085 if (layer_id->spatial_layer_id == 0) { 1086 // Reference LAST, update LAST. Keep LAST and GOLDEN in slots 0 and 3. 1087 ref_frame_config->ref_idx[0] = 0; 1088 ref_frame_config->ref_idx[3] = 3; 1089 ref_frame_config->refresh[0] = 1; 1090 } else if (layer_id->spatial_layer_id == 1) { 1091 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 3 1092 // and GOLDEN to slot 0. Update slot 3 (LAST). 1093 ref_frame_config->ref_idx[0] = 3; 1094 ref_frame_config->ref_idx[3] = 0; 1095 ref_frame_config->refresh[3] = 1; 1096 } 1097 // Reference GOLDEN. 1098 if (layer_id->spatial_layer_id > 0) ref_frame_config->reference[3] = 1; 1099 } else if (number_temporal_layers_ == 1 && number_spatial_layers_ == 3) { 1100 // 3 spatial layers, 1 temporal. 1101 // Note for this case , we set the buffer idx for all references to be 1102 // either LAST or GOLDEN, which are always valid references, since decoder 1103 // will check if any of the 7 references is valid scale in 1104 // valid_ref_frame_size(). 1105 layer_id->temporal_layer_id = 0; 1106 if (layer_id->spatial_layer_id == 0) { 1107 // Reference LAST, update LAST. Set all other buffer_idx to 0. 1108 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 1109 ref_frame_config->refresh[0] = 1; 1110 } else if (layer_id->spatial_layer_id == 1) { 1111 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1 1112 // and GOLDEN (and all other refs) to slot 0. 1113 // Update slot 1 (LAST). 1114 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0; 1115 ref_frame_config->ref_idx[0] = 1; 1116 if (use_last_as_scaled) { 1117 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 1; 1118 ref_frame_config->ref_idx[0] = 0; 1119 ref_frame_config->ref_idx[3] = 1; 1120 } 1121 ref_frame_config->refresh[1] = 1; 1122 } else if (layer_id->spatial_layer_id == 2) { 1123 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2 1124 // and GOLDEN (and all other refs) to slot 1. 1125 // Update slot 2 (LAST). 1126 for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 1; 1127 ref_frame_config->ref_idx[0] = 2; 1128 ref_frame_config->refresh[2] = 1; 1129 if (multi_ref) { 1130 ref_frame_config->ref_idx[6] = 7; 1131 ref_frame_config->reference[6] = 1; 1132 if (base_count % 10 == 0) ref_frame_config->refresh[7] = 1; 1133 } 1134 } 1135 // Reference GOLDEN. 1136 if (layer_id->spatial_layer_id > 0) { 1137 if (use_last_as_scaled_single_ref) 1138 ref_frame_config->reference[3] = 0; 1139 else 1140 ref_frame_config->reference[3] = 1; 1141 } 1142 } else if (number_temporal_layers_ == 3 && number_spatial_layers_ == 3) { 1143 if (simulcast_mode) { 1144 ref_config_simulcast3SL3TL(ref_frame_config, layer_id, is_key_frame, 1145 superframe_cnt_); 1146 } else { 1147 ref_config_3SL3TL(ref_frame_config, layer_id, is_key_frame, 1148 superframe_cnt_); 1149 // Allow for top spatial layer to use additional temporal reference. 1150 // Additional reference is only updated on base temporal layer, every 1151 // 10 TL0 frames here. 1152 if (multi_ref && layer_id->spatial_layer_id == 2) { 1153 ref_frame_config->ref_idx[6] = 7; 1154 if (!is_key_frame) ref_frame_config->reference[6] = 1; 1155 if (base_count % 10 == 0 && layer_id->temporal_layer_id == 0) 1156 ref_frame_config->refresh[7] = 1; 1157 } 1158 } 1159 } 1160 // If the top spatial layer is first-time encoded in mid-sequence 1161 // (i.e., dynamic_enable_disable_mode = 1), then don't predict from LAST, 1162 // since it will have been last updated on first key frame (SL0) and so 1163 // be different resolution from SL2. 1164 if (dynamic_enable_disable_mode == 1 && 1165 layer_id->spatial_layer_id == number_spatial_layers_ - 1) 1166 ref_frame_config->reference[0] = 0; 1167 return layer_flags; 1168 } 1169 1170 virtual void initialize_svc(int number_temporal_layers, 1171 int number_spatial_layers, 1172 aom_svc_params *svc_params) { 1173 svc_params->number_spatial_layers = number_spatial_layers; 1174 svc_params->number_temporal_layers = number_temporal_layers; 1175 for (int i = 0; i < number_temporal_layers * number_spatial_layers; ++i) { 1176 svc_params->max_quantizers[i] = 60; 1177 svc_params->min_quantizers[i] = 2; 1178 svc_params->layer_target_bitrate[i] = target_layer_bitrate_[i]; 1179 } 1180 // Do at most 3 spatial or temporal layers here. 1181 svc_params->framerate_factor[0] = 1; 1182 if (number_temporal_layers == 2) { 1183 svc_params->framerate_factor[0] = 2; 1184 svc_params->framerate_factor[1] = 1; 1185 } else if (number_temporal_layers == 3) { 1186 svc_params->framerate_factor[0] = 4; 1187 svc_params->framerate_factor[1] = 2; 1188 svc_params->framerate_factor[2] = 1; 1189 } 1190 svc_params->scaling_factor_num[0] = 1; 1191 svc_params->scaling_factor_den[0] = 1; 1192 if (number_spatial_layers == 2) { 1193 svc_params->scaling_factor_num[0] = 1; 1194 svc_params->scaling_factor_den[0] = 2; 1195 svc_params->scaling_factor_num[1] = 1; 1196 svc_params->scaling_factor_den[1] = 1; 1197 } else if (number_spatial_layers == 3) { 1198 svc_params->scaling_factor_num[0] = 1; 1199 svc_params->scaling_factor_den[0] = 4; 1200 svc_params->scaling_factor_num[1] = 1; 1201 svc_params->scaling_factor_den[1] = 2; 1202 svc_params->scaling_factor_num[2] = 1; 1203 svc_params->scaling_factor_den[2] = 1; 1204 } 1205 } 1206 1207 virtual void BasicRateTargetingSVC3TL1SLTest() { 1208 SetUpCbr(); 1209 cfg_.g_error_resilient = 1; 1210 1211 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1212 288, 30, 1, 0, 300); 1213 const int bitrate_array[2] = { 200, 550 }; 1214 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1215 ResetModel(); 1216 SetTargetBitratesFor1SL3TL(); 1217 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1218 CheckDatarate(0.60, 1.60); 1219 #if CONFIG_AV1_DECODER 1220 // Top temporal layers are non_reference, so exlcude them from 1221 // mismatch count, since loopfilter/cdef is not applied for these on 1222 // encoder side, but is always applied on decoder. 1223 // This means 150 = #frames(300) - #TL2_frames(150). 1224 EXPECT_EQ((int)GetMismatchFrames(), 150); 1225 #endif 1226 } 1227 1228 virtual void SetFrameQpSVC3TL1SLTest() { 1229 SetUpCbr(); 1230 cfg_.g_error_resilient = 1; 1231 1232 user_define_frame_qp_ = 1; 1233 total_frame_ = 300; 1234 1235 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1236 288, 30, 1, 0, 300); 1237 const int bitrate_array[2] = { 200, 550 }; 1238 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1239 ResetModel(); 1240 SetTargetBitratesFor1SL3TL(); 1241 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1242 } 1243 1244 virtual void SetFrameQpSVC3TL3SLTest() { 1245 SetUpCbr(); 1246 cfg_.g_error_resilient = 0; 1247 1248 user_define_frame_qp_ = 1; 1249 total_frame_ = 300; 1250 1251 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1252 288, 30, 1, 0, 300); 1253 const int bitrate_array[2] = { 600, 1200 }; 1254 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1255 ResetModel(); 1256 SetTargetBitratesFor3SL3TL(); 1257 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1258 } 1259 1260 virtual void BasicRateTargetingSVC3TL1SLScreenTest() { 1261 SetUpCbr(); 1262 cfg_.g_error_resilient = 0; 1263 1264 ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 60); 1265 1266 const int bitrate_array[2] = { 1000, 1500 }; 1267 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1268 ResetModel(); 1269 screen_mode_ = 1; 1270 SetTargetBitratesFor1SL3TL(); 1271 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1272 CheckDatarate(0.40, 2.0); 1273 #if CONFIG_AV1_DECODER 1274 // Top temporal layers are non_reference, so exlcude them from 1275 // mismatch count, since loopfilter/cdef is not applied for these on 1276 // encoder side, but is always applied on decoder. 1277 // This means 30 = #frames(60) - #TL2_frames(30). 1278 // We use LE for screen since loopfilter level can become very small 1279 // or zero and then the frame is not a mismatch. 1280 EXPECT_LE((int)GetMismatchFrames(), 30); 1281 #endif 1282 } 1283 1284 virtual void BasicRateTargetingSVC2TL1SLScreenDropFrameTest() { 1285 cfg_.rc_buf_initial_sz = 50; 1286 cfg_.rc_buf_optimal_sz = 50; 1287 cfg_.rc_buf_sz = 100; 1288 cfg_.rc_dropframe_thresh = 30; 1289 cfg_.rc_min_quantizer = 0; 1290 cfg_.rc_max_quantizer = 52; 1291 cfg_.rc_end_usage = AOM_CBR; 1292 cfg_.g_lag_in_frames = 0; 1293 cfg_.g_error_resilient = 0; 1294 1295 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1296 288, 30, 1, 0, 300); 1297 1298 const int bitrate_array[2] = { 60, 100 }; 1299 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1300 ResetModel(); 1301 screen_mode_ = 1; 1302 SetTargetBitratesFor1SL2TL(); 1303 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1304 CheckDatarate(0.75, 1.8); 1305 #if CONFIG_AV1_DECODER 1306 // Top temporal layers are non_reference, so exlcude them from 1307 // mismatch count, since loopfilter/cdef is not applied for these on 1308 // encoder side, but is always applied on decoder. 1309 // This means 300 = #frames(300) - #TL2_frames(150). 1310 // We use LE for screen since loopfilter level can become very small 1311 // or zero and then the frame is not a mismatch. 1312 EXPECT_LE((int)GetMismatchFrames(), 150); 1313 #endif 1314 } 1315 1316 virtual void BasicRateTargetingSVC2TL1SLScreenDropFrame1920x1080Test() { 1317 cfg_.rc_buf_initial_sz = 50; 1318 cfg_.rc_buf_optimal_sz = 50; 1319 cfg_.rc_buf_sz = 100; 1320 cfg_.rc_dropframe_thresh = 30; 1321 cfg_.rc_min_quantizer = 0; 1322 cfg_.rc_max_quantizer = 52; 1323 cfg_.rc_end_usage = AOM_CBR; 1324 cfg_.g_lag_in_frames = 0; 1325 cfg_.g_error_resilient = 0; 1326 1327 ::libaom_test::Y4mVideoSource video("screendata.1920_1080.y4m", 0, 60); 1328 1329 const int bitrate_array[2] = { 60, 100 }; 1330 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1331 ResetModel(); 1332 screen_mode_ = 1; 1333 SetTargetBitratesFor1SL2TL(); 1334 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1335 #if CONFIG_AV1_DECODER 1336 // Top temporal layers are non_reference, so exclude them from 1337 // mismatch count, since loopfilter/cdef is not applied for these on 1338 // encoder side, but is always applied on decoder. 1339 // This means 150 = #frames(300) - #TL2_frames(150). 1340 // We use LE for screen since loopfilter level can become very small 1341 // or zero and then the frame is not a mismatch. 1342 EXPECT_LE(GetMismatchFrames(), 150u); 1343 #endif 1344 } 1345 1346 virtual void 1347 BasicRateTargetingSVC2TL1SLScreenDropFrame1920x10804ThreadTest() { 1348 cfg_.rc_buf_initial_sz = 50; 1349 cfg_.rc_buf_optimal_sz = 50; 1350 cfg_.rc_buf_sz = 100; 1351 cfg_.rc_dropframe_thresh = 30; 1352 cfg_.rc_min_quantizer = 0; 1353 cfg_.rc_max_quantizer = 52; 1354 cfg_.rc_end_usage = AOM_CBR; 1355 cfg_.g_lag_in_frames = 0; 1356 cfg_.g_error_resilient = 0; 1357 cfg_.g_threads = 4; 1358 1359 ::libaom_test::Y4mVideoSource video("screendata.1920_1080.y4m", 0, 60); 1360 1361 const int bitrate_array[2] = { 60, 100 }; 1362 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1363 ResetModel(); 1364 tile_columns_ = 1; 1365 tile_rows_ = 1; 1366 screen_mode_ = 1; 1367 SetTargetBitratesFor1SL2TL(); 1368 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1369 #if CONFIG_AV1_DECODER 1370 // Top temporal layers are non_reference, so exclude them from 1371 // mismatch count, since loopfilter/cdef is not applied for these on 1372 // encoder side, but is always applied on decoder. 1373 // This means 150 = #frames(300) - #TL2_frames(150). 1374 // We use LE for screen since loopfilter level can become very small 1375 // or zero and then the frame is not a mismatch. 1376 EXPECT_LE(GetMismatchFrames(), 150u); 1377 #endif 1378 } 1379 1380 virtual void BasicRateTargetingSVC1TL3SLScreenTest() { 1381 SetUpCbr(); 1382 cfg_.g_error_resilient = 0; 1383 1384 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 1385 1386 const int bitrate_array[2] = { 800, 1200 }; 1387 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1388 ResetModel(); 1389 screen_mode_ = 1; 1390 SetTargetBitratesFor3SL1TL(); 1391 target_layer_bitrate_[0] = 30 * cfg_.rc_target_bitrate / 100; 1392 target_layer_bitrate_[1] = 60 * cfg_.rc_target_bitrate / 100; 1393 target_layer_bitrate_[2] = cfg_.rc_target_bitrate; 1394 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1395 CheckDatarate(0.50, 1.5); 1396 #if CONFIG_AV1_DECODER 1397 EXPECT_EQ((int)GetMismatchFrames(), 0); 1398 #endif 1399 } 1400 1401 virtual void BasicRateTargetingSVC1TL1SLScreenScCutsMotionTest() { 1402 SetUpCbr(); 1403 cfg_.g_error_resilient = 0; 1404 1405 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1406 288, 30, 1, 0, 300); 1407 1408 const int bitrate_array[2] = { 200, 500 }; 1409 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1410 ResetModel(); 1411 screen_mode_ = 1; 1412 SetTargetBitratesFor1SL1TL(); 1413 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1414 CheckDatarate(0.40, 1.7); 1415 #if CONFIG_AV1_DECODER 1416 EXPECT_EQ((int)GetMismatchFrames(), 0); 1417 #endif 1418 } 1419 1420 virtual void BasicRateTargetingSVC3TL1SLResizeTest() { 1421 SetUpCbr(); 1422 cfg_.g_error_resilient = 0; 1423 cfg_.rc_resize_mode = RESIZE_DYNAMIC; 1424 1425 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1426 1, 0, 400); 1427 cfg_.g_w = 640; 1428 cfg_.g_h = 480; 1429 const int bitrate_array[2] = { 50, 70 }; 1430 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1431 ResetModel(); 1432 SetTargetBitratesFor1SL3TL(); 1433 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1434 CheckDatarate(0.80, 2.0); 1435 #if CONFIG_AV1_DECODER 1436 unsigned int last_w = cfg_.g_w; 1437 unsigned int last_h = cfg_.g_h; 1438 int resize_down_count = 0; 1439 for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); 1440 info != frame_info_list_.end(); ++info) { 1441 if (info->w != last_w || info->h != last_h) { 1442 // Verify that resize down occurs. 1443 ASSERT_LT(info->w, last_w); 1444 ASSERT_LT(info->h, last_h); 1445 last_w = info->w; 1446 last_h = info->h; 1447 resize_down_count++; 1448 } 1449 } 1450 // Must be at least one resize down. 1451 ASSERT_GE(resize_down_count, 1); 1452 #else 1453 printf("Warning: AV1 decoder unavailable, unable to check resize count!\n"); 1454 #endif 1455 } 1456 1457 virtual void BasicRateTargetingSVC1TL2SLTest() { 1458 SetUpCbr(); 1459 cfg_.g_error_resilient = 0; 1460 1461 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1462 288, 30, 1, 0, 300); 1463 const int bitrate_array[2] = { 300, 600 }; 1464 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1465 ResetModel(); 1466 SetTargetBitratesFor2SL1TL(); 1467 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1468 CheckDatarate(0.80, 1.60); 1469 } 1470 1471 virtual void BasicRateTargetingSVC3TL3SLIntraStartDecodeBaseMidSeq() { 1472 SetUpCbr(); 1473 cfg_.rc_max_quantizer = 56; 1474 cfg_.g_error_resilient = 0; 1475 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1476 288, 30, 1, 0, 300); 1477 const int bitrate_array[2] = { 500, 1000 }; 1478 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1479 ResetModel(); 1480 intra_only_ = 1; 1481 frame_sync_ = 20; 1482 frame_to_start_decoding_ = frame_sync_; 1483 layer_to_decode_ = 0; 1484 SetTargetBitratesFor3SL3TL(); 1485 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1486 // Only check datarate on SL0 - this is layer that is decoded starting at 1487 // frame_to_start_decoding_. 1488 CheckDatarate(0.50, 1.60, number_temporal_layers_); 1489 #if CONFIG_AV1_DECODER 1490 // Only base spatial layer is decoded and there are no non-referenece 1491 // frames on S0, so #mismatch must be 0. 1492 EXPECT_EQ((int)GetMismatchFrames(), 0); 1493 #endif 1494 } 1495 1496 virtual void BasicRateTargetingSVC3TL3SLIntraMidSeqDecodeAll() { 1497 SetUpCbr(); 1498 cfg_.rc_max_quantizer = 56; 1499 cfg_.g_error_resilient = 0; 1500 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1501 288, 30, 1, 0, 300); 1502 const int bitrate_array[2] = { 500, 1000 }; 1503 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1504 ResetModel(); 1505 intra_only_ = 1; 1506 frame_sync_ = 20; 1507 frame_to_start_decoding_ = 0; 1508 layer_to_decode_ = 3; 1509 SetTargetBitratesFor3SL3TL(); 1510 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1511 CheckDatarate(0.585, 1.60); 1512 #if CONFIG_AV1_DECODER 1513 // All 3 spatial layers are decoded, starting at frame 0, so there are 1514 // and there 300/2 = 150 non-reference frames, so mismatch is 150. 1515 EXPECT_EQ((int)GetMismatchFrames(), 150); 1516 #endif 1517 } 1518 1519 virtual void BasicRateTargetingSVC3TL3SLSimulcast() { 1520 SetUpCbr(); 1521 cfg_.rc_max_quantizer = 56; 1522 cfg_.g_error_resilient = 0; 1523 cfg_.kf_max_dist = 150; 1524 cfg_.kf_min_dist = 150; 1525 int num_frames = 300; 1526 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1527 288, 30, 1, 0, num_frames); 1528 const int bitrate_array[2] = { 500, 1000 }; 1529 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1530 ResetModel(); 1531 simulcast_mode_ = 1; 1532 frame_to_start_decoding_ = cfg_.kf_max_dist; 1533 layer_to_decode_ = 2; // SL2 1534 SetTargetBitratesFor3SL3TL(); 1535 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1536 // Only SL2 layer is decoded. 1537 for (int tl = 0; tl < number_temporal_layers_; tl++) { 1538 int i = layer_to_decode_ * number_temporal_layers_ + tl; 1539 ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.6) 1540 << " The datarate for the file is lower than target by too much!"; 1541 ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.7) 1542 << " The datarate for the file is greater than target by too much!"; 1543 } 1544 #if CONFIG_AV1_DECODER 1545 // Only top spatial layer (SL2) is decoded, starting at frame 150 1546 // (frame_to_start_decoding_), so there (300 - 150) / 2 = 75 1547 // non-reference frames, so mismatch is 75. 1548 int num_mismatch = (num_frames - frame_to_start_decoding_) / 2; 1549 EXPECT_EQ((int)GetMismatchFrames(), num_mismatch); 1550 #endif 1551 } 1552 1553 virtual void BasicRateTargetingSVC1TL2SLIntraOnlyTest() { 1554 SetUpCbr(); 1555 cfg_.g_error_resilient = 0; 1556 1557 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1558 288, 30, 1, 0, 300); 1559 const int bitrate_array[2] = { 300, 600 }; 1560 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1561 ResetModel(); 1562 intra_only_ = 1; 1563 SetTargetBitratesFor2SL1TL(); 1564 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1565 CheckDatarate(0.80, 1.60); 1566 } 1567 1568 virtual void BasicRateTargetingSVC1TL1SLIntraOnlyTest() { 1569 SetUpCbr(); 1570 cfg_.g_error_resilient = 0; 1571 1572 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1573 288, 30, 1, 0, 300); 1574 const int bitrate_array[2] = { 300, 600 }; 1575 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1576 ResetModel(); 1577 intra_only_single_layer_ = true; 1578 SetTargetBitratesFor1SL1TL(); 1579 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1580 CheckDatarate(0.80, 1.60); 1581 } 1582 1583 virtual void BasicRateTargetingSVC1TL3SLTest() { 1584 SetUpCbr(); 1585 cfg_.g_error_resilient = 0; 1586 1587 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1588 288, 30, 1, 0, 300); 1589 const int bitrate_array[2] = { 500, 1000 }; 1590 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1591 ResetModel(); 1592 SetTargetBitratesFor3SL1TL(); 1593 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1594 CheckDatarate(0.80, 1.38); 1595 } 1596 1597 virtual void BasicRateTargetingSVC1TL3SLLastIsScaledTest() { 1598 SetUpCbr(); 1599 cfg_.g_error_resilient = 0; 1600 1601 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1602 288, 30, 1, 0, 300); 1603 const int bitrate_array[2] = { 500, 1000 }; 1604 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1605 ResetModel(); 1606 use_last_as_scaled_ = true; 1607 SetTargetBitratesFor3SL1TL(); 1608 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1609 CheckDatarate(0.80, 1.38); 1610 } 1611 1612 virtual void BasicRateTargetingSVC1TL3SLLastIsScaledSingleRefTest() { 1613 SetUpCbr(); 1614 cfg_.g_error_resilient = 0; 1615 1616 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1617 288, 30, 1, 0, 300); 1618 const int bitrate_array[2] = { 500, 1000 }; 1619 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1620 ResetModel(); 1621 use_last_as_scaled_ = true; 1622 use_last_as_scaled_single_ref_ = true; 1623 SetTargetBitratesFor3SL1TL(); 1624 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1625 CheckDatarate(0.80, 1.38); 1626 } 1627 1628 virtual void BasicRateTargetingSVC1TL3SLMultiRefTest() { 1629 SetUpCbr(); 1630 cfg_.g_error_resilient = 0; 1631 1632 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1633 288, 30, 1, 0, 300); 1634 const int bitrate_array[2] = { 500, 1000 }; 1635 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1636 ResetModel(); 1637 multi_ref_ = 1; 1638 SetTargetBitratesFor3SL1TL(); 1639 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1640 CheckDatarate(0.80, 1.38); 1641 } 1642 1643 virtual void BasicRateTargetingSVC3TL3SLTest() { 1644 SetUpCbr(); 1645 cfg_.g_error_resilient = 0; 1646 1647 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1648 288, 30, 1, 0, 300); 1649 const int bitrate_array[2] = { 600, 1200 }; 1650 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1651 ResetModel(); 1652 SetTargetBitratesFor3SL3TL(); 1653 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1654 CheckDatarate(0.50, 1.38); 1655 } 1656 1657 virtual void BasicRateTargetingSVC3TL3SLHDTest() { 1658 SetUpCbr(); 1659 cfg_.g_error_resilient = 0; 1660 1661 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 1662 const int bitrate_array[2] = { 600, 1200 }; 1663 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1664 ResetModel(); 1665 SetTargetBitratesFor3SL3TL(); 1666 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1667 CheckDatarate(0.70, 1.45); 1668 } 1669 1670 virtual void BasicRateTargetingFixedModeSVC3TL3SLHDTest() { 1671 SetUpCbr(); 1672 cfg_.g_error_resilient = 0; 1673 1674 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 1675 const int bitrate_array[2] = { 600, 1200 }; 1676 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1677 ResetModel(); 1678 use_fixed_mode_svc_ = 1; 1679 SetTargetBitratesFor3SL3TL(); 1680 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1681 CheckDatarate(0.70, 1.45); 1682 } 1683 1684 virtual void BasicRateTargetingSVC3TL3SLMultiThreadSpeedPerLayerTest() { 1685 SetUpCbr(); 1686 cfg_.g_error_resilient = 0; 1687 cfg_.g_threads = 2; 1688 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1689 1, 0, 400); 1690 cfg_.g_w = 640; 1691 cfg_.g_h = 480; 1692 const int bitrate_array[2] = { 600, 1200 }; 1693 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1694 ResetModel(); 1695 tile_columns_ = 1; 1696 tile_rows_ = 0; 1697 set_speed_per_layer_ = true; 1698 SetTargetBitratesFor3SL3TL(); 1699 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1700 CheckDatarate(0.70, 1.45); 1701 } 1702 1703 virtual void BasicRateTargetingSVC3TL3SLHDMultiThread2Test() { 1704 SetUpCbr(); 1705 cfg_.g_error_resilient = 0; 1706 cfg_.g_threads = 2; 1707 1708 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 1709 const int bitrate_array[2] = { 600, 1200 }; 1710 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1711 ResetModel(); 1712 tile_columns_ = 1; 1713 tile_rows_ = 0; 1714 SetTargetBitratesFor3SL3TL(); 1715 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1716 CheckDatarate(0.70, 1.45); 1717 } 1718 1719 virtual void BasicRateTargetingSVC2TL1SLHDMultiThread4Test() { 1720 SetUpCbr(); 1721 cfg_.g_error_resilient = 0; 1722 cfg_.g_threads = 4; 1723 1724 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 1725 const int bitrate_array[2] = { 600, 1200 }; 1726 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1727 ResetModel(); 1728 tile_columns_ = 1; 1729 tile_rows_ = 1; 1730 SetTargetBitratesFor1SL2TL(); 1731 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1732 CheckDatarate(0.70, 1.45); 1733 } 1734 1735 virtual void BasicRateTargetingSVC2TL1SLHDMultiThread4AutoTilesTest() { 1736 SetUpCbr(); 1737 cfg_.g_error_resilient = 0; 1738 cfg_.g_threads = 4; 1739 1740 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 1741 const int bitrate_array[2] = { 600, 1200 }; 1742 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1743 ResetModel(); 1744 auto_tiles_ = 1; 1745 SetTargetBitratesFor1SL2TL(); 1746 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1747 CheckDatarate(0.70, 1.45); 1748 } 1749 1750 virtual void BasicRateTargetingSVC3TL3SLHDMultiThread4Test() { 1751 SetUpCbr(); 1752 cfg_.g_error_resilient = 0; 1753 cfg_.g_threads = 4; 1754 1755 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 1756 const int bitrate_array[2] = { 600, 1200 }; 1757 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1758 ResetModel(); 1759 tile_columns_ = 1; 1760 tile_rows_ = 1; 1761 SetTargetBitratesFor3SL3TL(); 1762 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1763 CheckDatarate(0.70, 1.45); 1764 } 1765 1766 virtual void BasicRateTargetingSVC3TL3SLHDMultiRefTest() { 1767 SetUpCbr(); 1768 cfg_.g_error_resilient = 0; 1769 1770 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 1771 const int bitrate_array[2] = { 600, 1200 }; 1772 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1773 ResetModel(); 1774 multi_ref_ = 1; 1775 SetTargetBitratesFor3SL3TL(); 1776 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1777 CheckDatarate(0.70, 1.45); 1778 } 1779 1780 virtual void BasicRateTargetingSVC3TL3SLKfTest() { 1781 SetUpCbr(); 1782 cfg_.g_error_resilient = 0; 1783 cfg_.kf_mode = AOM_KF_AUTO; 1784 cfg_.kf_min_dist = cfg_.kf_max_dist = 100; 1785 1786 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1787 288, 30, 1, 0, 300); 1788 const int bitrate_array[2] = { 600, 1200 }; 1789 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1790 ResetModel(); 1791 SetTargetBitratesFor3SL3TL(); 1792 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1793 CheckDatarate(0.55, 1.4); 1794 } 1795 1796 virtual void BasicRateTargeting444SVC3TL3SLTest() { 1797 SetUpCbr(); 1798 cfg_.g_error_resilient = 0; 1799 cfg_.g_profile = 1; 1800 1801 ::libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140); 1802 1803 const int bitrate_array[2] = { 600, 1200 }; 1804 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1805 ResetModel(); 1806 SetTargetBitratesFor3SL3TL(); 1807 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1808 CheckDatarate(0.70, 1.38); 1809 } 1810 1811 virtual void BasicRateTargetingSVC3TL1SLMultiRefDropAllEnhTest() { 1812 SetUpCbr(); 1813 // error_resilient can set to off/0, since for SVC the context update 1814 // is done per-layer. 1815 cfg_.g_error_resilient = 0; 1816 1817 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1818 288, 30, 1, 0, 300); 1819 const int bitrate_array[2] = { 200, 550 }; 1820 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1821 ResetModel(); 1822 multi_ref_ = 1; 1823 // Drop TL1 and TL2: #frames(300) - #TL0. 1824 drop_frames_ = 300 - 300 / 4; 1825 int n = 0; 1826 for (int i = 0; i < 300; i++) { 1827 if (i % 4 != 0) { 1828 drop_frames_list_[n] = i; 1829 n++; 1830 } 1831 } 1832 SetTargetBitratesFor1SL3TL(); 1833 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1834 CheckDatarate(0.60, 1.60); 1835 #if CONFIG_AV1_DECODER 1836 // Test that no mismatches have been found. 1837 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 1838 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 1839 EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_); 1840 EXPECT_EQ((int)GetMismatchFrames(), 0); 1841 #endif 1842 } 1843 1844 virtual void BasicRateTargetingSVC3TL1SLDropAllEnhTest() { 1845 SetUpCbr(); 1846 // error_resilient can set to off/0, since for SVC the context update 1847 // is done per-layer. 1848 cfg_.g_error_resilient = 0; 1849 1850 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1851 288, 30, 1, 0, 300); 1852 const int bitrate_array[2] = { 200, 550 }; 1853 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1854 ResetModel(); 1855 // Drop TL1 and TL2: #frames(300) - #TL0. 1856 drop_frames_ = 300 - 300 / 4; 1857 int n = 0; 1858 for (int i = 0; i < 300; i++) { 1859 if (i % 4 != 0) { 1860 drop_frames_list_[n] = i; 1861 n++; 1862 } 1863 } 1864 SetTargetBitratesFor1SL3TL(); 1865 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1866 CheckDatarate(0.60, 1.60); 1867 #if CONFIG_AV1_DECODER 1868 // Test that no mismatches have been found. 1869 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 1870 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 1871 EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_); 1872 EXPECT_EQ((int)GetMismatchFrames(), 0); 1873 #endif 1874 } 1875 1876 virtual void BasicRateTargetingSVC3TL1SLDropTL2EnhTest() { 1877 SetUpCbr(); 1878 // error_resilient for sequence can be off/0, since dropped frames (TL2) 1879 // are non-reference frames. 1880 cfg_.g_error_resilient = 0; 1881 1882 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1883 288, 30, 1, 0, 300); 1884 const int bitrate_array[2] = { 200, 550 }; 1885 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1886 ResetModel(); 1887 // Drop TL2: #frames(300) - (#TL0 + #TL1). 1888 drop_frames_ = 300 - 300 / 2; 1889 int n = 0; 1890 for (int i = 0; i < 300; i++) { 1891 if (i % 2 != 0) { 1892 drop_frames_list_[n] = i; 1893 n++; 1894 } 1895 } 1896 SetTargetBitratesFor1SL3TL(); 1897 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1898 CheckDatarate(0.60, 1.60); 1899 #if CONFIG_AV1_DECODER 1900 // Test that no mismatches have been found. 1901 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 1902 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 1903 EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_); 1904 EXPECT_EQ((int)GetMismatchFrames(), 0); 1905 #endif 1906 } 1907 1908 virtual void BasicRateTargetingSVC3TL1SLDropAllEnhFrameERTest() { 1909 SetUpCbr(); 1910 1911 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1912 288, 30, 1, 0, 300); 1913 const int bitrate_array[2] = { 200, 550 }; 1914 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1915 ResetModel(); 1916 // Set error_resilience at frame level, with codec control, 1917 // on/1 for enahancement layers and off/0 for base layer frames. 1918 set_frame_level_er_ = 1; 1919 1920 // Drop TL1 and TL2: #frames(300) - #TL0. 1921 drop_frames_ = 300 - 300 / 4; 1922 int n = 0; 1923 for (int i = 0; i < 300; i++) { 1924 if (i % 4 != 0) { 1925 drop_frames_list_[n] = i; 1926 n++; 1927 } 1928 } 1929 SetTargetBitratesFor1SL3TL(); 1930 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1931 CheckDatarate(0.60, 1.60); 1932 #if CONFIG_AV1_DECODER 1933 // Test that no mismatches have been found. 1934 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 1935 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 1936 EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_); 1937 EXPECT_EQ((int)GetMismatchFrames(), 0); 1938 #endif 1939 } 1940 1941 virtual void BasicRateTargetingSVC3TL1SLDropSetEnhFrameERTest() { 1942 SetUpCbr(); 1943 1944 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1945 288, 30, 1, 0, 300); 1946 const int bitrate_array[2] = { 200, 550 }; 1947 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1948 ResetModel(); 1949 // Set error_resilience at frame level, with codec control, 1950 // on/1 for enahancement layers and off/0 for base layer frames. 1951 set_frame_level_er_ = 1; 1952 1953 // Drop TL1 and TL2: for part of sequence. Start at first TL2 at 1954 // frame 101, and end at second T2 at frame 199. Frame 200 is TL0, 1955 // so we can continue decoding without mismatch (since LAST is the 1956 // only reference and error_resilient = 1 on TL1/TL2 frames). 1957 int n = 0; 1958 #if CONFIG_AV1_DECODER 1959 int num_nonref = 300 / 2; 1960 #endif 1961 for (int i = 101; i < 200; i++) { 1962 if (i % 4 != 0) { 1963 drop_frames_list_[n] = i; 1964 n++; 1965 #if CONFIG_AV1_DECODER 1966 if (i % 2 != 0) num_nonref -= 1; 1967 #endif 1968 } 1969 } 1970 drop_frames_ = n; 1971 SetTargetBitratesFor1SL3TL(); 1972 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 1973 CheckDatarate(0.60, 1.60); 1974 #if CONFIG_AV1_DECODER 1975 // Test that no mismatches have been found. 1976 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 1977 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 1978 EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_); 1979 EXPECT_EQ((int)GetMismatchFrames(), num_nonref); 1980 #endif 1981 } 1982 1983 virtual void BasicRateTargetingSVC2TL1SLDropSetEnhER0Test() { 1984 SetUpCbr(); 1985 1986 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 1987 288, 30, 1, 0, 300); 1988 const int bitrate_array[2] = { 200, 550 }; 1989 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 1990 ResetModel(); 1991 1992 // Set error_resilience off. 1993 cfg_.g_error_resilient = 0; 1994 1995 // Drop TL1: for part of sequence. Start at first TL1 at 1996 // frame 101, and end at frame 199. Frame 200 is TL0, 1997 // so we can continue decoding without mismatch (since LAST is the 1998 // only reference). 1999 int n = 0; 2000 #if CONFIG_AV1_DECODER 2001 int num_nonref = 300 / 2; 2002 #endif 2003 for (int i = 101; i < 200; i++) { 2004 if (i % 2 != 0) { 2005 drop_frames_list_[n] = i; 2006 n++; 2007 #if CONFIG_AV1_DECODER 2008 if (i % 2 != 0) num_nonref -= 1; 2009 #endif 2010 } 2011 } 2012 drop_frames_ = n; 2013 number_temporal_layers_ = 2; 2014 target_layer_bitrate_[0] = 70 * cfg_.rc_target_bitrate / 100; 2015 target_layer_bitrate_[1] = cfg_.rc_target_bitrate; 2016 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2017 CheckDatarate(0.60, 1.60); 2018 #if CONFIG_AV1_DECODER 2019 // Test that no mismatches have been found. 2020 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 2021 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 2022 EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_); 2023 EXPECT_EQ((int)GetMismatchFrames(), num_nonref); 2024 #endif 2025 } 2026 2027 virtual void BasicRateTargetingSVC3TL1SLDropSetEnhER0Test() { 2028 SetUpCbr(); 2029 2030 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 2031 288, 30, 1, 0, 300); 2032 const int bitrate_array[2] = { 200, 550 }; 2033 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2034 ResetModel(); 2035 2036 // Set error_resilience off. 2037 cfg_.g_error_resilient = 0; 2038 2039 // Drop TL1 and TL2: for part of sequence. Start at first TL2 at 2040 // frame 101, and end at second T2 at frame 199. Frame 200 is TL0, 2041 // so we can continue decoding without mismatch (since LAST is the 2042 // only reference). 2043 int n = 0; 2044 #if CONFIG_AV1_DECODER 2045 int num_nonref = 300 / 2; 2046 #endif 2047 for (int i = 101; i < 200; i++) { 2048 if (i % 4 != 0) { 2049 drop_frames_list_[n] = i; 2050 n++; 2051 #if CONFIG_AV1_DECODER 2052 if (i % 2 != 0) num_nonref -= 1; 2053 #endif 2054 } 2055 } 2056 drop_frames_ = n; 2057 SetTargetBitratesFor1SL3TL(); 2058 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2059 CheckDatarate(0.60, 1.60); 2060 #if CONFIG_AV1_DECODER 2061 // Test that no mismatches have been found. 2062 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 2063 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 2064 EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_); 2065 EXPECT_EQ((int)GetMismatchFrames(), num_nonref); 2066 #endif 2067 } 2068 2069 virtual void BasicRateTargetingSVC3TL3SLDropSetEnhER0Test() { 2070 SetUpCbr(); 2071 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 2072 288, 30, 1, 0, 300); 2073 const int bitrate_array[2] = { 200, 550 }; 2074 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2075 ResetModel(); 2076 // Set error_resilience off. 2077 cfg_.g_error_resilient = 0; 2078 // Drop TL1 and TL2: for part of sequence. Start at first TL2 at 2079 // frame 101, and end at second T2 at frame 199. Frame 200 is TL0, 2080 // so we can continue decoding without mismatch (since LAST is the 2081 // only reference). 2082 // Drop here means drop whole superframe. 2083 int n = 0; 2084 #if CONFIG_AV1_DECODER 2085 int num_nonref = 300 / 2; 2086 #endif 2087 for (int i = 101; i < 200; i++) { 2088 if (i % 4 != 0) { 2089 drop_frames_list_[n] = i; 2090 n++; 2091 #if CONFIG_AV1_DECODER 2092 if (i % 2 != 0) num_nonref -= 1; 2093 #endif 2094 } 2095 } 2096 SetTargetBitratesFor3SL3TL(); 2097 multi_ref_ = 1; 2098 drop_frames_ = n * number_spatial_layers_; 2099 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2100 CheckDatarate(0.60, 1.60); 2101 #if CONFIG_AV1_DECODER 2102 // Test that no mismatches have been found. 2103 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 2104 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 2105 EXPECT_EQ(300 * number_spatial_layers_ - GetDecodedFrames(), drop_frames_); 2106 EXPECT_EQ((int)GetMismatchFrames(), num_nonref); 2107 #endif 2108 } 2109 2110 virtual void BasicRateTargetingSVC3TL1SLMultiRefCompoundTest() { 2111 SetUpCbr(); 2112 cfg_.g_error_resilient = 0; 2113 2114 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 2115 1, 0, 400); 2116 cfg_.g_w = 640; 2117 cfg_.g_h = 480; 2118 const int bitrate_array[2] = { 400, 800 }; 2119 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2120 ResetModel(); 2121 multi_ref_ = 1; 2122 comp_pred_ = 1; 2123 SetTargetBitratesFor1SL3TL(); 2124 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2125 CheckDatarate(0.80, 1.60); 2126 } 2127 2128 virtual void BasicRateTargetingSVC1TL3SLDynEnablTest() { 2129 SetUpCbr(); 2130 cfg_.g_error_resilient = 0; 2131 2132 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 2133 1, 0, 400); 2134 const int bitrate_array[2] = { 500, 1000 }; 2135 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2136 ResetModel(); 2137 SetTargetBitratesFor3SL1TL(); 2138 dynamic_enable_disable_mode_ = 1; 2139 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2140 // No need to check RC on top layer which is disabled part of the time. 2141 CheckDatarate(0.80, 1.38, number_spatial_layers_ - 1); 2142 } 2143 2144 virtual void BasicRateTargetingSVC1TL3SLDynDisEnablTest() { 2145 SetUpCbr(); 2146 cfg_.g_error_resilient = 0; 2147 2148 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 2149 288, 30, 1, 0, 300); 2150 const int bitrate_array[2] = { 500, 1000 }; 2151 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2152 ResetModel(); 2153 SetTargetBitratesFor3SL1TL(); 2154 dynamic_enable_disable_mode_ = 2; 2155 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2156 // No need to check RC on top layer which is disabled part of the time. 2157 CheckDatarate(0.80, 1.38, number_spatial_layers_ - 1); 2158 } 2159 2160 virtual void BasicRateTargetingRPS1TL1SLDropFramesTest() { 2161 SetUpCbr(); 2162 2163 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 2164 288, 30, 1, 0, 300); 2165 const int bitrate_array[2] = { 100, 300 }; 2166 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2167 ResetModel(); 2168 rps_mode_ = 1; 2169 rps_recovery_frame_ = 100; 2170 cfg_.g_error_resilient = 0; 2171 // Drop x frames before the recovery frames (where the reference 2172 // is switched to an older reference (golden or altref). 2173 // GOLDEN is 8 frames behind (for the rps pattern example) so we can't 2174 // drop more than 8 frames recovery frame, so choose x = 7. 2175 int n = 0; 2176 for (int i = rps_recovery_frame_ - 7; i < rps_recovery_frame_; i++) { 2177 drop_frames_list_[n] = i; 2178 n++; 2179 } 2180 drop_frames_ = n; 2181 SetTargetBitratesFor1SL1TL(); 2182 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2183 CheckDatarate(0.60, 1.60); 2184 #if CONFIG_AV1_DECODER 2185 // Test that no mismatches have been found. 2186 std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; 2187 std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; 2188 EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_); 2189 EXPECT_EQ((int)GetMismatchFrames(), 0); 2190 #endif 2191 } 2192 2193 virtual void BasicRateTargetingSVC3TL3SLExternalResizePattern1Test() { 2194 SetUpCbr(); 2195 cfg_.g_error_resilient = 0; 2196 const int bitrate_array[2] = { 600, 1200 }; 2197 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2198 cfg_.g_w = 1280; 2199 cfg_.g_h = 720; 2200 ResizingVideoSource video(1, 1280, 720); 2201 ResetModel(); 2202 external_resize_dynamic_drop_layer_ = true; 2203 external_resize_pattern_ = 1; 2204 SetTargetBitratesFor3SL3TL(); 2205 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2206 } 2207 2208 virtual void BasicRateTargetingSVC3TL3SLExternalResizePattern1HighResTest() { 2209 SetUpCbr(); 2210 cfg_.g_error_resilient = 0; 2211 const int bitrate_array[2] = { 600, 1200 }; 2212 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2213 cfg_.g_w = 1850; 2214 cfg_.g_h = 1110; 2215 cfg_.g_forced_max_frame_width = 1850; 2216 cfg_.g_forced_max_frame_height = 1110; 2217 ResizingVideoSource video(1, 1850, 1110); 2218 ResetModel(); 2219 external_resize_dynamic_drop_layer_ = true; 2220 external_resize_pattern_ = 1; 2221 SetTargetBitratesFor3SL3TL(); 2222 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2223 } 2224 2225 virtual void BasicRateTargetingSVC3TL3SLExternalResizePattern2Test() { 2226 SetUpCbr(); 2227 cfg_.g_error_resilient = 0; 2228 const int bitrate_array[2] = { 600, 1200 }; 2229 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2230 cfg_.g_w = 1280; 2231 cfg_.g_h = 720; 2232 ResizingVideoSource video(2, 1280, 720); 2233 ResetModel(); 2234 external_resize_dynamic_drop_layer_ = true; 2235 external_resize_pattern_ = 2; 2236 SetTargetBitratesFor3SL3TL(); 2237 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2238 } 2239 2240 virtual void BasicRateTargetingSVC3TL3SLExternalResizePattern2HighResTest() { 2241 SetUpCbr(); 2242 cfg_.g_error_resilient = 0; 2243 const int bitrate_array[2] = { 600, 1200 }; 2244 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2245 cfg_.g_w = 1850; 2246 cfg_.g_h = 1110; 2247 cfg_.g_forced_max_frame_width = 1850; 2248 cfg_.g_forced_max_frame_height = 1110; 2249 ResizingVideoSource video(2, 1850, 1110); 2250 ResetModel(); 2251 external_resize_dynamic_drop_layer_ = true; 2252 external_resize_pattern_ = 2; 2253 SetTargetBitratesFor3SL3TL(); 2254 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2255 } 2256 2257 virtual void BasicRateTargetingSVC3TL1SLDynamicTLTest() { 2258 SetUpCbr(); 2259 cfg_.g_error_resilient = 0; 2260 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 2261 1, 0, 400); 2262 const int bitrate_array[2] = { 600, 1200 }; 2263 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2264 target_layer_bitrate_[0] = cfg_.rc_target_bitrate; 2265 cfg_.g_w = 640; 2266 cfg_.g_h = 480; 2267 ResetModel(); 2268 number_temporal_layers_ = 1; 2269 number_spatial_layers_ = 1; 2270 dynamic_tl_ = true; 2271 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2272 } 2273 2274 virtual void BasicRateTargetingSVC1TL3SLIssue433046392() { 2275 cfg_.rc_buf_initial_sz = 500; 2276 cfg_.rc_buf_optimal_sz = 500; 2277 cfg_.rc_buf_sz = 1000; 2278 cfg_.rc_dropframe_thresh = 0; 2279 cfg_.rc_min_quantizer = 0; 2280 cfg_.rc_max_quantizer = 63; 2281 cfg_.rc_end_usage = AOM_CBR; 2282 cfg_.g_lag_in_frames = 0; 2283 cfg_.g_error_resilient = 0; 2284 const int bitrate_array[2] = { 600, 1200 }; 2285 cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; 2286 cfg_.g_w = 1280; 2287 cfg_.g_h = 720; 2288 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); 2289 ResetModel(); 2290 dynamic_scale_factors_ = true; 2291 number_temporal_layers_ = 1; 2292 number_spatial_layers_ = 3; 2293 target_layer_bitrate_[0] = 1 * cfg_.rc_target_bitrate / 8; 2294 target_layer_bitrate_[1] = 3 * cfg_.rc_target_bitrate / 8; 2295 target_layer_bitrate_[2] = 4 * cfg_.rc_target_bitrate / 8; 2296 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 2297 } 2298 2299 int layer_frame_cnt_; 2300 int superframe_cnt_; 2301 int number_temporal_layers_; 2302 int number_spatial_layers_; 2303 // Allow for up to 3 temporal layers. 2304 int target_layer_bitrate_[AOM_MAX_LAYERS]; 2305 aom_svc_params_t svc_params_; 2306 aom_svc_ref_frame_config_t ref_frame_config_; 2307 aom_svc_ref_frame_comp_pred_t ref_frame_comp_pred_; 2308 aom_svc_layer_id_t layer_id_; 2309 double effective_datarate_tl[AOM_MAX_LAYERS]; 2310 unsigned int drop_frames_; 2311 unsigned int drop_frames_list_[1000]; 2312 unsigned int mismatch_nframes_; 2313 unsigned int decoded_nframes_; 2314 double mismatch_psnr_; 2315 int set_frame_level_er_; 2316 int multi_ref_; 2317 int use_fixed_mode_svc_; 2318 int comp_pred_; 2319 int dynamic_enable_disable_mode_; 2320 int intra_only_; 2321 int intra_only_single_layer_; 2322 unsigned int frame_to_start_decoding_; 2323 unsigned int layer_to_decode_; 2324 unsigned int frame_sync_; 2325 unsigned int current_video_frame_; 2326 int screen_mode_; 2327 int rps_mode_; 2328 int rps_recovery_frame_; 2329 int simulcast_mode_; 2330 bool use_last_as_scaled_; 2331 bool use_last_as_scaled_single_ref_; 2332 2333 int user_define_frame_qp_; 2334 int frame_qp_; 2335 int total_frame_; 2336 bool set_speed_per_layer_; 2337 libaom_test::ACMRandom rnd_; 2338 bool external_resize_dynamic_drop_layer_; 2339 int bitrate_layer_[9]; 2340 int external_resize_pattern_; 2341 bool dynamic_tl_; 2342 bool dynamic_scale_factors_; 2343 }; 2344 2345 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial. 2346 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SL) { 2347 BasicRateTargetingSVC3TL1SLTest(); 2348 } 2349 2350 TEST_P(DatarateTestSVC, SetFrameQpSVC3TL1SL) { SetFrameQpSVC3TL1SLTest(); } 2351 2352 TEST_P(DatarateTestSVC, SetFrameQpSVC3TL3SL) { SetFrameQpSVC3TL3SLTest(); } 2353 2354 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial 2355 // for screen mode. 2356 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLScreen) { 2357 BasicRateTargetingSVC3TL1SLScreenTest(); 2358 } 2359 2360 // Check basic rate targeting for CBR, for 2 temporal layers, 1 spatial 2361 // for screen mode, with frame dropper on at low bitrates. Use small 2362 // values of rc_buf_initial/optimal/sz to trigger postencode frame drop. 2363 TEST_P(DatarateTestSVC, BasicRateTargetingSVC2TL1SLScreenDropFrame) { 2364 BasicRateTargetingSVC2TL1SLScreenDropFrameTest(); 2365 } 2366 2367 // Check basic rate targeting for CBR, for 2 temporal layers, 1 spatial 2368 // for screen mode, with frame dropper on at low bitrates. Use small 2369 // values of rc_buf_initial/optimal/sz to trigger postencode frame drop. 2370 // Use 1920x1080 clip. 2371 TEST_P(DatarateTestSVC, BasicRateTargetingSVC2TL1SLScreenDropFrame1920x1080) { 2372 BasicRateTargetingSVC2TL1SLScreenDropFrame1920x1080Test(); 2373 } 2374 2375 // Check basic rate targeting for CBR, for 2 temporal layers, 1 spatial 2376 // for screen mode, with frame dropper on at low bitrates. Use small 2377 // values of rc_buf_initial/optimal/sz to trigger postencode frame drop. 2378 // Use 1920x1080 clip. This test runs with 4 threads. 2379 TEST_P(DatarateTestSVC, 2380 BasicRateTargetingSVC2TL1SLScreenDropFrame1920x10804Thread) { 2381 BasicRateTargetingSVC2TL1SLScreenDropFrame1920x10804ThreadTest(); 2382 } 2383 2384 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal 2385 // for screen mode. 2386 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLScreen) { 2387 BasicRateTargetingSVC1TL3SLScreenTest(); 2388 } 2389 2390 // Check basic rate targeting for CBR, for 1 temporal layer, 1 spatial 2391 // for screen mode, with source with many scene cuts and motion. 2392 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL1SLScreenScCutsMotion) { 2393 BasicRateTargetingSVC1TL1SLScreenScCutsMotionTest(); 2394 } 2395 2396 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial, 2397 // with dynamic resize on. Encode at very low bitrate and check that 2398 // there is at least one resize (down) event. 2399 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLResize) { 2400 BasicRateTargetingSVC3TL1SLResizeTest(); 2401 } 2402 2403 // Check basic rate targeting for CBR, for 2 spatial layers, 1 temporal. 2404 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL2SL) { 2405 BasicRateTargetingSVC1TL2SLTest(); 2406 } 2407 2408 // Check basic rate targeting for CBR, for 3 spatial layers, 3 temporal, 2409 // with Intra-only frame inserted in the stream. Verify that we can start 2410 // decoding the SL0 stream at the intra_only frame in mid-sequence. 2411 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLIntraStartDecodeBaseMidSeq) { 2412 BasicRateTargetingSVC3TL3SLIntraStartDecodeBaseMidSeq(); 2413 } 2414 2415 // Check basic rate targeting for CBR, for 3spatial layers, 3 temporal, 2416 // with Intra-only frame inserted in the stream. Verify that we can 2417 // decode all frames and layers with no mismatch. 2418 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLIntraMidSeqDecodeAll) { 2419 BasicRateTargetingSVC3TL3SLIntraMidSeqDecodeAll(); 2420 } 2421 2422 // Check simulcast mode for 3 spatial layers, 3 temporal, 2423 // Key frame is inserted on base SLO in mid-stream, and verify that the 2424 // top spatial layer (SL2) case be decoded, starting with an Intra-only frame. 2425 // Verify that we can decode all frames for SL2 with no mismatch. 2426 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLSimulcast) { 2427 BasicRateTargetingSVC3TL3SLSimulcast(); 2428 } 2429 2430 // Check basic rate targeting for CBR, for 2 spatial layers, 1 temporal, 2431 // with Intra-only frame inserted in the stream. 2432 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL2SLIntraOnly) { 2433 BasicRateTargetingSVC1TL2SLIntraOnlyTest(); 2434 } 2435 2436 // Check basic rate targeting for CBR, for 1 spatial layers, 1 temporal, 2437 // with Intra-only frame (frame with no references) inserted in the stream. 2438 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL1SLIntraOnly) { 2439 BasicRateTargetingSVC1TL1SLIntraOnlyTest(); 2440 } 2441 2442 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal. 2443 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SL) { 2444 BasicRateTargetingSVC1TL3SLTest(); 2445 } 2446 2447 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal. 2448 // Force the spatial reference to be LAST, with a second temporal 2449 // reference (GOLDEN). 2450 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLLastIsScaled) { 2451 BasicRateTargetingSVC1TL3SLLastIsScaledTest(); 2452 } 2453 2454 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal. 2455 // Force the spatial reference to be LAST, and force only 1 reference. 2456 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLastIsScaledSingleRef) { 2457 BasicRateTargetingSVC1TL3SLLastIsScaledSingleRefTest(); 2458 } 2459 2460 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal, 2461 // with additional temporal reference for top spatial layer. 2462 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLMultiRef) { 2463 BasicRateTargetingSVC1TL3SLMultiRefTest(); 2464 } 2465 2466 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers. 2467 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SL) { 2468 BasicRateTargetingSVC3TL3SLTest(); 2469 } 2470 2471 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers. 2472 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHD) { 2473 BasicRateTargetingSVC3TL3SLHDTest(); 2474 } 2475 2476 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, 2477 // for fixed mode SVC. 2478 TEST_P(DatarateTestSVC, BasicRateTargetingFixedModeSVC3TL3SLHD) { 2479 BasicRateTargetingFixedModeSVC3TL3SLHDTest(); 2480 } 2481 2482 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, 2483 // for 2 threads, 2 tile_columns, row-mt enabled, and different speed 2484 // per layer. 2485 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLMultiThreadSpeedPerLayer) { 2486 BasicRateTargetingSVC3TL3SLMultiThreadSpeedPerLayerTest(); 2487 } 2488 2489 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, 2490 // for 2 threads, 2 tile_columns, row-mt enabled. 2491 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMultiThread2) { 2492 BasicRateTargetingSVC3TL3SLHDMultiThread2Test(); 2493 } 2494 2495 // Check basic rate targeting for CBR, for 1 spatial, 2 temporal layers, 2496 // for 4 threads, 2 tile_columns, 2 tiles_rows, row-mt enabled. 2497 TEST_P(DatarateTestSVC, BasicRateTargetingSVC2TL1SLHDMultiThread4) { 2498 BasicRateTargetingSVC2TL1SLHDMultiThread4Test(); 2499 } 2500 2501 // Check basic rate targeting for CBR, for 1 spatial, 2 temporal layers, 2502 // for 4 threads, row-mt enabled, and auto_tiling enabled. 2503 TEST_P(DatarateTestSVC, BasicRateTargetingSVC2TL1SLHDMultiThread4AutoTiles) { 2504 BasicRateTargetingSVC2TL1SLHDMultiThread4AutoTilesTest(); 2505 } 2506 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, 2507 // for 4 threads, 2 tile_columns, 2 tiles_rows, row-mt enabled. 2508 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMultiThread4) { 2509 BasicRateTargetingSVC3TL3SLHDMultiThread4Test(); 2510 } 2511 2512 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, 2513 // with additional temporal reference for top spatial layer. 2514 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMultiRef) { 2515 BasicRateTargetingSVC3TL3SLHDMultiRefTest(); 2516 } 2517 2518 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, 2519 // for auto key frame mode with short key frame period. 2520 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLKf) { 2521 BasicRateTargetingSVC3TL3SLKfTest(); 2522 } 2523 2524 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, 2525 // for 4:4:4 input. 2526 #if defined(CONFIG_MAX_DECODE_PROFILE) && CONFIG_MAX_DECODE_PROFILE < 1 2527 TEST_P(DatarateTestSVC, DISABLED_BasicRateTargeting444SVC3TL3SL) { 2528 #else 2529 TEST_P(DatarateTestSVC, BasicRateTargeting444SVC3TL3SL) { 2530 #endif 2531 BasicRateTargeting444SVC3TL3SLTest(); 2532 } 2533 2534 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer, 2535 // with dropping of all enhancement layers (TL 1 and TL2). Check that the base 2536 // layer (TL0) can still be decodeable (with no mismatch) with the 2537 // error_resilient flag set to 0. This test used the pattern with multiple 2538 // references (last, golden, and altref), updated on base layer. 2539 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLMultiRefDropAllEnh) { 2540 BasicRateTargetingSVC3TL1SLMultiRefDropAllEnhTest(); 2541 } 2542 2543 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer, 2544 // with dropping of all enhancement layers (TL 1 and TL2). Check that the base 2545 // layer (TL0) can still be decodeable (with no mismatch) with the 2546 // error_resilient flag set to 0. 2547 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropAllEnh) { 2548 BasicRateTargetingSVC3TL1SLDropAllEnhTest(); 2549 } 2550 2551 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer, 2552 // with dropping of the TL2 enhancement layer, which are non-reference 2553 // (droppble) frames. For the base layer (TL0) and TL1 to still be decodeable 2554 // (with no mismatch), the error_resilient_flag may be off (set to 0), 2555 // since TL2 are non-reference frames. 2556 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropTL2Enh) { 2557 BasicRateTargetingSVC3TL1SLDropTL2EnhTest(); 2558 } 2559 2560 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer, 2561 // with dropping of all enhancement layers (TL 1 and TL2). Test that the 2562 // error_resilient flag can be set at frame level, with on/1 on 2563 // enhancement layers and off/0 on base layer. 2564 // This allows for successful decoding after dropping enhancement layer frames. 2565 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropAllEnhFrameER) { 2566 BasicRateTargetingSVC3TL1SLDropAllEnhFrameERTest(); 2567 } 2568 2569 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer, 2570 // with dropping set of enhancement layers (TL 1 and TL2) in middle of sequence. 2571 // Test that the error_resilient flag can be set at frame level, with on/1 on 2572 // enhancement layers and off/0 on base layer. 2573 // This allows for successful decoding after dropping a set enhancement layer 2574 // frames in the sequence. 2575 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropSetEnhFrameER) { 2576 BasicRateTargetingSVC3TL1SLDropSetEnhFrameERTest(); 2577 } 2578 2579 // Check basic rate targeting for CBR, for 2 temporal layers, 1 spatial layer, 2580 // with dropping set of enhancement layers (TL 1) in middle of sequence. 2581 // Test that the error_resilient flag can be 0/off for all frames. 2582 // This allows for successful decoding after dropping a set enhancement layer 2583 // frames in the sequence. 2584 TEST_P(DatarateTestSVC, BasicRateTargetingSVC2TL1SLDropSetEnhER0) { 2585 BasicRateTargetingSVC2TL1SLDropSetEnhER0Test(); 2586 } 2587 2588 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer, 2589 // with dropping set of enhancement layers (TL 1 and TL2) in middle of sequence. 2590 // Test that the error_resilient flag can be 0/off for all frames. 2591 // This allows for successful decoding after dropping a set enhancement layer 2592 // frames in the sequence. 2593 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropSetEnhER0) { 2594 BasicRateTargetingSVC3TL1SLDropSetEnhER0Test(); 2595 } 2596 2597 // Check basic rate targeting for CBR, for 3 temporal layers, 3 spatial layers, 2598 // with dropping set of enhancement layers (superframe TL 1 and TL2) in middle 2599 // of sequence. Test that the error_resilient flag can be 0/off for all frames. 2600 // This allows for successful decoding after dropping a set enhancement layer 2601 // frames in the sequence. 2602 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLDropSetEnhER0) { 2603 BasicRateTargetingSVC3TL3SLDropSetEnhER0Test(); 2604 } 2605 2606 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer, 2607 // with compound prediction on, for pattern with two additional refereces 2608 // (golden and altref), both updated on base TLO frames. 2609 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLMultiRefCompound) { 2610 BasicRateTargetingSVC3TL1SLMultiRefCompoundTest(); 2611 } 2612 2613 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal, 2614 // with the top spatial layer starting disabled (0 bitrate) and then 2615 // dynamically enabled after x frames with nonzero bitrate. 2616 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLDynEnabl) { 2617 BasicRateTargetingSVC1TL3SLDynEnablTest(); 2618 } 2619 2620 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal, 2621 // with the top spatial layer dynamically disabled snd enabled during the 2622 // middle of the sequence. 2623 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLDynDisEnabl) { 2624 BasicRateTargetingSVC1TL3SLDynDisEnablTest(); 2625 } 2626 2627 // Check basic rate targeting and encoder/decodermismatch, for RPS 2628 // with 1 layer. A number of consecutive frames are lost midway in 2629 // sequence, and encoder resorts to a longer term reference to recovery 2630 // and continue decoding successfully. 2631 TEST_P(DatarateTestSVC, BasicRateTargetingRPS1TL1SLDropFrames) { 2632 BasicRateTargetingRPS1TL1SLDropFramesTest(); 2633 } 2634 2635 // For 1 pass CBR SVC with 3 spatial and 3 temporal layers with external resize 2636 // and denoiser enabled. The external resizer will resize down and back up, 2637 // setting 0/nonzero bitrate on spatial enhancement layers to disable/enable 2638 // layers. Resizing starts on first frame and the pattern is: 2639 // 1/4 -> 1/2 -> 1 -> 1/4 -> 1/2. Configured resolution is 1280x720. 2640 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLExternalResizePattern1) { 2641 BasicRateTargetingSVC3TL3SLExternalResizePattern1Test(); 2642 } 2643 2644 // For 1 pass CBR SVC with 3 spatial and 3 temporal layers with external resize 2645 // and denoiser enabled. The external resizer will resize down and back up, 2646 // setting 0/nonzero bitrate on spatial enhancement layers to disable/enable 2647 // layers. Resizing starts on first frame and the pattern is: 2648 // 1/4 -> 1/2 -> 1 -> 1/4 -> 1/2. Configured resolution is 1850x1110. 2649 TEST_P(DatarateTestSVC, 2650 BasicRateTargetingSVC3TL3SLExternalResizePattern1HighRes) { 2651 BasicRateTargetingSVC3TL3SLExternalResizePattern1HighResTest(); 2652 } 2653 2654 // For 1 pass CBR SVC with 3 spatial and 3 temporal layers with external resize 2655 // and denoiser enabled. The external resizer will resize down and back up, 2656 // setting 0/nonzero bitrate on spatial enhancement layers to disable/enable 2657 // layers. Resizing starts on first frame and the pattern is: 2658 // 1/2 -> 1/4 -> 1 -> 1/2 -> 1/4. Configured resolution is 1280x720. 2659 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLExternalResizePattern2) { 2660 BasicRateTargetingSVC3TL3SLExternalResizePattern2Test(); 2661 } 2662 2663 // For 1 pass CBR SVC with 3 spatial and 3 temporal layers with external resize 2664 // and denoiser enabled. The external resizer will resize down and back up, 2665 // setting 0/nonzero bitrate on spatial enhancement layers to disable/enable 2666 // layers. Resizing starts on first frame and the pattern is: 2667 // 1/2 -> 1/4 -> 1 -> 1/2 -> 1/4. Configured resolution is 1850x1110. 2668 TEST_P(DatarateTestSVC, 2669 BasicRateTargetingSVC3TL3SLExternalResizePattern2HighRes) { 2670 BasicRateTargetingSVC3TL3SLExternalResizePattern2HighResTest(); 2671 } 2672 2673 // For 1 pass CBR SVC with 1 spatial and dynamic temporal layers. 2674 // Start/initialize with 1 temporal layer and then enable 3 temporal layers 2675 // during the sequence, and then back to 1. 2676 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDynamicTL) { 2677 BasicRateTargetingSVC3TL1SLDynamicTLTest(); 2678 } 2679 2680 // For 1 pass CBR SVC with 3 spatial and 1 temporal layer. 2681 // This encoding is to catch the issue in b:433046392. Encoder is initialized 2682 // for 3 spatial layers with top resolution of 1280x720. Starting from first 2683 // frame the scale factor for top layer is set to 1/2 (so top layer will be 2684 // same resolution as middle) and 0 bitrate is set for top layer to skip 2685 // encoding that layer. Then mid-way in sequence the scale factor is set to 1/1 2686 // (so top layer is 1280x720) and non-zero bitrate is set for all layers. 2687 // Disabling usage of src_sad_blk_64x64 for spatial layers fixes the issues with 2688 // this encoding. 2689 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLIssue433046392) { 2690 BasicRateTargetingSVC1TL3SLIssue433046392(); 2691 } 2692 2693 TEST(SvcParams, BitrateOverflow) { 2694 uint8_t buf[6] = { 0 }; 2695 aom_image_t img; 2696 aom_codec_ctx_t enc; 2697 aom_codec_enc_cfg_t cfg; 2698 2699 EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I420, 1, 1, 1, buf)); 2700 2701 aom_codec_iface_t *const iface = aom_codec_av1_cx(); 2702 EXPECT_EQ(aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_REALTIME), 2703 AOM_CODEC_OK); 2704 cfg.g_w = 1; 2705 cfg.g_h = 1; 2706 ASSERT_EQ(aom_codec_enc_init(&enc, iface, &cfg, 0), AOM_CODEC_OK); 2707 2708 aom_svc_params_t svc_params = {}; 2709 svc_params.framerate_factor[0] = 1; 2710 svc_params.framerate_factor[1] = 2; 2711 svc_params.number_spatial_layers = 1; 2712 svc_params.number_temporal_layers = 2; 2713 svc_params.layer_target_bitrate[0] = INT_MAX; 2714 svc_params.layer_target_bitrate[1] = INT_MAX; 2715 EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_SVC_PARAMS, &svc_params), 2716 AOM_CODEC_OK); 2717 EXPECT_EQ( 2718 aom_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, /*flags=*/0), 2719 AOM_CODEC_OK); 2720 EXPECT_EQ(aom_codec_encode(&enc, /*img=*/nullptr, /*pts=*/0, /*duration=*/0, 2721 /*flags=*/0), 2722 AOM_CODEC_OK); 2723 EXPECT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK); 2724 } 2725 2726 AV1_INSTANTIATE_TEST_SUITE(DatarateTestSVC, 2727 ::testing::Values(::libaom_test::kRealTime), 2728 ::testing::Range(7, 12), ::testing::Values(0, 3), 2729 ::testing::Values(0, 1)); 2730 2731 } // namespace 2732 } // namespace datarate_test