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,
25 #include <pulsecore/idxset.h>
27 agl_nodeset *agl_nodeset_init (struct userdata *u)
33 ns = pa_xnew0 (agl_nodeset, 1);
34 ns->nodes = pa_idxset_new (pa_idxset_trivial_hash_func,
35 pa_idxset_trivial_compare_func);
36 ns->roles = pa_hashmap_new (pa_idxset_string_hash_func,
37 pa_idxset_string_compare_func);
38 ns->binaries = pa_hashmap_new (pa_idxset_string_hash_func,
39 pa_idxset_string_compare_func);
43 void agl_nodeset_done(struct userdata *u)
46 agl_nodeset_map *role, *binary;
50 if (u && (ns = u->nodeset)) {
51 pa_idxset_free (ns->nodes, NULL);
53 PA_HASHMAP_FOREACH(role, ns->roles, state) {
54 pa_xfree ((void *)role->name);
55 pa_xfree ((void *)role->resdef);
57 pa_hashmap_free (ns->roles);
59 PA_HASHMAP_FOREACH(binary, ns->binaries, state) {
60 pa_xfree ((void *)binary->name);
61 pa_xfree ((void *)binary->resdef);
63 pa_hashmap_free (ns->binaries);
65 for (i = 0; i < APCLASS_DIM; i++)
66 pa_xfree((void *)ns->class_name[i]);
72 int agl_nodeset_add_role (struct userdata *u, const char *role, agl_node_type type, agl_nodeset_resdef *resdef)
78 pa_assert_se (ns = u->nodeset);
80 map = pa_xnew0 (agl_nodeset_map, 1);
81 map->name = pa_xstrdup (role);
83 map->role = pa_xstrdup (role);
86 map->resdef = pa_xnew (agl_nodeset_resdef, 1);
87 memcpy (map->resdef, resdef, sizeof(agl_nodeset_resdef));
90 return pa_hashmap_put (ns->roles, (void *)map->name, map);
93 agl_node *agl_node_create (struct userdata *u, agl_node *data)
99 pa_assert_se (ns = u->nodeset);
101 node = pa_xnew0 (agl_node, 1);
103 pa_idxset_put (ns->nodes, node, &node->index);
106 node->key = pa_xstrdup (data->key);
107 node->direction = data->direction;
108 node->implement = data->implement;
109 node->channels = data->channels;
110 node->location = data->location;
111 node->privacy = data->privacy;
112 node->type = data->type;
113 node->zone = pa_xstrdup (data->zone);
114 node->visible = data->visible;
115 node->available = data->available;
116 node->amname = pa_xstrdup (data->amname ? data->amname : data->paname);
117 node->amdescr = pa_xstrdup(data->amdescr ? data->amdescr : "");
118 node->amid = data->amid;
119 node->paname = pa_xstrdup (data->paname);
120 node->stamp = data->stamp;
121 node->rset.id = data->rset.id ? pa_xstrdup(data->rset.id) : NULL;
122 node->rset.grant = data->rset.grant;
124 if (node->implement == agl_device) {
125 node->pacard.index = data->pacard.index;
126 if (data->pacard.profile)
127 node->pacard.profile = pa_xstrdup (data->pacard.profile);
129 node->paport = data->paport;
136 void agl_node_destroy (struct userdata *u, agl_node *node)
142 pa_assert_se (ns = u->nodeset);
144 pa_idxset_remove_by_index (ns->nodes, node->index);
149 const char *agl_node_type_str (agl_node_type type)
152 case agl_node_type_unknown: return "Unknown";
153 case agl_radio: return "Radio";
154 case agl_player: return "Player";
155 case agl_navigator: return "Navigator";
156 case agl_game: return "Game";
157 case agl_browser: return "Browser";
158 case agl_camera: return "Camera";
159 case agl_phone: return "Phone";
160 case agl_alert: return "Alert";
161 case agl_event: return "Event";
162 case agl_system: return "System";
163 default: return "default";
167 const char *agl_node_direction_str (agl_direction direction)
170 case agl_direction_unknown: return "unknown";
171 case agl_input: return "input";
172 case agl_output: return "output";
173 default: return "< ??? >";
177 agl_node *agl_node_get_from_data (struct userdata *u, agl_direction type, void *data)
179 pa_sink_input_new_data *sinp_data;
180 pa_source_output_new_data *sout_data;
181 agl_nodeset *nodeset;
187 pa_assert (nodeset = u->nodeset);
189 pa_assert (type == agl_input || type == agl_output);
191 /* input (= sink_input) */
192 if (type == agl_input) {
193 sinp_data = (pa_sink_input_new_data *) data;
194 PA_IDXSET_FOREACH(node, nodeset->nodes, index) {
195 if (node->client == sinp_data->client)
198 /* output (= source_output) TODO */
205 agl_node *agl_node_get_from_client (struct userdata *u, pa_client *client)
207 agl_nodeset *nodeset;
213 pa_assert (nodeset = u->nodeset);
215 PA_IDXSET_FOREACH(node, nodeset->nodes, index) {
216 if (node->client == client)
223 bool agl_node_has_highest_priority (struct userdata *u, agl_node *node)
225 agl_nodeset *nodeset;
232 pa_assert (nodeset = u->nodeset);
234 priority = agl_router_get_node_priority (u, node);
236 PA_IDXSET_FOREACH(n, nodeset->nodes, index) {
237 if ((n != node) && (agl_router_get_node_priority (u, n) >= priority))