blob: 11eeceaa988a65bdff24308e294902f1eaa23567 [file] [log] [blame]
isheriff31687812016-10-04 08:43:09 -07001/*
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#ifndef WEBRTC_MODULES_PACING_ALR_DETECTOR_H_
12#define WEBRTC_MODULES_PACING_ALR_DETECTOR_H_
13
14#include "webrtc/common_types.h"
tschumim82c55932017-07-11 06:56:04 -070015#include "webrtc/modules/pacing/interval_budget.h"
isheriff31687812016-10-04 08:43:09 -070016#include "webrtc/modules/pacing/paced_sender.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020017#include "webrtc/rtc_base/optional.h"
18#include "webrtc/rtc_base/rate_statistics.h"
isheriff31687812016-10-04 08:43:09 -070019#include "webrtc/typedefs.h"
20
21namespace webrtc {
22
23// Application limited region detector is a class that utilizes signals of
24// elapsed time and bytes sent to estimate whether network traffic is
25// currently limited by the application's ability to generate traffic.
26//
27// AlrDetector provides a signal that can be utilized to adjust
28// estimate bandwidth.
29// Note: This class is not thread-safe.
sprang89c4a7e2017-06-30 13:27:40 -070030
isheriff31687812016-10-04 08:43:09 -070031class AlrDetector {
32 public:
33 AlrDetector();
34 ~AlrDetector();
Sergey Ulanov0182f852016-11-16 15:42:11 -080035
tschumim82c55932017-07-11 06:56:04 -070036 void OnBytesSent(size_t bytes_sent, int64_t delta_time_ms);
Sergey Ulanov0182f852016-11-16 15:42:11 -080037
isheriff31687812016-10-04 08:43:09 -070038 // Set current estimated bandwidth.
39 void SetEstimatedBitrate(int bitrate_bps);
Sergey Ulanov0182f852016-11-16 15:42:11 -080040
sergeyu80ed35e2016-11-28 13:11:13 -080041 // Returns time in milliseconds when the current application-limited region
42 // started or empty result if the sender is currently not application-limited.
43 rtc::Optional<int64_t> GetApplicationLimitedRegionStartTime() const;
isheriff31687812016-10-04 08:43:09 -070044
sprang89c4a7e2017-06-30 13:27:40 -070045 struct AlrExperimentSettings {
46 float pacing_factor = PacedSender::kDefaultPaceMultiplier;
47 int64_t max_paced_queue_time = PacedSender::kMaxQueueLengthMs;
tschumim82c55932017-07-11 06:56:04 -070048 int alr_bandwidth_usage_percent = kDefaultAlrBandwidthUsagePercent;
49 int alr_start_budget_level_percent = kDefaultAlrStartBudgetLevelPercent;
50 int alr_stop_budget_level_percent = kDefaultAlrStopBudgetLevelPercent;
sprang89c4a7e2017-06-30 13:27:40 -070051 };
52 static rtc::Optional<AlrExperimentSettings> ParseAlrSettingsFromFieldTrial();
53
54 // Sent traffic percentage as a function of network capacity used to determine
55 // application-limited region. ALR region start when bandwidth usage drops
56 // below kAlrStartUsagePercent and ends when it raises above
57 // kAlrEndUsagePercent. NOTE: This is intentionally conservative at the moment
58 // until BW adjustments of application limited region is fine tuned.
tschumim82c55932017-07-11 06:56:04 -070059 static constexpr int kDefaultAlrBandwidthUsagePercent = 65;
60 static constexpr int kDefaultAlrStartBudgetLevelPercent = 20;
61 static constexpr int kDefaultAlrStopBudgetLevelPercent = -20;
sprang89c4a7e2017-06-30 13:27:40 -070062 static const char* kScreenshareProbingBweExperimentName;
63
tschumim82c55932017-07-11 06:56:04 -070064 void UpdateBudgetWithElapsedTime(int64_t delta_time_ms);
65 void UpdateBudgetWithBytesSent(size_t bytes_sent);
sergeyu80ed35e2016-11-28 13:11:13 -080066
tschumim82c55932017-07-11 06:56:04 -070067 private:
68 int bandwidth_usage_percent_;
69 int alr_start_budget_level_percent_;
70 int alr_stop_budget_level_percent_;
71
72 IntervalBudget alr_budget_;
sergeyu80ed35e2016-11-28 13:11:13 -080073 rtc::Optional<int64_t> alr_started_time_ms_;
isheriff31687812016-10-04 08:43:09 -070074};
75
76} // namespace webrtc
77
78#endif // WEBRTC_MODULES_PACING_ALR_DETECTOR_H_