[pulseaudio-discuss] [PATCH 12/21] sink-node, source-node: Introduce sink and source nodes

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Wed Jun 19 08:40:09 PDT 2013


These node types take care of things that are common to all sink and
source nodes.
---
 src/Makefile.am             |  2 ++
 src/pulsecore/sink-node.c   | 70 +++++++++++++++++++++++++++++++++++++++++++++
 src/pulsecore/sink-node.h   | 40 ++++++++++++++++++++++++++
 src/pulsecore/source-node.c | 70 +++++++++++++++++++++++++++++++++++++++++++++
 src/pulsecore/source-node.h | 40 ++++++++++++++++++++++++++
 5 files changed, 222 insertions(+)
 create mode 100644 src/pulsecore/sink-node.c
 create mode 100644 src/pulsecore/sink-node.h
 create mode 100644 src/pulsecore/source-node.c
 create mode 100644 src/pulsecore/source-node.h

diff --git a/src/Makefile.am b/src/Makefile.am
index f4c5aa2..22245c4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -891,6 +891,8 @@ libpulsecore_ at PA_MAJORMINOR@_la_SOURCES = \
 		pulsecore/remap_mmx.c pulsecore/remap_sse.c \
 		pulsecore/resampler.c pulsecore/resampler.h \
 		pulsecore/rtpoll.c pulsecore/rtpoll.h \
+		pulsecore/sink-node.c pulsecore/sink-node.h \
+		pulsecore/source-node.c pulsecore/source-node.h \
 		pulsecore/mix.c pulsecore/mix.h \
 		pulsecore/cpu.h \
 		pulsecore/cpu-arm.c pulsecore/cpu-arm.h \
diff --git a/src/pulsecore/sink-node.c b/src/pulsecore/sink-node.c
new file mode 100644
index 0000000..4c4153d
--- /dev/null
+++ b/src/pulsecore/sink-node.c
@@ -0,0 +1,70 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright (c) 2013 Intel Corporation
+  Author: Tanu Kaskinen <tanu.kaskinen at intel.com>
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "sink-node.h"
+
+pa_sink_node *pa_sink_node_new(pa_sink *sink, const char *name) {
+    pa_node_new_data data;
+    pa_node *node;
+    pa_sink_node *sink_node;
+
+    pa_assert(sink);
+    pa_assert(name);
+
+    pa_node_new_data_init(&data);
+    pa_node_new_data_set_name(&data, name);
+    pa_node_new_data_set_description(&data, pa_sink_get_description(sink));
+    pa_node_new_data_set_direction(&data, PA_DIRECTION_OUTPUT);
+
+    node = pa_node_new(sink->core, &data);
+    pa_node_new_data_done(&data);
+
+    if (!node) {
+        pa_log("Failed to create a node for sink %s.", sink->name);
+        return NULL;
+    }
+
+    sink_node = pa_xnew0(pa_sink_node, 1);
+    sink_node->core = sink->core;
+    sink_node->node = node;
+    sink_node->sink = sink;
+
+    node->userdata = sink_node;
+
+    /* We may need to move this to pa_sink_node_put() at some point. */
+    pa_node_put(node);
+
+    return sink_node;
+}
+
+void pa_sink_node_free(pa_sink_node *sink_node) {
+    pa_assert(sink_node);
+
+    if (sink_node->node)
+        pa_node_free(sink_node->node);
+
+    pa_xfree(sink_node);
+}
diff --git a/src/pulsecore/sink-node.h b/src/pulsecore/sink-node.h
new file mode 100644
index 0000000..94e2456
--- /dev/null
+++ b/src/pulsecore/sink-node.h
@@ -0,0 +1,40 @@
+#ifndef foosinknodehfoo
+#define foosinknodehfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright (c) 2013 Intel Corporation
+  Author: Tanu Kaskinen <tanu.kaskinen at intel.com>
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+typedef struct pa_sink_node pa_sink_node;
+
+#include <pulsecore/core.h>
+#include <pulsecore/node.h>
+
+struct pa_sink_node {
+    pa_core *core;
+    pa_node *node;
+    pa_sink *sink;
+};
+
+pa_sink_node *pa_sink_node_new(pa_sink *sink, const char *name);
+void pa_sink_node_free(pa_sink_node *sink_node);
+
+#endif
diff --git a/src/pulsecore/source-node.c b/src/pulsecore/source-node.c
new file mode 100644
index 0000000..b596d0f
--- /dev/null
+++ b/src/pulsecore/source-node.c
@@ -0,0 +1,70 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright (c) 2013 Intel Corporation
+  Author: Tanu Kaskinen <tanu.kaskinen at intel.com>
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "source-node.h"
+
+pa_source_node *pa_source_node_new(pa_source *source, const char *name) {
+    pa_node_new_data data;
+    pa_node *node;
+    pa_source_node *source_node;
+
+    pa_assert(source);
+    pa_assert(name);
+
+    pa_node_new_data_init(&data);
+    pa_node_new_data_set_name(&data, name);
+    pa_node_new_data_set_description(&data, pa_source_get_description(source));
+    pa_node_new_data_set_direction(&data, PA_DIRECTION_INPUT);
+
+    node = pa_node_new(source->core, &data);
+    pa_node_new_data_done(&data);
+
+    if (!node) {
+        pa_log("Failed to create a node for source %s.", source->name);
+        return NULL;
+    }
+
+    source_node = pa_xnew0(pa_source_node, 1);
+    source_node->core = source->core;
+    source_node->node = node;
+    source_node->source = source;
+
+    node->userdata = source_node;
+
+    /* We may need to move this to pa_source_node_put() at some point. */
+    pa_node_put(node);
+
+    return source_node;
+}
+
+void pa_source_node_free(pa_source_node *source_node) {
+    pa_assert(source_node);
+
+    if (source_node->node)
+        pa_node_free(source_node->node);
+
+    pa_xfree(source_node);
+}
diff --git a/src/pulsecore/source-node.h b/src/pulsecore/source-node.h
new file mode 100644
index 0000000..b4c4a26
--- /dev/null
+++ b/src/pulsecore/source-node.h
@@ -0,0 +1,40 @@
+#ifndef foosourcenodehfoo
+#define foosourcenodehfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright (c) 2013 Intel Corporation
+  Author: Tanu Kaskinen <tanu.kaskinen at intel.com>
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+typedef struct pa_source_node pa_source_node;
+
+#include <pulsecore/core.h>
+#include <pulsecore/node.h>
+
+struct pa_source_node {
+    pa_core *core;
+    pa_node *node;
+    pa_source *source;
+};
+
+pa_source_node *pa_source_node_new(pa_source *source, const char *name);
+void pa_source_node_free(pa_source_node *source_node);
+
+#endif
-- 
1.8.1.2



More information about the pulseaudio-discuss mailing list