mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-08 13:29:59 -05:00
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
This commit is contained in:
parent
ea3ebd09d1
commit
6b34896130
15 changed files with 370 additions and 239 deletions
|
|
@ -162,9 +162,18 @@ struct pa_core {
|
|||
/* Some hashmaps for all sorts of entities */
|
||||
pa_hashmap *namereg, *shared;
|
||||
|
||||
/* The default sink/source */
|
||||
pa_source *default_source;
|
||||
/* The default sink/source as configured by the user. If the user hasn't
|
||||
* explicitly configured anything, these are set to NULL. */
|
||||
pa_sink *configured_default_sink;
|
||||
pa_source *configured_default_source;
|
||||
|
||||
/* The effective default sink/source. If no sink or source is explicitly
|
||||
* configured as the default, we pick the device that ranks highest
|
||||
* according to the compare_sinks() and compare_sources() functions in
|
||||
* core.c. pa_core_update_default_sink/source() has to be called whenever
|
||||
* anything changes that might change the comparison results. */
|
||||
pa_sink *default_sink;
|
||||
pa_source *default_source;
|
||||
|
||||
pa_channel_map default_channel_map;
|
||||
pa_sample_spec default_sample_spec;
|
||||
|
|
@ -227,6 +236,21 @@ enum {
|
|||
|
||||
pa_core* pa_core_new(pa_mainloop_api *m, bool shared, bool enable_memfd, size_t shm_size);
|
||||
|
||||
void pa_core_set_configured_default_sink(pa_core *core, pa_sink *sink);
|
||||
void pa_core_set_configured_default_source(pa_core *core, pa_source *source);
|
||||
|
||||
/* These should be called whenever something changes that may affect the
|
||||
* default sink or source choice.
|
||||
*
|
||||
* If the default source choice happens between two monitor sources, the
|
||||
* monitored sinks are compared, so if the default sink changes, the default
|
||||
* source may change too. However, pa_core_update_default_sink() calls
|
||||
* pa_core_update_default_source() internally, so it's sufficient to only call
|
||||
* pa_core_update_default_sink() when something happens that affects the sink
|
||||
* ordering. */
|
||||
void pa_core_update_default_sink(pa_core *core);
|
||||
void pa_core_update_default_source(pa_core *core);
|
||||
|
||||
/* Check whether no one is connected to this core */
|
||||
void pa_core_check_idle(pa_core *c);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue