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

Side by Side Diff: webrtc/api/peerconnection.cc

Issue 1765423005: Change VideoRtpReceiver to create remote VideoTrack and VideoTrackSource. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed up the comments. Created 4 years, 9 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 | « webrtc/api/peerconnection.h ('k') | webrtc/api/remotevideocapturer.h » ('j') | 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 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
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
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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream,
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 stream, track_id, factory_->worker_thread(), ssrc, session_.get());
1332 new VideoRtpReceiver(video_track, ssrc, session_.get()))); 1320 receivers_.push_back(
1321 RtpReceiverProxy::Create(signaling_thread(), video_receiver));
1333 } 1322 }
1334 1323
1335 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote 1324 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote
1336 // description. 1325 // description.
1337 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, 1326 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream,
1338 AudioTrackInterface* audio_track) { 1327 AudioTrackInterface* audio_track) {
1339 auto it = FindReceiverForTrack(audio_track); 1328 auto it = FindReceiverForTrack(audio_track);
1340 if (it == receivers_.end()) { 1329 if (it == receivers_.end()) {
1341 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id() 1330 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id()
1342 << " doesn't exist."; 1331 << " doesn't exist.";
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 const std::string& track_id, 1659 const std::string& track_id,
1671 uint32_t ssrc, 1660 uint32_t ssrc,
1672 cricket::MediaType media_type) { 1661 cricket::MediaType media_type) {
1673 MediaStreamInterface* stream = remote_streams_->find(stream_label); 1662 MediaStreamInterface* stream = remote_streams_->find(stream_label);
1674 1663
1675 if (media_type == cricket::MEDIA_TYPE_AUDIO) { 1664 if (media_type == cricket::MEDIA_TYPE_AUDIO) {
1676 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack( 1665 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack(
1677 ssrc, session_.get(), stream, track_id); 1666 ssrc, session_.get(), stream, track_id);
1678 CreateAudioReceiver(stream, audio_track, ssrc); 1667 CreateAudioReceiver(stream, audio_track, ssrc);
1679 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { 1668 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
1680 VideoTrackInterface* video_track = 1669 CreateVideoReceiver(stream, track_id, ssrc);
1681 remote_stream_factory_->AddVideoTrack(stream, track_id);
1682 CreateVideoReceiver(stream, video_track, ssrc);
1683 } else { 1670 } else {
1684 RTC_DCHECK(false && "Invalid media type"); 1671 RTC_DCHECK(false && "Invalid media type");
1685 } 1672 }
1686 } 1673 }
1687 1674
1688 void PeerConnection::OnRemoteTrackRemoved(const std::string& stream_label, 1675 void PeerConnection::OnRemoteTrackRemoved(const std::string& stream_label,
1689 const std::string& track_id, 1676 const std::string& track_id,
1690 cricket::MediaType media_type) { 1677 cricket::MediaType media_type) {
1691 MediaStreamInterface* stream = remote_streams_->find(stream_label); 1678 MediaStreamInterface* stream = remote_streams_->find(stream_label);
1692 1679
1693 if (media_type == cricket::MEDIA_TYPE_AUDIO) { 1680 if (media_type == cricket::MEDIA_TYPE_AUDIO) {
1694 rtc::scoped_refptr<AudioTrackInterface> audio_track = 1681 rtc::scoped_refptr<AudioTrackInterface> audio_track =
1695 stream->FindAudioTrack(track_id); 1682 stream->FindAudioTrack(track_id);
1696 if (audio_track) { 1683 if (audio_track) {
1697 audio_track->set_state(webrtc::MediaStreamTrackInterface::kEnded); 1684 audio_track->set_state(webrtc::MediaStreamTrackInterface::kEnded);
1698 stream->RemoveTrack(audio_track); 1685 stream->RemoveTrack(audio_track);
1699 DestroyAudioReceiver(stream, audio_track); 1686 DestroyAudioReceiver(stream, audio_track);
1700 } 1687 }
1701 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { 1688 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
1702 rtc::scoped_refptr<VideoTrackInterface> video_track = 1689 rtc::scoped_refptr<VideoTrackInterface> video_track =
1703 stream->FindVideoTrack(track_id); 1690 stream->FindVideoTrack(track_id);
1704 if (video_track) { 1691 if (video_track) {
1705 video_track->set_state(webrtc::MediaStreamTrackInterface::kEnded);
1706 stream->RemoveTrack(video_track); 1692 stream->RemoveTrack(video_track);
1693 // Stopping or destroying a VideoRtpReceiver will end the
1694 // VideoRtpReceiver::track().
1707 DestroyVideoReceiver(stream, video_track); 1695 DestroyVideoReceiver(stream, video_track);
1708 } 1696 }
1709 } else { 1697 } else {
1710 ASSERT(false && "Invalid media type"); 1698 ASSERT(false && "Invalid media type");
1711 } 1699 }
1712 } 1700 }
1713 1701
1714 void PeerConnection::UpdateEndedRemoteMediaStreams() { 1702 void PeerConnection::UpdateEndedRemoteMediaStreams() {
1715 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_to_remove; 1703 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_to_remove;
1716 for (size_t i = 0; i < remote_streams_->count(); ++i) { 1704 for (size_t i = 0; i < remote_streams_->count(); ++i) {
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2100 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2113 for (const auto& channel : sctp_data_channels_) { 2101 for (const auto& channel : sctp_data_channels_) {
2114 if (channel->id() == sid) { 2102 if (channel->id() == sid) {
2115 return channel; 2103 return channel;
2116 } 2104 }
2117 } 2105 }
2118 return nullptr; 2106 return nullptr;
2119 } 2107 }
2120 2108
2121 } // namespace webrtc 2109 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.h ('k') | webrtc/api/remotevideocapturer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698