[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] 2 commits: alsa-ucm: Add enable, disable, status helpers for modifiers
PulseAudio Marge Bot (@pulseaudio-merge-bot)
gitlab at gitlab.freedesktop.org
Sun Mar 19 20:53:07 UTC 2023
PulseAudio Marge Bot pushed to branch master at PulseAudio / pulseaudio
Commits:
b382a00f by Alper Nebi Yasak at 2023-03-19T20:51:00+00:00
alsa-ucm: Add enable, disable, status helpers for modifiers
These are mostly the same as the device helpers added in c83b34516929
("alsa-ucm: Add enable, disable, status helpers for devices"), but for
modifiers instead.
Signed-off-by: Alper Nebi Yasak <alpernebiyasak at gmail.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/742>
- - - - -
b7426901 by Alper Nebi Yasak at 2023-03-19T20:51:00+00:00
alsa-ucm: Disable old modifiers when switching profiles of same verb
While switching profiles of the same UCM verb, existing code first
disables devices that are only on the first profile to avoid conflicts.
However, it only disables devices, not modifiers. Even worse, modifiers
which have PlaybackPCM/CapturePCM are incorrectly treated as devices and
result in a segmentation fault.
Check what we are disabling, and call the appropriate disable function
for both devices and modifiers. Modifiers are disabled before devices,
because _dismod calls fail when the modifier's supported devices are
disabled.
Signed-off-by: Alper Nebi Yasak <alpernebiyasak at gmail.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/742>
- - - - -
1 changed file:
- src/modules/alsa/alsa-ucm.c
Changes:
=====================================
src/modules/alsa/alsa-ucm.c
=====================================
@@ -702,6 +702,57 @@ static int ucm_get_modifiers(pa_alsa_ucm_verb *verb, snd_use_case_mgr_t *uc_mgr)
return 0;
};
+static long ucm_modifier_status(pa_alsa_ucm_config *ucm, pa_alsa_ucm_modifier *mod) {
+ const char *mod_name = pa_proplist_gets(mod->proplist, PA_ALSA_PROP_UCM_NAME);
+ char *modstatus;
+ long status = 0;
+
+ modstatus = pa_sprintf_malloc("_modstatus/%s", mod_name);
+ if (snd_use_case_geti(ucm->ucm_mgr, modstatus, &status) < 0) {
+ pa_log_debug("Failed to get status for UCM modifier %s", mod_name);
+ status = -1;
+ }
+ pa_xfree(modstatus);
+
+ return status;
+}
+
+static int ucm_modifier_disable(pa_alsa_ucm_config *ucm, pa_alsa_ucm_modifier *mod) {
+ const char *mod_name = pa_proplist_gets(mod->proplist, PA_ALSA_PROP_UCM_NAME);
+
+ /* We don't need to disable modifiers that are already disabled */
+ if (ucm_modifier_status(ucm, mod) == 0) {
+ pa_log_debug("UCM modifier %s is already disabled", mod_name);
+ return 0;
+ }
+
+ pa_log_debug("Disabling UCM modifier %s", mod_name);
+ if (snd_use_case_set(ucm->ucm_mgr, "_dismod", mod_name) < 0) {
+ pa_log("Failed to disable UCM modifier %s", mod_name);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int ucm_modifier_enable(pa_alsa_ucm_config *ucm, pa_alsa_ucm_modifier *mod) {
+ const char *mod_name = pa_proplist_gets(mod->proplist, PA_ALSA_PROP_UCM_NAME);
+
+ /* We don't need to enable modifiers that are already enabled */
+ if (ucm_modifier_status(ucm, mod) > 0) {
+ pa_log_debug("UCM modifier %s is already enabled", mod_name);
+ return 0;
+ }
+
+ pa_log_debug("Enabling UCM modifier %s", mod_name);
+ if (snd_use_case_set(ucm->ucm_mgr, "_enamod", mod_name) < 0) {
+ pa_log("Failed to enable UCM modifier %s", mod_name);
+ return -1;
+ }
+
+ return 0;
+}
+
static void add_role_to_device(pa_alsa_ucm_device *dev, const char *dev_name, const char *role_name, const char *role) {
const char *cur = pa_proplist_gets(dev->proplist, role_name);
@@ -1447,15 +1498,28 @@ int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, pa_card *card, pa_alsa_prof
}
} else if (ucm->active_verb) {
+ /* Disable modifiers not in new profile. Has to be done before
+ * devices, because _dismod fails if a modifier's supported
+ * devices are disabled. */
+ PA_IDXSET_FOREACH(map, old_profile->input_mappings, idx)
+ if (new_profile && !pa_idxset_contains(new_profile->input_mappings, map))
+ if (map->ucm_context.ucm_modifier && ucm_modifier_disable(ucm, map->ucm_context.ucm_modifier) < 0)
+ ret = -1;
+
+ PA_IDXSET_FOREACH(map, old_profile->output_mappings, idx)
+ if (new_profile && !pa_idxset_contains(new_profile->output_mappings, map))
+ if (map->ucm_context.ucm_modifier && ucm_modifier_disable(ucm, map->ucm_context.ucm_modifier) < 0)
+ ret = -1;
+
/* Disable devices not in new profile */
PA_IDXSET_FOREACH(map, old_profile->input_mappings, idx)
if (new_profile && !pa_idxset_contains(new_profile->input_mappings, map))
- if (ucm_device_disable(ucm, map->ucm_context.ucm_device) < 0)
+ if (map->ucm_context.ucm_device && ucm_device_disable(ucm, map->ucm_context.ucm_device) < 0)
ret = -1;
PA_IDXSET_FOREACH(map, old_profile->output_mappings, idx)
if (new_profile && !pa_idxset_contains(new_profile->output_mappings, map))
- if (ucm_device_disable(ucm, map->ucm_context.ucm_device) < 0)
+ if (map->ucm_context.ucm_device && ucm_device_disable(ucm, map->ucm_context.ucm_device) < 0)
ret = -1;
}
ucm->active_verb = verb;
@@ -2298,12 +2362,7 @@ void pa_alsa_ucm_roled_stream_begin(pa_alsa_ucm_config *ucm, const char *role, p
PA_LLIST_FOREACH(mod, ucm->active_verb->modifiers) {
if ((mod->action_direction == dir) && (pa_streq(mod->media_role, role))) {
if (mod->enabled_counter == 0) {
- const char *mod_name = pa_proplist_gets(mod->proplist, PA_ALSA_PROP_UCM_NAME);
-
- pa_log_info("Enable ucm modifier %s", mod_name);
- if (snd_use_case_set(ucm->ucm_mgr, "_enamod", mod_name) < 0) {
- pa_log("Failed to enable ucm modifier %s", mod_name);
- }
+ ucm_modifier_enable(ucm, mod);
}
mod->enabled_counter++;
@@ -2323,14 +2382,8 @@ void pa_alsa_ucm_roled_stream_end(pa_alsa_ucm_config *ucm, const char *role, pa_
if ((mod->action_direction == dir) && (pa_streq(mod->media_role, role))) {
mod->enabled_counter--;
- if (mod->enabled_counter == 0) {
- const char *mod_name = pa_proplist_gets(mod->proplist, PA_ALSA_PROP_UCM_NAME);
-
- pa_log_info("Disable ucm modifier %s", mod_name);
- if (snd_use_case_set(ucm->ucm_mgr, "_dismod", mod_name) < 0) {
- pa_log("Failed to disable ucm modifier %s", mod_name);
- }
- }
+ if (mod->enabled_counter == 0)
+ ucm_modifier_disable(ucm, mod);
break;
}
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/3aaeb5113d2cec907bd101df22bb28b1a1b8394d...b74269016c1f7babcdd69d33f20cedbe33fe3124
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/3aaeb5113d2cec907bd101df22bb28b1a1b8394d...b74269016c1f7babcdd69d33f20cedbe33fe3124
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20230319/8a3a8068/attachment-0001.htm>
More information about the pulseaudio-commits
mailing list