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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/pacing/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 =
53 static_cast<int>((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_DCHECK(bitrate_bps);
73 estimated_bitrate_bps_ = bitrate_bps;
74 }
75
76 bool AlrDetector::InApplicationLimitedRegion() {
77 return application_limited_count_ >= kApplicationLimitedThreshold;
78 }
79
80 } // namespace webrtc
OLDNEW
« 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