[pulseaudio-discuss] [PATCH v2 18/21] sink-input, source-output: Add set_initial_sink/source()

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Thu Dec 5 06:19:18 PST 2013


When a router module sets the initial sink for a sink input, it
doesn't have access to the new data, so it has to set i->sink instead
of calling pa_sink_input_new_data_set_sink(). It also has to do format
negotiation. pa_sink_input_set_initial_sink() is a convenience
function for doing both things in a single step.
---
 src/pulsecore/sink-input.c    | 27 +++++++++++++++++++++++++++
 src/pulsecore/sink-input.h    |  4 ++++
 src/pulsecore/source-output.c | 27 +++++++++++++++++++++++++++
 src/pulsecore/source-output.h |  4 ++++
 4 files changed, 62 insertions(+)

diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 4264c5f..0469a15 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -32,6 +32,7 @@
 #include <pulse/util.h>
 #include <pulse/internal.h>
 
+#include <pulsecore/core-format.h>
 #include <pulsecore/i18n.h>
 #include <pulsecore/mix.h>
 #include <pulsecore/core-subscribe.h>
@@ -911,6 +912,32 @@ void pa_sink_input_put(pa_sink_input *i) {
 }
 
 /* Called from the main thread. */
+int pa_sink_input_set_initial_sink(pa_sink_input *i, pa_sink *sink) {
+    pa_idxset *sink_formats;
+    int r;
+    const pa_format_info *format;
+
+    pa_assert(i);
+    pa_assert(i->state == PA_SINK_INPUT_INIT);
+    pa_assert(sink);
+
+    sink_formats = pa_sink_get_formats(sink);
+    r = pa_format_info_negotiate(i->req_formats, sink_formats, &format);
+    pa_idxset_free(sink_formats, (pa_free_cb_t) pa_format_info_free);
+
+    if (r < 0)
+        return r;
+
+    if (i->format)
+        pa_format_info_free(i->format);
+
+    i->format = pa_format_info_copy(format);
+    i->sink = sink;
+
+    return 0;
+}
+
+/* Called from the main thread. */
 const char *pa_sink_input_get_description(pa_sink_input *i) {
     const char *description;
 
diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h
index 85d3518..a773be1 100644
--- a/src/pulsecore/sink-input.h
+++ b/src/pulsecore/sink-input.h
@@ -367,6 +367,10 @@ size_t pa_sink_input_get_max_request(pa_sink_input *i);
 
 /* Callable by everyone from main thread*/
 
+/* Sets i->sink and does format negotiation. May be called only when the input
+ * state is PA_SINK_INPUT_INIT. */
+int pa_sink_input_set_initial_sink(pa_sink_input *i, pa_sink *sink);
+
 const char *pa_sink_input_get_description(pa_sink_input *i);
 
 /* External code may request disconnection with this function */
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index e92e546..28381f5 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -32,6 +32,7 @@
 #include <pulse/util.h>
 #include <pulse/internal.h>
 
+#include <pulsecore/core-format.h>
 #include <pulsecore/i18n.h>
 #include <pulsecore/mix.h>
 #include <pulsecore/core-subscribe.h>
@@ -802,6 +803,32 @@ void pa_source_output_put(pa_source_output *o) {
 }
 
 /* Called from the main thread. */
+int pa_source_output_set_initial_source(pa_source_output *o, pa_source *source) {
+    pa_idxset *source_formats;
+    int r;
+    const pa_format_info *format;
+
+    pa_assert(o);
+    pa_assert(o->state == PA_SOURCE_OUTPUT_INIT);
+    pa_assert(source);
+
+    source_formats = pa_source_get_formats(source);
+    r = pa_format_info_negotiate(o->req_formats, source_formats, &format);
+    pa_idxset_free(source_formats, (pa_free_cb_t) pa_format_info_free);
+
+    if (r < 0)
+        return r;
+
+    if (o->format)
+        pa_format_info_free(o->format);
+
+    o->format = pa_format_info_copy(format);
+    o->source = source;
+
+    return 0;
+}
+
+/* Called from the main thread. */
 const char *pa_source_output_get_description(pa_source_output *o) {
     const char *description;
 
diff --git a/src/pulsecore/source-output.h b/src/pulsecore/source-output.h
index 371a27e..765209e 100644
--- a/src/pulsecore/source-output.h
+++ b/src/pulsecore/source-output.h
@@ -312,6 +312,10 @@ size_t pa_source_output_get_max_rewind(pa_source_output *o);
 
 /* Callable by everyone from the main thread. */
 
+/* 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);
+
 const char *pa_source_output_get_description(pa_source_output *o);
 
 /* External code may request disconnection with this function */
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list