Line data Source code
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.
19 : constexpr int kMeasurementPeriodMs = 500;
20 :
21 : // Sent traffic percentage as a function of network capacity used to determine
22 : // application-limited region. ALR region start when bandwidth usage drops below
23 : // kAlrStartUsagePercent and ends when it raises above kAlrEndUsagePercent.
24 : // NOTE: This is intentionally conservative at the moment until BW adjustments
25 : // of application limited region is fine tuned.
26 : constexpr int kAlrStartUsagePercent = 30;
27 : constexpr int kAlrEndUsagePercent = 50;
28 :
29 : } // namespace
30 :
31 : namespace webrtc {
32 :
33 0 : AlrDetector::AlrDetector()
34 0 : : rate_(kMeasurementPeriodMs, RateStatistics::kBpsScale) {}
35 :
36 0 : AlrDetector::~AlrDetector() {}
37 :
38 0 : void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t now_ms) {
39 0 : RTC_DCHECK(estimated_bitrate_bps_);
40 :
41 0 : rate_.Update(bytes_sent, now_ms);
42 0 : rtc::Optional<uint32_t> rate = rate_.Rate(now_ms);
43 0 : if (!rate)
44 0 : return;
45 :
46 0 : int percentage = static_cast<int>(*rate) * 100 / estimated_bitrate_bps_;
47 0 : if (percentage < kAlrStartUsagePercent && !alr_started_time_ms_) {
48 0 : alr_started_time_ms_ = rtc::Optional<int64_t>(now_ms);
49 0 : } else if (percentage > kAlrEndUsagePercent && alr_started_time_ms_) {
50 0 : alr_started_time_ms_ = rtc::Optional<int64_t>();
51 : }
52 : }
53 :
54 0 : void AlrDetector::SetEstimatedBitrate(int bitrate_bps) {
55 0 : RTC_DCHECK(bitrate_bps);
56 0 : estimated_bitrate_bps_ = bitrate_bps;
57 0 : }
58 :
59 0 : rtc::Optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime()
60 : const {
61 0 : return alr_started_time_ms_;
62 : }
63 :
64 : } // namespace webrtc
|