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 27 matching lines...) Expand all Loading... |
38 #include "webrtc/media/sctp/sctpdataengine.h" | 38 #include "webrtc/media/sctp/sctpdataengine.h" |
39 #include "webrtc/pc/channelmanager.h" | 39 #include "webrtc/pc/channelmanager.h" |
40 #include "webrtc/system_wrappers/include/field_trial.h" | 40 #include "webrtc/system_wrappers/include/field_trial.h" |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 using webrtc::DataChannel; | 44 using webrtc::DataChannel; |
45 using webrtc::MediaConstraintsInterface; | 45 using webrtc::MediaConstraintsInterface; |
46 using webrtc::MediaStreamInterface; | 46 using webrtc::MediaStreamInterface; |
47 using webrtc::PeerConnectionInterface; | 47 using webrtc::PeerConnectionInterface; |
| 48 using webrtc::RtpSenderInternal; |
48 using webrtc::RtpSenderInterface; | 49 using webrtc::RtpSenderInterface; |
| 50 using webrtc::RtpSenderProxy; |
| 51 using webrtc::RtpSenderProxyWithInternal; |
49 using webrtc::StreamCollection; | 52 using webrtc::StreamCollection; |
50 | 53 |
51 static const char kDefaultStreamLabel[] = "default"; | 54 static const char kDefaultStreamLabel[] = "default"; |
52 static const char kDefaultAudioTrackLabel[] = "defaulta0"; | 55 static const char kDefaultAudioTrackLabel[] = "defaulta0"; |
53 static const char kDefaultVideoTrackLabel[] = "defaultv0"; | 56 static const char kDefaultVideoTrackLabel[] = "defaultv0"; |
54 | 57 |
55 // The min number of tokens must present in Turn host uri. | 58 // The min number of tokens must present in Turn host uri. |
56 // e.g. user@turn.example.org | 59 // e.g. user@turn.example.org |
57 static const size_t kTurnHostTokensNum = 2; | 60 static const size_t kTurnHostTokensNum = 2; |
58 // Number of tokens must be preset when TURN uri has transport param. | 61 // Number of tokens must be preset when TURN uri has transport param. |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 345 |
343 bool IsValidOfferToReceiveMedia(int value) { | 346 bool IsValidOfferToReceiveMedia(int value) { |
344 typedef PeerConnectionInterface::RTCOfferAnswerOptions Options; | 347 typedef PeerConnectionInterface::RTCOfferAnswerOptions Options; |
345 return (value >= Options::kUndefined) && | 348 return (value >= Options::kUndefined) && |
346 (value <= Options::kMaxOfferToReceiveMedia); | 349 (value <= Options::kMaxOfferToReceiveMedia); |
347 } | 350 } |
348 | 351 |
349 // Add the stream and RTP data channel info to |session_options|. | 352 // Add the stream and RTP data channel info to |session_options|. |
350 void AddSendStreams( | 353 void AddSendStreams( |
351 cricket::MediaSessionOptions* session_options, | 354 cricket::MediaSessionOptions* session_options, |
352 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, | 355 const std::vector<rtc::scoped_refptr< |
| 356 RtpSenderProxyWithInternal<RtpSenderInternal>>>& senders, |
353 const std::map<std::string, rtc::scoped_refptr<DataChannel>>& | 357 const std::map<std::string, rtc::scoped_refptr<DataChannel>>& |
354 rtp_data_channels) { | 358 rtp_data_channels) { |
355 session_options->streams.clear(); | 359 session_options->streams.clear(); |
356 for (const auto& sender : senders) { | 360 for (const auto& sender : senders) { |
357 session_options->AddSendStream(sender->media_type(), sender->id(), | 361 session_options->AddSendStream(sender->media_type(), sender->id(), |
358 sender->stream_id()); | 362 sender->internal()->stream_id()); |
359 } | 363 } |
360 | 364 |
361 // Check for data channels. | 365 // Check for data channels. |
362 for (const auto& kv : rtp_data_channels) { | 366 for (const auto& kv : rtp_data_channels) { |
363 const DataChannel* channel = kv.second; | 367 const DataChannel* channel = kv.second; |
364 if (channel->state() == DataChannel::kConnecting || | 368 if (channel->state() == DataChannel::kConnecting || |
365 channel->state() == DataChannel::kOpen) { | 369 channel->state() == DataChannel::kOpen) { |
366 // |streamid| and |sync_label| are both set to the DataChannel label | 370 // |streamid| and |sync_label| are both set to the DataChannel label |
367 // here so they can be signaled the same way as MediaStreams and Tracks. | 371 // here so they can be signaled the same way as MediaStreams and Tracks. |
368 // For MediaStreams, the sync_label is the MediaStream label and the | 372 // For MediaStreams, the sync_label is the MediaStream label and the |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 rtcp_cname_(GenerateRtcpCname()), | 544 rtcp_cname_(GenerateRtcpCname()), |
541 local_streams_(StreamCollection::Create()), | 545 local_streams_(StreamCollection::Create()), |
542 remote_streams_(StreamCollection::Create()) {} | 546 remote_streams_(StreamCollection::Create()) {} |
543 | 547 |
544 PeerConnection::~PeerConnection() { | 548 PeerConnection::~PeerConnection() { |
545 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); | 549 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); |
546 RTC_DCHECK(signaling_thread()->IsCurrent()); | 550 RTC_DCHECK(signaling_thread()->IsCurrent()); |
547 // Need to detach RTP senders/receivers from WebRtcSession, | 551 // Need to detach RTP senders/receivers from WebRtcSession, |
548 // since it's about to be destroyed. | 552 // since it's about to be destroyed. |
549 for (const auto& sender : senders_) { | 553 for (const auto& sender : senders_) { |
550 sender->Stop(); | 554 sender->internal()->Stop(); |
551 } | 555 } |
552 for (const auto& receiver : receivers_) { | 556 for (const auto& receiver : receivers_) { |
553 receiver->Stop(); | 557 receiver->internal()->Stop(); |
554 } | 558 } |
555 // Destroy stats_ because it depends on session_. | 559 // Destroy stats_ because it depends on session_. |
556 stats_.reset(nullptr); | 560 stats_.reset(nullptr); |
557 // Now destroy session_ before destroying other members, | 561 // Now destroy session_ before destroying other members, |
558 // because its destruction fires signals (such as VoiceChannelDestroyed) | 562 // because its destruction fires signals (such as VoiceChannelDestroyed) |
559 // which will trigger some final actions in PeerConnection... | 563 // which will trigger some final actions in PeerConnection... |
560 session_.reset(nullptr); | 564 session_.reset(nullptr); |
561 // port_allocator_ lives on the network thread and should be destroyed there. | 565 // port_allocator_ lives on the network thread and should be destroyed there. |
562 network_thread()->Invoke<void>([this] { port_allocator_.reset(nullptr); }); | 566 network_thread()->Invoke<void>([this] { port_allocator_.reset(nullptr); }); |
563 } | 567 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 << "Adding a track with two streams is not currently supported."; | 699 << "Adding a track with two streams is not currently supported."; |
696 return nullptr; | 700 return nullptr; |
697 } | 701 } |
698 // TODO(deadbeef): Support adding a track to two different senders. | 702 // TODO(deadbeef): Support adding a track to two different senders. |
699 if (FindSenderForTrack(track) != senders_.end()) { | 703 if (FindSenderForTrack(track) != senders_.end()) { |
700 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; | 704 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; |
701 return nullptr; | 705 return nullptr; |
702 } | 706 } |
703 | 707 |
704 // TODO(deadbeef): Support adding a track to multiple streams. | 708 // TODO(deadbeef): Support adding a track to multiple streams. |
705 rtc::scoped_refptr<RtpSenderInterface> new_sender; | 709 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender; |
706 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { | 710 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { |
707 new_sender = RtpSenderProxy::Create( | 711 new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
708 signaling_thread(), | 712 signaling_thread(), |
709 new AudioRtpSender(static_cast<AudioTrackInterface*>(track), | 713 new AudioRtpSender(static_cast<AudioTrackInterface*>(track), |
710 session_.get(), stats_.get())); | 714 session_.get(), stats_.get())); |
711 if (!streams.empty()) { | 715 if (!streams.empty()) { |
712 new_sender->set_stream_id(streams[0]->label()); | 716 new_sender->internal()->set_stream_id(streams[0]->label()); |
713 } | 717 } |
714 const TrackInfo* track_info = FindTrackInfo( | 718 const TrackInfo* track_info = FindTrackInfo( |
715 local_audio_tracks_, new_sender->stream_id(), track->id()); | 719 local_audio_tracks_, new_sender->internal()->stream_id(), track->id()); |
716 if (track_info) { | 720 if (track_info) { |
717 new_sender->SetSsrc(track_info->ssrc); | 721 new_sender->internal()->SetSsrc(track_info->ssrc); |
718 } | 722 } |
719 } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) { | 723 } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) { |
720 new_sender = RtpSenderProxy::Create( | 724 new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
721 signaling_thread(), | 725 signaling_thread(), |
722 new VideoRtpSender(static_cast<VideoTrackInterface*>(track), | 726 new VideoRtpSender(static_cast<VideoTrackInterface*>(track), |
723 session_.get())); | 727 session_.get())); |
724 if (!streams.empty()) { | 728 if (!streams.empty()) { |
725 new_sender->set_stream_id(streams[0]->label()); | 729 new_sender->internal()->set_stream_id(streams[0]->label()); |
726 } | 730 } |
727 const TrackInfo* track_info = FindTrackInfo( | 731 const TrackInfo* track_info = FindTrackInfo( |
728 local_video_tracks_, new_sender->stream_id(), track->id()); | 732 local_video_tracks_, new_sender->internal()->stream_id(), track->id()); |
729 if (track_info) { | 733 if (track_info) { |
730 new_sender->SetSsrc(track_info->ssrc); | 734 new_sender->internal()->SetSsrc(track_info->ssrc); |
731 } | 735 } |
732 } else { | 736 } else { |
733 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << track->kind(); | 737 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << track->kind(); |
734 return rtc::scoped_refptr<RtpSenderInterface>(); | 738 return rtc::scoped_refptr<RtpSenderInterface>(); |
735 } | 739 } |
736 | 740 |
737 senders_.push_back(new_sender); | 741 senders_.push_back(new_sender); |
738 observer_->OnRenegotiationNeeded(); | 742 observer_->OnRenegotiationNeeded(); |
739 return new_sender; | 743 return new_sender; |
740 } | 744 } |
741 | 745 |
742 bool PeerConnection::RemoveTrack(RtpSenderInterface* sender) { | 746 bool PeerConnection::RemoveTrack(RtpSenderInterface* sender) { |
743 TRACE_EVENT0("webrtc", "PeerConnection::RemoveTrack"); | 747 TRACE_EVENT0("webrtc", "PeerConnection::RemoveTrack"); |
744 if (IsClosed()) { | 748 if (IsClosed()) { |
745 return false; | 749 return false; |
746 } | 750 } |
747 | 751 |
748 auto it = std::find(senders_.begin(), senders_.end(), sender); | 752 auto it = std::find(senders_.begin(), senders_.end(), sender); |
749 if (it == senders_.end()) { | 753 if (it == senders_.end()) { |
750 LOG(LS_ERROR) << "Couldn't find sender " << sender->id() << " to remove."; | 754 LOG(LS_ERROR) << "Couldn't find sender " << sender->id() << " to remove."; |
751 return false; | 755 return false; |
752 } | 756 } |
753 (*it)->Stop(); | 757 (*it)->internal()->Stop(); |
754 senders_.erase(it); | 758 senders_.erase(it); |
755 | 759 |
756 observer_->OnRenegotiationNeeded(); | 760 observer_->OnRenegotiationNeeded(); |
757 return true; | 761 return true; |
758 } | 762 } |
759 | 763 |
760 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( | 764 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( |
761 AudioTrackInterface* track) { | 765 AudioTrackInterface* track) { |
762 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); | 766 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); |
763 if (!track) { | 767 if (!track) { |
(...skipping 11 matching lines...) Expand all Loading... |
775 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; | 779 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; |
776 return NULL; | 780 return NULL; |
777 } | 781 } |
778 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); | 782 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); |
779 } | 783 } |
780 | 784 |
781 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( | 785 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( |
782 const std::string& kind, | 786 const std::string& kind, |
783 const std::string& stream_id) { | 787 const std::string& stream_id) { |
784 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); | 788 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); |
785 rtc::scoped_refptr<RtpSenderInterface> new_sender; | 789 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender; |
786 if (kind == MediaStreamTrackInterface::kAudioKind) { | 790 if (kind == MediaStreamTrackInterface::kAudioKind) { |
787 new_sender = RtpSenderProxy::Create( | 791 new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
788 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); | 792 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); |
789 } else if (kind == MediaStreamTrackInterface::kVideoKind) { | 793 } else if (kind == MediaStreamTrackInterface::kVideoKind) { |
790 new_sender = RtpSenderProxy::Create(signaling_thread(), | 794 new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
791 new VideoRtpSender(session_.get())); | 795 signaling_thread(), new VideoRtpSender(session_.get())); |
792 } else { | 796 } else { |
793 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; | 797 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; |
794 return new_sender; | 798 return new_sender; |
795 } | 799 } |
796 if (!stream_id.empty()) { | 800 if (!stream_id.empty()) { |
797 new_sender->set_stream_id(stream_id); | 801 new_sender->internal()->set_stream_id(stream_id); |
798 } | 802 } |
799 senders_.push_back(new_sender); | 803 senders_.push_back(new_sender); |
800 return new_sender; | 804 return new_sender; |
801 } | 805 } |
802 | 806 |
803 std::vector<rtc::scoped_refptr<RtpSenderInterface>> PeerConnection::GetSenders() | 807 std::vector<rtc::scoped_refptr<RtpSenderInterface>> PeerConnection::GetSenders() |
804 const { | 808 const { |
805 return senders_; | 809 std::vector<rtc::scoped_refptr<RtpSenderInterface>> ret; |
| 810 for (const auto& sender : senders_) { |
| 811 ret.push_back(sender.get()); |
| 812 } |
| 813 return ret; |
806 } | 814 } |
807 | 815 |
808 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> | 816 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> |
809 PeerConnection::GetReceivers() const { | 817 PeerConnection::GetReceivers() const { |
810 return receivers_; | 818 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> ret; |
| 819 for (const auto& receiver : receivers_) { |
| 820 ret.push_back(receiver.get()); |
| 821 } |
| 822 return ret; |
811 } | 823 } |
812 | 824 |
813 bool PeerConnection::GetStats(StatsObserver* observer, | 825 bool PeerConnection::GetStats(StatsObserver* observer, |
814 MediaStreamTrackInterface* track, | 826 MediaStreamTrackInterface* track, |
815 StatsOutputLevel level) { | 827 StatsOutputLevel level) { |
816 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); | 828 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); |
817 RTC_DCHECK(signaling_thread()->IsCurrent()); | 829 RTC_DCHECK(signaling_thread()->IsCurrent()); |
818 if (!VERIFY(observer != NULL)) { | 830 if (!VERIFY(observer != NULL)) { |
819 LOG(LS_ERROR) << "GetStats - observer is NULL."; | 831 LOG(LS_ERROR) << "GetStats - observer is NULL."; |
820 return false; | 832 return false; |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 } | 1308 } |
1297 default: | 1309 default: |
1298 RTC_DCHECK(false && "Not implemented"); | 1310 RTC_DCHECK(false && "Not implemented"); |
1299 break; | 1311 break; |
1300 } | 1312 } |
1301 } | 1313 } |
1302 | 1314 |
1303 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, | 1315 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, |
1304 const std::string& track_id, | 1316 const std::string& track_id, |
1305 uint32_t ssrc) { | 1317 uint32_t ssrc) { |
1306 receivers_.push_back(RtpReceiverProxy::Create( | 1318 receivers_.push_back( |
1307 signaling_thread(), | 1319 RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( |
1308 new AudioRtpReceiver(stream, track_id, ssrc, session_.get()))); | 1320 signaling_thread(), |
| 1321 new AudioRtpReceiver(stream, track_id, ssrc, session_.get()))); |
1309 } | 1322 } |
1310 | 1323 |
1311 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, | 1324 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, |
1312 const std::string& track_id, | 1325 const std::string& track_id, |
1313 uint32_t ssrc) { | 1326 uint32_t ssrc) { |
1314 receivers_.push_back(RtpReceiverProxy::Create( | 1327 receivers_.push_back( |
1315 signaling_thread(), | 1328 RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( |
1316 new VideoRtpReceiver(stream, track_id, factory_->worker_thread(), ssrc, | 1329 signaling_thread(), |
1317 session_.get()))); | 1330 new VideoRtpReceiver(stream, track_id, factory_->worker_thread(), |
| 1331 ssrc, session_.get()))); |
1318 } | 1332 } |
1319 | 1333 |
1320 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote | 1334 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote |
1321 // description. | 1335 // description. |
1322 void PeerConnection::DestroyReceiver(const std::string& track_id) { | 1336 void PeerConnection::DestroyReceiver(const std::string& track_id) { |
1323 auto it = FindReceiverForTrack(track_id); | 1337 auto it = FindReceiverForTrack(track_id); |
1324 if (it == receivers_.end()) { | 1338 if (it == receivers_.end()) { |
1325 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_id | 1339 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_id |
1326 << " doesn't exist."; | 1340 << " doesn't exist."; |
1327 } else { | 1341 } else { |
1328 (*it)->Stop(); | 1342 (*it)->internal()->Stop(); |
1329 receivers_.erase(it); | 1343 receivers_.erase(it); |
1330 } | 1344 } |
1331 } | 1345 } |
1332 | 1346 |
1333 void PeerConnection::StopReceivers(cricket::MediaType media_type) { | 1347 void PeerConnection::StopReceivers(cricket::MediaType media_type) { |
1334 TrackInfos* current_tracks = GetRemoteTracks(media_type); | 1348 TrackInfos* current_tracks = GetRemoteTracks(media_type); |
1335 for (const auto& track_info : *current_tracks) { | 1349 for (const auto& track_info : *current_tracks) { |
1336 auto it = FindReceiverForTrack(track_info.track_id); | 1350 auto it = FindReceiverForTrack(track_info.track_id); |
1337 if (it == receivers_.end()) { | 1351 if (it == receivers_.end()) { |
1338 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_info.track_id | 1352 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_info.track_id |
1339 << " doesn't exist."; | 1353 << " doesn't exist."; |
1340 } else { | 1354 } else { |
1341 (*it)->Stop(); | 1355 (*it)->internal()->Stop(); |
1342 } | 1356 } |
1343 } | 1357 } |
1344 } | 1358 } |
1345 | 1359 |
1346 void PeerConnection::OnIceConnectionChange( | 1360 void PeerConnection::OnIceConnectionChange( |
1347 PeerConnectionInterface::IceConnectionState new_state) { | 1361 PeerConnectionInterface::IceConnectionState new_state) { |
1348 RTC_DCHECK(signaling_thread()->IsCurrent()); | 1362 RTC_DCHECK(signaling_thread()->IsCurrent()); |
1349 // After transitioning to "closed", ignore any additional states from | 1363 // After transitioning to "closed", ignore any additional states from |
1350 // WebRtcSession (such as "disconnected"). | 1364 // WebRtcSession (such as "disconnected"). |
1351 if (IsClosed()) { | 1365 if (IsClosed()) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 } | 1408 } |
1395 observer_->OnSignalingChange(signaling_state_); | 1409 observer_->OnSignalingChange(signaling_state_); |
1396 } | 1410 } |
1397 | 1411 |
1398 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, | 1412 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, |
1399 MediaStreamInterface* stream) { | 1413 MediaStreamInterface* stream) { |
1400 auto sender = FindSenderForTrack(track); | 1414 auto sender = FindSenderForTrack(track); |
1401 if (sender != senders_.end()) { | 1415 if (sender != senders_.end()) { |
1402 // We already have a sender for this track, so just change the stream_id | 1416 // We already have a sender for this track, so just change the stream_id |
1403 // so that it's correct in the next call to CreateOffer. | 1417 // so that it's correct in the next call to CreateOffer. |
1404 (*sender)->set_stream_id(stream->label()); | 1418 (*sender)->internal()->set_stream_id(stream->label()); |
1405 return; | 1419 return; |
1406 } | 1420 } |
1407 | 1421 |
1408 // Normal case; we've never seen this track before. | 1422 // Normal case; we've never seen this track before. |
1409 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( | 1423 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender = |
1410 signaling_thread(), | 1424 RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
1411 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get())); | 1425 signaling_thread(), new AudioRtpSender(track, stream->label(), |
| 1426 session_.get(), stats_.get())); |
1412 senders_.push_back(new_sender); | 1427 senders_.push_back(new_sender); |
1413 // If the sender has already been configured in SDP, we call SetSsrc, | 1428 // If the sender has already been configured in SDP, we call SetSsrc, |
1414 // which will connect the sender to the underlying transport. This can | 1429 // which will connect the sender to the underlying transport. This can |
1415 // occur if a local session description that contains the ID of the sender | 1430 // occur if a local session description that contains the ID of the sender |
1416 // is set before AddStream is called. It can also occur if the local | 1431 // is set before AddStream is called. It can also occur if the local |
1417 // session description is not changed and RemoveStream is called, and | 1432 // session description is not changed and RemoveStream is called, and |
1418 // later AddStream is called again with the same stream. | 1433 // later AddStream is called again with the same stream. |
1419 const TrackInfo* track_info = | 1434 const TrackInfo* track_info = |
1420 FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); | 1435 FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); |
1421 if (track_info) { | 1436 if (track_info) { |
1422 new_sender->SetSsrc(track_info->ssrc); | 1437 new_sender->internal()->SetSsrc(track_info->ssrc); |
1423 } | 1438 } |
1424 } | 1439 } |
1425 | 1440 |
1426 // TODO(deadbeef): Don't destroy RtpSenders here; they should be kept around | 1441 // TODO(deadbeef): Don't destroy RtpSenders here; they should be kept around |
1427 // indefinitely, when we have unified plan SDP. | 1442 // indefinitely, when we have unified plan SDP. |
1428 void PeerConnection::OnAudioTrackRemoved(AudioTrackInterface* track, | 1443 void PeerConnection::OnAudioTrackRemoved(AudioTrackInterface* track, |
1429 MediaStreamInterface* stream) { | 1444 MediaStreamInterface* stream) { |
1430 auto sender = FindSenderForTrack(track); | 1445 auto sender = FindSenderForTrack(track); |
1431 if (sender == senders_.end()) { | 1446 if (sender == senders_.end()) { |
1432 LOG(LS_WARNING) << "RtpSender for track with id " << track->id() | 1447 LOG(LS_WARNING) << "RtpSender for track with id " << track->id() |
1433 << " doesn't exist."; | 1448 << " doesn't exist."; |
1434 return; | 1449 return; |
1435 } | 1450 } |
1436 (*sender)->Stop(); | 1451 (*sender)->internal()->Stop(); |
1437 senders_.erase(sender); | 1452 senders_.erase(sender); |
1438 } | 1453 } |
1439 | 1454 |
1440 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, | 1455 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, |
1441 MediaStreamInterface* stream) { | 1456 MediaStreamInterface* stream) { |
1442 auto sender = FindSenderForTrack(track); | 1457 auto sender = FindSenderForTrack(track); |
1443 if (sender != senders_.end()) { | 1458 if (sender != senders_.end()) { |
1444 // We already have a sender for this track, so just change the stream_id | 1459 // We already have a sender for this track, so just change the stream_id |
1445 // so that it's correct in the next call to CreateOffer. | 1460 // so that it's correct in the next call to CreateOffer. |
1446 (*sender)->set_stream_id(stream->label()); | 1461 (*sender)->internal()->set_stream_id(stream->label()); |
1447 return; | 1462 return; |
1448 } | 1463 } |
1449 | 1464 |
1450 // Normal case; we've never seen this track before. | 1465 // Normal case; we've never seen this track before. |
1451 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( | 1466 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender = |
1452 signaling_thread(), | 1467 RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
1453 new VideoRtpSender(track, stream->label(), session_.get())); | 1468 signaling_thread(), |
| 1469 new VideoRtpSender(track, stream->label(), session_.get())); |
1454 senders_.push_back(new_sender); | 1470 senders_.push_back(new_sender); |
1455 const TrackInfo* track_info = | 1471 const TrackInfo* track_info = |
1456 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); | 1472 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); |
1457 if (track_info) { | 1473 if (track_info) { |
1458 new_sender->SetSsrc(track_info->ssrc); | 1474 new_sender->internal()->SetSsrc(track_info->ssrc); |
1459 } | 1475 } |
1460 } | 1476 } |
1461 | 1477 |
1462 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, | 1478 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, |
1463 MediaStreamInterface* stream) { | 1479 MediaStreamInterface* stream) { |
1464 auto sender = FindSenderForTrack(track); | 1480 auto sender = FindSenderForTrack(track); |
1465 if (sender == senders_.end()) { | 1481 if (sender == senders_.end()) { |
1466 LOG(LS_WARNING) << "RtpSender for track with id " << track->id() | 1482 LOG(LS_WARNING) << "RtpSender for track with id " << track->id() |
1467 << " doesn't exist."; | 1483 << " doesn't exist."; |
1468 return; | 1484 return; |
1469 } | 1485 } |
1470 (*sender)->Stop(); | 1486 (*sender)->internal()->Stop(); |
1471 senders_.erase(sender); | 1487 senders_.erase(sender); |
1472 } | 1488 } |
1473 | 1489 |
1474 void PeerConnection::PostSetSessionDescriptionFailure( | 1490 void PeerConnection::PostSetSessionDescriptionFailure( |
1475 SetSessionDescriptionObserver* observer, | 1491 SetSessionDescriptionObserver* observer, |
1476 const std::string& error) { | 1492 const std::string& error) { |
1477 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1493 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1478 msg->error = error; | 1494 msg->error = error; |
1479 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_FAILED, msg); | 1495 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_FAILED, msg); |
1480 } | 1496 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1762 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); | 1778 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); |
1763 OnLocalTrackSeen(stream_label, track_id, params.first_ssrc(), media_type); | 1779 OnLocalTrackSeen(stream_label, track_id, params.first_ssrc(), media_type); |
1764 } | 1780 } |
1765 } | 1781 } |
1766 } | 1782 } |
1767 | 1783 |
1768 void PeerConnection::OnLocalTrackSeen(const std::string& stream_label, | 1784 void PeerConnection::OnLocalTrackSeen(const std::string& stream_label, |
1769 const std::string& track_id, | 1785 const std::string& track_id, |
1770 uint32_t ssrc, | 1786 uint32_t ssrc, |
1771 cricket::MediaType media_type) { | 1787 cricket::MediaType media_type) { |
1772 RtpSenderInterface* sender = FindSenderById(track_id); | 1788 RtpSenderInternal* sender = FindSenderById(track_id); |
1773 if (!sender) { | 1789 if (!sender) { |
1774 LOG(LS_WARNING) << "An unknown RtpSender with id " << track_id | 1790 LOG(LS_WARNING) << "An unknown RtpSender with id " << track_id |
1775 << " has been configured in the local description."; | 1791 << " has been configured in the local description."; |
1776 return; | 1792 return; |
1777 } | 1793 } |
1778 | 1794 |
1779 if (sender->media_type() != media_type) { | 1795 if (sender->media_type() != media_type) { |
1780 LOG(LS_WARNING) << "An RtpSender has been configured in the local" | 1796 LOG(LS_WARNING) << "An RtpSender has been configured in the local" |
1781 << " description with an unexpected media type."; | 1797 << " description with an unexpected media type."; |
1782 return; | 1798 return; |
1783 } | 1799 } |
1784 | 1800 |
1785 sender->set_stream_id(stream_label); | 1801 sender->set_stream_id(stream_label); |
1786 sender->SetSsrc(ssrc); | 1802 sender->SetSsrc(ssrc); |
1787 } | 1803 } |
1788 | 1804 |
1789 void PeerConnection::OnLocalTrackRemoved(const std::string& stream_label, | 1805 void PeerConnection::OnLocalTrackRemoved(const std::string& stream_label, |
1790 const std::string& track_id, | 1806 const std::string& track_id, |
1791 uint32_t ssrc, | 1807 uint32_t ssrc, |
1792 cricket::MediaType media_type) { | 1808 cricket::MediaType media_type) { |
1793 RtpSenderInterface* sender = FindSenderById(track_id); | 1809 RtpSenderInternal* sender = FindSenderById(track_id); |
1794 if (!sender) { | 1810 if (!sender) { |
1795 // This is the normal case. I.e., RemoveStream has been called and the | 1811 // This is the normal case. I.e., RemoveStream has been called and the |
1796 // SessionDescriptions has been renegotiated. | 1812 // SessionDescriptions has been renegotiated. |
1797 return; | 1813 return; |
1798 } | 1814 } |
1799 | 1815 |
1800 // A sender has been removed from the SessionDescription but it's still | 1816 // A sender has been removed from the SessionDescription but it's still |
1801 // associated with the PeerConnection. This only occurs if the SDP doesn't | 1817 // associated with the PeerConnection. This only occurs if the SDP doesn't |
1802 // match with the calls to CreateSender, AddStream and RemoveStream. | 1818 // match with the calls to CreateSender, AddStream and RemoveStream. |
1803 if (sender->media_type() != media_type) { | 1819 if (sender->media_type() != media_type) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1887 void PeerConnection::CreateRemoteRtpDataChannel(const std::string& label, | 1903 void PeerConnection::CreateRemoteRtpDataChannel(const std::string& label, |
1888 uint32_t remote_ssrc) { | 1904 uint32_t remote_ssrc) { |
1889 rtc::scoped_refptr<DataChannel> channel( | 1905 rtc::scoped_refptr<DataChannel> channel( |
1890 InternalCreateDataChannel(label, nullptr)); | 1906 InternalCreateDataChannel(label, nullptr)); |
1891 if (!channel.get()) { | 1907 if (!channel.get()) { |
1892 LOG(LS_WARNING) << "Remote peer requested a DataChannel but" | 1908 LOG(LS_WARNING) << "Remote peer requested a DataChannel but" |
1893 << "CreateDataChannel failed."; | 1909 << "CreateDataChannel failed."; |
1894 return; | 1910 return; |
1895 } | 1911 } |
1896 channel->SetReceiveSsrc(remote_ssrc); | 1912 channel->SetReceiveSsrc(remote_ssrc); |
1897 auto proxy_channel = DataChannelProxy::Create(signaling_thread(), channel); | 1913 rtc::scoped_refptr<DataChannelInterface> proxy_channel = |
| 1914 DataChannelProxy::Create(signaling_thread(), channel); |
1898 // Call both the raw pointer and scoped_refptr versions of the method | 1915 // Call both the raw pointer and scoped_refptr versions of the method |
1899 // for compatibility. | 1916 // for compatibility. |
1900 observer_->OnDataChannel(proxy_channel.get()); | 1917 observer_->OnDataChannel(proxy_channel.get()); |
1901 observer_->OnDataChannel(std::move(proxy_channel)); | 1918 observer_->OnDataChannel(std::move(proxy_channel)); |
1902 } | 1919 } |
1903 | 1920 |
1904 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( | 1921 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( |
1905 const std::string& label, | 1922 const std::string& label, |
1906 const InternalDataChannelInit* config) { | 1923 const InternalDataChannelInit* config) { |
1907 if (IsClosed()) { | 1924 if (IsClosed()) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2021 void PeerConnection::OnDataChannelOpenMessage( | 2038 void PeerConnection::OnDataChannelOpenMessage( |
2022 const std::string& label, | 2039 const std::string& label, |
2023 const InternalDataChannelInit& config) { | 2040 const InternalDataChannelInit& config) { |
2024 rtc::scoped_refptr<DataChannel> channel( | 2041 rtc::scoped_refptr<DataChannel> channel( |
2025 InternalCreateDataChannel(label, &config)); | 2042 InternalCreateDataChannel(label, &config)); |
2026 if (!channel.get()) { | 2043 if (!channel.get()) { |
2027 LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message."; | 2044 LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message."; |
2028 return; | 2045 return; |
2029 } | 2046 } |
2030 | 2047 |
2031 auto proxy_channel = DataChannelProxy::Create(signaling_thread(), channel); | 2048 rtc::scoped_refptr<DataChannelInterface> proxy_channel = |
| 2049 DataChannelProxy::Create(signaling_thread(), channel); |
2032 // Call both the raw pointer and scoped_refptr versions of the method | 2050 // Call both the raw pointer and scoped_refptr versions of the method |
2033 // for compatibility. | 2051 // for compatibility. |
2034 observer_->OnDataChannel(proxy_channel.get()); | 2052 observer_->OnDataChannel(proxy_channel.get()); |
2035 observer_->OnDataChannel(std::move(proxy_channel)); | 2053 observer_->OnDataChannel(std::move(proxy_channel)); |
2036 } | 2054 } |
2037 | 2055 |
2038 RtpSenderInterface* PeerConnection::FindSenderById(const std::string& id) { | 2056 RtpSenderInternal* PeerConnection::FindSenderById(const std::string& id) { |
2039 auto it = | 2057 auto it = std::find_if( |
2040 std::find_if(senders_.begin(), senders_.end(), | 2058 senders_.begin(), senders_.end(), |
2041 [id](const rtc::scoped_refptr<RtpSenderInterface>& sender) { | 2059 [id](const rtc::scoped_refptr< |
2042 return sender->id() == id; | 2060 RtpSenderProxyWithInternal<RtpSenderInternal>>& sender) { |
2043 }); | 2061 return sender->id() == id; |
2044 return it != senders_.end() ? it->get() : nullptr; | 2062 }); |
| 2063 return it != senders_.end() ? (*it)->internal() : nullptr; |
2045 } | 2064 } |
2046 | 2065 |
2047 std::vector<rtc::scoped_refptr<RtpSenderInterface>>::iterator | 2066 std::vector< |
| 2067 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator |
2048 PeerConnection::FindSenderForTrack(MediaStreamTrackInterface* track) { | 2068 PeerConnection::FindSenderForTrack(MediaStreamTrackInterface* track) { |
2049 return std::find_if( | 2069 return std::find_if( |
2050 senders_.begin(), senders_.end(), | 2070 senders_.begin(), senders_.end(), |
2051 [track](const rtc::scoped_refptr<RtpSenderInterface>& sender) { | 2071 [track](const rtc::scoped_refptr< |
| 2072 RtpSenderProxyWithInternal<RtpSenderInternal>>& sender) { |
2052 return sender->track() == track; | 2073 return sender->track() == track; |
2053 }); | 2074 }); |
2054 } | 2075 } |
2055 | 2076 |
2056 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator | 2077 std::vector<rtc::scoped_refptr< |
| 2078 RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator |
2057 PeerConnection::FindReceiverForTrack(const std::string& track_id) { | 2079 PeerConnection::FindReceiverForTrack(const std::string& track_id) { |
2058 return std::find_if( | 2080 return std::find_if( |
2059 receivers_.begin(), receivers_.end(), | 2081 receivers_.begin(), receivers_.end(), |
2060 [track_id](const rtc::scoped_refptr<RtpReceiverInterface>& receiver) { | 2082 [track_id](const rtc::scoped_refptr< |
| 2083 RtpReceiverProxyWithInternal<RtpReceiverInternal>>& receiver) { |
2061 return receiver->id() == track_id; | 2084 return receiver->id() == track_id; |
2062 }); | 2085 }); |
2063 } | 2086 } |
2064 | 2087 |
2065 PeerConnection::TrackInfos* PeerConnection::GetRemoteTracks( | 2088 PeerConnection::TrackInfos* PeerConnection::GetRemoteTracks( |
2066 cricket::MediaType media_type) { | 2089 cricket::MediaType media_type) { |
2067 RTC_DCHECK(media_type == cricket::MEDIA_TYPE_AUDIO || | 2090 RTC_DCHECK(media_type == cricket::MEDIA_TYPE_AUDIO || |
2068 media_type == cricket::MEDIA_TYPE_VIDEO); | 2091 media_type == cricket::MEDIA_TYPE_VIDEO); |
2069 return (media_type == cricket::MEDIA_TYPE_AUDIO) ? &remote_audio_tracks_ | 2092 return (media_type == cricket::MEDIA_TYPE_AUDIO) ? &remote_audio_tracks_ |
2070 : &remote_video_tracks_; | 2093 : &remote_video_tracks_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 port_allocator_->set_candidate_filter( | 2179 port_allocator_->set_candidate_filter( |
2157 ConvertIceTransportTypeToCandidateFilter(configuration.type)); | 2180 ConvertIceTransportTypeToCandidateFilter(configuration.type)); |
2158 // Call this last since it may create pooled allocator sessions using the | 2181 // Call this last since it may create pooled allocator sessions using the |
2159 // candidate filter set above. | 2182 // candidate filter set above. |
2160 port_allocator_->SetConfiguration(stun_servers, turn_servers, | 2183 port_allocator_->SetConfiguration(stun_servers, turn_servers, |
2161 configuration.ice_candidate_pool_size); | 2184 configuration.ice_candidate_pool_size); |
2162 return true; | 2185 return true; |
2163 } | 2186 } |
2164 | 2187 |
2165 } // namespace webrtc | 2188 } // namespace webrtc |
OLD | NEW |