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

@ -728,10 +728,6 @@ static void route_source_output(struct userdata *u, pa_source_output *so) {
pa_assert(u);
pa_assert(u->do_routing);
/* Don't override user or application routing requests. */
if (so->save_source || so->source_requested_by_application)
return;
if (so->direct_on_input)
return;
@ -739,6 +735,10 @@ static void route_source_output(struct userdata *u, pa_source_output *so) {
if (!so->source)
return;
/* Don't override user or application routing requests. */
if (pa_safe_streq(so->source->name, so->preferred_source) || so->source_requested_by_application)
return;
auto_filtered_prop = pa_proplist_gets(so->proplist, "module-device-manager.auto_filtered");
if (auto_filtered_prop)
auto_filtered = (pa_parse_boolean(auto_filtered_prop) == 1);

View file

@ -222,9 +222,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;
@ -233,6 +230,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;
/* It might happen that a stream and a source are set up at the
same time, in which case we want to make sure we don't
interfere with that */

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)

View file

@ -184,7 +184,7 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
}
PA_IDXSET_FOREACH(o, old_default_source->outputs, idx) {
if (o->save_source || !PA_SOURCE_OUTPUT_IS_LINKED(o->state))
if (pa_safe_streq(o->source->name, o->preferred_source) || !PA_SOURCE_OUTPUT_IS_LINKED(o->state))
continue;
if (pa_source_output_move_to(o, source, false) < 0)