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

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

Issue 2023373002: Separating internal and external methods of RtpSender/RtpReceiver. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Giving RtpReceiver the same treatment and fixing formatting. Created 4 years, 6 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
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 27 matching lines...) Expand all
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::RtpSenderProxyEx;
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
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<RtpSenderProxyEx<RtpSenderInternal>>>&
356 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->get()->stream_id());
pthatcher1 2016/06/03 00:23:50 would it make sense to call it internal() instead
Taylor Brandstetter 2016/06/03 22:48:39 Done.
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
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->get()->Stop();
551 } 555 }
552 for (const auto& receiver : receivers_) { 556 for (const auto& receiver : receivers_) {
553 receiver->Stop(); 557 receiver->get()->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
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<RtpSenderProxyEx<RtpSenderInternal>> new_sender;
706 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { 710 if (track->kind() == MediaStreamTrackInterface::kAudioKind) {
707 new_sender = RtpSenderProxy::Create( 711 new_sender = RtpSenderProxyEx<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->get()->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->get()->stream_id(), track->id());
716 if (track_info) { 720 if (track_info) {
717 new_sender->SetSsrc(track_info->ssrc); 721 new_sender->get()->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 = RtpSenderProxyEx<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->get()->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->get()->stream_id(), track->id());
729 if (track_info) { 733 if (track_info) {
730 new_sender->SetSsrc(track_info->ssrc); 734 new_sender->get()->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)->get()->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
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<RtpSenderProxyEx<RtpSenderInternal>> new_sender;
786 if (kind == MediaStreamTrackInterface::kAudioKind) { 790 if (kind == MediaStreamTrackInterface::kAudioKind) {
787 new_sender = RtpSenderProxy::Create( 791 new_sender = RtpSenderProxyEx<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 = RtpSenderProxyEx<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->get()->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
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(RtpReceiverProxyEx<RtpReceiverInternal>::Create(
1307 signaling_thread(), 1319 signaling_thread(),
1308 new AudioRtpReceiver(stream, track_id, ssrc, session_.get()))); 1320 new AudioRtpReceiver(stream, track_id, ssrc, session_.get())));
1309 } 1321 }
1310 1322
1311 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, 1323 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream,
1312 const std::string& track_id, 1324 const std::string& track_id,
1313 uint32_t ssrc) { 1325 uint32_t ssrc) {
1314 receivers_.push_back(RtpReceiverProxy::Create( 1326 receivers_.push_back(RtpReceiverProxyEx<RtpReceiverInternal>::Create(
1315 signaling_thread(), 1327 signaling_thread(),
1316 new VideoRtpReceiver(stream, track_id, factory_->worker_thread(), ssrc, 1328 new VideoRtpReceiver(stream, track_id, factory_->worker_thread(), ssrc,
1317 session_.get()))); 1329 session_.get())));
1318 } 1330 }
1319 1331
1320 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote 1332 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote
1321 // description. 1333 // description.
1322 void PeerConnection::DestroyReceiver(const std::string& track_id) { 1334 void PeerConnection::DestroyReceiver(const std::string& track_id) {
1323 auto it = FindReceiverForTrack(track_id); 1335 auto it = FindReceiverForTrack(track_id);
1324 if (it == receivers_.end()) { 1336 if (it == receivers_.end()) {
1325 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_id 1337 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_id
1326 << " doesn't exist."; 1338 << " doesn't exist.";
1327 } else { 1339 } else {
1328 (*it)->Stop(); 1340 (*it)->get()->Stop();
1329 receivers_.erase(it); 1341 receivers_.erase(it);
1330 } 1342 }
1331 } 1343 }
1332 1344
1333 void PeerConnection::StopReceivers(cricket::MediaType media_type) { 1345 void PeerConnection::StopReceivers(cricket::MediaType media_type) {
1334 TrackInfos* current_tracks = GetRemoteTracks(media_type); 1346 TrackInfos* current_tracks = GetRemoteTracks(media_type);
1335 for (const auto& track_info : *current_tracks) { 1347 for (const auto& track_info : *current_tracks) {
1336 auto it = FindReceiverForTrack(track_info.track_id); 1348 auto it = FindReceiverForTrack(track_info.track_id);
1337 if (it == receivers_.end()) { 1349 if (it == receivers_.end()) {
1338 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_info.track_id 1350 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_info.track_id
1339 << " doesn't exist."; 1351 << " doesn't exist.";
1340 } else { 1352 } else {
1341 (*it)->Stop(); 1353 (*it)->get()->Stop();
1342 } 1354 }
1343 } 1355 }
1344 } 1356 }
1345 1357
1346 void PeerConnection::OnIceConnectionChange( 1358 void PeerConnection::OnIceConnectionChange(
1347 PeerConnectionInterface::IceConnectionState new_state) { 1359 PeerConnectionInterface::IceConnectionState new_state) {
1348 RTC_DCHECK(signaling_thread()->IsCurrent()); 1360 RTC_DCHECK(signaling_thread()->IsCurrent());
1349 // After transitioning to "closed", ignore any additional states from 1361 // After transitioning to "closed", ignore any additional states from
1350 // WebRtcSession (such as "disconnected"). 1362 // WebRtcSession (such as "disconnected").
1351 if (IsClosed()) { 1363 if (IsClosed()) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 } 1406 }
1395 observer_->OnSignalingChange(signaling_state_); 1407 observer_->OnSignalingChange(signaling_state_);
1396 } 1408 }
1397 1409
1398 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, 1410 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track,
1399 MediaStreamInterface* stream) { 1411 MediaStreamInterface* stream) {
1400 auto sender = FindSenderForTrack(track); 1412 auto sender = FindSenderForTrack(track);
1401 if (sender != senders_.end()) { 1413 if (sender != senders_.end()) {
1402 // We already have a sender for this track, so just change the stream_id 1414 // 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. 1415 // so that it's correct in the next call to CreateOffer.
1404 (*sender)->set_stream_id(stream->label()); 1416 (*sender)->get()->set_stream_id(stream->label());
1405 return; 1417 return;
1406 } 1418 }
1407 1419
1408 // Normal case; we've never seen this track before. 1420 // Normal case; we've never seen this track before.
1409 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( 1421 rtc::scoped_refptr<RtpSenderProxyEx<RtpSenderInternal>> new_sender =
1410 signaling_thread(), 1422 RtpSenderProxyEx<RtpSenderInternal>::Create(
1411 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get())); 1423 signaling_thread(), new AudioRtpSender(track, stream->label(),
1424 session_.get(), stats_.get()));
1412 senders_.push_back(new_sender); 1425 senders_.push_back(new_sender);
1413 // If the sender has already been configured in SDP, we call SetSsrc, 1426 // If the sender has already been configured in SDP, we call SetSsrc,
1414 // which will connect the sender to the underlying transport. This can 1427 // 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 1428 // 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 1429 // is set before AddStream is called. It can also occur if the local
1417 // session description is not changed and RemoveStream is called, and 1430 // session description is not changed and RemoveStream is called, and
1418 // later AddStream is called again with the same stream. 1431 // later AddStream is called again with the same stream.
1419 const TrackInfo* track_info = 1432 const TrackInfo* track_info =
1420 FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); 1433 FindTrackInfo(local_audio_tracks_, stream->label(), track->id());
1421 if (track_info) { 1434 if (track_info) {
1422 new_sender->SetSsrc(track_info->ssrc); 1435 new_sender->get()->SetSsrc(track_info->ssrc);
1423 } 1436 }
1424 } 1437 }
1425 1438
1426 // TODO(deadbeef): Don't destroy RtpSenders here; they should be kept around 1439 // TODO(deadbeef): Don't destroy RtpSenders here; they should be kept around
1427 // indefinitely, when we have unified plan SDP. 1440 // indefinitely, when we have unified plan SDP.
1428 void PeerConnection::OnAudioTrackRemoved(AudioTrackInterface* track, 1441 void PeerConnection::OnAudioTrackRemoved(AudioTrackInterface* track,
1429 MediaStreamInterface* stream) { 1442 MediaStreamInterface* stream) {
1430 auto sender = FindSenderForTrack(track); 1443 auto sender = FindSenderForTrack(track);
1431 if (sender == senders_.end()) { 1444 if (sender == senders_.end()) {
1432 LOG(LS_WARNING) << "RtpSender for track with id " << track->id() 1445 LOG(LS_WARNING) << "RtpSender for track with id " << track->id()
1433 << " doesn't exist."; 1446 << " doesn't exist.";
1434 return; 1447 return;
1435 } 1448 }
1436 (*sender)->Stop(); 1449 (*sender)->get()->Stop();
1437 senders_.erase(sender); 1450 senders_.erase(sender);
1438 } 1451 }
1439 1452
1440 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, 1453 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track,
1441 MediaStreamInterface* stream) { 1454 MediaStreamInterface* stream) {
1442 auto sender = FindSenderForTrack(track); 1455 auto sender = FindSenderForTrack(track);
1443 if (sender != senders_.end()) { 1456 if (sender != senders_.end()) {
1444 // We already have a sender for this track, so just change the stream_id 1457 // 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. 1458 // so that it's correct in the next call to CreateOffer.
1446 (*sender)->set_stream_id(stream->label()); 1459 (*sender)->get()->set_stream_id(stream->label());
1447 return; 1460 return;
1448 } 1461 }
1449 1462
1450 // Normal case; we've never seen this track before. 1463 // Normal case; we've never seen this track before.
1451 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( 1464 rtc::scoped_refptr<RtpSenderProxyEx<RtpSenderInternal>> new_sender =
1452 signaling_thread(), 1465 RtpSenderProxyEx<RtpSenderInternal>::Create(
1453 new VideoRtpSender(track, stream->label(), session_.get())); 1466 signaling_thread(),
1467 new VideoRtpSender(track, stream->label(), session_.get()));
1454 senders_.push_back(new_sender); 1468 senders_.push_back(new_sender);
1455 const TrackInfo* track_info = 1469 const TrackInfo* track_info =
1456 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); 1470 FindTrackInfo(local_video_tracks_, stream->label(), track->id());
1457 if (track_info) { 1471 if (track_info) {
1458 new_sender->SetSsrc(track_info->ssrc); 1472 new_sender->get()->SetSsrc(track_info->ssrc);
1459 } 1473 }
1460 } 1474 }
1461 1475
1462 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, 1476 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track,
1463 MediaStreamInterface* stream) { 1477 MediaStreamInterface* stream) {
1464 auto sender = FindSenderForTrack(track); 1478 auto sender = FindSenderForTrack(track);
1465 if (sender == senders_.end()) { 1479 if (sender == senders_.end()) {
1466 LOG(LS_WARNING) << "RtpSender for track with id " << track->id() 1480 LOG(LS_WARNING) << "RtpSender for track with id " << track->id()
1467 << " doesn't exist."; 1481 << " doesn't exist.";
1468 return; 1482 return;
1469 } 1483 }
1470 (*sender)->Stop(); 1484 (*sender)->get()->Stop();
1471 senders_.erase(sender); 1485 senders_.erase(sender);
1472 } 1486 }
1473 1487
1474 void PeerConnection::PostSetSessionDescriptionFailure( 1488 void PeerConnection::PostSetSessionDescriptionFailure(
1475 SetSessionDescriptionObserver* observer, 1489 SetSessionDescriptionObserver* observer,
1476 const std::string& error) { 1490 const std::string& error) {
1477 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); 1491 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer);
1478 msg->error = error; 1492 msg->error = error;
1479 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_FAILED, msg); 1493 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_FAILED, msg);
1480 } 1494 }
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); 1776 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc));
1763 OnLocalTrackSeen(stream_label, track_id, params.first_ssrc(), media_type); 1777 OnLocalTrackSeen(stream_label, track_id, params.first_ssrc(), media_type);
1764 } 1778 }
1765 } 1779 }
1766 } 1780 }
1767 1781
1768 void PeerConnection::OnLocalTrackSeen(const std::string& stream_label, 1782 void PeerConnection::OnLocalTrackSeen(const std::string& stream_label,
1769 const std::string& track_id, 1783 const std::string& track_id,
1770 uint32_t ssrc, 1784 uint32_t ssrc,
1771 cricket::MediaType media_type) { 1785 cricket::MediaType media_type) {
1772 RtpSenderInterface* sender = FindSenderById(track_id); 1786 RtpSenderInternal* sender = FindSenderById(track_id);
1773 if (!sender) { 1787 if (!sender) {
1774 LOG(LS_WARNING) << "An unknown RtpSender with id " << track_id 1788 LOG(LS_WARNING) << "An unknown RtpSender with id " << track_id
1775 << " has been configured in the local description."; 1789 << " has been configured in the local description.";
1776 return; 1790 return;
1777 } 1791 }
1778 1792
1779 if (sender->media_type() != media_type) { 1793 if (sender->media_type() != media_type) {
1780 LOG(LS_WARNING) << "An RtpSender has been configured in the local" 1794 LOG(LS_WARNING) << "An RtpSender has been configured in the local"
1781 << " description with an unexpected media type."; 1795 << " description with an unexpected media type.";
1782 return; 1796 return;
1783 } 1797 }
1784 1798
1785 sender->set_stream_id(stream_label); 1799 sender->set_stream_id(stream_label);
1786 sender->SetSsrc(ssrc); 1800 sender->SetSsrc(ssrc);
1787 } 1801 }
1788 1802
1789 void PeerConnection::OnLocalTrackRemoved(const std::string& stream_label, 1803 void PeerConnection::OnLocalTrackRemoved(const std::string& stream_label,
1790 const std::string& track_id, 1804 const std::string& track_id,
1791 uint32_t ssrc, 1805 uint32_t ssrc,
1792 cricket::MediaType media_type) { 1806 cricket::MediaType media_type) {
1793 RtpSenderInterface* sender = FindSenderById(track_id); 1807 RtpSenderInternal* sender = FindSenderById(track_id);
1794 if (!sender) { 1808 if (!sender) {
1795 // This is the normal case. I.e., RemoveStream has been called and the 1809 // This is the normal case. I.e., RemoveStream has been called and the
1796 // SessionDescriptions has been renegotiated. 1810 // SessionDescriptions has been renegotiated.
1797 return; 1811 return;
1798 } 1812 }
1799 1813
1800 // A sender has been removed from the SessionDescription but it's still 1814 // 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 1815 // associated with the PeerConnection. This only occurs if the SDP doesn't
1802 // match with the calls to CreateSender, AddStream and RemoveStream. 1816 // match with the calls to CreateSender, AddStream and RemoveStream.
1803 if (sender->media_type() != media_type) { 1817 if (sender->media_type() != media_type) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 void PeerConnection::CreateRemoteRtpDataChannel(const std::string& label, 1901 void PeerConnection::CreateRemoteRtpDataChannel(const std::string& label,
1888 uint32_t remote_ssrc) { 1902 uint32_t remote_ssrc) {
1889 rtc::scoped_refptr<DataChannel> channel( 1903 rtc::scoped_refptr<DataChannel> channel(
1890 InternalCreateDataChannel(label, nullptr)); 1904 InternalCreateDataChannel(label, nullptr));
1891 if (!channel.get()) { 1905 if (!channel.get()) {
1892 LOG(LS_WARNING) << "Remote peer requested a DataChannel but" 1906 LOG(LS_WARNING) << "Remote peer requested a DataChannel but"
1893 << "CreateDataChannel failed."; 1907 << "CreateDataChannel failed.";
1894 return; 1908 return;
1895 } 1909 }
1896 channel->SetReceiveSsrc(remote_ssrc); 1910 channel->SetReceiveSsrc(remote_ssrc);
1897 auto proxy_channel = DataChannelProxy::Create(signaling_thread(), channel); 1911 rtc::scoped_refptr<DataChannelInterface> proxy_channel =
1912 DataChannelProxy::Create(signaling_thread(), channel);
1898 // Call both the raw pointer and scoped_refptr versions of the method 1913 // Call both the raw pointer and scoped_refptr versions of the method
1899 // for compatibility. 1914 // for compatibility.
1900 observer_->OnDataChannel(proxy_channel.get()); 1915 observer_->OnDataChannel(proxy_channel.get());
1901 observer_->OnDataChannel(std::move(proxy_channel)); 1916 observer_->OnDataChannel(std::move(proxy_channel));
1902 } 1917 }
1903 1918
1904 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( 1919 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel(
1905 const std::string& label, 1920 const std::string& label,
1906 const InternalDataChannelInit* config) { 1921 const InternalDataChannelInit* config) {
1907 if (IsClosed()) { 1922 if (IsClosed()) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 void PeerConnection::OnDataChannelOpenMessage( 2036 void PeerConnection::OnDataChannelOpenMessage(
2022 const std::string& label, 2037 const std::string& label,
2023 const InternalDataChannelInit& config) { 2038 const InternalDataChannelInit& config) {
2024 rtc::scoped_refptr<DataChannel> channel( 2039 rtc::scoped_refptr<DataChannel> channel(
2025 InternalCreateDataChannel(label, &config)); 2040 InternalCreateDataChannel(label, &config));
2026 if (!channel.get()) { 2041 if (!channel.get()) {
2027 LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message."; 2042 LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message.";
2028 return; 2043 return;
2029 } 2044 }
2030 2045
2031 auto proxy_channel = DataChannelProxy::Create(signaling_thread(), channel); 2046 rtc::scoped_refptr<DataChannelInterface> proxy_channel =
2047 DataChannelProxy::Create(signaling_thread(), channel);
2032 // Call both the raw pointer and scoped_refptr versions of the method 2048 // Call both the raw pointer and scoped_refptr versions of the method
2033 // for compatibility. 2049 // for compatibility.
2034 observer_->OnDataChannel(proxy_channel.get()); 2050 observer_->OnDataChannel(proxy_channel.get());
2035 observer_->OnDataChannel(std::move(proxy_channel)); 2051 observer_->OnDataChannel(std::move(proxy_channel));
2036 } 2052 }
2037 2053
2038 RtpSenderInterface* PeerConnection::FindSenderById(const std::string& id) { 2054 RtpSenderInternal* PeerConnection::FindSenderById(const std::string& id) {
2039 auto it = 2055 auto it = std::find_if(
2040 std::find_if(senders_.begin(), senders_.end(), 2056 senders_.begin(), senders_.end(),
2041 [id](const rtc::scoped_refptr<RtpSenderInterface>& sender) { 2057 [id](const rtc::scoped_refptr<RtpSenderProxyEx<RtpSenderInternal>>&
2042 return sender->id() == id; 2058 sender) { return sender->id() == id; });
2043 }); 2059 return it != senders_.end() ? it->get()->get() : nullptr;
2044 return it != senders_.end() ? it->get() : nullptr;
2045 } 2060 }
2046 2061
2047 std::vector<rtc::scoped_refptr<RtpSenderInterface>>::iterator 2062 std::vector<rtc::scoped_refptr<RtpSenderProxyEx<RtpSenderInternal>>>::iterator
2048 PeerConnection::FindSenderForTrack(MediaStreamTrackInterface* track) { 2063 PeerConnection::FindSenderForTrack(MediaStreamTrackInterface* track) {
2049 return std::find_if( 2064 return std::find_if(
2050 senders_.begin(), senders_.end(), 2065 senders_.begin(), senders_.end(),
2051 [track](const rtc::scoped_refptr<RtpSenderInterface>& sender) { 2066 [track](const rtc::scoped_refptr<RtpSenderProxyEx<RtpSenderInternal>>&
2052 return sender->track() == track; 2067 sender) { return sender->track() == track; });
2053 });
2054 } 2068 }
2055 2069
2056 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator 2070 std::vector<
2071 rtc::scoped_refptr<RtpReceiverProxyEx<RtpReceiverInternal>>>::iterator
2057 PeerConnection::FindReceiverForTrack(const std::string& track_id) { 2072 PeerConnection::FindReceiverForTrack(const std::string& track_id) {
2058 return std::find_if( 2073 return std::find_if(
2059 receivers_.begin(), receivers_.end(), 2074 receivers_.begin(), receivers_.end(),
2060 [track_id](const rtc::scoped_refptr<RtpReceiverInterface>& receiver) { 2075 [track_id](
2061 return receiver->id() == track_id; 2076 const rtc::scoped_refptr<RtpReceiverProxyEx<RtpReceiverInternal>>&
2062 }); 2077 receiver) { return receiver->id() == track_id; });
2063 } 2078 }
2064 2079
2065 PeerConnection::TrackInfos* PeerConnection::GetRemoteTracks( 2080 PeerConnection::TrackInfos* PeerConnection::GetRemoteTracks(
2066 cricket::MediaType media_type) { 2081 cricket::MediaType media_type) {
2067 RTC_DCHECK(media_type == cricket::MEDIA_TYPE_AUDIO || 2082 RTC_DCHECK(media_type == cricket::MEDIA_TYPE_AUDIO ||
2068 media_type == cricket::MEDIA_TYPE_VIDEO); 2083 media_type == cricket::MEDIA_TYPE_VIDEO);
2069 return (media_type == cricket::MEDIA_TYPE_AUDIO) ? &remote_audio_tracks_ 2084 return (media_type == cricket::MEDIA_TYPE_AUDIO) ? &remote_audio_tracks_
2070 : &remote_video_tracks_; 2085 : &remote_video_tracks_;
2071 } 2086 }
2072 2087
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 port_allocator_->set_candidate_filter( 2171 port_allocator_->set_candidate_filter(
2157 ConvertIceTransportTypeToCandidateFilter(configuration.type)); 2172 ConvertIceTransportTypeToCandidateFilter(configuration.type));
2158 // Call this last since it may create pooled allocator sessions using the 2173 // Call this last since it may create pooled allocator sessions using the
2159 // candidate filter set above. 2174 // candidate filter set above.
2160 port_allocator_->SetConfiguration(stun_servers, turn_servers, 2175 port_allocator_->SetConfiguration(stun_servers, turn_servers,
2161 configuration.ice_candidate_pool_size); 2176 configuration.ice_candidate_pool_size);
2162 return true; 2177 return true;
2163 } 2178 }
2164 2179
2165 } // namespace webrtc 2180 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698