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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" | 26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" |
27 #include "webrtc/modules/utility/include/process_thread.h" | 27 #include "webrtc/modules/utility/include/process_thread.h" |
28 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 28 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
29 #include "webrtc/video/payload_router.h" | 29 #include "webrtc/video/payload_router.h" |
30 | 30 |
31 namespace webrtc { | 31 namespace webrtc { |
32 namespace { | 32 namespace { |
33 | 33 |
34 static const uint32_t kTimeOffsetSwitchThreshold = 30; | 34 static const uint32_t kTimeOffsetSwitchThreshold = 30; |
35 | 35 |
36 // Makes sure that the bitrate and the min, max values are in valid range. | |
37 static void ClampBitrates(int* bitrate_bps, | |
38 int* min_bitrate_bps, | |
39 int* max_bitrate_bps) { | |
40 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, | |
41 // and that we don't try to set the min bitrate to 0 from any applications. | |
42 // The congestion controller should allow a min bitrate of 0. | |
43 const int kMinBitrateBps = 10000; | |
44 if (*min_bitrate_bps < kMinBitrateBps) | |
45 *min_bitrate_bps = kMinBitrateBps; | |
46 if (*max_bitrate_bps > 0) | |
47 *max_bitrate_bps = std::max(*min_bitrate_bps, *max_bitrate_bps); | |
48 if (*bitrate_bps > 0) | |
49 *bitrate_bps = std::max(*min_bitrate_bps, *bitrate_bps); | |
50 } | |
51 | |
52 class WrappingBitrateEstimator : public RemoteBitrateEstimator { | 36 class WrappingBitrateEstimator : public RemoteBitrateEstimator { |
53 public: | 37 public: |
54 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock) | 38 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock) |
55 : observer_(observer), | 39 : observer_(observer), |
56 clock_(clock), | 40 clock_(clock), |
57 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 41 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
58 rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)), | 42 rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)), |
59 using_absolute_send_time_(false), | 43 using_absolute_send_time_(false), |
60 packets_since_absolute_send_time_(0), | 44 packets_since_absolute_send_time_(0), |
61 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {} | 45 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {} |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 205 |
222 CongestionController::~CongestionController() {} | 206 CongestionController::~CongestionController() {} |
223 | 207 |
224 void CongestionController::Init() { | 208 void CongestionController::Init() { |
225 transport_feedback_adapter_.SetBitrateEstimator( | 209 transport_feedback_adapter_.SetBitrateEstimator( |
226 new DelayBasedBwe(&transport_feedback_adapter_)); | 210 new DelayBasedBwe(&transport_feedback_adapter_)); |
227 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( | 211 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( |
228 min_bitrate_bps_); | 212 min_bitrate_bps_); |
229 } | 213 } |
230 | 214 |
| 215 |
231 void CongestionController::SetBweBitrates(int min_bitrate_bps, | 216 void CongestionController::SetBweBitrates(int min_bitrate_bps, |
232 int start_bitrate_bps, | 217 int start_bitrate_bps, |
233 int max_bitrate_bps) { | 218 int max_bitrate_bps) { |
234 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); | 219 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, |
| 220 // and that we don't try to set the min bitrate to 0 from any applications. |
| 221 // The congestion controller should allow a min bitrate of 0. |
| 222 const int kMinBitrateBps = 10000; |
| 223 if (min_bitrate_bps < kMinBitrateBps) |
| 224 min_bitrate_bps = kMinBitrateBps; |
| 225 if (max_bitrate_bps > 0) |
| 226 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps); |
| 227 if (start_bitrate_bps > 0) |
| 228 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps); |
| 229 |
235 bitrate_controller_->SetBitrates(start_bitrate_bps, | 230 bitrate_controller_->SetBitrates(start_bitrate_bps, |
236 min_bitrate_bps, | 231 min_bitrate_bps, |
237 max_bitrate_bps); | 232 max_bitrate_bps); |
238 | 233 |
239 if (remote_bitrate_estimator_) | 234 if (remote_bitrate_estimator_) |
240 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); | 235 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); |
241 min_bitrate_bps_ = min_bitrate_bps; | 236 min_bitrate_bps_ = min_bitrate_bps; |
242 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( | 237 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( |
243 min_bitrate_bps_); | 238 min_bitrate_bps_); |
244 MaybeTriggerOnNetworkChanged(); | 239 MaybeTriggerOnNetworkChanged(); |
245 } | 240 } |
246 | 241 |
247 void CongestionController::ResetBweAndBitrates(int bitrate_bps, | |
248 int min_bitrate_bps, | |
249 int max_bitrate_bps) { | |
250 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); | |
251 // TODO(honghaiz): Recreate this object once the bitrate controller is | |
252 // no longer exposed outside CongestionController. | |
253 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps, | |
254 max_bitrate_bps); | |
255 min_bitrate_bps_ = min_bitrate_bps; | |
256 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is | |
257 // no longer exposed outside CongestionController. | |
258 if (remote_bitrate_estimator_) | |
259 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); | |
260 | |
261 RemoteBitrateEstimator* rbe = | |
262 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_); | |
263 transport_feedback_adapter_.SetBitrateEstimator(rbe); | |
264 rbe->SetMinBitrate(min_bitrate_bps); | |
265 // TODO(holmer): Trigger a new probe once mid-call probing is implemented. | |
266 MaybeTriggerOnNetworkChanged(); | |
267 } | |
268 | |
269 BitrateController* CongestionController::GetBitrateController() const { | 242 BitrateController* CongestionController::GetBitrateController() const { |
270 return bitrate_controller_.get(); | 243 return bitrate_controller_.get(); |
271 } | 244 } |
272 | 245 |
273 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( | 246 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( |
274 bool send_side_bwe) { | 247 bool send_side_bwe) { |
275 if (send_side_bwe) { | 248 if (send_side_bwe) { |
276 return &remote_estimator_proxy_; | 249 return &remote_estimator_proxy_; |
277 } else { | 250 } else { |
278 return remote_bitrate_estimator_.get(); | 251 return remote_bitrate_estimator_.get(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 bool CongestionController::IsSendQueueFull() const { | 340 bool CongestionController::IsSendQueueFull() const { |
368 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | 341 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; |
369 } | 342 } |
370 | 343 |
371 bool CongestionController::IsNetworkDown() const { | 344 bool CongestionController::IsNetworkDown() const { |
372 rtc::CritScope cs(&critsect_); | 345 rtc::CritScope cs(&critsect_); |
373 return network_state_ == kNetworkDown; | 346 return network_state_ == kNetworkDown; |
374 } | 347 } |
375 | 348 |
376 } // namespace webrtc | 349 } // namespace webrtc |
OLD | NEW |