blob: 2becd3025e03e6f8a24defa903548510700c1135 [file] [log] [blame]
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +01001/*
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 MODULES_CONGESTION_CONTROLLER_RTP_PROBE_CONTROLLER_H_
12#define MODULES_CONGESTION_CONTROLLER_RTP_PROBE_CONTROLLER_H_
13
14#include <stdint.h>
15
16#include <initializer_list>
17
18#include "api/optional.h"
19#include "modules/congestion_controller/rtp/network_control/include/network_control.h"
20
21namespace webrtc {
22
23class Clock;
24
25// This class controls initiation of probing to estimate initial channel
26// capacity. There is also support for probing during a session when max
27// bitrate is adjusted by an application.
28class ProbeController {
29 public:
30 explicit ProbeController(NetworkControllerObserver* observer);
31 ~ProbeController();
32
33 void SetBitrates(int64_t min_bitrate_bps,
34 int64_t start_bitrate_bps,
35 int64_t max_bitrate_bps,
36 int64_t at_time_ms);
37
38 void OnNetworkAvailability(NetworkAvailability msg);
39
40 void SetEstimatedBitrate(int64_t bitrate_bps, int64_t at_time_ms);
41
42 void EnablePeriodicAlrProbing(bool enable);
43
44 void SetAlrStartTimeMs(rtc::Optional<int64_t> alr_start_time);
45 void SetAlrEndedTimeMs(int64_t alr_end_time);
46
47 void RequestProbe(int64_t at_time_ms);
48
49 // Resets the ProbeController to a state equivalent to as if it was just
50 // created EXCEPT for |enable_periodic_alr_probing_|.
51 void Reset(int64_t at_time_ms);
52
53 void Process(int64_t at_time_ms);
54
55 private:
56 enum class State {
57 // Initial state where no probing has been triggered yet.
58 kInit,
59 // Waiting for probing results to continue further probing.
60 kWaitingForProbingResult,
61 // Probing is complete.
62 kProbingComplete,
63 };
64
65 void InitiateExponentialProbing(int64_t at_time_ms);
66 void InitiateProbing(int64_t now_ms,
67 std::initializer_list<int64_t> bitrates_to_probe,
68 bool probe_further);
69
70 NetworkControllerObserver* const observer_;
71
72 bool network_available_;
73 State state_;
74 int64_t min_bitrate_to_probe_further_bps_;
75 int64_t time_last_probing_initiated_ms_;
76 int64_t estimated_bitrate_bps_;
77 int64_t start_bitrate_bps_;
78 int64_t max_bitrate_bps_;
79 int64_t last_bwe_drop_probing_time_ms_;
80 rtc::Optional<int64_t> alr_start_time_ms_;
81 rtc::Optional<int64_t> alr_end_time_ms_;
82 bool enable_periodic_alr_probing_;
83 int64_t time_of_last_large_drop_ms_;
84 int64_t bitrate_before_last_large_drop_bps_;
85
86 bool in_rapid_recovery_experiment_;
87 // For WebRTC.BWE.MidCallProbing.* metric.
88 bool mid_call_probing_waiting_for_result_;
89 int64_t mid_call_probing_bitrate_bps_;
90 int64_t mid_call_probing_succcess_threshold_;
91
92 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ProbeController);
93};
94
95} // namespace webrtc
96
97#endif // MODULES_CONGESTION_CONTROLLER_RTP_PROBE_CONTROLLER_H_