19-year-old develops Raspbmc, makes streaming to a Raspberry Pi nearly idiot-proof.

0 comments


Raspberry Pi + iPad mini + AirPlay = home entertainment heaven.
Jon Brodkin

There are so many incredible things you can do with a Raspberry Pi. You could build a robot. Invent a new kind of musical instrument. Or send the tiny computer nearly into outer space on a picture-taking balloon adventure.

Sadly, I have no idea how to do any of those things. But I bought a couple of Raspberry Pis, and it would have felt wasteful not to at least do something useful with them.

The obvious choice was home media streaming. The first floor of my place has all the consumer electronics and home networking a tech journalist could ask for, but my second floor was pretty bare. Enter the Raspberry Pi (and a 7-year-old TV that had been gathering dust in a corner as a result of being replaced a year ago).

Long story short, I am now streaming music from my iPad to that TV using Apple's AirPlay protocol and Raspberry Pi media software called Raspbmc. I can stream HD video in the same way, but I set it up primarily for music.

The best part is I didn't have to do anything other than follow instructions. All the heavy lifting was taken care of by the creator of Raspbmc (a 19-year-old student, believe it or not), and the developers of XBMC, the popular home media software on which it's based. XBMC developers reverse-engineered the AirPlay protocol to let it work on non-Apple devices.

Raspbmc isn't perfect—there are short delays between issuing a command from my iPad (pressing play, pause, skip, etc.) and hearing the results on the Pi-enabled TV. Considering the low cost and coolness factor, though, it was a fun project worth doing.

Enlarge / Raspbmc's easy-to-use interface.
Jon Brodkin

Getting started

What I used:

Jon Brodkin
Jon Brodkin

If you want to take on this rather easy project, the first step is heading to the Raspbmc downloads page and grabbing the network image. You'll load this onto an SD card on a Windows, Mac, or Linux computer.

Windows installation is performed by a setup program, while Mac and Linux users should open the terminal and enter a couple of simple commands:

Before installing the Raspbmc network image to the SD card, make sure you're not installing to the wrong disk, since you could lose data.

After that's done, stick the SD card into the Pi and hook it up to a TV or whatever device you're using. The Pi has no on/off switch, so you turn it on simply by plugging in a micro-USB power supply.

As long as you're connected to the Internet, the Pi will now install the latest version of Raspbmc. This requires a wired connection. If you lack an Ethernet hookup at this point, you can get the standalone Raspbmc image instead of the network image from the downloads page.

During installation, you'll see messages like "Connection to Raspbmc update server successful," "Formatting partitions," "Downloading kernel modules," and "Downloading root file system—grab a coffee!" The installer will inform you to wait 15 to 25 minutes for it to do its thing and then reboot into Raspbmc. Mine took 22 minutes.

Keyboard input didn't work for me immediately after the installation. Unplugging the Pi and then plugging it back in did the trick, except for a nasty message telling me "Raspbmc did not shut down properly."

Once Raspbmc is installed, it can be used over Wi-Fi. After completing the installation on my living room TV, where I had an Ethernet connection, I brought the Pi upstairs to my bedroom, where Wi-Fi is my only option. With a cheap USB wireless adapter plugged in, I navigated to Programs/Raspbmc settings/Network Configuration, selected "wireless" and typed in my network name and password to connect.

Getting AirPlay working was as simple as heading toward System/Settings/Services/AirPlay and checking "Allow XBMC to receive AirPlay content." Once that was done, my iPad began showing "XBMC (raspbmc)" as an AirPlay target from the music and video apps. This will work from any iOS device or from iTunes on a computer:

Enlarge / My AirPlay receivers: An Apple TV downstairs, a Raspberry Pi upstairs.
Enlarge / 1080p!
Jon Brodkin
Enlarge / AirPlaying music.
Jon Brodkin

Almost perfect

I initially attempted to install Raspbmc on a Raspberry Pi with 512MB of RAM, but the Pi simply shut off during the installation process each time. As if by magic, it worked perfectly on the 256MB model.

As it turns out, the power supply was likely the culprit, even though I used the same supply on both devices. Raspbmc creator Sam Nazarko explained to me via e-mail that "if you are using the same power supply on both Pis but only getting issues on the second, then it is likely the 512 Pi has higher resistance on the F3 polyfuse, and thus exposes the inadequacy of the power supply to a greater extent."

I didn't expect the power supply to be a problem since I had been able to run Raspbian, the recommended operating system for the Pi, on both the 256MB and 512MB devices. In any case, Raspbmc is working smoothly on the Pi with 256MB of RAM.

The only noticeable problem is one I mentioned earlier, a delay of about two seconds between issuing commands like play or pause and seeing or hearing the results. The delay occurs on both Wi-Fi and Ethernet. Others have also noticed the slow buffering, making fast-forwarding and rewinding a bit tricky. For me, the delay mostly occurs when playing music. Playing and pausing videos has been near-instantaneous.

In addition to AirPlay, Raspbmc plays music and video from local USB drives or from computers in your house if you add network locations via the settings menu.

Raspbmc is impressive software, period, and even more so when you consider that its creator is a teenager. Raspberry Pi Foundation community manager Liz Upton described Nazarko as a "terrifyingly young developer" when the final version of Raspbmc was released in February.

Nazarko spent more than a year developing Raspbmc and described the process on his blog. He received important help from the Pi Foundation, which gave him a Pi prior to the device's launch, and from numerous other people, including the developers of XBMC.

Why AirPlay can run on non-Apple devices

Those XBMC developers are the ones we can thank for getting AirPlay to run, even on non-Apple hardware. One thing you may wonder given Apple's tendency to lock down its products is why it's possible to use AirPlay with non-Apple hardware at all.

I contacted the XBMC team and received a detailed answer from an XBMC developer who goes by the name "Memphiz." Memphiz explains that Apple's streaming protocols are "closed," but they were reverse-engineered by developers to allow them to work on non-Apple hardware. Just as Apple can eliminate jailbreaks on new versions of iOS, the company could change AirPlay in such a way that the XBMC and Raspbmc implementations would stop working.

Memphiz's explanation via e-mail is worth quoting in full:

1. AirPlay (meaning video and pictures) is not encrypted. It just transfers a playback URL (HTTP) to the receiver and also some control messages. In case of e.x. YouTube app it transfers the video URL directly from YouTube to the receiver. When AirPlaying from the video app or from the camera roll it spawns an HTTP server and passes its own URL to the receiver. For images it just sends the JPEG data via HTTP. There are also a lot of control messages for controlling playback (client to receiver) or announcing playback states (receiver client). The protocol is reverse engineered and can be found on github.

2. AirTunes (meaning music streaming) is a whole different thing. It needs encryption. There are at least three different encryption types possible. The weakest was broken by some guy a couple of years ago. He extracted a private RSA key from an Apple AirPort Express or something like that. We use a third-party library here for allowing XBMC to receive music streams. It's based on a standalone app called "shairport"—we made a library out of it and added some fixups/patches. The AirTunes protocol is also reverse engineered and can be found via Google.

3. Basically it is possible as you can see in XBMC. But as it's still a closed protocol, our implementation might break here and there once Apple changes something on OS updates. Though we are happy to have the support in, it's a bit like playing blackjack (not knowing which Apple card comes next).

Cheap, but not insanely so

As you probably know, a Raspberry Pi sells for the remarkably low price of $35. For my setup, this turned into about $100, including $6 for an HDMI cable, $11 for a Wi-Fi adapter, $30 for a Bluetooth keyboard, and $18 for an SD card. If you have an old keyboard lying around and buy cheaper accessories than I did, you might cut the cost in half.

Ultimately, you're not saving a ton of money compared to buying a $100 Apple TV, which will do AirPlay plus iTunes home sharing, Netflix streaming, and other goodies—it even runs XBMC if it's jailbroken. Nazarko told me that "Netflix is a no-go on Raspbmc and iTunes home sharing is not possible."

As they say, though, eff that. AirPlay is way cooler on a Raspberry Pi.

No comments: