router: get routing group from classmap
[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_effect_t)(struct userdata *, agl_rtgroup *, agl_node *, bool new);
33
34 struct agl_rtgroup {
35         char *name;          /**< name of the rtgroup */
36         agl_dlist entries;   /**< listhead of ordered rtentries */
37         agl_node *node;      /**< final node */
38         agl_rtgroup_accept_t accept; /**< function pointer, whether to accept a node or not */
39         agl_rtgroup_effect_t effect; /**< function pointer, custom action such as volume up, down */
40 };
41
42 typedef struct {
43         pa_hashmap *input;
44         pa_hashmap *output;
45 } agl_rtgroup_hash;
46
47 typedef struct {
48         agl_rtgroup **input[AGL_ZONE_MAX];
49         agl_rtgroup **output[AGL_ZONE_MAX];
50 } agl_rtgroup_classmap;
51
52 struct agl_router {
53         agl_rtgroup_hash rtgroups;
54         size_t maplen;                /**< length of the class */
55         agl_rtgroup_classmap classmap; /**< map device node types to rtgroups */
56         int *priormap;                /**< stream node priorities */
57         agl_dlist nodlist;            /**< priorized list of the stream nodes
58                                         (entry in node: rtprilist) */
59         agl_dlist connlist;           /**< listhead of the connections */
60 };
61
62 struct agl_connection {
63         agl_dlist link;    /**< list of connections */
64         bool blocked;      /**< true if this conflicts with another route */
65         uint16_t amid;     /**< audio manager connection id */
66         uint32_t from;     /**< source node index */
67         uint32_t to;       /**< destination node index */
68         uint32_t stream;   /**< index of the sink-input to be routed */
69 };
70
71 agl_router *agl_router_init (struct userdata *);
72 void agl_router_done (struct userdata *);
73
74 bool agl_router_default_accept (struct userdata *, agl_rtgroup *, agl_node *);
75 bool agl_router_phone_accept (struct userdata *, agl_rtgroup *, agl_node *);
76 int agl_router_default_effect (struct userdata *, agl_rtgroup *, agl_node *, bool);
77 int agl_router_phone_effect (struct userdata *, agl_rtgroup *, agl_node *, bool);
78
79 agl_rtgroup *agl_router_create_rtgroup (struct userdata *, agl_direction, const char *, const char *, agl_rtgroup_accept_t, agl_rtgroup_effect_t);
80 void agl_router_destroy_rtgroup (struct userdata *, agl_direction, const char *);
81 bool agl_router_assign_class_to_rtgroup (struct userdata *, agl_node_type, uint32_t, agl_direction, const char *);
82 agl_rtgroup * agl_router_get_rtgroup_from_class (struct userdata *u, agl_node_type class, uint32_t zone, agl_direction type);
83 void agl_router_assign_class_priority (struct userdata *, agl_node_type, int);
84 int agl_router_get_node_priority (struct userdata *, agl_node *);
85 bool agl_router_apply_node_priority_effect (struct userdata *, agl_node *, bool);
86
87 void agl_router_register_node (struct userdata *, agl_node *);
88 void agl_router_unregister_node (struct userdata *, agl_node *);
89 agl_node *agl_router_make_prerouting (struct userdata *, agl_node *);
90 void agl_router_make_routing (struct userdata *);
91
92 void implement_default_route (struct userdata *, agl_node *, agl_node *, uint32_t);
93 agl_node *find_default_route (struct userdata *, agl_node *, uint32_t);
94 void remove_routes (struct userdata *, agl_node *, agl_node*, uint32_t);
95
96 #endif