Skip to content

Draw a sidecar over a remux on the content's clock: a clock-only side reader - #1202

Merged
GLinnik21 merged 6 commits into
mainfrom
fix/sidecar-remux-keyframe-snap
Nov 2, 2026
Merged

GLinnik21 merged 6 commits into
mainfrom
fix/sidecar-remux-keyframe-snap

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

The bug

With Boost Dialog on, a direct play becomes a PMS remux (start.mkv, video copied). Every remux
(re)start — seek, resume, audio switch — begins on a Part keyframe earlier than or at the
requested offset, but the engine labels that first frame with the requested offset (disp_base),
so playpos_ns runs ahead of the content by the snap. Embedded text cues are already corrected by
the side reader (-delta); an EXTERNAL sidecar is in the Part's file time and nothing corrected
it, so it was drawn early — permanently.

Measured on one real file (GOP 2.002 s, first remux frame at 0.083 s): requested 439/475/564/917 s
started at 438.438/474.474/562.562/914.914. At 917 s the keyframe at or before the offset is
916.916 s yet PMS used 914.914 s, so the delta_assumed fallback is 2.002 s wrong; only the
byte-exact whole-packet Anchor match names the right keyframe.

The fix

A clock-only run of the existing side reader for a sidecar over an admitted remux: the same
keyframe scan and byte-exact anchor match, no subtitle packets, no store, no side_subs_owner /
desired_sub_idx, and never the server's burn. The exact delta is published to a lock-free mirror
(EXACT_DELTA_NS, i64::MIN sentinel, written only on an exact match) and applied only on the
sidecar's draw (player::subtitle_draw → sidecar_clock_ns); the screen subtracts the viewer's
timing offset itself, so it composes. Audio, disp_base, pts_shift, the embedded-cue path and
subtitle_clock_ns are untouched.

Off the reader's local-link/bitrate gate, or with no exact match, the sidecar is drawn exactly as
before.

Known limit (documented, not hidden)

The delta is known a moment after each remux start — the scan read 28 MB and took ~4.3 s on the
test file. Until then the sidecar is drawn on the old clock, and when the delta lands the position
drops once, which ass_source::Clock::sample treats as a discontinuity; a cue can repeat once.
After that it is in sync, across seeks and audio switches.

Verified

  • Device (debug build, this branch): subside: anchor match=exact … delta_ms=-1709 scan_ms=4322
    and … delta_ms=-2334 scan_ms=4370; the owner confirmed the sidecar is in sync after the
    correction (the transient above is what they saw).
  • Host: make test-crate C=plx_media 1987 passed / 0 failed; make test-hostsim C=plx_media
    2210 passed / 0 failed; make test-crate C=plx_screens T=ass_subtitles 18 passed; the
    FFmpeg-backed fixture (--ignored, PLX_FFMPEG_DIR) passed, now asserting that an assumed delta
    never reaches the mirror and that a clock-only pass returns Measured without installing an ASS
    source.
  • New tests drive player::subtitle_draw itself, pin that a delta measured by a track run survives
    apply() into the clock-only role, and pin that a clock-only failure (give-up or refused thread)
    never raises the server burn on either start path.

Not proven

An exact match at 917-style non-zero geometry on the host: building an Anchor needs the Part's
own keyframe packet bytes, which the FFmpeg fixture cannot produce without a PMS. The device runs
above are the evidence for that.

GLinnik21 and others added 6 commits November 2, 2026 00:22
…(SIMULATED red)

With Boost Dialog on, a direct play is a PMS remux that starts on the Part keyframe at or
before the requested offset while the app labels that frame with the requested offset, so the
playhead runs ahead of the content (measured: 0.645 s at 439 s, 2.169 s at 917 s). An external
subtitle is in file time and nothing corrects it.

This commit adds the draw seam (`player::subtitle_draw`, `player::sidecar_clock_ns`, the screen
calls the former), the lock-free exact-delta mirror (`subside::publish_exact` /
`exact_delta_ns`, published by `read_once` on a byte-exact match only) and the tests. The RED IS
SIMULATED, not historical: `sidecar_clock_ns` returns today's unshifted playhead, which is what
the old screen sampled, so the new tests fail with the measured numbers (439.083 s drawn where
438.438 s is on screen). The next commit makes it correct.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01P6ZnFcXzZ7owuVqq9sFBpL
… reader

PMS starts a remux on a Part keyframe at or before the requested offset, and the app labels
that frame with the requested offset, so the playhead led the content by the snap (0.6-2.2 s
measured). An embedded track's cues were already moved by the side reader; an external
sidecar (file time) was not, and drew early.

The side reader now runs CLOCK-ONLY for a sidecar over an admitted remux
(`route::side_reader_target`, `subside::CLOCK_ONLY`): the same keyframe scan and byte-exact
Anchor match, no subtitle packet read, no track or ASS source opened, no subtitle selection or
`side_subs_owner` taken, and it can never raise the server-burn failure. A byte-exact match is
published lock-free (`subside::exact_delta_ns`), and `player::sidecar_clock_ns` adds it to the
sidecar's playhead only for a sidecar drawn over a remux. An assumed delta is never used: the
keyframe at or before the offset was measured 2.002 s wrong at 917 s. Embedded cues are not
touched. Off the reader's gate (remote link, huge bitrate) or without an exact match the
sidecar is drawn exactly as before. `stop`/`start` clear the measurement, so a run the reader is
not admitted for never inherits another run's snap.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01P6ZnFcXzZ7owuVqq9sFBpL
…ange made false

A clock-only run takes no subtitle selection and no demuxer ownership, its measurement dies
with the engine run (stop/start), and a clock-only give-up is never the server burn. Updates
sidecar.rs "The clock", the soft-subs-plan keyframe-snap paragraph (it covered only the old
server WebVTT stream) and the player CLAUDE.md sidecar paragraph.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01P6ZnFcXzZ7owuVqq9sFBpL
…raw is pinned

A mid-play pick whose clock-only reader thread cannot be spawned raised the
server-burn flag, so an embedded track the viewer switched to before the pump
polled it was burned. A give-up and a refused start now go through one policy
that reads the run kind, and a clock-only failure logs its own line: the harness
grades `subside: failed` / `subside: could not start` as the TRACK reader
failing, and the engine's start failure had the same defect.

Tests that would have stayed green with the bug:
- the FFmpeg fixture now proves an assumed delta never reaches the draw's
  mirror, and a clock-only pass returns Measured without installing an ASS
  source;
- `player::subtitle_draw` is driven for real, so handing the sidecar the raw
  playhead fails;
- an exact delta a track run measured survives `apply` into the clock-only role
  within the same engine run.
… one

The 917 s counterexample (PMS started on 914.914 s while 916.916 s existed)
refutes the "keyframe at or before the offset" phrasing this branch had added,
so correct it at every site and say what the assumed mapping really assumes.
State the sidecar's early window plainly too: until the exact match lands after
each remux start the sidecar is drawn as before, and the drop when it lands can
show one cue twice. Stop claiming every lookup goes through subtitle_clock_ns:
the sidecar is asked at sidecar_clock_ns and the screen subtracts the offset
itself.
The engine's start failure now goes through `subside::failed_reading` instead of
re-encoding the same two labels and the same burn decision inline, so the two
roles cannot drift. The polarity test says what it pins (the policy both start
paths call) and the draw test says it pins `subtitle_draw`'s answer, not the
screen's call site, with an identity check instead of "is a script".

Prose: image-set lookups are the ones that go through `subtitle_clock_ns`
(embedded text is sampled at the playhead, the screen subtracts the offset), the
offset range is 60 s not 30, the subside module doc says "earlier than or at",
and the log inventory lists `clock-only failed`.
@GLinnik21
GLinnik21 merged commit 1e9bd1d into main Nov 2, 2026
20 checks passed
@GLinnik21
GLinnik21 deleted the fix/sidecar-remux-keyframe-snap branch November 2, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant