blob: 4faa8af3e3f487c3c459abdf2d22b82fb92dde8a [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
16#include "webrtc/base/criticalsection.h"
17#include "webrtc/common_types.h"
18#include "webrtc/modules/pacing/paced_sender.h"
19
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:
29 ProbeController(PacedSender* pacer, Clock* clock);
30
31 void SetBitrates(int min_bitrate_bps,
32 int start_bitrate_bps,
33 int max_bitrate_bps);
Sergey Ulanove2b15012016-11-22 16:08:30 -080034
35 void OnNetworkStateChanged(NetworkState state);
36
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070037 void SetEstimatedBitrate(int bitrate_bps);
38
sergeyu80ed35e2016-11-28 13:11:13 -080039 void EnablePeriodicAlrProbing(bool enable);
40 void Process();
41
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070042 private:
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070043 enum class State {
44 // Initial state where no probing has been triggered yet.
45 kInit,
46 // Waiting for probing results to continue further probing.
47 kWaitingForProbingResult,
48 // Probing is complete.
49 kProbingComplete,
50 };
Sergey Ulanove2b15012016-11-22 16:08:30 -080051
52 void InitiateExponentialProbing() EXCLUSIVE_LOCKS_REQUIRED(critsect_);
sergeyu80ed35e2016-11-28 13:11:13 -080053 void InitiateProbing(int64_t now_ms,
54 std::initializer_list<int> bitrates_to_probe,
Sergey Ulanove2b15012016-11-22 16:08:30 -080055 int min_bitrate_to_probe_further_bps)
56 EXCLUSIVE_LOCKS_REQUIRED(critsect_);
57
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070058 rtc::CriticalSection critsect_;
59 PacedSender* const pacer_;
60 Clock* const clock_;
Sergey Ulanove2b15012016-11-22 16:08:30 -080061 NetworkState network_state_ GUARDED_BY(critsect_);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070062 State state_ GUARDED_BY(critsect_);
63 int min_bitrate_to_probe_further_bps_ GUARDED_BY(critsect_);
64 int64_t time_last_probing_initiated_ms_ GUARDED_BY(critsect_);
65 int estimated_bitrate_bps_ GUARDED_BY(critsect_);
Sergey Ulanove2b15012016-11-22 16:08:30 -080066 int start_bitrate_bps_ GUARDED_BY(critsect_);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070067 int max_bitrate_bps_ GUARDED_BY(critsect_);
Irfan Sheriff1eb12932016-10-18 17:04:25 -070068 int64_t last_alr_probing_time_ GUARDED_BY(critsect_);
sergeyu80ed35e2016-11-28 13:11:13 -080069 bool enable_periodic_alr_probing_ GUARDED_BY(critsect_);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070070
71 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ProbeController);
72};
73
74} // namespace webrtc
75
76#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_PROBE_CONTROLLER_H_