Skip to main content

rtc/statistics/
mod.rs

1//! Statistics module for WebRTC.
2//!
3//! This module provides:
4//! - `stats` - W3C WebRTC Statistics API types
5//! - `report` - Statistics report generation
6//!
7//! # Stats Selection
8//!
9//! When calling `get_stats()`, you can optionally provide a [`StatsSelector`]
10//! to filter the returned statistics to only those relevant to a specific
11//! sender or receiver.
12//!
13//! # Example
14//!
15//! ```
16//! use rtc::peer_connection::RTCPeerConnection;
17//! use rtc::rtp_transceiver::RTCRtpSenderId;
18//! use rtc::statistics::StatsSelector;
19//! use std::time::Instant;
20//!
21//! # fn example(pc: &mut RTCPeerConnection, sender_id: RTCRtpSenderId) {
22//! // Get all stats
23//! let all_stats = pc.get_stats(Instant::now(), StatsSelector::None);
24//!
25//! // Get stats for a specific sender
26//! let sender_stats = pc.get_stats(Instant::now(), StatsSelector::Sender(sender_id));
27//! # }
28//! ```
29
30use crate::rtp_transceiver::{RTCRtpReceiverId, RTCRtpSenderId};
31
32#[cfg(test)]
33mod statistics_tests;
34
35pub(crate) mod accumulator;
36pub mod report;
37pub mod stats;
38
39/// Selector for filtering statistics in `get_stats()`.
40///
41/// This enum corresponds to the optional `selector` parameter in the
42/// W3C WebRTC `getStats()` method. When provided, it filters the returned
43/// statistics to only those relevant to the specified sender or receiver.
44///
45/// # W3C Reference
46///
47/// See [The stats selection algorithm](https://www.w3.org/TR/webrtc/#the-stats-selection-algorithm)
48///
49/// # Variants
50///
51/// - `None` - Return all statistics for the entire connection
52/// - `Sender` - Return statistics for a specific RTP sender and referenced objects
53/// - `Receiver` - Return statistics for a specific RTP receiver and referenced objects
54pub enum StatsSelector {
55    /// Gather stats for the whole connection.
56    ///
57    /// Returns all available statistics objects including peer connection,
58    /// transport, ICE candidates, codecs, data channels, and all RTP streams.
59    None,
60
61    /// Gather stats for a specific RTP sender.
62    ///
63    /// Returns:
64    /// - All `RTCOutboundRtpStreamStats` for streams being sent by this sender
65    /// - All stats objects referenced by those outbound streams (transport,
66    ///   codec, remote inbound stats, etc.)
67    Sender(RTCRtpSenderId),
68
69    /// Gather stats for a specific RTP receiver.
70    ///
71    /// Returns:
72    /// - All `RTCInboundRtpStreamStats` for streams being received by this receiver
73    /// - All stats objects referenced by those inbound streams (transport,
74    ///   codec, remote outbound stats, etc.)
75    Receiver(RTCRtpReceiverId),
76}