sink-input: add a new API pa_sink_input_set_preferred_sink

If the sink here is NULL, that means users want to clear the
preferred_sink and move the sink-input to the default_sink, otherwise
set the preferred_sink to the sink->name and move the sink-input to
the sink. After that fire the sink_input_change event.

After adding this API, we can use this API to simplify the entry_apply
in the module-stream-restore.c.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
This commit is contained in:
Hui Wang 2019-01-15 19:28:23 +08:00
parent fbf8716685
commit 24d5d180b8
3 changed files with 18 additions and 8 deletions

View file

@ -1958,17 +1958,11 @@ static void entry_apply(struct userdata *u, const char *name, struct entry *e) {
/* If the device is not valid we should make sure the
preferred_sink is cleared as the user may have specifically
removed the sink element from the rule. */
pa_xfree(si->preferred_sink);
si->preferred_sink = NULL;
/* This is cheating a bit. The sink input itself has not changed
but the rules governing its routing have, so we fire this event
such that other routing modules (e.g. module-device-manager)
will pick up the change and reapply their routing */
pa_subscription_post(si->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, si->index);
pa_sink_input_set_preferred_sink(si, NULL);
}
} else if ((s = pa_namereg_get(u->core, e->device, PA_NAMEREG_SINK))) {
pa_log_info("Restoring device for stream %s.", name);
pa_sink_input_move_to(si, s, true);
pa_sink_input_set_preferred_sink(si, s);
}
}
}