[pulseaudio-discuss] [PATCH 08/23] device-port: Generate monitor nodes for output ports

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Wed Nov 20 01:26:00 PST 2013


---
 src/pulsecore/device-port.c | 31 +++++++++++++++++++++++++++++++
 src/pulsecore/device-port.h |  1 +
 src/pulsecore/node.h        |  3 ++-
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 9801e35..cf62ec3 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -22,7 +22,10 @@
 ***/
 
 #include "device-port.h"
+
 #include <pulsecore/card.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/i18n.h>
 
 PA_DEFINE_PUBLIC_CLASS(pa_device_port, pa_object);
 
@@ -99,6 +102,9 @@ static void device_port_free(pa_object *o) {
     pa_assert(p);
     pa_assert(pa_device_port_refcnt(p) == 0);
 
+    if (p->monitor_node)
+        pa_node_free(p->monitor_node);
+
     if (p->node)
         pa_node_free(p->node);
 
@@ -149,6 +155,31 @@ pa_device_port *pa_device_port_new(pa_core *c, pa_device_port_new_data *data, si
     p->node->owner = p;
     pa_node_put(p->node);
 
+    if (p->direction == PA_DIRECTION_OUTPUT) {
+        char *description;
+        pa_node_new_data monitor_data;
+
+        description = pa_sprintf_malloc(_("Monitor of %s"), p->node->description);
+
+        pa_node_new_data_init(&monitor_data);
+        pa_node_new_data_set_description(&monitor_data, description);
+        pa_xfree(description);
+        pa_node_new_data_set_type(&monitor_data, PA_NODE_TYPE_PORT_MONITOR);
+        pa_node_new_data_set_direction(&monitor_data, PA_DIRECTION_INPUT);
+        pa_node_new_data_set_monitor_of(&monitor_data, p->node);
+
+        p->monitor_node = pa_node_new(p->core, &monitor_data);
+        pa_node_new_data_done(&monitor_data);
+
+        if (!p->monitor_node) {
+            pa_log("Failed to create a monitor node for port %s.", p->name);
+            goto fail;
+        }
+
+        p->monitor_node->owner = p;
+        pa_node_put(p->monitor_node);
+    }
+
     return p;
 
 fail:
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index 6b2a677..7e580c1 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -55,6 +55,7 @@ struct pa_device_port {
     int64_t latency_offset;
 
     pa_node *node;
+    pa_node *monitor_node;
 
     /* .. followed by some implementation specific data */
 };
diff --git a/src/pulsecore/node.h b/src/pulsecore/node.h
index 4168533..4504c79 100644
--- a/src/pulsecore/node.h
+++ b/src/pulsecore/node.h
@@ -30,7 +30,8 @@ typedef struct pa_node pa_node;
 
 /* The node type determines what the owner pointer of pa_node points to. */
 typedef enum {
-    PA_NODE_TYPE_PORT,          /* owner: pa_port */
+    PA_NODE_TYPE_PORT,          /* owner: pa_device_port */
+    PA_NODE_TYPE_PORT_MONITOR,  /* owner: pa_device_port */
     PA_NODE_TYPE_SINK,          /* owner: pa_sink */
     PA_NODE_TYPE_SOURCE,        /* owner: pa_source */
     PA_NODE_TYPE_SINK_INPUT,    /* owner: pa_sink_input */
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list