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

Side by Side Diff: talk/app/webrtc/peerconnection.cc

Issue 1563403002: Adding AddTrack/RemoveTrack to native PeerConnection API. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding default implementation for new methods. Created 4 years, 11 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 | « talk/app/webrtc/peerconnection.h ('k') | talk/app/webrtc/peerconnectioninterface.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 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 0; 784 0;
785 }), 785 }),
786 stream_observers_.end()); 786 stream_observers_.end());
787 787
788 if (IsClosed()) { 788 if (IsClosed()) {
789 return; 789 return;
790 } 790 }
791 observer_->OnRenegotiationNeeded(); 791 observer_->OnRenegotiationNeeded();
792 } 792 }
793 793
794 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::AddTrack(
795 MediaStreamTrackInterface* track,
796 std::vector<MediaStreamInterface*> streams) {
797 TRACE_EVENT0("webrtc", "PeerConnection::AddTrack");
798 if (IsClosed()) {
799 return nullptr;
800 }
801 if (streams.size() >= 2) {
802 LOG(LS_ERROR)
803 << "Adding a track with two streams is not currently supported.";
804 return nullptr;
805 }
806 // TODO(deadbeef): Support adding a track to two different senders.
807 if (FindSenderForTrack(track) != senders_.end()) {
808 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists.";
809 return nullptr;
810 }
811
812 // TODO(deadbeef): Support adding a track to multiple streams.
813 rtc::scoped_refptr<RtpSenderInterface> new_sender;
814 if (track->kind() == MediaStreamTrackInterface::kAudioKind) {
815 new_sender = RtpSenderProxy::Create(
816 signaling_thread(),
817 new AudioRtpSender(static_cast<AudioTrackInterface*>(track),
818 session_.get(), stats_.get()));
819 if (!streams.empty()) {
820 new_sender->set_stream_id(streams[0]->label());
821 }
822 const TrackInfo* track_info = FindTrackInfo(
823 local_audio_tracks_, new_sender->stream_id(), track->id());
824 if (track_info) {
825 new_sender->SetSsrc(track_info->ssrc);
826 }
827 } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) {
828 new_sender = RtpSenderProxy::Create(
829 signaling_thread(),
830 new VideoRtpSender(static_cast<VideoTrackInterface*>(track),
831 session_.get()));
832 if (!streams.empty()) {
833 new_sender->set_stream_id(streams[0]->label());
834 }
835 const TrackInfo* track_info = FindTrackInfo(
836 local_video_tracks_, new_sender->stream_id(), track->id());
837 if (track_info) {
838 new_sender->SetSsrc(track_info->ssrc);
839 }
840 } else {
841 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << track->kind();
842 return rtc::scoped_refptr<RtpSenderInterface>();
843 }
844
845 senders_.push_back(new_sender);
846 observer_->OnRenegotiationNeeded();
847 return new_sender;
848 }
849
850 bool PeerConnection::RemoveTrack(RtpSenderInterface* sender) {
851 TRACE_EVENT0("webrtc", "PeerConnection::RemoveTrack");
852 if (IsClosed()) {
853 return false;
854 }
855
856 auto it = std::find(senders_.begin(), senders_.end(), sender);
857 if (it == senders_.end()) {
858 LOG(LS_ERROR) << "Couldn't find sender " << sender->id() << " to remove.";
859 return false;
860 }
861 (*it)->Stop();
862 senders_.erase(it);
863
864 observer_->OnRenegotiationNeeded();
865 return true;
866 }
867
794 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( 868 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender(
795 AudioTrackInterface* track) { 869 AudioTrackInterface* track) {
796 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); 870 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender");
797 if (!track) { 871 if (!track) {
798 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; 872 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL.";
799 return NULL; 873 return NULL;
800 } 874 }
801 if (!local_streams_->FindAudioTrack(track->id())) { 875 if (!local_streams_->FindAudioTrack(track->id())) {
802 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; 876 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track.";
803 return NULL; 877 return NULL;
804 } 878 }
805 879
806 rtc::scoped_refptr<DtmfSenderInterface> sender( 880 rtc::scoped_refptr<DtmfSenderInterface> sender(
807 DtmfSender::Create(track, signaling_thread(), session_.get())); 881 DtmfSender::Create(track, signaling_thread(), session_.get()));
808 if (!sender.get()) { 882 if (!sender.get()) {
809 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; 883 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create.";
810 return NULL; 884 return NULL;
811 } 885 }
812 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); 886 return DtmfSenderProxy::Create(signaling_thread(), sender.get());
813 } 887 }
814 888
815 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( 889 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender(
816 const std::string& kind, 890 const std::string& kind,
817 const std::string& stream_id) { 891 const std::string& stream_id) {
818 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); 892 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender");
819 RtpSenderInterface* new_sender; 893 rtc::scoped_refptr<RtpSenderInterface> new_sender;
820 if (kind == MediaStreamTrackInterface::kAudioKind) { 894 if (kind == MediaStreamTrackInterface::kAudioKind) {
821 new_sender = new AudioRtpSender(session_.get(), stats_.get()); 895 new_sender = RtpSenderProxy::Create(
896 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get()));
822 } else if (kind == MediaStreamTrackInterface::kVideoKind) { 897 } else if (kind == MediaStreamTrackInterface::kVideoKind) {
823 new_sender = new VideoRtpSender(session_.get()); 898 new_sender = RtpSenderProxy::Create(signaling_thread(),
899 new VideoRtpSender(session_.get()));
824 } else { 900 } else {
825 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; 901 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind;
826 return rtc::scoped_refptr<RtpSenderInterface>(); 902 return new_sender;
827 } 903 }
828 if (!stream_id.empty()) { 904 if (!stream_id.empty()) {
829 new_sender->set_stream_id(stream_id); 905 new_sender->set_stream_id(stream_id);
830 } 906 }
831 senders_.push_back(new_sender); 907 senders_.push_back(new_sender);
832 return RtpSenderProxy::Create(signaling_thread(), new_sender); 908 return new_sender;
833 } 909 }
834 910
835 std::vector<rtc::scoped_refptr<RtpSenderInterface>> PeerConnection::GetSenders() 911 std::vector<rtc::scoped_refptr<RtpSenderInterface>> PeerConnection::GetSenders()
836 const { 912 const {
837 std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders; 913 return senders_;
838 for (const auto& sender : senders_) {
839 senders.push_back(RtpSenderProxy::Create(signaling_thread(), sender.get()));
840 }
841 return senders;
842 } 914 }
843 915
844 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> 916 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>
845 PeerConnection::GetReceivers() const { 917 PeerConnection::GetReceivers() const {
846 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers; 918 return receivers_;
847 for (const auto& receiver : receivers_) {
848 receivers.push_back(
849 RtpReceiverProxy::Create(signaling_thread(), receiver.get()));
850 }
851 return receivers;
852 } 919 }
853 920
854 bool PeerConnection::GetStats(StatsObserver* observer, 921 bool PeerConnection::GetStats(StatsObserver* observer,
855 MediaStreamTrackInterface* track, 922 MediaStreamTrackInterface* track,
856 StatsOutputLevel level) { 923 StatsOutputLevel level) {
857 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); 924 TRACE_EVENT0("webrtc", "PeerConnection::GetStats");
858 RTC_DCHECK(signaling_thread()->IsCurrent()); 925 RTC_DCHECK(signaling_thread()->IsCurrent());
859 if (!VERIFY(observer != NULL)) { 926 if (!VERIFY(observer != NULL)) {
860 LOG(LS_ERROR) << "GetStats - observer is NULL."; 927 LOG(LS_ERROR) << "GetStats - observer is NULL.";
861 return false; 928 return false;
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 } 1378 }
1312 default: 1379 default:
1313 RTC_DCHECK(false && "Not implemented"); 1380 RTC_DCHECK(false && "Not implemented");
1314 break; 1381 break;
1315 } 1382 }
1316 } 1383 }
1317 1384
1318 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, 1385 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream,
1319 AudioTrackInterface* audio_track, 1386 AudioTrackInterface* audio_track,
1320 uint32_t ssrc) { 1387 uint32_t ssrc) {
1321 receivers_.push_back(new AudioRtpReceiver(audio_track, ssrc, session_.get())); 1388 receivers_.push_back(RtpReceiverProxy::Create(
1389 signaling_thread(),
1390 new AudioRtpReceiver(audio_track, ssrc, session_.get())));
1322 } 1391 }
1323 1392
1324 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, 1393 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream,
1325 VideoTrackInterface* video_track, 1394 VideoTrackInterface* video_track,
1326 uint32_t ssrc) { 1395 uint32_t ssrc) {
1327 receivers_.push_back(new VideoRtpReceiver(video_track, ssrc, session_.get())); 1396 receivers_.push_back(RtpReceiverProxy::Create(
1397 signaling_thread(),
1398 new VideoRtpReceiver(video_track, ssrc, session_.get())));
1328 } 1399 }
1329 1400
1330 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote 1401 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote
1331 // description. 1402 // description.
1332 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, 1403 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream,
1333 AudioTrackInterface* audio_track) { 1404 AudioTrackInterface* audio_track) {
1334 auto it = FindReceiverForTrack(audio_track); 1405 auto it = FindReceiverForTrack(audio_track);
1335 if (it == receivers_.end()) { 1406 if (it == receivers_.end()) {
1336 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id() 1407 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id()
1337 << " doesn't exist."; 1408 << " doesn't exist.";
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 MediaStreamInterface* stream) { 1480 MediaStreamInterface* stream) {
1410 auto sender = FindSenderForTrack(track); 1481 auto sender = FindSenderForTrack(track);
1411 if (sender != senders_.end()) { 1482 if (sender != senders_.end()) {
1412 // We already have a sender for this track, so just change the stream_id 1483 // We already have a sender for this track, so just change the stream_id
1413 // so that it's correct in the next call to CreateOffer. 1484 // so that it's correct in the next call to CreateOffer.
1414 (*sender)->set_stream_id(stream->label()); 1485 (*sender)->set_stream_id(stream->label());
1415 return; 1486 return;
1416 } 1487 }
1417 1488
1418 // Normal case; we've never seen this track before. 1489 // Normal case; we've never seen this track before.
1419 AudioRtpSender* new_sender = 1490 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create(
1420 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get()); 1491 signaling_thread(),
1492 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get()));
1421 senders_.push_back(new_sender); 1493 senders_.push_back(new_sender);
1422 // If the sender has already been configured in SDP, we call SetSsrc, 1494 // If the sender has already been configured in SDP, we call SetSsrc,
1423 // which will connect the sender to the underlying transport. This can 1495 // which will connect the sender to the underlying transport. This can
1424 // occur if a local session description that contains the ID of the sender 1496 // occur if a local session description that contains the ID of the sender
1425 // is set before AddStream is called. It can also occur if the local 1497 // is set before AddStream is called. It can also occur if the local
1426 // session description is not changed and RemoveStream is called, and 1498 // session description is not changed and RemoveStream is called, and
1427 // later AddStream is called again with the same stream. 1499 // later AddStream is called again with the same stream.
1428 const TrackInfo* track_info = 1500 const TrackInfo* track_info =
1429 FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); 1501 FindTrackInfo(local_audio_tracks_, stream->label(), track->id());
1430 if (track_info) { 1502 if (track_info) {
(...skipping 19 matching lines...) Expand all
1450 MediaStreamInterface* stream) { 1522 MediaStreamInterface* stream) {
1451 auto sender = FindSenderForTrack(track); 1523 auto sender = FindSenderForTrack(track);
1452 if (sender != senders_.end()) { 1524 if (sender != senders_.end()) {
1453 // We already have a sender for this track, so just change the stream_id 1525 // We already have a sender for this track, so just change the stream_id
1454 // so that it's correct in the next call to CreateOffer. 1526 // so that it's correct in the next call to CreateOffer.
1455 (*sender)->set_stream_id(stream->label()); 1527 (*sender)->set_stream_id(stream->label());
1456 return; 1528 return;
1457 } 1529 }
1458 1530
1459 // Normal case; we've never seen this track before. 1531 // Normal case; we've never seen this track before.
1460 VideoRtpSender* new_sender = 1532 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create(
1461 new VideoRtpSender(track, stream->label(), session_.get()); 1533 signaling_thread(),
1534 new VideoRtpSender(track, stream->label(), session_.get()));
1462 senders_.push_back(new_sender); 1535 senders_.push_back(new_sender);
1463 const TrackInfo* track_info = 1536 const TrackInfo* track_info =
1464 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); 1537 FindTrackInfo(local_video_tracks_, stream->label(), track->id());
1465 if (track_info) { 1538 if (track_info) {
1466 new_sender->SetSsrc(track_info->ssrc); 1539 new_sender->SetSsrc(track_info->ssrc);
1467 } 1540 }
1468 } 1541 }
1469 1542
1470 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, 1543 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track,
1471 MediaStreamInterface* stream) { 1544 MediaStreamInterface* stream) {
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2149 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2077 for (const auto& channel : sctp_data_channels_) { 2150 for (const auto& channel : sctp_data_channels_) {
2078 if (channel->id() == sid) { 2151 if (channel->id() == sid) {
2079 return channel; 2152 return channel;
2080 } 2153 }
2081 } 2154 }
2082 return nullptr; 2155 return nullptr;
2083 } 2156 }
2084 2157
2085 } // namespace webrtc 2158 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/peerconnection.h ('k') | talk/app/webrtc/peerconnectioninterface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698