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

Side by Side Diff: webrtc/modules/pacing/alr_detector.cc

Issue 2340763004: Add AlrDetector (Closed)
Patch Set: Created 4 years, 3 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
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 : 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.
39 total_elapsed_time_ms_(0),
40 estimated_bitrate_bps_(0),
41 application_limited_count_(0) {}
42
43 AlrDetector::~AlrDetector() {}
44
45 void AlrDetector::ReportElapsedTime(int64_t delta_time_ms) {
46 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.
47 if (total_elapsed_time_ms_ > kMeasurementPeriodMs) {
48 RTC_DCHECK(estimated_bitrate_bps_);
49 int max_bytes =
50 (total_elapsed_time_ms_ * estimated_bitrate_bps_) / (8 * 1000);
51 int utilization = (total_bytes_sent_ * 100) / max_bytes;
52 if (utilization < kUsagePercent) {
53 application_limited_count_++;
54 if (application_limited_count_ == kApplicationLimitedThreshold)
55 LOG(LS_INFO) << "ALR start";
56 } else {
57 if (application_limited_count_ >= kApplicationLimitedThreshold)
58 LOG(LS_INFO) << "ALR stop";
59 application_limited_count_ = 0;
60 }
61 total_elapsed_time_ms_ = delta_time_ms;
62 total_bytes_sent_ = 0;
63 }
64 total_elapsed_time_ms_ += delta_time_ms;
65 }
66
67 void AlrDetector::ReportBytesSent(size_t bytes) {
68 RTC_DCHECK(bytes);
69 RTC_DCHECK(estimated_bitrate_bps_);
70 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.
71 }
72
73 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) {
74 RTC_DCHECK(bitrate_bps);
75 estimated_bitrate_bps_ = bitrate_bps;
76 }
77
78 bool AlrDetector::InApplicationLimitedRegion() {
79 return application_limited_count_ >= kApplicationLimitedThreshold;
80 }
81
82 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698