Some systems include both "default:" and "hw:" for the same usb device
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c
index c6ec6c6..2373956 100644
--- a/src/audio/alsa/SDL_alsa_audio.c
+++ b/src/audio/alsa/SDL_alsa_audio.c
@@ -771,7 +771,28 @@ ALSA_HotplugThread(void *arg)
ALSA_Device *seen = NULL;
ALSA_Device *prev;
int i;
+ const char *match = "default:";
+ size_t match_len = strlen(match);
+ /* determine what kind of name to match. Use "hw:" devices if they
+ exist, otherwise use "default:" */
+ for (i = 0; hints[i]; i++) {
+ char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
+ if (!name) {
+ continue;
+ }
+
+ if (SDL_strncmp(name, "hw:", 3) == 0) {
+ match = "hw:";
+ match_len = strlen(match);
+ free(name);
+ break;
+ }
+
+ free(name);
+ }
+
+ /* look through the list of device names to find matches */
for (i = 0; hints[i]; i++) {
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) {
@@ -779,8 +800,7 @@ ALSA_HotplugThread(void *arg)
}
/* only want physical hardware interfaces */
- if (SDL_strncmp(name, "hw:", 3) == 0 ||
- SDL_strncmp(name, "default:", 8) == 0) {
+ if (SDL_strncmp(name, match, match_len) == 0) {
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 isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);