mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
alsa: more tapdancing to enumerate physical hardware devices.
Apparently some systems see "hw:", some see "default:" and some see "sysdefault:" (and maybe others!). My workstation sees both "hw:" and "sysdefault:" ... Try to find a prefix we like and prioritize the prefixes we (think) we want most. If everything else fails, if there's a "default" (not a prefix) device name, list that by itself so the user gets _something_ here. If we can't find a prefix we like _and_ there's no "default" device, report no hardware found at all.
This commit is contained in:
parent
9db5e9aae9
commit
ca42373fb5
@ -773,23 +773,40 @@ ALSA_HotplugThread(void *arg)
|
|||||||
ALSA_Device *unseen = devices;
|
ALSA_Device *unseen = devices;
|
||||||
ALSA_Device *seen = NULL;
|
ALSA_Device *seen = NULL;
|
||||||
ALSA_Device *prev;
|
ALSA_Device *prev;
|
||||||
int i;
|
int i, j;
|
||||||
const char *match = "default:";
|
const char *match = NULL;
|
||||||
size_t match_len = strlen(match);
|
int bestmatch = 0xFFFF;
|
||||||
|
size_t match_len = 0;
|
||||||
|
int defaultdev = -1;
|
||||||
|
static const char * const prefixes[] = {
|
||||||
|
"hw:", "sysdefault:", "default:", NULL
|
||||||
|
};
|
||||||
|
|
||||||
/* determine what kind of name to match. Use "hw:" devices if they
|
/* Apparently there are several different ways that ALSA lists
|
||||||
exist, otherwise use "default:" */
|
actual hardware. It could be prefixed with "hw:" or "default:"
|
||||||
|
or "sysdefault:" and maybe others. Go through the list and see
|
||||||
|
if we can find a preferred prefix for the system. */
|
||||||
for (i = 0; hints[i]; i++) {
|
for (i = 0; hints[i]; i++) {
|
||||||
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
|
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
|
||||||
if (!name) {
|
if (!name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_strncmp(name, "hw:", 3) == 0) {
|
/* full name, not a prefix */
|
||||||
match = "hw:";
|
if ((defaultdev == -1) && (SDL_strcmp(name, "default") == 0)) {
|
||||||
match_len = strlen(match);
|
defaultdev = i;
|
||||||
free(name);
|
}
|
||||||
break;
|
|
||||||
|
for (j = 0; prefixes[j]; j++) {
|
||||||
|
const char *prefix = prefixes[j];
|
||||||
|
const size_t prefixlen = strlen(prefix);
|
||||||
|
if (SDL_strncmp(name, prefix, prefixlen) == 0) {
|
||||||
|
if (j < bestmatch) {
|
||||||
|
bestmatch = j;
|
||||||
|
match = prefix;
|
||||||
|
match_len = prefixlen;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(name);
|
free(name);
|
||||||
@ -797,13 +814,20 @@ ALSA_HotplugThread(void *arg)
|
|||||||
|
|
||||||
/* look through the list of device names to find matches */
|
/* look through the list of device names to find matches */
|
||||||
for (i = 0; hints[i]; i++) {
|
for (i = 0; hints[i]; i++) {
|
||||||
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
|
char *name;
|
||||||
|
|
||||||
|
/* if we didn't find a device name prefix we like at all... */
|
||||||
|
if ((!match) && (defaultdev != i)) {
|
||||||
|
continue; /* ...skip anything that isn't the default device. */
|
||||||
|
}
|
||||||
|
|
||||||
|
name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
|
||||||
if (!name) {
|
if (!name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only want physical hardware interfaces */
|
/* only want physical hardware interfaces */
|
||||||
if (SDL_strncmp(name, match, match_len) == 0) {
|
if (!match || (SDL_strncmp(name, match, match_len) == 0)) {
|
||||||
char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
|
char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
|
||||||
const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
|
const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
|
||||||
const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
|
const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user