[pulseaudio-discuss] [PATCH 03/11] New module: module-skoa-router

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Sat Nov 23 21:58:00 PST 2013


This module shall be our default router. Currently it doesn't do
anything, but I will next move the code from module-alsa-card that
moves streams during profile changes from the old sinks and sources
to the new sinks and sources. That kind of logic is better suited for
a routing policy module than the alsa module, because the logic isn't
(or shouldn't be) in any way specific to the alsa card.

What's the deal with the name? What does "skoa" mean? It doesn't mean
anything, or rather, it can mean whatever you want it to mean. I have
my own meaning for the word.

The reason behind such a strange name is that the module doesn't have
any more definite purpose or scope than to be our default router
module for now. module-default-router would be otherwise a good name,
but it would cause trouble if we ever want to make some completely
different module our default router. What would we do in that
situation? The first idea that comes to mind is to keep the module
name, but swap the implementation. That's not a good idea, however,
because if the old version supported some configuration parameters
that the new version doesn't support, then old configuration files
would break. The next idea is to keep the name module-default-router
for the old version, and call the new module something else, and load
the new version in the default configuration instead of
module-default-router. But that then causes infinite confusion, if a
module called "module-default-router" isn't actually the default
router. So, module-default-router isn't a good name, and I didn't
have any better ideas than coming up with a random name that doesn't
mean anything.
---
 src/Makefile.am                  |  8 +++++
 src/daemon/default.pa.in         |  3 ++
 src/daemon/system.pa.in          |  3 ++
 src/modules/module-skoa-router.c | 78 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+)
 create mode 100644 src/modules/module-skoa-router.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 3a25049..e024d9a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1077,6 +1077,7 @@ modlibexec_LTLIBRARIES += \
 		module-cli-protocol-tcp.la \
 		module-experimental-router.la \
 		module-simple-protocol-tcp.la \
+		module-skoa-router.la \
 		module-null-sink.la \
 		module-null-source.la \
 		module-sine-source.la \
@@ -1364,6 +1365,7 @@ SYMDEF_FILES = \
 		module-pipe-source-symdef.h \
 		module-simple-protocol-tcp-symdef.h \
 		module-simple-protocol-unix-symdef.h \
+		module-skoa-router-symdef.h \
 		module-native-protocol-tcp-symdef.h \
 		module-native-protocol-unix-symdef.h \
 		module-native-protocol-fd-symdef.h \
@@ -1918,6 +1920,12 @@ module_intended_roles_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_intended_roles_la_LIBADD = $(MODULE_LIBADD)
 module_intended_roles_la_CFLAGS = $(AM_CFLAGS)
 
+# The current default router module
+module_skoa_router_la_SOURCES = modules/module-skoa-router.c
+module_skoa_router_la_LDFLAGS = $(MODULE_LDFLAGS)
+module_skoa_router_la_LIBADD = $(MODULE_LIBADD)
+module_skoa_router_la_CFLAGS = $(AM_CFLAGS)
+
 # An experimental router module
 module_experimental_router_la_SOURCES = modules/module-experimental-router.c
 module_experimental_router_la_LDFLAGS = $(MODULE_LDFLAGS)
diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in
index f50d929..72fa8e6 100755
--- a/src/daemon/default.pa.in
+++ b/src/daemon/default.pa.in
@@ -196,6 +196,9 @@ ifelse(@HAVE_X11@, 1, [dnl
 #.endif
 ])dnl
 
+# Do some automatic routing
+load-module module-skoa-router
+
 ### Make some devices default
 #set-default-sink output
 #set-default-source input
diff --git a/src/daemon/system.pa.in b/src/daemon/system.pa.in
index e881a12..800b4b2 100755
--- a/src/daemon/system.pa.in
+++ b/src/daemon/system.pa.in
@@ -69,3 +69,6 @@ load-module module-suspend-on-idle
 
 ### Enable positioned event sounds
 load-module module-position-event-sounds
+
+# Do some automatic routing
+load-module module-skoa-router
diff --git a/src/modules/module-skoa-router.c b/src/modules/module-skoa-router.c
new file mode 100644
index 0000000..f763977
--- /dev/null
+++ b/src/modules/module-skoa-router.c
@@ -0,0 +1,78 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2013 Intel Corporation
+
+  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 "module-skoa-router-symdef.h"
+
+#include <pulsecore/i18n.h>
+#include <pulsecore/module.h>
+#include <pulsecore/router.h>
+
+PA_MODULE_AUTHOR("Tanu Kaskinen");
+PA_MODULE_DESCRIPTION(_("The current default router module"));
+PA_MODULE_VERSION(PACKAGE_VERSION);
+PA_MODULE_LOAD_ONCE(true);
+
+struct userdata {
+    pa_router *router;
+};
+
+int pa__init(pa_module *module) {
+    struct userdata *u;
+    int r;
+
+    pa_assert(module);
+
+    module->userdata = u = pa_xnew0(struct userdata, 1);
+    u->router = pa_router_new(module->core);
+
+    if (!u->router)
+        goto fail;
+
+    r = pa_router_put(u->router);
+
+    if (r < 0)
+        goto fail;
+
+    return 0;
+
+fail:
+    pa__done(module);
+
+    return -1;
+}
+
+void pa__done(pa_module *module) {
+    struct userdata *u;
+
+    pa_assert(module);
+
+    if (!(u = module->userdata))
+        return;
+
+    if (u->router)
+        pa_router_free(u->router);
+
+    pa_xfree(u);
+}
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list