diff options
author | Arun Raghavan <arun@asymptotic.io> | 2020-10-30 15:01:19 -0400 |
---|---|---|
committer | Arun Raghavan <arun@arunraghavan.net> | 2020-11-17 16:38:56 +0000 |
commit | d83ad6990e4b383dd08311fd6135556ba84e5847 (patch) | |
tree | 4cc0062e9d695e0c77fe9af5dea23b71ad892784 | |
parent | 323195e305ce3bd0f183fc66a301b8ad6120e17f (diff) | |
download | pulseaudio-d83ad6990e4b383dd08311fd6135556ba84e5847.tar.gz |
module-alsa-card: Drop availability groups with only one port
These are not really meaningful, and can be confusing for clients.
Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/1022
-rw-r--r-- | src/modules/alsa/module-alsa-card.c | 35 | ||||
-rw-r--r-- | src/pulse/introspect.h | 3 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index 267d30c3b..a6f2e0d34 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -675,6 +675,40 @@ static void init_jacks(struct userdata *u) { } } +static void prune_singleton_availability_groups(pa_hashmap *ports) { + pa_device_port *p; + pa_hashmap *group_counts; + void *state, *count; + const char *group; + + /* Collect groups and erase those that don't have more than 1 path */ + group_counts = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); + + PA_HASHMAP_FOREACH(p, ports, state) { + if (p->availability_group) { + count = pa_hashmap_get(group_counts, p->availability_group); + pa_hashmap_remove(group_counts, p->availability_group); + pa_hashmap_put(group_counts, p->availability_group, count + 1); + } + } + + /* Now we have an availability_group -> count map, let's drop all groups + * that have only one member */ + PA_HASHMAP_FOREACH_KV(group, count, group_counts, state) { + if (count == PA_UINT_TO_PTR(1)) + pa_hashmap_remove(group_counts, group); + } + + PA_HASHMAP_FOREACH(p, ports, state) { + if (p->availability_group && !pa_hashmap_get(group_counts, p->availability_group)) { + pa_xfree(p->availability_group); + p->availability_group = NULL; + } + } + + pa_hashmap_free(group_counts); +} + static void set_card_name(pa_card_new_data *data, pa_modargs *ma, const char *device_id) { char *t; const char *n; @@ -924,6 +958,7 @@ int pa__init(pa_module *m) { } add_disabled_profile(data.profiles); + prune_singleton_availability_groups(data.ports); if (pa_modargs_get_proplist(u->modargs, "card_properties", data.proplist, PA_UPDATE_REPLACE) < 0) { pa_log("Invalid properties"); diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h index 8fff1ac77..c547bde09 100644 --- a/src/pulse/introspect.h +++ b/src/pulse/introspect.h @@ -240,8 +240,7 @@ typedef struct pa_sink_port_info { * input from the user to determine which device was plugged in. The application should * then activate the user-chosen port. * - * May be NULL, in which case the port is not part of any availability group (which is - * the same as having a group with only one member). + * May be NULL, in which case the port is not part of any availability group. * * The group identifier must be treated as an opaque identifier. The string may look * like an ALSA control name, but applications must not assume any such relationship. |