summaryrefslogtreecommitdiff
path: root/indra/llwebrtc/llwebrtc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llwebrtc/llwebrtc.cpp')
-rw-r--r--indra/llwebrtc/llwebrtc.cpp51
1 files changed, 48 insertions, 3 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp
index 7e2b5d2741..d453ad0c7b 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);
}
@@ -651,6 +657,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 +795,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 +815,8 @@ LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() :
mWebRTCImpl(nullptr),
mPeerConnection(nullptr),
mMute(MUTE_INITIAL),
- mAnswerReceived(false)
+ mAnswerReceived(false),
+ mPendingJobs(0)
{
}
@@ -809,6 +824,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 +839,10 @@ void LLWebRTCPeerConnectionImpl::init(LLWebRTCImpl * webrtc_impl)
mWebRTCImpl = webrtc_impl;
mPeerConnectionFactory = mWebRTCImpl->getPeerConnectionFactory();
}
+
void LLWebRTCPeerConnectionImpl::terminate()
{
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this]()
{
@@ -864,7 +885,9 @@ void LLWebRTCPeerConnectionImpl::terminate()
observer->OnPeerConnectionClosed();
}
}
+ mPendingJobs--;
});
+ mPeerConnectionFactory.release();
}
void LLWebRTCPeerConnectionImpl::setSignalingObserver(LLWebRTCSignalingObserver *observer) { mSignalingObserverList.emplace_back(observer); }
@@ -885,6 +908,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti
RTC_DCHECK(!mPeerConnection);
mAnswerReceived = false;
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this,options]()
{
@@ -906,6 +930,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 +949,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti
{
observer->OnRenegotiationNeeded();
}
+ mPendingJobs--;
return;
}
@@ -980,6 +1012,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions offerOptions;
mPeerConnection->CreateOffer(this, offerOptions);
+ mPendingJobs--;
});
return true;
@@ -1022,6 +1055,7 @@ void LLWebRTCPeerConnectionImpl::AnswerAvailable(const std::string &sdp)
{
RTC_LOG(LS_INFO) << __FUNCTION__ << " Remote SDP: " << sdp;
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this, sdp]()
{
@@ -1031,6 +1065,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 +1088,7 @@ void LLWebRTCPeerConnectionImpl::setMute(bool mute)
mMute = new_state;
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this, force_reset, enable]()
{
@@ -1076,6 +1112,7 @@ void LLWebRTCPeerConnectionImpl::setMute(bool mute)
track->set_enabled(enable);
}
}
+ mPendingJobs--;
}
});
}
@@ -1097,6 +1134,7 @@ void LLWebRTCPeerConnectionImpl::resetMute()
void LLWebRTCPeerConnectionImpl::setReceiveVolume(float volume)
{
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this, volume]()
{
@@ -1115,11 +1153,13 @@ void LLWebRTCPeerConnectionImpl::setReceiveVolume(float volume)
}
}
}
+ mPendingJobs--;
});
}
void LLWebRTCPeerConnectionImpl::setSendVolume(float volume)
{
+ mPendingJobs++;
mWebRTCImpl->PostSignalingTask(
[this, volume]()
{
@@ -1130,6 +1170,7 @@ void LLWebRTCPeerConnectionImpl::setSendVolume(float volume)
track->GetSource()->SetVolume(volume*5.0);
}
}
+ mPendingJobs--;
});
}
@@ -1206,11 +1247,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 +1511,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--;
});
}
}