diff --git a/modules/rtp_rtcp/source/remote_ntp_time_estimator.cc b/modules/rtp_rtcp/source/remote_ntp_time_estimator.cc index 21ef24a646..898e5b734d 100644 --- a/modules/rtp_rtcp/source/remote_ntp_time_estimator.cc +++ b/modules/rtp_rtcp/source/remote_ntp_time_estimator.cc @@ -21,9 +21,9 @@ namespace webrtc { namespace { -constexpr int kMinimumNumberOfSamples = 2; +constexpr int kMinimumNumberOfSamples = 3; constexpr TimeDelta kTimingLogInterval = TimeDelta::Seconds(10); -constexpr int kClocksOffsetSmoothingWindow = 100; +constexpr int kClocksOffsetSmoothingWindow = 7; // Subtracts two NtpTime values keeping maximum precision. int64_t Subtract(NtpTime minuend, NtpTime subtrahend) { 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 e9e8ce9fcc..dda58dc7cd 100644 --- a/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc +++ b/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc @@ -27,6 +27,9 @@ constexpr Timestamp kRemoteClockInitialTime = Timestamp::Millis(373); constexpr uint32_t kTimestampOffset = 567; constexpr int64_t kRemoteToLocalClockOffsetNtp = ToNtpUnits(kLocalClockInitialTime - kRemoteClockInitialTime); +// There can be small rounding differences when converting to the +// sub nano second precision of the NTP timestamps. +constexpr int64_t kEpsilon = 1; class RemoteNtpTimeEstimatorTest : public ::testing::Test { protected: @@ -85,10 +88,14 @@ TEST_F(RemoteNtpTimeEstimatorTest, Estimate) { // Remote sends second RTCP SR. SendRtcpSr(); + AdvanceTime(TimeDelta::Millis(800)); + // Remote sends third RTCP SR. + SendRtcpSr(); + // Local peer gets enough RTCP SR to calculate the capture time. EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp)); - EXPECT_EQ(estimator_.EstimateRemoteToLocalClockOffset(), - kRemoteToLocalClockOffsetNtp); + EXPECT_NEAR(*estimator_.EstimateRemoteToLocalClockOffset(), + kRemoteToLocalClockOffsetNtp, kEpsilon); } TEST_F(RemoteNtpTimeEstimatorTest, AveragesErrorsOut) { @@ -103,8 +110,8 @@ TEST_F(RemoteNtpTimeEstimatorTest, AveragesErrorsOut) { int64_t capture_ntp_time_ms = local_clock_.CurrentNtpInMilliseconds(); // Local peer gets enough RTCP SR to calculate the capture time. EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp)); - EXPECT_EQ(kRemoteToLocalClockOffsetNtp, - estimator_.EstimateRemoteToLocalClockOffset()); + EXPECT_NEAR(kRemoteToLocalClockOffsetNtp, + *estimator_.EstimateRemoteToLocalClockOffset(), kEpsilon); // Remote sends corrupted RTCP SRs AdvanceTime(TimeDelta::Seconds(1)); @@ -121,8 +128,8 @@ TEST_F(RemoteNtpTimeEstimatorTest, AveragesErrorsOut) { // Errors should be averaged out. EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp)); - EXPECT_EQ(kRemoteToLocalClockOffsetNtp, - estimator_.EstimateRemoteToLocalClockOffset()); + EXPECT_NEAR(kRemoteToLocalClockOffsetNtp, + *estimator_.EstimateRemoteToLocalClockOffset(), kEpsilon); } } // namespace