Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: webrtc/modules/congestion_controller/congestion_controller.cc

Issue 2725823002: Move delay_based_bwe_ into CongestionController (Closed)
Patch Set: UT thread-checking. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 CongestionController::CongestionController( 154 CongestionController::CongestionController(
155 Clock* clock, 155 Clock* clock,
156 Observer* observer, 156 Observer* observer,
157 RemoteBitrateObserver* remote_bitrate_observer, 157 RemoteBitrateObserver* remote_bitrate_observer,
158 RtcEventLog* event_log, 158 RtcEventLog* event_log,
159 PacketRouter* packet_router, 159 PacketRouter* packet_router,
160 std::unique_ptr<PacedSender> pacer) 160 std::unique_ptr<PacedSender> pacer)
161 : clock_(clock), 161 : clock_(clock),
162 observer_(observer), 162 observer_(observer),
163 event_log_(event_log),
163 packet_router_(packet_router), 164 packet_router_(packet_router),
164 pacer_(std::move(pacer)), 165 pacer_(std::move(pacer)),
165 bitrate_controller_( 166 bitrate_controller_(
166 BitrateController::CreateBitrateController(clock_, event_log)), 167 BitrateController::CreateBitrateController(clock_, event_log)),
167 probe_controller_(new ProbeController(pacer_.get(), clock_)), 168 probe_controller_(new ProbeController(pacer_.get(), clock_)),
168 retransmission_rate_limiter_( 169 retransmission_rate_limiter_(
169 new RateLimiter(clock, kRetransmitWindowSizeMs)), 170 new RateLimiter(clock, kRetransmitWindowSizeMs)),
170 remote_bitrate_estimator_(remote_bitrate_observer, clock_), 171 remote_bitrate_estimator_(remote_bitrate_observer, clock_),
171 remote_estimator_proxy_(clock_, packet_router_), 172 remote_estimator_proxy_(clock_, packet_router_),
172 transport_feedback_adapter_(event_log, clock_, bitrate_controller_.get()), 173 transport_feedback_adapter_(clock_),
173 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()), 174 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()),
174 max_bitrate_bps_(0), 175 max_bitrate_bps_(0),
175 last_reported_bitrate_bps_(0), 176 last_reported_bitrate_bps_(0),
176 last_reported_fraction_loss_(0), 177 last_reported_fraction_loss_(0),
177 last_reported_rtt_(0), 178 last_reported_rtt_(0),
178 network_state_(kNetworkUp) { 179 network_state_(kNetworkUp),
179 transport_feedback_adapter_.InitBwe(); 180 delay_based_bwe_(new DelayBasedBwe(event_log_, clock_)) {
180 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_); 181 delay_based_bwe_->SetMinBitrate(min_bitrate_bps_);
182 worker_thread_checker_.DetachFromThread();
181 } 183 }
182 184
183 CongestionController::~CongestionController() {} 185 CongestionController::~CongestionController() {}
184 186
185 void CongestionController::OnReceivedPacket(int64_t arrival_time_ms, 187 void CongestionController::OnReceivedPacket(int64_t arrival_time_ms,
186 size_t payload_size, 188 size_t payload_size,
187 const RTPHeader& header) { 189 const RTPHeader& header) {
188 // Send-side BWE. 190 // Send-side BWE.
189 if (header.extension.hasTransportSequenceNumber) { 191 if (header.extension.hasTransportSequenceNumber) {
190 remote_estimator_proxy_.IncomingPacket(arrival_time_ms, payload_size, 192 remote_estimator_proxy_.IncomingPacket(arrival_time_ms, payload_size,
(...skipping 12 matching lines...) Expand all
203 bitrate_controller_->SetBitrates(start_bitrate_bps, 205 bitrate_controller_->SetBitrates(start_bitrate_bps,
204 min_bitrate_bps, 206 min_bitrate_bps,
205 max_bitrate_bps); 207 max_bitrate_bps);
206 208
207 probe_controller_->SetBitrates(min_bitrate_bps, start_bitrate_bps, 209 probe_controller_->SetBitrates(min_bitrate_bps, start_bitrate_bps,
208 max_bitrate_bps); 210 max_bitrate_bps);
209 max_bitrate_bps_ = max_bitrate_bps; 211 max_bitrate_bps_ = max_bitrate_bps;
210 212
211 remote_bitrate_estimator_.SetMinBitrate(min_bitrate_bps); 213 remote_bitrate_estimator_.SetMinBitrate(min_bitrate_bps);
212 min_bitrate_bps_ = min_bitrate_bps; 214 min_bitrate_bps_ = min_bitrate_bps;
213 if (start_bitrate_bps > 0) 215 {
214 transport_feedback_adapter_.SetStartBitrate(start_bitrate_bps); 216 rtc::CritScope cs(&bwe_lock_);
215 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_); 217 if (start_bitrate_bps > 0)
218 delay_based_bwe_->SetStartBitrate(start_bitrate_bps);
219 delay_based_bwe_->SetMinBitrate(min_bitrate_bps_);
220 }
216 MaybeTriggerOnNetworkChanged(); 221 MaybeTriggerOnNetworkChanged();
217 } 222 }
218 223
219 void CongestionController::ResetBweAndBitrates(int bitrate_bps, 224 void CongestionController::ResetBweAndBitrates(int bitrate_bps,
220 int min_bitrate_bps, 225 int min_bitrate_bps,
221 int max_bitrate_bps) { 226 int max_bitrate_bps) {
222 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); 227 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
223 // TODO(honghaiz): Recreate this object once the bitrate controller is 228 // TODO(honghaiz): Recreate this object once the bitrate controller is
224 // no longer exposed outside CongestionController. 229 // no longer exposed outside CongestionController.
225 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps, 230 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps,
226 max_bitrate_bps); 231 max_bitrate_bps);
227 min_bitrate_bps_ = min_bitrate_bps; 232 min_bitrate_bps_ = min_bitrate_bps;
228 max_bitrate_bps_ = max_bitrate_bps; 233 max_bitrate_bps_ = max_bitrate_bps;
229 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is 234 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is
230 // no longer exposed outside CongestionController. 235 // no longer exposed outside CongestionController.
231 remote_bitrate_estimator_.SetMinBitrate(min_bitrate_bps); 236 remote_bitrate_estimator_.SetMinBitrate(min_bitrate_bps);
232 237
233 transport_feedback_adapter_.ClearSendTimeHistory(); 238 transport_feedback_adapter_.ClearSendTimeHistory();
234 transport_feedback_adapter_.InitBwe(); 239 {
235 transport_feedback_adapter_.SetStartBitrate(bitrate_bps); 240 rtc::CritScope cs(&bwe_lock_);
236 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps); 241 delay_based_bwe_.reset(new DelayBasedBwe(event_log_, clock_));
242 delay_based_bwe_->SetStartBitrate(bitrate_bps);
243 delay_based_bwe_->SetMinBitrate(min_bitrate_bps);
244 }
237 245
238 probe_controller_->Reset(); 246 probe_controller_->Reset();
239 probe_controller_->SetBitrates(min_bitrate_bps, bitrate_bps, max_bitrate_bps); 247 probe_controller_->SetBitrates(min_bitrate_bps, bitrate_bps, max_bitrate_bps);
240 248
241 MaybeTriggerOnNetworkChanged(); 249 MaybeTriggerOnNetworkChanged();
242 } 250 }
243 251
244 BitrateController* CongestionController::GetBitrateController() const { 252 BitrateController* CongestionController::GetBitrateController() const {
245 return bitrate_controller_.get(); 253 return bitrate_controller_.get();
246 } 254 }
247 255
248 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( 256 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator(
249 bool send_side_bwe) { 257 bool send_side_bwe) {
250 if (send_side_bwe) { 258 if (send_side_bwe) {
251 return &remote_estimator_proxy_; 259 return &remote_estimator_proxy_;
252 } else { 260 } else {
253 return &remote_bitrate_estimator_; 261 return &remote_bitrate_estimator_;
254 } 262 }
255 } 263 }
256 264
257 TransportFeedbackObserver*
258 CongestionController::GetTransportFeedbackObserver() {
259 return &transport_feedback_adapter_;
260 }
261
262 RateLimiter* CongestionController::GetRetransmissionRateLimiter() { 265 RateLimiter* CongestionController::GetRetransmissionRateLimiter() {
263 return retransmission_rate_limiter_.get(); 266 return retransmission_rate_limiter_.get();
264 } 267 }
265 268
266 void CongestionController::EnablePeriodicAlrProbing(bool enable) { 269 void CongestionController::EnablePeriodicAlrProbing(bool enable) {
267 probe_controller_->EnablePeriodicAlrProbing(enable); 270 probe_controller_->EnablePeriodicAlrProbing(enable);
268 } 271 }
269 272
270 void CongestionController::SetAllocatedSendBitrateLimits( 273 void CongestionController::SetAllocatedSendBitrateLimits(
271 int min_send_bitrate_bps, 274 int min_send_bitrate_bps,
272 int max_padding_bitrate_bps) { 275 int max_padding_bitrate_bps) {
273 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps); 276 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps);
274 } 277 }
275 278
276 int64_t CongestionController::GetPacerQueuingDelayMs() const { 279 int64_t CongestionController::GetPacerQueuingDelayMs() const {
277 return IsNetworkDown() ? 0 : pacer_->QueueInMs(); 280 return IsNetworkDown() ? 0 : pacer_->QueueInMs();
278 } 281 }
279 282
280 void CongestionController::SignalNetworkState(NetworkState state) { 283 void CongestionController::SignalNetworkState(NetworkState state) {
281 LOG(LS_INFO) << "SignalNetworkState " 284 LOG(LS_INFO) << "SignalNetworkState "
282 << (state == kNetworkUp ? "Up" : "Down"); 285 << (state == kNetworkUp ? "Up" : "Down");
283 if (state == kNetworkUp) { 286 if (state == kNetworkUp) {
284 pacer_->Resume(); 287 pacer_->Resume();
285 } else { 288 } else {
286 pacer_->Pause(); 289 pacer_->Pause();
287 } 290 }
288 { 291 {
289 rtc::CritScope cs(&critsect_); 292 rtc::CritScope cs(&network_state_lock_);
290 network_state_ = state; 293 network_state_ = state;
291 } 294 }
292 probe_controller_->OnNetworkStateChanged(state); 295 probe_controller_->OnNetworkStateChanged(state);
293 MaybeTriggerOnNetworkChanged(); 296 MaybeTriggerOnNetworkChanged();
294 } 297 }
295 298
296 void CongestionController::SetTransportOverhead( 299 void CongestionController::SetTransportOverhead(
297 size_t transport_overhead_bytes_per_packet) { 300 size_t transport_overhead_bytes_per_packet) {
298 transport_feedback_adapter_.SetTransportOverhead( 301 transport_feedback_adapter_.SetTransportOverhead(
299 transport_overhead_bytes_per_packet); 302 transport_overhead_bytes_per_packet);
300 } 303 }
301 304
302 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { 305 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
303 // We're not interested in packets without an id, which may be stun packets, 306 // We're not interested in packets without an id, which may be stun packets,
304 // etc, sent on the same transport. 307 // etc, sent on the same transport.
305 if (sent_packet.packet_id == -1) 308 if (sent_packet.packet_id == -1)
306 return; 309 return;
307 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, 310 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id,
308 sent_packet.send_time_ms); 311 sent_packet.send_time_ms);
309 } 312 }
310 313
311 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 314 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
312 remote_bitrate_estimator_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); 315 remote_bitrate_estimator_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
313 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); 316 {
317 rtc::CritScope cs(&bwe_lock_);
318 delay_based_bwe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
319 }
314 } 320 }
315 321
316 int64_t CongestionController::TimeUntilNextProcess() { 322 int64_t CongestionController::TimeUntilNextProcess() {
317 return std::min(bitrate_controller_->TimeUntilNextProcess(), 323 return std::min(bitrate_controller_->TimeUntilNextProcess(),
318 remote_bitrate_estimator_.TimeUntilNextProcess()); 324 remote_bitrate_estimator_.TimeUntilNextProcess());
319 } 325 }
320 326
321 void CongestionController::Process() { 327 void CongestionController::Process() {
322 bitrate_controller_->Process(); 328 bitrate_controller_->Process();
323 remote_bitrate_estimator_.Process(); 329 remote_bitrate_estimator_.Process();
324 probe_controller_->Process(); 330 probe_controller_->Process();
325 MaybeTriggerOnNetworkChanged(); 331 MaybeTriggerOnNetworkChanged();
326 } 332 }
327 333
334 void CongestionController::AddPacket(uint16_t sequence_number,
335 size_t length,
336 const PacedPacketInfo& pacing_info) {
337 transport_feedback_adapter_.AddPacket(sequence_number, length, pacing_info);
338 }
339
340 void CongestionController::OnTransportFeedback(
341 const rtcp::TransportFeedback& feedback) {
342 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
343 transport_feedback_adapter_.OnTransportFeedback(feedback);
344 DelayBasedBwe::Result result;
345 {
346 rtc::CritScope cs(&bwe_lock_);
347 result = delay_based_bwe_->IncomingPacketFeedbackVector(
348 transport_feedback_adapter_.GetTransportFeedbackVector());
349 }
350 if (result.updated)
351 bitrate_controller_->OnDelayBasedBweResult(result);
352 }
353
354 std::vector<PacketFeedback> CongestionController::GetTransportFeedbackVector()
355 const {
356 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
357 return transport_feedback_adapter_.GetTransportFeedbackVector();
358 }
359
328 void CongestionController::MaybeTriggerOnNetworkChanged() { 360 void CongestionController::MaybeTriggerOnNetworkChanged() {
329 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a 361 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a
330 // BitrateObserver is used. Remove this check once the ctor is removed. 362 // BitrateObserver is used. Remove this check once the ctor is removed.
331 if (!observer_) 363 if (!observer_)
332 return; 364 return;
333 365
334 uint32_t bitrate_bps; 366 uint32_t bitrate_bps;
335 uint8_t fraction_loss; 367 uint8_t fraction_loss;
336 int64_t rtt; 368 int64_t rtt;
337 bool estimate_changed = bitrate_controller_->GetNetworkParameters( 369 bool estimate_changed = bitrate_controller_->GetNetworkParameters(
338 &bitrate_bps, &fraction_loss, &rtt); 370 &bitrate_bps, &fraction_loss, &rtt);
339 if (estimate_changed) { 371 if (estimate_changed) {
340 pacer_->SetEstimatedBitrate(bitrate_bps); 372 pacer_->SetEstimatedBitrate(bitrate_bps);
341 probe_controller_->SetEstimatedBitrate(bitrate_bps); 373 probe_controller_->SetEstimatedBitrate(bitrate_bps);
342 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); 374 retransmission_rate_limiter_->SetMaxRate(bitrate_bps);
343 } 375 }
344 376
345 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; 377 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps;
346 378
347 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { 379 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) {
348 observer_->OnNetworkChanged( 380 int64_t probing_interval_ms;
349 bitrate_bps, fraction_loss, rtt, 381 {
350 transport_feedback_adapter_.GetProbingIntervalMs()); 382 rtc::CritScope cs(&bwe_lock_);
383 probing_interval_ms = delay_based_bwe_->GetProbingIntervalMs();
384 }
385 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt,
386 probing_interval_ms);
351 remote_estimator_proxy_.OnBitrateChanged(bitrate_bps); 387 remote_estimator_proxy_.OnBitrateChanged(bitrate_bps);
352 } 388 }
353 } 389 }
354 390
355 bool CongestionController::HasNetworkParametersToReportChanged( 391 bool CongestionController::HasNetworkParametersToReportChanged(
356 uint32_t bitrate_bps, 392 uint32_t bitrate_bps,
357 uint8_t fraction_loss, 393 uint8_t fraction_loss,
358 int64_t rtt) { 394 int64_t rtt) {
359 rtc::CritScope cs(&critsect_); 395 rtc::CritScope cs(&network_state_lock_);
360 bool changed = 396 bool changed =
361 last_reported_bitrate_bps_ != bitrate_bps || 397 last_reported_bitrate_bps_ != bitrate_bps ||
362 (bitrate_bps > 0 && (last_reported_fraction_loss_ != fraction_loss || 398 (bitrate_bps > 0 && (last_reported_fraction_loss_ != fraction_loss ||
363 last_reported_rtt_ != rtt)); 399 last_reported_rtt_ != rtt));
364 if (changed && (last_reported_bitrate_bps_ == 0 || bitrate_bps == 0)) { 400 if (changed && (last_reported_bitrate_bps_ == 0 || bitrate_bps == 0)) {
365 LOG(LS_INFO) << "Bitrate estimate state changed, BWE: " << bitrate_bps 401 LOG(LS_INFO) << "Bitrate estimate state changed, BWE: " << bitrate_bps
366 << " bps."; 402 << " bps.";
367 } 403 }
368 last_reported_bitrate_bps_ = bitrate_bps; 404 last_reported_bitrate_bps_ = bitrate_bps;
369 last_reported_fraction_loss_ = fraction_loss; 405 last_reported_fraction_loss_ = fraction_loss;
370 last_reported_rtt_ = rtt; 406 last_reported_rtt_ = rtt;
371 return changed; 407 return changed;
372 } 408 }
373 409
374 bool CongestionController::IsSendQueueFull() const { 410 bool CongestionController::IsSendQueueFull() const {
375 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; 411 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
376 } 412 }
377 413
378 bool CongestionController::IsNetworkDown() const { 414 bool CongestionController::IsNetworkDown() const {
379 rtc::CritScope cs(&critsect_); 415 rtc::CritScope cs(&network_state_lock_);
380 return network_state_ == kNetworkDown; 416 return network_state_ == kNetworkDown;
381 } 417 }
382 418
383 } // namespace webrtc 419 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/congestion_controller/BUILD.gn ('k') | webrtc/modules/congestion_controller/congestion_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698