Repository navigation
Anchor the subtitle prefetch seek on the subtitle axis (#234) - #236
Merged
Merged
Conversation
The forward prefetcher positions with avformat_seek_file(ctx, -1, ...), which leaves the reference stream to av_find_default_stream_index. That score awards +200 to any stream with discard != AVDISCARD_ALL, so until 5.23.10 the subtitle stream won it simply by being the only stream not fully discarded, and the seek was measured on the subtitle axis by accident rather than by intent. #230's pacing stream sits at AVDISCARD_NONKEY, which is not AVDISCARD_ALL, so from 5.23.11 it collected the same +200 and video outranked the subtitle stream 275 to 200. On Matroska the seek then jumps to the cluster holding the last video keyframe, and a landing cue that starts further back than that cluster is behind the read head before the first packet is delivered: never harvested, never decoded, so neither the #143 candidate seed nor the #204 finalize can recover it. MP4 absorbs the same anchor change because mov_read_seek re-seeks every stream individually and backwards, which is why the #230 tests missed it. Pass the anchor explicitly instead, converting the target into that stream's own time base. The #230 park is unchanged. Reported by cmcpherson274, bisected across four releases on identical fixture bytes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01At1agC2qU2Y2MX2BKLdT4N
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.
What broke
5.23.11 regressed the #143 / #204 shape: a seek landing whose only later display set sits beyond the lead window is never shown. Reported by @cmcpherson274 with a bisection across four releases on identical fixture bytes (5.23.10 good, 5.23.11 dark, deterministic 3/3).
Root cause
Positioning, not the park.
The prefetcher seeks with
avformat_seek_file(ctx, -1, ...). A -1 stream index leaves the reference stream toav_find_default_stream_index, whose score awards +200 to any stream withdiscard != AVDISCARD_ALL(libavformat/avformat.c:369).AVDISCARD_ALL, so the subtitle stream was the only one collecting that +200 and won 200 to 75. The target was measured on the subtitle axis and the seek landed on the last cue at or before it.AVDISCARD_NONKEY, which is notAVDISCARD_ALL. Video now scores 275 and wins.On Matroska
matroska_read_seekjumps to the cluster byte position the reference stream's index entry names, so everything in earlier clusters is simply not read: a landing cue that starts further back than that cluster is behind the read head before the first packet arrives. It is never harvested, so neither the #143 candidate seed nor the #204 finalize ever sees it. That matches the reporter'sharvesteddropping 3 to 1 with noapplySubtitleEventat the destination.The reader never asked for the subtitle axis, it inherited it from a discard flag.
Fix
seekBounded(to:anchorStreamIndex:timeout:)takes the anchor explicitly and converts the target into that stream's own time base. The prefetcher passes its lowest subtitle stream index, which is exactly what the score used to elect. The #230 park is untouched.Why the #230 tests did not catch it
They run on MP4.
mov_read_seekre-seeks every stream individually and backwards, so a sparse subtitle track keeps its landing sample whatever the reference is. The container difference is now a test of its own.Verification
Issue234SideReaderSeekAnchorTests, 8 cases on a purpose-built 3.4 KB Matroska fixture (keyframe every second, two cues: landing at 3 s running to 11 s, successor at 12 s, clusters every 5 s, seek to 7.5 s). Covers the libavformat mechanism, the regression at demuxer level, the fix, the mov contrast, the time-base conversion and the anchor edge cases.pacingStreamSkipsTheLandingCuereproduces the reported symptom directly: unpaced the first delivered cue is the 3 s landing, paced it is the 12 s successor.prefetchLoopHarvestsTheLandingCueruns the real prefetch loop: without the anchor the landing never reaches the store, with it both cues do.swift test: 1161 tests / 185 suites green.swift build -Xswiftc -strict-concurrency=completeclean, tvOS SimulatorxcodebuildBUILD SUCCEEDED.Reporter retest still open, so no auto-close keyword.