media-session: switch to the route when availability changed

When a user plugs in headphones, they expect to hear an audio through
them. Currently, that usecase might or might not work with pipewire
depending on the user's luck, because pipewire instead uses port
priorities, and those apparently rarely have sane default values.

PulseAudio ignored priorities here, instead it made use of the port
right away. This should better match user expectations (who plugged in
headphones and is expecting to hear sound), so let's do the same in
pipewire.

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1170
This commit is contained in:
Konstantin Kharlamov 2021-06-13 21:40:12 +03:00 committed by Wim Taymans
parent 3512977450
commit 84acfbbda5

View file

@ -566,13 +566,29 @@ static int find_best_route(struct device *dev, uint32_t device_id, struct route
parse_enum_route(p, device_id, &t) < 0)
continue;
if (t.available == SPA_PARAM_AVAILABILITY_yes) {
if (best_avail.name == NULL || t.priority > best_avail.priority)
if (t.available == SPA_PARAM_AVAILABILITY_yes || t.available == SPA_PARAM_AVAILABILITY_unknown) {
struct route_info *ri;
if ((ri = find_route_info(dev, &t)) && ri->direction == SPA_DIRECTION_OUTPUT &&
ri->available != ri->prev_available) {
/* If route availability changed, that means a user just
* plugged in something like headphones, and they probably
* expect to hear sound from it. Switch to it immediately.
*
* TODO: switch INPUT ports without source and the input
* ports their source->active_port is part of a group of
* ports (see module-switch-on-port-available.c in PulseAudio).
*/
best_avail = t;
}
else if (t.available != SPA_PARAM_AVAILABILITY_no) {
if (best_unk.name == NULL || t.priority > best_unk.priority)
best_unk = t;
ri->save = true;
break;
}
else if (t.available == SPA_PARAM_AVAILABILITY_yes) {
if (best_avail.name == NULL || t.priority > best_avail.priority)
best_avail = t;
} else { // SPA_PARAM_AVAILABILITY_unknown
if (best_unk.name == NULL || t.priority > best_unk.priority)
best_unk = t;
}
}
}
best = best_avail;