It was reported in bug 93006 that on hardware that has HDMI and analog outputs on different cards, the HDMI sink is chosen by default even when headphones are plugged in. The headphone port has higher priority than the HDMI port, but that is not reflected in the sink priorities. This patch changes that - the sink/source priority is now the same as the active port priority, unless the sink/source doesn't have any ports, in which case the old priority logic is retained. BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=93006 --- src/pulsecore/sink.c | 18 ++++++++++++------ src/pulsecore/source.c | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 9b6e46b..aba11aa 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -251,7 +251,6 @@ pa_sink* pa_sink_new( s->core = core; s->state = PA_SINK_INIT; s->flags = flags; - s->priority = 0; s->suspend_cause = data->suspend_cause; pa_sink_set_mixer_dirty(s, false); s->name = pa_xstrdup(name); @@ -259,9 +258,6 @@ pa_sink* pa_sink_new( s->driver = pa_xstrdup(pa_path_get_filename(data->driver)); s->module = data->module; s->card = data->card; - - s->priority = pa_device_init_priority(s->proplist); - s->sample_spec = data->sample_spec; s->channel_map = data->channel_map; s->default_sample_rate = s->sample_spec.rate; @@ -309,10 +305,13 @@ pa_sink* pa_sink_new( if (!s->active_port) s->active_port = pa_device_port_find_best(s->ports); - if (s->active_port) + if (s->active_port) { + s->priority = s->active_port->priority; s->port_latency_offset = s->active_port->latency_offset; - else + } else { + s->priority = pa_device_init_priority(s->proplist); s->port_latency_offset = 0; + } s->save_volume = data->save_volume; s->save_muted = data->save_muted; @@ -3375,6 +3374,13 @@ int pa_sink_set_port(pa_sink *s, const char *name, bool save) { s->active_port = port; s->save_port = save; + if (port->priority != s->priority) { + pa_log_info("%s: priority: %u -> %u", s->name, s->priority, port->priority); + s->priority = port->priority; + + pa_core_update_default_sink(s->core); + } + pa_sink_set_port_latency_offset(s, s->active_port->latency_offset); pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_PORT_CHANGED], s); diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 6292e28..5dae761 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -238,7 +238,6 @@ pa_source* pa_source_new( s->core = core; s->state = PA_SOURCE_INIT; s->flags = flags; - s->priority = 0; s->suspend_cause = data->suspend_cause; pa_source_set_mixer_dirty(s, false); s->name = pa_xstrdup(name); @@ -246,9 +245,6 @@ pa_source* pa_source_new( s->driver = pa_xstrdup(pa_path_get_filename(data->driver)); s->module = data->module; s->card = data->card; - - s->priority = pa_device_init_priority(s->proplist); - s->sample_spec = data->sample_spec; s->channel_map = data->channel_map; s->default_sample_rate = s->sample_spec.rate; @@ -297,10 +293,13 @@ pa_source* pa_source_new( if (!s->active_port) s->active_port = pa_device_port_find_best(s->ports); - if (s->active_port) + if (s->active_port) { + s->priority = s->active_port->priority; s->port_latency_offset = s->active_port->latency_offset; - else + } else { + s->priority = pa_device_init_priority(s->proplist); s->port_latency_offset = 0; + } s->save_volume = data->save_volume; s->save_muted = data->save_muted; @@ -2644,6 +2643,14 @@ int pa_source_set_port(pa_source *s, const char *name, bool save) { s->active_port = port; s->save_port = save; + if (port->priority != s->priority) { + pa_log_info("%s: priority: %u -> %u", s->name, s->priority, port->priority); + s->priority = port->priority; + + /* The source priority may affect the default source choice. */ + pa_core_update_default_source(s->core); + } + pa_source_set_port_latency_offset(s, s->active_port->latency_offset); pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_PORT_CHANGED], s); -- 2.9.3