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
27 changes: 23 additions & 4 deletions drafts/draft-lcurley-moq-mpegts.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ What remains is media in a codec-neutral catalog, plus the signaling a demultipl
| | mpeg2ts packaging | mpegts section |
|:--------|:--------|:--------|
| MoQ track | one per program or multiplex | one per elementary stream |
| Object payload | whole source packets | one media frame, or one verbatim PES payload or section |
| Object payload | whole source packets | one media frame, or one verbatim PES payload, PES packet, or section |
| Packaging | `mpeg2ts` | none defined; media keeps its own |
| Catalog | `mpeg2ts*` members on each track | one `mpegts` root member |
| Relay | caches and drops whole objects | drops and prioritizes per elementary stream |
Expand Down Expand Up @@ -126,6 +126,7 @@ type Track = {
"pid": number,
"descriptors": Descriptor[] | undefined,
"verbatim": Verbatim | undefined,
"pesPacket": PesPacket | undefined,
}
~~~

Expand All @@ -134,9 +135,10 @@ 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.

`verbatim` marks a track carrying an undecoded elementary stream ({{verbatim}}).
`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 neither a `verbatim` record nor a track the catalog describes.
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}}).
Expand Down Expand Up @@ -243,7 +245,22 @@ A publisher SHOULD record it, since strict demultiplexers reject a relabeled PES

Each frame MUST be a keyframe in its own group: a verbatim payload is all-or-nothing.

A verbatim track has no codec, dimensions, or decoder configuration, so a publisher MUST NOT describe it as a media rendition and MUST describe it only by its `tracks` entry.
A track can instead carry each PES whole, header included:

~~~
type PesPacket = {
"streamType": number,
}
~~~

`streamType` is the PMT `stream_type` to re-announce, as for `Verbatim`.
Each frame MUST be exactly one PES packet, from its start code through its payload, with a `PES_packet_length` that matches the frame, or zero only where {{mpeg2}} lets a video stream leave it unbounded.
The `stream_id`, the PTS and DTS when present, and every other header field ride in the frame, with the PTS and DTS on the catalog clock; a PES without a PTS carries none.
The frame's timestamp is the packet's placement: the program clock at its first byte, on the same timeline.
A consumer MUST refuse a frame that is not one well-formed PES packet.
The record is a member beside `verbatim` rather than a `framing` value, so a consumer that predates it ignores the track instead of refusing the catalog.

A verbatim or whole-PES track has no codec, dimensions, or decoder configuration, so a publisher MUST NOT describe it as a media rendition and MUST describe it only by its `tracks` entry, and a consumer MUST refuse a catalog that describes one as both.
Nothing there declares a container, so its frames use hang's `legacy` container ({{hang}}): a varint microsecond timestamp followed by the payload.


Expand Down Expand Up @@ -349,6 +366,7 @@ A consumer rebuilding a transport stream:
- MUST re-emit each track's `descriptors` as its ES-level descriptors, and `programDescriptors` as the PMT's `program_info`.
- MUST re-emit each `si` entry's sections byte-for-byte on that entry's PID, reading them from its track ({{si-track}}), at least as often as its `interval` when declared.
- MUST repacketize each verbatim track per its `framing` and `streamType`, using `streamId` when recorded.
- MUST packetize each `pesPacket` frame unchanged on its track's PID, its first byte going out no earlier than the frame's timestamp, and SHOULD send it as close to that as the multiplex allows.
- SHOULD pad the output with null packets to `muxRate` when present, so the rebuilt stream is constant-rate again; a source that exceeds the rate is passed through rather than delayed or dropped.

With no `program` the consumer synthesizes an identity, and SHOULD then omit any carried `si`, which describes a program that no longer exists.
Expand Down Expand Up @@ -423,6 +441,7 @@ A broadcast demultiplexed from a DVB transport stream: video and audio described
{:numbered="false"}

- Added the `m2ts` section, a transport stream carried whole, with its mapping onto MSFTS; the comparison uses MSFTS's `mpeg2ts` names.
- Added the `pesPacket` record: each frame one whole PES packet, timestamped with its placement. A consumer that predates it drops the track rather than refusing the catalog.

## draft-lcurley-moq-mpegts-00
{:numbered="false"}
Expand Down
1 change: 0 additions & 1 deletion quest/m1/ts-reliability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ remain with their current quests.

- [Plan: semantic fidelity](/quest/m1/ts-reliability/fidelity.md) - explicit profiles and PMT lifecycle contracts produce implementation quests
- [Raw stream types](/quest/m1/ts-reliability/stream-type.md) - unknown stream types survive export instead of failing the PMT
- [Whole-PES export](/quest/m1/ts-reliability/pes-export.md) - export writes `pesPacket` tracks byte for byte at their placement
- [Whole-PES import](/quest/m1/ts-reliability/pes-import.md) - private PES travels whole at its source placement, a missing PTS stays missing, and the `pes` framing is deleted
- [Section placement](/quest/m1/ts-reliability/section-placement.md) - sections share the PCR placement clock instead of the video PTS
- [Loss and recovery tests](/quest/m1/ts-reliability/recovery.md) - actual MoQ omissions exercise reacquisition and unaffected tracks
Expand Down
73 changes: 0 additions & 73 deletions quest/m1/ts-reliability/pes-export.md

This file was deleted.

6 changes: 1 addition & 5 deletions quest/m1/ts-reliability/pes-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ round-trip test first.
header, so rebasing leaves it valid; assert that with a CRC fixture), extension data, stuffing, and the special stream-ID forms
that have no optional header. Each PES keeps its own stream_id.
- **Catalog.** The entry records `pid`, `descriptors` and the `pesPacket`
member that [export](/quest/m1/ts-reliability/pes-export.md) reads, and
member that export reads, and
no `verbatim` record. A published exporter ignores such an entry and
silently leaves the stream out of its TS; that is the accepted cost.
- **Refusal.** A PES carrying a clock this does not rebase (ESCR, a
Expand Down Expand Up @@ -96,7 +96,3 @@ Update `drafts/draft-lcurley-moq-mpegts.md` (the importer writes
`pesPacket` and states what it refuses; `framing` is `"section"` only and
required, `streamId` removed, changelog -01 noting the break with -00) and
the TS lines of `doc/bin/cli.md` and `doc/lib/rs/moq-mux.md`.

## Required

- [Whole-PES export](/quest/m1/ts-reliability/pes-export.md) - export reads `pesPacket` before import writes it
3 changes: 1 addition & 2 deletions quest/m1/ts-reliability/section-placement.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ derives from the PCR in `SectionStream`, replacing `last_pts`/`start_pts`
and the edge clamp in `SectionStream::emit`. SCTE-35 splice times live in
the section bytes and keep their `pts_adjustment` rebasing.

Export treats the new timestamp the way
[whole-PES export](/quest/m1/ts-reliability/pes-export.md) treats
Export treats the new timestamp the way it treats
`pesPacket`: an arrival time on the same placement path, so the first
section byte goes out at the placement and never earlier, with the TS
header and pointer field just before it (not `Track::push`'s decode
Expand Down
55 changes: 51 additions & 4 deletions rs/moq-mux/src/container/ts/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//!
//! The `mpegts` section carries everything needed to faithfully re-mux a broadcast
//! back to MPEG-TS that doesn't belong in the codec-neutral media configs: one
//! entry per track (its original PID and PMT descriptors), a `verbatim` carriage
//! record for every elementary stream we don't decode (SCTE-35, teletext, DVB
//! subtitles, private data, ...), the program-level PMT descriptors, the program
//! entry per track (its original PID and PMT descriptors), a `verbatim` or
//! `pesPacket` carriage record for every elementary stream we don't decode (SCTE-35,
//! teletext, DVB subtitles, private data, ...), the program-level PMT descriptors, the program
//! identity ([`Program`]), and the standalone SI table map ([`SiEntry`]).
//! Demuxed media tracks keep their codec config in the base `video`/`audio`
//! sections; only their MPEG-TS identity lands here. A constant-rate source also
Expand Down Expand Up @@ -86,7 +86,8 @@ pub(super) fn si_interval(table_id: u8) -> Option<Duration> {
#[non_exhaustive]
pub struct Mpegts {
/// Per-track MPEG-TS info, keyed by MoQ track name. Media tracks record their
/// PID and PMT descriptors; undecoded tracks add a [`Verbatim`] carriage record.
/// PID and PMT descriptors; undecoded tracks add a [`Verbatim`] or [`PesPacket`]
/// carriage record.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub tracks: BTreeMap<String, Track>,

Expand Down Expand Up @@ -306,6 +307,11 @@ pub struct Track {
/// Present when the stream is carried verbatim (not decoded into `video`/`audio`).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub verbatim: Option<Verbatim>,

/// Present when each frame is one whole PES packet, sent at its timestamp. An entry
/// carries this or [`Self::verbatim`], never both.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pes_packet: Option<PesPacket>,
}

impl Track {
Expand All @@ -315,6 +321,7 @@ impl Track {
pid,
descriptors: Vec::new(),
verbatim: None,
pes_packet: None,
}
}
}
Expand Down Expand Up @@ -352,6 +359,29 @@ impl Verbatim {
}
}

/// Carriage record for an undecoded elementary stream whose frames are whole PES packets.
///
/// Each frame is one complete PES packet, start code through payload, with its PTS, DTS
/// and every other header field already on the catalog clock. Its timestamp is the
/// packet's placement: the program clock at its first byte, which export sends it at.
/// A member beside [`Verbatim`] rather than a [`Framing`], so a consumer that predates it
/// ignores the track instead of refusing the catalog.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct PesPacket {
/// PMT `stream_type` to re-announce (0x06 private PES, ...). The `stream_id` rides
/// in each packet.
pub stream_type: u8,
}

impl PesPacket {
/// A new whole-PES carriage record of the given `stream_type`.
pub fn new(stream_type: u8) -> Self {
Self { stream_type }
}
}

/// How a verbatim stream's payload is framed on the wire, so export can repacketize it.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -464,6 +494,7 @@ mod test {
data: Bytes::from_static(b"eng\x00"),
}],
verbatim: None,
pes_packet: None,
},
);
// A verbatim SCTE-35 track.
Expand All @@ -473,6 +504,17 @@ mod test {
pid: 0x102,
descriptors: Vec::new(),
verbatim: Some(Verbatim::new(0x86, Framing::Section)),
pes_packet: None,
},
);
// A whole-PES private data track.
mpegts.tracks.insert(
"0.ts".to_string(),
Track {
pid: 0x103,
descriptors: Vec::new(),
verbatim: None,
pes_packet: Some(PesPacket::new(0x06)),
},
);
mpegts.program_descriptors.push(Descriptor {
Expand All @@ -488,6 +530,10 @@ mod test {
json.contains("\"muxRate\":2500000"),
"mux rate is a bare integer: {json}"
);
assert!(
json.contains("\"pesPacket\":{\"streamType\":6}"),
"the whole-PES member is camelCase: {json}"
);

let parsed: Ext = serde_json::from_str(&json).unwrap();
assert_eq!(parsed.mpegts, mpegts, "mpegts section round-trips");
Expand Down Expand Up @@ -654,6 +700,7 @@ mod test {
data: Bytes::from_static(b"CUEI"),
}],
verbatim: Some(Verbatim::new(0x86, Framing::Section)),
pes_packet: None,
},
);
let expected = guard.ext.mpegts.clone();
Expand Down
Loading
Loading