summaryrefslogtreecommitdiff
path: root/indra/llwebrtc
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llwebrtc')
-rw-r--r--indra/llwebrtc/llwebrtc.cpp65
-rw-r--r--indra/llwebrtc/llwebrtc_impl.h5
2 files changed, 63 insertions, 7 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp
index 7e2b5d2741..7c2481a94c 100644
--- a/indra/llwebrtc/llwebrtc.cpp
+++ b/indra/llwebrtc/llwebrtc.cpp
@@ -390,8 +390,6 @@ void LLWebRTCImpl::terminate()
mSignalingThread->BlockingCall([this]() { mPeerConnectionFactory = nullptr; });
- mPeerConnections.clear();
-
mWorkerThread->BlockingCall(
[this]()
{
@@ -402,6 +400,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);
}
@@ -582,14 +588,20 @@ void LLWebRTCImpl::workerDeployDevices()
void LLWebRTCImpl::setCaptureDevice(const std::string &id)
{
- mRecordingDevice = id;
- deployDevices();
+ if (mRecordingDevice != id)
+ {
+ mRecordingDevice = id;
+ deployDevices();
+ }
}
void LLWebRTCImpl::setRenderDevice(const std::string &id)
{
- mPlayoutDevice = id;
- deployDevices();
+ if (mPlayoutDevice != id)
+ {
+ mPlayoutDevice = id;
+ deployDevices();
+ }
}
// updateDevices needs to happen on the worker thread.
@@ -651,6 +663,13 @@ void LLWebRTCImpl::OnDevicesUpdated()
void LLWebRTCImpl::setTuningMode(bool enable)
{
mTuningMode = enable;
+ if (!mTuningMode
+ && !mMute
+ && mPeerCustomProcessor
+ && mPeerCustomProcessor->getGain() != mGain)
+ {
+ mPeerCustomProcessor->setGain(mGain);
+ }
mWorkerThread->PostTask(
[this]
{
@@ -782,6 +801,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())
{
@@ -801,7 +821,8 @@ LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() :
mWebRTCImpl(nullptr),
mPeerConnection(nullptr),
mMute(MUTE_INITIAL),
- mAnswerReceived(false)
+ mAnswerReceived(false),
+ mPendingJobs(0)
{
}
@@ -809,6 +830,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";
+ }
}
//
@@ -820,8 +845,10 @@ void LLWebRTCPeerConnectionImpl::init(LLWebRTCImpl * webrtc_impl)
mWebRTCImpl = webrtc_impl;
mPeerConnectionFactory = mWebRTCImpl->getPeerConnectionFactory();
}
+
void LLWebRTCPeerConnectionImpl::terminate()
{
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this]()
{
@@ -864,7 +891,9 @@ void LLWebRTCPeerConnectionImpl::terminate()
observer->OnPeerConnectionClosed();
}
}
+ mPendingJobs--;
});
+ mPeerConnectionFactory.release();
}
void LLWebRTCPeerConnectionImpl::setSignalingObserver(LLWebRTCSignalingObserver *observer) { mSignalingObserverList.emplace_back(observer); }
@@ -885,6 +914,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti
RTC_DCHECK(!mPeerConnection);
mAnswerReceived = false;
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this,options]()
{
@@ -906,6 +936,13 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti
config.set_max_port(60100);
webrtc::PeerConnectionDependencies pc_dependencies(this);
+ if (mPeerConnectionFactory == nullptr)
+ {
+ RTC_LOG(LS_ERROR) << __FUNCTION__ << "Error creating peer connection, factory doesn't exist";
+ // Too early?
+ mPendingJobs--;
+ return;
+ }
auto error_or_peer_connection = mPeerConnectionFactory->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
if (error_or_peer_connection.ok())
{
@@ -918,6 +955,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti
{
observer->OnRenegotiationNeeded();
}
+ mPendingJobs--;
return;
}
@@ -980,6 +1018,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions offerOptions;
mPeerConnection->CreateOffer(this, offerOptions);
+ mPendingJobs--;
});
return true;
@@ -1022,6 +1061,7 @@ void LLWebRTCPeerConnectionImpl::AnswerAvailable(const std::string &sdp)
{
RTC_LOG(LS_INFO) << __FUNCTION__ << " Remote SDP: " << sdp;
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this, sdp]()
{
@@ -1031,6 +1071,7 @@ void LLWebRTCPeerConnectionImpl::AnswerAvailable(const std::string &sdp)
mPeerConnection->SetRemoteDescription(webrtc::CreateSessionDescription(webrtc::SdpType::kAnswer, sdp),
webrtc::scoped_refptr<webrtc::SetRemoteDescriptionObserverInterface>(this));
}
+ mPendingJobs--;
});
}
@@ -1053,6 +1094,7 @@ void LLWebRTCPeerConnectionImpl::setMute(bool mute)
mMute = new_state;
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this, force_reset, enable]()
{
@@ -1076,6 +1118,7 @@ void LLWebRTCPeerConnectionImpl::setMute(bool mute)
track->set_enabled(enable);
}
}
+ mPendingJobs--;
}
});
}
@@ -1097,6 +1140,7 @@ void LLWebRTCPeerConnectionImpl::resetMute()
void LLWebRTCPeerConnectionImpl::setReceiveVolume(float volume)
{
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this, volume]()
{
@@ -1115,11 +1159,13 @@ void LLWebRTCPeerConnectionImpl::setReceiveVolume(float volume)
}
}
}
+ mPendingJobs--;
});
}
void LLWebRTCPeerConnectionImpl::setSendVolume(float volume)
{
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this, volume]()
{
@@ -1130,6 +1176,7 @@ void LLWebRTCPeerConnectionImpl::setSendVolume(float volume)
track->GetSource()->SetVolume(volume*5.0);
}
}
+ mPendingJobs--;
});
}
@@ -1206,11 +1253,13 @@ void LLWebRTCPeerConnectionImpl::OnConnectionChange(webrtc::PeerConnectionInterf
{
case webrtc::PeerConnectionInterface::PeerConnectionState::kConnected:
{
+ mPendingJobs++;
mWebRTCImpl->PostWorkerTask([this]() {
for (auto &observer : mSignalingObserverList)
{
observer->OnAudioEstablished(this);
}
+ mPendingJobs--;
});
break;
}
@@ -1468,11 +1517,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--;
});
}
}
diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h
index fbc60d48e3..9d3af985ef 100644
--- a/indra/llwebrtc/llwebrtc_impl.h
+++ b/indra/llwebrtc/llwebrtc_impl.h
@@ -428,6 +428,9 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, public webrtc::AudioDeviceO
~LLWebRTCImpl()
{
delete mLogSink;
+
+ // Explicit cleanup for the sake of debugging and crash stacks
+ mPeerCustomProcessor = nullptr;
}
void init();
@@ -679,6 +682,8 @@ class LLWebRTCPeerConnectionImpl : public LLWebRTCPeerConnectionInterface,
// data
std::vector<LLWebRTCDataObserver *> mDataObserverList;
webrtc::scoped_refptr<webrtc::DataChannelInterface> mDataChannel;
+
+ std::atomic<int> mPendingJobs;
};
}