From a67a9d92562130a93403566e5af50d621fd6fb22 Mon Sep 17 00:00:00 2001 From: Sergey Silkin Date: Thu, 24 Jan 2019 11:32:55 +0100 Subject: [PATCH] Handle zero number of spatial layers at calculation of VP9 SVC padding. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: chromium:923330 Change-Id: I66e3b17e5a22b7de9d9b83d5dda486ec5b4364fc Reviewed-on: https://webrtc-review.googlesource.com/c/119600 Reviewed-by: Erik Språng Commit-Queue: Sergey Silkin Cr-Commit-Position: refs/heads/master@{#26388} --- modules/video_coding/codecs/vp9/svc_rate_allocator.cc | 3 +++ .../codecs/vp9/svc_rate_allocator_unittest.cc | 9 +++++++++ 2 files changed, 12 insertions(+) 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 {