OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/modules/congestion_controller/alr_detector.h" |
| 12 |
| 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/logging.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Time period over which outgoing traffic is measured and considered a single |
| 19 // data point. |
| 20 constexpr int kMeasurementPeriodMs = 100; |
| 21 |
| 22 // Minimum number of consecutive measurements over |kMeasurementPeriodMs| time |
| 23 // that indicate sending rate is below |kUsagePercent| to consider being |
| 24 // application limited. |
| 25 constexpr int kApplicationLimitedThreshold = 5; |
| 26 |
| 27 // Sent traffic percentage as a function of network capaicty to consider traffic |
| 28 // as application limited. |
| 29 // NOTE: This is intentionally conservative at the moment until BW adjustments |
| 30 // of application limited region is fine tuned. |
| 31 constexpr int kUsagePercent = 30; |
| 32 |
| 33 } // namespace |
| 34 |
| 35 namespace webrtc { |
| 36 |
| 37 AlrDetector::AlrDetector() |
| 38 : measurement_interval_bytes_sent_(0), |
| 39 measurement_interval_elapsed_time_ms_(0), |
| 40 estimated_bitrate_bps_(0), |
| 41 application_limited_count_(0) {} |
| 42 |
| 43 AlrDetector::~AlrDetector() {} |
| 44 |
| 45 void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t elapsed_time_ms) { |
| 46 rtc::CritScope cs(&critsect_); |
| 47 if (measurement_interval_elapsed_time_ms_ > kMeasurementPeriodMs) { |
| 48 RTC_DCHECK(estimated_bitrate_bps_); |
| 49 int max_bytes = |
| 50 (measurement_interval_elapsed_time_ms_ * estimated_bitrate_bps_) / |
| 51 (8 * 1000); |
| 52 RTC_DCHECK_GT(max_bytes, 0); |
| 53 int utilization = (measurement_interval_bytes_sent_ * 100) / max_bytes; |
| 54 if (utilization < kUsagePercent) { |
| 55 application_limited_count_++; |
| 56 if (application_limited_count_ == kApplicationLimitedThreshold) |
| 57 LOG(LS_INFO) << "ALR start"; |
| 58 } else { |
| 59 if (application_limited_count_ >= kApplicationLimitedThreshold) |
| 60 LOG(LS_INFO) << "ALR stop"; |
| 61 application_limited_count_ = 0; |
| 62 } |
| 63 measurement_interval_elapsed_time_ms_ = elapsed_time_ms; |
| 64 measurement_interval_bytes_sent_ = bytes_sent; |
| 65 } else { |
| 66 measurement_interval_elapsed_time_ms_ += elapsed_time_ms; |
| 67 measurement_interval_bytes_sent_ += bytes_sent; |
| 68 } |
| 69 } |
| 70 |
| 71 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) { |
| 72 rtc::CritScope cs(&critsect_); |
| 73 RTC_DCHECK(bitrate_bps); |
| 74 estimated_bitrate_bps_ = bitrate_bps; |
| 75 } |
| 76 |
| 77 bool AlrDetector::InApplicationLimitedRegion() { |
| 78 rtc::CritScope cs(&critsect_); |
| 79 return application_limited_count_ >= kApplicationLimitedThreshold; |
| 80 } |
| 81 |
| 82 } // namespace webrtc |
OLD | NEW |