From f846861f04fe8a5c755a12da45ba6e12e38a9360 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Thu, 2 Oct 2025 21:06:32 +0300 Subject: #4777 Fix webrtc crashing in worker threads on shutdown --- indra/llwebrtc/llwebrtc.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'indra/llwebrtc/llwebrtc.cpp') 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(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--; }); } } -- cgit v1.2.3 From d76d0c239cd02eefcab30f02fa2eb84eaf4f3cdc Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Tue, 7 Oct 2025 22:42:18 +0300 Subject: #4796 Preferences' mic volume slider had no effect. --- indra/llwebrtc/llwebrtc.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indra/llwebrtc/llwebrtc.cpp') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index cbf2dfd67e..2cf3f6bbf8 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -641,6 +641,13 @@ void LLWebRTCImpl::OnDevicesUpdated() void LLWebRTCImpl::setTuningMode(bool enable) { mTuningMode = enable; + if (!mTuningMode + && !mMute + && mPeerCustomProcessor + && mPeerCustomProcessor->getGain() != mGain) + { + mPeerCustomProcessor->setGain(mGain); + } mWorkerThread->PostTask( [this] { -- cgit v1.2.3 From 400351f3b8354686c58d78a6234e43d2c82ffd22 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Thu, 9 Oct 2025 23:59:43 +0300 Subject: #4777 Fix crash on missing factory --- indra/llwebrtc/llwebrtc.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indra/llwebrtc/llwebrtc.cpp') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index 2cf3f6bbf8..f93ad07c1f 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -914,6 +914,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()) { -- cgit v1.2.3 From 164912418ccfd8c7a8ee02443db18e5fce19c8c4 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Tue, 28 Oct 2025 10:03:25 -0700 Subject: Fix issue where mac was crashing during an attempt to unplug or replug microphone. (#4897) The mac audio device manager was being "helpful" by restarting playout and recording if the Default device was changed, assuming the application wouldn't care. However, we received an update of device change, and attempted to stop and start playout anyway, causing a conflict. The fix was simply to not deploy new devices when the device id didn't change. --- indra/llwebrtc/llwebrtc.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'indra/llwebrtc/llwebrtc.cpp') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index b9f126e511..161d8d7e91 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -572,14 +572,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. -- cgit v1.2.3