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

Side by Side Diff: webrtc/call/call.cc

Issue 2060403002: Add task queue to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@move_getpadding
Patch Set: Rebased Created 4 years, 5 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
11 #include <string.h> 11 #include <string.h>
12
13 #include <algorithm> 12 #include <algorithm>
14 #include <map> 13 #include <map>
15 #include <memory> 14 #include <memory>
16 #include <vector> 15 #include <vector>
17 16
18 #include "webrtc/audio/audio_receive_stream.h" 17 #include "webrtc/audio/audio_receive_stream.h"
19 #include "webrtc/audio/audio_send_stream.h" 18 #include "webrtc/audio/audio_send_stream.h"
20 #include "webrtc/audio/audio_state.h" 19 #include "webrtc/audio/audio_state.h"
21 #include "webrtc/audio/scoped_voe_interface.h" 20 #include "webrtc/audio/scoped_voe_interface.h"
22 #include "webrtc/base/checks.h" 21 #include "webrtc/base/checks.h"
23 #include "webrtc/base/constructormagic.h" 22 #include "webrtc/base/constructormagic.h"
24 #include "webrtc/base/logging.h" 23 #include "webrtc/base/logging.h"
24 #include "webrtc/base/task_queue.h"
25 #include "webrtc/base/thread_annotations.h" 25 #include "webrtc/base/thread_annotations.h"
26 #include "webrtc/base/thread_checker.h" 26 #include "webrtc/base/thread_checker.h"
27 #include "webrtc/base/trace_event.h" 27 #include "webrtc/base/trace_event.h"
28 #include "webrtc/call.h" 28 #include "webrtc/call.h"
29 #include "webrtc/call/bitrate_allocator.h" 29 #include "webrtc/call/bitrate_allocator.h"
30 #include "webrtc/call/rtc_event_log.h" 30 #include "webrtc/call/rtc_event_log.h"
31 #include "webrtc/config.h" 31 #include "webrtc/config.h"
32 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 32 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
33 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" 33 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
34 #include "webrtc/modules/pacing/paced_sender.h" 34 #include "webrtc/modules/pacing/paced_sender.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 webrtc::AudioSendStream* CreateAudioSendStream( 67 webrtc::AudioSendStream* CreateAudioSendStream(
68 const webrtc::AudioSendStream::Config& config) override; 68 const webrtc::AudioSendStream::Config& config) override;
69 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; 69 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override;
70 70
71 webrtc::AudioReceiveStream* CreateAudioReceiveStream( 71 webrtc::AudioReceiveStream* CreateAudioReceiveStream(
72 const webrtc::AudioReceiveStream::Config& config) override; 72 const webrtc::AudioReceiveStream::Config& config) override;
73 void DestroyAudioReceiveStream( 73 void DestroyAudioReceiveStream(
74 webrtc::AudioReceiveStream* receive_stream) override; 74 webrtc::AudioReceiveStream* receive_stream) override;
75 75
76 webrtc::VideoSendStream* CreateVideoSendStream( 76 webrtc::VideoSendStream* CreateVideoSendStream(
77 const webrtc::VideoSendStream::Config& config, 77 webrtc::VideoSendStream::Config config,
78 const VideoEncoderConfig& encoder_config) override; 78 VideoEncoderConfig encoder_config) override;
stefan-webrtc 2016/07/08 15:56:41 Should we change this for audio above too, and for
perkj_webrtc 2016/07/11 11:41:07 This match CreateVideoReceiveStream now. I guess a
79 void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; 79 void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override;
80 80
81 webrtc::VideoReceiveStream* CreateVideoReceiveStream( 81 webrtc::VideoReceiveStream* CreateVideoReceiveStream(
82 webrtc::VideoReceiveStream::Config configuration) override; 82 webrtc::VideoReceiveStream::Config configuration) override;
83 void DestroyVideoReceiveStream( 83 void DestroyVideoReceiveStream(
84 webrtc::VideoReceiveStream* receive_stream) override; 84 webrtc::VideoReceiveStream* receive_stream) override;
85 85
86 Stats GetStats() const override; 86 Stats GetStats() const override;
87 87
88 DeliveryStatus DeliverPacket(MediaType media_type, 88 DeliveryStatus DeliverPacket(MediaType media_type,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); 189 int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_);
190 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_); 190 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
191 int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_); 191 int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_);
192 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_); 192 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
193 193
194 std::map<std::string, rtc::NetworkRoute> network_routes_; 194 std::map<std::string, rtc::NetworkRoute> network_routes_;
195 195
196 VieRemb remb_; 196 VieRemb remb_;
197 const std::unique_ptr<CongestionController> congestion_controller_; 197 const std::unique_ptr<CongestionController> congestion_controller_;
198 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; 198 const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
199 // TODO(perkj): |worker_queue_| is supposed to replace
200 // |module_process_thread_|.
201 // |worker_queue| is defined last to ensure all pending tasks are cancelled
202 // and deleted before any other members.
203 rtc::TaskQueue worker_queue_;
199 204
200 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 205 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
201 }; 206 };
202 } // namespace internal 207 } // namespace internal
203 208
204 Call* Call::Create(const Call::Config& config) { 209 Call* Call::Create(const Call::Config& config) {
205 return new internal::Call(config); 210 return new internal::Call(config);
206 } 211 }
207 212
208 namespace internal { 213 namespace internal {
(...skipping 19 matching lines...) Expand all
228 first_packet_sent_ms_(-1), 233 first_packet_sent_ms_(-1),
229 estimated_send_bitrate_sum_kbits_(0), 234 estimated_send_bitrate_sum_kbits_(0),
230 pacer_bitrate_sum_kbits_(0), 235 pacer_bitrate_sum_kbits_(0),
231 min_allocated_send_bitrate_bps_(0), 236 min_allocated_send_bitrate_bps_(0),
232 num_bitrate_updates_(0), 237 num_bitrate_updates_(0),
233 configured_max_padding_bitrate_bps_(0), 238 configured_max_padding_bitrate_bps_(0),
234 239
235 remb_(clock_), 240 remb_(clock_),
236 congestion_controller_( 241 congestion_controller_(
237 new CongestionController(clock_, this, &remb_, event_log_.get())), 242 new CongestionController(clock_, this, &remb_, event_log_.get())),
238 video_send_delay_stats_(new SendDelayStats(clock_)) { 243 video_send_delay_stats_(new SendDelayStats(clock_)),
244 worker_queue_("worker_queue") {
239 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 245 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
240 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); 246 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
241 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, 247 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps,
242 config.bitrate_config.min_bitrate_bps); 248 config.bitrate_config.min_bitrate_bps);
243 if (config.bitrate_config.max_bitrate_bps != -1) { 249 if (config.bitrate_config.max_bitrate_bps != -1) {
244 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, 250 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps,
245 config.bitrate_config.start_bitrate_bps); 251 config.bitrate_config.start_bitrate_bps);
246 } 252 }
247 253
248 Trace::CreateTrace(); 254 Trace::CreateTrace();
249 call_stats_->RegisterStatsObserver(congestion_controller_.get()); 255 call_stats_->RegisterStatsObserver(congestion_controller_.get());
250 256
251 congestion_controller_->SetBweBitrates( 257 congestion_controller_->SetBweBitrates(
252 config_.bitrate_config.min_bitrate_bps, 258 config_.bitrate_config.min_bitrate_bps,
253 config_.bitrate_config.start_bitrate_bps, 259 config_.bitrate_config.start_bitrate_bps,
254 config_.bitrate_config.max_bitrate_bps); 260 config_.bitrate_config.max_bitrate_bps);
255 261
256 module_process_thread_->Start(); 262 module_process_thread_->Start();
257 module_process_thread_->RegisterModule(call_stats_.get()); 263 module_process_thread_->RegisterModule(call_stats_.get());
258 module_process_thread_->RegisterModule(congestion_controller_.get()); 264 module_process_thread_->RegisterModule(congestion_controller_.get());
259 pacer_thread_->RegisterModule(congestion_controller_->pacer()); 265 pacer_thread_->RegisterModule(congestion_controller_->pacer());
260 pacer_thread_->RegisterModule( 266 pacer_thread_->RegisterModule(
261 congestion_controller_->GetRemoteBitrateEstimator(true)); 267 congestion_controller_->GetRemoteBitrateEstimator(true));
262 pacer_thread_->Start(); 268 pacer_thread_->Start();
263 } 269 }
264 270
265 Call::~Call() { 271 Call::~Call() {
266 RTC_DCHECK(!remb_.InUse()); 272 RTC_DCHECK(!remb_.InUse());
267 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 273 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
268 UpdateSendHistograms(); 274 {
275 rtc::CritScope lock(&bitrate_crit_);
276 UpdateSendHistograms();
277 }
269 UpdateReceiveHistograms(); 278 UpdateReceiveHistograms();
270 RTC_CHECK(audio_send_ssrcs_.empty()); 279 RTC_CHECK(audio_send_ssrcs_.empty());
271 RTC_CHECK(video_send_ssrcs_.empty()); 280 RTC_CHECK(video_send_ssrcs_.empty());
272 RTC_CHECK(video_send_streams_.empty()); 281 RTC_CHECK(video_send_streams_.empty());
273 RTC_CHECK(audio_receive_ssrcs_.empty()); 282 RTC_CHECK(audio_receive_ssrcs_.empty());
274 RTC_CHECK(video_receive_ssrcs_.empty()); 283 RTC_CHECK(video_receive_ssrcs_.empty());
275 RTC_CHECK(video_receive_streams_.empty()); 284 RTC_CHECK(video_receive_streams_.empty());
276 285
277 pacer_thread_->Stop(); 286 pacer_thread_->Stop();
278 pacer_thread_->DeRegisterModule(congestion_controller_->pacer()); 287 pacer_thread_->DeRegisterModule(congestion_controller_->pacer());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 it->second == audio_receive_stream) { 421 it->second == audio_receive_stream) {
413 sync_stream_mapping_.erase(it); 422 sync_stream_mapping_.erase(it);
414 ConfigureSync(sync_group); 423 ConfigureSync(sync_group);
415 } 424 }
416 } 425 }
417 UpdateAggregateNetworkState(); 426 UpdateAggregateNetworkState();
418 delete audio_receive_stream; 427 delete audio_receive_stream;
419 } 428 }
420 429
421 webrtc::VideoSendStream* Call::CreateVideoSendStream( 430 webrtc::VideoSendStream* Call::CreateVideoSendStream(
422 const webrtc::VideoSendStream::Config& config, 431 webrtc::VideoSendStream::Config config,
423 const VideoEncoderConfig& encoder_config) { 432 VideoEncoderConfig encoder_config) {
424 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); 433 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream");
425 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 434 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
426 435
427 video_send_delay_stats_->AddSsrcs(config); 436 video_send_delay_stats_->AddSsrcs(config);
437 event_log_->LogVideoSendStreamConfig(config);
438
428 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if 439 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if
429 // the call has already started. 440 // the call has already started.
441 // Copy ssrcs from |config| since |config| is moved.
442 std::vector<uint32_t> ssrcs = config.rtp.ssrcs;
430 VideoSendStream* send_stream = new VideoSendStream( 443 VideoSendStream* send_stream = new VideoSendStream(
431 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), 444 num_cpu_cores_, module_process_thread_.get(), &worker_queue_,
432 congestion_controller_.get(), bitrate_allocator_.get(), 445 call_stats_.get(), congestion_controller_.get(), bitrate_allocator_.get(),
433 video_send_delay_stats_.get(), &remb_, event_log_.get(), config, 446 video_send_delay_stats_.get(), &remb_, event_log_.get(),
434 encoder_config, suspended_video_send_ssrcs_); 447 std::move(config), std::move(encoder_config),
448 suspended_video_send_ssrcs_);
449
435 { 450 {
436 WriteLockScoped write_lock(*send_crit_); 451 WriteLockScoped write_lock(*send_crit_);
437 for (uint32_t ssrc : config.rtp.ssrcs) { 452 for (uint32_t ssrc : ssrcs) {
438 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); 453 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end());
439 video_send_ssrcs_[ssrc] = send_stream; 454 video_send_ssrcs_[ssrc] = send_stream;
440 } 455 }
441 video_send_streams_.insert(send_stream); 456 video_send_streams_.insert(send_stream);
442 } 457 }
443 send_stream->SignalNetworkState(video_network_state_); 458 send_stream->SignalNetworkState(video_network_state_);
444 UpdateAggregateNetworkState(); 459 UpdateAggregateNetworkState();
445 event_log_->LogVideoSendStreamConfig(config); 460
446 return send_stream; 461 return send_stream;
447 } 462 }
448 463
449 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { 464 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
450 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); 465 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream");
451 RTC_DCHECK(send_stream != nullptr); 466 RTC_DCHECK(send_stream != nullptr);
452 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 467 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
453 468
454 send_stream->Stop(); 469 send_stream->Stop();
455 470
456 VideoSendStream* send_stream_impl = nullptr; 471 VideoSendStream* send_stream_impl = nullptr;
457 { 472 {
458 WriteLockScoped write_lock(*send_crit_); 473 WriteLockScoped write_lock(*send_crit_);
459 auto it = video_send_ssrcs_.begin(); 474 auto it = video_send_ssrcs_.begin();
460 while (it != video_send_ssrcs_.end()) { 475 while (it != video_send_ssrcs_.end()) {
461 if (it->second == static_cast<VideoSendStream*>(send_stream)) { 476 if (it->second == static_cast<VideoSendStream*>(send_stream)) {
462 send_stream_impl = it->second; 477 send_stream_impl = it->second;
463 video_send_ssrcs_.erase(it++); 478 video_send_ssrcs_.erase(it++);
464 } else { 479 } else {
465 ++it; 480 ++it;
466 } 481 }
467 } 482 }
468 video_send_streams_.erase(send_stream_impl); 483 video_send_streams_.erase(send_stream_impl);
469 } 484 }
470 RTC_CHECK(send_stream_impl != nullptr); 485 RTC_CHECK(send_stream_impl != nullptr);
471 486
472 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); 487 VideoSendStream::RtpStateMap rtp_state =
488 send_stream_impl->StopPermanentlyAndGetRtpStates();
473 489
474 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); 490 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin();
475 it != rtp_state.end(); 491 it != rtp_state.end(); ++it) {
476 ++it) {
477 suspended_video_send_ssrcs_[it->first] = it->second; 492 suspended_video_send_ssrcs_[it->first] = it->second;
478 } 493 }
479 494
480 UpdateAggregateNetworkState(); 495 UpdateAggregateNetworkState();
481 delete send_stream_impl; 496 delete send_stream_impl;
482 } 497 }
483 498
484 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( 499 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream(
485 webrtc::VideoReceiveStream::Config configuration) { 500 webrtc::VideoReceiveStream::Config configuration) {
486 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); 501 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream");
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { 706 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
692 if (first_packet_sent_ms_ == -1) 707 if (first_packet_sent_ms_ == -1)
693 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); 708 first_packet_sent_ms_ = clock_->TimeInMilliseconds();
694 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, 709 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id,
695 clock_->TimeInMilliseconds()); 710 clock_->TimeInMilliseconds());
696 congestion_controller_->OnSentPacket(sent_packet); 711 congestion_controller_->OnSentPacket(sent_packet);
697 } 712 }
698 713
699 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, 714 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss,
700 int64_t rtt_ms) { 715 int64_t rtt_ms) {
716 // TODO(perkj): Consider making sure CongestionController operates on
717 // |worker_queue_|.
718 if (!worker_queue_.IsCurrent()) {
719 worker_queue_.PostTask([this, target_bitrate_bps, fraction_loss, rtt_ms] {
720 OnNetworkChanged(target_bitrate_bps, fraction_loss, rtt_ms);
721 });
722 return;
723 }
724 RTC_DCHECK_RUN_ON(&worker_queue_);
701 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, 725 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss,
702 rtt_ms); 726 rtt_ms);
703 727
704 { 728 {
705 rtc::CritScope lock(&bitrate_crit_); 729 rtc::CritScope lock(&bitrate_crit_);
706 // We only update these stats if we have send streams, and assume that 730 // We only update these stats if we have send streams, and assume that
707 // OnNetworkChanged is called roughly with a fixed frequency. 731 // OnNetworkChanged is called roughly with a fixed frequency.
708 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; 732 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000;
709 // Pacer bitrate might be higher than bitrate estimate if enforcing min 733 // Pacer bitrate might be higher than bitrate estimate if enforcing min
710 // bitrate. 734 // bitrate.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 // thread. Then this check can be enabled. 892 // thread. Then this check can be enabled.
869 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); 893 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread());
870 if (RtpHeaderParser::IsRtcp(packet, length)) 894 if (RtpHeaderParser::IsRtcp(packet, length))
871 return DeliverRtcp(media_type, packet, length); 895 return DeliverRtcp(media_type, packet, length);
872 896
873 return DeliverRtp(media_type, packet, length, packet_time); 897 return DeliverRtp(media_type, packet, length, packet_time);
874 } 898 }
875 899
876 } // namespace internal 900 } // namespace internal
877 } // namespace webrtc 901 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698