[pulseaudio-discuss] [PATCH 3/4] move streams to new appeared sinks if they prefer these sinks

Hui Wang hui.wang at canonical.com
Mon Nov 5 01:47:15 UTC 2018


When a new sink appears, all streams that have their "preferred_sink"
set to the new sink should be moved to the new sink.

Signed-off-by: Hui Wang <hui.wang at canonical.com>
---
 src/pulsecore/sink.c | 31 +++++++++++++++++++++++++++++++
 src/pulsecore/sink.h |  1 +
 2 files changed, 32 insertions(+)

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 63a3456e7..a2a390beb 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -722,6 +722,8 @@ void pa_sink_put(pa_sink* s) {
     /* This function must be called after the PA_CORE_HOOK_SINK_PUT hook,
      * because module-switch-on-connect needs to know the old default sink */
     pa_core_update_default_sink(s->core, false);
+
+    pa_sink_bind_preferred_stream_to_a_sink(s);
 }
 
 /* Called from main context */
@@ -3919,3 +3921,32 @@ void pa_sink_move_streams_from_oldsink_to_newsink(pa_sink *old_sink, pa_sink *ne
 
     return;
 }
+
+void pa_sink_bind_preferred_stream_to_a_sink(pa_sink *s) {
+    pa_sink_input *si;
+    uint32_t idx;
+    pa_core *c;
+
+    if (!s)
+	return;
+
+    c = s->core;
+    PA_IDXSET_FOREACH(si, c->sink_inputs, idx) {
+        if (si->sink == s)
+            continue;
+
+        /* Skip this sink input if it is connecting a filter sink to
+         * the master */
+        if (si->origin_sink)
+            continue;
+
+        /* It might happen that a stream and a sink are set up at the
+           same time, in which case we want to make sure we don't
+           interfere with that */
+	if (!PA_SINK_INPUT_IS_LINKED(si->state))
+            continue;
+
+        if (si->preferred_sink != NULL && pa_streq(si->preferred_sink, s->name))
+           pa_sink_input_move_to(si, s, false);
+    }
+}
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index f207a094c..24e4678b1 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -562,4 +562,5 @@ void pa_sink_set_reference_volume_direct(pa_sink *s, const pa_cvolume *volume);
     pa_assert(pa_thread_mq_get() || !PA_SINK_IS_LINKED((s)->state))
 
 void pa_sink_move_streams_from_oldsink_to_newsink(pa_sink *old_sink, pa_sink *new_sink, bool from_user);
+void pa_sink_bind_preferred_stream_to_a_sink(pa_sink *s);
 #endif
-- 
2.17.1



More information about the pulseaudio-discuss mailing list