diff --git a/webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc b/webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc index f976183d1b..1f6ccf13a9 100644 --- a/webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc @@ -46,12 +46,10 @@ class RemoteNtpTimeEstimatorTest : public ::testing::Test { void SendRtcpSr() { uint32_t rtcp_timestamp = GetRemoteTimestamp(); - uint32_t ntp_seconds; - uint32_t ntp_fractions; - remote_clock_.CurrentNtp(ntp_seconds, ntp_fractions); + NtpTime ntp = remote_clock_.CurrentNtpTime(); AdvanceTimeMilliseconds(kTestRtt / 2); - ReceiveRtcpSr(kTestRtt, rtcp_timestamp, ntp_seconds, ntp_fractions); + ReceiveRtcpSr(kTestRtt, rtcp_timestamp, ntp.seconds(), ntp.fractions()); } void UpdateRtcpTimestamp(int64_t rtt, uint32_t ntp_secs, uint32_t ntp_frac, diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc index 40b8e061b9..c15ef8d251 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc @@ -295,14 +295,11 @@ TEST_F(RtcpSenderTest, SendSr) { rtcp_sender_->SetSendingStatus(feedback_state, true); feedback_state.packets_sent = kPacketCount; feedback_state.media_bytes_sent = kOctetCount; - uint32_t ntp_secs; - uint32_t ntp_frac; - clock_.CurrentNtp(ntp_secs, ntp_frac); + NtpTime ntp = clock_.CurrentNtpTime(); EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpSr)); EXPECT_EQ(1, parser()->sender_report()->num_packets()); EXPECT_EQ(kSenderSsrc, parser()->sender_report()->sender_ssrc()); - EXPECT_EQ(ntp_secs, parser()->sender_report()->ntp().seconds()); - EXPECT_EQ(ntp_frac, parser()->sender_report()->ntp().fractions()); + EXPECT_EQ(ntp, parser()->sender_report()->ntp()); EXPECT_EQ(kPacketCount, parser()->sender_report()->sender_packet_count()); EXPECT_EQ(kOctetCount, parser()->sender_report()->sender_octet_count()); EXPECT_EQ(kStartRtpTimestamp + kRtpTimestamp, @@ -640,17 +637,14 @@ TEST_F(RtcpSenderTest, SendXrWithRrtr) { rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); EXPECT_EQ(0, rtcp_sender_->SetSendingStatus(feedback_state(), false)); rtcp_sender_->SendRtcpXrReceiverReferenceTime(true); - uint32_t ntp_secs; - uint32_t ntp_frac; - clock_.CurrentNtp(ntp_secs, ntp_frac); + NtpTime ntp = clock_.CurrentNtpTime(); EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state(), kRtcpReport)); EXPECT_EQ(1, parser()->xr()->num_packets()); EXPECT_EQ(kSenderSsrc, parser()->xr()->sender_ssrc()); EXPECT_FALSE(parser()->xr()->dlrr()); EXPECT_FALSE(parser()->xr()->voip_metric()); ASSERT_TRUE(parser()->xr()->rrtr()); - EXPECT_EQ(ntp_secs, parser()->xr()->rrtr()->ntp().seconds()); - EXPECT_EQ(ntp_frac, parser()->xr()->rrtr()->ntp().fractions()); + EXPECT_EQ(ntp, parser()->xr()->rrtr()->ntp()); } TEST_F(RtcpSenderTest, TestNoXrRrtrSentIfSending) { diff --git a/webrtc/system_wrappers/include/clock.h b/webrtc/system_wrappers/include/clock.h index 506684496c..36721fa3aa 100644 --- a/webrtc/system_wrappers/include/clock.h +++ b/webrtc/system_wrappers/include/clock.h @@ -38,16 +38,12 @@ class Clock { // source is fixed for this clock. virtual int64_t TimeInMicroseconds() const = 0; - // Retrieve an NTP absolute timestamp in seconds and fractions of a second. - virtual void CurrentNtp(uint32_t& seconds, uint32_t& fractions) const = 0; + // Retrieve an NTP absolute timestamp. + virtual NtpTime CurrentNtpTime() const = 0; // Retrieve an NTP absolute timestamp in milliseconds. virtual int64_t CurrentNtpInMilliseconds() const = 0; - // TODO(danilchap): Make pure virtual once implemented in derived classed - // replacing CurrentNtp function. - virtual NtpTime CurrentNtpTime() const; - // Converts an NTP timestamp to a millisecond timestamp. static int64_t NtpToMs(uint32_t seconds, uint32_t fractions) { return NtpTime(seconds, fractions).ToMs(); @@ -71,8 +67,8 @@ class SimulatedClock : public Clock { // source is fixed for this clock. int64_t TimeInMicroseconds() const override; - // Retrieve an NTP absolute timestamp in milliseconds. - void CurrentNtp(uint32_t& seconds, uint32_t& fractions) const override; + // Retrieve an NTP absolute timestamp. + NtpTime CurrentNtpTime() const override; // Converts an NTP timestamp to a millisecond timestamp. int64_t CurrentNtpInMilliseconds() const override; diff --git a/webrtc/system_wrappers/source/clock.cc b/webrtc/system_wrappers/source/clock.cc index f31556fc4f..f65adfcbb1 100644 --- a/webrtc/system_wrappers/source/clock.cc +++ b/webrtc/system_wrappers/source/clock.cc @@ -25,13 +25,6 @@ namespace webrtc { -NtpTime Clock::CurrentNtpTime() const { - uint32_t seconds; - uint32_t fractions; - CurrentNtp(seconds, fractions); - return NtpTime(seconds, fractions); -} - class RealTimeClock : public Clock { // Return a timestamp in milliseconds relative to some arbitrary source; the // source is fixed for this clock. @@ -45,13 +38,15 @@ class RealTimeClock : public Clock { return rtc::TimeMicros(); } - // Retrieve an NTP absolute timestamp in seconds and fractions of a second. - void CurrentNtp(uint32_t& seconds, uint32_t& fractions) const override { + // Retrieve an NTP absolute timestamp. + NtpTime CurrentNtpTime() const override { timeval tv = CurrentTimeVal(); double microseconds_in_seconds; + uint32_t seconds; Adjust(tv, &seconds, µseconds_in_seconds); - fractions = static_cast( + uint32_t fractions = static_cast( microseconds_in_seconds * kMagicNtpFractionalUnit + 0.5); + return NtpTime(seconds, fractions); } // Retrieve an NTP absolute timestamp in milliseconds. @@ -247,11 +242,12 @@ int64_t SimulatedClock::TimeInMicroseconds() const { return time_us_; } -void SimulatedClock::CurrentNtp(uint32_t& seconds, uint32_t& fractions) const { +NtpTime SimulatedClock::CurrentNtpTime() const { int64_t now_ms = TimeInMilliseconds(); - seconds = (now_ms / 1000) + kNtpJan1970; - fractions = + uint32_t seconds = (now_ms / 1000) + kNtpJan1970; + uint32_t fractions = static_cast((now_ms % 1000) * kMagicNtpFractionalUnit / 1000); + return NtpTime(seconds, fractions); } int64_t SimulatedClock::CurrentNtpInMilliseconds() const { diff --git a/webrtc/test/drifting_clock.cc b/webrtc/test/drifting_clock.cc index 76f17235ce..b11077641d 100644 --- a/webrtc/test/drifting_clock.cc +++ b/webrtc/test/drifting_clock.cc @@ -39,15 +39,14 @@ int64_t DriftingClock::TimeInMicroseconds() const { return clock_->TimeInMicroseconds() + Drift(); } -void DriftingClock::CurrentNtp(uint32_t& seconds, uint32_t& fractions) const { +NtpTime DriftingClock::CurrentNtpTime() const { // NTP precision is 1/2^32 seconds, i.e. 2^32 ntp fractions = 1 second. const double kNtpFracPerMicroSecond = 4294.967296; // = 2^32 / 10^6 - clock_->CurrentNtp(seconds, fractions); - uint64_t total_fractions = (static_cast(seconds) << 32) | fractions; + NtpTime ntp = clock_->CurrentNtpTime(); + uint64_t total_fractions = static_cast(ntp); total_fractions += Drift() * kNtpFracPerMicroSecond; - seconds = total_fractions >> 32; - fractions = static_cast(total_fractions); + return NtpTime(total_fractions); } int64_t DriftingClock::CurrentNtpInMilliseconds() const { diff --git a/webrtc/test/drifting_clock.h b/webrtc/test/drifting_clock.h index d434186d7d..43708da9d3 100644 --- a/webrtc/test/drifting_clock.h +++ b/webrtc/test/drifting_clock.h @@ -29,7 +29,7 @@ class DriftingClock : public Clock { int64_t TimeInMilliseconds() const override; int64_t TimeInMicroseconds() const override; - void CurrentNtp(uint32_t& seconds, uint32_t& fractions) const override; + NtpTime CurrentNtpTime() const override; int64_t CurrentNtpInMilliseconds() const override; private: