OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/congestion_controller/probe_controller.h" | 11 #include "webrtc/modules/congestion_controller/probe_controller.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <initializer_list> | 14 #include <initializer_list> |
15 | 15 |
16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
17 #include "webrtc/base/safe_conversions.h" | |
17 #include "webrtc/system_wrappers/include/metrics.h" | 18 #include "webrtc/system_wrappers/include/metrics.h" |
18 | 19 |
19 namespace webrtc { | 20 namespace webrtc { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Number of deltas between probes per cluster. On the very first cluster, | 24 // Number of deltas between probes per cluster. On the very first cluster, |
24 // we will need kProbeDeltasPerCluster + 1 probes, but on a cluster following | 25 // we will need kProbeDeltasPerCluster + 1 probes, but on a cluster following |
25 // another, we need kProbeDeltasPerCluster probes. | 26 // another, we need kProbeDeltasPerCluster probes. |
26 constexpr int kProbeDeltasPerCluster = 5; | 27 constexpr int kProbeDeltasPerCluster = 5; |
27 | 28 |
28 // Maximum waiting time from the time of initiating probing to getting | 29 // Maximum waiting time from the time of initiating probing to getting |
29 // the measured results back. | 30 // the measured results back. |
30 constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000; | 31 constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000; |
31 | 32 |
32 // Value of |min_bitrate_to_probe_further_bps_| that indicates | 33 // Value of |min_bitrate_to_probe_further_bps_| that indicates |
33 // further probing is disabled. | 34 // further probing is disabled. |
34 constexpr int kExponentialProbingDisabled = 0; | 35 constexpr int kExponentialProbingDisabled = 0; |
35 | 36 |
36 // Default probing bitrate limit. Applied only when the application didn't | 37 // Default probing bitrate limit. Applied only when the application didn't |
37 // specify max bitrate. | 38 // specify max bitrate. |
38 constexpr int kDefaultMaxProbingBitrateBps = 5000000; | 39 constexpr int64_t kDefaultMaxProbingBitrateBps = 5000000; |
39 | 40 |
40 // This is a limit on how often probing can be done when there is a BW | 41 // This is a limit on how often probing can be done when there is a BW |
41 // drop detected in ALR. | 42 // drop detected in ALR. |
42 constexpr int64_t kAlrProbingIntervalMinMs = 5000; | 43 constexpr int64_t kAlrProbingIntervalMinMs = 5000; |
43 | 44 |
44 // Interval between probes when ALR periodic probing is enabled. | 45 // Interval between probes when ALR periodic probing is enabled. |
45 constexpr int64_t kAlrPeriodicProbingIntervalMs = 5000; | 46 constexpr int64_t kAlrPeriodicProbingIntervalMs = 5000; |
46 | 47 |
47 // Minimum probe bitrate percentage to probe further for repeated probes. | 48 // Minimum probe bitrate percentage to probe further for repeated probes, |
48 constexpr int kRepeatedProbeMinPercentage = 125; | 49 // relative to the previous probe. For example, if 1Mbps probe results in |
50 // 80kbps, then we'll probe again at 1.6Mbps. In that case second probe won't be | |
51 // sent if we get 600kbps from the first one. | |
52 constexpr int kRepeatedProbeMinPercentage = 70; | |
49 | 53 |
50 } // namespace | 54 } // namespace |
51 | 55 |
52 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) | 56 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) |
53 : pacer_(pacer), | 57 : pacer_(pacer), |
54 clock_(clock), | 58 clock_(clock), |
55 network_state_(kNetworkUp), | 59 network_state_(kNetworkUp), |
56 state_(State::kInit), | 60 state_(State::kInit), |
57 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), | 61 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), |
58 time_last_probing_initiated_ms_(0), | 62 time_last_probing_initiated_ms_(0), |
59 estimated_bitrate_bps_(0), | 63 estimated_bitrate_bps_(0), |
60 start_bitrate_bps_(0), | 64 start_bitrate_bps_(0), |
61 max_bitrate_bps_(0), | 65 max_bitrate_bps_(0), |
62 last_alr_probing_time_(clock_->TimeInMilliseconds()), | 66 last_alr_probing_time_(clock_->TimeInMilliseconds()), |
63 enable_periodic_alr_probing_(false) {} | 67 enable_periodic_alr_probing_(false) {} |
64 | 68 |
65 void ProbeController::SetBitrates(int min_bitrate_bps, | 69 void ProbeController::SetBitrates(int64_t min_bitrate_bps, |
66 int start_bitrate_bps, | 70 int64_t start_bitrate_bps, |
67 int max_bitrate_bps) { | 71 int64_t max_bitrate_bps) { |
68 rtc::CritScope cs(&critsect_); | 72 rtc::CritScope cs(&critsect_); |
69 | 73 |
70 if (start_bitrate_bps > 0) { | 74 if (start_bitrate_bps > 0) { |
71 start_bitrate_bps_ = start_bitrate_bps; | 75 start_bitrate_bps_ = start_bitrate_bps; |
72 } else if (start_bitrate_bps_ == 0) { | 76 } else if (start_bitrate_bps_ == 0) { |
73 start_bitrate_bps_ = min_bitrate_bps; | 77 start_bitrate_bps_ = min_bitrate_bps; |
74 } | 78 } |
75 | 79 |
76 int old_max_bitrate_bps = max_bitrate_bps_; | 80 int old_max_bitrate_bps = max_bitrate_bps_; |
philipel
2016/12/14 09:33:44
int64_t
Sergey Ulanov
2016/12/14 22:41:26
Done.
| |
77 max_bitrate_bps_ = max_bitrate_bps; | 81 max_bitrate_bps_ = max_bitrate_bps; |
78 | 82 |
79 switch (state_) { | 83 switch (state_) { |
80 case State::kInit: | 84 case State::kInit: |
81 if (network_state_ == kNetworkUp) | 85 if (network_state_ == kNetworkUp) |
82 InitiateExponentialProbing(); | 86 InitiateExponentialProbing(); |
83 break; | 87 break; |
84 | 88 |
85 case State::kWaitingForProbingResult: | 89 case State::kWaitingForProbingResult: |
86 break; | 90 break; |
87 | 91 |
88 case State::kProbingComplete: | 92 case State::kProbingComplete: |
89 // Initiate probing when |max_bitrate_| was increased mid-call. | 93 // Initiate probing when |max_bitrate_| was increased mid-call. |
90 if (estimated_bitrate_bps_ != 0 && | 94 if (estimated_bitrate_bps_ != kExponentialProbingDisabled && |
91 estimated_bitrate_bps_ < old_max_bitrate_bps && | 95 estimated_bitrate_bps_ < old_max_bitrate_bps && |
92 max_bitrate_bps_ > old_max_bitrate_bps) { | 96 max_bitrate_bps_ > old_max_bitrate_bps) { |
93 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, | 97 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, false); |
94 kExponentialProbingDisabled); | |
95 } | 98 } |
96 break; | 99 break; |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { | 103 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { |
101 rtc::CritScope cs(&critsect_); | 104 rtc::CritScope cs(&critsect_); |
102 network_state_ = network_state; | 105 network_state_ = network_state; |
103 if (network_state_ == kNetworkUp && state_ == State::kInit) | 106 if (network_state_ == kNetworkUp && state_ == State::kInit) |
104 InitiateExponentialProbing(); | 107 InitiateExponentialProbing(); |
105 } | 108 } |
106 | 109 |
107 void ProbeController::InitiateExponentialProbing() { | 110 void ProbeController::InitiateExponentialProbing() { |
108 RTC_DCHECK(network_state_ == kNetworkUp); | 111 RTC_DCHECK(network_state_ == kNetworkUp); |
109 RTC_DCHECK(state_ == State::kInit); | 112 RTC_DCHECK(state_ == State::kInit); |
110 RTC_DCHECK_GT(start_bitrate_bps_, 0); | 113 RTC_DCHECK_GT(start_bitrate_bps_, 0); |
111 | 114 |
112 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 115 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
113 // 1.2 Mbps to continue probing. | 116 // 1.2 Mbps to continue probing. |
114 InitiateProbing(clock_->TimeInMilliseconds(), | 117 InitiateProbing(clock_->TimeInMilliseconds(), |
115 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, | 118 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, true); |
116 4 * start_bitrate_bps_); | |
117 } | 119 } |
118 | 120 |
119 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { | 121 void ProbeController::SetEstimatedBitrate(int64_t bitrate_bps) { |
120 rtc::CritScope cs(&critsect_); | 122 rtc::CritScope cs(&critsect_); |
121 int64_t now_ms = clock_->TimeInMilliseconds(); | 123 int64_t now_ms = clock_->TimeInMilliseconds(); |
122 | 124 |
123 if (state_ == State::kWaitingForProbingResult) { | 125 if (state_ == State::kWaitingForProbingResult) { |
124 // Continue probing if probing results indicate channel has greater | 126 // Continue probing if probing results indicate channel has greater |
125 // capacity. | 127 // capacity. |
126 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps | 128 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps |
127 << " Minimum to probe further: " | 129 << " Minimum to probe further: " |
128 << min_bitrate_to_probe_further_bps_; | 130 << min_bitrate_to_probe_further_bps_; |
129 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && | 131 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && |
130 bitrate_bps > min_bitrate_to_probe_further_bps_) { | 132 bitrate_bps > min_bitrate_to_probe_further_bps_) { |
131 // Double the probing bitrate and expect a minimum of 25% gain to | 133 // Double the probing bitrate. |
132 // continue probing. | 134 InitiateProbing(now_ms, {2 * bitrate_bps}, true); |
133 InitiateProbing(now_ms, {2 * bitrate_bps}, | |
134 bitrate_bps * kRepeatedProbeMinPercentage / 100); | |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 // Detect a drop in estimated BW when operating in ALR and not already | 138 // Detect a drop in estimated BW when operating in ALR and not already |
139 // probing. The current response is to initiate a single probe session at the | 139 // probing. The current response is to initiate a single probe session at the |
140 // previous bitrate and immediately use the reported bitrate as the new | 140 // previous bitrate and immediately use the reported bitrate as the new |
141 // bitrate. | 141 // bitrate. |
142 // | 142 // |
143 // If the probe session fails, the assumption is that this drop was a | 143 // If the probe session fails, the assumption is that this drop was a |
144 // real one from a competing flow or something else on the network and | 144 // real one from a competing flow or something else on the network and |
145 // it ramps up from bitrate_bps. | 145 // it ramps up from bitrate_bps. |
146 if (state_ == State::kProbingComplete && | 146 if (state_ == State::kProbingComplete && |
147 pacer_->GetApplicationLimitedRegionStartTime() && | 147 pacer_->GetApplicationLimitedRegionStartTime() && |
148 bitrate_bps < estimated_bitrate_bps_ / 2 && | 148 bitrate_bps < estimated_bitrate_bps_ / 2 && |
149 (now_ms - last_alr_probing_time_) > kAlrProbingIntervalMinMs) { | 149 (now_ms - last_alr_probing_time_) > kAlrProbingIntervalMinMs) { |
150 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; | 150 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; |
151 // Track how often we probe in response to BW drop in ALR. | 151 // Track how often we probe in response to BW drop in ALR. |
152 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", | 152 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", |
153 (now_ms - last_alr_probing_time_) / 1000); | 153 (now_ms - last_alr_probing_time_) / 1000); |
154 InitiateProbing(now_ms, {estimated_bitrate_bps_}, | 154 InitiateProbing(now_ms, {estimated_bitrate_bps_}, false); |
155 kExponentialProbingDisabled); | |
156 last_alr_probing_time_ = now_ms; | 155 last_alr_probing_time_ = now_ms; |
157 | 156 |
158 // TODO(isheriff): May want to track when we did ALR probing in order | 157 // TODO(isheriff): May want to track when we did ALR probing in order |
159 // to reset |last_alr_probing_time_| if we validate that it was a | 158 // to reset |last_alr_probing_time_| if we validate that it was a |
160 // drop due to exogenous event. | 159 // drop due to exogenous event. |
161 } | 160 } |
162 | 161 |
163 estimated_bitrate_bps_ = bitrate_bps; | 162 estimated_bitrate_bps_ = bitrate_bps; |
164 } | 163 } |
165 | 164 |
(...skipping 19 matching lines...) Expand all Loading... | |
185 return; | 184 return; |
186 | 185 |
187 // Probe bandwidth periodically when in ALR state. | 186 // Probe bandwidth periodically when in ALR state. |
188 rtc::Optional<int64_t> alr_start_time = | 187 rtc::Optional<int64_t> alr_start_time = |
189 pacer_->GetApplicationLimitedRegionStartTime(); | 188 pacer_->GetApplicationLimitedRegionStartTime(); |
190 if (alr_start_time) { | 189 if (alr_start_time) { |
191 int64_t next_probe_time_ms = | 190 int64_t next_probe_time_ms = |
192 std::max(*alr_start_time, time_last_probing_initiated_ms_) + | 191 std::max(*alr_start_time, time_last_probing_initiated_ms_) + |
193 kAlrPeriodicProbingIntervalMs; | 192 kAlrPeriodicProbingIntervalMs; |
194 if (now_ms >= next_probe_time_ms) { | 193 if (now_ms >= next_probe_time_ms) { |
195 InitiateProbing( | 194 InitiateProbing(now_ms, {estimated_bitrate_bps_ * 2}, true); |
196 now_ms, {estimated_bitrate_bps_ * 2}, | |
197 estimated_bitrate_bps_ * kRepeatedProbeMinPercentage / 100); | |
198 } | 195 } |
199 } | 196 } |
200 } | 197 } |
201 | 198 |
202 void ProbeController::InitiateProbing( | 199 void ProbeController::InitiateProbing( |
203 int64_t now_ms, | 200 int64_t now_ms, |
204 std::initializer_list<int> bitrates_to_probe, | 201 std::initializer_list<int64_t> bitrates_to_probe, |
205 int min_bitrate_to_probe_further_bps) { | 202 bool probe_further) { |
206 bool first_cluster = true; | 203 bool first_cluster = true; |
207 for (int bitrate : bitrates_to_probe) { | 204 for (int64_t bitrate : bitrates_to_probe) { |
208 int max_probe_bitrate_bps = | 205 int max_probe_bitrate_bps = |
philipel
2016/12/14 09:43:10
int64_t
Sergey Ulanov
2016/12/14 22:41:26
Done.
| |
209 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; | 206 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; |
210 bitrate = std::min(bitrate, max_probe_bitrate_bps); | 207 if (bitrate > max_probe_bitrate_bps) { |
208 bitrate = max_probe_bitrate_bps; | |
209 probe_further = false; | |
210 } | |
211 if (first_cluster) { | 211 if (first_cluster) { |
212 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); | 212 pacer_->CreateProbeCluster(rtc::checked_cast<int>(bitrate), |
213 kProbeDeltasPerCluster + 1); | |
213 first_cluster = false; | 214 first_cluster = false; |
214 } else { | 215 } else { |
215 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); | 216 pacer_->CreateProbeCluster(rtc::checked_cast<int>(bitrate), |
217 kProbeDeltasPerCluster); | |
216 } | 218 } |
217 } | 219 } |
218 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | |
219 time_last_probing_initiated_ms_ = now_ms; | 220 time_last_probing_initiated_ms_ = now_ms; |
220 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) | 221 if (probe_further) { |
222 state_ = State::kWaitingForProbingResult; | |
223 min_bitrate_to_probe_further_bps_ = | |
224 (*(bitrates_to_probe.end() - 1)) * kRepeatedProbeMinPercentage / 100; | |
225 } else { | |
221 state_ = State::kProbingComplete; | 226 state_ = State::kProbingComplete; |
222 else | 227 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
223 state_ = State::kWaitingForProbingResult; | 228 } |
224 } | 229 } |
225 | 230 |
226 } // namespace webrtc | 231 } // namespace webrtc |
OLD | NEW |