In RTP to NTP estimator do not allow huge jumps in NTP timestamps
Bug: webrtc:9698
Change-Id: I64b5ec4d611fd2981bbc11ef2652e97cfd1e72c7
Reviewed-on: https://webrtc-review.googlesource.com/c/110247
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25577}
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 5254cd5..6ee8b02 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 @@
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<int64_t>(NtpTime::kFractionsPerSecond) /
+ 1000;
NtpTime ntp(static_cast<uint64_t>(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 aaef4b1..5697d37 100644
--- a/system_wrappers/source/rtp_to_ntp_estimator.cc
+++ b/system_wrappers/source/rtp_to_ntp_estimator.cc
@@ -21,6 +21,11 @@
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 @@
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)