[PATCH 23/30] source-output: Add pa_source_output_set_direct_on_input()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The function is useful for routers that want to route a sink input to
a newly added source output.

o->source and o->direct_on_input must be kept in sync with each other,
which is why pa_source_output_set_initial_source() was modified to
update o->direct_on_input.
---
 src/pulsecore/source-output.c | 24 ++++++++++++++++++++++++
 src/pulsecore/source-output.h |  6 +++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index 83e3715..ed46a41 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -748,6 +748,30 @@ int pa_source_output_set_initial_source(pa_source_output *o, pa_source *source)
     o->format = pa_format_info_copy(format);
     o->source = source;
 
+    if (o->direct_on_input && source != o->direct_on_input->sink->monitor_source) {
+        r = pa_source_output_set_direct_on_input(o, NULL);
+        /* Setting direct_on_input to NULL should always succeed. */
+        pa_assert(r >= 0);
+    }
+
+    return 0;
+}
+
+/* Called from the main thread. */
+int pa_source_output_set_direct_on_input(pa_source_output *o, pa_sink_input *input) {
+    pa_assert(o);
+    pa_assert(o->state == PA_SOURCE_OUTPUT_INIT);
+
+    if (input) {
+        int r;
+
+        r = pa_source_output_set_initial_source(o, input->sink->monitor_source);
+        if (r < 0)
+            return r;
+    }
+
+    o->direct_on_input = o->thread_info.direct_on_input = input;
+
     return 0;
 }
 
diff --git a/src/pulsecore/source-output.h b/src/pulsecore/source-output.h
index 8ce8b6d..3119a66 100644
--- a/src/pulsecore/source-output.h
+++ b/src/pulsecore/source-output.h
@@ -311,7 +311,11 @@ size_t pa_source_output_get_max_rewind(pa_source_output *o);
 
 /* Sets o->source and does format negotiation. May be called only when the
  * output state is PA_SOURCE_OUTPUT_INIT. */
-int pa_source_output_set_initial_source(pa_source_output *i, pa_source *source);
+int pa_source_output_set_initial_source(pa_source_output *o, pa_source *source);
+
+/* Sets o->direct_on_input and also sets the initial source. May be called only
+ * when the output state is PA_SOURCE_OUTPUT_INIT. */
+int pa_source_output_set_direct_on_input(pa_source_output *o, pa_sink_input *input);
 
 const char *pa_source_output_get_description(pa_source_output *o);
 
-- 
1.8.3.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux