Use ArrayView versions of SendRtp and SendRtcp

This CL adds [[deprecated]] to the old signatures, and uses the new
signatures throughout.

Bug: webrtc:14870
Change-Id: Ic9a8198ac0a2f954e1b2e7d05a55dbe04342f958
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/314962
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40517}
This commit is contained in:
Harald Alvestrand 2023-08-04 12:18:45 +00:00 committed by WebRTC LUCI CQ
parent 8dc55689d2
commit 34d82df2ba
11 changed files with 32 additions and 27 deletions

View file

@ -48,6 +48,8 @@ class Transport {
// New style functions. Default implementations are to accomodate // New style functions. Default implementations are to accomodate
// subclasses that haven't been converted to new style yet. // subclasses that haven't been converted to new style yet.
// TODO(bugs.webrtc.org/14870): Deprecate and remove old functions. // TODO(bugs.webrtc.org/14870): Deprecate and remove old functions.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
virtual bool SendRtp(rtc::ArrayView<const uint8_t> packet, virtual bool SendRtp(rtc::ArrayView<const uint8_t> packet,
const PacketOptions& options) { const PacketOptions& options) {
return SendRtp(packet.data(), packet.size(), options); return SendRtp(packet.data(), packet.size(), options);
@ -55,11 +57,17 @@ class Transport {
virtual bool SendRtcp(rtc::ArrayView<const uint8_t> packet) { virtual bool SendRtcp(rtc::ArrayView<const uint8_t> packet) {
return SendRtcp(packet.data(), packet.size()); return SendRtcp(packet.data(), packet.size());
} }
#pragma clang diagnostic pop
// Old style functions. // Old style functions.
virtual bool SendRtp(const uint8_t* packet, [[deprecated("Use ArrayView version")]] virtual bool
size_t length, SendRtp(const uint8_t* packet, size_t length, const PacketOptions& options) {
const PacketOptions& options) = 0; return SendRtp(rtc::MakeArrayView(packet, length), options);
virtual bool SendRtcp(const uint8_t* packet, size_t length) = 0; }
[[deprecated("Use ArrayView version")]] virtual bool SendRtcp(
const uint8_t* packet,
size_t length) {
return SendRtcp(rtc::MakeArrayView(packet, length));
}
protected: protected:
virtual ~Transport() {} virtual ~Transport() {}

View file

@ -356,9 +356,11 @@ void FakeNetworkPipe::DeliverNetworkPacket(NetworkPacket* packet) {
return; return;
} }
if (packet->is_rtcp()) { if (packet->is_rtcp()) {
transport->SendRtcp(packet->data(), packet->data_length()); transport->SendRtcp(
rtc::MakeArrayView(packet->data(), packet->data_length()));
} else { } else {
transport->SendRtp(packet->data(), packet->data_length(), transport->SendRtp(
rtc::MakeArrayView(packet->data(), packet->data_length()),
packet->packet_options()); packet->packet_options());
} }
} else if (receiver_) { } else if (receiver_) {

View file

@ -5589,8 +5589,7 @@ TEST_F(WebRtcVideoChannelTest, TestSetDscpOptions) {
// Packets should also self-identify their dscp in PacketOptions. // Packets should also self-identify their dscp in PacketOptions.
const uint8_t kData[10] = {0}; const uint8_t kData[10] = {0};
EXPECT_TRUE(ChannelImplAsTransport(send_channel.get()) EXPECT_TRUE(ChannelImplAsTransport(send_channel.get())->SendRtcp(kData));
->SendRtcp(kData, sizeof(kData)));
EXPECT_EQ(rtc::DSCP_CS1, network_interface->options().dscp); EXPECT_EQ(rtc::DSCP_CS1, network_interface->options().dscp);
send_channel->SetInterface(nullptr); send_channel->SetInterface(nullptr);

View file

@ -3255,9 +3255,7 @@ TEST_P(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
// Packets should also self-identify their dscp in PacketOptions. // Packets should also self-identify their dscp in PacketOptions.
const uint8_t kData[10] = {0}; const uint8_t kData[10] = {0};
EXPECT_TRUE(SendImplFromPointer(channel.get()) EXPECT_TRUE(SendImplFromPointer(channel.get())->transport()->SendRtcp(kData));
->transport()
->SendRtcp(kData, sizeof(kData)));
EXPECT_EQ(rtc::DSCP_CS1, network_interface.options().dscp); EXPECT_EQ(rtc::DSCP_CS1, network_interface.options().dscp);
channel->SetInterface(nullptr); channel->SetInterface(nullptr);

View file

@ -416,7 +416,7 @@ bool DEPRECATED_RtpSenderEgress::SendPacketToNetwork(
const PacedPacketInfo& pacing_info) { const PacedPacketInfo& pacing_info) {
int bytes_sent = -1; int bytes_sent = -1;
if (transport_) { if (transport_) {
bytes_sent = transport_->SendRtp(packet.data(), packet.size(), options) bytes_sent = transport_->SendRtp(packet, options)
? static_cast<int>(packet.size()) ? static_cast<int>(packet.size())
: -1; : -1;
if (event_log_ && bytes_sent > 0) { if (event_log_ && bytes_sent > 0) {

View file

@ -242,7 +242,7 @@ int32_t RTCPSender::SendLossNotification(const FeedbackState& feedback_state,
bool buffering_allowed) { bool buffering_allowed) {
int32_t error_code = -1; int32_t error_code = -1;
auto callback = [&](rtc::ArrayView<const uint8_t> packet) { auto callback = [&](rtc::ArrayView<const uint8_t> packet) {
transport_->SendRtcp(packet.data(), packet.size()); transport_->SendRtcp(packet);
error_code = 0; error_code = 0;
if (event_log_) { if (event_log_) {
event_log_->Log(std::make_unique<RtcEventRtcpPacketOutgoing>(packet)); event_log_->Log(std::make_unique<RtcEventRtcpPacketOutgoing>(packet));
@ -659,7 +659,7 @@ int32_t RTCPSender::SendRTCP(const FeedbackState& feedback_state,
const uint16_t* nack_list) { const uint16_t* nack_list) {
int32_t error_code = -1; int32_t error_code = -1;
auto callback = [&](rtc::ArrayView<const uint8_t> packet) { auto callback = [&](rtc::ArrayView<const uint8_t> packet) {
if (transport_->SendRtcp(packet.data(), packet.size())) { if (transport_->SendRtcp(packet)) {
error_code = 0; error_code = 0;
if (event_log_) { if (event_log_) {
event_log_->Log(std::make_unique<RtcEventRtcpPacketOutgoing>(packet)); event_log_->Log(std::make_unique<RtcEventRtcpPacketOutgoing>(packet));
@ -938,7 +938,7 @@ void RTCPSender::SendCombinedRtcpPacket(
} }
RTC_DCHECK_LE(max_packet_size, IP_PACKET_SIZE); RTC_DCHECK_LE(max_packet_size, IP_PACKET_SIZE);
auto callback = [&](rtc::ArrayView<const uint8_t> packet) { auto callback = [&](rtc::ArrayView<const uint8_t> packet) {
if (transport_->SendRtcp(packet.data(), packet.size())) { if (transport_->SendRtcp(packet)) {
if (event_log_) if (event_log_)
event_log_->Log(std::make_unique<RtcEventRtcpPacketOutgoing>(packet)); event_log_->Log(std::make_unique<RtcEventRtcpPacketOutgoing>(packet));
} }

View file

@ -522,7 +522,7 @@ bool RtpSenderEgress::SendPacketToNetwork(const RtpPacketToSend& packet,
RTC_DCHECK_RUN_ON(worker_queue_); RTC_DCHECK_RUN_ON(worker_queue_);
int bytes_sent = -1; int bytes_sent = -1;
if (transport_) { if (transport_) {
bytes_sent = transport_->SendRtp(packet.data(), packet.size(), options) bytes_sent = transport_->SendRtp(packet, options)
? static_cast<int>(packet.size()) ? static_cast<int>(packet.size())
: -1; : -1;
if (event_log_ && bytes_sent > 0) { if (event_log_ && bytes_sent > 0) {

View file

@ -166,7 +166,7 @@ TEST_F(RetransmissionEndToEndTest, ReceivesNackAndRetransmitsAudio) {
nack.SetPacketIds(nack_list, 1); nack.SetPacketIds(nack_list, 1);
rtc::Buffer buffer = nack.Build(); rtc::Buffer buffer = nack.Build();
EXPECT_TRUE(receive_transport_->SendRtcp(buffer.data(), buffer.size())); EXPECT_TRUE(receive_transport_->SendRtcp(buffer));
} }
return SEND_PACKET; return SEND_PACKET;

View file

@ -336,7 +336,7 @@ void RtpRtcpEndToEndTest::TestRtpStatePreservation(
rtcp::RapidResyncRequest force_send_sr_back_request; rtcp::RapidResyncRequest force_send_sr_back_request;
rtc::Buffer packet = force_send_sr_back_request.Build(); rtc::Buffer packet = force_send_sr_back_request.Build();
static_cast<webrtc::Transport*>(receive_transport_.get()) static_cast<webrtc::Transport*>(receive_transport_.get())
->SendRtcp(packet.data(), packet.size()); ->SendRtcp(packet);
} }
CreateFrameGeneratorCapturer(30, 1280, 720); CreateFrameGeneratorCapturer(30, 1280, 720);
StartVideoSources(); StartVideoSources();

View file

@ -22,20 +22,19 @@ TransportAdapter::TransportAdapter(Transport* transport)
TransportAdapter::~TransportAdapter() = default; TransportAdapter::~TransportAdapter() = default;
bool TransportAdapter::SendRtp(const uint8_t* packet, bool TransportAdapter::SendRtp(rtc::ArrayView<const uint8_t> packet,
size_t length,
const PacketOptions& options) { const PacketOptions& options) {
if (!enabled_.load()) if (!enabled_.load())
return false; return false;
return transport_->SendRtp(packet, length, options); return transport_->SendRtp(packet, options);
} }
bool TransportAdapter::SendRtcp(const uint8_t* packet, size_t length) { bool TransportAdapter::SendRtcp(rtc::ArrayView<const uint8_t> packet) {
if (!enabled_.load()) if (!enabled_.load())
return false; return false;
return transport_->SendRtcp(packet, length); return transport_->SendRtcp(packet);
} }
void TransportAdapter::Enable() { void TransportAdapter::Enable() {

View file

@ -25,10 +25,9 @@ class TransportAdapter : public Transport {
explicit TransportAdapter(Transport* transport); explicit TransportAdapter(Transport* transport);
~TransportAdapter() override; ~TransportAdapter() override;
bool SendRtp(const uint8_t* packet, bool SendRtp(rtc::ArrayView<const uint8_t> packet,
size_t length,
const PacketOptions& options) override; const PacketOptions& options) override;
bool SendRtcp(const uint8_t* packet, size_t length) override; bool SendRtcp(rtc::ArrayView<const uint8_t> packet) override;
void Enable(); void Enable();
void Disable(); void Disable();