NikNakk
Posts: 4
Joined: Fri Aug 10, 2012 8:28 am

AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Fri Aug 10, 2012 8:41 am

Hi,

I've been playing round with XBMC on Raspbian to see if I can get AirTunes working. There are two issues with it, as far as I can tell. One I can solve, the other I haven't as yet.

Issue 1: libshairport and IPv4/6

libshairport is the library made by the XBMC creators based on the shairport code that allows decryption of the AirTunes stream. It includes code that was intended to use IPv6 in preference, and fall back to IPv4 if IPv6 doesn't work. However, the code as stands doesn't work. It will work if the kernel supports IPv6 (most modern linux distros, but not the default Raspbian kernel). It will work if the C headers for IPv6 are missing. But if the headers are present, it does the following:
- Create an addrinfo block for the server using IPv6 (and therefore the IPv6 localhost address)
- Try to create an IPv6 socket
- Fail and create a IPv4 socket
- Try to bind to the IPv4 socket using an IPv6 address info block
- Crash with the error 'address family not supported by this protocol'

I'd imagine anyone trying to use AirTunes on the default Raspbian kernel has seen this error pop up and not been sure what it is.

The possible solutions are as follows:
1. Recompile the kernel to support IPv6
2. Correct the error in the libshairport code so that the addrinfo block is recreated with an IPv4 address if creating an IPv6 socket fails
3. (Temporary hack) Replace the checks for #ifdef AF_INET6 in the code with a dummy #ifdef SOMETHINGTHATISNOTDEFINED

I've gone with 3 as a proof of concept, and once libshairport is recompiled like this, that side of things works. In the longer term, it would be better to do 1 (since there will in the next couple of years be IPv6 only internet sites) and also do 2 (since it's a bug that should be fixed.)

Issue 2:
So, libshaiport's working well. The debug messages in the log indicate that it's connecting to the iOS device and getting the stream and decoding it. But still no music! 'Working' pops up on the screen briefly, and then stops. The log has an error about 'error demuxing stream'.

This issue relates to the fact that AirTunes uses Apple Lossless Audio Codec (ALAC), Raspberry Pi XBMC uses OMXPlayer for everything, and OMXPlayer doesn't support ALAC. XBMC on any other OS would use PAPlayer for audio, which does support ALAC. I've tried editing the PlayerCoreConfig.h to force XBMC to use PAPlayer, but then XBMC cannot play any music and crashes with a Segmentation Fault, presumably due to lack of memory or some other bug in PAPlayer when running on Raspberry Pi.

There are 2 possible solutions to this:
1. Get PAPlayer working on Raspberry Pi
2. Get OMXPlayer to support ALAC as streamed by AirTunes and decrypted by Shairport.

Both of these are, I'm afraid, a little beyond me at the moment, but I would love to see what someone who knows more about OMXPlayer or PAPlayer can do.

Nick

User avatar
Sander
Posts: 174
Joined: Wed Aug 31, 2011 1:01 pm

Re: AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Thu Aug 16, 2012 11:36 am

NikNakk wrote:However, the code as stands doesn't work. It will work if the kernel supports IPv6 (most modern linux distros, but not the default Raspbian kernel).
Hi,

AFAIK, the Raspbian kernel *does* support IPv6: after a manual "sudo insmod ipv6" or "ipv6" in /etc/mocules, ipv6 shows up in ifconfig. See http://ipv6-or-no-ipv6.blogspot.nl/2012 ... fault.html

So:
- is loading of the ipv6 module a 4th workaround?
- does the code need ipv6 in the kernel (which is there, I would say), or does it need the module ipv6 to be loaded (which is possible, and should be done by default IMHO)?

Sander

trouch
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
Contact: Website

Re: AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Thu Aug 16, 2012 7:10 pm

check this out : http://trouch.com/2012/08/03/airpi-airp ... raspberry/
IPv6 isn't required. but if the ipv6 module is loaded, it works too.
don't hope to use airplay over internet as it uses bonjour protocol which is a multicast based protocol and so is non routable on Internet, even with IPv6.

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com

NikNakk
Posts: 4
Joined: Fri Aug 10, 2012 8:28 am

Re: AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Sat Aug 18, 2012 1:46 pm

I haven't checked yet, but loading it as a module should work fine. However, the libshairport code should still be fixed.

I've now got a working fix to the libshairport code that falls back to ipv4 properly.

More importantly, I now understand the problem with xbmc on Rpi and the stream generated by libshairport. Contrary to what I wrote before, libshairport actually does the ALAC decoding itself and presents a pipe with a 16 bit little endian PCM stereo stream with mime-type x-xbmc-pcm. PAPlayer uses a codec file called BXACodec.cpp to handle this.

PA player on RPi is broken (but normally disabled). I think this relates to the fact that the Audio Engine code has not been implemented. In any case, when PAPlayer initiates the audio stream it gets a null pointer that ultimately leads to the seg fault I described before.

Getting PA player working would be nice, but would require a fairly major effort. What I have managed to achieve is to get dvdplayer to handle the libshairport stream. I've tested it successfully on a x86 PC at present, but have compiled the code for RPi and all being well should be able to post patches to the xbmc-rbp source later today.

Finally, we should have AirTunes audio within XBMC on Raspberry Pi!

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Mon Aug 20, 2012 2:10 pm

Eagerly awaiting a resolve on this ;)

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Tavalin
Posts: 59
Joined: Mon Apr 16, 2012 9:53 pm

Re: AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Mon Aug 20, 2012 2:39 pm

Sounds like excellent work so far! Keep it up!

NikNakk
Posts: 4
Joined: Fri Aug 10, 2012 8:28 am

Re: AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Mon Aug 20, 2012 9:23 pm

Hi,

I've been working on it. I have AirTunes working in XBMC on my Raspberry Pi, but it sounds like it's coming through a low quality radio in a bathroom. I've tried playing some PCM audio in a WAV file, which works fine, so I'm trying to work out where the problem is. I've also started my own git repository with modified sources at https://www.github.com/NikNakk/xbmc-rbp.git

It should build ok on a Raspberry pi. I do my building using a PC running Ubuntu and using a schroot environment with qemu-arm-static and the Raspbian distro.

Installation instructions (tested on Raspbian):
- If compiling on a Raspberry pi, configure 224 MB kernel:

Code: Select all

sudo cp /boot/arm224_start.elf /boot/start.elf
sudo reboot
- Install build dependencies:

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential autoconf ccache gawk gperf mesa-utils zip unzip git
sudo apt-get install autotools-dev comerr-dev dpkg-dev libalsaplayer-dev \
    libapt-pkg-dev:armhf libasound2-dev:armhf libass-dev:armhf libatk1.0-dev \
    libavahi-client-dev libavahi-common-dev libavcodec-dev libavformat-dev \
    libafpclient0 libafpclient-dev libplist1 libplist-dev \
    libavutil-dev libbison-dev:armhf libbluray-dev:armhf libboost1.50-dev \
    libbz2-dev:armhf libc-dev-bin libc6-dev:armhf libcaca-dev libcairo2-dev \
    libcdio-dev libclalsadrv-dev libcrypto++-dev libcups2-dev libcurl3-gnutls-dev \
    libdbus-1-dev libdbus-glib-1-dev libdirectfb-dev libdrm-dev libegl1-mesa-dev \
    libelf-dev libenca-dev libept-dev libevent-dev libexpat1-dev libflac-dev:armhf \
    libfontconfig1-dev libfreetype6-dev libfribidi-dev libgconf2-dev \
    libgcrypt11-dev libgdk-pixbuf2.0-dev libgl1-mesa-dev libgles2-mesa-dev \
    libglew-dev:armhf libglewmx-dev:armhf libglib2.0-dev libglu1-mesa-dev \
    libgnome-keyring-dev libgnutls-dev libgpg-error-dev libgtk2.0-dev libhal-dev \
    libhunspell-dev:armhf libice-dev:armhf libicu-dev libidn11-dev libiso9660-dev \
    libjasper-dev libjbig-dev:armhf libjconv-dev libjpeg8-dev:armhf libkrb5-dev \
    libldap2-dev:armhf libltdl-dev:armhf liblzo2-dev libmad0-dev libmicrohttpd-dev \
    libmodplug-dev libmp3lame-dev:armhf libmpeg2-4-dev libmysqlclient-dev \
    libncurses5-dev libnfs-dev libnspr4-dev libnss3-dev libogg-dev:armhf \ 
    libopenal-dev:armhf libp11-kit-dev libpam0g-dev:armhf libpango1.0-dev \
    libpcre++-dev libpcre3-dev libpixman-1-dev libpng12-dev \
    libprotobuf-dev libpthread-stubs0-dev:armhf \
    libpulse-dev:armhf librtmp-dev libsamplerate0-dev:armhf \
    libsdl-image1.2-dev:armhf libsdl1.2-dev libslang2-dev:armhf \
    libsm-dev:armhf libsmbclient-dev:armhf libspeex-dev:armhf \
    libsqlite3-dev libssh-dev libssh2-1-dev libssl-dev libstdc++6-4.6-dev \
    libtagcoll2-dev libtasn1-3-dev libtiff4-dev libtinfo-dev:armhf libtinyxml-dev \
    libts-dev:armhf libudev-dev libv8-dev libva-dev:armhf libvdpau-dev:armhf \
    libvorbis-dev:armhf libvpx-dev:armhf libwebp-dev:armhf libwibble-dev \
    libx11-dev:armhf libx11-xcb-dev libxapian-dev libxau-dev:armhf \
    libxcb-glx0-dev:armhf libxcb-render0-dev:armhf libxcb-shm0-dev:armhf \
    libxcb1-dev:armhf libxcomposite-dev libxcursor-dev:armhf libxdamage-dev \
    libxdmcp-dev:armhf libxext-dev:armhf libxfixes-dev libxft-dev libxi-dev \
    libxinerama-dev:armhf libxml2-dev:armhf libxmu-dev:armhf libxrandr-dev \
    libxrender-dev:armhf libxslt1-dev libxss-dev:armhf libxt-dev:armhf \
    libxtst-dev:armhf libxxf86vm-dev libyajl-dev libzip-dev linux-libc-dev:armhf \
    lzma-dev mesa-common-dev python-dev python2.7-dev x11proto-composite-dev \
    x11proto-core-dev x11proto-damage-dev x11proto-dri2-dev x11proto-fixes-dev \
    x11proto-gl-dev x11proto-input-dev x11proto-kb-dev x11proto-randr-dev \
    x11proto-record-dev x11proto-render-dev x11proto-scrnsaver-dev \
    x11proto-xext-dev x11proto-xf86vidmode-dev x11proto-xinerama-dev xtrans-dev \
    zlib1g-dev:armhf avahi-daemon
If you haven't already set up ldconfig for the VideoCore library, do so:

Code: Select all

sudo sh -c "echo /opt/vc/lib/ >> /etc/ld.so.conf.d/0_broadcom.conf"
sudo ldconfig
Get my git repository:

Code: Select all

mkdir ~/NikNakk
cd ~/NikNakk
git clone --depth 1 git://github.com/xbmc/xbmc-rbp.git
Set up xbmc configs:

Code: Select all

cd xbmc-rbp
./bootstrap
./configure --with-platform=raspberry-pi --disable-debug
Uninstall any existing libshairport:

Code: Select all

sudo apt-get remove libshairport*
Make and install libshairport:

Code: Select all

sudo make install -C lib/libshairport libdir=/usr/lib/arm-linux-gnueabihf
Make xbmc (and fix problem with FEH.py):

Code: Select all

cd ~/NikNakk/xbmc-rbp
./configure --with-platform=raspberry-pi --disable-debug
make
sed -i 's/if "--no-test" in sys.argv:/if 1==1:/' tools/Linux/FEH.py
sudo make install
Now change to 128 MB split and reboot:

Code: Select all

sudo cp /boot/arm128_start.elf /boot/start.elf
sudo reboot
If all is well:

Code: Select all

xbmc
Note: Check the output of configure. At the end, it will tell you which options are enabled/disabled. If something you want is disabled, you're probably missing a library for it (and so my dependencies above are probably deficient). Try re-running configure using (for example) --enable-airtunes and you may get a useful hint as to what's missing.

As I understand it, most Raspberry Pi distros have the VideoCore libraries in /opt/vc . Using --with-platform=raspberry-pi should add this to the includes and ldflags, but if your distro has them somewhere else (and not in the standard /usr/ tree) you'll need to make sure LDFLAGS and CPPFLAGS are set appropriately.

Please let me know how you get on.

Now I need to work out why the sound's messed up!

NikNakk
Posts: 4
Joined: Fri Aug 10, 2012 8:28 am

Re: AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Tue Aug 21, 2012 8:28 pm

I've corrected a couple of errors in the repository and in the instructions. New instructions below:

Installation instructions (tested on Raspbian):
- If compiling on a Raspberry pi, configure 224 MB kernel:

Code: Select all

    sudo cp /boot/arm224_start.elf /boot/start.elf
    sudo reboot
- Install build dependencies:

Code: Select all

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install build-essential autoconf ccache gawk gperf mesa-utils zip unzip git
    sudo apt-get install autotools-dev comerr-dev dpkg-dev libalsaplayer-dev \
        libapt-pkg-dev:armhf libasound2-dev:armhf libass-dev:armhf libatk1.0-dev \
        libavahi-client-dev libavahi-common-dev libavcodec-dev libavformat-dev \
        libafpclient0 libafpclient-dev libplist1 libplist-dev \
        libavutil-dev libbison-dev:armhf libbluray-dev:armhf libboost1.50-dev \
        libbz2-dev:armhf libc-dev-bin libc6-dev:armhf libcaca-dev libcairo2-dev \
        libcdio-dev libclalsadrv-dev libcrypto++-dev libcups2-dev libcurl3-gnutls-dev \
        libdbus-1-dev libdbus-glib-1-dev libdirectfb-dev libdrm-dev libegl1-mesa-dev \
        libelf-dev libenca-dev libept-dev libevent-dev libexpat1-dev libflac-dev:armhf \
        libfontconfig1-dev libfreetype6-dev libfribidi-dev libgconf2-dev \
        libgcrypt11-dev libgdk-pixbuf2.0-dev libgl1-mesa-dev libgles2-mesa-dev \
        libglew-dev:armhf libglewmx-dev:armhf libglib2.0-dev libglu1-mesa-dev \
        libgnome-keyring-dev libgnutls-dev libgpg-error-dev libgtk2.0-dev libhal-dev \
        libhunspell-dev:armhf libice-dev:armhf libicu-dev libidn11-dev libiso9660-dev \
        libjasper-dev libjbig-dev:armhf libjconv-dev libjpeg8-dev:armhf libkrb5-dev \
        libldap2-dev:armhf libltdl-dev:armhf liblzo2-dev libmad0-dev libmicrohttpd-dev \
        libmodplug-dev libmp3lame-dev:armhf libmpeg2-4-dev libmysqlclient-dev \
        libncurses5-dev libnfs-dev libnspr4-dev libnss3-dev libogg-dev:armhf \
        libopenal-dev:armhf libp11-kit-dev libpam0g-dev:armhf libpango1.0-dev \
        libpcre++-dev libpcre3-dev libpixman-1-dev libpng12-dev \
        libprotobuf-dev libpthread-stubs0-dev:armhf \
        libpulse-dev:armhf librtmp-dev libsamplerate0-dev:armhf \
        libsdl-image1.2-dev:armhf libsdl1.2-dev libslang2-dev:armhf \
        libsm-dev:armhf libsmbclient-dev:armhf libspeex-dev:armhf \
        libsqlite3-dev libssh-dev libssh2-1-dev libssl-dev libstdc++6-4.6-dev \
        libtagcoll2-dev libtasn1-3-dev libtiff4-dev libtinfo-dev:armhf libtinyxml-dev \
        libts-dev:armhf libudev-dev libv8-dev libva-dev:armhf libvdpau-dev:armhf \
        libvorbis-dev:armhf libvpx-dev:armhf libwebp-dev:armhf libwibble-dev \
        libx11-dev:armhf libx11-xcb-dev libxapian-dev libxau-dev:armhf \
        libxcb-glx0-dev:armhf libxcb-render0-dev:armhf libxcb-shm0-dev:armhf \
        libxcb1-dev:armhf libxcomposite-dev libxcursor-dev:armhf libxdamage-dev \
        libxdmcp-dev:armhf libxext-dev:armhf libxfixes-dev libxft-dev libxi-dev \
        libxinerama-dev:armhf libxml2-dev:armhf libxmu-dev:armhf libxrandr-dev \
        libxrender-dev:armhf libxslt1-dev libxss-dev:armhf libxt-dev:armhf \
        libxtst-dev:armhf libxxf86vm-dev libyajl-dev libzip-dev linux-libc-dev:armhf \
        lzma-dev mesa-common-dev python-dev python2.7-dev x11proto-composite-dev \
        x11proto-core-dev x11proto-damage-dev x11proto-dri2-dev x11proto-fixes-dev \
        x11proto-gl-dev x11proto-input-dev x11proto-kb-dev x11proto-randr-dev \
        x11proto-record-dev x11proto-render-dev x11proto-scrnsaver-dev \
        x11proto-xext-dev x11proto-xf86vidmode-dev x11proto-xinerama-dev xtrans-dev \
        zlib1g-dev:armhf avahi-daemon


If you haven't already set up ldconfig for the VideoCore library, do so:

Code: Select all

    sudo sh -c "echo /opt/vc/lib/ >> /etc/ld.so.conf.d/0_broadcom.conf"
    sudo ldconfig
Get my git repository:

Code: Select all

    mkdir ~/NikNakk
    cd ~/NikNakk
    git clone --depth 1 git://github.com/xbmc/xbmc-rbp.git
Set up xbmc configs:

Code: Select all

    cd xbmc-rbp
    ./bootstrap
Uninstall any existing libshairport:

Code: Select all

    sudo apt-get remove libshairport*
Make and install libshairport:

Code: Select all

	make -C lib/libshairport 
    sudo make install -C lib/libshairport libdir=/usr/lib/arm-linux-gnueabihf prefix=/usr

Configure, make, install xbmc (and fix problem with FEH.py):

Code: Select all

    cd ~/NikNakk/xbmc-rbp
    ./configure --with-platform=raspberry-pi --disable-debug --host=arm-linux-gnueabihf
    make
    sed -i 's/if "--no-test" in sys.argv:/if 1==1:/' tools/Linux/FEH.py
    sudo make install
Now change to 128 MB split and reboot:

Code: Select all

    sudo cp /boot/arm128_start.elf /boot/start.elf
    sudo reboot

If all is well:

Code: Select all

    xbmc

Note: Check the output of configure. At the end, it will tell you which options are enabled/disabled. If something you want is disabled, you're probably missing a library for it (and so my dependencies above are probably deficient). Try re-running configure using (for example) --enable-airtunes and you may get a useful hint as to what's missing.

As I understand it, most Raspberry Pi distros have the VideoCore libraries in /opt/vc . Using --with-platform=raspberry-pi should add this to the includes and ldflags, but if your distro has them somewhere else (and not in the standard /usr/ tree) you'll need to make sure LDFLAGS and CPPFLAGS are set appropriately.

Please let me know how you get on.

Now I need to work out why the sound's messed up!

adib
Posts: 1
Joined: Fri Aug 03, 2012 10:12 am

Re: AirTunes (AirPlay audio) and XBMC on Raspberry Pi

Fri Sep 28, 2012 6:36 am

Hi,

Any updates about audio is issue?

NikNakk, you might take a look here https://github.com/NikNakk/xbmc-rbp/blo ... Server.cpp around line 331.
I think that if you are using FFmpeg to handle the stream and set the format to s16le, FFmpeg would expect a raw pcm file which does not have any header, it contains only samples.The code in the AirTunesServer.cpp writes a header which is piked up by the BXAcodec when PAplayer is used, and I think that will offsets the samples and get you the messed up sound.
So the idea would be to remove the lines 331 - 340 to see if that will fix it.
I have done that, but I do not own an Apple device, and I have tried with pulseaudio but it does not handle UDP for now (there is some work going on on that matter).

Let me know if that helped!

Return to “Media centres”