11 #include <sys/types.h>
12 #include <sys/socket.h>
14 #include <pulsecore/pulsecore-config.h>
16 #include <pulsecore/core-util.h>
17 #include <pulsecore/card.h>
18 #include <pulsecore/sink.h>
19 #include <pulsecore/source.h>
20 #include <pulsecore/sink-input.h>
26 #ifndef DEFAULT_CONFIG_DIR
27 #define DEFAULT_CONFIG_DIR "/etc/pulse"
30 #define DEFAULT_NULL_SINK_NAME "null.mir"
34 uint32_t module_index;
39 static uint32_t stamp;
41 static char *sink_input_name(pa_proplist *);
44 pa_null_sink *pa_utils_create_null_sink(struct userdata *u, const char *name)
55 pa_assert_se((core = u->core));
59 name = DEFAULT_NULL_SINK_NAME;
62 snprintf(args, sizeof(args), "sink_name=\"%s\" channels=2", name);
63 module = pa_module_load(core, "module-null-sink", args);
67 pa_log("failed to load null sink '%s'", name);
69 PA_IDXSET_FOREACH(s, core->sinks, idx) {
70 if (s->module && s->module == module) {
72 pa_log_info("mir null sink is '%s'", name);
78 ns = pa_xnew0(pa_null_sink, 1);
79 ns->name = pa_xstrdup(name);
80 ns->module_index = module ? module->index : PA_IDXSET_INVALID;
81 ns->sink_index = sink ? sink->index : PA_IDXSET_INVALID;
86 void pa_utils_destroy_null_sink(struct userdata *u)
92 if (u && (ns = u->nullsink) && (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)
109 pa_assert_se((core = u->core));
110 pa_assert_se((ns = u->nullsink));
112 return pa_idxset_get_by_index(core->sinks, ns->sink_index);
117 char *pa_utils_get_card_name(pa_card *card)
119 return (card && card->name) ? card->name : "<unknown>";
122 char *pa_utils_get_sink_name(pa_sink *sink)
124 return (sink && sink->name) ? sink->name : "<unknown>";
127 char *pa_utils_get_source_name(pa_source *source)
129 return (source && source->name) ? source->name : "<unknown>";
132 char *pa_utils_get_sink_input_name(pa_sink_input *sinp)
136 if (sinp && (name = sink_input_name(sinp->proplist)))
142 char *pa_utils_get_sink_input_name_from_data(pa_sink_input_new_data *data)
146 if (data && (name = sink_input_name(data->proplist)))
153 void pa_utils_set_stream_routing_properties(pa_proplist *pl,
164 snprintf(clid, sizeof(clid), "%d", styp);
165 clnam = mir_node_type_str(styp);
166 method = sink ? PA_ROUTING_EXPLICIT : PA_ROUTING_DEFAULT;
168 if (pa_proplist_sets(pl, PA_PROP_ROUTING_CLASS_NAME, clnam ) < 0 ||
169 pa_proplist_sets(pl, PA_PROP_ROUTING_CLASS_ID , clid ) < 0 ||
170 pa_proplist_sets(pl, PA_PROP_ROUTING_METHOD , method) < 0 )
172 pa_log("failed to set properties on sink-input. "
173 "some routing function might malfunction later on");
177 pa_bool_t pa_utils_stream_has_default_route(pa_proplist *pl)
183 method = pa_proplist_gets(pl, PA_PROP_ROUTING_METHOD);
185 if (method && pa_streq(method, PA_ROUTING_DEFAULT))
192 static char *sink_input_name(pa_proplist *pl)
197 if ((appnam = pa_proplist_gets(pl, PA_PROP_APPLICATION_NAME)))
198 return (char *)appnam;
200 if ((binnam = pa_proplist_gets(pl, PA_PROP_APPLICATION_PROCESS_BINARY)))
201 return (char *)binnam;
207 const char *pa_utils_file_path(const char *file, char *buf, size_t len)
213 snprintf(buf, len, "%s/%s", DEFAULT_CONFIG_DIR, file);
219 const uint32_t pa_utils_new_stamp(void)
224 const uint32_t pa_utils_get_stamp(void)
235 * indent-tabs-mode: nil