mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 19:36:45 +02:00
Merge pull request #16381 from amerhifi/amer-dev471-re
case Dev 471: HMD default audio behavior
This commit is contained in:
commit
42234b119f
11 changed files with 173 additions and 67 deletions
|
@ -258,13 +258,12 @@ Flickable {
|
||||||
Layout.preferredHeight: contentItem.height
|
Layout.preferredHeight: contentItem.height
|
||||||
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
||||||
interactive: false
|
interactive: false
|
||||||
spacing: simplifiedUI.margins.settings.spacingBetweenRadiobuttons
|
|
||||||
clip: true
|
clip: true
|
||||||
model: AudioScriptingInterface.devices.input
|
model: AudioScriptingInterface.devices.input
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: inputDeviceCheckbox.height
|
height: model.type != "hmd" ? inputDeviceCheckbox.height + simplifiedUI.margins.settings.spacingBetweenRadiobuttons : 0
|
||||||
|
visible: model.type != "hmd"
|
||||||
SimplifiedControls.RadioButton {
|
SimplifiedControls.RadioButton {
|
||||||
id: inputDeviceCheckbox
|
id: inputDeviceCheckbox
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
@ -354,13 +353,12 @@ Flickable {
|
||||||
Layout.preferredHeight: contentItem.height
|
Layout.preferredHeight: contentItem.height
|
||||||
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
||||||
interactive: false
|
interactive: false
|
||||||
spacing: simplifiedUI.margins.settings.spacingBetweenRadiobuttons
|
|
||||||
clip: true
|
clip: true
|
||||||
model: AudioScriptingInterface.devices.output
|
model: AudioScriptingInterface.devices.output
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: outputDeviceCheckbox.height
|
height: model.type != "hmd" ? outputDeviceCheckbox.height +simplifiedUI.margins.settings.spacingBetweenRadiobuttons : 0
|
||||||
|
visible: model.type != "hmd"
|
||||||
SimplifiedControls.RadioButton {
|
SimplifiedControls.RadioButton {
|
||||||
id: outputDeviceCheckbox
|
id: outputDeviceCheckbox
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
|
|
@ -259,13 +259,13 @@ Flickable {
|
||||||
Layout.preferredHeight: contentItem.height
|
Layout.preferredHeight: contentItem.height
|
||||||
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
||||||
interactive: false
|
interactive: false
|
||||||
spacing: simplifiedUI.margins.settings.spacingBetweenRadiobuttons
|
|
||||||
clip: true
|
clip: true
|
||||||
model: AudioScriptingInterface.devices.input
|
model: AudioScriptingInterface.devices.input
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: inputDeviceCheckbox.height
|
height: model.type != "desktop" ? inputDeviceCheckbox.height + simplifiedUI.margins.settings.spacingBetweenRadiobuttons : 0
|
||||||
|
visible: model.type != "desktop"
|
||||||
|
|
||||||
SimplifiedControls.RadioButton {
|
SimplifiedControls.RadioButton {
|
||||||
id: inputDeviceCheckbox
|
id: inputDeviceCheckbox
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
@ -355,13 +355,12 @@ Flickable {
|
||||||
Layout.preferredHeight: contentItem.height
|
Layout.preferredHeight: contentItem.height
|
||||||
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
||||||
interactive: false
|
interactive: false
|
||||||
spacing: simplifiedUI.margins.settings.spacingBetweenRadiobuttons
|
|
||||||
clip: true
|
clip: true
|
||||||
model: AudioScriptingInterface.devices.output
|
model: AudioScriptingInterface.devices.output
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: outputDeviceCheckbox.height
|
height: model.type != "desktop" ? outputDeviceCheckbox.height + simplifiedUI.margins.settings.spacingBetweenRadiobuttons : 0
|
||||||
|
visible: model.type != "desktop"
|
||||||
SimplifiedControls.RadioButton {
|
SimplifiedControls.RadioButton {
|
||||||
id: outputDeviceCheckbox
|
id: outputDeviceCheckbox
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
|
|
@ -44,7 +44,8 @@ enum AudioDeviceRole {
|
||||||
SelectedDesktopRole,
|
SelectedDesktopRole,
|
||||||
SelectedHMDRole,
|
SelectedHMDRole,
|
||||||
PeakRole,
|
PeakRole,
|
||||||
InfoRole
|
InfoRole,
|
||||||
|
TypeRole
|
||||||
};
|
};
|
||||||
|
|
||||||
QHash<int, QByteArray> AudioDeviceList::_roles {
|
QHash<int, QByteArray> AudioDeviceList::_roles {
|
||||||
|
@ -52,7 +53,8 @@ QHash<int, QByteArray> AudioDeviceList::_roles {
|
||||||
{ SelectedDesktopRole, "selectedDesktop" },
|
{ SelectedDesktopRole, "selectedDesktop" },
|
||||||
{ SelectedHMDRole, "selectedHMD" },
|
{ SelectedHMDRole, "selectedHMD" },
|
||||||
{ PeakRole, "peak" },
|
{ PeakRole, "peak" },
|
||||||
{ InfoRole, "info" }
|
{ InfoRole, "info" },
|
||||||
|
{ TypeRole, "type"}
|
||||||
};
|
};
|
||||||
|
|
||||||
static QString getTargetDevice(bool hmd, QAudio::Mode mode) {
|
static QString getTargetDevice(bool hmd, QAudio::Mode mode) {
|
||||||
|
@ -60,12 +62,6 @@ static QString getTargetDevice(bool hmd, QAudio::Mode mode) {
|
||||||
auto& setting = getSetting(hmd, mode);
|
auto& setting = getSetting(hmd, mode);
|
||||||
if (setting.isSet()) {
|
if (setting.isSet()) {
|
||||||
deviceName = setting.get();
|
deviceName = setting.get();
|
||||||
} else if (hmd) {
|
|
||||||
if (mode == QAudio::AudioInput) {
|
|
||||||
deviceName = qApp->getActiveDisplayPlugin()->getPreferredAudioInDevice();
|
|
||||||
} else { // if (_mode == QAudio::AudioOutput)
|
|
||||||
deviceName = qApp->getActiveDisplayPlugin()->getPreferredAudioOutDevice();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
deviceName = HifiAudioDeviceInfo::DEFAULT_DEVICE_NAME;
|
deviceName = HifiAudioDeviceInfo::DEFAULT_DEVICE_NAME;
|
||||||
}
|
}
|
||||||
|
@ -144,6 +140,8 @@ QVariant AudioDeviceList::data(const QModelIndex& index, int role) const {
|
||||||
return _devices.at(index.row())->selectedHMD;
|
return _devices.at(index.row())->selectedHMD;
|
||||||
} else if (role == InfoRole) {
|
} else if (role == InfoRole) {
|
||||||
return QVariant::fromValue<HifiAudioDeviceInfo>(_devices.at(index.row())->info);
|
return QVariant::fromValue<HifiAudioDeviceInfo>(_devices.at(index.row())->info);
|
||||||
|
} else if (role == TypeRole) {
|
||||||
|
return _devices.at(index.row())->type;
|
||||||
} else {
|
} else {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -166,8 +164,8 @@ void AudioDeviceList::resetDevice(bool contextIsHMD) {
|
||||||
QString deviceName = getTargetDevice(contextIsHMD, _mode);
|
QString deviceName = getTargetDevice(contextIsHMD, _mode);
|
||||||
// FIXME can't use blocking connections here, so we can't determine whether the switch succeeded or not
|
// FIXME can't use blocking connections here, so we can't determine whether the switch succeeded or not
|
||||||
// We need to have the AudioClient emit signals on switch success / failure
|
// We need to have the AudioClient emit signals on switch success / failure
|
||||||
QMetaObject::invokeMethod(client, "switchAudioDevice",
|
QMetaObject::invokeMethod(client, "switchAudioDevice",
|
||||||
Q_ARG(QAudio::Mode, _mode), Q_ARG(QString, deviceName));
|
Q_ARG(QAudio::Mode, _mode), Q_ARG(QString, deviceName), Q_ARG(bool, contextIsHMD));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
bool switchResult = false;
|
bool switchResult = false;
|
||||||
|
@ -265,13 +263,20 @@ void AudioDeviceList::onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices
|
||||||
bool hmdIsSelected = false;
|
bool hmdIsSelected = false;
|
||||||
bool desktopIsSelected = false;
|
bool desktopIsSelected = false;
|
||||||
|
|
||||||
foreach(const HifiAudioDeviceInfo& deviceInfo, devices) {
|
if (!_backupSelectedDesktopDeviceName.isEmpty() && !_backupSelectedHMDDeviceName.isEmpty()) {
|
||||||
for (bool isHMD : {false, true}) {
|
foreach(const HifiAudioDeviceInfo& deviceInfo, devices) {
|
||||||
auto& backupSelectedDeviceName = isHMD ? _backupSelectedHMDDeviceName : _backupSelectedDesktopDeviceName;
|
for (bool isHMD : {false, true}) {
|
||||||
if (deviceInfo.deviceName() == backupSelectedDeviceName) {
|
auto& backupSelectedDeviceName = isHMD ? _backupSelectedHMDDeviceName : _backupSelectedDesktopDeviceName;
|
||||||
HifiAudioDeviceInfo& selectedDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice;
|
if (deviceInfo.deviceName() == backupSelectedDeviceName) {
|
||||||
selectedDevice = deviceInfo;
|
if (isHMD && deviceInfo.getDeviceType() != HifiAudioDeviceInfo::desktop) {
|
||||||
backupSelectedDeviceName.clear();
|
_selectedHMDDevice= deviceInfo;
|
||||||
|
backupSelectedDeviceName.clear();
|
||||||
|
} else if (!isHMD && deviceInfo.getDeviceType() != HifiAudioDeviceInfo::hmd) {
|
||||||
|
_selectedDesktopDevice = deviceInfo;
|
||||||
|
backupSelectedDeviceName.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,10 +286,18 @@ void AudioDeviceList::onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices
|
||||||
device.info = deviceInfo;
|
device.info = deviceInfo;
|
||||||
|
|
||||||
if (deviceInfo.isDefault()) {
|
if (deviceInfo.isDefault()) {
|
||||||
if (deviceInfo.getMode() == QAudio::AudioInput) {
|
if (deviceInfo.getDeviceType() == HifiAudioDeviceInfo::desktop) {
|
||||||
device.display = "Computer's default microphone (recommended)";
|
if (deviceInfo.getMode() == QAudio::AudioInput) {
|
||||||
} else {
|
device.display = "Computer's default microphone (recommended)";
|
||||||
device.display = "Computer's default audio (recommended)";
|
} else {
|
||||||
|
device.display = "Computer's default audio (recommended)";
|
||||||
|
}
|
||||||
|
} else if (deviceInfo.getDeviceType() == HifiAudioDeviceInfo::hmd) {
|
||||||
|
if (deviceInfo.getMode() == QAudio::AudioInput) {
|
||||||
|
device.display = "Headset's default mic (recommended)";
|
||||||
|
} else {
|
||||||
|
device.display = "Headset's default audio (recommended)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
device.display = device.info.deviceName()
|
device.display = device.info.deviceName()
|
||||||
|
@ -292,6 +305,19 @@ void AudioDeviceList::onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices
|
||||||
.remove("Device")
|
.remove("Device")
|
||||||
.replace(" )", ")");
|
.replace(" )", ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (deviceInfo.getDeviceType()) {
|
||||||
|
case HifiAudioDeviceInfo::hmd:
|
||||||
|
device.type = "hmd";
|
||||||
|
break;
|
||||||
|
case HifiAudioDeviceInfo::desktop:
|
||||||
|
device.type = "desktop";
|
||||||
|
break;
|
||||||
|
case HifiAudioDeviceInfo::both:
|
||||||
|
device.type = "both";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (bool isHMD : {false, true}) {
|
for (bool isHMD : {false, true}) {
|
||||||
HifiAudioDeviceInfo& selectedDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice;
|
HifiAudioDeviceInfo& selectedDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice;
|
||||||
|
@ -302,8 +328,14 @@ void AudioDeviceList::onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//no selected device for context. fallback to saved
|
//no selected device for context. fallback to saved
|
||||||
const QString& savedDeviceName = isHMD ? _hmdSavedDeviceName : _desktopSavedDeviceName;
|
QString& savedDeviceName = isHMD ? _hmdSavedDeviceName : _desktopSavedDeviceName;
|
||||||
isSelected = (device.info.deviceName() == savedDeviceName);
|
|
||||||
|
if (device.info.deviceName() == savedDeviceName) {
|
||||||
|
if ((isHMD && device.info.getDeviceType() != HifiAudioDeviceInfo::desktop) ||
|
||||||
|
(!isHMD && device.info.getDeviceType() != HifiAudioDeviceInfo::hmd)) {
|
||||||
|
isSelected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
QString display;
|
QString display;
|
||||||
bool selectedDesktop { false };
|
bool selectedDesktop { false };
|
||||||
bool selectedHMD { false };
|
bool selectedHMD { false };
|
||||||
|
QString type;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AudioDeviceList : public QAbstractListModel {
|
class AudioDeviceList : public QAbstractListModel {
|
||||||
|
|
|
@ -6,6 +6,7 @@ setup_hifi_library(Network Multimedia ${PLATFORM_QT_COMPONENTS})
|
||||||
link_hifi_libraries(audio plugins)
|
link_hifi_libraries(audio plugins)
|
||||||
include_hifi_library_headers(shared)
|
include_hifi_library_headers(shared)
|
||||||
include_hifi_library_headers(networking)
|
include_hifi_library_headers(networking)
|
||||||
|
include_hifi_library_headers(gpu)
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID)
|
||||||
else ()
|
else ()
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <QtMultimedia/QAudioInput>
|
#include <QtMultimedia/QAudioInput>
|
||||||
#include <QtMultimedia/QAudioOutput>
|
#include <QtMultimedia/QAudioOutput>
|
||||||
|
|
||||||
|
#include <shared/QtHelpers.h>
|
||||||
#include <ThreadHelpers.h>
|
#include <ThreadHelpers.h>
|
||||||
#include <NodeList.h>
|
#include <NodeList.h>
|
||||||
#include <plugins/CodecPlugin.h>
|
#include <plugins/CodecPlugin.h>
|
||||||
|
@ -47,6 +48,7 @@
|
||||||
#include <SettingHandle.h>
|
#include <SettingHandle.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include <Transform.h>
|
#include <Transform.h>
|
||||||
|
#include <plugins/DisplayPlugin.h>
|
||||||
|
|
||||||
#include "AudioClientLogging.h"
|
#include "AudioClientLogging.h"
|
||||||
#include "AudioLogging.h"
|
#include "AudioLogging.h"
|
||||||
|
@ -81,20 +83,50 @@ Mutex _recordMutex;
|
||||||
|
|
||||||
HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode);
|
HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode);
|
||||||
|
|
||||||
|
static QString getHmdAudioDeviceName(QAudio::Mode mode) {
|
||||||
|
foreach(DisplayPluginPointer displayPlugin, PluginManager::getInstance()->getAllDisplayPlugins()) {
|
||||||
|
if (displayPlugin && displayPlugin->isHmd()) {
|
||||||
|
if (mode == QAudio::AudioInput) {
|
||||||
|
return displayPlugin->getPreferredAudioInDevice();
|
||||||
|
} else {
|
||||||
|
return displayPlugin->getPreferredAudioOutDevice();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
// thread-safe
|
// thread-safe
|
||||||
QList<HifiAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode) {
|
QList<HifiAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode) {
|
||||||
|
//get hmd device name prior to locking device mutex. in case of shutdown, this thread will be locked and audio client
|
||||||
|
//cannot properly shut down.
|
||||||
|
QString hmdDeviceName = getHmdAudioDeviceName(mode);
|
||||||
|
|
||||||
// NOTE: availableDevices() clobbers the Qt internal device list
|
// NOTE: availableDevices() clobbers the Qt internal device list
|
||||||
Lock lock(_deviceMutex);
|
Lock lock(_deviceMutex);
|
||||||
auto devices = QAudioDeviceInfo::availableDevices(mode);
|
auto devices = QAudioDeviceInfo::availableDevices(mode);
|
||||||
|
|
||||||
QList<HifiAudioDeviceInfo> newDevices;
|
QList<HifiAudioDeviceInfo> newDevices;
|
||||||
|
|
||||||
for (auto& device : devices) {
|
for (auto& device : devices) {
|
||||||
newDevices.push_back(HifiAudioDeviceInfo(device, false, mode));
|
newDevices.push_back(HifiAudioDeviceInfo(device, false, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
newDevices.push_front(defaultAudioDeviceForMode(mode));
|
newDevices.push_front(defaultAudioDeviceForMode(mode));
|
||||||
|
|
||||||
|
if (!hmdDeviceName.isNull() && !hmdDeviceName.isEmpty()) {
|
||||||
|
HifiAudioDeviceInfo hmdDevice;
|
||||||
|
foreach(auto device, newDevices) {
|
||||||
|
if (device.getDevice().deviceName() == hmdDeviceName) {
|
||||||
|
hmdDevice = HifiAudioDeviceInfo(device.getDevice(), true, mode, HifiAudioDeviceInfo::hmd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hmdDevice.getDevice().isNull()) {
|
||||||
|
newDevices.push_front(hmdDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
return newDevices;
|
return newDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +142,8 @@ void AudioClient::checkDevices() {
|
||||||
auto inputDevices = getAvailableDevices(QAudio::AudioInput);
|
auto inputDevices = getAvailableDevices(QAudio::AudioInput);
|
||||||
auto outputDevices = getAvailableDevices(QAudio::AudioOutput);
|
auto outputDevices = getAvailableDevices(QAudio::AudioOutput);
|
||||||
|
|
||||||
QMetaObject::invokeMethod(this, "changeDefault", Q_ARG(HifiAudioDeviceInfo, inputDevices.first()), Q_ARG(QAudio::Mode, QAudio::AudioInput));
|
checkDefaultChanges(inputDevices);
|
||||||
QMetaObject::invokeMethod(this, "changeDefault", Q_ARG(HifiAudioDeviceInfo, outputDevices.first()), Q_ARG(QAudio::Mode, QAudio::AudioOutput));
|
checkDefaultChanges(outputDevices);
|
||||||
|
|
||||||
Lock lock(_deviceMutex);
|
Lock lock(_deviceMutex);
|
||||||
if (inputDevices != _inputDevices) {
|
if (inputDevices != _inputDevices) {
|
||||||
|
@ -125,6 +157,14 @@ void AudioClient::checkDevices() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioClient::checkDefaultChanges(QList<HifiAudioDeviceInfo>& devices) {
|
||||||
|
foreach(auto device, devices) {
|
||||||
|
if (device.isDefault()) {
|
||||||
|
QMetaObject::invokeMethod(this, "changeDefault", Q_ARG(HifiAudioDeviceInfo, device), Q_ARG(QAudio::Mode, device.getMode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HifiAudioDeviceInfo AudioClient::getActiveAudioDevice(QAudio::Mode mode) const {
|
HifiAudioDeviceInfo AudioClient::getActiveAudioDevice(QAudio::Mode mode) const {
|
||||||
Lock lock(_deviceMutex);
|
Lock lock(_deviceMutex);
|
||||||
|
|
||||||
|
@ -386,12 +426,14 @@ void AudioClient::setAudioPaused(bool pause) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiAudioDeviceInfo getNamedAudioDeviceForMode(QAudio::Mode mode, const QString& deviceName) {
|
HifiAudioDeviceInfo getNamedAudioDeviceForMode(QAudio::Mode mode, const QString& deviceName, bool isHmd=false) {
|
||||||
HifiAudioDeviceInfo result;
|
HifiAudioDeviceInfo result;
|
||||||
foreach (HifiAudioDeviceInfo audioDevice, getAvailableDevices(mode)) {
|
foreach (HifiAudioDeviceInfo audioDevice, getAvailableDevices(mode)) {
|
||||||
if (audioDevice.deviceName().trimmed() == deviceName.trimmed()) {
|
if (audioDevice.deviceName().trimmed() == deviceName.trimmed()) {
|
||||||
result = audioDevice;
|
if ((!isHmd && audioDevice.getDeviceType() != HifiAudioDeviceInfo::hmd) || (isHmd && audioDevice.getDeviceType() != HifiAudioDeviceInfo::desktop)) {
|
||||||
break;
|
result = audioDevice;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -477,7 +519,7 @@ HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
||||||
// find a device in the list that matches the name we have and return it
|
// find a device in the list that matches the name we have and return it
|
||||||
foreach(QAudioDeviceInfo audioDevice, devices){
|
foreach(QAudioDeviceInfo audioDevice, devices){
|
||||||
if (audioDevice.deviceName() == CFStringGetCStringPtr(deviceName, kCFStringEncodingMacRoman)) {
|
if (audioDevice.deviceName() == CFStringGetCStringPtr(deviceName, kCFStringEncodingMacRoman)) {
|
||||||
return HifiAudioDeviceInfo(audioDevice, true, mode);
|
return HifiAudioDeviceInfo(audioDevice, true, mode, HifiAudioDeviceInfo::desktop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -532,7 +574,7 @@ HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
||||||
HifiAudioDeviceInfo foundDevice;
|
HifiAudioDeviceInfo foundDevice;
|
||||||
foreach(QAudioDeviceInfo audioDevice, devices) {
|
foreach(QAudioDeviceInfo audioDevice, devices) {
|
||||||
if (audioDevice.deviceName().trimmed() == deviceName.trimmed()) {
|
if (audioDevice.deviceName().trimmed() == deviceName.trimmed()) {
|
||||||
foundDevice=HifiAudioDeviceInfo(audioDevice,true,mode);
|
foundDevice = HifiAudioDeviceInfo(audioDevice, true, mode, HifiAudioDeviceInfo::desktop);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -558,8 +600,8 @@ HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// fallback for failed lookup is the default device
|
// fallback for failed lookup is the default device
|
||||||
return (mode == QAudio::AudioInput) ? HifiAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice(), true,mode) :
|
return (mode == QAudio::AudioInput) ? HifiAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice(), true, mode, HifiAudioDeviceInfo::desktop) :
|
||||||
HifiAudioDeviceInfo(QAudioDeviceInfo::defaultOutputDevice(), true, mode);
|
HifiAudioDeviceInfo(QAudioDeviceInfo::defaultOutputDevice(), true, mode, HifiAudioDeviceInfo::desktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioClient::getNamedAudioDeviceForModeExists(QAudio::Mode mode, const QString& deviceName) {
|
bool AudioClient::getNamedAudioDeviceForModeExists(QAudio::Mode mode, const QString& deviceName) {
|
||||||
|
@ -763,6 +805,7 @@ void AudioClient::stop() {
|
||||||
// Destruction of the pointers will occur when the parent object (this) is destroyed)
|
// Destruction of the pointers will occur when the parent object (this) is destroyed)
|
||||||
{
|
{
|
||||||
Lock lock(_checkDevicesMutex);
|
Lock lock(_checkDevicesMutex);
|
||||||
|
_checkDevicesTimer->stop();
|
||||||
_checkDevicesTimer = nullptr;
|
_checkDevicesTimer = nullptr;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -948,13 +991,18 @@ void AudioClient::selectAudioFormat(const QString& selectedCodecName) {
|
||||||
|
|
||||||
void AudioClient::changeDefault(HifiAudioDeviceInfo newDefault, QAudio::Mode mode) {
|
void AudioClient::changeDefault(HifiAudioDeviceInfo newDefault, QAudio::Mode mode) {
|
||||||
HifiAudioDeviceInfo currentDevice = mode == QAudio::AudioInput ? _inputDeviceInfo : _outputDeviceInfo;
|
HifiAudioDeviceInfo currentDevice = mode == QAudio::AudioInput ? _inputDeviceInfo : _outputDeviceInfo;
|
||||||
if (currentDevice.isDefault() && currentDevice.getDevice() != newDefault.getDevice()) {
|
if (currentDevice.isDefault() && currentDevice.getDeviceType() == newDefault.getDeviceType() && currentDevice.getDevice() != newDefault.getDevice()) {
|
||||||
switchAudioDevice(mode, newDefault);
|
switchAudioDevice(mode, newDefault);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioClient::switchAudioDevice(QAudio::Mode mode, const HifiAudioDeviceInfo& deviceInfo) {
|
bool AudioClient::switchAudioDevice(QAudio::Mode mode, const HifiAudioDeviceInfo& deviceInfo) {
|
||||||
auto device = deviceInfo;
|
auto device = deviceInfo;
|
||||||
|
if (deviceInfo.getDevice().isNull()) {
|
||||||
|
qCDebug(audioclient) << __FUNCTION__ << " switching to null device :"
|
||||||
|
<< deviceInfo.deviceName() << " : " << deviceInfo.getDevice().deviceName();
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == QAudio::AudioInput) {
|
if (mode == QAudio::AudioInput) {
|
||||||
return switchInputToAudioDevice(device);
|
return switchInputToAudioDevice(device);
|
||||||
} else {
|
} else {
|
||||||
|
@ -962,8 +1010,8 @@ bool AudioClient::switchAudioDevice(QAudio::Mode mode, const HifiAudioDeviceInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioClient::switchAudioDevice(QAudio::Mode mode, const QString& deviceName) {
|
bool AudioClient::switchAudioDevice(QAudio::Mode mode, const QString& deviceName, bool isHmd) {
|
||||||
return switchAudioDevice(mode, getNamedAudioDeviceForMode(mode, deviceName));
|
return switchAudioDevice(mode, getNamedAudioDeviceForMode(mode, deviceName, isHmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::configureReverb() {
|
void AudioClient::configureReverb() {
|
||||||
|
@ -1771,7 +1819,8 @@ void AudioClient::outputFormatChanged() {
|
||||||
bool AudioClient::switchInputToAudioDevice(const HifiAudioDeviceInfo inputDeviceInfo, bool isShutdownRequest) {
|
bool AudioClient::switchInputToAudioDevice(const HifiAudioDeviceInfo inputDeviceInfo, bool isShutdownRequest) {
|
||||||
Q_ASSERT_X(QThread::currentThread() == thread(), Q_FUNC_INFO, "Function invoked on wrong thread");
|
Q_ASSERT_X(QThread::currentThread() == thread(), Q_FUNC_INFO, "Function invoked on wrong thread");
|
||||||
|
|
||||||
qCDebug(audioclient) << __FUNCTION__ << "inputDeviceInfo: [" << _inputDeviceInfo.deviceName() <<"----"<<inputDeviceInfo.getDevice().deviceName() << "]";
|
qCDebug(audioclient) << __FUNCTION__ << "_inputDeviceInfo: [" << _inputDeviceInfo.deviceName() << ":" << _inputDeviceInfo.getDevice().deviceName()
|
||||||
|
<< "-- inputDeviceInfo:" << inputDeviceInfo.deviceName() << ":" << inputDeviceInfo.getDevice().deviceName() << "]";
|
||||||
bool supportedFormat = false;
|
bool supportedFormat = false;
|
||||||
|
|
||||||
// NOTE: device start() uses the Qt internal device list
|
// NOTE: device start() uses the Qt internal device list
|
||||||
|
@ -1823,8 +1872,9 @@ bool AudioClient::switchInputToAudioDevice(const HifiAudioDeviceInfo inputDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputDeviceInfo.getDevice().isNull()) {
|
if (!inputDeviceInfo.getDevice().isNull()) {
|
||||||
qCDebug(audioclient) << "The audio input device " << inputDeviceInfo.deviceName() << "is available.";
|
qCDebug(audioclient) << "The audio input device" << inputDeviceInfo.deviceName() << ":" << inputDeviceInfo.getDevice().deviceName() << "is available.";
|
||||||
|
|
||||||
|
//do not update UI that we're changing devices if default or same device
|
||||||
bool doEmit = _inputDeviceInfo.deviceName() != inputDeviceInfo.deviceName();
|
bool doEmit = _inputDeviceInfo.deviceName() != inputDeviceInfo.deviceName();
|
||||||
_inputDeviceInfo = inputDeviceInfo;
|
_inputDeviceInfo = inputDeviceInfo;
|
||||||
if (doEmit) {
|
if (doEmit) {
|
||||||
|
@ -1959,9 +2009,9 @@ void AudioClient::setHeadsetPluggedIn(bool pluggedIn) {
|
||||||
bool aecEnabled = enableAEC.get();
|
bool aecEnabled = enableAEC.get();
|
||||||
|
|
||||||
if ((pluggedIn || !aecEnabled) && _inputDeviceInfo.deviceName() != VOICE_RECOGNITION) {
|
if ((pluggedIn || !aecEnabled) && _inputDeviceInfo.deviceName() != VOICE_RECOGNITION) {
|
||||||
switchAudioDevice(QAudio::AudioInput, VOICE_RECOGNITION);
|
switchAudioDevice(QAudio::AudioInput, VOICE_RECOGNITION, false);
|
||||||
} else if (!pluggedIn && aecEnabled && _inputDeviceInfo.deviceName() != VOICE_COMMUNICATION) {
|
} else if (!pluggedIn && aecEnabled && _inputDeviceInfo.deviceName() != VOICE_COMMUNICATION) {
|
||||||
switchAudioDevice(QAudio::AudioInput, VOICE_COMMUNICATION);
|
switchAudioDevice(QAudio::AudioInput, VOICE_COMMUNICATION, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_isHeadsetPluggedIn = pluggedIn;
|
_isHeadsetPluggedIn = pluggedIn;
|
||||||
|
@ -2006,8 +2056,9 @@ void AudioClient::noteAwakening() {
|
||||||
|
|
||||||
bool AudioClient::switchOutputToAudioDevice(const HifiAudioDeviceInfo outputDeviceInfo, bool isShutdownRequest) {
|
bool AudioClient::switchOutputToAudioDevice(const HifiAudioDeviceInfo outputDeviceInfo, bool isShutdownRequest) {
|
||||||
Q_ASSERT_X(QThread::currentThread() == thread(), Q_FUNC_INFO, "Function invoked on wrong thread");
|
Q_ASSERT_X(QThread::currentThread() == thread(), Q_FUNC_INFO, "Function invoked on wrong thread");
|
||||||
|
|
||||||
qCDebug(audioclient) << "AudioClient::switchOutputToAudioDevice() outputDeviceInfo: [" << outputDeviceInfo.deviceName() << "]";
|
qCDebug(audioclient) << __FUNCTION__ << "_outputdeviceInfo: [" << _outputDeviceInfo.deviceName() << ":" << _outputDeviceInfo.getDevice().deviceName()
|
||||||
|
<< "-- outputDeviceInfo:" << outputDeviceInfo.deviceName() << ":" << outputDeviceInfo.getDevice().deviceName() << "]";
|
||||||
bool supportedFormat = false;
|
bool supportedFormat = false;
|
||||||
|
|
||||||
// NOTE: device start() uses the Qt internal device list
|
// NOTE: device start() uses the Qt internal device list
|
||||||
|
@ -2063,7 +2114,9 @@ bool AudioClient::switchOutputToAudioDevice(const HifiAudioDeviceInfo outputDevi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outputDeviceInfo.getDevice().isNull()) {
|
if (!outputDeviceInfo.getDevice().isNull()) {
|
||||||
qCDebug(audioclient) << "The audio output device " << outputDeviceInfo.deviceName() << "is available.";
|
qCDebug(audioclient) << "The audio output device" << outputDeviceInfo.deviceName() << ":" << outputDeviceInfo.getDevice().deviceName() << "is available.";
|
||||||
|
|
||||||
|
//do not update UI that we're changing devices if default or same device
|
||||||
bool doEmit = _outputDeviceInfo.deviceName() != outputDeviceInfo.deviceName();
|
bool doEmit = _outputDeviceInfo.deviceName() != outputDeviceInfo.deviceName();
|
||||||
_outputDeviceInfo = outputDeviceInfo;
|
_outputDeviceInfo = outputDeviceInfo;
|
||||||
if (doEmit) {
|
if (doEmit) {
|
||||||
|
|
|
@ -238,10 +238,11 @@ public slots:
|
||||||
|
|
||||||
bool shouldLoopbackInjectors() override { return _shouldEchoToServer; }
|
bool shouldLoopbackInjectors() override { return _shouldEchoToServer; }
|
||||||
Q_INVOKABLE void changeDefault(HifiAudioDeviceInfo newDefault, QAudio::Mode mode);
|
Q_INVOKABLE void changeDefault(HifiAudioDeviceInfo newDefault, QAudio::Mode mode);
|
||||||
|
void checkDefaultChanges(QList<HifiAudioDeviceInfo>& devices);
|
||||||
|
|
||||||
// calling with a null QAudioDevice will use the system default
|
// calling with a null QAudioDevice will use the system default
|
||||||
bool switchAudioDevice(QAudio::Mode mode, const HifiAudioDeviceInfo& deviceInfo = HifiAudioDeviceInfo());
|
bool switchAudioDevice(QAudio::Mode mode, const HifiAudioDeviceInfo& deviceInfo = HifiAudioDeviceInfo());
|
||||||
bool switchAudioDevice(QAudio::Mode mode, const QString& deviceName);
|
bool switchAudioDevice(QAudio::Mode mode, const QString& deviceName, bool isHmd);
|
||||||
// Qt opensles plugin is not able to detect when the headset is plugged in
|
// Qt opensles plugin is not able to detect when the headset is plugged in
|
||||||
void setHeadsetPluggedIn(bool pluggedIn);
|
void setHeadsetPluggedIn(bool pluggedIn);
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,14 @@ HifiAudioDeviceInfo& HifiAudioDeviceInfo::operator=(const HifiAudioDeviceInfo& o
|
||||||
_audioDeviceInfo = other.getDevice();
|
_audioDeviceInfo = other.getDevice();
|
||||||
_mode = other.getMode();
|
_mode = other.getMode();
|
||||||
_isDefault = other.isDefault();
|
_isDefault = other.isDefault();
|
||||||
|
_deviceType = other.getDeviceType();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool HifiAudioDeviceInfo::operator==(const HifiAudioDeviceInfo& rhs) const {
|
bool HifiAudioDeviceInfo::operator==(const HifiAudioDeviceInfo& rhs) const {
|
||||||
//Does the QAudioDeviceinfo match as well as is this the default device or
|
//Does the QAudioDeviceinfo match as well as is this the default device or
|
||||||
return getDevice() == rhs.getDevice() && isDefault() == rhs.isDefault();
|
return getDevice() == rhs.getDevice() && isDefault() == rhs.isDefault();
|
||||||
}
|
}
|
||||||
bool HifiAudioDeviceInfo::operator!=(const HifiAudioDeviceInfo& rhs) const {
|
bool HifiAudioDeviceInfo::operator!=(const HifiAudioDeviceInfo& rhs) const {
|
||||||
return getDevice() != rhs.getDevice() || isDefault() != rhs.isDefault();
|
return getDevice() != rhs.getDevice() || isDefault() != rhs.isDefault();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,19 +23,27 @@ class HifiAudioDeviceInfo : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum DeviceType {
|
||||||
|
desktop,
|
||||||
|
hmd,
|
||||||
|
both
|
||||||
|
};
|
||||||
|
|
||||||
HifiAudioDeviceInfo() : QObject() {}
|
HifiAudioDeviceInfo() : QObject() {}
|
||||||
HifiAudioDeviceInfo(const HifiAudioDeviceInfo &deviceInfo) : QObject(){
|
HifiAudioDeviceInfo(const HifiAudioDeviceInfo &deviceInfo) : QObject(){
|
||||||
_audioDeviceInfo = deviceInfo.getDevice();
|
_audioDeviceInfo = deviceInfo.getDevice();
|
||||||
_mode = deviceInfo.getMode();
|
_mode = deviceInfo.getMode();
|
||||||
_isDefault = deviceInfo.isDefault();
|
_isDefault = deviceInfo.isDefault();
|
||||||
|
_deviceType = deviceInfo.getDeviceType();
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiAudioDeviceInfo(QAudioDeviceInfo deviceInfo, bool isDefault, QAudio::Mode mode) :
|
HifiAudioDeviceInfo(QAudioDeviceInfo deviceInfo, bool isDefault, QAudio::Mode mode, DeviceType devType=both) :
|
||||||
_audioDeviceInfo(deviceInfo),
|
_audioDeviceInfo(deviceInfo),
|
||||||
_isDefault(isDefault),
|
_isDefault(isDefault),
|
||||||
_mode(mode){
|
_mode(mode),
|
||||||
|
_deviceType(devType){
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMode(QAudio::Mode mode) { _mode = mode; }
|
void setMode(QAudio::Mode mode) { _mode = mode; }
|
||||||
void setIsDefault() { _isDefault = true; }
|
void setIsDefault() { _isDefault = true; }
|
||||||
void setDevice(QAudioDeviceInfo devInfo);
|
void setDevice(QAudioDeviceInfo devInfo);
|
||||||
|
@ -52,7 +60,7 @@ public:
|
||||||
QAudioDeviceInfo getDevice() const { return _audioDeviceInfo; }
|
QAudioDeviceInfo getDevice() const { return _audioDeviceInfo; }
|
||||||
bool isDefault() const { return _isDefault; }
|
bool isDefault() const { return _isDefault; }
|
||||||
QAudio::Mode getMode() const { return _mode; }
|
QAudio::Mode getMode() const { return _mode; }
|
||||||
|
DeviceType getDeviceType() const { return _deviceType; }
|
||||||
HifiAudioDeviceInfo& operator=(const HifiAudioDeviceInfo& other);
|
HifiAudioDeviceInfo& operator=(const HifiAudioDeviceInfo& other);
|
||||||
bool operator==(const HifiAudioDeviceInfo& rhs) const;
|
bool operator==(const HifiAudioDeviceInfo& rhs) const;
|
||||||
bool operator!=(const HifiAudioDeviceInfo& rhs) const;
|
bool operator!=(const HifiAudioDeviceInfo& rhs) const;
|
||||||
|
@ -61,6 +69,7 @@ private:
|
||||||
QAudioDeviceInfo _audioDeviceInfo;
|
QAudioDeviceInfo _audioDeviceInfo;
|
||||||
bool _isDefault { false };
|
bool _isDefault { false };
|
||||||
QAudio::Mode _mode { QAudio::AudioInput };
|
QAudio::Mode _mode { QAudio::AudioInput };
|
||||||
|
DeviceType _deviceType{ both };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const QString DEFAULT_DEVICE_NAME;
|
static const QString DEFAULT_DEVICE_NAME;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QPluginLoader>
|
#include <QtCore/QPluginLoader>
|
||||||
|
#include <shared/QtHelpers.h>
|
||||||
|
|
||||||
//#define HIFI_PLUGINMANAGER_DEBUG
|
//#define HIFI_PLUGINMANAGER_DEBUG
|
||||||
#if defined(HIFI_PLUGINMANAGER_DEBUG)
|
#if defined(HIFI_PLUGINMANAGER_DEBUG)
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
|
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
#include <UserActivityLogger.h>
|
#include <UserActivityLogger.h>
|
||||||
|
#include <QThreadPool>
|
||||||
|
|
||||||
#include "RuntimePlugin.h"
|
#include "RuntimePlugin.h"
|
||||||
#include "CodecPlugin.h"
|
#include "CodecPlugin.h"
|
||||||
|
@ -221,7 +223,17 @@ const OculusPlatformPluginPointer PluginManager::getOculusPlatformPlugin() {
|
||||||
return oculusPlatformPlugin;
|
return oculusPlatformPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DisplayPluginList& PluginManager::getDisplayPlugins() {
|
DisplayPluginList PluginManager::getAllDisplayPlugins() {
|
||||||
|
if (thread() != QThread::currentThread()) {
|
||||||
|
DisplayPluginList list;
|
||||||
|
QMetaObject::invokeMethod(this, "getAllDisplayPlugins", Qt::BlockingQueuedConnection, Q_RETURN_ARG(DisplayPluginList, list));
|
||||||
|
return list;
|
||||||
|
} else {
|
||||||
|
return _displayPlugins;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const DisplayPluginList& PluginManager::getDisplayPlugins() {
|
||||||
static std::once_flag once;
|
static std::once_flag once;
|
||||||
static auto deviceAddedCallback = [](QString deviceName) {
|
static auto deviceAddedCallback = [](QString deviceName) {
|
||||||
qCDebug(plugins) << "Added device: " << deviceName;
|
qCDebug(plugins) << "Added device: " << deviceName;
|
||||||
|
|
|
@ -51,6 +51,7 @@ public:
|
||||||
|
|
||||||
using PluginFilter = std::function<bool(const QJsonObject&)>;
|
using PluginFilter = std::function<bool(const QJsonObject&)>;
|
||||||
void setPluginFilter(PluginFilter pluginFilter) { _pluginFilter = pluginFilter; }
|
void setPluginFilter(PluginFilter pluginFilter) { _pluginFilter = pluginFilter; }
|
||||||
|
Q_INVOKABLE DisplayPluginList getAllDisplayPlugins();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void inputDeviceRunningChanged(const QString& pluginName, bool isRunning, const QStringList& runningDevices);
|
void inputDeviceRunningChanged(const QString& pluginName, bool isRunning, const QStringList& runningDevices);
|
||||||
|
|
Loading…
Reference in a new issue