Repository navigation
fix(playback): demux a subtitle window the file's index can't read in time - #4272
Conversation
… time A window with a duration now waits at most 10 seconds for the kept track or the file's index, then demuxes the source, which streams cues as it goes. On storage where each random read costs about a second, reading one 600-second window through the index took minutes, so the web player gave up after 30 seconds with nothing. A PGS window that gave up this way warms the cached .sup with a demux instead of reading the whole track through the index, whose random reads starved the playback stream reading the same file. Windows open to the end and tracks only the index can read keep waiting as before. Closes #4199 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 25 seconds. View limit details
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Closes #4199
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A, Android N/A, Roku N/A (server-side fix; a client that requests subtitle windows gets it without a change)
With an embedded PGS subtitle selected, the web player stalls on large files that sit on storage where a random read is slow, such as a FUSE mount of remote storage with a local read cache. Subtitle windows come back empty after 30 seconds, and the video stutters or never starts.
A 600-second subtitle window was read through the file's index: one random read per cue, about 200 cues per window, with nothing written to the response until every read finished. At about a second per read that takes minutes. The web player gives up on a window that sends nothing for 30 seconds. The background warm that followed then read every cue of the whole track the same way, and those random reads starved the playback stream reading the same file.
This change gives a window with a duration 10 seconds to come from the kept track or the index. After that the window is demuxed with FFmpeg, which reads the file in order and streams cues as it goes. A PGS window that gave up this way warms the cached
.supwith a demux too, instead of reading the whole track through the index. On storage with fast random reads nothing changes: a window still reads in well under a second.Approach
SubtitleCache.windowbounds the read withcontext.WithTimeoutCause, so only its own 10-second bound counts as slow; a client that leaves is handled as before.serveWindowedSUPwarms withdemuxAndKeepwhen the window gave up on that bound, and withsourcedotherwise, as before. The demux keeps the track, so later windows come from the kept track and don't touch the source's index.S_TEXT/WEBVTT, which have no demux to fall back to), and on-demand HLS rendition windows, which don't go through the subtitle cache.docs/architecture/embedded-subtitle-index.mddescribes the bound.Validation
Reproduced live on an isolated sandbox at
9d432cf09(currentmain): direct play of a 7.3 GB, 40 Mbit/s H.264 file with a PGS track, its library on a FUSE mount that models remote storage with a read cache (a cold random read about 0.8 s, sequential reads about 30-40 MB/s, shared bandwidth, fetched blocks cached). A client that behaves like the web player (30-second stall timeout, the player's retry backoff) and reads the media stream ran for 150 seconds from a cold state, alternating builds:mainOn
mainthe server log shows the same sequence as the report: the first window answered 200 with 0 bytes after 35 seconds, the warm started at that moment, and 90 seconds later it gave way withkeptsub: the track is still being readwhile the modelled storage had pulled about 4 GB through hundreds of random-read streams. With the fix the warm starts 10 seconds after the window request and the storage settles to one or two sequential streams.A window for a seek, sent 60 seconds in while the warm was still reading the file, sent its first byte 20 seconds after the request with the fix and nothing in 30 seconds on
main.A new test fails on
mainwith an empty response at the client's 30-second mark and passes with the fix; it also covers the index-only exemption.Go build, vet, gofmt,
go mod tidy -diff,make lint-changed,make lint-router-recovery,make verify-local-pathsandmake verify-size-ratchetpass.make test-gopasses exceptTestCopyRemuxSubtitleRenditionRealFFmpegandTestRunStatsWithRealFFmpeg, which fail the same way onmainwith the test host's FFmpeg 6.1. Database-backed tests were skipped; the change touches no database code. Web and contract checks don't apply; nothing underweb/orcontracts/changed.The browser itself wasn't driven: the measurements come from the API client above and the server log.
Evidence: https://evidence.siloserver.org/r/silo-server/issue-4199/
Risks
Checklist
Follow-ups
maina whole-track PGS request on the same setup got nothing for four attempts while the playback stream received 46 seconds of video in 120. This change leaves that path alone; a separate fix follows.AI Disclosure
🤖 Generated with Claude Code
Note
Fix slow embedded-subtitle window reads by falling back to demux after 10s
subtitleWindowIndexWait(10 seconds) before giving up, tracked via a newerrSlowWindowReadsentinel in subtitle_source.goSubtitleCache.serveWindowedSUPin subtitle_cache.go falls through to extraction and warms the cached track withdemuxAndKeepinstead of reading the whole track through the indexserveWindowFromSourcenow propagate to the callerSubtitleCache.windownow returns a packet-and-error pair instead of packet only; callers must handle the error resultMacroscope summarized 5c31510.