diff --git a/modules/video_coding/codecs/vp9/svc_rate_allocator.cc b/modules/video_coding/codecs/vp9/svc_rate_allocator.cc index 0535abda8a..f6ddb1e8e1 100644 --- a/modules/video_coding/codecs/vp9/svc_rate_allocator.cc +++ b/modules/video_coding/codecs/vp9/svc_rate_allocator.cc @@ -227,6 +227,9 @@ uint32_t SvcRateAllocator::GetMaxBitrateBps(const VideoCodec& codec) { uint32_t SvcRateAllocator::GetPaddingBitrateBps(const VideoCodec& codec) { const size_t num_spatial_layers = GetNumActiveSpatialLayers(codec); + if (num_spatial_layers == 0) { + return 0; // All layers are deactivated. + } if (codec.mode == VideoCodecMode::kRealtimeVideo) { float scale_factor = 0.0; diff --git a/modules/video_coding/codecs/vp9/svc_rate_allocator_unittest.cc b/modules/video_coding/codecs/vp9/svc_rate_allocator_unittest.cc index 3c3f020349..dd40057ff9 100644 --- a/modules/video_coding/codecs/vp9/svc_rate_allocator_unittest.cc +++ b/modules/video_coding/codecs/vp9/svc_rate_allocator_unittest.cc @@ -188,6 +188,15 @@ TEST(SvcRateAllocatorTest, DeativateLayers) { } } +TEST(SvcRateAllocatorTest, NoPaddingIfAllLayersAreDeactivated) { + VideoCodec codec = Configure(1280, 720, 3, 1, false); + EXPECT_EQ(codec.VP9()->numberOfSpatialLayers, 3U); + // Deactivation of base layer deactivates all layers. + codec.spatialLayers[0].active = false; + uint32_t padding_bps = SvcRateAllocator::GetPaddingBitrateBps(codec); + EXPECT_EQ(padding_bps, 0U); +} + class SvcRateAllocatorTestParametrizedContentType : public testing::Test, public testing::WithParamInterface {