mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 02:42:19 +02:00
PR comments
This commit is contained in:
parent
b53968fd64
commit
97e96f7b67
6 changed files with 65 additions and 100 deletions
|
@ -97,3 +97,11 @@ bool HMDScriptingInterface::isMounted() const{
|
|||
auto displayPlugin = qApp->getActiveDisplayPlugin();
|
||||
return (displayPlugin->isHmd() && displayPlugin->isDisplayVisible());
|
||||
}
|
||||
|
||||
QString HMDScriptingInterface::preferredAudioInput() const {
|
||||
return qApp->getActiveDisplayPlugin()->getPreferredAudioInDevice();
|
||||
}
|
||||
|
||||
QString HMDScriptingInterface::preferredAudioOutput() const {
|
||||
return qApp->getActiveDisplayPlugin()->getPreferredAudioOutDevice();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
|
||||
Q_INVOKABLE glm::vec2 sphericalToOverlay(const glm::vec2 & sphericalPos) const;
|
||||
Q_INVOKABLE glm::vec2 overlayToSpherical(const glm::vec2 & overlayPos) const;
|
||||
Q_INVOKABLE QString preferredAudioInput() const;
|
||||
Q_INVOKABLE QString preferredAudioOutput() const;
|
||||
|
||||
public:
|
||||
HMDScriptingInterface();
|
||||
|
|
|
@ -175,6 +175,50 @@ int numDestinationSamplesRequired(const QAudioFormat& sourceFormat, const QAudio
|
|||
return (numSourceSamples * ratio) + 0.5f;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QString friendlyNameForAudioDevice(IMMDevice* pEndpoint) {
|
||||
QString deviceName;
|
||||
IPropertyStore* pPropertyStore;
|
||||
pEndpoint->OpenPropertyStore(STGM_READ, &pPropertyStore);
|
||||
pEndpoint->Release();
|
||||
pEndpoint = NULL;
|
||||
PROPVARIANT pv;
|
||||
PropVariantInit(&pv);
|
||||
HRESULT hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &pv);
|
||||
pPropertyStore->Release();
|
||||
pPropertyStore = NULL;
|
||||
deviceName = QString::fromWCharArray((wchar_t*)pv.pwszVal);
|
||||
if (!IsWindows8OrGreater()) {
|
||||
// Windows 7 provides only the 31 first characters of the device name.
|
||||
const DWORD QT_WIN7_MAX_AUDIO_DEVICENAME_LEN = 31;
|
||||
deviceName = deviceName.left(QT_WIN7_MAX_AUDIO_DEVICENAME_LEN);
|
||||
}
|
||||
PropVariantClear(&pv);
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
QString AudioClient::friendlyNameForAudioDevice(wchar_t* guid) {
|
||||
QString deviceName;
|
||||
HRESULT hr = S_OK;
|
||||
CoInitialize(NULL);
|
||||
IMMDeviceEnumerator* pMMDeviceEnumerator = NULL;
|
||||
CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pMMDeviceEnumerator);
|
||||
IMMDevice* pEndpoint;
|
||||
hr = pMMDeviceEnumerator->GetDevice(guid, &pEndpoint);
|
||||
if (hr == E_NOTFOUND) {
|
||||
printf("Audio Error: device not found\n");
|
||||
deviceName = QString("NONE");
|
||||
} else {
|
||||
deviceName = ::friendlyNameForAudioDevice(pEndpoint);
|
||||
}
|
||||
pMMDeviceEnumerator->Release();
|
||||
pMMDeviceEnumerator = NULL;
|
||||
CoUninitialize();
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
QAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
||||
#ifdef __APPLE__
|
||||
if (QAudioDeviceInfo::availableDevices(mode).size() > 1) {
|
||||
|
@ -248,23 +292,7 @@ QAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
|||
printf("Audio Error: device not found\n");
|
||||
deviceName = QString("NONE");
|
||||
} else {
|
||||
IPropertyStore* pPropertyStore;
|
||||
pEndpoint->OpenPropertyStore(STGM_READ, &pPropertyStore);
|
||||
pEndpoint->Release();
|
||||
pEndpoint = NULL;
|
||||
PROPVARIANT pv;
|
||||
PropVariantInit(&pv);
|
||||
hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &pv);
|
||||
pPropertyStore->Release();
|
||||
pPropertyStore = NULL;
|
||||
deviceName = QString::fromWCharArray((wchar_t*)pv.pwszVal);
|
||||
if (!IsWindows8OrGreater()) {
|
||||
// Windows 7 provides only the 31 first characters of the device name.
|
||||
const DWORD QT_WIN7_MAX_AUDIO_DEVICENAME_LEN = 31;
|
||||
deviceName = deviceName.left(QT_WIN7_MAX_AUDIO_DEVICENAME_LEN);
|
||||
}
|
||||
qCDebug(audioclient) << (mode == QAudio::AudioOutput ? "output" : "input") << " device:" << deviceName;
|
||||
PropVariantClear(&pv);
|
||||
deviceName = friendlyNameForAudioDevice(pEndpoint);
|
||||
}
|
||||
pMMDeviceEnumerator->Release();
|
||||
pMMDeviceEnumerator = NULL;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <QtCore/qsystemdetection.h>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <QtCore/QObject>
|
||||
|
@ -126,6 +127,10 @@ public:
|
|||
|
||||
static const float CALLBACK_ACCELERATOR_RATIO;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
static QString friendlyNameForAudioDevice(wchar_t* guid);
|
||||
#endif
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
void stop();
|
||||
|
|
|
@ -7,21 +7,13 @@
|
|||
//
|
||||
#include "OculusDisplayPlugin.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <Mmsystem.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <devicetopology.h>
|
||||
#include <Functiondiscoverykeys_devpkey.h>
|
||||
#include <VersionHelpers.h>
|
||||
#endif
|
||||
// Odd ordering of header is required to avoid 'macro redinition warnings'
|
||||
#include <AudioClient.h>
|
||||
|
||||
#include <OVR_CAPI_Audio.h>
|
||||
#include <QtCore/QThread>
|
||||
|
||||
#include <shared/NsightHelpers.h>
|
||||
#include <AudioClient.h>
|
||||
|
||||
#include "OculusHelpers.h"
|
||||
|
||||
const QString OculusDisplayPlugin::NAME("Oculus Rift");
|
||||
|
@ -33,38 +25,9 @@ bool OculusDisplayPlugin::internalActivate() {
|
|||
if (result && _session) {
|
||||
ovr_SetInt(_session, OVR_PERF_HUD_MODE, currentDebugMode);
|
||||
}
|
||||
|
||||
auto audioClient = DependencyManager::get<AudioClient>();
|
||||
QString riftAudioIn = getPreferredAudioInDevice();
|
||||
if (riftAudioIn != QString()) {
|
||||
_savedAudioIn = audioClient->getDeviceName(QAudio::Mode::AudioInput);
|
||||
QMetaObject::invokeMethod(audioClient.data(), "switchInputToAudioDevice", Q_ARG(const QString&, riftAudioIn));
|
||||
} else {
|
||||
_savedAudioIn.clear();
|
||||
}
|
||||
|
||||
QString riftAudioOut = getPreferredAudioOutDevice();
|
||||
if (riftAudioOut != QString()) {
|
||||
_savedAudioOut = audioClient->getDeviceName(QAudio::Mode::AudioOutput);
|
||||
QMetaObject::invokeMethod(audioClient.data(), "switchOutputToAudioDevice", Q_ARG(const QString&, riftAudioOut));
|
||||
} else {
|
||||
_savedAudioOut.clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void OculusDisplayPlugin::internalDeactivate() {
|
||||
auto audioClient = DependencyManager::get<AudioClient>();
|
||||
if (_savedAudioIn != QString()) {
|
||||
QMetaObject::invokeMethod(audioClient.data(), "switchInputToAudioDevice", Q_ARG(const QString&, _savedAudioIn));
|
||||
}
|
||||
if (_savedAudioOut != QString()) {
|
||||
QMetaObject::invokeMethod(audioClient.data(), "switchOutputToAudioDevice", Q_ARG(const QString&, _savedAudioOut));
|
||||
}
|
||||
Parent::internalDeactivate();
|
||||
}
|
||||
|
||||
void OculusDisplayPlugin::cycleDebugOutput() {
|
||||
if (_session) {
|
||||
currentDebugMode = static_cast<ovrPerfHudMode>((currentDebugMode + 1) % ovrPerfHud_Count);
|
||||
|
@ -137,50 +100,12 @@ bool OculusDisplayPlugin::isHmdMounted() const {
|
|||
(ovrFalse != status.HmdMounted));
|
||||
}
|
||||
|
||||
static QString audioDeviceFriendlyName(LPCWSTR device) {
|
||||
QString deviceName;
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
CoInitialize(NULL);
|
||||
IMMDeviceEnumerator* pMMDeviceEnumerator = NULL;
|
||||
CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pMMDeviceEnumerator);
|
||||
IMMDevice* pEndpoint;
|
||||
hr = pMMDeviceEnumerator->GetDevice(device, &pEndpoint);
|
||||
if (hr == E_NOTFOUND) {
|
||||
printf("Audio Error: device not found\n");
|
||||
deviceName = QString("NONE");
|
||||
} else {
|
||||
IPropertyStore* pPropertyStore;
|
||||
pEndpoint->OpenPropertyStore(STGM_READ, &pPropertyStore);
|
||||
pEndpoint->Release();
|
||||
pEndpoint = NULL;
|
||||
PROPVARIANT pv;
|
||||
PropVariantInit(&pv);
|
||||
hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &pv);
|
||||
pPropertyStore->Release();
|
||||
pPropertyStore = NULL;
|
||||
deviceName = QString::fromWCharArray((wchar_t*)pv.pwszVal);
|
||||
if (!IsWindows8OrGreater()) {
|
||||
// Windows 7 provides only the 31 first characters of the device name.
|
||||
const DWORD QT_WIN7_MAX_AUDIO_DEVICENAME_LEN = 31;
|
||||
deviceName = deviceName.left(QT_WIN7_MAX_AUDIO_DEVICENAME_LEN);
|
||||
}
|
||||
qDebug() << " device:" << deviceName;
|
||||
PropVariantClear(&pv);
|
||||
}
|
||||
pMMDeviceEnumerator->Release();
|
||||
pMMDeviceEnumerator = NULL;
|
||||
CoUninitialize();
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
|
||||
QString OculusDisplayPlugin::getPreferredAudioInDevice() const {
|
||||
WCHAR buffer[OVR_AUDIO_MAX_DEVICE_STR_SIZE];
|
||||
if (!OVR_SUCCESS(ovr_GetAudioDeviceInGuidStr(buffer))) {
|
||||
return QString();
|
||||
}
|
||||
return audioDeviceFriendlyName(buffer);
|
||||
return AudioClient::friendlyNameForAudioDevice(buffer);
|
||||
}
|
||||
|
||||
QString OculusDisplayPlugin::getPreferredAudioOutDevice() const {
|
||||
|
@ -188,6 +113,6 @@ QString OculusDisplayPlugin::getPreferredAudioOutDevice() const {
|
|||
if (!OVR_SUCCESS(ovr_GetAudioDeviceOutGuidStr(buffer))) {
|
||||
return QString();
|
||||
}
|
||||
return audioDeviceFriendlyName(buffer);
|
||||
return AudioClient::friendlyNameForAudioDevice(buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ public:
|
|||
|
||||
protected:
|
||||
bool internalActivate() override;
|
||||
void internalDeactivate() override;
|
||||
void hmdPresent() override;
|
||||
bool isHmdMounted() const override;
|
||||
void customizeContext() override;
|
||||
|
@ -33,8 +32,6 @@ private:
|
|||
static const QString NAME;
|
||||
bool _enablePreview { false };
|
||||
bool _monoPreview { true };
|
||||
QString _savedAudioIn;
|
||||
QString _savedAudioOut;
|
||||
|
||||
SwapFboPtr _sceneFbo;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue