[pulseaudio-discuss] [PATCH v3 2/8] sink-input: add a new API pa_sink_input_set_preferred_sink
Hui Wang
hui.wang at canonical.com
Sun Aug 18 05:32:35 UTC 2019
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 | 13 +++++++++++++
src/pulsecore/sink-input.h | 2 ++
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 3c50fda1e..c8bc02ecd 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -1957,18 +1957,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 18766019e..7521bed08 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -2418,3 +2418,16 @@ 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);
+ }
+}
diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h
index 16b6bf8eb..d3de6e3f8 100644
--- a/src/pulsecore/sink-input.h
+++ b/src/pulsecore/sink-input.h
@@ -461,6 +461,8 @@ void pa_sink_input_set_volume_direct(pa_sink_input *i, const pa_cvolume *volume)
* i->reference_ratio and logs a message if the value changes. */
void pa_sink_input_set_reference_ratio(pa_sink_input *i, const pa_cvolume *ratio);
+void pa_sink_input_set_preferred_sink(pa_sink_input *i, pa_sink *s);
+
#define pa_sink_input_assert_io_context(s) \
pa_assert(pa_thread_mq_get() || !PA_SINK_INPUT_IS_LINKED((s)->state))
--
2.17.1
More information about the pulseaudio-discuss
mailing list