Skip to content

Commit 8088aad

Browse files
Erik SprångWebRTC LUCI CQ
authored andcommitted
Send first probe packet directly instead of enqueuing it.
This avoids potentially creating needless containers in the packet queue and removes usage of the packet prio, allowing it to be moved in an upcoming CL. Bug: webrtc:11340 Change-Id: Iddd9e7e4e73c97ab25a85e42bcc0094d61fd60d3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/259524 Reviewed-by: Emil Lundmark <[email protected]> Commit-Queue: Erik Språng <[email protected]> Cr-Commit-Position: refs/heads/main@{#36602}
1 parent 1cb5383 commit 8088aad

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

modules/pacing/pacing_controller.cc

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ void PacingController::ProcessPackets() {
456456

457457
PacedPacketInfo pacing_info;
458458
DataSize recommended_probe_size = DataSize::Zero();
459+
DataSize data_sent = DataSize::Zero();
459460
bool is_probing = prober_.is_probing();
460461
if (is_probing) {
461462
// Probe timing is sensitive, and handled explicitly by BitrateProber, so
@@ -472,8 +473,8 @@ void PacingController::ProcessPackets() {
472473
// If no RTP modules sending media are registered, we may not get a
473474
// padding packet back.
474475
if (!padding.empty()) {
475-
// Insert with high priority so larger media packets don't preempt it.
476-
EnqueuePacketInternal(std::move(padding[0]), kFirstPriority);
476+
// Send packet immediately to avoid priority inversions.
477+
data_sent += SendPacket(std::move(padding[0]), pacing_info, now);
477478
// We should never get more than one padding packets with a requested
478479
// size of 1 byte.
479480
RTC_DCHECK_EQ(padding.size(), 1u);
@@ -485,13 +486,18 @@ void PacingController::ProcessPackets() {
485486
}
486487
}
487488

488-
DataSize data_sent = DataSize::Zero();
489489
// Circuit breaker, making sure main loop isn't forever.
490490
static constexpr int kMaxIterations = 1 << 16;
491491
int iteration = 0;
492492
int packets_sent = 0;
493493
int padding_packets_generated = 0;
494494
for (; iteration < kMaxIterations; ++iteration) {
495+
// If we are currently probing, we need to stop the send loop when we have
496+
// reached the send target.
497+
if (is_probing && data_sent >= recommended_probe_size) {
498+
break;
499+
}
500+
495501
// Fetch packet, so long as queue is not empty or budget is not
496502
// exhausted.
497503
std::unique_ptr<RtpPacketToSend> rtp_packet =
@@ -518,33 +524,9 @@ void PacingController::ProcessPackets() {
518524
// Can't fetch new packet and no padding to send, exit send loop.
519525
break;
520526
} else {
521-
RTC_DCHECK(rtp_packet);
522-
RTC_DCHECK(rtp_packet->packet_type().has_value());
523-
const RtpPacketMediaType packet_type = *rtp_packet->packet_type();
524-
DataSize packet_size = DataSize::Bytes(rtp_packet->payload_size() +
525-
rtp_packet->padding_size());
526-
527-
if (include_overhead_) {
528-
packet_size += DataSize::Bytes(rtp_packet->headers_size()) +
529-
transport_overhead_per_packet_;
530-
}
531-
532-
packet_sender_->SendPacket(std::move(rtp_packet), pacing_info);
533-
for (auto& packet : packet_sender_->FetchFec()) {
534-
EnqueuePacket(std::move(packet));
535-
}
536-
data_sent += packet_size;
527+
data_sent += SendPacket(std::move(rtp_packet), pacing_info, now);
537528
++packets_sent;
538529

539-
// Send done, update send time.
540-
OnPacketSent(packet_type, packet_size, now);
541-
542-
// If we are currently probing, we need to stop the send loop when we
543-
// have reached the send target.
544-
if (is_probing && data_sent >= recommended_probe_size) {
545-
break;
546-
}
547-
548530
// Update target send time in case that are more packets that we are late
549531
// in processing.
550532
if (mode_ == ProcessMode::kDynamic) {
@@ -658,6 +640,31 @@ std::unique_ptr<RtpPacketToSend> PacingController::GetPendingPacket(
658640
return packet_queue_.Pop();
659641
}
660642

643+
DataSize PacingController::SendPacket(std::unique_ptr<RtpPacketToSend> packet,
644+
const PacedPacketInfo& pacing_info,
645+
Timestamp now) {
646+
RTC_DCHECK(packet);
647+
RTC_DCHECK(packet->packet_type().has_value());
648+
const RtpPacketMediaType packet_type = *packet->packet_type();
649+
DataSize packet_size =
650+
DataSize::Bytes(packet->payload_size() + packet->padding_size());
651+
652+
if (include_overhead_) {
653+
packet_size += DataSize::Bytes(packet->headers_size()) +
654+
transport_overhead_per_packet_;
655+
}
656+
657+
packet_sender_->SendPacket(std::move(packet), pacing_info);
658+
for (std::unique_ptr<RtpPacketToSend>& packet : packet_sender_->FetchFec()) {
659+
EnqueuePacket(std::move(packet));
660+
}
661+
662+
// Sending complete, update send time.
663+
OnPacketSent(packet_type, packet_size, now);
664+
665+
return packet_size;
666+
}
667+
661668
void PacingController::OnPacketSent(RtpPacketMediaType packet_type,
662669
DataSize packet_size,
663670
Timestamp send_time) {

modules/pacing/pacing_controller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ class PacingController {
167167
const PacedPacketInfo& pacing_info,
168168
Timestamp target_send_time,
169169
Timestamp now);
170+
DataSize SendPacket(std::unique_ptr<RtpPacketToSend> packet,
171+
const PacedPacketInfo& pacing_info,
172+
Timestamp now);
170173
void OnPacketSent(RtpPacketMediaType packet_type,
171174
DataSize packet_size,
172175
Timestamp send_time);

0 commit comments

Comments
 (0)