Skip to content

Add SRT MPEG-TS ingest with fMP4 repackaging and MoQ object publishing. - #14

Merged
mondain merged 7 commits into
mainfrom
srt-ingest-tj
Jun 11, 2026
Merged

Add SRT MPEG-TS ingest with fMP4 repackaging and MoQ object publishing.#14
mondain merged 7 commits into
mainfrom
srt-ingest-tj

Conversation

@TilsonJoji

@TilsonJoji TilsonJoji commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

This is PR that adds SRT live ingest support to the publisher.

It allows the publisher to receive MPEG-TS over SRT, parse the incoming transport stream, extract audio/video samples, repackage them into fragmented MP4 media objects, and publish them as MoQ objects.

Key changes

  • Adds SRT caller-based live ingest using configurable SRT endpoints.
  • Parses MPEG-TS input and extracts H.264/H.265 video and AAC audio samples.
  • Builds fMP4 moof+mdat media fragments from the extracted samples.
  • Publishes generated media fragments as MoQ objects using track/group/object mapping.
  • Adds live-source selection so ingest is either stdin or srt, not both at the same time.
  • Adds codec discovery for catalog/bootstrap generation before publishing.
  • Preserves audio/video timing using normalized PTS handling for live media.

Notes

  • This is intended to enable live MPEG-TS over SRT from Synamedia Encoder and bridge it into the existing MoQ publishing flow through fMP4 media objects.
  • Tested on D16
  • The SRT and stdin live publishing paths currently share similar publishing/control-plane logic, this PR intentionally does not refactor them into a common core. The SRT path currently seem to work well for live streaming, so the refactor is deferred to a follow-up PR to keep the change easier to validate. The follow-up PR would keep SRT media object generation unchanged, while consolidating shared MoQ publishing.

@TilsonJoji
TilsonJoji marked this pull request as ready for review June 3, 2026 10:34
mondain and others added 4 commits June 3, 2026 10:43
- annexb_to_avcc: add missing end-of-buffer fixup so the final NAL unit
  in each call is not truncated by 3 bytes; mirrors the identical guard
  already present in extract_nal_units()

- build_hvcc_box: tighten sps_payload_size guard from < 12 to < 13;
  general_level_idc is read at sps_data[12] which requires size >= 13

- Video dimensions: replace hardcoded 1920x1080 placeholder with actual
  values parsed from the first keyframe SPS. Adds RbspBitReader,
  parse_h264_dimensions() (full RBSP including high-profile scaling
  lists, POC, frame cropping), and parse_hevc_dimensions() (full
  profile_tier_level, conformance window). Results are stored under
  discovery mutex alongside codec_private so the rebuilt init segment
  carries correct tkhd/stsd dimensions for any resolution.
base_pts90k is set from the first published sample. When a subsequent
sample arrives with a lower PTS the offset was silently clamped to 0,
producing tfdt=0 in the moof. Two scenarios trigger this:

- Small underflow (audio pre-roll / jitter): one or two frames at t=0
  is harmless; keep the zero-clamp for this case.

- 33-bit PTS rollover (~26.5 h): sample.pts90k wraps from near 2^33
  back to zero while base_pts90k remains large, so every subsequent
  sample gets tfdt=0 and the decoder timeline collapses permanently.

Fix: if the backward jump exceeds 2^32 ticks (~13 h, impossible as
normal jitter) treat it as a rollover and reset base_pts90k to the new
PTS. Duration tracking recovers naturally on the next frame via the
existing last_pts / 500 ms clamp logic.
annexb_to_avcc: skip zero-length NAL units produced when two start
codes are adjacent (nal_size=0). Without this, a zero-length BE32
prefix is emitted and the decoder misreads the following bytes as NAL
data, corrupting the rest of the AVCC stream. On skip, the outer loop
resumes from the same position and correctly finds the next start code.

SRT drain_queue: move finish_group loop before the error-path return so
subgroup streams opened with fin=false are always closed, even when
drain_queue fails mid-batch. The original status is preserved: a
finish_group failure only updates status when it was previously clean.

creation_time_us: stamp each fragment with the wall-clock time at
build time so queue-delay metrics produce meaningful values instead of
always reading zero.
…PTS offsets for each moof. With live SRT ingest, PTS can have small jitter, which can produce non-monotonic decode times. The MSE adapter then sees overlapping media ranges and drops payloads.Switched back to the accumulation-based timeline. For each track, the next base_decode_time is derived from the previous sample’s decode time plus its sample duration. This guarantees monotonic tfdt values even when raw PTS has small jitter.Since the encoder is configured with no B-frames, there is no decode reordering concern.
@mondain
mondain merged commit 4d61027 into main Jun 11, 2026
3 checks passed
@mondain
mondain deleted the srt-ingest-tj branch June 11, 2026 17:38
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.

2 participants