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

Unified Diff: webrtc/modules/remote_bitrate_estimator/overuse_detector.cc

Issue 1151603008: Make the BWE threshold adaptive. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Improve self-fairness. Created 5 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/remote_bitrate_estimator/overuse_detector.cc
diff --git a/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc b/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc
index 33b234c1f3aee2d962fe301a58cf8ec225af5750..72776a6ccb0da459ba8d8daedcb3f1e51bb1d979 100644
--- a/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc
+++ b/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc
@@ -11,25 +11,47 @@
#include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h"
#include <algorithm>
+#include <sstream>
#include <math.h>
#include <stdlib.h>
+#include "webrtc/base/common.h"
#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
+#include "webrtc/system_wrappers/interface/field_trial.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
-enum { kOverUsingTimeThreshold = 100 };
+enum { kOverUsingTimeThreshold = 10 };
+const char* kAdaptiveThresholdExperiment = "WebRTC-AdaptiveBweThreshold";
+const char* kEnabledPrefix = "Enabled";
+const size_t kEnabledPrefixLength = 7;
+const char* kSubExperimentVariation2 = "Var2";
+const size_t kSubExperimentVariationLength = 4;
+const size_t kMinExperimentLength =
+ kEnabledPrefixLength + kSubExperimentVariationLength + 3;
+
+const double kMaxAdaptOffsetMs = 15.0;
OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options)
: options_(options),
- threshold_(options_.initial_threshold),
+ threshold_(12.5),
+ last_update_ms_(-1),
prev_offset_(0.0),
time_over_using_(-1),
overuse_counter_(0),
- hypothesis_(kBwNormal) {}
+ hypothesis_(kBwNormal),
+ k_up_(0.006469),
+ k_down_(0.000175) {
Gaetano Carlucci 2015/06/25 11:58:36 We should Update the values of K_up_ and K_down_ a
stefan-webrtc 2015/06/25 12:37:12 Done.
+ double k_up = 0.0;
+ double k_down = 0.0;
+ if (GetExperimentThresholds(&k_up, &k_down)) {
+ k_up_ = k_up;
+ k_down_ = k_down;
+ }
+}
OveruseDetector::~OveruseDetector() {}
@@ -37,25 +59,11 @@ BandwidthUsage OveruseDetector::State() const {
return hypothesis_;
}
-
-void OveruseDetector::SetRateControlRegion(RateControlRegion region) {
- switch (region) {
- case kRcMaxUnknown: {
- threshold_ = options_.initial_threshold;
- break;
- }
- case kRcAboveMax:
- case kRcNearMax: {
- threshold_ = options_.initial_threshold / 2;
- break;
- }
- }
-}
-
BandwidthUsage OveruseDetector::Detect(double offset,
double ts_delta,
int num_of_deltas,
- int64_t now_ms) {
+ int64_t now_ms,
+ int incoming_bitrate) {
Gaetano Carlucci 2015/06/25 11:58:36 remove incoming_bitrate
stefan-webrtc 2015/06/25 12:37:12 Done.
if (num_of_deltas < 2) {
return kBwNormal;
}
@@ -64,7 +72,6 @@ BandwidthUsage OveruseDetector::Detect(double offset,
const double T = std::min(num_of_deltas, 60) * offset;
BWE_TEST_LOGGING_PLOT(1, "offset", now_ms, T);
BWE_TEST_LOGGING_PLOT(1, "threshold", now_ms, threshold_);
-
if (T > threshold_) {
if (time_over_using_ == -1) {
// Initialize the timer. Assume that we've been
@@ -93,6 +100,90 @@ BandwidthUsage OveruseDetector::Detect(double offset,
overuse_counter_ = 0;
hypothesis_ = kBwNormal;
}
+
+ UpdateThreshold(T, now_ms, incoming_bitrate);
+
return hypothesis_;
}
+
+void OveruseDetector::UpdateThreshold(double modified_offset,
+ int64_t now_ms,
+ int incoming_bitrate) {
Gaetano Carlucci 2015/06/25 11:58:36 remove incoming_bitrate
stefan-webrtc 2015/06/25 12:37:12 Done.
+ if (!AdaptiveThresholdExperimentIsEnabled())
+ return;
+
+ const int kMaxBitrateBps = 2000000;
+ const int kMinBitrateBps = 500000;
+ incoming_bitrate =
+ std::max(std::min(incoming_bitrate, kMaxBitrateBps), kMinBitrateBps);
+
Gaetano Carlucci 2015/06/25 11:58:36 remove kMaxBitrateBps and kMinBitrateBps
stefan-webrtc 2015/06/25 12:37:12 Done.
+ if (last_update_ms_ == -1)
+ last_update_ms_ = now_ms;
+
+ if (ExperimentVariationIsEnabled(kSubExperimentVariation2) &&
+ fabs(modified_offset) > threshold_ + kMaxAdaptOffsetMs) {
+ // Avoid adapting the threshold to big latency spikes, caused e.g.,
+ // by a sudden capacity drop.
+ last_update_ms_ = now_ms;
+ return;
+ }
+
+ double k;
+ if (fabs(modified_offset) < threshold_) {
+ k = k_down_ +
+ k_down_ * static_cast<double>(incoming_bitrate - kMaxBitrateBps / 2) /
+ static_cast<double>(kMaxBitrateBps);
Gaetano Carlucci 2015/06/25 11:58:36 remove the fine tuning of k_down_
stefan-webrtc 2015/06/25 12:37:12 Done.
+ } else {
+ k = k_up_ +
+ k_up_ * static_cast<double>(kMaxBitrateBps / 2 - incoming_bitrate) /
+ static_cast<double>(kMaxBitrateBps);
Gaetano Carlucci 2015/06/25 11:58:36 remove the fine tuning of k_up_
stefan-webrtc 2015/06/25 12:37:12 Done.
+ }
+
+ threshold_ +=
+ k * (fabs(modified_offset) - threshold_) * (now_ms - last_update_ms_);
+
+ const double kMinThreshold = 6;
+ const double kMaxThreshold = 600;
+ threshold_ = std::min(std::max(threshold_, kMinThreshold), kMaxThreshold);
+
+ last_update_ms_ = now_ms;
+}
+
+bool OveruseDetector::AdaptiveThresholdExperimentIsEnabled() const {
+ std::string experiment_string =
+ webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment);
+ if (experiment_string.length() < kMinExperimentLength)
+ return false;
+ return experiment_string.substr(0, kEnabledPrefixLength) == kEnabledPrefix;
+}
+
+bool OveruseDetector::ExperimentVariationIsEnabled(
+ const char* variation) const {
+ std::string experiment_string =
+ webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment);
+ if (experiment_string.length() < kMinExperimentLength)
+ return false;
+ return experiment_string.substr(kEnabledPrefixLength,
+ kSubExperimentVariationLength) == variation;
+}
+
+// Gets thresholds from the experiment name following the format
+// "WebRTC-AdaptiveBweThreshold/Enabled-0.5,0.002/".
+bool OveruseDetector::GetExperimentThresholds(double* k_up,
+ double* k_down) const {
+ if (!AdaptiveThresholdExperimentIsEnabled())
+ return false;
+ std::string experiment_string =
+ webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment);
+ std::stringstream ss(experiment_string.substr(
+ kEnabledPrefixLength + kSubExperimentVariationLength + 1));
+ ss >> *k_up;
+ if (ss.peek() != ',')
+ return false;
+ ss.ignore();
+ ss >> *k_down;
+ if (ss.rdbuf()->in_avail() > 0)
+ return false;
+ return true;
+}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698