diff --git a/modules/video_coding/jitter_estimator.cc b/modules/video_coding/jitter_estimator.cc index cd505835d1..44e2a9811e 100644 --- a/modules/video_coding/jitter_estimator.cc +++ b/modules/video_coding/jitter_estimator.cc @@ -23,6 +23,7 @@ #include "rtc_base/experiments/jitter_upper_bound_experiment.h" #include "rtc_base/numerics/safe_conversions.h" #include "system_wrappers/include/clock.h" +#include "system_wrappers/include/field_trial.h" namespace webrtc { namespace { @@ -50,6 +51,8 @@ VCMJitterEstimator::VCMJitterEstimator(Clock* clock) time_deviation_upper_bound_( JitterUpperBoundExperiment::GetUpperBoundSigmas().value_or( kDefaultMaxTimestampDeviationInSigmas)), + enable_reduced_delay_( + !field_trial::IsEnabled("WebRTC-ReducedJitterDelayKillSwitch")), clock_(clock) { Reset(); } @@ -395,22 +398,25 @@ int VCMJitterEstimator::GetJitterEstimate( } } - static const double kJitterScaleLowThreshold = 5.0; - static const double kJitterScaleHighThreshold = 10.0; - double fps = GetFrameRate(); - // Ignore jitter for very low fps streams. - if (fps < kJitterScaleLowThreshold) { - if (fps == 0.0) { - return rtc::checked_cast(std::max(0.0, jitterMS) + 0.5); + if (enable_reduced_delay_) { + static const double kJitterScaleLowThreshold = 5.0; + static const double kJitterScaleHighThreshold = 10.0; + double fps = GetFrameRate(); + // Ignore jitter for very low fps streams. + if (fps < kJitterScaleLowThreshold) { + if (fps == 0.0) { + return rtc::checked_cast(std::max(0.0, jitterMS) + 0.5); + } + return 0; } - return 0; - } - // Semi-low frame rate; scale by factor linearly interpolated from 0.0 at - // kJitterScaleLowThreshold to 1.0 at kJitterScaleHighThreshold. - if (fps < kJitterScaleHighThreshold) { - jitterMS = (1.0 / (kJitterScaleHighThreshold - kJitterScaleLowThreshold)) * - (fps - kJitterScaleLowThreshold) * jitterMS; + // Semi-low frame rate; scale by factor linearly interpolated from 0.0 at + // kJitterScaleLowThreshold to 1.0 at kJitterScaleHighThreshold. + if (fps < kJitterScaleHighThreshold) { + jitterMS = + (1.0 / (kJitterScaleHighThreshold - kJitterScaleLowThreshold)) * + (fps - kJitterScaleLowThreshold) * jitterMS; + } } return rtc::checked_cast(std::max(0.0, jitterMS) + 0.5); diff --git a/modules/video_coding/jitter_estimator.h b/modules/video_coding/jitter_estimator.h index d9798b40a1..1d69b95769 100644 --- a/modules/video_coding/jitter_estimator.h +++ b/modules/video_coding/jitter_estimator.h @@ -150,6 +150,7 @@ class VCMJitterEstimator { rtc::RollingAccumulator fps_counter_; const double time_deviation_upper_bound_; + const bool enable_reduced_delay_; Clock* clock_; }; diff --git a/modules/video_coding/jitter_estimator_tests.cc b/modules/video_coding/jitter_estimator_tests.cc index 1ad9abb56f..14baae7e81 100644 --- a/modules/video_coding/jitter_estimator_tests.cc +++ b/modules/video_coding/jitter_estimator_tests.cc @@ -72,6 +72,22 @@ TEST_F(TestVCMJitterEstimator, TestLowRate) { } } +TEST_F(TestVCMJitterEstimator, TestLowRateDisabled) { + test::ScopedFieldTrials field_trials( + "WebRTC-ReducedJitterDelayKillSwitch/Enabled/"); + SetUp(); + + ValueGenerator gen(10); + uint64_t time_delta_us = rtc::kNumMicrosecsPerSec / 5; + for (int i = 0; i < 60; ++i) { + estimator_->UpdateEstimate(gen.Delay(), gen.FrameSize()); + AdvanceClock(time_delta_us); + if (i > 2) + EXPECT_GT(estimator_->GetJitterEstimate(0, absl::nullopt), 0); + gen.Advance(); + } +} + TEST_F(TestVCMJitterEstimator, TestUpperBound) { struct TestContext { TestContext()