From ae89ae093e31675930bb59a006189287f228e319 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 29 Jun 2021 17:43:00 +0200 Subject: [PATCH] acp: strip UCM alibpref from mapping Strip the alibpref from the device string in the mapping name. This name is used to generate the node name eventually and we don't want this random identifier in it. Fixes #1362 --- spa/plugins/alsa/acp/acp.c | 12 +++--------- spa/plugins/alsa/acp/alsa-ucm.c | 18 ++++++++++++++++-- spa/plugins/alsa/acp/alsa-ucm.h | 2 ++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/spa/plugins/alsa/acp/acp.c b/spa/plugins/alsa/acp/acp.c index 0be849947..cceed935f 100644 --- a/spa/plugins/alsa/acp/acp.c +++ b/spa/plugins/alsa/acp/acp.c @@ -242,24 +242,18 @@ static void init_device(pa_card *impl, pa_alsa_device *dev, pa_alsa_direction_t dev->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); if (m->ucm_context.ucm) { - const char *alibpref = NULL; dev->ucm_context = &m->ucm_context; - if ((snd_use_case_get(impl->ucm.ucm_mgr, "_alibpref", &alibpref) != 0)) - alibpref = NULL; - if (alibpref == NULL) - alibpref = strdup("_ucm"); - if (alibpref != NULL) { + if (impl->ucm.alibpref != NULL) { char **d; for (d = m->device_strings; *d; d++) { - if (pa_startswith(*d, alibpref)) { - size_t plen = strlen(alibpref); + if (pa_startswith(*d, impl->ucm.alibpref)) { + size_t plen = strlen(impl->ucm.alibpref); size_t len = strlen(*d); memmove(*d, (*d) + plen, len - plen + 1); dev->device.flags |= ACP_DEVICE_UCM_DEVICE; break; } } - free((void*)alibpref); } } pa_dynarray_init(&dev->port_array, NULL); diff --git a/spa/plugins/alsa/acp/alsa-ucm.c b/spa/plugins/alsa/acp/alsa-ucm.c index 730e7bff2..93731b7cb 100644 --- a/spa/plugins/alsa/acp/alsa-ucm.c +++ b/spa/plugins/alsa/acp/alsa-ucm.c @@ -806,12 +806,16 @@ int pa_alsa_ucm_query_profiles(pa_alsa_ucm_config *ucm, int card_index) { err = -PA_ALSA_ERR_UCM_NO_VERB; } + snd_use_case_get(ucm->ucm_mgr, "_alibpref", (const char**)&ucm->alibpref); + snd_use_case_free_list(verb_list, num_verbs); ucm_verb_fail: if (err < 0) { snd_use_case_mgr_close(ucm->ucm_mgr); ucm->ucm_mgr = NULL; + free(ucm->alibpref); + ucm->alibpref = NULL; } ucm_mgr_fail: @@ -1521,6 +1525,12 @@ static void alsa_mapping_add_ucm_modifier(pa_alsa_mapping *m, pa_alsa_ucm_modifi pa_channel_map_init(&m->channel_map); } +static const char *ucm_strip(pa_alsa_ucm_config *ucm, const char *dev) { + if (ucm->alibpref != NULL && pa_startswith(dev, ucm->alibpref)) + return dev + strlen(ucm->alibpref); + return dev; +} + static int ucm_create_mapping_direction( pa_alsa_ucm_config *ucm, pa_alsa_profile_set *ps, @@ -1535,7 +1545,8 @@ static int ucm_create_mapping_direction( char *mapping_name; unsigned priority, rate, channels; - mapping_name = pa_sprintf_malloc("Mapping %s: %s: %s", verb_name, device_str, is_sink ? "sink" : "source"); + mapping_name = pa_sprintf_malloc("Mapping %s: %s: %s", verb_name, + ucm_strip(ucm, device_str), is_sink ? "sink" : "source"); m = pa_alsa_mapping_get(ps, mapping_name); if (!m) { @@ -1591,7 +1602,8 @@ static int ucm_create_mapping_for_modifier( pa_alsa_mapping *m; char *mapping_name; - mapping_name = pa_sprintf_malloc("Mapping %s: %s: %s", verb_name, device_str, is_sink ? "sink" : "source"); + mapping_name = pa_sprintf_malloc("Mapping %s: %s: %s", verb_name, + ucm_strip(ucm, device_str), is_sink ? "sink" : "source"); m = pa_alsa_mapping_get(ps, mapping_name); if (!m) { @@ -2122,6 +2134,8 @@ void pa_alsa_ucm_free(pa_alsa_ucm_config *ucm) { snd_use_case_mgr_close(ucm->ucm_mgr); ucm->ucm_mgr = NULL; } + free(ucm->alibpref); + ucm->alibpref = NULL; } void pa_alsa_ucm_mapping_context_free(pa_alsa_ucm_mapping_context *context) { diff --git a/spa/plugins/alsa/acp/alsa-ucm.h b/spa/plugins/alsa/acp/alsa-ucm.h index 2e7a885cf..0d2102800 100644 --- a/spa/plugins/alsa/acp/alsa-ucm.h +++ b/spa/plugins/alsa/acp/alsa-ucm.h @@ -263,6 +263,8 @@ struct pa_alsa_ucm_config { pa_hashmap *mixers; PA_LLIST_HEAD(pa_alsa_ucm_verb, verbs); PA_LLIST_HEAD(pa_alsa_jack, jacks); + + char *alibpref; }; struct pa_alsa_ucm_mapping_context {