Skip to content

fix(qos): report late-input drops in the audio mixers and fix QoS stats - #1274

Open
srperens wants to merge 1 commit into
mainfrom
fix/qos-late-drops-audio
Open

srperens wants to merge 1 commit into
mainfrom
fix/qos-late-drops-audio

Conversation

@srperens

Copy link
Copy Markdown
Collaborator

Refs #1265

Problem

A builtin.mixer audiomixer dropped a late input for a whole connection, and nothing was logged or shown (#1265). There were four causes:

  1. audiomixer and liveadder post a QoS message for a dropped input only when the input pad's qos-messages is set. It defaults to false, and Strom set it only on the WHEP Input liveadder pads.
  2. When such a message arrives, its source is the pad (sink_1), not the element. The bus handler used the source name, so the report named no block (block_id: None, element sink_1).
  3. bus.rs read qos.stats() as (format, processed). gstreamer-rs 0.25 returns (processed, dropped), so total_processed carried the cumulative dropped count, and the real processed count was lost.
  4. Health was inverted. is_falling_behind = avg_proportion < 1.0 is true when an element keeps up, and an audiomixer input that drops everything reports a proportion of 1.0 (measured: proportion=(double)1 on every drop message, see Evidence). The frontend used the same thresholds (Warning < 0.95, Critical < 0.8), and its state never expired.

Change

  • gst::aggregator_qos::report_late_input_drops sets qos-messages=true on an aggregator's sink pads, now and in future (a pad-added handler that captures nothing). It is called from make_audiomixer (Audio Mixer: main, solo, monitor, aux and group buses; Live Audio Router), from the Audio Router's audiomixers, and from both WHEP Input liveadders. The per-pad set in whep/input/stream.rs is gone because the helper now covers it. The property exists from GStreamer 1.20, below our 1.22 floor. The find_property check only keeps another element class working.
  • gst/pipeline/qos.rs (new, the QoS code moved out of pipeline/mod.rs):
    • parse_qos reads (processed, dropped) in that order. A pad source is mapped to its parent element, and the pad name is kept along with the element linked to that pad (e.g. mixer:to_main_queue_1, which shows it was channel 2). The unit is samples/frames for GST_FORMAT_DEFAULT, taken from the pad's caps, or buffers/bytes.
    • QoSAggregator is keyed on (element, pad). The counts are cumulative per source, so drops in a period are the growth of the dropped count since the last period, and a decrease counts as a counter reset (flush, restart). A source that reports no dropped count counts one drop per message.
    • Health is dropped_in_period > 0, no longer the proportion.
    • DropLogGate logs the first drop per input at once (warn!, names the element, input pad, upstream element and unit), then the sum at most every 10 s, and forgets a source after 10 quiet seconds.
  • StromEvent::QoSStats: no field renamed or removed. It gains pad_name, upstream_element, total_dropped, dropped_in_period and stats_format, all with serde defaults, so old payloads still parse (unit test). openapi.json is updated on purpose.
  • Frontend qos_monitor.rs: health follows dropped_in_period (Warning) and ≥ 10 QoS messages in a period (Critical, a continuous drop). Reports expire after 15 s, like buffer_age.rs. Entries are keyed per (node, element, pad). A node shows the worst of its inputs. The tooltip and log line name the input and the drop count, not a proportion percentage.

Behaviour changes, on purpose: total_processed now carries the processed count. Before, it carried the dropped count. is_falling_behind flips meaning: it is now true when the element dropped data in the period. Before, it was true when the proportion was below 1.0. Consumers that read these fields (Open Live) will see different values.

Rejected:

  • Keying health on the proportion with corrected thresholds. Aggregator inputs report 1.0 while they drop, so the proportion says nothing about drops.
  • Setting qos-messages at each request_pad_simple call site. Most audiomixer pads in the mixer block are requested by the generic linker (ElementPadRef::element), and the pad-added handler covers every call site, including future ones.

Evidence

  • An audiomixer input pad posts QoS only with qos-messages, the pad is the source, and the proportion stays 1.0 while it drops. Measured with gst-launch 1.28.6 on macOS: audiomixer sink_1::qos-messages=true ... audiotestsrc is-live=true ! identity sleep-time=40000 ! mix. gives Got message from pad "mix:sink_1" (qos): ... proportion=(double)1 ... format=(GstFormat)default, processed=(guint64)3200, dropped=(guint64)1920.
  • Guard: mixer_late_input_qos_test::a_late_mixer_input_is_reported_with_its_block_and_pad builds a flow through PipelineManager with the real builtin.mixer block. Input 1 is a live tone. Input 2 is a live tone behind identity sleep-time=40000. The test asserts a QoSStats with block_id=mixer, element_name=mixer:audiomixer, a pad name, upstream_element=mixer:to_main_queue_1, total_dropped > 0 and is_falling_behind. Revert checks, each run locally:
    • without report_late_input_drops in make_audiomixer: no QoS drop reported for an input pad of the mixer block's audiomixer; QoS reports: []
    • without the pad-to-element mapping: QoS reports: [(None, "sink_3", None, None, Some(20480), 20480, true), (None, "sink_1", ...), ...]. There is no block, only bare pad names.
    • with the old health rule (avg_proportion < 1.0): every report has is_falling_behind=false, e.g. (Some("mixer"), "mixer:audiomixer", Some("sink_1"), Some("mixer:to_main_queue_1"), Some(19721), 19721, false)
  • The stats order is guarded by gst::pipeline::qos::tests::a_pad_qos_message_is_read_as_its_element_and_pad. With the old (dropped, processed) read it fails with left: Some(1920) right: Some(3200).
  • Per-period drops, counter reset, no-new-drops and per-pad keying are covered by unit tests in gst::pipeline::qos::tests. The log gate (first drop at once, then at most once per 10 s, flush, forget) is covered there too. Frontend health and TTL are covered in qos_monitor::tests. Old-payload parsing is covered in events::event_accessor_tests::qos_stats_without_the_drop_fields_still_parses.
  • gst::aggregator_qos::tests::requested_audiomixer_pads_post_qos_messages checks that pads that already exist and pads requested later are both covered.

Tests

Ran on macOS (arm64), GStreamer 1.28.6:

  • cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, cargo clippy --all-targets --features efp -- -D warnings: clean. The pre-commit hook also ran wasm32 clippy: clean.
  • cargo test --workspace --lib: 1344 + 106 + 215 passed.
  • cargo test --test it -- openapi_test mixer_late_input_qos liveaudiorouter latency_diagnosis latency_redistribute: 45 passed.
  • cargo test --test it -- drop_on_latency audioprocessor: passed.
  • cargo test --test gst_floor_smoke_test: 5 passed. It runs the Audio Mixer block on the local 1.28, not on 1.22.

Failed locally, same on main: whep_input_video_test (3 tests), with ICE failed from whepsrc on this Mac. I restored main's WHEP files and reran: same 3 failures. Not caused by this change.

Not run: the full --test it suite, and Linux or Windows locally. CI covers those.

The new test needs only audiotestsrc, identity, audiomixer and fakesink (core and base), which are in every CI image. It asserts with common::require_elements and does not skip.

Lesson

Added to docs/BLOCK_GUIDELINES.md under "Reported Latency": a mixer reports the late data it drops. Every audio aggregator a block creates goes through gst::aggregator_qos::report_late_input_drops, and the new integration test guards the Audio Mixer.

For the reviewer

  • The QoSStats WebSocket contract: total_processed and is_falling_behind change meaning (see Change). Field names and types are unchanged, and new fields are additive with defaults.
  • More QoS traffic: every audio mixer input now posts a message per dropped buffer (dozens per second while an input is late). They are aggregated per second before broadcast and gated to one log line per 10 s per input, so the cost is bus dispatch only while something is dropping.
  • The frontend Critical threshold (≥ 10 QoS messages in a one-second period) is a judgement call. It separates "an input is continuously late" from "an occasional late buffer".

Out of scope

  • Video aggregators (vision mixer, compositor): a parallel PR handles the vision mixer's per-pad drop reporting. It plugs into the same per-(element, pad) cumulative-delta aggregation.
  • Mapping an aggregator pad back to the block's own input pad name (input_2) instead of the internal upstream element (mixer:to_main_queue_1). That needs per-block knowledge of the internal chains.

🤖 Generated with Claude Code

audiomixer and liveadder drop input that misses its deadline and post a
QoS message only when the input pad's qos-messages is set, which defaults
to false. A mixer input could be dropped for a whole connection with
nothing logged or shown (#1265).

- Set qos-messages on every audio aggregator sink pad Strom creates
  (make_audiomixer: Audio Mixer, Live Audio Router; Audio Router;
  WHEP Input liveadder) through gst::aggregator_qos.
- Read Qos::stats() as (processed, dropped). total_processed carried the
  dropped count.
- Map a QoS message from a pad to its parent element and keep the pad
  name and the upstream element, so a drop names the block and input.
- Aggregate per element and pad; drops per period are the growth of the
  cumulative dropped count, a decrease is a counter reset.
- Health follows drops, not proportion (is_falling_behind was
  avg_proportion < 1.0, true when an element keeps up). Frontend health
  follows drops too, and reports expire after 15 s.
- Log the first drop per input at once, then the sum at most every 10 s.
- StromEvent::QoSStats gains optional pad_name, upstream_element,
  total_dropped, dropped_in_period, stats_format (serde defaults).

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