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
This commit is contained in:
Wim Taymans 2021-06-10 15:36:26 +02:00
parent 283e13629c
commit 1c513464c8
2 changed files with 8 additions and 3 deletions

View file

@ -252,6 +252,9 @@ static void init_device(pa_card *impl, pa_alsa_device *dev, pa_alsa_direction_t
char **d; char **d;
for (d = m->device_strings; *d; d++) { for (d = m->device_strings; *d; d++) {
if (pa_startswith(*d, alibpref)) { 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; dev->device.flags |= ACP_DEVICE_UCM_DEVICE;
break; break;
} }

View file

@ -9,6 +9,7 @@
#include <limits.h> #include <limits.h>
#include <spa/pod/filter.h> #include <spa/pod/filter.h>
#include <spa/utils/string.h>
#include <spa/support/system.h> #include <spa/support/system.h>
#define NAME "alsa-pcm" #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)) if ((snd_use_case_get(state->ucm, "_alibpref", &alibpref) != 0))
alibpref = NULL; alibpref = NULL;
if (alibpref != NULL) { if (alibpref != NULL) {
size_t len = strlen(alibpref); char name[sizeof(state->props.device)];
if (len > 4 && strncmp(state->props.device, alibpref, 4) == 0) spa_scnprintf(name, sizeof(name), "%s%s", alibpref,
memcpy(state->props.device, alibpref, len); state->props.device);
strcpy(state->props.device, name);
} }
} }
return 0; return 0;