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

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

Issue 1713043002: Late initialize MediaController, for less resource i.e. ProcessThread, usage by PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Ugly but implemented Created 4 years, 10 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 INVALID, // Unknown. 77 INVALID, // Unknown.
78 }; 78 };
79 static_assert(INVALID == arraysize(kValidIceServiceTypes), 79 static_assert(INVALID == arraysize(kValidIceServiceTypes),
80 "kValidIceServiceTypes must have as many strings as ServiceType " 80 "kValidIceServiceTypes must have as many strings as ServiceType "
81 "has values."); 81 "has values.");
82 82
83 enum { 83 enum {
84 MSG_SET_SESSIONDESCRIPTION_SUCCESS = 0, 84 MSG_SET_SESSIONDESCRIPTION_SUCCESS = 0,
85 MSG_SET_SESSIONDESCRIPTION_FAILED, 85 MSG_SET_SESSIONDESCRIPTION_FAILED,
86 MSG_CREATE_SESSIONDESCRIPTION_FAILED, 86 MSG_CREATE_SESSIONDESCRIPTION_FAILED,
87 MSG_GETSTATS,
88 MSG_FREE_DATACHANNELS, 87 MSG_FREE_DATACHANNELS,
89 }; 88 };
90 89
91 struct SetSessionDescriptionMsg : public rtc::MessageData { 90 struct SetSessionDescriptionMsg : public rtc::MessageData {
92 explicit SetSessionDescriptionMsg( 91 explicit SetSessionDescriptionMsg(
93 webrtc::SetSessionDescriptionObserver* observer) 92 webrtc::SetSessionDescriptionObserver* observer)
94 : observer(observer) { 93 : observer(observer) {
95 } 94 }
96 95
97 rtc::scoped_refptr<webrtc::SetSessionDescriptionObserver> observer; 96 rtc::scoped_refptr<webrtc::SetSessionDescriptionObserver> observer;
98 std::string error; 97 std::string error;
99 }; 98 };
100 99
101 struct CreateSessionDescriptionMsg : public rtc::MessageData { 100 struct CreateSessionDescriptionMsg : public rtc::MessageData {
102 explicit CreateSessionDescriptionMsg( 101 explicit CreateSessionDescriptionMsg(
103 webrtc::CreateSessionDescriptionObserver* observer) 102 webrtc::CreateSessionDescriptionObserver* observer)
104 : observer(observer) {} 103 : observer(observer) {}
105 104
106 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer; 105 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer;
107 std::string error; 106 std::string error;
108 }; 107 };
109 108
110 struct GetStatsMsg : public rtc::MessageData {
111 GetStatsMsg(webrtc::StatsObserver* observer,
112 webrtc::MediaStreamTrackInterface* track)
113 : observer(observer), track(track) {
114 }
115 rtc::scoped_refptr<webrtc::StatsObserver> observer;
116 rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track;
117 };
118
119 // |in_str| should be of format 109 // |in_str| should be of format
120 // stunURI = scheme ":" stun-host [ ":" stun-port ] 110 // stunURI = scheme ":" stun-host [ ":" stun-port ]
121 // scheme = "stun" / "stuns" 111 // scheme = "stun" / "stuns"
122 // stun-host = IP-literal / IPv4address / reg-name 112 // stun-host = IP-literal / IPv4address / reg-name
123 // stun-port = *DIGIT 113 // stun-port = *DIGIT
124 // 114 //
125 // draft-petithuguenin-behave-turn-uris-01 115 // draft-petithuguenin-behave-turn-uris-01
126 // turnURI = scheme ":" turn-host [ ":" turn-port ] 116 // turnURI = scheme ":" turn-host [ ":" turn-port ]
127 // turn-host = username@IP-literal / IPv4address / reg-name 117 // turn-host = username@IP-literal / IPv4address / reg-name
128 bool GetServiceTypeAndHostnameFromUri(const std::string& in_str, 118 bool GetServiceTypeAndHostnameFromUri(const std::string& in_str,
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { 600 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) {
611 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; 601 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP;
612 LOG(LS_INFO) << "TCP candidates are disabled."; 602 LOG(LS_INFO) << "TCP candidates are disabled.";
613 } 603 }
614 604
615 port_allocator_->set_flags(portallocator_flags); 605 port_allocator_->set_flags(portallocator_flags);
616 // No step delay is used while allocating ports. 606 // No step delay is used while allocating ports.
617 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); 607 port_allocator_->set_step_delay(cricket::kMinimumStepDelay);
618 608
619 // We rely on default values when constraints aren't found. 609 // We rely on default values when constraints aren't found.
620 cricket::MediaConfig media_config; 610 media_config_.disable_prerenderer_smoothing =
621
622 media_config.disable_prerenderer_smoothing =
623 configuration.disable_prerenderer_smoothing; 611 configuration.disable_prerenderer_smoothing;
624 612
625 // Find DSCP constraint. 613 // Find DSCP constraint.
626 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, 614 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp,
627 &media_config.enable_dscp, NULL); 615 &media_config_.enable_dscp, NULL);
628 // Find constraints for cpu overuse detection. 616 // Find constraints for cpu overuse detection.
629 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, 617 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection,
630 &media_config.enable_cpu_overuse_detection, NULL); 618 &media_config_.enable_cpu_overuse_detection, NULL);
631
632 media_controller_.reset(factory_->CreateMediaController(media_config));
633
634 remote_stream_factory_.reset(new RemoteMediaStreamFactory(
635 factory_->signaling_thread(), media_controller_->channel_manager()));
636 619
637 session_.reset( 620 session_.reset(
638 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), 621 new WebRtcSession(factory_->signaling_thread(), factory_->worker_thread(),
639 factory_->worker_thread(), port_allocator_.get())); 622 port_allocator_.get()));
640 stats_.reset(new StatsCollector(this)); 623 stats_.reset(new StatsCollector(this));
641 624
642 // Initialize the WebRtcSession. It creates transport channels etc. 625 // Initialize the WebRtcSession. It creates transport channels etc.
643 if (!session_->Initialize(factory_->options(), constraints, 626 if (!session_->Initialize(factory_->options(), constraints,
644 std::move(dtls_identity_store), configuration)) { 627 std::move(dtls_identity_store), configuration)) {
645 return false; 628 return false;
646 } 629 }
647 630
648 // Register PeerConnection as receiver of local ice candidates. 631 // Register PeerConnection as receiver of local ice candidates.
649 // All the callbacks will be posted to the application from PeerConnection. 632 // All the callbacks will be posted to the application from PeerConnection.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 std::vector<MediaStreamInterface*> streams) { 718 std::vector<MediaStreamInterface*> streams) {
736 TRACE_EVENT0("webrtc", "PeerConnection::AddTrack"); 719 TRACE_EVENT0("webrtc", "PeerConnection::AddTrack");
737 if (IsClosed()) { 720 if (IsClosed()) {
738 return nullptr; 721 return nullptr;
739 } 722 }
740 if (streams.size() >= 2) { 723 if (streams.size() >= 2) {
741 LOG(LS_ERROR) 724 LOG(LS_ERROR)
742 << "Adding a track with two streams is not currently supported."; 725 << "Adding a track with two streams is not currently supported.";
743 return nullptr; 726 return nullptr;
744 } 727 }
728
745 // TODO(deadbeef): Support adding a track to two different senders. 729 // TODO(deadbeef): Support adding a track to two different senders.
746 if (FindSenderForTrack(track) != senders_.end()) { 730 if (FindSenderForTrack(track) != senders_.end()) {
747 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; 731 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists.";
748 return nullptr; 732 return nullptr;
749 } 733 }
750 734
735 LateInitialize();
751 // TODO(deadbeef): Support adding a track to multiple streams. 736 // TODO(deadbeef): Support adding a track to multiple streams.
752 rtc::scoped_refptr<RtpSenderInterface> new_sender; 737 rtc::scoped_refptr<RtpSenderInterface> new_sender;
753 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { 738 if (track->kind() == MediaStreamTrackInterface::kAudioKind) {
754 new_sender = RtpSenderProxy::Create( 739 new_sender = RtpSenderProxy::Create(
755 signaling_thread(), 740 signaling_thread(),
756 new AudioRtpSender(static_cast<AudioTrackInterface*>(track), 741 new AudioRtpSender(static_cast<AudioTrackInterface*>(track),
757 session_.get(), stats_.get())); 742 session_.get(), stats_.get()));
758 if (!streams.empty()) { 743 if (!streams.empty()) {
759 new_sender->set_stream_id(streams[0]->label()); 744 new_sender->set_stream_id(streams[0]->label());
760 } 745 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); 794 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender");
810 if (!track) { 795 if (!track) {
811 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; 796 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL.";
812 return NULL; 797 return NULL;
813 } 798 }
814 if (!local_streams_->FindAudioTrack(track->id())) { 799 if (!local_streams_->FindAudioTrack(track->id())) {
815 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; 800 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track.";
816 return NULL; 801 return NULL;
817 } 802 }
818 803
804 LateInitialize();
819 rtc::scoped_refptr<DtmfSenderInterface> sender( 805 rtc::scoped_refptr<DtmfSenderInterface> sender(
820 DtmfSender::Create(track, signaling_thread(), session_.get())); 806 DtmfSender::Create(track, signaling_thread(), session_.get()));
821 if (!sender.get()) { 807 if (!sender.get()) {
822 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; 808 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create.";
823 return NULL; 809 return NULL;
824 } 810 }
825 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); 811 return DtmfSenderProxy::Create(signaling_thread(), sender.get());
826 } 812 }
827 813
828 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( 814 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender(
829 const std::string& kind, 815 const std::string& kind,
830 const std::string& stream_id) { 816 const std::string& stream_id) {
831 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); 817 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender");
818 LateInitialize();
832 rtc::scoped_refptr<RtpSenderInterface> new_sender; 819 rtc::scoped_refptr<RtpSenderInterface> new_sender;
833 if (kind == MediaStreamTrackInterface::kAudioKind) { 820 if (kind == MediaStreamTrackInterface::kAudioKind) {
834 new_sender = RtpSenderProxy::Create( 821 new_sender = RtpSenderProxy::Create(
835 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); 822 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get()));
836 } else if (kind == MediaStreamTrackInterface::kVideoKind) { 823 } else if (kind == MediaStreamTrackInterface::kVideoKind) {
837 new_sender = RtpSenderProxy::Create(signaling_thread(), 824 new_sender = RtpSenderProxy::Create(signaling_thread(),
838 new VideoRtpSender(session_.get())); 825 new VideoRtpSender(session_.get()));
839 } else { 826 } else {
840 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; 827 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind;
841 return new_sender; 828 return new_sender;
(...skipping 17 matching lines...) Expand all
859 846
860 bool PeerConnection::GetStats(StatsObserver* observer, 847 bool PeerConnection::GetStats(StatsObserver* observer,
861 MediaStreamTrackInterface* track, 848 MediaStreamTrackInterface* track,
862 StatsOutputLevel level) { 849 StatsOutputLevel level) {
863 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); 850 TRACE_EVENT0("webrtc", "PeerConnection::GetStats");
864 RTC_DCHECK(signaling_thread()->IsCurrent()); 851 RTC_DCHECK(signaling_thread()->IsCurrent());
865 if (!VERIFY(observer != NULL)) { 852 if (!VERIFY(observer != NULL)) {
866 LOG(LS_ERROR) << "GetStats - observer is NULL."; 853 LOG(LS_ERROR) << "GetStats - observer is NULL.";
867 return false; 854 return false;
868 } 855 }
869
870 stats_->UpdateStats(level); 856 stats_->UpdateStats(level);
871 signaling_thread()->Post(this, MSG_GETSTATS, 857 StatsReports reports;
872 new GetStatsMsg(observer, track)); 858 stats_->GetStats(track, &reports);
tommi 2016/02/22 15:22:05 Is this change necessary for the goal of the CL?
the sun 2016/02/23 14:14:03 Duh! I thought I remembered that a Post() to curre
859 observer->OnComplete(reports);
873 return true; 860 return true;
874 } 861 }
875 862
876 PeerConnectionInterface::SignalingState PeerConnection::signaling_state() { 863 PeerConnectionInterface::SignalingState PeerConnection::signaling_state() {
877 return signaling_state_; 864 return signaling_state_;
878 } 865 }
879 866
880 PeerConnectionInterface::IceState PeerConnection::ice_state() { 867 PeerConnectionInterface::IceState PeerConnection::ice_state() {
881 return ice_state_; 868 return ice_state_;
882 } 869 }
(...skipping 18 matching lines...) Expand all
901 rtc::scoped_ptr<InternalDataChannelInit> internal_config; 888 rtc::scoped_ptr<InternalDataChannelInit> internal_config;
902 if (config) { 889 if (config) {
903 internal_config.reset(new InternalDataChannelInit(*config)); 890 internal_config.reset(new InternalDataChannelInit(*config));
904 } 891 }
905 rtc::scoped_refptr<DataChannelInterface> channel( 892 rtc::scoped_refptr<DataChannelInterface> channel(
906 InternalCreateDataChannel(label, internal_config.get())); 893 InternalCreateDataChannel(label, internal_config.get()));
907 if (!channel.get()) { 894 if (!channel.get()) {
908 return nullptr; 895 return nullptr;
909 } 896 }
910 897
898 LateInitialize();
911 // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or 899 // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or
912 // the first SCTP DataChannel. 900 // the first SCTP DataChannel.
913 if (session_->data_channel_type() == cricket::DCT_RTP || first_datachannel) { 901 if (session_->data_channel_type() == cricket::DCT_RTP || first_datachannel) {
914 observer_->OnRenegotiationNeeded(); 902 observer_->OnRenegotiationNeeded();
915 } 903 }
916 904
917 return DataChannelProxy::Create(signaling_thread(), channel.get()); 905 return DataChannelProxy::Create(signaling_thread(), channel.get());
918 } 906 }
919 907
920 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, 908 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 } 958 }
971 959
972 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, 960 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer,
973 const RTCOfferAnswerOptions& options) { 961 const RTCOfferAnswerOptions& options) {
974 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); 962 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer");
975 if (!VERIFY(observer != nullptr)) { 963 if (!VERIFY(observer != nullptr)) {
976 LOG(LS_ERROR) << "CreateOffer - observer is NULL."; 964 LOG(LS_ERROR) << "CreateOffer - observer is NULL.";
977 return; 965 return;
978 } 966 }
979 967
968 LateInitialize();
980 cricket::MediaSessionOptions session_options; 969 cricket::MediaSessionOptions session_options;
981 if (!GetOptionsForOffer(options, &session_options)) { 970 if (!GetOptionsForOffer(options, &session_options)) {
982 std::string error = "CreateOffer called with invalid options."; 971 std::string error = "CreateOffer called with invalid options.";
983 LOG(LS_ERROR) << error; 972 LOG(LS_ERROR) << error;
984 PostCreateSessionDescriptionFailure(observer, error); 973 PostCreateSessionDescriptionFailure(observer, error);
985 return; 974 return;
986 } 975 }
987 976
988 session_->CreateOffer(observer, options, session_options); 977 session_->CreateOffer(observer, options, session_options);
989 } 978 }
990 979
991 void PeerConnection::CreateAnswer( 980 void PeerConnection::CreateAnswer(
992 CreateSessionDescriptionObserver* observer, 981 CreateSessionDescriptionObserver* observer,
993 const MediaConstraintsInterface* constraints) { 982 const MediaConstraintsInterface* constraints) {
994 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); 983 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer");
995 if (!VERIFY(observer != nullptr)) { 984 if (!VERIFY(observer != nullptr)) {
996 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; 985 LOG(LS_ERROR) << "CreateAnswer - observer is NULL.";
997 return; 986 return;
998 } 987 }
999 988
989 LateInitialize();
1000 cricket::MediaSessionOptions session_options; 990 cricket::MediaSessionOptions session_options;
1001 if (!GetOptionsForAnswer(constraints, &session_options)) { 991 if (!GetOptionsForAnswer(constraints, &session_options)) {
1002 std::string error = "CreateAnswer called with invalid constraints."; 992 std::string error = "CreateAnswer called with invalid constraints.";
1003 LOG(LS_ERROR) << error; 993 LOG(LS_ERROR) << error;
1004 PostCreateSessionDescriptionFailure(observer, error); 994 PostCreateSessionDescriptionFailure(observer, error);
1005 return; 995 return;
1006 } 996 }
1007 997
1008 session_->CreateAnswer(observer, constraints, session_options); 998 session_->CreateAnswer(observer, constraints, session_options);
1009 } 999 }
1010 1000
1011 void PeerConnection::SetLocalDescription( 1001 void PeerConnection::SetLocalDescription(
1012 SetSessionDescriptionObserver* observer, 1002 SetSessionDescriptionObserver* observer,
1013 SessionDescriptionInterface* desc) { 1003 SessionDescriptionInterface* desc) {
1014 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); 1004 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription");
1015 if (!VERIFY(observer != nullptr)) { 1005 if (!VERIFY(observer != nullptr)) {
1016 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; 1006 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL.";
1017 return; 1007 return;
1018 } 1008 }
1019 if (!desc) { 1009 if (!desc) {
1020 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); 1010 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL.");
1021 return; 1011 return;
1022 } 1012 }
1013 LateInitialize();
1023 // Update stats here so that we have the most recent stats for tracks and 1014 // Update stats here so that we have the most recent stats for tracks and
1024 // streams that might be removed by updating the session description. 1015 // streams that might be removed by updating the session description.
1025 stats_->UpdateStats(kStatsOutputLevelStandard); 1016 stats_->UpdateStats(kStatsOutputLevelStandard);
1026 std::string error; 1017 std::string error;
1027 if (!session_->SetLocalDescription(desc, &error)) { 1018 if (!session_->SetLocalDescription(desc, &error)) {
1028 PostSetSessionDescriptionFailure(observer, error); 1019 PostSetSessionDescriptionFailure(observer, error);
1029 return; 1020 return;
1030 } 1021 }
1031 1022
1032 // If setting the description decided our SSL role, allocate any necessary 1023 // If setting the description decided our SSL role, allocate any necessary
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 SessionDescriptionInterface* desc) { 1082 SessionDescriptionInterface* desc) {
1092 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); 1083 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription");
1093 if (!VERIFY(observer != nullptr)) { 1084 if (!VERIFY(observer != nullptr)) {
1094 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL."; 1085 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL.";
1095 return; 1086 return;
1096 } 1087 }
1097 if (!desc) { 1088 if (!desc) {
1098 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); 1089 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL.");
1099 return; 1090 return;
1100 } 1091 }
1092 LateInitialize();
1101 // Update stats here so that we have the most recent stats for tracks and 1093 // Update stats here so that we have the most recent stats for tracks and
1102 // streams that might be removed by updating the session description. 1094 // streams that might be removed by updating the session description.
1103 stats_->UpdateStats(kStatsOutputLevelStandard); 1095 stats_->UpdateStats(kStatsOutputLevelStandard);
1104 std::string error; 1096 std::string error;
1105 if (!session_->SetRemoteDescription(desc, &error)) { 1097 if (!session_->SetRemoteDescription(desc, &error)) {
1106 PostSetSessionDescriptionFailure(observer, error); 1098 PostSetSessionDescriptionFailure(observer, error);
1107 return; 1099 return;
1108 } 1100 }
1109 1101
1110 // If setting the description decided our SSL role, allocate any necessary 1102 // If setting the description decided our SSL role, allocate any necessary
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 1228
1237 const SessionDescriptionInterface* PeerConnection::remote_description() const { 1229 const SessionDescriptionInterface* PeerConnection::remote_description() const {
1238 return session_->remote_description(); 1230 return session_->remote_description();
1239 } 1231 }
1240 1232
1241 void PeerConnection::Close() { 1233 void PeerConnection::Close() {
1242 TRACE_EVENT0("webrtc", "PeerConnection::Close"); 1234 TRACE_EVENT0("webrtc", "PeerConnection::Close");
1243 // Update stats here so that we have the most recent stats for tracks and 1235 // Update stats here so that we have the most recent stats for tracks and
1244 // streams before the channels are closed. 1236 // streams before the channels are closed.
1245 stats_->UpdateStats(kStatsOutputLevelStandard); 1237 stats_->UpdateStats(kStatsOutputLevelStandard);
1246
1247 session_->Close(); 1238 session_->Close();
1239 media_controller_.reset(nullptr);
1240 remote_stream_factory_.reset(nullptr);
1248 } 1241 }
1249 1242
1250 void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/, 1243 void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/,
1251 WebRtcSession::State state) { 1244 WebRtcSession::State state) {
1252 switch (state) { 1245 switch (state) {
1253 case WebRtcSession::STATE_INIT: 1246 case WebRtcSession::STATE_INIT:
1254 ChangeSignalingState(PeerConnectionInterface::kStable); 1247 ChangeSignalingState(PeerConnectionInterface::kStable);
1255 break; 1248 break;
1256 case WebRtcSession::STATE_SENTOFFER: 1249 case WebRtcSession::STATE_SENTOFFER:
1257 ChangeSignalingState(PeerConnectionInterface::kHaveLocalOffer); 1250 ChangeSignalingState(PeerConnectionInterface::kHaveLocalOffer);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 delete param; 1285 delete param;
1293 break; 1286 break;
1294 } 1287 }
1295 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { 1288 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: {
1296 CreateSessionDescriptionMsg* param = 1289 CreateSessionDescriptionMsg* param =
1297 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); 1290 static_cast<CreateSessionDescriptionMsg*>(msg->pdata);
1298 param->observer->OnFailure(param->error); 1291 param->observer->OnFailure(param->error);
1299 delete param; 1292 delete param;
1300 break; 1293 break;
1301 } 1294 }
1302 case MSG_GETSTATS: {
1303 GetStatsMsg* param = static_cast<GetStatsMsg*>(msg->pdata);
1304 StatsReports reports;
1305 stats_->GetStats(param->track, &reports);
1306 param->observer->OnComplete(reports);
1307 delete param;
1308 break;
1309 }
1310 case MSG_FREE_DATACHANNELS: { 1295 case MSG_FREE_DATACHANNELS: {
1311 sctp_data_channels_to_free_.clear(); 1296 sctp_data_channels_to_free_.clear();
1312 break; 1297 break;
1313 } 1298 }
1314 default: 1299 default:
1315 RTC_DCHECK(false && "Not implemented"); 1300 RTC_DCHECK(false && "Not implemented");
1316 break; 1301 break;
1317 } 1302 }
1318 } 1303 }
1319 1304
1320 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, 1305 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream,
1321 AudioTrackInterface* audio_track, 1306 AudioTrackInterface* audio_track,
1322 uint32_t ssrc) { 1307 uint32_t ssrc) {
1308 LateInitialize();
1323 receivers_.push_back(RtpReceiverProxy::Create( 1309 receivers_.push_back(RtpReceiverProxy::Create(
1324 signaling_thread(), 1310 signaling_thread(),
1325 new AudioRtpReceiver(audio_track, ssrc, session_.get()))); 1311 new AudioRtpReceiver(audio_track, ssrc, session_.get())));
1326 } 1312 }
1327 1313
1328 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, 1314 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream,
1329 VideoTrackInterface* video_track, 1315 VideoTrackInterface* video_track,
1330 uint32_t ssrc) { 1316 uint32_t ssrc) {
1317 LateInitialize();
1331 receivers_.push_back(RtpReceiverProxy::Create( 1318 receivers_.push_back(RtpReceiverProxy::Create(
1332 signaling_thread(), 1319 signaling_thread(),
1333 new VideoRtpReceiver(video_track, ssrc, session_.get()))); 1320 new VideoRtpReceiver(video_track, ssrc, session_.get())));
1334 } 1321 }
1335 1322
1336 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote 1323 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote
1337 // description. 1324 // description.
1338 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, 1325 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream,
1339 AudioTrackInterface* audio_track) { 1326 AudioTrackInterface* audio_track) {
1340 auto it = FindReceiverForTrack(audio_track); 1327 auto it = FindReceiverForTrack(audio_track);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, 1395 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track,
1409 MediaStreamInterface* stream) { 1396 MediaStreamInterface* stream) {
1410 auto sender = FindSenderForTrack(track); 1397 auto sender = FindSenderForTrack(track);
1411 if (sender != senders_.end()) { 1398 if (sender != senders_.end()) {
1412 // We already have a sender for this track, so just change the stream_id 1399 // 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. 1400 // so that it's correct in the next call to CreateOffer.
1414 (*sender)->set_stream_id(stream->label()); 1401 (*sender)->set_stream_id(stream->label());
1415 return; 1402 return;
1416 } 1403 }
1417 1404
1405 LateInitialize();
1418 // Normal case; we've never seen this track before. 1406 // Normal case; we've never seen this track before.
1419 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( 1407 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create(
1420 signaling_thread(), 1408 signaling_thread(),
1421 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get())); 1409 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get()));
1422 senders_.push_back(new_sender); 1410 senders_.push_back(new_sender);
1423 // If the sender has already been configured in SDP, we call SetSsrc, 1411 // If the sender has already been configured in SDP, we call SetSsrc,
1424 // which will connect the sender to the underlying transport. This can 1412 // which will connect the sender to the underlying transport. This can
1425 // occur if a local session description that contains the ID of the sender 1413 // occur if a local session description that contains the ID of the sender
1426 // is set before AddStream is called. It can also occur if the local 1414 // is set before AddStream is called. It can also occur if the local
1427 // session description is not changed and RemoveStream is called, and 1415 // session description is not changed and RemoveStream is called, and
(...skipping 22 matching lines...) Expand all
1450 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, 1438 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track,
1451 MediaStreamInterface* stream) { 1439 MediaStreamInterface* stream) {
1452 auto sender = FindSenderForTrack(track); 1440 auto sender = FindSenderForTrack(track);
1453 if (sender != senders_.end()) { 1441 if (sender != senders_.end()) {
1454 // We already have a sender for this track, so just change the stream_id 1442 // We already have a sender for this track, so just change the stream_id
1455 // so that it's correct in the next call to CreateOffer. 1443 // so that it's correct in the next call to CreateOffer.
1456 (*sender)->set_stream_id(stream->label()); 1444 (*sender)->set_stream_id(stream->label());
1457 return; 1445 return;
1458 } 1446 }
1459 1447
1448 LateInitialize();
1460 // Normal case; we've never seen this track before. 1449 // Normal case; we've never seen this track before.
1461 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( 1450 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create(
1462 signaling_thread(), 1451 signaling_thread(),
1463 new VideoRtpSender(track, stream->label(), session_.get())); 1452 new VideoRtpSender(track, stream->label(), session_.get()));
1464 senders_.push_back(new_sender); 1453 senders_.push_back(new_sender);
1465 const TrackInfo* track_info = 1454 const TrackInfo* track_info =
1466 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); 1455 FindTrackInfo(local_video_tracks_, stream->label(), track->id());
1467 if (track_info) { 1456 if (track_info) {
1468 new_sender->SetSsrc(track_info->ssrc); 1457 new_sender->SetSsrc(track_info->ssrc);
1469 } 1458 }
(...skipping 20 matching lines...) Expand all
1490 } 1479 }
1491 1480
1492 void PeerConnection::PostCreateSessionDescriptionFailure( 1481 void PeerConnection::PostCreateSessionDescriptionFailure(
1493 CreateSessionDescriptionObserver* observer, 1482 CreateSessionDescriptionObserver* observer,
1494 const std::string& error) { 1483 const std::string& error) {
1495 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); 1484 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
1496 msg->error = error; 1485 msg->error = error;
1497 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); 1486 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
1498 } 1487 }
1499 1488
1489 void PeerConnection::LateInitialize() {
1490 if (!media_controller_) {
1491 RTC_DCHECK(!remote_stream_factory_);
1492 media_controller_.reset(factory_->CreateMediaController(media_config_));
1493 session_->LateInitialize(media_controller_.get());
tommi 2016/02/22 15:22:05 Would it make sense to media_controller_ be owned
the sun 2016/02/23 14:14:03 It used to be owned by WebRtcSession: https://code
1494 remote_stream_factory_.reset(new RemoteMediaStreamFactory(
1495 factory_->signaling_thread(), media_controller_->channel_manager()));
1496 }
1497 }
1498
1500 bool PeerConnection::GetOptionsForOffer( 1499 bool PeerConnection::GetOptionsForOffer(
1501 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, 1500 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
1502 cricket::MediaSessionOptions* session_options) { 1501 cricket::MediaSessionOptions* session_options) {
1503 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) { 1502 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) {
1504 return false; 1503 return false;
1505 } 1504 }
1506 1505
1506 LateInitialize();
1507 AddSendStreams(session_options, senders_, rtp_data_channels_); 1507 AddSendStreams(session_options, senders_, rtp_data_channels_);
1508 // Offer to receive audio/video if the constraint is not set and there are 1508 // Offer to receive audio/video if the constraint is not set and there are
1509 // send streams, or we're currently receiving. 1509 // send streams, or we're currently receiving.
1510 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { 1510 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) {
1511 session_options->recv_audio = 1511 session_options->recv_audio =
1512 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || 1512 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) ||
1513 !remote_audio_tracks_.empty(); 1513 !remote_audio_tracks_.empty();
1514 } 1514 }
1515 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { 1515 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) {
1516 session_options->recv_video = 1516 session_options->recv_video =
(...skipping 13 matching lines...) Expand all
1530 1530
1531 bool PeerConnection::GetOptionsForAnswer( 1531 bool PeerConnection::GetOptionsForAnswer(
1532 const MediaConstraintsInterface* constraints, 1532 const MediaConstraintsInterface* constraints,
1533 cricket::MediaSessionOptions* session_options) { 1533 cricket::MediaSessionOptions* session_options) {
1534 session_options->recv_audio = false; 1534 session_options->recv_audio = false;
1535 session_options->recv_video = false; 1535 session_options->recv_video = false;
1536 if (!ParseConstraintsForAnswer(constraints, session_options)) { 1536 if (!ParseConstraintsForAnswer(constraints, session_options)) {
1537 return false; 1537 return false;
1538 } 1538 }
1539 1539
1540 LateInitialize();
1540 AddSendStreams(session_options, senders_, rtp_data_channels_); 1541 AddSendStreams(session_options, senders_, rtp_data_channels_);
1541 session_options->bundle_enabled = 1542 session_options->bundle_enabled =
1542 session_options->bundle_enabled && 1543 session_options->bundle_enabled &&
1543 (session_options->has_audio() || session_options->has_video() || 1544 (session_options->has_audio() || session_options->has_video() ||
1544 session_options->has_data()); 1545 session_options->has_data());
1545 1546
1546 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams 1547 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams
1547 // are not signaled in the SDP so does not go through that path and must be 1548 // are not signaled in the SDP so does not go through that path and must be
1548 // handled here. 1549 // handled here.
1549 if (session_->data_channel_type() == cricket::DCT_SCTP) { 1550 if (session_->data_channel_type() == cricket::DCT_SCTP) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 } 1632 }
1632 } 1633 }
1633 } 1634 }
1634 1635
1635 void PeerConnection::OnRemoteTrackSeen(const std::string& stream_label, 1636 void PeerConnection::OnRemoteTrackSeen(const std::string& stream_label,
1636 const std::string& track_id, 1637 const std::string& track_id,
1637 uint32_t ssrc, 1638 uint32_t ssrc,
1638 cricket::MediaType media_type) { 1639 cricket::MediaType media_type) {
1639 MediaStreamInterface* stream = remote_streams_->find(stream_label); 1640 MediaStreamInterface* stream = remote_streams_->find(stream_label);
1640 1641
1642 LateInitialize();
1641 if (media_type == cricket::MEDIA_TYPE_AUDIO) { 1643 if (media_type == cricket::MEDIA_TYPE_AUDIO) {
1642 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack( 1644 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack(
1643 ssrc, session_.get(), stream, track_id); 1645 ssrc, session_.get(), stream, track_id);
1644 CreateAudioReceiver(stream, audio_track, ssrc); 1646 CreateAudioReceiver(stream, audio_track, ssrc);
1645 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { 1647 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
1646 VideoTrackInterface* video_track = 1648 VideoTrackInterface* video_track =
1647 remote_stream_factory_->AddVideoTrack(stream, track_id); 1649 remote_stream_factory_->AddVideoTrack(stream, track_id);
1648 CreateVideoReceiver(stream, video_track, ssrc); 1650 CreateVideoReceiver(stream, video_track, ssrc);
1649 } else { 1651 } else {
1650 RTC_DCHECK(false && "Invalid media type"); 1652 RTC_DCHECK(false && "Invalid media type");
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 observer_->OnDataChannel( 1889 observer_->OnDataChannel(
1888 DataChannelProxy::Create(signaling_thread(), channel)); 1890 DataChannelProxy::Create(signaling_thread(), channel));
1889 } 1891 }
1890 1892
1891 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( 1893 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel(
1892 const std::string& label, 1894 const std::string& label,
1893 const InternalDataChannelInit* config) { 1895 const InternalDataChannelInit* config) {
1894 if (IsClosed()) { 1896 if (IsClosed()) {
1895 return nullptr; 1897 return nullptr;
1896 } 1898 }
1899 LateInitialize();
1897 if (session_->data_channel_type() == cricket::DCT_NONE) { 1900 if (session_->data_channel_type() == cricket::DCT_NONE) {
1898 LOG(LS_ERROR) 1901 LOG(LS_ERROR)
1899 << "InternalCreateDataChannel: Data is not supported in this call."; 1902 << "InternalCreateDataChannel: Data is not supported in this call.";
1900 return nullptr; 1903 return nullptr;
1901 } 1904 }
1902 InternalDataChannelInit new_config = 1905 InternalDataChannelInit new_config =
1903 config ? (*config) : InternalDataChannelInit(); 1906 config ? (*config) : InternalDataChannelInit();
1904 if (session_->data_channel_type() == cricket::DCT_SCTP) { 1907 if (session_->data_channel_type() == cricket::DCT_SCTP) {
1905 if (new_config.id < 0) { 1908 if (new_config.id < 0) {
1906 rtc::SSLRole role; 1909 rtc::SSLRole role;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2081 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2079 for (const auto& channel : sctp_data_channels_) { 2082 for (const auto& channel : sctp_data_channels_) {
2080 if (channel->id() == sid) { 2083 if (channel->id() == sid) {
2081 return channel; 2084 return channel;
2082 } 2085 }
2083 } 2086 }
2084 return nullptr; 2087 return nullptr;
2085 } 2088 }
2086 2089
2087 } // namespace webrtc 2090 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698