#include <pulsecore/pulsecore-config.h>
#include <pulsecore/core-util.h>
-#include <pulsecore/card.h>
#include <pulsecore/sink.h>
+#include <pulsecore/card.h>
#include <pulsecore/source.h>
#include <pulsecore/sink-input.h>
#include <pulsecore/source-output.h>
static uint32_t stamp;
static char *stream_name(pa_proplist *);
+static pa_bool_t get_unsigned_property(pa_proplist *, const char *,uint32_t *);
pa_null_sink *pa_utils_create_null_sink(struct userdata *u, const char *name)
return "<unknown>";
}
+char *pa_utils_get_zone(pa_proplist *pl)
+{
+ const char *zone;
+
+ pa_assert(pl);
+
+ if (!(zone = pa_proplist_gets(pl, PA_PROP_ZONE_NAME)))
+ zone = PA_ZONE_NAME_DEFAULT;
+
+ return (char *)zone;
+}
pa_bool_t pa_utils_set_stream_routing_properties(pa_proplist *pl,
int styp,
return (int)clid;
}
+
+pa_bool_t pa_utils_set_resource_properties(pa_proplist *pl,
+ pa_nodeset_resdef *resdef)
+{
+ char priority[32];
+ char rsetflags[32];
+ char audioflags[32];
+
+ pa_assert(pl);
+
+ if (!resdef)
+ return FALSE;
+
+ snprintf(priority , sizeof(priority) , "%d", resdef->priority );
+ snprintf(rsetflags , sizeof(rsetflags) , "%d", resdef->flags.rset );
+ snprintf(audioflags, sizeof(audioflags), "%d", resdef->flags.audio);
+
+ if (pa_proplist_sets(pl, PA_PROP_RESOURCE_PRIORITY , priority ) < 0 ||
+ pa_proplist_sets(pl, PA_PROP_RESOURCE_SET_FLAGS , rsetflags ) < 0 ||
+ pa_proplist_sets(pl, PA_PROP_RESOURCE_AUDIO_FLAGS, audioflags) < 0 )
+ {
+ pa_log("failed to set some resource property");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+pa_bool_t pa_utils_unset_resource_properties(pa_proplist *pl)
+{
+ pa_assert(pl);
+
+ if (pa_proplist_unset(pl, PA_PROP_RESOURCE_PRIORITY ) < 0 ||
+ pa_proplist_unset(pl, PA_PROP_RESOURCE_SET_FLAGS ) < 0 ||
+ pa_proplist_unset(pl, PA_PROP_RESOURCE_AUDIO_FLAGS) < 0 )
+ {
+ pa_log("failed to unset some resource property");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+pa_nodeset_resdef *pa_utils_get_resource_properties(pa_proplist *pl,
+ pa_nodeset_resdef *rd)
+{
+ pa_assert(pl);
+ pa_assert(rd);
+
+ int success;
+
+ memset(rd, 0, sizeof(pa_nodeset_resdef));
+
+ success = get_unsigned_property(pl, PA_PROP_RESOURCE_PRIORITY,
+ &rd->priority);
+ success |= get_unsigned_property(pl, PA_PROP_RESOURCE_SET_FLAGS,
+ &rd->flags.rset);
+ success |= get_unsigned_property(pl, PA_PROP_RESOURCE_AUDIO_FLAGS,
+ &rd->flags.audio);
+
+ return success ? rd : NULL;
+}
+
+
+static pa_bool_t get_unsigned_property(pa_proplist *pl,
+ const char *name,
+ uint32_t *value)
+{
+ const char *str;
+ char *e;
+
+ pa_assert(pl);
+ pa_assert(name);
+ pa_assert(value);
+
+ if (!(str = pa_proplist_gets(pl, name))) {
+ *value = 0;
+ return FALSE;
+ }
+
+ *value = strtoul(str, &e, 10);
+
+ if (e == str || *e) {
+ *value = 0;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
void pa_utils_set_port_properties(pa_device_port *port, mir_node *node)
{
+ const char *profile;
+ char propnam[512];
char nodeidx[256];
pa_assert(port);
pa_assert(port->proplist);
pa_assert(node);
+ pa_assert_se((profile = node->pacard.profile));
+ snprintf(propnam, sizeof(propnam), "%s.%s", PA_PROP_NODE_INDEX, profile);
snprintf(nodeidx, sizeof(nodeidx), "%u", node->index);
- pa_proplist_sets(port->proplist, PA_PROP_NODE_INDEX, nodeidx);
+ pa_proplist_sets(port->proplist, propnam, nodeidx);
}
mir_node *pa_utils_get_node_from_port(struct userdata *u,
- pa_device_port *port)
+ pa_device_port *port,
+ void **state)
{
+ const char *name;
const char *value;
char *e;
uint32_t index = PA_IDXSET_INVALID;
pa_assert(port);
pa_assert(port->proplist);
- if ((value = pa_proplist_gets(port->proplist, PA_PROP_NODE_INDEX))) {
- index = strtoul(value, &e, 10);
+ while ((name = pa_proplist_iterate(port->proplist, state))) {
+ if (!strncmp(name, PA_PROP_NODE_INDEX, sizeof(PA_PROP_NODE_INDEX)-1)) {
+ if ((value = pa_proplist_gets(port->proplist, name))) {
+ index = strtoul(value, &e, 10);
+ node = NULL;
- if (value[0] && !e[0])
- node = mir_node_find_by_index(u, index);
+ if (value[0] && !e[0])
+ node = mir_node_find_by_index(u, index);
+
+ if (node)
+ return node;
+
+ pa_log("Can't find node %u for port %s", index, port->name);
+ }
+ }
}
- return node;
+ return NULL;
}
mir_node *pa_utils_get_node_from_stream(struct userdata *u,
-
/*
* Local Variables:
* c-basic-offset: 4