| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 } // namespace | 136 } // namespace |
| 137 | 137 |
| 138 CongestionController::CongestionController( | 138 CongestionController::CongestionController( |
| 139 Clock* clock, | 139 Clock* clock, |
| 140 BitrateObserver* bitrate_observer, | 140 BitrateObserver* bitrate_observer, |
| 141 RemoteBitrateObserver* remote_bitrate_observer) | 141 RemoteBitrateObserver* remote_bitrate_observer) |
| 142 : clock_(clock), | 142 : clock_(clock), |
| 143 observer_(nullptr), | 143 observer_(nullptr), |
| 144 packet_router_(new PacketRouter()), | 144 packet_router_(new PacketRouter()), |
| 145 pacer_(new PacedSender(clock_, | 145 pacer_(new PacedSender(clock_, packet_router_.get())), |
| 146 packet_router_.get())), | |
| 147 remote_bitrate_estimator_( | 146 remote_bitrate_estimator_( |
| 148 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 147 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
| 149 bitrate_controller_( | 148 bitrate_controller_( |
| 150 BitrateController::CreateBitrateController(clock_, bitrate_observer)), | 149 BitrateController::CreateBitrateController(clock_, bitrate_observer)), |
| 151 remote_estimator_proxy_(clock_, packet_router_.get()), | 150 remote_estimator_proxy_(clock_, packet_router_.get()), |
| 152 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 151 transport_feedback_adapter_(bitrate_controller_.get(), clock_), |
| 153 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 152 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
| 154 send_queue_is_full_(false) { | 153 last_reported_bitrate_bps_(0), |
| 154 last_reported_fraction_loss_(0), |
| 155 last_reported_rtt_(0), |
| 156 network_state_(kNetworkUp) { |
| 155 Init(); | 157 Init(); |
| 156 } | 158 } |
| 157 | 159 |
| 158 CongestionController::CongestionController( | 160 CongestionController::CongestionController( |
| 159 Clock* clock, | 161 Clock* clock, |
| 160 Observer* observer, | 162 Observer* observer, |
| 161 RemoteBitrateObserver* remote_bitrate_observer) | 163 RemoteBitrateObserver* remote_bitrate_observer) |
| 162 : clock_(clock), | 164 : clock_(clock), |
| 163 observer_(observer), | 165 observer_(observer), |
| 164 packet_router_(new PacketRouter()), | 166 packet_router_(new PacketRouter()), |
| 165 pacer_(new PacedSender(clock_, | 167 pacer_(new PacedSender(clock_, packet_router_.get())), |
| 166 packet_router_.get())), | |
| 167 remote_bitrate_estimator_( | 168 remote_bitrate_estimator_( |
| 168 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 169 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
| 169 bitrate_controller_(BitrateController::CreateBitrateController(clock_)), | 170 bitrate_controller_(BitrateController::CreateBitrateController(clock_)), |
| 170 remote_estimator_proxy_(clock_, packet_router_.get()), | 171 remote_estimator_proxy_(clock_, packet_router_.get()), |
| 171 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 172 transport_feedback_adapter_(bitrate_controller_.get(), clock_), |
| 172 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 173 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
| 173 send_queue_is_full_(false) { | 174 last_reported_bitrate_bps_(0), |
| 175 last_reported_fraction_loss_(0), |
| 176 last_reported_rtt_(0), |
| 177 network_state_(kNetworkUp) { |
| 174 Init(); | 178 Init(); |
| 175 } | 179 } |
| 176 | 180 |
| 177 CongestionController::CongestionController( | 181 CongestionController::CongestionController( |
| 178 Clock* clock, | 182 Clock* clock, |
| 179 Observer* observer, | 183 Observer* observer, |
| 180 RemoteBitrateObserver* remote_bitrate_observer, | 184 RemoteBitrateObserver* remote_bitrate_observer, |
| 181 std::unique_ptr<PacketRouter> packet_router, | 185 std::unique_ptr<PacketRouter> packet_router, |
| 182 std::unique_ptr<PacedSender> pacer) | 186 std::unique_ptr<PacedSender> pacer) |
| 183 : clock_(clock), | 187 : clock_(clock), |
| 184 observer_(observer), | 188 observer_(observer), |
| 185 packet_router_(std::move(packet_router)), | 189 packet_router_(std::move(packet_router)), |
| 186 pacer_(std::move(pacer)), | 190 pacer_(std::move(pacer)), |
| 187 remote_bitrate_estimator_( | 191 remote_bitrate_estimator_( |
| 188 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 192 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
| 189 // Constructed last as this object calls the provided callback on | 193 // Constructed last as this object calls the provided callback on |
| 190 // construction. | 194 // construction. |
| 191 bitrate_controller_(BitrateController::CreateBitrateController(clock_)), | 195 bitrate_controller_(BitrateController::CreateBitrateController(clock_)), |
| 192 remote_estimator_proxy_(clock_, packet_router_.get()), | 196 remote_estimator_proxy_(clock_, packet_router_.get()), |
| 193 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 197 transport_feedback_adapter_(bitrate_controller_.get(), clock_), |
| 194 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 198 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
| 195 send_queue_is_full_(false) { | 199 last_reported_bitrate_bps_(0), |
| 200 last_reported_fraction_loss_(0), |
| 201 last_reported_rtt_(0), |
| 202 network_state_(kNetworkUp) { |
| 196 Init(); | 203 Init(); |
| 197 } | 204 } |
| 198 | 205 |
| 199 CongestionController::~CongestionController() {} | 206 CongestionController::~CongestionController() {} |
| 200 | 207 |
| 201 void CongestionController::Init() { | 208 void CongestionController::Init() { |
| 202 transport_feedback_adapter_.SetBitrateEstimator( | 209 transport_feedback_adapter_.SetBitrateEstimator( |
| 203 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_)); | 210 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_)); |
| 204 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( | 211 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( |
| 205 min_bitrate_bps_); | 212 min_bitrate_bps_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 int64_t CongestionController::GetPacerQueuingDelayMs() const { | 265 int64_t CongestionController::GetPacerQueuingDelayMs() const { |
| 259 return pacer_->QueueInMs(); | 266 return pacer_->QueueInMs(); |
| 260 } | 267 } |
| 261 | 268 |
| 262 void CongestionController::SignalNetworkState(NetworkState state) { | 269 void CongestionController::SignalNetworkState(NetworkState state) { |
| 263 if (state == kNetworkUp) { | 270 if (state == kNetworkUp) { |
| 264 pacer_->Resume(); | 271 pacer_->Resume(); |
| 265 } else { | 272 } else { |
| 266 pacer_->Pause(); | 273 pacer_->Pause(); |
| 267 } | 274 } |
| 275 { |
| 276 rtc::CritScope cs(&critsect_); |
| 277 network_state_ = state; |
| 278 } |
| 279 MaybeTriggerOnNetworkChanged(); |
| 268 } | 280 } |
| 269 | 281 |
| 270 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { | 282 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { |
| 271 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, | 283 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, |
| 272 sent_packet.send_time_ms); | 284 sent_packet.send_time_ms); |
| 273 } | 285 } |
| 274 | 286 |
| 275 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 287 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
| 276 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 288 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
| 277 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 289 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 290 | 302 |
| 291 void CongestionController::MaybeTriggerOnNetworkChanged() { | 303 void CongestionController::MaybeTriggerOnNetworkChanged() { |
| 292 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a | 304 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a |
| 293 // BitrateObserver is used. Remove this check once the ctor is removed. | 305 // BitrateObserver is used. Remove this check once the ctor is removed. |
| 294 if (!observer_) | 306 if (!observer_) |
| 295 return; | 307 return; |
| 296 | 308 |
| 297 uint32_t bitrate_bps; | 309 uint32_t bitrate_bps; |
| 298 uint8_t fraction_loss; | 310 uint8_t fraction_loss; |
| 299 int64_t rtt; | 311 int64_t rtt; |
| 300 bool network_changed = bitrate_controller_->GetNetworkParameters( | 312 bool estimate_changed = bitrate_controller_->GetNetworkParameters( |
| 301 &bitrate_bps, &fraction_loss, &rtt); | 313 &bitrate_bps, &fraction_loss, &rtt); |
| 302 if (network_changed) | 314 if (estimate_changed) |
| 303 pacer_->SetEstimatedBitrate(bitrate_bps); | 315 pacer_->SetEstimatedBitrate(bitrate_bps); |
| 304 bool send_queue_is_full = | 316 |
| 305 pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | 317 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; |
| 306 bitrate_bps = send_queue_is_full ? 0 : bitrate_bps; | 318 |
| 307 if ((network_changed && !send_queue_is_full) || | 319 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { |
| 308 UpdateSendQueueStatus(send_queue_is_full)) { | |
| 309 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); | 320 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); |
| 310 } | 321 } |
| 311 } | 322 } |
| 312 | 323 |
| 313 bool CongestionController::UpdateSendQueueStatus(bool send_queue_is_full) { | 324 bool CongestionController::HasNetworkParametersToReportChanged( |
| 325 uint32_t bitrate_bps, |
| 326 uint8_t fraction_loss, |
| 327 int64_t rtt) { |
| 314 rtc::CritScope cs(&critsect_); | 328 rtc::CritScope cs(&critsect_); |
| 315 bool result = send_queue_is_full_ != send_queue_is_full; | 329 bool changed = |
| 316 send_queue_is_full_ = send_queue_is_full; | 330 last_reported_bitrate_bps_ != bitrate_bps || |
| 317 return result; | 331 (bitrate_bps > 0 && (last_reported_fraction_loss_ != fraction_loss || |
| 332 last_reported_rtt_ != rtt)); |
| 333 last_reported_bitrate_bps_ = bitrate_bps; |
| 334 last_reported_fraction_loss_ = fraction_loss; |
| 335 last_reported_rtt_ = rtt; |
| 336 return changed; |
| 337 } |
| 338 |
| 339 bool CongestionController::IsSendQueueFull() const { |
| 340 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; |
| 341 } |
| 342 |
| 343 bool CongestionController::IsNetworkDown() const { |
| 344 rtc::CritScope cs(&critsect_); |
| 345 return network_state_ == kNetworkDown; |
| 318 } | 346 } |
| 319 | 347 |
| 320 } // namespace webrtc | 348 } // namespace webrtc |
| OLD | NEW |