blob: f73bc17b3db8004f49a6fa1c91044d632714facb [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
Sebastian Janssonea86bb72018-02-14 16:53:38 +000011#ifndef MODULES_PACING_ALR_DETECTOR_H_
12#define MODULES_PACING_ALR_DETECTOR_H_
isheriff31687812016-10-04 08:43:09 -070013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "api/optional.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020015#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/pacing/interval_budget.h"
17#include "modules/pacing/paced_sender.h"
18#include "rtc_base/rate_statistics.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020019#include "typedefs.h" // NOLINT(build/include)
isheriff31687812016-10-04 08:43:09 -070020
21namespace webrtc {
22
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +010023class RtcEventLog;
24
isheriff31687812016-10-04 08:43:09 -070025// 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.
32class AlrDetector {
33 public:
34 AlrDetector();
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +010035 explicit AlrDetector(RtcEventLog* event_log);
isheriff31687812016-10-04 08:43:09 -070036 ~AlrDetector();
Sergey Ulanov0182f852016-11-16 15:42:11 -080037
Sebastian Janssonea86bb72018-02-14 16:53:38 +000038 void OnBytesSent(size_t bytes_sent, int64_t delta_time_ms);
Sergey Ulanov0182f852016-11-16 15:42:11 -080039
isheriff31687812016-10-04 08:43:09 -070040 // Set current estimated bandwidth.
41 void SetEstimatedBitrate(int bitrate_bps);
Sergey Ulanov0182f852016-11-16 15:42:11 -080042
sergeyu80ed35e2016-11-28 13:11:13 -080043 // 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;
isheriff31687812016-10-04 08:43:09 -070046
sprang89c4a7e2017-06-30 13:27:40 -070047 // 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.
tschumim82c55932017-07-11 06:56:04 -070052 static constexpr int kDefaultAlrBandwidthUsagePercent = 65;
tschumim9d117642017-07-17 01:41:41 -070053 static constexpr int kDefaultAlrStartBudgetLevelPercent = 80;
54 static constexpr int kDefaultAlrStopBudgetLevelPercent = 50;
sprang89c4a7e2017-06-30 13:27:40 -070055
tschumim82c55932017-07-11 06:56:04 -070056 void UpdateBudgetWithElapsedTime(int64_t delta_time_ms);
57 void UpdateBudgetWithBytesSent(size_t bytes_sent);
sergeyu80ed35e2016-11-28 13:11:13 -080058
tschumim82c55932017-07-11 06:56:04 -070059 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_;
sergeyu80ed35e2016-11-28 13:11:13 -080065 rtc::Optional<int64_t> alr_started_time_ms_;
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +010066
67 RtcEventLog* event_log_;
isheriff31687812016-10-04 08:43:09 -070068};
69
70} // namespace webrtc
71
Sebastian Janssonea86bb72018-02-14 16:53:38 +000072#endif // MODULES_PACING_ALR_DETECTOR_H_