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}
This commit is contained in:
Erik Språng
2020-10-01 16:26:45 +02:00
committed by Commit Bot
parent 2e537b8c33
commit b3d539ef25

View File

@ -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;
}