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

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

Issue 1409193003: Remove network_enabled_crit_ in call.cc. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void ConfigureSync(const std::string& sync_group) 94 void ConfigureSync(const std::string& sync_group)
95 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); 95 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
96 96
97 const int num_cpu_cores_; 97 const int num_cpu_cores_;
98 const rtc::scoped_ptr<ProcessThread> module_process_thread_; 98 const rtc::scoped_ptr<ProcessThread> module_process_thread_;
99 const rtc::scoped_ptr<CallStats> call_stats_; 99 const rtc::scoped_ptr<CallStats> call_stats_;
100 const rtc::scoped_ptr<CongestionController> congestion_controller_; 100 const rtc::scoped_ptr<CongestionController> congestion_controller_;
101 Call::Config config_; 101 Call::Config config_;
102 rtc::ThreadChecker configuration_thread_checker_; 102 rtc::ThreadChecker configuration_thread_checker_;
103 103
104 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This 104 bool network_enabled_;
105 // ensures that we have a consistent network state signalled to all senders
106 // and receivers.
107 rtc::CriticalSection network_enabled_crit_;
108 bool network_enabled_ GUARDED_BY(network_enabled_crit_);
109 105
110 rtc::scoped_ptr<RWLockWrapper> receive_crit_; 106 rtc::scoped_ptr<RWLockWrapper> receive_crit_;
111 // Audio and Video receive streams are owned by the client that creates them. 107 // Audio and Video receive streams are owned by the client that creates them.
112 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ 108 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_
113 GUARDED_BY(receive_crit_); 109 GUARDED_BY(receive_crit_);
114 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ 110 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_
115 GUARDED_BY(receive_crit_); 111 GUARDED_BY(receive_crit_);
116 std::set<VideoReceiveStream*> video_receive_streams_ 112 std::set<VideoReceiveStream*> video_receive_streams_
117 GUARDED_BY(receive_crit_); 113 GUARDED_BY(receive_crit_);
118 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ 114 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 191 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
196 return this; 192 return this;
197 } 193 }
198 194
199 webrtc::AudioSendStream* Call::CreateAudioSendStream( 195 webrtc::AudioSendStream* Call::CreateAudioSendStream(
200 const webrtc::AudioSendStream::Config& config) { 196 const webrtc::AudioSendStream::Config& config) {
201 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); 197 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream");
202 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 198 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
203 AudioSendStream* send_stream = new AudioSendStream(config); 199 AudioSendStream* send_stream = new AudioSendStream(config);
204 { 200 {
205 rtc::CritScope lock(&network_enabled_crit_);
206 WriteLockScoped write_lock(*send_crit_); 201 WriteLockScoped write_lock(*send_crit_);
207 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == 202 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) ==
208 audio_send_ssrcs_.end()); 203 audio_send_ssrcs_.end());
209 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; 204 audio_send_ssrcs_[config.rtp.ssrc] = send_stream;
210 205
211 if (!network_enabled_) 206 if (!network_enabled_)
pbos-webrtc 2015/10/22 15:19:11 Do this outside write_lock.
mflodman 2015/10/22 15:26:15 Done.
212 send_stream->SignalNetworkState(kNetworkDown); 207 send_stream->SignalNetworkState(kNetworkDown);
213 } 208 }
214 return send_stream; 209 return send_stream;
215 } 210 }
216 211
217 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { 212 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) {
218 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); 213 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream");
219 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 214 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
220 RTC_DCHECK(send_stream != nullptr); 215 RTC_DCHECK(send_stream != nullptr);
221 216
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); 272 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream");
278 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 273 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
279 274
280 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if 275 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if
281 // the call has already started. 276 // the call has already started.
282 VideoSendStream* send_stream = new VideoSendStream( 277 VideoSendStream* send_stream = new VideoSendStream(
283 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), 278 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(),
284 congestion_controller_.get(), config, encoder_config, 279 congestion_controller_.get(), config, encoder_config,
285 suspended_video_send_ssrcs_); 280 suspended_video_send_ssrcs_);
286 281
287 // This needs to be taken before send_crit_ as both locks need to be held
288 // while changing network state.
289 rtc::CritScope lock(&network_enabled_crit_);
290 WriteLockScoped write_lock(*send_crit_); 282 WriteLockScoped write_lock(*send_crit_);
291 for (uint32_t ssrc : config.rtp.ssrcs) { 283 for (uint32_t ssrc : config.rtp.ssrcs) {
292 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); 284 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end());
293 video_send_ssrcs_[ssrc] = send_stream; 285 video_send_ssrcs_[ssrc] = send_stream;
294 } 286 }
295 video_send_streams_.insert(send_stream); 287 video_send_streams_.insert(send_stream);
296 288
297 if (event_log_) 289 if (event_log_)
298 event_log_->LogVideoSendStreamConfig(config); 290 event_log_->LogVideoSendStreamConfig(config);
299 291
300 if (!network_enabled_) 292 if (!network_enabled_)
301 send_stream->SignalNetworkState(kNetworkDown); 293 send_stream->SignalNetworkState(kNetworkDown);
pbos-webrtc 2015/10/22 15:19:10 Do this before taking write_lock.
mflodman 2015/10/22 15:26:15 Done.
302 return send_stream; 294 return send_stream;
303 } 295 }
304 296
305 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { 297 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
306 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); 298 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream");
307 RTC_DCHECK(send_stream != nullptr); 299 RTC_DCHECK(send_stream != nullptr);
308 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 300 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
309 301
310 send_stream->Stop(); 302 send_stream->Stop();
311 303
(...skipping 25 matching lines...) Expand all
337 } 329 }
338 330
339 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( 331 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream(
340 const webrtc::VideoReceiveStream::Config& config) { 332 const webrtc::VideoReceiveStream::Config& config) {
341 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); 333 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream");
342 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 334 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
343 VideoReceiveStream* receive_stream = new VideoReceiveStream( 335 VideoReceiveStream* receive_stream = new VideoReceiveStream(
344 num_cpu_cores_, congestion_controller_.get(), config, 336 num_cpu_cores_, congestion_controller_.get(), config,
345 config_.voice_engine, module_process_thread_.get(), call_stats_.get()); 337 config_.voice_engine, module_process_thread_.get(), call_stats_.get());
346 338
347 // This needs to be taken before receive_crit_ as both locks need to be held
348 // while changing network state.
349 rtc::CritScope lock(&network_enabled_crit_);
350 WriteLockScoped write_lock(*receive_crit_); 339 WriteLockScoped write_lock(*receive_crit_);
351 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == 340 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
352 video_receive_ssrcs_.end()); 341 video_receive_ssrcs_.end());
353 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; 342 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
354 // TODO(pbos): Configure different RTX payloads per receive payload. 343 // TODO(pbos): Configure different RTX payloads per receive payload.
355 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = 344 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it =
356 config.rtp.rtx.begin(); 345 config.rtp.rtx.begin();
357 if (it != config.rtp.rtx.end()) 346 if (it != config.rtp.rtx.end())
358 video_receive_ssrcs_[it->second.ssrc] = receive_stream; 347 video_receive_ssrcs_[it->second.ssrc] = receive_stream;
359 video_receive_streams_.insert(receive_stream); 348 video_receive_streams_.insert(receive_stream);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 return; 432 return;
444 } 433 }
445 config_.bitrate_config = bitrate_config; 434 config_.bitrate_config = bitrate_config;
446 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, 435 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps,
447 bitrate_config.start_bitrate_bps, 436 bitrate_config.start_bitrate_bps,
448 bitrate_config.max_bitrate_bps); 437 bitrate_config.max_bitrate_bps);
449 } 438 }
450 439
451 void Call::SignalNetworkState(NetworkState state) { 440 void Call::SignalNetworkState(NetworkState state) {
452 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 441 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
453 // Take crit for entire function, it needs to be held while updating streams
454 // to guarantee a consistent state across streams.
455 rtc::CritScope lock(&network_enabled_crit_);
456 network_enabled_ = state == kNetworkUp; 442 network_enabled_ = state == kNetworkUp;
457 congestion_controller_->SignalNetworkState(state); 443 congestion_controller_->SignalNetworkState(state);
458 { 444 {
459 ReadLockScoped write_lock(*send_crit_); 445 ReadLockScoped write_lock(*send_crit_);
460 for (auto& kv : audio_send_ssrcs_) { 446 for (auto& kv : audio_send_ssrcs_) {
461 kv.second->SignalNetworkState(state); 447 kv.second->SignalNetworkState(state);
462 } 448 }
463 for (auto& kv : video_send_ssrcs_) { 449 for (auto& kv : video_send_ssrcs_) {
464 kv.second->SignalNetworkState(state); 450 kv.second->SignalNetworkState(state);
465 } 451 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 // thread. Then this check can be enabled. 588 // thread. Then this check can be enabled.
603 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); 589 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread());
604 if (RtpHeaderParser::IsRtcp(packet, length)) 590 if (RtpHeaderParser::IsRtcp(packet, length))
605 return DeliverRtcp(media_type, packet, length); 591 return DeliverRtcp(media_type, packet, length);
606 592
607 return DeliverRtp(media_type, packet, length, packet_time); 593 return DeliverRtp(media_type, packet, length, packet_time);
608 } 594 }
609 595
610 } // namespace internal 596 } // namespace internal
611 } // namespace webrtc 597 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698