Repository navigation
Conversation
…elivery queue Adds @moq/media-sync, a dependency-free core for anchoring media timestamps to a local clock, pacing deliveries, and serializing them per media kind with generation-scoped cancellation: a delivery stages its effects and returns a commit, and cancel()/reset() discard anything staged before the retirement. Shared vectors let wrappers that adapt units or callbacks test against the same cases as the core. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: HangPlayerEngineer <hangplayerengineer@paperclip.blockcast.net>
|
At the very least a before/after comparison of your final bundle size... and why it even matters. |
|
Thanks for putting this together, @kkroo. We're going to close it: we don't want to take on and maintain a separate (Written by Claude Opus 5.5) |
Problem
A receiver that does not use
@moq/watch(a different container, decoder, or renderer) has no way to reuse the playback clock or the per-track delivery fencing.Syncinjs/watch/src/sync.tsdepends on@moq/signals,@moq/netprobes and brandedTime.Milli, and its generation fence is theepochthatvideo/decoder.tschecks inline after each wait, so every other receiver re-implements both. We maintain two receivers (a hang fork and a moqtail-based one) that currently share one copy of this logic out of tree.Approach
Add
js/media-sync(@moq/media-sync), dependency-free, ~220 lines:received(ts)seeds and lowers the reference;now(kind)andwait(ts, kind, signal)apply a per-kind buffer.timestampScalekeeps the caller's units (1 for ms, 1000 for µs).waitthrows on an unseeded clock, so callers seed before waiting.enqueue(ts, kind, stage)paces and serializes per kind. A stage returns a commit (or{commit, discard}); the commit runs only if its generation is still current after everyawait.cancel(kind)/reset()abort the generation'sAbortSignal, drop queued work, and allow timestamp reuse.reset()also clears the clock and wakes parked waits.@moq/media-sync/vectorsexports the clock, pacing and retirement vectors, so wrappers that change units or callbacks run the same cases as the core.@moq/watchis not changed in this PR. This is an additive core, not a drop-in replacement for its currentSync:watchstill usesclose()for teardown andepocharound video waits; this core has neither API.Impact
@moq/media-sync(exportsMediaSync,MediaKind,MediaDelivery,MediaDeliveryStage,MediaSyncOptions) and subpath./vectors. No change to any existing API or wire format.Alternatives
@moq/watchSync. That keeps the queue behind a player package that pulls in signals, net and the UI. A receiver that only wants the fence would depend on a player.wait. That is smaller, but it adds a callback interface and still leaves every receiver to re-implement the clock.Synctoday: after fix(watch): hold parked video waits across a shared clock reset #5272, aSync.waitparked acrossreset()holds until the next frame re-anchors. Here a reset wakes the wait and the generation fence discards its commit. Migratingwatchonto this core would need that choice made explicitly, so this PR leaves it for later.Follow-ups
watch'sSyncqueue and epoch fence on this core, if wanted, with explicit teardown (close()), epoch fencing, and reset/wait integration.doc/lib/js/if the package is accepted.Validation
a4f8a552f952c683b72cf1a6365bf5a476910e60. Independently rerun vector suite: 15 tests pass, 29 expectations.@moq/*packages.Need help on this PR? Tag
@codesmith-botwith what you need.