[pulseaudio-discuss] [PATCH v3 08/18] device-port: Add support for nodes

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Wed Jul 3 04:09:11 PDT 2013


---
 src/pulsecore/device-port.c | 32 ++++++++++++++++++++++++++++++++
 src/pulsecore/device-port.h |  6 ++++++
 2 files changed, 38 insertions(+)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 8bff5b6..142859b 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -31,6 +31,9 @@ pa_device_port_new_data *pa_device_port_new_data_init(pa_device_port_new_data *d
 
     pa_zero(*data);
     data->available = PA_AVAILABLE_UNKNOWN;
+    pa_node_new_data_init(&data->node_data);
+    pa_node_new_data_set_type(&data->node_data, PA_NODE_TYPE_PORT);
+
     return data;
 }
 
@@ -58,11 +61,19 @@ void pa_device_port_new_data_set_direction(pa_device_port_new_data *data, pa_dir
     pa_assert(data);
 
     data->direction = direction;
+    pa_node_new_data_set_direction(&data->node_data, direction);
+}
+
+void pa_device_port_new_data_set_create_node(pa_device_port_new_data *data, bool create) {
+    pa_assert(data);
+
+    data->create_node = create;
 }
 
 void pa_device_port_new_data_done(pa_device_port_new_data *data) {
     pa_assert(data);
 
+    pa_node_new_data_done(&data->node_data);
     pa_xfree(data->name);
     pa_xfree(data->description);
 }
@@ -94,6 +105,9 @@ static void device_port_free(pa_object *o) {
     pa_assert(p);
     pa_assert(pa_device_port_refcnt(p) == 0);
 
+    if (p->node)
+        pa_node_free(p->node);
+
     if (p->proplist)
         pa_proplist_free(p->proplist);
 
@@ -130,7 +144,25 @@ pa_device_port *pa_device_port_new(pa_core *c, pa_device_port_new_data *data, si
     p->latency_offset = 0;
     p->proplist = pa_proplist_new();
 
+    if (data->create_node) {
+        if (!data->node_data.description)
+            pa_node_new_data_set_description(&data->node_data, p->description);
+
+        if (!(p->node = pa_node_new(p->core, &data->node_data))) {
+            pa_log("Failed to create a node for port %s.", p->name);
+            goto fail;
+        }
+
+        p->node->owner = p;
+        pa_node_put(p->node);
+    }
+
     return p;
+
+fail:
+    pa_device_port_unref(p);
+
+    return NULL;
 }
 
 void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index b10d554..a66949e 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -54,6 +54,8 @@ struct pa_device_port {
     pa_direction_t direction;
     int64_t latency_offset;
 
+    pa_node *node;
+
     /* .. followed by some implementation specific data */
 };
 
@@ -67,6 +69,9 @@ typedef struct pa_device_port_new_data {
     char *description;
     pa_available_t available;
     pa_direction_t direction;
+
+    bool create_node;
+    pa_node_new_data node_data;
 } pa_device_port_new_data;
 
 pa_device_port_new_data *pa_device_port_new_data_init(pa_device_port_new_data *data);
@@ -74,6 +79,7 @@ void pa_device_port_new_data_set_name(pa_device_port_new_data *data, const char
 void pa_device_port_new_data_set_description(pa_device_port_new_data *data, const char *description);
 void pa_device_port_new_data_set_available(pa_device_port_new_data *data, pa_available_t available);
 void pa_device_port_new_data_set_direction(pa_device_port_new_data *data, pa_direction_t direction);
+void pa_device_port_new_data_set_create_node(pa_device_port_new_data *data, bool create);
 void pa_device_port_new_data_done(pa_device_port_new_data *data);
 
 pa_device_port *pa_device_port_new(pa_core *c, pa_device_port_new_data *data, size_t extra);
-- 
1.8.1.2



More information about the pulseaudio-discuss mailing list