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 |
11 #include "webrtc/api/peerconnection.h" | 11 #include "webrtc/api/peerconnection.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <cctype> // for isdigit | 14 #include <cctype> // for isdigit |
15 #include <utility> | 15 #include <utility> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/api/audiotrack.h" | 18 #include "webrtc/api/audiotrack.h" |
19 #include "webrtc/api/dtmfsender.h" | 19 #include "webrtc/api/dtmfsender.h" |
20 #include "webrtc/api/jsepicecandidate.h" | 20 #include "webrtc/api/jsepicecandidate.h" |
21 #include "webrtc/api/jsepsessiondescription.h" | 21 #include "webrtc/api/jsepsessiondescription.h" |
22 #include "webrtc/api/mediaconstraintsinterface.h" | |
23 #include "webrtc/api/mediastream.h" | 22 #include "webrtc/api/mediastream.h" |
24 #include "webrtc/api/mediastreamobserver.h" | 23 #include "webrtc/api/mediastreamobserver.h" |
25 #include "webrtc/api/mediastreamproxy.h" | 24 #include "webrtc/api/mediastreamproxy.h" |
26 #include "webrtc/api/mediastreamtrackproxy.h" | 25 #include "webrtc/api/mediastreamtrackproxy.h" |
27 #include "webrtc/api/remoteaudiosource.h" | 26 #include "webrtc/api/remoteaudiosource.h" |
28 #include "webrtc/api/remotevideocapturer.h" | 27 #include "webrtc/api/remotevideocapturer.h" |
29 #include "webrtc/api/rtpreceiver.h" | 28 #include "webrtc/api/rtpreceiver.h" |
30 #include "webrtc/api/rtpsender.h" | 29 #include "webrtc/api/rtpsender.h" |
31 #include "webrtc/api/streamcollection.h" | 30 #include "webrtc/api/streamcollection.h" |
32 #include "webrtc/api/videosource.h" | 31 #include "webrtc/api/videosource.h" |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 // Candidates must have unique priorities, so that connectivity checks | 532 // Candidates must have unique priorities, so that connectivity checks |
534 // are performed in a well-defined order. | 533 // are performed in a well-defined order. |
535 int priority = static_cast<int>(turn_servers->size() - 1); | 534 int priority = static_cast<int>(turn_servers->size() - 1); |
536 for (cricket::RelayServerConfig& turn_server : *turn_servers) { | 535 for (cricket::RelayServerConfig& turn_server : *turn_servers) { |
537 // First in the list gets highest priority. | 536 // First in the list gets highest priority. |
538 turn_server.priority = priority--; | 537 turn_server.priority = priority--; |
539 } | 538 } |
540 return true; | 539 return true; |
541 } | 540 } |
542 | 541 |
542 class PeerConnection::StoredConstraints : public MediaConstraintsInterface { | |
543 public: | |
544 explicit StoredConstraints(const MediaConstraintsInterface* constraints) { | |
545 if (constraints) { | |
546 mandatory_ = constraints->GetMandatory(); | |
547 optional_ = constraints->GetOptional(); | |
548 } | |
549 } | |
550 ~StoredConstraints() override {} | |
551 | |
552 const MediaConstraintsInterface::Constraints& | |
553 GetMandatory() const override { return mandatory_; } | |
554 const MediaConstraintsInterface::Constraints& | |
555 GetOptional() const override { return optional_; } | |
556 private: | |
557 MediaConstraintsInterface::Constraints mandatory_; | |
558 MediaConstraintsInterface::Constraints optional_; | |
559 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(StoredConstraints); | |
560 }; | |
561 | |
562 class PeerConnection::LiveSession { | |
pthatcher1
2016/02/26 21:51:20
What is a LiveSession? It appears to be a random
the sun
2016/02/29 15:58:22
Indeed. Great suggestion! Look at the current solu
| |
563 public: | |
564 LiveSession(PeerConnection* pc, | |
565 PeerConnectionFactory* factory, | |
566 cricket::PortAllocator* port_allocator, | |
567 const cricket::MediaConfig& media_config, | |
568 const PeerConnectionInterface::RTCConfiguration& configuration, | |
569 const MediaConstraintsInterface* constraints, | |
570 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store) { | |
571 RTC_DCHECK(pc); | |
572 RTC_DCHECK(factory); | |
573 RTC_DCHECK(port_allocator); | |
574 RTC_DCHECK(constraints); | |
575 media_controller_.reset(factory->CreateMediaController(media_config)); | |
576 remote_stream_factory_.reset(new RemoteMediaStreamFactory( | |
577 factory->signaling_thread(), media_controller_->channel_manager())); | |
578 session_.reset( | |
579 new WebRtcSession(media_controller_.get(), factory->signaling_thread(), | |
580 factory->worker_thread(), port_allocator)); | |
581 stats_.reset(new StatsCollector(pc)); | |
582 | |
583 // Initialize the WebRtcSession. It creates transport channels etc. | |
584 RTC_CHECK(session_->Initialize(factory->options(), constraints, | |
585 std::move(dtls_identity_store), configuration)); | |
586 | |
587 // Register PeerConnection as receiver of local ice candidates. | |
588 // All the callbacks will be posted to the application from PeerConnection. | |
589 session_->RegisterIceObserver(pc); | |
590 session_->SignalState.connect(pc, &PeerConnection::OnSessionStateChange); | |
591 session_->SignalVoiceChannelDestroyed.connect( | |
592 pc, &PeerConnection::OnVoiceChannelDestroyed); | |
593 session_->SignalVideoChannelDestroyed.connect( | |
594 pc, &PeerConnection::OnVideoChannelDestroyed); | |
595 session_->SignalDataChannelCreated.connect( | |
596 pc, &PeerConnection::OnDataChannelCreated); | |
597 session_->SignalDataChannelDestroyed.connect( | |
598 pc, &PeerConnection::OnDataChannelDestroyed); | |
599 session_->SignalDataChannelOpenMessage.connect( | |
600 pc, &PeerConnection::OnDataChannelOpenMessage); | |
601 } | |
602 | |
603 ~LiveSession() { | |
604 // TODO(solenberg): Disconnect signals. Kill kill kill. | |
605 } | |
606 | |
607 RemoteMediaStreamFactory* remote_stream_factory() { | |
608 return remote_stream_factory_.get(); | |
609 } | |
610 WebRtcSession* session() { | |
611 return session_.get(); | |
612 } | |
613 StatsCollector* stats() { | |
614 return stats_.get(); | |
615 } | |
616 | |
617 private: | |
618 rtc::scoped_ptr<MediaControllerInterface> media_controller_; | |
619 rtc::scoped_ptr<RemoteMediaStreamFactory> remote_stream_factory_; | |
620 // The session_ scoped_ptr is declared at the bottom of PeerConnection | |
621 // because its destruction fires signals (such as VoiceChannelDestroyed) | |
622 // which will trigger some final actions in PeerConnection... | |
623 rtc::scoped_ptr<WebRtcSession> session_; | |
624 // ... But stats_ depends on session_ so it should be destroyed even earlier. | |
625 rtc::scoped_ptr<StatsCollector> stats_; | |
626 | |
627 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(LiveSession); | |
628 }; | |
629 | |
543 PeerConnection::PeerConnection(PeerConnectionFactory* factory) | 630 PeerConnection::PeerConnection(PeerConnectionFactory* factory) |
544 : factory_(factory), | 631 : factory_(factory), |
545 observer_(NULL), | 632 observer_(NULL), |
546 uma_observer_(NULL), | 633 uma_observer_(NULL), |
547 signaling_state_(kStable), | 634 signaling_state_(kStable), |
548 ice_state_(kIceNew), | 635 ice_state_(kIceNew), |
549 ice_connection_state_(kIceConnectionNew), | 636 ice_connection_state_(kIceConnectionNew), |
550 ice_gathering_state_(kIceGatheringNew), | 637 ice_gathering_state_(kIceGatheringNew), |
551 local_streams_(StreamCollection::Create()), | 638 local_streams_(StreamCollection::Create()), |
552 remote_streams_(StreamCollection::Create()) {} | 639 remote_streams_(StreamCollection::Create()) {} |
553 | 640 |
554 PeerConnection::~PeerConnection() { | 641 PeerConnection::~PeerConnection() { |
555 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); | 642 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); |
556 RTC_DCHECK(signaling_thread()->IsCurrent()); | 643 RTC_DCHECK(signaling_thread()->IsCurrent()); |
557 // Need to detach RTP senders/receivers from WebRtcSession, | 644 DestroyLiveSession(); |
558 // since it's about to be destroyed. | |
559 for (const auto& sender : senders_) { | |
560 sender->Stop(); | |
561 } | |
562 for (const auto& receiver : receivers_) { | |
563 receiver->Stop(); | |
564 } | |
565 } | 645 } |
566 | 646 |
567 bool PeerConnection::Initialize( | 647 bool PeerConnection::Initialize( |
568 const PeerConnectionInterface::RTCConfiguration& configuration, | 648 const PeerConnectionInterface::RTCConfiguration& configuration, |
569 const MediaConstraintsInterface* constraints, | 649 const MediaConstraintsInterface* constraints, |
570 rtc::scoped_ptr<cricket::PortAllocator> allocator, | 650 rtc::scoped_ptr<cricket::PortAllocator> allocator, |
571 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 651 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
572 PeerConnectionObserver* observer) { | 652 PeerConnectionObserver* observer) { |
573 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); | 653 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
574 RTC_DCHECK(observer != nullptr); | 654 RTC_DCHECK(observer != nullptr); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { | 686 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { |
607 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | 687 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
608 LOG(LS_INFO) << "TCP candidates are disabled."; | 688 LOG(LS_INFO) << "TCP candidates are disabled."; |
609 } | 689 } |
610 | 690 |
611 port_allocator_->set_flags(portallocator_flags); | 691 port_allocator_->set_flags(portallocator_flags); |
612 // No step delay is used while allocating ports. | 692 // No step delay is used while allocating ports. |
613 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); | 693 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
614 | 694 |
615 // We rely on default values when constraints aren't found. | 695 // We rely on default values when constraints aren't found. |
616 cricket::MediaConfig media_config; | 696 media_config_.disable_prerenderer_smoothing = |
617 | |
618 media_config.disable_prerenderer_smoothing = | |
619 configuration.disable_prerenderer_smoothing; | 697 configuration.disable_prerenderer_smoothing; |
620 | 698 |
621 // Find DSCP constraint. | 699 // Find DSCP constraint. |
622 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, | 700 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, |
623 &media_config.enable_dscp, NULL); | 701 &media_config_.enable_dscp, NULL); |
624 // Find constraints for cpu overuse detection. | 702 // Find constraints for cpu overuse detection. |
625 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, | 703 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, |
626 &media_config.enable_cpu_overuse_detection, NULL); | 704 &media_config_.enable_cpu_overuse_detection, NULL); |
627 | 705 |
628 media_controller_.reset(factory_->CreateMediaController(media_config)); | 706 configuration_ = configuration; |
629 | 707 constraints_.reset(new StoredConstraints(constraints)); |
630 remote_stream_factory_.reset(new RemoteMediaStreamFactory( | 708 dtls_identity_store_ = std::move(dtls_identity_store); |
631 factory_->signaling_thread(), media_controller_->channel_manager())); | |
632 | |
633 session_.reset( | |
634 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), | |
635 factory_->worker_thread(), port_allocator_.get())); | |
636 stats_.reset(new StatsCollector(this)); | |
637 | |
638 // Initialize the WebRtcSession. It creates transport channels etc. | |
639 if (!session_->Initialize(factory_->options(), constraints, | |
640 std::move(dtls_identity_store), configuration)) { | |
641 return false; | |
642 } | |
643 | |
644 // Register PeerConnection as receiver of local ice candidates. | |
645 // All the callbacks will be posted to the application from PeerConnection. | |
646 session_->RegisterIceObserver(this); | |
647 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); | |
648 session_->SignalVoiceChannelDestroyed.connect( | |
649 this, &PeerConnection::OnVoiceChannelDestroyed); | |
650 session_->SignalVideoChannelDestroyed.connect( | |
651 this, &PeerConnection::OnVideoChannelDestroyed); | |
652 session_->SignalDataChannelCreated.connect( | |
653 this, &PeerConnection::OnDataChannelCreated); | |
654 session_->SignalDataChannelDestroyed.connect( | |
655 this, &PeerConnection::OnDataChannelDestroyed); | |
656 session_->SignalDataChannelOpenMessage.connect( | |
657 this, &PeerConnection::OnDataChannelOpenMessage); | |
658 return true; | 709 return true; |
659 } | 710 } |
660 | 711 |
661 rtc::scoped_refptr<StreamCollectionInterface> | 712 rtc::scoped_refptr<StreamCollectionInterface> |
662 PeerConnection::local_streams() { | 713 PeerConnection::local_streams() { |
663 return local_streams_; | 714 return local_streams_; |
664 } | 715 } |
665 | 716 |
666 rtc::scoped_refptr<StreamCollectionInterface> | 717 rtc::scoped_refptr<StreamCollectionInterface> |
667 PeerConnection::remote_streams() { | 718 PeerConnection::remote_streams() { |
(...skipping 21 matching lines...) Expand all Loading... | |
689 this, &PeerConnection::OnVideoTrackRemoved); | 740 this, &PeerConnection::OnVideoTrackRemoved); |
690 stream_observers_.push_back(rtc::scoped_ptr<MediaStreamObserver>(observer)); | 741 stream_observers_.push_back(rtc::scoped_ptr<MediaStreamObserver>(observer)); |
691 | 742 |
692 for (const auto& track : local_stream->GetAudioTracks()) { | 743 for (const auto& track : local_stream->GetAudioTracks()) { |
693 OnAudioTrackAdded(track.get(), local_stream); | 744 OnAudioTrackAdded(track.get(), local_stream); |
694 } | 745 } |
695 for (const auto& track : local_stream->GetVideoTracks()) { | 746 for (const auto& track : local_stream->GetVideoTracks()) { |
696 OnVideoTrackAdded(track.get(), local_stream); | 747 OnVideoTrackAdded(track.get(), local_stream); |
697 } | 748 } |
698 | 749 |
699 stats_->AddStream(local_stream); | 750 stats()->AddStream(local_stream); |
700 observer_->OnRenegotiationNeeded(); | 751 observer_->OnRenegotiationNeeded(); |
701 return true; | 752 return true; |
702 } | 753 } |
703 | 754 |
704 void PeerConnection::RemoveStream(MediaStreamInterface* local_stream) { | 755 void PeerConnection::RemoveStream(MediaStreamInterface* local_stream) { |
705 TRACE_EVENT0("webrtc", "PeerConnection::RemoveStream"); | 756 TRACE_EVENT0("webrtc", "PeerConnection::RemoveStream"); |
706 for (const auto& track : local_stream->GetAudioTracks()) { | 757 for (const auto& track : local_stream->GetAudioTracks()) { |
707 OnAudioTrackRemoved(track.get(), local_stream); | 758 OnAudioTrackRemoved(track.get(), local_stream); |
708 } | 759 } |
709 for (const auto& track : local_stream->GetVideoTracks()) { | 760 for (const auto& track : local_stream->GetVideoTracks()) { |
(...skipping 21 matching lines...) Expand all Loading... | |
731 std::vector<MediaStreamInterface*> streams) { | 782 std::vector<MediaStreamInterface*> streams) { |
732 TRACE_EVENT0("webrtc", "PeerConnection::AddTrack"); | 783 TRACE_EVENT0("webrtc", "PeerConnection::AddTrack"); |
733 if (IsClosed()) { | 784 if (IsClosed()) { |
734 return nullptr; | 785 return nullptr; |
735 } | 786 } |
736 if (streams.size() >= 2) { | 787 if (streams.size() >= 2) { |
737 LOG(LS_ERROR) | 788 LOG(LS_ERROR) |
738 << "Adding a track with two streams is not currently supported."; | 789 << "Adding a track with two streams is not currently supported."; |
739 return nullptr; | 790 return nullptr; |
740 } | 791 } |
792 | |
741 // TODO(deadbeef): Support adding a track to two different senders. | 793 // TODO(deadbeef): Support adding a track to two different senders. |
742 if (FindSenderForTrack(track) != senders_.end()) { | 794 if (FindSenderForTrack(track) != senders_.end()) { |
743 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; | 795 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; |
744 return nullptr; | 796 return nullptr; |
745 } | 797 } |
746 | 798 |
747 // TODO(deadbeef): Support adding a track to multiple streams. | 799 // TODO(deadbeef): Support adding a track to multiple streams. |
748 rtc::scoped_refptr<RtpSenderInterface> new_sender; | 800 rtc::scoped_refptr<RtpSenderInterface> new_sender; |
749 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { | 801 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { |
750 new_sender = RtpSenderProxy::Create( | 802 new_sender = RtpSenderProxy::Create( |
751 signaling_thread(), | 803 signaling_thread(), |
752 new AudioRtpSender(static_cast<AudioTrackInterface*>(track), | 804 new AudioRtpSender(static_cast<AudioTrackInterface*>(track), session(), |
753 session_.get(), stats_.get())); | 805 stats())); |
754 if (!streams.empty()) { | 806 if (!streams.empty()) { |
755 new_sender->set_stream_id(streams[0]->label()); | 807 new_sender->set_stream_id(streams[0]->label()); |
756 } | 808 } |
757 const TrackInfo* track_info = FindTrackInfo( | 809 const TrackInfo* track_info = FindTrackInfo( |
758 local_audio_tracks_, new_sender->stream_id(), track->id()); | 810 local_audio_tracks_, new_sender->stream_id(), track->id()); |
759 if (track_info) { | 811 if (track_info) { |
760 new_sender->SetSsrc(track_info->ssrc); | 812 new_sender->SetSsrc(track_info->ssrc); |
761 } | 813 } |
762 } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) { | 814 } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) { |
763 new_sender = RtpSenderProxy::Create( | 815 new_sender = RtpSenderProxy::Create( |
764 signaling_thread(), | 816 signaling_thread(), |
765 new VideoRtpSender(static_cast<VideoTrackInterface*>(track), | 817 new VideoRtpSender(static_cast<VideoTrackInterface*>(track), |
766 session_.get())); | 818 session())); |
767 if (!streams.empty()) { | 819 if (!streams.empty()) { |
768 new_sender->set_stream_id(streams[0]->label()); | 820 new_sender->set_stream_id(streams[0]->label()); |
769 } | 821 } |
770 const TrackInfo* track_info = FindTrackInfo( | 822 const TrackInfo* track_info = FindTrackInfo( |
771 local_video_tracks_, new_sender->stream_id(), track->id()); | 823 local_video_tracks_, new_sender->stream_id(), track->id()); |
772 if (track_info) { | 824 if (track_info) { |
773 new_sender->SetSsrc(track_info->ssrc); | 825 new_sender->SetSsrc(track_info->ssrc); |
774 } | 826 } |
775 } else { | 827 } else { |
776 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << track->kind(); | 828 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << track->kind(); |
(...skipping 16 matching lines...) Expand all Loading... | |
793 LOG(LS_ERROR) << "Couldn't find sender " << sender->id() << " to remove."; | 845 LOG(LS_ERROR) << "Couldn't find sender " << sender->id() << " to remove."; |
794 return false; | 846 return false; |
795 } | 847 } |
796 (*it)->Stop(); | 848 (*it)->Stop(); |
797 senders_.erase(it); | 849 senders_.erase(it); |
798 | 850 |
799 observer_->OnRenegotiationNeeded(); | 851 observer_->OnRenegotiationNeeded(); |
800 return true; | 852 return true; |
801 } | 853 } |
802 | 854 |
855 WebRtcSession* PeerConnection::session() { | |
856 CreateLiveSession(); | |
857 return live_session_->session(); | |
858 } | |
859 | |
803 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( | 860 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( |
804 AudioTrackInterface* track) { | 861 AudioTrackInterface* track) { |
805 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); | 862 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); |
806 if (!track) { | 863 if (!track) { |
807 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; | 864 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; |
808 return NULL; | 865 return NULL; |
809 } | 866 } |
810 if (!local_streams_->FindAudioTrack(track->id())) { | 867 if (!local_streams_->FindAudioTrack(track->id())) { |
811 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; | 868 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; |
812 return NULL; | 869 return NULL; |
813 } | 870 } |
814 | 871 |
815 rtc::scoped_refptr<DtmfSenderInterface> sender( | 872 rtc::scoped_refptr<DtmfSenderInterface> sender( |
816 DtmfSender::Create(track, signaling_thread(), session_.get())); | 873 DtmfSender::Create(track, signaling_thread(), session())); |
817 if (!sender.get()) { | 874 if (!sender.get()) { |
818 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; | 875 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; |
819 return NULL; | 876 return NULL; |
820 } | 877 } |
821 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); | 878 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); |
822 } | 879 } |
823 | 880 |
824 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( | 881 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( |
825 const std::string& kind, | 882 const std::string& kind, |
826 const std::string& stream_id) { | 883 const std::string& stream_id) { |
827 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); | 884 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); |
828 rtc::scoped_refptr<RtpSenderInterface> new_sender; | 885 rtc::scoped_refptr<RtpSenderInterface> new_sender; |
829 if (kind == MediaStreamTrackInterface::kAudioKind) { | 886 if (kind == MediaStreamTrackInterface::kAudioKind) { |
830 new_sender = RtpSenderProxy::Create( | 887 new_sender = RtpSenderProxy::Create( |
831 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); | 888 signaling_thread(), new AudioRtpSender(session(), stats())); |
832 } else if (kind == MediaStreamTrackInterface::kVideoKind) { | 889 } else if (kind == MediaStreamTrackInterface::kVideoKind) { |
833 new_sender = RtpSenderProxy::Create(signaling_thread(), | 890 new_sender = RtpSenderProxy::Create(signaling_thread(), |
834 new VideoRtpSender(session_.get())); | 891 new VideoRtpSender(session())); |
835 } else { | 892 } else { |
836 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; | 893 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; |
837 return new_sender; | 894 return new_sender; |
838 } | 895 } |
839 if (!stream_id.empty()) { | 896 if (!stream_id.empty()) { |
840 new_sender->set_stream_id(stream_id); | 897 new_sender->set_stream_id(stream_id); |
841 } | 898 } |
842 senders_.push_back(new_sender); | 899 senders_.push_back(new_sender); |
843 return new_sender; | 900 return new_sender; |
844 } | 901 } |
(...skipping 11 matching lines...) Expand all Loading... | |
856 bool PeerConnection::GetStats(StatsObserver* observer, | 913 bool PeerConnection::GetStats(StatsObserver* observer, |
857 MediaStreamTrackInterface* track, | 914 MediaStreamTrackInterface* track, |
858 StatsOutputLevel level) { | 915 StatsOutputLevel level) { |
859 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); | 916 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); |
860 RTC_DCHECK(signaling_thread()->IsCurrent()); | 917 RTC_DCHECK(signaling_thread()->IsCurrent()); |
861 if (!VERIFY(observer != NULL)) { | 918 if (!VERIFY(observer != NULL)) { |
862 LOG(LS_ERROR) << "GetStats - observer is NULL."; | 919 LOG(LS_ERROR) << "GetStats - observer is NULL."; |
863 return false; | 920 return false; |
864 } | 921 } |
865 | 922 |
866 stats_->UpdateStats(level); | 923 stats()->UpdateStats(level); |
867 signaling_thread()->Post(this, MSG_GETSTATS, | 924 signaling_thread()->Post(this, MSG_GETSTATS, |
868 new GetStatsMsg(observer, track)); | 925 new GetStatsMsg(observer, track)); |
869 return true; | 926 return true; |
870 } | 927 } |
871 | 928 |
872 PeerConnectionInterface::SignalingState PeerConnection::signaling_state() { | 929 PeerConnectionInterface::SignalingState PeerConnection::signaling_state() { |
873 return signaling_state_; | 930 return signaling_state_; |
874 } | 931 } |
875 | 932 |
876 PeerConnectionInterface::IceState PeerConnection::ice_state() { | 933 PeerConnectionInterface::IceState PeerConnection::ice_state() { |
(...skipping 22 matching lines...) Expand all Loading... | |
899 internal_config.reset(new InternalDataChannelInit(*config)); | 956 internal_config.reset(new InternalDataChannelInit(*config)); |
900 } | 957 } |
901 rtc::scoped_refptr<DataChannelInterface> channel( | 958 rtc::scoped_refptr<DataChannelInterface> channel( |
902 InternalCreateDataChannel(label, internal_config.get())); | 959 InternalCreateDataChannel(label, internal_config.get())); |
903 if (!channel.get()) { | 960 if (!channel.get()) { |
904 return nullptr; | 961 return nullptr; |
905 } | 962 } |
906 | 963 |
907 // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or | 964 // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or |
908 // the first SCTP DataChannel. | 965 // the first SCTP DataChannel. |
909 if (session_->data_channel_type() == cricket::DCT_RTP || first_datachannel) { | 966 if (session()->data_channel_type() == cricket::DCT_RTP || first_datachannel) { |
910 observer_->OnRenegotiationNeeded(); | 967 observer_->OnRenegotiationNeeded(); |
911 } | 968 } |
912 | 969 |
913 return DataChannelProxy::Create(signaling_thread(), channel.get()); | 970 return DataChannelProxy::Create(signaling_thread(), channel.get()); |
914 } | 971 } |
915 | 972 |
916 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, | 973 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, |
917 const MediaConstraintsInterface* constraints) { | 974 const MediaConstraintsInterface* constraints) { |
918 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); | 975 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); |
919 if (!VERIFY(observer != nullptr)) { | 976 if (!VERIFY(observer != nullptr)) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
974 } | 1031 } |
975 | 1032 |
976 cricket::MediaSessionOptions session_options; | 1033 cricket::MediaSessionOptions session_options; |
977 if (!GetOptionsForOffer(options, &session_options)) { | 1034 if (!GetOptionsForOffer(options, &session_options)) { |
978 std::string error = "CreateOffer called with invalid options."; | 1035 std::string error = "CreateOffer called with invalid options."; |
979 LOG(LS_ERROR) << error; | 1036 LOG(LS_ERROR) << error; |
980 PostCreateSessionDescriptionFailure(observer, error); | 1037 PostCreateSessionDescriptionFailure(observer, error); |
981 return; | 1038 return; |
982 } | 1039 } |
983 | 1040 |
984 session_->CreateOffer(observer, options, session_options); | 1041 session()->CreateOffer(observer, options, session_options); |
985 } | 1042 } |
986 | 1043 |
987 void PeerConnection::CreateAnswer( | 1044 void PeerConnection::CreateAnswer( |
988 CreateSessionDescriptionObserver* observer, | 1045 CreateSessionDescriptionObserver* observer, |
989 const MediaConstraintsInterface* constraints) { | 1046 const MediaConstraintsInterface* constraints) { |
990 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); | 1047 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); |
991 if (!VERIFY(observer != nullptr)) { | 1048 if (!VERIFY(observer != nullptr)) { |
992 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; | 1049 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; |
993 return; | 1050 return; |
994 } | 1051 } |
995 | 1052 |
996 cricket::MediaSessionOptions session_options; | 1053 cricket::MediaSessionOptions session_options; |
997 if (!GetOptionsForAnswer(constraints, &session_options)) { | 1054 if (!GetOptionsForAnswer(constraints, &session_options)) { |
998 std::string error = "CreateAnswer called with invalid constraints."; | 1055 std::string error = "CreateAnswer called with invalid constraints."; |
999 LOG(LS_ERROR) << error; | 1056 LOG(LS_ERROR) << error; |
1000 PostCreateSessionDescriptionFailure(observer, error); | 1057 PostCreateSessionDescriptionFailure(observer, error); |
1001 return; | 1058 return; |
1002 } | 1059 } |
1003 | 1060 |
1004 session_->CreateAnswer(observer, constraints, session_options); | 1061 session()->CreateAnswer(observer, constraints, session_options); |
1005 } | 1062 } |
1006 | 1063 |
1007 void PeerConnection::SetLocalDescription( | 1064 void PeerConnection::SetLocalDescription( |
1008 SetSessionDescriptionObserver* observer, | 1065 SetSessionDescriptionObserver* observer, |
1009 SessionDescriptionInterface* desc) { | 1066 SessionDescriptionInterface* desc) { |
1010 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); | 1067 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); |
1011 if (!VERIFY(observer != nullptr)) { | 1068 if (!VERIFY(observer != nullptr)) { |
1012 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; | 1069 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; |
1013 return; | 1070 return; |
1014 } | 1071 } |
1015 if (!desc) { | 1072 if (!desc) { |
1016 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); | 1073 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); |
1017 return; | 1074 return; |
1018 } | 1075 } |
1019 // Update stats here so that we have the most recent stats for tracks and | 1076 // Update stats here so that we have the most recent stats for tracks and |
1020 // streams that might be removed by updating the session description. | 1077 // streams that might be removed by updating the session description. |
1021 stats_->UpdateStats(kStatsOutputLevelStandard); | 1078 stats()->UpdateStats(kStatsOutputLevelStandard); |
1022 std::string error; | 1079 std::string error; |
1023 if (!session_->SetLocalDescription(desc, &error)) { | 1080 if (!session()->SetLocalDescription(desc, &error)) { |
1024 PostSetSessionDescriptionFailure(observer, error); | 1081 PostSetSessionDescriptionFailure(observer, error); |
1025 return; | 1082 return; |
1026 } | 1083 } |
1027 | 1084 |
1028 // If setting the description decided our SSL role, allocate any necessary | 1085 // If setting the description decided our SSL role, allocate any necessary |
1029 // SCTP sids. | 1086 // SCTP sids. |
1030 rtc::SSLRole role; | 1087 rtc::SSLRole role; |
1031 if (session_->data_channel_type() == cricket::DCT_SCTP && | 1088 if (session()->data_channel_type() == cricket::DCT_SCTP && |
1032 session_->GetSslRole(session_->data_channel(), &role)) { | 1089 session()->GetSslRole(session()->data_channel(), &role)) { |
1033 AllocateSctpSids(role); | 1090 AllocateSctpSids(role); |
1034 } | 1091 } |
1035 | 1092 |
1036 // Update state and SSRC of local MediaStreams and DataChannels based on the | 1093 // Update state and SSRC of local MediaStreams and DataChannels based on the |
1037 // local session description. | 1094 // local session description. |
1038 const cricket::ContentInfo* audio_content = | 1095 const cricket::ContentInfo* audio_content = |
1039 GetFirstAudioContent(desc->description()); | 1096 GetFirstAudioContent(desc->description()); |
1040 if (audio_content) { | 1097 if (audio_content) { |
1041 if (audio_content->rejected) { | 1098 if (audio_content->rejected) { |
1042 RemoveTracks(cricket::MEDIA_TYPE_AUDIO); | 1099 RemoveTracks(cricket::MEDIA_TYPE_AUDIO); |
(...skipping 29 matching lines...) Expand all Loading... | |
1072 UpdateLocalRtpDataChannels(data_desc->streams()); | 1129 UpdateLocalRtpDataChannels(data_desc->streams()); |
1073 } | 1130 } |
1074 } | 1131 } |
1075 | 1132 |
1076 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1133 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1077 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); | 1134 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
1078 | 1135 |
1079 // MaybeStartGathering needs to be called after posting | 1136 // MaybeStartGathering needs to be called after posting |
1080 // MSG_SET_SESSIONDESCRIPTION_SUCCESS, so that we don't signal any candidates | 1137 // MSG_SET_SESSIONDESCRIPTION_SUCCESS, so that we don't signal any candidates |
1081 // before signaling that SetLocalDescription completed. | 1138 // before signaling that SetLocalDescription completed. |
1082 session_->MaybeStartGathering(); | 1139 session()->MaybeStartGathering(); |
1083 } | 1140 } |
1084 | 1141 |
1085 void PeerConnection::SetRemoteDescription( | 1142 void PeerConnection::SetRemoteDescription( |
1086 SetSessionDescriptionObserver* observer, | 1143 SetSessionDescriptionObserver* observer, |
1087 SessionDescriptionInterface* desc) { | 1144 SessionDescriptionInterface* desc) { |
1088 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); | 1145 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); |
1089 if (!VERIFY(observer != nullptr)) { | 1146 if (!VERIFY(observer != nullptr)) { |
1090 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL."; | 1147 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL."; |
1091 return; | 1148 return; |
1092 } | 1149 } |
1093 if (!desc) { | 1150 if (!desc) { |
1094 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); | 1151 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); |
1095 return; | 1152 return; |
1096 } | 1153 } |
1097 // Update stats here so that we have the most recent stats for tracks and | 1154 // Update stats here so that we have the most recent stats for tracks and |
1098 // streams that might be removed by updating the session description. | 1155 // streams that might be removed by updating the session description. |
1099 stats_->UpdateStats(kStatsOutputLevelStandard); | 1156 stats()->UpdateStats(kStatsOutputLevelStandard); |
1100 std::string error; | 1157 std::string error; |
1101 if (!session_->SetRemoteDescription(desc, &error)) { | 1158 if (!session()->SetRemoteDescription(desc, &error)) { |
1102 PostSetSessionDescriptionFailure(observer, error); | 1159 PostSetSessionDescriptionFailure(observer, error); |
1103 return; | 1160 return; |
1104 } | 1161 } |
1105 | 1162 |
1106 // If setting the description decided our SSL role, allocate any necessary | 1163 // If setting the description decided our SSL role, allocate any necessary |
1107 // SCTP sids. | 1164 // SCTP sids. |
1108 rtc::SSLRole role; | 1165 rtc::SSLRole role; |
1109 if (session_->data_channel_type() == cricket::DCT_SCTP && | 1166 if (session()->data_channel_type() == cricket::DCT_SCTP && |
1110 session_->GetSslRole(session_->data_channel(), &role)) { | 1167 session()->GetSslRole(session()->data_channel(), &role)) { |
1111 AllocateSctpSids(role); | 1168 AllocateSctpSids(role); |
1112 } | 1169 } |
1113 | 1170 |
1114 const cricket::SessionDescription* remote_desc = desc->description(); | 1171 const cricket::SessionDescription* remote_desc = desc->description(); |
1115 const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); | 1172 const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); |
1116 const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc); | 1173 const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc); |
1117 const cricket::AudioContentDescription* audio_desc = | 1174 const cricket::AudioContentDescription* audio_desc = |
1118 GetFirstAudioContentDescription(remote_desc); | 1175 GetFirstAudioContentDescription(remote_desc); |
1119 const cricket::VideoContentDescription* video_desc = | 1176 const cricket::VideoContentDescription* video_desc = |
1120 GetFirstVideoContentDescription(remote_desc); | 1177 GetFirstVideoContentDescription(remote_desc); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1167 if (data_desc) { | 1224 if (data_desc) { |
1168 if (rtc::starts_with(data_desc->protocol().data(), | 1225 if (rtc::starts_with(data_desc->protocol().data(), |
1169 cricket::kMediaProtocolRtpPrefix)) { | 1226 cricket::kMediaProtocolRtpPrefix)) { |
1170 UpdateRemoteRtpDataChannels(GetActiveStreams(data_desc)); | 1227 UpdateRemoteRtpDataChannels(GetActiveStreams(data_desc)); |
1171 } | 1228 } |
1172 } | 1229 } |
1173 | 1230 |
1174 // Iterate new_streams and notify the observer about new MediaStreams. | 1231 // Iterate new_streams and notify the observer about new MediaStreams. |
1175 for (size_t i = 0; i < new_streams->count(); ++i) { | 1232 for (size_t i = 0; i < new_streams->count(); ++i) { |
1176 MediaStreamInterface* new_stream = new_streams->at(i); | 1233 MediaStreamInterface* new_stream = new_streams->at(i); |
1177 stats_->AddStream(new_stream); | 1234 stats()->AddStream(new_stream); |
1178 observer_->OnAddStream(new_stream); | 1235 observer_->OnAddStream(new_stream); |
1179 } | 1236 } |
1180 | 1237 |
1181 UpdateEndedRemoteMediaStreams(); | 1238 UpdateEndedRemoteMediaStreams(); |
1182 | 1239 |
1183 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1240 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1184 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); | 1241 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
1185 } | 1242 } |
1186 | 1243 |
1187 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { | 1244 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { |
1188 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); | 1245 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); |
1189 if (port_allocator_) { | 1246 if (port_allocator_) { |
1190 cricket::ServerAddresses stun_servers; | 1247 cricket::ServerAddresses stun_servers; |
1191 std::vector<cricket::RelayServerConfig> turn_servers; | 1248 std::vector<cricket::RelayServerConfig> turn_servers; |
1192 if (!ParseIceServers(config.servers, &stun_servers, &turn_servers)) { | 1249 if (!ParseIceServers(config.servers, &stun_servers, &turn_servers)) { |
1193 return false; | 1250 return false; |
1194 } | 1251 } |
1195 port_allocator_->SetIceServers(stun_servers, turn_servers); | 1252 port_allocator_->SetIceServers(stun_servers, turn_servers); |
1196 } | 1253 } |
1197 session_->SetIceConfig(session_->ParseIceConfig(config)); | 1254 session()->SetIceConfig(session()->ParseIceConfig(config)); |
1198 return session_->SetIceTransports(config.type); | 1255 return session()->SetIceTransports(config.type); |
1199 } | 1256 } |
1200 | 1257 |
1201 bool PeerConnection::AddIceCandidate( | 1258 bool PeerConnection::AddIceCandidate( |
1202 const IceCandidateInterface* ice_candidate) { | 1259 const IceCandidateInterface* ice_candidate) { |
1203 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); | 1260 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); |
1204 return session_->ProcessIceMessage(ice_candidate); | 1261 return session()->ProcessIceMessage(ice_candidate); |
1205 } | 1262 } |
1206 | 1263 |
1207 void PeerConnection::RegisterUMAObserver(UMAObserver* observer) { | 1264 void PeerConnection::RegisterUMAObserver(UMAObserver* observer) { |
1208 TRACE_EVENT0("webrtc", "PeerConnection::RegisterUmaObserver"); | 1265 TRACE_EVENT0("webrtc", "PeerConnection::RegisterUmaObserver"); |
1209 uma_observer_ = observer; | 1266 uma_observer_ = observer; |
1210 | 1267 |
1211 if (session_) { | 1268 if (live_session_) { |
1212 session_->set_metrics_observer(uma_observer_); | 1269 session()->set_metrics_observer(uma_observer_); |
1213 } | 1270 } |
1214 | 1271 |
1215 // Send information about IPv4/IPv6 status. | 1272 // Send information about IPv4/IPv6 status. |
1216 if (uma_observer_ && port_allocator_) { | 1273 if (uma_observer_ && port_allocator_) { |
1217 if (port_allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6) { | 1274 if (port_allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6) { |
1218 uma_observer_->IncrementEnumCounter( | 1275 uma_observer_->IncrementEnumCounter( |
1219 kEnumCounterAddressFamily, kPeerConnection_IPv6, | 1276 kEnumCounterAddressFamily, kPeerConnection_IPv6, |
1220 kPeerConnectionAddressFamilyCounter_Max); | 1277 kPeerConnectionAddressFamilyCounter_Max); |
1221 } else { | 1278 } else { |
1222 uma_observer_->IncrementEnumCounter( | 1279 uma_observer_->IncrementEnumCounter( |
1223 kEnumCounterAddressFamily, kPeerConnection_IPv4, | 1280 kEnumCounterAddressFamily, kPeerConnection_IPv4, |
1224 kPeerConnectionAddressFamilyCounter_Max); | 1281 kPeerConnectionAddressFamilyCounter_Max); |
1225 } | 1282 } |
1226 } | 1283 } |
1227 } | 1284 } |
1228 | 1285 |
1229 const SessionDescriptionInterface* PeerConnection::local_description() const { | 1286 const SessionDescriptionInterface* PeerConnection::local_description() const { |
1230 return session_->local_description(); | 1287 return session()->local_description(); |
1231 } | 1288 } |
1232 | 1289 |
1233 const SessionDescriptionInterface* PeerConnection::remote_description() const { | 1290 const SessionDescriptionInterface* PeerConnection::remote_description() const { |
1234 return session_->remote_description(); | 1291 return session()->remote_description(); |
1235 } | 1292 } |
1236 | 1293 |
1237 void PeerConnection::Close() { | 1294 void PeerConnection::Close() { |
1238 TRACE_EVENT0("webrtc", "PeerConnection::Close"); | 1295 TRACE_EVENT0("webrtc", "PeerConnection::Close"); |
1239 // Update stats here so that we have the most recent stats for tracks and | 1296 // Update stats here so that we have the most recent stats for tracks and |
1240 // streams before the channels are closed. | 1297 // streams before the channels are closed. |
1241 stats_->UpdateStats(kStatsOutputLevelStandard); | 1298 stats()->UpdateStats(kStatsOutputLevelStandard); |
1242 | 1299 session()->Close(); |
1243 session_->Close(); | 1300 DestroyLiveSession(); |
1244 } | 1301 } |
1245 | 1302 |
1246 void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/, | 1303 void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/, |
1247 WebRtcSession::State state) { | 1304 WebRtcSession::State state) { |
1248 switch (state) { | 1305 switch (state) { |
1249 case WebRtcSession::STATE_INIT: | 1306 case WebRtcSession::STATE_INIT: |
1250 ChangeSignalingState(PeerConnectionInterface::kStable); | 1307 ChangeSignalingState(PeerConnectionInterface::kStable); |
1251 break; | 1308 break; |
1252 case WebRtcSession::STATE_SENTOFFER: | 1309 case WebRtcSession::STATE_SENTOFFER: |
1253 ChangeSignalingState(PeerConnectionInterface::kHaveLocalOffer); | 1310 ChangeSignalingState(PeerConnectionInterface::kHaveLocalOffer); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { | 1348 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { |
1292 CreateSessionDescriptionMsg* param = | 1349 CreateSessionDescriptionMsg* param = |
1293 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); | 1350 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); |
1294 param->observer->OnFailure(param->error); | 1351 param->observer->OnFailure(param->error); |
1295 delete param; | 1352 delete param; |
1296 break; | 1353 break; |
1297 } | 1354 } |
1298 case MSG_GETSTATS: { | 1355 case MSG_GETSTATS: { |
1299 GetStatsMsg* param = static_cast<GetStatsMsg*>(msg->pdata); | 1356 GetStatsMsg* param = static_cast<GetStatsMsg*>(msg->pdata); |
1300 StatsReports reports; | 1357 StatsReports reports; |
1301 stats_->GetStats(param->track, &reports); | 1358 stats()->GetStats(param->track, &reports); |
1302 param->observer->OnComplete(reports); | 1359 param->observer->OnComplete(reports); |
1303 delete param; | 1360 delete param; |
1304 break; | 1361 break; |
1305 } | 1362 } |
1306 case MSG_FREE_DATACHANNELS: { | 1363 case MSG_FREE_DATACHANNELS: { |
1307 sctp_data_channels_to_free_.clear(); | 1364 sctp_data_channels_to_free_.clear(); |
1308 break; | 1365 break; |
1309 } | 1366 } |
1310 default: | 1367 default: |
1311 RTC_DCHECK(false && "Not implemented"); | 1368 RTC_DCHECK(false && "Not implemented"); |
1312 break; | 1369 break; |
1313 } | 1370 } |
1314 } | 1371 } |
1315 | 1372 |
1316 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, | 1373 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, |
1317 AudioTrackInterface* audio_track, | 1374 AudioTrackInterface* audio_track, |
1318 uint32_t ssrc) { | 1375 uint32_t ssrc) { |
1319 receivers_.push_back(RtpReceiverProxy::Create( | 1376 receivers_.push_back(RtpReceiverProxy::Create( |
1320 signaling_thread(), | 1377 signaling_thread(), |
1321 new AudioRtpReceiver(audio_track, ssrc, session_.get()))); | 1378 new AudioRtpReceiver(audio_track, ssrc, session()))); |
1322 } | 1379 } |
1323 | 1380 |
1324 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, | 1381 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, |
1325 VideoTrackInterface* video_track, | 1382 VideoTrackInterface* video_track, |
1326 uint32_t ssrc) { | 1383 uint32_t ssrc) { |
1327 receivers_.push_back(RtpReceiverProxy::Create( | 1384 receivers_.push_back(RtpReceiverProxy::Create( |
1328 signaling_thread(), | 1385 signaling_thread(), |
1329 new VideoRtpReceiver(video_track, ssrc, session_.get()))); | 1386 new VideoRtpReceiver(video_track, ssrc, session()))); |
1330 } | 1387 } |
1331 | 1388 |
1332 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote | 1389 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote |
1333 // description. | 1390 // description. |
1334 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, | 1391 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, |
1335 AudioTrackInterface* audio_track) { | 1392 AudioTrackInterface* audio_track) { |
1336 auto it = FindReceiverForTrack(audio_track); | 1393 auto it = FindReceiverForTrack(audio_track); |
1337 if (it == receivers_.end()) { | 1394 if (it == receivers_.end()) { |
1338 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id() | 1395 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id() |
1339 << " doesn't exist."; | 1396 << " doesn't exist."; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1407 if (sender != senders_.end()) { | 1464 if (sender != senders_.end()) { |
1408 // We already have a sender for this track, so just change the stream_id | 1465 // We already have a sender for this track, so just change the stream_id |
1409 // so that it's correct in the next call to CreateOffer. | 1466 // so that it's correct in the next call to CreateOffer. |
1410 (*sender)->set_stream_id(stream->label()); | 1467 (*sender)->set_stream_id(stream->label()); |
1411 return; | 1468 return; |
1412 } | 1469 } |
1413 | 1470 |
1414 // Normal case; we've never seen this track before. | 1471 // Normal case; we've never seen this track before. |
1415 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( | 1472 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( |
1416 signaling_thread(), | 1473 signaling_thread(), |
1417 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get())); | 1474 new AudioRtpSender(track, stream->label(), session(), stats())); |
1418 senders_.push_back(new_sender); | 1475 senders_.push_back(new_sender); |
1419 // If the sender has already been configured in SDP, we call SetSsrc, | 1476 // If the sender has already been configured in SDP, we call SetSsrc, |
1420 // which will connect the sender to the underlying transport. This can | 1477 // which will connect the sender to the underlying transport. This can |
1421 // occur if a local session description that contains the ID of the sender | 1478 // occur if a local session description that contains the ID of the sender |
1422 // is set before AddStream is called. It can also occur if the local | 1479 // is set before AddStream is called. It can also occur if the local |
1423 // session description is not changed and RemoveStream is called, and | 1480 // session description is not changed and RemoveStream is called, and |
1424 // later AddStream is called again with the same stream. | 1481 // later AddStream is called again with the same stream. |
1425 const TrackInfo* track_info = | 1482 const TrackInfo* track_info = |
1426 FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); | 1483 FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); |
1427 if (track_info) { | 1484 if (track_info) { |
(...skipping 21 matching lines...) Expand all Loading... | |
1449 if (sender != senders_.end()) { | 1506 if (sender != senders_.end()) { |
1450 // We already have a sender for this track, so just change the stream_id | 1507 // We already have a sender for this track, so just change the stream_id |
1451 // so that it's correct in the next call to CreateOffer. | 1508 // so that it's correct in the next call to CreateOffer. |
1452 (*sender)->set_stream_id(stream->label()); | 1509 (*sender)->set_stream_id(stream->label()); |
1453 return; | 1510 return; |
1454 } | 1511 } |
1455 | 1512 |
1456 // Normal case; we've never seen this track before. | 1513 // Normal case; we've never seen this track before. |
1457 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( | 1514 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( |
1458 signaling_thread(), | 1515 signaling_thread(), |
1459 new VideoRtpSender(track, stream->label(), session_.get())); | 1516 new VideoRtpSender(track, stream->label(), session())); |
1460 senders_.push_back(new_sender); | 1517 senders_.push_back(new_sender); |
1461 const TrackInfo* track_info = | 1518 const TrackInfo* track_info = |
1462 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); | 1519 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); |
1463 if (track_info) { | 1520 if (track_info) { |
1464 new_sender->SetSsrc(track_info->ssrc); | 1521 new_sender->SetSsrc(track_info->ssrc); |
1465 } | 1522 } |
1466 } | 1523 } |
1467 | 1524 |
1468 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, | 1525 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, |
1469 MediaStreamInterface* stream) { | 1526 MediaStreamInterface* stream) { |
(...skipping 21 matching lines...) Expand all Loading... | |
1491 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); | 1548 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); |
1492 msg->error = error; | 1549 msg->error = error; |
1493 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); | 1550 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); |
1494 } | 1551 } |
1495 | 1552 |
1496 bool PeerConnection::GetOptionsForOffer( | 1553 bool PeerConnection::GetOptionsForOffer( |
1497 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 1554 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
1498 cricket::MediaSessionOptions* session_options) { | 1555 cricket::MediaSessionOptions* session_options) { |
1499 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1556 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
1500 // ContentInfos. | 1557 // ContentInfos. |
1501 if (session_->local_description()) { | 1558 if (session()->local_description()) { |
1502 for (const cricket::ContentInfo& content : | 1559 for (const cricket::ContentInfo& content : |
1503 session_->local_description()->description()->contents()) { | 1560 session()->local_description()->description()->contents()) { |
1504 session_options->transport_options[content.name] = | 1561 session_options->transport_options[content.name] = |
1505 cricket::TransportOptions(); | 1562 cricket::TransportOptions(); |
1506 } | 1563 } |
1507 } | 1564 } |
1508 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) { | 1565 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) { |
1509 return false; | 1566 return false; |
1510 } | 1567 } |
1511 | 1568 |
1512 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1569 AddSendStreams(session_options, senders_, rtp_data_channels_); |
1513 // Offer to receive audio/video if the constraint is not set and there are | 1570 // Offer to receive audio/video if the constraint is not set and there are |
1514 // send streams, or we're currently receiving. | 1571 // send streams, or we're currently receiving. |
1515 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { | 1572 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { |
1516 session_options->recv_audio = | 1573 session_options->recv_audio = |
1517 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || | 1574 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || |
1518 !remote_audio_tracks_.empty(); | 1575 !remote_audio_tracks_.empty(); |
1519 } | 1576 } |
1520 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { | 1577 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { |
1521 session_options->recv_video = | 1578 session_options->recv_video = |
1522 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) || | 1579 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) || |
1523 !remote_video_tracks_.empty(); | 1580 !remote_video_tracks_.empty(); |
1524 } | 1581 } |
1525 session_options->bundle_enabled = | 1582 session_options->bundle_enabled = |
1526 session_options->bundle_enabled && | 1583 session_options->bundle_enabled && |
1527 (session_options->has_audio() || session_options->has_video() || | 1584 (session_options->has_audio() || session_options->has_video() || |
1528 session_options->has_data()); | 1585 session_options->has_data()); |
1529 | 1586 |
1530 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { | 1587 if (session()->data_channel_type() == cricket::DCT_SCTP && |
1588 HasDataChannels()) { | |
1531 session_options->data_channel_type = cricket::DCT_SCTP; | 1589 session_options->data_channel_type = cricket::DCT_SCTP; |
1532 } | 1590 } |
1533 return true; | 1591 return true; |
1534 } | 1592 } |
1535 | 1593 |
1536 bool PeerConnection::GetOptionsForAnswer( | 1594 bool PeerConnection::GetOptionsForAnswer( |
1537 const MediaConstraintsInterface* constraints, | 1595 const MediaConstraintsInterface* constraints, |
1538 cricket::MediaSessionOptions* session_options) { | 1596 cricket::MediaSessionOptions* session_options) { |
1539 session_options->recv_audio = false; | 1597 session_options->recv_audio = false; |
1540 session_options->recv_video = false; | 1598 session_options->recv_video = false; |
1541 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1599 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
1542 // ContentInfos. | 1600 // ContentInfos. |
1543 if (session_->remote_description()) { | 1601 if (session()->remote_description()) { |
1544 // Initialize the transport_options map. | 1602 // Initialize the transport_options map. |
1545 for (const cricket::ContentInfo& content : | 1603 for (const cricket::ContentInfo& content : |
1546 session_->remote_description()->description()->contents()) { | 1604 session()->remote_description()->description()->contents()) { |
1547 session_options->transport_options[content.name] = | 1605 session_options->transport_options[content.name] = |
1548 cricket::TransportOptions(); | 1606 cricket::TransportOptions(); |
1549 } | 1607 } |
1550 } | 1608 } |
1551 if (!ParseConstraintsForAnswer(constraints, session_options)) { | 1609 if (!ParseConstraintsForAnswer(constraints, session_options)) { |
1552 return false; | 1610 return false; |
1553 } | 1611 } |
1554 | 1612 |
1555 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1613 AddSendStreams(session_options, senders_, rtp_data_channels_); |
1556 session_options->bundle_enabled = | 1614 session_options->bundle_enabled = |
1557 session_options->bundle_enabled && | 1615 session_options->bundle_enabled && |
1558 (session_options->has_audio() || session_options->has_video() || | 1616 (session_options->has_audio() || session_options->has_video() || |
1559 session_options->has_data()); | 1617 session_options->has_data()); |
1560 | 1618 |
1561 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 1619 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
1562 // are not signaled in the SDP so does not go through that path and must be | 1620 // are not signaled in the SDP so does not go through that path and must be |
1563 // handled here. | 1621 // handled here. |
1564 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1622 if (session()->data_channel_type() == cricket::DCT_SCTP) { |
1565 session_options->data_channel_type = cricket::DCT_SCTP; | 1623 session_options->data_channel_type = cricket::DCT_SCTP; |
1566 } | 1624 } |
1567 return true; | 1625 return true; |
1568 } | 1626 } |
1569 | 1627 |
1570 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { | 1628 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { |
1571 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); | 1629 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); |
1572 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, | 1630 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, |
1573 media_type, nullptr); | 1631 media_type, nullptr); |
1574 } | 1632 } |
(...skipping 28 matching lines...) Expand all Loading... | |
1603 // The sync_label is the MediaStream label and the |stream.id| is the | 1661 // The sync_label is the MediaStream label and the |stream.id| is the |
1604 // track id. | 1662 // track id. |
1605 const std::string& stream_label = params.sync_label; | 1663 const std::string& stream_label = params.sync_label; |
1606 const std::string& track_id = params.id; | 1664 const std::string& track_id = params.id; |
1607 uint32_t ssrc = params.first_ssrc(); | 1665 uint32_t ssrc = params.first_ssrc(); |
1608 | 1666 |
1609 rtc::scoped_refptr<MediaStreamInterface> stream = | 1667 rtc::scoped_refptr<MediaStreamInterface> stream = |
1610 remote_streams_->find(stream_label); | 1668 remote_streams_->find(stream_label); |
1611 if (!stream) { | 1669 if (!stream) { |
1612 // This is a new MediaStream. Create a new remote MediaStream. | 1670 // This is a new MediaStream. Create a new remote MediaStream. |
1613 stream = remote_stream_factory_->CreateMediaStream(stream_label); | 1671 stream = remote_stream_factory()->CreateMediaStream(stream_label); |
1614 remote_streams_->AddStream(stream); | 1672 remote_streams_->AddStream(stream); |
1615 new_streams->AddStream(stream); | 1673 new_streams->AddStream(stream); |
1616 } | 1674 } |
1617 | 1675 |
1618 const TrackInfo* track_info = | 1676 const TrackInfo* track_info = |
1619 FindTrackInfo(*current_tracks, stream_label, track_id); | 1677 FindTrackInfo(*current_tracks, stream_label, track_id); |
1620 if (!track_info) { | 1678 if (!track_info) { |
1621 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); | 1679 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); |
1622 OnRemoteTrackSeen(stream_label, track_id, ssrc, media_type); | 1680 OnRemoteTrackSeen(stream_label, track_id, ssrc, media_type); |
1623 } | 1681 } |
1624 } | 1682 } |
1625 | 1683 |
1626 // Add default track if necessary. | 1684 // Add default track if necessary. |
1627 if (default_track_needed) { | 1685 if (default_track_needed) { |
1628 rtc::scoped_refptr<MediaStreamInterface> default_stream = | 1686 rtc::scoped_refptr<MediaStreamInterface> default_stream = |
1629 remote_streams_->find(kDefaultStreamLabel); | 1687 remote_streams_->find(kDefaultStreamLabel); |
1630 if (!default_stream) { | 1688 if (!default_stream) { |
1631 // Create the new default MediaStream. | 1689 // Create the new default MediaStream. |
1632 default_stream = | 1690 default_stream = |
1633 remote_stream_factory_->CreateMediaStream(kDefaultStreamLabel); | 1691 remote_stream_factory()->CreateMediaStream(kDefaultStreamLabel); |
1634 remote_streams_->AddStream(default_stream); | 1692 remote_streams_->AddStream(default_stream); |
1635 new_streams->AddStream(default_stream); | 1693 new_streams->AddStream(default_stream); |
1636 } | 1694 } |
1637 std::string default_track_id = (media_type == cricket::MEDIA_TYPE_AUDIO) | 1695 std::string default_track_id = (media_type == cricket::MEDIA_TYPE_AUDIO) |
1638 ? kDefaultAudioTrackLabel | 1696 ? kDefaultAudioTrackLabel |
1639 : kDefaultVideoTrackLabel; | 1697 : kDefaultVideoTrackLabel; |
1640 const TrackInfo* default_track_info = | 1698 const TrackInfo* default_track_info = |
1641 FindTrackInfo(*current_tracks, kDefaultStreamLabel, default_track_id); | 1699 FindTrackInfo(*current_tracks, kDefaultStreamLabel, default_track_id); |
1642 if (!default_track_info) { | 1700 if (!default_track_info) { |
1643 current_tracks->push_back( | 1701 current_tracks->push_back( |
1644 TrackInfo(kDefaultStreamLabel, default_track_id, 0)); | 1702 TrackInfo(kDefaultStreamLabel, default_track_id, 0)); |
1645 OnRemoteTrackSeen(kDefaultStreamLabel, default_track_id, 0, media_type); | 1703 OnRemoteTrackSeen(kDefaultStreamLabel, default_track_id, 0, media_type); |
1646 } | 1704 } |
1647 } | 1705 } |
1648 } | 1706 } |
1649 | 1707 |
1650 void PeerConnection::OnRemoteTrackSeen(const std::string& stream_label, | 1708 void PeerConnection::OnRemoteTrackSeen(const std::string& stream_label, |
1651 const std::string& track_id, | 1709 const std::string& track_id, |
1652 uint32_t ssrc, | 1710 uint32_t ssrc, |
1653 cricket::MediaType media_type) { | 1711 cricket::MediaType media_type) { |
1654 MediaStreamInterface* stream = remote_streams_->find(stream_label); | 1712 MediaStreamInterface* stream = remote_streams_->find(stream_label); |
1655 | 1713 |
1656 if (media_type == cricket::MEDIA_TYPE_AUDIO) { | 1714 if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
1657 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack( | 1715 AudioTrackInterface* audio_track = remote_stream_factory()->AddAudioTrack( |
1658 ssrc, session_.get(), stream, track_id); | 1716 ssrc, session(), stream, track_id); |
1659 CreateAudioReceiver(stream, audio_track, ssrc); | 1717 CreateAudioReceiver(stream, audio_track, ssrc); |
1660 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 1718 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
1661 VideoTrackInterface* video_track = | 1719 VideoTrackInterface* video_track = |
1662 remote_stream_factory_->AddVideoTrack(stream, track_id); | 1720 remote_stream_factory()->AddVideoTrack(stream, track_id); |
1663 CreateVideoReceiver(stream, video_track, ssrc); | 1721 CreateVideoReceiver(stream, video_track, ssrc); |
1664 } else { | 1722 } else { |
1665 RTC_DCHECK(false && "Invalid media type"); | 1723 RTC_DCHECK(false && "Invalid media type"); |
1666 } | 1724 } |
1667 } | 1725 } |
1668 | 1726 |
1669 void PeerConnection::OnRemoteTrackRemoved(const std::string& stream_label, | 1727 void PeerConnection::OnRemoteTrackRemoved(const std::string& stream_label, |
1670 const std::string& track_id, | 1728 const std::string& track_id, |
1671 cricket::MediaType media_type) { | 1729 cricket::MediaType media_type) { |
1672 MediaStreamInterface* stream = remote_streams_->find(stream_label); | 1730 MediaStreamInterface* stream = remote_streams_->find(stream_label); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1902 observer_->OnDataChannel( | 1960 observer_->OnDataChannel( |
1903 DataChannelProxy::Create(signaling_thread(), channel)); | 1961 DataChannelProxy::Create(signaling_thread(), channel)); |
1904 } | 1962 } |
1905 | 1963 |
1906 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( | 1964 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( |
1907 const std::string& label, | 1965 const std::string& label, |
1908 const InternalDataChannelInit* config) { | 1966 const InternalDataChannelInit* config) { |
1909 if (IsClosed()) { | 1967 if (IsClosed()) { |
1910 return nullptr; | 1968 return nullptr; |
1911 } | 1969 } |
1912 if (session_->data_channel_type() == cricket::DCT_NONE) { | 1970 if (session()->data_channel_type() == cricket::DCT_NONE) { |
1913 LOG(LS_ERROR) | 1971 LOG(LS_ERROR) |
1914 << "InternalCreateDataChannel: Data is not supported in this call."; | 1972 << "InternalCreateDataChannel: Data is not supported in this call."; |
1915 return nullptr; | 1973 return nullptr; |
1916 } | 1974 } |
1917 InternalDataChannelInit new_config = | 1975 InternalDataChannelInit new_config = |
1918 config ? (*config) : InternalDataChannelInit(); | 1976 config ? (*config) : InternalDataChannelInit(); |
1919 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1977 if (session()->data_channel_type() == cricket::DCT_SCTP) { |
1920 if (new_config.id < 0) { | 1978 if (new_config.id < 0) { |
1921 rtc::SSLRole role; | 1979 rtc::SSLRole role; |
1922 if ((session_->GetSslRole(session_->data_channel(), &role)) && | 1980 if ((session()->GetSslRole(session()->data_channel(), &role)) && |
1923 !sid_allocator_.AllocateSid(role, &new_config.id)) { | 1981 !sid_allocator_.AllocateSid(role, &new_config.id)) { |
1924 LOG(LS_ERROR) << "No id can be allocated for the SCTP data channel."; | 1982 LOG(LS_ERROR) << "No id can be allocated for the SCTP data channel."; |
1925 return nullptr; | 1983 return nullptr; |
1926 } | 1984 } |
1927 } else if (!sid_allocator_.ReserveSid(new_config.id)) { | 1985 } else if (!sid_allocator_.ReserveSid(new_config.id)) { |
1928 LOG(LS_ERROR) << "Failed to create a SCTP data channel " | 1986 LOG(LS_ERROR) << "Failed to create a SCTP data channel " |
1929 << "because the id is already in use or out of range."; | 1987 << "because the id is already in use or out of range."; |
1930 return nullptr; | 1988 return nullptr; |
1931 } | 1989 } |
1932 } | 1990 } |
1933 | 1991 |
1934 rtc::scoped_refptr<DataChannel> channel(DataChannel::Create( | 1992 rtc::scoped_refptr<DataChannel> channel(DataChannel::Create( |
1935 session_.get(), session_->data_channel_type(), label, new_config)); | 1993 session(), session()->data_channel_type(), label, new_config)); |
1936 if (!channel) { | 1994 if (!channel) { |
1937 sid_allocator_.ReleaseSid(new_config.id); | 1995 sid_allocator_.ReleaseSid(new_config.id); |
1938 return nullptr; | 1996 return nullptr; |
1939 } | 1997 } |
1940 | 1998 |
1941 if (channel->data_channel_type() == cricket::DCT_RTP) { | 1999 if (channel->data_channel_type() == cricket::DCT_RTP) { |
1942 if (rtp_data_channels_.find(channel->label()) != rtp_data_channels_.end()) { | 2000 if (rtp_data_channels_.find(channel->label()) != rtp_data_channels_.end()) { |
1943 LOG(LS_ERROR) << "DataChannel with label " << channel->label() | 2001 LOG(LS_ERROR) << "DataChannel with label " << channel->label() |
1944 << " already exists."; | 2002 << " already exists."; |
1945 return nullptr; | 2003 return nullptr; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2092 | 2150 |
2093 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2151 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
2094 for (const auto& channel : sctp_data_channels_) { | 2152 for (const auto& channel : sctp_data_channels_) { |
2095 if (channel->id() == sid) { | 2153 if (channel->id() == sid) { |
2096 return channel; | 2154 return channel; |
2097 } | 2155 } |
2098 } | 2156 } |
2099 return nullptr; | 2157 return nullptr; |
2100 } | 2158 } |
2101 | 2159 |
2160 void PeerConnection::CreateLiveSession() { | |
2161 if (!live_session_) { | |
2162 live_session_.reset(new LiveSession(this, factory_.get(), | |
2163 port_allocator_.get(), media_config_, configuration_, | |
2164 constraints_.get(), std::move(dtls_identity_store_))); | |
2165 session()->set_metrics_observer(uma_observer_); | |
2166 } | |
2167 } | |
2168 | |
2169 void PeerConnection::DestroyLiveSession() { | |
2170 // Need to detach RTP senders/receivers from WebRtcSession, | |
2171 // since it's about to be destroyed. | |
2172 for (const auto& sender : senders_) { | |
2173 sender->Stop(); | |
2174 } | |
2175 for (const auto& receiver : receivers_) { | |
2176 receiver->Stop(); | |
2177 } | |
2178 live_session_.reset(nullptr); | |
2179 } | |
2180 | |
2181 const WebRtcSession* PeerConnection::session() const { | |
2182 const_cast<PeerConnection*>(this)->CreateLiveSession(); | |
2183 return live_session_->session(); | |
2184 } | |
2185 | |
2186 RemoteMediaStreamFactory* PeerConnection::remote_stream_factory() { | |
2187 CreateLiveSession(); | |
2188 return live_session_->remote_stream_factory(); | |
2189 } | |
2190 | |
2191 StatsCollector* PeerConnection::stats() { | |
2192 CreateLiveSession(); | |
2193 return live_session_->stats(); | |
2194 } | |
2195 | |
2102 } // namespace webrtc | 2196 } // namespace webrtc |
OLD | NEW |