blob: df0b7d24079a04a7121996cfab689f73ce936e77 [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"
15#include "webrtc/modules/pacing/paced_sender.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020016#include "webrtc/rtc_base/optional.h"
17#include "webrtc/rtc_base/rate_statistics.h"
isheriff31687812016-10-04 08:43:09 -070018#include "webrtc/typedefs.h"
19
20namespace webrtc {
21
22// Application limited region detector is a class that utilizes signals of
23// elapsed time and bytes sent to estimate whether network traffic is
24// currently limited by the application's ability to generate traffic.
25//
26// AlrDetector provides a signal that can be utilized to adjust
27// estimate bandwidth.
28// Note: This class is not thread-safe.
sprang89c4a7e2017-06-30 13:27:40 -070029
isheriff31687812016-10-04 08:43:09 -070030class AlrDetector {
31 public:
32 AlrDetector();
33 ~AlrDetector();
Sergey Ulanov0182f852016-11-16 15:42:11 -080034
35 void OnBytesSent(size_t bytes_sent, int64_t now_ms);
36
isheriff31687812016-10-04 08:43:09 -070037 // Set current estimated bandwidth.
38 void SetEstimatedBitrate(int bitrate_bps);
Sergey Ulanov0182f852016-11-16 15:42:11 -080039
sergeyu80ed35e2016-11-28 13:11:13 -080040 // 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;
isheriff31687812016-10-04 08:43:09 -070043
sprang89c4a7e2017-06-30 13:27:40 -070044 struct AlrExperimentSettings {
45 float pacing_factor = PacedSender::kDefaultPaceMultiplier;
46 int64_t max_paced_queue_time = PacedSender::kMaxQueueLengthMs;
47 int alr_start_usage_percent = kDefaultAlrStartUsagePercent;
48 int alr_end_usage_percent = kDefaultAlrEndUsagePercent;
49 };
50 static rtc::Optional<AlrExperimentSettings> ParseAlrSettingsFromFieldTrial();
51
52 // Sent traffic percentage as a function of network capacity used to determine
53 // application-limited region. ALR region start when bandwidth usage drops
54 // below kAlrStartUsagePercent and ends when it raises above
55 // kAlrEndUsagePercent. NOTE: This is intentionally conservative at the moment
56 // until BW adjustments of application limited region is fine tuned.
57 static constexpr int kDefaultAlrStartUsagePercent = 60;
58 static constexpr int kDefaultAlrEndUsagePercent = 70;
59 static const char* kScreenshareProbingBweExperimentName;
60
isheriff31687812016-10-04 08:43:09 -070061 private:
sprang89c4a7e2017-06-30 13:27:40 -070062 int alr_start_usage_percent_;
63 int alr_end_usage_percent_;
Sergey Ulanov0182f852016-11-16 15:42:11 -080064 RateStatistics rate_;
sprang89c4a7e2017-06-30 13:27:40 -070065 int estimated_bitrate_bps_;
sergeyu80ed35e2016-11-28 13:11:13 -080066
67 // Non-empty in ALR state.
68 rtc::Optional<int64_t> alr_started_time_ms_;
isheriff31687812016-10-04 08:43:09 -070069};
70
71} // namespace webrtc
72
73#endif // WEBRTC_MODULES_PACING_ALR_DETECTOR_H_