blob: bacea0c5d5aa290ad8306060665493f7b0a2889c [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"
Sebastian Jansson95edb032019-01-17 16:24:12 +010021#include "api/transport/webrtc_key_value_config.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "rtc_base/constructor_magic.h"
Sebastian Janssonda2ec402018-08-02 16:27:28 +020023#include "rtc_base/system/unused.h"
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010024
25namespace webrtc {
26
27class Clock;
28
29// This class controls initiation of probing to estimate initial channel
30// capacity. There is also support for probing during a session when max
31// bitrate is adjusted by an application.
32class ProbeController {
33 public:
Sebastian Jansson95edb032019-01-17 16:24:12 +010034 explicit ProbeController(const WebRtcKeyValueConfig* key_value_config);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010035 ~ProbeController();
36
Sebastian Janssonda2ec402018-08-02 16:27:28 +020037 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetBitrates(
38 int64_t min_bitrate_bps,
39 int64_t start_bitrate_bps,
40 int64_t max_bitrate_bps,
41 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010042
philipeldb4fa4b2018-03-06 18:29:22 +010043 // The total bitrate, as opposed to the max bitrate, is the sum of the
44 // configured bitrates for all active streams.
Sebastian Janssonda2ec402018-08-02 16:27:28 +020045 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig>
46 OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate,
47 int64_t at_time_ms);
philipeldb4fa4b2018-03-06 18:29:22 +010048
Sebastian Janssonda2ec402018-08-02 16:27:28 +020049 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> OnNetworkAvailability(
50 NetworkAvailability msg);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010051
Sebastian Janssonda2ec402018-08-02 16:27:28 +020052 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetEstimatedBitrate(
53 int64_t bitrate_bps,
54 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010055
56 void EnablePeriodicAlrProbing(bool enable);
57
Danil Chapovalov0040b662018-06-18 10:48:16 +020058 void SetAlrStartTimeMs(absl::optional<int64_t> alr_start_time);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010059 void SetAlrEndedTimeMs(int64_t alr_end_time);
60
Sebastian Janssonda2ec402018-08-02 16:27:28 +020061 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> RequestProbe(
62 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010063
Sebastian Jansson8d33c0c2018-10-22 10:22:03 +020064 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig>
65 InitiateCapacityProbing(int64_t bitrate_bps, int64_t at_time_ms);
66
Erik Språng791d43c2019-01-08 15:46:06 +010067 // Sets a new maximum probing bitrate, without generating a new probe cluster.
68 void SetMaxBitrate(int64_t max_bitrate_bps);
69
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010070 // Resets the ProbeController to a state equivalent to as if it was just
71 // created EXCEPT for |enable_periodic_alr_probing_|.
72 void Reset(int64_t at_time_ms);
73
Sebastian Janssonda2ec402018-08-02 16:27:28 +020074 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> Process(
75 int64_t at_time_ms);
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +020076
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010077 private:
78 enum class State {
79 // Initial state where no probing has been triggered yet.
80 kInit,
81 // Waiting for probing results to continue further probing.
82 kWaitingForProbingResult,
83 // Probing is complete.
84 kProbingComplete,
85 };
86
Sebastian Janssonda2ec402018-08-02 16:27:28 +020087 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig>
88 InitiateExponentialProbing(int64_t at_time_ms);
89 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> InitiateProbing(
90 int64_t now_ms,
91 std::initializer_list<int64_t> bitrates_to_probe,
92 bool probe_further);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010093
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010094 bool network_available_;
95 State state_;
96 int64_t min_bitrate_to_probe_further_bps_;
97 int64_t time_last_probing_initiated_ms_;
98 int64_t estimated_bitrate_bps_;
99 int64_t start_bitrate_bps_;
100 int64_t max_bitrate_bps_;
101 int64_t last_bwe_drop_probing_time_ms_;
Danil Chapovalov0040b662018-06-18 10:48:16 +0200102 absl::optional<int64_t> alr_start_time_ms_;
103 absl::optional<int64_t> alr_end_time_ms_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100104 bool enable_periodic_alr_probing_;
105 int64_t time_of_last_large_drop_ms_;
106 int64_t bitrate_before_last_large_drop_bps_;
philipel0676f222018-04-17 16:12:21 +0200107 int64_t max_total_allocated_bitrate_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100108
Erik Språngcfe36ca2018-11-29 17:32:48 +0100109 const bool in_rapid_recovery_experiment_;
110 const bool limit_probes_with_allocateable_rate_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100111 // For WebRTC.BWE.MidCallProbing.* metric.
112 bool mid_call_probing_waiting_for_result_;
113 int64_t mid_call_probing_bitrate_bps_;
114 int64_t mid_call_probing_succcess_threshold_;
115
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +0200116 RTC_DISALLOW_COPY_AND_ASSIGN(ProbeController);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100117};
118
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100119} // namespace webrtc
120
Sebastian Janssonfc7ec8e2018-02-28 16:48:00 +0100121#endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_