WASAPI: Correctly handle no input or output devices instead of crashing.

This commit is contained in:
Jacques Heunis 2016-06-04 14:38:11 +02:00
parent cdc4e2fd2a
commit 4b95b79f27
2 changed files with 36 additions and 26 deletions

View file

@ -666,9 +666,12 @@ static int refresh_devices(struct SoundIoPrivate *si) {
if (FAILED(hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(siw->device_enumerator, eRender, if (FAILED(hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(siw->device_enumerator, eRender,
eMultimedia, &rd.default_render_device))) eMultimedia, &rd.default_render_device)))
{ {
if(hr != E_NOTFOUND) {
deinit_refresh_devices(&rd); deinit_refresh_devices(&rd);
return SoundIoErrorOpeningDevice; return SoundIoErrorOpeningDevice;
} }
}
if(rd.default_render_device) {
if (rd.lpwstr) { if (rd.lpwstr) {
CoTaskMemFree(rd.lpwstr); CoTaskMemFree(rd.lpwstr);
rd.lpwstr = NULL; rd.lpwstr = NULL;
@ -681,14 +684,18 @@ static int refresh_devices(struct SoundIoPrivate *si) {
deinit_refresh_devices(&rd); deinit_refresh_devices(&rd);
return err; return err;
} }
}
if (FAILED(hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(siw->device_enumerator, eCapture, if (FAILED(hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(siw->device_enumerator, eCapture,
eMultimedia, &rd.default_capture_device))) eMultimedia, &rd.default_capture_device)))
{ {
if(hr != E_NOTFOUND) {
deinit_refresh_devices(&rd); deinit_refresh_devices(&rd);
return SoundIoErrorOpeningDevice; return SoundIoErrorOpeningDevice;
} }
}
if(rd.default_capture_device) {
if (rd.lpwstr) { if (rd.lpwstr) {
CoTaskMemFree(rd.lpwstr); CoTaskMemFree(rd.lpwstr);
rd.lpwstr = NULL; rd.lpwstr = NULL;
@ -701,6 +708,7 @@ static int refresh_devices(struct SoundIoPrivate *si) {
deinit_refresh_devices(&rd); deinit_refresh_devices(&rd);
return err; return err;
} }
}
if (FAILED(hr = IMMDeviceEnumerator_EnumAudioEndpoints(siw->device_enumerator, if (FAILED(hr = IMMDeviceEnumerator_EnumAudioEndpoints(siw->device_enumerator,

View file

@ -24,6 +24,8 @@
#include <audiosessiontypes.h> #include <audiosessiontypes.h>
#include <audiopolicy.h> #include <audiopolicy.h>
#define E_NOTFOUND 0x80070490
struct SoundIoPrivate; struct SoundIoPrivate;
int soundio_wasapi_init(struct SoundIoPrivate *si); int soundio_wasapi_init(struct SoundIoPrivate *si);