Repository navigation
Relay: read further ahead, stream in large pieces, keep the Mac awake - #15
Merged
Merged
Conversation
Less buffering when the TV plays through the relay or from a local file. - HLS read-ahead: the next four segments of each playlist, two fetched at once, instead of one. Playlists are tracked separately (demuxed audio has its own); a seek or quality switch drops and cancels what was fetched for the old position. A failed segment stays as a marker so it is not refetched in a loop. Cap raised to 64 MB (16 MB/item), with in-flight fetches reserved against it. - Body read-ahead (ahead.go): any other streamed body (a whole video file, a segment that was not prefetched) is read up to 16 MB past what the TV has taken, so a slow moment at the site is covered. Four responses at a time; a starved TV gets bytes at once, a busy one lets reads fill 128 KB chunks. A paused TV fills the buffer and then back-pressures the site as before. - Copies go in 128 KB pieces instead of the 4 KB the bufio.Reader's WriteTo fell back to. - Keep awake (awake.go): while a relayed cast or a command-line file plays, and up to 30 minutes into a pause, the helper runs /usr/bin/caffeinate -i -w <pid>. The sandbox profile allows exactly that program, fork, signalling its own children, and the power management service; nothing else can be started. With an old profile the exec fails and casting works as before. Tests: TestPrefetchWindow, TestCopyAhead, TestKeepAwake, TestCaffeinate; each fails with its fix removed. Checked by hand under the real profile: caffeinate holds PreventUserIdleSystemSleep, is killed on release, exits by itself when the helper dies, /bin/ls is still refused, and -selftest passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Less buffering when the TV plays through the relay or plays a file from
xcast <file>. Direct casts are unchanged: there the TV fetches from the site itself.Changes
host/prefetch.go)host/ahead.go, new)bufio.Reader.WriteTofalling back to its own buffer size.host/awake.go, new)/usr/bin/caffeinate -i -w <pid>.Sandbox change (
install/xcast.sb)New rules:
process-forkprocess-execof/usr/bin/caffeinateonlysignalto its own children onlymach-lookupofcom.apple.PowerManagement.controlcaffeinate runs inside the same sandbox, and no other program can be started. The worst an attacker could do with this is keep the Mac from idle sleep. Documented in
docs/SECURITY-MODEL.md.With an older installed profile the exec fails, and casting works as before without keep-awake. Run
./install.shto get the new profile.Memory ceiling: 64 MB of prefetched segments plus 4 × 16 MB of body read-ahead.
Tests
TestPrefetchWindow,TestCopyAhead,TestKeepAwake,TestCaffeinate.io.Copy, a 4 KB copy buffer, no hold, and no stale-timer guard.go vet,staticcheck,govulncheckandgo test -raceare clean.PreventUserIdleSystemSleep./bin/lsis still refused.-selftestpasses.Not tested: playback on a real TV. There are no before/after stall numbers yet.
Docs
docs/HOW-IT-WORKS.mdanddocs/SECURITY-MODEL.md.🤖 Generated with Claude Code