Skip to content

fix(moq-mux): grow a TS export's audio send-ahead before its clock anchors - #9839

Draft
kixelated wants to merge 2 commits into
mainfrom
quest/m1/ts-export-audio-rate
Draft

kixelated wants to merge 2 commits into
mainfrom
quest/m1/ts-export-audio-rate

Conversation

@kixelated

@kixelated kixelated commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Works on quest/m1/ts-export-audio-rate.md. Draft: the long-delay case is fixed, short delays need a decision.

Summary

A moq export ts that took up a measured rate while its jitter clock was still being acquired found no margin yet, so its audio send-ahead stayed where it was. At the recorded rate the audio then missed decode deadlines. On ffmpeg_ac3.ts with a 2 s delay, the rate arrives at +1.8 s, before the clock anchors.

  • rs/moq-mux/src/container/ts/export.rs: the send-ahead grows freely until the clock anchors (as it already did before the tables). In the first second after the anchor, it grows by the spare seen since the anchor. A pending replacement program reads its own jitter engine, not the active one's.
  • rs/moq-mux/src/jitter.rs: adds Engine::spare_seen, which is the margin, or the least spare so far before a whole second has passed, and None until a frame has a deadline. Buffer::reading becomes crate-visible.

Anchor check (from the 2026-11-26 decision)

The decision was to grow freely until the first release and to check whether the anchor really stays open until then. It doesn't always:

  • An acquisition ends when its first held frame falls due, so for audio alone it anchors at the first release.
  • Once a track starts a new group and every expected track has been heard (a video source), it anchors right away, up to a delay before the first release.

So I gated on the anchor, not the release. After the anchor, the spare measured since then bounds growth.

Public API / wire impact

None (crate-internal).

Validation

  • New an_ffmpeg_audio_source_measured_while_its_clock_is_acquired_keeps_its_audio_on_time: all six ffmpeg_*.ts fixtures, Rate::Measured, delays of 500 ms, 2 s, and 3 s. It drops nothing and pads above the recorded rate. It fails without the fix.
  • Extended the_margin_is_the_least_spare_over_a_second to cover spare_seen.
  • cargo nextest on every container::ts test plus the jitter test: 801 passed.
  • cargo clippy -p moq-mux --all-targets -D warnings and cargo fmt --check are clean. In just check, only rs_cross failed, on this host's toolchain (alloca: LTO requires LLD), unrelated to the diff.
  • A throwaway sweep (100 ms–3 s × Measured/Wait/Given × six codecs) gave the remaining short-delay numbers, now recorded in the quest.

What remains

The quest is rewritten to what's left: short delays (100 ms, and mp2 at 300 ms). There, FFmpeg's ~186 ms PES packing already makes frames late, the spare is negative, and the export fails where a given-rate export only drops frames. Also eac3 at 300 ms drops one frame from the post-second margin cap; this predates this PR. Lifting the cap entirely was tried and drops frames at 500 ms and 1 s, so it's out.

Waiting

  • Maintainer: When a rate is learned mid-stream at a delay too short for the source (frames already miss their deadlines, so the send-ahead cannot grow), what should the export do?
    • Fail loud naming the delay (Recommended) - refuse with an error that the delay is shorter than the source sends ahead, instead of the misleading "raise the multiplex rate"; at these delays an export given the rate drops a third of the audio anyway
    • Grow anyway once frames already miss - grow to what the rate needs when the spare is negative, matching the given-rate export's drops, at the cost of a rule that flips at zero spare
    • Pad above the recorded rate - raise the padded rate to what the capped send-ahead needs, keeping every frame the source delivers on time but departing from the recorded CBR, often several times over

Caused by

  • moq-dev/moq#9636 - bounded mid-stream send-ahead growth by the jitter margin, which is unknown until a second has passed (found by person)

Follow-ups

None; the remainder stays in this quest.

Models

Size: M
Implementer: Claude Code, claude-opus-5-5, unknown (arm A, cohort advisor-2026-11)

🤖 Generated with Claude Code

(Written by Opus 5.5)

…chors

A rate the import measures after the export's tables but before the
jitter clock anchors found no margin yet and grew the send-ahead not at
all, so a slow multiplex missed audio decode deadlines (ffmpeg_ac3.ts at
a 2 s delay). Grow freely until the clock anchors, and use the spare
since the anchor until a whole second has passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A TS export that learns its rate mid-stream keeps its audio on time fix(moq-mux): grow a TS export's audio send-ahead before its clock anchors Nov 28, 2026

This branch has not been deployed

No deployments
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.

1 participant