Replace all RTPSender::SendToNetwork with EnqueuePackets

Bug: None
Change-Id: I1bcfbd9c16b329f3aa3f95d8ed61b82131e0da1d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/316922
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Auto-Submit: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40591}
This commit is contained in:
Danil Chapovalov 2023-08-21 17:34:55 +02:00 committed by WebRTC LUCI CQ
parent 798708ff9d
commit 233165b239
4 changed files with 26 additions and 43 deletions

View File

@ -461,22 +461,6 @@ std::vector<std::unique_ptr<RtpPacketToSend>> RTPSender::GeneratePadding(
return padding_packets;
}
bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet) {
RTC_DCHECK(packet);
auto packet_type = packet->packet_type();
RTC_CHECK(packet_type) << "Packet type must be set before sending.";
if (packet->capture_time() <= Timestamp::Zero()) {
packet->set_capture_time(clock_->CurrentTime());
}
std::vector<std::unique_ptr<RtpPacketToSend>> packets;
packets.emplace_back(std::move(packet));
paced_sender_->EnqueuePackets(std::move(packets));
return true;
}
void RTPSender::EnqueuePackets(
std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
RTC_DCHECK(!packets.empty());

View File

@ -144,11 +144,6 @@ class RTPSender {
return flexfec_ssrc_;
}
// Sends packet to `transport_` or to the pacer, depending on configuration.
// TODO(bugs.webrtc.org/XXX): Remove in favor of EnqueuePackets().
bool SendToNetwork(std::unique_ptr<RtpPacketToSend> packet)
RTC_LOCKS_EXCLUDED(send_mutex_);
// Pass a set of packets to RtpPacketSender instance, for paced or immediate
// sending to the network.
void EnqueuePackets(std::vector<std::unique_ptr<RtpPacketToSend>> packets)

View File

@ -14,6 +14,7 @@
#include <memory>
#include <utility>
#include <vector>
#include "absl/strings/match.h"
#include "absl/types/optional.h"
@ -300,11 +301,13 @@ bool RTPSenderAudio::SendAudio(AudioFrameType frame_type,
packet->SequenceNumber());
packet->set_packet_type(RtpPacketMediaType::kAudio);
packet->set_allow_retransmission(true);
bool send_result = rtp_sender_->SendToNetwork(std::move(packet));
std::vector<std::unique_ptr<RtpPacketToSend>> packets(1);
packets[0] = std::move(packet);
rtp_sender_->EnqueuePackets(std::move(packets));
if (first_packet_sent_()) {
RTC_LOG(LS_INFO) << "First audio RTP packet sent to pacer";
}
return send_result;
return true;
}
// Audio level magnitude and voice activity flag are set for each RTP packet
@ -340,19 +343,16 @@ bool RTPSenderAudio::SendTelephoneEventPacket(bool ended,
uint32_t dtmf_timestamp,
uint16_t duration,
bool marker_bit) {
uint8_t send_count = 1;
bool result = true;
size_t send_count = ended ? 3 : 1;
if (ended) {
// resend last packet in an event 3 times
send_count = 3;
}
do {
std::vector<std::unique_ptr<RtpPacketToSend>> packets;
packets.reserve(send_count);
for (size_t i = 0; i < send_count; ++i) {
// Send DTMF data.
constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr;
constexpr size_t kDtmfSize = 4;
std::unique_ptr<RtpPacketToSend> packet(
new RtpPacketToSend(kNoExtensions, kRtpHeaderSize + kDtmfSize));
auto packet = std::make_unique<RtpPacketToSend>(kNoExtensions,
kRtpHeaderSize + kDtmfSize);
packet->SetPayloadType(dtmf_current_event_.payload_type);
packet->SetMarker(marker_bit);
packet->SetSsrc(rtp_sender_->SSRC());
@ -383,10 +383,9 @@ bool RTPSenderAudio::SendTelephoneEventPacket(bool ended,
packet->set_packet_type(RtpPacketMediaType::kAudio);
packet->set_allow_retransmission(true);
result = rtp_sender_->SendToNetwork(std::move(packet));
send_count--;
} while (send_count > 0 && result);
return result;
packets.push_back(std::move(packet));
}
rtp_sender_->EnqueuePackets(std::move(packets));
return true;
}
} // namespace webrtc

View File

@ -201,8 +201,9 @@ class RtpSenderTest : public ::testing::Test {
packet->set_allow_retransmission(true);
// Packet should be stored in a send bucket.
EXPECT_TRUE(
rtp_sender_->SendToNetwork(std::make_unique<RtpPacketToSend>(*packet)));
std::vector<std::unique_ptr<RtpPacketToSend>> packets(1);
packets[0] = std::make_unique<RtpPacketToSend>(*packet);
rtp_sender_->EnqueuePackets(std::move(packets));
return packet;
}
@ -232,10 +233,12 @@ class RtpSenderTest : public ::testing::Test {
size_t GenerateAndSendPadding(size_t target_size_bytes) {
size_t generated_bytes = 0;
std::vector<std::unique_ptr<RtpPacketToSend>> packets;
for (auto& packet : GeneratePadding(target_size_bytes)) {
generated_bytes += packet->payload_size() + packet->padding_size();
rtp_sender_->SendToNetwork(std::move(packet));
packets.push_back(std::move(packet));
}
rtp_sender_->EnqueuePackets(std::move(packets));
return generated_bytes;
}
@ -339,7 +342,8 @@ TEST_F(RtpSenderTest, PaddingAlwaysAllowedOnAudio) {
}
TEST_F(RtpSenderTest, SendToNetworkForwardsPacketsToPacer) {
auto packet =
std::vector<std::unique_ptr<RtpPacketToSend>> packets(1);
packets[0] =
BuildRtpPacket(kPayload, kMarkerBit, kTimestamp, Timestamp::Zero());
Timestamp now = clock_->CurrentTime();
@ -347,7 +351,8 @@ TEST_F(RtpSenderTest, SendToNetworkForwardsPacketsToPacer) {
EnqueuePackets(ElementsAre(AllOf(
Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)),
Pointee(Property(&RtpPacketToSend::capture_time, now))))));
EXPECT_TRUE(rtp_sender_->SendToNetwork(std::move(packet)));
rtp_sender_->EnqueuePackets(std::move(packets));
}
TEST_F(RtpSenderTest, ReSendPacketForwardsPacketsToPacer) {
@ -398,7 +403,7 @@ TEST_F(RtpSenderTest, SendPadding) {
std::vector<std::unique_ptr<RtpPacketToSend>> padding_packets =
Sequence(GeneratePadding(kPaddingTargetBytes));
ASSERT_THAT(padding_packets, SizeIs(1));
rtp_sender_->SendToNetwork(std::move(padding_packets[0]));
rtp_sender_->EnqueuePackets(std::move(padding_packets));
}
// Send a regular video packet again.