Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1385)

Unified Diff: webrtc/modules/congestion_controller/delay_based_bwe.cc

Issue 2924093002: Revert of Refactored incoming bitrate estimator. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/congestion_controller/delay_based_bwe.cc
diff --git a/webrtc/modules/congestion_controller/delay_based_bwe.cc b/webrtc/modules/congestion_controller/delay_based_bwe.cc
index 147f2432b21b7100f5c2b3a138c97fe6db060152..fca5143bb12881211f83372773489c549e4933cc 100644
--- a/webrtc/modules/congestion_controller/delay_based_bwe.cc
+++ b/webrtc/modules/congestion_controller/delay_based_bwe.cc
@@ -38,6 +38,8 @@
// This ssrc is used to fulfill the current API but will be removed
// after the API has been changed.
constexpr uint32_t kFixedSsrc = 0;
+constexpr int kInitialRateWindowMs = 500;
+constexpr int kRateWindowMs = 150;
// Parameters for linear least squares fit of regression line to noisy data.
constexpr size_t kDefaultTrendlineWindowSize = 20;
@@ -53,9 +55,103 @@
webrtc::field_trial::FindFullName(kBweSparseUpdateExperiment);
return experiment_string == "Enabled";
}
+
+class PacketFeedbackComparator {
+ public:
+ inline bool operator()(const webrtc::PacketFeedback& lhs,
+ const webrtc::PacketFeedback& rhs) {
+ if (lhs.arrival_time_ms != rhs.arrival_time_ms)
+ return lhs.arrival_time_ms < rhs.arrival_time_ms;
+ if (lhs.send_time_ms != rhs.send_time_ms)
+ return lhs.send_time_ms < rhs.send_time_ms;
+ return lhs.sequence_number < rhs.sequence_number;
+ }
+};
+
+void SortPacketFeedbackVector(const std::vector<webrtc::PacketFeedback>& input,
+ std::vector<webrtc::PacketFeedback>* output) {
+ auto pred = [](const webrtc::PacketFeedback& packet_feedback) {
+ return packet_feedback.arrival_time_ms !=
+ webrtc::PacketFeedback::kNotReceived;
+ };
+ std::copy_if(input.begin(), input.end(), std::back_inserter(*output), pred);
+ std::sort(output->begin(), output->end(), PacketFeedbackComparator());
+}
} // namespace
namespace webrtc {
+
+DelayBasedBwe::BitrateEstimator::BitrateEstimator()
+ : sum_(0),
+ current_win_ms_(0),
+ prev_time_ms_(-1),
+ bitrate_estimate_(-1.0f),
+ bitrate_estimate_var_(50.0f) {}
+
+void DelayBasedBwe::BitrateEstimator::Update(int64_t now_ms, int bytes) {
+ int rate_window_ms = kRateWindowMs;
+ // We use a larger window at the beginning to get a more stable sample that
+ // we can use to initialize the estimate.
+ if (bitrate_estimate_ < 0.f)
+ rate_window_ms = kInitialRateWindowMs;
+ float bitrate_sample = UpdateWindow(now_ms, bytes, rate_window_ms);
+ if (bitrate_sample < 0.0f)
+ return;
+ if (bitrate_estimate_ < 0.0f) {
+ // This is the very first sample we get. Use it to initialize the estimate.
+ bitrate_estimate_ = bitrate_sample;
+ return;
+ }
+ // Define the sample uncertainty as a function of how far away it is from the
+ // current estimate.
+ float sample_uncertainty =
+ 10.0f * std::abs(bitrate_estimate_ - bitrate_sample) / bitrate_estimate_;
+ float sample_var = sample_uncertainty * sample_uncertainty;
+ // Update a bayesian estimate of the rate, weighting it lower if the sample
+ // uncertainty is large.
+ // The bitrate estimate uncertainty is increased with each update to model
+ // that the bitrate changes over time.
+ float pred_bitrate_estimate_var = bitrate_estimate_var_ + 5.f;
+ bitrate_estimate_ = (sample_var * bitrate_estimate_ +
+ pred_bitrate_estimate_var * bitrate_sample) /
+ (sample_var + pred_bitrate_estimate_var);
+ bitrate_estimate_var_ = sample_var * pred_bitrate_estimate_var /
+ (sample_var + pred_bitrate_estimate_var);
+}
+
+float DelayBasedBwe::BitrateEstimator::UpdateWindow(int64_t now_ms,
+ int bytes,
+ int rate_window_ms) {
+ // Reset if time moves backwards.
+ if (now_ms < prev_time_ms_) {
+ prev_time_ms_ = -1;
+ sum_ = 0;
+ current_win_ms_ = 0;
+ }
+ if (prev_time_ms_ >= 0) {
+ current_win_ms_ += now_ms - prev_time_ms_;
+ // Reset if nothing has been received for more than a full window.
+ if (now_ms - prev_time_ms_ > rate_window_ms) {
+ sum_ = 0;
+ current_win_ms_ %= rate_window_ms;
+ }
+ }
+ prev_time_ms_ = now_ms;
+ float bitrate_sample = -1.0f;
+ if (current_win_ms_ >= rate_window_ms) {
+ bitrate_sample = 8.0f * sum_ / static_cast<float>(rate_window_ms);
+ current_win_ms_ -= rate_window_ms;
+ sum_ = 0;
+ }
+ sum_ += bytes;
+ return bitrate_sample;
+}
+
+rtc::Optional<uint32_t> DelayBasedBwe::BitrateEstimator::bitrate_bps() const {
+ if (bitrate_estimate_ < 0.f)
+ return rtc::Optional<uint32_t>();
+ return rtc::Optional<uint32_t>(bitrate_estimate_ * 1000);
+}
DelayBasedBwe::DelayBasedBwe(RtcEventLog* event_log, const Clock* clock)
: event_log_(event_log),
@@ -63,6 +159,7 @@
inter_arrival_(),
trendline_estimator_(),
detector_(),
+ receiver_incoming_bitrate_(),
last_seen_packet_ms_(-1),
uma_recorded_(false),
probe_bitrate_estimator_(event_log),
@@ -80,17 +177,16 @@
DelayBasedBwe::~DelayBasedBwe() {}
DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector(
- const std::vector<PacketFeedback>& packet_feedback_vector,
- rtc::Optional<uint32_t> acked_bitrate_bps) {
- RTC_DCHECK(std::is_sorted(packet_feedback_vector.begin(),
- packet_feedback_vector.end(),
- PacketFeedbackComparator()));
+ const std::vector<PacketFeedback>& packet_feedback_vector) {
RTC_DCHECK(network_thread_.CalledOnValidThread());
+ std::vector<PacketFeedback> sorted_packet_feedback_vector;
+ SortPacketFeedbackVector(packet_feedback_vector,
+ &sorted_packet_feedback_vector);
// TOOD(holmer): An empty feedback vector here likely means that
// all acks were too late and that the send time history had
// timed out. We should reduce the rate when this occurs.
- if (packet_feedback_vector.empty()) {
+ if (sorted_packet_feedback_vector.empty()) {
LOG(LS_WARNING) << "Very late feedback received.";
return DelayBasedBwe::Result();
}
@@ -103,7 +199,7 @@
}
bool overusing = false;
bool delayed_feedback = true;
- for (const auto& packet_feedback : packet_feedback_vector) {
+ for (const auto& packet_feedback : sorted_packet_feedback_vector) {
if (packet_feedback.send_time_ms < 0)
continue;
delayed_feedback = false;
@@ -117,11 +213,12 @@
++consecutive_delayed_feedbacks_;
if (consecutive_delayed_feedbacks_ >= kMaxConsecutiveFailedLookups) {
consecutive_delayed_feedbacks_ = 0;
- return OnLongFeedbackDelay(packet_feedback_vector.back().arrival_time_ms);
+ return OnLongFeedbackDelay(
+ sorted_packet_feedback_vector.back().arrival_time_ms);
}
} else {
consecutive_delayed_feedbacks_ = 0;
- return MaybeUpdateEstimate(overusing, acked_bitrate_bps);
+ return MaybeUpdateEstimate(overusing);
}
return Result();
}
@@ -146,6 +243,10 @@
void DelayBasedBwe::IncomingPacketFeedback(
const PacketFeedback& packet_feedback) {
int64_t now_ms = clock_->TimeInMilliseconds();
+
+ receiver_incoming_bitrate_.Update(packet_feedback.arrival_time_ms,
+ packet_feedback.payload_size);
+ Result result;
// Reset if the stream has timed out.
if (last_seen_packet_ms_ == -1 ||
now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) {
@@ -188,12 +289,12 @@
}
}
-DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(
- bool overusing,
- rtc::Optional<uint32_t> acked_bitrate_bps) {
+DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(bool overusing) {
Result result;
int64_t now_ms = clock_->TimeInMilliseconds();
+ rtc::Optional<uint32_t> acked_bitrate_bps =
+ receiver_incoming_bitrate_.bitrate_bps();
rtc::Optional<int> probe_bitrate_bps =
probe_bitrate_estimator_.FetchAndResetLastEstimatedBitrateBps();
// Currently overusing the bandwidth.

Powered by Google App Engine
This is Rietveld 408576698