summaryrefslogtreecommitdiff
path: root/indra/llwebrtc
diff options
context:
space:
mode:
authorRoxanne Skelly <roxie@lindenlab.com>2024-03-19 22:47:44 -0700
committerGitHub <noreply@github.com>2024-03-19 22:47:44 -0700
commit6047b61b2afc7eea0292e76920699aa7973bc33d (patch)
treea1e0973bb30f86a528d0ac07f14b0f10f899a462 /indra/llwebrtc
parent410be3b2d0ebbf6746140712430e54270541aecd (diff)
parent0e2fc4d35ea1fdef0028a5132602985da2e1c463 (diff)
Merge pull request #1021 from secondlife/roxie/webrtc-voice-workqueue
WebRTC: Make callbacks from webrtc-proper launch workqueue jobs to run code on the main thread, instead of relying on mutexes and such.
Diffstat (limited to 'indra/llwebrtc')
-rw-r--r--indra/llwebrtc/llwebrtc.cpp56
-rw-r--r--indra/llwebrtc/llwebrtc.h3
-rw-r--r--indra/llwebrtc/llwebrtc_impl.h16
3 files changed, 37 insertions, 38 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp
index b7501bd0e0..34d950b804 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()
{
- mWebRTCImpl->SignalingBlockingCall(
- [this]()
+ 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(
+ [=]()
{
- if (mPeerConnection)
+ if (connection)
{
- mPeerConnection->Close();
- mPeerConnection = nullptr;
+ connection->Close();
+ }
+ if (dataChannel)
+ {
+ 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)
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;
};
}