diff --git a/modules/pacing/mock/mock_paced_sender.h b/modules/pacing/mock/mock_paced_sender.h index 4a5337d70b..0bf102f36d 100644 --- a/modules/pacing/mock/mock_paced_sender.h +++ b/modules/pacing/mock/mock_paced_sender.h @@ -36,8 +36,7 @@ class MockPacedSender : public PacedSender { MOCK_CONST_METHOD0(QueueInMs, int64_t()); MOCK_CONST_METHOD0(QueueInPackets, int()); MOCK_CONST_METHOD0(ExpectedQueueTimeMs, int64_t()); - MOCK_CONST_METHOD0(GetApplicationLimitedRegionStartTime, - absl::optional()); + MOCK_METHOD0(GetApplicationLimitedRegionStartTime, absl::optional()); MOCK_METHOD0(Process, void()); }; diff --git a/modules/pacing/paced_sender.cc b/modules/pacing/paced_sender.cc index 7e0ac781e2..050fbb651a 100644 --- a/modules/pacing/paced_sender.cc +++ b/modules/pacing/paced_sender.cc @@ -47,7 +47,7 @@ PacedSender::PacedSender(const Clock* clock, RtcEventLog* event_log) : clock_(clock), packet_sender_(packet_sender), - alr_detector_(absl::make_unique(event_log)), + alr_detector_(), drain_large_queues_(!field_trial::IsDisabled("WebRTC-Pacer-DrainQueue")), send_padding_if_silent_( field_trial::IsEnabled("WebRTC-Pacer-PadInSilence")), @@ -158,6 +158,8 @@ void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { pacing_bitrate_kbps_ = std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * pacing_factor_; + if (!alr_detector_) + alr_detector_ = absl::make_unique(nullptr /*event_log*/); alr_detector_->SetEstimatedBitrate(bitrate_bps); } @@ -214,9 +216,10 @@ int64_t PacedSender::ExpectedQueueTimeMs() const { pacing_bitrate_kbps_); } -absl::optional PacedSender::GetApplicationLimitedRegionStartTime() - const { +absl::optional PacedSender::GetApplicationLimitedRegionStartTime() { rtc::CritScope cs(&critsect_); + if (!alr_detector_) + alr_detector_ = absl::make_unique(nullptr /*event_log*/); return alr_detector_->GetApplicationLimitedRegionStartTime(); } @@ -295,7 +298,8 @@ void PacedSender::Process() { size_t bytes_sent = packet_sender_->TimeToSendPadding(1, PacedPacketInfo()); critsect_.Enter(); OnPaddingSent(bytes_sent); - alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); + if (alr_detector_) + alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); } if (paused_) @@ -378,7 +382,8 @@ void PacedSender::Process() { if (!probing_send_failure_) prober_.ProbeSent(TimeMilliseconds(), bytes_sent); } - alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); + if (alr_detector_) + alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); } void PacedSender::ProcessThreadAttached(ProcessThread* process_thread) { diff --git a/modules/pacing/paced_sender.h b/modules/pacing/paced_sender.h index 4586d29cca..6c88159e53 100644 --- a/modules/pacing/paced_sender.h +++ b/modules/pacing/paced_sender.h @@ -127,7 +127,7 @@ class PacedSender : public Pacer { virtual int64_t ExpectedQueueTimeMs() const; // Deprecated, alr detection will be moved out of the pacer. - virtual absl::optional GetApplicationLimitedRegionStartTime() const; + virtual absl::optional GetApplicationLimitedRegionStartTime(); // Returns the number of milliseconds until the module want a worker thread // to call Process. @@ -167,7 +167,7 @@ class PacedSender : public Pacer { const Clock* const clock_; PacketSender* const packet_sender_; - const std::unique_ptr alr_detector_ RTC_PT_GUARDED_BY(critsect_); + std::unique_ptr alr_detector_ RTC_PT_GUARDED_BY(critsect_); const bool drain_large_queues_; const bool send_padding_if_silent_;