Skip to main content

Module ts

Module ts 

Source
Expand description

Minimal MPEG-2 Transport Stream demuxer.

Scope: take a .ts / .m2ts byte stream, locate the PAT and a PMT, pick the first video elementary stream the PMT advertises, and return its PES payloads as one sample per access unit.

PTS is carried through on the first PES packet that opens an AU; continuation packets accumulate bytes onto the current sample until the next payload_unit_start_indicator=1 closes it.

What’s implemented:

  • PAT walk that surfaces every program in the file, with a default “first program” pick (matches legacy behaviour) and a select_program(program_number) API for callers that want one of the others (Squad-37).
  • PMT walk: video stream_types 0x02 (MPEG-2), 0x1B (H.264), 0x24 (HEVC) plus audio stream_types 0x0F (AAC-ADTS, Squad-27), 0x81 (AC-3, ATSC A/53), 0x87 (E-AC-3, ATSC A/53), and 0x06 (PES private) when the ES descriptor loop carries a registration_descriptor tagged “AC-3” / “EAC3” (DVB / ETSI TS 101 154) — Squad-37.
  • Encrypted streams (transport_scrambling_control != 0 on the active video PID) trip a one-time typed warn and switch the demuxer into a drop-everything mode (Squad-37); previously the bytes were silently skipped on a per-packet basis which meant a partial-scramble error condition could still leak garbled samples.

What’s not implemented:

  • Full CRC validation of PAT/PMT (we trust what the bitstream gives us; a mis-CRCed file is already corrupt and will surface as wrong stream_type or truncated samples further down).
  • Multiple video streams within one program (we take the first).
  • Adaptation-field-only packets with payload=0 are passed over transparently.
  • BDAV 192-byte wrapper (the 4-byte timestamp prefix) — if present, we detect and strip it.
  • Common-Access (CA) tables: encrypted streams are dropped, not decrypted (we don’t carry CA descriptors).

Structs§

AudioStreamInfo
Per-audio-stream info gathered from one PMT entry. kind is the codec family — extraction reads the first frame to derive codec_private / sample_rate / channels.
ProgramInfo
One MPEG-TS program found in the PAT, after the corresponding PMT has been walked. pmt_pid is the bitstream-side PID where the PMT section lives; video_streams / audio_streams are the elementary streams the PMT advertises (video filtered to MPEG-2 / H.264 / HEVC; audio filtered to AAC-ADTS / AC-3 / E-AC-3 — exactly the codec families we can passthrough). A program with neither a recognised video nor a recognised audio stream is still surfaced so callers can see “this program exists, just contains things we can’t carry”.
TsStreamingDemuxer
Streaming MPEG-TS demuxer. Holds the PES reassembly buffer for one in-flight access unit only — yields whenever a PUSI=1 packet closes the current sample (or at EOF for the final pending sample).
VideoStreamInfo
Per-stream info gathered from one PMT entry.

Enums§

AudioCodecKind
Audio codec discriminator surfaced from the PMT walk. The PMT only tells us the codec family; the actual codec_private bytes (asc for AAC, dac3 / dec3 for AC-3 / E-AC-3) are derived in extract_* by reading the first frame of the elementary stream.