{{{#!div class="box" [[Image(http://xpra.org/icons/sound.png)]] = Sound = You can get more diagnostic messages by using the command line debug flag {{{-d sound}}} (or by setting {{{XPRA_SOUND_DEBUG=1}}}). (see [/wiki/Debugging Debugging]) {{{XPRA_SOUND_QUEUE_TIME}}} can be used to control the default amount of buffering on the receiver. }}} {{{#!div class="box" == Status and Configuration == Sound support has been stable for a while now, but the only codecs that are widely used are '''mp3''' and '''wavpack'''. [[BR]] Unlike screen updates which are discrete events, sound compression processes the operating system's sound data stream and so this is a continuous process which will take up a little bit of CPU and bandwidth. If you want to turn off speaker forwarding, set {{{speaker = no}}} in your system wide {{{xpra.conf}}} (to disable it globally) or in the per-user configuration file. }}} {{{#!div class="box" == Development == Useful development documentation: * [http://harmattan-dev.nokia.com/docs/library/html/gstreamer0.10-doc/gstreamer-plugins-0.10/gstreamer-plugins-queue.html queue] element * [http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-dataaccess.html Pipeline manipulation] * [http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-buffering.html Buffering] * [http://docs.gstreamer.com/display/GstSDK/Basic+tutorial+12%3A+Streaming Basic tutorial: Streaming] }}} {{{#!div class="box" == Requirements == You will need: * a build/installation including {{{GStreamer}}} support for both client and server. We need the "base" plugins and the "ugly" plugins (for mp3) * a client with sound output of any kind (even virtual) * a server with pulseaudio installed (for going beyond the simple test step) * users must be "pulseaudio-enabled" - whatever that means in terms of permissions and user setup (policy, user group, etc: this is distribution specific) }}} {{{#!div class="box" == Standalone Tests == You can run the following test commands to run/test individual parts of the sound pipeline: * {{{./xpra/sound/gstreamer_util.py}}} (named {{{GStreamer_Info.exe}}}) on MS Windows) - will dump all the gstreamer plugins installed, validates that the gstreamer installation is functional. At present, you will need at least the following plugins for mp3 encoding (mp3 is the default codec): * for the server: {{{pulsesrc}}}, {{{audioconvert}}}, {{{audioresample}}}, {{{lamemp3enc}}} and {{{appsink}}} * for the client: {{{appsrc}}}, {{{mp3parse}}}, {{{mad}}}, {{{volume}}}, {{{audioconvert}}}, {{{audioresample}}}, {{{queue}}} and {{{pulsesink}}} * {{{./xpra/sound/pulseaudio_util.py}}} will list the pulseaudio devices found if a pulseaudio server is running * {{{./xpra/sound/src.py}}} will dump the sound coming from the pulseaudio server to a file until interrupted (named {{{Sound_Record.exe}}} on MS Windows) * {{{./xpra/sound/sink.py}}} will play a sound file until interrupted - a "cheap mp3 player" ({{{Sound_Play.exe}}} on MS Windows) }}} {{{#!div class="box" == Test Sound Source Setup == The easiest way of testing that a system is capable of forwarding and receiving sound is on a Posix system (Linux, BSD, etc). Using the {{{XPRA_SOUND_TEST}}} environment variable, we can instruct the xpra server to use a fake sound source instead of hooking into a pulseaudio server (which we do not have to / want to start, yet): {{{ XPRA_SOUND_TEST=1 xpra start :10 --no-pulseaudio }}} Then we can just attach the client from the same system: {{{ xpra attach }}} You should then hear a constant (rather annoying) tone. Getting this far ensures that sound forwarding does work on this system, albeit from a fake source instead of a pulseaudio server. }}} {{{#!div class="box" == Test Sound Output == Since we use [http://gstreamer.freedesktop.org/ GStreamer] for sound support, the first thing to do is to check if gstreamer sound output works on your system. Using gst-launch: {{{ gst-launch audiotestsrc ! audioconvert ! audioresample ! autoaudiosink }}} If the {{{autoaudiosink}}} does not work for you, you may want to try other options (availability varies): {{{pulsesink}}} ({{{PulseAudio}}}), {{{osxaudiosink}}} (OSX), {{{directsoundsink}}} (MS Windows), {{{alsasink}}} / {{{osssink}}} / {{{oss4sink}}} / {{{jackaudiosink}}} (Posix). If this does not work, please refer to [http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gst-running.html Running GStreamer Applications] documentation (in particular {{{GST_DEBUG}}}) If you find a better sink to use with xpra, you can specify it this way: {{{ XPRA_SOUND_SINK=value xpra attach ... }}} }}} {{{#!div class="box" == Simple Diagnostics == Things to look for: * if the speaker is greyed out in the tray then sound is not enabled, check: * the speaker and/or microphone options are enabled in the default {{{xpra.conf}}} file, remove any {{{--no-speaker}}} or {{{--no-microphone}}} options. * Session Info shows sound attributes in 'Features' (see example screenshots below) * "xpra info" should show the pipeline state when a client is playing sound: {{{ $ xpra info | grep -i speaker speaker.state=active }}} * {{{pavucontrol}}} both on the client and inside the xpra session (see example screenshots below) }}} {{{#!div class="box" == Using an existing pulseaudio server == Next, we want to add pulseaudio, but without starting it ourselves, so we can simply re-use the existing server that gets started with most modern desktops. [[BR]] Check that pulseaudio is running in your Posix desktop: {{{ ps -ef | grep pulseaudio }}} Start an xpra server: {{{ xpra start :10 --no-pulseaudio }}} Or create a shadow of the current desktop session: {{{ xpra shadow :0 --no-pulseaudio }}} Attach from the same machine: {{{ xpra attach }}} The server log file should contain the warning message: {{{ identical pulseaudio server, refusing to create a sound loop - sound disabled }}} Getting this far should ensure that all the components are installed, enabled and that the xpra server found the pulseaudio device to connect to. }}} {{{#!div class="box" == Test Remote Setup == Using a second client machine (or a second desktop session, virtual machine, etc), we can connect this new client to the server and get the sound from the desktop session forwarded to the client. The server can be running the test source or a the desktop session's pulseaudio server. In the case of an existing pulseaudio server, simply start any sound application in the desktop session, the sound should come out in both this session's speakers (if any) and the client's speakers (if any / different!). {{{pavucontrol}}} on the server should show an Xpra entry in the {{{Recording}}} tab. The client should show an Xpra entry in the {{{Playback}}} tab (or whatever mixer/sound tool you have installed) - see screenshots below. }}} {{{#!div class="box" == Full Setup == Finally, we may want an xpra session to use a dedicated pulseaudio server. This is more difficult and at present, unless you really know what you are doing and are prepared to pickup the pieces, you should not attempt to do this as a user which already has an existing pulseaudio server running. Simply clearing the environment and trying to start a new pulseaudio instance will not work without some serious hacks to the environment variables that pulseaudio uses to find existing instances. If this is what you really want, [http://winswitch.org/about/ winswitch] will do this for you. [[BR]] Now, assuming that you have a dedicated user, '''without''' any pulseaudio server running, and that the {{{pulseaudio}}} option is enabled (ie: no {{{--no-pulseaudio}}} command line option and no {{{pulseaudio = no}}} in the {{{xpra.conf}}} file). You should be able to setup a sound-capable environment by using simply: {{{ xpra start :10 }}} If, this does not work, you may want to try to start the pulseaudio server manually via: {{{ xpra start :10 --no-pulseaudio \ --start-child="pulseaudio --start --daemonize=false --system=false \ --exit-idle-time=-1 -n --load=module-suspend-on-idle \ --load=module-null-sink --load=module-native-protocol-unix \ --log-level=4 --log-target=stderr" }}} Notes: * you will need to use a tcp socket ({{{--bind-tcp=}}} or ssh forwarding to connect to this account - out of scope here. The default {{{log-level}}} in the default {{{xpra.conf}}} file is low, but if you raise it to 4 or above (ie: if you use the explicit command line above to start pulseaudio), you should then see these messages in the server log: {{{ (..) D: [pulseaudio] main.c: Got org.PulseAudio1! D: [pulseaudio] main.c: Got org.pulseaudio.Server! I: [pulseaudio] main.c: Daemon startup complete. 2013-01-07 17:42:55,732 xpra is ready. }}} And when connecting a sound capable client: {{{ I: [pulseaudio] client.c: Created 0 "Native client (UNIX socket client)" (...) 2013-01-07 17:44:32,205 will send sound using mp3 codec (...) 2013-01-07 17:44:32,309 starting sound using null.monitor D: [pulseaudio] module-suspend-on-idle.c: Sink null becomes busy. }}} And yet more log messages as your start a sound application in this xpra session. }}} {{{#!div class="box" == ALSA, OSS, etc == The instructions above will make sound work with all applications that use pulseaudio for output. For those that do not, please see [http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/PerfectSetup PulseAudio Perfect Setup] to route their sound to pulseaudio. }}} {{{#!div class="box" == Screenshots == * Sound information displayed on session info (with speaker enabled and running and microphone disabled): [[BR]] [[Image(/raw-attachment/wiki/Sound/session-info-sound.png)]] * A Linux client's pavucontrol showing the Xpra application connected to the local pulseaudio server: [[BR]] [[Image(/raw-attachment/wiki/Sound/pavucontrol-client.png)]] * pavucontrol running within the xpra session ("on the server"), showing xpra recording the session's sound: [[BR]] [[Image(/raw-attachment/wiki/Sound/pavucontrol-server.png)]] }}}