Support comma-separated lists in SDL_AUDIODRIVER

This commit is contained in:
Luis Cáceres 2021-04-02 06:28:10 +01:00 committed by Ryan C. Gordon
parent 5ec69285fa
commit 45de0a1d13

View file

@ -972,19 +972,38 @@ SDL_AudioInit(const char *driver_name)
driver_name = SDL_getenv("SDL_AUDIODRIVER"); driver_name = SDL_getenv("SDL_AUDIODRIVER");
} }
for (i = 0; (!initialized) && (bootstrap[i]); ++i) { if (driver_name != NULL) {
/* make sure we should even try this driver before doing so... */ const char *driver_attempt = driver_name;
const AudioBootStrap *backend = bootstrap[i]; while (driver_attempt != NULL && *driver_attempt != 0 && !initialized) {
if ((driver_name && (SDL_strncasecmp(backend->name, driver_name, SDL_strlen(driver_name)) != 0)) || const char *driver_attempt_end = SDL_strchr(driver_attempt, ',');
(!driver_name && backend->demand_only)) { size_t driver_attempt_len = (driver_attempt_end != NULL) ? (driver_attempt_end - driver_attempt)
continue; : SDL_strlen(driver_attempt);
}
tried_to_init = 1; for (i = 0; bootstrap[i]; ++i) {
SDL_zero(current_audio); if (SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0) {
current_audio.name = backend->name; tried_to_init = 1;
current_audio.desc = backend->desc; SDL_zero(current_audio);
initialized = backend->init(&current_audio.impl); current_audio.name = bootstrap[i]->name;
current_audio.desc = bootstrap[i]->desc;
initialized = bootstrap[i]->init(&current_audio.impl);
break;
}
}
driver_attempt = (driver_attempt_end != NULL) ? (driver_attempt_end + 1) : NULL;
}
} else {
for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
if(bootstrap[i]->demand_only) {
continue;
}
tried_to_init = 1;
SDL_zero(current_audio);
current_audio.name = bootstrap[i]->name;
current_audio.desc = bootstrap[i]->desc;
initialized = bootstrap[i]->init(&current_audio.impl);
}
} }
if (!initialized) { if (!initialized) {