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