Clean up loss based bwe v2: store delay based estimate locally.

This is to avoid passing delay based estimate value twice from send side  bwe.

Bug: webrtc:12707
Change-Id: Idc77cf7c2f4ecc60ae1dcfead325320532e7a7ca
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282864
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Diep Bui <diepbp@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38600}
This commit is contained in:
Diep Bui 2022-11-09 16:09:11 +00:00 committed by WebRTC LUCI CQ
parent 0dbee62eb9
commit 3d7771cc08
4 changed files with 122 additions and 187 deletions

View file

@ -138,8 +138,7 @@ bool LossBasedBweV2::IsReady() const {
num_observations_ > 0; num_observations_ > 0;
} }
LossBasedBweV2::Result LossBasedBweV2::GetLossBasedResult( LossBasedBweV2::Result LossBasedBweV2::GetLossBasedResult() const {
DataRate delay_based_limit) const {
Result result; Result result;
result.state = current_state_; result.state = current_state_;
if (!IsReady()) { if (!IsReady()) {
@ -156,16 +155,16 @@ LossBasedBweV2::Result LossBasedBweV2::GetLossBasedResult(
"statistics before it can be used."; "statistics before it can be used.";
} }
} }
result.bandwidth_estimate = IsValid(delay_based_limit) result.bandwidth_estimate = IsValid(delay_based_estimate_)
? delay_based_limit ? delay_based_estimate_
: DataRate::PlusInfinity(); : DataRate::PlusInfinity();
return result; return result;
} }
if (IsValid(delay_based_limit)) { if (IsValid(delay_based_estimate_)) {
result.bandwidth_estimate = result.bandwidth_estimate =
std::min({current_estimate_.loss_limited_bandwidth, std::min({current_estimate_.loss_limited_bandwidth,
GetInstantUpperBound(), delay_based_limit}); GetInstantUpperBound(), delay_based_estimate_});
} else { } else {
result.bandwidth_estimate = std::min( result.bandwidth_estimate = std::min(
current_estimate_.loss_limited_bandwidth, GetInstantUpperBound()); current_estimate_.loss_limited_bandwidth, GetInstantUpperBound());
@ -221,6 +220,7 @@ void LossBasedBweV2::UpdateBandwidthEstimate(
DataRate delay_based_estimate, DataRate delay_based_estimate,
BandwidthUsage delay_detector_state, BandwidthUsage delay_detector_state,
absl::optional<DataRate> probe_bitrate) { absl::optional<DataRate> probe_bitrate) {
delay_based_estimate_ = delay_based_estimate;
if (!IsEnabled()) { if (!IsEnabled()) {
RTC_LOG(LS_WARNING) RTC_LOG(LS_WARNING)
<< "The estimator must be enabled before it can be used."; << "The estimator must be enabled before it can be used.";
@ -245,7 +245,7 @@ void LossBasedBweV2::UpdateBandwidthEstimate(
ChannelParameters best_candidate = current_estimate_; ChannelParameters best_candidate = current_estimate_;
double objective_max = std::numeric_limits<double>::lowest(); double objective_max = std::numeric_limits<double>::lowest();
for (ChannelParameters candidate : GetCandidates(delay_based_estimate)) { for (ChannelParameters candidate : GetCandidates()) {
NewtonsMethodUpdate(candidate); NewtonsMethodUpdate(candidate);
const double candidate_objective = GetObjective(candidate); const double candidate_objective = GetObjective(candidate);
@ -309,11 +309,11 @@ void LossBasedBweV2::UpdateBandwidthEstimate(
if (IsEstimateIncreasingWhenLossLimited(best_candidate)) { if (IsEstimateIncreasingWhenLossLimited(best_candidate)) {
current_state_ = LossBasedState::kIncreasing; current_state_ = LossBasedState::kIncreasing;
} else if (IsValid(delay_based_estimate) && } else if (IsValid(delay_based_estimate_) &&
best_candidate.loss_limited_bandwidth < delay_based_estimate) { best_candidate.loss_limited_bandwidth < delay_based_estimate_) {
current_state_ = LossBasedState::kDecreasing; current_state_ = LossBasedState::kDecreasing;
} else if (IsValid(delay_based_estimate) && } else if (IsValid(delay_based_estimate_) &&
best_candidate.loss_limited_bandwidth == delay_based_estimate) { best_candidate.loss_limited_bandwidth == delay_based_estimate_) {
current_state_ = LossBasedState::kDelayBasedEstimate; current_state_ = LossBasedState::kDelayBasedEstimate;
} }
current_estimate_ = best_candidate; current_estimate_ = best_candidate;
@ -716,8 +716,7 @@ double LossBasedBweV2::GetAverageReportedLossRatio() const {
return num_lost_packets / num_packets; return num_lost_packets / num_packets;
} }
DataRate LossBasedBweV2::GetCandidateBandwidthUpperBound( DataRate LossBasedBweV2::GetCandidateBandwidthUpperBound() const {
DataRate delay_based_estimate) const {
DataRate candidate_bandwidth_upper_bound = max_bitrate_; DataRate candidate_bandwidth_upper_bound = max_bitrate_;
if (IsBandwidthLimitedDueToLoss() && if (IsBandwidthLimitedDueToLoss() &&
IsValid(bandwidth_limit_in_current_window_)) { IsValid(bandwidth_limit_in_current_window_)) {
@ -727,9 +726,9 @@ DataRate LossBasedBweV2::GetCandidateBandwidthUpperBound(
if (config_->trendline_integration_enabled) { if (config_->trendline_integration_enabled) {
candidate_bandwidth_upper_bound = candidate_bandwidth_upper_bound =
std::min(GetInstantUpperBound(), candidate_bandwidth_upper_bound); std::min(GetInstantUpperBound(), candidate_bandwidth_upper_bound);
if (IsValid(delay_based_estimate)) { if (IsValid(delay_based_estimate_)) {
candidate_bandwidth_upper_bound = candidate_bandwidth_upper_bound =
std::min(delay_based_estimate, candidate_bandwidth_upper_bound); std::min(delay_based_estimate_, candidate_bandwidth_upper_bound);
} }
} }
@ -751,8 +750,8 @@ DataRate LossBasedBweV2::GetCandidateBandwidthUpperBound(
return candidate_bandwidth_upper_bound; return candidate_bandwidth_upper_bound;
} }
std::vector<LossBasedBweV2::ChannelParameters> LossBasedBweV2::GetCandidates( std::vector<LossBasedBweV2::ChannelParameters> LossBasedBweV2::GetCandidates()
DataRate delay_based_estimate) const { const {
std::vector<DataRate> bandwidths; std::vector<DataRate> bandwidths;
bool can_increase_bitrate = TrendlineEsimateAllowBitrateIncrease(); bool can_increase_bitrate = TrendlineEsimateAllowBitrateIncrease();
for (double candidate_factor : config_->candidate_factors) { for (double candidate_factor : config_->candidate_factors) {
@ -770,16 +769,16 @@ std::vector<LossBasedBweV2::ChannelParameters> LossBasedBweV2::GetCandidates(
config_->bandwidth_backoff_lower_bound_factor); config_->bandwidth_backoff_lower_bound_factor);
} }
if (IsValid(delay_based_estimate) && if (IsValid(delay_based_estimate_) &&
config_->append_delay_based_estimate_candidate) { config_->append_delay_based_estimate_candidate) {
if (can_increase_bitrate && if (can_increase_bitrate &&
delay_based_estimate > current_estimate_.loss_limited_bandwidth) { delay_based_estimate_ > current_estimate_.loss_limited_bandwidth) {
bandwidths.push_back(delay_based_estimate); bandwidths.push_back(delay_based_estimate_);
} }
} }
const DataRate candidate_bandwidth_upper_bound = const DataRate candidate_bandwidth_upper_bound =
GetCandidateBandwidthUpperBound(delay_based_estimate); GetCandidateBandwidthUpperBound();
std::vector<ChannelParameters> candidates; std::vector<ChannelParameters> candidates;
candidates.resize(bandwidths.size()); candidates.resize(bandwidths.size());

View file

@ -57,7 +57,7 @@ class LossBasedBweV2 {
bool IsReady() const; bool IsReady() const;
// Returns `DataRate::PlusInfinity` if no BWE can be calculated. // Returns `DataRate::PlusInfinity` if no BWE can be calculated.
Result GetLossBasedResult(DataRate delay_based_limit) const; Result GetLossBasedResult() const;
void SetAcknowledgedBitrate(DataRate acknowledged_bitrate); void SetAcknowledgedBitrate(DataRate acknowledged_bitrate);
void SetBandwidthEstimate(DataRate bandwidth_estimate); void SetBandwidthEstimate(DataRate bandwidth_estimate);
@ -139,9 +139,8 @@ class LossBasedBweV2 {
// Returns `0.0` if not enough loss statistics have been received. // Returns `0.0` if not enough loss statistics have been received.
double GetAverageReportedLossRatio() const; double GetAverageReportedLossRatio() const;
std::vector<ChannelParameters> GetCandidates( std::vector<ChannelParameters> GetCandidates() const;
DataRate delay_based_estimate) const; DataRate GetCandidateBandwidthUpperBound() const;
DataRate GetCandidateBandwidthUpperBound(DataRate delay_based_estimate) const;
Derivatives GetDerivatives(const ChannelParameters& channel_parameters) const; Derivatives GetDerivatives(const ChannelParameters& channel_parameters) const;
double GetFeasibleInherentLoss( double GetFeasibleInherentLoss(
const ChannelParameters& channel_parameters) const; const ChannelParameters& channel_parameters) const;
@ -193,6 +192,7 @@ class LossBasedBweV2 {
DataRate max_bitrate_ = DataRate::PlusInfinity(); DataRate max_bitrate_ = DataRate::PlusInfinity();
LossBasedState current_state_ = LossBasedState::kDelayBasedEstimate; LossBasedState current_state_ = LossBasedState::kDelayBasedEstimate;
DataRate probe_bitrate_ = DataRate::PlusInfinity(); DataRate probe_bitrate_ = DataRate::PlusInfinity();
DataRate delay_based_estimate_ = DataRate::PlusInfinity();
}; };
} // namespace webrtc } // namespace webrtc

View file

@ -201,12 +201,14 @@ TEST_P(LossBasedBweV2Test, ReturnsDelayBasedEstimateWhenDisabled) {
Config(/*enabled=*/false, /*valid=*/true, Config(/*enabled=*/false, /*valid=*/true,
/*trendline_integration_enabled=*/GetParam())); /*trendline_integration_enabled=*/GetParam()));
LossBasedBweV2 loss_based_bandwidth_estimator(&key_value_config); LossBasedBweV2 loss_based_bandwidth_estimator(&key_value_config);
loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
EXPECT_EQ(loss_based_bandwidth_estimator /*packet_results=*/{},
.GetLossBasedResult( /*delay_based_estimate=*/DataRate::KilobitsPerSec(100),
/*delay_based_limit=*/DataRate::KilobitsPerSec(100)) BandwidthUsage::kBwNormal,
.bandwidth_estimate, /*probe_estimate=*/absl::nullopt);
DataRate::KilobitsPerSec(100)); EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
DataRate::KilobitsPerSec(100));
} }
TEST_P(LossBasedBweV2Test, TEST_P(LossBasedBweV2Test,
@ -215,12 +217,14 @@ TEST_P(LossBasedBweV2Test,
Config(/*enabled=*/true, /*valid=*/false, Config(/*enabled=*/true, /*valid=*/false,
/*trendline_integration_enabled=*/GetParam())); /*trendline_integration_enabled=*/GetParam()));
LossBasedBweV2 loss_based_bandwidth_estimator(&key_value_config); LossBasedBweV2 loss_based_bandwidth_estimator(&key_value_config);
loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
EXPECT_EQ(loss_based_bandwidth_estimator /*packet_results=*/{},
.GetLossBasedResult( /*delay_based_estimate=*/DataRate::KilobitsPerSec(100),
/*delay_based_limit=*/DataRate::KilobitsPerSec(100)) BandwidthUsage::kBwNormal,
.bandwidth_estimate, /*probe_estimate=*/absl::nullopt);
DataRate::KilobitsPerSec(100)); EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
DataRate::KilobitsPerSec(100));
} }
TEST_P(LossBasedBweV2Test, TEST_P(LossBasedBweV2Test,
@ -241,10 +245,8 @@ TEST_P(LossBasedBweV2Test,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_TRUE(loss_based_bandwidth_estimator.IsReady()); EXPECT_TRUE(loss_based_bandwidth_estimator.IsReady());
EXPECT_TRUE( EXPECT_TRUE(loss_based_bandwidth_estimator.GetLossBasedResult()
loss_based_bandwidth_estimator .bandwidth_estimate.IsFinite());
.GetLossBasedResult(/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate.IsFinite());
} }
TEST_P(LossBasedBweV2Test, NoBandwidthEstimateGivenNoInitialization) { TEST_P(LossBasedBweV2Test, NoBandwidthEstimateGivenNoInitialization) {
@ -261,10 +263,8 @@ TEST_P(LossBasedBweV2Test, NoBandwidthEstimateGivenNoInitialization) {
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_FALSE(loss_based_bandwidth_estimator.IsReady()); EXPECT_FALSE(loss_based_bandwidth_estimator.IsReady());
EXPECT_TRUE( EXPECT_TRUE(loss_based_bandwidth_estimator.GetLossBasedResult()
loss_based_bandwidth_estimator .bandwidth_estimate.IsPlusInfinity());
.GetLossBasedResult(/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate.IsPlusInfinity());
} }
TEST_P(LossBasedBweV2Test, NoBandwidthEstimateGivenNotEnoughFeedback) { TEST_P(LossBasedBweV2Test, NoBandwidthEstimateGivenNotEnoughFeedback) {
@ -290,20 +290,16 @@ TEST_P(LossBasedBweV2Test, NoBandwidthEstimateGivenNotEnoughFeedback) {
DataRate::KilobitsPerSec(600)); DataRate::KilobitsPerSec(600));
EXPECT_FALSE(loss_based_bandwidth_estimator.IsReady()); EXPECT_FALSE(loss_based_bandwidth_estimator.IsReady());
EXPECT_TRUE( EXPECT_TRUE(loss_based_bandwidth_estimator.GetLossBasedResult()
loss_based_bandwidth_estimator .bandwidth_estimate.IsPlusInfinity());
.GetLossBasedResult(/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate.IsPlusInfinity());
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
not_enough_feedback, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, not_enough_feedback, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_FALSE(loss_based_bandwidth_estimator.IsReady()); EXPECT_FALSE(loss_based_bandwidth_estimator.IsReady());
EXPECT_TRUE( EXPECT_TRUE(loss_based_bandwidth_estimator.GetLossBasedResult()
loss_based_bandwidth_estimator .bandwidth_estimate.IsPlusInfinity());
.GetLossBasedResult(/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate.IsPlusInfinity());
} }
TEST_P(LossBasedBweV2Test, TEST_P(LossBasedBweV2Test,
@ -327,30 +323,24 @@ TEST_P(LossBasedBweV2Test,
enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_NE(loss_based_bandwidth_estimator EXPECT_NE(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(600));
.bandwidth_estimate,
DataRate::KilobitsPerSec(600));
loss_based_bandwidth_estimator.SetBandwidthEstimate( loss_based_bandwidth_estimator.SetBandwidthEstimate(
DataRate::KilobitsPerSec(600)); DataRate::KilobitsPerSec(600));
EXPECT_EQ(loss_based_bandwidth_estimator EXPECT_EQ(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(600));
.bandwidth_estimate,
DataRate::KilobitsPerSec(600));
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_NE(loss_based_bandwidth_estimator EXPECT_NE(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(600));
.bandwidth_estimate,
DataRate::KilobitsPerSec(600));
} }
TEST_P(LossBasedBweV2Test, TEST_P(LossBasedBweV2Test,
@ -380,20 +370,16 @@ TEST_P(LossBasedBweV2Test,
enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_EQ(loss_based_bandwidth_estimator_1 EXPECT_EQ(
.GetLossBasedResult( loss_based_bandwidth_estimator_1.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(660));
.bandwidth_estimate,
DataRate::KilobitsPerSec(660));
loss_based_bandwidth_estimator_1.SetAcknowledgedBitrate( loss_based_bandwidth_estimator_1.SetAcknowledgedBitrate(
DataRate::KilobitsPerSec(900)); DataRate::KilobitsPerSec(900));
EXPECT_EQ(loss_based_bandwidth_estimator_1 EXPECT_EQ(
.GetLossBasedResult( loss_based_bandwidth_estimator_1.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(660));
.bandwidth_estimate,
DataRate::KilobitsPerSec(660));
loss_based_bandwidth_estimator_1.UpdateBandwidthEstimate( loss_based_bandwidth_estimator_1.UpdateBandwidthEstimate(
enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
@ -402,14 +388,9 @@ TEST_P(LossBasedBweV2Test,
enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_NE(loss_based_bandwidth_estimator_1 EXPECT_NE(
.GetLossBasedResult( loss_based_bandwidth_estimator_1.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) loss_based_bandwidth_estimator_2.GetLossBasedResult().bandwidth_estimate);
.bandwidth_estimate,
loss_based_bandwidth_estimator_2
.GetLossBasedResult(
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate);
} }
TEST_P(LossBasedBweV2Test, TEST_P(LossBasedBweV2Test,
@ -429,11 +410,9 @@ TEST_P(LossBasedBweV2Test,
enough_feedback_no_received_packets, DataRate::PlusInfinity(), enough_feedback_no_received_packets, DataRate::PlusInfinity(),
BandwidthUsage::kBwNormal, /*probe_estimate=*/absl::nullopt); BandwidthUsage::kBwNormal, /*probe_estimate=*/absl::nullopt);
EXPECT_EQ(loss_based_bandwidth_estimator EXPECT_EQ(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(100));
.bandwidth_estimate,
DataRate::KilobitsPerSec(100));
} }
TEST_P(LossBasedBweV2Test, BandwidthEstimateNotIncreaseWhenNetworkUnderusing) { TEST_P(LossBasedBweV2Test, BandwidthEstimateNotIncreaseWhenNetworkUnderusing) {
@ -459,19 +438,15 @@ TEST_P(LossBasedBweV2Test, BandwidthEstimateNotIncreaseWhenNetworkUnderusing) {
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_1, DataRate::PlusInfinity(), enough_feedback_1, DataRate::PlusInfinity(),
BandwidthUsage::kBwUnderusing, /*probe_estimate=*/absl::nullopt); BandwidthUsage::kBwUnderusing, /*probe_estimate=*/absl::nullopt);
EXPECT_LE(loss_based_bandwidth_estimator EXPECT_LE(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(600));
.bandwidth_estimate,
DataRate::KilobitsPerSec(600));
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_LE(loss_based_bandwidth_estimator EXPECT_LE(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(600));
.bandwidth_estimate,
DataRate::KilobitsPerSec(600));
} }
// When network is normal, estimate can increase but never be higher than // When network is normal, estimate can increase but never be higher than
@ -499,21 +474,18 @@ TEST_P(LossBasedBweV2Test,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
// If the delay based estimate is infinity, then loss based estimate increases // If the delay based estimate is infinity, then loss based estimate increases
// and not bounded by delay based estimate. // and not bounded by delay based estimate.
EXPECT_GT(loss_based_bandwidth_estimator EXPECT_GT(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) DataRate::KilobitsPerSec(600));
.bandwidth_estimate,
DataRate::KilobitsPerSec(600));
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_2, /*delay_based_estimate=*/DataRate::KilobitsPerSec(500),
BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
// If the delay based estimate is not infinity, then loss based estimate is // If the delay based estimate is not infinity, then loss based estimate is
// bounded by delay based estimate. // bounded by delay based estimate.
EXPECT_EQ(loss_based_bandwidth_estimator EXPECT_EQ(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::KilobitsPerSec(500)) DataRate::KilobitsPerSec(500));
.bandwidth_estimate,
DataRate::KilobitsPerSec(500));
} }
// When loss based bwe receives a strong signal of overusing and an increase in // When loss based bwe receives a strong signal of overusing and an increase in
@ -548,11 +520,9 @@ TEST_P(LossBasedBweV2Test, UseAckedBitrateForEmegencyBackOff) {
enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwOverusing, enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwOverusing,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
// The estimate bitrate now is backed off based on acked bitrate. // The estimate bitrate now is backed off based on acked bitrate.
EXPECT_LE(loss_based_bandwidth_estimator EXPECT_LE(
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
/*delay_based_limit=*/DataRate::PlusInfinity()) acked_bitrate);
.bandwidth_estimate,
acked_bitrate);
} }
// When receiving the same packet feedback, loss based bwe ignores the feedback // When receiving the same packet feedback, loss based bwe ignores the feedback
@ -573,19 +543,15 @@ TEST_P(LossBasedBweV2Test, NoBweChangeIfObservationDurationUnchanged) {
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
DataRate estimate_1 = loss_based_bandwidth_estimator DataRate estimate_1 =
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate;
// Use the same feedback and check if the estimate is unchanged. // Use the same feedback and check if the estimate is unchanged.
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
DataRate estimate_2 = loss_based_bandwidth_estimator DataRate estimate_2 =
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate;
EXPECT_EQ(estimate_2, estimate_1); EXPECT_EQ(estimate_2, estimate_1);
} }
@ -610,18 +576,14 @@ TEST_P(LossBasedBweV2Test,
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
DataRate estimate_1 = loss_based_bandwidth_estimator DataRate estimate_1 =
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate;
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
DataRate estimate_2 = loss_based_bandwidth_estimator DataRate estimate_2 =
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate;
EXPECT_EQ(estimate_2, estimate_1); EXPECT_EQ(estimate_2, estimate_1);
} }
@ -646,18 +608,14 @@ TEST_P(LossBasedBweV2Test,
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
DataRate estimate_1 = loss_based_bandwidth_estimator DataRate estimate_1 =
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate;
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_2, DataRate::PlusInfinity(), enough_feedback_2, DataRate::PlusInfinity(),
BandwidthUsage::kBwUnderusing, /*probe_estimate=*/absl::nullopt); BandwidthUsage::kBwUnderusing, /*probe_estimate=*/absl::nullopt);
DataRate estimate_2 = loss_based_bandwidth_estimator DataRate estimate_2 =
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate;
EXPECT_LE(estimate_2, estimate_1); EXPECT_LE(estimate_2, estimate_1);
} }
@ -689,18 +647,14 @@ TEST_P(LossBasedBweV2Test,
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal, enough_feedback_1, DataRate::PlusInfinity(), BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
DataRate estimate_1 = loss_based_bandwidth_estimator DataRate estimate_1 =
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate;
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwOverusing, enough_feedback_2, DataRate::PlusInfinity(), BandwidthUsage::kBwOverusing,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
DataRate estimate_2 = loss_based_bandwidth_estimator DataRate estimate_2 =
.GetLossBasedResult( loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
/*delay_based_limit=*/DataRate::PlusInfinity())
.bandwidth_estimate;
EXPECT_LT(estimate_2, estimate_1); EXPECT_LT(estimate_2, estimate_1);
} }
@ -725,15 +679,13 @@ TEST_P(LossBasedBweV2Test,
enough_feedback_1, delay_based_estimate, BandwidthUsage::kBwNormal, enough_feedback_1, delay_based_estimate, BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_EQ( EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
delay_based_estimate); delay_based_estimate);
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_2, delay_based_estimate, BandwidthUsage::kBwNormal, enough_feedback_2, delay_based_estimate, BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
EXPECT_EQ( EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
delay_based_estimate); delay_based_estimate);
} }
@ -761,7 +713,7 @@ TEST_P(LossBasedBweV2Test,
enough_feedback_1, delay_based_estimate, BandwidthUsage::kBwNormal, enough_feedback_1, delay_based_estimate, BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
LossBasedBweV2::Result result_at_loss = LossBasedBweV2::Result result_at_loss =
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate); loss_based_bandwidth_estimator.GetLossBasedResult();
// Network recovers after loss. // Network recovers after loss.
std::vector<PacketResult> enough_feedback_2 = std::vector<PacketResult> enough_feedback_2 =
@ -775,7 +727,7 @@ TEST_P(LossBasedBweV2Test,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
LossBasedBweV2::Result result_after_recovery = LossBasedBweV2::Result result_after_recovery =
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate); loss_based_bandwidth_estimator.GetLossBasedResult();
EXPECT_EQ(result_after_recovery.bandwidth_estimate, EXPECT_EQ(result_after_recovery.bandwidth_estimate,
result_at_loss.bandwidth_estimate * 1.5); result_at_loss.bandwidth_estimate * 1.5);
} }
@ -815,8 +767,7 @@ TEST_P(LossBasedBweV2Test,
// The estimate is capped by acked_bitrate * BwRampupUpperBoundFactor. // The estimate is capped by acked_bitrate * BwRampupUpperBoundFactor.
DataRate estimate_2 = DataRate estimate_2 =
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
.bandwidth_estimate;
EXPECT_EQ(estimate_2, acked_bitrate * 1.2); EXPECT_EQ(estimate_2, acked_bitrate * 1.2);
} }
@ -859,8 +810,7 @@ TEST_P(LossBasedBweV2Test,
// The estimate is capped by current_estimate * kMaxIncreaseFactor because // The estimate is capped by current_estimate * kMaxIncreaseFactor because
// it recently backed off. // it recently backed off.
DataRate estimate_2 = DataRate estimate_2 =
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
.bandwidth_estimate;
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_3, delay_based_estimate, BandwidthUsage::kBwNormal, enough_feedback_3, delay_based_estimate, BandwidthUsage::kBwNormal,
@ -868,8 +818,7 @@ TEST_P(LossBasedBweV2Test,
// The latest estimate is the same as the previous estimate since the sent // The latest estimate is the same as the previous estimate since the sent
// packets were sent within the DelayedIncreaseWindow. // packets were sent within the DelayedIncreaseWindow.
EXPECT_EQ( EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
estimate_2); estimate_2);
} }
@ -910,16 +859,14 @@ TEST_P(LossBasedBweV2Test, KeepIncreasingEstimateAfterDelayedIncreaseWindow) {
// The estimate is capped by current_estimate * kMaxIncreaseFactor because it // The estimate is capped by current_estimate * kMaxIncreaseFactor because it
// recently backed off. // recently backed off.
DataRate estimate_2 = DataRate estimate_2 =
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate;
.bandwidth_estimate;
loss_based_bandwidth_estimator.UpdateBandwidthEstimate( loss_based_bandwidth_estimator.UpdateBandwidthEstimate(
enough_feedback_3, delay_based_estimate, BandwidthUsage::kBwNormal, enough_feedback_3, delay_based_estimate, BandwidthUsage::kBwNormal,
/*probe_estimate=*/absl::nullopt); /*probe_estimate=*/absl::nullopt);
// The estimate can continue increasing after the DelayedIncreaseWindow. // The estimate can continue increasing after the DelayedIncreaseWindow.
EXPECT_GE( EXPECT_GE(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
estimate_2); estimate_2);
} }
@ -954,8 +901,7 @@ TEST_P(LossBasedBweV2Test, NotIncreaseIfInherentLossLessThanAverageLoss) {
// Do not increase the bitrate because inherent loss is less than average loss // Do not increase the bitrate because inherent loss is less than average loss
EXPECT_EQ( EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
DataRate::KilobitsPerSec(600)); DataRate::KilobitsPerSec(600));
} }
@ -993,8 +939,7 @@ TEST_P(LossBasedBweV2Test,
// Because LossThresholdOfHighBandwidthPreference is 20%, the average loss is // Because LossThresholdOfHighBandwidthPreference is 20%, the average loss is
// 10%, bandwidth estimate should increase. // 10%, bandwidth estimate should increase.
EXPECT_GT( EXPECT_GT(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
DataRate::KilobitsPerSec(600)); DataRate::KilobitsPerSec(600));
} }
@ -1032,8 +977,7 @@ TEST_P(LossBasedBweV2Test,
// Because LossThresholdOfHighBandwidthPreference is 5%, the average loss is // Because LossThresholdOfHighBandwidthPreference is 5%, the average loss is
// 10%, bandwidth estimate should decrease. // 10%, bandwidth estimate should decrease.
EXPECT_LT( EXPECT_LT(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
DataRate::KilobitsPerSec(600)); DataRate::KilobitsPerSec(600));
} }
@ -1071,7 +1015,7 @@ TEST_P(LossBasedBweV2Test, UseProbeResultWhenRecoveringFromLoss) {
probe_estimate); probe_estimate);
LossBasedBweV2::Result result_after_recovery = LossBasedBweV2::Result result_after_recovery =
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate); loss_based_bandwidth_estimator.GetLossBasedResult();
EXPECT_EQ(result_after_recovery.bandwidth_estimate, probe_estimate); EXPECT_EQ(result_after_recovery.bandwidth_estimate, probe_estimate);
} }
@ -1111,8 +1055,7 @@ TEST_P(LossBasedBweV2Test,
// At 10% loss rate and high loss rate threshold to be 10%, cap the estimate // At 10% loss rate and high loss rate threshold to be 10%, cap the estimate
// to be 500 * 1000-0.1 = 400kbps. // to be 500 * 1000-0.1 = 400kbps.
EXPECT_EQ( EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
DataRate::KilobitsPerSec(400)); DataRate::KilobitsPerSec(400));
} }
@ -1152,8 +1095,7 @@ TEST_P(LossBasedBweV2Test,
// At 50% loss rate and high loss rate threshold to be 30%, cap the estimate // At 50% loss rate and high loss rate threshold to be 30%, cap the estimate
// to be the min bitrate. // to be the min bitrate.
EXPECT_EQ( EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
DataRate::KilobitsPerSec(10)); DataRate::KilobitsPerSec(10));
} }
@ -1193,8 +1135,7 @@ TEST_P(LossBasedBweV2Test,
// At 100% loss rate and high loss rate threshold to be 30%, cap the estimate // At 100% loss rate and high loss rate threshold to be 30%, cap the estimate
// to be the min bitrate. // to be the min bitrate.
EXPECT_EQ( EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
DataRate::KilobitsPerSec(10)); DataRate::KilobitsPerSec(10));
} }
@ -1225,8 +1166,7 @@ TEST_P(LossBasedBweV2Test, EstimateRecoversAfterHighLoss) {
// Make sure that the estimate is set to min bitrate because of 100% loss // Make sure that the estimate is set to min bitrate because of 100% loss
// rate. // rate.
EXPECT_EQ( EXPECT_EQ(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
DataRate::KilobitsPerSec(10)); DataRate::KilobitsPerSec(10));
// Create some feedbacks with 0 loss rate to simulate network recovering. // Create some feedbacks with 0 loss rate to simulate network recovering.
@ -1248,8 +1188,7 @@ TEST_P(LossBasedBweV2Test, EstimateRecoversAfterHighLoss) {
// The estimate increases as network recovers. // The estimate increases as network recovers.
EXPECT_GT( EXPECT_GT(
loss_based_bandwidth_estimator.GetLossBasedResult(delay_based_estimate) loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.bandwidth_estimate,
DataRate::KilobitsPerSec(10)); DataRate::KilobitsPerSec(10));
} }
@ -1271,9 +1210,7 @@ TEST_P(LossBasedBweV2Test, EstimateIsNotHigherThanMaxBitrate) {
BandwidthUsage::kBwNormal, /*probe_estimate=*/absl::nullopt); BandwidthUsage::kBwNormal, /*probe_estimate=*/absl::nullopt);
EXPECT_LE( EXPECT_LE(
loss_based_bandwidth_estimator loss_based_bandwidth_estimator.GetLossBasedResult().bandwidth_estimate,
.GetLossBasedResult(/*delay_based_estimate=*/DataRate::PlusInfinity())
.bandwidth_estimate,
DataRate::KilobitsPerSec(1000)); DataRate::KilobitsPerSec(1000));
} }

View file

@ -526,8 +526,7 @@ void SendSideBandwidthEstimation::UpdateEstimate(Timestamp at_time) {
if (LossBasedBandwidthEstimatorV2ReadyForUse()) { if (LossBasedBandwidthEstimatorV2ReadyForUse()) {
LossBasedBweV2::Result result = LossBasedBweV2::Result result =
loss_based_bandwidth_estimator_v2_.GetLossBasedResult( loss_based_bandwidth_estimator_v2_.GetLossBasedResult();
delay_based_limit_);
loss_based_state_ = result.state; loss_based_state_ = result.state;
UpdateTargetBitrate(result.bandwidth_estimate, at_time); UpdateTargetBitrate(result.bandwidth_estimate, at_time);
return; return;