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}
This commit is contained in:
parent
92a7a1810c
commit
21dc1890f4
@ -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,
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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>(
|
||||
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 @@ 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<uint32_t>((now_ms % 1000) * kMagicNtpFractionalUnit / 1000);
|
||||
return NtpTime(seconds, fractions);
|
||||
}
|
||||
|
||||
int64_t SimulatedClock::CurrentNtpInMilliseconds() const {
|
||||
|
||||
@ -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<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 {
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user