Finalize basic configuration logic
[staging/agl-audio-plugin.git] / router.h
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 #ifndef paaglrouter
23 #define paaglrouter
24
25 #include "userdata.h"
26 #include "list.h"
27 #include "node.h"
28
29 #define AGL_ZONE_MAX 8  /* max 8 zones, demo is using 5 */ /* DEFINED IN MURPHY */
30
31 typedef bool (*agl_rtgroup_accept_t)(struct userdata *, agl_rtgroup *, agl_node *);
32 typedef int (*agl_rtgroup_compare_t)(struct userdata *, agl_rtgroup *, agl_node *, agl_node *);
33
34 struct agl_rtgroup {
35         char *name;      /**< name of the rtgroup */
36         agl_dlist entries;   /**< listhead of ordered rtentries */
37         agl_rtgroup_accept_t accept; /**< function pointer, whether to accept a node or not */
38         agl_rtgroup_compare_t compare; /**< function pointer, comparision for ordering */
39 };
40
41 typedef struct {
42         pa_hashmap *input;
43         pa_hashmap *output;
44 } agl_rtgroup_hash;
45
46 typedef struct {
47         agl_rtgroup **input[AGL_ZONE_MAX];
48         agl_rtgroup **output[AGL_ZONE_MAX];
49 } agl_rtgroup_classmap;
50
51 struct agl_router {
52         agl_rtgroup_hash rtgroups;
53         size_t maplen;                /**< length of the class */
54         agl_rtgroup_classmap classmap; /**< map device node types to rtgroups */
55         int *priormap;                /**< stream node priorities */
56         agl_dlist nodlist;            /**< priorized list of the stream nodes
57                                         (entry in node: rtprilist) */
58         agl_dlist connlist;           /**< listhead of the connections */
59 };
60
61 struct agl_connection {
62         agl_dlist link;    /**< list of connections */
63         bool blocked;      /**< true if this conflicts with another route */
64         uint16_t amid;     /**< audio manager connection id */
65         uint32_t from;     /**< source node index */
66         uint32_t to;       /**< destination node index */
67         uint32_t stream;   /**< index of the sink-input to be routed */
68 };
69
70 agl_router *agl_router_init (struct userdata *);
71 void agl_router_done (struct userdata *);
72
73 bool agl_router_default_accept (struct userdata *, agl_rtgroup *, agl_node *);
74 bool agl_router_phone_accept (struct userdata *, agl_rtgroup *, agl_node *);
75 int agl_router_default_compare (struct userdata *, agl_rtgroup *, agl_node *, agl_node *);
76 int agl_router_phone_compare (struct userdata *, agl_rtgroup *, agl_node *, agl_node *);
77
78 agl_rtgroup *agl_router_create_rtgroup (struct userdata *, agl_direction, const char *, agl_rtgroup_accept_t, agl_rtgroup_compare_t);
79 void agl_router_destroy_rtgroup (struct userdata *, agl_direction, const char *);
80 bool agl_router_assign_class_to_rtgroup (struct userdata *, agl_node_type, uint32_t, agl_direction, const char *);
81 void agl_router_assign_class_priority (struct userdata *, agl_node_type, int);
82
83 void agl_router_register_node (struct userdata *, agl_node *);
84 void agl_router_unregister_node (struct userdata *, agl_node *);
85 agl_node *agl_router_make_prerouting (struct userdata *, agl_node *);
86 void agl_router_make_routing (struct userdata *);
87
88 void implement_default_route (struct userdata *, agl_node *, agl_node *, uint32_t);
89 agl_node *find_default_route (struct userdata *, agl_node *, uint32_t);
90 void remove_routes (struct userdata *, agl_node *, agl_node*, uint32_t);
91
92 #endif