mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 00:47:33 +02:00
working on swapping default devices on system change
This commit is contained in:
parent
e689531410
commit
66725f5f1b
3 changed files with 28 additions and 4 deletions
|
@ -121,6 +121,8 @@ AudioDeviceList::~AudioDeviceList() {
|
|||
// store the selected device
|
||||
foreach(std::shared_ptr<AudioDevice> adevice, _devices) {
|
||||
if (adevice->selectedDesktop) {
|
||||
qDebug() << "AMER ----> " << adevice->info.getId();
|
||||
qDebug() << " AMER-------------> " << adevice->info.deviceName();
|
||||
settingDesktop.set(adevice->info.deviceName());
|
||||
}
|
||||
if (adevice->selectedHMD) {
|
||||
|
|
|
@ -119,6 +119,31 @@ void AudioClient::checkDevices() {
|
|||
auto inputDevices = getAvailableDevices(QAudio::AudioInput);
|
||||
auto outputDevices = getAvailableDevices(QAudio::AudioOutput);
|
||||
|
||||
{
|
||||
Lock lock(_deviceMutex);
|
||||
//is the current device the default selected device?
|
||||
if (_inputDeviceInfo.isDefault() && _inputDeviceInfo == _defaultInputDevice) {
|
||||
auto defInput = defaultAudioDeviceForMode(QAudio::AudioInput);
|
||||
|
||||
//Has the default device changed
|
||||
if (_defaultInputDevice.getDevice() != defInput.getDevice()) {
|
||||
qDebug() << "Changing Current Default device " << _defaultInputDevice.getAudioDeviceName();
|
||||
_defaultInputDevice.setDevice(defInput.getDevice());
|
||||
qDebug() << "NEW Default device " << _defaultInputDevice.getAudioDeviceName();
|
||||
QMetaObject::invokeMethod(this, "switchInputToAudioDevice", Qt::QueuedConnection, Q_ARG(HifiAudioDeviceInfo, _defaultInputDevice));
|
||||
}
|
||||
}
|
||||
|
||||
if (_outputDeviceInfo.isDefault() && _inputDeviceInfo == _defaultInputDevice) {
|
||||
auto defOutput = defaultAudioDeviceForMode(QAudio::AudioOutput);
|
||||
|
||||
if (_defaultOutputDevice.getDevice() != defOutput.getDevice()) {
|
||||
_defaultOutputDevice.setDevice(defOutput.getDevice());
|
||||
QMetaObject::invokeMethod(this, "switchOutputToAudioDevice", Qt::QueuedConnection, Q_ARG(HifiAudioDeviceInfo, _defaultOutputDevice));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//add the pseudo device to the list of devices
|
||||
inputDevices.push_front(_defaultInputDevice);
|
||||
outputDevices.push_front(_defaultOutputDevice);
|
||||
|
@ -342,19 +367,16 @@ AudioClient::AudioClient() :
|
|||
|
||||
connect(&_receivedAudioStream, &InboundAudioStream::mismatchedAudioCodec, this, &AudioClient::handleMismatchAudioFormat);
|
||||
|
||||
|
||||
_defaultOutputDevice = defaultAudioDeviceForMode(QAudio::AudioOutput);
|
||||
_defaultOutputDevice.setDeviceName("Default audio (recommended)");
|
||||
_defaultOutputDevice.setIsDefault(true);
|
||||
_defaultOutputDevice.setMode(QAudio::AudioOutput);
|
||||
|
||||
|
||||
_defaultInputDevice = defaultAudioDeviceForMode(QAudio::AudioInput);
|
||||
_defaultInputDevice.setDeviceName("Default microphone (recommended)");
|
||||
_defaultInputDevice.setIsDefault(true);
|
||||
_defaultInputDevice.setMode(QAudio::AudioInput);
|
||||
|
||||
|
||||
// initialize wasapi; if getAvailableDevices is called from the CheckDevicesThread before this, it will crash
|
||||
getAvailableDevices(QAudio::AudioInput);
|
||||
getAvailableDevices(QAudio::AudioOutput);
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
}
|
||||
void setDevice(QAudioDeviceInfo devInfo);
|
||||
void setId(QString name);
|
||||
|
||||
QString getAudioDeviceName() { return _audioDeviceInfo.deviceName(); }
|
||||
QString getId() const { return _uniqueId; }
|
||||
QAudioDeviceInfo getDevice() const { return _audioDeviceInfo; }
|
||||
QString deviceName() const { return _deviceName; }
|
||||
|
|
Loading…
Reference in a new issue