OLD | NEW |
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 Loading... |
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // thread. Re-enable once that is fixed. | 190 // thread. Re-enable once that is fixed. |
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); |
| 200 if (!network_enabled_) |
| 201 send_stream->SignalNetworkState(kNetworkDown); |
204 { | 202 { |
205 rtc::CritScope lock(&network_enabled_crit_); | |
206 WriteLockScoped write_lock(*send_crit_); | 203 WriteLockScoped write_lock(*send_crit_); |
207 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == | 204 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == |
208 audio_send_ssrcs_.end()); | 205 audio_send_ssrcs_.end()); |
209 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; | 206 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; |
210 | |
211 if (!network_enabled_) | |
212 send_stream->SignalNetworkState(kNetworkDown); | |
213 } | 207 } |
214 return send_stream; | 208 return send_stream; |
215 } | 209 } |
216 | 210 |
217 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { | 211 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
218 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); | 212 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); |
219 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 213 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
220 RTC_DCHECK(send_stream != nullptr); | 214 RTC_DCHECK(send_stream != nullptr); |
221 | 215 |
222 send_stream->Stop(); | 216 send_stream->Stop(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 271 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
278 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 272 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
279 | 273 |
280 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if | 274 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
281 // the call has already started. | 275 // the call has already started. |
282 VideoSendStream* send_stream = new VideoSendStream( | 276 VideoSendStream* send_stream = new VideoSendStream( |
283 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), | 277 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), |
284 congestion_controller_.get(), config, encoder_config, | 278 congestion_controller_.get(), config, encoder_config, |
285 suspended_video_send_ssrcs_); | 279 suspended_video_send_ssrcs_); |
286 | 280 |
287 // This needs to be taken before send_crit_ as both locks need to be held | 281 if (!network_enabled_) |
288 // while changing network state. | 282 send_stream->SignalNetworkState(kNetworkDown); |
289 rtc::CritScope lock(&network_enabled_crit_); | 283 |
290 WriteLockScoped write_lock(*send_crit_); | 284 WriteLockScoped write_lock(*send_crit_); |
291 for (uint32_t ssrc : config.rtp.ssrcs) { | 285 for (uint32_t ssrc : config.rtp.ssrcs) { |
292 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); | 286 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
293 video_send_ssrcs_[ssrc] = send_stream; | 287 video_send_ssrcs_[ssrc] = send_stream; |
294 } | 288 } |
295 video_send_streams_.insert(send_stream); | 289 video_send_streams_.insert(send_stream); |
296 | 290 |
297 if (event_log_) | 291 if (event_log_) |
298 event_log_->LogVideoSendStreamConfig(config); | 292 event_log_->LogVideoSendStreamConfig(config); |
299 | 293 |
300 if (!network_enabled_) | |
301 send_stream->SignalNetworkState(kNetworkDown); | |
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 Loading... |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |