summaryrefslogtreecommitdiffstats
path: root/router.h
blob: 0bf21d5176bb5d70b709ccf94038e7a6fa3450c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * module-agl-audio -- PulseAudio module for providing audio routing support
 * (forked from "module-murphy-ivi" - https://github.com/otcshare )
 * Copyright (c) 2012, Intel Corporation.
 * Copyright (c) 2016, IoT.bzh
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
 * MA 02110-1301 USA.
 *
 */
#ifndef paaglrouter
#define paaglrouter

#include "userdata.h"
#include "list.h"
#include "node.h"

#define AGL_ZONE_MAX 8	/* max 8 zones, demo is using 5 */ /* DEFINED IN MURPHY */

typedef bool (*agl_rtgroup_accept_t)(struct userdata *, agl_rtgroup *, agl_node *);
typedef int (*agl_rtgroup_compare_t)(struct userdata *, agl_rtgroup *, agl_node *, agl_node *);

struct agl_rtgroup {
	char *name;          /**< name of the rtgroup */
	agl_dlist entries;   /**< listhead of ordered rtentries */
	agl_node *node;      /**< final node */
	agl_rtgroup_accept_t accept; /**< function pointer, whether to accept a node or not */
	agl_rtgroup_compare_t compare; /**< function pointer, comparision for ordering */
};

typedef struct {
	pa_hashmap *input;
	pa_hashmap *output;
} agl_rtgroup_hash;

typedef struct {
	agl_rtgroup **input[AGL_ZONE_MAX];
	agl_rtgroup **output[AGL_ZONE_MAX];
} agl_rtgroup_classmap;

struct agl_router {
	agl_rtgroup_hash rtgroups;
	size_t maplen;		      /**< length of the class */
	agl_rtgroup_classmap classmap; /**< map device node types to rtgroups */
	int *priormap;                /**< stream node priorities */
	agl_dlist nodlist;            /**< priorized list of the stream nodes
                                        (entry in node: rtprilist) */
	agl_dlist connlist;           /**< listhead of the connections */
};

struct agl_connection {
	agl_dlist link;    /**< list of connections */
	bool blocked;      /**< true if this conflicts with another route */
	uint16_t amid;     /**< audio manager connection id */
	uint32_t from;     /**< source node index */
	uint32_t to;       /**< destination node index */
	uint32_t stream;   /**< index of the sink-input to be routed */
};

agl_router *agl_router_init (struct userdata *);
void agl_router_done (struct userdata *);

bool agl_router_default_accept (struct userdata *, agl_rtgroup *, agl_node *);
bool agl_router_phone_accept (struct userdata *, agl_rtgroup *, agl_node *);
int agl_router_default_compare (struct userdata *, agl_rtgroup *, agl_node *, agl_node *);
int agl_router_phone_compare (struct userdata *, agl_rtgroup *, agl_node *, agl_node *);

agl_rtgroup *agl_router_create_rtgroup (struct userdata *, agl_direction, const char *, const char *, agl_rtgroup_accept_t, agl_rtgroup_compare_t);
void agl_router_destroy_rtgroup (struct userdata *, agl_direction, const char *);
bool agl_router_assign_class_to_rtgroup (struct userdata *, agl_node_type, uint32_t, agl_direction, const char *);
void agl_router_assign_class_priority (struct userdata *, agl_node_type, int);

void agl_router_register_node (struct userdata *, agl_node *);
void agl_router_unregister_node (struct userdata *, agl_node *);
agl_node *agl_router_make_prerouting (struct userdata *, agl_node *);
void agl_router_make_routing (struct userdata *);

void implement_default_route (struct userdata *, agl_node *, agl_node *, uint32_t);
agl_node *find_default_route (struct userdata *, agl_node *, uint32_t);
void remove_routes (struct userdata *, agl_node *, agl_node*, uint32_t);

#endif