Repository navigation
Conversation
With ignore-pcr, tsdemux anchors its timestamps once, on the first PES it parses, and keeps any error in that sample for the whole connection. A caller that encoded before connecting is stamped seconds ahead, a sender that stalls is stamped late for seconds, and ffmpeg's default muxing adds its send-ahead (~350 ms audio, ~500 ms video) as latency. gst::ts_arrival_clock keeps tsdemux's PTS spacing and replaces only its anchor, from srtsrc's arrival timestamps: per stream the largest lead in a 2 s window, the latest-arriving stream setting one shared pad offset, late buffers re-anchoring once confirmed (at once after a caller change), and output never stepping backwards. On by default with ignore_pcr; block properties arrival_retiming and arrival_margin_ms (100 ms). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015zM1LedicrqbhDqxh6B5UV
This was referenced Oct 20, 2026
This was referenced Oct 27, 2026
This was referenced Nov 10, 2026
Collaborator
Author
|
Superseded by #1272: rebased onto main, with two fixes on top (latency budget paid twice, B-frames out of decode order), measured in the PR. |
srperens
added a commit
that referenced
this pull request
Nov 18, 2026
…ency budget (#1272) * feat(mpegtssrt_input): retime tsdemux output from SRT arrival With ignore-pcr, tsdemux anchors its timestamps once, on the first PES it parses, and keeps any error in that sample for the whole connection. A caller that encoded before connecting is stamped seconds ahead, a sender that stalls is stamped late for seconds, and ffmpeg's default muxing adds its send-ahead (~350 ms audio, ~500 ms video) as latency. gst::ts_arrival_clock keeps tsdemux's PTS spacing and replaces only its anchor, from srtsrc's arrival timestamps: per stream the largest lead in a 2 s window, the latest-arriving stream setting one shared pad offset, late buffers re-anchoring once confirmed (at once after a caller change), and output never stepping backwards. On by default with ignore_pcr; block properties arrival_retiming and arrival_margin_ms (100 ms). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015zM1LedicrqbhDqxh6B5UV * fix(mpegtssrt_input): retime against the deadline, keep B-frames in decode order The arrival retiming from #1088 stamped the latest stream a margin after its arrival, on top of the SRT latency srtsrc reports, so the budget was paid twice. Measure lead against the deadline instead: the pipeline's running time at arrival minus the reported SRT + tsdemux latency. Arrival is the pipeline clock's running time, from Instant calibrated against the clock every 256 srtsrc buffers. srtsrc's own stamp is up to 1.3 s behind the clock in a caller's connect burst. The never-step-backwards rule compared PTS. Video with B-frames goes out in decode order, so every B-frame raised the video offset and the next P-frame lowered it: B-frames went out at the wrong time and video drifted 30-120 ms behind audio. Compare DTS where the buffer has one. Refs #1265 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(mpegtssrt_input): anchor arrival retiming on decode order, review fixes Review findings on #1272: - Lead and lateness use the decode-order running time (DTS, else PTS). Anchored on PTS, every B-frame after a P-frame missed its deadline whenever video set the anchor, and the on-time P-frames kept that from being confirmed. - Late runs are kept per stream, so two late buffers of different streams cannot confirm 100 ms between them. An on-time buffer of any stream still ends every stream's run. - A DTS before the segment origin gives a smaller running time instead of none. - The budget counts 700 ms for a negative tsdemux latency, as tsdemux itself does. - The trust window after a caller change starts at the first arrival, so a caller that connects before any data gets it. - Calibrate against the pipeline clock by time (500 ms), not one buffer in 256: a deliberate, bounded exception to the probe lock rule. - A per-slot generation stops a removed pad's probes from writing into a slot a new pad has claimed. - The integration test measures lead against the pipeline clock, not srtsrc's stamp, and picks listener ports below the ephemeral range. - Margin description and doc comments corrected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #813 (alternative approach to the same bug)
Problem
With
ignore-pcr=true(the block default), tsdemux maps the sender's PTS onto running time from one reference: the arrival of the first PES it parsed. It never takes a new one, so any error in that one sample lasts for the whole connection. Measured locally over SRT (lead = running time out of tsdemux minus arrival, i.e. delay the stream adds downstream):PCR mode would track the sender's clock, but too many senders get PCR wrong to rely on it. That is why
ignore-pcris the default.#813 corrects the stale-head case with a one-shot correction in the first 3 s, above 500 ms. Most of its listed limits follow from that shape: nothing under 500 ms, nothing after 3 s, no drift, no
mode=caller.Change
New
gst::ts_arrival_clock, wired intobuiltin.mpegtssrt_inputwhenignore_pcrand the newarrival_retimingproperty are on (both default true). It keeps tsdemux's PTS spacing and replaces only its anchor, fromsrtsrc's arrival timestamps (within 0–8 ms of real arrival, measured):offset = margin − min over streams (best lead).marginis the newarrival_margin_msproperty, 100 ms by default.caller-added/caller-removed, every late buffer re-anchors at once, which also absorbs the junk buffer tsdemux flushes from the previous caller (one buffer stamped ~1.3 s off, seen in the integration test).gst_pad_set_offseton each tsdemux source pad, only on a change of ≥ 5 ms (or a late buffer). An offset set inside the buffer probe applies to that same buffer (checked).Rejected along the way (measured):
Evidence
Real block (
MpegTsSrtInputBuilder) over SRT on macOS, GStreamer 1.28.6, passthrough, lead at the block outputs:arrival_retiming=falsearrival_retiming=trueA clean GStreamer caller now leads ~100 ms where it led ~0 before: that is the margin. For ffmpeg streams the margin is far less than what tsdemux added before. Whether 100 ms is the right default, and whether to report it in the latency query instead of stamping it, is open (see below).
Tests
Ran on macOS (arm64, GStreamer 1.28.6),
STROM_REQUIRE_GST_PLUGINS=1:cargo test --lib ts_arrival_clock: 11 unit tests (healthy A/V spread, stale head, stale tail, stall, drift 0.5 %, caller change, junk buffer at a caller change, unannounced reference jump, stream that stops, no backwards step, no offset churn on jitter). All pass.cargo test --test mpegtssrt_arrival_retiming_test: 4 integration tests over real SRT with an in-process H.264 + AAC caller. 10 consecutive runs green after widening the decode-mode lower bound (one earlier run hit −79 ms after the decoder against a −50 bound).arrival_retiming=falseboth early-caller tests fail (~2 000 ms). With thecaller-added/caller-removedhookup removed,a_clean_caller_after_a_corrected_one_is_not_latefails (its first ~100 ms go out late).a_clean_caller_stays_within_the_marginpasses with retiming off too: it guards the margin bound, not the bug.mpegtssrt_absent_caller_test,mpegtssrt_input_program_change_test,mpegtssrt_streamheader_test,pipeline_lifecycle_test,openapi_test, clippy (-D warnings, with and without--features efp), fmt.Not run: Linux CI (this PR's run will be the first), the rest of the integration suite, the Open Live rig, a real network (all measurements are on localhost).
For the reviewer
ignore_pcrchanges timing. Clean GStreamer callers gain ~100 ms (the margin), and ffmpeg-muxed callers lose ~250 ms.arrival_retiming=falserestores today's behaviour.marginahead of arrival rather than reporting it in the latency query. Reporting would be more GStreamer-like. Stamping keeps the change local to the block, matches what the measurements validated, and lets late-buffer detection work against zero.set_offsetin a BUFFER probe takes the pad's object lock, but only when the offset changes (≥ 5 ms, or a late buffer); everything else is atomics. In the clean-connect test the offset changes a handful of times per connection.Out of scope
🤖 Generated with Claude Code
https://claude.ai/code/session_015zM1LedicrqbhDqxh6B5UV