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