From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- .../libwebrtc/modules/pacing/bitrate_prober.cc | 32 +++++++++++------ .../libwebrtc/modules/pacing/bitrate_prober.h | 6 ++++ .../libwebrtc/modules/pacing/pacing_controller.cc | 4 +++ .../libwebrtc/modules/pacing/pacing_controller.h | 3 ++ .../modules/pacing/pacing_controller_unittest.cc | 41 ++++++++++++++++++---- .../libwebrtc/modules/pacing/packet_router.cc | 10 ++++++ .../libwebrtc/modules/pacing/packet_router.h | 2 ++ .../modules/pacing/packet_router_unittest.cc | 25 +++++++++++++ .../modules/pacing/task_queue_paced_sender.cc | 5 +++ .../modules/pacing/task_queue_paced_sender.h | 3 ++ 10 files changed, 114 insertions(+), 17 deletions(-) (limited to 'third_party/libwebrtc/modules/pacing') diff --git a/third_party/libwebrtc/modules/pacing/bitrate_prober.cc b/third_party/libwebrtc/modules/pacing/bitrate_prober.cc index e60a1e5283..17729b5775 100644 --- a/third_party/libwebrtc/modules/pacing/bitrate_prober.cc +++ b/third_party/libwebrtc/modules/pacing/bitrate_prober.cc @@ -52,6 +52,18 @@ void BitrateProber::SetEnabled(bool enable) { } } +void BitrateProber::SetAllowProbeWithoutMediaPacket(bool allow) { + config_.allow_start_probing_immediately = allow; + MaybeSetActiveState(/*packet_size=*/DataSize::Zero()); +} + +void BitrateProber::MaybeSetActiveState(DataSize packet_size) { + if (ReadyToSetActiveState(packet_size)) { + next_probe_time_ = Timestamp::MinusInfinity(); + probing_state_ = ProbingState::kActive; + } +} + bool BitrateProber::ReadyToSetActiveState(DataSize packet_size) const { if (clusters_.empty()) { RTC_DCHECK(probing_state_ == ProbingState::kDisabled || @@ -63,19 +75,19 @@ bool BitrateProber::ReadyToSetActiveState(DataSize packet_size) const { case ProbingState::kActive: return false; case ProbingState::kInactive: - // If config_.min_packet_size > 0, a "large enough" packet must be sent - // first, before a probe can be generated and sent. Otherwise, send the - // probe asap. + if (config_.allow_start_probing_immediately) { + return true; + } + // If config_.min_packet_size > 0, a "large enough" packet must be + // sent first, before a probe can be generated and sent. Otherwise, + // send the probe asap. return packet_size >= std::min(RecommendedMinProbeSize(), config_.min_packet_size.Get()); } } void BitrateProber::OnIncomingPacket(DataSize packet_size) { - if (ReadyToSetActiveState(packet_size)) { - next_probe_time_ = Timestamp::MinusInfinity(); - probing_state_ = ProbingState::kActive; - } + MaybeSetActiveState(packet_size); } void BitrateProber::CreateProbeCluster( @@ -101,10 +113,8 @@ void BitrateProber::CreateProbeCluster( cluster.pace_info.probe_cluster_id = cluster_config.id; clusters_.push(cluster); - if (ReadyToSetActiveState(/*packet_size=*/DataSize::Zero())) { - next_probe_time_ = Timestamp::MinusInfinity(); - probing_state_ = ProbingState::kActive; - } + MaybeSetActiveState(/*packet_size=*/DataSize::Zero()); + RTC_DCHECK(probing_state_ == ProbingState::kActive || probing_state_ == ProbingState::kInactive); diff --git a/third_party/libwebrtc/modules/pacing/bitrate_prober.h b/third_party/libwebrtc/modules/pacing/bitrate_prober.h index 82aba6ee3a..821bbf32eb 100644 --- a/third_party/libwebrtc/modules/pacing/bitrate_prober.h +++ b/third_party/libwebrtc/modules/pacing/bitrate_prober.h @@ -38,6 +38,9 @@ struct BitrateProberConfig { // This defines the max min packet size, meaning that on high bitrates // a packet of at least this size is needed to trigger sending a probe. FieldTrialParameter min_packet_size; + + // If true, `min_packet_size` is ignored. + bool allow_start_probing_immediately = false; }; // Note that this class isn't thread-safe by itself and therefore relies @@ -48,6 +51,7 @@ class BitrateProber { ~BitrateProber() = default; void SetEnabled(bool enable); + void SetAllowProbeWithoutMediaPacket(bool allow); // Returns true if the prober is in a probing session, i.e., it currently // wants packets to be sent out according to the time returned by @@ -105,6 +109,8 @@ class BitrateProber { }; Timestamp CalculateNextProbeTime(const ProbeCluster& cluster) const; + + void MaybeSetActiveState(DataSize packet_size); bool ReadyToSetActiveState(DataSize packet_size) const; ProbingState probing_state_; diff --git a/third_party/libwebrtc/modules/pacing/pacing_controller.cc b/third_party/libwebrtc/modules/pacing/pacing_controller.cc index 41f97a37fb..a45c5d8f63 100644 --- a/third_party/libwebrtc/modules/pacing/pacing_controller.cc +++ b/third_party/libwebrtc/modules/pacing/pacing_controller.cc @@ -252,6 +252,10 @@ void PacingController::SetSendBurstInterval(TimeDelta burst_interval) { send_burst_interval_ = burst_interval; } +void PacingController::SetAllowProbeWithoutMediaPacket(bool allow) { + prober_.SetAllowProbeWithoutMediaPacket(allow); +} + TimeDelta PacingController::ExpectedQueueTime() const { RTC_DCHECK_GT(adjusted_media_rate_, DataRate::Zero()); return QueueSizeData() / adjusted_media_rate_; diff --git a/third_party/libwebrtc/modules/pacing/pacing_controller.h b/third_party/libwebrtc/modules/pacing/pacing_controller.h index fe6ee737a9..bdf8bef392 100644 --- a/third_party/libwebrtc/modules/pacing/pacing_controller.h +++ b/third_party/libwebrtc/modules/pacing/pacing_controller.h @@ -160,6 +160,9 @@ class PacingController { // 'burst_interval'. void SetSendBurstInterval(TimeDelta burst_interval); + // A probe may be sent without first waing for a media packet. + void SetAllowProbeWithoutMediaPacket(bool allow); + // Returns the time when the oldest packet was queued. Timestamp OldestPacketEnqueueTime() const; diff --git a/third_party/libwebrtc/modules/pacing/pacing_controller_unittest.cc b/third_party/libwebrtc/modules/pacing/pacing_controller_unittest.cc index 2c3a71b369..8a37292b95 100644 --- a/third_party/libwebrtc/modules/pacing/pacing_controller_unittest.cc +++ b/third_party/libwebrtc/modules/pacing/pacing_controller_unittest.cc @@ -1366,10 +1366,9 @@ TEST_F(PacingControllerTest, CanProbeWithPaddingBeforeFirstMediaPacket) { const int kInitialBitrateBps = 300000; PacingControllerProbing packet_sender; - const test::ExplicitKeyValueConfig trials( - "WebRTC-Bwe-ProbingBehavior/min_packet_size:0/"); auto pacer = - std::make_unique(&clock_, &packet_sender, trials); + std::make_unique(&clock_, &packet_sender, trials_); + pacer->SetAllowProbeWithoutMediaPacket(true); std::vector probe_clusters = { {.at_time = clock_.CurrentTime(), .target_data_rate = kFirstClusterRate, @@ -1393,16 +1392,46 @@ TEST_F(PacingControllerTest, CanProbeWithPaddingBeforeFirstMediaPacket) { EXPECT_GT(packet_sender.padding_packets_sent(), 5); } +TEST_F(PacingControllerTest, ProbeSentAfterSetAllowProbeWithoutMediaPacket) { + const int kInitialBitrateBps = 300000; + + PacingControllerProbing packet_sender; + auto pacer = + std::make_unique(&clock_, &packet_sender, trials_); + std::vector probe_clusters = { + {.at_time = clock_.CurrentTime(), + .target_data_rate = kFirstClusterRate, + .target_duration = TimeDelta::Millis(15), + .target_probe_count = 5, + .id = 0}}; + pacer->CreateProbeClusters(probe_clusters); + + pacer->SetPacingRates( + DataRate::BitsPerSec(kInitialBitrateBps * kPaceMultiplier), + DataRate::Zero()); + + pacer->SetAllowProbeWithoutMediaPacket(true); + + Timestamp start = clock_.CurrentTime(); + Timestamp next_process = pacer->NextSendTime(); + while (clock_.CurrentTime() < start + TimeDelta::Millis(100) && + next_process.IsFinite()) { + AdvanceTimeUntil(next_process); + pacer->ProcessPackets(); + next_process = pacer->NextSendTime(); + } + EXPECT_GT(packet_sender.padding_packets_sent(), 5); +} + TEST_F(PacingControllerTest, CanNotProbeWithPaddingIfGeneratePaddingFails) { // const size_t kPacketSize = 1200; const int kInitialBitrateBps = 300000; PacingControllerProbing packet_sender; packet_sender.SetCanGeneratePadding(false); - const test::ExplicitKeyValueConfig trials( - "WebRTC-Bwe-ProbingBehavior/min_packet_size:0/"); auto pacer = - std::make_unique(&clock_, &packet_sender, trials); + std::make_unique(&clock_, &packet_sender, trials_); + pacer->SetAllowProbeWithoutMediaPacket(true); std::vector probe_clusters = { {.at_time = clock_.CurrentTime(), .target_data_rate = kFirstClusterRate, diff --git a/third_party/libwebrtc/modules/pacing/packet_router.cc b/third_party/libwebrtc/modules/pacing/packet_router.cc index 4c986ad027..0ad64f212d 100644 --- a/third_party/libwebrtc/modules/pacing/packet_router.cc +++ b/third_party/libwebrtc/modules/pacing/packet_router.cc @@ -65,6 +65,16 @@ void PacketRouter::AddSendRtpModule(RtpRtcpInterface* rtp_module, } } +bool PacketRouter::SupportsRtxPayloadPadding() const { + RTC_DCHECK_RUN_ON(&thread_checker_); + for (RtpRtcpInterface* rtp_module : send_modules_list_) { + if (rtp_module->SupportsRtxPayloadPadding()) { + return true; + } + } + return false; +} + void PacketRouter::AddSendRtpModuleToMap(RtpRtcpInterface* rtp_module, uint32_t ssrc) { RTC_DCHECK_RUN_ON(&thread_checker_); diff --git a/third_party/libwebrtc/modules/pacing/packet_router.h b/third_party/libwebrtc/modules/pacing/packet_router.h index 61779f49e5..4c5747f7e3 100644 --- a/third_party/libwebrtc/modules/pacing/packet_router.h +++ b/third_party/libwebrtc/modules/pacing/packet_router.h @@ -50,6 +50,8 @@ class PacketRouter : public PacingController::PacketSender { void AddSendRtpModule(RtpRtcpInterface* rtp_module, bool remb_candidate); void RemoveSendRtpModule(RtpRtcpInterface* rtp_module); + bool SupportsRtxPayloadPadding() const; + void AddReceiveRtpModule(RtcpFeedbackSenderInterface* rtcp_sender, bool remb_candidate); void RemoveReceiveRtpModule(RtcpFeedbackSenderInterface* rtcp_sender); diff --git a/third_party/libwebrtc/modules/pacing/packet_router_unittest.cc b/third_party/libwebrtc/modules/pacing/packet_router_unittest.cc index af8534316c..b91c309eec 100644 --- a/third_party/libwebrtc/modules/pacing/packet_router_unittest.cc +++ b/third_party/libwebrtc/modules/pacing/packet_router_unittest.cc @@ -125,6 +125,31 @@ TEST_F(PacketRouterTest, GeneratePaddingPrioritizesRtx) { packet_router_.RemoveSendRtpModule(&rtp_2); } +TEST_F(PacketRouterTest, SupportsRtxPayloadPaddingFalseIfNoRtxSendModule) { + EXPECT_FALSE(packet_router_.SupportsRtxPayloadPadding()); + + NiceMock none_rtx_module; + ON_CALL(none_rtx_module, SupportsRtxPayloadPadding()) + .WillByDefault(Return(false)); + + packet_router_.AddSendRtpModule(&none_rtx_module, false); + EXPECT_FALSE(packet_router_.SupportsRtxPayloadPadding()); + + packet_router_.RemoveSendRtpModule(&none_rtx_module); + EXPECT_FALSE(packet_router_.SupportsRtxPayloadPadding()); +} + +TEST_F(PacketRouterTest, SupportsRtxPayloadPaddingTrueIfRtxSendModule) { + NiceMock rtx_module; + ON_CALL(rtx_module, SupportsRtxPayloadPadding()).WillByDefault(Return(true)); + + packet_router_.AddSendRtpModule(&rtx_module, false); + EXPECT_TRUE(packet_router_.SupportsRtxPayloadPadding()); + + packet_router_.RemoveSendRtpModule(&rtx_module); + EXPECT_FALSE(packet_router_.SupportsRtxPayloadPadding()); +} + TEST_F(PacketRouterTest, GeneratePaddingPrioritizesVideo) { // Two RTP modules. Neither support RTX, both support padding, // but the first one is for audio and second for video. diff --git a/third_party/libwebrtc/modules/pacing/task_queue_paced_sender.cc b/third_party/libwebrtc/modules/pacing/task_queue_paced_sender.cc index f7218e48a1..5559153251 100644 --- a/third_party/libwebrtc/modules/pacing/task_queue_paced_sender.cc +++ b/third_party/libwebrtc/modules/pacing/task_queue_paced_sender.cc @@ -52,6 +52,11 @@ void TaskQueuePacedSender::SetSendBurstInterval(TimeDelta burst_interval) { pacing_controller_.SetSendBurstInterval(burst_interval); } +void TaskQueuePacedSender::SetAllowProbeWithoutMediaPacket(bool allow) { + RTC_DCHECK_RUN_ON(task_queue_); + pacing_controller_.SetAllowProbeWithoutMediaPacket(allow); +} + void TaskQueuePacedSender::EnsureStarted() { RTC_DCHECK_RUN_ON(task_queue_); is_started_ = true; diff --git a/third_party/libwebrtc/modules/pacing/task_queue_paced_sender.h b/third_party/libwebrtc/modules/pacing/task_queue_paced_sender.h index e29acdf878..a1d2474ca1 100644 --- a/third_party/libwebrtc/modules/pacing/task_queue_paced_sender.h +++ b/third_party/libwebrtc/modules/pacing/task_queue_paced_sender.h @@ -60,6 +60,9 @@ class TaskQueuePacedSender : public RtpPacketPacer, public RtpPacketSender { // 'burst_interval'. void SetSendBurstInterval(TimeDelta burst_interval); + // A probe may be sent without first waing for a media packet. + void SetAllowProbeWithoutMediaPacket(bool allow); + // Ensure that necessary delayed tasks are scheduled. void EnsureStarted(); -- cgit v1.2.3