diff --git a/video/adaptation/video_stream_encoder_resource_manager.cc b/video/adaptation/video_stream_encoder_resource_manager.cc index 8d532f3e2c..81d23a124b 100644 --- a/video/adaptation/video_stream_encoder_resource_manager.cc +++ b/video/adaptation/video_stream_encoder_resource_manager.cc @@ -292,7 +292,7 @@ VideoStreamEncoderResourceManager::degradation_preference() const { return degradation_preference_; } -void VideoStreamEncoderResourceManager::EnsureEncodeUsageResourceStarted() { +void VideoStreamEncoderResourceManager::ConfigureEncodeUsageResource() { RTC_DCHECK_RUN_ON(encoder_queue_); RTC_DCHECK(encoder_settings_.has_value()); if (encode_usage_resource_->is_started()) { diff --git a/video/adaptation/video_stream_encoder_resource_manager.h b/video/adaptation/video_stream_encoder_resource_manager.h index 30bab53cbf..7e458a92b3 100644 --- a/video/adaptation/video_stream_encoder_resource_manager.h +++ b/video/adaptation/video_stream_encoder_resource_manager.h @@ -92,7 +92,7 @@ class VideoStreamEncoderResourceManager void SetDegradationPreferences(DegradationPreference degradation_preference); DegradationPreference degradation_preference() const; - void EnsureEncodeUsageResourceStarted(); + void ConfigureEncodeUsageResource(); // Initializes the pixel limit resource if the "WebRTC-PixelLimitResource" // field trial is enabled. This can be used for testing. void MaybeInitializePixelLimitResource(); diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 9a05e47eda..4215fd9897 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -1044,7 +1044,7 @@ void VideoStreamEncoder::ReconfigureEncoder() { } if (pending_encoder_creation_) { - stream_resource_manager_.EnsureEncodeUsageResourceStarted(); + stream_resource_manager_.ConfigureEncodeUsageResource(); pending_encoder_creation_ = false; } @@ -1530,6 +1530,7 @@ void VideoStreamEncoder::EncodeVideoFrame(const VideoFrame& video_frame, if (encoder_info_ != info) { OnEncoderSettingsChanged(); + stream_resource_manager_.ConfigureEncodeUsageResource(); RTC_LOG(LS_INFO) << "Encoder settings changed from " << encoder_info_.ToString() << " to " << info.ToString(); } diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index dea22de1b3..aed1625f9e 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -6427,6 +6427,45 @@ TEST_F(VideoStreamEncoderTest, video_stream_encoder_->Stop(); } +TEST_F(VideoStreamEncoderTest, + CpuAdaptationThresholdsUpdatesWhenHardwareAccelerationChange) { + const int kFrameWidth = 1280; + const int kFrameHeight = 720; + + const CpuOveruseOptions default_options; + video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources( + DataRate::BitsPerSec(kTargetBitrateBps), + DataRate::BitsPerSec(kTargetBitrateBps), + DataRate::BitsPerSec(kTargetBitrateBps), 0, 0, 0); + video_source_.IncomingCapturedFrame( + CreateFrame(1, kFrameWidth, kFrameHeight)); + WaitForEncodedFrame(1); + EXPECT_EQ(video_stream_encoder_->overuse_detector_proxy_->GetOptions() + .low_encode_usage_threshold_percent, + default_options.low_encode_usage_threshold_percent); + EXPECT_EQ(video_stream_encoder_->overuse_detector_proxy_->GetOptions() + .high_encode_usage_threshold_percent, + default_options.high_encode_usage_threshold_percent); + + CpuOveruseOptions hardware_options; + hardware_options.low_encode_usage_threshold_percent = 150; + hardware_options.high_encode_usage_threshold_percent = 200; + fake_encoder_.SetIsHardwareAccelerated(true); + + video_source_.IncomingCapturedFrame( + CreateFrame(2, kFrameWidth, kFrameHeight)); + WaitForEncodedFrame(2); + + EXPECT_EQ(video_stream_encoder_->overuse_detector_proxy_->GetOptions() + .low_encode_usage_threshold_percent, + hardware_options.low_encode_usage_threshold_percent); + EXPECT_EQ(video_stream_encoder_->overuse_detector_proxy_->GetOptions() + .high_encode_usage_threshold_percent, + hardware_options.high_encode_usage_threshold_percent); + + video_stream_encoder_->Stop(); +} + TEST_F(VideoStreamEncoderTest, DropsFramesWhenEncoderOvershoots) { const int kFrameWidth = 320; const int kFrameHeight = 240;