Implement JSON configuration file
[staging/agl-audio-plugin.git] / audiomgr.c
1 /*
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
6  *
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.
10  *
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.
15  *
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,
19  * MA 02110-1301 USA.
20  *
21  */
22 #include "audiomgr.h"
23
24 #define DS_DOWN 255
25
26 typedef struct {
27         const char *name;
28         uint16_t    id;
29         uint16_t    state;
30 } domain_t;
31
32 typedef struct {
33         uint16_t    fromidx;
34         uint16_t    toidx;
35         uint32_t    channels;
36 } link_t;
37
38 typedef struct {
39         int          maxlink;
40         int          nlink;
41         link_t      *links;
42 } routes_t;
43
44 struct agl_audiomgr {
45         domain_t      domain;
46         pa_hashmap   *nodes;        /**< nodes ie. sinks and sources */
47         pa_hashmap   *conns;        /**< connections */
48         routes_t      defrts;       /**< default routes */
49 };
50
51 struct agl_audiomgr *agl_audiomgr_init (struct userdata *u)
52 {
53         agl_audiomgr *am;
54
55         pa_assert (u);
56
57         am = pa_xnew0 (agl_audiomgr, 1);
58         am->domain.id = AM_ID_INVALID;
59         am->domain.state = DS_DOWN;
60         am->nodes = pa_hashmap_new (pa_idxset_trivial_hash_func,
61                                     pa_idxset_trivial_compare_func);
62         am->conns = pa_hashmap_new (pa_idxset_trivial_hash_func,
63                                     pa_idxset_trivial_compare_func);
64         return am;
65 }
66
67 void agl_audiomgr_done (struct userdata *u)
68 {
69         agl_audiomgr *am;
70
71         if (u && (am = u->audiomgr)) {
72                 //if (u->routerif && am->domain.id != AM_ID_INVALID)
73                 //      pa_routerif_unregister_domain (u, am->domain.id);
74
75                 pa_hashmap_free (am->nodes);
76                 pa_hashmap_free (am->conns);
77                 pa_xfree ((void *)am->domain.name);
78                 pa_xfree (am);
79                 u->audiomgr = NULL;
80         }
81 }
82