From 4d08c9ad609d47c16d03ae3d5230c14d8d52f49e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Mar 2023 15:13:41 +0100 Subject: [PATCH] alsa-ucm: Set profiles by their struct instance, not their name While switching profiles, it's possible that we will want to do more work besides switching UCM verbs. The alsa-card module already has our profiles as structs, but passes in only the names instead of the entire struct. Make things work with the struct instead, so we can add other things (like a UCM context) to it and use those here. Co-authored-by: Tanu Kaskinen [Alper: Split into its own commit and integrated Tanu's snippet.] Signed-off-by: Alper Nebi Yasak --- spa/plugins/alsa/acp/acp.c | 3 +-- spa/plugins/alsa/acp/alsa-ucm.c | 15 +++++++-------- spa/plugins/alsa/acp/alsa-ucm.h | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/spa/plugins/alsa/acp/acp.c b/spa/plugins/alsa/acp/acp.c index a48e3eed9..d96ab725c 100644 --- a/spa/plugins/alsa/acp/acp.c +++ b/spa/plugins/alsa/acp/acp.c @@ -1429,8 +1429,7 @@ int acp_card_set_profile(struct acp_card *card, uint32_t new_index, uint32_t fla /* if UCM is available for this card then update the verb */ if (impl->use_ucm && !(np->profile.flags & ACP_PROFILE_PRO)) { if ((res = pa_alsa_ucm_set_profile(&impl->ucm, impl, - np->profile.flags & ACP_PROFILE_OFF ? NULL : np->profile.name, - op ? op->profile.name : NULL)) < 0) { + np->profile.flags & ACP_PROFILE_OFF ? NULL : np, op)) < 0) { return res; } } diff --git a/spa/plugins/alsa/acp/alsa-ucm.c b/spa/plugins/alsa/acp/alsa-ucm.c index 53f9c4894..af982e96c 100644 --- a/spa/plugins/alsa/acp/alsa-ucm.c +++ b/spa/plugins/alsa/acp/alsa-ucm.c @@ -1418,19 +1418,18 @@ void pa_alsa_ucm_add_ports( } /* Change UCM verb and device to match selected card profile */ -int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, pa_card *card, const char *new_profile, const char *old_profile) { +int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, pa_card *card, pa_alsa_profile *new_profile, pa_alsa_profile *old_profile) { int ret = 0; const char *profile; pa_alsa_ucm_verb *verb; if (new_profile == old_profile) - return ret; - else if (new_profile == NULL || old_profile == NULL) - profile = new_profile ? new_profile : SND_USE_CASE_VERB_INACTIVE; - else if (!pa_streq(new_profile, old_profile)) - profile = new_profile; + return 0; + + if (new_profile == NULL) + profile = SND_USE_CASE_VERB_INACTIVE; else - return ret; + profile = new_profile->name; /* change verb */ pa_log_info("Set UCM verb to %s", profile); @@ -2420,7 +2419,7 @@ pa_alsa_profile_set* pa_alsa_ucm_add_profile_set(pa_alsa_ucm_config *ucm, pa_cha return NULL; } -int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, pa_card *card, const char *new_profile, const char *old_profile) { +int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, pa_card *card, pa_alsa_profile *new_profile, pa_alsa_profile *old_profile) { return -1; } diff --git a/spa/plugins/alsa/acp/alsa-ucm.h b/spa/plugins/alsa/acp/alsa-ucm.h index 0914e15ae..dd1694de6 100644 --- a/spa/plugins/alsa/acp/alsa-ucm.h +++ b/spa/plugins/alsa/acp/alsa-ucm.h @@ -147,7 +147,7 @@ typedef struct pa_alsa_ucm_volume pa_alsa_ucm_volume; int pa_alsa_ucm_query_profiles(pa_alsa_ucm_config *ucm, int card_index); pa_alsa_profile_set* pa_alsa_ucm_add_profile_set(pa_alsa_ucm_config *ucm, pa_channel_map *default_channel_map); -int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, pa_card *card, const char *new_profile, const char *old_profile); +int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, pa_card *card, pa_alsa_profile *new_profile, pa_alsa_profile *old_profile); int pa_alsa_ucm_get_verb(snd_use_case_mgr_t *uc_mgr, const char *verb_name, const char *verb_desc, pa_alsa_ucm_verb **p_verb);