2 * module-murphy-ivi -- PulseAudio module for providing audio routing support
3 * Copyright (c) 2012, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU Lesser General Public License,
7 * version 2.1, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
30 #include <sys/types.h>
31 #include <sys/socket.h>
33 #include <pulsecore/pulsecore-config.h>
35 #include <pulsecore/core-util.h>
36 #include <pulsecore/card.h>
37 #include <pulsecore/sink.h>
38 #include <pulsecore/source.h>
39 #include <pulsecore/sink-input.h>
40 #include <pulsecore/source-output.h>
46 #ifndef DEFAULT_CONFIG_DIR
47 #define DEFAULT_CONFIG_DIR "/etc/pulse"
50 #define DEFAULT_NULL_SINK_NAME "null.mir"
54 uint32_t module_index;
59 static uint32_t stamp;
61 static char *stream_name(pa_proplist *);
64 pa_null_sink *pa_utils_create_null_sink(struct userdata *u, const char *name)
75 pa_assert_se((core = u->core));
79 name = DEFAULT_NULL_SINK_NAME;
82 snprintf(args, sizeof(args), "sink_name=\"%s\" channels=2", name);
83 module = pa_module_load(core, "module-null-sink", args);
87 pa_log("failed to load null sink '%s'", name);
89 PA_IDXSET_FOREACH(s, core->sinks, idx) {
90 if (s->module && s->module == module) {
92 pa_log_info("mir null sink is '%s'", name);
98 ns = pa_xnew0(pa_null_sink, 1);
99 ns->name = pa_xstrdup(name);
100 ns->module_index = module ? module->index : PA_IDXSET_INVALID;
101 ns->sink_index = sink ? sink->index : PA_IDXSET_INVALID;
106 void pa_utils_destroy_null_sink(struct userdata *u)
112 if (u && (ns = u->nullsink) && (core = u->core)) {
113 if ((module = pa_idxset_get_by_index(core->modules,ns->module_index))){
114 pa_log_info("unloading null sink '%s'", ns->name);
115 pa_module_unload(core, module, FALSE);
123 pa_sink *pa_utils_get_null_sink(struct userdata *u)
129 pa_assert_se((core = u->core));
130 pa_assert_se((ns = u->nullsink));
132 return pa_idxset_get_by_index(core->sinks, ns->sink_index);
135 pa_source *pa_utils_get_null_source(struct userdata *u)
137 pa_sink *ns = pa_utils_get_null_sink(u);
139 return ns ? ns->monitor_source : NULL;
144 char *pa_utils_get_card_name(pa_card *card)
146 return (card && card->name) ? card->name : "<unknown>";
149 char *pa_utils_get_sink_name(pa_sink *sink)
151 return (sink && sink->name) ? sink->name : "<unknown>";
154 char *pa_utils_get_source_name(pa_source *source)
156 return (source && source->name) ? source->name : "<unknown>";
159 char *pa_utils_get_sink_input_name(pa_sink_input *sinp)
163 if (sinp && (name = stream_name(sinp->proplist)))
169 char *pa_utils_get_sink_input_name_from_data(pa_sink_input_new_data *data)
173 if (data && (name = stream_name(data->proplist)))
180 char *pa_utils_get_source_output_name(pa_source_output *sout)
184 if (sout && (name = stream_name(sout->proplist)))
190 char *pa_utils_get_source_output_name_from_data(pa_source_output_new_data*data)
194 if (data && (name = stream_name(data->proplist)))
201 void pa_utils_set_stream_routing_properties(pa_proplist *pl,
210 pa_assert(styp >= 0);
212 snprintf(clid, sizeof(clid), "%d", styp);
213 clnam = mir_node_type_str(styp);
214 method = target ? PA_ROUTING_EXPLICIT : PA_ROUTING_DEFAULT;
216 if (pa_proplist_sets(pl, PA_PROP_ROUTING_CLASS_NAME, clnam ) < 0 ||
217 pa_proplist_sets(pl, PA_PROP_ROUTING_CLASS_ID , clid ) < 0 ||
218 pa_proplist_sets(pl, PA_PROP_ROUTING_METHOD , method) < 0 )
220 pa_log("failed to set some stream property");
224 void pa_utils_set_stream_routing_method_property(pa_proplist *pl,
227 const char *method = explicit ? PA_ROUTING_EXPLICIT : PA_ROUTING_DEFAULT;
231 if (pa_proplist_sets(pl, PA_PROP_ROUTING_METHOD, method) < 0) {
232 pa_log("failed to set routing method property on sink-input");
236 pa_bool_t pa_utils_stream_has_default_route(pa_proplist *pl)
242 method = pa_proplist_gets(pl, PA_PROP_ROUTING_METHOD);
244 if (method && pa_streq(method, PA_ROUTING_DEFAULT))
250 int pa_utils_get_stream_class(pa_proplist *pl)
252 const char *clid_str;
254 unsigned long int clid = 0;
258 if ((clid_str = pa_proplist_gets(pl, PA_PROP_ROUTING_CLASS_ID))) {
259 clid = strtoul(clid_str, &e, 10);
268 void pa_utils_set_port_properties(pa_device_port *port, mir_node *node)
273 pa_assert(port->proplist);
276 snprintf(nodeidx, sizeof(nodeidx), "%u", node->index);
278 pa_proplist_sets(port->proplist, PA_PROP_NODE_INDEX, nodeidx);
281 mir_node *pa_utils_get_node_from_port(struct userdata *u,
282 pa_device_port *port)
286 uint32_t index = PA_IDXSET_INVALID;
287 mir_node *node = NULL;
291 pa_assert(port->proplist);
293 if ((value = pa_proplist_gets(port->proplist, PA_PROP_NODE_INDEX))) {
294 index = strtoul(value, &e, 10);
296 if (value[0] && !e[0])
297 node = mir_node_find_by_index(u, index);
303 mir_node *pa_utils_get_node_from_stream(struct userdata *u,
308 pa_source_output *sout;
311 const char *index_str;
312 uint32_t index = PA_IDXSET_INVALID;
318 pa_assert(type == mir_input || type == mir_output);
320 if (type == mir_input) {
321 sinp = (pa_sink_input *)ptr;
323 snprintf(name, sizeof(name), "sink-input.%u", sinp->index);
326 sout = (pa_source_output *)ptr;
328 snprintf(name, sizeof(name), "source-output.%u", sout->index);
332 if ((index_str = pa_proplist_gets(pl, PA_PROP_NODE_INDEX))) {
333 index = strtoul(index_str, &e, 10);
334 if (e != index_str && *e == '\0') {
335 if ((node = mir_node_find_by_index(u, index)))
338 pa_log_debug("can't find find node for %s", name);
345 mir_node *pa_utils_get_node_from_data(struct userdata *u,
349 pa_sink_input_new_data *sinp;
350 pa_source_output_new_data *sout;
353 const char *index_str;
354 uint32_t index = PA_IDXSET_INVALID;
360 pa_assert(type == mir_input || type == mir_output);
362 if (type == mir_input) {
363 sinp = (pa_sink_input_new_data *)ptr;
365 snprintf(name, sizeof(name), "sink-input");
368 sout = (pa_source_output_new_data *)ptr;
370 snprintf(name, sizeof(name), "source-output");
374 if ((index_str = pa_proplist_gets(pl, PA_PROP_NODE_INDEX))) {
375 index = strtoul(index_str, &e, 10);
376 if (e != index_str && *e == '\0') {
377 if ((node = mir_node_find_by_index(u, index)))
380 pa_log_debug("can't find find node for %s", name);
387 static char *stream_name(pa_proplist *pl)
392 if ((appnam = pa_proplist_gets(pl, PA_PROP_APPLICATION_NAME)))
393 return (char *)appnam;
395 if ((binnam = pa_proplist_gets(pl, PA_PROP_APPLICATION_PROCESS_BINARY)))
396 return (char *)binnam;
402 const char *pa_utils_file_path(const char *file, char *buf, size_t len)
408 snprintf(buf, len, "%s/%s", DEFAULT_CONFIG_DIR, file);
414 uint32_t pa_utils_new_stamp(void)
419 uint32_t pa_utils_get_stamp(void)
430 * indent-tabs-mode: nil