mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +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>
|
||||
#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 <QtMultimedia/QAudioInput>
|
||||
#include <QtMultimedia/QAudioOutput>
|
||||
|
@ -147,24 +156,56 @@ QAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
|||
#endif
|
||||
#ifdef WIN32
|
||||
QString deviceName;
|
||||
if (mode == QAudio::AudioInput) {
|
||||
WAVEINCAPS wic;
|
||||
// first use WAVE_MAPPER to get the default devices manufacturer ID
|
||||
waveInGetDevCaps(WAVE_MAPPER, &wic, sizeof(wic));
|
||||
//Use the received manufacturer id to get the device's real name
|
||||
waveInGetDevCaps(wic.wMid, &wic, sizeof(wic));
|
||||
qDebug() << "input device:" << wic.szPname;
|
||||
deviceName = wic.szPname;
|
||||
//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) {
|
||||
WAVEINCAPS wic;
|
||||
// first use WAVE_MAPPER to get the default devices manufacturer ID
|
||||
waveInGetDevCaps(WAVE_MAPPER, &wic, sizeof(wic));
|
||||
//Use the received manufacturer id to get the device's real name
|
||||
waveInGetDevCaps(wic.wMid, &wic, sizeof(wic));
|
||||
qDebug() << "input device:" << wic.szPname;
|
||||
deviceName = wic.szPname;
|
||||
} else {
|
||||
WAVEOUTCAPS woc;
|
||||
// first use WAVE_MAPPER to get the default devices manufacturer ID
|
||||
waveOutGetDevCaps(WAVE_MAPPER, &woc, sizeof(woc));
|
||||
//Use the received manufacturer id to get the device's real name
|
||||
waveOutGetDevCaps(woc.wMid, &woc, sizeof(woc));
|
||||
qDebug() << "output device:" << woc.szPname;
|
||||
deviceName = woc.szPname;
|
||||
}
|
||||
} else {
|
||||
WAVEOUTCAPS woc;
|
||||
// first use WAVE_MAPPER to get the default devices manufacturer ID
|
||||
waveOutGetDevCaps(WAVE_MAPPER, &woc, sizeof(woc));
|
||||
//Use the received manufacturer id to get the device's real name
|
||||
waveOutGetDevCaps(woc.wMid, &woc, sizeof(woc));
|
||||
qDebug() << "output device:" << woc.szPname;
|
||||
deviceName = woc.szPname;
|
||||
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);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue