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);
134 pa_source *pa_utils_get_null_source(struct userdata *u)
136 pa_sink *ns = pa_utils_get_null_sink(u);
138 return ns ? ns->monitor_source : NULL;
143 char *pa_utils_get_card_name(pa_card *card)
145 return (card && card->name) ? card->name : "<unknown>";
148 char *pa_utils_get_sink_name(pa_sink *sink)
150 return (sink && sink->name) ? sink->name : "<unknown>";
153 char *pa_utils_get_source_name(pa_source *source)
155 return (source && source->name) ? source->name : "<unknown>";
158 char *pa_utils_get_sink_input_name(pa_sink_input *sinp)
162 if (sinp && (name = sink_input_name(sinp->proplist)))
168 char *pa_utils_get_sink_input_name_from_data(pa_sink_input_new_data *data)
172 if (data && (name = sink_input_name(data->proplist)))
179 void pa_utils_set_stream_routing_properties(pa_proplist *pl,
188 pa_assert(styp >= 0);
190 snprintf(clid, sizeof(clid), "%d", styp);
191 clnam = mir_node_type_str(styp);
192 method = sink ? PA_ROUTING_EXPLICIT : PA_ROUTING_DEFAULT;
194 if (pa_proplist_sets(pl, PA_PROP_ROUTING_CLASS_NAME, clnam ) < 0 ||
195 pa_proplist_sets(pl, PA_PROP_ROUTING_CLASS_ID , clid ) < 0 ||
196 pa_proplist_sets(pl, PA_PROP_ROUTING_METHOD , method) < 0 )
198 pa_log("failed to set some property on sink-input");
202 void pa_utils_set_stream_routing_method_property(pa_proplist *pl,
205 const char *method = explicit ? PA_ROUTING_EXPLICIT : PA_ROUTING_DEFAULT;
209 if (pa_proplist_sets(pl, PA_PROP_ROUTING_METHOD, method) < 0) {
210 pa_log("failed to set routing method property on sink-input");
214 pa_bool_t pa_utils_stream_has_default_route(pa_proplist *pl)
220 method = pa_proplist_gets(pl, PA_PROP_ROUTING_METHOD);
222 if (method && pa_streq(method, PA_ROUTING_DEFAULT))
228 int pa_utils_get_stream_class(pa_proplist *pl)
230 const char *clid_str;
232 unsigned long int clid = 0;
236 if ((clid_str = pa_proplist_gets(pl, PA_PROP_ROUTING_CLASS_ID))) {
237 clid = strtoul(clid_str, &e, 10);
247 static char *sink_input_name(pa_proplist *pl)
252 if ((appnam = pa_proplist_gets(pl, PA_PROP_APPLICATION_NAME)))
253 return (char *)appnam;
255 if ((binnam = pa_proplist_gets(pl, PA_PROP_APPLICATION_PROCESS_BINARY)))
256 return (char *)binnam;
262 const char *pa_utils_file_path(const char *file, char *buf, size_t len)
268 snprintf(buf, len, "%s/%s", DEFAULT_CONFIG_DIR, file);
274 uint32_t pa_utils_new_stamp(void)
279 uint32_t pa_utils_get_stamp(void)
290 * indent-tabs-mode: nil