blob: 4a3071cc592b944e43dd921e8ea28b12841b9db9 [file] [log] [blame]
Irfan Sheriffb2540bb2016-09-12 12:28:54 -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_CONGESTION_CONTROLLER_PROBE_CONTROLLER_H_
12#define WEBRTC_MODULES_CONGESTION_CONTROLLER_PROBE_CONTROLLER_H_
13
14#include <initializer_list>
15
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070016#include "webrtc/common_types.h"
17#include "webrtc/modules/pacing/paced_sender.h"
kjellanderc8fa6922017-06-30 14:02:00 -070018#include "webrtc/rtc_base/criticalsection.h"
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070019
20namespace webrtc {
21
22class Clock;
23
24// This class controls initiation of probing to estimate initial channel
25// capacity. There is also support for probing during a session when max
26// bitrate is adjusted by an application.
27class ProbeController {
28 public:
elad.alon61ce37e2017-03-09 07:09:31 -080029 ProbeController(PacedSender* pacer, const Clock* clock);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070030
sergeyu5bc39452016-12-15 10:42:09 -080031 void SetBitrates(int64_t min_bitrate_bps,
32 int64_t start_bitrate_bps,
33 int64_t max_bitrate_bps);
Sergey Ulanove2b15012016-11-22 16:08:30 -080034
35 void OnNetworkStateChanged(NetworkState state);
36
sergeyu5bc39452016-12-15 10:42:09 -080037 void SetEstimatedBitrate(int64_t bitrate_bps);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070038
sergeyu80ed35e2016-11-28 13:11:13 -080039 void EnablePeriodicAlrProbing(bool enable);
philipelcb9ba302017-03-07 06:30:59 -080040
41 // Resets the ProbeController to a state equivalent to as if it was just
42 // created EXCEPT for |enable_periodic_alr_probing_|.
43 void Reset();
44
sergeyu80ed35e2016-11-28 13:11:13 -080045 void Process();
46
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070047 private:
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070048 enum class State {
49 // Initial state where no probing has been triggered yet.
50 kInit,
51 // Waiting for probing results to continue further probing.
52 kWaitingForProbingResult,
53 // Probing is complete.
54 kProbingComplete,
55 };
Sergey Ulanove2b15012016-11-22 16:08:30 -080056
57 void InitiateExponentialProbing() EXCLUSIVE_LOCKS_REQUIRED(critsect_);
sergeyu80ed35e2016-11-28 13:11:13 -080058 void InitiateProbing(int64_t now_ms,
sergeyu5bc39452016-12-15 10:42:09 -080059 std::initializer_list<int64_t> bitrates_to_probe,
60 bool probe_further) EXCLUSIVE_LOCKS_REQUIRED(critsect_);
Sergey Ulanove2b15012016-11-22 16:08:30 -080061
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070062 rtc::CriticalSection critsect_;
63 PacedSender* const pacer_;
elad.alon61ce37e2017-03-09 07:09:31 -080064 const Clock* const clock_;
Sergey Ulanove2b15012016-11-22 16:08:30 -080065 NetworkState network_state_ GUARDED_BY(critsect_);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070066 State state_ GUARDED_BY(critsect_);
sergeyu5bc39452016-12-15 10:42:09 -080067 int64_t min_bitrate_to_probe_further_bps_ GUARDED_BY(critsect_);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070068 int64_t time_last_probing_initiated_ms_ GUARDED_BY(critsect_);
sergeyu5bc39452016-12-15 10:42:09 -080069 int64_t estimated_bitrate_bps_ GUARDED_BY(critsect_);
70 int64_t start_bitrate_bps_ GUARDED_BY(critsect_);
71 int64_t max_bitrate_bps_ GUARDED_BY(critsect_);
Irfan Sheriff1eb12932016-10-18 17:04:25 -070072 int64_t last_alr_probing_time_ GUARDED_BY(critsect_);
sergeyu80ed35e2016-11-28 13:11:13 -080073 bool enable_periodic_alr_probing_ GUARDED_BY(critsect_);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070074
philipel2df07342017-01-16 09:31:49 -080075 // For WebRTC.BWE.MidCallProbing.* metric.
76 bool mid_call_probing_waiting_for_result_ GUARDED_BY(&critsect_);
77 int64_t mid_call_probing_bitrate_bps_ GUARDED_BY(&critsect_);
78 int64_t mid_call_probing_succcess_threshold_ GUARDED_BY(&critsect_);
79
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070080 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ProbeController);
81};
82
83} // namespace webrtc
84
85#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_PROBE_CONTROLLER_H_