Sets VP9 buffer size and speed based on highest active spatial layer.
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 <sprang@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32280}
diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc
index b31cd3d..59a0a13 100644
--- a/modules/video_coding/codecs/vp9/vp9_impl.cc
+++ b/modules/video_coding/codecs/vp9/vp9_impl.cc
@@ -397,6 +397,8 @@
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 @@
}
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 @@
}
current_bitrate_allocation_ = bitrate_allocation;
+ cpu_speed_ = GetCpuSpeed(highest_active_width, highest_active_height);
config_changed_ = true;
return true;
}
@@ -966,6 +975,7 @@
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;
}