Skip to content

Subtitle side-demuxer takes ~55 s to emit the first cue after a backward seek (video plays normally meanwhile) #96

Closed

Description

@rrgomes

Split from the #93 retest.

Test asset: native Dolby Vision Profile 8.1, 4K HEVC Main10 (HDR10 fallback), ~25 Mbps, MKV, embedded text/PGS subtitle track (stream 2). tvOS 26.5, Apple TV 4K (3rd gen), loopback-HLS native path.

After an aggressive backward seek, the embedded subtitle reader blocks for ~55 s before emitting its first cue, while video plays normally at the new position the whole time — so subtitles simply disappear for ~a minute. Re-selecting the subtitle track in the UI doesn't help: it restarts the same reader, which blocks again.

Trace (backward seek to ~560 s at t0; video plays 560→575 fine throughout):

t0+3s   embedded subtitle reader started: stream=2 startAt=560.30s effectiveStart=562.50s seekTo=560.50s …
t0+56s  subtitle first cue: pktPTS=561812 → startTime=561.812s endTime=562.813s
t0+59s  embedded subtitle reader parked: demuxPos=666.0s playhead=576.0s lead=90s

So the reader takes ~55 s to surface the first cue at 561.8 s, then catches up in a burst (560→666 in the last ~3 s). The block correlates with the main video producer doing segment restarts / cache-misses on the same seek — suggesting the subtitle side-demuxer is starved on the shared source read (or reads forward from a stale anchor, cf. the closed #52).

During normal forward playback the reader scans cleanly (starts/exits roughly every ~1 s, emitting cues, parking at lead=90s) — the pathology is specific to re-seeking backward.

Happy to attach the full trace.

Activity

  1. superuser404notfound commented on Jul 3, 2026

    @superuser404notfound
    Owner

    Thanks for splitting this out, the trace shape is very telling.

    The reader itself anchors correctly (seekTo=560.50s for a first cue at 561.8 s), so this is not the stale-anchor class from #52. Reading ~1.3 s of stream in 55 s while the main producer is doing restarts and 30 s cache-misses on the same link points at source-read starvation: the subtitle side-demuxer competes with the segment producer for the same saturated connection, gets a small fraction of it, and only bursts ahead (560 to 666 in the last ~3 s) once the producer settles. That is the same resource-arbitration class we recently fixed for still-frame extraction (elective reads now yield while a restart is in flight or the forward buffer is low), and the subtitle reader likely needs an equivalent policy, though with care, since unlike thumbnails its output is user-visible content that must eventually arrive.

    One more thing the full trace should answer: the produced segments also feed the selected subtitle track through a pump tap on the main demuxer, which is meant to cover exactly this window without waiting for the side reader. Your trace suggests that coverage did not engage after the backward seek. Please do attach the full timestamped trace (producer, host, and the subtitle reader lines); the tap's arming and emission lines around the seek are the part I want to see.

  2. rrgomes commented on Jul 5, 2026

    @rrgomes
    ContributorAuthor

    Fresh trace on the 4.12.1 tag, different asset: 4K HEVC (3840x2076) ~26 Mbps MKV, E-AC3, two embedded SRT tracks, LAN source over Wi-Fi. Scrub-heavy session with the overlay subtitle path active throughout.

    The June ~55 s shape didn't recur — worst first-cue gap on this pin was 26 s — but the mechanism is now cleanly visible with the 4.12 diagnostics, and it's the same class as the residual I just posted on #93: the side reader's cold read sits in a long wait the counters can't see, then a reconnect (or a single slow detour fetch) unblocks it.

    Two windows, verbatim:

    19:20:31.405 embedded subtitle reader started: stream=2 startAt=814.30s effectiveStart=814.30s seekTo=812.30s codec=94225
    19:20:50.345 [AVIOReader] slow read: 18938ms at offset=2661629352 detour=0(0ms,0fetch) stallWaits=10(70ms,10signaled) reconnects=1 backoff=0ms staleGenDropped=0b gen=24->25
    19:20:50.362 subtitle first cue: pktPTS=812062 → startTime=812.062s endTime=814.147s
    
    19:21:40.617 [HLSVideoEngine] producer restarted at idx=194 (seek=777.53s, restart took 0ms; stopWait=0ms seek=0ms build=0ms)
    19:21:49.164 embedded subtitle reader started: stream=2 startAt=766.10s effectiveStart=791.60s seekTo=789.60s
    19:22:12.653 [AVIOReader] slow read: 32040ms at offset=2547006794 detour=0(0ms,0fetch) stallWaits=9(71ms,9signaled) reconnects=1 backoff=0ms staleGenDropped=0b gen=13->14
    19:22:12.660 [HLSSegmentProducer] first source read after start took 32047ms
    19:22:15.611 [AVIOReader] slow read: 26446ms at offset=2567851104 detour=1(26446ms,1fetch) stallWaits=0(0ms,0signaled) reconnects=0 backoff=0ms staleGenDropped=0b gen=28->28
    19:22:15.612 subtitle first cue: pktPTS=783325 → startTime=783.325s endTime=784.576s
    

    Two things stand out. First, the second window's detour line: a single detour fetch took the whole 26.4 s — a 4 MB block at ~1.2 Mbps effective from a LAN origin whose producer connection was serving the same file at full rate at the same moment, so it's per-connection starvation rather than origin or link capacity. Second, the user-visible effect has inverted since 4.9: video recovery from a backward scrub is now instant (segment retention + the 0 ms restart above), so the subtitle reader's 15–30 s cold read is no longer masked by an equally slow video path — subtitles just vanish for tens of seconds while playback runs, and a user who scrubs again before the read completes restarts the reader and never sees a cue at all. That's how this was reported to me ("subtitles stopped rendering after a scrub back").

    Same asset also confirms the catch-up side is fine once the read lands (no burst, #100 holding). Full log window available if useful; happy to re-run with any added instrumentation.

  3. rrgomes commented on Jul 5, 2026

    @rrgomes
    ContributorAuthor

    Same three sessions as the #93 retest (main @ 8aed0db): two on the DV P8.1 asset, one on the dual-SRT 4K HEVC asset, subtitles on throughout, aggressive backward scrubs.

    The markClosed supersede half works — no stale-generation competition observed anywhere. But the base case persists as you predicted, and the sessions surfaced a second, compounding mechanism.

    1. Side-reader starvation, still there. The cleanest sample: a superseded reader's replacement did a single 4 MB detour fetch that took 24.2 s while the producer was actively restarting/serving on its own connections:

    slow read: 24157ms at offset=1274408659 detour=1(24157ms,1fetch) stallWaits=0(0ms,0signaled) reconnects=0 backoff=0ms staleGenDropped=0b iters=1 unaccounted=0ms gen=8->8
    

    First-cue delays on reader restarts that collide with producer cold reads ran 15-17 s across all sessions.

    2. New: the superseding reader anchors to a stale clock, leaving a structural cue hole. When a scrub supersedes while the previous landing is still wedged (so the AVPlayer clock hasn't dropped yet), the restarted reader anchors to that stale clock instead of the in-flight seek target — and nothing ever re-anchors it when the engine's own recovery restarts the producer at the true target. Three exhibits, holes growing with scrub distance:

    • anchor 393.6 s vs landing 360.9 s → first cue 389.3 s, ~25 s of playback with no cues possible
    • anchor 262.3 s vs landing 204.8 s → first cue 248.9 s, ~44 s hole (subtitles visibly returned on screen exactly as the playhead crossed 248.9)
    • anchor 824.0 s vs landing 633.8 s → first cue 812.1 s, ~178 s hole — verified on screen: video played ~3 minutes with no subtitles, which then reappeared unprompted as the playhead crossed ~812 s
    embedded subtitle reader started: stream=2 startAt=824.00s effectiveStart=824.00s seekTo=822.00s ...
    producer restarted at idx=158 (seek=633.84s, restart took 6ms; ...)   <- 7ms later
    subtitle first cue: pktPTS=812062 -> startTime=812.062s
    embedded subtitle reader parked: demuxPos=914.4s playhead=636.9s lead=90s
    

    So even with instant reads, a superseding scrub during a wedge produces an (anchor − target)-length subtitle gap. Distinct from the starvation, compounds with it.

    3. Pump tap: never engaged. Grepped all three session logs for the tap's arming/emission lines — zero occurrences. It did not engage in the post-backward-seek window in any of these runs, consistent with your read that it doesn't cover this case yet.

  4. superuser404notfound commented on Jul 6, 2026

    @superuser404notfound
    Owner

    Retest sorted this into three mechanisms, one of which is fixed on main @ 52b6ade.

    The stale-clock anchor (fixed), the big user-visible one. Your exhibits (anchor 393.6 vs landing 360.9, 262.3 vs 204.8, and 824.0 vs 633.8 with the ~178s on-screen blackout) trace to two spots. When a scrub supersedes while the previous landing is still wedged, the wedge-reconcile path re-anchored the producer to the true recovery target but returned before the normal-landing subtitle re-arm, so the side reader was never re-seeked; and separately the reader's effectiveStart = max(startAt, sourceTime) let the frozen stale-ahead AVPlayer clock override a legitimate backward target. The reader is now re-armed in the wedge path at the same recovery target the producer aims at, and the forward catch-up is suppressed while a recovery seek is pending, so a frozen stale-ahead clock can no longer push the anchor past the landing.

    The side-reader starvation (still open). detour=1(24157ms,1fetch) while the producer serves the same file at full rate is the same per-connection origin starvation as the #93 cold read, and it is not fixed yet. One contributor is reduced on 52b6ade: with subtitles on, the reader also competed with the wedged-restart reopen for the origin's connection slots, and the reader now defers its origin I/O while a restart is in flight (see #93). The base case of one side reader vs the producer both pulling live is the same unlocalized ~15s cold read as #93, and I am chasing that there first.

    The pump tap (still open). Confirmed from your grep, it never engaged in the post-backward-seek window. That is the real fix for the base case (it would make the side reader non-critical). To chase why it does not arm after a backward seek I need the full timestamped trace with the tap's arming and emission lines around the seek.

    Retest ask, main @ 52b6ade: the stale-clock cue holes (anchor ahead of landing) should be gone, and subtitles should re-anchor to the true target after a wedged scrub. The starvation cold read and the tap gap remain.

  5. rrgomes commented on Jul 6, 2026

    @rrgomes
    ContributorAuthor

    Same two sessions as the #93 retest (main @ 52b6ade), subtitles on throughout.

    The stale-anchor race is gone. ~25 reader restarts across both sessions; every effectiveStart stayed at or within ~11 s of startAt (live-clock drift during reader spin-up, not the frozen stale-ahead anchor), and no (anchor − landing) cue holes appeared. Post-wedge re-arms landed their first cue at or below the playhead every time.

    The starvation half is now the whole user-visible story, exactly as scoped. The one on-screen subtitle anomaly this session was this class: a scrub-back restarted the reader, its cold read starved, and the first cue landed 16.5 s later — at which point subtitles visibly returned on their own:

    22:02:30.439 embedded subtitle reader started: stream=2 startAt=886.80s effectiveStart=892.20s seekTo=890.20s
    22:02:44.970 slow read: 21782ms at offset=3099273951 detour=0(0ms,0fetch) stallWaits=8(72ms,8signaled) reconnects=1 backoff=0ms staleGenDropped=0b iters=17 unaccounted=21710ms gen=5->6
    22:02:46.977 subtitle first cue: pktPTS=888931 -> startTime=888.931s
    

    Pump tap: still zero arming/emission lines in both full session logs. If the tap's arming diagnostics need a debug flag or only emit on a specific path, point me at it and I'll capture the trace you asked for — otherwise it simply never armed post-backward-seek again.

  6. superuser404notfound commented on Jul 7, 2026

    @superuser404notfound
    Owner

    Two things from your 52b6ade retest.

    M2 (stale-clock anchor): confirmed fixed, thanks. ~25 reader restarts, every effectiveStart at or within live-clock drift of startAt, no (anchor - landing) cue holes. That half is closed.

    M3 (pump tap): the zero-grep is correct, and it is expected, not a missing debug flag. The arming line [HLSVideoEngine] subtitle pump tap armed for streams … is category: .session and release-visible (no DEBUG gate), so if you see none, it genuinely never armed. The reason it never arms on your trace: the pump tap only exists to fill the native WebVTT rendition, which we ship only on iOS (for PiP and AirPlay, where AVKit needs a real legible rendition). On tvOS there is no native WebVTT path, so the tap never arms and the on-frame overlay is fed by the side demuxer by design. So the tap is not the lever for the tvOS overlay case, and there is nothing further to capture there.

    That leaves M1 (side-reader starvation) as the whole user-visible story, exactly as you scoped it, and it is the same per-connection origin starvation as the #93 cold read: your slow read: 21782ms … reconnects=1 iters=17 unaccounted=21710ms is the identical "empty counters, all unaccounted" shape. Rather than route tvOS subtitles through the tap, the fix is to get the demuxer read loop itself clean, which fixes the side reader and the #93 video cold read together.

    The instrument for that is up on main @ 9cfa74b (see #93): the slow read: line now carries lockWait= (loop-head window-lock acquisition) and connect= (the synchronous reconnect/connect path), both subtracted from unaccounted. The side reader runs the same loop, so your next trace names the branch for this issue too. Same drill, subtitles on, one starved first-cue read is enough.

  7. rrgomes commented on Jul 8, 2026

    @rrgomes
    ContributorAuthor

    9cfa74b data point for the starved side-reader, from the same retest session as the #93 traces (the 4K HEVC 3840x2076 dual-SRT asset, SRT enabled): the session's final backward scrub restarted the embedded reader and the first cue took ~16s to land — and the side-reader's read is exactly the block:

    15:24:05.648 embedded subtitle reader started: stream=2 startAt=701.40s effectiveStart=701.40s seekTo=699.40s
    15:24:05.986 (final scrub step lands: target=691.4s)
    15:24:21.702 slow read: 16053ms at offset=2263084672 detour=0(0ms,0fetch) stallWaits=15(36ms,15signaled) reconnects=1 backoff=0ms lockWait=0ms connect=3ms staleGenDropped=0b iters=31 unaccounted=16012ms gen=22->23
    15:24:21.711 subtitle first cue: pktPTS=694945 -> startTime=694.945s
    15:24:21.712 embedded subtitle reader started: stream=2 startAt=691.40s effectiveStart=706.70s seekTo=704.70s
    

    Same signature as the #93 lines — lockWait=0, connect=3ms, the block fully unaccounted — and the cue renders 9ms after the read returns. Healthy reader restarts earlier in the same scrub ladder (no cold read in the way) delivered first cues in ~100-600ms. Consistent with M1 riding the same read loop as #93; nothing here looks like it needs a separate mechanism.

  8. superuser404notfound commented on Jul 8, 2026

    @superuser404notfound
    Owner

    Your 9cfa74b side-reader line (lockWait=0 connect=3ms, block fully unaccounted, cue 9ms after the read returns) is the identical signature to the #93 video cold reads, so M1 rides the exact same read loop as I read it too.

    Rather than duplicate the ask: I posted the next step on #93. The two release-visible lines it asks for (gen=N response headers after / gen=N first data after, both already in 9cfa74b) come from the same session logs you captured here, so one grep covers both issues. Whichever branch those lines name closes this one and #93 together.

  9. superuser404notfound commented on Jul 9, 2026

    @superuser404notfound
    Owner

    Root cause found and fixed, on the shared read loop, so this closes with #93.

    Your side-reader line (lockWait=0 connect=3ms, block in unaccounted, cue right after the read returns) was the same defect as the #93 video cold reads. The two fixed caps rrgomes surfaced (15.0s and 35.0s) are the detour block fetch's timeouts (min(15, chunkRequestTimeout) idle, chunkRequestTimeout = 35 total): a backward-seek read serves through the detour cache, a miss fetches a 4 MB block over the pooled session, and on a per-connection-starved origin that fetch rode its full budget before the rescue reconnect (which serves in ~30-190ms). It read as unaccounted because the diagnostics only timed a successful detour serve, never a miss. Full write-up on #93.

    Fix on main @ 0ba8dae: the detour fetch now uses a tight ~4s interactive budget and aborts fast so the reconnect serves; the miss path now records its fetch time. The subtitle side reader inherits the same playback AVIO profile, so it gets the fix for free.

    Retest ask, main @ 0ba8dae, subtitles on: after a starved backward scrub the first cue should land within ~4s instead of 15-35s, and the slow-read line for the side reader should carry the time on detour= (~4000ms) rather than unaccounted=.

  10. rrgomes commented on Jul 12, 2026

    @rrgomes
    ContributorAuthor

    Retested on 5.0.2 (d5aadc9), PGS subtitles on throughout — full numbers and the day's only two slow-read lines (2.1 s / 2.7 s, unaccounted=0ms, forward-fill stallWaits, not admission) are on #93.

    The ~55 s first-cue signature is unreproducible. Across ~180 seeks in three scrub-storm sessions on the 2021 Apple TV 4K — 69 backward target jumps, 17 of them cache misses — there was no cue starvation of any kind: first cues after backward scrubs land as soon as the position settles (applySubtitleEvent within ~1 s of the landing), and during long multi-seek chases the cue path actually runs ahead of the presented frame (noted on #93). No side-reader slow-read line printed all day; with the packet-store rework in 5.0.2 there is no side reader left to starve, and its replacement kept up under storm load.

    Confirms the shared-read-loop diagnosis from our side — good to close with #93.

  11. superuser404notfound commented on Jul 12, 2026

    @superuser404notfound
    Owner

    Confirmed closed on 5.0.2 (d5aadc9). The ~55s first-cue starvation is unreproducible across the same three storm sessions with subtitles on throughout, first cues landing within ~1s of the settle, and with the packet-store rework there is no separate side reader left to starve, its replacement kept pace under storm load. Same shared read-loop diagnosis as #93, confirmed by extinction from both ends. Thanks again for the thorough retest.

    Closing together with #93.

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