From bd4a718667fde2843f65c96e3fb9a2241fceb32d Mon Sep 17 00:00:00 2001 From: Evan Shrubsole Date: Fri, 14 Aug 2020 10:08:54 +0200 Subject: [PATCH] [Adaptation] Make resource most limited if kLimitReached hit This occurs when a resource causes an adaptation down but the current adaptations can not be adapted any more. Any further adaptation will result in the status kLimitReached, and so any resource that adapts down should also be most limited. Bug: webrtc:11695 Change-Id: Idfdf23f482b1b4a132cec49a9be76adc0aec4361 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/181586 Commit-Queue: Evan Shrubsole Reviewed-by: Ilya Nikolaevskiy Cr-Commit-Position: refs/heads/master@{#31933} --- .../resource_adaptation_processor.cc | 7 ++++++ .../resource_adaptation_processor_unittest.cc | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/call/adaptation/resource_adaptation_processor.cc b/call/adaptation/resource_adaptation_processor.cc index 94a5b7f963..fd81c9b567 100644 --- a/call/adaptation/resource_adaptation_processor.cc +++ b/call/adaptation/resource_adaptation_processor.cc @@ -305,6 +305,13 @@ ResourceAdaptationProcessor::OnResourceOveruse( if (adaptation.min_pixel_limit_reached()) { encoder_stats_observer_->OnMinPixelLimitReached(); } + if (adaptation.status() == Adaptation::Status::kLimitReached) { + // Add resource as most limited. + VideoStreamAdapter::RestrictionsWithCounters restrictions; + std::tie(std::ignore, restrictions) = FindMostLimitedResources(); + UpdateResourceLimitations(reason_resource, restrictions.restrictions, + restrictions.counters); + } if (adaptation.status() != Adaptation::Status::kValid) { rtc::StringBuilder message; message << "Not adapting down because VideoStreamAdapter returned " diff --git a/call/adaptation/resource_adaptation_processor_unittest.cc b/call/adaptation/resource_adaptation_processor_unittest.cc index c27958c4fc..17e0a2f142 100644 --- a/call/adaptation/resource_adaptation_processor_unittest.cc +++ b/call/adaptation/resource_adaptation_processor_unittest.cc @@ -709,4 +709,29 @@ TEST_F(ResourceAdaptationProcessorTest, resource_ = nullptr; } +TEST_F(ResourceAdaptationProcessorTest, + ResourceOverusedAtLimitReachedWillShareMostLimited) { + video_stream_adapter_->SetDegradationPreference( + DegradationPreference::MAINTAIN_FRAMERATE); + SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize); + + bool has_reached_min_pixels = false; + ON_CALL(frame_rate_provider_, OnMinPixelLimitReached()) + .WillByDefault(testing::Assign(&has_reached_min_pixels, true)); + + // Adapt 10 times, which should make us hit the limit. + for (int i = 0; i < 10; ++i) { + resource_->SetUsageState(ResourceUsageState::kOveruse); + RestrictSource(restrictions_listener_.restrictions()); + } + EXPECT_TRUE(has_reached_min_pixels); + auto last_update_count = restrictions_listener_.restrictions_updated_count(); + other_resource_->SetUsageState(ResourceUsageState::kOveruse); + // Now both |resource_| and |other_resource_| are most limited. Underuse of + // |resource_| will not adapt up. + resource_->SetUsageState(ResourceUsageState::kUnderuse); + EXPECT_EQ(last_update_count, + restrictions_listener_.restrictions_updated_count()); +} + } // namespace webrtc