source-output: change bool save_source to char *preferred_source

The finial objective is to store the preferred source name in the
source-output struct, and use module-stream-restore to save and
restore it.

This patch just replaces the save_source with preferred_source, and
tries to keep the original logic.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
This commit is contained in:
Hui Wang 2019-12-06 21:51:10 +08:00 committed by Tanu Kaskinen
parent 734a00c849
commit 5eec504d68
6 changed files with 54 additions and 29 deletions

View file

@ -1369,16 +1369,18 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
mute_updated = !created_new_entry && (!old->muted_valid || entry->muted != old->muted);
}
if (source_output->save_source) {
if (source_output->preferred_source != NULL) {
pa_source *s;
pa_xfree(entry->device);
entry->device = pa_xstrdup(source_output->source->name);
entry->device = pa_xstrdup(source_output->preferred_source);
entry->device_valid = true;
device_updated = !created_new_entry && (!old->device_valid || !pa_streq(entry->device, old->device));
if (source_output->source->card) {
s = pa_namereg_get(c, entry->device, PA_NAMEREG_SOURCE);
if (s && s->card) {
pa_xfree(entry->card);
entry->card = pa_xstrdup(source_output->source->card->name);
entry->card = pa_xstrdup(s->card->name);
entry->card_valid = true;
}
}
@ -1653,9 +1655,6 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
if (so->source == source)
continue;
if (so->save_source)
continue;
if (so->direct_on_input)
continue;
@ -1663,6 +1662,9 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
if (!so->source)
continue;
if (pa_safe_streq(so->source->name, so->preferred_source))
continue;
/* Skip this source output if it is connecting a filter source to
* the master */
if (so->destination_source)
@ -1898,12 +1900,13 @@ static void entry_apply(struct userdata *u, const char *name, struct entry *e) {
if (u->restore_device) {
if (!e->device_valid) {
if (so->save_source) {
if (so->preferred_source != NULL) {
pa_log_info("Ensuring device is not saved for stream %s.", name);
/* If the device is not valid we should make sure the
save flag is cleared as the user may have specifically
preferred_source is cleared as the user may have specifically
removed the source element from the rule. */
so->save_source = false;
pa_xfree(so->preferred_source);
so->preferred_source = NULL;
/* This is cheating a bit. The source output 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)