[3/3] core: prefer available devices during default source/sink selection

Submitted by Georg Chini on April 9, 2018, 6:38 p.m.

Details

Message ID 20180409183826.18593-4-georg@chini.tk
State New
Series "card: Add messages to control jack detection"
Headers show

Commit Message

Georg Chini April 9, 2018, 6:38 p.m.
Because ports with disabled jack detection are set to availability
unknown by default, available ports should be preferred over ports
with unknown availability.
---
 src/pulsecore/core.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index acd47cbb..8c074afe 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -325,7 +325,15 @@  static int compare_sinks(pa_sink *a, pa_sink *b) {
 
     core = a->core;
 
-    /* Available sinks always beat unavailable sinks. */
+    /* Available sinks always beat sinks with unknown availability. */
+    if ((!a->active_port || a->active_port->available <= PA_AVAILABLE_UNKNOWN)
+            && b->active_port && b->active_port->available == PA_AVAILABLE_YES)
+        return -1;
+    if ((!b->active_port || b->active_port->available <= PA_AVAILABLE_UNKNOWN)
+            && a->active_port && a->active_port->available == PA_AVAILABLE_YES)
+        return 1;
+
+    /* Possibly available sinks always beat unavailable sinks. */
     if (a->active_port && a->active_port->available == PA_AVAILABLE_NO
             && (!b->active_port || b->active_port->available != PA_AVAILABLE_NO))
         return -1;
@@ -402,7 +410,15 @@  static int compare_sources(pa_source *a, pa_source *b) {
 
     core = a->core;
 
-    /* Available sources always beat unavailable sources. */
+    /* Available sources always beat sources with unknown availability. */
+    if ((!a->active_port || a->active_port->available <= PA_AVAILABLE_UNKNOWN)
+            && b->active_port && b->active_port->available == PA_AVAILABLE_YES)
+        return -1;
+    if ((!b->active_port || b->active_port->available <= PA_AVAILABLE_UNKNOWN)
+            && a->active_port && a->active_port->available == PA_AVAILABLE_YES)
+        return 1;
+
+    /* Possibly available sources always beat unavailable sources. */
     if (a->active_port && a->active_port->available == PA_AVAILABLE_NO
             && (!b->active_port || b->active_port->available != PA_AVAILABLE_NO))
         return -1;