Skip to content

Subtitle side-demuxer reads forward from a stale anchor when activated mid-playback (no pause) → long delay to first cue on slow/remote sources #52

Closed

Description

What happened?

Calling selectSubtitleTrack(index:) mid-playback without pausing on a large/remote (high-latency) source shows the first on-screen cue ~25–35s later, instead of the ~1–2s the API docstring promises.

The side Demuxer (runEmbeddedSubtitleReader) anchors at the playhead captured at call time and reads forward. On a slow source the open (demuxer open + duration*0.5 prewarm seek + seek-to-playhead) costs several seconds, during which unpaused playback advances — so the reader seeks to a now-stale position behind the live playhead and pages forward over already-played content. Those cues arrive behind the playhead and are dropped by the current-cue lookup until the read catches up.

The anchor is correct for the instant it was captured; the gap is that the reader never re-samples the playhead after the slow open. Not a crash — purely a latency at activation.

Steps to reproduce

  1. engine.load(url:) a large remote (high-latency) HEVC source with an embedded text (SubRip) subtitle track; start playback and let it run a few seconds so the playhead is advancing. Do not pause.
  2. Call selectSubtitleTrack(index:) for the text track.
  3. Measure time from the call to the first in-window cue: ~25–35s.

Isolating contrasts (each freezes one variable and the delay disappears):

  • Pause first, then activate, then resume → cues present immediately on resume, same remote source.
  • Small/local source, no pause → ~1s (open is fast enough that the playhead barely moves).

AetherEngine version or commit SHA

6bc4e75 3.11.2

Host app

Custom / my own integration

Platform

macOS

OS version

macos 27, iOS 27

Device / chip

m2, a19 pro

Playback path

Native AVPlayer

Source media (for playback bugs)

MKV · HEVC (Main 10) · Dolby Vision Profile 7 · ~3840×2160 · audio: ANY. Streamed from a remote CDN (high origin latency). ffprobe output available on request. Reproduces on any source whose side-demuxer open is slow relative to playback (large / remote / high-latency); not on small/local fixtures.

Error codes / log lines

embedded subtitle reader started: stream=19 startAt=4626.60s seekTo=4624.60s   ← this line lands several seconds after the selectSubtitleTrack call (slow open)
subtitle first cue: pktPTS=4624669 → startTime=4624.669s
... first emitted cues sit behind the still-advancing live playhead ...
... reader pages forward; cues only get ahead of the playhead tens of seconds later → first visible cue

Anything else

Root cause (hypothesis). runEmbeddedSubtitleReader derives seekTo once from the startAt captured before demuxer.open + the prewarm seek; on a slow source those steps consume wall-clock during which (unpaused) playback advances, but the reader never re-samples the playhead before seeking. (Per CONTRIBUTING this is engine-side — it traces to the side-demuxer, not anything a host could cleanly work around.)

Suggested direction (you know the engine's invariants far better than I do — this is a hint, not a prescription, and it's untested against your tree): after the open + prewarm, re-sample the live playhead and seek there instead of the startAt captured before the (slow) open, rather than reading forward from the stale anchor. It would re-target the single existing seek (no extra network seek), and should be a no-op when paused, on a fast/local open, and on the seek re-arm path (clock.sourceTime is already the seek target there). Two things I'd watch if you go this way: keep the -2.0 bitmap-SETUP lead-in on the new target, and initialize the read-ahead playheadSnapshot to the re-sampled value too, or the first packet trips the park gate immediately.

Activity

  1. ghost added
    bug
    on Jun 19, 2026
  2. superuser404notfound commented on Jun 20, 2026

    @superuser404notfound
    Owner

    Thanks for the unusually precise report, including the isolating contrasts (pause-first, small/local) that pin it to the slow open rather than the anchor math. Your root-cause read is exactly right.

    runEmbeddedSubtitleReader captured the playhead (startAt) before demuxer.open and the duration*0.5 prewarm seek. On a high-latency source those steps cost several seconds of wall-clock, during which unpaused playback advances, so the seek-to-startAt-2 lands behind the live playhead and the reader pages forward over already-played content. Those cues arrive behind the playhead and get dropped by the current-cue lookup until the read catches up, which is the tens-of-seconds activation delay.

    Fixed on main (1909138) along the direction you suggested: after the open + prewarm, the reader re-samples the live playhead and re-targets the single existing seek to it instead of the stale pre-open anchor. No extra network seek. A max(startAt, fresh) guards the direction so it never seeks behind the requested anchor, which keeps it a no-op when paused, on a fast/local open, and on the seek re-arm path (where sourceTime already equals startAt). Both of your watch-outs are handled: the -2.0 bitmap SETUP lead-in is kept on the new target, and the read-ahead playheadSnapshot is seeded from the re-sampled value so the first packet does not trip the park gate.

    The embedded subtitle reader started log line now prints both startAt and effectiveStart so the re-sample is visible in diagnostics.

    This will ship in the next tagged release. If you can retest off main against your remote DV7 source in the meantime, a confirmation that first-cue latency drops back to ~1-2s would be appreciated.

  3. ghost closed this as completedon Jun 20, 2026
  4. rrgomes commented on Jun 21, 2026

    @rrgomes
    Contributor

    On 3.11.6 this fix also resolved two symptoms we (a separate host integration) had been chasing independently — both narrower-looking than the activation-delay this issue was filed for, but the same root cause:

    1. PGS "catch-up burst" on a mid-file start. Starting a title ~25–40 min in flooded the screen with a rapid burst of PGS cues before settling. The embedded subtitle reader started log showed exactly the stale anchor described here — e.g. startAt=0.00s -> effectiveStart=2469.28s — i.e. the reader was seeking to 0 and paging forward over the entire already-played span, and those cues landed at the host as one burst. With the re-sample they start at the playhead and the burst is gone.

    2. PGS subtitles that never appeared at all. On a large DV-P7 / FLAC / PGS title, the selected PGS track produced no on-screen cues whatsoever (startAt=0.00s -> effectiveStart=60.14s). Same mechanism — every cue arrived behind the live playhead and was dropped by the current-cue lookup, so nothing ever displayed. Now they show.

    So the fix had broader reach than the slow-remote activation delay. Thanks — nice catch by @reckloon and clean fix.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions