commit 128de602f766f9ac8d929203326da3068a03be65
parent d3076dd909e5fad7b0d5faefa855fc1921d581b4
Author: Michael Froman <mfroman@mozilla.com>
Date: Wed, 15 Oct 2025 11:42:56 -0500
Bug 1993083 - Vendor libwebrtc from 43ad70896c
Upstream commit: https://webrtc.googlesource.com/src/+/43ad70896caedd30cd6893424eeca335b2255337
Cleanup AlrDetector construction
Merge all constructors into single one
Pass Environment instead of its components separately
Hide AlrDetectorConfig from public api
Unwrap unique_ptr<AlrDetector> as AlrDetector is never moved
Bug: None
Change-Id: I80ca6bc5fad60074e5f5fb94c496173726c56764
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/402641
Auto-Submit: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45262}
Diffstat:
7 files changed, 58 insertions(+), 75 deletions(-)
diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor
@@ -1,4 +1,4 @@
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
-libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-15T16:41:44.855423+00:00.
+libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-15T16:42:47.314222+00:00.
# base of lastest vendoring
-cdc641f20d
+43ad70896c
diff --git a/third_party/libwebrtc/modules/congestion_controller/goog_cc/BUILD.gn b/third_party/libwebrtc/modules/congestion_controller/goog_cc/BUILD.gn
@@ -25,7 +25,6 @@ rtc_library("goog_cc") {
"../../../api:field_trials_view",
"../../../api:network_state_predictor_api",
"../../../api/environment",
- "../../../api/rtc_event_log",
"../../../api/transport:bandwidth_usage",
"../../../api/transport:network_control",
"../../../api/units:data_rate",
@@ -33,15 +32,11 @@ rtc_library("goog_cc") {
"../../../api/units:time_delta",
"../../../api/units:timestamp",
"../../../logging:rtc_event_bwe",
- "../../../logging:rtc_event_pacing",
"../../../rtc_base:checks",
"../../../rtc_base:logging",
- "../../../rtc_base/experiments:alr_experiment",
"../../../rtc_base/experiments:field_trial_parser",
"../../../rtc_base/experiments:rate_control_settings",
- "../../../system_wrappers",
"../../remote_bitrate_estimator",
- "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/strings:string_view",
]
}
@@ -78,6 +73,7 @@ rtc_library("alr_detector") {
]
deps = [
"../../../api:field_trials_view",
+ "../../../api/environment",
"../../../api/rtc_event_log",
"../../../api/units:data_rate",
"../../../api/units:data_size",
@@ -85,7 +81,6 @@ rtc_library("alr_detector") {
"../../../api/units:timestamp",
"../../../logging:rtc_event_pacing",
"../../../rtc_base:checks",
- "../../../rtc_base:safe_conversions",
"../../../rtc_base:timeutils",
"../../../rtc_base/experiments:alr_experiment",
"../../../rtc_base/experiments:field_trial_parser",
diff --git a/third_party/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc b/third_party/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc
@@ -13,6 +13,7 @@
#include <memory>
#include <optional>
+#include "api/environment/environment.h"
#include "api/field_trials_view.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "api/units/data_rate.h"
@@ -27,50 +28,37 @@
namespace webrtc {
-namespace {
-AlrDetectorConfig GetConfigFromTrials(const FieldTrialsView* key_value_config) {
- RTC_CHECK(AlrExperimentSettings::MaxOneFieldTrialEnabled(*key_value_config));
+AlrDetector::AlrDetectorConfig::AlrDetectorConfig(
+ const FieldTrialsView& key_value_config) {
+ RTC_CHECK(AlrExperimentSettings::MaxOneFieldTrialEnabled(key_value_config));
std::optional<AlrExperimentSettings> experiment_settings =
AlrExperimentSettings::CreateFromFieldTrial(
- *key_value_config,
+ key_value_config,
AlrExperimentSettings::kScreenshareProbingBweExperimentName);
if (!experiment_settings) {
experiment_settings = AlrExperimentSettings::CreateFromFieldTrial(
- *key_value_config,
+ key_value_config,
AlrExperimentSettings::kStrictPacingAndProbingExperimentName);
}
- AlrDetectorConfig conf;
if (experiment_settings) {
- conf.bandwidth_usage_ratio =
+ bandwidth_usage_ratio =
experiment_settings->alr_bandwidth_usage_percent / 100.0;
- conf.start_budget_level_ratio =
+ start_budget_level_ratio =
experiment_settings->alr_start_budget_level_percent / 100.0;
- conf.stop_budget_level_ratio =
+ stop_budget_level_ratio =
experiment_settings->alr_stop_budget_level_percent / 100.0;
}
- conf.Parser()->Parse(
- key_value_config->Lookup("WebRTC-AlrDetectorParameters"));
- return conf;
-}
-} // namespace
-
-std::unique_ptr<StructParametersParser> AlrDetectorConfig::Parser() {
- return StructParametersParser::Create( //
+ StructParametersParser::Create( //
"bw_usage", &bandwidth_usage_ratio, //
"start", &start_budget_level_ratio, //
- "stop", &stop_budget_level_ratio);
+ "stop", &stop_budget_level_ratio)
+ ->Parse(key_value_config.Lookup("WebRTC-AlrDetectorParameters"));
}
-AlrDetector::AlrDetector(AlrDetectorConfig config, RtcEventLog* event_log)
- : conf_(config), alr_budget_(0, true), event_log_(event_log) {}
-
-AlrDetector::AlrDetector(const FieldTrialsView* key_value_config)
- : AlrDetector(GetConfigFromTrials(key_value_config), nullptr) {}
+AlrDetector::AlrDetector(const Environment& env)
+ : env_(env), conf_(env_.field_trials()), alr_budget_(0, true) {}
-AlrDetector::AlrDetector(const FieldTrialsView* key_value_config,
- RtcEventLog* event_log)
- : AlrDetector(GetConfigFromTrials(key_value_config), event_log) {}
-AlrDetector::~AlrDetector() {}
+AlrDetector::~AlrDetector() = default;
void AlrDetector::OnBytesSent(DataSize bytes_sent, Timestamp send_time) {
if (!last_send_time_.has_value()) {
@@ -94,8 +82,8 @@ void AlrDetector::OnBytesSent(DataSize bytes_sent, Timestamp send_time) {
state_changed = true;
alr_started_time_ = std::nullopt;
}
- if (event_log_ && state_changed) {
- event_log_->Log(
+ if (state_changed) {
+ env_.event_log().Log(
std::make_unique<RtcEventAlrState>(alr_started_time_.has_value()));
}
}
diff --git a/third_party/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.h b/third_party/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.h
@@ -11,31 +11,17 @@
#ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_ALR_DETECTOR_H_
#define MODULES_CONGESTION_CONTROLLER_GOOG_CC_ALR_DETECTOR_H_
-#include <memory>
#include <optional>
+#include "api/environment/environment.h"
#include "api/field_trials_view.h"
#include "api/units/data_rate.h"
#include "api/units/data_size.h"
#include "api/units/timestamp.h"
#include "modules/pacing/interval_budget.h"
-#include "rtc_base/experiments/struct_parameters_parser.h"
namespace webrtc {
-class RtcEventLog;
-
-struct AlrDetectorConfig {
- // Sent traffic ratio as a function of network capacity used to determine
- // application-limited region. ALR region start when bandwidth usage drops
- // below kAlrStartUsageRatio and ends when it raises above
- // kAlrEndUsageRatio. NOTE: This is intentionally conservative at the moment
- // until BW adjustments of application limited region is fine tuned.
- double bandwidth_usage_ratio = 0.65;
- double start_budget_level_ratio = 0.80;
- double stop_budget_level_ratio = 0.50;
- std::unique_ptr<StructParametersParser> Parser();
-};
// Application limited region detector is a class that utilizes signals of
// elapsed time and bytes sent to estimate whether network traffic is
// currently limited by the application's ability to generate traffic.
@@ -45,9 +31,11 @@ struct AlrDetectorConfig {
// Note: This class is not thread-safe.
class AlrDetector {
public:
- AlrDetector(AlrDetectorConfig config, RtcEventLog* event_log);
- explicit AlrDetector(const FieldTrialsView* key_value_config);
- AlrDetector(const FieldTrialsView* key_value_config, RtcEventLog* event_log);
+ explicit AlrDetector(const Environment& env);
+
+ AlrDetector(const AlrDetector&) = delete;
+ AlrDetector& operator=(const AlrDetector&) = delete;
+
~AlrDetector();
void OnBytesSent(DataSize bytes_sent, Timestamp send_time);
@@ -61,14 +49,26 @@ class AlrDetector {
private:
friend class GoogCcStatePrinter;
+ struct AlrDetectorConfig {
+ explicit AlrDetectorConfig(const FieldTrialsView& key_value_config);
+
+ // Sent traffic ratio as a function of network capacity used to determine
+ // application-limited region. ALR region start when bandwidth usage drops
+ // below kAlrStartUsageRatio and ends when it raises above
+ // kAlrEndUsageRatio. NOTE: This is intentionally conservative at the moment
+ // until BW adjustments of application limited region is fine tuned.
+ double bandwidth_usage_ratio = 0.65;
+ double start_budget_level_ratio = 0.80;
+ double stop_budget_level_ratio = 0.50;
+ };
+
+ const Environment env_;
const AlrDetectorConfig conf_;
std::optional<Timestamp> last_send_time_;
IntervalBudget alr_budget_;
std::optional<Timestamp> alr_started_time_;
-
- RtcEventLog* event_log_;
};
} // namespace webrtc
diff --git a/third_party/libwebrtc/modules/congestion_controller/goog_cc/alr_detector_unittest.cc b/third_party/libwebrtc/modules/congestion_controller/goog_cc/alr_detector_unittest.cc
@@ -13,6 +13,7 @@
#include <optional>
#include "absl/base/nullability.h"
+#include "api/environment/environment_factory.h"
#include "api/field_trials.h"
#include "api/units/data_rate.h"
#include "api/units/time_delta.h"
@@ -68,9 +69,9 @@ class SimulateOutgoingTrafficIn {
} // namespace
TEST(AlrDetectorTest, AlrDetection) {
- FieldTrials field_trials = CreateTestFieldTrials();
SimulatedClock clock(Timestamp::Seconds(1));
- AlrDetector alr_detector(&field_trials);
+ AlrDetector alr_detector(
+ CreateEnvironment(CreateTestFieldTrialsPtr(), &clock));
alr_detector.SetEstimatedBitrate(kEstimatedBitrate);
// Start in non-ALR state.
@@ -96,9 +97,9 @@ TEST(AlrDetectorTest, AlrDetection) {
}
TEST(AlrDetectorTest, ShortSpike) {
- FieldTrials field_trials = CreateTestFieldTrials();
SimulatedClock clock(Timestamp::Seconds(1));
- AlrDetector alr_detector(&field_trials);
+ AlrDetector alr_detector(
+ CreateEnvironment(CreateTestFieldTrialsPtr(), &clock));
alr_detector.SetEstimatedBitrate(kEstimatedBitrate);
// Start in non-ALR state.
EXPECT_FALSE(alr_detector.GetApplicationLimitedRegionStartTime());
@@ -123,9 +124,9 @@ TEST(AlrDetectorTest, ShortSpike) {
}
TEST(AlrDetectorTest, BandwidthEstimateChanges) {
- FieldTrials field_trials = CreateTestFieldTrials();
SimulatedClock clock(Timestamp::Seconds(1));
- AlrDetector alr_detector(&field_trials);
+ AlrDetector alr_detector(
+ CreateEnvironment(CreateTestFieldTrialsPtr(), &clock));
alr_detector.SetEstimatedBitrate(kEstimatedBitrate);
// Start in non-ALR state.
@@ -174,11 +175,11 @@ TEST(AlrDetectorTest, ParseActiveFieldTrial) {
}
TEST(AlrDetectorTest, ParseAlrSpecificFieldTrial) {
- FieldTrials field_trials = CreateTestFieldTrials(
- "WebRTC-AlrDetectorParameters/"
- "bw_usage:90%,start:0%,stop:-10%/");
- AlrDetector alr_detector(&field_trials);
SimulatedClock clock(Timestamp::Seconds(1));
+ AlrDetector alr_detector(CreateEnvironment(
+ CreateTestFieldTrialsPtr(
+ "WebRTC-AlrDetectorParameters/bw_usage:90%,start:0%,stop:-10%/"),
+ &clock));
alr_detector.SetEstimatedBitrate(kEstimatedBitrate);
// Start in non-ALR state.
diff --git a/third_party/libwebrtc/modules/congestion_controller/goog_cc/goog_cc_network_control.cc b/third_party/libwebrtc/modules/congestion_controller/goog_cc/goog_cc_network_control.cc
@@ -113,8 +113,7 @@ GoogCcNetworkController::GoogCcNetworkController(NetworkControllerConfig config,
bandwidth_estimation_(
std::make_unique<SendSideBandwidthEstimation>(&env_.field_trials(),
&env_.event_log())),
- alr_detector_(std::make_unique<AlrDetector>(&env_.field_trials(),
- &env_.event_log())),
+ alr_detector_(env_),
probe_bitrate_estimator_(new ProbeBitrateEstimator(&env_.event_log())),
network_estimator_(std::move(goog_cc_config.network_state_estimator)),
network_state_predictor_(
@@ -221,7 +220,7 @@ NetworkControlUpdate GoogCcNetworkController::OnProcessInterval(
}
bandwidth_estimation_->UpdateEstimate(msg.at_time);
probe_controller_->SetAlrStartTime(
- alr_detector_->GetApplicationLimitedRegionStartTime());
+ alr_detector_.GetApplicationLimitedRegionStartTime());
auto probes = probe_controller_->Process(msg.at_time);
update.probe_cluster_configs.insert(update.probe_cluster_configs.end(),
@@ -262,9 +261,9 @@ NetworkControlUpdate GoogCcNetworkController::OnRoundTripTimeUpdate(
NetworkControlUpdate GoogCcNetworkController::OnSentPacket(
SentPacket sent_packet) {
- alr_detector_->OnBytesSent(sent_packet.size, sent_packet.send_time);
+ alr_detector_.OnBytesSent(sent_packet.size, sent_packet.send_time);
acknowledged_bitrate_estimator_->SetAlr(
- alr_detector_->GetApplicationLimitedRegionStartTime().has_value());
+ alr_detector_.GetApplicationLimitedRegionStartTime().has_value());
if (!first_packet_sent_) {
first_packet_sent_ = true;
@@ -444,7 +443,7 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback(
}
std::optional<Timestamp> alr_start_time =
- alr_detector_->GetApplicationLimitedRegionStartTime();
+ alr_detector_.GetApplicationLimitedRegionStartTime();
if (previously_in_alr_ && !alr_start_time.has_value()) {
acknowledged_bitrate_estimator_->SetAlrEndedTime(report.feedback_time);
probe_controller_->SetAlrEndedTime(report.feedback_time);
@@ -613,7 +612,7 @@ void GoogCcNetworkController::MaybeTriggerOnNetworkChanged(
last_estimated_round_trip_time_ = round_trip_time;
last_loss_base_state_ = loss_based_state;
- alr_detector_->SetEstimatedBitrate(loss_based_target_rate);
+ alr_detector_.SetEstimatedBitrate(loss_based_target_rate);
TimeDelta bwe_period = delay_based_bwe_->GetExpectedBwePeriod();
diff --git a/third_party/libwebrtc/modules/congestion_controller/goog_cc/goog_cc_network_control.h b/third_party/libwebrtc/modules/congestion_controller/goog_cc/goog_cc_network_control.h
@@ -98,7 +98,7 @@ class GoogCcNetworkController : public NetworkControllerInterface {
congestion_window_pushback_controller_;
std::unique_ptr<SendSideBandwidthEstimation> bandwidth_estimation_;
- std::unique_ptr<AlrDetector> alr_detector_;
+ AlrDetector alr_detector_;
std::unique_ptr<ProbeBitrateEstimator> probe_bitrate_estimator_;
std::unique_ptr<NetworkStateEstimator> network_estimator_;
std::unique_ptr<NetworkStatePredictor> network_state_predictor_;