From 8679fdf406cc172edc77c5d18cbdf93348818175 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Sat, 21 Nov 2009 17:37:44 +0100 Subject: [PATCH] Add support for pausing MPlayer --- debian/changelog | 6 ++++++ debian/headphoned.zheadphoned.init | 12 ++++++++++++ debian/postrm | 16 ++++++++++++++++ debian/rules | 2 +- makefile | 3 +++ src/headphoned.c | 11 +++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 debian/postrm diff --git a/debian/changelog b/debian/changelog index fd68590..a26fb30 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +headphoned (1.4) diablo; urgency=low + + * Add support for pausing MPlayer + + -- Thomas Perl Sat, 21 Nov 2009 17:37:08 +0100 + headphoned (1.3) diablo; urgency=low * Add support for pausing Panucci diff --git a/debian/headphoned.zheadphoned.init b/debian/headphoned.zheadphoned.init index 846ce61..08ff60b 100644 --- a/debian/headphoned.zheadphoned.init +++ b/debian/headphoned.zheadphoned.init @@ -20,6 +20,18 @@ DESC="Headphone daemon" export DBUS_SESSION_BUS_ADDRESS='unix:path=/tmp/session_bus_socket' # XXX end +# Add the headphoned FIFO to MPlayer's global configuration +CONFIG_LINE="input:file=/etc/headphoned/mplayer-input" +MPLAYER_CONF="/etc/mplayer/mplayer.conf" +if [ -f "$MPLAYER_CONF" ]; then + if ! grep "$CONFIG_LINE" "$MPLAYER_CONF" >/dev/null; then + echo -n "Updating $MPLAYER_CONF... " + echo $CONFIG_LINE >>$MPLAYER_CONF + echo "done." + fi +fi +# End Add the headphoned FIFO to MPlayer's global configuration + test -x $DAEMON || exit 0 set -e diff --git a/debian/postrm b/debian/postrm new file mode 100644 index 0000000..1b92f0f --- /dev/null +++ b/debian/postrm @@ -0,0 +1,16 @@ +#!/bin/sh + +#DEBHELPER# + +CONFIG_LINE="input:file=\/etc\/headphoned\/mplayer-input" +MPLAYER_CONF="/etc/mplayer/mplayer.conf" + +# Remove the headphoned "input" config option for MPlayer (if it exists) +if [ -f "$MPLAYER_CONF" ]; then + if grep "$CONFIG_LINE" "$MPLAYER_CONF" >/dev/null; then + echo -n "Updating $MPLAYER_CONF... " + sed -i -e "/$CONFIG_LINE/d" "$MPLAYER_CONF" + echo "done." + fi +fi + diff --git a/debian/rules b/debian/rules index 0aa4a44..b495e60 100755 --- a/debian/rules +++ b/debian/rules @@ -63,7 +63,7 @@ binary-arch: build install dh_link dh_strip dh_compress - dh_fixperms + dh_fixperms --exclude=/etc/headphoned/mplayer-input dh_installdeb dh_shlibdeps dh_gencontrol diff --git a/makefile b/makefile index 2905814..46e3f6b 100644 --- a/makefile +++ b/makefile @@ -12,6 +12,9 @@ $(PROG): $(OBJS) install: $(PROG) install $(PROG) $(DESTDIR)$(PREFIX)/sbin/$(PROG) + mkdir -p $(DESTDIR)/etc/$(PROG) + mkfifo $(DESTDIR)/etc/$(PROG)/mplayer-input + chown user:users $(DESTDIR)/etc/$(PROG)/mplayer-input clean: rm -f $(PROG) $(OBJS) diff --git a/src/headphoned.c b/src/headphoned.c index 2daaf69..adfdf55 100644 --- a/src/headphoned.c +++ b/src/headphoned.c @@ -18,6 +18,7 @@ #include #include #include +#include #define STATE_FILE "/sys/devices/platform/gpio-switch/headphone/state" #define STATE_CONNECTED_STR "connected" @@ -33,6 +34,8 @@ #define PANUCCI_PATH "/panucciInterface" #define PANUCCI_INTF "org.panucci.panucciInterface" +#define MPLAYER_FIFO "/etc/headphoned/mplayer-input" + // Volume control is currently broken, as something is messing // with the controls from outside this process in GConf.. //#define ENABLE_VOLUME_CONTROL @@ -90,6 +93,7 @@ on_file_changed(GIOChannel* source, GIOCondition condition, gpointer data) gint volume = headphoned->volume[headphoned->state]; #endif gchar* result; + int mplayer_fifo; g_io_channel_seek_position(source, 0, G_SEEK_SET, NULL); g_io_channel_read_line(source, &result, NULL, NULL, NULL); @@ -122,6 +126,13 @@ on_file_changed(GIOChannel* source, GIOCondition condition, gpointer data) NULL, DBUS_TYPE_INVALID); } + + /* MPlayer */ + if ((mplayer_fifo = open(MPLAYER_FIFO, + O_WRONLY | O_NONBLOCK)) != -1) { + write(mplayer_fifo, "pause\n", 6); + close(mplayer_fifo); + } } #endif } -- 1.7.9.5