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}
This commit is contained in:
Ilya Nikolaevskiy 2018-11-09 10:52:39 +01:00 committed by Commit Bot
parent 06f6bc9ec4
commit ee45f900c4
2 changed files with 9 additions and 2 deletions

View File

@ -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<int64_t>(NtpTime::kFractionsPerSecond) /
1000;
NtpTime ntp(static_cast<uint64_t>(remote_clock_.CurrentNtpTime()) +
ntp_error_fractions);
AdvanceTimeMilliseconds(kTestRtt / 2 + networking_delay_ms);

View File

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