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

Tanu Kaskinen tanuk at iki.fi
Wed Oct 3 10:22:05 UTC 2018


On Tue, 2018-08-07 at 22:00 -0700, João Paulo Rechi Vita wrote:
> 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.

I don't really understand this logic. Not all ports with status YES on
a profile are necessarily active, and I don't see why inactive ports
should prevent switching away from the current profile.

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

So you want to switch to the headphones in that case? That's good, but
what if I have headphones plugged in and I plug in a HDMI monitor that
I don't want to use for sound? This patch breaks that use case.

I'm not sure what we should do. Maybe add some HDMI specific code, so
that when HDMI is plugged in, we switch to it only if the HDMI port is
the card's preferred port (which means that the user has previously
manually chosen the HDMI output).

> 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;
-- 
Tanu

https://www.patreon.com/tanuk
https://liberapay.com/tanuk



More information about the pulseaudio-discuss mailing list