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..46eb077aae61ee2fc0cffd6ad141690366172b98 |
--- /dev/null |
+++ b/webrtc/modules/pacing/alr_detector.cc |
@@ -0,0 +1,82 @@ |
+/* |
+ * 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() |
+ : total_bytes_sent_(0), |
philipel
2016/09/15 15:00:20
I think |total_bytes_sent_| is not really correct,
Irfan
2016/09/19 06:51:13
Done.
|
+ total_elapsed_time_ms_(0), |
+ estimated_bitrate_bps_(0), |
+ application_limited_count_(0) {} |
+ |
+AlrDetector::~AlrDetector() {} |
+ |
+void AlrDetector::ReportElapsedTime(int64_t delta_time_ms) { |
+ RTC_DCHECK(delta_time_ms); |
philipel
2016/09/15 15:00:20
RTC_DCHECK_GT(delta_time_ms, 0);
Irfan
2016/09/19 06:51:13
Done.
|
+ if (total_elapsed_time_ms_ > kMeasurementPeriodMs) { |
+ RTC_DCHECK(estimated_bitrate_bps_); |
+ int max_bytes = |
+ (total_elapsed_time_ms_ * estimated_bitrate_bps_) / (8 * 1000); |
+ int utilization = (total_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; |
+ } |
+ total_elapsed_time_ms_ = delta_time_ms; |
+ total_bytes_sent_ = 0; |
+ } |
+ total_elapsed_time_ms_ += delta_time_ms; |
+} |
+ |
+void AlrDetector::ReportBytesSent(size_t bytes) { |
+ RTC_DCHECK(bytes); |
+ RTC_DCHECK(estimated_bitrate_bps_); |
+ total_bytes_sent_ += bytes; |
philipel
2016/09/15 15:00:20
I think we should combine ReportBytesSent and Repo
Irfan
2016/09/19 06:51:13
Done.
|
+} |
+ |
+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 |