Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit e76c694

Browse files
taste1981jianjunz
authored andcommitted
Update bwe logic to seperate gpra with gcc. Also allow application set lower/upper bounds of bitrate for gpra (#83)
1 parent e8ccac0 commit e76c694

File tree

3 files changed

+115
-20
lines changed

3 files changed

+115
-20
lines changed

modules/congestion_controller/goog_cc/goog_cc_network_control.cc

Lines changed: 107 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h"
3333
#include "rtc_base/checks.h"
3434
#include "rtc_base/logging.h"
35+
#include "system_wrappers/include/field_trial.h"
3536
#ifdef INTEL_GPRA
3637
#include "gpra_bwe.h"
3738
#endif
@@ -54,6 +55,39 @@ constexpr float kDefaultPaceMultiplier = 2.5f;
5455
// However, if we actually are overusing, we want to drop to something slightly
5556
// below the current throughput estimate to drain the network queues.
5657
constexpr double kProbeDropThroughputFraction = 0.85;
58+
}
59+
60+
bool AllowExternalBwe() {
61+
#ifdef INTEL_GPRA
62+
if (field_trial::IsEnabled("OWT-ExternalBwe")) {
63+
return true;
64+
} else {
65+
return false;
66+
}
67+
#else
68+
return false;
69+
#endif
70+
}
71+
72+
bool GetExternalBweRateLimits(int* start_bitrate_kbps,
73+
int* min_bitrate_kbps,
74+
int* max_bitrate_kbps) {
75+
std::string expr_str = webrtc::field_trial::FindFullName("OWT-BweRateLimits");
76+
if (expr_str.empty())
77+
return false;
78+
int parsed_values =
79+
sscanf_s(expr_str.c_str(), "Enabled-%u,%u,%u", start_bitrate_kbps,
80+
min_bitrate_kbps, max_bitrate_kbps);
81+
if (parsed_values == 3) {
82+
RTC_CHECK_GE(*start_bitrate_kbps, 0)
83+
<< "start_bitrate_kbps must not be smaller than 0.";
84+
RTC_CHECK_GE(*min_bitrate_kbps, 0)
85+
<< " min_bitrate_kbps must not be smaller than 0.";
86+
RTC_CHECK_GE(*max_bitrate_kbps, 0)
87+
<< "max_bitrate_kbps must not be smaller than 0";
88+
return true;
89+
}
90+
return false;
5791

5892
bool IsEnabled(const FieldTrialsView* config, absl::string_view key) {
5993
return absl::StartsWith(config->Lookup(key), "Enabled");
@@ -106,7 +140,13 @@ GoogCcNetworkController::GoogCcNetworkController(NetworkControllerConfig config,
106140
network_state_predictor_(
107141
std::move(goog_cc_config.network_state_predictor)),
108142
#ifdef INTEL_GPRA
109-
delay_based_bwe_(new GPRABwe()),
143+
delay_based_bwe_(AllowExternalBwe() ? new GPRABwe() : nullptr),
144+
delay_based_bwe_gcc_(
145+
AllowExternalBwe()
146+
? nullptr
147+
: new DelayBasedBwe(key_value_config_,
148+
event_log_,
149+
network_state_predictor_.get())),
110150
#else
111151
delay_based_bwe_(new DelayBasedBwe(key_value_config_,
112152
event_log_,
@@ -132,6 +172,25 @@ GoogCcNetworkController::GoogCcNetworkController(NetworkControllerConfig config,
132172
key_value_config_->Lookup("WebRTC-Bwe-SafeResetOnRouteChange"));
133173
if (delay_based_bwe_)
134174
delay_based_bwe_->SetMinBitrate(kCongestionControllerMinBitrate);
175+
if (delay_based_bwe_gcc_)
176+
delay_based_bwe_gcc_->SetMinBitrate(congestion_controller::GetMinBitrate());
177+
if (AllowExternalBwe()) {
178+
if (GetExternalBweRateLimits(&external_start_bitrate_kbps_,
179+
&external_min_bitrate_kbps_,
180+
&external_max_bitrate_kbps_)) {
181+
if (external_start_bitrate_kbps_ > 0)
182+
delay_based_bwe_->SetStartBitrate(
183+
webrtc::DataRate::BitsPerSec(external_start_bitrate_kbps_ * 1024));
184+
if (external_min_bitrate_kbps_ > 0)
185+
delay_based_bwe_->SetMinBitrate(
186+
webrtc::DataRate::BitsPerSec(external_min_bitrate_kbps_ * 1024));
187+
#ifdef INTEL_GPRA
188+
// Only intel_gpra module allows setting maxbitrate.
189+
if (external_max_bitrate_kbps_ > 0)
190+
delay_based_bwe_->SetMaxBitrate(external_max_bitrate_kbps_ * 1024);
191+
#endif
192+
}
193+
}
135194
}
136195

137196
GoogCcNetworkController::~GoogCcNetworkController() {}
@@ -250,6 +309,10 @@ NetworkControlUpdate GoogCcNetworkController::OnRoundTripTimeUpdate(
250309
RTC_DCHECK(!msg.round_trip_time.IsZero());
251310
if (delay_based_bwe_)
252311
delay_based_bwe_->OnRttUpdate(msg.round_trip_time);
312+
#ifdef INTEL_GPRA
313+
if (delay_based_bwe_gcc_)
314+
delay_based_bwe_gcc_->OnRttUpdate(msg.round_trip_time);
315+
#endif
253316
bandwidth_estimation_->UpdateRtt(msg.round_trip_time, msg.receive_time);
254317
return NetworkControlUpdate();
255318
}
@@ -316,7 +379,12 @@ NetworkControlUpdate GoogCcNetworkController::OnStreamsConfig(
316379

317380
if (use_min_allocatable_as_lower_bound_) {
318381
ClampConstraints();
319-
delay_based_bwe_->SetMinBitrate(min_data_rate_);
382+
if (delay_based_bwe_)
383+
delay_based_bwe_->SetMinBitrate(min_data_rate_);
384+
#ifdef INTEL_GPRA
385+
if (delay_based_bwe_gcc_)
386+
delay_based_bwe_gcc_->SetMinBitrate(min_data_rate_);
387+
#endif
320388
bandwidth_estimation_->SetMinMaxBitrate(min_data_rate_, max_data_rate_);
321389
}
322390
}
@@ -408,7 +476,8 @@ void GoogCcNetworkController::UpdateCongestionWindowSize() {
408476
}
409477

410478
NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback(
411-
TransportPacketsFeedback report, int64_t current_offset_ms) {
479+
TransportPacketsFeedback report,
480+
int64_t current_offset_ms) {
412481
if (report.packet_feedbacks.empty()) {
413482
// TODO(bugs.webrtc.org/10125): Design a better mechanism to safe-guard
414483
// against building very large network queues.
@@ -453,6 +522,12 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback(
453522
int64_t mean_rtt_ms = sum_rtt_ms / feedback_max_rtts_.size();
454523
if (delay_based_bwe_)
455524
delay_based_bwe_->OnRttUpdate(TimeDelta::Millis(mean_rtt_ms));
525+
else {
526+
#ifdef INTEL_GPRA
527+
if (delay_based_bwe_gcc_)
528+
delay_based_bwe_gcc_->OnRttUpdate(TimeDelta::Millis(mean_rtt_ms));
529+
#endif
530+
}
456531
}
457532

458533
TimeDelta feedback_min_rtt = TimeDelta::PlusInfinity();
@@ -519,7 +594,6 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback(
519594
absl::optional<DataRate> probe_bitrate =
520595
probe_bitrate_estimator_->FetchAndResetLastEstimatedBitrate();
521596
#ifdef INTEL_GPRA
522-
523597
if (ignore_probes_lower_than_network_estimate_ && probe_bitrate &&
524598
estimate_ && *probe_bitrate < estimate_->link_capacity_lower) {
525599
#else
@@ -549,10 +623,18 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback(
549623

550624
DelayBasedBwe::Result result;
551625
#ifdef INTEL_GPRA
552-
delay_based_bwe_->SetCurrentOffsetMs(current_offset_ms);
553-
result = delay_based_bwe_->IncomingPacketFeedbackVector(
554-
report, acknowledged_bitrate, probe_bitrate, estimate_,
555-
alr_start_time.has_value());
626+
if (delay_based_bwe_) {
627+
delay_based_bwe_->SetCurrentOffsetMs(current_offset_ms);
628+
result = delay_based_bwe_->IncomingPacketFeedbackVector(
629+
report, acknowledged_bitrate, probe_bitrate, estimate_,
630+
alr_start_time.has_value());
631+
} else {
632+
if (delay_based_bwe_gcc_) {
633+
result = delay_based_bwe_gcc_->IncomingPacketFeedbackVector(
634+
report, acknowledged_bitrate, probe_bitrate, estimate_,
635+
alr_start_time.has_value());
636+
}
637+
}
556638
#else
557639
result = delay_based_bwe_->IncomingPacketFeedbackVector(
558640
report, acknowledged_bitrate, probe_bitrate, estimate_,
@@ -616,8 +698,16 @@ NetworkControlUpdate GoogCcNetworkController::GetNetworkState(
616698
last_estimated_fraction_loss_.value_or(0) / 255.0;
617699
update.target_rate->network_estimate.round_trip_time =
618700
last_estimated_round_trip_time_;
619-
update.target_rate->network_estimate.bwe_period =
620-
delay_based_bwe_->GetExpectedBwePeriod();
701+
if (delay_based_bwe_)
702+
update.target_rate->network_estimate.bwe_period =
703+
delay_based_bwe_->GetExpectedBwePeriod();
704+
else {
705+
#ifdef INTEL_GPRA
706+
if (delay_based_bwe_gcc_)
707+
update.target_rate->network_estimate.bwe_period =
708+
delay_based_bwe_gcc_->GetExpectedBwePeriod();
709+
#endif
710+
}
621711

622712
update.target_rate->at_time = at_time;
623713
update.target_rate->target_rate = last_pushback_target_rate_;
@@ -681,10 +771,14 @@ void GoogCcNetworkController::MaybeTriggerOnNetworkChanged(
681771

682772
alr_detector_->SetEstimatedBitrate(loss_based_target_rate.bps());
683773

774+
#ifndef INTEL_GPRA
684775
TimeDelta bwe_period = delay_based_bwe_->GetExpectedBwePeriod();
685-
686-
#ifdef INTEL_GPRA
687-
delay_based_bwe_->SetCurrentPacketLossRate(fraction_loss);
776+
#else
777+
TimeDelta bwe_period = delay_based_bwe_.get()
778+
? delay_based_bwe_->GetExpectedBwePeriod()
779+
: delay_based_bwe_gcc_->GetExpectedBwePeriod();
780+
if (delay_based_bwe_)
781+
delay_based_bwe_->SetCurrentPacketLossRate(fraction_loss);
688782
#endif
689783

690784
TargetTransferRate target_rate_msg;

modules/congestion_controller/goog_cc/goog_cc_network_control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class GoogCcNetworkController : public NetworkControllerInterface {
114114
std::unique_ptr<NetworkStatePredictor> network_state_predictor_;
115115
#ifdef INTEL_GPRA
116116
std::unique_ptr<GPRABwe> delay_based_bwe_;
117+
std::unique_ptr<DelayBasedBwe> delay_based_bwe_gcc_;
117118
#else
118119
std::unique_ptr<DelayBasedBwe> delay_based_bwe_;
119120
#endif

modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ void SendSideBandwidthEstimation::UpdateReceiverEstimate(Timestamp at_time,
333333
DataRate bandwidth) {
334334
// TODO(srte): Ensure caller passes PlusInfinity, not zero, to represent no
335335
// limitation.
336-
if (field_trial::IsEnabled("OWT-LowLatencyMode")) {
337-
// For low latency mode, we will always ignore REMB result.
336+
if (is_using_external_bwe_) {
337+
// Ignore remb if using GPRA.
338338
return;
339339
}
340340
receiver_limit_ = bandwidth.IsZero() ? DataRate::PlusInfinity() : bandwidth;
@@ -463,9 +463,9 @@ void SendSideBandwidthEstimation::UpdateRtt(TimeDelta rtt, Timestamp at_time) {
463463

464464
void SendSideBandwidthEstimation::UpdateEstimate(Timestamp at_time) {
465465
if (rtt_backoff_.CorrectedRtt(at_time) > rtt_backoff_.rtt_limit_) {
466-
// If last decrease happens before 1 second, and current target is larger than
467-
// 5kbps, and we decided an RTT backoff is neccessary, we drop current target by
468-
// 0.8 and use that as estimation result.
466+
// If last decrease happens before 1 second, and current target is larger
467+
// than 5kbps, and we decided an RTT backoff is neccessary, we drop current
468+
// target by 0.8 and use that as estimation result.
469469
if (at_time - time_last_decrease_ >= rtt_backoff_.drop_interval_ &&
470470
current_target_ > rtt_backoff_.bandwidth_floor_) {
471471
time_last_decrease_ = at_time;
@@ -667,11 +667,11 @@ void SendSideBandwidthEstimation::MaybeLogLossBasedEvent(Timestamp at_time) {
667667

668668
void SendSideBandwidthEstimation::UpdateTargetBitrate(DataRate new_bitrate,
669669
Timestamp at_time) {
670-
if (is_low_latency_mode_)
670+
if (is_using_external_bwe_)
671671
new_bitrate = GetUpperLimit();
672672
else
673673
new_bitrate = std::min(new_bitrate, GetUpperLimit());
674-
if (new_bitrate < min_bitrate_configured_) {
674+
if (!is_using_external_bwe_ && new_bitrate < min_bitrate_configured_) {
675675
MaybeLogLowBitrateWarning(new_bitrate, at_time);
676676
new_bitrate = min_bitrate_configured_;
677677
}

0 commit comments

Comments
 (0)