switch-on-port-available: prefer ports that have been selected by the user
Let's assume that there are two output ports, and they are on
different profiles:
* Integrated speakers (priority: 10000, available)
* HDMI (priority: 5900, not available)
Then the user plugs in an HDMI monitor with speakers. Since the HDMI
priority is lower than the speaker priority, we don't route to HDMI by
default. However, the user manually switches the profile to use the
HDMI output.
Then the user plugs out the monitor, so we switch back to speakers.
When the monitor is plugged back in, the user needs to manually switch
the audio output again. That should be improved: if the user preferred
to the HDMI output over the speakers, we should remember that and
automatically switch to HDMI whenever it becomes available.
The lack of automatic switching is even worse when the monitor goes to
a sleep mode after some period of inactivity. The monitor audio may
become unavailable, and PulseAudio can't distinguish that from the
case where the monitor is physically unplugged. Even worse, the
monitor may become unavailable for a short while when adjusting the
display parameters (for example, media center software may adjust the
display parameters to match the media that is being played back). In
these cases we clearly should switch automatically back to HDMI when
it becomes available again.
This patch fixes the problem by setting pa_card.preferred_input_port
and pa_card.preferred_output_port when the user changes the card
profile or a port, and switching to the preferred port when it becomes
available.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=93946