Reduce the moving median window size in Remote ntp time estimator.
Too big median window will cause errors with large clock drifts, since we'll end up using old values for estimated clock drift. If the window is too small, the remote clock offset estimation could be noisy or we could even end up using outliers as the offset estimation. I will not claim that I choose the correct value, and I'm not sure how to measure the quality of the remote clock offset estimations. Bug: webrtc:379809147 Change-Id: Ib317548d3eec74105d468ef53830e12eb114df7d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/368580 Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Olov Brändström <brandstrom@google.com> Cr-Commit-Position: refs/heads/main@{#43439}
This commit is contained in:
parent
319892c4d9
commit
1b0371a54e
@ -21,9 +21,9 @@ namespace webrtc {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr int kMinimumNumberOfSamples = 2;
|
constexpr int kMinimumNumberOfSamples = 3;
|
||||||
constexpr TimeDelta kTimingLogInterval = TimeDelta::Seconds(10);
|
constexpr TimeDelta kTimingLogInterval = TimeDelta::Seconds(10);
|
||||||
constexpr int kClocksOffsetSmoothingWindow = 100;
|
constexpr int kClocksOffsetSmoothingWindow = 7;
|
||||||
|
|
||||||
// Subtracts two NtpTime values keeping maximum precision.
|
// Subtracts two NtpTime values keeping maximum precision.
|
||||||
int64_t Subtract(NtpTime minuend, NtpTime subtrahend) {
|
int64_t Subtract(NtpTime minuend, NtpTime subtrahend) {
|
||||||
|
|||||||
@ -27,6 +27,9 @@ constexpr Timestamp kRemoteClockInitialTime = Timestamp::Millis(373);
|
|||||||
constexpr uint32_t kTimestampOffset = 567;
|
constexpr uint32_t kTimestampOffset = 567;
|
||||||
constexpr int64_t kRemoteToLocalClockOffsetNtp =
|
constexpr int64_t kRemoteToLocalClockOffsetNtp =
|
||||||
ToNtpUnits(kLocalClockInitialTime - kRemoteClockInitialTime);
|
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 {
|
class RemoteNtpTimeEstimatorTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
@ -85,10 +88,14 @@ TEST_F(RemoteNtpTimeEstimatorTest, Estimate) {
|
|||||||
// Remote sends second RTCP SR.
|
// Remote sends second RTCP SR.
|
||||||
SendRtcpSr();
|
SendRtcpSr();
|
||||||
|
|
||||||
|
AdvanceTime(TimeDelta::Millis(800));
|
||||||
|
// Remote sends third RTCP SR.
|
||||||
|
SendRtcpSr();
|
||||||
|
|
||||||
// Local peer gets enough RTCP SR to calculate the capture time.
|
// Local peer gets enough RTCP SR to calculate the capture time.
|
||||||
EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp));
|
EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp));
|
||||||
EXPECT_EQ(estimator_.EstimateRemoteToLocalClockOffset(),
|
EXPECT_NEAR(*estimator_.EstimateRemoteToLocalClockOffset(),
|
||||||
kRemoteToLocalClockOffsetNtp);
|
kRemoteToLocalClockOffsetNtp, kEpsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RemoteNtpTimeEstimatorTest, AveragesErrorsOut) {
|
TEST_F(RemoteNtpTimeEstimatorTest, AveragesErrorsOut) {
|
||||||
@ -103,8 +110,8 @@ TEST_F(RemoteNtpTimeEstimatorTest, AveragesErrorsOut) {
|
|||||||
int64_t capture_ntp_time_ms = local_clock_.CurrentNtpInMilliseconds();
|
int64_t capture_ntp_time_ms = local_clock_.CurrentNtpInMilliseconds();
|
||||||
// Local peer gets enough RTCP SR to calculate the capture time.
|
// Local peer gets enough RTCP SR to calculate the capture time.
|
||||||
EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp));
|
EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp));
|
||||||
EXPECT_EQ(kRemoteToLocalClockOffsetNtp,
|
EXPECT_NEAR(kRemoteToLocalClockOffsetNtp,
|
||||||
estimator_.EstimateRemoteToLocalClockOffset());
|
*estimator_.EstimateRemoteToLocalClockOffset(), kEpsilon);
|
||||||
|
|
||||||
// Remote sends corrupted RTCP SRs
|
// Remote sends corrupted RTCP SRs
|
||||||
AdvanceTime(TimeDelta::Seconds(1));
|
AdvanceTime(TimeDelta::Seconds(1));
|
||||||
@ -121,8 +128,8 @@ TEST_F(RemoteNtpTimeEstimatorTest, AveragesErrorsOut) {
|
|||||||
|
|
||||||
// Errors should be averaged out.
|
// Errors should be averaged out.
|
||||||
EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp));
|
EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp));
|
||||||
EXPECT_EQ(kRemoteToLocalClockOffsetNtp,
|
EXPECT_NEAR(kRemoteToLocalClockOffsetNtp,
|
||||||
estimator_.EstimateRemoteToLocalClockOffset());
|
*estimator_.EstimateRemoteToLocalClockOffset(), kEpsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user