Repository navigation
fix(latency): bridge appsrcs report the latency they can hold, gate repeated bus warnings - #1072
Conversation
srperens
left a comment
There was a problem hiding this comment.
Verdict: Comment. The latency fix is right, sits at the right layer, and all seven new tests ran in CI. It is Comment only because the warning gate changes the main bus handler of every flow (GLOBAL), and the protocol leaves a change that wide to a maintainer. I found nothing that should block the merge.
Suggested (optional)
backend/src/gst/pipeline/warning_gate.rs: when the map is full and nothing is stale, evict the oldest entry, or clear the map. See the gate under Diagnosis.
Claims
| Claim | Verdict | Evidence |
|---|---|---|
| WHIP slots and Media Player outputs are the only production live bridge appsrcs | CONFIRMED |
Every other AppSrc::builder() in backend/src is test-only; the overlay one is not live: backend/src/blocks/builtin/vision_mixer/builder/pipeline_cpu.rs:275 — .is_live(false) |
| The helper reports the queue as the max and keeps min at 0 | CONFIRMED |
backend/src/blocks/mod.rs:46 — .max_latency(APPSRC_MAX_TIME.nseconds() as i64). Used at backend/src/blocks/builtin/whip/input/slots.rs:291 — let appsrc = live_bridge_appsrc(APPSRC_MAX_BYTES_AUDIO), video slot and Media Player builder likewise |
| An explicit min of 0 gives the same reported min as today's default | EXTERNAL |
This depends on appsrc/basesrc query semantics. Assumed from the author's GStreamer 1.28 reproduction |
| The guard tests fail if the fix is reverted | CONFIRMED |
The mixer test asserts both directions: the bridge gives 0 warnings and a default live appsrc gives more than 0 (backend/src/blocks/builtin/mixer/tests.rs:1633). The two property tests assert Some(APPSRC_MAX_TIME) |
Diagnosis. The cause explains the symptom. The aggregator takes the smallest max among its inputs, a live appsrc reports a max of 0, and the 1 s default queue after it caps the mixer below the 2 s SRT minimum. Coverage is BOUNDED to appsrc bridges. A non-appsrc live source that understates its max would still trip this, and only the gate limits the cost of that. Fixing the reporting input, rather than raising queue sizes, is correct under the default-queue rule.
Gate: the bus handler is a signal watch, not a probe, so the Mutex and format! are fine there. Its bound is weaker than 256, though. retain only drops entries older than 10 s (backend/src/gst/pipeline/warning_gate.rs:44 — if self.seen.len() >= MAX_TRACKED {). A warning whose debug text changes on every message then grows the map to rate × 10 s entries, with an O(n) retain on each insert. Those pass the gate anyway, so no regression, but the gate cannot help there. Also, a storm's final held-back count is never reported.
Radius. GLOBAL. The gate runs in every flow's main handler (backend/src/gst/pipeline/bus.rs:128 — let Some(suppressed) = warning_gate.lock().unwrap().check(key, Instant::now())). PipelineWarning consumers only display it; shape unchanged. Block bus handlers are separate, so the early return skips nothing else.
Overlaps
- #1073 is stacked on this PR (it contains
f989f53) and editsbus.rs. Land this one first. - Draft #1025 edits the same
use crate::blocks::{...}block inslots.rsandblocks/mod.rs. Expect a trivial rebase. - #1024 ("decreasing DTS") is qtmux debug-log output, not a bus warning, so the gate does not touch it.
Tests & CI. At f989f53: Check (Linux), Build (Linux x86_64/ARM64), Check & Build (WASM) and API Contract Check pass. The Check (Linux) log shows all seven new tests ... ok. rtpL16pay, rtpjitterbuffer and rtpL16depay come from gstreamer1.0-plugins-good, which is in the ci.yml package list. macOS/Windows skipped; nothing platform-specific, Linux-green suffices.
Design record. Rejected options are in the body. The new BLOCK_GUIDELINES.md section is a contract change by the maintainer; noted only.
Confidence: HIGH
…epeated bus warnings WHIP Input and Media Player hand media into the flow through a live appsrc left at its default latency, which reports a maximum of 0 although it queues up to 10 s. After the mixer's default queue that caps the mixer's maximum at 1 s. With an SRT input at 2000 ms in the same mixer, every aggregator in the block failed its latency configuration on every cycle: ~1400 "Impossible to configure latency" warnings per second, each logged and broadcast, and the mixers re-querying latency upstream each time. A production flow burned ~280% CPU this way. - blocks::live_bridge_appsrc builds those appsrcs and reports APPSRC_MAX_TIME as their maximum latency; the minimum stays 0. - The bus handler lets the same warning from the same source through once per 10 s, with the count it held back. - BLOCK_GUIDELINES gains a Reported Latency section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019c8J2sWW25auY4wAjxpoTN
… bounded
A warning whose debug text carries a drifting value ("min 0:00:02.023...")
got a new gate key on every change and passed the gate each time. Digits in
the debug text are now masked in the key; the source name and message are
kept as they are.
When the map is full and nothing in it is stale, it is cleared, so it can
no longer grow past MAX_TRACKED.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f989f53 to
55b5ae2
Compare
|
Review findings addressed in 55b5ae2, rebased onto current
Also verified the Ran locally (macOS, GStreamer 1.28.6): |
srperens
left a comment
There was a problem hiding this comment.
Area: Pipeline bus warnings, latency of live bridges
This reviews only the new commit 55b5ae2: the gate key masks digit runs in the debug text, and the map is cleared when it is full and nothing in it is stale. Both answer the earlier review: the drifting-value key and the bound. The rest is unchanged from f989f53, which git range-diff shows as identical.
Neighbours: #1073 is stacked on this PR and was only rebased onto the new commit. Its own patch is unchanged, so it was not reviewed again.
Found nothing blocking. Checked:
bus.rsmasks onlydebug_info, and the source name stays in the key, soqueue3andqueue4stay apart.check()cannot hold more thanMAX_TRACKEDentries after theclear(). The new unit test covers it.Check (Linux)passed at this head and runs--lib, so both new unit tests ran.
One cost, small: clear() also drops the held-back counts of warnings still inside their 10 s window. Those counts are never reported, as before for the last burst of any warning. It only matters under a storm of more than 256 distinct keys, so this is a note, not a finding.
Refs: no issue. Found on a production demo flow.
Problem
A vision mixer + audio mixer flow with three SRT inputs, a WHIP guest and a Media Player clip burned ~280% CPU. Every aggregator in both mixer blocks (
audiomixer,aux0_mixer, the GLmixer,mv_comp) failed its latency configuration ~1400 times per second:latency: 2000.appsrcleft at its default latency. A live appsrc at its defaults reports max = 0, as if it could not hold a buffer, but these appsrcs queue up toAPPSRC_MAX_TIME(10 s). After the mixer's default queue (1 s), the mixer's maximum becomes 1.000 s.The aggregator re-queries latency upstream on every cycle while it is unconfigured, and posts a warning each time. Strom logs every warning and broadcasts a
PipelineWarningto every client, so the proxy in front of Strom loaded up too. Any flow that mixes an input with more than ~1 s of latency and a WHIP or Media Player input hits this.Change
blocks::live_bridge_appsrc(max_bytes)builds a live bridge appsrc. It reports its queue (APPSRC_MAX_TIME) as maximum latency and keeps the minimum at 0, so existing flows keep the latency they had. WHIP Input slots (audio and video) and Media Player outputs use it. Those are the only production appsrcs that bridge live media into a flow; the vision mixer overlay appsrc is not live and does not take part in latency.intersrcalready passes latency on correctly (min from the producer, max NONE).PipelineWarningevent. A warning that loops can no longer turn into a CPU storm. Errors and infos are unchanged.docs/BLOCK_GUIDELINES.mdgains a "Reported Latency" section. A source reports the latency it can actually hold, and any block that bridges through anappsrcuseslive_bridge_appsrc.Rejected:
max-size-timein front of the mixers. That hides the wrong report, costs memory on every input, and goes against the default-queue rule.APPSRC_MAX_TIME, so 10 s is the honest value.Evidence
test_a_bridge_input_next_to_a_two_second_input_configures_latencybuilds the real mixer block (100 ms latency, 2000 ms min-upstream-latency, as on the flow) and feeds channel 0 throughrtpjitterbuffer latency=2000and channel 1 throughlive_bridge_appsrc. 0 warnings. With the two latency lines removed from the helper it fails withleft: 7240 right: 0(warnings in 4 s). The same test also asserts that a default live appsrc still triggers the warning, so the setup keeps showing the failure it guards.slot_appsrcs_report_the_latency_their_queue_can_hold. With the fix reverted it fails withappsrc_audio_0 ... left: None right: Some(0:00:10.000000000).every_output_appsrc_reports_the_latency_its_queue_can_hold. With the fix reverted it fails withappsrc_video ... left: None.gst::pipeline::warning_gateunit tests (first passes, repeats held, released after the interval with the count, distinct keys separate, map bounded). They exercise the gate itself, not the bus handler wiring.max-latency=10sgave 0, and the min stayed the same.Tests
Ran on macOS (GStreamer 1.28.6):
cargo test --lib: 980 passed, 6 ignored.cargo test --test pipeline_lifecycle_test --test media_player_control_test --test media_player_hls_test --test bus_signal_watch_balance_test --test drop_on_latency_test: all passed.cargo clippy --all-targets: clean.Skipped: none of the new tests have an early return.
rtpL16pay,rtpjitterbufferandrtpL16depayare in gstreamer1.0-plugins-good, which is in the CI package list.Not run: the full flow on a server. Not deployed yet.
For the reviewer
PipelineWarningevent shape is unchanged. Only its text gains "(repeated N times in the last 10 s)" when warnings were held back.Out of scope
🤖 Generated with Claude Code
https://claude.ai/code/session_019c8J2sWW25auY4wAjxpoTN