Handle 'device changed' callback

master
Roxie Linden 2024-02-03 22:02:48 -08:00
parent fd077d8a9b
commit 73b00bfe94
5 changed files with 55 additions and 11 deletions

View File

@ -113,6 +113,7 @@ void LLWebRTCImpl::init()
mTuningDeviceModule->SetStereoRecording(true);
mTuningDeviceModule->SetStereoPlayout(true);
mTuningDeviceModule->EnableBuiltInAEC(false);
mTuningDeviceModule->SetAudioDeviceSink(this);
updateDevices();
});
@ -379,31 +380,42 @@ void LLWebRTCImpl::setRenderDevice(const std::string &id)
void LLWebRTCImpl::updateDevices()
{
int16_t renderDeviceCount = mTuningDeviceModule->PlayoutDevices();
int16_t renderDeviceCount = mTuningDeviceModule->PlayoutDevices();
int16_t currentRenderDeviceIndex = mTuningDeviceModule->GetPlayoutDevice();
LLWebRTCVoiceDeviceList renderDeviceList;
for (int16_t index = 0; index < renderDeviceCount; index++)
{
char name[webrtc::kAdmMaxDeviceNameSize];
char guid[webrtc::kAdmMaxGuidSize];
mTuningDeviceModule->PlayoutDeviceName(index, name, guid);
renderDeviceList.emplace_back(name, guid);
renderDeviceList.emplace_back(name, guid, index == currentRenderDeviceIndex);
}
int16_t captureDeviceCount = mTuningDeviceModule->RecordingDevices();
int16_t captureDeviceCount = mTuningDeviceModule->RecordingDevices();
int16_t currentCaptureDeviceIndex = mTuningDeviceModule->GetRecordingDevice();
LLWebRTCVoiceDeviceList captureDeviceList;
for (int16_t index = 0; index < captureDeviceCount; index++)
{
char name[webrtc::kAdmMaxDeviceNameSize];
char guid[webrtc::kAdmMaxGuidSize];
mTuningDeviceModule->RecordingDeviceName(index, name, guid);
captureDeviceList.emplace_back(name, guid);
captureDeviceList.emplace_back(name, guid, index == currentCaptureDeviceIndex);
}
for (auto &observer : mVoiceDevicesObserverList)
{
observer->OnDevicesChanged(renderDeviceList, captureDeviceList);
observer->OnDevicesChanged(renderDeviceList,
captureDeviceList);
}
}
void LLWebRTCImpl::OnDevicesUpdated()
{
updateDevices();
}
void LLWebRTCImpl::setTuningMode(bool enable)
{
mWorkerThread->BlockingCall(

View File

@ -56,11 +56,14 @@ class LLWebRTCVoiceDevice
{
public:
std::string display_name; // friendly value for the user
std::string id; // internal value for selection
std::string id; // internal value for selection
bool current; // current device
LLWebRTCVoiceDevice(const std::string &display_name, const std::string &id) :
LLWebRTCVoiceDevice(const std::string &display_name, const std::string &id, bool current) :
display_name(display_name),
id(id) {};
id(id),
current(current)
{};
};
typedef std::vector<LLWebRTCVoiceDevice> LLWebRTCVoiceDeviceList;

View File

@ -89,7 +89,7 @@ class LLAudioDeviceObserver : public webrtc::AudioDeviceDataObserver
float mMicrophoneEnergy;
};
class LLWebRTCImpl : public LLWebRTCDeviceInterface
class LLWebRTCImpl : public LLWebRTCDeviceInterface, public webrtc::AudioDeviceSink
{
public:
LLWebRTCImpl() :
@ -117,6 +117,11 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface
float getTuningAudioLevel() override;
float getPeerAudioLevel() override;
//
// AudioDeviceSink
//
void OnDevicesUpdated() override;
//
// Helpers
//

View File

@ -8,7 +8,7 @@
* ne
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* License as published by the Free Software Foundation
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
@ -689,16 +689,41 @@ void LLWebRTCVoiceClient::setDevicesListUpdated(bool state)
void LLWebRTCVoiceClient::OnDevicesChanged(const llwebrtc::LLWebRTCVoiceDeviceList &render_devices,
const llwebrtc::LLWebRTCVoiceDeviceList &capture_devices)
{
std::string inputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
std::string outputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
clearRenderDevices();
bool renderDeviceSet = false;
for (auto &device : render_devices)
{
addRenderDevice(LLVoiceDevice(device.display_name, device.id));
if (device.current && outputDevice == device.id)
{
setRenderDevice(outputDevice);
renderDeviceSet = true;
}
}
if (!renderDeviceSet)
{
setRenderDevice("Default");
}
clearCaptureDevices();
bool captureDeviceSet = false;
for (auto &device : capture_devices)
{
addCaptureDevice(LLVoiceDevice(device.display_name, device.id));
if (device.current && inputDevice == device.id)
{
setCaptureDevice(outputDevice);
captureDeviceSet = true;
}
}
if (!captureDeviceSet)
{
setCaptureDevice("Default");
}
setDevicesListUpdated(true);
}

View File

@ -102,7 +102,6 @@ public:
/// @name Devices
//@{
// This returns true when it's safe to bring up the "device settings" dialog in the prefs.
// i.e. when the daemon is running and connected, and the device lists are populated.
bool deviceSettingsAvailable() override;
bool deviceSettingsUpdated() override; //return if the list has been updated and never fetched, only to be called from the voicepanel.