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