[PATCH] alsa-ucm: Make combination ports have lower priority

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sounds reasonable.

-----Original Message-----
From: David Henningsson [mailto:david.henningsson@xxxxxxxxxxxxx] 
Sent: Thursday, July 25, 2013 11:47 PM
To: pulseaudio-discuss at lists.freedesktop.org
Cc: Feng Wei-B34248; David Henningsson
Subject: [PATCH] alsa-ucm: Make combination ports have lower priority

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 at canonical.com>
---
 src/modules/alsa/alsa-ucm.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c index 9205cdf..c38c5ba 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -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,9 +669,11 @@ 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;
+        priority = is_sink ? dev->playback_priority : 
+ dev->capture_priority;
 
         dev = pdevices[i];
         dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME); @@ -683,10 +686,15 @@ static void ucm_add_port_combination(
         pa_xfree(desc);
         desc = tmp;
 
-        /* FIXME: Is this true? */
-        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, use the formula
+       1/p = 1/p1 + 1/p2 + ... 1/pn. */
+    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;
--
1.7.9.5





[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux