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 | |
| 11 | #ifndef WEBRTC_MODULES_PACING_ALR_DETECTOR_H_ |
| 12 | #define WEBRTC_MODULES_PACING_ALR_DETECTOR_H_ |
| 13 | |
kwiberg | 84f6a3f | 2017-09-05 08:43:13 -0700 | [diff] [blame] | 14 | #include "webrtc/api/optional.h" |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 15 | #include "webrtc/common_types.h" |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 16 | #include "webrtc/modules/pacing/interval_budget.h" |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 17 | #include "webrtc/modules/pacing/paced_sender.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 18 | #include "webrtc/rtc_base/rate_statistics.h" |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 19 | #include "webrtc/typedefs.h" |
| 20 | |
| 21 | namespace 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. |
| 30 | class AlrDetector { |
| 31 | public: |
| 32 | AlrDetector(); |
| 33 | ~AlrDetector(); |
Sergey Ulanov | 0182f85 | 2016-11-16 15:42:11 -0800 | [diff] [blame] | 34 | |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 35 | void OnBytesSent(size_t bytes_sent, int64_t delta_time_ms); |
Sergey Ulanov | 0182f85 | 2016-11-16 15:42:11 -0800 | [diff] [blame] | 36 | |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 37 | // Set current estimated bandwidth. |
| 38 | void SetEstimatedBitrate(int bitrate_bps); |
Sergey Ulanov | 0182f85 | 2016-11-16 15:42:11 -0800 | [diff] [blame] | 39 | |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 40 | // Returns time in milliseconds when the current application-limited region |
| 41 | // started or empty result if the sender is currently not application-limited. |
| 42 | rtc::Optional<int64_t> GetApplicationLimitedRegionStartTime() const; |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 43 | |
sprang | 89c4a7e | 2017-06-30 13:27:40 -0700 | [diff] [blame] | 44 | struct AlrExperimentSettings { |
| 45 | float pacing_factor = PacedSender::kDefaultPaceMultiplier; |
| 46 | int64_t max_paced_queue_time = PacedSender::kMaxQueueLengthMs; |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 47 | int alr_bandwidth_usage_percent = kDefaultAlrBandwidthUsagePercent; |
| 48 | int alr_start_budget_level_percent = kDefaultAlrStartBudgetLevelPercent; |
| 49 | int alr_stop_budget_level_percent = kDefaultAlrStopBudgetLevelPercent; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 50 | // Will be sent to the receive side for stats slicing. |
| 51 | // Can be 0..6, because it's sent as a 3 bits value and there's also |
| 52 | // reserved value to indicate absence of experiment. |
| 53 | int group_id = 0; |
sprang | 89c4a7e | 2017-06-30 13:27:40 -0700 | [diff] [blame] | 54 | }; |
stefan | d7a418f | 2017-08-08 06:51:05 -0700 | [diff] [blame] | 55 | static rtc::Optional<AlrExperimentSettings> ParseAlrSettingsFromFieldTrial( |
| 56 | const char* experiment_name); |
sprang | 89c4a7e | 2017-06-30 13:27:40 -0700 | [diff] [blame] | 57 | |
| 58 | // Sent traffic percentage as a function of network capacity used to determine |
| 59 | // application-limited region. ALR region start when bandwidth usage drops |
| 60 | // below kAlrStartUsagePercent and ends when it raises above |
| 61 | // kAlrEndUsagePercent. NOTE: This is intentionally conservative at the moment |
| 62 | // until BW adjustments of application limited region is fine tuned. |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 63 | static constexpr int kDefaultAlrBandwidthUsagePercent = 65; |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 64 | static constexpr int kDefaultAlrStartBudgetLevelPercent = 80; |
| 65 | static constexpr int kDefaultAlrStopBudgetLevelPercent = 50; |
agrieve | 26622d3 | 2017-08-08 10:48:15 -0700 | [diff] [blame] | 66 | static const char kScreenshareProbingBweExperimentName[]; |
| 67 | static const char kStrictPacingAndProbingExperimentName[]; |
sprang | 89c4a7e | 2017-06-30 13:27:40 -0700 | [diff] [blame] | 68 | |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 69 | void UpdateBudgetWithElapsedTime(int64_t delta_time_ms); |
| 70 | void UpdateBudgetWithBytesSent(size_t bytes_sent); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 71 | |
tschumim | 82c5593 | 2017-07-11 06:56:04 -0700 | [diff] [blame] | 72 | private: |
| 73 | int bandwidth_usage_percent_; |
| 74 | int alr_start_budget_level_percent_; |
| 75 | int alr_stop_budget_level_percent_; |
| 76 | |
| 77 | IntervalBudget alr_budget_; |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 78 | rtc::Optional<int64_t> alr_started_time_ms_; |
isheriff | 3168781 | 2016-10-04 08:43:09 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace webrtc |
| 82 | |
| 83 | #endif // WEBRTC_MODULES_PACING_ALR_DETECTOR_H_ |