Restart CPU overuse detection when encoder settings has changed.

This could potentially lead to unnecessary restarts since it is also
started after the encoder is created. However, it is needed since the
hardware acceleration support can change even though the encoder has
not been recreated.

Bug: b/145730598
Change-Id: Iad1330e7c7bdf769a68c4ecf7abb6abbf3a4fe71
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203140
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Jakob Ivarsson <jakobi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33060}
This commit is contained in:
Jakob Ivarsson 2021-01-22 16:27:43 +01:00 committed by Commit Bot
parent 2803a2def1
commit 461b1d903f
4 changed files with 43 additions and 3 deletions

View File

@ -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()) {

View File

@ -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();

View File

@ -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();
}

View File

@ -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;