Skip to content

amosarbiv-work/airplay2-receiver

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Experimental

Very quick python implementation of AP2 protocol using minimal multi-room features. For now it implements:

  • HomeKit transient pairing (SRP/Curve25519/ChaCha20-Poly1305)
  • HomeKit non-transient pairing
  • FairPlay (v3) authentication
  • Receiving of both REALTIME and BUFFERED Airplay2 audio streams
  • Airplay2 Service publication
  • Decoding of all Airplay2 supported CODECs: ALAC, AAC, OPUS, PCM. Ref: here and here
  • Output latency compensation for sync with other Airplay receivers

For now it does not implement:

  • MFi Authentication / FairPlay v2 (one of them is required by iTunes/Windows)
  • Audio Sync

This code is experimental. This receiver do not expect to be a real receiver but a toolbox for learning/debugging all airplay protocols and related pairing/authentication methods.

Latest additions:

  • Implement RTP buffer (manage FLUSHBUFFERED) : play/pause/timeline/playlist

Next steps:

  • PTP (Precision Time Protocol)
  • Remove all os specific code (Soft Volume management)
  • Sender (branch-sender) - Implementation
  • Implement RSA Authentication
  • Raspbian package
  • DACP/(+MRP?) Support
  • FairPlay v2 Support

Raspberry Pi 4

Install docker and then build the image:

docker build -f docker/Dockerfile -t ap2-receiver .

To run the receiver:

docker run -it --rm --device /dev/snd --net host ap2-receiver --volume `pwd`/pairings/:/airplay2/pairings/

Default network device is wlan0, you can change this with AP2IFACE env variable:

docker run -it --rm --device /dev/snd --env AP2IFACE=eth0 --net host ap2-receiver

Docker Compose

Example Docker Compose

cat << EOF > docker-compose.yaml

version: '3.8'
services:
 ap2:
   restart: unless-stopped
   network_mode: host
   build: .
   # In case we change from host mode and need to map ports.
   # ports:
     # - "7000:7000"
     # - "10000-10100:10000-10100/udp"
   volumes:
     - ./pairings:/airplay2/pairings/
   # devices:
   #  - "/dev/snd"
   environment: # All variables are optional.
     - AP2HOSTNAME=Airplay2
     - AP2IFACE=eth0
     - NO_VOLUME_MANAGEMENT=true
EOF

docker-compose up

Debian

sudo apt install -y libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libswresample-dev libavfilter-dev portaudio19-dev python3 python3-pip python3-pyaudio build-essential pkg-config git alsa-utils
git clone https://github.com/openairplay/airplay2-receiver.git
cd airplay2-receiver/
pip3 install virtualenv
virtualenv airplay2-receiver
cd airplay2-receiver/
pip3 install -r requirements.txt
pip3 install pyaudio

macOS Catalina

To run the receiver please use Python 3 and do the following:

  • Run the following commands
brew install python3
brew install portaudio
virtualenv -p /usr/local/bin/python3 proto
source proto/bin/activate
pip install -r requirements.txt
pip install --global-option=build_ext --global-option="-I/usr/local/Cellar/portaudio/19.6.0/include" --global-option="-L/usr/local/Cellar/portaudio/19.6.0/lib" pyaudio


python ap2-receiver.py -m myap2 --netiface=en0

Windows

To run the receiver please use Python 3 and do the following:

  • Run the following commands
cd [WHERE_YOU_CLONED_AIRPLAY2_RECEIVER]
virtualenv airplay2-receiver
cd airplay2-receiver
.\Scripts\activate
pip install -r requirements.txt
pip install pipwin pycaw
pipwin install pyaudio

python ap2-receiver.py -m myap2 -n [YOUR_INTERFACE_GUID] (looks like this for instance {02681AC0-AD52-4E15-9BD6-8C6A08C4F836} )
  • the AirPlay 2 receiver is announced as myap2.

Tested on Python 3.7.5 / macOS 10.15.2 with iPhone X 13.3 and Raspberry Pi 4

Protocol notes

https://emanuelecozzi.net/docs/airplay2

About

AirPlay 2 Receiver - Python implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.1%
  • Other 0.9%