+/*** Sources ***/
+
+#define HASH_NODE struct pulse_source
+#define HASH_PREFIX(x) pulse_source_##x
+#define HASH_KEY_ATOMIC idx
+#define HASH_WANT_CLEANUP
+#define HASH_WANT_LOOKUP
+#define HASH_WANT_REMOVE
+#define HASH_ZERO_FILL
+#include <ucw/hashtable.h>
+
+static void pulse_source_cb(pa_context *ctx UNUSED, const pa_source_info *i, int eol, void *userdata)
+{
+ struct pulse_op *op = userdata;
+
+ if (eol)
+ {
+ if (op->is_init)
+ {
+ PULSE_STATE(PS_GET_SERVER);
+ PULSE_ASYNC_INIT_RUN(pa_context_get_server_info, pulse_server_cb);
+ }
+ pulse_op_done(op);
+ return;
+ }
+
+ DBG("Pulse: SOURCE #%u: %s (%s) flags=%08x channels=%u volume=%u mute=%d base_vol=%u state=%u port=%s",
+ i->index, i->name, i->description, i->flags, i->channel_map.channels, i->volume.values[0], i->mute, i->base_volume, i->state,
+ (i->active_port ? i->active_port->name : "none"));
+ pulse_dump_proplist(i->proplist);
+
+ struct pulse_source *s = pulse_source_lookup(i->index);
+ if (!clist_is_linked(&s->n))
+ clist_add_tail(&pulse_source_list, &s->n);
+ SET_STRING(s->name, i->name);
+ s->channels = i->channel_map.channels;
+ s->volume = pa_cvolume_avg(&i->volume);
+ s->base_volume = i->base_volume;
+ s->mute = i->mute;
+ s->suspended = (i->state == PA_SOURCE_SUSPENDED);
+ SET_STRING(s->active_port, (i->active_port ? i->active_port->name : "none"));
+ schedule_update();
+}
+
+static void pulse_source_gone(int idx)
+{
+ DBG("Pulse: REMOVE SOURCE #%d", idx);
+ struct pulse_source *s = pulse_source_lookup(idx);
+ clist_remove(&s->n);
+ pulse_source_remove(s);
+ schedule_update();
+}
+
+struct pulse_source *pulse_source_by_name(const char *name)
+{
+ CLIST_FOR_EACH(struct pulse_source *, s, pulse_source_list)
+ if (!strcmp(s->name, name))
+ return s;
+ return NULL;
+}
+
+struct pulse_source *pulse_source_by_idx(int idx)
+{
+ return pulse_source_lookup(idx);
+}
+
+void pulse_source_set_volume(int idx, pa_cvolume *cvol)
+{
+ PULSE_ASYNC_RUN(pa_context_set_source_volume_by_index, idx, cvol, pulse_success_cb);
+}
+
+void pulse_source_set_mute(int idx, bool mute)
+{
+ PULSE_ASYNC_RUN(pa_context_set_source_mute_by_index, idx, mute, pulse_success_cb);
+}
+
+void pulse_source_set_port(int idx, const char *port)
+{
+ PULSE_ASYNC_RUN(pa_context_set_source_port_by_index, idx, port, pulse_success_cb);
+}
+