diff options
author | Jan Niklas Hasse <[email protected]> | 2018-03-08 10:07:22 +0100 |
---|---|---|
committer | Jan Niklas Hasse <[email protected]> | 2018-03-08 10:07:22 +0100 |
commit | a6f93a501a08ddf35f98473822a70258e70f613a (patch) | |
tree | 2e987a65d45cd20633f2f9c091f605e84bb27962 /Alc | |
parent | 767807cd2273eb9e760b25d792820b1c8f1946e1 (diff) |
Handle passing NULL to SDL_OpenAudioDevice as a special device
https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/2
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/backends/sdl2.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Alc/backends/sdl2.c b/Alc/backends/sdl2.c index c191a528..9881594d 100644 --- a/Alc/backends/sdl2.c +++ b/Alc/backends/sdl2.c @@ -54,6 +54,8 @@ DECLARE_DEFAULT_ALLOCATORS(ALCsdl2Backend) DEFINE_ALCBACKEND_VTABLE(ALCsdl2Backend); +static const ALCchar defaultDeviceName[] = "Default device"; + static void ALCsdl2Backend_Construct(ALCsdl2Backend *self, ALCdevice *device) { ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); @@ -95,13 +97,16 @@ static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name) want.callback = ALCsdl2Backend_audioCallback; want.userdata = self; - if(!name) - name = SDL_GetAudioDeviceName(0, 0); + if (name && strcmp(name, defaultDeviceName) == 0) + name = NULL; // Passing NULL to SDL_OpenAudioDevice is special and will NOT select the first + // device in the list. self->deviceID = SDL_OpenAudioDevice(name, 0, &want, NULL, 0); if(self->deviceID == 0) { ERR("Could not open device\n"); return ALC_INVALID_VALUE; } + if(!name) + name = defaultDeviceName; alstr_copy_cstr(&STATIC_CAST(ALCbackend, self)->mDevice->DeviceName, name); return ALC_NO_ERROR; @@ -173,6 +178,7 @@ static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory* UNUSED(self), enu } else if(!SDL_WasInit(SDL_INIT_AUDIO)) SDL_InitSubSystem(SDL_INIT_AUDIO); + AppendAllDevicesList(defaultDeviceName); for(int i = 0; i < SDL_GetNumAudioDevices(0); ++i) AppendAllDevicesList(SDL_GetAudioDeviceName(i, 0)); if(quit) |