summaryrefslogtreecommitdiff
path: root/indra/llwebrtc
diff options
context:
space:
mode:
authorRoxie Linden <roxie@lindenlab.com>2024-03-19 15:23:43 -0700
committerRoxie Linden <roxie@lindenlab.com>2024-03-19 15:23:43 -0700
commit5bc92b8031e9a6258bab8b24d42090a495cec6e5 (patch)
tree07eb27fc3411a0cb32f6245bfea9d7cd6d1f889c /indra/llwebrtc
parente4dee511cab0a98e802e2c0cc12b3d8b9b90a8df (diff)
Simplify workqueue calls. Fix issue with webrtc blocking on destruction.
Diffstat (limited to 'indra/llwebrtc')
-rw-r--r--indra/llwebrtc/llwebrtc.cpp62
-rw-r--r--indra/llwebrtc/llwebrtc.h3
-rw-r--r--indra/llwebrtc/llwebrtc_impl.h16
3 files changed, 44 insertions, 37 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp
index 6400f807fd..283b94dd3c 100644
--- a/indra/llwebrtc/llwebrtc.cpp
+++ b/indra/llwebrtc/llwebrtc.cpp
@@ -562,8 +562,10 @@ void LLWebRTCImpl::freePeerConnection(LLWebRTCPeerConnectionInterface* peer_conn
// Most peer connection (signaling) happens on
// the signaling thread.
-LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() :
+LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() :
mWebRTCImpl(nullptr),
+ mClosing(false),
+ mPeerConnection(nullptr),
mMute(false),
mAnswerReceived(false)
{
@@ -580,13 +582,24 @@ void LLWebRTCPeerConnectionImpl::init(LLWebRTCImpl * webrtc_impl)
}
void LLWebRTCPeerConnectionImpl::terminate()
{
+ rtc::scoped_refptr<webrtc::PeerConnectionInterface> connection;
+ mPeerConnection.swap(connection);
+ rtc::scoped_refptr<webrtc::DataChannelInterface> dataChannel;
+ mDataChannel.swap(dataChannel);
+ rtc::scoped_refptr<webrtc::MediaStreamInterface> localStream;
+ mLocalStream.swap(localStream);
+
mWebRTCImpl->PostSignalingTask(
- [this]()
+ [=]()
{
- if (mPeerConnection)
+ if (connection)
+ {
+ connection->Close();
+ }
+ if (dataChannel)
{
- mPeerConnection->Close();
- mPeerConnection = nullptr;
+ dataChannel->UnregisterObserver();
+ dataChannel->Close();
}
});
}
@@ -710,24 +723,9 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection()
bool LLWebRTCPeerConnectionImpl::shutdownConnection()
{
- if (mPeerConnection)
- {
- mWebRTCImpl->PostSignalingTask(
- [this]()
- {
- if (mPeerConnection)
- {
- mPeerConnection->Close();
- mPeerConnection = nullptr;
- }
- for (auto &observer : mSignalingObserverList)
- {
- observer->OnPeerConnectionShutdown();
- }
- });
- return true;
- }
- return false;
+ mClosing = true;
+ terminate();
+ return true;
}
void LLWebRTCPeerConnectionImpl::enableSenderTracks(bool enable)
@@ -1057,14 +1055,16 @@ void LLWebRTCPeerConnectionImpl::OnSuccess(webrtc::SessionDescriptionInterface *
}
RTC_LOG(LS_INFO) << __FUNCTION__ << " Local SDP: " << sdp_mangled_stream.str();
-
+ std::string mangled_sdp = sdp_mangled_stream.str();
for (auto &observer : mSignalingObserverList)
{
- observer->OnOfferAvailable(sdp_mangled_stream.str());
+ observer->OnOfferAvailable(mangled_sdp);
}
+
+ mPeerConnection->SetLocalDescription(std::unique_ptr<webrtc::SessionDescriptionInterface>(
+ webrtc::CreateSessionDescription(webrtc::SdpType::kOffer, mangled_sdp)),
+ rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface>(this));
- mPeerConnection->SetLocalDescription(std::unique_ptr<webrtc::SessionDescriptionInterface>(webrtc::CreateSessionDescription(webrtc::SdpType::kOffer, sdp_mangled_stream.str())),
- rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface>(this));
}
void LLWebRTCPeerConnectionImpl::OnFailure(webrtc::RTCError error)
@@ -1135,6 +1135,14 @@ void LLWebRTCPeerConnectionImpl::OnStateChange()
break;
case webrtc::DataChannelInterface::kClosed:
RTC_LOG(LS_INFO) << __FUNCTION__ << " Data Channel State closed";
+ // if the data channel is up, we need to shut it down, holding off
+ // on termination of the peer connection until it's been closed.
+ if (mClosing)
+ {
+ // a close was requested, and the data channel has closed,
+ // so go ahead and call shutdownConnection again to clean up.
+ shutdownConnection();
+ }
break;
default:
break;
diff --git a/indra/llwebrtc/llwebrtc.h b/indra/llwebrtc/llwebrtc.h
index dab7774499..be2e5cdf68 100644
--- a/indra/llwebrtc/llwebrtc.h
+++ b/indra/llwebrtc/llwebrtc.h
@@ -192,9 +192,6 @@ class LLWebRTCSignalingObserver
// Called when the data channel has been established and data
// transfer can begin.
virtual void OnDataChannelReady(LLWebRTCDataInterface *data_interface) = 0;
-
- // Called when a peer connection has finished shutting down.
- virtual void OnPeerConnectionShutdown() = 0;
};
diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h
index 1f696e8c66..38810a29b5 100644
--- a/indra/llwebrtc/llwebrtc_impl.h
+++ b/indra/llwebrtc/llwebrtc_impl.h
@@ -346,21 +346,23 @@ class LLWebRTCPeerConnectionImpl : public LLWebRTCPeerConnectionInterface,
LLWebRTCImpl * mWebRTCImpl;
+ bool mClosing;
+
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> mPeerConnectionFactory;
- bool mMute;
+ bool mMute;
// signaling
- std::vector<LLWebRTCSignalingObserver *> mSignalingObserverList;
+ std::vector<LLWebRTCSignalingObserver *> mSignalingObserverList;
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> mCachedIceCandidates;
- bool mAnswerReceived;
+ bool mAnswerReceived;
- rtc::scoped_refptr<webrtc::PeerConnectionInterface> mPeerConnection;
- rtc::scoped_refptr<webrtc::MediaStreamInterface> mLocalStream;
+ rtc::scoped_refptr<webrtc::PeerConnectionInterface> mPeerConnection;
+ rtc::scoped_refptr<webrtc::MediaStreamInterface> mLocalStream;
// data
- std::vector<LLWebRTCDataObserver *> mDataObserverList;
- rtc::scoped_refptr<webrtc::DataChannelInterface> mDataChannel;
+ std::vector<LLWebRTCDataObserver *> mDataObserverList;
+ rtc::scoped_refptr<webrtc::DataChannelInterface> mDataChannel;
};
}