| 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   if (measurement_interval_elapsed_time_ms_ > kMeasurementPeriodMs) { | 
 |  47     RTC_DCHECK(estimated_bitrate_bps_); | 
 |  48     int max_bytes = | 
 |  49         (measurement_interval_elapsed_time_ms_ * estimated_bitrate_bps_) / | 
 |  50         (8 * 1000); | 
 |  51     RTC_DCHECK_GT(max_bytes, 0); | 
 |  52     int utilization = (measurement_interval_bytes_sent_ * 100) / max_bytes; | 
 |  53     if (utilization < kUsagePercent) { | 
 |  54       application_limited_count_++; | 
 |  55       if (application_limited_count_ == kApplicationLimitedThreshold) | 
 |  56         LOG(LS_INFO) << "ALR start"; | 
 |  57     } else { | 
 |  58       if (application_limited_count_ >= kApplicationLimitedThreshold) | 
 |  59         LOG(LS_INFO) << "ALR stop"; | 
 |  60       application_limited_count_ = 0; | 
 |  61     } | 
 |  62     measurement_interval_elapsed_time_ms_ = elapsed_time_ms; | 
 |  63     measurement_interval_bytes_sent_ = bytes_sent; | 
 |  64   } else { | 
 |  65     measurement_interval_elapsed_time_ms_ += elapsed_time_ms; | 
 |  66     measurement_interval_bytes_sent_ += bytes_sent; | 
 |  67   } | 
 |  68 } | 
 |  69  | 
 |  70 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) { | 
 |  71   RTC_DCHECK(bitrate_bps); | 
 |  72   estimated_bitrate_bps_ = bitrate_bps; | 
 |  73 } | 
 |  74  | 
 |  75 bool AlrDetector::InApplicationLimitedRegion() { | 
 |  76   return application_limited_count_ >= kApplicationLimitedThreshold; | 
 |  77 } | 
 |  78  | 
 |  79 }  // namespace webrtc | 
| OLD | NEW |