[pulseaudio-discuss] [PATCH 02/30] sink, source: Add get_node() convenience functions

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Thu Jan 16 07:02:28 PST 2014


---
 src/pulsecore/sink.c   | 10 ++++++++++
 src/pulsecore/sink.h   |  4 ++++
 src/pulsecore/source.c | 13 +++++++++++++
 src/pulsecore/source.h |  5 +++++
 4 files changed, 32 insertions(+)

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 1045952..65b7050 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -3370,6 +3370,16 @@ void pa_sink_set_latency_offset(pa_sink *s, int64_t offset) {
         s->thread_info.latency_offset = offset;
 }
 
+/* Called from the main thread. */
+pa_node *pa_sink_get_node(pa_sink *s) {
+    pa_assert(s);
+
+    if (s->active_port)
+        return s->active_port->node;
+
+    return s->node;
+}
+
 /* Called from main context */
 size_t pa_sink_get_max_rewind(pa_sink *s) {
     size_t r;
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index b9f59c1..020ee3d 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -423,6 +423,10 @@ const char *pa_sink_get_description(pa_sink *s);
 int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough);
 void pa_sink_set_latency_offset(pa_sink *s, int64_t offset);
 
+/* If the sink has ports, returns the active port's node. Otherwise returns
+ * s->node. */
+pa_node *pa_sink_get_node(pa_sink *s);
+
 /* The returned value is supposed to be in the time domain of the sound card! */
 pa_usec_t pa_sink_get_latency(pa_sink *s);
 pa_usec_t pa_sink_get_requested_latency(pa_sink *s);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 08a816b..0ee05b9 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -2674,6 +2674,19 @@ void pa_source_set_latency_offset(pa_source *s, int64_t offset) {
         s->thread_info.latency_offset = offset;
 }
 
+/* Called from the main thread. */
+pa_node *pa_source_get_node(pa_source *s) {
+    pa_assert(s);
+
+    if (s->active_port)
+        return s->active_port->node;
+
+    if (s->monitor_of && s->monitor_of->active_port)
+        return s->monitor_of->active_port->node->monitor;
+
+    return s->node;
+}
+
 /* Called from main thread */
 size_t pa_source_get_max_rewind(pa_source *s) {
     size_t r;
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index 8734202..fcb52a7 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -357,6 +357,11 @@ void pa_source_update_flags(pa_source *s, pa_source_flags_t mask, pa_source_flag
 const char *pa_source_get_description(pa_source *s);
 void pa_source_set_latency_offset(pa_source *s, int64_t offset);
 
+/* If the source has ports, returns the active port's node. If the source is
+ * a monitor source and the sink has ports, returns the monitor node of the
+ * sink's active port. Otherwise returns s->node. */
+pa_node *pa_source_get_node(pa_source *s);
+
 /* The returned value is supposed to be in the time domain of the sound card! */
 pa_usec_t pa_source_get_latency(pa_source *s);
 pa_usec_t pa_source_get_requested_latency(pa_source *s);
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list