Repository navigation
fix(subtitles): bound how far a PGS sidecar reads ahead - #528
Conversation
A PGS subtitle sent as a .sup sidecar (the remux and transcode route) was read from start to finish as soon as it was mounted, and every caption image it decoded stayed in the sample queue until playback reached it. For a feature film that is tens of MB of Java heap; a phone with a 192 MB heap ran out of memory, or stalled at startup, as soon as the track was selected. The sidecar wrapper keeps re-continuing its loader so a sidecar never gates the video. It now leaves the loader parked once its queued cues are more than two minutes past the playhead, and continues it as playback catches up (from the playback ticks) or after a seek. Only the PGS sidecar sets a limit; text sidecars still load in one go. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis 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:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe player factory applies a 120-second lookahead to PGS sidecar subtitles. The sidecar period pauses loading when its buffered position exceeds that limit relative to the playback floor, then resumes when playback catches up. Other subtitle types retain unbounded loading by default. ChangesSidecar subtitle lookahead
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant SiloMediaSourceFactory
participant NonGatingSidecarPeriod
participant Delegate
SiloMediaSourceFactory->>NonGatingSidecarPeriod: Configure the sidecar lookahead
NonGatingSidecarPeriod->>Delegate: Request continuation when within the limit
NonGatingSidecarPeriod->>NonGatingSidecarPeriod: Hold continuation when buffered data exceeds the limit
NonGatingSidecarPeriod->>Delegate: Resume after playback catches up
Merge Risk: ⚪ Minimal · up to The PGS read-ahead bound appears mergeable after normal checks. The investigated track-reselection path does not leave subtitles permanently stalled. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Related issue: N/A
Validation tasks: changes #323 C4; changes #324 C4
When the server sends an embedded PGS subtitle as a
.supsidecar (remux and transcode sessions), the app reads the whole file the moment the track is mounted and keeps every decoded caption image in memory until playback reaches it. For a feature film that is tens of MB of Java heap. On a phone emulator with a 192 MB heap, selecting the English PGS track on a 33 Mbps remux crashed the app with anOutOfMemoryErroron the ExoPlayer playback thread, or left it stuck at startup with the heap at 189 MB. The TV emulator survived the same track at 159 MB, close to the same limit.This change bounds how far a PGS sidecar reads ahead of the playhead, so it holds a few minutes of captions instead of the whole film.
Approach
NonGatingSidecarPeriodkeeps a sidecar out of theMergingMediaSourceloading gate by re-continuing itsProgressiveMediaPeriodevery time it parks at its 1 MiB check interval, with no limit. It now takes an optional read-ahead limit. When the delegate parks and its queued cues are already more than that far past the playhead, the wrapper leaves it parked. It continues the delegate once the playhead closes the gap, checked fromdiscardBuffer(called on the playing period every tick) andreevaluateBuffer. A seek clears the hold and restarts the read as before, and the check is skipped until the delegate has prepared.Only the PGS sidecar sets a limit (two minutes, in
SiloPlayerFactory). Text sidecars still load in one go, so their behaviour does not change. Phone and TV share this code.Validation
SidecarSubtitleMediaSourceTestcases cover holding, resuming from both playback callbacks, seeks, finished and unprepared delegates, and the unlimited text case.:androidApp:assembleDebugand:androidTvApp:assembleDebugpass.Evidence
Evidence: https://evidence.siloserver.org/r/silo-android/pgs-sidecar-memory/
Risks
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Bound PGS sidecar subtitle reads to 120s ahead of playback
maxLookaheadUsparameter toSidecarSubtitleMediaSource, defaulting toC.TIME_UNSET(unbounded). The player factory sets it to 120,000,000 µs for PGS sidecars only.NonGatingSidecarPeriodnow tracks prepared and held-ahead state. When the delegate's buffered position is more than the lookahead past the playback floor, loading kicks are suppressed. The hold clears on seeks, and playback ticks or buffer reevaluations resume loading once the gap closes. Unprepared delegates andC.TIME_END_OF_SOURCEare never held.SiloPlayerFactoryin SiloPlayerFactory.kt if a different lookahead is needed.Macroscope summarized c27bae2.