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

Submitted by João Paulo Rechi Vita on Aug. 8, 2018, 5 a.m.

Details

Message ID 20180808050052.32327-3-jprvita@endlessm.com
State New
Series "Audio routing fixes and improvements"
Headers show

Commit Message

João Paulo Rechi Vita Aug. 8, 2018, 5 a.m.
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(-)

Patch hide | download patch | download mbox

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;

Comments

Tanu Kaskinen Oct. 3, 2018, 10:22 a.m.
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;
João Paulo Rechi Vita Oct. 6, 2018, 1:26 a.m.
On Wed, Oct 3, 2018 at 3:22 AM Tanu Kaskinen <tanuk@iki.fi> wrote:
>
> 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.
>

Previously if there was an active port with higher priority than the
port we were trying to switch to and availability YES or UNKNOWN, we
would avoid switching away from the active port to the new port. The
idea is to reduce the preference given to the active port to only when
it has higher priority than the port we were trying to switch to and
availability YES only. The rationale is that since a port with
availability UNKNOWN might not really be available, we shouldn't avoid
the port switching in that case.

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

My idea is that unless a port has been manually selected by the user
at some point in time, it should always follow the priorities defined
in mixer paths files. In both cases you described headphones should
win since the have the higher priority. Notice that the change does
not blindly choose the active profile if it is active and has a YES
port, it simply adds it to the list of profiles that would be
considered, but it still has to have the higher priority by the end of
the loop (which gives a bonus to preferred profile).

So unless I'm missing something or mixing up concepts, despite the
order of connection, if you connect both HDMI and headphones, the
headphones will always be preferred because the have higher priority
(assuming no manual choices were made at any point).

This is consistent with the results I got when testing this, but at
this point is important to say we actually change the ports priorities
downstream to give external devices a higher priority:
https://github.com/endlessm/pulseaudio/commit/40d00e72f74b2177ebead548427debadd6d1c05e.
I believe it should still work the same way for the HDMI+HP case we
are discussing, but I'm now not so sure if we will end up with
Speakers always winning with the upstream priorities. Actually,
probably this commit should have been left for a separate series,
together with the one pointed by the link above. I'll re-organize
things a bit and re-send -- should RFCs continue to be sent to the
list, or should they also be submitted though a gitlab MR?

Thanks for the feedback!

--
João Paulo Rechi Vita
http://about.me/jprvita
Tanu Kaskinen Oct. 7, 2018, 7:45 a.m.
On Fri, 2018-10-05 at 18:26 -0700, João Paulo Rechi Vita wrote:
> On Wed, Oct 3, 2018 at 3:22 AM Tanu Kaskinen <tanuk@iki.fi> wrote:
> > 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.
> > 
> 
> Previously if there was an active port with higher priority than the
> port we were trying to switch to and availability YES or UNKNOWN, we
> would avoid switching away from the active port to the new port. The
> idea is to reduce the preference given to the active port to only when
> it has higher priority than the port we were trying to switch to and
> availability YES only. The rationale is that since a port with
> availability UNKNOWN might not really be available, we shouldn't avoid
> the port switching in that case.

I probably didn't make my point clear enough. The patch considers also
ports that are *not active* if they are part of the active profile.
This is the thing that doesn't make sense to me. To me it seems that
only active ports should be considered.

As for ignoring currently active ports with UNKNOWN status - that
doesn't seem like a good idea either. If the port is active, it's very
likely that it's also available, because otherwise the user would have
switched to something else. Is there some real use case where treating
UNKNOWN and YES statuses as the same has caused problems?

> > > 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).
> > 
> 
> My idea is that unless a port has been manually selected by the user
> at some point in time, it should always follow the priorities defined
> in mixer paths files. In both cases you described headphones should
> win since the have the higher priority. Notice that the change does
> not blindly choose the active profile if it is active and has a YES
> port, it simply adds it to the list of profiles that would be
> considered, but it still has to have the higher priority by the end of
> the loop (which gives a bonus to preferred profile).
> 
> So unless I'm missing something or mixing up concepts, despite the
> order of connection, if you connect both HDMI and headphones, the
> headphones will always be preferred because the have higher priority
> (assuming no manual choices were made at any point).

My example may have been bad, because I didn't consider that the active
profile with the headphone port may have higher priority than any of
the potential HDMI profiles. However, we shouldn't be comparing profile
priorities anyway when deciding between headphones and HDMI, we should
compare the port priorities. Your patch removed the only place where
port priorities are compared.

A better example about the special nature of HDMI would be S/PDIF
instead of headphones. S/PDIF has lower priority than HDMI, but we
still shouldn't switch from S/PDIF to HDMI automatically if the user
hasn't chosen HDMI before. In my opinion we should never switch to HDMI
automatically before the user has indicated that they want to use HDMI
for audio. We don't know if the HDMI monitor has audio capabilities, or
it may only have headphone output. If we switch to it automatically, in
some cases it will look like audio stopped working altogether, which is
pretty bad.

Regarding your example of an HDMI monitor being used while headphones
are plugged in: I agree that switching to headphones makes sense, but
now that I read the patch again, it seems that this case should have
been working already. The patch removed this code from
profile_good_for_output():

    if ((sink->active_port->available != PA_AVAILABLE_NO) && (sink->active_port->priority >= port->priority))
        return false;

That code doesn't prevent the switch to headphones, because the
headphone port has higher priority than the HDMI port.

> This is consistent with the results I got when testing this, but at
> this point is important to say we actually change the ports priorities
> downstream to give external devices a higher priority:
> https://github.com/endlessm/pulseaudio/commit/40d00e72f74b2177ebead548427debadd6d1c05e.
> I believe it should still work the same way for the HDMI+HP case we
> are discussing, but I'm now not so sure if we will end up with
> Speakers always winning with the upstream priorities.

Yes, the port priorities are not set up as good as they should.
Speakers shouldn't be the highest-priority port. That problem is
mitigated to a large extent by marking speakers unavailable when
headphones or lineout is plugged in, but that's not really ideal.

The priority order of ports should actually depend on whether they have
jack detection support or not. Speakers should have higher priority
than external ports without jack detection, but lower priority than
external ports with jack detection.

> Actually,
> probably this commit should have been left for a separate series,
> together with the one pointed by the link above. I'll re-organize
> things a bit and re-send -- should RFCs continue to be sent to the
> list, or should they also be submitted though a gitlab MR?

I guess the mailing list makes sense if you hope to get comments from a
larger audience. If you just want comments from the maintainers, then
MRs are better. Either is fine for me.
João Paulo Rechi Vita Nov. 21, 2018, 7:43 p.m.
Hello Tanu! Sorry it took me so long to get back on this issue, but I
was busy with some urgent things lately. Please find my reply in-line
below.

On Sun, Oct 7, 2018 at 12:46 AM Tanu Kaskinen <tanuk@iki.fi> wrote:
>
> On Fri, 2018-10-05 at 18:26 -0700, João Paulo Rechi Vita wrote:
> > On Wed, Oct 3, 2018 at 3:22 AM Tanu Kaskinen <tanuk@iki.fi> wrote:
> > > 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.
> > >
> >
> > Previously if there was an active port with higher priority than the
> > port we were trying to switch to and availability YES or UNKNOWN, we
> > would avoid switching away from the active port to the new port. The
> > idea is to reduce the preference given to the active port to only when
> > it has higher priority than the port we were trying to switch to and
> > availability YES only. The rationale is that since a port with
> > availability UNKNOWN might not really be available, we shouldn't avoid
> > the port switching in that case.
>
> I probably didn't make my point clear enough. The patch considers also
> ports that are *not active* if they are part of the active profile.
> This is the thing that doesn't make sense to me. To me it seems that
> only active ports should be considered.
>

It looks like I got a bit confused on my previous reply to this -- I
agree with your point here.

> As for ignoring currently active ports with UNKNOWN status - that
> doesn't seem like a good idea either. If the port is active, it's very
> likely that it's also available, because otherwise the user would have
> switched to something else. Is there some real use case where treating
> UNKNOWN and YES statuses as the same has caused problems?
>

IIRC this was to solve a problem on a machine without internal
speakers and only headphones and HDMI ports, where HDMI availability
was always UNKNOWN despite the cable being connected or not. Since it
was the higher priority port with availability != NO it would be
selected when no headphones were connected. Later when connecting
headphones the audio would not be routed to headphones since the
currently active port had availability UNKNOWN.

I can't reproduce it anymore though, and this commit has been carried
over for a couple of years now, so we can probably ignore it. I'll
drop it downstream and if we find any problems I'll come back with a
better informed proposal :)

> > > > 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).
> > >
> >
> > My idea is that unless a port has been manually selected by the user
> > at some point in time, it should always follow the priorities defined
> > in mixer paths files. In both cases you described headphones should
> > win since the have the higher priority. Notice that the change does
> > not blindly choose the active profile if it is active and has a YES
> > port, it simply adds it to the list of profiles that would be
> > considered, but it still has to have the higher priority by the end of
> > the loop (which gives a bonus to preferred profile).
> >
> > So unless I'm missing something or mixing up concepts, despite the
> > order of connection, if you connect both HDMI and headphones, the
> > headphones will always be preferred because the have higher priority
> > (assuming no manual choices were made at any point).
>
> My example may have been bad, because I didn't consider that the active
> profile with the headphone port may have higher priority than any of
> the potential HDMI profiles. However, we shouldn't be comparing profile
> priorities anyway when deciding between headphones and HDMI, we should
> compare the port priorities. Your patch removed the only place where
> port priorities are compared.
>
> A better example about the special nature of HDMI would be S/PDIF
> instead of headphones. S/PDIF has lower priority than HDMI, but we
> still shouldn't switch from S/PDIF to HDMI automatically if the user
> hasn't chosen HDMI before. In my opinion we should never switch to HDMI
> automatically before the user has indicated that they want to use HDMI
> for audio. We don't know if the HDMI monitor has audio capabilities, or
> it may only have headphone output. If we switch to it automatically, in
> some cases it will look like audio stopped working altogether, which is
> pretty bad.
>
> Regarding your example of an HDMI monitor being used while headphones
> are plugged in: I agree that switching to headphones makes sense, but
> now that I read the patch again, it seems that this case should have
> been working already. The patch removed this code from
> profile_good_for_output():
>
>     if ((sink->active_port->available != PA_AVAILABLE_NO) && (sink->active_port->priority >= port->priority))
>         return false;
>
> That code doesn't prevent the switch to headphones, because the
> headphone port has higher priority than the HDMI port.
>

Yes, I guess this bit has changed since then. This was part of a big
downstream refactor and an attempt to upstream as much of our fixes as
possible, and I let this slip through.

> > This is consistent with the results I got when testing this, but at
> > this point is important to say we actually change the ports priorities
> > downstream to give external devices a higher priority:
> > https://github.com/endlessm/pulseaudio/commit/40d00e72f74b2177ebead548427debadd6d1c05e.
> > I believe it should still work the same way for the HDMI+HP case we
> > are discussing, but I'm now not so sure if we will end up with
> > Speakers always winning with the upstream priorities.
>
> Yes, the port priorities are not set up as good as they should.
> Speakers shouldn't be the highest-priority port. That problem is
> mitigated to a large extent by marking speakers unavailable when
> headphones or lineout is plugged in, but that's not really ideal.
>
> The priority order of ports should actually depend on whether they have
> jack detection support or not. Speakers should have higher priority
> than external ports without jack detection, but lower priority than
> external ports with jack detection.
>

Is there a way to specify that in the paths files?

> > Actually,
> > probably this commit should have been left for a separate series,
> > together with the one pointed by the link above. I'll re-organize
> > things a bit and re-send -- should RFCs continue to be sent to the
> > list, or should they also be submitted though a gitlab MR?
>
> I guess the mailing list makes sense if you hope to get comments from a
> larger audience. If you just want comments from the maintainers, then
> MRs are better. Either is fine for me.
>

Thanks for the throughout review, and sorry for wasting your time with
an unnecessary patch.

--
João Paulo Rechi Vita
http://about.me/jprvita
Tanu Kaskinen Nov. 22, 2018, 9:17 a.m.
On Wed, 2018-11-21 at 11:43 -0800, João Paulo Rechi Vita wrote:
> Hello Tanu! Sorry it took me so long to get back on this issue, but I
> was busy with some urgent things lately. Please find my reply in-line
> below.

No problem!

> On Sun, Oct 7, 2018 at 12:46 AM Tanu Kaskinen <tanuk@iki.fi> wrote:
> > On Fri, 2018-10-05 at 18:26 -0700, João Paulo Rechi Vita wrote:
> > > This is consistent with the results I got when testing this, but at
> > > this point is important to say we actually change the ports priorities
> > > downstream to give external devices a higher priority:
> > > https://github.com/endlessm/pulseaudio/commit/40d00e72f74b2177ebead548427debadd6d1c05e.
> > > I believe it should still work the same way for the HDMI+HP case we
> > > are discussing, but I'm now not so sure if we will end up with
> > > Speakers always winning with the upstream priorities.
> > 
> > Yes, the port priorities are not set up as good as they should.
> > Speakers shouldn't be the highest-priority port. That problem is
> > mitigated to a large extent by marking speakers unavailable when
> > headphones or lineout is plugged in, but that's not really ideal.
> > 
> > The priority order of ports should actually depend on whether they have
> > jack detection support or not. Speakers should have higher priority
> > than external ports without jack detection, but lower priority than
> > external ports with jack detection.
> > 
> 
> Is there a way to specify that in the paths files?

No, otherwise this probably would have been fixed already :)

I'm not sure how the fix should be implemented. Maybe the simplest fix
would be to have two priority values for each path. One would be used
when the path has jack detection support and the other when the path
doesn't support jack detection. But perhaps it would be better to not
have very complex policy rules embedded in the path configuration,
because policy decisions don't really belong in the hardware
description.

I'd like to have a lookup table for mapping an output device type to
its priority (and of course another table for input device types).
Currently it's very cumbersome to try to get an overview of how the
different alsa paths relate to each other in terms of priority, and
that's only alsa, trying to figure out how other outputs rank is even
harder. The table that I envision would be generic (not specific to
alsa or any other backend), and as fine-grained as necessary. There
would be entries not only for simple stuff like "headphones",
"speakers" and "hdmi", but distinction would be made between outputs
that support or don't support jack detection, integrated or external
speakers etc., whatever is relevant for building a complete ranking of
all different kinds of outputs that we support (and can distinguish).
The backend (e.g. alsa) would either directly set the device type, or
provide a generic metadata structure that a generic function could use
to map the metadata into the device type identifier (the latter option
seems better, because it probably reduces duplication of work between
the backends, and the metadata could be useful for policy modules).

Making that table reconfigurable by users or policy modules would be
desirable, but the first step would be to just have such table.