From 70bbbcdc8440a6a616467a24496f497b225a2cee Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Sat, 7 Dec 2019 10:29:14 +0800 Subject: [PATCH] source-output: clear the preferred_source if it is default_source When the user moves a stream to the current default source, the preferred_source should be set to NULL and module-stream-restore should clear the routing for that stream in the stream database. From that point on the stream will be always routed to the default source. Signed-off-by: Hui Wang --- src/modules/module-stream-restore.c | 16 ++++++++++------ src/pulsecore/source-output.c | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index 644571b43..5aecc7759 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -1369,17 +1369,21 @@ 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->preferred_source != NULL) { - pa_source *s; + if (source_output->preferred_source != NULL || !created_new_entry) { + pa_source *s = NULL; + pa_xfree(entry->device); 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 (!entry->device) + entry->device_valid = false; - s = pa_namereg_get(c, entry->device, PA_NAMEREG_SOURCE); - if (s && s->card) { - pa_xfree(entry->card); + device_updated = !created_new_entry && !pa_safe_streq(entry->device, old->device); + pa_xfree(entry->card); + entry->card = NULL; + entry->card_valid = false; + if (entry->device_valid && (s = pa_namereg_get(c, entry->device, PA_NAMEREG_SOURCE)) && s->card) { entry->card = pa_xstrdup(s->card->name); entry->card_valid = true; } diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c index 2e6df822a..336b0d090 100644 --- a/src/pulsecore/source-output.c +++ b/src/pulsecore/source-output.c @@ -1561,8 +1561,12 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, bool save save the preferred_source */ if (save) { pa_xfree(o->preferred_source); - o->preferred_source = pa_xstrdup(dest->name); + if (dest == dest->core->default_source) + o->preferred_source = NULL; + else + o->preferred_source = pa_xstrdup(dest->name); } + pa_idxset_put(o->source->outputs, pa_source_output_ref(o), NULL); pa_cvolume_remap(&o->volume_factor_source, &o->channel_map, &o->source->channel_map);