blob: 0b1e685bab7ed2f27e7e5fef201f9d24d3332dea [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 Janssonda2ec402018-08-02 16:27:28 +020022#include "rtc_base/system/unused.h"
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010023
24namespace webrtc {
25
26class Clock;
27
28// This class controls initiation of probing to estimate initial channel
29// capacity. There is also support for probing during a session when max
30// bitrate is adjusted by an application.
31class ProbeController {
32 public:
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +020033 ProbeController();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010034 ~ProbeController();
35
Sebastian Janssonda2ec402018-08-02 16:27:28 +020036 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetBitrates(
37 int64_t min_bitrate_bps,
38 int64_t start_bitrate_bps,
39 int64_t max_bitrate_bps,
40 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010041
philipeldb4fa4b2018-03-06 18:29:22 +010042 // The total bitrate, as opposed to the max bitrate, is the sum of the
43 // configured bitrates for all active streams.
Sebastian Janssonda2ec402018-08-02 16:27:28 +020044 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig>
45 OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate,
46 int64_t at_time_ms);
philipeldb4fa4b2018-03-06 18:29:22 +010047
Sebastian Janssonda2ec402018-08-02 16:27:28 +020048 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> OnNetworkAvailability(
49 NetworkAvailability msg);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010050
Sebastian Janssonda2ec402018-08-02 16:27:28 +020051 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetEstimatedBitrate(
52 int64_t bitrate_bps,
53 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010054
55 void EnablePeriodicAlrProbing(bool enable);
56
Danil Chapovalov0040b662018-06-18 10:48:16 +020057 void SetAlrStartTimeMs(absl::optional<int64_t> alr_start_time);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010058 void SetAlrEndedTimeMs(int64_t alr_end_time);
59
Sebastian Janssonda2ec402018-08-02 16:27:28 +020060 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> RequestProbe(
61 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010062
Sebastian Jansson8d33c0c2018-10-22 10:22:03 +020063 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig>
64 InitiateCapacityProbing(int64_t bitrate_bps, int64_t at_time_ms);
65
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010066 // Resets the ProbeController to a state equivalent to as if it was just
67 // created EXCEPT for |enable_periodic_alr_probing_|.
68 void Reset(int64_t at_time_ms);
69
Sebastian Janssonda2ec402018-08-02 16:27:28 +020070 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> Process(
71 int64_t at_time_ms);
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +020072
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010073 private:
74 enum class State {
75 // Initial state where no probing has been triggered yet.
76 kInit,
77 // Waiting for probing results to continue further probing.
78 kWaitingForProbingResult,
79 // Probing is complete.
80 kProbingComplete,
81 };
82
Sebastian Janssonda2ec402018-08-02 16:27:28 +020083 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig>
84 InitiateExponentialProbing(int64_t at_time_ms);
85 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> InitiateProbing(
86 int64_t now_ms,
87 std::initializer_list<int64_t> bitrates_to_probe,
88 bool probe_further);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010089
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010090 bool network_available_;
91 State state_;
92 int64_t min_bitrate_to_probe_further_bps_;
93 int64_t time_last_probing_initiated_ms_;
94 int64_t estimated_bitrate_bps_;
95 int64_t start_bitrate_bps_;
96 int64_t max_bitrate_bps_;
97 int64_t last_bwe_drop_probing_time_ms_;
Danil Chapovalov0040b662018-06-18 10:48:16 +020098 absl::optional<int64_t> alr_start_time_ms_;
99 absl::optional<int64_t> alr_end_time_ms_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100100 bool enable_periodic_alr_probing_;
101 int64_t time_of_last_large_drop_ms_;
102 int64_t bitrate_before_last_large_drop_bps_;
philipel0676f222018-04-17 16:12:21 +0200103 int64_t max_total_allocated_bitrate_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100104
Erik Språngcfe36ca2018-11-29 17:32:48 +0100105 const bool in_rapid_recovery_experiment_;
106 const bool limit_probes_with_allocateable_rate_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100107 // For WebRTC.BWE.MidCallProbing.* metric.
108 bool mid_call_probing_waiting_for_result_;
109 int64_t mid_call_probing_bitrate_bps_;
110 int64_t mid_call_probing_succcess_threshold_;
111
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +0200112 RTC_DISALLOW_COPY_AND_ASSIGN(ProbeController);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100113};
114
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100115} // namespace webrtc
116
Sebastian Janssonfc7ec8e2018-02-28 16:48:00 +0100117#endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_