Replace Clock::CurrentNtp with Clock::CurrentNtpTime
CurrentNtp return time by taking two output parameters by reference
(also breaks style guide)
CurrentNtpTime treat ntp time as single entity and returns it using NtpTime structure.
(making interface clearer)
BUG=None
Review-Url: https://codereview.webrtc.org/2733823002
Cr-Commit-Position: refs/heads/master@{#17088}
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 f976183..1f6ccf1 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 @@
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 40b8e06..c15ef8d 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 @@
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 @@
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 5066844..36721fa 100644
--- a/webrtc/system_wrappers/include/clock.h
+++ b/webrtc/system_wrappers/include/clock.h
@@ -38,16 +38,12 @@
// 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 @@
// 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 f31556f..f65adfc 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 @@
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>(
+ uint32_t fractions = static_cast<uint32_t>(
microseconds_in_seconds * kMagicNtpFractionalUnit + 0.5);
+ return NtpTime(seconds, fractions);
}
// Retrieve an NTP absolute timestamp in milliseconds.
@@ -247,11 +242,12 @@
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<uint32_t>((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 76f1723..b110776 100644
--- a/webrtc/test/drifting_clock.cc
+++ b/webrtc/test/drifting_clock.cc
@@ -39,15 +39,14 @@
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<uint64_t>(seconds) << 32) | fractions;
+ NtpTime ntp = clock_->CurrentNtpTime();
+ uint64_t total_fractions = static_cast<uint64_t>(ntp);
total_fractions += Drift() * kNtpFracPerMicroSecond;
- seconds = total_fractions >> 32;
- fractions = static_cast<uint32_t>(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 d434186..43708da 100644
--- a/webrtc/test/drifting_clock.h
+++ b/webrtc/test/drifting_clock.h
@@ -29,7 +29,7 @@
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: