Skip to content

getStats: add remote-outbound-rtp + inbound jitter/loss/kind/codecId#40

Merged
nus merged 1 commit into
mainfrom
getstats-inbound-remote-outbound
Jun 8, 2026
Merged

getStats: add remote-outbound-rtp + inbound jitter/loss/kind/codecId#40
nus merged 1 commit into
mainfrom
getstats-inbound-remote-outbound

Conversation

@nus

@nus nus commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Addresses the W3C getStats gap from the RFC/W3C divergence audit, and fixes a latent RTCP-feedback bug found along the way.

Problem

The receive path tracked only packetsReceived/bytesReceived, so InboundRtpStats exposed neither loss nor jitter, and there was no remote-outbound-rtp stat despite RTCP SR being parsed. Worse, webdartc emitted RTCP RR report blocks with hard-coded fractionLost=0/cumulativeLost=0/jitter=0 — so remote senders received no real reception feedback.

Change

  • New RtpReceptionTracker (receive_stats.dart): pure RFC 3550 §A.3 loss + §A.8 interarrival jitter accounting per SSRC, unit-tested in isolation (mirrors how rtcp_math.dart isolates pure RTCP math).
  • _RtpRecvStats drives the tracker (bound to the stream's clock rate on the first packet) and captures the latest SR detail.
  • RR blocks now carry real fractionLost / cumulativeLost / extendedHighestSeq / jitter instead of zeros.
  • InboundRtpStats gains kind, packetsLost, jitter (seconds), codecId; new RemoteOutboundRtpStats emitted from received SR (packetsSent/bytesSent/remoteTimestamp/reportsReceived), paired to the inbound entry via localId.
  • ntpToDateTime helper (rtcp_math.dart) for the SR remoteTimestamp.

Notes (from /simplify)

  • Receive-side jitter uses the negotiated a=rtpmap clock rate (new _ptClockRateMap, mirroring _ptKindMap), not a hardcoded 48k/90k guess — correct for G.711/8 kHz and other non-default codecs.
  • Codec (kind + clock rate) is resolved once on first-bind, not per packet, keeping the RTP receive hot path cheap.

Tests

  • Tracker unit tests (receive_stats_test.dart): in-order / gap / duplicate / wrap / fraction-lost / jitter.
  • getStats loopback (stats_test.dart): asserts the new inbound fields and the remote-outbound pairing.
  • dart analyze clean; 642 unit + 22 e2e pass (Chrome RTP/RTCP interop intact with the corrected non-zero RR feedback).

🤖 Generated with Claude Code

The receive path tracked only packetsReceived/bytesReceived, so
InboundRtpStats exposed neither loss nor jitter, and webdartc emitted
RTCP RR report blocks with hard-coded fractionLost=0/cumulativeLost=0/
jitter=0 — giving remote senders no real reception feedback. There was
also no remote-outbound-rtp stat despite SR being parsed.

- New `RtpReceptionTracker` (lib/rtp/receive_stats.dart): pure RFC 3550
  §A.3 loss + §A.8 interarrival jitter accounting per SSRC, unit-tested
  in isolation.
- `_RtpRecvStats` now drives the tracker (lazily bound to the stream's
  clock rate on the first packet) and captures the latest SR detail.
- RTCP RR blocks now carry real fractionLost / cumulativeLost /
  extendedHighestSeq / jitter instead of zeros — fixes the all-zero
  feedback gap.
- InboundRtpStats gains `kind`, `packetsLost`, `jitter` (seconds), and
  `codecId`; new RemoteOutboundRtpStats emitted from received SR
  (packetsSent/bytesSent/remoteTimestamp/reportsReceived), paired with
  the inbound entry via localId.
- `ntpToDateTime` helper (rtcp_math.dart) for the SR remoteTimestamp.

Tracker has direct unit tests (loss/dup/wrap/fraction/jitter); the
getStats loopback test asserts the new inbound fields and the
remote-outbound pairing. Full suite + e2e (Chrome RTP/RTCP) pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@nus nus merged commit c73ecd2 into main Jun 8, 2026
15 checks passed
@nus nus deleted the getstats-inbound-remote-outbound branch June 8, 2026 05:42
nus added a commit that referenced this pull request Jun 8, 2026
…edia (#43)

Scenario 2 only asserted onTrack — the receive-side getStats fields added
in #40 (inbound jitter/packetsLost/kind/codecId, and the SR-derived
remote-outbound-rtp) were never checked against a real sender.

Extend the media-receiver helper to poll getStats once a track is flowing
and assert:
- inbound-rtp: packetsReceived>0, jitter>=0 (real interarrival jitter),
  kind, and a resolvable codecId;
- remote-outbound-rtp: present and linked to the inbound entry via
  localId, with reportsReceived>0 and a non-null remoteTimestamp.

packetsSent is only required non-negative, not positive: it's the SR's
sender packet count, which is browser/timing-dependent (Firefox's first SR
reports 0, Chrome ~120) — caught by running the Firefox e2e too.

Validated against both browsers, including under 5% loss where the helper
observed real packetsLost: e.g. Chrome jitter≈0.0012s / packetsSent=122,
and a lossy run "packets=119 lost=7". Confirms #40's jitter and loss
computation against conditions the loopback unit test can't reproduce.

Co-authored-by: Claude Opus 4.8 <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