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,
26 pa_loopback *pa_loopback_init (void)
28 pa_loopback *loopback = pa_xnew0 (pa_loopback, 1);
33 void pa_loopback_done (struct userdata *u, pa_loopback *loopback)
35 pa_loopnode *loop, *n;
38 pa_assert_se (core = u->core);
40 PA_LLIST_FOREACH_SAFE(loop, n, loopback->loopnodes) {
41 pa_module_unload_by_index(core, loop->module_index, false);
45 pa_loopnode *pa_loopnode_create (struct userdata *u, pa_loopnode_type type,
46 uint32_t node_index, uint32_t source_index, uint32_t sink_index)
54 pa_source_output *sout;
56 pa_loopnode *loopnode;
61 pa_assert_se (core = u->core);
63 source = pa_idxset_get_by_index (core->sources, source_index);
64 sonam = pa_utils_get_source_name (source);
65 sink = pa_idxset_get_by_index (core->sinks, sink_index);
66 sinam = pa_utils_get_sink_name (sink);
68 snprintf (args, sizeof(args), "source=\"%s\" sink=\"%s\"", sonam, sinam);
69 module = pa_module_load (core, "module-loopback", args);
72 pa_log ("failed to load loopback for source '%s' & sink '%s'", sonam, sinam);
76 /* find the sink_input/source_output couple generated but the module we just loaded */
77 PA_IDXSET_FOREACH(sout, core->source_outputs, idx) {
78 if (sout->module && sout->module == module)
82 PA_IDXSET_FOREACH(sinp, core->sink_inputs, idx) {
83 if (sinp->module && sinp->module == module)
88 pa_module_unload (core, module, false);
92 loopnode = pa_xnew0 (pa_loopnode, 1);
93 loopnode->module_index = module->index;
94 loopnode->source_output_index = sout->index;
95 loopnode->sink_input_index = sinp->index;
100 void pa_loopnode_destroy (struct userdata *u, pa_loopnode *loopnode)
105 if (u && (core = u->core)) {
106 if ((module = pa_idxset_get_by_index (core->modules, loopnode->module_index))){
107 pa_log_info ("unloading loopback");
108 pa_module_unload (core, module, false);