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
7 changes: 6 additions & 1 deletion drafts/draft-lcurley-moq-mpegts.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ A publisher MUST NOT record 0x0000 (PAT) or 0x1FFF (null packets), which carry n

`descriptors` are the track's ES-level descriptors from the PMT ({{descriptor}}), in PMT order.

A publisher MUST NOT change an entry's `pid`, `descriptors`, or carriage record in place, so a track name means one elementary stream for its life.
A stream the PMT revises ends its track and continues as a new track under a new name; one the PMT drops leaves `tracks` as its track ends, and a PID listed again later gets a new name too.

`verbatim` and `pesPacket` mark a track carrying an undecoded elementary stream ({{verbatim}}).
An entry MUST NOT carry both, and a consumer MUST refuse a catalog with one that does.
A decoded track MAY appear here too, to preserve its `pid` and `descriptors`.
A consumer MUST ignore an entry with no `verbatim` record, no `pesPacket` record, and no track the catalog describes, so one that predates `pesPacket` drops such a track from the stream it rebuilds.

## programDescriptors
The PMT's program-level descriptors (`program_info`), in PMT order ({{descriptor}}).
The PMT's program-level descriptors (`program_info`), in PMT order ({{descriptor}}), updated in place as the PMT revises them.

## program {#field-program}
The program identity from the PAT:
Expand All @@ -158,6 +161,7 @@ type Program = {
They are the only service-layer fields this document parses; everything else about the program stays inside the opaque `si` tables.

A publisher MUST include `program` when the broadcast came from a transport stream, and omit it otherwise.
A publisher MUST NOT change `transportStreamId` or `programNumber` in place: the carried `si` describes that service, so a source whose PAT names another ends the broadcast.

## si {#field-si}
The standalone service information tables, keyed by the PID they ride on and then by `table_id`:
Expand Down Expand Up @@ -452,6 +456,7 @@ A broadcast demultiplexed from a DVB transport stream: video and audio described
- `verbatim` carries sections only, breaking -00: `framing` is required and `"section"` its only value, and `streamId` is gone. A consumer refuses a -00 catalog with `"pes"` framing or a `verbatim` record without `framing`. A publisher carries an undecoded PES stream as `pesPacket`, and refuses one it cannot carry unaltered.
- A flagged PCR jump on an `m2ts` track follows hang's discontinuity marker rather than a skipped group sequence.
- An `m2ts` track unwraps PCRs from its history, clamps extrapolated object times at a forward discontinuity, and cuts a fallback group after one second. `randomAccess` covers every published group; `muxRate` follows the measured source rate.
- A `tracks` entry is never changed in place: a stream the PMT revises continues under a new name, and one it drops leaves the section. `programDescriptors` follows the PMT; `program`'s `transportStreamId` and `programNumber` do not change.

## draft-lcurley-moq-mpegts-00
{:numbered="false"}
Expand Down
3 changes: 1 addition & 2 deletions quest/m1/catalog-identity-rs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ minting a name where the identity changes and updating in place otherwise:
explicit pad name after caps renegotiation.
- TS AAC/MP2/AC-3 and FLV legacy audio fix the config from the first header
and silently ignore a later change; refuse or mint instead. A PMT that
changes a PID's stream type belongs to
[Live PAT/PMT changes](/quest/m1/ts-reliability/pmt-lifecycle.md).
changes a PID's stream type or descriptors already opens a new track.
- `moq-audio`/`moq-ffi` `set_bitrate` should update the catalog's bitrate.

FLV, fMP4, MKV, HLS import, and `moq-transcode` rungs already comply; keep
Expand Down
8 changes: 5 additions & 3 deletions quest/m1/ts-reliability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ refused means an error or a counted drop.
| DSM-CC types (0x0A to 0x0D), 0x86 without `CUEI` | Today PES-parsed into damage, or dropped uncounted | [routes](/quest/m1/ts-reliability/stream-routes.md) |
| CAT, EMM/ECM, ATSC PSIP, other SI PIDs, unlisted PIDs, TS scrambling | Outside the profile, raw lane; counted when the import reads every program. Today dropped uncounted | [routes](/quest/m1/ts-reliability/stream-routes.md) |
| DVB SI on 0x0010, 0x0011, 0x0012, 0x0014 | Preserved: snapshot track per PID and `table_id` | landed |
| Program identity, program and ES descriptors | Preserved, but captured once | [PMT changes](/quest/m1/ts-reliability/pmt-lifecycle.md) |
| PMT add, remove, retype; PID reuse; PAT changes | Normalized: in place under fresh track names, PMT rebuilt at the next `version_number`; program identity changes refused; a removed program retires, and returns as a new epoch. Today stale tracks on import, refusal or stale PMT on export | [PMT changes](/quest/m1/ts-reliability/pmt-lifecycle.md) |
| Program identity, program and ES descriptors | Preserved: descriptors follow each PMT revision; an identity change refuses | landed |
| PMT add, remove, retype; PID reuse | Normalized without a new epoch: a changed or reused PID ends its track and continues under a fresh name, and the PMT is rebuilt at the next `version_number`. Import landed; today refusal or stale PMT on export | [PMT export](/quest/m1/ts-reliability/pmt-export.md) |
| PAT changes: moved PMT PID, programs added or removed | Normalized: followed; a removed program retires, and returns as a new epoch. Today ignored, or the whole multiplex stops | [PAT changes](/quest/m1/ts-reliability/pat-lifecycle.md) |
| Programs without video | Preserved when the PMT names a PCR PID; refused without one | landed |
| PCR | Normalized: rebased, carried on the first video PID, else audio, else a dedicated PCR-only PID | landed |
| Mux rate, null stuffing | Normalized: re-padded to `muxRate` while the source is CBR | landed |
Expand All @@ -123,7 +124,8 @@ remain with their current quests.

## Required

- [Live PAT/PMT changes](/quest/m1/ts-reliability/pmt-lifecycle.md) - a revised PMT or PAT never leaves a track name meaning other content
- [PMT export](/quest/m1/ts-reliability/pmt-export.md) - a TS export announces each PMT revision at the next `version_number`
- [PAT changes](/quest/m1/ts-reliability/pat-lifecycle.md) - a revised PAT never leaves a broadcast meaning another program
- [Stream routes](/quest/m1/ts-reliability/stream-routes.md) - every PID gets a declared route, and what is not carried is counted
- [Arrival stamps](/quest/m1/ts-reliability/arrival-stamps.md) - frames carry their local arrival time, so a stalled path never lets late frames out
- [Release clock false alarms](/quest/m1/ts-reliability/release-clock-false-alarms.md) - no false jitter leap at a 500 ms delay and no false drift alarm
Expand Down
48 changes: 48 additions & 0 deletions quest/m1/ts-reliability/pat-lifecycle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# [M] Live PAT changes keep programs honest

## Goal

A live TS source whose PAT changes mid-stream keeps every broadcast meaning
one program. A moved PMT PID, a program added, and a program removed or
returning each have one observable outcome: followed, published, retired,
or published as a new epoch. None is silently ignored.

## Plan

What the code does today:

- A PAT naming another PMT PID for the program adds a reassembler but never
drops the old one, and `program.pmtPid` keeps the first.
- `Programs` ignores a program a later PAT adds, without a warning.
- Under `--program all`, a later PAT that removes one program reaches every
per-program `Import`; the removed program's `handle_pat` errors,
`Programs::feed` propagates it, and the whole multiplex ingest stops,
including unrelated programs.
- A PAT naming another `transport_stream_id`, or a single-program import's
PAT naming another program, already refuses the import.

Decided 2026-10-20 by the maintainer:

- A new PMT PID for the same program moves the reassembler and updates
`program.pmtPid`, which the export follows with a new PAT. `Programs`
publishes a program a later PAT adds as its own broadcast, as it does for
the first PAT, rather than ignoring it.
- A later PAT that removes a program retires that program's broadcast: its
tracks finish and it is unannounced, while the other programs carry on.
If the program returns, it publishes a new epoch of its broadcast, never
the retired instance's names for new content. A single-program import
whose selected program leaves the PAT ends, as today.
- Open: a PAT that names a program whose PMT never arrives. Decide whether
the import refuses it or waits, and which clock bounds the wait (found in
[moq-dev/moq#6122](https://github.com/moq-dev/moq/pull/6122)).

Rust: `rs/moq-mux` TS `Import::handle_pat` and `Programs`.

Tests use the generated `fixture::Mux` builder: a PMT PID move, and a
`--program all` MPTS whose PAT adds a program, drops one and later restores
it: the other program runs uninterrupted, and the returning one publishes a
new epoch.

## Related

- [PMT export](/quest/m1/ts-reliability/pmt-export.md) - the export follows a moved PMT PID with a new PAT
52 changes: 52 additions & 0 deletions quest/m1/ts-reliability/pmt-export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# [M] TS export follows a PMT revision

## Goal

A TS export of a broadcast whose layout changes mid-stream announces the
revised layout as an ordinary PMT revision. A track added, retired, or
replaced under a fresh name changes the PMT at the next `version_number`;
nothing else blips.

## Plan

The import already keeps track names honest: a changed `stream_type` or ES
descriptor loop finishes the old track, drops its catalog entry, and opens
a new uniquely named one; a removed stream finishes its track and leaves
the catalog; `programDescriptors` updates in place; a program identity
change refuses.

What the export does today:

- `Export` builds the PAT/PMT once. A track added afterward fails the export
("TS track layout changed after PAT/PMT was emitted"), so every revision
the import publishes ends the export.
- A track that leaves the catalog keeps its PID in the PMT forever, and
`programDescriptors` is read once.
- A switch to another instance already rebuilds the tables at the next
`version_number`.

Decided 2026-10-20 by the maintainer:

- Export rebuilds the PMT at the next `version_number` when the track set
or an entry changes, drops a retired track's PID once its track ends, and
keeps the PCR PID unless its track retires. A TS receiver sees an
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
ordinary PMT revision and a Hang player sees a rendition switch.

A `programDescriptors` change is an entry change too: the PMT carries the
revised `program_info` at the next `version_number`.

Rust: `rs/moq-mux` TS export. Draft
([mpegts](/drafts/draft-lcurley-moq-mpegts.md)): the rebuild section says
how a consumer revises the PMT.

Tests use the generated `fixture::Mux` builder through import and export:
PMT add, remove, retype, descriptor-only change, version rollover (31 to
0), PID reuse after removal, and a program descriptor change, each
asserting the exported PMT's streams and version sequence. Extend the
TSDuck round trip with a generated mid-stream PMT revision so
`compliance.py` checks the rebuilt version sequence in CI.

## Related

- [PAT changes](/quest/m1/ts-reliability/pat-lifecycle.md) - a moved PMT PID reaches the export as a new PAT
- [Hitless TS](/quest/m2/ts-hitless.md) - identical legs must revise their PMT identically
96 changes: 0 additions & 96 deletions quest/m1/ts-reliability/pmt-lifecycle.md

This file was deleted.

4 changes: 0 additions & 4 deletions quest/m1/ts-reliability/stream-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,3 @@ program 2's PIDs, asserting the catalog, the
stats rows (the unlisted PID's row asserted field by field), and an export
round trip of the carried streams. The MPEG-2 video arm also runs the TSDuck
round trip and an FFmpeg decode of the export in `test/ts`.

## Related

- [Live PAT/PMT changes](/quest/m1/ts-reliability/pmt-lifecycle.md) - a revised `stream_type` takes the route this quest declares
20 changes: 17 additions & 3 deletions rs/moq-mux/examples/scte35_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ fn main() -> anyhow::Result<()> {
})
.collect::<anyhow::Result<_>>()?;

// Pass the input packets through; insert the augmented PMT right after the first PMT,
// and splice the cues in at evenly spread positions so each lands on a later PTS.
// Pass the input packets through; insert the augmented PMT right after the first PMT and
// rewrite every later one to match, since a PMT that stops listing the SCTE-35 PID retires
// its track. Splice the cues in at evenly spread positions so each lands on a later PTS.
anyhow::ensure!(
input.len() % 188 == 0,
"input TS length {} is not a multiple of 188",
Expand Down Expand Up @@ -193,9 +194,22 @@ fn main() -> anyhow::Result<()> {
cue_at.len()
);

let first = &packets[pmt_idx];
let mut out = Vec::new();
for (i, p) in packets.iter().enumerate() {
out.extend_from_slice(p);
if i > pmt_idx && pid_of(p) == pmt_pid.as_u16() {
// Only a repeat of the first PMT has its augmented form: a revised PMT, another
// program's section, or a PMT spanning packets would each need its own.
anyhow::ensure!(
p[..3] == first[..3] && p[3] & 0xf0 == first[3] & 0xf0 && p[4..] == first[4..],
"packet {i} on the PMT PID is not a repeat of the first PMT, which this generator cannot rewrite"
);
// The input's own continuity counter, so the rewrite adds no counter error.
out.extend_from_slice(&[p[0], p[1], p[2], (aug_pmt[3] & 0xf0) | (p[3] & 0x0f)]);
out.extend_from_slice(&aug_pmt[4..]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
} else {
out.extend_from_slice(p);
}
if i == pmt_idx {
out.extend_from_slice(&aug_pmt);
}
Expand Down
15 changes: 14 additions & 1 deletion rs/moq-mux/src/container/ts/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ impl Mux {
pcr_pid: u16,
streams: &[(u8, u16, &[u8])],
info: usize,
) -> &mut Self {
self.pmt_at(0, pid, program, pcr_pid, streams, info)
}

/// A [`Self::pmt_with`] at `version_number` `version`.
pub(super) fn pmt_at(
&mut self,
version: u8,
pid: u16,
program: u16,
pcr_pid: u16,
streams: &[(u8, u16, &[u8])],
info: usize,
) -> &mut Self {
let mut descriptors = Vec::new();
while descriptors.len() < info {
Expand All @@ -239,7 +252,7 @@ impl Mux {
]);
body.extend_from_slice(info);
}
self.section(pid, &psi::section(psi::PMT_TABLE_ID, program, 0, 0, 0, &body))
self.section(pid, &psi::section(psi::PMT_TABLE_ID, program, version, 0, 0, &body))
}

pub(super) fn bytes(&self) -> Vec<u8> {
Expand Down
Loading