From c4ed20d97138e157615773e565814632dc558c21 Mon Sep 17 00:00:00 2001 From: Autumn Date: Wed, 11 Aug 2021 01:00:58 +0200 Subject: [PATCH] [cherry-pick & squash] Allow comma-separated SDL_AUDIODRIVER & "pulseaudio" alias for "pulse" driver --- src/audio/SDL_audio.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index beb26e0b..f88f9e4f 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -342,18 +342,28 @@ int SDL_AudioInit(const char *driver_name) #endif /* SDL_AUDIO_DRIVER_ESD */ if ( audio == NULL ) { if ( driver_name != NULL ) { -#if 0 /* This will be replaced with a better driver selection API */ - if ( SDL_strrchr(driver_name, ':') != NULL ) { - idx = atoi(SDL_strrchr(driver_name, ':')+1); - } + const char *driver_attempt = driver_name; + while(driver_attempt != NULL && *driver_attempt != 0 && audio == NULL) { + const char* driver_attempt_end = SDL_strchr(driver_attempt, ','); + size_t driver_attempt_len = (driver_attempt_end != NULL) ? (driver_attempt_end - driver_attempt) + : SDL_strlen(driver_attempt); +#if SDL_AUDIO_DRIVER_PULSE + /* SDL 2.0 uses the name "pulseaudio", so we'll support both */ + if ( (driver_attempt_len == SDL_strlen("pulseaudio")) && + (SDL_strncasecmp(driver_attempt, "pulseaudio", driver_attempt_len) == 0 ) ) { + driver_attempt_len = SDL_strlen("pulse"); + } #endif - for ( i=0; bootstrap[i]; ++i ) { - if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) { - if ( bootstrap[i]->available() ) { - audio=bootstrap[i]->create(idx); - break; + for ( i=0; bootstrap[i]; ++i ) { + if ((driver_attempt_len == SDL_strlen(bootstrap[i]->name)) && + (SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0)) { + if ( bootstrap[i]->available() ) { + audio=bootstrap[i]->create(idx); + break; + } } } + driver_attempt = (driver_attempt_end != NULL) ? (driver_attempt_end + 1) : NULL; } } else { for ( i=0; bootstrap[i]; ++i ) { -- 2.32.0