| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 : clock_(clock), | 92 : clock_(clock), |
| 93 observer_(observer), | 93 observer_(observer), |
| 94 pacer_(pacer), | 94 pacer_(pacer), |
| 95 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), | 95 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), |
| 96 bandwidth_estimation_(), | 96 bandwidth_estimation_(), |
| 97 reserved_bitrate_bps_(0), | 97 reserved_bitrate_bps_(0), |
| 98 last_bitrate_bps_(0), | 98 last_bitrate_bps_(0), |
| 99 last_fraction_loss_(0), | 99 last_fraction_loss_(0), |
| 100 last_rtt_ms_(0), | 100 last_rtt_ms_(0), |
| 101 last_reserved_bitrate_bps_(0), | 101 last_reserved_bitrate_bps_(0), |
| 102 send_queue_full_(false) { | 102 send_queue_ready_(true) { |
| 103 RTC_DCHECK(observer_); | 103 RTC_DCHECK(observer_); |
| 104 RTC_DCHECK(pacer_); | 104 RTC_DCHECK(pacer_); |
| 105 // This calls the observer_, which means that the observer provided by the | 105 // This calls the observer_, which means that the observer provided by the |
| 106 // user must be ready to accept a bitrate update when it constructs the | 106 // user must be ready to accept a bitrate update when it constructs the |
| 107 // controller. We do this to avoid having to keep synchronized initial values | 107 // controller. We do this to avoid having to keep synchronized initial values |
| 108 // in both the controller and the allocator. | 108 // in both the controller and the allocator. |
| 109 MaybeTriggerOnNetworkChanged(); | 109 MaybeTriggerOnNetworkChanged(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { | 112 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { | 197 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { |
| 198 uint32_t bitrate_bps; | 198 uint32_t bitrate_bps; |
| 199 uint8_t fraction_loss; | 199 uint8_t fraction_loss; |
| 200 int64_t rtt; | 200 int64_t rtt; |
| 201 | 201 |
| 202 bool network_changed = | 202 bool network_changed = |
| 203 GetNetworkParameters(&bitrate_bps, &fraction_loss, &rtt); | 203 GetNetworkParameters(&bitrate_bps, &fraction_loss, &rtt); |
| 204 if (network_changed) { | 204 if (network_changed) { |
| 205 pacer_->SetNetWorkEstimateTargetBitrate(bitrate_bps); | 205 pacer_->SetNetWorkEstimateTargetBitrate(bitrate_bps); |
| 206 } | 206 } |
| 207 bool send_queue_full = | 207 bool send_queue_ready = pacer_->CanSendMorePackets(); |
| 208 pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | |
| 209 | 208 |
| 210 bitrate_bps = send_queue_full ? 0 : bitrate_bps; | 209 bitrate_bps = send_queue_ready ? bitrate_bps : 0; |
| 211 if (UpdateSendQueueStatus(send_queue_full) || | 210 if (UpdateSendQueueStatus(send_queue_ready) || |
| 212 (network_changed && !send_queue_full)) { | 211 (network_changed && send_queue_ready)) { |
| 213 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); | 212 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); |
| 214 return; | 213 return; |
| 215 } | 214 } |
| 216 } | 215 } |
| 217 | 216 |
| 218 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, | 217 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, |
| 219 uint8_t* fraction_loss, | 218 uint8_t* fraction_loss, |
| 220 int64_t* rtt) { | 219 int64_t* rtt) { |
| 221 rtc::CritScope cs(&critsect_); | 220 rtc::CritScope cs(&critsect_); |
| 222 int current_bitrate; | 221 int current_bitrate; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 233 last_bitrate_bps_ = *bitrate; | 232 last_bitrate_bps_ = *bitrate; |
| 234 last_fraction_loss_ = *fraction_loss; | 233 last_fraction_loss_ = *fraction_loss; |
| 235 last_rtt_ms_ = *rtt; | 234 last_rtt_ms_ = *rtt; |
| 236 last_reserved_bitrate_bps_ = reserved_bitrate_bps_; | 235 last_reserved_bitrate_bps_ = reserved_bitrate_bps_; |
| 237 new_bitrate = true; | 236 new_bitrate = true; |
| 238 } | 237 } |
| 239 | 238 |
| 240 return new_bitrate; | 239 return new_bitrate; |
| 241 } | 240 } |
| 242 | 241 |
| 243 bool BitrateControllerImpl::UpdateSendQueueStatus(bool is_full) { | 242 bool BitrateControllerImpl::UpdateSendQueueStatus(bool is_ready) { |
| 244 rtc::CritScope cs(&critsect_); | 243 rtc::CritScope cs(&critsect_); |
| 245 bool changed = is_full != send_queue_full_; | 244 bool changed = is_ready != send_queue_ready_; |
| 246 send_queue_full_ = is_full; | 245 send_queue_ready_ = is_ready; |
| 247 if (changed) { | 246 if (changed) { |
| 248 LOG(LS_INFO) << "Send queue status changed state. " | 247 LOG(LS_INFO) << "Send queue status changed state. " |
| 249 << " Queue is " << (changed ? "full" : "not full."); | 248 << " Queue is " |
| 249 << (send_queue_ready_ ? "ready." : " not ready."); |
| 250 } | 250 } |
| 251 return changed; | 251 return changed; |
| 252 } | 252 } |
| 253 | 253 |
| 254 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { | 254 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { |
| 255 rtc::CritScope cs(&critsect_); | 255 rtc::CritScope cs(&critsect_); |
| 256 int bitrate; | 256 int bitrate; |
| 257 uint8_t fraction_loss; | 257 uint8_t fraction_loss; |
| 258 int64_t rtt; | 258 int64_t rtt; |
| 259 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); | 259 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); |
| 260 if (bitrate > 0) { | 260 if (bitrate > 0) { |
| 261 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); | 261 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); |
| 262 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); | 262 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); |
| 263 *bandwidth = bitrate; | 263 *bandwidth = bitrate; |
| 264 return true; | 264 return true; |
| 265 } | 265 } |
| 266 return false; | 266 return false; |
| 267 } | 267 } |
| 268 } // namespace webrtc | 268 } // namespace webrtc |
| OLD | NEW |