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>
45 #ifndef DEFAULT_CONFIG_DIR
46 #define DEFAULT_CONFIG_DIR "/etc/pulse"
49 #define DEFAULT_NULL_SINK_NAME "null.mir"
53 uint32_t module_index;
58 static uint32_t stamp;
60 static char *sink_input_name(pa_proplist *);
63 pa_null_sink *pa_utils_create_null_sink(struct userdata *u, const char *name)
74 pa_assert_se((core = u->core));
78 name = DEFAULT_NULL_SINK_NAME;
81 snprintf(args, sizeof(args), "sink_name=\"%s\" channels=2", name);
82 module = pa_module_load(core, "module-null-sink", args);
86 pa_log("failed to load null sink '%s'", name);
88 PA_IDXSET_FOREACH(s, core->sinks, idx) {
89 if (s->module && s->module == module) {
91 pa_log_info("mir null sink is '%s'", name);
97 ns = pa_xnew0(pa_null_sink, 1);
98 ns->name = pa_xstrdup(name);
99 ns->module_index = module ? module->index : PA_IDXSET_INVALID;
100 ns->sink_index = sink ? sink->index : PA_IDXSET_INVALID;
105 void pa_utils_destroy_null_sink(struct userdata *u)
111 if (u && (ns = u->nullsink) && (core = u->core)) {
112 if ((module = pa_idxset_get_by_index(core->modules,ns->module_index))){
113 pa_log_info("unloading null sink '%s'", ns->name);
114 pa_module_unload(core, module, FALSE);
122 pa_sink *pa_utils_get_null_sink(struct userdata *u)
128 pa_assert_se((core = u->core));
129 pa_assert_se((ns = u->nullsink));
131 return pa_idxset_get_by_index(core->sinks, ns->sink_index);
136 char *pa_utils_get_card_name(pa_card *card)
138 return (card && card->name) ? card->name : "<unknown>";
141 char *pa_utils_get_sink_name(pa_sink *sink)
143 return (sink && sink->name) ? sink->name : "<unknown>";
146 char *pa_utils_get_source_name(pa_source *source)
148 return (source && source->name) ? source->name : "<unknown>";
151 char *pa_utils_get_sink_input_name(pa_sink_input *sinp)
155 if (sinp && (name = sink_input_name(sinp->proplist)))
161 char *pa_utils_get_sink_input_name_from_data(pa_sink_input_new_data *data)
165 if (data && (name = sink_input_name(data->proplist)))
172 void pa_utils_set_stream_routing_properties(pa_proplist *pl,
181 pa_assert(styp >= 0);
183 snprintf(clid, sizeof(clid), "%d", styp);
184 clnam = mir_node_type_str(styp);
185 method = sink ? PA_ROUTING_EXPLICIT : PA_ROUTING_DEFAULT;
187 if (pa_proplist_sets(pl, PA_PROP_ROUTING_CLASS_NAME, clnam ) < 0 ||
188 pa_proplist_sets(pl, PA_PROP_ROUTING_CLASS_ID , clid ) < 0 ||
189 pa_proplist_sets(pl, PA_PROP_ROUTING_METHOD , method) < 0 )
191 pa_log("failed to set some property on sink-input");
195 void pa_utils_set_stream_routing_method_property(pa_proplist *pl,
198 const char *method = explicit ? PA_ROUTING_EXPLICIT : PA_ROUTING_DEFAULT;
202 if (pa_proplist_sets(pl, PA_PROP_ROUTING_METHOD, method) < 0) {
203 pa_log("failed to set routing method property on sink-input");
207 pa_bool_t pa_utils_stream_has_default_route(pa_proplist *pl)
213 method = pa_proplist_gets(pl, PA_PROP_ROUTING_METHOD);
215 if (method && pa_streq(method, PA_ROUTING_DEFAULT))
221 int pa_utils_get_stream_class(pa_proplist *pl)
223 const char *clid_str;
225 unsigned long int clid = 0;
229 if ((clid_str = pa_proplist_gets(pl, PA_PROP_ROUTING_CLASS_ID))) {
230 clid = strtoul(clid_str, &e, 10);
240 static char *sink_input_name(pa_proplist *pl)
245 if ((appnam = pa_proplist_gets(pl, PA_PROP_APPLICATION_NAME)))
246 return (char *)appnam;
248 if ((binnam = pa_proplist_gets(pl, PA_PROP_APPLICATION_PROCESS_BINARY)))
249 return (char *)binnam;
255 const char *pa_utils_file_path(const char *file, char *buf, size_t len)
261 snprintf(buf, len, "%s/%s", DEFAULT_CONFIG_DIR, file);
267 uint32_t pa_utils_new_stamp(void)
272 uint32_t pa_utils_get_stamp(void)
283 * indent-tabs-mode: nil