fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

New AirPlay Mirroring Server (Open Source)

Wed Jun 12, 2019 4:50 pm

Hi all,
I’d like to introduce RPiPlay, an open-source AirPlay mirroring server for the Raspberry Pi!

Introduction
For a long time, I've wanted to use the Raspberry Pi (And a Zero in particular) as an AirPlay mirroring receiver. Not just the low price point makes it a great device for that purpose, it's also very portable while at the same time having a powerful graphics chip for decoding the H264 that AirPlay uses. Unfortunately though, there wasn't any suitable software available for the Pi. I would even have paid a few dollars for a commercial solution, but the only option (rplay) seems to be mostly abandoned and doesn’t work with recent versions of iOS.

I had also done research on open source implementations for Linux, but couldn’t find any. So, I was hugely surprised when a few weeks ago, a routinely scan of GitHub actually yielded a very promising project: A GitHub user by the name of dsafa22 had published a fully open-source AirPlay mirroring server for Android in C.
Over the last few weeks, I ported this project to the Raspberry Pi, utilizing OpenSSL and the Pi’s hardware acceleration to speed it up until it was reasonably fast for the Pi.

Current State
So, we now have a fully open source AirPlay mirroring receiver for the Raspberry Pi! At this point, the screen mirroring is working pretty well on any Raspberry Pi I tested (Pi Zero and Pi 3B+). Unfortunately, the FDK AAC decoder library used for decoding the AAC audio signal is running purely on the CPU (the Pi doesn’t have HW acceleration for audio decoding), and the Pi Zero doesn’t seem quite powerful enough to handle networking, video and audio at the same time. That’s why audio is only working smoothly on the Pi 3B+. Update 07-2019: Nevertheless, as of RPiPlay version 1.1, video and audio is working pretty well even on the Pi Zero.

As for the supported sender devices, any iOS device running iOS 9 or newer is supported. From a little research into the AirPlay protocol and its version history (The protocol has evolved far more over time than the recent release of AirPlay 2 would imply), I was able to find that the implemented protocol is considered a legacy protocol by iOS devices running iOS 12. This might mean the current implementation could break with any new iOS release. I added my version history research to the project’s README file.

Contributing
Now that we have a working starting point, I’m hoping for support from the great Raspberry Pi community for improving and maintaining the project. As mentioned above, I’m expecting Apple to break the implementation with any new iOS version. As I’d like to stress, I also only did the port to the Raspberry Pi, all the hard work was done by dsafa22 (huge kudos to him!). Although I’ll give my best to contribute what’s within my limits of ability, I’m hoping for help from enthusiasts more familiar with multimedia programming and reverse-engineering.

In particular, if anyone knows how the NTP clock synchronization can be used to adjust the video scheduler for smooth playback while keeping lag at a reasonable level, please let me know! From StackOverflow, I was able to understand how the round-trip time can be calculated, and this discussion implies the task involves clock stretching, but I’m still rather clueless. Update 07-2019: Implemented in version 1.1.

GitHub Link
The project can be found at https://github.com/FD-/RPiPlay. Build instructions and more information are available there.

I’m looking forward to this becoming a joint project of the fabulous Raspberry Pi community!
Last edited by fd_ on Sun Jul 14, 2019 6:11 pm, edited 2 times in total.

tvjon
Posts: 715
Joined: Mon Jan 07, 2013 9:11 am

Re: New Open Source AirPlay Mirroring Server

Wed Jun 12, 2019 5:26 pm

Thank you kindly for this.

It built just fine, & I've just tested it with photo's from iOS 12.4

Next a video which is also fine, initially audio via HDMI.

Next played another video, but no more audio.

So,

$ ./rpiplay -a analog

& so far a couple of short videos, & audio is fine for both.

Well done!

fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

Re: New Open Source AirPlay Mirroring Server

Fri Jun 28, 2019 12:53 pm

tvjon wrote:
Wed Jun 12, 2019 5:26 pm
Thank you kindly for this.

It built just fine, & I've just tested it with photo's from iOS 12.4

Next a video which is also fine, initially audio via HDMI.

Next played another video, but no more audio.

So,

$ ./rpiplay -a analog

& so far a couple of short videos, & audio is fine for both.

Well done!
Thanks for your feedback! Great to hear someone is using the program!

tvjon
Posts: 715
Joined: Mon Jan 07, 2013 9:11 am

Re: New Open Source AirPlay Mirroring Server

Fri Jun 28, 2019 1:30 pm

fd_ wrote:
Fri Jun 28, 2019 12:53 pm
...Thanks for your feedback! Great to hear someone is using the program!
You're welcome. In fact, I have some more.

I was pondering whether to go to Github, or perhaps you'd prefer feedback here?
Github obviously has mechanism in place for all this, but I suspect more people read the (sub) forums, so more exposure?


I finally have a Pi4 so naturally wanted to test rpiplay.

Can't build it at present ON (actually it's a different GCC, so will have to try same GCC on RPi3) Pi4, as make complains it can't find a dns* header.

Well, as I reported, it built fine on RPi3, so took a closer look at Buster's files.
I see the Buster dns libraries are updated.

I haven't looked at your code much yet, but I'm much happier with C rather than C++.

Anyway I cheated & simply copied your "old" rpiplay libdns to /usr/lib, & you'll be pleased to know, rpiplay works on RPi4 now :)

Thank you again for your efforts on this. It's much more pleasant browsing through my iOS photo's, deciding which to delete, etc., on this big hdmi monitor attached to my Pi, rather than the diminutive iPad mini screen.

Camistotle
Posts: 1
Joined: Sun Jun 30, 2019 12:53 am

Re: New Open Source AirPlay Mirroring Server

Sun Jun 30, 2019 12:57 am

So super noob question, how do I build this? The guide has a few commands but it loses me at “cmake ..”

nauynix
Posts: 1
Joined: Wed Jul 03, 2019 2:39 pm

Re: New AirPlay Mirroring Server (Open Source)

Wed Jul 03, 2019 2:41 pm

Yeah, the ".." in cmake refers to the directory that you copied the github rpiplay from. Hence, you have to git clone *rpiplay url* into a folder, and then cmake that.

I also got rpiplay to work on rpi3, and its wonderful, but I was wondering if theres any way to stream to youtube in the youtube app.

fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

Re: New Open Source AirPlay Mirroring Server

Wed Jul 03, 2019 6:07 pm

tvjon wrote: I was pondering whether to go to Github, or perhaps you'd prefer feedback here?
Github obviously has mechanism in place for all this, but I suspect more people read the (sub) forums, so more exposure?
For minor things I'm fine with either way. For bigger bugs, feature requests or anything else where progress or additional details are to be tracked, it's easier to use GitHub issue reports where all information can be added to the specific issue.
tvjon wrote:I finally have a Pi4 so naturally wanted to test rpiplay.

Can't build it at present ON (actually it's a different GCC, so will have to try same GCC on RPi3) Pi4, as make complains it can't find a dns* header.

Well, as I reported, it built fine on RPi3, so took a closer look at Buster's files.
I see the Buster dns libraries are updated.

I haven't looked at your code much yet, but I'm much happier with C rather than C++.

Anyway I cheated & simply copied your "old" rpiplay libdns to /usr/lib, & you'll be pleased to know, rpiplay works on RPi4 now :)

Thank you again for your efforts on this. It's much more pleasant browsing through my iOS photo's, deciding which to delete, etc., on this big hdmi monitor attached to my Pi, rather than the diminutive iPad mini screen.
I just built RPiPlay in a fresh Buster image on a Pi Zero and it just worked by following the instructions from the Repo. Probably you forgot to run `sudo apt-get install libavahi-compat-libdnssd-dev`?
Camistotle wrote: So super noob question, how do I build this? The guide has a few commands but it loses me at “cmake ..”
You should be able to build by just carefully following the instructions from the GitHub repo. All instructions are to be executed after the Repo has been cloned, from within the project's root folder. I'll try to make that clearer in the instructions.
nauynix wrote: I also got rpiplay to work on rpi3, and its wonderful, but I was wondering if theres any way to stream to youtube in the youtube app.
AirPlay video uses a different protocol that has the iOS device relay the url and information of the (HLS) video it is currently playing to the AirPlay server. The server would then start streaming the video directly from the server (ie Youtube in this case), and the iOS device would act as a remote control for pausing, seeking and so on. From the code base we have already, it shouldn't be too difficult to add the AirPlay video protocol, (the tricky parts are mostly the same as for AirPlay mirroring), it's rather a question of time. I personally don't need the feature, so I'm not going to invest the time to implement it. However, I'd gladly see someone else working on it, and would readily help where I can and provide all information I already have about the protocol.
Until someone adds this protocol, you will have to resort to mirroring your screen while playing the video on your iOS device for the video to appear on RPiPlay. This will not fill the TV screen and won't work 100% smooth though.

fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

Re: New AirPlay Mirroring Server (Open Source)

Sun Jul 14, 2019 6:07 pm

I just published version 1.1 with quite some improvements:
  • Now audio and video work on the Raspberry Pi Zero. Make sure you're not running other CPU-intensive tasks in parallel!
  • Smoother video due to clock syncing
  • Correct lip-sync due to clock syncing
  • Lower latency due to injecting max_dec_frame_buffering into SPS NAL
  • Disabled debug logging by default
  • Added command line flag for debug logging
  • Added command line flag for unsynchronized low-latency mode
  • Bug fixes
Last edited by fd_ on Sun Nov 17, 2019 3:52 pm, edited 1 time in total.

leifdaniel
Posts: 4
Joined: Sat Jul 13, 2019 4:46 am

Re: New AirPlay Mirroring Server (Open Source)

Mon Jul 15, 2019 4:39 am

Thank you, awesome project. Two things:

1. Maybe I'm stupid, but how do you close the program once it's running?

2. It runs on the Pi 4 with both audio and video, but will disconnect and freeze the screen about every 30 seconds.

Any ideas?

fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

Re: New AirPlay Mirroring Server (Open Source)

Mon Jul 15, 2019 10:47 am

leifdaniel wrote:
Mon Jul 15, 2019 4:39 am
Thank you, awesome project. Two things:

1. Maybe I'm stupid, but how do you close the program once it's running?

2. It runs on the Pi 4 with both audio and video, but will disconnect and freeze the screen about every 30 seconds.

Any ideas?
1. Pressing Ctrl+C on the keyboard should quit the program. However, there is a known bug that sometimes leads to the program getting stuck. If you experience that case, the fastest workaround is a reboot.
2. That is strange! What iOS version and device are you using? Does the program print any hint (Please check with the -d debug log flag)?

zeck_do
Posts: 1
Joined: Tue Jul 23, 2019 7:18 pm

Re: New AirPlay Mirroring Server (Open Source)

Tue Jul 23, 2019 7:23 pm

Hi I‘m a noob but what is the activation line in order to activate the AirPlay server?
Greetings

roberthogberg
Posts: 1
Joined: Sat Aug 03, 2019 11:25 am

Re: New AirPlay Mirroring Server (Open Source)

Sat Aug 03, 2019 11:27 am

Does it support AirPlay 2? And can I thereby choose my rpi as one of many outputs?

fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

Re: New AirPlay Mirroring Server (Open Source)

Sun Aug 04, 2019 10:41 am

roberthogberg wrote: Does it support AirPlay 2? And can I thereby choose my rpi as one of many outputs?
AFAICT, it's not even known what AirPlay 2 means for AirPlay mirroring protocol-wise. So no, AirPlay 2 is not supported. For more details on the protocol evolution (or how much about it can be reconstructed from information on the Internet), have a look at the bottom of the README in the GitHub repo.

valentin.dusollier
Posts: 3
Joined: Fri Nov 03, 2017 10:34 am

Re: New AirPlay Mirroring Server (Open Source)

Thu Sep 12, 2019 4:16 pm

Hi,

Very nice project ! It has been years I'm waiting for a solution like that, rplay worked well but in the past...

You said on GitHub : "RPiPlay might not be suitable for remote video playback, as it lacks a dedicated component for that", do you plan to add it to RPiPlay ? That would be very nice cause either on the iOS app or on Safari (youtube.com) remote video playback on Youtube simply don't work for me... The app tells me "Unable to play the video... Something went wrong" and youtube.com just gives up and plays the video like I never use the AirPlay button...

PS : I'm using iOS 13.0 and macOS 10.14.6

fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

Re: New AirPlay Mirroring Server (Open Source)

Thu Sep 12, 2019 4:18 pm

valentin.dusollier wrote:
Thu Sep 12, 2019 4:16 pm
Hi,

Very nice project ! It has been years I'm waiting for a solution like that, rplay worked well but in the past...

You said on GitHub : "RPiPlay might not be suitable for remote video playback, as it lacks a dedicated component for that", do you plan to add it to RPiPlay ? That would be very nice cause either on the iOS app or on Safari (youtube.com) remote video playback on Youtube simply don't work for me... The app tells me "Unable to play the video... Something went wrong" and youtube.com just gives up and plays the video like I never use the AirPlay button...

PS : I'm using iOS 13.0 and macOS 10.14.6
No, I'm not planning to add that feature. But you're very welcome to contribute it ;) https://github.com/FD-/RPiPlay/issues/7

KattyMan06
Posts: 1
Joined: Sun Sep 15, 2019 7:01 pm

Re: New AirPlay Mirroring Server (Open Source)

Sun Sep 15, 2019 7:02 pm

So umm I tried to airplay mirror my iphone and nothing happens on my rpi as in it just stays on the normal rpi home screen

fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

Re: New AirPlay Mirroring Server (Open Source)

Mon Sep 16, 2019 5:47 pm

KattyMan06 wrote:
Sun Sep 15, 2019 7:02 pm
So umm I tried to airplay mirror my iphone and nothing happens on my rpi as in it just stays on the normal rpi home screen
Well, if you want a sound troubleshoot, you need to include much more details about your setup. If you're seeing the same issue as some people have reported on GitHub (eg https://github.com/FD-/RPiPlay/issues/18), updating your system to the newest version could help.

patuso
Posts: 2
Joined: Fri Oct 25, 2019 5:07 am

Re: New AirPlay Mirroring Server (Open Source)

Fri Oct 25, 2019 5:48 am

Hi,

First of all, thank you for this project, it's working beautifully!

I see that it was recently changed such that a black screen appears when there is no connection. Is there a way for nothing to appear instead (so I would see whatever is running behind). In my specific case I'm running magic mirror (https://github.com/MichMich/MagicMirror) and would like that to appear when the connection ends (currently appears when I exit RPiPlay).

I'm a beginner with rpi, but I can navigate on github to the Aug 16 commit ("Show blank screen after connection ended ") and see the changes that were made. If I look for those files on my rpi and revert the changes will I get what I want? Would I need to add anything else, or not revert some of those changes? Or would it be way more complicated than that (in which case I'll try to add a GPIO button to start/exit RPiPlay)?

Thank you!

fd_
Posts: 66
Joined: Thu Oct 25, 2018 7:35 am

Re: New AirPlay Mirroring Server (Open Source)

Fri Oct 25, 2019 8:57 am

patuso wrote:
Fri Oct 25, 2019 5:48 am
Hi,

First of all, thank you for this project, it's working beautifully!

I see that it was recently changed such that a black screen appears when there is no connection. Is there a way for nothing to appear instead (so I would see whatever is running behind). In my specific case I'm running magic mirror (https://github.com/MichMich/MagicMirror) and would like that to appear when the connection ends (currently appears when I exit RPiPlay).

I'm a beginner with rpi, but I can navigate on github to the Aug 16 commit ("Show blank screen after connection ended ") and see the changes that were made. If I look for those files on my rpi and revert the changes will I get what I want? Would I need to add anything else, or not revert some of those changes? Or would it be way more complicated than that (in which case I'll try to add a GPIO button to start/exit RPiPlay)?

Thank you!
You don't need to touch the code. Just run RPiPlay with the -b flag.

patuso
Posts: 2
Joined: Fri Oct 25, 2019 5:07 am

Re: New AirPlay Mirroring Server (Open Source)

Sat Oct 26, 2019 12:04 am

Awesome, thank you, that was easy!
fd_ wrote:
Fri Oct 25, 2019 8:57 am
patuso wrote:
Fri Oct 25, 2019 5:48 am
Hi,

First of all, thank you for this project, it's working beautifully!

I see that it was recently changed such that a black screen appears when there is no connection. Is there a way for nothing to appear instead (so I would see whatever is running behind). In my specific case I'm running magic mirror (https://github.com/MichMich/MagicMirror) and would like that to appear when the connection ends (currently appears when I exit RPiPlay).

I'm a beginner with rpi, but I can navigate on github to the Aug 16 commit ("Show blank screen after connection ended ") and see the changes that were made. If I look for those files on my rpi and revert the changes will I get what I want? Would I need to add anything else, or not revert some of those changes? Or would it be way more complicated than that (in which case I'll try to add a GPIO button to start/exit RPiPlay)?

Thank you!
You don't need to touch the code. Just run RPiPlay with the -b flag.

CostaDelSol
Posts: 1
Joined: Fri Nov 01, 2019 8:32 pm

Re: New AirPlay Mirroring Server (Open Source)

Fri Nov 01, 2019 9:54 pm

Hello!
Thanks for this awesome work! I just discovered your tool and I wanted to use it with OSMC on my Pi 3B+. I use the OSMC November update (i just updated it before to know I was going to need your tool) and after followed your tuto on GitHub, this is the output I have after the cmake command:

[email protected]:/home/osmc/RPiPlay/build# cmake ..
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

Am I missing something? Or is this because I use OSMC?

Thanks a lot!

stevo246
Posts: 2
Joined: Sun Nov 10, 2019 12:58 pm

Re: New AirPlay Mirroring Server (Open Source)

Sun Nov 10, 2019 1:03 pm

Hi,

I am a beginner and need more details for cmake compilation. I have already clone your github folder and install all required packages. What should I do to compile your project on a rasbian pi with Rasbian OS?

Thanks for your help.

stevo246
Posts: 2
Joined: Sun Nov 10, 2019 12:58 pm

Re: New AirPlay Mirroring Server (Open Source)

Sun Nov 10, 2019 7:30 pm

I got it :-)! It works very fine for me with my MacBook Pro and iPhone...

Questions for usage:
1. How can I start the program with specific arguments -n? I can only double click the application to start?!
2. Can I change the black background to another if there is no connection?

Thank you guys...

bls
Posts: 291
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: New AirPlay Mirroring Server (Open Source)

Sun Nov 10, 2019 11:12 pm

This is pretty sweet! Once I installed the pre-reqs, cmake and make worked flawlessly. Thanks!

Nancy10
Posts: 1
Joined: Sat Nov 16, 2019 1:33 pm

Re: New AirPlay Mirroring Server (Open Source)

Sat Nov 16, 2019 1:36 pm

Can anybody compile it to run on a standalone mode ( no need for any external ) libraries. or as a XBCM/Kodi plugin caus that would make it even better

Return to “Other projects”