mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-22 23:15:32 +00:00
WASAPI: Correctly handle no input or output devices instead of crashing.
This commit is contained in:
parent
cdc4e2fd2a
commit
4b95b79f27
60
src/wasapi.c
60
src/wasapi.c
|
@ -666,40 +666,48 @@ static int refresh_devices(struct SoundIoPrivate *si) {
|
|||
if (FAILED(hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(siw->device_enumerator, eRender,
|
||||
eMultimedia, &rd.default_render_device)))
|
||||
{
|
||||
deinit_refresh_devices(&rd);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
if(hr != E_NOTFOUND) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
}
|
||||
if (rd.lpwstr) {
|
||||
CoTaskMemFree(rd.lpwstr);
|
||||
rd.lpwstr = NULL;
|
||||
}
|
||||
if (FAILED(hr = IMMDevice_GetId(rd.default_render_device, &rd.lpwstr))) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
if ((err = from_lpwstr(rd.lpwstr, &rd.default_render_id, &rd.default_render_id_len))) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return err;
|
||||
if(rd.default_render_device) {
|
||||
if (rd.lpwstr) {
|
||||
CoTaskMemFree(rd.lpwstr);
|
||||
rd.lpwstr = NULL;
|
||||
}
|
||||
if (FAILED(hr = IMMDevice_GetId(rd.default_render_device, &rd.lpwstr))) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
if ((err = from_lpwstr(rd.lpwstr, &rd.default_render_id, &rd.default_render_id_len))) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (FAILED(hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(siw->device_enumerator, eCapture,
|
||||
eMultimedia, &rd.default_capture_device)))
|
||||
{
|
||||
deinit_refresh_devices(&rd);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
if(hr != E_NOTFOUND) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
}
|
||||
if (rd.lpwstr) {
|
||||
CoTaskMemFree(rd.lpwstr);
|
||||
rd.lpwstr = NULL;
|
||||
}
|
||||
if (FAILED(hr = IMMDevice_GetId(rd.default_capture_device, &rd.lpwstr))) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
if ((err = from_lpwstr(rd.lpwstr, &rd.default_capture_id, &rd.default_capture_id_len))) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return err;
|
||||
if(rd.default_capture_device) {
|
||||
if (rd.lpwstr) {
|
||||
CoTaskMemFree(rd.lpwstr);
|
||||
rd.lpwstr = NULL;
|
||||
}
|
||||
if (FAILED(hr = IMMDevice_GetId(rd.default_capture_device, &rd.lpwstr))) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
if ((err = from_lpwstr(rd.lpwstr, &rd.default_capture_id, &rd.default_capture_id_len))) {
|
||||
deinit_refresh_devices(&rd);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <audiosessiontypes.h>
|
||||
#include <audiopolicy.h>
|
||||
|
||||
#define E_NOTFOUND 0x80070490
|
||||
|
||||
struct SoundIoPrivate;
|
||||
int soundio_wasapi_init(struct SoundIoPrivate *si);
|
||||
|
||||
|
|
Loading…
Reference in a new issue