diff --git a/js/watch/src/video/decoder.test.ts b/js/watch/src/video/decoder.test.ts index 13747c0f444..c0a03b3c8db 100644 --- a/js/watch/src/video/decoder.test.ts +++ b/js/watch/src/video/decoder.test.ts @@ -1226,6 +1226,73 @@ describe("Decoder stalls", () => { } }); + it("holds the last picture through a declared end without a stall", async () => { + const { clock, feeds, playback, stalls, feedback, close } = await cold(); + try { + feeds.push(0, sample(0n, 0)); + for (let ms = 100; ms <= 2000; ms += 100) { + await clock.advance(100); + feeds.push(0, sample(0n, ms * 1000, false)); + await microtasks(); + } + // The publisher ends the media, and the last picture holds well past the buffering timeout. + feeds.push(0, marker(0n, 2_100_000)); + for (let i = 0; i < 30; i++) await clock.advance(100); + expect(playback.decoder.out.frame.peek()?.timestamp).toBe(2_000_000); + expect(playback.decoder.out.stalled.peek()).toBe(false); + expect(stalls()).toBe(0); + expect(feedback()).toBe(0); + } finally { + await close(); + } + }); + + it("a declared end clears a stall already raised and stops its stalled time", async () => { + const { clock, feeds, playback, stalls, feedback, close } = await cold(); + const stalled = () => playback.decoder.out.stats.peek()?.stalled ?? 0; + try { + feeds.push(0, sample(0n, 0)); + for (let ms = 100; ms <= 2000; ms += 100) { + await clock.advance(100); + feeds.push(0, sample(0n, ms * 1000, false)); + await microtasks(); + } + // The frames stop, and the last picture freezes into a stall. + for (let i = 0; i < 16; i++) await clock.advance(100); + expect(playback.decoder.out.stalled.peek()).toBe(true); + expect(stalls()).toBe(1); + expect(stalled()).toBe(0); + + // The publisher then declares the end: the stall closes and its time stops growing. + feeds.push(0, marker(0n, 2_100_000)); + await microtasks(); + expect(playback.decoder.out.stalled.peek()).toBe(false); + const closed = stalled(); + expect(closed).toBeGreaterThan(0); + for (let i = 0; i < 30; i++) await clock.advance(100); + expect(playback.decoder.out.stalled.peek()).toBe(false); + expect(stalled()).toBe(closed); + expect(stalls()).toBe(1); + expect(feedback()).toBe(1); + } finally { + await close(); + } + }); + + it("a declared end before the first picture ends startup buffering", async () => { + const { feeds, playback, stalls, close } = await cold(); + try { + expect(playback.decoder.out.stalled.peek()).toBe(true); + feeds.push(0, marker(0n, 0)); + await microtasks(); + expect(playback.decoder.out.frame.peek()).toBeUndefined(); + expect(playback.decoder.out.stalled.peek()).toBe(false); + expect(stalls()).toBe(0); + } finally { + await close(); + } + }); + it("clears the buffering state while disabled", async () => { const { playback, close } = await cold(); try { diff --git a/js/watch/src/video/decoder.ts b/js/watch/src/video/decoder.ts index 39be38bbbd2..8042e3b3829 100644 --- a/js/watch/src/video/decoder.ts +++ b/js/watch/src/video/decoder.ts @@ -42,7 +42,8 @@ type Selection = { kind: "none" } | { kind: "selected"; rendition: Rendition } | // One run of the active rendition's playback. A poster may show while it starts, and only a picture // that played and then froze is a stall. -type Playback = "starting" | "playing" | "stalled"; +// A picture held through the publisher's declared end is no stall either. +type Playback = "starting" | "playing" | "ended" | "stalled"; /** Signals the decoder reads. */ export type DecoderInput = { @@ -456,6 +457,13 @@ export class Decoder { return; } + // After the publisher's declared end no picture is coming, whether one shows or not. + const active = effect.get(this.#active); + if (active && effect.get(active.ended) !== undefined) { + this.#out.stalled.set(false); + return; + } + const frame = effect.get(this.#out.frame); if (!frame) { this.#out.stalled.set(true); @@ -463,7 +471,6 @@ export class Decoder { } this.#out.stalled.set(false); - effect.timer(() => { this.#out.stalled.set(true); }, Nano.fromMilli(BUFFERING)); @@ -483,6 +490,10 @@ export class Decoder { playback.set("starting"); return; } + if (inner.get(active.ended) !== undefined) { + playback.set("ended"); + return; + } playback.set("playing"); inner.timer(() => playback.set("stalled"), Nano.fromMilli(BUFFERING)); }); @@ -604,8 +615,9 @@ class DecoderTrack { // A hole or timeline restart makes the next decoded frame decide whether the codec resets. #resetPending = false; - // A declared endpoint stays in force through holes until a later group starts a new timeline. - #endGroup?: bigint; + // The group the publisher declared the media ends with. It stays in force through holes until a + // later group starts a new timeline. + readonly ended = new Signal(undefined); // The newest consumer reading this track, whose estimate a replacement continues. The predecessor // is only held until the first one opens. @@ -958,9 +970,11 @@ class DecoderTrack { if (read.kind === "gap") { if (latest !== undefined) this.#resetPending = true; } else if (read.kind === "end") { - if (latest === undefined || read.group >= latest) this.#endGroup = read.group; - } else if (this.#endGroup !== undefined && read.group > this.#endGroup) { - this.#endGroup = undefined; + if (latest === undefined || read.group >= latest) this.ended.set(read.group); + } else { + const ended = this.ended.peek(); + if (ended === undefined || read.group <= ended) return; + this.ended.set(undefined); this.#onBreak(read.group); } } @@ -1177,6 +1191,11 @@ class Rendition { return this.min.spread; } + // The group the publisher declared the clock-driving decoder's media ends with. + get ended(): Getter { + return this.min.ended; + } + // Show the max-delay picture when it is at or past the min-delay one, so it wins ties, else the // min-delay picture. Only pictures read from `start` on, the min-delay decoder's timeline, are // candidates: one held from before a restart neither shows nor sets the floor. Not `caughtUp`: its diff --git a/quest/m1/explicit-state/README.md b/quest/m1/explicit-state/README.md index 02506d23ad4..d5d5b8aedd6 100644 --- a/quest/m1/explicit-state/README.md +++ b/quest/m1/explicit-state/README.md @@ -76,7 +76,6 @@ which collapses that state and waits on [Drop set](/quest/m1/drop-set.md). - [Track and group end-of-life](/quest/m1/explicit-state/track-end.md) - moq-net's track and group outcomes are one enum each, in Rust and JS - [moq-net phase data](/quest/m1/explicit-state/net-phases.md) - moq-net's session and subscription state machines keep each phase's data in its variant - [moq-mux and moq-gst lifecycles](/quest/m1/explicit-state/mux-gst.md) - export sources, TS and fMP4 export tracks, and gst pads are explicit state -- [Video's declared-end freeze is not a stall](/quest/m1/explicit-state/video-declared-end.md) - video holding its last picture through a declared end counts no stall, like audio's declared silence ## Related diff --git a/quest/m1/explicit-state/video-declared-end.md b/quest/m1/explicit-state/video-declared-end.md deleted file mode 100644 index 88f31eaae8d..00000000000 --- a/quest/m1/explicit-state/video-declared-end.md +++ /dev/null @@ -1,20 +0,0 @@ -# [XS] Video's declared-end freeze is not a stall - -## Goal - -`` doesn't count a stall while video holds its last picture -through a publisher's declared end, as audio already doesn't for a declared -silence. The stall count, stalled time, and the echo `stalls`/`stalled` -feedback agree between audio and video. - -## Plan - -Planned 2026-11-07 (maintainer, /quest-complete), a follow-up of -[moq-dev/moq#8209](https://github.com/moq-dev/moq/pull/8209), which made -watch count a stall only while a rendition plays. It left this one case as -on `main`: a picture held through a declared end for longer than the 500 ms -buffering timer still counts as a stall. Give video's playback state a -declared-end phase, as audio's handles a declared silence, so the buffering -timer doesn't run there. Test a declared end held past 500 ms. - -Public API: none. Wire: none.