From 552eed534c8b2811ee3255219a60b599321468b6 Mon Sep 17 00:00:00 2001 From: Evan Shrubsole Date: Tue, 11 Aug 2020 15:13:03 +0200 Subject: [PATCH] [Adaptation] Don't toggle EncoderUsageResource on/off Instead it should be ensured that it is started with the correct config. This removes confusion regarding a resource state. If the resource check is stopped then the adaptations for that resource should be removed, and there is no way to determine that if we have one method for stop for both reconfigure and shutdown. Bug: webrtc:11843 Change-Id: I491f2fd1f4f803a4610124c7b0026ad75ab4a9cc Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/181368 Reviewed-by: Ilya Nikolaevskiy Commit-Queue: Evan Shrubsole Cr-Commit-Position: refs/heads/master@{#31913} --- video/adaptation/video_stream_encoder_resource_manager.cc | 6 ++++-- video/adaptation/video_stream_encoder_resource_manager.h | 4 +--- video/video_stream_encoder.cc | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/video/adaptation/video_stream_encoder_resource_manager.cc b/video/adaptation/video_stream_encoder_resource_manager.cc index 7461d4f123..16c8b3d5b3 100644 --- a/video/adaptation/video_stream_encoder_resource_manager.cc +++ b/video/adaptation/video_stream_encoder_resource_manager.cc @@ -336,10 +336,12 @@ VideoStreamEncoderResourceManager::degradation_preference() const { return degradation_preference_; } -void VideoStreamEncoderResourceManager::StartEncodeUsageResource() { +void VideoStreamEncoderResourceManager::EnsureEncodeUsageResourceStarted() { RTC_DCHECK_RUN_ON(encoder_queue_); - RTC_DCHECK(!encode_usage_resource_->is_started()); RTC_DCHECK(encoder_settings_.has_value()); + if (encode_usage_resource_->is_started()) { + encode_usage_resource_->StopCheckForOveruse(); + } encode_usage_resource_->StartCheckForOveruse(GetCpuOveruseOptions()); } diff --git a/video/adaptation/video_stream_encoder_resource_manager.h b/video/adaptation/video_stream_encoder_resource_manager.h index a0a53eafc9..10d0e66c1c 100644 --- a/video/adaptation/video_stream_encoder_resource_manager.h +++ b/video/adaptation/video_stream_encoder_resource_manager.h @@ -89,9 +89,7 @@ class VideoStreamEncoderResourceManager void SetDegradationPreferences(DegradationPreference degradation_preference); DegradationPreference degradation_preference() const; - // Starts the encode usage resource. The quality scaler resource is - // automatically started on being configured. - void StartEncodeUsageResource(); + void EnsureEncodeUsageResourceStarted(); // Stops the encode usage and quality scaler resources if not already stopped. void StopManagedResources(); diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 2e9e453c78..e64e1e92ef 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -841,8 +841,7 @@ void VideoStreamEncoder::ReconfigureEncoder() { // We may be able to change this to "EnsureStarted()" if it took care of // reconfiguring the QualityScaler as well. (ConfigureQualityScaler() is // invoked later in this method.) - stream_resource_manager_.StopManagedResources(); - stream_resource_manager_.StartEncodeUsageResource(); + stream_resource_manager_.EnsureEncodeUsageResourceStarted(); pending_encoder_creation_ = false; }