summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-11-28 02:11:32 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2012-11-28 02:11:32 +0100
commit73a2298c1dc18d419b9b5cbd09300aad87401324 (patch)
treedc666f21b5179222f0bbdd9692d1a893042aff49
downloadpulse-volume-change-notify-73a2298c1dc18d419b9b5cbd09300aad87401324.tar.gz
pulse-volume-change-notify-73a2298c1dc18d419b9b5cbd09300aad87401324.tar.xz
pulse-volume-change-notify-73a2298c1dc18d419b9b5cbd09300aad87401324.zip
initial commit
-rw-r--r--.gitignore1
-rw-r--r--Makefile15
-rw-r--r--module-volume-change-notify.c101
3 files changed, 117 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..140f8cf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.so
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..2aef974
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+TARGET=volume-change-notify
+MODULE=module-$(TARGET)
+
+PULSEAUDIO=$(HOME)/tmp/pulseaudio-2.1
+DBUS_CFLAGS=$(shell pkg-config --cflags dbus-1)
+DBUS_LDFLAGS=$(shell pkg-config --libs dbus-1)
+
+CFLAGS=-I$(PULSEAUDIO) -I$(PULSEAUDIO)/src $(DBUS_CFLAGS)
+LDFLAGS=$(DBUS_LDFLAGS)
+
+$(MODULE).so: $(MODULE).c
+ gcc $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $<
+
+clean:
+ $(RM) $(MODULE).so
diff --git a/module-volume-change-notify.c b/module-volume-change-notify.c
new file mode 100644
index 0000000..f204909
--- /dev/null
+++ b/module-volume-change-notify.c
@@ -0,0 +1,101 @@
+#include <config.h>
+
+#include <pulsecore/module.h>
+#include <pulsecore/core-subscribe.h>
+#include <pulse/introspect.h>
+
+#include <dbus/dbus.h>
+
+PA_MODULE_AUTHOR("Alexander Sulfrian");
+PA_MODULE_DESCRIPTION("Module that notify you on volume changes of sinks.");
+PA_MODULE_VERSION(PACKAGE_VERSION);
+PA_MODULE_USAGE("");
+
+struct userdata {
+ pa_core *core;
+ pa_module *module;
+ pa_subscription *subscription;
+
+ /* dbus stuff */
+ DBusError dbus_error;
+ DBusConnection *dbus_connection;
+};
+
+void sink_change_event_cb(pa_core *c, pa_subscription_event_type_t t,
+ uint32_t idx, void *userdata)
+{
+ pa_sink *s;
+ char vol[PA_CVOLUME_SNPRINT_MAX];
+
+ if (PA_SUBSCRIPTION_EVENT_CHANGE & t == 0)
+ return;
+
+ s = pa_idxset_get_by_index(c->sinks, idx);
+ if (!s)
+ return;
+
+ pa_cvolume_snprint(vol, PA_CVOLUME_SNPRINT_MAX, &s->reference_volume);
+ pa_log("Volume: %s %s", s->name, vol);
+}
+
+void pa__done(pa_module *m)
+{
+ struct userdata *u;
+
+ if (!(u = m->userdata))
+ return;
+
+ pa_subscription_free(u->subscription);
+
+ if (u->dbus_connection)
+ dbus_connection_close(u->dbus_connection);
+
+ pa_xfree(u);
+}
+
+int pa__init(pa_module* m)
+{
+ struct userdata *u;
+ pa_subscription_mask_t mask;
+ int ret;
+
+ m->userdata = u = pa_xnew0(struct userdata, 1);
+ u->core = m->core;
+ u->module = m;
+
+ mask = PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT | PA_SUBSCRIPTION_EVENT_CHANGE;
+ u->subscription = pa_subscription_new(m->core, mask,
+ sink_change_event_cb, u);
+
+ /* initialize dbus */
+ dbus_error_init(&u->dbus_error);
+ u->dbus_connection = dbus_bus_get(DBUS_BUS_SESSION, &u->dbus_error);
+ if (dbus_error_is_set(&u->dbus_error)) {
+ pa_log("DBus Connection Error (%s)\n", u->dbus_error.message);
+ dbus_error_free(&u->dbus_error);
+ }
+
+ if (!u->dbus_connection)
+ goto fail;
+
+ /* request a name on the bus */
+ ret = dbus_bus_request_name(u->dbus_connection,
+ "org.PulseAudio.VolumeNotification",
+ DBUS_NAME_FLAG_REPLACE_EXISTING,
+ &u->dbus_error);
+
+ if (dbus_error_is_set(&u->dbus_error)) {
+ pa_log("DBus Name Error (%s)\n", u->dbus_error.message);
+ dbus_error_free(&u->dbus_error);
+ }
+
+ if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
+ goto fail;
+ }
+
+ return 0;
+
+fail:
+ pa__done(m);
+ return -1;
+}