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//! ```ignore
16//! use rtc::statistics::StatsSelector;
17//!
18//! // Get all stats
19//! let all_stats = pc.get_stats(Instant::now(), StatsSelector::None);
20//!
21//! // Get stats for a specific sender
22//! let sender_stats = pc.get_stats(Instant::now(), StatsSelector::Sender(sender_id));
23//! ```
24
25use crate::rtp_transceiver::{RTCRtpReceiverId, RTCRtpSenderId};
26
27#[cfg(test)]
28mod statistics_tests;
29
30pub(crate) mod accumulator;
31pub mod report;
32pub mod stats;
33
34/// Selector for filtering statistics in `get_stats()`.
35///
36/// This enum corresponds to the optional `selector` parameter in the
37/// W3C WebRTC `getStats()` method. When provided, it filters the returned
38/// statistics to only those relevant to the specified sender or receiver.
39///
40/// # W3C Reference
41///
42/// See [The stats selection algorithm](https://www.w3.org/TR/webrtc/#the-stats-selection-algorithm)
43///
44/// # Variants
45///
46/// - `None` - Return all statistics for the entire connection
47/// - `Sender` - Return statistics for a specific RTP sender and referenced objects
48/// - `Receiver` - Return statistics for a specific RTP receiver and referenced objects
49pub enum StatsSelector {
50 /// Gather stats for the whole connection.
51 ///
52 /// Returns all available statistics objects including peer connection,
53 /// transport, ICE candidates, codecs, data channels, and all RTP streams.
54 None,
55
56 /// Gather stats for a specific RTP sender.
57 ///
58 /// Returns:
59 /// - All `RTCOutboundRtpStreamStats` for streams being sent by this sender
60 /// - All stats objects referenced by those outbound streams (transport,
61 /// codec, remote inbound stats, etc.)
62 Sender(RTCRtpSenderId),
63
64 /// Gather stats for a specific RTP receiver.
65 ///
66 /// Returns:
67 /// - All `RTCInboundRtpStreamStats` for streams being received by this receiver
68 /// - All stats objects referenced by those inbound streams (transport,
69 /// codec, remote outbound stats, etc.)
70 Receiver(RTCRtpReceiverId),
71}