Skip to content

Presented frame drifts ~6 s ahead of currentTime/sourceTime after a rapid bidirectional seek burst (loopback-HLS native path) — frameAhead/producerShift/hostShift all report 0 #65

Closed

Description

@rrgomes

Filing as the Watch Together consumer that just adopted isSeeking/seekTarget (#42/#38 — working well for us, thanks). Seen on 3.13.4, tvOS 26, native loopback-HLS direct play (H.264 title with a PGS subtitle track).

Symptom. After a rapid bidirectional seek/scrub burst, the engine settles into a state where the frame on screen is ~6 s ahead, in source content, of what currentTime and clock.sourceTime report — and it stays there (persists through a pause; does not reconcile). Hosts read currentTime for the scrubber and sourceTime for the subtitle clock, so the timeline and subtitles both trail the picture by ~6 s.

Frame-exact verified: with playback paused, opening the same file in IINA and stepping to the exact frame on screen read ~6 s later than the engine's reported position (not an eyeball estimate).

The engine's coherence metrics did not reflect it. At that moment, reading the public accessors:

currentTime=181.50  sourceTime≈181.5  avpClock=181.58  frameAhead=0.000  producerShift=0.000  hostShift=0.000

currentTime ≈ avpClock, and frameAhead = producerShift − hostShift = 0 — so the engine believed it was fully coherent while the presented content was ~6 s further along. (avBufAhead was ~6.5 s per the memprobe — suggestive, but I won't over-read it.)

Trigger / repro. Hit via a two-peer "dueling scrub" — both peers scrubbing opposite directions, ~10 seek(to:) on one engine within a few seconds. The seek pattern (rapid alternating-direction seeks on the loopback-HLS native path) should reproduce solo — like the #49 seektest harness but alternating direction rather than monotonic. Looks like a sibling of #49 (closed) where the divergence lands between the presented source content and currentTime, with the shift accounting reading 0.

Hypothesis (low confidence — you know the internals): the producer's source-PTS → playlist-time mapping drifts by ~6 s under the alternating-direction burst, but the shift used to derive currentTime/sourceTime settles back to 0 without capturing the offset — so AVPlayer faithfully presents the playlist position whose bytes are ~6 s of source ahead of the reported clock.

Happy to help: I can capture an on-device trace pairing avpClock/currentTime/frameAhead against an IINA-frame-matched ground truth, and run any specific seek pattern you'd like.

Activity

  1. added a commit that references this issue on Jun 24, 2026
  2. superuser404notfound commented on Jun 24, 2026

    @superuser404notfound
    Owner

    Thanks for the precise report, and the frame-exact IINA cross-check is exactly what makes this actionable.

    Traced it to the loopback-HLS shift fold. Where I have landed:

    • Live defers a producer shift change by appending a (seamOutputSeconds, newShift) seam to a history, then folds currentTime/sourceTime with "newest seam at or before the raw AVPlayer clock", so bytes buffered under the old shift keep folding with the old shift until the playhead crosses the seam.
    • The VOD scrub path has no such history. Every producer restart routes through onPlaylistShiftChanged, which collapses the seam history to a single (-inf, newShift) baseline, so the fold degenerates to the latest scalar shift. The seam-append path is gated if isLive in the producer, so VOD never records one.
    • A VOD seek does not flush AVPlayer's buffer (bare seek(to:), no replaceCurrentItem), and loopback segment URLs are index-stable with a byte-deterministic init.mp4. So after a bidirectional burst, AVPlayer can keep presenting buffered bytes that a superseded producer epoch muxed under a different shift, while the fold uses the latest scalar. That matches your trace: picture ~6 s ahead, with frameAhead/producerShift/hostShift all 0 (they only compare the settled producer shift against the host scalar, which are equal by construction, with no per-buffered-segment memory), and avBufAhead roughly equal to the shift delta.

    Two candidate roots produce that same avBufAhead == offset signature, and I cannot separate them from source alone because they need different fixes:

    • Root A: the per-restart producer shift actually VARIES across the burst (a seek lands off the planned keyframe, or the uniform-fallback segment plan kicks in), so the buffered old-epoch bytes fold with the wrong shift. Fix: port the live seam-history to shift-changing VOD restarts.
    • Root B: the per-restart shift is invariant and the ~6 s comes from the loopback playlist startSeconds disagreeing with the restarted segment's tfdt. A seam port would not address this; it needs a buffer flush or segment URL re-key on a shift-changing restart.

    To tell them apart I pushed instrumentation in ee0238c. If you can pin to that (or newer) and capture one dueling-scrub burst with engine logging on, two log families settle it:

    1. [AetherEngine] #65 VOD shift published: <s>s (prev <s>s, delta <s>s, changed=YES/no) ... avBufAhead=<s>s, alongside the producer's existing [HLSSegmentProducer] video gate open: ... shift=<ticks>. Two distinct shift values across the burst means Root A; an invariant shift means Root B.
    2. The 30 s memprobe line now also carries frameAhead= prodShift= hostShift= seams= avBufAhead=. At the divergent moment I expect seams=1 (the degenerate VOD history) with a multi-second avBufAhead while the three shift numbers read 0.

    If a headless macOS repro is easier on your side, aetherctl seektest <file> --seeks 40 --gap-ms 60 now runs the alternating burst and prints a Root A / Root B / inconclusive verdict from those same logs. It flags short, fully-produced files as inconclusive, since the cascade only fires when a seek lands beyond the producer write head, so it wants a longer title.

    Once we know which root, the fix is straightforward. Thanks again.

  3. rrgomes commented on Jun 25, 2026

    @rrgomes
    ContributorAuthor

    Captured on 4.0.2, tvOS 26. Source: a ~2h 4K HEVC title, ~52 Mbps, TrueHD audio (so it bridges through the engine and plays via the loopback-HLS path), direct-played. Solo alternating forward/back scrub burst (~12 seeks). Verdict: Root B (invariant shift).

    #65 VOD shift published — always 0, never changes across the burst:

    #65 VOD shift published: 0.000s (prev 0.000s, delta 0.000s, changed=no) seams->1 rawClock=0.00s  avBufAhead=0.00s
    #65 VOD shift published: 0.000s (prev 0.000s, delta 0.000s, changed=no) seams->1 rawClock=91.10s avBufAhead=3.01s
    

    Every [HLSSegmentProducer] video gate open in the burst is shift=0 too. The memprobe at the divergent moment is the Root B signature you predicted — seams=1, a multi-second avBufAhead, and all three shift numbers reading 0:

    memprobe t=90s … avBufAhead=6.5s avBufBehind=31.5s frameAhead=0.00s prodShift=0.00s hostShift=0.00s seams=1
    

    So it's the invariant-shift / playlist-startSeconds-vs-restarted-tfdt case, not a varying per-restart shift — the seam-history port wouldn't address it.

    One extra data point: on this feature-length, high-bitrate title the divergence cascaded into a full producer stall. After the burst, memprobe pktTotal / avioFetchedMB / muxBytesMB froze identical and avBufAhead stuck at ~1.6 s, playback frozen on screen:

    memprobe t=150s … pktTotal=426576 avioFetchedMB=2370 muxBytesMB=640 avBufAhead=1.6s … seams=1
    memprobe t=240s … pktTotal=426576 avioFetchedMB=2370 muxBytesMB=640 avBufAhead=1.6s … seams=1   (identical — producer dead)
    

    Possibly the #50-family loopback wedge rather than #65 proper, but flagging it since on a long high-bitrate title the burst stalls the producer outright rather than just offsetting the clock. Happy to capture more, or run a specific seek pattern.

  4. added a commit that references this issue on Jun 25, 2026
  5. superuser404notfound commented on Jun 25, 2026

    @superuser404notfound
    Owner

    Thanks for the 4.0.2 capture, and especially for the frozen-producer data point. That recapture made me re-check my own instrumentation, and I owe you a correction: the "Root B (invariant shift)" readout was weaker than I implied. The avBufAhead=6.5s is just normal forward buffer, and frameAhead/prodShift/hostShift=0 is true by construction whenever the shift is invariant, so those three numbers cannot actually see a presented-vs-clock gap. Your frame-exact IINA check is solid; the problem is the engine had no signal that could corroborate it either way. So I built one.

    b08ab0a (please pin to it or any newer main) adds two positive probes, both on category: .session:

    1. Per-segment ledger at the VOD routing site:
      [HLSSegmentProducer] #65 ledger seg-N base=B itemAxis=X sourceStart=Y planSource=Z drift=D shift=S
      This maps each segment's item-axis position (what currentTime reports) to the actual source content muxed into it. drift = sourceStart - planSource. A multi-second drift on the segment your playhead sits in is a positive confirmation that the picture leads the clock, with the exact seg/epoch. drift ~0 across the whole burst means there is no content-vs-clock offset, and the 6 s is something else (see HDR10+ and Dolby Vision missing dynamic metadata #2).

    2. VOD backpressure wedge probe, wrapping the producer's two backpressure gates:
      [HLSSegmentProducer] #65 backpressure PARK (alloc|advance) head= target= cacheTarget= highStored= cached= parked=Ns
      This only fires on an abnormal park (no playback progress for > ~2 segment durations), so healthy backpressure stays quiet. A frozen cacheTarget below target is the producer wedge that matches your 90 s pktTotal freeze; a climbing cacheTarget is just normal buffering. Every VOD pump watchdog is currently live-only, which is why nothing breaks this on VOD.

    Could you reproduce one dueling-scrub burst on the same ~2 h title, engine logging on, and paste:

    • the #65 ledger lines around the divergent moment (and the currentTime you read there, so I can match it to a seg),
    • the one-time [HLSVideoEngine] segment plan: ... line (keyframe-aligned vs uniform fallback),
    • any #65 backpressure PARK lines during the freeze.

    That trace is dispositive: drift > 0 on a segment points the fix at the content-drift source; drift ~0 plus PARK lines points it at the VOD wedge. Either way I stop guessing. Thanks again for the rigor.

  6. added a commit that references this issue on Jun 25, 2026
  7. rrgomes commented on Jun 26, 2026

    @rrgomes
    ContributorAuthor

    4.1.0 (931f0a3), reproduced cleanly. tvOS, loopback-HLS native path; a 2.1h 4K HEVC + TrueHD title. Rapid bidirectional scrub burst (~20 relative seeks / ~19s).

    The ledger exonerates the producer — every segment through the burst is exact:

    #65 ledger seg-63 base=46 itemAxis=252.711s sourceStart=252.711s planSource=252.711s drift=0.000s shift=0.000s
    

    The divergence is engineClock vs the AVPlayer clock — a snap-to-seek-target: in every FreezeDiag engineClock == lastSeekTarget while AVPlayer's clock lags 30–40s, stuck buffering with empty/tiny loaded ranges:

    state=buffering engineClock=179.900 avpClock=149.900 loaded=[147.0-151.0]  (30s)
    state=buffering engineClock=160.800 avpClock=120.800 loaded=[]             (40s)
    state=buffering engineClock=187.500 avpClock=157.500 loaded=[156.4-159.9]  (30s)
    

    Gaps are ~integer multiples of the 10s seek step — the engine clock advances one step per rapid seek while AVPlayer lands only the first. frameAhead/producerShift/hostShift=0 throughout.

    Then it deadlocks with no recovery: backpressure PARK head=64 target=54 cacheTarget=53 cached=20, escalating parked=12s→62s+. The wedge is also severe enough to starve our UDP log sender on a longer burst.

    Net: producer is clean; the engine resolves clock+state to the seek target before AVPlayer lands it (a sustained-burst form of #37), AVPlayer never catches up, and the producer parks permanently with no VOD watchdog. Happy to add an AVPlayer timeControlStatus/seek-completion trace if useful.

  8. superuser404notfound commented on Jun 26, 2026

    @superuser404notfound
    Owner

    Fix shipped in 4.2.2.

    Your 4.1.0 trace nailed it: the producer ledger was clean (drift=0 throughout), so this was never a content/shift drift but a two-half livelock on the loopback path. A sustained burst left the engine clock latched at an optimistic seek target AVPlayer never reached, while the segment producer parked on backpressure with no VOD watchdog, and the two waited on each other with no recovery floor.

    4.2.2 gives both halves a recovery floor:

    • The native VOD seek await is now bounded by a cadence budget. When a seek does not land and AVPlayer is genuinely starved (no forward buffer), the engine reconciles its clock to AVPlayer's real rendered position instead of the unreachable target and re-anchors the producer there. A slow-but-buffering seek still awaits its real landing exactly as before.
    • The VOD backpressure park gains the watchdog the live paths always had: a consumer fetch target frozen past a threshold breaks the park and re-anchors the producer on AVPlayer's real position (a slow-but-advancing consumer never trips it, and a storm guard bounds re-anchors if AVPlayer never resumes).

    If you can retest on a long high-bitrate title: aetherctl seektest <file> --seeks 40 --gap-ms 60 now prints the wedge-break / re-anchor / reconcile recovery signals, and AetherPlayer is pinned to 4.2.2 for an interactive repro. Thanks again for the frame-exact diagnosis.

  9. rrgomes commented on Jun 26, 2026

    @rrgomes
    ContributorAuthor

    The 4.2.2 #65 fix resolves the scrub-burst case, but its backpressure wedge-breaker has a false-positive: a deliberate user pause is misread as a wedge. Captured on 4.5.1, tvOS 26. Source: a ~2.1 h 4K HEVC direct-play with TrueHD audio (so it bridges to the loopback-HLS native path), 3× PGS subtitle tracks.

    Repro: play the loopback-HLS native title, pause for >~24 s, then resume.

    What happens (device-mirrored EngineLog):

    1. Pause → [NativeAVPlayerHost] timeControlStatus=paused rate=0.0. The producer correctly stops being consumed.
    2. ~24 s later the backpressure detector trips — on the pause, not a wedge:
    [HLSSegmentProducer] #65 backpressure PARK (advance) head=128 target=118 cacheTarget=117 … parked=22s (no playback progress)
    [HLSSegmentProducer] #65 backpressure WEDGE BROKEN (advance) … parked=24s; exiting pump for host re-anchor on AVPlayer position
    [HLSVideoEngine] #65 backpressure wedge: re-anchoring producer to AVPlayer position 456.47s -> seg114 (attempt 1/5)
    
    1. The player is still paused, so the consumer never advances → re-anchor 2/5…5/5 over ~3.5 min, then:
    [HLSVideoEngine] #65 backpressure wedge re-anchor cap reached (6 consecutive at pos=456.47s); giving up (AVPlayer not resuming).
    
    1. On resume, AVPlayer can't recover — its loaded buffer is stranded behind the playhead and never refills:
    [FreezeDiag] trigger=stall state=playing engineClock=463.917 avpClock=463.917 tcs=1 waitReason=AVPlayerWaitingToMinimizeStallsReason loaded=[264.3-338.1] frameAhead=0.000
    

    loaded=[264.3-338.1] vs avpClock=463.917 — the buffer sits ~125–200 s behind the playhead and never advances; pause/resume is inert. Permanent wedge (force-quit required).

    Root cause: BackpressureWedgeDetector (Piece A) treats a frozen consumer fetch target as a wedge, but a paused AVPlayer legitimately freezes it — it issues no forward fetch by design. With no pause-awareness the detector fires during the pause, and the re-anchor loop runs against a player that can't advance because it's paused, burning all 6 attempts and leaving the producer re-anchored at 456 s while AVPlayer's buffer is stranded at 264–338 s, a state resume can't recover.

    Suggested fix: suspend the backpressure wedge detector (and its park timer) whenever rate == 0 / timeControlStatus == .paused; only run wedge detection when playback is actually requested. A paused consumer must never trip it. The seek-deadline starvation path (Piece B) likely wants the same pause-guard.

    For real-world use this bites harder than the original #65 (which needed a sustained dueling-scrub) — it fires on an ordinary >24 s pause of bridged-audio content. We've pinned back to 4.2.1 locally meanwhile. Happy to capture a fresh-logger onset trace or the resume sequence if useful.

  10. added 2 commits that reference this issue on Jun 26, 2026
  11. 23 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions