]> code.delx.au - pulseaudio/commitdiff
alsa-ucm: Make combination ports have lower priority
authorDavid Henningsson <david.henningsson@canonical.com>
Fri, 19 Jul 2013 14:38:16 +0000 (16:38 +0200)
committerDavid Henningsson <david.henningsson@canonical.com>
Fri, 26 Jul 2013 12:30:08 +0000 (14:30 +0200)
Usually, you want to use one input or output at a time: e g,
you expect your speaker to mute when you plug in headphones.

Therefore, the headphones+speaker port should have lower priority
and both headphones and speaker.

A practical formula to do this is 1/x = 1/xa + 1/xb + .. + 1/xn.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
src/modules/alsa/alsa-ucm.c

index 9205cdf77e7b7ba2366cde82405541bfc488a45a..0fa26953346b29c68c420ef5c68b95d6582f280e 100644 (file)
@@ -655,6 +655,7 @@ static void ucm_add_port_combination(
     pa_device_port *port;
     int i;
     unsigned priority;
+    double prio2;
     char *name, *desc;
     const char *dev_name;
     const char *direction;
@@ -668,6 +669,7 @@ static void ucm_add_port_combination(
             : pa_sprintf_malloc("Combination port for %s", dev_name);
 
     priority = is_sink ? dev->playback_priority : dev->capture_priority;
+    prio2 = (priority == 0 ? 0 : 1.0/priority);
 
     for (i = 1; i < num; i++) {
         char *tmp;
@@ -683,10 +685,19 @@ static void ucm_add_port_combination(
         pa_xfree(desc);
         desc = tmp;
 
-        /* FIXME: Is this true? */
-        priority += (is_sink ? dev->playback_priority : dev->capture_priority);
+        priority = is_sink ? dev->playback_priority : dev->capture_priority;
+        if (priority != 0 && prio2 > 0)
+            prio2 += 1.0/priority;
     }
 
+    /* Make combination ports always have lower priority, and use the formula
+       1/p = 1/p1 + 1/p2 + ... 1/pn.
+       This way, the result will always be less than the individual components,
+       yet higher components will lead to higher result. */
+
+    if (num > 1)
+        priority = prio2 > 0 ? 1.0/prio2 : 0;
+
     port = pa_hashmap_get(ports, name);
     if (!port) {
         pa_device_port_new_data port_data;