replace NtpTime->Clock with Clock->NtpTime dependency
BUG=None Review-Url: https://codereview.webrtc.org/2393723004 Cr-Commit-Position: refs/heads/master@{#16519}
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
|
||||
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
||||
#include "webrtc/modules/rtp_rtcp/source/time_util.h"
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -78,7 +79,7 @@ void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header,
|
||||
// are received, 4 will be ignored.
|
||||
if (in_order) {
|
||||
// Current time in samples.
|
||||
NtpTime receive_time(*clock_);
|
||||
NtpTime receive_time = clock_->CurrentNtpTime();
|
||||
|
||||
// Wrong if we use RetransmitOfOldPacket.
|
||||
if (receive_counters_.transmitted.packets > 1 &&
|
||||
|
||||
@ -260,7 +260,7 @@ bool RTCPReceiver::LastReceivedXrReferenceTimeInfo(
|
||||
|
||||
// Get the delay since last received report (RFC 3611).
|
||||
uint32_t receive_time_ntp = CompactNtp(last_received_xr_ntp_);
|
||||
uint32_t now_ntp = CompactNtp(NtpTime(*clock_));
|
||||
uint32_t now_ntp = CompactNtp(clock_->CurrentNtpTime());
|
||||
|
||||
info->delay_since_last_rr = now_ntp - receive_time_ntp;
|
||||
return true;
|
||||
@ -423,7 +423,7 @@ void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block,
|
||||
remote_sender_info_.sendPacketCount = sender_report.sender_packet_count();
|
||||
remote_sender_info_.sendOctetCount = sender_report.sender_octet_count();
|
||||
|
||||
last_received_sr_ntp_.SetCurrent(*clock_);
|
||||
last_received_sr_ntp_ = clock_->CurrentNtpTime();
|
||||
} else {
|
||||
// We will only store the send report from one source, but
|
||||
// we will store all the receive blocks.
|
||||
@ -504,7 +504,7 @@ void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block,
|
||||
if (!receiver_only_ && send_time_ntp != 0) {
|
||||
uint32_t delay_ntp = report_block.delay_since_last_sr();
|
||||
// Local NTP time.
|
||||
uint32_t receive_time_ntp = CompactNtp(NtpTime(*clock_));
|
||||
uint32_t receive_time_ntp = CompactNtp(clock_->CurrentNtpTime());
|
||||
|
||||
// RTT in 1/(2^16) seconds.
|
||||
uint32_t rtt_ntp = receive_time_ntp - delay_ntp - send_time_ntp;
|
||||
@ -709,7 +709,7 @@ void RTCPReceiver::HandleXrReceiveReferenceTime(uint32_t sender_ssrc,
|
||||
const rtcp::Rrtr& rrtr) {
|
||||
remote_time_info_.ssrc = sender_ssrc;
|
||||
remote_time_info_.last_rr = CompactNtp(rrtr.ntp());
|
||||
last_received_xr_ntp_.SetCurrent(*clock_);
|
||||
last_received_xr_ntp_ = clock_->CurrentNtpTime();
|
||||
}
|
||||
|
||||
void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) {
|
||||
@ -728,7 +728,7 @@ void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) {
|
||||
return;
|
||||
|
||||
uint32_t delay_ntp = rti.delay_since_last_rr;
|
||||
uint32_t now_ntp = CompactNtp(NtpTime(*clock_));
|
||||
uint32_t now_ntp = CompactNtp(clock_->CurrentNtpTime());
|
||||
|
||||
uint32_t rtt_ntp = now_ntp - delay_ntp - send_time_ntp;
|
||||
xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp);
|
||||
|
||||
@ -271,7 +271,7 @@ TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesRTT) {
|
||||
EXPECT_EQ(
|
||||
-1, rtcp_receiver_.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
|
||||
|
||||
uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_));
|
||||
uint32_t sent_ntp = CompactNtp(system_clock_.CurrentNtpTime());
|
||||
system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
|
||||
|
||||
rtcp::SenderReport sr;
|
||||
@ -301,7 +301,7 @@ TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesNegativeRTTAsOne) {
|
||||
EXPECT_EQ(
|
||||
-1, rtcp_receiver_.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
|
||||
|
||||
uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_));
|
||||
uint32_t sent_ntp = CompactNtp(system_clock_.CurrentNtpTime());
|
||||
system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
|
||||
|
||||
rtcp::SenderReport sr;
|
||||
@ -774,7 +774,7 @@ TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithSubBlock) {
|
||||
|
||||
InjectRtcpPacket(xr);
|
||||
|
||||
uint32_t compact_ntp_now = CompactNtp(NtpTime(system_clock_));
|
||||
uint32_t compact_ntp_now = CompactNtp(system_clock_.CurrentNtpTime());
|
||||
EXPECT_TRUE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms));
|
||||
uint32_t rtt_ntp = compact_ntp_now - kDelay - kLastRR;
|
||||
EXPECT_NEAR(CompactNtpRttToMs(rtt_ntp), rtt_ms, 1);
|
||||
@ -793,7 +793,7 @@ TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) {
|
||||
|
||||
InjectRtcpPacket(xr);
|
||||
|
||||
uint32_t compact_ntp_now = CompactNtp(NtpTime(system_clock_));
|
||||
uint32_t compact_ntp_now = CompactNtp(system_clock_.CurrentNtpTime());
|
||||
int64_t rtt_ms = 0;
|
||||
EXPECT_TRUE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms));
|
||||
uint32_t rtt_ntp = compact_ntp_now - kDelay - kLastRR;
|
||||
@ -859,7 +859,7 @@ TEST_F(RtcpReceiverTest, RttCalculatedAfterExtendedReportsDlrr) {
|
||||
const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff);
|
||||
const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
|
||||
rtcp_receiver_.SetRtcpXrRrtrStatus(true);
|
||||
NtpTime now(system_clock_);
|
||||
NtpTime now = system_clock_.CurrentNtpTime();
|
||||
uint32_t sent_ntp = CompactNtp(now);
|
||||
system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
|
||||
|
||||
@ -879,7 +879,7 @@ TEST_F(RtcpReceiverTest, XrDlrrCalculatesNegativeRttAsOne) {
|
||||
const int64_t kRttMs = rand.Rand(-3600 * 1000, -1);
|
||||
const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff);
|
||||
const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
|
||||
NtpTime now(system_clock_);
|
||||
NtpTime now = system_clock_.CurrentNtpTime();
|
||||
uint32_t sent_ntp = CompactNtp(now);
|
||||
system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
|
||||
rtcp_receiver_.SetRtcpXrRrtrStatus(true);
|
||||
|
||||
@ -779,7 +779,7 @@ int32_t RTCPSender::SendCompoundRTCP(
|
||||
|
||||
// We need to send our NTP even if we haven't received any reports.
|
||||
RtcpContext context(feedback_state, nack_size, nack_list, pictureID,
|
||||
NtpTime(*clock_));
|
||||
clock_->CurrentNtpTime());
|
||||
|
||||
PrepareReport(feedback_state);
|
||||
|
||||
|
||||
@ -22,11 +22,6 @@ inline uint32_t NtpToRtp(NtpTime ntp, uint32_t freq) {
|
||||
uint32_t tmp = (static_cast<uint64_t>(ntp.fractions()) * freq) >> 32;
|
||||
return ntp.seconds() * freq + tmp;
|
||||
}
|
||||
// Return the current RTP timestamp from the NTP timestamp
|
||||
// returned by the specified clock.
|
||||
inline uint32_t CurrentRtp(const Clock& clock, uint32_t freq) {
|
||||
return NtpToRtp(NtpTime(clock), freq);
|
||||
}
|
||||
|
||||
// Helper function for compact ntp representation:
|
||||
// RFC 3550, Section 4. Time Format.
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "webrtc/system_wrappers/include/ntp_time.h"
|
||||
#include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
@ -43,8 +44,14 @@ class Clock {
|
||||
// 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);
|
||||
static int64_t NtpToMs(uint32_t seconds, uint32_t fractions) {
|
||||
return NtpTime(seconds, fractions).ToMs();
|
||||
}
|
||||
|
||||
// Returns an instance of the real-time system clock implementation.
|
||||
static Clock* GetRealTimeClock();
|
||||
|
||||
@ -12,25 +12,17 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class NtpTime {
|
||||
public:
|
||||
NtpTime() : seconds_(0), fractions_(0) {}
|
||||
explicit NtpTime(const Clock& clock) {
|
||||
clock.CurrentNtp(seconds_, fractions_);
|
||||
}
|
||||
NtpTime(uint32_t seconds, uint32_t fractions)
|
||||
: seconds_(seconds), fractions_(fractions) {}
|
||||
|
||||
NtpTime(const NtpTime&) = default;
|
||||
NtpTime& operator=(const NtpTime&) = default;
|
||||
|
||||
void SetCurrent(const Clock& clock) {
|
||||
clock.CurrentNtp(seconds_, fractions_);
|
||||
}
|
||||
void Set(uint32_t seconds, uint32_t fractions) {
|
||||
seconds_ = seconds;
|
||||
fractions_ = fractions;
|
||||
@ -40,8 +32,12 @@ class NtpTime {
|
||||
fractions_ = 0;
|
||||
}
|
||||
|
||||
int64_t ToMs() const { return Clock::NtpToMs(seconds_, fractions_); }
|
||||
|
||||
int64_t ToMs() const {
|
||||
static constexpr double kNtpFracPerMs = 4.294967296E6; // 2^32 / 1000.
|
||||
const double frac_ms = static_cast<double>(fractions_) / kNtpFracPerMs;
|
||||
return 1000 * static_cast<int64_t>(seconds_) +
|
||||
static_cast<int64_t>(frac_ms + 0.5);
|
||||
}
|
||||
// NTP standard (RFC1305, section 3.1) explicitly state value 0/0 is invalid.
|
||||
bool Valid() const { return !(seconds_ == 0 && fractions_ == 0); }
|
||||
|
||||
|
||||
@ -25,12 +25,11 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
const double kNtpFracPerMs = 4.294967296E6;
|
||||
|
||||
int64_t Clock::NtpToMs(uint32_t ntp_secs, uint32_t ntp_frac) {
|
||||
const double ntp_frac_ms = static_cast<double>(ntp_frac) / kNtpFracPerMs;
|
||||
return 1000 * static_cast<int64_t>(ntp_secs) +
|
||||
static_cast<int64_t>(ntp_frac_ms + 0.5);
|
||||
NtpTime Clock::CurrentNtpTime() const {
|
||||
uint32_t seconds;
|
||||
uint32_t fractions;
|
||||
CurrentNtp(seconds, fractions);
|
||||
return NtpTime(seconds, fractions);
|
||||
}
|
||||
|
||||
class RealTimeClock : public Clock {
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
#include "webrtc/system_wrappers/include/ntp_time.h"
|
||||
#include "webrtc/test/gtest.h"
|
||||
|
||||
@ -45,21 +46,10 @@ TEST(NtpTimeTest, SetIsSameAs2ParameterConstructor) {
|
||||
EXPECT_EQ(ntp1, ntp2);
|
||||
}
|
||||
|
||||
TEST(NtpTimeTest, SetCurrentIsSameAs1ParameterConstructor) {
|
||||
SimulatedClock clock(0x0123456789abcdef);
|
||||
|
||||
NtpTime ntp1(clock);
|
||||
NtpTime ntp2;
|
||||
EXPECT_NE(ntp1, ntp2);
|
||||
|
||||
ntp2.SetCurrent(clock);
|
||||
EXPECT_EQ(ntp1, ntp2);
|
||||
}
|
||||
|
||||
TEST(NtpTimeTest, ToMsMeansToNtpMilliseconds) {
|
||||
SimulatedClock clock(0x123456789abc);
|
||||
|
||||
NtpTime ntp(clock);
|
||||
NtpTime ntp = clock.CurrentNtpTime();
|
||||
EXPECT_EQ(ntp.ToMs(), Clock::NtpToMs(ntp.seconds(), ntp.fractions()));
|
||||
EXPECT_EQ(ntp.ToMs(), clock.CurrentNtpInMilliseconds());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user