Summary: in this article I explain how you can stream music (audio) from your Ubuntu computer to XBMC using UPnP. While this recipe also allows you to play every MP3 file on your computer, it is targeted to getting the audio from your speakers to your home cinema set.
While test-driving XBMC 12 during the pre-beta phase I noticed how I could use AirPlay with iTunes under Windows to get sound from my crappy laptop speakers to the home cinema setup powered by XBMC.
Thinking this should also be possible from within Ubuntu Linux sent me on a goose chase that seemed to end up nowhere.
From the ‘paprefs’ utility, you can actually connect with the AirPlay capabilities of XBMC. But instead of sharing sound, you in-sta crash or hang XBMC. Even better, since this functionality is managed by PulseAudio, merely logging in on Ubuntu will hang XBMC as PulseAudio keeps connecting.
I read multiple stories how this is a RAOP (I assume this is the Linuxy name for AirPlay) issue where UDP should be used but TCP is preferred or something. Looking at the libshairplay website (which seems to be used by PA), it says UDP is supposed to be working for quite some time now. I gave up on this.
Next up is sharing local audio using UPnP: paprefs => ‘Network Server’ => ‘Make local sound devices available as DNLA/UPnP Media Server’. Fire up XBMC, search for audio using UPnP aaaaaand…. nothing.
It turns out that enabling this option only loads a module which creates an HTTP audio sink. Put another way: the audio from your sound card is shared on the network, it is just not advertised so nothing can find it.
This is the point where you need Rygel. While the description tells you about transcoding media for Xboxes and PlayStations, the core of Rygel is a UPnP media server. You need this functionality to advertise the audio sources to the local network.
If you now start Rygel (3) by typing ‘rygel’ you will get a listing for any found media, Rythmbox music collection (if its running) and the internal sound cards (1).
But all is not well yet: when you point XBMC to the internal sound card (or the special DNLA device if you enabled it in ‘paprefs’) XBMC will crash: http://trac.xbmc.org/ticket/13579
Hopefully this bug will get fixed soon but in the meantime it leaves us without streaming audio. Luckily there is another solution in the form of the GstLaunch (2) plugin for Rygel. Do note that this is another package seperate from Rygel itself (it took me 10 minutes to figure out why the plugin was seemingly awol when it was in fact not installed).
The GstLauncher plugin allows you to connect a GStreamer pipeline to the network as a UPnP source. While this in theory opens up loads of fun stuff to play with, it can also be used to generate audio streams from the internal sound card for XBMC.
Open up your rygel.conf (I removed the one in ~/.config/rygel.conf and put everything in /etc/rygel.conf) and put the following in there (comment the existing GstLaunch section):
[GstLaunch]
enabled=true
launch-items=pulseaudioflac;pulseaudiomp3;pulseaudiopcm
pulseaudioflac-title=FLAC on @HOSTNAME@
pulseaudioflac-mime=audio/flac
pulseaudioflac-launch=pulsesrc
device=upnp.monitor ! flacenc
quality=8
pulseaudiomp3-title=MP3 on @HOSTNAME@
pulseaudiomp3-mime=audio/mpeg
pulseaudiomp3-launch=pulsesrc
device=upnp.monitor ! lamemp3enc
target=quality
quality=6
pulseaudiopcm-title=PCM on @HOSTNAME@
pulseaudiopcm-mime=audio/x-wav
pulseaudiopcm-launch=pulsesrc
device=upnp.monitor ! wavenc
Feel free to cut this list down to just the formats you want (do not forget to modify launch-items accordingly). MP3 is lossy and as such lowers audio quality and has a high latency. FLAC is losless and should have low latency but XBMC refuses to play the FLAC stream. It complains about the -lack of- metadata and similar issues have been solved in GStreamer 0.11 while I am using 0.10. I assume a newer Ubuntu will fix this. Finally PCM is uncompressed wave but requires the most bandwidth – I am using this option.
You will end up with something like this:
+--> (1) PulseAudio => HTTP stream from internal audio --+
Ubuntu --+--> (2) Rygel => HTTP audio stream from GstLaunch ------+--> network -> XBMC
+--> (3) Rygel UPnP server ------------------------------+
Note that (1) would be the preferred option as its built into Ubuntu but currently does not work in XBMC. Start Rygel and find the GstLaunch entry in the UPnP listing. Pick one of the streams to start listening, enjoy!