Skip to content

Commit 40a9fdb

Browse files
committed
#4652 webrtc crash when switching devices
1 parent 34dcaaa commit 40a9fdb

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

indra/llwebrtc/llwebrtc.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ void LLWebRTCImpl::workerDeployDevices()
484484
}
485485
}
486486

487-
mDeviceModule->StopPlayout();
488487
mDeviceModule->ForceStopRecording();
489488
#if WEBRTC_WIN
489+
mDeviceModule->StopPlayout();
490490
if (recordingDevice < 0)
491491
{
492492
mDeviceModule->SetRecordingDevice((webrtc::AudioDeviceModule::WindowsDeviceType)recordingDevice);
@@ -496,6 +496,8 @@ void LLWebRTCImpl::workerDeployDevices()
496496
mDeviceModule->SetRecordingDevice(recordingDevice);
497497
}
498498
#else
499+
// Calls own StopPlayout from AudioDeviceMac::HandleDeviceChange()
500+
// Don't call twice, StopPlayout's Finalize isn't thread safe
499501
mDeviceModule->SetRecordingDevice(recordingDevice);
500502
#endif
501503
mDeviceModule->InitMicrophone();
@@ -576,8 +578,22 @@ void LLWebRTCImpl::setCaptureDevice(const std::string &id)
576578
deployDevices();
577579
}
578580

579-
void LLWebRTCImpl::setRenderDevice(const std::string &id)
581+
void LLWebRTCImpl::setRenderDevice(const std::string &id, bool stop_playout)
580582
{
583+
#if !WEBRTC_WIN
584+
// Workaround for a macOS crash
585+
// Due to insecure StopPlayout call, can't call StopPlayout from
586+
// workerDeployDevices, nor can use ForceStopPlayout()
587+
// For now only call StopPlayout when switching devices from preferences
588+
if (stop_playout)
589+
{
590+
mWorkerThread->BlockingCall(
591+
[this]
592+
{
593+
mDeviceModule->StopPlayout();
594+
});
595+
}
596+
#endif
581597
mPlayoutDevice = id;
582598
deployDevices();
583599
}

indra/llwebrtc/llwebrtc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class LLWebRTCDeviceInterface
149149

150150
// set the capture and render devices using the unique identifier for the device
151151
virtual void setCaptureDevice(const std::string& id) = 0;
152-
virtual void setRenderDevice(const std::string& id) = 0;
152+
virtual void setRenderDevice(const std::string& id, bool stop_playout) = 0;
153153
virtual void setDevices(const std::string& caprure_id, const std::string& render_id) = 0;
154154

155155
// Device observers for device change callbacks.

indra/llwebrtc/llwebrtc_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, public webrtc::AudioDeviceO
442442
void unsetDevicesObserver(LLWebRTCDevicesObserver *observer) override;
443443

444444
void setCaptureDevice(const std::string& id) override;
445-
void setRenderDevice(const std::string& id) override;
445+
void setRenderDevice(const std::string& id, bool stop_playout) override;
446446
void setDevices(const std::string& caprure_id, const std::string& render_id) override;
447447

448448
void setTuningMode(bool enable) override;

indra/newview/llvoicewebrtc.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,11 @@ void LLWebRTCVoiceClient::OnDevicesChangedImpl(const llwebrtc::LLWebRTCVoiceDevi
779779
}
780780
else if (update_render)
781781
{
782-
setRenderDevice(outputDevice);
782+
if (mWebRTCDeviceInterface)
783+
{
784+
LL_DEBUGS("Voice") << "new render device is " << outputDevice << LL_ENDL;
785+
mWebRTCDeviceInterface->setRenderDevice(outputDevice, false);
786+
}
783787
}
784788
else if (update_capture)
785789
{
@@ -812,7 +816,7 @@ void LLWebRTCVoiceClient::setRenderDevice(const std::string& name)
812816
if (mWebRTCDeviceInterface)
813817
{
814818
LL_DEBUGS("Voice") << "new render device is " << name << LL_ENDL;
815-
mWebRTCDeviceInterface->setRenderDevice(name);
819+
mWebRTCDeviceInterface->setRenderDevice(name, true);
816820
}
817821
}
818822

0 commit comments

Comments
 (0)