From b88355eaaf2f891c47f81ce5b2a568f1715e497d Mon Sep 17 00:00:00 2001 From: Jacques Heunis Date: Fri, 16 Sep 2016 21:47:00 +0200 Subject: [PATCH] Return more descriptive/exact errors when available in WASAPI. --- src/wasapi.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/wasapi.c b/src/wasapi.c index ab478c8..1ea0761 100644 --- a/src/wasapi.c +++ b/src/wasapi.c @@ -713,8 +713,9 @@ static int refresh_devices(struct SoundIoPrivate *si) { } if (FAILED(hr = IMMDevice_GetId(rd.default_capture_device, &rd.lpwstr))) { deinit_refresh_devices(&rd); - // 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. + if(hr == E_OUTOFMEMORY) { + return SoundIoErrorNoMem; + } return SoundIoErrorNoMem; } if ((err = from_lpwstr(rd.lpwstr, &rd.default_capture_id, &rd.default_capture_id_len))) { @@ -932,8 +933,8 @@ static int refresh_devices(struct SoundIoPrivate *si) { } int device_name_len; if ((err = from_lpwstr(rd.prop_variant_value.pwszVal, &rd.device_shared->name, &device_name_len))) { - rd.device_shared->probe_error = SoundIoErrorOpeningDevice; - rd.device_raw->probe_error = SoundIoErrorOpeningDevice; + rd.device_shared->probe_error = err; + rd.device_raw->probe_error = err; rd.device_shared = NULL; rd.device_raw = NULL; continue; @@ -974,19 +975,19 @@ static int refresh_devices(struct SoundIoPrivate *si) { if ((err = detect_valid_sample_rates(&rd, valid_wave_format, dev_raw, AUDCLNT_SHAREMODE_EXCLUSIVE))) { - rd.device_raw->probe_error = SoundIoErrorOpeningDevice; + rd.device_raw->probe_error = err; rd.device_raw = NULL; } if (rd.device_raw && (err = detect_valid_formats(&rd, valid_wave_format, dev_raw, AUDCLNT_SHAREMODE_EXCLUSIVE))) { - rd.device_raw->probe_error = SoundIoErrorOpeningDevice; + rd.device_raw->probe_error = err; rd.device_raw = NULL; } if (rd.device_raw && (err = detect_valid_layouts(&rd, valid_wave_format, dev_raw, AUDCLNT_SHAREMODE_EXCLUSIVE))) { - rd.device_raw->probe_error = SoundIoErrorOpeningDevice; + rd.device_raw->probe_error = err; rd.device_raw = NULL; } @@ -1030,7 +1031,7 @@ static int refresh_devices(struct SoundIoPrivate *si) { if ((err = detect_valid_formats(&rd, rd.wave_format, dev_shared, AUDCLNT_SHAREMODE_SHARED))) { - rd.device_shared->probe_error = SoundIoErrorOpeningDevice; + rd.device_shared->probe_error = err; rd.device_shared = NULL; } else {