core: move source-outputs conditionally when update default_source

When the default source changes, the streams from the old default
source should be moved to the new default source, unless the
preferred_source string is set to the old default source and the
active port of the old default source is not unavailable

Signed-off-by: Hui Wang <hui.wang@canonical.com>
This commit is contained in:
Hui Wang 2019-12-07 11:14:23 +08:00 committed by Tanu Kaskinen
parent 70bbbcdc84
commit c254f8405c
4 changed files with 47 additions and 25 deletions

View file

@ -116,9 +116,6 @@ 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 *old_default_source;
const char *s;
struct userdata *u = userdata;
@ -172,29 +169,9 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
return PA_HOOK_OK;
}
old_default_source = c->default_source;
/* Actually do the switch to the new source */
pa_core_set_configured_default_source(c, source->name);
/* Now move all old outputs over */
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, old_default_source->outputs, idx) {
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)
pa_log_info("Failed to move source output %u \"%s\" to %s.", o->index,
pa_strnull(pa_proplist_gets(o->proplist, PA_PROP_APPLICATION_NAME)), source->name);
else
pa_log_info("Successfully moved source output %u \"%s\" to %s.", o->index,
pa_strnull(pa_proplist_gets(o->proplist, PA_PROP_APPLICATION_NAME)), source->name);
}
return PA_HOOK_OK;
}