[pulseaudio-discuss] [PATCH 16/21] alsa: Add node support

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


---
 src/modules/alsa/alsa-sink.c        |  9 +++++++++
 src/modules/alsa/alsa-source.c      |  9 +++++++++
 src/modules/alsa/module-alsa-card.c | 26 ++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index fda621b..a7c66db 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -42,6 +42,7 @@
 #include <pulsecore/core.h>
 #include <pulsecore/i18n.h>
 #include <pulsecore/module.h>
+#include <pulsecore/sink-node.h>
 #include <pulsecore/memchunk.h>
 #include <pulsecore/sink.h>
 #include <pulsecore/modargs.h>
@@ -94,6 +95,7 @@ struct userdata {
     pa_core *core;
     pa_module *module;
     pa_sink *sink;
+    pa_sink_node *sink_node;
 
     pa_thread *thread;
     pa_thread_mq thread_mq;
@@ -2034,6 +2036,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     pa_sink_new_data data;
     pa_alsa_profile_set *profile_set = NULL;
     void *state = NULL;
+    bool belong_to_card = !!mapping;
 
     pa_assert(m);
     pa_assert(ma);
@@ -2419,6 +2422,9 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
 
     pa_sink_put(u->sink);
 
+    if (!belong_to_card)
+        u->sink_node = pa_sink_node_new(u->sink, "alsa-output");
+
     if (profile_set)
         pa_alsa_profile_set_free(profile_set);
 
@@ -2439,6 +2445,9 @@ fail:
 static void userdata_free(struct userdata *u) {
     pa_assert(u);
 
+    if (u->sink_node)
+        pa_sink_node_free(u->sink_node);
+
     if (u->sink)
         pa_sink_unlink(u->sink);
 
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index da8222d..a93ba95 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -37,6 +37,7 @@
 #include <pulsecore/core.h>
 #include <pulsecore/i18n.h>
 #include <pulsecore/module.h>
+#include <pulsecore/source-node.h>
 #include <pulsecore/memchunk.h>
 #include <pulsecore/sink.h>
 #include <pulsecore/modargs.h>
@@ -84,6 +85,7 @@ struct userdata {
     pa_core *core;
     pa_module *module;
     pa_source *source;
+    pa_source_node *source_node;
 
     pa_thread *thread;
     pa_thread_mq thread_mq;
@@ -1743,6 +1745,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     pa_source_new_data data;
     pa_alsa_profile_set *profile_set = NULL;
     void *state = NULL;
+    bool belong_to_card = !!mapping;
 
     pa_assert(m);
     pa_assert(ma);
@@ -2094,6 +2097,9 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
 
     pa_source_put(u->source);
 
+    if (!belong_to_card)
+        u->source_node = pa_source_node_new(u->source, "alsa-input");
+
     if (profile_set)
         pa_alsa_profile_set_free(profile_set);
 
@@ -2114,6 +2120,9 @@ fail:
 static void userdata_free(struct userdata *u) {
     pa_assert(u);
 
+    if (u->source_node)
+        pa_source_node_free(u->source_node);
+
     if (u->source)
         pa_source_unlink(u->source);
 
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index fe05e3d..b09b71b 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -26,8 +26,10 @@
 #include <pulse/xmalloc.h>
 
 #include <pulsecore/core-util.h>
+#include <pulsecore/dynarray.h>
 #include <pulsecore/i18n.h>
 #include <pulsecore/modargs.h>
+#include <pulsecore/port-node.h>
 #include <pulsecore/queue.h>
 
 #include <modules/reserve-wrap.h>
@@ -116,6 +118,7 @@ struct userdata {
     pa_alsa_fdlist *mixer_fdl;
 
     pa_card *card;
+    pa_dynarray *nodes;
 
     pa_modargs *modargs;
 
@@ -613,6 +616,8 @@ int pa__init(pa_module *m) {
     const char *profile = NULL;
     char *fn = NULL;
     pa_bool_t namereg_fail = FALSE;
+    void *state;
+    pa_device_port *port;
 
     pa_alsa_refcnt_inc();
 
@@ -766,6 +771,24 @@ int pa__init(pa_module *m) {
                     "is abused (i.e. fixes are not pushed to ALSA), the decibel fix feature may be removed in some future "
                     "PulseAudio version.", u->card->name);
 
+    u->nodes = pa_dynarray_new((pa_free_cb_t) pa_port_node_free);
+
+    PA_HASHMAP_FOREACH(port, u->card->ports, state) {
+        pa_port_node *node;
+
+        if ((node = pa_port_node_new(port, port->direction == PA_DIRECTION_OUTPUT ? "alsa-output" : "alsa-input")))
+            pa_dynarray_append(u->nodes, node);
+        else {
+            /* We could perhaps just ignore failures, but it's nice to be able
+             * to assume that nodes exist either for all or none of the
+             * ports. */
+            pa_log("Failed to create a node for port %s. Removing all nodes of card %s.", port->name, u->card->name);
+            pa_dynarray_free(u->nodes);
+            u->nodes = NULL;
+            break;
+        }
+    }
+
     return 0;
 
 fail:
@@ -805,6 +828,9 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         goto finish;
 
+    if (u->nodes)
+        pa_dynarray_free(u->nodes);
+
     if (u->sink_input_put_hook_slot)
         pa_hook_slot_free(u->sink_input_put_hook_slot);
 
-- 
1.8.1.2



More information about the pulseaudio-discuss mailing list