Skip to main content

vector_calls/
stats.rs

1//! The counters one call keeps for its whole life, shared by the media threads, the
2//! liveness check and the stats line. Atomics so no thread waits on another.
3
4use std::sync::atomic::{AtomicU32, AtomicU64, Ordering};
5
6#[derive(Default)]
7pub struct MediaStats {
8    pub sent: AtomicU64,
9    pub send_dropped: AtomicU64,
10    pub received: AtomicU64,
11    /// Frames skipped over: a hole wider than FEC covers, or a jump past a backlog.
12    pub lost: AtomicU64,
13    /// Frames the buffer discarded on purpose to take latency back.
14    pub shed: AtomicU64,
15    /// Frames rebuilt from the FEC data in their successor.
16    pub rebuilt: AtomicU64,
17    pub concealed: AtomicU64,
18    pub late: AtomicU64,
19    pub depth_ms: AtomicU32,
20    pub jitter_ms: AtomicU32,
21    /// Cable clicks cut out of the microphone before encoding.
22    pub clicks_cut: AtomicU64,
23    /// What the encoder is sending at, in kbit/s.
24    pub bitrate_kbps: AtomicU32,
25    /// Packets the network dropped on the way out, percent of the last second (f32 bits).
26    pub net_loss: AtomicU32,
27    /// Loudness of what the microphone sends after processing, 0 to 1 (f32 bits).
28    pub mic_level: AtomicU32,
29    /// Loudness of what the peer sends, 0 to 1 (f32 bits).
30    pub peer_level: AtomicU32,
31    /// A shared screen's sound: frames sent and received on its own track.
32    pub share_sent: AtomicU64,
33    pub share_received: AtomicU64,
34    /// The next outgoing sequence number (u16). Lives here, not in the capture
35    /// loop, so a restarted engine keeps counting: the peer drops everything
36    /// numbered below what it last played, and a reset silences us until the
37    /// count catches back up.
38    pub next_seq: AtomicU32,
39    pub next_share_seq: AtomicU32,
40}
41
42impl MediaStats {
43    pub fn mic_level(&self) -> f32 {
44        f32::from_bits(self.mic_level.load(Ordering::Relaxed))
45    }
46    pub fn peer_level(&self) -> f32 {
47        f32::from_bits(self.peer_level.load(Ordering::Relaxed))
48    }
49    pub fn net_loss(&self) -> f32 {
50        f32::from_bits(self.net_loss.load(Ordering::Relaxed))
51    }
52}