# AirPlay v0.1.0 - Table of Contents

> A pure-Elixir AirPlay (RAOP) audio sender: discover receivers and stream lossless ALAC audio to them — no native dependencies.

## Pages

- [AirPlay](readme.md)

## Modules

- AirPlay 1 (RAOP)
  - [AirPlay](AirPlay.md): A pure-Elixir **AirPlay (RAOP) audio sender** — discover receivers on the LAN and
stream lossless audio to them, with no native dependencies (just `:crypto`,
`:gen_udp` and `:gen_tcp`).
  - [AirPlay.Alac](AirPlay.Alac.md): Pack PCM into **uncompressed** ALAC frames for AirPlay/RAOP.
  - [AirPlay.Cast](AirPlay.Cast.md): Play a PCM buffer to an AirPlay/RAOP receiver, end to end — a small session
GenServer exposing `play/3`, `stop/1`, `set_volume/2`.
  - [AirPlay.Discovery](AirPlay.Discovery.md): Discover AirPlay/RAOP receivers on the LAN via **mDNS** (multicast DNS,
`224.0.0.251:5353`) — the Bonjour service browse Apple devices use. Queries the
`_raop._tcp.local` service and resolves each instance's SRV (host/port) + A
(address) from the responses.
  - [AirPlay.Ntp](AirPlay.Ntp.md): NTP 64-bit timestamps for the AirPlay/RAOP timing channel.
  - [AirPlay.Player](AirPlay.Player.md): Streams ALAC-over-RTP audio to an AirPlay/RAOP receiver after the RTSP
handshake. Owns three UDP sockets
  - [AirPlay.Rtp](AirPlay.Rtp.md): RAOP packet builders: audio (PT 0x60), control `sync` (0xd4), and timing
response (0xd3). All multi-byte fields are big-endian.

  - [AirPlay.Rtsp](AirPlay.Rtsp.md): Minimal RTSP/1.0 client for the AirPlay/RAOP control plane.
  - [AirPlay.Session](AirPlay.Session.md): Drives the AirPlay/RAOP control handshake against a receiver.
  - [AirPlay.Source](AirPlay.Source.md): Decode a library track to the PCM format AirPlay/RAOP wants: 44.1 kHz, 16-bit,
stereo, little-endian, via `ffmpeg`. Returns the raw interleaved s16le bytes,
which `AirPlay.Alac` chops into 352-sample frames.

- AirPlay 2 (experimental)
  - [AirPlay.V2.Crypto](AirPlay.V2.Crypto.md): Crypto primitives for AirPlay 2 pairing + the encrypted channel, mapping the
AirPlay 2 scheme onto Erlang `:crypto`
  - [AirPlay.V2.Pairing](AirPlay.V2.Pairing.md): AirPlay 2 **transient** pairing over RTSP (`/pair-setup`), porting
`AirPlayClientV2.PairSetup1/PairSetup2`. No PIN / Apple account:
SRP-6a with username `"Pair-Setup"`, password `"3939"`. On success the SRP
session key keys the ChaCha20-Poly1305 control + audio channel.
  - [AirPlay.V2.Plist](AirPlay.V2.Plist.md): Minimal Apple binary property list (`bplist00`) codec for AirPlay 2 — enough for
the `/info` response and the `/setup` request body.
  - [AirPlay.V2.Ptp](AirPlay.V2.Ptp.md): Minimal IEEE-1588v2 (PTP) **grandmaster** for AirPlay 2 — the timing gate for
HomePods. HomePods negotiate `timingProtocol:"PTP"` and schedule
playback against a PTP network clock; we advertise ourselves as the grandmaster
so the receiver slaves to our clock, then `SETRATEANCHORTIME` references a real
time on this clock.
  - [AirPlay.V2.Rtsp2](AirPlay.V2.Rtsp2.md): Encrypted RTSP/1.0 over a paired AirPlay 2 connection. After
`AirPlay.V2.Pairing`, the whole RTSP message (request line + headers + body)
is wrapped through `AirPlay.V2.SecureChannel` (ChaCha20-Poly1305 block
framing); responses are decrypted and parsed the same way. Mirrors
`RTSPClientV2.Request`. Verified live against a real AirPlay 2
device (encrypted GET /info → decrypted 200 OK).

  - [AirPlay.V2.SecureChannel](AirPlay.V2.SecureChannel.md): The encrypted RTSP control channel used after AirPlay 2 pairing — a port of
`EncryptionContext`. Once paired, every RTSP message is wrapped:
split into ≤1024-byte blocks, each emitted as
`[len:u16-le][ciphertext][tag:16]`, ChaCha20-Poly1305 with a 12-byte nonce
`<<0::32, counter::little-64>>` (separate write/read counters) and AAD = the
2-byte length prefix.
  - [AirPlay.V2.Setup](AirPlay.V2.Setup.md): AirPlay 2 stream setup over the encrypted RTSP channel, porting
`SetupAirPlay2Session` / `SetupAirPlay2Stream`
  - [AirPlay.V2.Srp](AirPlay.V2.Srp.md): SRP-6a client for AirPlay 2 transient pairing, byte-exact to
the AirPlay 2 SRP-6a parameters.
  - [AirPlay.V2.TLV](AirPlay.V2.TLV.md): TLV8 encoding for AirPlay 2 / HomeKit pairing (`/pair-setup`, `/pair-verify`).

