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

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

Issue 1766653002: Replace SetCapturer and SetCaptureDevice by SetSource. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 4 years, 8 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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 // TODO(deadbeef): Support adding a track to two different senders. 682 // TODO(deadbeef): Support adding a track to two different senders.
683 if (FindSenderForTrack(track) != senders_.end()) { 683 if (FindSenderForTrack(track) != senders_.end()) {
684 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; 684 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists.";
685 return nullptr; 685 return nullptr;
686 } 686 }
687 687
688 // TODO(deadbeef): Support adding a track to multiple streams. 688 // TODO(deadbeef): Support adding a track to multiple streams.
689 rtc::scoped_refptr<RtpSenderInterface> new_sender; 689 rtc::scoped_refptr<RtpSenderInterface> new_sender;
690 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { 690 if (track->kind() == MediaStreamTrackInterface::kAudioKind) {
691 new_sender = RtpSenderProxy::Create( 691 new_sender = RtpSenderProxy::Create(
692 signaling_thread(), 692 signaling_thread(), nullptr,
693 new AudioRtpSender(static_cast<AudioTrackInterface*>(track), 693 new AudioRtpSender(static_cast<AudioTrackInterface*>(track),
694 session_.get(), stats_.get())); 694 session_.get(), stats_.get()));
695 if (!streams.empty()) { 695 if (!streams.empty()) {
696 new_sender->set_stream_id(streams[0]->label()); 696 new_sender->set_stream_id(streams[0]->label());
697 } 697 }
698 const TrackInfo* track_info = FindTrackInfo( 698 const TrackInfo* track_info = FindTrackInfo(
699 local_audio_tracks_, new_sender->stream_id(), track->id()); 699 local_audio_tracks_, new_sender->stream_id(), track->id());
700 if (track_info) { 700 if (track_info) {
701 new_sender->SetSsrc(track_info->ssrc); 701 new_sender->SetSsrc(track_info->ssrc);
702 } 702 }
703 } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) { 703 } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) {
704 new_sender = RtpSenderProxy::Create( 704 new_sender = RtpSenderProxy::Create(
705 signaling_thread(), 705 signaling_thread(), nullptr,
706 new VideoRtpSender(static_cast<VideoTrackInterface*>(track), 706 new VideoRtpSender(static_cast<VideoTrackInterface*>(track),
707 session_.get())); 707 session_.get()));
708 if (!streams.empty()) { 708 if (!streams.empty()) {
709 new_sender->set_stream_id(streams[0]->label()); 709 new_sender->set_stream_id(streams[0]->label());
710 } 710 }
711 const TrackInfo* track_info = FindTrackInfo( 711 const TrackInfo* track_info = FindTrackInfo(
712 local_video_tracks_, new_sender->stream_id(), track->id()); 712 local_video_tracks_, new_sender->stream_id(), track->id());
713 if (track_info) { 713 if (track_info) {
714 new_sender->SetSsrc(track_info->ssrc); 714 new_sender->SetSsrc(track_info->ssrc);
715 } 715 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; 752 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track.";
753 return NULL; 753 return NULL;
754 } 754 }
755 755
756 rtc::scoped_refptr<DtmfSenderInterface> sender( 756 rtc::scoped_refptr<DtmfSenderInterface> sender(
757 DtmfSender::Create(track, signaling_thread(), session_.get())); 757 DtmfSender::Create(track, signaling_thread(), session_.get()));
758 if (!sender.get()) { 758 if (!sender.get()) {
759 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; 759 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create.";
760 return NULL; 760 return NULL;
761 } 761 }
762 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); 762 return DtmfSenderProxy::Create(signaling_thread(), nullptr, sender.get());
763 } 763 }
764 764
765 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( 765 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender(
766 const std::string& kind, 766 const std::string& kind,
767 const std::string& stream_id) { 767 const std::string& stream_id) {
768 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); 768 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender");
769 rtc::scoped_refptr<RtpSenderInterface> new_sender; 769 rtc::scoped_refptr<RtpSenderInterface> new_sender;
770 if (kind == MediaStreamTrackInterface::kAudioKind) { 770 if (kind == MediaStreamTrackInterface::kAudioKind) {
771 new_sender = RtpSenderProxy::Create( 771 new_sender = RtpSenderProxy::Create(
772 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); 772 signaling_thread(), nullptr,
773 new AudioRtpSender(session_.get(), stats_.get()));
773 } else if (kind == MediaStreamTrackInterface::kVideoKind) { 774 } else if (kind == MediaStreamTrackInterface::kVideoKind) {
774 new_sender = RtpSenderProxy::Create(signaling_thread(), 775 new_sender = RtpSenderProxy::Create(signaling_thread(), nullptr,
775 new VideoRtpSender(session_.get())); 776 new VideoRtpSender(session_.get()));
776 } else { 777 } else {
777 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; 778 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind;
778 return new_sender; 779 return new_sender;
779 } 780 }
780 if (!stream_id.empty()) { 781 if (!stream_id.empty()) {
781 new_sender->set_stream_id(stream_id); 782 new_sender->set_stream_id(stream_id);
782 } 783 }
783 senders_.push_back(new_sender); 784 senders_.push_back(new_sender);
784 return new_sender; 785 return new_sender;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 if (!channel.get()) { 845 if (!channel.get()) {
845 return nullptr; 846 return nullptr;
846 } 847 }
847 848
848 // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or 849 // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or
849 // the first SCTP DataChannel. 850 // the first SCTP DataChannel.
850 if (session_->data_channel_type() == cricket::DCT_RTP || first_datachannel) { 851 if (session_->data_channel_type() == cricket::DCT_RTP || first_datachannel) {
851 observer_->OnRenegotiationNeeded(); 852 observer_->OnRenegotiationNeeded();
852 } 853 }
853 854
854 return DataChannelProxy::Create(signaling_thread(), channel.get()); 855 return DataChannelProxy::Create(signaling_thread(), nullptr, channel.get());
855 } 856 }
856 857
857 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, 858 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer,
858 const MediaConstraintsInterface* constraints) { 859 const MediaConstraintsInterface* constraints) {
859 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); 860 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer");
860 if (!VERIFY(observer != nullptr)) { 861 if (!VERIFY(observer != nullptr)) {
861 LOG(LS_ERROR) << "CreateOffer - observer is NULL."; 862 LOG(LS_ERROR) << "CreateOffer - observer is NULL.";
862 return; 863 return;
863 } 864 }
864 RTCOfferAnswerOptions options; 865 RTCOfferAnswerOptions options;
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 default: 1277 default:
1277 RTC_DCHECK(false && "Not implemented"); 1278 RTC_DCHECK(false && "Not implemented");
1278 break; 1279 break;
1279 } 1280 }
1280 } 1281 }
1281 1282
1282 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, 1283 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream,
1283 const std::string& track_id, 1284 const std::string& track_id,
1284 uint32_t ssrc) { 1285 uint32_t ssrc) {
1285 receivers_.push_back(RtpReceiverProxy::Create( 1286 receivers_.push_back(RtpReceiverProxy::Create(
1286 signaling_thread(), 1287 signaling_thread(), nullptr,
1287 new AudioRtpReceiver(stream, track_id, ssrc, session_.get()))); 1288 new AudioRtpReceiver(stream, track_id, ssrc, session_.get())));
1288 } 1289 }
1289 1290
1290 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, 1291 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream,
1291 const std::string& track_id, 1292 const std::string& track_id,
1292 uint32_t ssrc) { 1293 uint32_t ssrc) {
1293 receivers_.push_back(RtpReceiverProxy::Create( 1294 receivers_.push_back(RtpReceiverProxy::Create(
1294 signaling_thread(), 1295 signaling_thread(), nullptr,
1295 new VideoRtpReceiver(stream, track_id, factory_->worker_thread(), ssrc, 1296 new VideoRtpReceiver(stream, track_id, factory_->worker_thread(), ssrc,
1296 session_.get()))); 1297 session_.get())));
1297 } 1298 }
1298 1299
1299 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote 1300 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote
1300 // description. 1301 // description.
1301 void PeerConnection::DestroyReceiver(const std::string& track_id) { 1302 void PeerConnection::DestroyReceiver(const std::string& track_id) {
1302 auto it = FindReceiverForTrack(track_id); 1303 auto it = FindReceiverForTrack(track_id);
1303 if (it == receivers_.end()) { 1304 if (it == receivers_.end()) {
1304 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_id 1305 LOG(LS_WARNING) << "RtpReceiver for track with id " << track_id
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 auto sender = FindSenderForTrack(track); 1380 auto sender = FindSenderForTrack(track);
1380 if (sender != senders_.end()) { 1381 if (sender != senders_.end()) {
1381 // We already have a sender for this track, so just change the stream_id 1382 // We already have a sender for this track, so just change the stream_id
1382 // so that it's correct in the next call to CreateOffer. 1383 // so that it's correct in the next call to CreateOffer.
1383 (*sender)->set_stream_id(stream->label()); 1384 (*sender)->set_stream_id(stream->label());
1384 return; 1385 return;
1385 } 1386 }
1386 1387
1387 // Normal case; we've never seen this track before. 1388 // Normal case; we've never seen this track before.
1388 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( 1389 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create(
1389 signaling_thread(), 1390 signaling_thread(), nullptr,
1390 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get())); 1391 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get()));
1391 senders_.push_back(new_sender); 1392 senders_.push_back(new_sender);
1392 // If the sender has already been configured in SDP, we call SetSsrc, 1393 // If the sender has already been configured in SDP, we call SetSsrc,
1393 // which will connect the sender to the underlying transport. This can 1394 // which will connect the sender to the underlying transport. This can
1394 // occur if a local session description that contains the ID of the sender 1395 // occur if a local session description that contains the ID of the sender
1395 // is set before AddStream is called. It can also occur if the local 1396 // is set before AddStream is called. It can also occur if the local
1396 // session description is not changed and RemoveStream is called, and 1397 // session description is not changed and RemoveStream is called, and
1397 // later AddStream is called again with the same stream. 1398 // later AddStream is called again with the same stream.
1398 const TrackInfo* track_info = 1399 const TrackInfo* track_info =
1399 FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); 1400 FindTrackInfo(local_audio_tracks_, stream->label(), track->id());
(...skipping 21 matching lines...) Expand all
1421 auto sender = FindSenderForTrack(track); 1422 auto sender = FindSenderForTrack(track);
1422 if (sender != senders_.end()) { 1423 if (sender != senders_.end()) {
1423 // We already have a sender for this track, so just change the stream_id 1424 // We already have a sender for this track, so just change the stream_id
1424 // so that it's correct in the next call to CreateOffer. 1425 // so that it's correct in the next call to CreateOffer.
1425 (*sender)->set_stream_id(stream->label()); 1426 (*sender)->set_stream_id(stream->label());
1426 return; 1427 return;
1427 } 1428 }
1428 1429
1429 // Normal case; we've never seen this track before. 1430 // Normal case; we've never seen this track before.
1430 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( 1431 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create(
1431 signaling_thread(), 1432 signaling_thread(), nullptr,
1432 new VideoRtpSender(track, stream->label(), session_.get())); 1433 new VideoRtpSender(track, stream->label(), session_.get()));
1433 senders_.push_back(new_sender); 1434 senders_.push_back(new_sender);
1434 const TrackInfo* track_info = 1435 const TrackInfo* track_info =
1435 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); 1436 FindTrackInfo(local_video_tracks_, stream->label(), track->id());
1436 if (track_info) { 1437 if (track_info) {
1437 new_sender->SetSsrc(track_info->ssrc); 1438 new_sender->SetSsrc(track_info->ssrc);
1438 } 1439 }
1439 } 1440 }
1440 1441
1441 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, 1442 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 // The sync_label is the MediaStream label and the |stream.id| is the 1593 // The sync_label is the MediaStream label and the |stream.id| is the
1593 // track id. 1594 // track id.
1594 const std::string& stream_label = params.sync_label; 1595 const std::string& stream_label = params.sync_label;
1595 const std::string& track_id = params.id; 1596 const std::string& track_id = params.id;
1596 uint32_t ssrc = params.first_ssrc(); 1597 uint32_t ssrc = params.first_ssrc();
1597 1598
1598 rtc::scoped_refptr<MediaStreamInterface> stream = 1599 rtc::scoped_refptr<MediaStreamInterface> stream =
1599 remote_streams_->find(stream_label); 1600 remote_streams_->find(stream_label);
1600 if (!stream) { 1601 if (!stream) {
1601 // This is a new MediaStream. Create a new remote MediaStream. 1602 // This is a new MediaStream. Create a new remote MediaStream.
1602 stream = MediaStreamProxy::Create(rtc::Thread::Current(), 1603 stream = MediaStreamProxy::Create(rtc::Thread::Current(), nullptr,
1603 MediaStream::Create(stream_label)); 1604 MediaStream::Create(stream_label));
1604 remote_streams_->AddStream(stream); 1605 remote_streams_->AddStream(stream);
1605 new_streams->AddStream(stream); 1606 new_streams->AddStream(stream);
1606 } 1607 }
1607 1608
1608 const TrackInfo* track_info = 1609 const TrackInfo* track_info =
1609 FindTrackInfo(*current_tracks, stream_label, track_id); 1610 FindTrackInfo(*current_tracks, stream_label, track_id);
1610 if (!track_info) { 1611 if (!track_info) {
1611 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); 1612 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc));
1612 OnRemoteTrackSeen(stream_label, track_id, ssrc, media_type); 1613 OnRemoteTrackSeen(stream_label, track_id, ssrc, media_type);
1613 } 1614 }
1614 } 1615 }
1615 1616
1616 // Add default track if necessary. 1617 // Add default track if necessary.
1617 if (default_track_needed) { 1618 if (default_track_needed) {
1618 rtc::scoped_refptr<MediaStreamInterface> default_stream = 1619 rtc::scoped_refptr<MediaStreamInterface> default_stream =
1619 remote_streams_->find(kDefaultStreamLabel); 1620 remote_streams_->find(kDefaultStreamLabel);
1620 if (!default_stream) { 1621 if (!default_stream) {
1621 // Create the new default MediaStream. 1622 // Create the new default MediaStream.
1622 default_stream = MediaStreamProxy::Create( 1623 default_stream = MediaStreamProxy::Create(
1623 rtc::Thread::Current(), MediaStream::Create(kDefaultStreamLabel)); 1624 rtc::Thread::Current(), nullptr,
1625 MediaStream::Create(kDefaultStreamLabel));
1624 remote_streams_->AddStream(default_stream); 1626 remote_streams_->AddStream(default_stream);
1625 new_streams->AddStream(default_stream); 1627 new_streams->AddStream(default_stream);
1626 } 1628 }
1627 std::string default_track_id = (media_type == cricket::MEDIA_TYPE_AUDIO) 1629 std::string default_track_id = (media_type == cricket::MEDIA_TYPE_AUDIO)
1628 ? kDefaultAudioTrackLabel 1630 ? kDefaultAudioTrackLabel
1629 : kDefaultVideoTrackLabel; 1631 : kDefaultVideoTrackLabel;
1630 const TrackInfo* default_track_info = 1632 const TrackInfo* default_track_info =
1631 FindTrackInfo(*current_tracks, kDefaultStreamLabel, default_track_id); 1633 FindTrackInfo(*current_tracks, kDefaultStreamLabel, default_track_id);
1632 if (!default_track_info) { 1634 if (!default_track_info) {
1633 current_tracks->push_back( 1635 current_tracks->push_back(
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 uint32_t remote_ssrc) { 1860 uint32_t remote_ssrc) {
1859 rtc::scoped_refptr<DataChannel> channel( 1861 rtc::scoped_refptr<DataChannel> channel(
1860 InternalCreateDataChannel(label, nullptr)); 1862 InternalCreateDataChannel(label, nullptr));
1861 if (!channel.get()) { 1863 if (!channel.get()) {
1862 LOG(LS_WARNING) << "Remote peer requested a DataChannel but" 1864 LOG(LS_WARNING) << "Remote peer requested a DataChannel but"
1863 << "CreateDataChannel failed."; 1865 << "CreateDataChannel failed.";
1864 return; 1866 return;
1865 } 1867 }
1866 channel->SetReceiveSsrc(remote_ssrc); 1868 channel->SetReceiveSsrc(remote_ssrc);
1867 observer_->OnDataChannel( 1869 observer_->OnDataChannel(
1868 DataChannelProxy::Create(signaling_thread(), channel)); 1870 DataChannelProxy::Create(signaling_thread(), nullptr, channel));
1869 } 1871 }
1870 1872
1871 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( 1873 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel(
1872 const std::string& label, 1874 const std::string& label,
1873 const InternalDataChannelInit* config) { 1875 const InternalDataChannelInit* config) {
1874 if (IsClosed()) { 1876 if (IsClosed()) {
1875 return nullptr; 1877 return nullptr;
1876 } 1878 }
1877 if (session_->data_channel_type() == cricket::DCT_NONE) { 1879 if (session_->data_channel_type() == cricket::DCT_NONE) {
1878 LOG(LS_ERROR) 1880 LOG(LS_ERROR)
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 const std::string& label, 1991 const std::string& label,
1990 const InternalDataChannelInit& config) { 1992 const InternalDataChannelInit& config) {
1991 rtc::scoped_refptr<DataChannel> channel( 1993 rtc::scoped_refptr<DataChannel> channel(
1992 InternalCreateDataChannel(label, &config)); 1994 InternalCreateDataChannel(label, &config));
1993 if (!channel.get()) { 1995 if (!channel.get()) {
1994 LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message."; 1996 LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message.";
1995 return; 1997 return;
1996 } 1998 }
1997 1999
1998 observer_->OnDataChannel( 2000 observer_->OnDataChannel(
1999 DataChannelProxy::Create(signaling_thread(), channel)); 2001 DataChannelProxy::Create(signaling_thread(), nullptr, channel));
2000 } 2002 }
2001 2003
2002 RtpSenderInterface* PeerConnection::FindSenderById(const std::string& id) { 2004 RtpSenderInterface* PeerConnection::FindSenderById(const std::string& id) {
2003 auto it = 2005 auto it =
2004 std::find_if(senders_.begin(), senders_.end(), 2006 std::find_if(senders_.begin(), senders_.end(),
2005 [id](const rtc::scoped_refptr<RtpSenderInterface>& sender) { 2007 [id](const rtc::scoped_refptr<RtpSenderInterface>& sender) {
2006 return sender->id() == id; 2008 return sender->id() == id;
2007 }); 2009 });
2008 return it != senders_.end() ? it->get() : nullptr; 2010 return it != senders_.end() ? it->get() : nullptr;
2009 } 2011 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2060 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2059 for (const auto& channel : sctp_data_channels_) { 2061 for (const auto& channel : sctp_data_channels_) {
2060 if (channel->id() == sid) { 2062 if (channel->id() == sid) {
2061 return channel; 2063 return channel;
2062 } 2064 }
2063 } 2065 }
2064 return nullptr; 2066 return nullptr;
2065 } 2067 }
2066 2068
2067 } // namespace webrtc 2069 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698