[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] module-alsa-card: Drop availability groups with only one port

Arun Raghavan gitlab at gitlab.freedesktop.org
Tue Nov 17 17:09:01 UTC 2020



Arun Raghavan pushed to branch master at PulseAudio / pulseaudio


Commits:
d83ad699 by Arun Raghavan at 2020-11-17T16:38:56+00:00
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

- - - - -


2 changed files:

- src/modules/alsa/module-alsa-card.c
- src/pulse/introspect.h


Changes:

=====================================
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");


=====================================
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.



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/d83ad6990e4b383dd08311fd6135556ba84e5847

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/d83ad6990e4b383dd08311fd6135556ba84e5847
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/20201117/de432b6c/attachment-0001.htm>


More information about the pulseaudio-commits mailing list