blob: 9f8e8ad5b53293034d51dc95c2ba048875f9b498 [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>
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +020017#include <vector>
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010018
Danil Chapovalov0040b662018-06-18 10:48:16 +020019#include "absl/types/optional.h"
Sebastian Janssonc6c44262018-05-09 10:33:39 +020020#include "api/transport/network_control.h"
21#include "rtc_base/constructormagic.h"
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010022
23namespace webrtc {
24
25class Clock;
26
27// 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:
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +020032 ProbeController();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010033 ~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
philipeldb4fa4b2018-03-06 18:29:22 +010040 // The total bitrate, as opposed to the max bitrate, is the sum of the
41 // configured bitrates for all active streams.
42 void OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate,
43 int64_t at_time_ms);
44
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010045 void OnNetworkAvailability(NetworkAvailability msg);
46
47 void SetEstimatedBitrate(int64_t bitrate_bps, int64_t at_time_ms);
48
49 void EnablePeriodicAlrProbing(bool enable);
50
Danil Chapovalov0040b662018-06-18 10:48:16 +020051 void SetAlrStartTimeMs(absl::optional<int64_t> alr_start_time);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010052 void SetAlrEndedTimeMs(int64_t alr_end_time);
53
54 void RequestProbe(int64_t at_time_ms);
55
56 // Resets the ProbeController to a state equivalent to as if it was just
57 // created EXCEPT for |enable_periodic_alr_probing_|.
58 void Reset(int64_t at_time_ms);
59
60 void Process(int64_t at_time_ms);
61
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +020062 std::vector<ProbeClusterConfig> GetAndResetPendingProbes();
63
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010064 private:
65 enum class State {
66 // Initial state where no probing has been triggered yet.
67 kInit,
68 // Waiting for probing results to continue further probing.
69 kWaitingForProbingResult,
70 // Probing is complete.
71 kProbingComplete,
72 };
73
74 void InitiateExponentialProbing(int64_t at_time_ms);
75 void InitiateProbing(int64_t now_ms,
76 std::initializer_list<int64_t> bitrates_to_probe,
77 bool probe_further);
78
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010079 bool network_available_;
80 State state_;
81 int64_t min_bitrate_to_probe_further_bps_;
82 int64_t time_last_probing_initiated_ms_;
83 int64_t estimated_bitrate_bps_;
84 int64_t start_bitrate_bps_;
85 int64_t max_bitrate_bps_;
86 int64_t last_bwe_drop_probing_time_ms_;
Danil Chapovalov0040b662018-06-18 10:48:16 +020087 absl::optional<int64_t> alr_start_time_ms_;
88 absl::optional<int64_t> alr_end_time_ms_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010089 bool enable_periodic_alr_probing_;
90 int64_t time_of_last_large_drop_ms_;
91 int64_t bitrate_before_last_large_drop_bps_;
philipel0676f222018-04-17 16:12:21 +020092 int64_t max_total_allocated_bitrate_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010093
94 bool in_rapid_recovery_experiment_;
95 // For WebRTC.BWE.MidCallProbing.* metric.
96 bool mid_call_probing_waiting_for_result_;
97 int64_t mid_call_probing_bitrate_bps_;
98 int64_t mid_call_probing_succcess_threshold_;
99
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +0200100 std::vector<ProbeClusterConfig> pending_probes_;
101
102 RTC_DISALLOW_COPY_AND_ASSIGN(ProbeController);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100103};
104
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100105} // namespace webrtc
106
Sebastian Janssonfc7ec8e2018-02-28 16:48:00 +0100107#endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_