From 5ed40cfa2edc98692b3d7d70324721b77df0f512 Mon Sep 17 00:00:00 2001 From: Mirta Dvornicic Date: Fri, 21 Feb 2020 16:35:51 +0100 Subject: [PATCH] Do not request encoder switch when the video is suspended. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: None Change-Id: I0ecd4db4ee53e1eb6682a2a98b684fcdf5c2e93b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168924 Commit-Queue: Mirta Dvornicic Reviewed-by: Rasmus Brandt Reviewed-by: Åsa Persson Cr-Commit-Position: refs/heads/master@{#30585} --- video/video_stream_encoder.cc | 7 +++--- video/video_stream_encoder_unittest.cc | 35 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index becf1df738..6939fbc332 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -1560,7 +1560,10 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate, } RTC_DCHECK_RUN_ON(&encoder_queue_); - if (settings_.encoder_switch_request_callback) { + const bool video_is_suspended = target_bitrate == DataRate::Zero(); + const bool video_suspension_changed = video_is_suspended != EncoderPaused(); + + if (!video_is_suspended && settings_.encoder_switch_request_callback) { if (encoder_selector_) { if (auto encoder = encoder_selector_->OnEncodingBitrate(target_bitrate)) { settings_.encoder_switch_request_callback->RequestEncoderSwitch( @@ -1594,8 +1597,6 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate, uint32_t framerate_fps = GetInputFramerateFps(); frame_dropper_.SetRates((target_bitrate.bps() + 500) / 1000, framerate_fps); - const bool video_is_suspended = target_bitrate == DataRate::Zero(); - const bool video_suspension_changed = video_is_suspended != EncoderPaused(); EncoderRateSettings new_rate_settings{ VideoBitrateAllocation(), static_cast(framerate_fps), diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index a307e4a3ee..2130a7ab64 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -5258,6 +5258,41 @@ TEST_F(VideoStreamEncoderTest, BitrateEncoderSwitch) { video_stream_encoder_->Stop(); } +TEST_F(VideoStreamEncoderTest, VideoSuspendedNoEncoderSwitch) { + constexpr int kDontCare = 100; + + StrictMock switch_callback; + video_send_config_.encoder_settings.encoder_switch_request_callback = + &switch_callback; + VideoEncoderConfig encoder_config = video_encoder_config_.Copy(); + encoder_config.codec_type = kVideoCodecVP8; + webrtc::test::ScopedFieldTrials field_trial( + "WebRTC-NetworkCondition-EncoderSwitch/" + "codec_thresholds:VP8;100;-1|H264;-1;30000," + "to_codec:AV1,to_param:ping,to_value:pong,window:2.0/"); + + // Reset encoder for new configuration to take effect. + ConfigureEncoder(std::move(encoder_config)); + + // Send one frame to trigger ReconfigureEncoder. + video_source_.IncomingCapturedFrame( + CreateFrame(kDontCare, kDontCare, kDontCare)); + + using Config = EncoderSwitchRequestCallback::Config; + EXPECT_CALL(switch_callback, RequestEncoderSwitch(Matcher(_))) + .Times(0); + + video_stream_encoder_->OnBitrateUpdated( + /*target_bitrate=*/DataRate::KilobitsPerSec(0), + /*stable_target_bitrate=*/DataRate::KilobitsPerSec(0), + /*link_allocation=*/DataRate::KilobitsPerSec(kDontCare), + /*fraction_lost=*/0, + /*rtt_ms=*/0, + /*cwnd_reduce_ratio=*/0); + + video_stream_encoder_->Stop(); +} + TEST_F(VideoStreamEncoderTest, ResolutionEncoderSwitch) { constexpr int kSufficientBitrateToNotDrop = 1000; constexpr int kHighRes = 500;