improve default sink/source handling
authorTanu Kaskinen <tanuk@iki.fi>
Thu, 16 Feb 2017 10:09:38 +0000 (12:09 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Tue, 2 May 2017 13:10:19 +0000 (16:10 +0300)
commit6b348961304903483aa78d4ddc1fd036ef75a7cb
tree0b4fb4741b057780e20dc2eca4100954a4533599
parentea3ebd09d1588a8bf2e4ecc14ac4c318065edc40
improve default sink/source handling

Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.

I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.

This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.

pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().

I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
15 files changed:
src/modules/dbus/iface-core.c
src/modules/dbus/iface-sample.c
src/modules/module-default-device-restore.c
src/modules/module-intended-roles.c
src/modules/module-rescue-streams.c
src/modules/module-switch-on-connect.c
src/pulsecore/cli-command.c
src/pulsecore/cli-text.c
src/pulsecore/core.c
src/pulsecore/core.h
src/pulsecore/namereg.c
src/pulsecore/namereg.h
src/pulsecore/protocol-native.c
src/pulsecore/sink.c
src/pulsecore/source.c