Skip to content

feat(watch): add adaptive audio playout and worker offload - #3

Draft
fperex wants to merge 381 commits into
mainfrom
debug-findings-solution
Draft

fperex wants to merge 381 commits into
mainfrom
debug-findings-solution

Conversation

@fperex

@fperex fperex commented Sep 13, 2026 •

Copy link
Copy Markdown
Owner

Adaptive audio playout for @moq/watch, an audio-led sync clock, and the audio supply moved off the page's main thread. Draft.

Problem

Audio reads and decoding on the page stop when its main thread blocks, and a short playout ring then runs dry. A gap in the audio (jitter, loss, a long outage) is heard as a dropout, and video is paced by the wall clock instead of by the audio that is playing.

Approach

  • Playout engine (js/watch/src/audio/playout/, specified in doc/concept/playout.md). The ring follows upstream's target(), its only target, by time stretch (one pitch period dropped or repeated, at most 15 ms per 100 ms). It skips ahead only for what a stretch cannot close, conceals a gap by repeating the last pitch period, and ends a long outage in digital silence. conceal (default on) turns concealment off.
  • Audio-led clock. The ring's playhead drives Sync through Sync.track("audio") and video is paced from it. When the audio stops, playback continues at wall speed from where the playhead was.
  • Worker offload (offload, default on). One worker per page does each player's network reads, container consumption, delay estimation, WebCodecs decoding and ring writes, on one extra relay session per URL. The ring is written by message, so plain (non-isolated) pages work and nothing depends on handing shared memory to the worklet, which Firefox can drop under a busy page (reproduction). The page keeps the AudioContext, A/V sync, video and controls. Audio stays on the page with offload="false", without Worker or a relay url, when CSP refuses the blob: worker, and for good when the worker fails, stops reporting for 2 s, refuses the rendition, or plays nothing within 5 s.
  • Stream reader. @moq/net accepts a session's bidirectional streams through one reader that is never released, because WebKit deadlocks in releaseLock() when a garbage collection starts inside it (reproduction).
  • Lifecycle. The audio context, and the publisher's capture context, close only after their render processor reports stopped; Chromium otherwise keeps every closed context and its worklet nodes alive. A player that leaves the page releases its context (attached).
  • Fixes, each with a regression test. moq-bench sends QUIC closes before exit. moq import reads stdin in 64 KiB blocks. moq play stops on SIGTERM. The hang libav polyfill bridges native chunks when only one codec half is missing. A JS group that exceeds the subscription max age resets with OLD like Rust. The MPEG-TS importer keeps fractional sample ticks. @moq/publish republishes the Opus description after the encoder is rebuilt on unmute, and opens a capture only after the previous one is released. New moq-net and moq-tokio tests cover held takeover tails across route switches and an open-edge rejoin.
  • Upstream's implementation. Uses upstream's Auto delay estimator and catalog jitter floor (moq-dev/moq#4162), rings and target, network resume and cache (moq-dev/moq#4741 and follow-ups), relay drain, 10 s reconnect timeout, publisher pause marker (moq-dev/moq#4880), audio-quality harness and moq-shaper; the fork's own versions were dropped.
  • Tests and tooling. Replay tests play the recorded traces through the engine, with budgets recorded for it. Nightly runs just js stretch-bench and just js remote-bench. The demo watch page has bench switches ?offload=0, ?stall=MS/EVERY and ?csp=1. .agents/commands/sync-upstream and .claude/skills/sync-upstream carry the fork's upstream sync, with its test in .github/justfile.

Results

Linux VPS, real browsers, 60 s rows, AAC 44.1 kHz speech and BBB, delay="auto", WebTransport. 26 rows across Playwright Firefox, native Firefox and Playwright Chromium, on plain and isolated pages:

  • No silence episodes, 24 painted fps, and a zero-sample fraction equal to the reference decode.
  • Auto target 209 ms and flat (186 ms advertised plus one frame).
  • Chromium lifecycle (5 reattaches, forced GC): audio handlers 4 before and 4 after; closed contexts are collected.
  • Deployed demo smoke: 24 fps and 0 underruns on all pages, with the audio on the worker.
  • CI at 2a5c3bc4e: Check, Test, Replay, macOS, Windows, Android and WASM pass.

Impact (public API and wire)

  • <moq-watch>: attributes and properties conceal and offload, both default on.
  • @moq/watch Player: inputs conceal, offload and url (the relay the worker dials; without it the audio stays on the page).
  • @moq/watch Audio.Decoder: inputs conceal, offload, url and attached (default on). Its out.thread and out.debug are @internal, so the published declarations drop them.
  • @moq/watch Sync: new track(name: "audio" | "video") returning SyncClockTrack, output out.clock, and received(timestamp, label?, at?) with an optional arrival time. New exports Clock and SyncClockTrack. reset() and close() drop the clock.
  • @moq/watch hosting: the audio worker is a second file beside the render worklet in assets/. Playback needs script-src and worker-src to allow blob:, or Watch.assets() pointing at the copied files.
  • @moq/net: a group dropped for exceeding the subscription max age rejects with an Error.Stream carrying StreamCode.Old, which is how Rust resets it and how a peer's reset reads back.
  • CLI behavior: moq import reads stdin in 64 KiB blocks, moq play stops on SIGINT and, on Unix, SIGTERM (doc/bin/cli.md), and the MPEG-TS importer keeps fractional sample ticks in its timestamps.
  • Rust: no exported item added or changed. Wire: no framing change, so no draft changes. Docs: doc/concept/playout.md, doc/lib/js/watch.md, js/watch/README.md.

Alternatives

Audio can stay on the page per player (offload="false"). A decode-only worker would still leave network reads exposed to page stalls, so the worker owns a session of its own.

Follow-ups and limits

  • After a player reattach, the first picture can wait for the next keyframe group, up to one GOP. This is upstream behavior, tracked as moq-dev/moq#4914 (relay side) and moq-dev/moq#4951 (player side).
  • A held group across a route switch is not woken when its successor is stamped: moq-dev/moq#4950.
  • The console shows "skipping slow groups" for audio groups without measured gaps, also on pure upstream.
  • Auto target can settle at 325 ms after a measured burst.
  • Native Safari is unmeasured. There is no listening, MOS or stereo verdict, and renderer updates are not compositor FPS. One page-only lifecycle row held one extra closed context; repeats were clean.

How to test

just check                                      # lint, compile and test what the branch changed
just test audio-quality --replays --enforce     # deterministic replay lane, seconds
just js stretch-bench                           # engine cost per render quantum

(Written by Claude Sonnet 5.5 and Claude Opus 5.5)

🤖 Generated with Claude Code

@fperex
fperex force-pushed the debug-findings-solution branch 2 times, most recently from 03a21ec to 0b2e4ca Compare September 16, 2026 17:54
@fperex fperex changed the title Realtime audio: NetEq-style playout engine, harness, and fixes (POC, draft) Realtime audio and video: NetEq-style playout engine, publisher clock, catalog and capture fixes, Safari audio context, harness (POC, draft) Sep 17, 2026
@fperex
fperex force-pushed the debug-findings-solution branch from be1fc2c to 0617b44 Compare September 18, 2026 04:27
@fperex fperex changed the title Realtime audio and video: NetEq-style playout engine, publisher clock, catalog and capture fixes, Safari audio context, harness (POC, draft) Realtime audio and video: NetEq-style playout in both engines, publisher clock, endpoint and tune-in fixes, harness (POC, draft) Sep 18, 2026
@fperex
fperex force-pushed the debug-findings-solution branch 2 times, most recently from d05ddae to 6baa498 Compare September 20, 2026 17:29
@fperex
fperex changed the base branch from dev to main September 20, 2026 17:29
@fperex
fperex force-pushed the debug-findings-solution branch 2 times, most recently from 0b16fcb to 86e9818 Compare September 21, 2026 07:31
fperex and others added 4 commits September 21, 2026 05:08
Upstream c7ae307 (moq-dev#3770) renamed the announce update's `active` field to
`kind` and missed this client, so every `* -> js-native-*` pair of smoke-full
times out waiting for a broadcast that was already announced. upstream/dev on
its own fails the same eight pairs.

The client had no `check` script and no tsconfig, so nothing typechecked it and
the rename went through silently; both are added here and `tsc --noEmit` catches
this exact break.

Public API: none. Wire: none.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/9dfaf444-e50a-4a6c-bd79-b9c9f7b28ded
The rebase onto upstream/main replayed our commits against renames and reshapes
that git cannot flag: code we added still called the old spellings, so the tip
built from commits that each looked clean.

- `Moq.Group.Expired` is `Moq.Error.Expired`, and a `maxAge` is a `Time.Milli`.
- `Broadcast.Producer.requested` is private to the wire. Inside `@moq/net` the
  test reaches it through `wireOf`; the video decoder tests serve a track they
  insert themselves and count the subscriptions opened on it, which is what a
  per-subscription request used to report.
- `Broadcast.Consumer.subscribe(name)` is `consumer.track(name).subscribe()`.
- The watch and publish components take one properties object, so the audio
  decoder reads `this.sync` rather than a constructor parameter, and the publish
  element reads its own private capture.
- `Sync` has no advertised-delay term left: the catalog's flush span seeds the
  estimator instead, so the two tests that asserted one are gone.
- A rendition handle is demand-gated, so a muted publisher encodes nothing. The
  unmute test asserts the track and its timeline survived rather than that the
  frames nobody asked for were served.
- The instant-delay flush moved out of `#runFlush` into an effect of its own:
  as a branch there it made the ring's flush depend on the delay, so every
  change to the delay parked playback.

On the Rust side `moq_mux::catalog::Producer::new` takes a `Config`, and
`moq_tokio::server::Request::close` is `reject(Reject::App(status))`.

`test/smoke/clients/js-native/subscribe.ts` is upstream's, and upstream's own
`just js check` fails on it: `Connection.connect` takes a properties object now
and `Established.consume` is gone. Repaired here rather than left to fail our
branch's CI.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/6f340c6c-7f1c-46dd-b659-7ec14e9878be
A jittery path starves the older groups, so the delivery cursor sat on a group whose stream
header had arrived and whose first frame never did, with another one just like it behind it.
The age budget measured the head against that immediate successor, read its missing start as
nothing being known yet and gave up, so the picture froze for seconds at a time with whole
groups of media buffered behind, until a watchdog rebuilt the track.

The bound now comes from the first later group that holds a frame, which is where the
timeline can actually resume and what rs/moq-mux already measures against. That same start
answers whether anything was lost, so the starved groups in between cost one playhead event
between them rather than one each.

Public API: none. Wire: none.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/6f340c6c-7f1c-46dd-b659-7ec14e9878be
The JS container consumer measured a slow group against whatever sat immediately behind it,
so a starved successor holding nothing parked delivery and froze the picture for seconds with
whole groups buffered. This consumer measures against the next group that holds a frame and
reaches the verdict, which is what the JS fix adopts.

Pin that: the cursor's group and the one behind it carry a stream header and no frame, and
the group behind those two is past the budget and gets delivered in order.

Public API: none. Wire: none.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/6f340c6c-7f1c-46dd-b659-7ec14e9878be
@fperex
fperex force-pushed the debug-findings-solution branch from 86e9818 to a6d5301 Compare September 21, 2026 12:05
fperex and others added 5 commits September 21, 2026 08:47
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Merge the explicit-time and driver-deadline refactors, datagram buffering,
and io_uring ECN support while retaining the fork's changes.

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
fperex and others added 8 commits September 21, 2026 08:53
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Integrate upstream a93fdb8 and preserve fork discovery handling.

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Shorten the histogram's decay so a temporary queue does not keep Auto
buffered for a minute after arrivals recover. Keep the gradual target
reduction and the same behavior for sustained jitter in Rust and JS.

Add a twenty-second recovery regression, regenerate the shared corpus,
and document the distinction between history age and quantile recovery.

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Reset and reconfigure AudioEncoder when framed input leaves its continuous
timeline. Chrome and Firefox otherwise stamp resumed audio beside the
last pre-gap packet, putting playback behind the current video.

The existing media lifecycle regression failed at 10.0 fps after resume
before this change and passed at 29.8 fps after it. All local lifecycle
cases and JavaScript gates pass. Clarify the mocked track test's scope.

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Keep live group expiry active while FIN is unacknowledged in both JS and Rust publishers. Apply Lite priority changes throughout that wait and let the async transport adapter update priorities before acknowledgement.

Regressions fail on blocked FIN and stale priority before the fixes. Verified with 2,148 JavaScript tests, JS checks/builds, and 1,593 Rust network/transport tests. Sustained-loss browser QA remains in progress.

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Own worklet effects with the AudioContext so rate changes cancel pending module loads before closing the old context. Preserve errors from module loads on the current context.

Reproduced the late-join AbortError in a real browser with a 44.1 kHz default context and a 48 kHz stream. The regression fails before the change; the matching browser run and full playback lifecycle now pass. JS checks/builds and all 2,150 tests pass.

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Reevaluate the local container budget when the shared playhead moves. Preserve
completed wire groups while parsing their final buffered frames, and retain the
audio clock when video skips a group. Add regressions for budget changes without
new arrivals and for a buffered keyframe becoming due.

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
fperex and others added 27 commits October 6, 2026 19:46
The render worklet now owns a Stretcher and renders every quantum through it, so
the ring converges on the playout target by time stretch instead of cutting
audio, conceals a gap with synthesized audio, and ends a long outage in digital
silence. The target is still `sync.out.delay`; the engine never computes one.

Both rings expose the reader surface the engine needs (view, peek, commit,
starve, report). The skip-ahead now waits for a surplus that outlasts a window of
playback and lands on the target, only past a 75 ms stretch band above it, and a
hole the reader already ran dry on is stepped over rather than replayed as
silence. The ring keeps the media playhead as READ less what the engine holds.
`createAudioBuffer` takes its properties as an object.

`conceal` (default on) is a new input on the audio decoder and the player, and a
`conceal` attribute on `<moq-watch>`. `Decoder.out.debug` is an internal view of
the ring's counters. doc/concept/playout.md describes the engine.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A track that renders on a playhead of its own can nominate it through
`sync.track(name).clock`, and every other track is then paced against it
instead of the wall clock. `Sync` extrapolates between samples at the
playhead's own rate, so a parked playhead parks playback, and re-derives its
reference from the sample, so dropping the clock leaves playback running at
wall speed from where the playhead was. `out.clock` names the track that
leads; audio wins over video.

A frame's wait now reads the playhead and its rate again when its timer
expires, so a playhead that slowed while a frame slept is not taken for one
that arrived.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The audio ring consumes media on the sound card's clock, and the playout
engine stretches, parks and skips, so video paced against the wall clock
drifts from what a listener hears. Both rings now report where the reader is
and how fast it moves, the audio buffer maps that through the device's output
timestamp, and the decoder publishes it as the audio track's clock while audio
is on.

The postMessage ring's reports carry the context time and a timeline echo, so
a report composed before a flush is dropped instead of putting the clock back
on the media the flush threw away. A playhead that has neither moved nor been
written to for a second stops being the clock.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Stream.accept took a reader of incomingBidirectionalStreams for every stream
and released it after the read. WebKit (Safari 26.6) deadlocks a thread whose
releaseLock() starts a garbage collection: the collection waits on a reader
lock the same call holds, and the page's main thread then parks in its own
collection behind the suspended JIT worklist. Every moq-lite session accepts
the relay's announce stream right after it connects, so a worker holding its
own session froze the whole page a few seconds after it connected.

Accept now reads a session's incoming bidi streams through one reader kept for
the session's life, as Readers already does for uni streams. No API or wire
change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The decoder built the audio graph and also fed it: subscribing, reading
containers, decoding, estimating arrival spread, and writing the ring. Those
move to a `Supply` that reaches the graph only through a `Graph` it is handed
(somewhere to write the ring, the output clock, the rate and channel count) and
reads the part of `Sync` it needs as inputs. The decoder keeps the context,
the worklet node, the playout target, the clock, and what the UI reads.

`createAudioBuffer` takes the transport as a property instead of choosing it,
so whoever builds the graph decides, and the page names the transport it picked
once per document instead of once per ring. No change to behaviour.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A writer that is not on the main thread cannot reach the node's port, so the
page can hand the worklet one end of a channel and the writer the other. The
worklet then takes every ring message from either, reports state on both
(the node's own port hears the first playback report, which is how the page
learns the worklet read what the writer sent), and says once on every port
when a message could not be deserialized.

A `close` message ends the processor, so a node the decoder replaced in a
context that stays open stops rendering instead of running until the context
closes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The messages between a page and the worker that will feed its audio, and the
one worker a page shares between its players. The page hands the worker a
player (a broadcast, a rendition, the relay to read it from), the timing it
reads of `Sync`, the graph to write the ring into, and the device clock; the
worker answers with a report every 50 ms.

The pool starts the worker for its first player and keeps it for as long as any
player holds it, plus two seconds, and forwards the page being put away and
coming back. A worker the page could not start (a CSP refusing it, no native
decoder, a transport the page races and the worker cannot) is remembered for
the document's life, so every later player falls back at once. One that stops
reporting while it plays fails every player on it, with a single warning.

A worker that plays nothing within five seconds of having everything it needs
from the page is a deadline the page counts on its own timer, ignoring checks
that ran late behind a stalled or hidden page.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The worker's host does for each player what the page's supply does: it reads
the broadcast over a session of its own to the relay the page named, resolves it
through a manual-catalog broadcast holding the page's pick, probes it against
its own decoder, and feeds the same `Supply` through the port the page handed
the render worklet. `Sync` stays on the page, so the supply reports its frames
and its resets back, and the page applies them.

The worker never loads libav and never touches `window`: it decodes only where
WebCodecs is native, and refuses a rendition it cannot decode. Its ring is
messages on every page, because Firefox drops shared memory posted over a port
the worklet was handed just before the page got busy.

`Remote` is the page's half. It exposes the outputs a supply does, so the decoder
reads either alike, and it says when the page has to take the audio back: the
worker cannot start, fails, stops reporting, refuses the rendition, plays nothing
within five seconds, or the worklet could not read what it was sent.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…er cannot play it

The decoder now runs its supply in the page's audio worker when the player has
a relay URL for it to dial and `offload` is on (the default), so a page busy
with layout, video or its own scripts cannot starve the ring. The page keeps the
AudioContext, `Sync`, the picture and the controls; the worker reports back the
estimate, the frames, the ring's counters and its playhead, and the page applies
them to the same outputs a supply on the page publishes.

The audio stays on the page without a `Worker`, without a URL, or with
`offload="false"`, and goes back to it for good, on a fresh node of the same
context so the viewer's gesture is not spent again, when the worker cannot start
(a CSP refusing it, no native decoder, a transport the page races and it cannot),
fails, stops reporting, refuses the rendition, plays nothing within five
seconds of having what it needs, or the worklet cannot read what it was sent.
`Decoder.out.thread` says which. A player that is not `attached` releases its
AudioContext, its render thread and its ring, and builds them again if it comes
back.

The worker is bundled by `vite-plugin-worklet`, like the capture worker, so a
page whose CSP refuses `blob:` hosts it beside the worklet with `assets()`.

`just js remote-bench` sweeps the page's cost of the reports over players and
report rate, and the nightly job runs it; the unit test holds the same property
by counting the work each report does.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Off unless the query asks. `?offload=0` keeps each tile's audio on the main
thread, `?stall=MS/EVERY` (with optional `stallAt` and `stallFor`, in seconds)
freezes the main thread on a schedule and records each freeze on
`window.__benchStall`, and `?csp=1` refuses every worker so the audio's fallback
to the page can be tried. A malformed query throws, so a row cannot quietly run
without the load it asked for.

The demo gains a test script so its tests run with the rest.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e next write

A reader concealing the old timeline kept playing it through a pause that
nothing refills, because both transports bumped the generation only on the
next anchoring write. Bump it at reset() so the engine stops covering a
declared pause.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The replay renders each quantum through the Stretcher on the simulated
clock, so the budgets cover the engine's concealment, stretch and skips
as well as the ring and the estimator. Port the fork's seven recorded
fixtures with per-profile gap budgets, a concealment test, a declared
pause test, and a Sync replay that compares audio-led pacing against the
wall clock on the same trace (24.5 ms ahead and 40.6 ms behind, against
58.4 and 123.2 on the wall clock).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… engine

The replay rows now render through the engine, which covers a gap and stretches a surplus out, so
the ring runs dry less and its skips land elsewhere. Exact measurements, replacing the previous
ceilings (underruns/min, underrun ms/min, skips/min, discarded ms/min, stalled, silence, target p95):

local-aac isolated: 0, 0, 2, 81.1, 0.025, 0.025, 203.2 -> 0, 0, 0, 0, 0, 0, 203.2
local-aac plain:    2, 4.9, 0, 0, 0.017, 0.015, 203.2 -> 0, 0, 0, 0, 0.008, 0, 203.2
relay-bbb isolated: 2, 0.5, 0, 0, 0.033, 0.024, 223.2 -> 0, 0, 0, 0, 0, 0, 223.2
relay-bbb plain:    0, 0, 2, 87.9, 0.017, 0.017, 223.2 -> 0, 0, 0, 0, 0, 0, 223.2
relay-mic isolated: 2, 2.7, 4, 510.8, 0.017, 0.027, 420 -> 0, 0, 4, 610.9, 0.017, 0.011, 420
relay-mic plain:    0, 0, 4, 564.6, 0.017, 0.027, 420 -> 0, 0, 2, 449.6, 0.017, 0.011, 420

relay-mic isolated is the one ceiling that rose: 253 ms discarded over the window before, 303 ms
now, in two skips both times. The extra 50 ms was not traced to a single cause.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The benchmark returned from main with its connection tasks still running, so
the runtime dropped them before the close frames were sent. The relay then
held every peer until its idle timeout. Stop the tasks and await
`Client::close` first, and keep the stop result through cleanup so a reporter
failure still fails the run.

Prove the actual binary sends a clean close to all eight peers before it
exits.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit d96374693d8e34ac3b521eef8395895f37224e7e)
`moq import` read stdin into an empty `BytesMut`, which offers 64 bytes per
read, and every tokio stdin read is a blocking-pool round trip. On a loaded
Linux runner that capped the importer near 1 MB/s, so each video keyframe burst
held the audio muxed behind it for hundreds of milliseconds, past the player's
fixed 250 ms delay. Reads now take up to 64 KiB, a default Linux pipe.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit cbfaa4403622c8a7d1dc87ecff75dfffdc4fcf2b)
The native player's window waited only on Ctrl-C, so a supervisor's SIGTERM
killed it on the default action instead of closing the window. Wait on the
shared `shutdown_signal`, which the stages already use, and cover it with a
real SIGTERM in an isolated nextest process.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 94c18a106778988f0ae2d71f7555b5274f44fe54)
… codec is missing

A browser can ship one half of the audio codec pair, such as AudioDecoder
without AudioEncoder. The polyfill replaces only what is missing, so
EncodedAudioChunk and AudioData stay the browser's own classes while the encoder
or decoder is libav's, and libav is handed instances it cannot read.

The polyfilled half now converts a native instance before using it: an
EncodedAudioChunk is copied into a libav one, and an AudioData goes through
AudioData.fromNative and is released once the encoder has read it. An instance
that is already libav's passes straight through, so the case where both halves
are polyfilled is untouched.

The test drives the bridging with stand-in classes rather than loading the wasm
build.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 7b209ad0d7eb3415a5f2f3ae1b3437034aa96b28)
A group that exceeds the subscription max age while content is unread failed with
a bare `Error`, so a JS publisher reset its stream with code 0 (INTERNAL) while
the Rust publisher sends OLD. A subscriber could not tell a group the publisher
dropped from an internal failure, and a window consumer that resyncs from
dropped groups treated it as fatal.

Fail the group with `Stream(StreamCode.Old)` instead. No new export: a local
reader and a peer's reset now read the same error.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 3d379ac9b79f44f12d2863b296bd0533b6224a40)
A PES carries one PTS and the importer derives the timestamp of every later frame
in that PES by adding the frame's sample duration. It added that duration in the
PES timescale, so each frame rounded down to a whole 90 kHz tick. A 44.1 kHz AAC
frame lasts 1024/44100 s, or 2089.795918... ticks, so almost 8.8 us was dropped
per frame and the error accumulated until the next explicit PES anchor.

The addition now happens in a timescale that holds both clocks exactly, the
least common multiple of the PES scale and the sample rate, so the fractional
remainder carries into the next frame instead of being discarded.

This changes the timestamp values the importer emits, but no wire format.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit b00a1211ee90f90b096d82fa668e70efeda38969)
…uilt

The audio encoder merges the decoder description onto the exact catalog config
object it was reported for. A rebuilt encoder (an unmute, a device replugged)
reports the same bytes against a fresh object, which is an equal value and so no
notification at all, and the rendition returned to the catalog without the
description a decoder initializes from. Force the notification.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 5cfdd5b6d1e23a3f3102670ce0008f0771bc2d7e)
A browser only starts handing a device back at `stop()`, and a run's cleanup is
not ordered against the next run's `getUserMedia`. Hiding a camera or microphone
while an attempt was still in flight and showing it again asked for a device the
page had not let go of yet. The next attempt now waits for the cancelled one to
be stopped.

Camera and Microphone each carried the same acquire-and-stop block, so it moves
into `Retry.open`.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 2bb370ff579e3b42676d0a3ba367ab81df200f50)
The warm rejoin test only ever parked a finished edge group. A front can also
park a track whose newest group the publisher has not finished, and a rejoining
reader must still be served from after the gap, not from that group's stale
copy. Run every version with the edge open as well as finished.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 9f92935f0346f6cd6073a5496a58672576ce8cff)
…'s catalog

A reader holding a group that its route never finishes gives it up once the next
route's content makes it stale, whether the group was continued across a switch or
not, and keeps it while the successor is inside the budget. A second front with no
copy of its own reads a finished catalog the first front resumed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 2ba94ec41e9680289d273281f5eb2ac2614aebf5)
The capture closed its AudioContext without telling its processor to stop, which
in Chromium keeps the closed context, and every node in it, alive for as long as
a processor in it has not stopped.

The capture processor now runs on until its input is cut, since Chromium ends a
processor that returned false at the first quantum after that without calling it
again, and then reports `stopped`. The capture closes a running context once every
processor built in it has said so, and one that is not running at once.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 095e72b2dd8d3384a23ec6db03bc788636a2fa5f)
…pped

Chromium keeps a closed AudioContext, and every node in it, for as long as one
of its processors has not stopped, and a processor only stops in a quantum its
context renders. The decoder closed the context straight after posting `close`
to the node, so every detach and every rate change left one context and one
worklet node in the page's heap (Blink AudioHandlers 4 -> 19 over 5 cycles, with
and without the worker, isolated or not).

The render processor now reports `stopped` on the node's own port in the quantum
that ends it, and the decoder closes a running context once every processor
built in it has said so. A context that is not running renders no such quantum,
so it is still closed at once, as is one that stops running or whose processor
fails while it waits.

The nodes are built inside the context's own run, so a teardown cancels their
module loads and tells their processors to stop before it asks for the close.

Restores fork commit 6b25efc on the re-ported decoder.

Public API: `Watch.Audio` unchanged (the new `Stopped` message is internal to
the render worklet's port). Wire: none.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The player hands its `enabled` to the decoder as `attached`, which is what
releases the audio context when the element leaves the document, and a mute
clears the download without it. Nothing pinned either.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

2 participants