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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion doc/bin/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ or use [`import srt`](/bin/srt).

MPEG-TS import carries H.264/H.265 and AAC/MP2/AC-3/E-AC-3/Opus, and passes
SCTE-35 and every other stream it does not decode (KLV, subtitles, DVB AC-3)
through as tracks. Each such PES goes through whole, at its place on the program clock
through as tracks. Video AUs can span PES, and a PES can contain several. Supply
a PTS for each AU or declare a proportional POC clock: AVC needs
`fixed_frame_rate_flag` and `temporal_poc_flag` in the TS timing descriptor plus
fixed-rate SPS VUI; HEVC needs VUI's `vui_poc_proportional_to_timing_flag`. Missing timing
ends the import instead of repeating a timestamp. Private and undecoded PES go through whole, at their place on the program clock
(PCR); one before the first PCR is dropped. A stream it cannot carry unaltered
is refused with a warning: any in a program with no PCR, and one whose PES carry
an ESCR, pack header or TREF, are scrambled, leave a non-video PES unbounded,
Expand Down
3 changes: 1 addition & 2 deletions quest/m1/ts-reliability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ refused means an error or a counted drop.

| Mechanism | Contract | Owner |
|:--|:--|:--|
| H.264 (0x1B), H.265 (0x24) | Preserved: video rendition, PID and ES descriptors in `mpegts.tracks`; DTS normalized from decode order. Today one access unit per PES | [access units](/quest/m1/ts-reliability/pes-access-units.md) |
| H.264 (0x1B), H.265 (0x24) | Preserved: video rendition, PID and ES descriptors in `mpegts.tracks`; AUs cross PES boundaries with source or explicitly proportional POC-derived PTS; DTS normalized from decode order | landed |
| AAC ADTS (0x0F), MP2, AC-3, E-AC-3, Opus (0x06 + `Opus`) | Preserved: audio rendition; Opus export labels mono and stereo, and 3 to 8 channels with an OpusHead in the Vorbis layout. Other mapping families (such as 255) refuse | landed |
| Private and unknown PES types, LATM (0x11), metadata (0x15) | Preserved: `pesPacket`, PTS and DTS rebased | landed |
| PES clock fields (ESCR, pack header, TREF), PES scrambling | Refused, counted in `refused` | landed |
Expand Down Expand Up @@ -99,7 +99,6 @@ catalog linger (#5305).
## Required

- [State bound](/quest/m1/ts-reliability/state-bound.md) - SI and revision state retire with what the source stops repeating
- [Access units](/quest/m1/ts-reliability/pes-access-units.md) - a PES carrying several access units publishes each at its own time
- [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

Expand Down
32 changes: 0 additions & 32 deletions quest/m1/ts-reliability/pes-access-units.md

This file was deleted.

5 changes: 5 additions & 0 deletions rs/moq-mux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ base64 = { workspace = true }
bytes = { workspace = true }
crc = "3"
h264-parser = { version = "0.4.2" }
h264-reader = "0.9.0"
hang = { workspace = true }
kio = { workspace = true }
memchr = "2"
Expand Down Expand Up @@ -77,5 +78,9 @@ harness = false
name = "containers"
harness = false

[[bench]]
name = "ts_video"
harness = false

[lints]
workspace = true
93 changes: 93 additions & 0 deletions rs/moq-mux/benches/ts_video.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//! Video assembly across access-unit size and PES fragmentation.
use bytes::Bytes;
use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use mpeg2ts::{
pes::{PesPacketReader, ReadPesPacket},
ts::TsPacketReader,
};
use std::{io::Cursor, time::Duration};

fn input(size: usize, payload: usize) -> Vec<u8> {
let fixture = include_bytes!("../src/container/ts/test_data/poc-avc.ts");
let mut reader = PesPacketReader::new(TsPacketReader::new(Cursor::new(fixture)));
// A real SPS/PPS/IDR exercises the timing parser rather than its explicit-PTS
// fallback for unsupported syntax. Padding stays in the final slice NAL.
let mut au = reader.read_pes_packet().unwrap().unwrap().data;
assert!(au.len() <= size);
au.resize(size, 0xff);
// The fixture's SDT/PAT/PMT declare one AVC stream on PID 0x100.
let mut out = include_bytes!("../src/container/ts/test_data/poc-avc.ts")[..188 * 3].to_vec();
let mut cc = 0;
for (n, data) in au.chunks(payload).enumerate() {
let len = data.len() + if n == 0 { 8 } else { 3 };
let mut pes = vec![
0,
0,
1,
0xe0,
(len >> 8) as u8,
len as u8,
0x80,
if n == 0 { 0x80 } else { 0 },
if n == 0 { 5 } else { 0 },
];
if n == 0 {
pes.extend([0x21, 0, 1, 0, 1]);
}
pes.extend(data);
for (packet, chunk) in pes.chunks(184).enumerate() {
let mut ts = vec![
0x47,
if packet == 0 { 0x41 } else { 1 },
0,
if chunk.len() == 184 { 0x10 | cc } else { 0x30 | cc },
];
cc = (cc + 1) & 15;
if chunk.len() < 184 {
let field = 183 - chunk.len();
ts.push(field as u8);
if field > 0 {
ts.push(0);
ts.resize(5 + field, 0xff);
}
}
ts.extend(chunk);
out.extend(ts);
}
}
out
}

fn assembly(c: &mut Criterion) {
let mut group = c.benchmark_group("ts_video");
group.measurement_time(Duration::from_secs(1));
group.warm_up_time(Duration::from_millis(200));
group.sample_size(10);
for size in [4_096, 65_536, 1_048_576] {
group.throughput(Throughput::Bytes(size as u64));
for payload in [64, 1_024, 65_000] {
let data = Bytes::from(input(size, payload));
group.bench_function(BenchmarkId::new(size.to_string(), payload), |b| {
b.iter_batched(
|| {
let mut broadcast = moq_net::broadcast::Info::new().produce();
let catalog = moq_mux::catalog::Producer::new(&mut broadcast, Default::default()).unwrap();
(
moq_mux::container::ts::Import::new(broadcast, catalog.reserve()),
catalog,
)
},
|(mut import, _catalog)| {
import.decode(&data).unwrap();
import.finish().unwrap();
std::hint::black_box(import);
},
BatchSize::SmallInput,
)
});
}
}
group.finish();
}
criterion_group!(benches, assembly);
criterion_main!(benches);
6 changes: 6 additions & 0 deletions rs/moq-mux/src/codec/h264/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ pub(crate) struct Params {
pps: Vec<Bytes>,
}

impl Params {
pub(crate) fn nals(&self) -> impl Iterator<Item = &Bytes> {
self.sps.iter().chain(&self.pps)
}
}

#[derive(Default)]
struct Avc3Frame {
chunks: BytesMut,
Expand Down
6 changes: 6 additions & 0 deletions rs/moq-mux/src/codec/h265/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ pub(crate) struct Params {
pps: Vec<Bytes>,
}

impl Params {
pub(crate) fn nals(&self) -> impl Iterator<Item = &Bytes> {
self.vps.iter().chain(&self.sps).chain(&self.pps)
}
}

#[derive(Default)]
struct Au {
chunks: BytesMut,
Expand Down
Loading
Loading