isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 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 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 11 | #ifndef MODULES_PACING_ALR_DETECTOR_H_ |
| 12 | #define MODULES_PACING_ALR_DETECTOR_H_ |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "api/optional.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 15 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/pacing/interval_budget.h" |
| 17 | #include "modules/pacing/paced_sender.h" |
| 18 | #include "rtc_base/rate_statistics.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 19 | #include "typedefs.h" // NOLINT(build/include) |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 23 | class RtcEventLog; |
| 24 | |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 25 | // Application limited region detector is a class that utilizes signals of |
| 26 | // elapsed time and bytes sent to estimate whether network traffic is |
| 27 | // currently limited by the application's ability to generate traffic. |
| 28 | // |
| 29 | // AlrDetector provides a signal that can be utilized to adjust |
| 30 | // estimate bandwidth. |
| 31 | // Note: This class is not thread-safe. |
| 32 | class AlrDetector { |
| 33 | public: |
| 34 | AlrDetector(); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 35 | explicit AlrDetector(RtcEventLog* event_log); |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 36 | ~AlrDetector(); |
Sergey Ulanov | 0182f85 | 2016-11-16 15:42:11 -0800 | [diff] [blame] | 37 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 38 | void OnBytesSent(size_t bytes_sent, int64_t delta_time_ms); |
Sergey Ulanov | 0182f85 | 2016-11-16 15:42:11 -0800 | [diff] [blame] | 39 | |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 40 | // Set current estimated bandwidth. |
| 41 | void SetEstimatedBitrate(int bitrate_bps); |
Sergey Ulanov | 0182f85 | 2016-11-16 15:42:11 -0800 | [diff] [blame] | 42 | |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 43 | // Returns time in milliseconds when the current application-limited region |
| 44 | // started or empty result if the sender is currently not application-limited. |
| 45 | rtc::Optional<int64_t> GetApplicationLimitedRegionStartTime() const; |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 46 | |
sprang | 89c4a7e | 2017-06-30 13:27:40 -0700 | [diff] [blame] | 47 | // Sent traffic percentage as a function of network capacity used to determine |
| 48 | // application-limited region. ALR region start when bandwidth usage drops |
| 49 | // below kAlrStartUsagePercent and ends when it raises above |
| 50 | // kAlrEndUsagePercent. NOTE: This is intentionally conservative at the moment |
| 51 | // until BW adjustments of application limited region is fine tuned. |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 52 | static constexpr int kDefaultAlrBandwidthUsagePercent = 65; |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 53 | static constexpr int kDefaultAlrStartBudgetLevelPercent = 80; |
| 54 | static constexpr int kDefaultAlrStopBudgetLevelPercent = 50; |
sprang | 89c4a7e | 2017-06-30 13:27:40 -0700 | [diff] [blame] | 55 | |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 56 | void UpdateBudgetWithElapsedTime(int64_t delta_time_ms); |
| 57 | void UpdateBudgetWithBytesSent(size_t bytes_sent); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 58 | |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 59 | private: |
| 60 | int bandwidth_usage_percent_; |
| 61 | int alr_start_budget_level_percent_; |
| 62 | int alr_stop_budget_level_percent_; |
| 63 | |
| 64 | IntervalBudget alr_budget_; |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 65 | rtc::Optional<int64_t> alr_started_time_ms_; |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 66 | |
| 67 | RtcEventLog* event_log_; |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // namespace webrtc |
| 71 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 72 | #endif // MODULES_PACING_ALR_DETECTOR_H_ |