mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 15:34:05 +02:00
adding hmd audio device info to deviceslist
changing locations one more merge working on the threading issue changing offices, working on qml simple qml filtering fixed spacing problem when item is removed
This commit is contained in:
parent
8f7f23480f
commit
c7e1fdaeac
10 changed files with 111 additions and 34 deletions
|
@ -258,13 +258,12 @@ Flickable {
|
|||
Layout.preferredHeight: contentItem.height
|
||||
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
||||
interactive: false
|
||||
spacing: simplifiedUI.margins.settings.spacingBetweenRadiobuttons
|
||||
clip: true
|
||||
model: AudioScriptingInterface.devices.input
|
||||
delegate: Item {
|
||||
width: parent.width
|
||||
height: inputDeviceCheckbox.height
|
||||
|
||||
width: parent.width
|
||||
height: model.type != "hmd" ? inputDeviceCheckbox.height + simplifiedUI.margins.settings.spacingBetweenRadiobuttons : 0
|
||||
visible: model.type != "hmd"
|
||||
SimplifiedControls.RadioButton {
|
||||
id: inputDeviceCheckbox
|
||||
anchors.left: parent.left
|
||||
|
@ -354,13 +353,12 @@ Flickable {
|
|||
Layout.preferredHeight: contentItem.height
|
||||
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
||||
interactive: false
|
||||
spacing: simplifiedUI.margins.settings.spacingBetweenRadiobuttons
|
||||
clip: true
|
||||
model: AudioScriptingInterface.devices.output
|
||||
delegate: Item {
|
||||
width: parent.width
|
||||
height: outputDeviceCheckbox.height
|
||||
|
||||
height: model.type != "hmd" ? outputDeviceCheckbox.height +simplifiedUI.margins.settings.spacingBetweenRadiobuttons : 0
|
||||
visible: model.type != "hmd"
|
||||
SimplifiedControls.RadioButton {
|
||||
id: outputDeviceCheckbox
|
||||
anchors.left: parent.left
|
||||
|
|
|
@ -259,13 +259,13 @@ Flickable {
|
|||
Layout.preferredHeight: contentItem.height
|
||||
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
||||
interactive: false
|
||||
spacing: simplifiedUI.margins.settings.spacingBetweenRadiobuttons
|
||||
clip: true
|
||||
model: AudioScriptingInterface.devices.input
|
||||
delegate: Item {
|
||||
width: parent.width
|
||||
height: inputDeviceCheckbox.height
|
||||
|
||||
width: parent.width
|
||||
height: model.type != "desktop" ? inputDeviceCheckbox.height + simplifiedUI.margins.settings.spacingBetweenRadiobuttons : 0
|
||||
visible: model.type != "desktop"
|
||||
|
||||
SimplifiedControls.RadioButton {
|
||||
id: inputDeviceCheckbox
|
||||
anchors.left: parent.left
|
||||
|
@ -355,13 +355,12 @@ Flickable {
|
|||
Layout.preferredHeight: contentItem.height
|
||||
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
|
||||
interactive: false
|
||||
spacing: simplifiedUI.margins.settings.spacingBetweenRadiobuttons
|
||||
clip: true
|
||||
model: AudioScriptingInterface.devices.output
|
||||
delegate: Item {
|
||||
width: parent.width
|
||||
height: outputDeviceCheckbox.height
|
||||
|
||||
height: model.type != "desktop" ? outputDeviceCheckbox.height + simplifiedUI.margins.settings.spacingBetweenRadiobuttons : 0
|
||||
visible: model.type != "desktop"
|
||||
SimplifiedControls.RadioButton {
|
||||
id: outputDeviceCheckbox
|
||||
anchors.left: parent.left
|
||||
|
|
|
@ -44,7 +44,8 @@ enum AudioDeviceRole {
|
|||
SelectedDesktopRole,
|
||||
SelectedHMDRole,
|
||||
PeakRole,
|
||||
InfoRole
|
||||
InfoRole,
|
||||
TypeRole
|
||||
};
|
||||
|
||||
QHash<int, QByteArray> AudioDeviceList::_roles {
|
||||
|
@ -52,7 +53,8 @@ QHash<int, QByteArray> AudioDeviceList::_roles {
|
|||
{ SelectedDesktopRole, "selectedDesktop" },
|
||||
{ SelectedHMDRole, "selectedHMD" },
|
||||
{ PeakRole, "peak" },
|
||||
{ InfoRole, "info" }
|
||||
{ InfoRole, "info" },
|
||||
{ TypeRole, "type"}
|
||||
};
|
||||
|
||||
static QString getTargetDevice(bool hmd, QAudio::Mode mode) {
|
||||
|
@ -144,6 +146,8 @@ QVariant AudioDeviceList::data(const QModelIndex& index, int role) const {
|
|||
return _devices.at(index.row())->selectedHMD;
|
||||
} else if (role == InfoRole) {
|
||||
return QVariant::fromValue<HifiAudioDeviceInfo>(_devices.at(index.row())->info);
|
||||
} else if (role == TypeRole) {
|
||||
return _devices.at(index.row())->type;
|
||||
} else {
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -281,10 +285,18 @@ void AudioDeviceList::onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices
|
|||
device.info = deviceInfo;
|
||||
|
||||
if (deviceInfo.isDefault()) {
|
||||
if (deviceInfo.getMode() == QAudio::AudioInput) {
|
||||
device.display = "Computer's default microphone (recommended)";
|
||||
} else {
|
||||
device.display = "Computer's default audio (recommended)";
|
||||
if (deviceInfo.getDeviceType() == HifiAudioDeviceInfo::desktop) {
|
||||
if (deviceInfo.getMode() == QAudio::AudioInput) {
|
||||
device.display = "Computer's default microphone (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 {
|
||||
device.display = device.info.deviceName()
|
||||
|
@ -292,6 +304,19 @@ void AudioDeviceList::onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices
|
|||
.remove("Device")
|
||||
.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}) {
|
||||
HifiAudioDeviceInfo& selectedDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice;
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
QString display;
|
||||
bool selectedDesktop { false };
|
||||
bool selectedHMD { false };
|
||||
QString type;
|
||||
};
|
||||
|
||||
class AudioDeviceList : public QAbstractListModel {
|
||||
|
|
|
@ -6,7 +6,7 @@ setup_hifi_library(Network Multimedia ${PLATFORM_QT_COMPONENTS})
|
|||
link_hifi_libraries(audio plugins)
|
||||
include_hifi_library_headers(shared)
|
||||
include_hifi_library_headers(networking)
|
||||
|
||||
include_hifi_library_headers(gpu)
|
||||
if (ANDROID)
|
||||
else ()
|
||||
target_webrtc()
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
#include <SettingHandle.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <Transform.h>
|
||||
|
||||
#include <plugins/DisplayPlugin.h>
|
||||
#include "AudioClientLogging.h"
|
||||
#include "AudioLogging.h"
|
||||
#include "AudioHelpers.h"
|
||||
|
@ -81,6 +81,21 @@ Mutex _recordMutex;
|
|||
|
||||
HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode);
|
||||
|
||||
#include <shared/QtHelpers.h>
|
||||
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
|
||||
QList<HifiAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode) {
|
||||
// NOTE: availableDevices() clobbers the Qt internal device list
|
||||
|
@ -88,13 +103,26 @@ QList<HifiAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode) {
|
|||
auto devices = QAudioDeviceInfo::availableDevices(mode);
|
||||
|
||||
QList<HifiAudioDeviceInfo> newDevices;
|
||||
|
||||
for (auto& device : devices) {
|
||||
newDevices.push_back(HifiAudioDeviceInfo(device, false, mode));
|
||||
}
|
||||
|
||||
newDevices.push_front(defaultAudioDeviceForMode(mode));
|
||||
|
||||
|
||||
QString hmdDeviceName = getHmdAudioDeviceName(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;
|
||||
}
|
||||
|
||||
|
@ -477,7 +505,7 @@ HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
|||
// find a device in the list that matches the name we have and return it
|
||||
foreach(QAudioDeviceInfo audioDevice, devices){
|
||||
if (audioDevice.deviceName() == CFStringGetCStringPtr(deviceName, kCFStringEncodingMacRoman)) {
|
||||
return HifiAudioDeviceInfo(audioDevice, true, mode);
|
||||
return HifiAudioDeviceInfo(audioDevice, true, mode, HifiAudioDeviceInfo::desktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -532,7 +560,7 @@ HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
|||
HifiAudioDeviceInfo foundDevice;
|
||||
foreach(QAudioDeviceInfo audioDevice, devices) {
|
||||
if (audioDevice.deviceName().trimmed() == deviceName.trimmed()) {
|
||||
foundDevice=HifiAudioDeviceInfo(audioDevice,true,mode);
|
||||
foundDevice=HifiAudioDeviceInfo(audioDevice,true,mode, HifiAudioDeviceInfo::desktop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -558,8 +586,8 @@ HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
|||
}
|
||||
#endif
|
||||
// fallback for failed lookup is the default device
|
||||
return (mode == QAudio::AudioInput) ? HifiAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice(), true,mode) :
|
||||
HifiAudioDeviceInfo(QAudioDeviceInfo::defaultOutputDevice(), true, mode);
|
||||
return (mode == QAudio::AudioInput) ? HifiAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice(), true,mode, HifiAudioDeviceInfo::desktop) :
|
||||
HifiAudioDeviceInfo(QAudioDeviceInfo::defaultOutputDevice(), true, mode, HifiAudioDeviceInfo::desktop);
|
||||
}
|
||||
|
||||
bool AudioClient::getNamedAudioDeviceForModeExists(QAudio::Mode mode, const QString& deviceName) {
|
||||
|
|
|
@ -22,6 +22,7 @@ HifiAudioDeviceInfo& HifiAudioDeviceInfo::operator=(const HifiAudioDeviceInfo& o
|
|||
_audioDeviceInfo = other.getDevice();
|
||||
_mode = other.getMode();
|
||||
_isDefault = other.isDefault();
|
||||
_deviceType = other.getDeviceType();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,19 +23,28 @@ class HifiAudioDeviceInfo : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum deviceType {
|
||||
desktop,
|
||||
hmd,
|
||||
both
|
||||
};
|
||||
|
||||
HifiAudioDeviceInfo() : QObject() {}
|
||||
HifiAudioDeviceInfo(const HifiAudioDeviceInfo &deviceInfo) : QObject(){
|
||||
_audioDeviceInfo = deviceInfo.getDevice();
|
||||
_mode = deviceInfo.getMode();
|
||||
_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),
|
||||
_isDefault(isDefault),
|
||||
_mode(mode){
|
||||
_mode(mode),
|
||||
_deviceType(devType){
|
||||
}
|
||||
|
||||
|
||||
void setMode(QAudio::Mode mode) { _mode = mode; }
|
||||
void setIsDefault() { _isDefault = true; }
|
||||
void setDevice(QAudioDeviceInfo devInfo);
|
||||
|
@ -52,15 +61,17 @@ public:
|
|||
QAudioDeviceInfo getDevice() const { return _audioDeviceInfo; }
|
||||
bool isDefault() const { return _isDefault; }
|
||||
QAudio::Mode getMode() const { return _mode; }
|
||||
|
||||
deviceType getDeviceType() const { return _deviceType; }
|
||||
HifiAudioDeviceInfo& operator=(const HifiAudioDeviceInfo& other);
|
||||
bool operator==(const HifiAudioDeviceInfo& rhs) const;
|
||||
bool operator!=(const HifiAudioDeviceInfo& rhs) const;
|
||||
|
||||
|
||||
private:
|
||||
QAudioDeviceInfo _audioDeviceInfo;
|
||||
bool _isDefault { false };
|
||||
QAudio::Mode _mode { QAudio::AudioInput };
|
||||
deviceType _deviceType{ both };
|
||||
|
||||
public:
|
||||
static const QString DEFAULT_DEVICE_NAME;
|
||||
|
|
|
@ -221,7 +221,21 @@ const OculusPlatformPluginPointer PluginManager::getOculusPlatformPlugin() {
|
|||
return oculusPlatformPlugin;
|
||||
}
|
||||
|
||||
const DisplayPluginList& PluginManager::getDisplayPlugins() {
|
||||
#include <shared/QtHelpers.h>
|
||||
#include <QThreadPool>
|
||||
|
||||
|
||||
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 auto deviceAddedCallback = [](QString deviceName) {
|
||||
qCDebug(plugins) << "Added device: " << deviceName;
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
|
||||
using PluginFilter = std::function<bool(const QJsonObject&)>;
|
||||
void setPluginFilter(PluginFilter pluginFilter) { _pluginFilter = pluginFilter; }
|
||||
|
||||
Q_INVOKABLE DisplayPluginList getAllDisplayPlugins();
|
||||
signals:
|
||||
void inputDeviceRunningChanged(const QString& pluginName, bool isRunning, const QStringList& runningDevices);
|
||||
|
||||
|
|
Loading…
Reference in a new issue