AirPlay to Linux / Ubuntu with Shairport v1.0

Linux can receive AirPlay audio using a program called Shairport that I covered over a year ago. Shairplay has since been re-written by the original developer James Laird to no longer rely on perl. The latest version is v1.0-dev here's how to get AirPlay working on Ubuntu using Shairport and iTunes to test it.


1. Download AirPlay (Shairport)
cd /tmp
sudo git clone https://github.com/abrasive/shairport.git shairport

2. Install dependencies
sudo apt-get install libssl-dev libavahi-client-dev libasound2-dev build-essential

3. Configure the Shairport build
cd shairport
./configure

4. Make & install Shairport
sudo make
sudo make install

5. Identify your audio output device
aplay -l

My output was:

**** List of PLAYBACK Hardware Devices ****
card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: PCH [HDA Intel PCH], device 0: ALC892 Analog [ALC892 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC892 Digital [ALC892 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

I want to output via digital spdif. For me that interface is ALC892 Digital [ALC892 Digital] and hardware card 1 device 1 i.e. hw:1,1

Note this device it is used in step 6.

5. Setup the firewall, 

Port 3689/ tcp
Port 5353/ tcp / udp
Port 5000 tp 5005 / tcp
Port 6000 to 6005 / udp
It also seems to use dynamic udp ports so I have opened 35000-65535, not ideal.

I use ufw to do this:

sudo ufw allow from 192.168.1.1/16 to any port 3689 proto tcp
sudo ufw allow from 192.168.1.1/16 to any port 5353
sudo ufw allow from 192.168.1.1/16 to any port 5000:5005 proto tcp
sudo ufw allow from 192.168.1.1/16 to any port 6000:6005 proto udp
sudo ufw allow from 192.168.1.1/16 to any port 35000:65535 proto udp

6. Run Shairport
shairport -v -a 'Name you want to appear in AirPlay' -o alsa-- -d hw:1,1

Add -v to the above for debugging info, -vv for more debug info and -vvv for even more debug info!

7. AirPlay to your new AirPlay receiver
Note when doing this from an Android phone running DoubleTwist I experienced significant lag before receiving audio c. 30 seconds to a minute. iTunes was pretty much instantaneous < 2 seconds and so was an iPhone.

Troubleshooting
If you receive no audio try disabling the firewall to test (sudo ufw disable), remember to re-enable it (sudo ufw enable)!

Note Shairport does not support AirPlay v2 raop2 which is the protocol that the Ubuntu AirPlay sender uses to output audio.

Credits to James Laird for Shairport no longer requiring Perl, source: https://github.com/abrasive/shairport/

2 comments:

  1. Thanks for this post - briliant stuff!

    I'm a bit of an Ubuntu newb, and there were a couple of bonus steps I needed to do - thought I'd comment them here, might help out another newbie.

    Before your step 1....I had to:

    1. Updated apt-get using: sudo apt-get update
    (everyone knows this, right?)
    2. Install git first using: sudo apt-get install git

    And then start at the guide's step 1.

    I didn't have a firewall, so I just ignored your step 5.

    When I got to step 6, I was getting an error about the output device, even though I had the hardware address correct (hw:0,0). Because my Ubuntu server is very simple - I ended up just running the following command:

    shairport -a 'fx160'

    This worked fine, since the default output was alsa, and it used my default audio output device.

    Now all I have to do is figure out how to make this happen automatically as the system boots!

    Thanks again for a great post.

    ReplyDelete
  2. i have finally got sound working with an external usb device on my system. the device is /proc/asound/UA1EX

    where do I find the output device character string that shairport needs in the -o field? For the life of me I can't seem to find it....

    thanks
    Phil Kemp

    ReplyDelete