Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/lib/rs/hang.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ the live edge to play: it skips groups that fall past `max`, and starts at the
group covering the live edge less `min` (your playout delay), plus a rendition's
catalog `warmup` passed to `with_warmup`, waiting up to that long for it when the
newest group arrives first. Both default to zero, which starts at the newest
group at once; `max` never moves the start.
group at once. A backlog that landed before the first read starts within `max`
of the newest content, keeping the group covering the live edge less `min` and
the warmup.
[`moq-video`](/lib/rs/moq-video) and [`moq-audio`](/lib/rs/moq-audio) publish
from a device. Examples:
[`video.rs`](https://github.com/moq-dev/moq/blob/main/rs/hang/examples/video.rs)
Expand Down
2 changes: 1 addition & 1 deletion js/hang/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ How to update your code for each breaking change, newest first.

`ConsumerProps.maxDelay` is `delay: GetterInit<Container.Delay>`, where `Delay` is `{ min?: Milli; max?: Milli | null }` and an omitted field is zero.
Replace `maxDelay: d` with `delay: { max: d }`, or derive it from a signal. `max: null` is no limit.
`min` is the playout delay: the consumer starts at the group covering the live edge less `min` plus any `warmup`, waiting for it when the newest group arrives first. `max` never moves the start.
`min` is the playout delay: the consumer starts at the group covering the live edge less `min` plus any `warmup`, waiting for it when the newest group arrives first. Before the first read, a backlog that already landed starts at the first group whose first frame is within `max`, plus the warmup, of the newest content, keeping the group covering the live edge less `min` and the warmup.

### The catalog rendition cap is removed

Expand Down
89 changes: 89 additions & 0 deletions js/hang/src/container/consumer.skips.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,92 @@ for (const count of [1, 16, 256]) {
}
});
}

// Pairs `rs/moq-mux`'s `a_buffered_backlog_starts_within_the_budget`: a backlog that lands whole before
// the first read starts at the first group whose first frame is within the budget of the newest one.
// Five one-second groups of ten frames and a one-frame sixth at 5 s, with a 1.5 s budget, start at the
// 4 s group, whether the sixth is open or finished.
for (const open of [true, false]) {
test(`a buffered backlog starts within the budget (sixth group ${open ? "open" : "finished"})`, async () => {
const warn = spyOn(console, "warn").mockImplementation(() => {});
const track = new Track.Producer("backlog");
const consumer = new Consumer(track.subscribe({ maxDelay: Milli(30_000) }), {
format: new Format("data"),
delay: { max: Milli(1500) },
});
const frame = (micros: number) => ({ payload: Varint.encode(micros), timestamp: Time.Timestamp.now() });
try {
for (let g = 0; g < 5; g++) {
const group = track.createGroup(g);
for (let f = 0; f < 10; f++) group.writeFrame(frame(g * 1_000_000 + f * 100_000));
group.finish();
}
const last = track.createGroup(5);
last.writeFrame(frame(5_000_000));
if (!open) last.finish();
while (consumer.buffered.peek().at(-1)?.end !== 5000) await consumer.buffered.changed();

const read: number[] = [];
for (let i = 0; i < 11; i++) {
const next = await consumer.next();
if (next?.kind !== "frame") throw new Error(`unexpected read: ${JSON.stringify(next)}`);
read.push(next.frame.timestamp);
}
const expected = [...Array.from({ length: 10 }, (_, f) => 4_000_000 + f * 100_000), 5_000_000];
expect(read).toEqual(expected);
} finally {
consumer.close();
track.finish();
track.close();
warn.mockRestore();
}
});
}

// The start waits on the next group's first frame, which may land within the budget, rather than
// dropping that group. Here the fifth group (4 s) arrived with its frames still in flight, so the start
// keeps the fourth and plays on into the fifth. Rust's
// `a_backlog_start_waits_on_a_successor_without_frames` pairs this case.
test("a backlog start waits on a successor without frames", async () => {
const warn = spyOn(console, "warn").mockImplementation(() => {});
const track = new Track.Producer("backlog");
const consumer = new Consumer(track.subscribe({ maxDelay: Milli(30_000) }), {
format: new Format("data"),
delay: { max: Milli(1500) },
});
const frame = (micros: number) => ({ payload: Varint.encode(micros), timestamp: Time.Timestamp.now() });
const frames = (g: number) => Array.from({ length: 10 }, (_, f) => g * 1_000_000 + f * 100_000);
const read: number[] = [];
const readN = async (n: number) => {
for (let i = 0; i < n; i++) {
const next = await consumer.next();
if (next?.kind !== "frame") throw new Error(`unexpected read: ${JSON.stringify(next)}`);
read.push(next.frame.timestamp);
}
};
try {
for (let g = 0; g < 4; g++) {
const group = track.createGroup(g);
for (const micros of frames(g)) group.writeFrame(frame(micros));
group.finish();
}
const fifth = track.createGroup(4);
// The fifth group's frames left before the sixth's, though they land after it.
const sent = Time.Timestamp.now();
const last = track.createGroup(5);
last.writeFrame(frame(5_000_000));
last.finish();
while (consumer.buffered.peek().at(-1)?.end !== 5000) await consumer.buffered.changed();

await readN(10);
for (const micros of frames(4)) fifth.writeFrame({ payload: Varint.encode(micros), timestamp: sent });
fifth.finish();
await readN(11);
expect(read).toEqual([...frames(3), ...frames(4), 5_000_000]);
} finally {
consumer.close();
track.finish();
track.close();
warn.mockRestore();
}
});
20 changes: 16 additions & 4 deletions js/hang/src/container/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export interface Delay {
* late group is waited for. A missing sequence also expires this much monotonic time after
* the first group past it arrived, even when the next group is a marker on a paused track.
* The local half of the subscription's `maxDelay`; both measure the same budget, one on the wire
* and one as frames are read. It bounds lateness only: it never moves the start.
* and one as frames are read. It bounds a join's lateness too: a backlog that landed before the
* first read starts at the first group whose first frame is within it, plus any warmup, of the
* newest content, though the start keeps the group covering the live edge less `min` and the warmup.
*/
max?: Milli | null;
}
Expand Down Expand Up @@ -511,11 +513,21 @@ export class Consumer {

const age = max - min;
if (age <= threshold) break;
// Until the reader warms, a group may cover the start's reach though it began before it: it is
// stale only once its successor starts a whole budget behind the newest content.
// Until the reader warms, a group may cover the start's reach though it began before it.
if (this.#warming()) {
const nextStart = this.#groups[1].start;
if (nextStart === undefined || max - nextStart < threshold) break;
if (nextStart === undefined) break;
if (this.#edge === undefined) {
// Before the first item, a backlog that landed whole starts within the budget, so only
// the group covering the live edge less the reach is kept: one whose successor starts
// past that point. Rust's start skip, in `Consumer::poll_event_once`, measures the same.
const target = this.#startTarget(this.#reach(this.#delay.peek()));
if (target !== undefined && nextStart > target) break;
} else if (max - nextStart < threshold) {
// Once reading began, it is stale only once its successor starts a whole budget behind
// the newest content.
break;
}
}

this.#groups.shift();
Expand Down
1 change: 0 additions & 1 deletion quest/m1/cut-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ leaving JS-only redesigns of `js/net` to [rs2ts](/quest/m2/rs2ts-js.md).

## Required

- [Rust and JS skip a backlog by the same measure](/quest/m1/cut-audit/catalog-parity.md) - a backlog join starts at the same group in every player
- [Text and data sections keep a prototype-named ID](/quest/m1/cut-audit/catalog-proto-ids.md) - text and data entries keep the ID JS's `z.record` drops

## Related
Expand Down
34 changes: 0 additions & 34 deletions quest/m1/cut-audit/catalog-parity.md

This file was deleted.

1 change: 1 addition & 0 deletions rs/moq-mux/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `container::Consumer` no longer plays a backlog that landed before its first read from the oldest group: until the first item, the start moves past each group whose first frame trails the newest content by more than the max delay plus the warmup, as `@moq/hang`'s consumer does, keeping the group covering the live edge less `Delay::min` and the warmup. A join starts at the same group in Rust and the browser. Once reading begins, only a blocking group is skipped, as before.
- fMP4 import applies each track's edit list to its frame timestamps and drops the samples before the edit, such as AAC priming, along with the video samples decoding from a dropped sync sample, and a passthrough init no longer carries the `edts`. A consumer that offsets AAC priming itself must stop, or it shifts the track twice. An edit list it can't reduce to one shift (several media edits, or a rate other than 1) is refused with `Error::UnsupportedEditList`.

## [0.10.11](https://github.com/moq-dev/moq/compare/moq-mux-v0.10.10...moq-mux-v0.10.11) - 2026-10-05
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-mux/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ How to update your code for each breaking change, newest first.

`container::Consumer::set_max_delay(Duration)` is `set_delay(Delay)`, and `with_delay(Delay)` is its builder.
`container::Delay { min, max }` defaults to zero for both: `max` (`None` for no limit) is the max delay that `set_max_delay` took, and the subscription still carries it.
`min` is the playout delay. An unfloored consumer starts at the group covering the live edge less `min` plus any `with_warmup`, waiting for it when the newest group arrives first; the max delay never moves the start.
`min` is the playout delay. An unfloored consumer starts at the group covering the live edge less `min` plus any `with_warmup`, waiting for it when the newest group arrives first. Before the first read, a backlog that already landed starts at the first group whose first frame is within the max delay, plus the warmup, of the newest content, keeping the group covering the live edge less `min` and the warmup.
Replace `consumer.set_max_delay(d)` with `consumer.set_delay(Delay { max: Some(d), ..Delay::default() })`, and set `min` to your playout delay. Call `with_warmup` before `with_delay`.

### Compression moves to the track
Expand Down
Loading