[v2,3/8] sink-input: clear the preferred_sink if it is default_sink

Submitted by Hui Wang on Jan. 17, 2019, 6:53 a.m.

Details

Message ID 20190117065340.18712-4-hui.wang@canonical.com
State New
Headers show
Series "Change the bool sink_save to char *preferred_sink" ( rev: 1 ) in PulseAudio

Commit Message

Hui Wang Jan. 17, 2019, 6:53 a.m.
When the user moves a stream to the current default sink, the
preferred_sink 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 sink.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
 src/modules/module-stream-restore.c | 19 ++++++++++++++-----
 src/pulsecore/sink-input.c          |  6 +++++-
 2 files changed, 19 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 366f1a5a8..142d1e3b4 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -1311,13 +1311,22 @@  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 (sink_input->preferred_sink != NULL) {
+        if (sink_input->preferred_sink != NULL || !created_new_entry) {
             pa_xfree(entry->device);
-            entry->device = pa_xstrdup(sink_input->preferred_sink);
-            entry->device_valid = true;
+            if (sink_input->preferred_sink != NULL) {
+                entry->device = pa_xstrdup(sink_input->preferred_sink);
+                entry->device_valid = true;
+            } else {
+                entry->device = NULL;
+                entry->device_valid = false;
+            }
 
-            device_updated = !created_new_entry && (!old->device_valid || !pa_streq(entry->device, old->device));
-            if (sink_input->sink->card) {
+            device_updated = !created_new_entry && !pa_safe_streq(entry->device, old->device);
+            if (entry->device_valid == false) {
+                pa_xfree(entry->card);
+                entry->card = NULL;
+                entry->card_valid = false;
+            } else {
                 pa_xfree(entry->card);
                 entry->card = pa_xstrdup(sink_input->sink->card->name);
                 entry->card_valid = true;
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 4dbc0cdef..f87c1f49f 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -1925,8 +1925,12 @@  int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, bool save) {
        save the preferred_sink */
     if (save) {
         pa_xfree(i->preferred_sink);
-        i->preferred_sink = pa_xstrdup(dest->name);
+        if (dest == dest->core->default_sink)
+            i->preferred_sink = NULL;
+        else
+            i->preferred_sink = pa_xstrdup(dest->name);
     }
+
     pa_idxset_put(dest->inputs, pa_sink_input_ref(i), NULL);
 
     PA_HASHMAP_FOREACH(v, i->volume_factor_sink_items, state)

Comments

On 17.01.19 07:53, Hui Wang wrote:
> When the user moves a stream to the current default sink, the
> preferred_sink 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 sink.
>
> Signed-off-by: Hui Wang <hui.wang@canonical.com>
> ---
>   src/modules/module-stream-restore.c | 19 ++++++++++++++-----
>   src/pulsecore/sink-input.c          |  6 +++++-
>   2 files changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
> index 366f1a5a8..142d1e3b4 100644
> --- a/src/modules/module-stream-restore.c
> +++ b/src/modules/module-stream-restore.c
> @@ -1311,13 +1311,22 @@ 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 (sink_input->preferred_sink != NULL) {
> +        if (sink_input->preferred_sink != NULL || !created_new_entry) {
>               pa_xfree(entry->device);
> -            entry->device = pa_xstrdup(sink_input->preferred_sink);
> -            entry->device_valid = true;
> +            if (sink_input->preferred_sink != NULL) {
> +                entry->device = pa_xstrdup(sink_input->preferred_sink);
> +                entry->device_valid = true;
> +            } else {
> +                entry->device = NULL;
> +                entry->device_valid = false;
> +            }
>   
> -            device_updated = !created_new_entry && (!old->device_valid || !pa_streq(entry->device, old->device));
> -            if (sink_input->sink->card) {
> +            device_updated = !created_new_entry && !pa_safe_streq(entry->device, old->device);
> +            if (entry->device_valid == false) {
> +                pa_xfree(entry->card);
> +                entry->card = NULL;
> +                entry->card_valid = false;
> +            } else {
>                   pa_xfree(entry->card);
>                   entry->card = pa_xstrdup(sink_input->sink->card->name);
>                   entry->card_valid = true;
You still need to check sink_input->sink->card. The virtual sinks don't 
have a card,
so it may well be that the device is valid but there is no card.
On 2019/6/30 下午6:47, Georg Chini wrote:
> On 17.01.19 07:53, Hui Wang wrote:
>> When the user moves a stream to the current default sink, the
>> preferred_sink 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 sink.
>>
>> Signed-off-by: Hui Wang <hui.wang@canonical.com>
>> ---
>>   src/modules/module-stream-restore.c | 19 ++++++++++++++-----
>>   src/pulsecore/sink-input.c          |  6 +++++-
>>   2 files changed, 19 insertions(+), 6 deletions(-)
>>
>> diff --git a/src/modules/module-stream-restore.c 
>> b/src/modules/module-stream-restore.c
>> index 366f1a5a8..142d1e3b4 100644
>> --- a/src/modules/module-stream-restore.c
>> +++ b/src/modules/module-stream-restore.c
>> @@ -1311,13 +1311,22 @@ 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 (sink_input->preferred_sink != NULL) {
>> +        if (sink_input->preferred_sink != NULL || !created_new_entry) {
>>               pa_xfree(entry->device);
>> -            entry->device = pa_xstrdup(sink_input->preferred_sink);
>> -            entry->device_valid = true;
>> +            if (sink_input->preferred_sink != NULL) {
>> +                entry->device = pa_xstrdup(sink_input->preferred_sink);
>> +                entry->device_valid = true;
>> +            } else {
>> +                entry->device = NULL;
>> +                entry->device_valid = false;
>> +            }
>>   -            device_updated = !created_new_entry && 
>> (!old->device_valid || !pa_streq(entry->device, old->device));
>> -            if (sink_input->sink->card) {
>> +            device_updated = !created_new_entry && 
>> !pa_safe_streq(entry->device, old->device);
>> +            if (entry->device_valid == false) {
>> +                pa_xfree(entry->card);
>> +                entry->card = NULL;
>> +                entry->card_valid = false;
>> +            } else {
>>                   pa_xfree(entry->card);
>>                   entry->card = 
>> pa_xstrdup(sink_input->sink->card->name);
>>                   entry->card_valid = true;
> You still need to check sink_input->sink->card. The virtual sinks 
> don't have a card,
> so it may well be that the device is valid but there is no card.
>
Ok, will add it.

Thanks.