source-output: add a new API pa_source_output_set_preferred_source

If the source here is NULL, that means users want to clear the
preferred_source and move the source-output to the default_source,
otherwise set the preferred_source to the source->name and move the
source-output to the source. After that fire the source_output_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-12-07 10:13:28 +08:00 committed by Tanu Kaskinen
parent 5eec504d68
commit e529db75ec
3 changed files with 18 additions and 8 deletions

View file

@ -1905,17 +1905,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_source is cleared as the user may have specifically
removed the source element from the rule. */
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)
will pick up the change and reapply their routing */
pa_subscription_post(so->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, so->index);
pa_source_output_set_preferred_source(so, NULL);
}
} else if ((s = pa_namereg_get(u->core, e->device, PA_NAMEREG_SOURCE))) {
pa_log_info("Restoring device for stream %s.", name);
pa_source_output_move_to(so, s, true);
pa_source_output_set_preferred_source(so, s);
}
}
}

View file

@ -1886,3 +1886,17 @@ void pa_source_output_set_reference_ratio(pa_source_output *o, const pa_cvolume
pa_cvolume_snprint_verbose(old_ratio_str, sizeof(old_ratio_str), &old_ratio, &o->channel_map, true),
pa_cvolume_snprint_verbose(new_ratio_str, sizeof(new_ratio_str), ratio, &o->channel_map, true));
}
/* Called from the main thread. */
void pa_source_output_set_preferred_source(pa_source_output *o, pa_source *s) {
pa_assert(o);
pa_xfree(o->preferred_source);
if (s) {
o->preferred_source = pa_xstrdup(s->name);
pa_source_output_move_to(o, s, false);
} else {
o->preferred_source = NULL;
pa_source_output_move_to(o, o->core->default_source, false);
}
}

View file

@ -402,6 +402,8 @@ void pa_source_output_set_volume_direct(pa_source_output *o, const pa_cvolume *v
* o->reference_ratio and logs a message if the value changes. */
void pa_source_output_set_reference_ratio(pa_source_output *o, const pa_cvolume *ratio);
void pa_source_output_set_preferred_source(pa_source_output *o, pa_source *s);
#define pa_source_output_assert_io_context(s) \
pa_assert(pa_thread_mq_get() || !PA_SOURCE_OUTPUT_IS_LINKED((s)->state))