rtc-svc: Set the multi-threading per spatial layer Add the (#threads, #tile_columns/rows) to the layer context for spatial layers. This allows for setting the multi-threading per spatial layer. For now, since the mt is not working well for real-time (especially for low resolns), we force lower spatial layers to always use 1 thread, and top layer to use the mt input by user. Future CL will add codec control to allow user to set the mt per spatial layer, when the mt performance is improved. Forcing lower resolutions to use 1 thread removes regression in the current codebase if user/application enables mt for svc. Change-Id: I22c5638dd6a92e5db6224078254d07bc15ac3e4e
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c index a1e41ba..6e58ba5 100644 --- a/av1/av1_cx_iface.c +++ b/av1/av1_cx_iface.c
@@ -2288,6 +2288,8 @@ num_workers = av1_fp_compute_num_enc_workers(cpi); #endif } else { + if (cpi->use_svc && cpi->svc.number_spatial_layers > 1) + av1_svc_set_mt_per_spatial_layer(cpi); av1_compute_num_workers_for_mt(cpi); num_workers = av1_get_max_num_workers(cpi); }
diff --git a/av1/encoder/svc_layercontext.c b/av1/encoder/svc_layercontext.c index 01cacd6..9f09a4d 100644 --- a/av1/encoder/svc_layercontext.c +++ b/av1/encoder/svc_layercontext.c
@@ -80,6 +80,9 @@ } svc->downsample_filter_type[sl] = BILINEAR; svc->downsample_filter_phase[sl] = 8; + svc->max_threads[sl] = 1; + svc->tile_columns[sl] = 0; + svc->tile_rows[sl] = 0; } if (svc->number_spatial_layers == 3) { svc->downsample_filter_type[0] = EIGHTTAP_SMOOTH; @@ -123,6 +126,17 @@ lrc->worst_quality = av1_quantizer_to_qindex(lc->max_q); lrc->best_quality = av1_quantizer_to_qindex(lc->min_q); } + // The user settings of mult-threading are only applied to top + // spatial layer for now, keep lower spatial layers at 1 thread. + if (sl == svc->number_spatial_layers - 1) { + svc->max_threads[sl] = cpi->oxcf.max_threads; + svc->tile_columns[sl] = cpi->oxcf.tile_cfg.tile_columns; + svc->tile_rows[sl] = cpi->oxcf.tile_cfg.tile_rows; + } else { + svc->max_threads[sl] = 1; + svc->tile_columns[sl] = 0; + svc->tile_rows[sl] = 0; + } } } @@ -339,3 +353,10 @@ svc->downsample_filter_type[svc->spatial_layer_id] = EIGHTTAP_SMOOTH; av1_set_size_literal(cpi, width, height); } + +void av1_svc_set_mt_per_spatial_layer(AV1_COMP *const cpi) { + int sl = cpi->svc.spatial_layer_id; + cpi->oxcf.max_threads = cpi->svc.max_threads[sl]; + cpi->oxcf.tile_cfg.tile_columns = cpi->svc.tile_columns[sl]; + cpi->oxcf.tile_cfg.tile_rows = cpi->svc.tile_rows[sl]; +}
diff --git a/av1/encoder/svc_layercontext.h b/av1/encoder/svc_layercontext.h index 1eeba5e..b28c301 100644 --- a/av1/encoder/svc_layercontext.h +++ b/av1/encoder/svc_layercontext.h
@@ -138,6 +138,21 @@ * Force zero-mv in mode search for the spatial/inter-layer reference. */ int force_zero_mode_spatial_ref; + + /*! + * max threads per spatial layer. + */ + int max_threads[AOM_MAX_SS_LAYERS]; + + /*! + * tile columns per spatial layer. + */ + int tile_columns[AOM_MAX_SS_LAYERS]; + + /*! + * tile rows per spatial layer. + */ + int tile_rows[AOM_MAX_SS_LAYERS]; } SVC; struct AV1_COMP; @@ -271,6 +286,17 @@ void av1_get_layer_resolution(const int width_org, const int height_org, const int num, const int den, int *width_out, int *height_out); + +/*!\brief Set multi-threading for the current spatial layer. + * + * \ingroup SVC + * \param[in] cpi Top level encoder structure + * + * \return Nothing is returned. Instead the max_threads, tile_columns and + tile_rows are set for the current spatial layer. + */ +void av1_svc_set_mt_per_spatial_layer(struct AV1_COMP *const cpi); + #ifdef __cplusplus } // extern "C" #endif
diff --git a/test/svc_datarate_test.cc b/test/svc_datarate_test.cc index e773511..a64a999 100644 --- a/test/svc_datarate_test.cc +++ b/test/svc_datarate_test.cc
@@ -93,6 +93,10 @@ encoder->Control(AV1E_SET_ENABLE_ORDER_HINT, 0); encoder->Control(AV1E_SET_ENABLE_TPL_MODEL, 0); encoder->Control(AV1E_SET_DELTAQ_MODE, 0); + if (cfg_.g_threads > 1) { + encoder->Control(AV1E_SET_TILE_COLUMNS, cfg_.g_threads >> 1); + encoder->Control(AV1E_SET_ROW_MT, 1); + } } if (number_spatial_layers_ == 2) { spatial_layer_id = (layer_frame_cnt_ % 2 == 0) ? 0 : 1; @@ -686,6 +690,90 @@ } } + virtual void BasicRateTargetingSVC3TL3SLHDMT2Test() { + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_dropframe_thresh = 0; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.rc_end_usage = AOM_CBR; + cfg_.g_lag_in_frames = 0; + cfg_.g_error_resilient = 0; + cfg_.g_threads = 2; + + ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); + const int bitrate_array[2] = { 600, 1200 }; + cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; + ResetModel(); + number_temporal_layers_ = 3; + number_spatial_layers_ = 3; + // SL0 + const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8; + target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100; + target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100; + target_layer_bitrate_[2] = bitrate_sl0; + // SL1 + const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8; + target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100; + target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100; + target_layer_bitrate_[5] = bitrate_sl1; + // SL2 + const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8; + target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100; + target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100; + target_layer_bitrate_[8] = bitrate_sl2; + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) { + ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70) + << " The datarate for the file is lower than target by too much!"; + ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.45) + << " The datarate for the file is greater than target by too much!"; + } + } + + virtual void BasicRateTargetingSVC3TL3SLHDMT4Test() { + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_dropframe_thresh = 0; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.rc_end_usage = AOM_CBR; + cfg_.g_lag_in_frames = 0; + cfg_.g_error_resilient = 0; + cfg_.g_threads = 4; + + ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); + const int bitrate_array[2] = { 600, 1200 }; + cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)]; + ResetModel(); + number_temporal_layers_ = 3; + number_spatial_layers_ = 3; + // SL0 + const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8; + target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100; + target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100; + target_layer_bitrate_[2] = bitrate_sl0; + // SL1 + const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8; + target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100; + target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100; + target_layer_bitrate_[5] = bitrate_sl1; + // SL2 + const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8; + target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100; + target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100; + target_layer_bitrate_[8] = bitrate_sl2; + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) { + ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70) + << " The datarate for the file is lower than target by too much!"; + ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.45) + << " The datarate for the file is greater than target by too much!"; + } + } + virtual void BasicRateTargetingSVC3TL3SLHDMultiRefTest() { cfg_.rc_buf_initial_sz = 500; cfg_.rc_buf_optimal_sz = 500; @@ -1055,6 +1143,17 @@ } // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, +// for 2 threads, 2 tile_columns, row-mt enabled. +TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMT2) { + BasicRateTargetingSVC3TL3SLHDMT2Test(); +} +// Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, +// for 4 threads, 4 tile_columns, row-mt enabled. +TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMT4) { + BasicRateTargetingSVC3TL3SLHDMT4Test(); +} + +// Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers, // with additional temporal reference for top spatial layer. TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMultiRef) { BasicRateTargetingSVC3TL3SLHDMultiRefTest();