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
This commit is contained in:
Arun Raghavan 2020-10-30 15:01:19 -04:00 committed by Arun Raghavan
parent 323195e305
commit d83ad6990e
2 changed files with 36 additions and 2 deletions

View file

@ -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) { static void set_card_name(pa_card_new_data *data, pa_modargs *ma, const char *device_id) {
char *t; char *t;
const char *n; const char *n;
@ -924,6 +958,7 @@ int pa__init(pa_module *m) {
} }
add_disabled_profile(data.profiles); 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) { if (pa_modargs_get_proplist(u->modargs, "card_properties", data.proplist, PA_UPDATE_REPLACE) < 0) {
pa_log("Invalid properties"); pa_log("Invalid properties");

View file

@ -240,8 +240,7 @@ typedef struct pa_sink_port_info {
* input from the user to determine which device was plugged in. The application should * input from the user to determine which device was plugged in. The application should
* then activate the user-chosen port. * then activate the user-chosen port.
* *
* May be NULL, in which case the port is not part of any availability group (which is * May be NULL, in which case the port is not part of any availability group.
* the same as having a group with only one member).
* *
* The group identifier must be treated as an opaque identifier. The string may look * 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. * like an ALSA control name, but applications must not assume any such relationship.