From 7e7e805d3b48377fd4487940be7707c8855ea447 Mon Sep 17 00:00:00 2001 From: Shuhai Peng Date: Mon, 11 Oct 2021 18:24:01 +0800 Subject: [PATCH] video: Re-configure scalers when encoder info changed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Encoder info will be modified at runtime. In fact, we should reduce the number of 'full' ReconfigureEncoder(). If only need subset of it at runtime, consider handle it in VideoStreamEncoder::EncodeVideoFrame(). Consider two cases: Re-configure scalers when encoder info changed. Consider two cases: 1. When the status of the scaler changes from enabled to disabled, if we don't do this CL, scaler will adapt up/down to trigger an unnecessary full ReconfigureEncoder() when the scaler should be banned. 2. When the status of the scaler changes from disabled to enabled, if we don't do this CL, scaler will not work until some code trigger ReconfigureEncoder(). In extreme cases, the scaler doesn't even work for a long time when we expect that the scaler should work. This CL aims to make scalers work properly when encoder info changed. BUG: None Change-Id: Iec17730b5fac5e642c0fb2d9b11c5b7434f0a220 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/233384 Reviewed-by: Ilya Nikolaevskiy Reviewed-by: Henrik Boström Commit-Queue: Ilya Nikolaevskiy Cr-Commit-Position: refs/heads/main@{#35175} --- video/video_stream_encoder.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 8774ff7b72..9180bbb917 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -848,6 +848,9 @@ void VideoStreamEncoder::ConfigureEncoder(VideoEncoderConfig config, }); } +// We should reduce the number of 'full' ReconfigureEncoder(). If only need +// subset of it at runtime, consider handle it in +// VideoStreamEncoder::EncodeVideoFrame() when encoder_info_ != info. void VideoStreamEncoder::ReconfigureEncoder() { // Running on the encoder queue. RTC_DCHECK(pending_encoder_reconfiguration_); @@ -1668,8 +1671,18 @@ void VideoStreamEncoder::EncodeVideoFrame(const VideoFrame& video_frame, if (encoder_info_ != info) { OnEncoderSettingsChanged(); stream_resource_manager_.ConfigureEncodeUsageResource(); - RTC_LOG(LS_INFO) << "Encoder settings changed from " - << encoder_info_.ToString() << " to " << info.ToString(); + // Re-configure scalers when encoder info changed. Consider two cases: + // 1. When the status of the scaler changes from enabled to disabled, if we + // don't do this CL, scaler will adapt up/down to trigger an unnecessary + // full ReconfigureEncoder() when the scaler should be banned. + // 2. When the status of the scaler changes from disabled to enabled, if we + // don't do this CL, scaler will not work until some code trigger + // ReconfigureEncoder(). In extreme cases, the scaler doesn't even work for + // a long time when we expect that the scaler should work. + stream_resource_manager_.ConfigureQualityScaler(info); + stream_resource_manager_.ConfigureBandwidthQualityScaler(info); + + RTC_LOG(LS_INFO) << "Encoder info changed to " << info.ToString(); } if (bitrate_adjuster_) {