summaryrefslogtreecommitdiffstats
path: root/pulse/ctl_pulse.c
diff options
context:
space:
mode:
Diffstat (limited to 'pulse/ctl_pulse.c')
-rw-r--r--pulse/ctl_pulse.c1000
1 files changed, 519 insertions, 481 deletions
diff --git a/pulse/ctl_pulse.c b/pulse/ctl_pulse.c
index dcf2769..6fa6546 100644
--- a/pulse/ctl_pulse.c
+++ b/pulse/ctl_pulse.c
@@ -28,19 +28,19 @@
typedef struct snd_ctl_pulse {
snd_ctl_ext_t ext;
- snd_pulse_t *p;
+ snd_pulse_t *p;
- char *source;
- char *sink;
+ char *source;
+ char *sink;
- pa_cvolume sink_volume;
- pa_cvolume source_volume;
+ pa_cvolume sink_volume;
+ pa_cvolume source_volume;
- int sink_muted;
- int source_muted;
+ int sink_muted;
+ int source_muted;
- int subscribed;
- int updated;
+ int subscribed;
+ int updated;
} snd_ctl_pulse_t;
#define SOURCE_VOL_NAME "Capture Volume"
@@ -53,534 +53,566 @@ typedef struct snd_ctl_pulse {
#define UPDATE_SOURCE_VOL 0x04
#define UPDATE_SOURCE_MUTE 0x08
-static void sink_info_cb(pa_context *c, const pa_sink_info *i, int is_last, void *userdata)
+static void sink_info_cb(pa_context * c, const pa_sink_info * i,
+ int is_last, void *userdata)
{
- snd_ctl_pulse_t *ctl = (snd_ctl_pulse_t*)userdata;
- int chan;
+ snd_ctl_pulse_t *ctl = (snd_ctl_pulse_t *) userdata;
+ int chan;
- assert(ctl);
+ assert(ctl);
- if (is_last) {
- pa_threaded_mainloop_signal(ctl->p->mainloop, 0);
- return;
- }
+ if (is_last) {
+ pa_threaded_mainloop_signal(ctl->p->mainloop, 0);
+ return;
+ }
- assert(i);
+ assert(i);
- if (!!ctl->sink_muted != !!i->mute) {
- ctl->sink_muted = i->mute;
- ctl->updated |= UPDATE_SINK_MUTE;
- pulse_poll_activate(ctl->p);
- }
+ if (!!ctl->sink_muted != !!i->mute) {
+ ctl->sink_muted = i->mute;
+ ctl->updated |= UPDATE_SINK_MUTE;
+ pulse_poll_activate(ctl->p);
+ }
- if (ctl->sink_volume.channels == i->volume.channels) {
- for (chan = 0;chan < ctl->sink_volume.channels;chan++)
- if (i->volume.values[chan] != ctl->sink_volume.values[chan])
- break;
+ if (ctl->sink_volume.channels == i->volume.channels) {
+ for (chan = 0; chan < ctl->sink_volume.channels; chan++)
+ if (i->volume.values[chan] !=
+ ctl->sink_volume.values[chan])
+ break;
- if (chan == ctl->sink_volume.channels)
- return;
+ if (chan == ctl->sink_volume.channels)
+ return;
- ctl->updated |= UPDATE_SINK_VOL;
- pulse_poll_activate(ctl->p);
- }
+ ctl->updated |= UPDATE_SINK_VOL;
+ pulse_poll_activate(ctl->p);
+ }
- memcpy(&ctl->sink_volume, &i->volume, sizeof(pa_cvolume));
+ memcpy(&ctl->sink_volume, &i->volume, sizeof(pa_cvolume));
}
-static void source_info_cb(pa_context *c, const pa_source_info *i, int is_last, void *userdata)
+static void source_info_cb(pa_context * c, const pa_source_info * i,
+ int is_last, void *userdata)
{
- snd_ctl_pulse_t *ctl = (snd_ctl_pulse_t*)userdata;
- int chan;
+ snd_ctl_pulse_t *ctl = (snd_ctl_pulse_t *) userdata;
+ int chan;
- assert(ctl);
+ assert(ctl);
- if (is_last) {
- pa_threaded_mainloop_signal(ctl->p->mainloop, 0);
- return;
- }
+ if (is_last) {
+ pa_threaded_mainloop_signal(ctl->p->mainloop, 0);
+ return;
+ }
- assert(i);
+ assert(i);
- if (!!ctl->source_muted != !!i->mute) {
- ctl->source_muted = i->mute;
- ctl->updated |= UPDATE_SOURCE_MUTE;
- pulse_poll_activate(ctl->p);
- }
+ if (!!ctl->source_muted != !!i->mute) {
+ ctl->source_muted = i->mute;
+ ctl->updated |= UPDATE_SOURCE_MUTE;
+ pulse_poll_activate(ctl->p);
+ }
- if (ctl->source_volume.channels == i->volume.channels) {
- for (chan = 0;chan < ctl->source_volume.channels;chan++)
- if (i->volume.values[chan] != ctl->source_volume.values[chan])
- break;
+ if (ctl->source_volume.channels == i->volume.channels) {
+ for (chan = 0; chan < ctl->source_volume.channels; chan++)
+ if (i->volume.values[chan] !=
+ ctl->source_volume.values[chan])
+ break;
- if (chan == ctl->source_volume.channels)
- return;
+ if (chan == ctl->source_volume.channels)
+ return;
- ctl->updated |= UPDATE_SOURCE_VOL;
- pulse_poll_activate(ctl->p);
- }
+ ctl->updated |= UPDATE_SOURCE_VOL;
+ pulse_poll_activate(ctl->p);
+ }
- memcpy(&ctl->source_volume, &i->volume, sizeof(pa_cvolume));
+ memcpy(&ctl->source_volume, &i->volume, sizeof(pa_cvolume));
}
-static void event_cb(pa_context *c, pa_subscription_event_type_t t,
- uint32_t index, void *userdata)
+static void event_cb(pa_context * c, pa_subscription_event_type_t t,
+ uint32_t index, void *userdata)
{
- snd_ctl_pulse_t *ctl = (snd_ctl_pulse_t*)userdata;
- pa_operation *o;
+ snd_ctl_pulse_t *ctl = (snd_ctl_pulse_t *) userdata;
+ pa_operation *o;
- assert(ctl && ctl->p && ctl->p->context);
+ assert(ctl && ctl->p && ctl->p->context);
- o = pa_context_get_sink_info_by_name(ctl->p->context, ctl->sink,
- sink_info_cb, ctl);
- pa_operation_unref(o);
+ o = pa_context_get_sink_info_by_name(ctl->p->context, ctl->sink,
+ sink_info_cb, ctl);
+ pa_operation_unref(o);
- o = pa_context_get_source_info_by_name(ctl->p->context, ctl->source,
- source_info_cb, ctl);
- pa_operation_unref(o);
+ o = pa_context_get_source_info_by_name(ctl->p->context,
+ ctl->source, source_info_cb,
+ ctl);
+ pa_operation_unref(o);
}
-static int pulse_update_volume(snd_ctl_pulse_t *ctl)
+static int pulse_update_volume(snd_ctl_pulse_t * ctl)
{
- int err;
- pa_operation *o;
-
- assert(ctl && ctl->p && ctl->p->context);
-
- o = pa_context_get_sink_info_by_name(ctl->p->context, ctl->sink,
- sink_info_cb, ctl);
- err = pulse_wait_operation(ctl->p, o);
- pa_operation_unref(o);
- if (err < 0)
- return err;
-
- o = pa_context_get_source_info_by_name(ctl->p->context, ctl->source,
- source_info_cb, ctl);
- err = pulse_wait_operation(ctl->p, o);
- pa_operation_unref(o);
- if (err < 0)
- return err;
-
- return 0;
+ int err;
+ pa_operation *o;
+
+ assert(ctl && ctl->p && ctl->p->context);
+
+ o = pa_context_get_sink_info_by_name(ctl->p->context, ctl->sink,
+ sink_info_cb, ctl);
+ err = pulse_wait_operation(ctl->p, o);
+ pa_operation_unref(o);
+ if (err < 0)
+ return err;
+
+ o = pa_context_get_source_info_by_name(ctl->p->context,
+ ctl->source, source_info_cb,
+ ctl);
+ err = pulse_wait_operation(ctl->p, o);
+ pa_operation_unref(o);
+ if (err < 0)
+ return err;
+
+ return 0;
}
-static int pulse_elem_count(snd_ctl_ext_t *ext)
+static int pulse_elem_count(snd_ctl_ext_t * ext)
{
- snd_ctl_pulse_t *ctl = ext->private_data;
- int count = 0;
+ snd_ctl_pulse_t *ctl = ext->private_data;
+ int count = 0;
- assert(ctl);
+ assert(ctl);
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- if (ctl->source)
- count += 2;
- if (ctl->sink)
- count += 2;
+ if (ctl->source)
+ count += 2;
+ if (ctl->sink)
+ count += 2;
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- return count;
+ return count;
}
-static int pulse_elem_list(snd_ctl_ext_t *ext, unsigned int offset,
- snd_ctl_elem_id_t *id)
+static int pulse_elem_list(snd_ctl_ext_t * ext, unsigned int offset,
+ snd_ctl_elem_id_t * id)
{
- snd_ctl_pulse_t *ctl = ext->private_data;
+ snd_ctl_pulse_t *ctl = ext->private_data;
- assert(ctl);
+ assert(ctl);
- snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
+ snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- if (ctl->source) {
- if (offset == 0)
- snd_ctl_elem_id_set_name(id, SOURCE_VOL_NAME);
- else if (offset == 1)
- snd_ctl_elem_id_set_name(id, SOURCE_MUTE_NAME);
- } else
- offset += 2;
+ if (ctl->source) {
+ if (offset == 0)
+ snd_ctl_elem_id_set_name(id, SOURCE_VOL_NAME);
+ else if (offset == 1)
+ snd_ctl_elem_id_set_name(id, SOURCE_MUTE_NAME);
+ } else
+ offset += 2;
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- if (offset == 2)
- snd_ctl_elem_id_set_name(id, SINK_VOL_NAME);
- else if (offset == 3)
- snd_ctl_elem_id_set_name(id, SINK_MUTE_NAME);
+ if (offset == 2)
+ snd_ctl_elem_id_set_name(id, SINK_VOL_NAME);
+ else if (offset == 3)
+ snd_ctl_elem_id_set_name(id, SINK_MUTE_NAME);
- return 0;
+ return 0;
}
-static snd_ctl_ext_key_t pulse_find_elem(snd_ctl_ext_t *ext,
- const snd_ctl_elem_id_t *id)
+static snd_ctl_ext_key_t pulse_find_elem(snd_ctl_ext_t * ext,
+ const snd_ctl_elem_id_t * id)
{
- const char *name;
+ const char *name;
- name = snd_ctl_elem_id_get_name(id);
+ name = snd_ctl_elem_id_get_name(id);
- if (strcmp(name, SOURCE_VOL_NAME) == 0)
- return 0;
- if (strcmp(name, SOURCE_MUTE_NAME) == 0)
- return 1;
- if (strcmp(name, SINK_VOL_NAME) == 0)
- return 2;
- if (strcmp(name, SINK_MUTE_NAME) == 0)
- return 3;
+ if (strcmp(name, SOURCE_VOL_NAME) == 0)
+ return 0;
+ if (strcmp(name, SOURCE_MUTE_NAME) == 0)
+ return 1;
+ if (strcmp(name, SINK_VOL_NAME) == 0)
+ return 2;
+ if (strcmp(name, SINK_MUTE_NAME) == 0)
+ return 3;
- return SND_CTL_EXT_KEY_NOT_FOUND;
+ return SND_CTL_EXT_KEY_NOT_FOUND;
}
-static int pulse_get_attribute(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
- int *type, unsigned int *acc, unsigned int *count)
+static int pulse_get_attribute(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,
+ int *type, unsigned int *acc,
+ unsigned int *count)
{
- snd_ctl_pulse_t *ctl = ext->private_data;
- int err = 0;
+ snd_ctl_pulse_t *ctl = ext->private_data;
+ int err = 0;
- if (key > 3)
- return -EINVAL;
+ if (key > 3)
+ return -EINVAL;
- assert(ctl);
- assert(ctl->p);
+ assert(ctl);
+ assert(ctl->p);
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- err = pulse_check_connection(ctl->p);
- if (err < 0)
- goto finish;
+ err = pulse_check_connection(ctl->p);
+ if (err < 0)
+ goto finish;
- err = pulse_update_volume(ctl);
- if (err < 0)
- goto finish;
+ err = pulse_update_volume(ctl);
+ if (err < 0)
+ goto finish;
- if (key & 1)
- *type = SND_CTL_ELEM_TYPE_BOOLEAN;
- else
- *type = SND_CTL_ELEM_TYPE_INTEGER;
+ if (key & 1)
+ *type = SND_CTL_ELEM_TYPE_BOOLEAN;
+ else
+ *type = SND_CTL_ELEM_TYPE_INTEGER;
- *acc = SND_CTL_EXT_ACCESS_READWRITE;
+ *acc = SND_CTL_EXT_ACCESS_READWRITE;
- if (key == 0)
- *count = ctl->source_volume.channels;
- else if (key == 2)
- *count = ctl->sink_volume.channels;
- else
- *count = 1;
+ if (key == 0)
+ *count = ctl->source_volume.channels;
+ else if (key == 2)
+ *count = ctl->sink_volume.channels;
+ else
+ *count = 1;
-finish:
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ finish:
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- return err;
+ return err;
}
-static int pulse_get_integer_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
- long *imin, long *imax, long *istep)
+static int pulse_get_integer_info(snd_ctl_ext_t * ext,
+ snd_ctl_ext_key_t key, long *imin,
+ long *imax, long *istep)
{
- *istep = 1;
- *imin = 0;
- *imax = PA_VOLUME_NORM;
+ *istep = 1;
+ *imin = 0;
+ *imax = PA_VOLUME_NORM;
- return 0;
+ return 0;
}
-static int pulse_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
- long *value)
+static int pulse_read_integer(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,
+ long *value)
{
- snd_ctl_pulse_t *ctl = ext->private_data;
- int err = 0, i;
- pa_cvolume *vol = NULL;
-
- assert(ctl);
- assert(ctl->p);
-
- pa_threaded_mainloop_lock(ctl->p->mainloop);
-
- err = pulse_check_connection(ctl->p);
- if (err < 0)
- goto finish;
-
- err = pulse_update_volume(ctl);
- if (err < 0)
- goto finish;
-
- switch (key) {
- case 0:
- vol = &ctl->source_volume;
- break;
- case 1:
- *value = !ctl->source_muted;
- break;
- case 2:
- vol = &ctl->sink_volume;
- break;
- case 3:
- *value = !ctl->sink_muted;
- break;
- default:
- err = -EINVAL;
- goto finish;
- }
-
- if (vol) {
- for (i = 0;i < vol->channels;i++)
- value[i] = vol->values[i];
- }
-
-finish:
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
-
- return err;
-}
+ snd_ctl_pulse_t *ctl = ext->private_data;
+ int err = 0, i;
+ pa_cvolume *vol = NULL;
+
+ assert(ctl);
+ assert(ctl->p);
+
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
+
+ err = pulse_check_connection(ctl->p);
+ if (err < 0)
+ goto finish;
+
+ err = pulse_update_volume(ctl);
+ if (err < 0)
+ goto finish;
+
+ switch (key) {
+ case 0:
+ vol = &ctl->source_volume;
+ break;
+ case 1:
+ *value = !ctl->source_muted;
+ break;
+ case 2:
+ vol = &ctl->sink_volume;
+ break;
+ case 3:
+ *value = !ctl->sink_muted;
+ break;
+ default:
+ err = -EINVAL;
+ goto finish;
+ }
-static int pulse_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
- long *value)
-{
- snd_ctl_pulse_t *ctl = ext->private_data;
- int err = 0, i;
- pa_operation *o;
- pa_cvolume *vol = NULL;
-
- assert(ctl);
- assert(ctl->p && ctl->p->context);
-
- pa_threaded_mainloop_lock(ctl->p->mainloop);
-
- err = pulse_check_connection(ctl->p);
- if (err < 0)
- goto finish;
-
- err = pulse_update_volume(ctl);
- if (err < 0)
- goto finish;
-
- switch (key) {
- case 0:
- vol = &ctl->source_volume;
- break;
- case 1:
- if (!!ctl->source_muted == !*value)
- goto finish;
- ctl->source_muted = !*value;
- break;
- case 2:
- vol = &ctl->sink_volume;
- break;
- case 3:
- if (!!ctl->sink_muted == !*value)
- goto finish;
- ctl->sink_muted = !*value;
- break;
- default:
- err = -EINVAL;
- goto finish;
- }
-
- if (vol) {
- for (i = 0;i < vol->channels;i++)
- if (value[i] != vol->values[i])
- break;
-
- if (i == vol->channels)
- goto finish;
-
- for (i = 0;i < vol->channels;i++)
- vol->values[i] = value[i];
-
- if (key == 0)
- o = pa_context_set_source_volume_by_name(ctl->p->context,
- ctl->source, vol, pulse_context_success_cb, ctl->p);
- else
- o = pa_context_set_sink_volume_by_name(ctl->p->context,
- ctl->sink, vol, pulse_context_success_cb, ctl->p);
- } else {
- if (key == 1)
- o = pa_context_set_source_mute_by_name(ctl->p->context,
- ctl->source, ctl->source_muted, pulse_context_success_cb, ctl->p);
- else
- o = pa_context_set_sink_mute_by_name(ctl->p->context,
- ctl->sink, ctl->sink_muted, pulse_context_success_cb, ctl->p);
- }
-
- err = pulse_wait_operation(ctl->p, o);
- pa_operation_unref(o);
- if (err < 0)
- goto finish;
-
- err = 1;
-
-finish:
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
-
- return err;
+ if (vol) {
+ for (i = 0; i < vol->channels; i++)
+ value[i] = vol->values[i];
+ }
+
+ finish:
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
+
+ return err;
}
-static void pulse_subscribe_events(snd_ctl_ext_t *ext, int subscribe)
+static int pulse_write_integer(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,
+ long *value)
{
- snd_ctl_pulse_t *ctl = ext->private_data;
+ snd_ctl_pulse_t *ctl = ext->private_data;
+ int err = 0, i;
+ pa_operation *o;
+ pa_cvolume *vol = NULL;
+
+ assert(ctl);
+ assert(ctl->p && ctl->p->context);
+
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
+
+ err = pulse_check_connection(ctl->p);
+ if (err < 0)
+ goto finish;
+
+ err = pulse_update_volume(ctl);
+ if (err < 0)
+ goto finish;
+
+ switch (key) {
+ case 0:
+ vol = &ctl->source_volume;
+ break;
+ case 1:
+ if (!!ctl->source_muted == !*value)
+ goto finish;
+ ctl->source_muted = !*value;
+ break;
+ case 2:
+ vol = &ctl->sink_volume;
+ break;
+ case 3:
+ if (!!ctl->sink_muted == !*value)
+ goto finish;
+ ctl->sink_muted = !*value;
+ break;
+ default:
+ err = -EINVAL;
+ goto finish;
+ }
+
+ if (vol) {
+ for (i = 0; i < vol->channels; i++)
+ if (value[i] != vol->values[i])
+ break;
+
+ if (i == vol->channels)
+ goto finish;
+
+ for (i = 0; i < vol->channels; i++)
+ vol->values[i] = value[i];
+
+ if (key == 0)
+ o = pa_context_set_source_volume_by_name(ctl->p->
+ context,
+ ctl->
+ source,
+ vol,
+ pulse_context_success_cb,
+ ctl->p);
+ else
+ o = pa_context_set_sink_volume_by_name(ctl->p->
+ context,
+ ctl->sink,
+ vol,
+ pulse_context_success_cb,
+ ctl->p);
+ } else {
+ if (key == 1)
+ o = pa_context_set_source_mute_by_name(ctl->p->
+ context,
+ ctl->source,
+ ctl->
+ source_muted,
+ pulse_context_success_cb,
+ ctl->p);
+ else
+ o = pa_context_set_sink_mute_by_name(ctl->p->
+ context,
+ ctl->sink,
+ ctl->
+ sink_muted,
+ pulse_context_success_cb,
+ ctl->p);
+ }
- assert(ctl);
+ err = pulse_wait_operation(ctl->p, o);
+ pa_operation_unref(o);
+ if (err < 0)
+ goto finish;
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ err = 1;
- ctl->subscribed = !!(subscribe & SND_CTL_EVENT_MASK_VALUE);
+ finish:
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ return err;
}
-static int pulse_read_event(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id,
- unsigned int *event_mask)
+static void pulse_subscribe_events(snd_ctl_ext_t * ext, int subscribe)
{
- snd_ctl_pulse_t *ctl = ext->private_data;
- int offset;
- int err = -EAGAIN;
+ snd_ctl_pulse_t *ctl = ext->private_data;
- assert(ctl);
+ assert(ctl);
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- if (!ctl->updated || !ctl->subscribed)
- goto finish;
+ ctl->subscribed = !!(subscribe & SND_CTL_EVENT_MASK_VALUE);
- if (ctl->source)
- offset = 2;
- else
- offset = 0;
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
+}
- if (ctl->updated & UPDATE_SOURCE_VOL) {
- pulse_elem_list(ext, 0, id);
- ctl->updated &= ~UPDATE_SOURCE_VOL;
- } else if (ctl->updated & UPDATE_SOURCE_MUTE) {
- pulse_elem_list(ext, 1, id);
- ctl->updated &= ~UPDATE_SOURCE_MUTE;
- } else if (ctl->updated & UPDATE_SINK_VOL) {
- pulse_elem_list(ext, offset + 0, id);
- ctl->updated &= ~UPDATE_SINK_VOL;
- } else if (ctl->updated & UPDATE_SINK_MUTE) {
- pulse_elem_list(ext, offset + 1, id);
- ctl->updated &= ~UPDATE_SINK_MUTE;
- }
+static int pulse_read_event(snd_ctl_ext_t * ext, snd_ctl_elem_id_t * id,
+ unsigned int *event_mask)
+{
+ snd_ctl_pulse_t *ctl = ext->private_data;
+ int offset;
+ int err = -EAGAIN;
+
+ assert(ctl);
+
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
+
+ if (!ctl->updated || !ctl->subscribed)
+ goto finish;
+
+ if (ctl->source)
+ offset = 2;
+ else
+ offset = 0;
+
+ if (ctl->updated & UPDATE_SOURCE_VOL) {
+ pulse_elem_list(ext, 0, id);
+ ctl->updated &= ~UPDATE_SOURCE_VOL;
+ } else if (ctl->updated & UPDATE_SOURCE_MUTE) {
+ pulse_elem_list(ext, 1, id);
+ ctl->updated &= ~UPDATE_SOURCE_MUTE;
+ } else if (ctl->updated & UPDATE_SINK_VOL) {
+ pulse_elem_list(ext, offset + 0, id);
+ ctl->updated &= ~UPDATE_SINK_VOL;
+ } else if (ctl->updated & UPDATE_SINK_MUTE) {
+ pulse_elem_list(ext, offset + 1, id);
+ ctl->updated &= ~UPDATE_SINK_MUTE;
+ }
- *event_mask = SND_CTL_EVENT_MASK_VALUE;
+ *event_mask = SND_CTL_EVENT_MASK_VALUE;
- if (!ctl->updated)
- pulse_poll_deactivate(ctl->p);
+ if (!ctl->updated)
+ pulse_poll_deactivate(ctl->p);
- err = 1;
+ err = 1;
-finish:
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ finish:
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- return err;
+ return err;
}
-static int pulse_ctl_poll_descriptors_count(snd_ctl_ext_t *ext)
+static int pulse_ctl_poll_descriptors_count(snd_ctl_ext_t * ext)
{
snd_ctl_pulse_t *ctl = ext->private_data;
int count;
- assert(ctl);
- assert(ctl->p);
+ assert(ctl);
+ assert(ctl->p);
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- count = pulse_poll_descriptors_count(ctl->p);
+ count = pulse_poll_descriptors_count(ctl->p);
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- return count;
+ return count;
}
-static int pulse_ctl_poll_descriptors(snd_ctl_ext_t *ext, struct pollfd *pfd, unsigned int space)
+static int pulse_ctl_poll_descriptors(snd_ctl_ext_t * ext,
+ struct pollfd *pfd,
+ unsigned int space)
{
- int num;
+ int num;
snd_ctl_pulse_t *ctl = ext->private_data;
- assert(ctl);
- assert(ctl->p);
+ assert(ctl);
+ assert(ctl->p);
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- num = pulse_poll_descriptors(ctl->p, pfd, space);
- if (num < 0)
- goto finish;
+ num = pulse_poll_descriptors(ctl->p, pfd, space);
+ if (num < 0)
+ goto finish;
-finish:
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ finish:
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- return num;
+ return num;
}
-static int pulse_ctl_poll_revents(snd_ctl_ext_t *ext, struct pollfd *pfd, unsigned int nfds, unsigned short *revents)
+static int pulse_ctl_poll_revents(snd_ctl_ext_t * ext, struct pollfd *pfd,
+ unsigned int nfds,
+ unsigned short *revents)
{
snd_ctl_pulse_t *ctl = ext->private_data;
int err = 0;
- assert(ctl);
- assert(ctl->p);
+ assert(ctl);
+ assert(ctl->p);
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- err = pulse_poll_revents(ctl->p, pfd, nfds, revents);
- if (err < 0)
- goto finish;
+ err = pulse_poll_revents(ctl->p, pfd, nfds, revents);
+ if (err < 0)
+ goto finish;
- *revents = 0;
+ *revents = 0;
- if (ctl->updated)
- *revents |= POLLIN;
+ if (ctl->updated)
+ *revents |= POLLIN;
-finish:
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ finish:
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- return err;
+ return err;
}
-static void pulse_close(snd_ctl_ext_t *ext)
+static void pulse_close(snd_ctl_ext_t * ext)
{
- snd_ctl_pulse_t *ctl = ext->private_data;
+ snd_ctl_pulse_t *ctl = ext->private_data;
- assert(ctl);
+ assert(ctl);
- if (ctl->p)
- pulse_free(ctl->p);
+ if (ctl->p)
+ pulse_free(ctl->p);
- if (ctl->source)
- free(ctl->source);
- if (ctl->sink)
- free(ctl->sink);
+ if (ctl->source)
+ free(ctl->source);
+ if (ctl->sink)
+ free(ctl->sink);
free(ctl);
}
static snd_ctl_ext_callback_t pulse_ext_callback = {
- .elem_count = pulse_elem_count,
- .elem_list = pulse_elem_list,
- .find_elem = pulse_find_elem,
- .get_attribute = pulse_get_attribute,
- .get_integer_info = pulse_get_integer_info,
- .read_integer = pulse_read_integer,
- .write_integer = pulse_write_integer,
- .subscribe_events = pulse_subscribe_events,
- .read_event = pulse_read_event,
- .poll_descriptors_count = pulse_ctl_poll_descriptors_count,
- .poll_descriptors = pulse_ctl_poll_descriptors,
- .poll_revents = pulse_ctl_poll_revents,
- .close = pulse_close,
+ .elem_count = pulse_elem_count,
+ .elem_list = pulse_elem_list,
+ .find_elem = pulse_find_elem,
+ .get_attribute = pulse_get_attribute,
+ .get_integer_info = pulse_get_integer_info,
+ .read_integer = pulse_read_integer,
+ .write_integer = pulse_write_integer,
+ .subscribe_events = pulse_subscribe_events,
+ .read_event = pulse_read_event,
+ .poll_descriptors_count = pulse_ctl_poll_descriptors_count,
+ .poll_descriptors = pulse_ctl_poll_descriptors,
+ .poll_revents = pulse_ctl_poll_revents,
+ .close = pulse_close,
};
-static void server_info_cb(pa_context *c, const pa_server_info*i, void *userdata)
+static void server_info_cb(pa_context * c, const pa_server_info * i,
+ void *userdata)
{
- snd_ctl_pulse_t *ctl = (snd_ctl_pulse_t*)userdata;
+ snd_ctl_pulse_t *ctl = (snd_ctl_pulse_t *) userdata;
- assert(ctl && i);
+ assert(ctl && i);
- if (i->default_source_name && !ctl->source)
- ctl->source = strdup(i->default_source_name);
- if (i->default_sink_name && !ctl->sink)
- ctl->sink = strdup(i->default_sink_name);
+ if (i->default_source_name && !ctl->source)
+ ctl->source = strdup(i->default_source_name);
+ if (i->default_sink_name && !ctl->sink)
+ ctl->sink = strdup(i->default_sink_name);
- pa_threaded_mainloop_signal(ctl->p->mainloop, 0);
+ pa_threaded_mainloop_signal(ctl->p->mainloop, 0);
}
SND_CTL_PLUGIN_DEFINE_FUNC(pulse)
@@ -592,127 +624,133 @@ SND_CTL_PLUGIN_DEFINE_FUNC(pulse)
const char *sink = NULL;
int err;
snd_ctl_pulse_t *ctl;
- pa_operation *o;
+ pa_operation *o;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id;
if (snd_config_get_id(n, &id) < 0)
continue;
- if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0 || strcmp(id, "hint") == 0)
+ if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0
+ || strcmp(id, "hint") == 0)
+ continue;
+ if (strcmp(id, "server") == 0) {
+ if (snd_config_get_string(n, &server) < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
continue;
- if (strcmp(id, "server") == 0) {
- if (snd_config_get_string(n, &server) < 0) {
- SNDERR("Invalid type for %s", id);
- return -EINVAL;
- }
- continue;
- }
- if (strcmp(id, "device") == 0) {
- if (snd_config_get_string(n, &device) < 0) {
- SNDERR("Invalid type for %s", id);
- return -EINVAL;
- }
- continue;
- }
- if (strcmp(id, "source") == 0) {
- if (snd_config_get_string(n, &source) < 0) {
- SNDERR("Invalid type for %s", id);
- return -EINVAL;
- }
- continue;
- }
- if (strcmp(id, "sink") == 0) {
- if (snd_config_get_string(n, &sink) < 0) {
- SNDERR("Invalid type for %s", id);
- return -EINVAL;
- }
- continue;
- }
+ }
+ if (strcmp(id, "device") == 0) {
+ if (snd_config_get_string(n, &device) < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+ continue;
+ }
+ if (strcmp(id, "source") == 0) {
+ if (snd_config_get_string(n, &source) < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+ continue;
+ }
+ if (strcmp(id, "sink") == 0) {
+ if (snd_config_get_string(n, &sink) < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+ continue;
+ }
SNDERR("Unknown field %s", id);
return -EINVAL;
}
ctl = calloc(1, sizeof(*ctl));
- ctl->p = pulse_new();
- if (!ctl->p) {
- err = -EIO;
- goto error;
- }
+ ctl->p = pulse_new();
+ if (!ctl->p) {
+ err = -EIO;
+ goto error;
+ }
- err = pulse_connect(ctl->p, server);
- if (err < 0)
- goto error;
+ err = pulse_connect(ctl->p, server);
+ if (err < 0)
+ goto error;
- if (source)
- ctl->source = strdup(source);
- else if (device)
- ctl->source = strdup(device);
+ if (source)
+ ctl->source = strdup(source);
+ else if (device)
+ ctl->source = strdup(device);
- if (sink)
- ctl->sink = strdup(sink);
- else if (device)
- ctl->sink = strdup(device);
+ if (sink)
+ ctl->sink = strdup(sink);
+ else if (device)
+ ctl->sink = strdup(device);
- if (!ctl->source || !ctl->sink) {
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ if (!ctl->source || !ctl->sink) {
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- o = pa_context_get_server_info(ctl->p->context, server_info_cb, ctl);
- err = pulse_wait_operation(ctl->p, o);
+ o = pa_context_get_server_info(ctl->p->context,
+ server_info_cb, ctl);
+ err = pulse_wait_operation(ctl->p, o);
- pa_operation_unref(o);
+ pa_operation_unref(o);
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- if (err < 0)
- goto error;
- }
+ if (err < 0)
+ goto error;
+ }
- pa_threaded_mainloop_lock(ctl->p->mainloop);
+ pa_threaded_mainloop_lock(ctl->p->mainloop);
- pa_context_set_subscribe_callback(ctl->p->context, event_cb, ctl);
+ pa_context_set_subscribe_callback(ctl->p->context, event_cb, ctl);
- o = pa_context_subscribe(ctl->p->context,
- PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE,
- pulse_context_success_cb, ctl->p);
+ o = pa_context_subscribe(ctl->p->context,
+ PA_SUBSCRIPTION_MASK_SINK |
+ PA_SUBSCRIPTION_MASK_SOURCE,
+ pulse_context_success_cb, ctl->p);
- err = pulse_wait_operation(ctl->p, o);
+ err = pulse_wait_operation(ctl->p, o);
- pa_operation_unref(o);
+ pa_operation_unref(o);
- pa_threaded_mainloop_unlock(ctl->p->mainloop);
+ pa_threaded_mainloop_unlock(ctl->p->mainloop);
- if (err < 0)
- goto error;
+ if (err < 0)
+ goto error;
- ctl->ext.version = SND_CTL_EXT_VERSION;
- ctl->ext.card_idx = 0;
- strncpy(ctl->ext.id, "pulse", sizeof(ctl->ext.id) - 1);
- strncpy(ctl->ext.driver, "PulseAudio plugin", sizeof(ctl->ext.driver) - 1);
- strncpy(ctl->ext.name, "PulseAudio", sizeof(ctl->ext.name) - 1);
- strncpy(ctl->ext.longname, "PulseAudio", sizeof(ctl->ext.longname) - 1);
- strncpy(ctl->ext.mixername, "PulseAudio", sizeof(ctl->ext.mixername) - 1);
- ctl->ext.poll_fd = -1;
- ctl->ext.callback = &pulse_ext_callback;
- ctl->ext.private_data = ctl;
+ ctl->ext.version = SND_CTL_EXT_VERSION;
+ ctl->ext.card_idx = 0;
+ strncpy(ctl->ext.id, "pulse", sizeof(ctl->ext.id) - 1);
+ strncpy(ctl->ext.driver, "PulseAudio plugin",
+ sizeof(ctl->ext.driver) - 1);
+ strncpy(ctl->ext.name, "PulseAudio", sizeof(ctl->ext.name) - 1);
+ strncpy(ctl->ext.longname, "PulseAudio",
+ sizeof(ctl->ext.longname) - 1);
+ strncpy(ctl->ext.mixername, "PulseAudio",
+ sizeof(ctl->ext.mixername) - 1);
+ ctl->ext.poll_fd = -1;
+ ctl->ext.callback = &pulse_ext_callback;
+ ctl->ext.private_data = ctl;
- err = snd_ctl_ext_create(&ctl->ext, name, mode);
- if (err < 0)
- goto error;
+ err = snd_ctl_ext_create(&ctl->ext, name, mode);
+ if (err < 0)
+ goto error;
- *handlep = ctl->ext.handle;
+ *handlep = ctl->ext.handle;
- return 0;
+ return 0;
-error:
- if (ctl->source)
- free(ctl->source);
- if (ctl->sink)
- free(ctl->sink);
+ error:
+ if (ctl->source)
+ free(ctl->source);
+ if (ctl->sink)
+ free(ctl->sink);
- if (ctl->p)
- pulse_free(ctl->p);
+ if (ctl->p)
+ pulse_free(ctl->p);
free(ctl);