[pulseaudio-discuss] [PATCH v2 2/8] sink-input: add a new API pa_sink_input_set_preferred_sink

Georg Chini georg at chini.tk
Sun Jun 30 10:44:08 UTC 2019


Sorry for the late feedback.

On 17.01.19 07:53, Hui Wang wrote:
> If the sink here is NULL, that means users want to clear the
> preferred_sink and move the sink-input to the default_sink, otherwise
> set the preferred_sink to the sink->name and move the sink-input to
> the sink. After that fire the sink_input_change event.
>
> After adding this API, we can use this API to simplify the entry_apply
> in the module-stream-restore.c.
>
> Signed-off-by: Hui Wang <hui.wang at canonical.com>
> ---
>   src/modules/module-stream-restore.c | 10 ++--------
>   src/pulsecore/sink-input.c          | 14 ++++++++++++++
>   src/pulsecore/sink-input.h          |  2 ++
>   3 files changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
> index a8c6a42c5..366f1a5a8 100644
> --- a/src/modules/module-stream-restore.c
> +++ b/src/modules/module-stream-restore.c
> @@ -1953,18 +1953,12 @@ static void entry_apply(struct userdata *u, const char *name, struct entry *e) {
>                          preferred_sink is cleared as the user may have specifically
>                          removed the sink element from the rule. */
>                       pa_xfree(si->preferred_sink);
> -                    si->preferred_sink = NULL;
> -                    /* This is cheating a bit. The sink input 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)
> -                       will pick up the change and reapply their routing */
> -                    pa_subscription_post(si->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, si->index);
> +                    pa_sink_input_set_preferred_sink(si, NULL);
>                   }
>               } else if ((s = pa_namereg_get(u->core, e->device, PA_NAMEREG_SINK))) {
>                   pa_log_info("Restoring device for stream %s.", name);
> -                pa_sink_input_move_to(si, s, true);
>                   pa_xfree(si->preferred_sink);
> -                si->preferred_sink = pa_xstrdup(s->name);
> +                pa_sink_input_set_preferred_sink(si, s);
>               }
>           }
>       }
> diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
> index f41eacf07..4dbc0cdef 100644
> --- a/src/pulsecore/sink-input.c
> +++ b/src/pulsecore/sink-input.c
> @@ -2416,3 +2416,17 @@ void pa_sink_input_set_reference_ratio(pa_sink_input *i, const pa_cvolume *ratio
>                    pa_cvolume_snprint_verbose(old_ratio_str, sizeof(old_ratio_str), &old_ratio, &i->channel_map, true),
>                    pa_cvolume_snprint_verbose(new_ratio_str, sizeof(new_ratio_str), ratio, &i->channel_map, true));
>   }
> +
> +/* Called from the main thread. */
> +void pa_sink_input_set_preferred_sink(pa_sink_input *i, pa_sink *s) {
> +    pa_assert(i);
> +
> +    if (s) {
> +        i->preferred_sink = pa_xstrdup(s->name);
> +        pa_sink_input_move_to(i, s, true);
> +    } else {
> +        i->preferred_sink = NULL;
> +        pa_sink_input_move_to(i, i->core->default_sink, true);
> +    }
> +    pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
> +}
You do not have to send the subscription event here, 
pa_sink_input_finish_move()
will already send the event.


More information about the pulseaudio-discuss mailing list