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 |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // Value of |min_bitrate_to_probe_further_bps_| that indicates | 32 // Value of |min_bitrate_to_probe_further_bps_| that indicates |
33 // further probing is disabled. | 33 // further probing is disabled. |
34 constexpr int kExponentialProbingDisabled = 0; | 34 constexpr int kExponentialProbingDisabled = 0; |
35 | 35 |
36 // Default probing bitrate limit. Applied only when the application didn't | 36 // Default probing bitrate limit. Applied only when the application didn't |
37 // specify max bitrate. | 37 // specify max bitrate. |
38 constexpr int kDefaultMaxProbingBitrateBps = 100000000; | 38 constexpr int kDefaultMaxProbingBitrateBps = 100000000; |
39 | 39 |
40 // This is a limit on how often probing can be done when there is a BW | 40 // This is a limit on how often probing can be done when there is a BW |
41 // drop detected in ALR region. | 41 // drop detected in ALR. |
42 constexpr int kAlrProbingIntervalLimitMs = 5000; | 42 constexpr int64_t kAlrProbingIntervalMinMs = 5000; |
| 43 |
| 44 // Interval between probes when ALR periodic probing is enabled. |
| 45 constexpr int64_t kAlrPeriodicProbingIntervalMs = 5000; |
| 46 |
| 47 // Minimum probe bitrate percentage to probe further for repeated probes. |
| 48 constexpr int kRepeatedProbeMinPercentage = 125; |
43 | 49 |
44 } // namespace | 50 } // namespace |
45 | 51 |
46 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) | 52 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) |
47 : pacer_(pacer), | 53 : pacer_(pacer), |
48 clock_(clock), | 54 clock_(clock), |
49 network_state_(kNetworkUp), | 55 network_state_(kNetworkUp), |
50 state_(State::kInit), | 56 state_(State::kInit), |
51 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), | 57 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), |
52 time_last_probing_initiated_ms_(0), | 58 time_last_probing_initiated_ms_(0), |
53 estimated_bitrate_bps_(0), | 59 estimated_bitrate_bps_(0), |
54 start_bitrate_bps_(0), | 60 start_bitrate_bps_(0), |
55 max_bitrate_bps_(0), | 61 max_bitrate_bps_(0), |
56 last_alr_probing_time_(clock_->TimeInMilliseconds()) {} | 62 last_alr_probing_time_(clock_->TimeInMilliseconds()), |
| 63 enable_periodic_alr_probing_(false) {} |
57 | 64 |
58 void ProbeController::SetBitrates(int min_bitrate_bps, | 65 void ProbeController::SetBitrates(int min_bitrate_bps, |
59 int start_bitrate_bps, | 66 int start_bitrate_bps, |
60 int max_bitrate_bps) { | 67 int max_bitrate_bps) { |
61 rtc::CritScope cs(&critsect_); | 68 rtc::CritScope cs(&critsect_); |
62 | 69 |
63 if (start_bitrate_bps > 0) { | 70 if (start_bitrate_bps > 0) { |
64 start_bitrate_bps_ = start_bitrate_bps; | 71 start_bitrate_bps_ = start_bitrate_bps; |
65 } else if (start_bitrate_bps_ == 0) { | 72 } else if (start_bitrate_bps_ == 0) { |
66 start_bitrate_bps_ = min_bitrate_bps; | 73 start_bitrate_bps_ = min_bitrate_bps; |
67 } | 74 } |
68 | 75 |
69 int old_max_bitrate_bps = max_bitrate_bps_; | 76 int old_max_bitrate_bps = max_bitrate_bps_; |
70 max_bitrate_bps_ = max_bitrate_bps; | 77 max_bitrate_bps_ = max_bitrate_bps; |
71 | 78 |
72 switch (state_) { | 79 switch (state_) { |
73 case State::kInit: | 80 case State::kInit: |
74 if (network_state_ == kNetworkUp) | 81 if (network_state_ == kNetworkUp) |
75 InitiateExponentialProbing(); | 82 InitiateExponentialProbing(); |
76 break; | 83 break; |
77 | 84 |
78 case State::kWaitingForProbingResult: | 85 case State::kWaitingForProbingResult: |
79 break; | 86 break; |
80 | 87 |
81 case State::kProbingComplete: | 88 case State::kProbingComplete: |
82 // Initiate probing when |max_bitrate_| was increased mid-call. | 89 // Initiate probing when |max_bitrate_| was increased mid-call. |
83 if (estimated_bitrate_bps_ != 0 && | 90 if (estimated_bitrate_bps_ != 0 && |
84 estimated_bitrate_bps_ < old_max_bitrate_bps && | 91 estimated_bitrate_bps_ < old_max_bitrate_bps && |
85 max_bitrate_bps_ > old_max_bitrate_bps) { | 92 max_bitrate_bps_ > old_max_bitrate_bps) { |
86 InitiateProbing({max_bitrate_bps}, kExponentialProbingDisabled); | 93 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, |
| 94 kExponentialProbingDisabled); |
87 } | 95 } |
88 break; | 96 break; |
89 } | 97 } |
90 } | 98 } |
91 | 99 |
92 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { | 100 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { |
93 rtc::CritScope cs(&critsect_); | 101 rtc::CritScope cs(&critsect_); |
94 network_state_ = network_state; | 102 network_state_ = network_state; |
95 if (network_state_ == kNetworkUp && state_ == State::kInit) | 103 if (network_state_ == kNetworkUp && state_ == State::kInit) |
96 InitiateExponentialProbing(); | 104 InitiateExponentialProbing(); |
97 } | 105 } |
98 | 106 |
99 void ProbeController::InitiateExponentialProbing() { | 107 void ProbeController::InitiateExponentialProbing() { |
100 RTC_DCHECK(network_state_ == kNetworkUp); | 108 RTC_DCHECK(network_state_ == kNetworkUp); |
101 RTC_DCHECK(state_ == State::kInit); | 109 RTC_DCHECK(state_ == State::kInit); |
102 RTC_DCHECK_GT(start_bitrate_bps_, 0); | 110 RTC_DCHECK_GT(start_bitrate_bps_, 0); |
103 | 111 |
104 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 112 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
105 // 1.2 Mbps to continue probing. | 113 // 1.2 Mbps to continue probing. |
106 InitiateProbing({3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, | 114 InitiateProbing(clock_->TimeInMilliseconds(), |
| 115 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, |
107 4 * start_bitrate_bps_); | 116 4 * start_bitrate_bps_); |
108 } | 117 } |
109 | 118 |
110 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { | 119 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { |
111 rtc::CritScope cs(&critsect_); | 120 rtc::CritScope cs(&critsect_); |
| 121 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 122 |
112 if (state_ == State::kWaitingForProbingResult) { | 123 if (state_ == State::kWaitingForProbingResult) { |
113 if ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > | 124 if ((now_ms - time_last_probing_initiated_ms_) > |
114 kMaxWaitingTimeForProbingResultMs) { | 125 kMaxWaitingTimeForProbingResultMs) { |
115 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; | 126 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; |
116 state_ = State::kProbingComplete; | 127 state_ = State::kProbingComplete; |
117 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | 128 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
118 } else { | 129 } else { |
119 // Continue probing if probing results indicate channel has greater | 130 // Continue probing if probing results indicate channel has greater |
120 // capacity. | 131 // capacity. |
121 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps | 132 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps |
122 << " Minimum to probe further: " | 133 << " Minimum to probe further: " |
123 << min_bitrate_to_probe_further_bps_; | 134 << min_bitrate_to_probe_further_bps_; |
124 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && | 135 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && |
125 bitrate_bps > min_bitrate_to_probe_further_bps_) { | 136 bitrate_bps > min_bitrate_to_probe_further_bps_) { |
126 // Double the probing bitrate and expect a minimum of 25% gain to | 137 // Double the probing bitrate and expect a minimum of 25% gain to |
127 // continue probing. | 138 // continue probing. |
128 InitiateProbing({2 * bitrate_bps}, 1.25 * bitrate_bps); | 139 InitiateProbing(now_ms, {2 * bitrate_bps}, |
| 140 bitrate_bps * kRepeatedProbeMinPercentage / 100); |
| 141 } else { |
| 142 // Stop exponential probing. |
| 143 state_ = State::kProbingComplete; |
| 144 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
129 } | 145 } |
130 } | 146 } |
131 } else { | 147 } |
132 // A drop in estimated BW when operating in ALR and not already probing. | 148 |
133 // The current response is to initiate a single probe session at the | 149 // Detect a drop in estimated BW when operating in ALR and not already |
134 // previous bitrate and immediately use the reported bitrate as the new | 150 // probing. The current response is to initiate a single probe session at the |
135 // bitrate. | 151 // previous bitrate and immediately use the reported bitrate as the new |
136 // | 152 // bitrate. |
137 // If the probe session fails, the assumption is that this drop was a | 153 // |
138 // real one from a competing flow or something else on the network and | 154 // If the probe session fails, the assumption is that this drop was a |
139 // it ramps up from bitrate_bps. | 155 // real one from a competing flow or something else on the network and |
140 if (pacer_->InApplicationLimitedRegion() && | 156 // it ramps up from bitrate_bps. |
141 bitrate_bps < 0.5 * estimated_bitrate_bps_) { | 157 if (state_ == State::kProbingComplete && |
142 int64_t now_ms = clock_->TimeInMilliseconds(); | 158 pacer_->GetApplicationLimitedRegionStartTime() && |
143 if ((now_ms - last_alr_probing_time_) > kAlrProbingIntervalLimitMs) { | 159 bitrate_bps < estimated_bitrate_bps_ / 2 && |
144 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; | 160 (now_ms - last_alr_probing_time_) > kAlrProbingIntervalMinMs) { |
145 // Track how often we probe in response to BW drop in ALR. | 161 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; |
146 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", | 162 // Track how often we probe in response to BW drop in ALR. |
147 (now_ms - last_alr_probing_time_) / 1000); | 163 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", |
148 InitiateProbing({estimated_bitrate_bps_}, kExponentialProbingDisabled); | 164 (now_ms - last_alr_probing_time_) / 1000); |
149 last_alr_probing_time_ = now_ms; | 165 InitiateProbing(now_ms, {estimated_bitrate_bps_}, |
150 } | 166 kExponentialProbingDisabled); |
151 } | 167 last_alr_probing_time_ = now_ms; |
| 168 |
152 // TODO(isheriff): May want to track when we did ALR probing in order | 169 // TODO(isheriff): May want to track when we did ALR probing in order |
153 // to reset |last_alr_probing_time_| if we validate that it was a | 170 // to reset |last_alr_probing_time_| if we validate that it was a |
154 // drop due to exogenous event. | 171 // drop due to exogenous event. |
155 } | 172 } |
| 173 |
156 estimated_bitrate_bps_ = bitrate_bps; | 174 estimated_bitrate_bps_ = bitrate_bps; |
157 } | 175 } |
158 | 176 |
| 177 void ProbeController::EnablePeriodicAlrProbing(bool enable) { |
| 178 rtc::CritScope cs(&critsect_); |
| 179 enable_periodic_alr_probing_ = enable; |
| 180 } |
| 181 |
| 182 void ProbeController::Process() { |
| 183 rtc::CritScope cs(&critsect_); |
| 184 |
| 185 if (state_ != State::kProbingComplete || !enable_periodic_alr_probing_) |
| 186 return; |
| 187 |
| 188 // Probe bandwidth periodically when in ALR state. |
| 189 rtc::Optional<int64_t> alr_start_time = |
| 190 pacer_->GetApplicationLimitedRegionStartTime(); |
| 191 if (alr_start_time) { |
| 192 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 193 int64_t next_probe_time_ms = |
| 194 std::max(*alr_start_time, time_last_probing_initiated_ms_) + |
| 195 kAlrPeriodicProbingIntervalMs; |
| 196 if (now_ms >= next_probe_time_ms) { |
| 197 InitiateProbing( |
| 198 now_ms, {estimated_bitrate_bps_ * 2}, |
| 199 estimated_bitrate_bps_ * kRepeatedProbeMinPercentage / 100); |
| 200 } |
| 201 } |
| 202 } |
| 203 |
159 void ProbeController::InitiateProbing( | 204 void ProbeController::InitiateProbing( |
| 205 int64_t now_ms, |
160 std::initializer_list<int> bitrates_to_probe, | 206 std::initializer_list<int> bitrates_to_probe, |
161 int min_bitrate_to_probe_further_bps) { | 207 int min_bitrate_to_probe_further_bps) { |
162 bool first_cluster = true; | 208 bool first_cluster = true; |
163 for (int bitrate : bitrates_to_probe) { | 209 for (int bitrate : bitrates_to_probe) { |
164 int max_probe_bitrate_bps = | 210 int max_probe_bitrate_bps = |
165 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; | 211 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; |
166 bitrate = std::min(bitrate, max_probe_bitrate_bps); | 212 bitrate = std::min(bitrate, max_probe_bitrate_bps); |
167 if (first_cluster) { | 213 if (first_cluster) { |
168 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); | 214 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); |
169 first_cluster = false; | 215 first_cluster = false; |
170 } else { | 216 } else { |
171 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); | 217 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); |
172 } | 218 } |
173 } | 219 } |
174 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | 220 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; |
175 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); | 221 time_last_probing_initiated_ms_ = now_ms; |
176 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) | 222 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) |
177 state_ = State::kProbingComplete; | 223 state_ = State::kProbingComplete; |
178 else | 224 else |
179 state_ = State::kWaitingForProbingResult; | 225 state_ = State::kWaitingForProbingResult; |
180 } | 226 } |
181 | 227 |
182 } // namespace webrtc | 228 } // namespace webrtc |
OLD | NEW |