mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 16:23:17 +02:00
Merge pull request #16421 from amerhifi/dev-2571new
case DEV-2771: Audio client shutdown lock
This commit is contained in:
commit
de5570ced8
7 changed files with 103 additions and 61 deletions
|
@ -375,14 +375,14 @@ Rectangle {
|
||||||
x: margins.paddings
|
x: margins.paddings
|
||||||
interactive: false;
|
interactive: false;
|
||||||
height: contentHeight;
|
height: contentHeight;
|
||||||
spacing: 4;
|
|
||||||
clip: true;
|
clip: true;
|
||||||
model: AudioScriptingInterface.devices.input;
|
model: AudioScriptingInterface.devices.input;
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
width: rightMostInputLevelPos - margins.paddings*2
|
width: rightMostInputLevelPos - margins.paddings*2
|
||||||
height: margins.sizeCheckBox > checkBoxInput.implicitHeight ?
|
height: ((type != "hmd" && bar.currentIndex === 0) || (type != "desktop" && bar.currentIndex === 1)) ?
|
||||||
margins.sizeCheckBox : checkBoxInput.implicitHeight
|
(margins.sizeCheckBox > checkBoxInput.implicitHeight ? margins.sizeCheckBox + 4 : checkBoxInput.implicitHeight + 4) : 0
|
||||||
|
visible: (type != "hmd" && bar.currentIndex === 0) || (type != "desktop" && bar.currentIndex === 1)
|
||||||
AudioControls.CheckBox {
|
AudioControls.CheckBox {
|
||||||
id: checkBoxInput
|
id: checkBoxInput
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
@ -470,13 +470,13 @@ Rectangle {
|
||||||
height: contentHeight;
|
height: contentHeight;
|
||||||
anchors.top: outputDeviceHeader.bottom;
|
anchors.top: outputDeviceHeader.bottom;
|
||||||
anchors.topMargin: 10;
|
anchors.topMargin: 10;
|
||||||
spacing: 4;
|
|
||||||
clip: true;
|
clip: true;
|
||||||
model: AudioScriptingInterface.devices.output;
|
model: AudioScriptingInterface.devices.output;
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
width: rightMostInputLevelPos
|
width: rightMostInputLevelPos
|
||||||
height: margins.sizeCheckBox > checkBoxOutput.implicitHeight ?
|
height: ((type != "hmd" && bar.currentIndex === 0) || (type != "desktop" && bar.currentIndex === 1)) ?
|
||||||
margins.sizeCheckBox : checkBoxOutput.implicitHeight
|
(margins.sizeCheckBox > checkBoxOutput.implicitHeight ? margins.sizeCheckBox + 4 : checkBoxOutput.implicitHeight + 4) : 0
|
||||||
|
visible: (type != "hmd" && bar.currentIndex === 0) || (type != "desktop" && bar.currentIndex === 1)
|
||||||
|
|
||||||
AudioControls.CheckBox {
|
AudioControls.CheckBox {
|
||||||
id: checkBoxOutput
|
id: checkBoxOutput
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <shared/QtHelpers.h>
|
#include <shared/QtHelpers.h>
|
||||||
|
#include <plugins/PluginManager.h>
|
||||||
#include <plugins/DisplayPlugin.h>
|
#include <plugins/DisplayPlugin.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
@ -68,6 +69,27 @@ static QString getTargetDevice(bool hmd, QAudio::Mode mode) {
|
||||||
return deviceName;
|
return deviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void checkHmdDefaultsChange(QAudio::Mode mode) {
|
||||||
|
QString name;
|
||||||
|
foreach(DisplayPluginPointer displayPlugin, PluginManager::getInstance()->getAllDisplayPlugins()) {
|
||||||
|
if (displayPlugin && displayPlugin->isHmd()) {
|
||||||
|
if (mode == QAudio::AudioInput) {
|
||||||
|
name = displayPlugin->getPreferredAudioInDevice();
|
||||||
|
} else {
|
||||||
|
name = displayPlugin->getPreferredAudioOutDevice();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name.isEmpty()) {
|
||||||
|
auto client = DependencyManager::get<AudioClient>().data();
|
||||||
|
QMetaObject::invokeMethod(client, "setHmdAudioName",
|
||||||
|
Q_ARG(QAudio::Mode, mode),
|
||||||
|
Q_ARG(const QString&, name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Qt::ItemFlags AudioDeviceList::_flags { Qt::ItemIsSelectable | Qt::ItemIsEnabled };
|
Qt::ItemFlags AudioDeviceList::_flags { Qt::ItemIsSelectable | Qt::ItemIsEnabled };
|
||||||
|
|
||||||
AudioDeviceList::AudioDeviceList(QAudio::Mode mode) : _mode(mode) {
|
AudioDeviceList::AudioDeviceList(QAudio::Mode mode) : _mode(mode) {
|
||||||
|
@ -256,13 +278,15 @@ std::shared_ptr<scripting::AudioDevice> getSimilarDevice(const QString& deviceNa
|
||||||
return devices[minDistanceIndex];
|
return devices[minDistanceIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDeviceList::onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices) {
|
|
||||||
|
void AudioDeviceList::onDevicesChanged(QAudio::Mode mode, const QList<HifiAudioDeviceInfo>& devices) {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
QList<std::shared_ptr<AudioDevice>> newDevices;
|
QList<std::shared_ptr<AudioDevice>> newDevices;
|
||||||
bool hmdIsSelected = false;
|
bool hmdIsSelected = false;
|
||||||
bool desktopIsSelected = false;
|
bool desktopIsSelected = false;
|
||||||
|
|
||||||
|
checkHmdDefaultsChange(mode);
|
||||||
if (!_backupSelectedDesktopDeviceName.isEmpty() && !_backupSelectedHMDDeviceName.isEmpty()) {
|
if (!_backupSelectedDesktopDeviceName.isEmpty() && !_backupSelectedHMDDeviceName.isEmpty()) {
|
||||||
foreach(const HifiAudioDeviceInfo& deviceInfo, devices) {
|
foreach(const HifiAudioDeviceInfo& deviceInfo, devices) {
|
||||||
for (bool isHMD : {false, true}) {
|
for (bool isHMD : {false, true}) {
|
||||||
|
@ -275,7 +299,6 @@ void AudioDeviceList::onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices
|
||||||
_selectedDesktopDevice = deviceInfo;
|
_selectedDesktopDevice = deviceInfo;
|
||||||
backupSelectedDeviceName.clear();
|
backupSelectedDeviceName.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -417,6 +440,9 @@ AudioDevices::AudioDevices(bool& contextIsHMD) : _contextIsHMD(contextIsHMD) {
|
||||||
connect(client, &AudioClient::deviceChanged, this, &AudioDevices::onDeviceChanged, Qt::QueuedConnection);
|
connect(client, &AudioClient::deviceChanged, this, &AudioDevices::onDeviceChanged, Qt::QueuedConnection);
|
||||||
connect(client, &AudioClient::devicesChanged, this, &AudioDevices::onDevicesChanged, Qt::QueuedConnection);
|
connect(client, &AudioClient::devicesChanged, this, &AudioDevices::onDevicesChanged, Qt::QueuedConnection);
|
||||||
connect(client, &AudioClient::peakValueListChanged, &_inputs, &AudioInputDeviceList::onPeakValueListChanged, Qt::QueuedConnection);
|
connect(client, &AudioClient::peakValueListChanged, &_inputs, &AudioInputDeviceList::onPeakValueListChanged, Qt::QueuedConnection);
|
||||||
|
|
||||||
|
checkHmdDefaultsChange(QAudio::AudioInput);
|
||||||
|
checkHmdDefaultsChange(QAudio::AudioOutput);
|
||||||
|
|
||||||
_inputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioInput), contextIsHMD);
|
_inputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioInput), contextIsHMD);
|
||||||
_outputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioOutput), contextIsHMD);
|
_outputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioOutput), contextIsHMD);
|
||||||
|
@ -425,9 +451,11 @@ AudioDevices::AudioDevices(bool& contextIsHMD) : _contextIsHMD(contextIsHMD) {
|
||||||
const QList<HifiAudioDeviceInfo>& devicesInput = client->getAudioDevices(QAudio::AudioInput);
|
const QList<HifiAudioDeviceInfo>& devicesInput = client->getAudioDevices(QAudio::AudioInput);
|
||||||
const QList<HifiAudioDeviceInfo>& devicesOutput = client->getAudioDevices(QAudio::AudioOutput);
|
const QList<HifiAudioDeviceInfo>& devicesOutput = client->getAudioDevices(QAudio::AudioOutput);
|
||||||
|
|
||||||
//setup devices
|
if (devicesInput.size() > 0 && devicesOutput.size() > 0) {
|
||||||
_inputs.onDevicesChanged(devicesInput);
|
//setup devices
|
||||||
_outputs.onDevicesChanged(devicesOutput);
|
_inputs.onDevicesChanged(QAudio::AudioInput, devicesInput);
|
||||||
|
_outputs.onDevicesChanged(QAudio::AudioOutput, devicesOutput);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioDevices::~AudioDevices() {}
|
AudioDevices::~AudioDevices() {}
|
||||||
|
@ -526,14 +554,14 @@ void AudioDevices::onDevicesChanged(QAudio::Mode mode, const QList<HifiAudioDevi
|
||||||
|
|
||||||
//set devices for both contexts
|
//set devices for both contexts
|
||||||
if (mode == QAudio::AudioInput) {
|
if (mode == QAudio::AudioInput) {
|
||||||
_inputs.onDevicesChanged(devices);
|
_inputs.onDevicesChanged(mode, devices);
|
||||||
|
|
||||||
static std::once_flag onceAfterInputDevicesChanged;
|
static std::once_flag onceAfterInputDevicesChanged;
|
||||||
std::call_once(onceAfterInputDevicesChanged, [&] { // we only want 'selectedDevicePlugged' signal to be handled after initial list of input devices was populated
|
std::call_once(onceAfterInputDevicesChanged, [&] { // we only want 'selectedDevicePlugged' signal to be handled after initial list of input devices was populated
|
||||||
connect(&_inputs, &AudioDeviceList::selectedDevicePlugged, this, &AudioDevices::chooseInputDevice);
|
connect(&_inputs, &AudioDeviceList::selectedDevicePlugged, this, &AudioDevices::chooseInputDevice);
|
||||||
});
|
});
|
||||||
} else { // if (mode == QAudio::AudioOutput)
|
} else { // if (mode == QAudio::AudioOutput)
|
||||||
_outputs.onDevicesChanged(devices);
|
_outputs.onDevicesChanged(mode, devices);
|
||||||
|
|
||||||
static std::once_flag onceAfterOutputDevicesChanged;
|
static std::once_flag onceAfterOutputDevicesChanged;
|
||||||
std::call_once(onceAfterOutputDevicesChanged, [&] { // we only want 'selectedDevicePlugged' signal to be handled after initial list of output devices was populated
|
std::call_once(onceAfterOutputDevicesChanged, [&] { // we only want 'selectedDevicePlugged' signal to be handled after initial list of output devices was populated
|
||||||
|
|
|
@ -58,7 +58,7 @@ signals:
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onDeviceChanged(const HifiAudioDeviceInfo& device, bool isHMD);
|
void onDeviceChanged(const HifiAudioDeviceInfo& device, bool isHMD);
|
||||||
void onDevicesChanged(const QList<HifiAudioDeviceInfo>& devices);
|
void onDevicesChanged(QAudio::Mode mode, const QList<HifiAudioDeviceInfo>& devices);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class AudioDevices;
|
friend class AudioDevices;
|
||||||
|
|
|
@ -6,7 +6,6 @@ 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 ()
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
#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"
|
||||||
|
@ -83,24 +82,32 @@ Mutex _recordMutex;
|
||||||
|
|
||||||
QString defaultAudioDeviceName(QAudio::Mode mode);
|
QString defaultAudioDeviceName(QAudio::Mode mode);
|
||||||
|
|
||||||
|
void AudioClient::setHmdAudioName(QAudio::Mode mode, const QString& name) {
|
||||||
|
QWriteLocker lock(&_hmdNameLock);
|
||||||
|
if (mode == QAudio::AudioInput) {
|
||||||
|
_hmdInputName = name;
|
||||||
|
} else {
|
||||||
|
_hmdOutputName = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// thread-safe
|
// thread-safe
|
||||||
QList<HifiAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode) {
|
QList<HifiAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode, const QString& hmdName) {
|
||||||
//get hmd device name prior to locking device mutex. in case of shutdown, this thread will be locked and audio client
|
//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.
|
//cannot properly shut down.
|
||||||
QString hmdDeviceName = QString();
|
|
||||||
QString defDeviceName = defaultAudioDeviceName(mode);
|
QString defDeviceName = defaultAudioDeviceName(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);
|
||||||
|
|
||||||
HifiAudioDeviceInfo defaultDesktopDevice;
|
HifiAudioDeviceInfo defaultDesktopDevice;
|
||||||
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));
|
||||||
if (device.deviceName() == defDeviceName.trimmed()) {
|
if (device.deviceName() == defDeviceName.trimmed()) {
|
||||||
defaultDesktopDevice = HifiAudioDeviceInfo(device, true, mode, HifiAudioDeviceInfo::desktop);
|
defaultDesktopDevice = HifiAudioDeviceInfo(device, true, mode, HifiAudioDeviceInfo::desktop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaultDesktopDevice.getDevice().isNull()) {
|
if (defaultDesktopDevice.getDevice().isNull()) {
|
||||||
|
@ -109,11 +116,11 @@ QList<HifiAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode) {
|
||||||
defaultDesktopDevice = HifiAudioDeviceInfo(devices.first(), true, mode, HifiAudioDeviceInfo::desktop);
|
defaultDesktopDevice = HifiAudioDeviceInfo(devices.first(), true, mode, HifiAudioDeviceInfo::desktop);
|
||||||
}
|
}
|
||||||
newDevices.push_front(defaultDesktopDevice);
|
newDevices.push_front(defaultDesktopDevice);
|
||||||
|
|
||||||
if (!hmdDeviceName.isNull() && !hmdDeviceName.isEmpty()) {
|
if (!hmdName.isNull()) {
|
||||||
HifiAudioDeviceInfo hmdDevice;
|
HifiAudioDeviceInfo hmdDevice;
|
||||||
foreach(auto device, newDevices) {
|
foreach(auto device, newDevices) {
|
||||||
if (device.getDevice().deviceName() == hmdDeviceName) {
|
if (device.getDevice().deviceName() == hmdName) {
|
||||||
hmdDevice = HifiAudioDeviceInfo(device.getDevice(), true, mode, HifiAudioDeviceInfo::hmd);
|
hmdDevice = HifiAudioDeviceInfo(device.getDevice(), true, mode, HifiAudioDeviceInfo::hmd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -135,9 +142,17 @@ void AudioClient::checkDevices() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto inputDevices = getAvailableDevices(QAudio::AudioInput);
|
QString hmdInputName;
|
||||||
auto outputDevices = getAvailableDevices(QAudio::AudioOutput);
|
QString hmdOutputName;
|
||||||
|
{
|
||||||
|
QReadLocker readLock(&_hmdNameLock);
|
||||||
|
hmdInputName = _hmdInputName;
|
||||||
|
hmdOutputName = _hmdOutputName;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto inputDevices = getAvailableDevices(QAudio::AudioInput, hmdInputName);
|
||||||
|
auto outputDevices = getAvailableDevices(QAudio::AudioOutput, hmdOutputName);
|
||||||
|
|
||||||
checkDefaultChanges(inputDevices);
|
checkDefaultChanges(inputDevices);
|
||||||
checkDefaultChanges(outputDevices);
|
checkDefaultChanges(outputDevices);
|
||||||
|
|
||||||
|
@ -320,10 +335,12 @@ AudioClient::AudioClient() {
|
||||||
|
|
||||||
connect(&_receivedAudioStream, &InboundAudioStream::mismatchedAudioCodec, this, &AudioClient::handleMismatchAudioFormat);
|
connect(&_receivedAudioStream, &InboundAudioStream::mismatchedAudioCodec, this, &AudioClient::handleMismatchAudioFormat);
|
||||||
|
|
||||||
// initialize wasapi; if getAvailableDevices is called from the CheckDevicesThread before this, it will crash
|
{
|
||||||
getAvailableDevices(QAudio::AudioInput);
|
QReadLocker readLock(&_hmdNameLock);
|
||||||
getAvailableDevices(QAudio::AudioOutput);
|
// initialize wasapi; if getAvailableDevices is called from the CheckDevicesThread before this, it will crash
|
||||||
|
getAvailableDevices(QAudio::AudioInput, _hmdInputName);
|
||||||
|
getAvailableDevices(QAudio::AudioOutput, _hmdOutputName);
|
||||||
|
}
|
||||||
// start a thread to detect any device changes
|
// start a thread to detect any device changes
|
||||||
_checkDevicesTimer = new QTimer(this);
|
_checkDevicesTimer = new QTimer(this);
|
||||||
const unsigned long DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000;
|
const unsigned long DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000;
|
||||||
|
@ -422,9 +439,9 @@ void AudioClient::setAudioPaused(bool pause) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiAudioDeviceInfo getNamedAudioDeviceForMode(QAudio::Mode mode, const QString& deviceName, bool isHmd=false) {
|
HifiAudioDeviceInfo getNamedAudioDeviceForMode(QAudio::Mode mode, const QString& deviceName, const QString& hmdName, bool isHmd=false) {
|
||||||
HifiAudioDeviceInfo result;
|
HifiAudioDeviceInfo result;
|
||||||
foreach (HifiAudioDeviceInfo audioDevice, getAvailableDevices(mode)) {
|
foreach (HifiAudioDeviceInfo audioDevice, getAvailableDevices(mode,hmdName)) {
|
||||||
if (audioDevice.deviceName().trimmed() == deviceName.trimmed()) {
|
if (audioDevice.deviceName().trimmed() == deviceName.trimmed()) {
|
||||||
if ((!isHmd && audioDevice.getDeviceType() != HifiAudioDeviceInfo::hmd) || (isHmd && audioDevice.getDeviceType() != HifiAudioDeviceInfo::desktop)) {
|
if ((!isHmd && audioDevice.getDeviceType() != HifiAudioDeviceInfo::hmd) || (isHmd && audioDevice.getDeviceType() != HifiAudioDeviceInfo::desktop)) {
|
||||||
result = audioDevice;
|
result = audioDevice;
|
||||||
|
@ -479,7 +496,7 @@ QString AudioClient::getWinDeviceName(wchar_t* guid) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode, const QString& hmdName) {
|
||||||
QString deviceName = defaultAudioDeviceName(mode);
|
QString deviceName = defaultAudioDeviceName(mode);
|
||||||
#if defined (Q_OS_ANDROID)
|
#if defined (Q_OS_ANDROID)
|
||||||
if (mode == QAudio::AudioInput) {
|
if (mode == QAudio::AudioInput) {
|
||||||
|
@ -495,7 +512,7 @@ HifiAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return getNamedAudioDeviceForMode(mode, deviceName);
|
return getNamedAudioDeviceForMode(mode, deviceName, hmdName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString defaultAudioDeviceName(QAudio::Mode mode) {
|
QString defaultAudioDeviceName(QAudio::Mode mode) {
|
||||||
|
@ -601,7 +618,9 @@ QString defaultAudioDeviceName(QAudio::Mode mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioClient::getNamedAudioDeviceForModeExists(QAudio::Mode mode, const QString& deviceName) {
|
bool AudioClient::getNamedAudioDeviceForModeExists(QAudio::Mode mode, const QString& deviceName) {
|
||||||
return (getNamedAudioDeviceForMode(mode, deviceName).deviceName() == deviceName);
|
QReadLocker readLock(&_hmdNameLock);
|
||||||
|
QString hmdName = mode == QAudio::AudioInput ? _hmdInputName : _hmdOutputName;
|
||||||
|
return (getNamedAudioDeviceForMode(mode, deviceName, hmdName).deviceName() == deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -763,24 +782,16 @@ void AudioClient::start() {
|
||||||
|
|
||||||
_desiredOutputFormat = _desiredInputFormat;
|
_desiredOutputFormat = _desiredInputFormat;
|
||||||
_desiredOutputFormat.setChannelCount(OUTPUT_CHANNEL_COUNT);
|
_desiredOutputFormat.setChannelCount(OUTPUT_CHANNEL_COUNT);
|
||||||
|
|
||||||
HifiAudioDeviceInfo inputDeviceInfo = defaultAudioDeviceForMode(QAudio::AudioInput);
|
QString inputName;
|
||||||
qCDebug(audioclient) << "The default audio input device is" << inputDeviceInfo.deviceName();
|
QString outputName;
|
||||||
bool inputFormatSupported = switchInputToAudioDevice(inputDeviceInfo);
|
{
|
||||||
|
QReadLocker readLock(&_hmdNameLock);
|
||||||
HifiAudioDeviceInfo outputDeviceInfo = defaultAudioDeviceForMode(QAudio::AudioOutput);
|
inputName = _hmdInputName;
|
||||||
qCDebug(audioclient) << "The default audio output device is" << outputDeviceInfo.deviceName();
|
outputName = _hmdOutputName;
|
||||||
bool outputFormatSupported = switchOutputToAudioDevice(outputDeviceInfo);
|
|
||||||
|
|
||||||
if (!inputFormatSupported) {
|
|
||||||
qCDebug(audioclient) << "Unable to set up audio input because of a problem with input format.";
|
|
||||||
qCDebug(audioclient) << "The closest format available is" << inputDeviceInfo.getDevice().nearestFormat(_desiredInputFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outputFormatSupported) {
|
|
||||||
qCDebug(audioclient) << "Unable to set up audio output because of a problem with output format.";
|
|
||||||
qCDebug(audioclient) << "The closest format available is" << outputDeviceInfo.getDevice().nearestFormat(_desiredOutputFormat);
|
|
||||||
}
|
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
connect(&_checkInputTimer, &QTimer::timeout, this, &AudioClient::checkInputTimeout);
|
connect(&_checkInputTimer, &QTimer::timeout, this, &AudioClient::checkInputTimeout);
|
||||||
_checkInputTimer.start(CHECK_INPUT_READS_MSECS);
|
_checkInputTimer.start(CHECK_INPUT_READS_MSECS);
|
||||||
|
@ -1007,7 +1018,12 @@ bool AudioClient::switchAudioDevice(QAudio::Mode mode, const HifiAudioDeviceInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioClient::switchAudioDevice(QAudio::Mode mode, const QString& deviceName, bool isHmd) {
|
bool AudioClient::switchAudioDevice(QAudio::Mode mode, const QString& deviceName, bool isHmd) {
|
||||||
return switchAudioDevice(mode, getNamedAudioDeviceForMode(mode, deviceName, isHmd));
|
QString hmdName;
|
||||||
|
{
|
||||||
|
QReadLocker readLock(&_hmdNameLock);
|
||||||
|
hmdName = mode == QAudio::AudioInput ? _hmdInputName : _hmdOutputName;
|
||||||
|
}
|
||||||
|
return switchAudioDevice(mode, getNamedAudioDeviceForMode(mode, deviceName, hmdName, isHmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::configureReverb() {
|
void AudioClient::configureReverb() {
|
||||||
|
|
|
@ -243,6 +243,7 @@ public slots:
|
||||||
// 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 isHmd);
|
bool switchAudioDevice(QAudio::Mode mode, const QString& deviceName, bool isHmd);
|
||||||
|
void setHmdAudioName(QAudio::Mode mode, const QString& name);
|
||||||
// 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);
|
||||||
|
|
||||||
|
@ -481,6 +482,9 @@ private:
|
||||||
QList<HifiAudioDeviceInfo> _inputDevices;
|
QList<HifiAudioDeviceInfo> _inputDevices;
|
||||||
QList<HifiAudioDeviceInfo> _outputDevices;
|
QList<HifiAudioDeviceInfo> _outputDevices;
|
||||||
|
|
||||||
|
QString _hmdInputName { QString() };
|
||||||
|
QString _hmdOutputName{ QString() };
|
||||||
|
|
||||||
AudioFileWav _audioFileWav;
|
AudioFileWav _audioFileWav;
|
||||||
|
|
||||||
bool _hasReceivedFirstPacket { false };
|
bool _hasReceivedFirstPacket { false };
|
||||||
|
@ -505,6 +509,7 @@ private:
|
||||||
|
|
||||||
AudioSolo _solo;
|
AudioSolo _solo;
|
||||||
|
|
||||||
|
QReadWriteLock _hmdNameLock;
|
||||||
Mutex _checkDevicesMutex;
|
Mutex _checkDevicesMutex;
|
||||||
QTimer* _checkDevicesTimer { nullptr };
|
QTimer* _checkDevicesTimer { nullptr };
|
||||||
Mutex _checkPeakValuesMutex;
|
Mutex _checkPeakValuesMutex;
|
||||||
|
|
|
@ -224,13 +224,7 @@ const OculusPlatformPluginPointer PluginManager::getOculusPlatformPlugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayPluginList PluginManager::getAllDisplayPlugins() {
|
DisplayPluginList PluginManager::getAllDisplayPlugins() {
|
||||||
if (thread() != QThread::currentThread()) {
|
return _displayPlugins;
|
||||||
DisplayPluginList list;
|
|
||||||
QMetaObject::invokeMethod(this, "getAllDisplayPlugins", Qt::BlockingQueuedConnection, Q_RETURN_ARG(DisplayPluginList, list));
|
|
||||||
return list;
|
|
||||||
} else {
|
|
||||||
return _displayPlugins;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const DisplayPluginList& PluginManager::getDisplayPlugins() {
|
const DisplayPluginList& PluginManager::getDisplayPlugins() {
|
||||||
|
|
Loading…
Reference in a new issue