rtc/statistics/stats/codec.rs
1//! Codec statistics.
2//!
3//! This module contains the [`RTCCodecStats`] type which provides
4//! information about codecs used for RTP streams.
5
6use super::RTCStats;
7use crate::rtp_transceiver::PayloadType;
8use serde::{Deserialize, Serialize};
9
10/// Statistics for a codec used in an RTP stream.
11///
12/// This struct corresponds to the `RTCCodecStats` dictionary in the
13/// W3C WebRTC Statistics API. It provides information about codecs
14/// currently in use for sending or receiving RTP streams.
15///
16/// Codec stats are only present when the codec is actively used by
17/// at least one RTP stream.
18///
19/// # W3C Reference
20///
21/// See [RTCCodecStats](https://www.w3.org/TR/webrtc-stats/#codec-dict*)
22#[derive(Debug, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24pub struct RTCCodecStats {
25 /// Base statistics fields (timestamp, type, id).
26 #[serde(flatten)]
27 pub stats: RTCStats,
28
29 /// The RTP payload type for this codec.
30 ///
31 /// This is the numeric payload type used in RTP packets.
32 pub payload_type: PayloadType,
33
34 /// The MIME type of the codec.
35 ///
36 /// Examples: "video/VP8", "video/H264", "audio/opus".
37 pub mime_type: String,
38
39 /// The number of audio channels for audio codecs.
40 ///
41 /// For video codecs, this is 0.
42 pub channels: u16,
43
44 /// The codec clock rate in Hz.
45 ///
46 /// For audio, this is typically 48000 (Opus) or 8000 (G.711).
47 /// For video, this is typically 90000.
48 pub clock_rate: u32,
49
50 /// The SDP format-specific parameters line (fmtp).
51 ///
52 /// This contains codec-specific configuration from the SDP.
53 /// For example, H.264 profile-level-id or Opus parameters.
54 pub sdp_fmtp_line: String,
55}