Skip to content

feat(vision_mixer): post QoS for input frames dropped as late - #1275

Open
srperens wants to merge 1 commit into
mainfrom
feat/vision-mixer-late-input-qos
Open

srperens wants to merge 1 commit into
mainfrom
feat/vision-mixer-late-input-qos

Conversation

@srperens

Copy link
Copy Markdown
Collaborator

Refs #1265

Problem

The vision mixer drops late input frames without a signal. In live mode a GstVideoAggregator (compositor on the CPU path, glvideomixerelement on the GPU path) drops every queued input buffer that ends before its next output frame. It does this in gst_video_aggregator_pad_skip_buffer, called from gst_aggregator_pad_skip_buffers, and logs only a debug line. Its own QoS message covers only late output. So an input that reaches the mixer later than its latency window disappears from program, and nothing on the bus says so. #1265 is the same class of problem for audio.

Change

The block counts late drops per input and posts a standard GStreamer QoS message for each input that dropped frames. The message source is the mixer's sink pad, so the drops go through the same QoS path as any element's.

  • Detection (new vision_mixer/late_input.rs): a BUFFER probe on each dist-mixer input pad (video inputs sink_0..N, then DSK inputs) converts the buffer's end to running time. It compares that with the end of the last frame the mixer pushed. This is the same comparison skip_buffer makes, and the output position only grows, so a buffer that is behind it on arrival is always dropped. The count can only be low, never high: a buffer that turns late while it waits in the queue is missed. Nothing the mixer shows is counted.
  • Probe cost: the probes only touch atomics. Each pad's segment (start+offset and base, rate 1.0 only) is stored from an EVENT_DOWNSTREAM probe. The output position comes from a probe on the mixer src pad, which fires once per output frame. FLUSH_STOP resets the counters.
  • Posting: messages are built and posted from the vision mixer's existing overlay timer thread, not from a probe. That thread already has a tested teardown path. Each message has live=true, the running time of the last late buffer, jitter equal to how late it was, and stats in Buffers format. processed and dropped are cumulative totals since the last flush, as in GStreamer's own QoS, as agreed with the consumer side. At most one message per second per input, and only when the dropped total went up.
  • Both backends: the same code covers the CPU and GPU paths. The probes go on the dist mixer whichever element it is. Mixer latency and timing are unchanged.

The QoS consumption fix is a separate PR. That PR parses Qos::stats(), maps a QoS message whose source is a pad to its parent element while keeping the pad name, and bases health on drops. Until it lands, the current bus.rs keys these messages by the pad name (sink_1).

Alternatives I rejected:

  • GstAggregatorPad::buffer-consumed: it fires for used and dropped buffers alike, and costs a signal emission per buffer.
  • Counting buffers in against frames out: it cannot tell a drop from a frame replaced by a newer one inside one output period, for example a 50 fps input on a 25 fps mixer.
  • Reading the aggregator pad segments directly: that takes object locks, which a buffer probe must not do.
  • A GStreamer patch: the target is 1.28 and the floor is 1.22. The missing upstream QoS is recorded in docs/UPSTREAM_NOTES.md.

Evidence

  • A late input posts QoS with dropped > 0 on its own mixer pad, and an on-time input posts none. The test is vision_mixer_late_input_qos_test::late_input_posts_qos_for_its_mixer_pad_only_{cpu,gpu}. It builds the real block with two live 30 fps inputs and stamps input 1 one second in the past. It asserts a QoS message from <block>:mixer.sink_1 with dropped > 0, processed >= dropped, and no QoS message from sink_0 over the following 3 s.
  • Revert check: with post_message replaced by dropping the message, both variants fail:
    panicked at backend/tests/it/vision_mixer_late_input_qos_test.rs:190:5:
    no QoS message with dropped > 0 for the late input's mixer pad vm_late_cpu:mixer.sink_1; pad QoS messages seen: []
    panicked at backend/tests/it/vision_mixer_late_input_qos_test.rs:190:5:
    no QoS message with dropped > 0 for the late input's mixer pad vm_late_gpu:mixer.sink_1; pad QoS messages seen: []
    
  • Detection accuracy, from a temporary debug print (since removed), CPU path: the late input counted every frame as dropped (35/35, 66/66, ...). The on-time input counted 0 dropped out of 300+ processed.

Tests

Ran on macOS (arm64) with GStreamer 1.28.6:

  • cargo test --test it vision_mixer_late_input_qos: 2 passed. The GPU variant also passed with STROM_REQUIRE_GL=1, so it did not skip.
  • Revert check as above: 2 failed.
  • cargo test --lib vision_mixer: 39 passed.
  • cargo test --test it pipeline_lifecycle: 4 passed.
  • cargo test --test it vision_mixer: 43 passed, 1 failed. The failure is failed_start_teardown_test::vision_mixer_overlay::failed_start_leaves_no_overlay_timer. It is not caused by this PR: it also fails with -- --skip late_input, and passes on its own. It counts the process-wide overlay_timers_running(), so any other vision mixer test running in parallel can break it. That is a test-isolation issue that exists without this change.
  • cargo fmt --all, cargo clippy --all-targets -- -D warnings, cargo clippy --all-targets --features efp -- -D warnings: clean.

Skipped or not run:

  • On CI, the GPU variant runs on Linux with surfaceless EGL (STROM_REQUIRE_GL=1) and is serialized with the other GL tests. I have not seen it run there.
  • Floor (1.22) smoke: not run.

Lesson

None for CLAUDE.md. Two upstream entries were added to docs/UPSTREAM_NOTES.md:

  • the aggregator's silent late-input drop;
  • an abort in gst_video_aggregator_fill_queues (start_running_time != -1 assertion) when a live input has a negative pad offset. It was measured once, on 1.28.6, while writing the test, and its cause is a guess. Because of it, the test shifts timestamps with a probe instead.

A note for test writers: a flow's thread-priority setup owns the bus sync handler, so a test that replaces it with set_sync_handler sees nothing. The test uses enable_sync_message_emission and connect_sync_message instead.

For the reviewer

  • Messages come from a pad, not an element, so consumers must handle a pad source. That is what the separate consumption PR does.
  • The count uses the arrival-time comparison, so it is a lower bound (see Change).
  • overlay.rs is over 1500 lines (1852 before this PR). I kept my change there to a field and a hook in the timer loop, and put the logic in late_input.rs. Splitting overlay.rs should be its own PR.

Out of scope

  • Multiview mixer (mv_comp) inputs: they carry the same frames as the dist mixer inputs, so counting them would count each late frame twice and say nothing about program.
  • queue_pgm_mv (leaky=upstream, max-size-buffers=1, CPU path): it drops by design whenever the multiview takes PGM slower than PGM is produced, for example a multiview framerate below the PGM framerate. These drops are not lost program frames, and reporting them would be noise.
  • Overlay appsrc (leaky, max-buffers=2): it carries the overlay graphic, which is re-rendered and pushed again. It is not media from an input.
  • PiP, stinger and border underlay pads: not counted. The stinger is clip playback, and the underlays carry one static frame.
  • The flaky failed_start_leaves_no_overlay_timer (see Tests): it needs its own fix.

🤖 Generated with Claude Code

A live video aggregator drops an input buffer that ends before its next
output frame with only a debug line, so an input that reaches the vision
mixer later than its latency window vanished from program without a
signal. The block now counts those drops per dist-mixer input (video and
DSK pads) and posts a standard QoS message with the mixer sink pad as
source, cumulative processed/dropped in Buffers, at most once a second
per input and only when the dropped total grew.

Detection: BUFFER probes on the mixer sink pads compare each buffer's end
running time with the end of the mixer's last output frame, the same
comparison as GstVideoAggregatorPad's skip_buffer. Atomics only; the
segments come from event probes, the output position from a probe on the
mixer src pad. The message is built on the overlay timer thread.

Refs #1265

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant