OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 } | 374 } |
375 } | 375 } |
376 | 376 |
377 } // namespace | 377 } // namespace |
378 | 378 |
379 namespace webrtc { | 379 namespace webrtc { |
380 | 380 |
381 // Factory class for creating remote MediaStreams and MediaStreamTracks. | 381 // Factory class for creating remote MediaStreams and MediaStreamTracks. |
382 class RemoteMediaStreamFactory { | 382 class RemoteMediaStreamFactory { |
383 public: | 383 public: |
384 explicit RemoteMediaStreamFactory(rtc::Thread* signaling_thread, | 384 explicit RemoteMediaStreamFactory(rtc::Thread* signaling_thread) |
385 rtc::Thread* worker_thread) | 385 : signaling_thread_(signaling_thread) {} |
386 : signaling_thread_(signaling_thread), | |
387 worker_thread_(worker_thread) {} | |
388 | 386 |
389 rtc::scoped_refptr<MediaStreamInterface> CreateMediaStream( | 387 rtc::scoped_refptr<MediaStreamInterface> CreateMediaStream( |
390 const std::string& stream_label) { | 388 const std::string& stream_label) { |
391 return MediaStreamProxy::Create(signaling_thread_, | 389 return MediaStreamProxy::Create(signaling_thread_, |
392 MediaStream::Create(stream_label)); | 390 MediaStream::Create(stream_label)); |
393 } | 391 } |
394 | 392 |
395 AudioTrackInterface* AddAudioTrack(uint32_t ssrc, | 393 AudioTrackInterface* AddAudioTrack(uint32_t ssrc, |
396 AudioProviderInterface* provider, | 394 AudioProviderInterface* provider, |
397 webrtc::MediaStreamInterface* stream, | 395 webrtc::MediaStreamInterface* stream, |
398 const std::string& track_id) { | 396 const std::string& track_id) { |
399 return AddTrack<AudioTrackInterface, AudioTrack, AudioTrackProxy>( | 397 return AddTrack<AudioTrackInterface, AudioTrack, AudioTrackProxy>( |
400 stream, track_id, RemoteAudioSource::Create(ssrc, provider)); | 398 stream, track_id, RemoteAudioSource::Create(ssrc, provider)); |
401 } | 399 } |
402 | 400 |
403 VideoTrackInterface* AddVideoTrack(webrtc::MediaStreamInterface* stream, | |
404 const std::string& track_id) { | |
405 return AddTrack<VideoTrackInterface, VideoTrack, VideoTrackProxy>( | |
406 stream, track_id, | |
407 VideoCapturerTrackSource::Create( | |
408 worker_thread_, new RemoteVideoCapturer(), nullptr, true) | |
409 .get()); | |
410 } | |
411 | |
412 private: | 401 private: |
413 template <typename TI, typename T, typename TP, typename S> | 402 template <typename TI, typename T, typename TP, typename S> |
414 TI* AddTrack(MediaStreamInterface* stream, | 403 TI* AddTrack(MediaStreamInterface* stream, |
415 const std::string& track_id, | 404 const std::string& track_id, |
416 const S& source) { | 405 const S& source) { |
417 rtc::scoped_refptr<TI> track( | 406 rtc::scoped_refptr<TI> track( |
418 TP::Create(signaling_thread_, T::Create(track_id, source))); | 407 TP::Create(signaling_thread_, T::Create(track_id, source))); |
419 track->set_state(webrtc::MediaStreamTrackInterface::kLive); | 408 track->set_state(webrtc::MediaStreamTrackInterface::kLive); |
420 if (stream->AddTrack(track)) { | 409 if (stream->AddTrack(track)) { |
421 return track; | 410 return track; |
422 } | 411 } |
423 return nullptr; | 412 return nullptr; |
424 } | 413 } |
425 | 414 |
426 rtc::Thread* signaling_thread_; | 415 rtc::Thread* signaling_thread_; |
427 rtc::Thread* worker_thread_; | |
428 }; | 416 }; |
429 | 417 |
430 bool ExtractMediaSessionOptions( | 418 bool ExtractMediaSessionOptions( |
431 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 419 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
432 cricket::MediaSessionOptions* session_options) { | 420 cricket::MediaSessionOptions* session_options) { |
433 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; | 421 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
434 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || | 422 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || |
435 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { | 423 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { |
436 return false; | 424 return false; |
437 } | 425 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | 592 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
605 LOG(LS_INFO) << "TCP candidates are disabled."; | 593 LOG(LS_INFO) << "TCP candidates are disabled."; |
606 } | 594 } |
607 | 595 |
608 port_allocator_->set_flags(portallocator_flags); | 596 port_allocator_->set_flags(portallocator_flags); |
609 // No step delay is used while allocating ports. | 597 // No step delay is used while allocating ports. |
610 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); | 598 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
611 | 599 |
612 media_controller_.reset(factory_->CreateMediaController(media_config)); | 600 media_controller_.reset(factory_->CreateMediaController(media_config)); |
613 | 601 |
614 remote_stream_factory_.reset(new RemoteMediaStreamFactory( | 602 remote_stream_factory_.reset( |
615 factory_->signaling_thread(), factory_->worker_thread())); | 603 new RemoteMediaStreamFactory(factory_->signaling_thread())); |
616 | 604 |
617 session_.reset( | 605 session_.reset( |
618 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), | 606 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), |
619 factory_->worker_thread(), port_allocator_.get())); | 607 factory_->worker_thread(), port_allocator_.get())); |
620 stats_.reset(new StatsCollector(this)); | 608 stats_.reset(new StatsCollector(this)); |
621 | 609 |
622 // Initialize the WebRtcSession. It creates transport channels etc. | 610 // Initialize the WebRtcSession. It creates transport channels etc. |
623 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store), | 611 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store), |
624 configuration)) { | 612 configuration)) { |
625 return false; | 613 return false; |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1317 } | 1305 } |
1318 | 1306 |
1319 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, | 1307 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, |
1320 AudioTrackInterface* audio_track, | 1308 AudioTrackInterface* audio_track, |
1321 uint32_t ssrc) { | 1309 uint32_t ssrc) { |
1322 receivers_.push_back(RtpReceiverProxy::Create( | 1310 receivers_.push_back(RtpReceiverProxy::Create( |
1323 signaling_thread(), | 1311 signaling_thread(), |
1324 new AudioRtpReceiver(audio_track, ssrc, session_.get()))); | 1312 new AudioRtpReceiver(audio_track, ssrc, session_.get()))); |
1325 } | 1313 } |
1326 | 1314 |
1327 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, | 1315 VideoRtpReceiver* PeerConnection::CreateVideoReceiver( |
1328 VideoTrackInterface* video_track, | 1316 const std::string& track_id, |
1329 uint32_t ssrc) { | 1317 uint32_t ssrc) { |
1330 receivers_.push_back(RtpReceiverProxy::Create( | 1318 VideoRtpReceiver* video_receiver = new VideoRtpReceiver( |
1331 signaling_thread(), | 1319 track_id, factory_->worker_thread(), ssrc, session_.get()); |
1332 new VideoRtpReceiver(video_track, ssrc, session_.get()))); | 1320 // RtpReceiverProxy takes ownership of |video_receiver|; |
1321 receivers_.push_back( | |
1322 RtpReceiverProxy::Create(signaling_thread(), video_receiver)); | |
1323 return video_receiver; | |
pthatcher1
2016/03/09 18:16:49
Why do we keep ownership of the proxy but then ret
perkj_webrtc
2016/03/09 21:22:59
That is my attempt to avoid a static cast and to b
Taylor Brandstetter
2016/03/09 22:10:41
I assume you mean "return an RtpReceiverInterface"
perkj_webrtc
2016/03/10 00:26:38
that is a very good idea.
| |
1333 } | 1324 } |
1334 | 1325 |
1335 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote | 1326 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote |
1336 // description. | 1327 // description. |
1337 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, | 1328 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, |
1338 AudioTrackInterface* audio_track) { | 1329 AudioTrackInterface* audio_track) { |
1339 auto it = FindReceiverForTrack(audio_track); | 1330 auto it = FindReceiverForTrack(audio_track); |
1340 if (it == receivers_.end()) { | 1331 if (it == receivers_.end()) { |
1341 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id() | 1332 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id() |
1342 << " doesn't exist."; | 1333 << " doesn't exist."; |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1670 const std::string& track_id, | 1661 const std::string& track_id, |
1671 uint32_t ssrc, | 1662 uint32_t ssrc, |
1672 cricket::MediaType media_type) { | 1663 cricket::MediaType media_type) { |
1673 MediaStreamInterface* stream = remote_streams_->find(stream_label); | 1664 MediaStreamInterface* stream = remote_streams_->find(stream_label); |
1674 | 1665 |
1675 if (media_type == cricket::MEDIA_TYPE_AUDIO) { | 1666 if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
1676 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack( | 1667 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack( |
1677 ssrc, session_.get(), stream, track_id); | 1668 ssrc, session_.get(), stream, track_id); |
1678 CreateAudioReceiver(stream, audio_track, ssrc); | 1669 CreateAudioReceiver(stream, audio_track, ssrc); |
1679 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 1670 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
1680 VideoTrackInterface* video_track = | 1671 VideoRtpReceiver* receiver = CreateVideoReceiver(track_id, ssrc); |
1681 remote_stream_factory_->AddVideoTrack(stream, track_id); | 1672 stream->AddTrack(receiver->video_track()); |
1682 CreateVideoReceiver(stream, video_track, ssrc); | |
1683 } else { | 1673 } else { |
1684 RTC_DCHECK(false && "Invalid media type"); | 1674 RTC_DCHECK(false && "Invalid media type"); |
1685 } | 1675 } |
1686 } | 1676 } |
1687 | 1677 |
1688 void PeerConnection::OnRemoteTrackRemoved(const std::string& stream_label, | 1678 void PeerConnection::OnRemoteTrackRemoved(const std::string& stream_label, |
1689 const std::string& track_id, | 1679 const std::string& track_id, |
1690 cricket::MediaType media_type) { | 1680 cricket::MediaType media_type) { |
1691 MediaStreamInterface* stream = remote_streams_->find(stream_label); | 1681 MediaStreamInterface* stream = remote_streams_->find(stream_label); |
1692 | 1682 |
1693 if (media_type == cricket::MEDIA_TYPE_AUDIO) { | 1683 if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
1694 rtc::scoped_refptr<AudioTrackInterface> audio_track = | 1684 rtc::scoped_refptr<AudioTrackInterface> audio_track = |
1695 stream->FindAudioTrack(track_id); | 1685 stream->FindAudioTrack(track_id); |
1696 if (audio_track) { | 1686 if (audio_track) { |
1697 audio_track->set_state(webrtc::MediaStreamTrackInterface::kEnded); | 1687 audio_track->set_state(webrtc::MediaStreamTrackInterface::kEnded); |
1698 stream->RemoveTrack(audio_track); | 1688 stream->RemoveTrack(audio_track); |
1699 DestroyAudioReceiver(stream, audio_track); | 1689 DestroyAudioReceiver(stream, audio_track); |
1700 } | 1690 } |
1701 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 1691 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
1702 rtc::scoped_refptr<VideoTrackInterface> video_track = | 1692 rtc::scoped_refptr<VideoTrackInterface> video_track = |
1703 stream->FindVideoTrack(track_id); | 1693 stream->FindVideoTrack(track_id); |
1704 if (video_track) { | 1694 if (video_track) { |
1705 video_track->set_state(webrtc::MediaStreamTrackInterface::kEnded); | |
1706 stream->RemoveTrack(video_track); | 1695 stream->RemoveTrack(video_track); |
1707 DestroyVideoReceiver(stream, video_track); | 1696 DestroyVideoReceiver(stream, video_track); |
pthatcher1
2016/03/09 18:16:49
Can you put a comment here saying "Stopping or des
perkj_webrtc
2016/03/09 21:22:59
Done.
| |
1708 } | 1697 } |
1709 } else { | 1698 } else { |
1710 ASSERT(false && "Invalid media type"); | 1699 ASSERT(false && "Invalid media type"); |
1711 } | 1700 } |
1712 } | 1701 } |
1713 | 1702 |
1714 void PeerConnection::UpdateEndedRemoteMediaStreams() { | 1703 void PeerConnection::UpdateEndedRemoteMediaStreams() { |
1715 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_to_remove; | 1704 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_to_remove; |
1716 for (size_t i = 0; i < remote_streams_->count(); ++i) { | 1705 for (size_t i = 0; i < remote_streams_->count(); ++i) { |
1717 MediaStreamInterface* stream = remote_streams_->at(i); | 1706 MediaStreamInterface* stream = remote_streams_->at(i); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2112 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2101 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
2113 for (const auto& channel : sctp_data_channels_) { | 2102 for (const auto& channel : sctp_data_channels_) { |
2114 if (channel->id() == sid) { | 2103 if (channel->id() == sid) { |
2115 return channel; | 2104 return channel; |
2116 } | 2105 } |
2117 } | 2106 } |
2118 return nullptr; | 2107 return nullptr; |
2119 } | 2108 } |
2120 | 2109 |
2121 } // namespace webrtc | 2110 } // namespace webrtc |
OLD | NEW |