Use webrtc::Clock to query for the NTP time and to convert timestamps

to NTP.

No-Try because of lack of infra lack of capacity on macs.

No-Try: True
Bug: webrtc:11327
Change-Id: Ie0c9983031a6d37ae54b1d2381c229bee1a89e8a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214134
Commit-Queue: Paul Hallak <phallak@google.com>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34078}
This commit is contained in:
Paul Hallak 2021-05-21 14:00:28 +02:00 committed by WebRTC LUCI CQ
parent 1cb796f03a
commit 00f6e75671
4 changed files with 24 additions and 32 deletions

View File

@ -332,8 +332,7 @@ RTCPReceiver::ConsumeReceivedXrReferenceTimeInfo() {
std::vector<rtcp::ReceiveTimeInfo> last_xr_rtis;
last_xr_rtis.reserve(last_xr_rtis_size);
const uint32_t now_ntp =
CompactNtp(TimeMicrosToNtp(clock_->TimeInMicroseconds()));
const uint32_t now_ntp = CompactNtp(clock_->CurrentNtpTime());
for (size_t i = 0; i < last_xr_rtis_size; ++i) {
RrtrInformation& rrtr = received_rrtrs_.front();
@ -481,7 +480,7 @@ void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block,
remote_sender_ntp_time_ = sender_report.ntp();
remote_sender_rtp_time_ = sender_report.rtp_timestamp();
last_received_sr_ntp_ = TimeMicrosToNtp(clock_->TimeInMicroseconds());
last_received_sr_ntp_ = clock_->CurrentNtpTime();
remote_sender_packet_count_ = sender_report.sender_packet_count();
remote_sender_octet_count_ = sender_report.sender_octet_count();
remote_sender_reports_count_++;
@ -571,7 +570,7 @@ void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block,
uint32_t delay_ntp = report_block.delay_since_last_sr();
// Local NTP time.
uint32_t receive_time_ntp =
CompactNtp(TimeMicrosToNtp(last_received_rb_.us()));
CompactNtp(clock_->ConvertTimestampToNtpTime(last_received_rb_));
// RTT in 1/(2^16) seconds.
uint32_t rtt_ntp = receive_time_ntp - delay_ntp - send_time_ntp;
@ -774,8 +773,7 @@ void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block,
void RTCPReceiver::HandleXrReceiveReferenceTime(uint32_t sender_ssrc,
const rtcp::Rrtr& rrtr) {
uint32_t received_remote_mid_ntp_time = CompactNtp(rrtr.ntp());
uint32_t local_receive_mid_ntp_time =
CompactNtp(TimeMicrosToNtp(clock_->TimeInMicroseconds()));
uint32_t local_receive_mid_ntp_time = CompactNtp(clock_->CurrentNtpTime());
auto it = received_rrtrs_ssrc_it_.find(sender_ssrc);
if (it != received_rrtrs_ssrc_it_.end()) {
@ -809,7 +807,7 @@ void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) {
return;
uint32_t delay_ntp = rti.delay_since_last_rr;
uint32_t now_ntp = CompactNtp(TimeMicrosToNtp(clock_->TimeInMicroseconds()));
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);

View File

@ -250,8 +250,7 @@ TEST(RtcpReceiverTest, InjectSrPacketCalculatesRTT) {
int64_t rtt_ms = 0;
EXPECT_EQ(-1, receiver.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
uint32_t sent_ntp =
CompactNtp(TimeMicrosToNtp(mocks.clock.TimeInMicroseconds()));
uint32_t sent_ntp = CompactNtp(mocks.clock.CurrentNtpTime());
mocks.clock.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
rtcp::SenderReport sr;
@ -282,8 +281,7 @@ TEST(RtcpReceiverTest, InjectSrPacketCalculatesNegativeRTTAsOne) {
int64_t rtt_ms = 0;
EXPECT_EQ(-1, receiver.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
uint32_t sent_ntp =
CompactNtp(TimeMicrosToNtp(mocks.clock.TimeInMicroseconds()));
uint32_t sent_ntp = CompactNtp(mocks.clock.CurrentNtpTime());
mocks.clock.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
rtcp::SenderReport sr;
@ -313,8 +311,7 @@ TEST(RtcpReceiverTest,
const uint32_t kDelayNtp = 123000;
const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
uint32_t sent_ntp =
CompactNtp(TimeMicrosToNtp(mocks.clock.TimeInMicroseconds()));
uint32_t sent_ntp = CompactNtp(mocks.clock.CurrentNtpTime());
mocks.clock.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
rtcp::SenderReport sr;
@ -831,8 +828,7 @@ TEST(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithSubBlock) {
receiver.IncomingPacket(xr.Build());
uint32_t compact_ntp_now =
CompactNtp(TimeMicrosToNtp(mocks.clock.TimeInMicroseconds()));
uint32_t compact_ntp_now = CompactNtp(mocks.clock.CurrentNtpTime());
EXPECT_TRUE(receiver.GetAndResetXrRrRtt(&rtt_ms));
uint32_t rtt_ntp = compact_ntp_now - kDelay - kLastRR;
EXPECT_NEAR(CompactNtpRttToMs(rtt_ntp), rtt_ms, 1);
@ -856,8 +852,7 @@ TEST(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) {
receiver.IncomingPacket(xr.Build());
uint32_t compact_ntp_now =
CompactNtp(TimeMicrosToNtp(mocks.clock.TimeInMicroseconds()));
uint32_t compact_ntp_now = CompactNtp(mocks.clock.CurrentNtpTime());
int64_t rtt_ms = 0;
EXPECT_TRUE(receiver.GetAndResetXrRrRtt(&rtt_ms));
uint32_t rtt_ntp = compact_ntp_now - kDelay - kLastRR;
@ -936,7 +931,7 @@ TEST(RtcpReceiverTest, RttCalculatedAfterExtendedReportsDlrr) {
const int64_t kRttMs = rand.Rand(1, 9 * 3600 * 1000);
const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff);
const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
NtpTime now = TimeMicrosToNtp(mocks.clock.TimeInMicroseconds());
NtpTime now = mocks.clock.CurrentNtpTime();
uint32_t sent_ntp = CompactNtp(now);
mocks.clock.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
@ -962,7 +957,7 @@ TEST(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 = TimeMicrosToNtp(mocks.clock.TimeInMicroseconds());
NtpTime now = mocks.clock.CurrentNtpTime();
uint32_t sent_ntp = CompactNtp(now);
mocks.clock.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
@ -1334,8 +1329,7 @@ TEST(RtcpReceiverTest, VerifyRttObtainedFromReportBlockDataObserver) {
const uint32_t kDelayNtp = 123000;
const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
uint32_t sent_ntp =
CompactNtp(TimeMicrosToNtp(mocks.clock.TimeInMicroseconds()));
uint32_t sent_ntp = CompactNtp(mocks.clock.CurrentNtpTime());
mocks.clock.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
rtcp::SenderReport sr;

View File

@ -17,6 +17,7 @@
#include <utility>
#include "api/rtc_event_log/rtc_event_log.h"
#include "api/units/timestamp.h"
#include "logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h"
#include "modules/rtp_rtcp/source/rtcp_packet/app.h"
#include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
@ -103,16 +104,16 @@ class RTCPSender::RtcpContext {
RtcpContext(const FeedbackState& feedback_state,
int32_t nack_size,
const uint16_t* nack_list,
int64_t now_us)
Timestamp now)
: feedback_state_(feedback_state),
nack_size_(nack_size),
nack_list_(nack_list),
now_us_(now_us) {}
now_(now) {}
const FeedbackState& feedback_state_;
const int32_t nack_size_;
const uint16_t* nack_list_;
const int64_t now_us_;
const Timestamp now_;
};
RTCPSender::RTCPSender(const RtpRtcpInterface::Configuration& config)
@ -414,11 +415,11 @@ void RTCPSender::BuildSR(const RtcpContext& ctx, PacketSender& sender) {
// when converted to milliseconds,
uint32_t rtp_timestamp =
timestamp_offset_ + last_rtp_timestamp_ +
((ctx.now_us_ + 500) / 1000 - last_frame_capture_time_ms_) * rtp_rate;
((ctx.now_.us() + 500) / 1000 - last_frame_capture_time_ms_) * rtp_rate;
rtcp::SenderReport report;
report.SetSenderSsrc(ssrc_);
report.SetNtp(TimeMicrosToNtp(ctx.now_us_));
report.SetNtp(clock_->ConvertTimestampToNtpTime(ctx.now_));
report.SetRtpTimestamp(rtp_timestamp);
report.SetPacketCount(ctx.feedback_state_.packets_sent);
report.SetOctetCount(ctx.feedback_state_.media_bytes_sent);
@ -584,7 +585,7 @@ void RTCPSender::BuildExtendedReports(const RtcpContext& ctx,
if (!sending_ && xr_send_receiver_reference_time_enabled_) {
rtcp::Rrtr rrtr;
rrtr.SetNtp(TimeMicrosToNtp(ctx.now_us_));
rrtr.SetNtp(clock_->ConvertTimestampToNtpTime(ctx.now_));
xr.SetRrtr(rrtr);
}
@ -673,7 +674,7 @@ absl::optional<int32_t> RTCPSender::ComputeCompoundRTCPPacket(
// We need to send our NTP even if we haven't received any reports.
RtcpContext context(feedback_state, nack_size, nack_list,
clock_->TimeInMicroseconds());
clock_->CurrentTime());
PrepareReport(feedback_state);
@ -783,7 +784,7 @@ std::vector<rtcp::ReportBlock> RTCPSender::CreateReportBlocks(
if (!result.empty() && ((feedback_state.last_rr_ntp_secs != 0) ||
(feedback_state.last_rr_ntp_frac != 0))) {
// Get our NTP as late as possible to avoid a race.
uint32_t now = CompactNtp(TimeMicrosToNtp(clock_->TimeInMicroseconds()));
uint32_t now = CompactNtp(clock_->CurrentNtpTime());
uint32_t receive_time = feedback_state.last_rr_ntp_secs & 0x0000FFFF;
receive_time <<= 16;

View File

@ -19,7 +19,6 @@
#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
#include "modules/rtp_rtcp/source/time_util.h"
#include "rtc_base/rate_limiter.h"
#include "test/gmock.h"
#include "test/gtest.h"
@ -160,7 +159,7 @@ TEST_F(RtcpSenderTest, SendSr) {
rtcp_sender->SetSendingStatus(feedback_state, true);
feedback_state.packets_sent = kPacketCount;
feedback_state.media_bytes_sent = kOctetCount;
NtpTime ntp = TimeMicrosToNtp(clock_.TimeInMicroseconds());
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());
@ -516,7 +515,7 @@ TEST_F(RtcpSenderTest, SendXrWithRrtr) {
auto rtcp_sender = CreateRtcpSender(config);
rtcp_sender->SetRTCPStatus(RtcpMode::kCompound);
rtcp_sender->SetSendingStatus(feedback_state(), false);
NtpTime ntp = TimeMicrosToNtp(clock_.TimeInMicroseconds());
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());