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,
26 #define DEFAULT_NULL_SINK_NAME "null.agl"
28 #ifndef PA_PROP_PROCESS_ENVIRONMENT
29 #define PA_PROP_PROCESS_ENVIRONMENT "application.process.environment"
31 #define PA_ZONE_NAME_DEFAULT "driver"
32 #define PA_PROP_ZONE_NAME "zone.name"
33 #define PA_PROP_ENV_ZONE PA_PROP_PROCESS_ENVIRONMENT ".AUDIO_ZONE"
35 #define PA_PROP_ROUTING_CLASS_NAME "routing.class.name"
36 #define PA_PROP_ROUTING_CLASS_ID "routing.class.id"
37 #define PA_PROP_ROUTING_METHOD "routing.method"
39 static uint32_t stamp;
43 uint32_t module_index;
47 pa_null_sink *pa_utils_create_null_sink (struct userdata *u, const char *name)
57 pa_assert_se (core = u->core);
60 name = DEFAULT_NULL_SINK_NAME; /* default is "null.agl" */
62 snprintf (args, sizeof(args), "sink_name=\"%s.%d\" channels=2", name, pa_utils_new_stamp ());
63 module = pa_module_load (core, "module-null-sink", args);
67 pa_log ("failed to load null sink '%s'", name);
70 PA_IDXSET_FOREACH(s, core->sinks, idx) {
71 if (s->module && s->module == module) {
73 pa_log_info("created agl null sink named '%s'", name);
79 ns = pa_xnew0 (pa_null_sink, 1);
80 ns->name = pa_xstrdup (name);
81 ns->module_index = module ? module->index : PA_IDXSET_INVALID;
82 ns->sink_index = sink ? sink->index : PA_IDXSET_INVALID;
87 void pa_utils_destroy_null_sink (struct userdata *u, pa_null_sink *ns)
92 if (u && (core = u->core)) {
93 if ((module = pa_idxset_get_by_index (core->modules, ns->module_index))){
94 pa_log_info ("unloading null sink '%s'", ns->name);
95 pa_module_unload (core, module, false);
103 pa_sink *pa_utils_get_null_sink (struct userdata *u, struct pa_null_sink *ns)
109 pa_assert_se ((core = u->core));
111 return pa_idxset_get_by_index (core->sinks, ns->sink_index);
114 pa_source *pa_utils_get_null_source (struct userdata *u, struct pa_null_sink *ns)
118 sink = pa_utils_get_null_sink (u, ns);
120 return sink ? sink->monitor_source : NULL;
124 const char *pa_utils_get_card_name (pa_card *card)
126 return (card && card->name) ? card->name : "<unknown>";
129 const char *pa_utils_get_card_bus (pa_card *card)
131 const char *bus = NULL;
134 if (card && !(bus = pa_proplist_gets (card->proplist,PA_PROP_DEVICE_BUS))) {
135 name = pa_utils_get_card_name (card);
136 if (!strncmp (name, "alsa_card.", 10)) {
137 if (!strncmp (name + 10, "pci-", 4))
139 else if (!strncmp (name + 10, "platform-", 9))
141 else if (!strncmp (name + 10, "usb-", 4))
149 const char *pa_utils_get_sink_name (pa_sink *sink)
151 return (sink && sink->name) ? sink->name : "<unknown>";
154 const char *pa_utils_get_source_name (pa_source *source)
156 return (source && source->name) ? source->name : "<unknown>";
159 const char *pa_utils_get_sink_input_name (pa_sink_input *sinp)
163 if (sinp && sinp->proplist) {
164 name = (char *)pa_proplist_gets (sinp->proplist, PA_PROP_APPLICATION_NAME);
166 name = (char *)pa_proplist_gets (sinp->proplist, PA_PROP_APPLICATION_PROCESS_BINARY);
171 return (const char *)name;
174 const char *pa_utils_get_source_output_name (pa_source_output *sout)
178 if (sout && sout->proplist) {
179 name = (char *)pa_proplist_gets (sout->proplist, PA_PROP_APPLICATION_NAME);
181 name = (char *)pa_proplist_gets (sout->proplist, PA_PROP_APPLICATION_PROCESS_BINARY);
186 return (const char *)name;
189 pa_sink *pa_utils_get_primary_alsa_sink (struct userdata *u)
196 pa_assert_se ((core = u->core));
198 PA_IDXSET_FOREACH(sink, core->sinks, idx) {
199 if (sink->name && strstr (sink->name, "alsa_output"))
206 void pa_utils_init_stamp (void)
211 uint32_t pa_utils_new_stamp (void)
216 uint32_t pa_utils_get_stamp (void)
223 char *pa_utils_get_zone (pa_proplist *pl, pa_proplist *client_props)
229 /* grab the "zone.name" PA_PROP environment variable ;
230 * otherwise just fall back to default "driver" zone */
231 zone = pa_proplist_gets (pl, PA_PROP_ZONE_NAME);
233 if (!client_props || !(zone = pa_proplist_gets (client_props, PA_PROP_ENV_ZONE)))
234 zone = PA_ZONE_NAME_DEFAULT;
240 bool pa_utils_set_stream_routing_properties (pa_proplist *pl, int styp, void *target)
242 const char *clnam; /* will become "agl_player" e.g. */
243 char clid[32]; /* will become "1" e.g. */
244 const char *method; /* will become "default" (it target is NULL) or "explicit" */
247 pa_assert (styp >= 0); /* type different from "agl_node_type_unknown" */
249 clnam = agl_node_type_str (styp);
250 snprintf (clid, sizeof(clid), "%d", styp);
251 method = target ? "explicit" : "default";
253 if (pa_proplist_sets (pl, PA_PROP_ROUTING_CLASS_NAME, clnam ) < 0 ||
254 pa_proplist_sets (pl, PA_PROP_ROUTING_CLASS_ID , clid ) < 0 ||
255 pa_proplist_sets (pl, PA_PROP_ROUTING_METHOD , method) < 0)
257 pa_log ("failed to set some stream property");
264 bool pa_utils_unset_stream_routing_properties (pa_proplist *pl)
268 if (pa_proplist_unset (pl, PA_PROP_ROUTING_CLASS_NAME) < 0 ||
269 pa_proplist_unset (pl, PA_PROP_ROUTING_CLASS_ID ) < 0 ||
270 pa_proplist_unset (pl, PA_PROP_ROUTING_METHOD ) < 0)
272 pa_log ("failed to unset some stream property");