sink: move the streams to the default_sink when the sink is unlinked

When a sink is unlinked, all streams of this sink are moved to
default_sink, this action is implemented in the core rather than
modules now.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
This commit is contained in:
Hui Wang 2019-01-16 15:40:53 +08:00
parent 60d948618e
commit 43e3a7f3c3
6 changed files with 21 additions and 189 deletions

View file

@ -762,6 +762,9 @@ void pa_sink_unlink(pa_sink* s) {
pa_core_update_default_sink(s->core);
if (linked)
pa_sink_move_streams_to_default_sink(s->core, s, false);
if (s->card)
pa_idxset_remove_by_data(s->card->sinks, s, NULL);
@ -3937,7 +3940,7 @@ void pa_sink_set_reference_volume_direct(pa_sink *s, const pa_cvolume *volume) {
pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_VOLUME_CHANGED], s);
}
void pa_sink_move_streams_to_default_sink(pa_core *core, pa_sink *old_sink) {
void pa_sink_move_streams_to_default_sink(pa_core *core, pa_sink *old_sink, bool default_sink_changed) {
pa_sink_input *i;
uint32_t idx;
bool old_sink_is_unavailable = false;
@ -3945,6 +3948,9 @@ void pa_sink_move_streams_to_default_sink(pa_core *core, pa_sink *old_sink) {
pa_assert(core);
pa_assert(old_sink);
if (core->state == PA_CORE_SHUTDOWN)
return;
if (core->default_sink == NULL || core->default_sink->unlink_requested)
return;
@ -3964,8 +3970,16 @@ void pa_sink_move_streams_to_default_sink(pa_core *core, pa_sink *old_sink) {
if (pa_safe_streq(old_sink->name, i->preferred_sink) && !old_sink_is_unavailable)
continue;
pa_log_info("The sink input %u \"%s\" is moving to %s due to change of the default sink.",
i->index, pa_strnull(pa_proplist_gets(i->proplist, PA_PROP_APPLICATION_NAME)), core->default_sink->name);
if (!pa_sink_input_may_move_to(i, core->default_sink))
continue;
if (default_sink_changed)
pa_log_info("The sink input %u \"%s\" is moving to %s due to change of the default sink.",
i->index, pa_strnull(pa_proplist_gets(i->proplist, PA_PROP_APPLICATION_NAME)), core->default_sink->name);
else
pa_log_info("The sink input %u \"%s\" is moving to %s due to unlink of a sink.",
i->index, pa_strnull(pa_proplist_gets(i->proplist, PA_PROP_APPLICATION_NAME)), core->default_sink->name);
pa_sink_input_move_to(i, core->default_sink, false);
}
}