Add remote-outbound stats for audio streams

Add missing members needed to surface `RTCRemoteOutboundRtpStreamStats`
via `ChannelReceive::GetRTCPStatistics()` - i.e., audio streams.

`GetSenderReportStats()` is added to both `ModuleRtpRtcpImpl` and
`ModuleRtpRtcpImpl2` and used by `ChannelReceive::GetRTCPStatistics()`.

Bug: webrtc:12529
Change-Id: Ia8f5dfe2e4cfc43e3ddd28f2f1149f5c00f9269d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211041
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33452}
This commit is contained in:
Alessio Bazzica
2021-03-12 17:45:26 +01:00
committed by Commit Bot
parent c80f955114
commit bc1c93dc6e
13 changed files with 318 additions and 11 deletions

View File

@ -27,6 +27,11 @@
#include "test/rtp_header_parser.h"
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::Field;
using ::testing::Gt;
using ::testing::Not;
using ::testing::Optional;
namespace webrtc {
namespace {
@ -616,4 +621,102 @@ TEST_F(RtpRtcpImplTest, StoresPacketInfoForSentPackets) {
/*is_last=*/1)));
}
// Checks that the sender report stats are not available if no RTCP SR was sent.
TEST_F(RtpRtcpImplTest, SenderReportStatsNotAvailable) {
EXPECT_THAT(receiver_.impl_->GetSenderReportStats(), Eq(absl::nullopt));
}
// Checks that the sender report stats are available if an RTCP SR was sent.
TEST_F(RtpRtcpImplTest, SenderReportStatsAvailable) {
// Send a frame in order to send an SR.
SendFrame(&sender_, sender_video_.get(), kBaseLayerTid);
// Send an SR.
ASSERT_THAT(sender_.impl_->SendRTCP(kRtcpReport), Eq(0));
EXPECT_THAT(receiver_.impl_->GetSenderReportStats(), Not(Eq(absl::nullopt)));
}
// Checks that the sender report stats are not available if an RTCP SR with an
// unexpected SSRC is received.
TEST_F(RtpRtcpImplTest, SenderReportStatsNotUpdatedWithUnexpectedSsrc) {
constexpr uint32_t kUnexpectedSenderSsrc = 0x87654321;
static_assert(kUnexpectedSenderSsrc != kSenderSsrc, "");
// Forge a sender report and pass it to the receiver as if an RTCP SR were
// sent by an unexpected sender.
rtcp::SenderReport sr;
sr.SetSenderSsrc(kUnexpectedSenderSsrc);
sr.SetNtp({/*seconds=*/1u, /*fractions=*/1u << 31});
sr.SetPacketCount(123u);
sr.SetOctetCount(456u);
auto raw_packet = sr.Build();
receiver_.impl_->IncomingRtcpPacket(raw_packet.data(), raw_packet.size());
EXPECT_THAT(receiver_.impl_->GetSenderReportStats(), Eq(absl::nullopt));
}
// Checks the stats derived from the last received RTCP SR are set correctly.
TEST_F(RtpRtcpImplTest, SenderReportStatsCheckStatsFromLastReport) {
using SenderReportStats = RtpRtcpInterface::SenderReportStats;
const NtpTime ntp(/*seconds=*/1u, /*fractions=*/1u << 31);
constexpr uint32_t kPacketCount = 123u;
constexpr uint32_t kOctetCount = 456u;
// Forge a sender report and pass it to the receiver as if an RTCP SR were
// sent by the sender.
rtcp::SenderReport sr;
sr.SetSenderSsrc(kSenderSsrc);
sr.SetNtp(ntp);
sr.SetPacketCount(kPacketCount);
sr.SetOctetCount(kOctetCount);
auto raw_packet = sr.Build();
receiver_.impl_->IncomingRtcpPacket(raw_packet.data(), raw_packet.size());
EXPECT_THAT(
receiver_.impl_->GetSenderReportStats(),
Optional(AllOf(Field(&SenderReportStats::last_remote_timestamp, Eq(ntp)),
Field(&SenderReportStats::packets_sent, Eq(kPacketCount)),
Field(&SenderReportStats::bytes_sent, Eq(kOctetCount)))));
}
// Checks that the sender report stats count equals the number of sent RTCP SRs.
TEST_F(RtpRtcpImplTest, SenderReportStatsCount) {
using SenderReportStats = RtpRtcpInterface::SenderReportStats;
// Send a frame in order to send an SR.
SendFrame(&sender_, sender_video_.get(), kBaseLayerTid);
// Send the first SR.
ASSERT_THAT(sender_.impl_->SendRTCP(kRtcpReport), Eq(0));
EXPECT_THAT(receiver_.impl_->GetSenderReportStats(),
Optional(Field(&SenderReportStats::reports_count, Eq(1u))));
// Send the second SR.
ASSERT_THAT(sender_.impl_->SendRTCP(kRtcpReport), Eq(0));
EXPECT_THAT(receiver_.impl_->GetSenderReportStats(),
Optional(Field(&SenderReportStats::reports_count, Eq(2u))));
}
// Checks that the sender report stats include a valid arrival time if an RTCP
// SR was sent.
TEST_F(RtpRtcpImplTest, SenderReportStatsArrivalTimestampSet) {
// Send a frame in order to send an SR.
SendFrame(&sender_, sender_video_.get(), kBaseLayerTid);
// Send an SR.
ASSERT_THAT(sender_.impl_->SendRTCP(kRtcpReport), Eq(0));
auto stats = receiver_.impl_->GetSenderReportStats();
ASSERT_THAT(stats, Not(Eq(absl::nullopt)));
EXPECT_TRUE(stats->last_arrival_timestamp.Valid());
}
// Checks that the packet and byte counters from an RTCP SR are not zero once
// a frame is sent.
TEST_F(RtpRtcpImplTest, SenderReportStatsPacketByteCounters) {
using SenderReportStats = RtpRtcpInterface::SenderReportStats;
// Send a frame in order to send an SR.
SendFrame(&sender_, sender_video_.get(), kBaseLayerTid);
ASSERT_THAT(sender_.transport_.rtp_packets_sent_, Gt(0));
// Advance time otherwise the RTCP SR report will not include any packets
// generated by `SendFrame()`.
clock_.AdvanceTimeMilliseconds(1);
// Send an SR.
ASSERT_THAT(sender_.impl_->SendRTCP(kRtcpReport), Eq(0));
EXPECT_THAT(receiver_.impl_->GetSenderReportStats(),
Optional(AllOf(Field(&SenderReportStats::packets_sent, Gt(0u)),
Field(&SenderReportStats::bytes_sent, Gt(0u)))));
}
} // namespace webrtc