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:
Tanu Kaskinen 2017-02-16 12:09:38 +02:00
parent ea3ebd09d1
commit 6b34896130
15 changed files with 370 additions and 239 deletions

View file

@ -721,7 +721,7 @@ static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, DBu
return;
}
pa_namereg_set_default_sink(c->core, pa_dbusiface_device_get_sink(fallback_sink));
pa_core_set_configured_default_sink(c->core, pa_dbusiface_device_get_sink(fallback_sink));
pa_dbus_send_empty_reply(conn, msg);
}
@ -809,7 +809,7 @@ static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, D
return;
}
pa_namereg_set_default_source(c->core, pa_dbusiface_device_get_source(fallback_source));
pa_core_set_configured_default_source(c->core, pa_dbusiface_device_get_source(fallback_source));
pa_dbus_send_empty_reply(conn, msg);
}
@ -1692,6 +1692,28 @@ static pa_hook_result_t sample_cache_removed_cb(void *hook_data, void *call_data
return PA_HOOK_OK;
}
static pa_dbusiface_device *create_dbus_object_for_sink(pa_dbusiface_core *c, pa_sink *s) {
pa_dbusiface_device *d;
const char *object_path;
DBusMessage *signal_msg;
d = pa_dbusiface_device_new_sink(c, s);
object_path = pa_dbusiface_device_get_path(d);
pa_assert_se(pa_hashmap_put(c->sinks_by_index, PA_UINT32_TO_PTR(s->index), d) >= 0);
pa_assert_se(pa_hashmap_put(c->sinks_by_path, (char *) object_path, d) >= 0);
pa_assert_se((signal_msg = dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH,
PA_DBUS_CORE_INTERFACE,
signals[SIGNAL_NEW_SINK].name)));
pa_assert_se(dbus_message_append_args(signal_msg, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID));
pa_dbus_protocol_send_signal(c->dbus_protocol, signal_msg);
dbus_message_unref(signal_msg);
return d;
}
static pa_hook_result_t default_sink_changed_cb(void *hook_data, void *call_data, void *slot_data) {
pa_dbusiface_core *c = slot_data;
pa_sink *new_fallback_sink = call_data;
@ -1707,7 +1729,15 @@ static pa_hook_result_t default_sink_changed_cb(void *hook_data, void *call_data
c->fallback_sink = new_fallback_sink ? pa_sink_ref(new_fallback_sink) : NULL;
if (c->fallback_sink) {
pa_assert_se((device_iface = pa_hashmap_get(c->sinks_by_index, PA_UINT32_TO_PTR(c->fallback_sink->index))));
device_iface = pa_hashmap_get(c->sinks_by_index, PA_UINT32_TO_PTR(c->fallback_sink->index));
/* It's possible that we haven't created a dbus object for the
* source yet, because if a new source immediately becomes the
* default source, the default source change hook is fired before
* the put hook. */
if (!device_iface)
device_iface = create_dbus_object_for_sink(c, c->fallback_sink);
object_path = pa_dbusiface_device_get_path(device_iface);
pa_assert_se((signal_msg = dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH,
@ -1730,6 +1760,28 @@ static pa_hook_result_t default_sink_changed_cb(void *hook_data, void *call_data
return PA_HOOK_OK;
}
static pa_dbusiface_device *create_dbus_object_for_source(pa_dbusiface_core *c, pa_source *s) {
pa_dbusiface_device *d;
const char *object_path;
DBusMessage *signal_msg;
d = pa_dbusiface_device_new_source(c, s);
object_path = pa_dbusiface_device_get_path(d);
pa_assert_se(pa_hashmap_put(c->sources_by_index, PA_UINT32_TO_PTR(s->index), d) >= 0);
pa_assert_se(pa_hashmap_put(c->sources_by_path, (char *) object_path, d) >= 0);
pa_assert_se((signal_msg = dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH,
PA_DBUS_CORE_INTERFACE,
signals[SIGNAL_NEW_SOURCE].name)));
pa_assert_se(dbus_message_append_args(signal_msg, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID));
pa_dbus_protocol_send_signal(c->dbus_protocol, signal_msg);
dbus_message_unref(signal_msg);
return d;
}
static pa_hook_result_t default_source_changed_cb(void *hook_data, void *call_data, void *slot_data) {
pa_dbusiface_core *c = slot_data;
pa_source *new_fallback_source = call_data;
@ -1745,7 +1797,15 @@ static pa_hook_result_t default_source_changed_cb(void *hook_data, void *call_da
c->fallback_source = new_fallback_source ? pa_source_ref(new_fallback_source) : NULL;
if (c->fallback_source) {
pa_assert_se((device_iface = pa_hashmap_get(c->sources_by_index, PA_UINT32_TO_PTR(c->fallback_source->index))));
device_iface = pa_hashmap_get(c->sources_by_index, PA_UINT32_TO_PTR(c->fallback_source->index));
/* It's possible that we haven't created a dbus object for the
* source yet, because if a new source immediately becomes the
* default source, the default source change hook is fired before
* the put hook. */
if (!device_iface)
device_iface = create_dbus_object_for_source(c, c->fallback_source);
object_path = pa_dbusiface_device_get_path(device_iface);
pa_assert_se((signal_msg = dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH,
@ -1983,26 +2043,17 @@ static pa_hook_result_t client_unlink_cb(void *hook_data, void *call_data, void
static pa_hook_result_t sink_put_cb(void *hook_data, void *call_data, void *slot_data) {
pa_dbusiface_core *c = slot_data;
pa_sink *s = call_data;
pa_dbusiface_device *d = NULL;
const char *object_path = NULL;
DBusMessage *signal_msg = NULL;
pa_assert(c);
pa_assert(s);
d = pa_dbusiface_device_new_sink(c, s);
object_path = pa_dbusiface_device_get_path(d);
/* We may have alredy encountered this sink, because if the new sink was
* chosen as the default sink, the default sink change hook was fired
* first, and we saw the sink in default_sink_changed_cb(). */
if (pa_hashmap_get(c->sinks_by_index, PA_UINT32_TO_PTR(s->index)))
return PA_HOOK_OK;
pa_assert_se(pa_hashmap_put(c->sinks_by_index, PA_UINT32_TO_PTR(s->index), d) >= 0);
pa_assert_se(pa_hashmap_put(c->sinks_by_path, (char *) object_path, d) >= 0);
pa_assert_se(signal_msg = dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH,
PA_DBUS_CORE_INTERFACE,
signals[SIGNAL_NEW_SINK].name));
pa_assert_se(dbus_message_append_args(signal_msg, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID));
pa_dbus_protocol_send_signal(c->dbus_protocol, signal_msg);
dbus_message_unref(signal_msg);
create_dbus_object_for_sink(c, s);
return PA_HOOK_OK;
}
@ -2037,26 +2088,17 @@ static pa_hook_result_t sink_unlink_cb(void *hook_data, void *call_data, void *s
static pa_hook_result_t source_put_cb(void *hook_data, void *call_data, void *slot_data) {
pa_dbusiface_core *c = slot_data;
pa_source *s = call_data;
pa_dbusiface_device *d = NULL;
const char *object_path = NULL;
DBusMessage *signal_msg = NULL;
pa_assert(c);
pa_assert(s);
d = pa_dbusiface_device_new_source(c, s);
object_path = pa_dbusiface_device_get_path(d);
/* We may have alredy encountered this source, because if the new source
* was chosen as the default source, the default source change hook was
* fired first, and we saw the source in default_source_changed_cb(). */
if (pa_hashmap_get(c->sources_by_index, PA_UINT32_TO_PTR(s->index)))
return PA_HOOK_OK;
pa_assert_se(pa_hashmap_put(c->sources_by_index, PA_UINT32_TO_PTR(s->index), d) >= 0);
pa_assert_se(pa_hashmap_put(c->sources_by_path, (char *) object_path, d) >= 0);
pa_assert_se((signal_msg = dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH,
PA_DBUS_CORE_INTERFACE,
signals[SIGNAL_NEW_SOURCE].name)));
pa_assert_se(dbus_message_append_args(signal_msg, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID));
pa_dbus_protocol_send_signal(c->dbus_protocol, signal_msg);
dbus_message_unref(signal_msg);
create_dbus_object_for_source(c, s);
return PA_HOOK_OK;
}
@ -2158,8 +2200,8 @@ pa_dbusiface_core *pa_dbusiface_core_new(pa_core *core) {
c->samples = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_sample_free);
c->modules = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_module_free);
c->clients = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_client_free);
c->fallback_sink = pa_namereg_get_default_sink(core);
c->fallback_source = pa_namereg_get_default_source(core);
c->fallback_sink = core->default_sink;
c->fallback_source = core->default_source;
c->default_sink_changed_slot = pa_hook_connect(&core->hooks[PA_CORE_HOOK_DEFAULT_SINK_CHANGED],
PA_HOOK_NORMAL, default_sink_changed_cb, c);
c->default_source_changed_slot = pa_hook_connect(&core->hooks[PA_CORE_HOOK_DEFAULT_SOURCE_CHANGED],

View file

@ -352,7 +352,6 @@ static void handle_play(DBusConnection *conn, DBusMessage *msg, void *userdata)
DBusMessageIter msg_iter;
dbus_uint32_t volume = 0;
pa_proplist *property_list = NULL;
pa_sink *sink = NULL;
pa_assert(conn);
pa_assert(msg);
@ -370,13 +369,18 @@ static void handle_play(DBusConnection *conn, DBusMessage *msg, void *userdata)
goto finish;
}
if (!(sink = pa_namereg_get_default_sink(s->sample->core))) {
if (!s->sample->core->default_sink) {
pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED,
"Can't play sample %s, because there are no sinks available.", s->sample->name);
goto finish;
}
if (pa_scache_play_item(s->sample->core, s->sample->name, sink, volume, property_list, NULL) < 0) {
if (pa_scache_play_item(s->sample->core,
s->sample->name,
s->sample->core->default_sink,
volume,
property_list,
NULL) < 0) {
pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "Playing sample %s failed.", s->sample->name);
goto finish;
}

View file

@ -56,7 +56,7 @@ static void load(struct userdata *u) {
/* We never overwrite manually configured settings */
if (u->core->default_sink)
if (u->core->configured_default_sink)
pa_log_info("Manually configured default sink, not overwriting.");
else if ((f = pa_fopen_cloexec(u->sink_filename, "r"))) {
char ln[256] = "";
@ -69,7 +69,7 @@ static void load(struct userdata *u) {
if (!ln[0])
pa_log_info("No previous default sink setting, ignoring.");
else if ((s = pa_namereg_get(u->core, ln, PA_NAMEREG_SINK))) {
pa_namereg_set_default_sink(u->core, s);
pa_core_set_configured_default_sink(u->core, s);
pa_log_info("Restored default sink '%s'.", ln);
} else
pa_log_info("Saved default sink '%s' not existent, not restoring default sink setting.", ln);
@ -77,7 +77,7 @@ static void load(struct userdata *u) {
} else if (errno != ENOENT)
pa_log("Failed to load default sink: %s", pa_cstrerror(errno));
if (u->core->default_source)
if (u->core->configured_default_source)
pa_log_info("Manually configured default source, not overwriting.");
else if ((f = pa_fopen_cloexec(u->source_filename, "r"))) {
char ln[256] = "";
@ -90,7 +90,7 @@ static void load(struct userdata *u) {
if (!ln[0])
pa_log_info("No previous default source setting, ignoring.");
else if ((s = pa_namereg_get(u->core, ln, PA_NAMEREG_SOURCE))) {
pa_namereg_set_default_source(u->core, s);
pa_core_set_configured_default_source(u->core, s);
pa_log_info("Restored default source '%s'.", ln);
} else
pa_log_info("Saved default source '%s' not existent, not restoring default source setting.", ln);
@ -107,8 +107,7 @@ static void save(struct userdata *u) {
if (u->sink_filename) {
if ((f = pa_fopen_cloexec(u->sink_filename, "w"))) {
pa_sink *s = pa_namereg_get_default_sink(u->core);
fprintf(f, "%s\n", s ? s->name : "");
fprintf(f, "%s\n", u->core->default_sink ? u->core->default_sink->name : "");
fclose(f);
} else
pa_log("Failed to save default sink: %s", pa_cstrerror(errno));
@ -116,8 +115,7 @@ static void save(struct userdata *u) {
if (u->source_filename) {
if ((f = pa_fopen_cloexec(u->source_filename, "w"))) {
pa_source *s = pa_namereg_get_default_source(u->core);
fprintf(f, "%s\n", s ? s->name : "");
fprintf(f, "%s\n", u->core->default_source ? u->core->default_source->name : "");
fclose(f);
} else
pa_log("Failed to save default source: %s", pa_cstrerror(errno));

View file

@ -69,7 +69,7 @@ static bool role_match(pa_proplist *proplist, const char *role) {
static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_new_data *new_data, struct userdata *u) {
const char *role;
pa_sink *s, *def;
pa_sink *s;
uint32_t idx;
pa_assert(c);
@ -92,13 +92,13 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
}
/* Prefer the default sink over any other sink, just in case... */
if ((def = pa_namereg_get_default_sink(c)))
if (role_match(def->proplist, role) && pa_sink_input_new_data_set_sink(new_data, def, false))
if (c->default_sink)
if (role_match(c->default_sink->proplist, role) && pa_sink_input_new_data_set_sink(new_data, c->default_sink, false))
return PA_HOOK_OK;
/* @todo: favour the highest priority device, not the first one we find? */
PA_IDXSET_FOREACH(s, c->sinks, idx) {
if (s == def)
if (s == c->default_sink)
continue;
if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)))
@ -113,7 +113,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_output_new_data *new_data, struct userdata *u) {
const char *role;
pa_source *s, *def;
pa_source *s;
uint32_t idx;
pa_assert(c);
@ -136,9 +136,9 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
}
/* Prefer the default source over any other source, just in case... */
if ((def = pa_namereg_get_default_source(c)))
if (role_match(def->proplist, role)) {
pa_source_output_new_data_set_source(new_data, def, false);
if (c->default_source)
if (role_match(c->default_source->proplist, role)) {
pa_source_output_new_data_set_source(new_data, c->default_source, false);
return PA_HOOK_OK;
}
@ -146,7 +146,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
if (s->monitor_of)
continue;
if (s == def)
if (s == c->default_source)
continue;
if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
@ -259,7 +259,6 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, struct userdata *u) {
pa_sink_input *si;
uint32_t idx;
pa_sink *def;
pa_assert(c);
pa_assert(sink);
@ -271,7 +270,7 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, str
return PA_HOOK_OK;
/* If there not default sink, then there is no sink at all */
if (!(def = pa_namereg_get_default_sink(c)))
if (!c->default_sink)
return PA_HOOK_OK;
PA_IDXSET_FOREACH(si, sink->inputs, idx) {
@ -286,14 +285,14 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, str
continue;
/* Would the default sink fit? If so, let's use it */
if (def != sink && role_match(def->proplist, role))
if (pa_sink_input_move_to(si, def, false) >= 0)
if (c->default_sink != sink && role_match(c->default_sink->proplist, role))
if (pa_sink_input_move_to(si, c->default_sink, false) >= 0)
continue;
/* Try to find some other fitting sink */
/* @todo: favour the highest priority device, not the first one we find? */
PA_IDXSET_FOREACH(d, c->sinks, jdx) {
if (d == def || d == sink)
if (d == c->default_sink || d == sink)
continue;
if (!PA_SINK_IS_LINKED(pa_sink_get_state(d)))
@ -311,7 +310,6 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, str
static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *source, struct userdata *u) {
pa_source_output *so;
uint32_t idx;
pa_source *def;
pa_assert(c);
pa_assert(source);
@ -323,7 +321,7 @@ static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *sourc
return PA_HOOK_OK;
/* If there not default source, then there is no source at all */
if (!(def = pa_namereg_get_default_source(c)))
if (!c->default_source)
return PA_HOOK_OK;
PA_IDXSET_FOREACH(so, source->outputs, idx) {
@ -341,15 +339,16 @@ static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *sourc
continue;
/* Would the default source fit? If so, let's use it */
if (def != source && role_match(def->proplist, role) && !source->monitor_of == !def->monitor_of) {
pa_source_output_move_to(so, def, false);
if (c->default_source != source && role_match(c->default_source->proplist, role)
&& !source->monitor_of == !c->default_source->monitor_of) {
pa_source_output_move_to(so, c->default_source, false);
continue;
}
/* Try to find some other fitting source */
/* @todo: favour the highest priority device, not the first one we find? */
PA_IDXSET_FOREACH(d, c->sources, jdx) {
if (d == def || d == source)
if (d == c->default_source || d == source)
continue;
if (!PA_SOURCE_IS_LINKED(pa_source_get_state(d)))

View file

@ -96,7 +96,7 @@ static void build_group_ports(pa_hashmap *g_ports, pa_hashmap *s_ports) {
}
static pa_sink* find_evacuation_sink(pa_core *c, pa_sink_input *i, pa_sink *skip) {
pa_sink *target, *def, *fb_sink = NULL;
pa_sink *target, *fb_sink = NULL;
uint32_t idx;
pa_hashmap *all_ports;
pa_device_port *best_port;
@ -104,15 +104,13 @@ static pa_sink* find_evacuation_sink(pa_core *c, pa_sink_input *i, pa_sink *skip
pa_assert(c);
pa_assert(i);
def = pa_namereg_get_default_sink(c);
if (def && def != skip && pa_sink_input_may_move_to(i, def))
return def;
if (c->default_sink && c->default_sink != skip && pa_sink_input_may_move_to(i, c->default_sink))
return c->default_sink;
all_ports = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
PA_IDXSET_FOREACH(target, c->sinks, idx) {
if (target == def)
if (target == c->default_sink)
continue;
if (target == skip)
@ -204,7 +202,7 @@ static pa_hook_result_t sink_input_move_fail_hook_callback(pa_core *c, pa_sink_i
}
static pa_source* find_evacuation_source(pa_core *c, pa_source_output *o, pa_source *skip) {
pa_source *target, *def, *fb_source = NULL;
pa_source *target, *fb_source = NULL;
uint32_t idx;
pa_hashmap *all_ports;
pa_device_port *best_port;
@ -212,15 +210,13 @@ static pa_source* find_evacuation_source(pa_core *c, pa_source_output *o, pa_sou
pa_assert(c);
pa_assert(o);
def = pa_namereg_get_default_source(c);
if (def && def != skip && pa_source_output_may_move_to(o, def))
return def;
if (c->default_source && c->default_source != skip && pa_source_output_may_move_to(o, c->default_source))
return c->default_source;
all_ports = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
PA_IDXSET_FOREACH(target, c->sources, idx) {
if (target == def)
if (target == c->default_source)
continue;
if (target == skip)

View file

@ -55,7 +55,7 @@ struct userdata {
static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void* userdata) {
pa_sink_input *i;
uint32_t idx;
pa_sink *def;
pa_sink *old_default_sink;
const char *s;
struct userdata *u = userdata;
@ -75,24 +75,25 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
return PA_HOOK_OK;
}
def = pa_namereg_get_default_sink(c);
if (def == sink)
if (c->default_sink == sink)
return PA_HOOK_OK;
if (u->only_from_unavailable)
if (!def->active_port || def->active_port->available != PA_AVAILABLE_NO)
if (!c->default_sink->active_port || c->default_sink->active_port->available != PA_AVAILABLE_NO)
return PA_HOOK_OK;
old_default_sink = c->default_sink;
/* Actually do the switch to the new sink */
pa_namereg_set_default_sink(c, sink);
pa_core_set_configured_default_sink(c, sink);
/* Now move all old inputs over */
if (pa_idxset_size(def->inputs) <= 0) {
if (pa_idxset_size(old_default_sink->inputs) <= 0) {
pa_log_debug("No sink inputs to move away.");
return PA_HOOK_OK;
}
PA_IDXSET_FOREACH(i, def->inputs, idx) {
PA_IDXSET_FOREACH(i, old_default_sink->inputs, idx) {
if (i->save_sink || !PA_SINK_INPUT_IS_LINKED(i->state))
continue;
@ -110,7 +111,7 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source, void* userdata) {
pa_source_output *o;
uint32_t idx;
pa_source *def;
pa_source *old_default_source;
const char *s;
struct userdata *u = userdata;
@ -134,24 +135,25 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
return PA_HOOK_OK;
}
def = pa_namereg_get_default_source(c);
if (def == source)
if (c->default_source == source)
return PA_HOOK_OK;
if (u->only_from_unavailable)
if (!def->active_port || def->active_port->available != PA_AVAILABLE_NO)
if (!c->default_source->active_port || c->default_source->active_port->available != PA_AVAILABLE_NO)
return PA_HOOK_OK;
old_default_source = c->default_source;
/* Actually do the switch to the new source */
pa_namereg_set_default_source(c, source);
pa_core_set_configured_default_source(c, source);
/* Now move all old outputs over */
if (pa_idxset_size(def->outputs) <= 0) {
if (pa_idxset_size(old_default_source->outputs) <= 0) {
pa_log_debug("No source outputs to move away.");
return PA_HOOK_OK;
}
PA_IDXSET_FOREACH(o, def->outputs, idx) {
PA_IDXSET_FOREACH(o, old_default_source->outputs, idx) {
if (o->save_source || !PA_SOURCE_OUTPUT_IS_LINKED(o->state))
continue;