Skip to content

Embedded ASS subtitle feed falls behind on packet-dense tracks #56

Closed

Description

@edde746

What happened?

I load a short MKV through the native AVPlayer/HLS path with embedded ASS subtitles and
LoadOptions(preserveASSMarkup: true). The active primary subtitle track is an embedded ASS track
with many same-timestamp events.

Expected: the embedded subtitle side-reader should read far enough ahead that host-rendered ASS cues
are available before playback reaches them. For this 26.087 s file, the reader should effectively reach
the end of the subtitle stream quickly, or at least keep the published subtitleCues ahead of playback.

Actual: subtitle rendering appears to stop after the early sequence. The reader/feed is not completely
dead, but it falls far behind while publishing one cue/event at a time through subtitleCues. At playback
offset ~15.0 s, the host had only received/appended 1098 ASS events and the maximum cue end time visible
through subtitleCues was still 8.167 s, even though the source stream contains thousands of ASS packets
after 8.167 s.

This makes later subtitles unavailable to the host renderer until too late, so the on-screen result looks
like subtitles stop rendering.

Steps to reproduce

  1. Use a host app that opts into raw ASS cue delivery:

    let options = LoadOptions(
        ...,
        preserveASSMarkup: true
    )
    try await engine.load(url: mkvURL, options: options)
  2. Select the embedded ASS subtitle track titled Dialogue (stream=4 in the sample below).

  3. Render the published engine.$subtitleCues in a host ASS renderer, using TrackInfo.assHeader plus
    each raw event line and its cue.startTime / cue.endTime.

  4. Start playback from 0.

  5. Observe that subtitles render early, then later cues are missing/delayed because the published cue feed
    is still processing the large 5.207s event cluster when playback has already advanced well past it.

Samples: https://litter.catbox.moe/ouz5gf.zip (Ex1.mkv)

AetherEngine version or commit SHA

3.12.0 / 0468901

Host app

Custom / my own integration

Platform

tvOS

OS version

tvOS 26.5

Device / chip

4K 3rd gen

Playback path

Native AVPlayer

Source media (for playback bugs)

No response

Error codes / log lines


Anything else

No response

Activity

  1. added
    bug
    on Jun 22, 2026
  2. superuser404notfound commented on Jun 22, 2026

    @superuser404notfound
    Owner

    Fixed in 3.13.1 (f604746).

    Root cause: the embedded subtitle side reader published every decoded event through its own awaited MainActor.run hop. On a packet-dense track those per-event hops serialize the demux loop against the host's on-MainActor ASS renderer, so demux throughput collapses to the MainActor scheduling rate and the published subtitleCues fall far behind the playhead. Your Ex1.mkv made this very concrete: the Dialogue track stacks 1534 ASS events on a single 5.207 s timestamp (and 1735 on another), so the reader was doing ~1534 awaited hops just to clear that one cluster, which is exactly where it stalled.

    The reader now coalesces decoded events and flushes them to the MainActor in a single hop, gated two ways:

    • a source-time window, so a sparse track still flushes per event (no added latency); and
    • a count cap, which is the decisive throttle for a same-timestamp burst (its span stays 0, so the window alone can't help). That turns the 1534-event cluster into roughly a dozen hops instead of 1534, and the demuxer streams freely between flushes.

    Flushing also happens before the read-ahead park and at end of stream; a track switch / seek / stop still drops the trailing batch via the existing cancellation guard. The native tx3g reader from 3.13.0 already wrote cues off-actor, so it was never affected.

    If you could retest with 3.13.1 on the same sample and confirm the later cues now stay ahead of the playhead, that would be much appreciated. Thanks for the very precise report and the reproduction files, the same-timestamp packet histogram is what pinned it down.

  3. edde746 commented on Jun 22, 2026

    @edde746
    Author

    Seems to be fixed.

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