diff --git a/js/watch/src/audio/decoder.test.ts b/js/watch/src/audio/decoder.test.ts index d2028a5eebe..8cacc93fec7 100644 --- a/js/watch/src/audio/decoder.test.ts +++ b/js/watch/src/audio/decoder.test.ts @@ -611,6 +611,27 @@ for (const cmaf of [false, true]) { }); } +it("rejoins the clock after decoding returns from absence", async () => { + const playback = await play(Duration.millis(100)); + const reanchor = spyOn(playback.sync, "reset"); + try { + await playback.play(12); + const [ring] = playback.rings(); + expect(ring.read([new Float32Array(128), new Float32Array(128)])).toBe(128); + playback.decoding.set(false); + await microtasks(); + playback.decoding.set(true); + await microtasks(); + expect(playback.resets()).toBe(1); + expect(ring.length).toBe(0); + expect(reanchor).not.toHaveBeenCalled(); + await playback.play(); + expect(playback.rings()).toEqual([ring]); + } finally { + playback.close(); + } +}); + describe("Decoder across a broadcast disable", () => { it("releases the graph when its broadcast is disabled and rebuilds on return", async () => { const playback = await play(Duration.millis(100)); diff --git a/js/watch/src/audio/decoder.ts b/js/watch/src/audio/decoder.ts index 2a07d2f0383..242c438c17d 100644 --- a/js/watch/src/audio/decoder.ts +++ b/js/watch/src/audio/decoder.ts @@ -576,21 +576,26 @@ export class Decoder { }); // Another broadcast (a new name, or a republish) brings its own timeline, which a ring and a - // clock anchored on the previous one would discard as already played. A return to the same - // instance keeps the anchor, so the relay's redelivered last group is still dropped as old. + // clock anchored on the previous one would discard as already played. // Every handle to one instance shares `closed`, so it identifies the instance where the // handle itself does not. if (this.#instance !== undefined && this.#instance !== active.closed) { this.sync.reset(); this.reset(); + } else if (this.#instance !== undefined && phase.kind === "stopped") { + // The picture returns at the live edge. Re-join audio to that clock immediately, + // rather than stretching the retained ring's lag back over several seconds. A + // running rendition swap keeps its seamless handover. + this.reset(); } this.#instance = active.closed; // The ring outlives this effect (it's keyed on the sample rate, channel count, and mode), so a - // replacement subscription on the same broadcast (a rendition swap, a return from an absence) - // inherits whatever its predecessor decoded. Samples are timestamp indexed, so the replacement - // overwrites the slots it lands on, but a publisher writing ahead of real-time leaves seconds - // of tail beyond them. Drop that once the replacement's first frame says where it starts. + // replacement subscription on the same broadcast (a rendition swap, or a fallback that stays + // running) inherits whatever its predecessor decoded; a return from an absence was reset above. + // Samples are timestamp indexed, so the replacement overwrites the slots it lands on, but a + // publisher writing ahead of real-time leaves seconds of tail beyond them. Drop that once the + // replacement's first frame says where it starts. this.#handover.opened(); effect.run((run) => { diff --git a/quest/m0/interop-green/README.md b/quest/m0/interop-green/README.md index 6412b9ad603..26b163b9ade 100644 --- a/quest/m0/interop-green/README.md +++ b/quest/m0/interop-green/README.md @@ -1,4 +1,4 @@ -# Interop and Video pass on main +# [XS] Interop and Video pass on main ## Goal @@ -11,7 +11,7 @@ so it only needs to stay green. ## Waiting - moq-dev/moq: the next scheduled Interop run on `main` passes, once the - [resumed-audio child](/quest/m0/interop-green/resume-sync.md) lands + [resumed-audio fix](https://github.com/moq-dev/moq/pull/8635) lands ([moq-dev/moq#8572](https://github.com/moq-dev/moq/pull/8572), the max-age fix, merged 2026-11-12). Check with `gh run list --repo moq-dev/moq --workflow interop.yml --event schedule`, @@ -184,7 +184,7 @@ Scheduled run picture by about 1.7 s. [moq-dev/moq#8507](https://github.com/moq-dev/moq/pull/8507) keeps audio that trails the clock up to its 2 s stretch bound and plays it faster, and a resume keeps the ring it had. Fixed by the child - [resumed audio snaps to the clock](/quest/m0/interop-green/resume-sync.md), + [resumed audio snaps to the clock](https://github.com/moq-dev/moq/pull/8635), decided 2026-11-12 (maintainer) to snap to the live picture rather than stretch the lag back. diff --git a/quest/m0/interop-green/resume-sync.md b/quest/m0/interop-green/resume-sync.md deleted file mode 100644 index a3715a23740..00000000000 --- a/quest/m0/interop-green/resume-sync.md +++ /dev/null @@ -1,26 +0,0 @@ -# [S] Resumed audio snaps to the clock - -## Goal - -A viewer that pauses and resumes hears its audio in sync with the picture from the first frame, as it did before [moq-dev/moq#8507](https://github.com/moq-dev/moq/pull/8507). So `just test media`'s pause and rejoin steps pass on every run, and a resumed viewer is not seconds behind for the stretch to catch up. Audio that falls behind because of network delay still catches up by playing faster; that is #8507's stretch and stays. - -Not in scope: the JS max-age expectation ([#8572](https://github.com/moq-dev/moq/pull/8572)) and the `go -> python` media cell. - -## Plan - -Found by the triage of scheduled Interop run [43260674067](https://github.com/moq-dev/moq/actions/runs/43260674067) (2026-11-12, head e9c6df852). Its `Media output and lifecycle` step failed on the pause case: `audio tone: after resume: 70/81 samples` in CI, and locally `audio/video sync: after resume: 0/79 samples within 200ms, median skew 600ms`. The 11-11 run, before #8507, passed that step. - -Cause: #8507 keeps audio that trails the shared clock by up to the stretch's 2 s bound and plays it faster to catch up (`js/watch/src/audio/ring-buffer.ts` `read`, bound from `js/watch/src/audio/latency.ts` `bound`). Before it, the ring skipped whatever trailed the clock. A return from pause resubscribes to the same broadcast instance, so `js/watch/src/audio/decoder.ts` keeps the predecessor's ring without a join. The resumed picture lands on the live edge, and the audio that trails it by about 1.7 s is stretched back over about 5 s. - -Evidence, `just test media --media-cases pause` in `test/interop/clients/js/media.ts`: - -- `main` at 18fc33ecc: 3 of 4 runs fail the resume sync (median skew 200 ms, or 0 of 79 in sync). -- Parent of #8507 (ac73d9e0b): passes, median skew 0 ms (one run). On a host at load 30, four full `just test media` runs there passed 1, and the other 3 failed only `audio tone` (67 to 70 of 81 samples, the CI signature), never sync; the 11-11 head a4bc922c6 passed 4 of 6, failing the same way. #8507 itself (4262a0691) failed 4 of 4 on sync, median skew 400 to 600 ms after resume. So the CI step can stay red under load after this fix, from a tone flake older than #8507. -- Experiment, not committed: a same-instance resubscribe calls the decoder's `reset()`, so the ring joins the clock again. 4 of 4 runs pass, median skew 0 ms. One full `just test media` run also passed the pause and rejoin steps, then failed the later `live incumbent fallback` case, which was not investigated. - -Decided 2026-11-12 (maintainer): ✅ snap to the live picture. Re-join the ring when a viewer returns from absence on the same instance, so resumed audio lands on the clock the way a tune-in does, and keep the 2 s bound for stalls. Rejected: stretch catch-up with #8507's time-stretch, which plays the lag back over about 5 s and costs the lip sync that #8031 fixed; relaxing the resume assertion to match it, since `js/watch/AGENTS.md` says to judge a player change by its lag first. Check it with `just test media --media-cases pause`. - -Open for the implementer: - -- Scope the re-join to a return from absence. The handover path (`#handover` in `decoder.ts`) also inherits the ring for a rendition swap and a fallback, which should keep their seamless handover. Check the fallback case. -- Native parity: `moq play` pauses through `rs/moq-audio`. Check whether its ring inherits the same way; `just test media` does not cover it. diff --git a/quest/m0/nightly/README.md b/quest/m0/nightly/README.md index 42a03707b87..5c4dd07f667 100644 --- a/quest/m0/nightly/README.md +++ b/quest/m0/nightly/README.md @@ -54,7 +54,7 @@ more children, all in m0. Owned elsewhere: the fuzz build ([moq-dev/moq#8657](https://github.com/moq-dev/moq/pull/8657)), the Python audit ([moq-dev/moq#8648](https://github.com/moq-dev/moq/pull/8648)), the size report's output ([moq-dev/moq#8654](https://github.com/moq-dev/moq/pull/8654)), -the firefox resume ([resume sync](/quest/m0/interop-green/resume-sync.md)), +the firefox resume ([moq-dev/moq#8635](https://github.com/moq-dev/moq/pull/8635)), and the chromium `av_lag` rows ([output latency](/quest/m2/audio-playout/output-latency.md) and [congestion catch-up](/quest/m2/audio-playout/congestion-catch-up.md)). diff --git a/quest/m2/audio-playout/congestion-catch-up.md b/quest/m2/audio-playout/congestion-catch-up.md index e6f45192dcc..76ffef2125d 100644 --- a/quest/m2/audio-playout/congestion-catch-up.md +++ b/quest/m2/audio-playout/congestion-catch-up.md @@ -59,4 +59,4 @@ native in the PR. ## Related -- [Resume sync](/quest/m0/interop-green/resume-sync.md) - snaps resumed audio to the clock, the same rule for a return from absence +- [moq-dev/moq#8635](https://github.com/moq-dev/moq/pull/8635) - snaps resumed audio to the clock, the same rule for a return from absence