@@ -456,6 +456,7 @@ void PacingController::ProcessPackets() {
456
456
457
457
PacedPacketInfo pacing_info;
458
458
DataSize recommended_probe_size = DataSize::Zero ();
459
+ DataSize data_sent = DataSize::Zero ();
459
460
bool is_probing = prober_.is_probing ();
460
461
if (is_probing) {
461
462
// Probe timing is sensitive, and handled explicitly by BitrateProber, so
@@ -472,8 +473,8 @@ void PacingController::ProcessPackets() {
472
473
// If no RTP modules sending media are registered, we may not get a
473
474
// padding packet back.
474
475
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 );
477
478
// We should never get more than one padding packets with a requested
478
479
// size of 1 byte.
479
480
RTC_DCHECK_EQ (padding.size (), 1u );
@@ -485,13 +486,18 @@ void PacingController::ProcessPackets() {
485
486
}
486
487
}
487
488
488
- DataSize data_sent = DataSize::Zero ();
489
489
// Circuit breaker, making sure main loop isn't forever.
490
490
static constexpr int kMaxIterations = 1 << 16 ;
491
491
int iteration = 0 ;
492
492
int packets_sent = 0 ;
493
493
int padding_packets_generated = 0 ;
494
494
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
+
495
501
// Fetch packet, so long as queue is not empty or budget is not
496
502
// exhausted.
497
503
std::unique_ptr<RtpPacketToSend> rtp_packet =
@@ -518,33 +524,9 @@ void PacingController::ProcessPackets() {
518
524
// Can't fetch new packet and no padding to send, exit send loop.
519
525
break ;
520
526
} 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);
537
528
++packets_sent;
538
529
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
-
548
530
// Update target send time in case that are more packets that we are late
549
531
// in processing.
550
532
if (mode_ == ProcessMode::kDynamic ) {
@@ -658,6 +640,31 @@ std::unique_ptr<RtpPacketToSend> PacingController::GetPendingPacket(
658
640
return packet_queue_.Pop ();
659
641
}
660
642
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
+
661
668
void PacingController::OnPacketSent (RtpPacketMediaType packet_type,
662
669
DataSize packet_size,
663
670
Timestamp send_time) {
0 commit comments