diff options
Diffstat (limited to 'indra/llwebrtc/llwebrtc.cpp')
| -rw-r--r-- | indra/llwebrtc/llwebrtc.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index 828896f620..cbf2dfd67e 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -374,8 +374,6 @@ void LLWebRTCImpl::terminate() mSignalingThread->BlockingCall([this]() { mPeerConnectionFactory = nullptr; }); - mPeerConnections.clear(); - mWorkerThread->BlockingCall( [this]() { @@ -386,6 +384,14 @@ void LLWebRTCImpl::terminate() mDeviceModule = nullptr; mTaskQueueFactory = nullptr; }); + + // In case peer connections still somehow have jobs in workers, + // only clear connections up after clearing workers. + mNetworkThread = nullptr; + mWorkerThread = nullptr; + mSignalingThread = nullptr; + + mPeerConnections.clear(); webrtc::LogMessage::RemoveLogToStream(mLogSink); } @@ -766,6 +772,7 @@ void LLWebRTCImpl::freePeerConnection(LLWebRTCPeerConnectionInterface* peer_conn std::find(mPeerConnections.begin(), mPeerConnections.end(), peer_connection); if (it != mPeerConnections.end()) { + // Todo: make sure conection had no jobs in workers mPeerConnections.erase(it); if (mPeerConnections.empty()) { @@ -785,7 +792,8 @@ LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() : mWebRTCImpl(nullptr), mPeerConnection(nullptr), mMute(MUTE_INITIAL), - mAnswerReceived(false) + mAnswerReceived(false), + mPendingJobs(0) { } @@ -793,6 +801,10 @@ LLWebRTCPeerConnectionImpl::~LLWebRTCPeerConnectionImpl() { mSignalingObserverList.clear(); mDataObserverList.clear(); + if (mPendingJobs > 0) + { + RTC_LOG(LS_ERROR) << __FUNCTION__ << "Destroying a connection that has " << std::to_string(mPendingJobs) << " unfinished jobs that might cause workers to crash"; + } } // @@ -804,8 +816,10 @@ void LLWebRTCPeerConnectionImpl::init(LLWebRTCImpl * webrtc_impl) mWebRTCImpl = webrtc_impl; mPeerConnectionFactory = mWebRTCImpl->getPeerConnectionFactory(); } + void LLWebRTCPeerConnectionImpl::terminate() { + mPendingJobs++; mWebRTCImpl->PostSignalingTask( [this]() { @@ -848,7 +862,9 @@ void LLWebRTCPeerConnectionImpl::terminate() observer->OnPeerConnectionClosed(); } } + mPendingJobs--; }); + mPeerConnectionFactory.release(); } void LLWebRTCPeerConnectionImpl::setSignalingObserver(LLWebRTCSignalingObserver *observer) { mSignalingObserverList.emplace_back(observer); } @@ -869,6 +885,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti RTC_DCHECK(!mPeerConnection); mAnswerReceived = false; + mPendingJobs++; mWebRTCImpl->PostSignalingTask( [this,options]() { @@ -902,6 +919,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti { observer->OnRenegotiationNeeded(); } + mPendingJobs--; return; } @@ -964,6 +982,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti webrtc::PeerConnectionInterface::RTCOfferAnswerOptions offerOptions; mPeerConnection->CreateOffer(this, offerOptions); + mPendingJobs--; }); return true; @@ -1006,6 +1025,7 @@ void LLWebRTCPeerConnectionImpl::AnswerAvailable(const std::string &sdp) { RTC_LOG(LS_INFO) << __FUNCTION__ << " Remote SDP: " << sdp; + mPendingJobs++; mWebRTCImpl->PostSignalingTask( [this, sdp]() { @@ -1015,6 +1035,7 @@ void LLWebRTCPeerConnectionImpl::AnswerAvailable(const std::string &sdp) mPeerConnection->SetRemoteDescription(webrtc::CreateSessionDescription(webrtc::SdpType::kAnswer, sdp), webrtc::scoped_refptr<webrtc::SetRemoteDescriptionObserverInterface>(this)); } + mPendingJobs--; }); } @@ -1037,6 +1058,7 @@ void LLWebRTCPeerConnectionImpl::setMute(bool mute) mMute = new_state; + mPendingJobs++; mWebRTCImpl->PostSignalingTask( [this, force_reset, enable]() { @@ -1060,6 +1082,7 @@ void LLWebRTCPeerConnectionImpl::setMute(bool mute) track->set_enabled(enable); } } + mPendingJobs--; } }); } @@ -1081,6 +1104,7 @@ void LLWebRTCPeerConnectionImpl::resetMute() void LLWebRTCPeerConnectionImpl::setReceiveVolume(float volume) { + mPendingJobs++; mWebRTCImpl->PostSignalingTask( [this, volume]() { @@ -1099,11 +1123,13 @@ void LLWebRTCPeerConnectionImpl::setReceiveVolume(float volume) } } } + mPendingJobs--; }); } void LLWebRTCPeerConnectionImpl::setSendVolume(float volume) { + mPendingJobs++; mWebRTCImpl->PostSignalingTask( [this, volume]() { @@ -1114,6 +1140,7 @@ void LLWebRTCPeerConnectionImpl::setSendVolume(float volume) track->GetSource()->SetVolume(volume*5.0); } } + mPendingJobs--; }); } @@ -1190,11 +1217,13 @@ void LLWebRTCPeerConnectionImpl::OnConnectionChange(webrtc::PeerConnectionInterf { case webrtc::PeerConnectionInterface::PeerConnectionState::kConnected: { + mPendingJobs++; mWebRTCImpl->PostWorkerTask([this]() { for (auto &observer : mSignalingObserverList) { observer->OnAudioEstablished(this); } + mPendingJobs--; }); break; } @@ -1452,11 +1481,13 @@ void LLWebRTCPeerConnectionImpl::sendData(const std::string& data, bool binary) { webrtc::CopyOnWriteBuffer cowBuffer(data.data(), data.length()); webrtc::DataBuffer buffer(cowBuffer, binary); + mPendingJobs++; mWebRTCImpl->PostNetworkTask([this, buffer]() { if (mDataChannel) { mDataChannel->Send(buffer); } + mPendingJobs--; }); } } |
