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 withIdentity::load_or_createor 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) andEvents. One sender → one stream → one output. - Receiver
Builder - Configures a
Receiver. Create one withReceiver::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§
- Audio
Sink - 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._tcpTXT records, matching what shairport-sync advertises in AirPlay 2 mode.gidequalspiwhen the device is not in a group.
Type Aliases§
- Event
Sender - The sending half handed to the library; the host keeps the receiver.
- Sink
Factory - Creates the sink for a stream, invoked at
SETUPphase 2 with the negotiated sample rate and channel count — once per stream.