Skip to content

Commit dbe1835

Browse files
committed
#4652 Improve switching of webrtc devices
1 parent 4e2a966 commit dbe1835

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

indra/llwebrtc/llwebrtc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@ void LLWebRTCImpl::setRenderDevice(const std::string &id)
582582
deployDevices();
583583
}
584584

585+
void LLWebRTCImpl::setDevices(const std::string& capture_id, const std::string& render_id)
586+
{
587+
mRecordingDevice = capture_id;
588+
mPlayoutDevice = render_id;
589+
deployDevices();
590+
}
591+
585592
// updateDevices needs to happen on the worker thread.
586593
void LLWebRTCImpl::updateDevices()
587594
{

indra/llwebrtc/llwebrtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class LLWebRTCDeviceInterface
150150
// set the capture and render devices using the unique identifier for the device
151151
virtual void setCaptureDevice(const std::string& id) = 0;
152152
virtual void setRenderDevice(const std::string& id) = 0;
153+
virtual void setDevices(const std::string& caprure_id, const std::string& render_id) = 0;
153154

154155
// Device observers for device change callbacks.
155156
virtual void setDevicesObserver(LLWebRTCDevicesObserver *observer) = 0;

indra/llwebrtc/llwebrtc_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, public webrtc::AudioDeviceO
443443

444444
void setCaptureDevice(const std::string& id) override;
445445
void setRenderDevice(const std::string& id) override;
446+
void setDevices(const std::string& caprure_id, const std::string& render_id) override;
446447

447448
void setTuningMode(bool enable) override;
448449
float getTuningAudioLevel() override;

indra/newview/llvoicewebrtc.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ void LLWebRTCVoiceClient::setCaptureDevice(const std::string& name)
699699
{
700700
if (mWebRTCDeviceInterface)
701701
{
702+
LL_DEBUGS("Voice") << "new capture device is " << name << LL_ENDL;
702703
mWebRTCDeviceInterface->setCaptureDevice(name);
703704
}
704705
}
@@ -727,10 +728,15 @@ void LLWebRTCVoiceClient::OnDevicesChangedImpl(const llwebrtc::LLWebRTCVoiceDevi
727728
return;
728729
}
729730
LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
731+
732+
LL_DEBUGS("Voice") << "Reiniting " << LL_ENDL;
733+
730734
std::string inputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
731735
std::string outputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
732736

733737
LL_DEBUGS("Voice") << "Setting devices to-input: '" << inputDevice << "' output: '" << outputDevice << "'" << LL_ENDL;
738+
bool update_render = false;
739+
bool update_capture = false;
734740

735741
// only set the render device if the device list has changed.
736742
if (mRenderDevices.size() != render_devices.size() || !std::equal(mRenderDevices.begin(),
@@ -744,7 +750,7 @@ void LLWebRTCVoiceClient::OnDevicesChangedImpl(const llwebrtc::LLWebRTCVoiceDevi
744750
{
745751
addRenderDevice(LLVoiceDevice(device.mDisplayName, device.mID));
746752
}
747-
setRenderDevice(outputDevice);
753+
update_render = true;
748754
}
749755

750756
// only set the capture device if the device list has changed.
@@ -761,6 +767,22 @@ void LLWebRTCVoiceClient::OnDevicesChangedImpl(const llwebrtc::LLWebRTCVoiceDevi
761767

762768
addCaptureDevice(LLVoiceDevice(device.mDisplayName, device.mID));
763769
}
770+
update_capture = true;
771+
}
772+
773+
if (update_render && update_capture)
774+
{
775+
// Do both in one go to avoid multiple deployDevices calls.
776+
// And to avoid situation where workerDeployDevices has an
777+
// obsolete device id or list
778+
setDevices(inputDevice, outputDevice);
779+
}
780+
else if (update_render)
781+
{
782+
setRenderDevice(outputDevice);
783+
}
784+
else if (update_capture)
785+
{
764786
setCaptureDevice(inputDevice);
765787
}
766788

@@ -789,10 +811,20 @@ void LLWebRTCVoiceClient::setRenderDevice(const std::string& name)
789811
{
790812
if (mWebRTCDeviceInterface)
791813
{
814+
LL_DEBUGS("Voice") << "new render device is " << name << LL_ENDL;
792815
mWebRTCDeviceInterface->setRenderDevice(name);
793816
}
794817
}
795818

819+
void LLWebRTCVoiceClient::setDevices(const std::string& capture_name, const std::string& render_name)
820+
{
821+
if (mWebRTCDeviceInterface)
822+
{
823+
LL_DEBUGS("Voice") << "new capture device: " << capture_name << " New render device: " << render_name << LL_ENDL;
824+
mWebRTCDeviceInterface->setDevices(capture_name, render_name);
825+
}
826+
}
827+
796828
void LLWebRTCVoiceClient::tuningStart()
797829
{
798830
if (!mIsInTuningMode)

indra/newview/llvoicewebrtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class LLWebRTCVoiceClient : public LLSingleton<LLWebRTCVoiceClient>,
124124

125125
void setCaptureDevice(const std::string& name) override;
126126
void setRenderDevice(const std::string& name) override;
127+
void setDevices(const std::string& capture_name, const std::string& render_name);
127128

128129
LLVoiceDeviceList& getCaptureDevices() override;
129130
LLVoiceDeviceList& getRenderDevices() override;

0 commit comments

Comments
 (0)