mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 08:21:24 +02:00
Merge pull request #2607 from thoys/hifi-win-default-device-fix
windows default device fix
This commit is contained in:
commit
dc89026215
1 changed files with 57 additions and 16 deletions
|
@ -15,6 +15,15 @@
|
||||||
#include <CoreAudio/AudioHardware.h>
|
#include <CoreAudio/AudioHardware.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#include <Mmsystem.h>
|
||||||
|
#include <mmdeviceapi.h>
|
||||||
|
#include <devicetopology.h>
|
||||||
|
#include <Functiondiscoverykeys_devpkey.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QtCore/QBuffer>
|
#include <QtCore/QBuffer>
|
||||||
#include <QtMultimedia/QAudioInput>
|
#include <QtMultimedia/QAudioInput>
|
||||||
#include <QtMultimedia/QAudioOutput>
|
#include <QtMultimedia/QAudioOutput>
|
||||||
|
@ -147,6 +156,13 @@ QAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
QString deviceName;
|
QString deviceName;
|
||||||
|
//Check for Windows Vista or higher, IMMDeviceEnumerator doesn't work below that.
|
||||||
|
OSVERSIONINFO osvi;
|
||||||
|
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
|
||||||
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||||
|
GetVersionEx(&osvi);
|
||||||
|
const DWORD VISTA_MAJOR_VERSION = 6;
|
||||||
|
if (osvi.dwMajorVersion < VISTA_MAJOR_VERSION) {// lower then vista
|
||||||
if (mode == QAudio::AudioInput) {
|
if (mode == QAudio::AudioInput) {
|
||||||
WAVEINCAPS wic;
|
WAVEINCAPS wic;
|
||||||
// first use WAVE_MAPPER to get the default devices manufacturer ID
|
// first use WAVE_MAPPER to get the default devices manufacturer ID
|
||||||
|
@ -164,6 +180,31 @@ QAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
||||||
qDebug() << "output device:" << woc.szPname;
|
qDebug() << "output device:" << woc.szPname;
|
||||||
deviceName = woc.szPname;
|
deviceName = woc.szPname;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
CoInitialize(NULL);
|
||||||
|
IMMDeviceEnumerator* pMMDeviceEnumerator = NULL;
|
||||||
|
CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pMMDeviceEnumerator);
|
||||||
|
IMMDevice* pEndpoint;
|
||||||
|
pMMDeviceEnumerator->GetDefaultAudioEndpoint(mode == QAudio::AudioOutput ? eRender : eCapture, eMultimedia, &pEndpoint);
|
||||||
|
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;
|
||||||
|
//QAudio devices seems to only take the 31 first characters of the Friendly Device Name.
|
||||||
|
const DWORD QT_WIN_MAX_AUDIO_DEVICENAME_LEN = 31;
|
||||||
|
deviceName = QString::fromWCharArray((wchar_t*)pv.pwszVal).left(QT_WIN_MAX_AUDIO_DEVICENAME_LEN);
|
||||||
|
qDebug() << (mode == QAudio::AudioOutput ? "output" : "input") << " device:" << deviceName;
|
||||||
|
PropVariantClear(&pv);
|
||||||
|
pMMDeviceEnumerator->Release();
|
||||||
|
pMMDeviceEnumerator = NULL;
|
||||||
|
CoUninitialize();
|
||||||
|
}
|
||||||
qDebug() << "DEBUG [" << deviceName << "] [" << getNamedAudioDeviceForMode(mode, deviceName).deviceName() << "]";
|
qDebug() << "DEBUG [" << deviceName << "] [" << getNamedAudioDeviceForMode(mode, deviceName).deviceName() << "]";
|
||||||
|
|
||||||
return getNamedAudioDeviceForMode(mode, deviceName);
|
return getNamedAudioDeviceForMode(mode, deviceName);
|
||||||
|
|
Loading…
Reference in a new issue