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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 for (const auto& receiver : receivers_) { | 556 for (const auto& receiver : receivers_) { |
557 receiver->internal()->Stop(); | 557 receiver->internal()->Stop(); |
558 } | 558 } |
559 // Destroy stats_ because it depends on session_. | 559 // Destroy stats_ because it depends on session_. |
560 stats_.reset(nullptr); | 560 stats_.reset(nullptr); |
561 // Now destroy session_ before destroying other members, | 561 // Now destroy session_ before destroying other members, |
562 // because its destruction fires signals (such as VoiceChannelDestroyed) | 562 // because its destruction fires signals (such as VoiceChannelDestroyed) |
563 // which will trigger some final actions in PeerConnection... | 563 // which will trigger some final actions in PeerConnection... |
564 session_.reset(nullptr); | 564 session_.reset(nullptr); |
565 // port_allocator_ lives on the network thread and should be destroyed there. | 565 // port_allocator_ lives on the network thread and should be destroyed there. |
566 network_thread()->Invoke<void>([this] { port_allocator_.reset(nullptr); }); | 566 network_thread()->Invoke<void>(RTC_FROM_HERE, |
| 567 [this] { port_allocator_.reset(nullptr); }); |
567 } | 568 } |
568 | 569 |
569 bool PeerConnection::Initialize( | 570 bool PeerConnection::Initialize( |
570 const PeerConnectionInterface::RTCConfiguration& configuration, | 571 const PeerConnectionInterface::RTCConfiguration& configuration, |
571 std::unique_ptr<cricket::PortAllocator> allocator, | 572 std::unique_ptr<cricket::PortAllocator> allocator, |
572 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, | 573 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
573 PeerConnectionObserver* observer) { | 574 PeerConnectionObserver* observer) { |
574 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); | 575 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
575 RTC_DCHECK(observer != nullptr); | 576 RTC_DCHECK(observer != nullptr); |
576 if (!observer) { | 577 if (!observer) { |
577 return false; | 578 return false; |
578 } | 579 } |
579 observer_ = observer; | 580 observer_ = observer; |
580 | 581 |
581 port_allocator_ = std::move(allocator); | 582 port_allocator_ = std::move(allocator); |
582 | 583 |
583 // The port allocator lives on the network thread and should be initialized | 584 // The port allocator lives on the network thread and should be initialized |
584 // there. | 585 // there. |
585 if (!network_thread()->Invoke<bool>(rtc::Bind( | 586 if (!network_thread()->Invoke<bool>( |
586 &PeerConnection::InitializePortAllocator_n, this, configuration))) { | 587 RTC_FROM_HERE, rtc::Bind(&PeerConnection::InitializePortAllocator_n, |
| 588 this, configuration))) { |
587 return false; | 589 return false; |
588 } | 590 } |
589 | 591 |
590 media_controller_.reset( | 592 media_controller_.reset( |
591 factory_->CreateMediaController(configuration.media_config)); | 593 factory_->CreateMediaController(configuration.media_config)); |
592 | 594 |
593 session_.reset( | 595 session_.reset( |
594 new WebRtcSession(media_controller_.get(), factory_->network_thread(), | 596 new WebRtcSession(media_controller_.get(), factory_->network_thread(), |
595 factory_->worker_thread(), factory_->signaling_thread(), | 597 factory_->worker_thread(), factory_->signaling_thread(), |
596 port_allocator_.get())); | 598 port_allocator_.get())); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 MediaStreamTrackInterface* track, | 828 MediaStreamTrackInterface* track, |
827 StatsOutputLevel level) { | 829 StatsOutputLevel level) { |
828 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); | 830 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); |
829 RTC_DCHECK(signaling_thread()->IsCurrent()); | 831 RTC_DCHECK(signaling_thread()->IsCurrent()); |
830 if (!VERIFY(observer != NULL)) { | 832 if (!VERIFY(observer != NULL)) { |
831 LOG(LS_ERROR) << "GetStats - observer is NULL."; | 833 LOG(LS_ERROR) << "GetStats - observer is NULL."; |
832 return false; | 834 return false; |
833 } | 835 } |
834 | 836 |
835 stats_->UpdateStats(level); | 837 stats_->UpdateStats(level); |
836 signaling_thread()->Post(this, MSG_GETSTATS, | 838 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_GETSTATS, |
837 new GetStatsMsg(observer, track)); | 839 new GetStatsMsg(observer, track)); |
838 return true; | 840 return true; |
839 } | 841 } |
840 | 842 |
841 PeerConnectionInterface::SignalingState PeerConnection::signaling_state() { | 843 PeerConnectionInterface::SignalingState PeerConnection::signaling_state() { |
842 return signaling_state_; | 844 return signaling_state_; |
843 } | 845 } |
844 | 846 |
845 PeerConnectionInterface::IceState PeerConnection::ice_state() { | 847 PeerConnectionInterface::IceState PeerConnection::ice_state() { |
846 return ice_state_; | 848 return ice_state_; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 const cricket::DataContentDescription* data_desc = | 1057 const cricket::DataContentDescription* data_desc = |
1056 static_cast<const cricket::DataContentDescription*>( | 1058 static_cast<const cricket::DataContentDescription*>( |
1057 data_content->description); | 1059 data_content->description); |
1058 if (rtc::starts_with(data_desc->protocol().data(), | 1060 if (rtc::starts_with(data_desc->protocol().data(), |
1059 cricket::kMediaProtocolRtpPrefix)) { | 1061 cricket::kMediaProtocolRtpPrefix)) { |
1060 UpdateLocalRtpDataChannels(data_desc->streams()); | 1062 UpdateLocalRtpDataChannels(data_desc->streams()); |
1061 } | 1063 } |
1062 } | 1064 } |
1063 | 1065 |
1064 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1066 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1065 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); | 1067 signaling_thread()->Post(RTC_FROM_HERE, this, |
| 1068 MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
1066 | 1069 |
1067 // MaybeStartGathering needs to be called after posting | 1070 // MaybeStartGathering needs to be called after posting |
1068 // MSG_SET_SESSIONDESCRIPTION_SUCCESS, so that we don't signal any candidates | 1071 // MSG_SET_SESSIONDESCRIPTION_SUCCESS, so that we don't signal any candidates |
1069 // before signaling that SetLocalDescription completed. | 1072 // before signaling that SetLocalDescription completed. |
1070 session_->MaybeStartGathering(); | 1073 session_->MaybeStartGathering(); |
1071 } | 1074 } |
1072 | 1075 |
1073 void PeerConnection::SetRemoteDescription( | 1076 void PeerConnection::SetRemoteDescription( |
1074 SetSessionDescriptionObserver* observer, | 1077 SetSessionDescriptionObserver* observer, |
1075 SessionDescriptionInterface* desc) { | 1078 SessionDescriptionInterface* desc) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 // Call both the raw pointer and scoped_refptr versions of the method | 1169 // Call both the raw pointer and scoped_refptr versions of the method |
1167 // for compatibility. | 1170 // for compatibility. |
1168 observer_->OnAddStream(new_stream); | 1171 observer_->OnAddStream(new_stream); |
1169 observer_->OnAddStream( | 1172 observer_->OnAddStream( |
1170 rtc::scoped_refptr<MediaStreamInterface>(new_stream)); | 1173 rtc::scoped_refptr<MediaStreamInterface>(new_stream)); |
1171 } | 1174 } |
1172 | 1175 |
1173 UpdateEndedRemoteMediaStreams(); | 1176 UpdateEndedRemoteMediaStreams(); |
1174 | 1177 |
1175 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1178 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1176 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); | 1179 signaling_thread()->Post(RTC_FROM_HERE, this, |
| 1180 MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
1177 } | 1181 } |
1178 | 1182 |
1179 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { | 1183 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { |
1180 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); | 1184 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); |
1181 if (port_allocator_) { | 1185 if (port_allocator_) { |
1182 if (!network_thread()->Invoke<bool>( | 1186 if (!network_thread()->Invoke<bool>( |
| 1187 RTC_FROM_HERE, |
1183 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this, | 1188 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this, |
1184 configuration))) { | 1189 configuration))) { |
1185 return false; | 1190 return false; |
1186 } | 1191 } |
1187 } | 1192 } |
1188 | 1193 |
1189 // TODO(deadbeef): Shouldn't have to hop to the worker thread twice... | 1194 // TODO(deadbeef): Shouldn't have to hop to the worker thread twice... |
1190 session_->SetIceConfig(session_->ParseIceConfig(configuration)); | 1195 session_->SetIceConfig(session_->ParseIceConfig(configuration)); |
1191 return true; | 1196 return true; |
1192 } | 1197 } |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 } | 1490 } |
1486 (*sender)->internal()->Stop(); | 1491 (*sender)->internal()->Stop(); |
1487 senders_.erase(sender); | 1492 senders_.erase(sender); |
1488 } | 1493 } |
1489 | 1494 |
1490 void PeerConnection::PostSetSessionDescriptionFailure( | 1495 void PeerConnection::PostSetSessionDescriptionFailure( |
1491 SetSessionDescriptionObserver* observer, | 1496 SetSessionDescriptionObserver* observer, |
1492 const std::string& error) { | 1497 const std::string& error) { |
1493 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1498 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1494 msg->error = error; | 1499 msg->error = error; |
1495 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_FAILED, msg); | 1500 signaling_thread()->Post(RTC_FROM_HERE, this, |
| 1501 MSG_SET_SESSIONDESCRIPTION_FAILED, msg); |
1496 } | 1502 } |
1497 | 1503 |
1498 void PeerConnection::PostCreateSessionDescriptionFailure( | 1504 void PeerConnection::PostCreateSessionDescriptionFailure( |
1499 CreateSessionDescriptionObserver* observer, | 1505 CreateSessionDescriptionObserver* observer, |
1500 const std::string& error) { | 1506 const std::string& error) { |
1501 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); | 1507 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); |
1502 msg->error = error; | 1508 msg->error = error; |
1503 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); | 1509 signaling_thread()->Post(RTC_FROM_HERE, this, |
| 1510 MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); |
1504 } | 1511 } |
1505 | 1512 |
1506 bool PeerConnection::GetOptionsForOffer( | 1513 bool PeerConnection::GetOptionsForOffer( |
1507 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 1514 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
1508 cricket::MediaSessionOptions* session_options) { | 1515 cricket::MediaSessionOptions* session_options) { |
1509 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1516 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
1510 // ContentInfos. | 1517 // ContentInfos. |
1511 if (session_->local_description()) { | 1518 if (session_->local_description()) { |
1512 for (const cricket::ContentInfo& content : | 1519 for (const cricket::ContentInfo& content : |
1513 session_->local_description()->description()->contents()) { | 1520 session_->local_description()->description()->contents()) { |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 for (auto it = sctp_data_channels_.begin(); it != sctp_data_channels_.end(); | 1999 for (auto it = sctp_data_channels_.begin(); it != sctp_data_channels_.end(); |
1993 ++it) { | 2000 ++it) { |
1994 if (it->get() == channel) { | 2001 if (it->get() == channel) { |
1995 if (channel->id() >= 0) { | 2002 if (channel->id() >= 0) { |
1996 sid_allocator_.ReleaseSid(channel->id()); | 2003 sid_allocator_.ReleaseSid(channel->id()); |
1997 } | 2004 } |
1998 // Since this method is triggered by a signal from the DataChannel, | 2005 // Since this method is triggered by a signal from the DataChannel, |
1999 // we can't free it directly here; we need to free it asynchronously. | 2006 // we can't free it directly here; we need to free it asynchronously. |
2000 sctp_data_channels_to_free_.push_back(*it); | 2007 sctp_data_channels_to_free_.push_back(*it); |
2001 sctp_data_channels_.erase(it); | 2008 sctp_data_channels_.erase(it); |
2002 signaling_thread()->Post(this, MSG_FREE_DATACHANNELS, nullptr); | 2009 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FREE_DATACHANNELS, |
| 2010 nullptr); |
2003 return; | 2011 return; |
2004 } | 2012 } |
2005 } | 2013 } |
2006 } | 2014 } |
2007 | 2015 |
2008 void PeerConnection::OnVoiceChannelDestroyed() { | 2016 void PeerConnection::OnVoiceChannelDestroyed() { |
2009 StopReceivers(cricket::MEDIA_TYPE_AUDIO); | 2017 StopReceivers(cricket::MEDIA_TYPE_AUDIO); |
2010 } | 2018 } |
2011 | 2019 |
2012 void PeerConnection::OnVideoChannelDestroyed() { | 2020 void PeerConnection::OnVideoChannelDestroyed() { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 port_allocator_->set_candidate_filter( | 2187 port_allocator_->set_candidate_filter( |
2180 ConvertIceTransportTypeToCandidateFilter(configuration.type)); | 2188 ConvertIceTransportTypeToCandidateFilter(configuration.type)); |
2181 // Call this last since it may create pooled allocator sessions using the | 2189 // Call this last since it may create pooled allocator sessions using the |
2182 // candidate filter set above. | 2190 // candidate filter set above. |
2183 port_allocator_->SetConfiguration(stun_servers, turn_servers, | 2191 port_allocator_->SetConfiguration(stun_servers, turn_servers, |
2184 configuration.ice_candidate_pool_size); | 2192 configuration.ice_candidate_pool_size); |
2185 return true; | 2193 return true; |
2186 } | 2194 } |
2187 | 2195 |
2188 } // namespace webrtc | 2196 } // namespace webrtc |
OLD | NEW |