Expand description
An embeddable AirPlay 1 (RAOP / AirTunes) audio receiver: stock
Apple senders (iPhone, iPad, Mac, iTunes) discover it, handshake with
it, and stream ALAC to it; the host application gets decoded PCM and
session events. The library owns network → PCM (discovery advertisement,
the RTSP handshake with Apple-Challenge, the three RTP channels,
decrypt, the jitter buffer with retransmits, the NTP clock model, ALAC
decode, and the prebuffer/latency-correct start); the host owns PCM →
speaker via an AudioSink.
Deliberate scope: one sender → one stream → one output. No AirPlay wire concepts (RTSP, SDP, RTP, sequence numbers) appear in this API.
use openairplay1::{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 state */ }
}
#[tokio::main]
async fn main() -> std::io::Result<()> {
let receiver = Receiver::builder().name("Office").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. Shared by the RTSP server and the mDNS advertisement: the MAC address must be the same in both places — clients verify theApple-Responsesignature against the MAC embedded in the service name. - Receiver
- An AirPlay 1 (RAOP) audio receiver: senders discover it, handshake with
it, and stream ALAC 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 handling (FLUSH) is already done inside the library — that variant is 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 - TXT records matching what shairport-sync advertises in classic
(AirPlay 1) mode: ALAC or PCM (
cn), optional RSA encryption (et), 44100/16/2 audio, no password.
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
SETUPwith the negotiated sample rate and channel count — once per stream.