mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-17 06:59:56 -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
|
|
@ -168,17 +168,6 @@ const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t
|
|||
|
||||
pa_assert_se(pa_hashmap_put(c->namereg, e->name, e) >= 0);
|
||||
|
||||
/* If a sink or source is registered and there was none registered
|
||||
* before we inform the clients which then can ask for the default
|
||||
* sink/source which is then assigned. We don't adjust the default
|
||||
* sink/source here right away to give the module the chance to
|
||||
* register more sinks/sources before we choose a new default
|
||||
* sink/source. */
|
||||
|
||||
if ((!c->default_sink && type == PA_NAMEREG_SINK) ||
|
||||
(!c->default_source && type == PA_NAMEREG_SOURCE))
|
||||
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
|
||||
|
||||
return e->name;
|
||||
}
|
||||
|
||||
|
|
@ -189,12 +178,6 @@ void pa_namereg_unregister(pa_core *c, const char *name) {
|
|||
pa_assert(name);
|
||||
|
||||
pa_assert_se(e = pa_hashmap_remove(c->namereg, name));
|
||||
|
||||
if (c->default_sink == e->data)
|
||||
pa_namereg_set_default_sink(c, NULL);
|
||||
else if (c->default_source == e->data)
|
||||
pa_namereg_set_default_source(c, NULL);
|
||||
|
||||
pa_xfree(e->name);
|
||||
pa_xfree(e);
|
||||
}
|
||||
|
|
@ -205,22 +188,16 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) {
|
|||
pa_assert(c);
|
||||
|
||||
if (type == PA_NAMEREG_SOURCE && (!name || pa_streq(name, "@DEFAULT_SOURCE@"))) {
|
||||
pa_source *s;
|
||||
|
||||
if ((s = pa_namereg_get_default_source(c)))
|
||||
return s;
|
||||
return c->default_source;
|
||||
|
||||
} else if (type == PA_NAMEREG_SINK && (!name || pa_streq(name, "@DEFAULT_SINK@"))) {
|
||||
pa_sink *s;
|
||||
|
||||
if ((s = pa_namereg_get_default_sink(c)))
|
||||
return s;
|
||||
return c->default_sink;
|
||||
|
||||
} else if (type == PA_NAMEREG_SOURCE && name && pa_streq(name, "@DEFAULT_MONITOR@")) {
|
||||
pa_sink *s;
|
||||
|
||||
if ((s = pa_namereg_get(c, NULL, PA_NAMEREG_SINK)))
|
||||
return s->monitor_source;
|
||||
if (c->default_sink)
|
||||
return c->default_sink->monitor_source;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!name)
|
||||
|
|
@ -248,83 +225,3 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) {
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pa_sink* pa_namereg_set_default_sink(pa_core*c, pa_sink *s) {
|
||||
pa_assert(c);
|
||||
|
||||
if (s && !PA_SINK_IS_LINKED(pa_sink_get_state(s)))
|
||||
return NULL;
|
||||
|
||||
if (c->default_sink != s) {
|
||||
c->default_sink = s;
|
||||
pa_hook_fire(&c->hooks[PA_CORE_HOOK_DEFAULT_SINK_CHANGED], c->default_sink);
|
||||
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
pa_source* pa_namereg_set_default_source(pa_core*c, pa_source *s) {
|
||||
pa_assert(c);
|
||||
|
||||
if (s && !PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
|
||||
return NULL;
|
||||
|
||||
if (c->default_source != s) {
|
||||
c->default_source = s;
|
||||
pa_hook_fire(&c->hooks[PA_CORE_HOOK_DEFAULT_SOURCE_CHANGED], c->default_source);
|
||||
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
pa_sink *pa_namereg_get_default_sink(pa_core *c) {
|
||||
pa_sink *s, *best = NULL;
|
||||
uint32_t idx;
|
||||
|
||||
pa_assert(c);
|
||||
|
||||
if (c->default_sink && PA_SINK_IS_LINKED(pa_sink_get_state(c->default_sink)))
|
||||
return c->default_sink;
|
||||
|
||||
PA_IDXSET_FOREACH(s, c->sinks, idx)
|
||||
if (PA_SINK_IS_LINKED(pa_sink_get_state(s)))
|
||||
if (!best || s->priority > best->priority)
|
||||
best = s;
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
pa_source *pa_namereg_get_default_source(pa_core *c) {
|
||||
pa_source *s, *best = NULL;
|
||||
uint32_t idx;
|
||||
|
||||
pa_assert(c);
|
||||
|
||||
if (c->default_source && PA_SOURCE_IS_LINKED(pa_source_get_state(c->default_source)))
|
||||
return c->default_source;
|
||||
|
||||
/* First, try to find one that isn't a monitor */
|
||||
PA_IDXSET_FOREACH(s, c->sources, idx)
|
||||
if (!s->monitor_of && PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
|
||||
if (!best ||
|
||||
s->priority > best->priority)
|
||||
best = s;
|
||||
|
||||
if (best)
|
||||
return best;
|
||||
|
||||
/* Then, fallback to a monitor */
|
||||
PA_IDXSET_FOREACH(s, c->sources, idx)
|
||||
if (PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
|
||||
if (!best ||
|
||||
s->priority > best->priority ||
|
||||
(s->priority == best->priority &&
|
||||
s->monitor_of &&
|
||||
best->monitor_of &&
|
||||
s->monitor_of->priority > best->monitor_of->priority))
|
||||
best = s;
|
||||
|
||||
return best;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue