From 1c513464c83a1459a111681c2738b673b25047f0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 10 Jun 2021 15:36:26 +0200 Subject: [PATCH] alsa: strip and add the _alibpref from device names Strip the _alibpref from the device name, it contains a local counter to identify the ucm card that should remain internal. We set a flag on the device to notify of this. Re-add the _alibpref of the local card to the device name if the device was flagged. See #1286 --- spa/plugins/alsa/acp/acp.c | 3 +++ spa/plugins/alsa/alsa-pcm.c | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/spa/plugins/alsa/acp/acp.c b/spa/plugins/alsa/acp/acp.c index f95440737..0be849947 100644 --- a/spa/plugins/alsa/acp/acp.c +++ b/spa/plugins/alsa/acp/acp.c @@ -252,6 +252,9 @@ static void init_device(pa_card *impl, pa_alsa_device *dev, pa_alsa_direction_t char **d; for (d = m->device_strings; *d; d++) { if (pa_startswith(*d, alibpref)) { + size_t plen = strlen(alibpref); + size_t len = strlen(*d); + memmove(*d, (*d) + plen, len - plen + 1); dev->device.flags |= ACP_DEVICE_UCM_DEVICE; break; } diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index d7572da09..d12db9154 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -9,6 +9,7 @@ #include #include +#include #include #define NAME "alsa-pcm" @@ -49,9 +50,10 @@ int spa_alsa_init(struct state *state) if ((snd_use_case_get(state->ucm, "_alibpref", &alibpref) != 0)) alibpref = NULL; if (alibpref != NULL) { - size_t len = strlen(alibpref); - if (len > 4 && strncmp(state->props.device, alibpref, 4) == 0) - memcpy(state->props.device, alibpref, len); + char name[sizeof(state->props.device)]; + spa_scnprintf(name, sizeof(name), "%s%s", alibpref, + state->props.device); + strcpy(state->props.device, name); } } return 0;