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/networkroute.h" |
20 #include "webrtc/base/rate_limiter.h" | 21 #include "webrtc/base/rate_limiter.h" |
21 #include "webrtc/base/socket.h" | 22 #include "webrtc/base/socket.h" |
22 #include "webrtc/base/thread_annotations.h" | 23 #include "webrtc/base/thread_annotations.h" |
23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 24 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
24 #include "webrtc/modules/congestion_controller/probe_controller.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" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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)), |
169 probe_controller_(new ProbeController(pacer_.get(), clock_)), | 170 probe_controller_(new ProbeController(pacer_.get(), clock_)), |
170 retransmission_rate_limiter_( | 171 retransmission_rate_limiter_( |
171 new RateLimiter(clock, kRetransmitWindowSizeMs)), | 172 new RateLimiter(clock, kRetransmitWindowSizeMs)), |
172 remote_estimator_proxy_(clock_, packet_router_.get()), | 173 remote_estimator_proxy_(clock_, packet_router_.get()), |
173 transport_feedback_adapter_(clock_, bitrate_controller_.get()), | 174 transport_feedback_adapter_(clock_, bitrate_controller_.get()), |
| 175 start_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
174 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 176 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
175 max_bitrate_bps_(0), | 177 max_bitrate_bps_(0), |
176 last_reported_bitrate_bps_(0), | 178 last_reported_bitrate_bps_(0), |
177 last_reported_fraction_loss_(0), | 179 last_reported_fraction_loss_(0), |
178 last_reported_rtt_(0), | 180 last_reported_rtt_(0), |
179 network_state_(kNetworkUp) { | 181 network_state_(kNetworkDown) { |
180 Init(); | 182 Init(); |
181 } | 183 } |
182 | 184 |
183 CongestionController::CongestionController( | 185 CongestionController::CongestionController( |
184 Clock* clock, | 186 Clock* clock, |
185 Observer* observer, | 187 Observer* observer, |
186 RemoteBitrateObserver* remote_bitrate_observer, | 188 RemoteBitrateObserver* remote_bitrate_observer, |
187 RtcEventLog* event_log, | 189 RtcEventLog* event_log, |
188 std::unique_ptr<PacketRouter> packet_router, | 190 std::unique_ptr<PacketRouter> packet_router, |
189 std::unique_ptr<PacedSender> pacer) | 191 std::unique_ptr<PacedSender> pacer) |
190 : clock_(clock), | 192 : clock_(clock), |
191 observer_(observer), | 193 observer_(observer), |
192 packet_router_(std::move(packet_router)), | 194 packet_router_(std::move(packet_router)), |
193 pacer_(std::move(pacer)), | 195 pacer_(std::move(pacer)), |
194 remote_bitrate_estimator_( | 196 remote_bitrate_estimator_( |
195 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 197 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
196 // Constructed last as this object calls the provided callback on | 198 // Constructed last as this object calls the provided callback on |
197 // construction. | 199 // construction. |
198 bitrate_controller_( | 200 bitrate_controller_( |
199 BitrateController::CreateBitrateController(clock_, event_log)), | 201 BitrateController::CreateBitrateController(clock_, event_log)), |
200 probe_controller_(new ProbeController(pacer_.get(), clock_)), | 202 probe_controller_(new ProbeController(pacer_.get(), clock_)), |
201 retransmission_rate_limiter_( | 203 retransmission_rate_limiter_( |
202 new RateLimiter(clock, kRetransmitWindowSizeMs)), | 204 new RateLimiter(clock, kRetransmitWindowSizeMs)), |
203 remote_estimator_proxy_(clock_, packet_router_.get()), | 205 remote_estimator_proxy_(clock_, packet_router_.get()), |
204 transport_feedback_adapter_(clock_, bitrate_controller_.get()), | 206 transport_feedback_adapter_(clock_, bitrate_controller_.get()), |
| 207 start_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
205 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 208 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
206 max_bitrate_bps_(0), | 209 max_bitrate_bps_(0), |
207 last_reported_bitrate_bps_(0), | 210 last_reported_bitrate_bps_(0), |
208 last_reported_fraction_loss_(0), | 211 last_reported_fraction_loss_(0), |
209 last_reported_rtt_(0), | 212 last_reported_rtt_(0), |
210 network_state_(kNetworkUp) { | 213 network_state_(kNetworkDown) { |
211 Init(); | 214 Init(); |
212 } | 215 } |
213 | 216 |
214 CongestionController::~CongestionController() {} | 217 CongestionController::~CongestionController() {} |
215 | 218 |
216 void CongestionController::Init() { | 219 void CongestionController::Init() { |
217 transport_feedback_adapter_.InitBwe(); | 220 transport_feedback_adapter_.InitBwe(); |
218 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_); | 221 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_); |
219 } | 222 } |
220 | 223 |
221 void CongestionController::SetBweBitrates(int min_bitrate_bps, | 224 void CongestionController::SetBweBitrates(int start_bitrate_bps, |
222 int start_bitrate_bps, | 225 int min_bitrate_bps, |
223 int max_bitrate_bps) { | 226 int max_bitrate_bps) { |
224 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); | 227 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); |
225 bitrate_controller_->SetBitrates(start_bitrate_bps, | 228 bitrate_controller_->SetBitrates(start_bitrate_bps, min_bitrate_bps, |
226 min_bitrate_bps, | |
227 max_bitrate_bps); | 229 max_bitrate_bps); |
228 | 230 |
229 probe_controller_->SetBitrates(min_bitrate_bps, start_bitrate_bps, | 231 probe_controller_->SetBitrates(start_bitrate_bps, min_bitrate_bps, |
230 max_bitrate_bps); | 232 max_bitrate_bps); |
| 233 |
| 234 start_bitrate_bps_ = start_bitrate_bps; |
| 235 min_bitrate_bps_ = min_bitrate_bps; |
231 max_bitrate_bps_ = max_bitrate_bps; | 236 max_bitrate_bps_ = max_bitrate_bps; |
232 | 237 |
233 if (remote_bitrate_estimator_) | 238 if (remote_bitrate_estimator_) |
234 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); | 239 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps_); |
235 min_bitrate_bps_ = min_bitrate_bps; | |
236 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_); | 240 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_); |
237 MaybeTriggerOnNetworkChanged(); | 241 MaybeTriggerOnNetworkChanged(); |
238 } | 242 } |
239 | 243 |
240 void CongestionController::ResetBweAndBitrates(int bitrate_bps, | 244 void CongestionController::OnNetworkRouteChanged( |
241 int min_bitrate_bps, | 245 const rtc::NetworkRoute& route) { |
242 int max_bitrate_bps) { | 246 LOG(LS_INFO) << "OnNetworkRouteChanged, " << (route.connected ? "" : "not ") |
243 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); | 247 << "connected."; |
| 248 |
| 249 if (route.connected) { |
| 250 pacer_->Resume(); |
| 251 } else { |
| 252 pacer_->Pause(); |
| 253 } |
| 254 { |
| 255 rtc::CritScope cs(&critsect_); |
| 256 network_state_ = route.connected ? kNetworkUp : kNetworkDown; |
| 257 } |
| 258 |
244 // TODO(honghaiz): Recreate this object once the bitrate controller is | 259 // TODO(honghaiz): Recreate this object once the bitrate controller is |
245 // no longer exposed outside CongestionController. | 260 // no longer exposed outside CongestionController. |
246 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps, | 261 bitrate_controller_->ResetBitrates(start_bitrate_bps_, min_bitrate_bps_, |
247 max_bitrate_bps); | 262 max_bitrate_bps_); |
248 min_bitrate_bps_ = min_bitrate_bps; | 263 |
249 max_bitrate_bps_ = max_bitrate_bps; | 264 // TODO(honghaiz): Recreate |remote_bitrate_estimator_| once the remote |
250 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is | 265 // bitrate estimator is no longer exposed outside CongestionController. |
251 // no longer exposed outside CongestionController. | |
252 if (remote_bitrate_estimator_) | |
253 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); | |
254 | 266 |
255 transport_feedback_adapter_.InitBwe(); | 267 transport_feedback_adapter_.InitBwe(); |
256 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps); | 268 |
| 269 probe_controller_->OnNetworkRouteChanged(route); |
| 270 |
257 // TODO(holmer): Trigger a new probe once mid-call probing is implemented. | 271 // TODO(holmer): Trigger a new probe once mid-call probing is implemented. |
258 MaybeTriggerOnNetworkChanged(); | 272 MaybeTriggerOnNetworkChanged(); |
259 } | 273 } |
260 | 274 |
261 BitrateController* CongestionController::GetBitrateController() const { | 275 BitrateController* CongestionController::GetBitrateController() const { |
262 return bitrate_controller_.get(); | 276 return bitrate_controller_.get(); |
263 } | 277 } |
264 | 278 |
265 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( | 279 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( |
266 bool send_side_bwe) { | 280 bool send_side_bwe) { |
(...skipping 16 matching lines...) Expand all Loading... |
283 void CongestionController::SetAllocatedSendBitrateLimits( | 297 void CongestionController::SetAllocatedSendBitrateLimits( |
284 int min_send_bitrate_bps, | 298 int min_send_bitrate_bps, |
285 int max_padding_bitrate_bps) { | 299 int max_padding_bitrate_bps) { |
286 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps); | 300 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps); |
287 } | 301 } |
288 | 302 |
289 int64_t CongestionController::GetPacerQueuingDelayMs() const { | 303 int64_t CongestionController::GetPacerQueuingDelayMs() const { |
290 return IsNetworkDown() ? 0 : pacer_->QueueInMs(); | 304 return IsNetworkDown() ? 0 : pacer_->QueueInMs(); |
291 } | 305 } |
292 | 306 |
293 void CongestionController::SignalNetworkState(NetworkState state) { | |
294 LOG(LS_INFO) << "SignalNetworkState " | |
295 << (state == kNetworkUp ? "Up" : "Down"); | |
296 if (state == kNetworkUp) { | |
297 pacer_->Resume(); | |
298 } else { | |
299 pacer_->Pause(); | |
300 } | |
301 { | |
302 rtc::CritScope cs(&critsect_); | |
303 network_state_ = state; | |
304 } | |
305 MaybeTriggerOnNetworkChanged(); | |
306 } | |
307 | |
308 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { | 307 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { |
309 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, | 308 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, |
310 sent_packet.send_time_ms); | 309 sent_packet.send_time_ms); |
311 } | 310 } |
312 | 311 |
313 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 312 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
314 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 313 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
315 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 314 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
316 } | 315 } |
317 | 316 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 bool CongestionController::IsSendQueueFull() const { | 371 bool CongestionController::IsSendQueueFull() const { |
373 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | 372 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; |
374 } | 373 } |
375 | 374 |
376 bool CongestionController::IsNetworkDown() const { | 375 bool CongestionController::IsNetworkDown() const { |
377 rtc::CritScope cs(&critsect_); | 376 rtc::CritScope cs(&critsect_); |
378 return network_state_ == kNetworkDown; | 377 return network_state_ == kNetworkDown; |
379 } | 378 } |
380 | 379 |
381 } // namespace webrtc | 380 } // namespace webrtc |
OLD | NEW |