[PATCH 9/9] device-port: Generate monitor nodes for output ports

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

 



Having a single monitor node for the monitor source that is associated
with multiple output ports doesn't really make sense, so I'm
generating separate nodes for each output port.
---
 src/pulsecore/device-port.c | 31 +++++++++++++++++++++++++++++++
 src/pulsecore/device-port.h |  1 +
 src/pulsecore/node.h        |  1 +
 3 files changed, 33 insertions(+)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 8435c1f..9f06b4b 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);
 
@@ -105,6 +108,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);
 
@@ -155,6 +161,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;
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index a66949e..abc7b0a 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..d5db901 100644
--- a/src/pulsecore/node.h
+++ b/src/pulsecore/node.h
@@ -31,6 +31,7 @@ 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_MONITOR,  /* owner: pa_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



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

  Powered by Linux