2 * module-agl-audio -- PulseAudio module for providing audio routing support
3 * (forked from "module-murphy-ivi" - https://github.com/otcshare )
4 * Copyright (c) 2012, Intel Corporation.
5 * Copyright (c) 2016, IoT.bzh
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU Lesser General Public License,
9 * version 2.1, as published by the Free Software Foundation.
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
23 /* Load the module with :
24 $ pulseaudio --system --dl-search-path=/mypath
25 $ pactl load-module mypamodule
26 (PS : /mypath must be world-readable, because PulseAudio drops
27 its own privileges after initial startup)
30 /* THIS IS PROVIDED BY "pulseaudio-module-devel" package */
32 #include <pulsecore/pulsecore-config.h> /* required for "module.h" */
33 #include <pulsecore/module.h>
34 #include <pulsecore/modargs.h> /* for "pa_modargs" */
36 #include "userdata.h" /* for "struct userdata" */
37 #include "config.h" /* for "agl_config_...()" */
38 #include "utils.h" /* for "struct agl_null_sink", "agl_utils_create_null_sink()"... */
39 #include "loopback.h" /* for "struct agl_loopback/loopnode" */
40 #include "zone.h" /* for "struct agl_zoneset" */
41 #include "node.h" /* for "struct agl_nodeset" */
42 #include "audiomgr.h" /* for "struct agl_audiomgr" */
43 #include "routerif.h" /* for "struct agl_routerif" */
44 #include "router.h" /* for "struct agl_router" */
45 #include "discover.h" /* for "struct agl_discover" */
46 #include "tracker.h" /* for "struct agl_tracker" */
48 #ifndef DEFAULT_CONFIG_DIR
49 #define DEFAULT_CONFIG_DIR "/etc/pulse"
52 #ifndef DEFAULT_CONFIG_FILE
53 #define DEFAULT_CONFIG_FILE "pulseaudio-agl.cfg"
59 static const char* const valid_modargs[] = {
70 /* INITIALIZATION FUNCTION */
72 int pa__init (pa_module *m)
74 pa_log ("Initializing \"pulseaudio-agl\" module");
76 struct userdata *u = NULL;
77 pa_modargs *ma = NULL; /* will contain module arguments */
80 const char *nsnam; /* NULL sink name (default = "null.agl") */
81 const char *amsocktype; /* Optional external routing daemon: socket type ("unix"/"tcp") */
82 const char *amaddr; /* Optional external routing daemon: socket address (path/ip address) */
83 const char *amport; /* Optional external routing daemon: socket port ("tcp" type only) */
89 /* treat module arguments */
91 ma = pa_modargs_new (m->argument, valid_modargs);
93 cfgdir = pa_modargs_get_value (ma, "config_dir", DEFAULT_CONFIG_DIR);
94 cfgfile = pa_modargs_get_value (ma, "config_file", DEFAULT_CONFIG_FILE);
95 nsnam = pa_modargs_get_value (ma, "null_sink_name", NULL);
96 amsocktype = pa_modargs_get_value (ma, "audiomgr_socktype", NULL);
97 amaddr = pa_modargs_get_value (ma, "audiomgr_address", NULL);
98 amport = pa_modargs_get_value (ma, "audiomgr_port", NULL);
100 pa_log ("cfgdir : %s", cfgdir);
101 pa_log ("cfgfile : %s", cfgfile);
103 /* initialize "stamp" incremental integer to 0 */
105 agl_utils_init_stamp ();
107 /* initialize userdata */
109 u = pa_xnew0 (struct userdata, 1);
112 u->nsnam = pa_xstrdup (nsnam) ;
113 u->zoneset = agl_zoneset_init (u);
114 u->nodeset = agl_nodeset_init (u);
115 u->audiomgr = agl_audiomgr_init (u);
116 u->routerif = agl_routerif_init (u, amsocktype, amaddr, amport);
117 u->router = agl_router_init (u);
118 u->discover = agl_discover_init (u);
119 u->tracker = agl_tracker_init (u);
123 /* apply the config file */
125 cfgpath = agl_config_file_get_path (cfgdir, cfgfile, buf, sizeof(buf));
126 agl_config_parse_file (u, cfgpath);
128 /* really initialize the module's core logic */
130 agl_tracker_synchronize (u);
134 pa_modargs_free (ma);
140 /* CLOSEUP FUNCTION */
141 void pa__done (pa_module *m)
143 pa_log ("Closing \"pulseaudio-agl\" module");
149 if (u = m->userdata) {
150 agl_tracker_done (u);
151 agl_discover_done (u);
153 agl_routerif_done (u);
154 agl_audiomgr_done (u);
155 agl_nodeset_done (u);
156 agl_zoneset_done (u);