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 |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { | 610 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { |
611 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | 611 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
612 LOG(LS_INFO) << "TCP candidates are disabled."; | 612 LOG(LS_INFO) << "TCP candidates are disabled."; |
613 } | 613 } |
614 | 614 |
615 port_allocator_->set_flags(portallocator_flags); | 615 port_allocator_->set_flags(portallocator_flags); |
616 // No step delay is used while allocating ports. | 616 // No step delay is used while allocating ports. |
617 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); | 617 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
618 | 618 |
619 // We rely on default values when constraints aren't found. | 619 // We rely on default values when constraints aren't found. |
620 cricket::MediaConfig media_config; | 620 media_config_.disable_prerenderer_smoothing = |
621 | |
622 media_config.disable_prerenderer_smoothing = | |
623 configuration.disable_prerenderer_smoothing; | 621 configuration.disable_prerenderer_smoothing; |
624 | 622 |
625 // Find DSCP constraint. | 623 // Find DSCP constraint. |
626 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, | 624 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, |
627 &media_config.enable_dscp, NULL); | 625 &media_config_.enable_dscp, NULL); |
628 // Find constraints for cpu overuse detection. | 626 // Find constraints for cpu overuse detection. |
629 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, | 627 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, |
630 &media_config.enable_cpu_overuse_detection, NULL); | 628 &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 | 629 |
637 session_.reset( | 630 session_.reset( |
638 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), | 631 new WebRtcSession(factory_->signaling_thread(), factory_->worker_thread(), |
639 factory_->worker_thread(), port_allocator_.get())); | 632 port_allocator_.get())); |
640 stats_.reset(new StatsCollector(this)); | 633 stats_.reset(new StatsCollector(this)); |
641 | 634 |
642 // Initialize the WebRtcSession. It creates transport channels etc. | 635 // Initialize the WebRtcSession. It creates transport channels etc. |
643 if (!session_->Initialize(factory_->options(), constraints, | 636 if (!session_->Initialize(factory_->options(), constraints, |
644 std::move(dtls_identity_store), configuration)) { | 637 std::move(dtls_identity_store), configuration)) { |
645 return false; | 638 return false; |
646 } | 639 } |
647 | 640 |
648 // Register PeerConnection as receiver of local ice candidates. | 641 // Register PeerConnection as receiver of local ice candidates. |
649 // All the callbacks will be posted to the application from PeerConnection. | 642 // All the callbacks will be posted to the application from PeerConnection. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 std::vector<MediaStreamInterface*> streams) { | 728 std::vector<MediaStreamInterface*> streams) { |
736 TRACE_EVENT0("webrtc", "PeerConnection::AddTrack"); | 729 TRACE_EVENT0("webrtc", "PeerConnection::AddTrack"); |
737 if (IsClosed()) { | 730 if (IsClosed()) { |
738 return nullptr; | 731 return nullptr; |
739 } | 732 } |
740 if (streams.size() >= 2) { | 733 if (streams.size() >= 2) { |
741 LOG(LS_ERROR) | 734 LOG(LS_ERROR) |
742 << "Adding a track with two streams is not currently supported."; | 735 << "Adding a track with two streams is not currently supported."; |
743 return nullptr; | 736 return nullptr; |
744 } | 737 } |
738 | |
745 // TODO(deadbeef): Support adding a track to two different senders. | 739 // TODO(deadbeef): Support adding a track to two different senders. |
746 if (FindSenderForTrack(track) != senders_.end()) { | 740 if (FindSenderForTrack(track) != senders_.end()) { |
747 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; | 741 LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; |
748 return nullptr; | 742 return nullptr; |
749 } | 743 } |
750 | 744 |
745 LateInitialize(); | |
pthatcher1
2016/02/24 23:10:09
Instead of calling LateInitialize everywhere (whic
the sun
2016/02/25 13:15:39
That's a good suggestion, but unfortunately it doe
| |
751 // TODO(deadbeef): Support adding a track to multiple streams. | 746 // TODO(deadbeef): Support adding a track to multiple streams. |
752 rtc::scoped_refptr<RtpSenderInterface> new_sender; | 747 rtc::scoped_refptr<RtpSenderInterface> new_sender; |
753 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { | 748 if (track->kind() == MediaStreamTrackInterface::kAudioKind) { |
754 new_sender = RtpSenderProxy::Create( | 749 new_sender = RtpSenderProxy::Create( |
755 signaling_thread(), | 750 signaling_thread(), |
756 new AudioRtpSender(static_cast<AudioTrackInterface*>(track), | 751 new AudioRtpSender(static_cast<AudioTrackInterface*>(track), |
757 session_.get(), stats_.get())); | 752 session_.get(), stats_.get())); |
758 if (!streams.empty()) { | 753 if (!streams.empty()) { |
759 new_sender->set_stream_id(streams[0]->label()); | 754 new_sender->set_stream_id(streams[0]->label()); |
760 } | 755 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); | 804 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); |
810 if (!track) { | 805 if (!track) { |
811 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; | 806 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; |
812 return NULL; | 807 return NULL; |
813 } | 808 } |
814 if (!local_streams_->FindAudioTrack(track->id())) { | 809 if (!local_streams_->FindAudioTrack(track->id())) { |
815 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; | 810 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; |
816 return NULL; | 811 return NULL; |
817 } | 812 } |
818 | 813 |
814 LateInitialize(); | |
819 rtc::scoped_refptr<DtmfSenderInterface> sender( | 815 rtc::scoped_refptr<DtmfSenderInterface> sender( |
820 DtmfSender::Create(track, signaling_thread(), session_.get())); | 816 DtmfSender::Create(track, signaling_thread(), session_.get())); |
821 if (!sender.get()) { | 817 if (!sender.get()) { |
822 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; | 818 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; |
823 return NULL; | 819 return NULL; |
824 } | 820 } |
825 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); | 821 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); |
826 } | 822 } |
827 | 823 |
828 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( | 824 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( |
829 const std::string& kind, | 825 const std::string& kind, |
830 const std::string& stream_id) { | 826 const std::string& stream_id) { |
831 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); | 827 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); |
828 LateInitialize(); | |
832 rtc::scoped_refptr<RtpSenderInterface> new_sender; | 829 rtc::scoped_refptr<RtpSenderInterface> new_sender; |
833 if (kind == MediaStreamTrackInterface::kAudioKind) { | 830 if (kind == MediaStreamTrackInterface::kAudioKind) { |
834 new_sender = RtpSenderProxy::Create( | 831 new_sender = RtpSenderProxy::Create( |
835 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); | 832 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); |
836 } else if (kind == MediaStreamTrackInterface::kVideoKind) { | 833 } else if (kind == MediaStreamTrackInterface::kVideoKind) { |
837 new_sender = RtpSenderProxy::Create(signaling_thread(), | 834 new_sender = RtpSenderProxy::Create(signaling_thread(), |
838 new VideoRtpSender(session_.get())); | 835 new VideoRtpSender(session_.get())); |
839 } else { | 836 } else { |
840 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; | 837 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; |
841 return new_sender; | 838 return new_sender; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 rtc::scoped_ptr<InternalDataChannelInit> internal_config; | 898 rtc::scoped_ptr<InternalDataChannelInit> internal_config; |
902 if (config) { | 899 if (config) { |
903 internal_config.reset(new InternalDataChannelInit(*config)); | 900 internal_config.reset(new InternalDataChannelInit(*config)); |
904 } | 901 } |
905 rtc::scoped_refptr<DataChannelInterface> channel( | 902 rtc::scoped_refptr<DataChannelInterface> channel( |
906 InternalCreateDataChannel(label, internal_config.get())); | 903 InternalCreateDataChannel(label, internal_config.get())); |
907 if (!channel.get()) { | 904 if (!channel.get()) { |
908 return nullptr; | 905 return nullptr; |
909 } | 906 } |
910 | 907 |
908 LateInitialize(); | |
911 // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or | 909 // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or |
912 // the first SCTP DataChannel. | 910 // the first SCTP DataChannel. |
913 if (session_->data_channel_type() == cricket::DCT_RTP || first_datachannel) { | 911 if (session_->data_channel_type() == cricket::DCT_RTP || first_datachannel) { |
914 observer_->OnRenegotiationNeeded(); | 912 observer_->OnRenegotiationNeeded(); |
915 } | 913 } |
916 | 914 |
917 return DataChannelProxy::Create(signaling_thread(), channel.get()); | 915 return DataChannelProxy::Create(signaling_thread(), channel.get()); |
918 } | 916 } |
919 | 917 |
920 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, | 918 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
970 } | 968 } |
971 | 969 |
972 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, | 970 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, |
973 const RTCOfferAnswerOptions& options) { | 971 const RTCOfferAnswerOptions& options) { |
974 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); | 972 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); |
975 if (!VERIFY(observer != nullptr)) { | 973 if (!VERIFY(observer != nullptr)) { |
976 LOG(LS_ERROR) << "CreateOffer - observer is NULL."; | 974 LOG(LS_ERROR) << "CreateOffer - observer is NULL."; |
977 return; | 975 return; |
978 } | 976 } |
979 | 977 |
978 LateInitialize(); | |
980 cricket::MediaSessionOptions session_options; | 979 cricket::MediaSessionOptions session_options; |
981 if (!GetOptionsForOffer(options, &session_options)) { | 980 if (!GetOptionsForOffer(options, &session_options)) { |
982 std::string error = "CreateOffer called with invalid options."; | 981 std::string error = "CreateOffer called with invalid options."; |
983 LOG(LS_ERROR) << error; | 982 LOG(LS_ERROR) << error; |
984 PostCreateSessionDescriptionFailure(observer, error); | 983 PostCreateSessionDescriptionFailure(observer, error); |
985 return; | 984 return; |
986 } | 985 } |
987 | 986 |
988 session_->CreateOffer(observer, options, session_options); | 987 session_->CreateOffer(observer, options, session_options); |
989 } | 988 } |
990 | 989 |
991 void PeerConnection::CreateAnswer( | 990 void PeerConnection::CreateAnswer( |
992 CreateSessionDescriptionObserver* observer, | 991 CreateSessionDescriptionObserver* observer, |
993 const MediaConstraintsInterface* constraints) { | 992 const MediaConstraintsInterface* constraints) { |
994 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); | 993 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); |
995 if (!VERIFY(observer != nullptr)) { | 994 if (!VERIFY(observer != nullptr)) { |
996 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; | 995 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; |
997 return; | 996 return; |
998 } | 997 } |
999 | 998 |
999 LateInitialize(); | |
1000 cricket::MediaSessionOptions session_options; | 1000 cricket::MediaSessionOptions session_options; |
1001 if (!GetOptionsForAnswer(constraints, &session_options)) { | 1001 if (!GetOptionsForAnswer(constraints, &session_options)) { |
1002 std::string error = "CreateAnswer called with invalid constraints."; | 1002 std::string error = "CreateAnswer called with invalid constraints."; |
1003 LOG(LS_ERROR) << error; | 1003 LOG(LS_ERROR) << error; |
1004 PostCreateSessionDescriptionFailure(observer, error); | 1004 PostCreateSessionDescriptionFailure(observer, error); |
1005 return; | 1005 return; |
1006 } | 1006 } |
1007 | 1007 |
1008 session_->CreateAnswer(observer, constraints, session_options); | 1008 session_->CreateAnswer(observer, constraints, session_options); |
1009 } | 1009 } |
1010 | 1010 |
1011 void PeerConnection::SetLocalDescription( | 1011 void PeerConnection::SetLocalDescription( |
1012 SetSessionDescriptionObserver* observer, | 1012 SetSessionDescriptionObserver* observer, |
1013 SessionDescriptionInterface* desc) { | 1013 SessionDescriptionInterface* desc) { |
1014 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); | 1014 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); |
1015 if (!VERIFY(observer != nullptr)) { | 1015 if (!VERIFY(observer != nullptr)) { |
1016 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; | 1016 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; |
1017 return; | 1017 return; |
1018 } | 1018 } |
1019 if (!desc) { | 1019 if (!desc) { |
1020 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); | 1020 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); |
1021 return; | 1021 return; |
1022 } | 1022 } |
1023 LateInitialize(); | |
1023 // Update stats here so that we have the most recent stats for tracks and | 1024 // 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. | 1025 // streams that might be removed by updating the session description. |
1025 stats_->UpdateStats(kStatsOutputLevelStandard); | 1026 stats_->UpdateStats(kStatsOutputLevelStandard); |
1026 std::string error; | 1027 std::string error; |
1027 if (!session_->SetLocalDescription(desc, &error)) { | 1028 if (!session_->SetLocalDescription(desc, &error)) { |
1028 PostSetSessionDescriptionFailure(observer, error); | 1029 PostSetSessionDescriptionFailure(observer, error); |
1029 return; | 1030 return; |
1030 } | 1031 } |
1031 | 1032 |
1032 // If setting the description decided our SSL role, allocate any necessary | 1033 // If setting the description decided our SSL role, allocate any necessary |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 SessionDescriptionInterface* desc) { | 1092 SessionDescriptionInterface* desc) { |
1092 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); | 1093 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); |
1093 if (!VERIFY(observer != nullptr)) { | 1094 if (!VERIFY(observer != nullptr)) { |
1094 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL."; | 1095 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL."; |
1095 return; | 1096 return; |
1096 } | 1097 } |
1097 if (!desc) { | 1098 if (!desc) { |
1098 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); | 1099 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); |
1099 return; | 1100 return; |
1100 } | 1101 } |
1102 LateInitialize(); | |
1101 // Update stats here so that we have the most recent stats for tracks and | 1103 // 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. | 1104 // streams that might be removed by updating the session description. |
1103 stats_->UpdateStats(kStatsOutputLevelStandard); | 1105 stats_->UpdateStats(kStatsOutputLevelStandard); |
1104 std::string error; | 1106 std::string error; |
1105 if (!session_->SetRemoteDescription(desc, &error)) { | 1107 if (!session_->SetRemoteDescription(desc, &error)) { |
1106 PostSetSessionDescriptionFailure(observer, error); | 1108 PostSetSessionDescriptionFailure(observer, error); |
1107 return; | 1109 return; |
1108 } | 1110 } |
1109 | 1111 |
1110 // If setting the description decided our SSL role, allocate any necessary | 1112 // If setting the description decided our SSL role, allocate any necessary |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1236 | 1238 |
1237 const SessionDescriptionInterface* PeerConnection::remote_description() const { | 1239 const SessionDescriptionInterface* PeerConnection::remote_description() const { |
1238 return session_->remote_description(); | 1240 return session_->remote_description(); |
1239 } | 1241 } |
1240 | 1242 |
1241 void PeerConnection::Close() { | 1243 void PeerConnection::Close() { |
1242 TRACE_EVENT0("webrtc", "PeerConnection::Close"); | 1244 TRACE_EVENT0("webrtc", "PeerConnection::Close"); |
1243 // Update stats here so that we have the most recent stats for tracks and | 1245 // Update stats here so that we have the most recent stats for tracks and |
1244 // streams before the channels are closed. | 1246 // streams before the channels are closed. |
1245 stats_->UpdateStats(kStatsOutputLevelStandard); | 1247 stats_->UpdateStats(kStatsOutputLevelStandard); |
1246 | |
1247 session_->Close(); | 1248 session_->Close(); |
1249 media_controller_.reset(nullptr); | |
1250 remote_stream_factory_.reset(nullptr); | |
1248 } | 1251 } |
1249 | 1252 |
1250 void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/, | 1253 void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/, |
1251 WebRtcSession::State state) { | 1254 WebRtcSession::State state) { |
1252 switch (state) { | 1255 switch (state) { |
1253 case WebRtcSession::STATE_INIT: | 1256 case WebRtcSession::STATE_INIT: |
1254 ChangeSignalingState(PeerConnectionInterface::kStable); | 1257 ChangeSignalingState(PeerConnectionInterface::kStable); |
1255 break; | 1258 break; |
1256 case WebRtcSession::STATE_SENTOFFER: | 1259 case WebRtcSession::STATE_SENTOFFER: |
1257 ChangeSignalingState(PeerConnectionInterface::kHaveLocalOffer); | 1260 ChangeSignalingState(PeerConnectionInterface::kHaveLocalOffer); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1313 } | 1316 } |
1314 default: | 1317 default: |
1315 RTC_DCHECK(false && "Not implemented"); | 1318 RTC_DCHECK(false && "Not implemented"); |
1316 break; | 1319 break; |
1317 } | 1320 } |
1318 } | 1321 } |
1319 | 1322 |
1320 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, | 1323 void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, |
1321 AudioTrackInterface* audio_track, | 1324 AudioTrackInterface* audio_track, |
1322 uint32_t ssrc) { | 1325 uint32_t ssrc) { |
1326 LateInitialize(); | |
1323 receivers_.push_back(RtpReceiverProxy::Create( | 1327 receivers_.push_back(RtpReceiverProxy::Create( |
1324 signaling_thread(), | 1328 signaling_thread(), |
1325 new AudioRtpReceiver(audio_track, ssrc, session_.get()))); | 1329 new AudioRtpReceiver(audio_track, ssrc, session_.get()))); |
1326 } | 1330 } |
1327 | 1331 |
1328 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, | 1332 void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, |
1329 VideoTrackInterface* video_track, | 1333 VideoTrackInterface* video_track, |
1330 uint32_t ssrc) { | 1334 uint32_t ssrc) { |
1335 LateInitialize(); | |
1331 receivers_.push_back(RtpReceiverProxy::Create( | 1336 receivers_.push_back(RtpReceiverProxy::Create( |
1332 signaling_thread(), | 1337 signaling_thread(), |
1333 new VideoRtpReceiver(video_track, ssrc, session_.get()))); | 1338 new VideoRtpReceiver(video_track, ssrc, session_.get()))); |
1334 } | 1339 } |
1335 | 1340 |
1336 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote | 1341 // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote |
1337 // description. | 1342 // description. |
1338 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, | 1343 void PeerConnection::DestroyAudioReceiver(MediaStreamInterface* stream, |
1339 AudioTrackInterface* audio_track) { | 1344 AudioTrackInterface* audio_track) { |
1340 auto it = FindReceiverForTrack(audio_track); | 1345 auto it = FindReceiverForTrack(audio_track); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1408 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, | 1413 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, |
1409 MediaStreamInterface* stream) { | 1414 MediaStreamInterface* stream) { |
1410 auto sender = FindSenderForTrack(track); | 1415 auto sender = FindSenderForTrack(track); |
1411 if (sender != senders_.end()) { | 1416 if (sender != senders_.end()) { |
1412 // We already have a sender for this track, so just change the stream_id | 1417 // 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. | 1418 // so that it's correct in the next call to CreateOffer. |
1414 (*sender)->set_stream_id(stream->label()); | 1419 (*sender)->set_stream_id(stream->label()); |
1415 return; | 1420 return; |
1416 } | 1421 } |
1417 | 1422 |
1423 LateInitialize(); | |
1418 // Normal case; we've never seen this track before. | 1424 // Normal case; we've never seen this track before. |
1419 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( | 1425 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( |
1420 signaling_thread(), | 1426 signaling_thread(), |
1421 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get())); | 1427 new AudioRtpSender(track, stream->label(), session_.get(), stats_.get())); |
1422 senders_.push_back(new_sender); | 1428 senders_.push_back(new_sender); |
1423 // If the sender has already been configured in SDP, we call SetSsrc, | 1429 // If the sender has already been configured in SDP, we call SetSsrc, |
1424 // which will connect the sender to the underlying transport. This can | 1430 // 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 | 1431 // 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 | 1432 // is set before AddStream is called. It can also occur if the local |
1427 // session description is not changed and RemoveStream is called, and | 1433 // session description is not changed and RemoveStream is called, and |
(...skipping 22 matching lines...) Expand all Loading... | |
1450 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, | 1456 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, |
1451 MediaStreamInterface* stream) { | 1457 MediaStreamInterface* stream) { |
1452 auto sender = FindSenderForTrack(track); | 1458 auto sender = FindSenderForTrack(track); |
1453 if (sender != senders_.end()) { | 1459 if (sender != senders_.end()) { |
1454 // We already have a sender for this track, so just change the stream_id | 1460 // 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. | 1461 // so that it's correct in the next call to CreateOffer. |
1456 (*sender)->set_stream_id(stream->label()); | 1462 (*sender)->set_stream_id(stream->label()); |
1457 return; | 1463 return; |
1458 } | 1464 } |
1459 | 1465 |
1466 LateInitialize(); | |
1460 // Normal case; we've never seen this track before. | 1467 // Normal case; we've never seen this track before. |
1461 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( | 1468 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( |
1462 signaling_thread(), | 1469 signaling_thread(), |
1463 new VideoRtpSender(track, stream->label(), session_.get())); | 1470 new VideoRtpSender(track, stream->label(), session_.get())); |
1464 senders_.push_back(new_sender); | 1471 senders_.push_back(new_sender); |
1465 const TrackInfo* track_info = | 1472 const TrackInfo* track_info = |
1466 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); | 1473 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); |
1467 if (track_info) { | 1474 if (track_info) { |
1468 new_sender->SetSsrc(track_info->ssrc); | 1475 new_sender->SetSsrc(track_info->ssrc); |
1469 } | 1476 } |
(...skipping 20 matching lines...) Expand all Loading... | |
1490 } | 1497 } |
1491 | 1498 |
1492 void PeerConnection::PostCreateSessionDescriptionFailure( | 1499 void PeerConnection::PostCreateSessionDescriptionFailure( |
1493 CreateSessionDescriptionObserver* observer, | 1500 CreateSessionDescriptionObserver* observer, |
1494 const std::string& error) { | 1501 const std::string& error) { |
1495 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); | 1502 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); |
1496 msg->error = error; | 1503 msg->error = error; |
1497 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); | 1504 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); |
1498 } | 1505 } |
1499 | 1506 |
1507 void PeerConnection::LateInitialize() { | |
1508 if (!media_controller_) { | |
1509 RTC_DCHECK(!remote_stream_factory_); | |
1510 media_controller_.reset(factory_->CreateMediaController(media_config_)); | |
1511 session_->LateInitialize(media_controller_.get()); | |
pthatcher1
2016/02/24 23:10:09
This would make a lot more sense if WebrtcSession
the sun
2016/02/25 13:15:39
Agree. Like I noted in an initial comment, that is
pthatcher1
2016/02/26 21:51:20
I appreciate that we'd like to fix the bug quickly
the sun
2016/02/29 15:58:22
Acknowledged.
| |
1512 remote_stream_factory_.reset(new RemoteMediaStreamFactory( | |
1513 factory_->signaling_thread(), media_controller_->channel_manager())); | |
pthatcher1
2016/02/24 23:10:09
I looked into this, and found that the ChannelMana
the sun
2016/02/25 13:15:39
Wow, thanks for taking such a deep dive!
What abo
pthatcher1
2016/02/26 21:51:20
ChannelManager::StartVideoCapture() is only called
the sun
2016/02/29 15:58:22
Acknowledged.
| |
1514 } | |
1515 } | |
1516 | |
1500 bool PeerConnection::GetOptionsForOffer( | 1517 bool PeerConnection::GetOptionsForOffer( |
1501 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 1518 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
1502 cricket::MediaSessionOptions* session_options) { | 1519 cricket::MediaSessionOptions* session_options) { |
1503 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) { | 1520 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) { |
1504 return false; | 1521 return false; |
1505 } | 1522 } |
1506 | 1523 |
1524 LateInitialize(); | |
1507 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1525 AddSendStreams(session_options, senders_, rtp_data_channels_); |
1508 // Offer to receive audio/video if the constraint is not set and there are | 1526 // Offer to receive audio/video if the constraint is not set and there are |
1509 // send streams, or we're currently receiving. | 1527 // send streams, or we're currently receiving. |
1510 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { | 1528 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { |
1511 session_options->recv_audio = | 1529 session_options->recv_audio = |
1512 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || | 1530 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || |
1513 !remote_audio_tracks_.empty(); | 1531 !remote_audio_tracks_.empty(); |
1514 } | 1532 } |
1515 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { | 1533 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { |
1516 session_options->recv_video = | 1534 session_options->recv_video = |
(...skipping 13 matching lines...) Expand all Loading... | |
1530 | 1548 |
1531 bool PeerConnection::GetOptionsForAnswer( | 1549 bool PeerConnection::GetOptionsForAnswer( |
1532 const MediaConstraintsInterface* constraints, | 1550 const MediaConstraintsInterface* constraints, |
1533 cricket::MediaSessionOptions* session_options) { | 1551 cricket::MediaSessionOptions* session_options) { |
1534 session_options->recv_audio = false; | 1552 session_options->recv_audio = false; |
1535 session_options->recv_video = false; | 1553 session_options->recv_video = false; |
1536 if (!ParseConstraintsForAnswer(constraints, session_options)) { | 1554 if (!ParseConstraintsForAnswer(constraints, session_options)) { |
1537 return false; | 1555 return false; |
1538 } | 1556 } |
1539 | 1557 |
1558 LateInitialize(); | |
1540 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1559 AddSendStreams(session_options, senders_, rtp_data_channels_); |
1541 session_options->bundle_enabled = | 1560 session_options->bundle_enabled = |
1542 session_options->bundle_enabled && | 1561 session_options->bundle_enabled && |
1543 (session_options->has_audio() || session_options->has_video() || | 1562 (session_options->has_audio() || session_options->has_video() || |
1544 session_options->has_data()); | 1563 session_options->has_data()); |
1545 | 1564 |
1546 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 1565 // 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 | 1566 // are not signaled in the SDP so does not go through that path and must be |
1548 // handled here. | 1567 // handled here. |
1549 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1568 if (session_->data_channel_type() == cricket::DCT_SCTP) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1631 } | 1650 } |
1632 } | 1651 } |
1633 } | 1652 } |
1634 | 1653 |
1635 void PeerConnection::OnRemoteTrackSeen(const std::string& stream_label, | 1654 void PeerConnection::OnRemoteTrackSeen(const std::string& stream_label, |
1636 const std::string& track_id, | 1655 const std::string& track_id, |
1637 uint32_t ssrc, | 1656 uint32_t ssrc, |
1638 cricket::MediaType media_type) { | 1657 cricket::MediaType media_type) { |
1639 MediaStreamInterface* stream = remote_streams_->find(stream_label); | 1658 MediaStreamInterface* stream = remote_streams_->find(stream_label); |
1640 | 1659 |
1660 LateInitialize(); | |
1641 if (media_type == cricket::MEDIA_TYPE_AUDIO) { | 1661 if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
1642 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack( | 1662 AudioTrackInterface* audio_track = remote_stream_factory_->AddAudioTrack( |
1643 ssrc, session_.get(), stream, track_id); | 1663 ssrc, session_.get(), stream, track_id); |
1644 CreateAudioReceiver(stream, audio_track, ssrc); | 1664 CreateAudioReceiver(stream, audio_track, ssrc); |
1645 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 1665 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
1646 VideoTrackInterface* video_track = | 1666 VideoTrackInterface* video_track = |
1647 remote_stream_factory_->AddVideoTrack(stream, track_id); | 1667 remote_stream_factory_->AddVideoTrack(stream, track_id); |
1648 CreateVideoReceiver(stream, video_track, ssrc); | 1668 CreateVideoReceiver(stream, video_track, ssrc); |
1649 } else { | 1669 } else { |
1650 RTC_DCHECK(false && "Invalid media type"); | 1670 RTC_DCHECK(false && "Invalid media type"); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1887 observer_->OnDataChannel( | 1907 observer_->OnDataChannel( |
1888 DataChannelProxy::Create(signaling_thread(), channel)); | 1908 DataChannelProxy::Create(signaling_thread(), channel)); |
1889 } | 1909 } |
1890 | 1910 |
1891 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( | 1911 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( |
1892 const std::string& label, | 1912 const std::string& label, |
1893 const InternalDataChannelInit* config) { | 1913 const InternalDataChannelInit* config) { |
1894 if (IsClosed()) { | 1914 if (IsClosed()) { |
1895 return nullptr; | 1915 return nullptr; |
1896 } | 1916 } |
1917 LateInitialize(); | |
1897 if (session_->data_channel_type() == cricket::DCT_NONE) { | 1918 if (session_->data_channel_type() == cricket::DCT_NONE) { |
1898 LOG(LS_ERROR) | 1919 LOG(LS_ERROR) |
1899 << "InternalCreateDataChannel: Data is not supported in this call."; | 1920 << "InternalCreateDataChannel: Data is not supported in this call."; |
1900 return nullptr; | 1921 return nullptr; |
1901 } | 1922 } |
1902 InternalDataChannelInit new_config = | 1923 InternalDataChannelInit new_config = |
1903 config ? (*config) : InternalDataChannelInit(); | 1924 config ? (*config) : InternalDataChannelInit(); |
1904 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1925 if (session_->data_channel_type() == cricket::DCT_SCTP) { |
1905 if (new_config.id < 0) { | 1926 if (new_config.id < 0) { |
1906 rtc::SSLRole role; | 1927 rtc::SSLRole role; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2078 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2099 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
2079 for (const auto& channel : sctp_data_channels_) { | 2100 for (const auto& channel : sctp_data_channels_) { |
2080 if (channel->id() == sid) { | 2101 if (channel->id() == sid) { |
2081 return channel; | 2102 return channel; |
2082 } | 2103 } |
2083 } | 2104 } |
2084 return nullptr; | 2105 return nullptr; |
2085 } | 2106 } |
2086 | 2107 |
2087 } // namespace webrtc | 2108 } // namespace webrtc |
OLD | NEW |