OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/include/congestion_controller.h" | 11 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <memory> | 14 #include <memory> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/rate_limiter.h" | 20 #include "webrtc/base/rate_limiter.h" |
21 #include "webrtc/base/socket.h" | 21 #include "webrtc/base/socket.h" |
22 #include "webrtc/base/thread_annotations.h" | 22 #include "webrtc/base/thread_annotations.h" |
23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
24 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | 24 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
| 25 #include "webrtc/modules/congestion_controller/probe_controller.h" |
25 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" | 26 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" |
26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s
end_time.h" | 27 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s
end_time.h" |
27 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" | 28 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" |
28 #include "webrtc/modules/utility/include/process_thread.h" | 29 #include "webrtc/modules/utility/include/process_thread.h" |
29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 30 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
30 #include "webrtc/video/payload_router.h" | 31 #include "webrtc/video/payload_router.h" |
31 | 32 |
32 namespace webrtc { | 33 namespace webrtc { |
33 namespace { | 34 namespace { |
34 | 35 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 RemoteBitrateObserver* remote_bitrate_observer, | 160 RemoteBitrateObserver* remote_bitrate_observer, |
160 RtcEventLog* event_log) | 161 RtcEventLog* event_log) |
161 : clock_(clock), | 162 : clock_(clock), |
162 observer_(observer), | 163 observer_(observer), |
163 packet_router_(new PacketRouter()), | 164 packet_router_(new PacketRouter()), |
164 pacer_(new PacedSender(clock_, packet_router_.get())), | 165 pacer_(new PacedSender(clock_, packet_router_.get())), |
165 remote_bitrate_estimator_( | 166 remote_bitrate_estimator_( |
166 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 167 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
167 bitrate_controller_( | 168 bitrate_controller_( |
168 BitrateController::CreateBitrateController(clock_, event_log)), | 169 BitrateController::CreateBitrateController(clock_, event_log)), |
| 170 probe_controller_(new ProbeController(pacer_.get(), clock_)), |
169 retransmission_rate_limiter_( | 171 retransmission_rate_limiter_( |
170 new RateLimiter(clock, kRetransmitWindowSizeMs)), | 172 new RateLimiter(clock, kRetransmitWindowSizeMs)), |
171 remote_estimator_proxy_(clock_, packet_router_.get()), | 173 remote_estimator_proxy_(clock_, packet_router_.get()), |
172 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 174 transport_feedback_adapter_(clock_), |
173 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 175 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
174 max_bitrate_bps_(0), | 176 max_bitrate_bps_(0), |
175 initial_probing_triggered_(false), | |
176 last_reported_bitrate_bps_(0), | 177 last_reported_bitrate_bps_(0), |
177 last_reported_fraction_loss_(0), | 178 last_reported_fraction_loss_(0), |
178 last_reported_rtt_(0), | 179 last_reported_rtt_(0), |
179 network_state_(kNetworkUp) { | 180 network_state_(kNetworkUp) { |
180 Init(); | 181 Init(); |
181 } | 182 } |
182 | 183 |
183 CongestionController::CongestionController( | 184 CongestionController::CongestionController( |
184 Clock* clock, | 185 Clock* clock, |
185 Observer* observer, | 186 Observer* observer, |
186 RemoteBitrateObserver* remote_bitrate_observer, | 187 RemoteBitrateObserver* remote_bitrate_observer, |
187 RtcEventLog* event_log, | 188 RtcEventLog* event_log, |
188 std::unique_ptr<PacketRouter> packet_router, | 189 std::unique_ptr<PacketRouter> packet_router, |
189 std::unique_ptr<PacedSender> pacer) | 190 std::unique_ptr<PacedSender> pacer) |
190 : clock_(clock), | 191 : clock_(clock), |
191 observer_(observer), | 192 observer_(observer), |
192 packet_router_(std::move(packet_router)), | 193 packet_router_(std::move(packet_router)), |
193 pacer_(std::move(pacer)), | 194 pacer_(std::move(pacer)), |
194 remote_bitrate_estimator_( | 195 remote_bitrate_estimator_( |
195 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 196 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
196 // Constructed last as this object calls the provided callback on | 197 // Constructed last as this object calls the provided callback on |
197 // construction. | 198 // construction. |
198 bitrate_controller_( | 199 bitrate_controller_( |
199 BitrateController::CreateBitrateController(clock_, event_log)), | 200 BitrateController::CreateBitrateController(clock_, event_log)), |
| 201 probe_controller_(new ProbeController(pacer_.get(), clock_)), |
200 retransmission_rate_limiter_( | 202 retransmission_rate_limiter_( |
201 new RateLimiter(clock, kRetransmitWindowSizeMs)), | 203 new RateLimiter(clock, kRetransmitWindowSizeMs)), |
202 remote_estimator_proxy_(clock_, packet_router_.get()), | 204 remote_estimator_proxy_(clock_, packet_router_.get()), |
203 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 205 transport_feedback_adapter_(clock_), |
204 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 206 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
205 max_bitrate_bps_(0), | 207 max_bitrate_bps_(0), |
206 initial_probing_triggered_(false), | |
207 last_reported_bitrate_bps_(0), | 208 last_reported_bitrate_bps_(0), |
208 last_reported_fraction_loss_(0), | 209 last_reported_fraction_loss_(0), |
209 last_reported_rtt_(0), | 210 last_reported_rtt_(0), |
210 network_state_(kNetworkUp) { | 211 network_state_(kNetworkUp) { |
211 Init(); | 212 Init(); |
212 } | 213 } |
213 | 214 |
214 CongestionController::~CongestionController() {} | 215 CongestionController::~CongestionController() {} |
215 | 216 |
216 void CongestionController::Init() { | 217 void CongestionController::Init() { |
217 transport_feedback_adapter_.SetBitrateEstimator( | 218 transport_feedback_adapter_.SetBitrateEstimator( |
218 new DelayBasedBwe(&transport_feedback_adapter_, clock_)); | 219 new DelayBasedBwe(bitrate_controller_.get(), clock_)); |
219 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( | 220 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( |
220 min_bitrate_bps_); | 221 min_bitrate_bps_); |
221 } | 222 } |
222 | 223 |
223 void CongestionController::SetBweBitrates(int min_bitrate_bps, | 224 void CongestionController::SetBweBitrates(int min_bitrate_bps, |
224 int start_bitrate_bps, | 225 int start_bitrate_bps, |
225 int max_bitrate_bps) { | 226 int max_bitrate_bps) { |
226 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); | 227 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); |
227 bitrate_controller_->SetBitrates(start_bitrate_bps, | 228 bitrate_controller_->SetBitrates(start_bitrate_bps, |
228 min_bitrate_bps, | 229 min_bitrate_bps, |
229 max_bitrate_bps); | 230 max_bitrate_bps); |
230 | 231 |
231 { | 232 probe_controller_->SetBitrates(min_bitrate_bps, start_bitrate_bps, |
232 rtc::CritScope cs(&critsect_); | 233 max_bitrate_bps); |
233 if (!initial_probing_triggered_) { | |
234 pacer_->CreateProbeCluster(start_bitrate_bps * 3, 6); | |
235 pacer_->CreateProbeCluster(start_bitrate_bps * 6, 5); | |
236 initial_probing_triggered_ = true; | |
237 } | |
238 | |
239 // Only do probing if: | |
240 // - we are mid-call, which we consider to be if | |
241 // |last_reported_bitrate_bps_| != 0, and | |
242 // - the current bitrate is lower than the new |max_bitrate_bps|, and | |
243 // - we actually want to increase the |max_bitrate_bps_|. | |
244 if (last_reported_bitrate_bps_ != 0 && | |
245 last_reported_bitrate_bps_ < static_cast<uint32_t>(max_bitrate_bps) && | |
246 max_bitrate_bps > max_bitrate_bps_) { | |
247 pacer_->CreateProbeCluster(max_bitrate_bps, 5); | |
248 } | |
249 } | |
250 max_bitrate_bps_ = max_bitrate_bps; | 234 max_bitrate_bps_ = max_bitrate_bps; |
251 | 235 |
252 if (remote_bitrate_estimator_) | 236 if (remote_bitrate_estimator_) |
253 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); | 237 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); |
254 min_bitrate_bps_ = min_bitrate_bps; | 238 min_bitrate_bps_ = min_bitrate_bps; |
255 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( | 239 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( |
256 min_bitrate_bps_); | 240 min_bitrate_bps_); |
257 MaybeTriggerOnNetworkChanged(); | 241 MaybeTriggerOnNetworkChanged(); |
258 } | 242 } |
259 | 243 |
260 void CongestionController::ResetBweAndBitrates(int bitrate_bps, | 244 void CongestionController::ResetBweAndBitrates(int bitrate_bps, |
261 int min_bitrate_bps, | 245 int min_bitrate_bps, |
262 int max_bitrate_bps) { | 246 int max_bitrate_bps) { |
263 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); | 247 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); |
264 // TODO(honghaiz): Recreate this object once the bitrate controller is | 248 // TODO(honghaiz): Recreate this object once the bitrate controller is |
265 // no longer exposed outside CongestionController. | 249 // no longer exposed outside CongestionController. |
266 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps, | 250 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps, |
267 max_bitrate_bps); | 251 max_bitrate_bps); |
268 min_bitrate_bps_ = min_bitrate_bps; | 252 min_bitrate_bps_ = min_bitrate_bps; |
269 max_bitrate_bps_ = max_bitrate_bps; | 253 max_bitrate_bps_ = max_bitrate_bps; |
270 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is | 254 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is |
271 // no longer exposed outside CongestionController. | 255 // no longer exposed outside CongestionController. |
272 if (remote_bitrate_estimator_) | 256 if (remote_bitrate_estimator_) |
273 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); | 257 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); |
274 | 258 |
275 RemoteBitrateEstimator* rbe = new DelayBasedBwe( | 259 RemoteBitrateEstimator* rbe = |
276 &transport_feedback_adapter_, clock_); | 260 new DelayBasedBwe(bitrate_controller_.get(), clock_); |
277 transport_feedback_adapter_.SetBitrateEstimator(rbe); | 261 transport_feedback_adapter_.SetBitrateEstimator(rbe); |
278 rbe->SetMinBitrate(min_bitrate_bps); | 262 rbe->SetMinBitrate(min_bitrate_bps); |
279 // TODO(holmer): Trigger a new probe once mid-call probing is implemented. | 263 // TODO(holmer): Trigger a new probe once mid-call probing is implemented. |
280 MaybeTriggerOnNetworkChanged(); | 264 MaybeTriggerOnNetworkChanged(); |
281 } | 265 } |
282 | 266 |
283 BitrateController* CongestionController::GetBitrateController() const { | 267 BitrateController* CongestionController::GetBitrateController() const { |
284 return bitrate_controller_.get(); | 268 return bitrate_controller_.get(); |
285 } | 269 } |
286 | 270 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 if (!observer_) | 338 if (!observer_) |
355 return; | 339 return; |
356 | 340 |
357 uint32_t bitrate_bps; | 341 uint32_t bitrate_bps; |
358 uint8_t fraction_loss; | 342 uint8_t fraction_loss; |
359 int64_t rtt; | 343 int64_t rtt; |
360 bool estimate_changed = bitrate_controller_->GetNetworkParameters( | 344 bool estimate_changed = bitrate_controller_->GetNetworkParameters( |
361 &bitrate_bps, &fraction_loss, &rtt); | 345 &bitrate_bps, &fraction_loss, &rtt); |
362 if (estimate_changed) { | 346 if (estimate_changed) { |
363 pacer_->SetEstimatedBitrate(bitrate_bps); | 347 pacer_->SetEstimatedBitrate(bitrate_bps); |
| 348 probe_controller_->SetEstimatedBitrate(bitrate_bps); |
364 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); | 349 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); |
365 } | 350 } |
366 | 351 |
367 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; | 352 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; |
368 | 353 |
369 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { | 354 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { |
370 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); | 355 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); |
371 } | 356 } |
372 } | 357 } |
373 | 358 |
(...skipping 19 matching lines...) Expand all Loading... |
393 bool CongestionController::IsSendQueueFull() const { | 378 bool CongestionController::IsSendQueueFull() const { |
394 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | 379 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; |
395 } | 380 } |
396 | 381 |
397 bool CongestionController::IsNetworkDown() const { | 382 bool CongestionController::IsNetworkDown() const { |
398 rtc::CritScope cs(&critsect_); | 383 rtc::CritScope cs(&critsect_); |
399 return network_state_ == kNetworkDown; | 384 return network_state_ == kNetworkDown; |
400 } | 385 } |
401 | 386 |
402 } // namespace webrtc | 387 } // namespace webrtc |
OLD | NEW |