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,
24 #include <pulsecore/idxset.h>
26 pa_nodeset *pa_nodeset_init (struct userdata *u)
32 ns = pa_xnew0 (pa_nodeset, 1);
33 ns->nodes = pa_idxset_new (pa_idxset_trivial_hash_func,
34 pa_idxset_trivial_compare_func);
35 ns->roles = pa_hashmap_new (pa_idxset_string_hash_func,
36 pa_idxset_string_compare_func);
37 ns->binaries = pa_hashmap_new (pa_idxset_string_hash_func,
38 pa_idxset_string_compare_func);
42 void pa_nodeset_done(struct userdata *u)
45 pa_nodeset_map *role, *binary;
49 if (u && (ns = u->nodeset)) {
50 pa_idxset_free (ns->nodes, NULL);
52 PA_HASHMAP_FOREACH(role, ns->roles, state) {
53 pa_xfree ((void *)role->name);
54 pa_xfree ((void *)role->resdef);
56 pa_hashmap_free (ns->roles);
58 PA_HASHMAP_FOREACH(binary, ns->binaries, state) {
59 pa_xfree ((void *)binary->name);
60 pa_xfree ((void *)binary->resdef);
62 pa_hashmap_free (ns->binaries);
64 for (i = 0; i < APCLASS_DIM; i++)
65 pa_xfree((void *)ns->class_name[i]);
71 agl_node *agl_node_create (struct userdata *u, agl_node *data)
77 pa_assert_se (ns = u->nodeset);
79 node = pa_xnew0 (agl_node, 1);
81 pa_idxset_put (ns->nodes, node, &node->index);
84 node->key = pa_xstrdup (data->key);
85 node->direction = data->direction;
86 node->implement = data->implement;
87 node->channels = data->channels;
88 node->location = data->location;
89 node->privacy = data->privacy;
90 node->type = data->type;
91 node->zone = pa_xstrdup (data->zone);
92 node->visible = data->visible;
93 node->available = data->available;
94 node->amname = pa_xstrdup (data->amname ? data->amname : data->paname);
95 node->amdescr = pa_xstrdup(data->amdescr ? data->amdescr : "");
96 node->amid = data->amid;
97 node->paname = pa_xstrdup (data->paname);
98 node->stamp = data->stamp;
99 node->rset.id = data->rset.id ? pa_xstrdup(data->rset.id) : NULL;
100 node->rset.grant = data->rset.grant;
102 if (node->implement == agl_device) {
103 node->pacard.index = data->pacard.index;
104 if (data->pacard.profile)
105 node->pacard.profile = pa_xstrdup (data->pacard.profile);
107 node->paport = data->paport;
111 /* TODO : register the node to the router */
112 /* agl_router_register_node (u, node); */
117 const char *agl_node_type_str (agl_node_type type)
120 case agl_node_type_unknown: return "Unknown";
121 case agl_radio: return "Radio";
122 case agl_player: return "Player";
123 case agl_navigator: return "Navigator";
124 case agl_game: return "Game";
125 case agl_browser: return "Browser";
126 case agl_camera: return "Camera";
127 case agl_phone: return "Phone";
128 case agl_alert: return "Alert";
129 case agl_event: return "Event";
130 case agl_system: return "System";
131 default: return "<user defined>";
135 agl_node *agl_node_get_from_data (struct userdata *u, agl_direction type, void *data)
137 pa_sink_input_new_data *sinp_data;
138 pa_source_output_new_data *sout_data;
145 pa_assert (nodeset = u->nodeset);
147 pa_assert (type == agl_input || type == agl_output);
149 /* input (= sink_input) */
150 if (type == agl_input) {
151 sinp_data = (pa_sink_input_new_data *) data;
152 PA_IDXSET_FOREACH(node, nodeset->nodes, index) {
153 if (node->client == sinp_data->client)
156 /* output (= source_output) TODO */
163 agl_node *agl_node_get_from_client (struct userdata *u, pa_client *client)
171 pa_assert (nodeset = u->nodeset);
173 PA_IDXSET_FOREACH(node, nodeset->nodes, index) {
174 if (node->client == client)