[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Alternative sound configuration for thin clients



Here is a draft patch to change the sound system on thin client
servers to try to get programs using /dev/dsp to work out of the box
on thin clients, and make sure ALSA forwards to Pulseaudio for thin
clients while still using the hardware sound card when running
applications locally.  I am unsure if the asound.conf setup will work,
and welcome feedback.

This setup is currently untested.

Index: debian/changelog
===================================================================
--- debian/changelog	(revision 60337)
+++ debian/changelog	(working copy)
@@ -12,6 +12,11 @@
   * Add SuspendTime=60 to arts configuration used with thin client
     logins, to make the setting consistent with the value currently
     used.
+  * Rewrite sound set for thin clients to use Pulseaudio and ALSA
+    forwarding to Pulseaudio for everything using ALSA, and divert
+    binaries and add wrappers using padsp for audacity and gtick to
+    get these packages currently using OSS /dev/dsp by default to
+    work.
 
   [ Holger Levsen ]
   * Rename example file default-ltsp.cfg to default-thin.cfg.
Index: etc/asound.conf
===================================================================
--- etc/asound.conf	(revision 0)
+++ etc/asound.conf	(revision 0)
@@ -0,0 +1,32 @@
+# Make it possible for ALSA forward to pulseaudio on thin clients.
+# Based on idea from
+# http://alsa.opensrc.org/index.php/Default_device_from_environment_variable
+
+pcm.!default {
+    @func refer
+    name { @func concat 
+           strings [ "pcm."
+                     { @func getenv
+                       vars [ ALSA_DEFAULT_PCM ]
+                       default "hw0"
+                     }
+           ]
+         }
+}
+
+ctl.!default {
+    @func refer
+    name { @func concat 
+           strings [ "ctl."
+                     { @func getenv
+                       vars [ ALSA_DEFAULT_CTL
+                              ALSA_DEFAULT_PCM
+                       ]
+                       default "hw0"
+                     }
+           ]
+         }
+}
+
+pcm.pulse { type pulse }
+ctl.pulse { type pulse }
Index: etc/X11/Xsession.d/15debian-edu-ltsp
===================================================================
--- etc/X11/Xsession.d/15debian-edu-ltsp	(revision 0)
+++ etc/X11/Xsession.d/15debian-edu-ltsp	(revision 0)
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# Tell ALSA to forward to pulseaudio on thin clients.  VARIABLE is
+# passed on and refered in /etc/asound.conf.  Based on idea from
+# http://alsa.opensrc.org/index.php/Default_device_from_environment_variable
+
+if [ "$LTSP_CLIENT" ] ; then
+    if [ "$PULSE_SERVER" ] ; then
+        # Pulseaudio
+	ALSA_DEFAULT_PCM=pulse
+	export ALSA_DEFAULT_PCM
+    fi
+fi

Index: sbin/debian-edu-ltsp-audiodivert
===================================================================
--- sbin/debian-edu-ltsp-audiodivert	(revision 0)
+++ sbin/debian-edu-ltsp-audiodivert	(revision 0)
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Divert some binaries that try to use /dev/dsp, which fail to work
+# with LTSP and need a wrapper to divert the audio to pulseaudio or
+# esd.
+
+programs="/usr/bin/audacity /usr/bin/gtick"
+divertowner=debian-edu-config
+
+create_diverts() {
+    for cmd in $programs ; do
+	if [ -x "$cmd" ] && [ ! -x "$cmd.ltsp" ] ; then
+	    cat <<EOF > "$cmd.ltsp"
+#!/bin/sh
+if [ "\$LTSP_CLIENT" ] ; then
+    if [ "\$PULSE_SERVER" ] && [ -x /usr/bin/padsp ] ; then
+        # Pulseaudio
+        wrapper=padsp
+    elif [ "\$ESPEAKER" ] && [ -x /usr/bin/esddsp ] ; then
+        wrapper=espdsp
+    elif [ "\$ESPEAKER" ] && [ -x /usr/bin/padsp ] ; then
+        # Pulseaudio with esd compatibility layer.  Not sure if this
+        # work [pere 2009-12-22]
+        wrapper=padsp
+    fi
+fi
+exec \$wrapper "$cmd" "\$@"
+EOF
+
+	    chmod 755 "$cmd.ltsp"
+
+	    dpkg-divert --package $divertowner --rename --add "$cmd"
+	    basename=$(basename "$cmd")
+	    ln -s "$basename.ltsp" "$cmd"
+	fi
+    done
+}
+
+remove_diverts() {
+    for cmd in $programs ; do
+        if [ -f $cmd.ltsp ] ; then
+            rm $cmd
+	    dpkg-divert --package $divertowner --rename --remove $cmd
+            rm $cmd.ltsp
+        fi
+    done
+}
+
+case "$1" in
+    create)
+	create_diverts
+	;;
+    remove)
+	remove_diverts
+	;;
+esac

Index: Makefile
===================================================================
--- Makefile	(revision 60337)
+++ Makefile	(working copy)
@@ -7,6 +7,7 @@
 
 SPROGS = debian-edu-restart-services \
 	debian-edu-test-install ltsp-make-client \
+        debian-edu-audiodivert \
         debian-edu-fsautoresize debian-edu-etc-svk \
         debian-edu-pxeinstall snakeoil-on-ice debian-edu-hwsetup
 
@@ -65,10 +66,12 @@
 
 # Files to install in /etc/
 SYSCONFFILES = \
+	asound.conf \
 	apt/apt.conf.d/99-edu-prefer-iceweasel \
 	X11/Xsession.d/05debian-edu-truncate-xerrorlog \
 	X11/Xsession.d/10debian-edu-one-login-per-host \
 	X11/Xsession.d/10debian-edu-set-umask \
+	X11/Xsession.d/15debian-edu-ltsp \
 	desktop-profiles/debian-edu-config.listing \
 	courier/authldaprc-debian-edu \
 	courier/imapd-debian-edu.cnf \
Index: cf/cf.ltsp
===================================================================
--- cf/cf.ltsp  (revision 60337)
+++ cf/cf.ltsp  (working copy)
@@ -223,3 +223,7 @@
         # snakeoil-on-ice (secondpass), and before
         # debian-edu-pxeinstall (forthpass).
         "/usr/sbin/ltsp-make-client"
+
+       # Divert some binaries to get them working with Pulseaudio or
+       # ALSA on thin clients.
+        "/usr/sbin/debian-edu-audiodivert create"

Happy hacking,
-- 
Petter Reinholdtsen


Reply to: