Repository navigation
Conversation
…s first The start gate counted packets as runway, so it could open before the video decoder had produced anything — a cold VideoToolbox session after app launch takes that long. Audio then played over a frozen picture, and the late video frames were shown as fast as they decoded until they caught up with the clock. The gate now also waits for every active lane to have a frame at its renderer, and anchors the clock at the latest lane's first frame, so a live TS joined mid-GOP (video waiting for its first keyframe) starts where the picture does instead of under audio alone. A lane that cannot buffer more, or every lane at EOF, still lets the clock start; a failed decoder marks its lane EOF and leaves the gate. Demux EOF ends the buffering, not the wait for a first frame. Co-Authored-By: Claude <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.
Problem
Reported from Lume: sometimes the audio plays immediately while the video is frozen, then the video "rushes" (fast-forwards) for a few seconds until it matches the sound. It happens most on the first channel after launching the app.
PlayerSession's start gate (allLanesReady) counts undecoded packets as runway. So the video lane could count as ready before its decoder had produced a single frame. On the first start after launch, VideoToolbox is still initialising, which takes a while. The clock started anyway:A related case: a live TS joined mid-GOP delivers its first video keyframe a second or two after the first audio. The clock was anchored at the audio's start, so the picture stayed empty for that stretch.
Fix
In
evaluatePlayback, the start condition is now: the buffer is ready and every active lane has a frame at its renderer (presentableStart). The clock is anchored at the latest lane's first enqueued PTS when that is ahead of the clock. The audio before it is dropped by the renderer as late.Escape hatches, so the gate can't wedge:
anyLaneFull): if one lane can't buffer more, waiting for another lane's first frame would only park the demuxer, so the clock starts. A video lane that never decodes is the stall watchdog's to report.Demux EOF now ends only the buffering, not the wait for a first frame. The decoders still hold what was read, and they drain to EOF on demux EOF.
A rebuffer mid-play and a keyframe-backward seek landing are unaffected: in both, the first PTS is behind the clock, so the clock is not re-anchored.
The rule is recorded among the key invariants in
AGENTS.md.Tests
videolate.ts: a TS whose video starts 2 s after its audio. New teststartsAtFirstPresentableFrameuses it withbufferTarget = 0.mainit fails three ways: the clock runs before any video frame, from the audio's start, at position ≈ 0.LIBDISPATCH_COOPERATIVE_POOL_STRICT=1 swift test: 284 of 285 pass. The one failure is "every decode path delivers the stream's HDR10 and HDR10+ metadata" (hardware path), which fails the same way on unmodifiedmainon this machine.startup=[…]from a cold launch should show the first frame shown no earlier than video's first frame.🤖 Generated with Claude Code