Add missing remote-outbound stats to RTCPReceiver::NTP

In order to add `RTCRemoteOutboundRtpStreamStats` (see [1]), the
following stats must be added:
- sender's packet count (see [2])
- sender's octet count (see [2])
- total number of RTCP SR blocks sent (see [3])

[1] https://www.w3.org/TR/webrtc-stats/#dom-rtcremoteoutboundrtpstreamstats
[2] https://tools.ietf.org/html/rfc3550#section-6.4.1
[3] https://www.w3.org/TR/webrtc-stats/#dom-rtcremoteoutboundrtpstreamstats-reportssent

Bug: webrtc:12529
Change-Id: I47ac2f79ba53631965d1cd7c1062f3d0f158d66e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/210963
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33423}
This commit is contained in:
Alessio Bazzica
2021-03-10 15:05:55 +01:00
committed by Commit Bot
parent da2fd2a2b2
commit 048adc7136
5 changed files with 54 additions and 10 deletions

View File

@ -174,6 +174,9 @@ RTCPReceiver::RTCPReceiver(const RtpRtcpInterface::Configuration& config,
// TODO(bugs.webrtc.org/10774): Remove fallback. // TODO(bugs.webrtc.org/10774): Remove fallback.
remote_ssrc_(0), remote_ssrc_(0),
remote_sender_rtp_time_(0), remote_sender_rtp_time_(0),
remote_sender_packet_count_(0),
remote_sender_octet_count_(0),
remote_sender_reports_count_(0),
xr_rrtr_status_(config.non_sender_rtt_measurement), xr_rrtr_status_(config.non_sender_rtt_measurement),
xr_rr_rtt_ms_(0), xr_rr_rtt_ms_(0),
oldest_tmmbr_info_ms_(0), oldest_tmmbr_info_ms_(0),
@ -325,7 +328,10 @@ bool RTCPReceiver::NTP(uint32_t* received_ntp_secs,
uint32_t* received_ntp_frac, uint32_t* received_ntp_frac,
uint32_t* rtcp_arrival_time_secs, uint32_t* rtcp_arrival_time_secs,
uint32_t* rtcp_arrival_time_frac, uint32_t* rtcp_arrival_time_frac,
uint32_t* rtcp_timestamp) const { uint32_t* rtcp_timestamp,
uint32_t* remote_sender_packet_count,
uint64_t* remote_sender_octet_count,
uint64_t* remote_sender_reports_count) const {
MutexLock lock(&rtcp_receiver_lock_); MutexLock lock(&rtcp_receiver_lock_);
if (!last_received_sr_ntp_.Valid()) if (!last_received_sr_ntp_.Valid())
return false; return false;
@ -335,7 +341,6 @@ bool RTCPReceiver::NTP(uint32_t* received_ntp_secs,
*received_ntp_secs = remote_sender_ntp_time_.seconds(); *received_ntp_secs = remote_sender_ntp_time_.seconds();
if (received_ntp_frac) if (received_ntp_frac)
*received_ntp_frac = remote_sender_ntp_time_.fractions(); *received_ntp_frac = remote_sender_ntp_time_.fractions();
// Rtp time from incoming SenderReport. // Rtp time from incoming SenderReport.
if (rtcp_timestamp) if (rtcp_timestamp)
*rtcp_timestamp = remote_sender_rtp_time_; *rtcp_timestamp = remote_sender_rtp_time_;
@ -346,6 +351,14 @@ bool RTCPReceiver::NTP(uint32_t* received_ntp_secs,
if (rtcp_arrival_time_frac) if (rtcp_arrival_time_frac)
*rtcp_arrival_time_frac = last_received_sr_ntp_.fractions(); *rtcp_arrival_time_frac = last_received_sr_ntp_.fractions();
// Counters.
if (remote_sender_packet_count)
*remote_sender_packet_count = remote_sender_packet_count_;
if (remote_sender_octet_count)
*remote_sender_octet_count = remote_sender_octet_count_;
if (remote_sender_reports_count)
*remote_sender_reports_count = remote_sender_reports_count_;
return true; return true;
} }
@ -519,6 +532,9 @@ void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block,
remote_sender_ntp_time_ = sender_report.ntp(); remote_sender_ntp_time_ = sender_report.ntp();
remote_sender_rtp_time_ = sender_report.rtp_timestamp(); remote_sender_rtp_time_ = sender_report.rtp_timestamp();
last_received_sr_ntp_ = TimeMicrosToNtp(clock_->TimeInMicroseconds()); last_received_sr_ntp_ = TimeMicrosToNtp(clock_->TimeInMicroseconds());
remote_sender_packet_count_ = sender_report.sender_packet_count();
remote_sender_octet_count_ = sender_report.sender_octet_count();
remote_sender_reports_count_++;
} else { } else {
// We will only store the send report from one source, but // We will only store the send report from one source, but
// we will store all the receive blocks. // we will store all the receive blocks.

View File

@ -68,11 +68,21 @@ class RTCPReceiver final {
uint32_t RemoteSSRC() const; uint32_t RemoteSSRC() const;
// Get received NTP. // Get received NTP.
// The types for the arguments below derive from the specification:
// - `remote_sender_packet_count`: `RTCSentRtpStreamStats.packetsSent` [1]
// - `remote_sender_octet_count`: `RTCSentRtpStreamStats.bytesSent` [1]
// - `remote_sender_reports_count`:
// `RTCRemoteOutboundRtpStreamStats.reportsSent` [2]
// [1] https://www.w3.org/TR/webrtc-stats/#remoteoutboundrtpstats-dict*
// [2] https://www.w3.org/TR/webrtc-stats/#dom-rtcsentrtpstreamstats
bool NTP(uint32_t* received_ntp_secs, bool NTP(uint32_t* received_ntp_secs,
uint32_t* received_ntp_frac, uint32_t* received_ntp_frac,
uint32_t* rtcp_arrival_time_secs, uint32_t* rtcp_arrival_time_secs,
uint32_t* rtcp_arrival_time_frac, uint32_t* rtcp_arrival_time_frac,
uint32_t* rtcp_timestamp) const; uint32_t* rtcp_timestamp,
uint32_t* remote_sender_packet_count,
uint64_t* remote_sender_octet_count,
uint64_t* remote_sender_reports_count) const;
std::vector<rtcp::ReceiveTimeInfo> ConsumeReceivedXrReferenceTimeInfo(); std::vector<rtcp::ReceiveTimeInfo> ConsumeReceivedXrReferenceTimeInfo();
@ -239,6 +249,9 @@ class RTCPReceiver final {
uint32_t remote_sender_rtp_time_ RTC_GUARDED_BY(rtcp_receiver_lock_); uint32_t remote_sender_rtp_time_ RTC_GUARDED_BY(rtcp_receiver_lock_);
// When did we receive the last send report. // When did we receive the last send report.
NtpTime last_received_sr_ntp_ RTC_GUARDED_BY(rtcp_receiver_lock_); NtpTime last_received_sr_ntp_ RTC_GUARDED_BY(rtcp_receiver_lock_);
uint32_t remote_sender_packet_count_ RTC_GUARDED_BY(rtcp_receiver_lock_);
uint64_t remote_sender_octet_count_ RTC_GUARDED_BY(rtcp_receiver_lock_);
uint64_t remote_sender_reports_count_ RTC_GUARDED_BY(rtcp_receiver_lock_);
// Received RRTR information in ascending receive time order. // Received RRTR information in ascending receive time order.
std::list<RrtrInformation> received_rrtrs_ std::list<RrtrInformation> received_rrtrs_

View File

@ -208,7 +208,8 @@ TEST(RtcpReceiverTest, InjectSrPacket) {
RTCPReceiver receiver(DefaultConfiguration(&mocks), &mocks.rtp_rtcp_impl); RTCPReceiver receiver(DefaultConfiguration(&mocks), &mocks.rtp_rtcp_impl);
receiver.SetRemoteSSRC(kSenderSsrc); receiver.SetRemoteSSRC(kSenderSsrc);
EXPECT_FALSE(receiver.NTP(nullptr, nullptr, nullptr, nullptr, nullptr)); EXPECT_FALSE(receiver.NTP(nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr));
int64_t now = mocks.clock.TimeInMilliseconds(); int64_t now = mocks.clock.TimeInMilliseconds();
rtcp::SenderReport sr; rtcp::SenderReport sr;
@ -219,7 +220,8 @@ TEST(RtcpReceiverTest, InjectSrPacket) {
OnReceivedRtcpReceiverReport(IsEmpty(), _, now)); OnReceivedRtcpReceiverReport(IsEmpty(), _, now));
receiver.IncomingPacket(sr.Build()); receiver.IncomingPacket(sr.Build());
EXPECT_TRUE(receiver.NTP(nullptr, nullptr, nullptr, nullptr, nullptr)); EXPECT_TRUE(receiver.NTP(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr));
} }
TEST(RtcpReceiverTest, InjectSrPacketFromUnknownSender) { TEST(RtcpReceiverTest, InjectSrPacketFromUnknownSender) {
@ -239,7 +241,8 @@ TEST(RtcpReceiverTest, InjectSrPacketFromUnknownSender) {
receiver.IncomingPacket(sr.Build()); receiver.IncomingPacket(sr.Build());
// But will not flag that he's gotten sender information. // But will not flag that he's gotten sender information.
EXPECT_FALSE(receiver.NTP(nullptr, nullptr, nullptr, nullptr, nullptr)); EXPECT_FALSE(receiver.NTP(nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr));
} }
TEST(RtcpReceiverTest, InjectSrPacketCalculatesRTT) { TEST(RtcpReceiverTest, InjectSrPacketCalculatesRTT) {

View File

@ -318,7 +318,10 @@ RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() {
if (rtcp_receiver_.NTP(&received_ntp_secs, &received_ntp_frac, if (rtcp_receiver_.NTP(&received_ntp_secs, &received_ntp_frac,
/*rtcp_arrival_time_secs=*/&state.last_rr_ntp_secs, /*rtcp_arrival_time_secs=*/&state.last_rr_ntp_secs,
/*rtcp_arrival_time_frac=*/&state.last_rr_ntp_frac, /*rtcp_arrival_time_frac=*/&state.last_rr_ntp_frac,
/*rtcp_timestamp=*/nullptr)) { /*rtcp_timestamp=*/nullptr,
/*remote_sender_packet_count=*/nullptr,
/*remote_sender_octet_count=*/nullptr,
/*remote_sender_reports_count=*/nullptr)) {
state.remote_sr = ((received_ntp_secs & 0x0000ffff) << 16) + state.remote_sr = ((received_ntp_secs & 0x0000ffff) << 16) +
((received_ntp_frac & 0xffff0000) >> 16); ((received_ntp_frac & 0xffff0000) >> 16);
} }
@ -482,7 +485,10 @@ int32_t ModuleRtpRtcpImpl::RemoteNTP(uint32_t* received_ntpsecs,
uint32_t* rtcp_timestamp) const { uint32_t* rtcp_timestamp) const {
return rtcp_receiver_.NTP(received_ntpsecs, received_ntpfrac, return rtcp_receiver_.NTP(received_ntpsecs, received_ntpfrac,
rtcp_arrival_time_secs, rtcp_arrival_time_frac, rtcp_arrival_time_secs, rtcp_arrival_time_frac,
rtcp_timestamp) rtcp_timestamp,
/*remote_sender_packet_count=*/nullptr,
/*remote_sender_octet_count=*/nullptr,
/*remote_sender_reports_count=*/nullptr)
? 0 ? 0
: -1; : -1;
} }

View File

@ -266,7 +266,10 @@ RTCPSender::FeedbackState ModuleRtpRtcpImpl2::GetFeedbackState() {
if (rtcp_receiver_.NTP(&received_ntp_secs, &received_ntp_frac, if (rtcp_receiver_.NTP(&received_ntp_secs, &received_ntp_frac,
/*rtcp_arrival_time_secs=*/&state.last_rr_ntp_secs, /*rtcp_arrival_time_secs=*/&state.last_rr_ntp_secs,
/*rtcp_arrival_time_frac=*/&state.last_rr_ntp_frac, /*rtcp_arrival_time_frac=*/&state.last_rr_ntp_frac,
/*rtcp_timestamp=*/nullptr)) { /*rtcp_timestamp=*/nullptr,
/*remote_sender_packet_count=*/nullptr,
/*remote_sender_octet_count=*/nullptr,
/*remote_sender_reports_count=*/nullptr)) {
state.remote_sr = ((received_ntp_secs & 0x0000ffff) << 16) + state.remote_sr = ((received_ntp_secs & 0x0000ffff) << 16) +
((received_ntp_frac & 0xffff0000) >> 16); ((received_ntp_frac & 0xffff0000) >> 16);
} }
@ -444,7 +447,10 @@ int32_t ModuleRtpRtcpImpl2::RemoteNTP(uint32_t* received_ntpsecs,
uint32_t* rtcp_timestamp) const { uint32_t* rtcp_timestamp) const {
return rtcp_receiver_.NTP(received_ntpsecs, received_ntpfrac, return rtcp_receiver_.NTP(received_ntpsecs, received_ntpfrac,
rtcp_arrival_time_secs, rtcp_arrival_time_frac, rtcp_arrival_time_secs, rtcp_arrival_time_frac,
rtcp_timestamp) rtcp_timestamp,
/*remote_sender_packet_count=*/nullptr,
/*remote_sender_octet_count=*/nullptr,
/*remote_sender_reports_count=*/nullptr)
? 0 ? 0
: -1; : -1;
} }