Skip to content

feat(srt): add SRT statistics for inputs and outputs - #564

Merged
srperens merged 2 commits into
mainfrom
feat/srt-statistics
May 12, 2026
Merged

feat(srt): add SRT statistics for inputs and outputs#564
srperens merged 2 commits into
mainfrom
feat/srt-statistics

Conversation

@srperens

Copy link
Copy Markdown
Collaborator

Summary

Adds on-demand SRT statistics for all four SRT block types (efpsrt_input, efpsrt_output, mpegtssrt_input, mpegtssrt_output), mirroring the existing WebRTC stats pattern.

  • Backend scans the pipeline for srtsrc / srtsink elements and reads their libsrt stats GstStructure. Handles caller-mode top-level, listener-mode GValueArray, and gst::Array / gst::List variants across gst-plugins-bad versions. Exposed via GET /api/flows/{id}/srt-stats.
  • API uses typed SrtRole / SrtMode enums and splits sender vs receiver counters (packets_sent_lost / packets_received_lost etc.) so the semantics of each counter is unambiguous. Peer address parsed from GInetSocketAddress and formatted as ip:port.
  • Frontend polls every 1s when the selected flow has an SRT block. Compact inline view in the graph node shows peer count, RTT, and recent loss %. The property-inspector view renders per-caller sections, separating NAK'd-then-retransmitted (recovered, green) from TLPKTDROP / TSBPD (actual data loss, red).
  • Per-second deltas are computed against the previous poll so loss / packet / byte counters show both lifetime totals and current rate (134k (450/s)), keeping the figures meaningful on long-running streams. Recent-interval loss fraction drives both the compact loss reading and a per-caller "Recent loss" row.
  • 8 unit tests cover the parser (sender / receiver split, listener callers array, address parsing, integer-width aliases, connected-flag heuristics).

Test plan

  • cargo check passes on backend + frontend (native + WASM)
  • cargo test --lib pipeline::srt — 8/8 pass
  • cargo test --test openapi_test — snapshot updated and clean
  • Pre-commit hooks (fmt, clippy, sensitive-content) green
  • Manual: caller-mode srtsrc receives stream → stats appear in inspector with correct receiver-side fields
  • Manual: listener-mode srtsink with 2 connected peers → both peers visible with addresses, per-caller stats, recent-loss readout
  • Manual: confirmed sender-side NAK'd-then-recovered loss displays green (Retransmitted: 678 (100% recovered)) rather than red, while TLPKTDROP would display red

🤖 Generated with Claude Code

Per Enstedt and others added 2 commits May 12, 2026 10:50
Adds on-demand SRT statistics for all four SRT block types
(efpsrt_input/output, mpegtssrt_input/output). Backend scans the
pipeline for srtsrc/srtsink elements, reads their libsrt stats
GstStructure (handling caller-mode top-level, listener-mode
GValueArray, and gst::Array variants across plugin versions), and
exposes them via GET /api/flows/{id}/srt-stats.

API design:
- SrtStats keyed by element name (`{block_id}:srtsink`)
- SrtConnectionStats with typed SrtRole / SrtMode enums
- SrtCallerStats splits sender vs receiver counters
  (packets_sent_lost / packets_received_lost, etc.) so the
  semantics of each counter is unambiguous
- Peer address parsed from GInetSocketAddress, formatted as ip:port

Frontend mirrors the WebRTC stats pattern:
- SrtStatsStore polls every 1s while the selected flow is running
  and the flow has at least one SRT block
- Compact inline view in the graph node: peer count, RTT, recent
  loss %
- Detailed property-inspector view with per-caller sections,
  separating NAK'd-then-retransmitted (recovered, green) from
  TLPKTDROP / TSBPD (actual data loss, red)
- Per-second deltas computed against the previous poll so loss /
  packet / byte counters show both lifetime totals and current
  rate ("134k (450/s)") — keeps the figures meaningful on
  long-running streams

Tested with caller-mode receivers, listener-mode senders with
multiple peers, and unit tests covering the parser fixtures.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Code review follow-ups:

- Promote `gio` from a backend-only direct dep to the workspace dep
  table so it stays version-aligned with the gstreamer/glib 0.22
  pins. Backend now references `gio.workspace = true`.

- Add unit tests for `caller_is_active` and `has_any_data` — both
  back the `connected` flag and the single-caller fall-through in
  `collect_element_stats`, so they deserve explicit coverage.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@srperens
srperens merged commit 423fba3 into main May 12, 2026
13 of 14 checks passed
@srperens
srperens deleted the feat/srt-statistics branch May 12, 2026 13:13
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