On Demand fetched by the relay's Mac: playing and keeping
Superseded 2026-11-03. The Swift server (
StationServer,RelayServer,antenna-tower-server,control-room, the Manager's launchd helper and MCP assistant) was replaced by the Go tower intower/(ADR 0005). What follows is history.
Design agreed 2026-10-17. Step 1 (buffer jobs, played from the Mac) is built: see "Built" below. Keeping into Plex is not.
Today a screen plays a provider's file by downloading it itself (read-ahead.md), and "download into Plex" is planned as a separate job on the relay's Mac (vod-relay.md, phase 2). Both are one thing: the Mac fetches a copy from its login. This doc makes them one mechanism.
Why move it:
- One stream per login. A login may allow one stream. Each Apple TV opens its own today; the Mac knows every job and can say which login is busy.
- Room. An Apple TV has little cache space (the "only X GB free" refusal); the Mac mini has plenty.
- Provider quirks in one place. The VPN route, providers that won't send part of a file, and 403s are met once, on the Mac.
- The login stays on the Mac. Today it is on each screen, in the provider's address. This reverses vod-relay.md's "streams don't pass through the Mac mini".
The Mac mini is always on, so it is the default path. The screen's own read-ahead stays as the fallback.
Decisions #
- One fetch job per copy, on the relay's Mac. A job downloads a copy from
its login with one request at a time, moved when the player skips (as
ReadAheadSessiondoes now, with the same runs map). - Two kinds.
- Buffer: started by Play. Held in the buffer folder, the bytes behind the picture let go, deleted when the last screen stops.
- Keep: started by Download. Written whole into the Plex folder on the
NAS under a temporary name, renamed when complete, then Plex is asked to
scan, as vod-relay.md describes. The title gains its
· Plexcopy, first choice from then on, and screens don't read Plex ahead.
- Playing a title being kept is the same job. The screen reads the partial file as it fills. A skip past what has arrived moves the download there; once playback ends, a second pass fills the gaps (the runs map knows which).
- Playback comes first. A keep job on a login pauses when a screen plays
from it, and carries on from what's held afterward. Keep jobs queue one at a
time per login. A screen that falls back to the provider asks the relay (or
IPTVLoad) first, so it doesn't meet a keep job on a one-stream login. - One screen per job, for now. The player's place is whichever reader read
last (
ReadAheadPlayhead). Two screens at different places would pull the one download back and forth. A second screen on the same title gets its own job, or waits: per-screen places are a later change. - The buffer folder is chosen in the Manager. It defaults to a folder on the Mac's own disk, not the NAS: a scratch buffer over SMB is one more way to fail. The Plex folders (movies, TV) are separate, set in the Plex pane.
- Keeping is manual. A Download button on a title's card (and on a series, for the whole show), in the Manager, and over MCP. Titles are not kept because they were watched.
- Fallback is today's read-ahead. No relay, a relay that doesn't answer, or
a job it refuses: the screen downloads for itself as it does now. The relay's
hello says
vodPlay: truewhen it serves jobs, so an older screen or Mac carries on as before.
The protocol #
Same token and client tracking as the planes feed (docs/manager-relay.md). Over the LAN only; the address a screen opens carries a job name, never a login.
| Request | Answer |
|---|---|
POST /v1/vod/jobs (copy, kind) |
Starts or joins a job: its name, the file's length, or why not. |
GET http://<relay>:<port>/<job>.<container> |
The file, ranged, as ReadAheadServer answers VLC now. |
GET /v1/vod/jobs/<job> |
How it stands (held ahead, starved, failed, requests, slow): the screen asks every 2 s. |
DELETE /v1/vod/jobs/<job> |
The screen is done: a buffer is deleted, a keep carries on. |
GET /v1/vod/jobs |
Every job: title, kind, login, bytes held, queued or paused. |
The file isn't a Hummingbird route: VLC can't send the household token, and the read-ahead server already lets go of the read a player left waiting when it hangs up at a skip (a Hummingbird handler waiting on the download wouldn't notice until it next wrote, and would pull the download back to where it was).
In the code #
- Manager side, not RetroLineup.
ReadAheadSessionuses Network andURLSessiondelegates; RetroLineup is Foundation-only and kept Linux-buildable for a NAS CLI. The Manager already runsReadAheadSessionfor its own player, so the job table lives there and reaches the relay through a backend the host passes in (VODBackend, likeRelayAdminBackend).RelayKitgets only the routes and their types. WhatReadAheaddecides (pure) stays in RetroLineup. - Check before building: how
RelayServerserves, since a multi-GB ranged response is not a small JSON answer. Binding the existing loopback server to the LAN, behind the household token, may be the smaller change. - Screens:
OnDemandCatalog.fileasks the relay for a job first and falls back toReadAheadServer.open. The play address is the relay's. - Manager: Relay pane shows the queue (title, login, bytes, paused or waiting,
and the share not being mounted); a buffer folder setting; Storage pane counts
the buffer. MCP:
download_vodand a job list.
Built (2026-10-17): step 1 #
- The request names the file, not its address.
VODJobRequestcarries the login's reference, movie or episode, the id and the container, and a job name (a UUID) the screen picks. The Mac builds the address from its own copy of the login (XtreamAPI.fileURL). The id and container must be letters and digits. - The Mac (
VODJobs, Sources/Shared/Channels/OnDemand/VODJobs.swift) opens aReadAheadSessiononReadAheadServer.relay, the same server as the screens' own but listening on the home network, not the loopback. Its folder is the one the Manager's own read-ahead uses; clearing it in the Storage pane leaves the jobs' folders alone. - The job's name is its only key, in the address VLC opens.
- Ended without being told: a job the player never reached in 45 s (the screen gave up on the answer and downloads it itself), or one the screen hasn't asked after for 2 minutes (a screen put away may leave VLC's connection open). A DELETE for a job still opening closes it once it opens.
- The screen (
OnDemandCatalog.fetched) asks first when the relay's hello saysvodPlay, for the files VLC plays (MKV, AVI). No answer in 30 s, or a refusal: it sends a DELETE for the name and downloads it itself, and says so in a warning.RelayReadAheadasks after the job every 2 s, so the loading screen ("DOWNLOADING ON MAC MINI"), held-ahead and the slow-load report work as before; five missed answers in a row and it's taken as lost. - The relay's own Mac reads ahead for itself as before.
Not yet: Keep jobs, the per-login queue, the Relay pane's list (the route is there), MCP, and a play job counted against its login's streams.
Order #
- Know why it sticks first. The loading report now ends with
requests N(how many requests VLC made of the screen's own server), and the app restarts that server on return from the background. A stuck load withrequests 0never reached the server; with more, VLC connected and stopped by itself, which moving the download to the Mac would not cure. - Job table and play route on the Manager; screens opt in; one title tried.
- The Plex write path: the share checked and remounted, temporary name and rename, queue per login, section scan.
- Play while keeping, and the second pass.
- The UI: Download on the card, the Relay pane queue, MCP.
Risks #
- The Mac asleep or restarted. The fallback is not optional.
- The Mac's disk. Up to
ReadAhead.cap(8 GB) held per title, times screens. - A skip during a keep. The single stream moves, so the whole file arrives later; the second pass has to be tested with real skips.
- The Mac's route to the provider (a VPN,
NetworkRoute) is now the one that matters, not the screen's. - Untested on real failures, as the copy change in vod-relay.md still is.
Open #
- Per-screen places, so two screens can share one job.
- The cap and the reserve for the buffer, when the folder is chosen.
- What a screen shows while a keep job holds its login ("STRONG IS BUSY DOWNLOADING").
Too slow #
The screen sends the title's running time with the job (seconds, when it
knows it; for a movie it doesn't time, the tower asks the provider). With it the
tower knows how fast the file has to come: its size over its running time. Once
a job has been downloading 15 s, it is judged every look by the provider's rate
over the latest 20 s: when what's still missing from the player's place to the
end would take longer to bring than the picture takes to play, the job is
slow (said once, and kept). The look also carries mb_per_s and
needs_mb_per_s. A screen that sees slow moves to the title's next copy,
from the same place; with no other copy it carries on, and its own stall watch
still offers to buffer ahead.
Phin Tech docs
Rabbit Ears Manager in the store →