Skip to main content

Crate openairplay2

Crate openairplay2 

Source
Expand description

An embeddable AirPlay 2 audio receiver: a real Mac/iPhone discovers it, pairs with it, and streams to it; the host application gets decoded PCM and session events. The library owns network → PCM (discovery advertisement, transient pairing, the encrypted control channel, the buffered-audio channel, decrypt, AAC decode, and the pause/seek/ backpressure semantics); the host owns PCM → speaker via an AudioSink.

Deliberate scope: one sender → one stream → one output. No PTP — for a single output, the sender’s buffering plus this library’s backpressure suffice (blocking AudioSink::write paces playback). No AirPlay wire concepts (plists, shk, sequence numbers) appear in this API.

use openairplay2::{AudioSink, Event, Receiver};

struct MySink;

impl AudioSink for MySink {
    fn write(&mut self, pcm: &[i16]) { /* blocking write paces playback */ }
    fn flush(&mut self) { /* seek: drop device/prebuffer state */ }
}

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let receiver = Receiver::builder()
        .name("Office")
        .identity_path("/var/lib/myapp/airplay-identity")
        .build()?;
    let (events, mut rx) = tokio::sync::mpsc::unbounded_channel();
    tokio::spawn(async move {
        while let Some(event) = rx.recv().await {
            if let Event::Volume { db } = event { /* your gain path */ }
        }
    });
    receiver.run(|_rate, _channels| Box::new(MySink), events).await
}

Structs§

Config
Receiver-wide configuration, resolved by ReceiverBuilder::build.
Identity
The receiver’s stable device identity: an Ed25519 keypair (the AirPlay pk) and a public-identifier UUID (pi). Senders remember a receiver by these, so they must not change across restarts — persist with Identity::load_or_create or store them yourself.
Receiver
An AirPlay 2 audio receiver: senders discover it, pair with it, and stream to it; the host gets decoded PCM (via its AudioSink) and Events. One sender → one stream → one output.
ReceiverBuilder
Configures a Receiver. Create one with Receiver::builder.

Enums§

Event
What the host needs to know about the streaming session. Transport control (pause, seek) is already handled inside the library — those variants are informational.

Traits§

AudioSink
Where decoded audio goes. Implemented by the host (the receiver binary’s sink is ALSA), called from a dedicated library-managed playback thread.

Functions§

txt_records
The _airplay._tcp TXT records, matching what shairport-sync advertises in AirPlay 2 mode. gid equals pi when the device is not in a group.

Type Aliases§

EventSender
The sending half handed to the library; the host keeps the receiver.
SinkFactory
Creates the sink for a stream, invoked at SETUP phase 2 with the negotiated sample rate and channel count — once per stream.