Fix potential division by zero in VP9 VideoCodecTest.

When GetSvcConfig returned fewer spatial layers than the number
statically configured from the test, we would crash on a SIGFPE.

This is not a problem in the production code, since there we
reset the encoder with the correct number of spatial layers
whenever the resolution changes.

Bug: None
Change-Id: I339e4a3c0fa993c7c649533c0eae71e1314194e7
Reviewed-on: https://webrtc-review.googlesource.com/85374
Reviewed-by: Michael Horowitz <mhoro@webrtc.org>
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Commit-Queue: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23741}
This commit is contained in:
Rasmus Brandt
2018-06-26 13:41:16 +02:00
committed by Commit Bot
parent 63c82a78d3
commit 58cd385e58
2 changed files with 4 additions and 0 deletions

View File

@ -76,6 +76,8 @@ void ConfigureSvc(VideoCodec* codec_settings) {
codec_settings->VP9()->numberOfSpatialLayers,
codec_settings->VP9()->numberOfTemporalLayers,
/* is_screen_sharing = */ false);
ASSERT_EQ(codec_settings->VP9()->numberOfSpatialLayers, layers.size())
<< "GetSvcConfig returned fewer spatial layers than configured.";
for (size_t i = 0; i < layers.size(); ++i) {
codec_settings->spatialLayers[i] = layers[i];

View File

@ -175,6 +175,7 @@ bool VP9EncoderImpl::SetSvcRates(
}
for (i = 0; i < num_active_spatial_layers_; ++i) {
RTC_CHECK_GT(total, 0);
config_->ss_target_bitrate[i] = static_cast<unsigned int>(
config_->rc_target_bitrate * rate_ratio[i] / total);
if (num_temporal_layers_ == 1) {
@ -436,6 +437,7 @@ int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) {
if (ExplicitlyConfiguredSpatialLayers()) {
for (int i = 0; i < num_spatial_layers_; ++i) {
const auto& layer = codec_.spatialLayers[i];
RTC_CHECK_GT(layer.width, 0);
const int scale_factor = codec_.width / layer.width;
RTC_DCHECK_GT(scale_factor, 0);