From a8201986a0846808be0d5d1fdb8161168f0b0df3 Mon Sep 17 00:00:00 2001 From: Jacques Heunis Date: Fri, 16 Sep 2016 10:12:35 +0200 Subject: [PATCH] Return slightly more descriptive soundio errors when RefreshDevices fails for WASAPI. --- src/wasapi.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wasapi.c b/src/wasapi.c index 84bc695..49709d9 100644 --- a/src/wasapi.c +++ b/src/wasapi.c @@ -671,6 +671,9 @@ static int refresh_devices(struct SoundIoPrivate *si) { { if(hr != E_NOTFOUND) { deinit_refresh_devices(&rd); + if(hr == E_OUTOFMEMORY) { + return SoundIoErrorNoMem; + } return SoundIoErrorOpeningDevice; } } @@ -681,7 +684,9 @@ static int refresh_devices(struct SoundIoPrivate *si) { } if (FAILED(hr = IMMDevice_GetId(rd.default_render_device, &rd.lpwstr))) { deinit_refresh_devices(&rd); - return SoundIoErrorOpeningDevice; + // MSDN states the IMMDevice_GetId can fail if the device is NULL, or if we're out of memory + // We know the device point isn't NULL so we're necessarily out of memory + return SoundIoErrorNoMem; } if ((err = from_lpwstr(rd.lpwstr, &rd.default_render_id, &rd.default_render_id_len))) { deinit_refresh_devices(&rd); @@ -695,6 +700,9 @@ static int refresh_devices(struct SoundIoPrivate *si) { { if(hr != E_NOTFOUND) { deinit_refresh_devices(&rd); + if(hr == E_OUTOFMEMORY) { + return SoundIoErrorNoMem; + } return SoundIoErrorOpeningDevice; } } @@ -705,7 +713,9 @@ static int refresh_devices(struct SoundIoPrivate *si) { } if (FAILED(hr = IMMDevice_GetId(rd.default_capture_device, &rd.lpwstr))) { deinit_refresh_devices(&rd); - return SoundIoErrorOpeningDevice; + // MSDN states the IMMDevice_GetId can fail if the device is NULL, or if we're out of memory + // We know the device point isn't NULL so we're necessarily out of memory. + return SoundIoErrorNoMem; } if ((err = from_lpwstr(rd.lpwstr, &rd.default_capture_id, &rd.default_capture_id_len))) { deinit_refresh_devices(&rd); @@ -718,11 +728,16 @@ static int refresh_devices(struct SoundIoPrivate *si) { eAll, DEVICE_STATE_ACTIVE, &rd.collection))) { deinit_refresh_devices(&rd); + if(hr == E_OUTOFMEMORY) { + return SoundIoErrorNoMem; + } return SoundIoErrorOpeningDevice; } UINT unsigned_count; if (FAILED(hr = IMMDeviceCollection_GetCount(rd.collection, &unsigned_count))) { + // In theory this shouldn't happen since the only documented failure case is that + // rd.collection is NULL, but then EnumAudioEndpoints should have failed. deinit_refresh_devices(&rd); return SoundIoErrorOpeningDevice; }