Chromium Code Reviews| Index: webrtc/call/call.cc |
| diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc |
| index dfb1879a5fdae4acb63dbc7bc167e3f28a364da2..0860629d79c7812d07b2c9d9c65c5467901329c2 100644 |
| --- a/webrtc/call/call.cc |
| +++ b/webrtc/call/call.cc |
| @@ -9,7 +9,6 @@ |
| */ |
| #include <string.h> |
| - |
| #include <algorithm> |
| #include <map> |
| #include <memory> |
| @@ -22,6 +21,7 @@ |
| #include "webrtc/base/checks.h" |
| #include "webrtc/base/constructormagic.h" |
| #include "webrtc/base/logging.h" |
| +#include "webrtc/base/task_queue.h" |
| #include "webrtc/base/thread_annotations.h" |
| #include "webrtc/base/thread_checker.h" |
| #include "webrtc/base/trace_event.h" |
| @@ -74,8 +74,8 @@ class Call : public webrtc::Call, |
| webrtc::AudioReceiveStream* receive_stream) override; |
| webrtc::VideoSendStream* CreateVideoSendStream( |
| - const webrtc::VideoSendStream::Config& config, |
| - const VideoEncoderConfig& encoder_config) override; |
| + webrtc::VideoSendStream::Config config, |
| + VideoEncoderConfig encoder_config) override; |
| void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; |
| webrtc::VideoReceiveStream* CreateVideoReceiveStream( |
| @@ -196,6 +196,11 @@ class Call : public webrtc::Call, |
| VieRemb remb_; |
| const std::unique_ptr<CongestionController> congestion_controller_; |
| const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
| + // TODO(perkj): |worker_queue_| is supposed to replace |
| + // |module_process_thread_|. |
| + // |worker_queue| is defined last to ensure all pending tasks are cancelled |
| + // and deleted before any other members. |
| + rtc::TaskQueue worker_queue_; |
| RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
| }; |
| @@ -235,7 +240,8 @@ Call::Call(const Call::Config& config) |
| remb_(clock_), |
| congestion_controller_( |
| new CongestionController(clock_, this, &remb_, event_log_.get())), |
| - video_send_delay_stats_(new SendDelayStats(clock_)) { |
| + video_send_delay_stats_(new SendDelayStats(clock_)), |
| + worker_queue_("worker_queue") { |
|
pbos-webrtc
2016/07/13 12:35:38
call_worker_queue or something tying it to call?
perkj_webrtc
2016/07/14 10:11:27
Done.
|
| RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| @@ -265,7 +271,10 @@ Call::Call(const Call::Config& config) |
| Call::~Call() { |
| RTC_DCHECK(!remb_.InUse()); |
| RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| - UpdateSendHistograms(); |
| + { |
| + rtc::CritScope lock(&bitrate_crit_); |
| + UpdateSendHistograms(); |
| + } |
| UpdateReceiveHistograms(); |
| RTC_CHECK(audio_send_ssrcs_.empty()); |
| RTC_CHECK(video_send_ssrcs_.empty()); |
| @@ -419,22 +428,28 @@ void Call::DestroyAudioReceiveStream( |
| } |
| webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| - const webrtc::VideoSendStream::Config& config, |
| - const VideoEncoderConfig& encoder_config) { |
| + webrtc::VideoSendStream::Config config, |
| + VideoEncoderConfig encoder_config) { |
| TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
| RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| video_send_delay_stats_->AddSsrcs(config); |
| + event_log_->LogVideoSendStreamConfig(config); |
| + |
| // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
| // the call has already started. |
| + // Copy ssrcs from |config| since |config| is moved. |
| + std::vector<uint32_t> ssrcs = config.rtp.ssrcs; |
| VideoSendStream* send_stream = new VideoSendStream( |
| - num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), |
| - congestion_controller_.get(), bitrate_allocator_.get(), |
| - video_send_delay_stats_.get(), &remb_, event_log_.get(), config, |
| - encoder_config, suspended_video_send_ssrcs_); |
| + num_cpu_cores_, module_process_thread_.get(), &worker_queue_, |
| + call_stats_.get(), congestion_controller_.get(), bitrate_allocator_.get(), |
| + video_send_delay_stats_.get(), &remb_, event_log_.get(), |
| + std::move(config), std::move(encoder_config), |
| + suspended_video_send_ssrcs_); |
| + |
| { |
| WriteLockScoped write_lock(*send_crit_); |
| - for (uint32_t ssrc : config.rtp.ssrcs) { |
| + for (uint32_t ssrc : ssrcs) { |
| RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
| video_send_ssrcs_[ssrc] = send_stream; |
| } |
| @@ -442,7 +457,7 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| } |
| send_stream->SignalNetworkState(video_network_state_); |
| UpdateAggregateNetworkState(); |
| - event_log_->LogVideoSendStreamConfig(config); |
| + |
| return send_stream; |
| } |
| @@ -469,11 +484,11 @@ void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
| } |
| RTC_CHECK(send_stream_impl != nullptr); |
| - VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); |
| + VideoSendStream::RtpStateMap rtp_state = |
| + send_stream_impl->StopPermanentlyAndGetRtpStates(); |
| for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); |
| - it != rtp_state.end(); |
| - ++it) { |
| + it != rtp_state.end(); ++it) { |
| suspended_video_send_ssrcs_[it->first] = it->second; |
| } |
| @@ -703,6 +718,15 @@ void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
| void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, |
| int64_t rtt_ms) { |
| + // TODO(perkj): Consider making sure CongestionController operates on |
| + // |worker_queue_|. |
| + if (!worker_queue_.IsCurrent()) { |
| + worker_queue_.PostTask([this, target_bitrate_bps, fraction_loss, rtt_ms] { |
| + OnNetworkChanged(target_bitrate_bps, fraction_loss, rtt_ms); |
| + }); |
| + return; |
| + } |
| + RTC_DCHECK_RUN_ON(&worker_queue_); |
| bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, |
| rtt_ms); |