[pulseaudio-discuss] [RFC PATCH 2/4] switch-on-port-available: Change criteria for keeping the active profile

João Paulo Rechi Vita jprvita at gmail.com
Wed Aug 8 05:00:50 UTC 2018


Prefer the active profile only if it has ports with available status YES
on the same direction of the port we are trying to switch to and a
higher priority than whichever profile we would select to switch to a
new port.

This patch removes the code that ensures that no profile switching will
happen when a new port is available if the currently active port's
available state is YES or UNKNOWN, for example when you have the
computer permanently plugged to a HDMI device with audio capabilities
and plug something on the headphones port.

In place of that code it adds new code to prefer the currently active
profile if it has at least one port with available state YES on the same
direction of the new available port and a higher priority than the
profile that would be selected to switch to this new port.

This was built uppon previous work by Mario Sanchez Prada.
---
 src/modules/module-switch-on-port-available.c | 32 +++++++------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c
index 385c2f693..d02100c58 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -64,8 +64,6 @@ static void card_info_free(struct card_info *info) {
 
 static bool profile_good_for_output(pa_card_profile *profile, pa_device_port *port) {
     pa_card *card;
-    pa_sink *sink;
-    uint32_t idx;
 
     pa_assert(profile);
 
@@ -83,21 +81,11 @@ static bool profile_good_for_output(pa_card_profile *profile, pa_device_port *po
     if (port == card->preferred_output_port)
         return true;
 
-    PA_IDXSET_FOREACH(sink, card->sinks, idx) {
-        if (!sink->active_port)
-            continue;
-
-        if ((sink->active_port->available != PA_AVAILABLE_NO) && (sink->active_port->priority >= port->priority))
-            return false;
-    }
-
     return true;
 }
 
 static bool profile_good_for_input(pa_card_profile *profile, pa_device_port *port) {
     pa_card *card;
-    pa_source *source;
-    uint32_t idx;
 
     pa_assert(profile);
 
@@ -115,14 +103,6 @@ static bool profile_good_for_input(pa_card_profile *profile, pa_device_port *por
     if (port == card->preferred_input_port)
         return true;
 
-    PA_IDXSET_FOREACH(source, card->sources, idx) {
-        if (!source->active_port)
-            continue;
-
-        if ((source->active_port->available != PA_AVAILABLE_NO) && (source->active_port->priority >= port->priority))
-            return false;
-    }
-
     return true;
 }
 
@@ -134,6 +114,13 @@ static int try_to_switch_profile(pa_device_port *port) {
     pa_log_debug("Finding best profile for port %s, preferred = %s",
                  port->name, pa_strnull(port->preferred_profile));
 
+    /* Prefer the current active profile if it has available ports on the same direction
+     * of the port we are trying to switch to and a higher priority */
+    if (pa_card_profile_has_available_ports(port->card->active_profile, port->direction, PA_AVAILABLE_YES)) {
+        best_profile = port->card->active_profile;
+        best_prio = port->card->active_profile->priority;
+    }
+
     PA_HASHMAP_FOREACH(profile, port->profiles, state) {
         bool good = false;
         const char *name;
@@ -171,6 +158,11 @@ static int try_to_switch_profile(pa_device_port *port) {
         return -1;
     }
 
+    if (best_profile == port->card->active_profile) {
+        pa_log_debug("No better profile found");
+        return -1;
+    }
+
     if (pa_card_set_profile(port->card, best_profile, false) != 0) {
         pa_log_debug("Could not set profile %s", best_profile->name);
         return -1;
-- 
2.18.0



More information about the pulseaudio-discuss mailing list