Skip to content

Commit

Permalink
Sync with latest Loss v2 changes. Fix Periodic ALR when we suddenly h…
Browse files Browse the repository at this point in the history
…ave no traffic due to low reported estimated bitrate. Change min bitrate constant.
  • Loading branch information
Eugene Voityuk committed Nov 22, 2022
1 parent f5ec63d commit 676b92e
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void LossBasedBweV2::SetMinMaxBitrate(DataRate min_bitrate,
void LossBasedBweV2::SetProbeBitrate(absl::optional<DataRate> probe_bitrate) {
if (probe_bitrate.has_value() && IsValid(probe_bitrate.value())) {
if (!IsValid(probe_bitrate_) || probe_bitrate_ > probe_bitrate.value()) {
MS_DEBUG_DEV("Setting probe bitrate to %d", probe_bitrate.value().bps());
probe_bitrate_ = probe_bitrate.value();
}
}
Expand All @@ -222,14 +223,12 @@ void LossBasedBweV2::UpdateBandwidthEstimate(
delay_based_estimate_ = delay_based_estimate;
upper_link_capacity_ = upper_link_capacity;
if (!IsEnabled()) {
/* RTC_LOG(LS_WARNING)
<< "The estimator must be enabled before it can be used.";*/
MS_WARN_TAG(bwe, "The estimator must be enabled before it can be used.");
return;
}
SetProbeBitrate(probe_bitrate);
if (packet_results.empty()) {
/* RTC_LOG(LS_VERBOSE)
<< "The estimate cannot be updated without any loss statistics.";*/
MS_WARN_TAG(bwe, "The estimate cannot be updated without any loss statistics.");
return;
}

Expand All @@ -238,8 +237,7 @@ void LossBasedBweV2::UpdateBandwidthEstimate(
}

if (!IsValid(current_estimate_.loss_limited_bandwidth)) {
/* RTC_LOG(LS_VERBOSE)
<< "The estimator must be initialized before it can be used.";*/
MS_WARN_TAG(bwe, "The estimator must be initialized before it can be used.");
return;
}

Expand Down Expand Up @@ -307,13 +305,12 @@ void LossBasedBweV2::UpdateBandwidthEstimate(
}
}

if (IsEstimateIncreasingWhenLossLimited(best_candidate)) {
if (IsEstimateIncreasingWhenLossLimited(best_candidate) &&
best_candidate.loss_limited_bandwidth < delay_based_estimate) {
current_state_ = LossBasedState::kIncreasing;
} else if (IsValid(delay_based_estimate_) &&
best_candidate.loss_limited_bandwidth < delay_based_estimate_) {
} else if (best_candidate.loss_limited_bandwidth < delay_based_estimate_) {
current_state_ = LossBasedState::kDecreasing;
} else if (IsValid(delay_based_estimate_) &&
best_candidate.loss_limited_bandwidth == delay_based_estimate_) {
} else if (best_candidate.loss_limited_bandwidth >= delay_based_estimate_) {
current_state_ = LossBasedState::kDelayBasedEstimate;
}
current_estimate_ = best_candidate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ void SendSideBandwidthEstimation::UpdateLossBasedEstimator(
report.packet_feedbacks, report.feedback_time);
}
if (LossBasedBandwidthEstimatorV2Enabled()) {
MS_DEBUG_DEV("Updating loss_based_bandwidth_estimator_v2_. Delay limit %lld, Upper Link Capacity %lld", delay_based_limit_.kbps(), upper_link_capacity.kbps());
if (probe_bitrate.has_value()) {
MS_DEBUG_DEV("Updating loss_based_bandwidth_estimator_v2_. Probe bitrate: %lld", probe_bitrate.value().kbps());
}
loss_based_bandwidth_estimator_v2_.UpdateBandwidthEstimate(
report.packet_feedbacks, delay_based_limit_, delay_detector_state,
probe_bitrate, upper_link_capacity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#define MS_CLASS "webrtc::AlrDetector"
// #define MS_LOG_DEV_LEVEL 3
#define MS_LOG_DEV_LEVEL 3

#include "modules/congestion_controller/goog_cc/alr_detector.h"
#include "rtc_base/numerics/safe_conversions.h"
Expand Down Expand Up @@ -66,6 +66,16 @@ AlrDetector::AlrDetector(const WebRtcKeyValueConfig* key_value_config)

AlrDetector::~AlrDetector() {}

// This is used to trigger ALR start state if we had sudden stop in traffic (all consumers paused due to low bw report).
void AlrDetector::Process() {
int64_t now = DepLibUV::GetTimeMsInt64();
if (!alr_started_time_ms_.has_value() && last_send_time_ms_.has_value()) {
if ((now - last_send_time_ms_.value()) > 1000) {
OnBytesSent(0, now);
}
}
}

void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t send_time_ms) {
if (!last_send_time_ms_.has_value()) {
last_send_time_ms_ = send_time_ms;
Expand Down Expand Up @@ -95,9 +105,14 @@ void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t send_time_ms) {

void AlrDetector::SetEstimatedBitrate(int bitrate_bps) {
//RTC_DCHECK(bitrate_bps);
int target_rate_kbps =
static_cast<double>(bitrate_bps) * conf_.bandwidth_usage_ratio / 1000;
alr_budget_.set_target_rate_kbps(target_rate_kbps);

if (last_estimated_bitrate_ != bitrate_bps) {
last_estimated_bitrate_ = bitrate_bps;
MS_DEBUG_TAG(bwe, "Setting ALR bitrate to %d", bitrate_bps);
int target_rate_kbps =
static_cast<double>(bitrate_bps) * conf_.bandwidth_usage_ratio / 1000;
alr_budget_.set_target_rate_kbps(target_rate_kbps);
}
}

absl::optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ class AlrDetector {
// Returns time in milliseconds when the current application-limited region
// started or empty result if the sender is currently not application-limited.
absl::optional<int64_t> GetApplicationLimitedRegionStartTime() const;
void Process();

private:
friend class GoogCcStatePrinter;
const AlrDetectorConfig conf_;

absl::optional<int64_t> last_send_time_ms_;

int last_estimated_bitrate_;
IntervalBudget alr_budget_;
absl::optional<int64_t> alr_started_time_ms_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ constexpr float kDefaultPaceMultiplier = 2.5f;
// below the current throughput estimate to drain the network queues.
constexpr double kProbeDropThroughputFraction = 0.85;

int64_t GetBpsOrDefault(const absl::optional<DataRate>& rate,
int64_t fallback_bps) {
if (rate && rate->IsFinite()) {
return rate->bps();
} else {
return fallback_bps;
}
}
bool IsEnabled(const WebRtcKeyValueConfig* config, absl::string_view key) {
return config->Lookup(key).find("Enabled") == 0;
}
Expand Down Expand Up @@ -210,6 +202,7 @@ NetworkControlUpdate GoogCcNetworkController::OnProcessInterval(
msg.pacer_queue->bytes());
}
bandwidth_estimation_->UpdateEstimate(msg.at_time);
alr_detector_->Process();
absl::optional<int64_t> start_time_ms =
alr_detector_->GetApplicationLimitedRegionStartTime();
probe_controller_->SetAlrStartTimeMs(start_time_ms);
Expand Down Expand Up @@ -529,6 +522,7 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback(
probe_controller_->SetNetworkStateEstimate(*estimate_);
}
}

absl::optional<DataRate> probe_bitrate =
probe_bitrate_estimator_->FetchAndResetLastEstimatedBitrate();
if (ignore_probes_lower_than_network_estimate_ && probe_bitrate &&
Expand Down Expand Up @@ -704,10 +698,10 @@ void GoogCcNetworkController::MaybeTriggerOnNetworkChanged(
probes.begin(), probes.end());
update->pacer_config = GetPacingRates(at_time);

MS_DEBUG_DEV("bwe [at_time:%" PRIu64", pushback_target_bps:%lld, estimate_bps:%lld]",
/* MS_DEBUG_DEV("bwe [at_time:%" PRIu64", pushback_target_bps:%lld, estimate_bps:%lld]",
at_time.ms(),
last_pushback_target_rate_.bps(),
last_raw_target_rate_.bps());
loss_based_target_rate.bps());*/
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#define MS_CLASS "webrtc::ProbeBitrateEstimator"
// #define MS_LOG_DEV_LEVEL 3
#define MS_LOG_DEV_LEVEL 3

#include "modules/congestion_controller/goog_cc/probe_bitrate_estimator.h"
#include "rtc_base/numerics/safe_conversions.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
*/

#define MS_CLASS "webrtc::ProbeController"
// #define MS_LOG_DEV_LEVEL 3
#define MS_LOG_DEV_LEVEL 3

#include "modules/congestion_controller/goog_cc/probe_controller.h"
#include "api/units/data_rate.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "rtc_base/numerics/safe_conversions.h"

#include "DepLibUV.hpp"
#include "Logger.hpp"

#include <absl/memory/memory.h>
Expand Down Expand Up @@ -172,10 +173,10 @@ std::vector<ProbeClusterConfig> ProbeController::SetBitrates(
} else if (start_bitrate_.IsZero()) {
start_bitrate_ = min_bitrate;
}
MS_DEBUG_DEV(
/* MS_DEBUG_DEV(
"[old_max_bitrate_bps:%lld, max_bitrate_bps:%lld]",
max_bitrate_bps_,
max_bitrate_bps);
max_bitrate_.bps(),
max_bitrate.bps());*/
// The reason we use the variable `old_max_bitrate_pbs` is because we
// need to set `max_bitrate_` before we call InitiateProbing.
DataRate old_max_bitrate = max_bitrate_;
Expand Down Expand Up @@ -305,7 +306,6 @@ std::vector<ProbeClusterConfig> ProbeController::SetEstimatedBitrate(
// bitrate_bps / 1000);
mid_call_probing_waiting_for_result_ = false;
}
std::vector<ProbeClusterConfig> pending_probes;
if (state_ == State::kWaitingForProbingResult) {
// Continue probing if probing results indicate channel has greater
// capacity.
Expand Down Expand Up @@ -339,13 +339,18 @@ void ProbeController::EnablePeriodicAlrProbing(bool enable) {

void ProbeController::SetAlrStartTimeMs(
absl::optional<int64_t> alr_start_time_ms) {
if (alr_start_time_ms) {
alr_start_time_ = Timestamp::ms(*alr_start_time_ms);
} else {
if ((alr_start_time_ms.has_value() && !alr_start_time_.has_value()) ||
(alr_start_time_ms.has_value() && alr_start_time_.has_value() && (alr_start_time_.value().ms() != alr_start_time_ms.value())))
{
MS_DEBUG_TAG(bwe, "ALR Start, start time %ld", alr_start_time_ms.value());
alr_start_time_ = Timestamp::ms(alr_start_time_ms.value());
}
/*} else {
alr_start_time_ = absl::nullopt;
}
}*/
}
void ProbeController::SetAlrEndedTimeMs(int64_t alr_end_time_ms) {
MS_DEBUG_TAG(bwe, "ALR End");
alr_end_time_.emplace(Timestamp::ms(alr_end_time_ms));
}

Expand Down Expand Up @@ -385,12 +390,6 @@ std::vector<ProbeClusterConfig> ProbeController::RequestProbe(
return std::vector<ProbeClusterConfig>();
}

void ProbeController::SetMaxBitrate(DataRate max_bitrate) {
MS_DEBUG_DEV("[max_bitrate_bps:%" PRIi64 "]", max_bitrate);

max_bitrate_ = max_bitrate;
}

void ProbeController::SetNetworkStateEstimate(
webrtc::NetworkStateEstimate estimate) {
network_estimate_ = estimate;
Expand All @@ -417,6 +416,7 @@ void ProbeController::Reset(Timestamp at_time) {

bool ProbeController::TimeForAlrProbe(Timestamp at_time) const {
if (enable_periodic_alr_probing_ && alr_start_time_) {
//MS_DEBUG_TAG(bwe, "enable_periodic_alr_probing_: %d, alr_start_time_: %lld", enable_periodic_alr_probing_, alr_start_time_.value().ms());
Timestamp next_probe_time =
std::max(*alr_start_time_, time_last_probing_initiated_) +
config_.alr_probing_interval;
Expand Down Expand Up @@ -515,14 +515,21 @@ std::vector<ProbeClusterConfig> ProbeController::InitiateProbing(
switch (bandwidth_limited_cause_) {
case BandwidthLimitedCause::kLossLimitedBweDecreasing:
// If bandwidth estimate is decreasing because of packet loss, do not
// send probes.
return {};
// send probes. Unless we are in ALR state, where we might not have traffic to estimate.
// This might be terribly wrong when we have a big gap between factual and probation bitrate.
if (!alr_start_time_) {
MS_DEBUG_TAG(bwe, "State is BandwidthLimitedCause::kLossLimitedBweDecreasing");
return {};
}
break;
case BandwidthLimitedCause::kLossLimitedBweIncreasing:
MS_DEBUG_TAG(bwe, "State is BandwidthLimitedCause::kLossLimitedBweIncreasing");
estimate_capped_bitrate =
std::min(max_probe_bitrate,
estimated_bitrate_ * config_.loss_limited_probe_scale);
break;
case BandwidthLimitedCause::kDelayBasedLimited:
MS_DEBUG_TAG(bwe, "State is BandwidthLimitedCause::kDelayBasedLimited");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ DataRate GetMinBitrate();
} // namespace congestion_controller

static const int64_t kBitrateWindowMs = 1000;

constexpr DataRate kCongestionControllerMinBitrate = DataRate::BitsPerSec<5000>();
// NOTE: the default value was 5000 kbps, which is just too small for SFU scenario.
constexpr DataRate kCongestionControllerMinBitrate = DataRate::BitsPerSec<150000>();

extern const char kBweTypeHistogram[];

Expand Down

0 comments on commit 676b92e

Please sign in to comment.