mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +02:00
Stopped windows crash when no audio device is detected
This commit is contained in:
parent
899c89eda7
commit
2329188939
1 changed files with 21 additions and 16 deletions
|
@ -200,22 +200,27 @@ QAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) {
|
||||||
CoInitialize(NULL);
|
CoInitialize(NULL);
|
||||||
IMMDeviceEnumerator* pMMDeviceEnumerator = NULL;
|
IMMDeviceEnumerator* pMMDeviceEnumerator = NULL;
|
||||||
CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pMMDeviceEnumerator);
|
CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pMMDeviceEnumerator);
|
||||||
IMMDevice* pEndpoint;
|
IMMDevice* pEndpoint;hr = pMMDeviceEnumerator->GetDefaultAudioEndpoint(mode == QAudio::AudioOutput ? eRender : eCapture, eMultimedia, &pEndpoint);
|
||||||
pMMDeviceEnumerator->GetDefaultAudioEndpoint(mode == QAudio::AudioOutput ? eRender : eCapture, eMultimedia, &pEndpoint);
|
if (hr == E_NOTFOUND){
|
||||||
IPropertyStore* pPropertyStore;
|
printf("Audio Error: device not found\n");
|
||||||
pEndpoint->OpenPropertyStore(STGM_READ, &pPropertyStore);
|
deviceName = QString("NONE");
|
||||||
pEndpoint->Release();
|
}
|
||||||
pEndpoint = NULL;
|
else {
|
||||||
PROPVARIANT pv;
|
IPropertyStore* pPropertyStore;
|
||||||
PropVariantInit(&pv);
|
pEndpoint->OpenPropertyStore(STGM_READ, &pPropertyStore);
|
||||||
hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &pv);
|
pEndpoint->Release();
|
||||||
pPropertyStore->Release();
|
pEndpoint = NULL;
|
||||||
pPropertyStore = NULL;
|
PROPVARIANT pv;
|
||||||
//QAudio devices seems to only take the 31 first characters of the Friendly Device Name.
|
PropVariantInit(&pv);
|
||||||
const DWORD QT_WIN_MAX_AUDIO_DEVICENAME_LEN = 31;
|
hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &pv);
|
||||||
deviceName = QString::fromWCharArray((wchar_t*)pv.pwszVal).left(QT_WIN_MAX_AUDIO_DEVICENAME_LEN);
|
pPropertyStore->Release();
|
||||||
qDebug() << (mode == QAudio::AudioOutput ? "output" : "input") << " device:" << deviceName;
|
pPropertyStore = NULL;
|
||||||
PropVariantClear(&pv);
|
//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->Release();
|
||||||
pMMDeviceEnumerator = NULL;
|
pMMDeviceEnumerator = NULL;
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
|
Loading…
Reference in a new issue