diff --git a/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc b/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc index 5254cd57bb..6ee8b02e19 100644 --- a/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc +++ b/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc @@ -56,7 +56,8 @@ class RemoteNtpTimeEstimatorTest : public ::testing::Test { int64_t networking_delay_ms) { uint32_t rtcp_timestamp = GetRemoteTimestamp(); int64_t ntp_error_fractions = - ntp_error_ms * NtpTime::kFractionsPerSecond / 1000; + ntp_error_ms * static_cast(NtpTime::kFractionsPerSecond) / + 1000; NtpTime ntp(static_cast(remote_clock_.CurrentNtpTime()) + ntp_error_fractions); AdvanceTimeMilliseconds(kTestRtt / 2 + networking_delay_ms); diff --git a/system_wrappers/source/rtp_to_ntp_estimator.cc b/system_wrappers/source/rtp_to_ntp_estimator.cc index aaef4b1b27..5697d3781b 100644 --- a/system_wrappers/source/rtp_to_ntp_estimator.cc +++ b/system_wrappers/source/rtp_to_ntp_estimator.cc @@ -21,6 +21,11 @@ namespace { const size_t kNumRtcpReportsToUse = 2; // Number of parameters samples used to smooth. const size_t kNumSamplesToSmooth = 20; +// Don't allow NTP timestamps to jump more than 1 hour. Chosen arbitrary as big +// enough to not affect normal use-cases. Yet it is smaller than RTP wrap-around +// half-period (90khz RTP clock wrap-arounds every 13.25 hours). After half of +// wrap-around period it is impossible to unwrap RTP timestamps correctly. +const int kMaxAllowedRtcpNtpIntervalMs = 60 * 60 * 1000; // Calculates the RTP timestamp frequency from two pairs of NTP/RTP timestamps. bool CalculateFrequency(int64_t ntp_ms1, @@ -133,7 +138,8 @@ bool RtpToNtpEstimator::UpdateMeasurements(uint32_t ntp_secs, if (!measurements_.empty()) { int64_t old_rtp_timestamp = measurements_.front().unwrapped_rtp_timestamp; int64_t old_ntp_ms = measurements_.front().ntp_time.ToMs(); - if (ntp_ms_new <= old_ntp_ms) { + if (ntp_ms_new <= old_ntp_ms || + ntp_ms_new > old_ntp_ms + kMaxAllowedRtcpNtpIntervalMs) { invalid_sample = true; } else if (unwrapped_rtp_timestamp <= old_rtp_timestamp) { RTC_LOG(LS_WARNING)