mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-23 03:55:33 +00:00
Merge pull request #79 from jacquesh/wasapi-device-error-handling
WASAPI: Correctly handle no input or output devices instead of crashing.
This commit is contained in:
commit
c2df644493
11
src/wasapi.c
11
src/wasapi.c
|
@ -25,6 +25,9 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Some HRESULT values are not defined by the windows headers
|
||||||
|
#define E_NOTFOUND 0x80070490
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// In C++ mode, IsEqualGUID() takes its arguments by reference
|
// In C++ mode, IsEqualGUID() takes its arguments by reference
|
||||||
#define IS_EQUAL_GUID(a, b) IsEqualGUID(*(a), *(b))
|
#define IS_EQUAL_GUID(a, b) IsEqualGUID(*(a), *(b))
|
||||||
|
@ -666,9 +669,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 +687,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 +711,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,
|
||||||
|
|
Loading…
Reference in a new issue