diff --git a/modules/pacing/pacing_controller.cc b/modules/pacing/pacing_controller.cc index f2895cf4e2..28d78734f3 100644 --- a/modules/pacing/pacing_controller.cc +++ b/modules/pacing/pacing_controller.cc @@ -463,6 +463,7 @@ void PacingController::ProcessPackets() { PacedPacketInfo pacing_info; DataSize recommended_probe_size = DataSize::Zero(); + DataSize data_sent = DataSize::Zero(); bool is_probing = prober_.is_probing(); if (is_probing) { // Probe timing is sensitive, and handled explicitly by BitrateProber, so @@ -479,11 +480,21 @@ void PacingController::ProcessPackets() { // If no RTP modules sending media are registered, we may not get a // padding packet back. if (!padding.empty()) { - // Insert with high priority so larger media packets don't preempt it. - EnqueuePacketInternal(std::move(padding[0]), kFirstPriority); // We should never get more than one padding packets with a requested // size of 1 byte. RTC_DCHECK_EQ(padding.size(), 1u); + + // Send packet immediately to avoid priority inversions. + data_sent += SendPacket(std::move(padding[0]), pacing_info, now); + + // If we are currently probing, we need to stop the send sending when + // we have reached the send target. + if (is_probing && data_sent >= recommended_probe_size) { + RTC_DCHECK(!data_sent.IsZero()); + probing_send_failure_ = false; + prober_.ProbeSent(CurrentTime(), data_sent); + return; + } } } } else { @@ -492,7 +503,6 @@ void PacingController::ProcessPackets() { } } - DataSize data_sent = DataSize::Zero(); // Circuit breaker, making sure main loop isn't forever. static constexpr int kMaxIterations = 1 << 16; int iteration = 0; @@ -525,29 +535,11 @@ void PacingController::ProcessPackets() { // Can't fetch new packet and no padding to send, exit send loop. break; } else { - RTC_DCHECK(rtp_packet); - RTC_DCHECK(rtp_packet->packet_type().has_value()); - const RtpPacketMediaType packet_type = *rtp_packet->packet_type(); - DataSize packet_size = DataSize::Bytes(rtp_packet->payload_size() + - rtp_packet->padding_size()); - - if (include_overhead_) { - packet_size += DataSize::Bytes(rtp_packet->headers_size()) + - transport_overhead_per_packet_; - } - - packet_sender_->SendPacket(std::move(rtp_packet), pacing_info); - for (auto& packet : packet_sender_->FetchFec()) { - EnqueuePacket(std::move(packet)); - } - data_sent += packet_size; + data_sent += SendPacket(std::move(rtp_packet), pacing_info, now); ++packets_sent; - // Send done, update send time. - OnPacketSent(packet_type, packet_size, now); - - // If we are currently probing, we need to stop the send loop when we - // have reached the send target. + // If we are currently probing, we need to stop the send loop when we have + // reached the send target. if (is_probing && data_sent >= recommended_probe_size) { break; } @@ -665,6 +657,31 @@ std::unique_ptr PacingController::GetPendingPacket( return packet_queue_.Pop(); } +DataSize PacingController::SendPacket(std::unique_ptr packet, + const PacedPacketInfo& pacing_info, + Timestamp now) { + RTC_DCHECK(packet); + RTC_DCHECK(packet->packet_type().has_value()); + const RtpPacketMediaType packet_type = *packet->packet_type(); + DataSize packet_size = + DataSize::Bytes(packet->payload_size() + packet->padding_size()); + + if (include_overhead_) { + packet_size += DataSize::Bytes(packet->headers_size()) + + transport_overhead_per_packet_; + } + + packet_sender_->SendPacket(std::move(packet), pacing_info); + for (std::unique_ptr& packet : packet_sender_->FetchFec()) { + EnqueuePacket(std::move(packet)); + } + + // Sending complete, update send time. + OnPacketSent(packet_type, packet_size, now); + + return packet_size; +} + void PacingController::OnPacketSent(RtpPacketMediaType packet_type, DataSize packet_size, Timestamp send_time) { diff --git a/modules/pacing/pacing_controller.h b/modules/pacing/pacing_controller.h index c3e1dde2fb..7c5b4a6d28 100644 --- a/modules/pacing/pacing_controller.h +++ b/modules/pacing/pacing_controller.h @@ -167,6 +167,9 @@ class PacingController { const PacedPacketInfo& pacing_info, Timestamp target_send_time, Timestamp now); + DataSize SendPacket(std::unique_ptr packet, + const PacedPacketInfo& pacing_info, + Timestamp now); void OnPacketSent(RtpPacketMediaType packet_type, DataSize packet_size, Timestamp send_time);