v0.56.0: Connect to AirPlay — stream to AirPlay speakers via pyatv

Every song is decoded by the ffmpeg CLI and streamed over RAOP, so ALAC
and AIFF play too (only FairPlay is refused). pyatv has no pause or seek
for RAOP, so both restart the stream at the heard position. The picker
lists every AirPlay device on the network, greyed with the reason when
LinTunes can't stream to it (video-only TVs, PIN pairing). Casting and
AirPlay are mutually exclusive; the visualizer tile shows the AirPlay glyph
and a click there stops it. Needs: pip install -e . (adds pyatv).
This commit is contained in:
2026-10-15 16:01:08 -07:00
parent 00aa5e7f2e
commit c1aee48b8b
16 changed files with 1647 additions and 34 deletions
+33 -1
View File
@@ -115,7 +115,7 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
finish/skip/stop/quit; the artist/album snapshot outlives a delete or
retag. Under 5 s is noise and never written. Only while the synced pref
`wrapped.track_history` is on: `Player.listen_ended` → `MainWindow` (adds
`src` desktop/cast and `ctx`, which it latches at `track_changed` because
`src` desktop/cast/airplay and `ctx`, which it latches at `track_changed` because
`_now_playing_context` moves before the old listen closes) →
`LibraryManager.record_listen`, flushed with the journal. The Rabbit writes
the same lines (`History.java`) only when sync put `"history": true` in its
@@ -808,6 +808,38 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
a 500 ms poll of `adjusted_current_time` (only trusted while PLAYING — it
creeps while paused).
- **`lintunes/airplay/`** — AirPlay playback (Connections → Connect to
AirPlay…, Round 87), via **pyatv**'s RAOP streaming and the opposite model
to `cast/`: an AirPlay speaker is *sent* PCM in real time, so every song is
decoded by the `ffmpeg` CLI (`stream.py`) and pyatv packetizes it — ALAC and
AIFF play here, only FairPlay is refused. pyatv's own sources don't fit
(its file path is miniaudio, no AAC/ALAC; its pipe path reports duration 0
and guesses the WAV header), so `stream.install_shim` patches the
`open_source` name in `pyatv.protocols.raop` to answer a `PcmRequest` with
an `FfmpegSource` at the negotiated rate. ffmpeg emits **big-endian**
(`s16be`): pyatv byteswaps its own little-endian samples, and the shim's
output is byte-identical to pyatv's `FileSource`. pyatv has **no pause or
seek** for RAOP (its pause *is* stop), so `AirPlaySink` runs one
`stream_file` per stretch of playback and pause/seek/resume start a new one
at `-ss`; each start bumps a generation, so a replaced stream can't report
"finished" and advance the queue. **A closed connection makes pyatv
*return*, not raise** — "the song ended" is only ffmpeg's EOF
(`outcome_of`), anything else is a lost speaker. Position is what's
*heard*: frames read minus the receiver's `22050 + rate` frames of latency
(~1.5 s, `support.heard_ms`). Volume: the slider's level through Qt's
log→linear curve, then that dB on pyatv's −30..0 scale
(`level_to_percent`), applied before each stream starts. Everything pyatv
runs on one `AsyncLoop` thread; results come back as Qt signals.
Discovery repeats `pyatv.scan` while the picker is open and lists *every*
AirPlay device, greyed with the reason when it can't be used (video-only
TVs/projectors have no RAOP; PIN pairing and passwords aren't built), in
`gui/cast_dialog.DevicePickerDialog`, which `ChromecastDialog` shares.
Connects go **RAOP-only** (`controller.raop_only`). Casting and AirPlay are
mutually exclusive (MainWindow disconnects the other first); the visualizer
tile shows the sink's `glyph`. Testing streams against **pyatv's own fake
receiver** (`tests/fake_device/raop.py` in its sdist, bound to 127.0.0.1) —
never a real speaker unless trav says so.
## Conventions & gotchas
- **The Rabbit R1's screen is not what the internet says.** Measured: