From b3d539ef2524c5daee18998478acd36765545268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Thu, 1 Oct 2020 16:26:45 +0200 Subject: [PATCH] Sets VP9 buffer size and speed based on highest active spatial layer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change the allocated buffer and encoder complexity was set based on the highest resolution configured regardless if that spatial layer was active or not. This should reduce memory pressure and improve visual quality when only a low resolution is requested. In test, increasing the encoder complexity has paradoxically also resulted in increased decoder speed. Bug: webrtc:11551 Change-Id: I3ae47a5856de82ff7d40fddfcb160935b12b1d2b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186301 Commit-Queue: Erik Språng Reviewed-by: Ilya Nikolaevskiy Cr-Commit-Position: refs/heads/master@{#32280} --- modules/video_coding/codecs/vp9/vp9_impl.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc index b31cd3d7bd..59a0a13c9b 100644 --- a/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -397,6 +397,8 @@ bool VP9EncoderImpl::SetSvcRates( first_active_layer_ = 0; bool seen_active_layer = false; bool expect_no_more_active_layers = false; + int highest_active_width = 0; + int highest_active_height = 0; for (int i = 0; i < num_spatial_layers_; ++i) { if (config_->ss_target_bitrate[i] > 0) { RTC_DCHECK(!expect_no_more_active_layers) << "Only middle layer is " @@ -406,6 +408,12 @@ bool VP9EncoderImpl::SetSvcRates( } num_active_spatial_layers_ = i + 1; seen_active_layer = true; + highest_active_width = + (svc_params_.scaling_factor_num[i] * config_->g_w) / + svc_params_.scaling_factor_den[i]; + highest_active_height = + (svc_params_.scaling_factor_num[i] * config_->g_h) / + svc_params_.scaling_factor_den[i]; } else { expect_no_more_active_layers = seen_active_layer; } @@ -421,6 +429,7 @@ bool VP9EncoderImpl::SetSvcRates( } current_bitrate_allocation_ = bitrate_allocation; + cpu_speed_ = GetCpuSpeed(highest_active_width, highest_active_height); config_changed_ = true; return true; } @@ -966,6 +975,7 @@ int VP9EncoderImpl::Encode(const VideoFrame& input_image, if (vpx_codec_enc_config_set(encoder_, config_)) { return WEBRTC_VIDEO_CODEC_ERROR; } + vpx_codec_control(encoder_, VP8E_SET_CPUUSED, cpu_speed_); config_changed_ = false; }