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

Unified Diff: webrtc/modules/pacing/alr_detector.cc

Issue 2340763004: Add AlrDetector (Closed)
Patch Set: Rebased Created 4 years, 2 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
« no previous file with comments | « webrtc/modules/pacing/alr_detector.h ('k') | webrtc/modules/pacing/alr_detector_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/pacing/alr_detector.cc
diff --git a/webrtc/modules/pacing/alr_detector.cc b/webrtc/modules/pacing/alr_detector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..677c7e018e59823faddcaafabe2c6ca804f383b4
--- /dev/null
+++ b/webrtc/modules/pacing/alr_detector.cc
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/pacing/alr_detector.h"
+
+#include "webrtc/base/checks.h"
+#include "webrtc/base/logging.h"
+
+namespace {
+
+// Time period over which outgoing traffic is measured and considered a single
+// data point.
+constexpr int kMeasurementPeriodMs = 100;
+
+// Minimum number of consecutive measurements over |kMeasurementPeriodMs| time
+// that indicate sending rate is below |kUsagePercent| to consider being
+// application limited.
+constexpr int kApplicationLimitedThreshold = 5;
+
+// Sent traffic percentage as a function of network capaicty to consider traffic
+// as application limited.
+// NOTE: This is intentionally conservative at the moment until BW adjustments
+// of application limited region is fine tuned.
+constexpr int kUsagePercent = 30;
+
+} // namespace
+
+namespace webrtc {
+
+AlrDetector::AlrDetector()
+ : measurement_interval_bytes_sent_(0),
+ measurement_interval_elapsed_time_ms_(0),
+ estimated_bitrate_bps_(0),
+ application_limited_count_(0) {}
+
+AlrDetector::~AlrDetector() {}
+
+void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t elapsed_time_ms) {
+ if (measurement_interval_elapsed_time_ms_ > kMeasurementPeriodMs) {
+ RTC_DCHECK(estimated_bitrate_bps_);
+ int max_bytes =
+ (measurement_interval_elapsed_time_ms_ * estimated_bitrate_bps_) /
+ (8 * 1000);
+ RTC_DCHECK_GT(max_bytes, 0);
+ int utilization =
+ static_cast<int>((measurement_interval_bytes_sent_ * 100) / max_bytes);
+ if (utilization < kUsagePercent) {
+ application_limited_count_++;
+ if (application_limited_count_ == kApplicationLimitedThreshold)
+ LOG(LS_INFO) << "ALR start";
+ } else {
+ if (application_limited_count_ >= kApplicationLimitedThreshold)
+ LOG(LS_INFO) << "ALR stop";
+ application_limited_count_ = 0;
+ }
+ measurement_interval_elapsed_time_ms_ = elapsed_time_ms;
+ measurement_interval_bytes_sent_ = bytes_sent;
+ } else {
+ measurement_interval_elapsed_time_ms_ += elapsed_time_ms;
+ measurement_interval_bytes_sent_ += bytes_sent;
+ }
+}
+
+void AlrDetector::SetEstimatedBitrate(int bitrate_bps) {
+ RTC_DCHECK(bitrate_bps);
+ estimated_bitrate_bps_ = bitrate_bps;
+}
+
+bool AlrDetector::InApplicationLimitedRegion() {
+ return application_limited_count_ >= kApplicationLimitedThreshold;
+}
+
+} // namespace webrtc
« no previous file with comments | « webrtc/modules/pacing/alr_detector.h ('k') | webrtc/modules/pacing/alr_detector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698