Only create ALR detector in PacedSender if deprecated functions are called.
Bug: webrtc:10108
Change-Id: Ic41693c4017b47093fc373547d59b7723493c70d
Reviewed-on: https://webrtc-review.googlesource.com/c/113527
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25937}
diff --git a/modules/pacing/mock/mock_paced_sender.h b/modules/pacing/mock/mock_paced_sender.h
index 4a5337d..0bf102f 100644
--- a/modules/pacing/mock/mock_paced_sender.h
+++ b/modules/pacing/mock/mock_paced_sender.h
@@ -36,8 +36,7 @@
MOCK_CONST_METHOD0(QueueInMs, int64_t());
MOCK_CONST_METHOD0(QueueInPackets, int());
MOCK_CONST_METHOD0(ExpectedQueueTimeMs, int64_t());
- MOCK_CONST_METHOD0(GetApplicationLimitedRegionStartTime,
- absl::optional<int64_t>());
+ MOCK_METHOD0(GetApplicationLimitedRegionStartTime, absl::optional<int64_t>());
MOCK_METHOD0(Process, void());
};
diff --git a/modules/pacing/paced_sender.cc b/modules/pacing/paced_sender.cc
index 7e0ac78..050fbb6 100644
--- a/modules/pacing/paced_sender.cc
+++ b/modules/pacing/paced_sender.cc
@@ -47,7 +47,7 @@
RtcEventLog* event_log)
: clock_(clock),
packet_sender_(packet_sender),
- alr_detector_(absl::make_unique<AlrDetector>(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 @@
pacing_bitrate_kbps_ =
std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) *
pacing_factor_;
+ if (!alr_detector_)
+ alr_detector_ = absl::make_unique<AlrDetector>(nullptr /*event_log*/);
alr_detector_->SetEstimatedBitrate(bitrate_bps);
}
@@ -214,9 +216,10 @@
pacing_bitrate_kbps_);
}
-absl::optional<int64_t> PacedSender::GetApplicationLimitedRegionStartTime()
- const {
+absl::optional<int64_t> PacedSender::GetApplicationLimitedRegionStartTime() {
rtc::CritScope cs(&critsect_);
+ if (!alr_detector_)
+ alr_detector_ = absl::make_unique<AlrDetector>(nullptr /*event_log*/);
return alr_detector_->GetApplicationLimitedRegionStartTime();
}
@@ -295,7 +298,8 @@
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 @@
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 4586d29..6c88159 100644
--- a/modules/pacing/paced_sender.h
+++ b/modules/pacing/paced_sender.h
@@ -127,7 +127,7 @@
virtual int64_t ExpectedQueueTimeMs() const;
// Deprecated, alr detection will be moved out of the pacer.
- virtual absl::optional<int64_t> GetApplicationLimitedRegionStartTime() const;
+ virtual absl::optional<int64_t> GetApplicationLimitedRegionStartTime();
// Returns the number of milliseconds until the module want a worker thread
// to call Process.
@@ -167,7 +167,7 @@
const Clock* const clock_;
PacketSender* const packet_sender_;
- const std::unique_ptr<AlrDetector> alr_detector_ RTC_PT_GUARDED_BY(critsect_);
+ std::unique_ptr<AlrDetector> alr_detector_ RTC_PT_GUARDED_BY(critsect_);
const bool drain_large_queues_;
const bool send_padding_if_silent_;