Skip to main content

rtc/rtp_transceiver/rtp_sender/
rtp_coding_parameters.rs

1use crate::rtp_transceiver::{RtpStreamId, SSRC};
2
3/// RTP coding parameters providing information for encoding and decoding.
4///
5/// Contains the RTP-level parameters that identify and configure a specific
6/// encoding or decoding of a media stream. This includes the SSRC, optional
7/// RID for simulcast identification, and parameters for retransmission (RTX)
8/// and forward error correction (FEC).
9///
10/// # Fields
11///
12/// * `rid` - RTP stream identifier, used in simulcast to identify quality layers (e.g., "q", "h", "f")
13/// * `ssrc` - Synchronization source identifier, uniquely identifies this RTP stream
14/// * `rtx` - Optional retransmission parameters for packet loss recovery
15/// * `fec` - Optional forward error correction parameters
16///
17/// # Examples
18///
19/// ```
20/// use rtc::rtp_transceiver::rtp_sender::RTCRtpCodingParameters;
21///
22/// // Basic parameters without retransmission or FEC
23/// let params = RTCRtpCodingParameters {
24///     rid: "".to_string(),
25///     ssrc: Some(12345),
26///     rtx: None,
27///     fec: None,
28/// };
29/// ```
30///
31/// ```
32/// use rtc::rtp_transceiver::rtp_sender::{RTCRtpCodingParameters, RTCRtpRtxParameters};
33///
34/// // Simulcast layer with retransmission
35/// let params = RTCRtpCodingParameters {
36///     rid: "h".to_string(),  // half resolution layer
37///     ssrc: Some(12345),
38///     rtx: Some(RTCRtpRtxParameters {
39///         ssrc: 12346,  // RTX uses different SSRC
40///     }),
41///     fec: None,
42/// };
43/// ```
44///
45/// # Specifications
46///
47/// * [ORTC RTCRtpCodingParameters](http://draft.ortc.org/#dom-rtcrtpcodingparameters)
48/// * [RFC 4588 - RTP Retransmission Payload Format](https://www.rfc-editor.org/rfc/rfc4588.html)
49/// * [RFC 8852 - RTP Stream Identifier](https://www.rfc-editor.org/rfc/rfc8852.html)
50#[derive(Default, Debug, Clone)]
51pub struct RTCRtpCodingParameters {
52    /// RTP stream identifier for simulcast/layered streams
53    pub rid: RtpStreamId,
54
55    /// Synchronization source identifier
56    pub ssrc: Option<SSRC>,
57    /// RTX (retransmission) parameters
58    pub rtx: Option<RTCRtpRtxParameters>,
59    /// FEC (forward error correction) parameters
60    pub fec: Option<RTCRtpFecParameters>,
61}
62
63/// RTX parameters for retransmission streams.
64///
65/// Configures a separate RTP stream used for retransmitting lost packets.
66/// The RTX stream uses its own SSRC to avoid interfering with the original
67/// media stream.
68///
69/// # Examples
70///
71/// ```
72/// use rtc::rtp_transceiver::rtp_sender::RTCRtpRtxParameters;
73///
74/// let rtx = RTCRtpRtxParameters {
75///     ssrc: 67890,  // Different from the main stream's SSRC
76/// };
77/// ```
78///
79/// # Specifications
80///
81/// * [ORTC RTCRtpRtxParameters](https://draft.ortc.org/#dom-rtcrtprtxparameters)
82/// * [RFC 4588 - RTP Retransmission Payload Format](https://www.rfc-editor.org/rfc/rfc4588.html)
83#[derive(Default, Debug, Clone)]
84pub struct RTCRtpRtxParameters {
85    /// SSRC for the RTX stream
86    pub ssrc: SSRC,
87}
88
89/// FEC parameters for forward error correction streams.
90///
91/// Configures a separate RTP stream used for forward error correction,
92/// allowing receivers to recover from packet loss without retransmission.
93/// The FEC stream uses its own SSRC.
94///
95/// # Examples
96///
97/// ```
98/// use rtc::rtp_transceiver::rtp_sender::RTCRtpFecParameters;
99///
100/// let fec = RTCRtpFecParameters {
101///     ssrc: 99999,  // Different from the main stream's SSRC
102/// };
103/// ```
104///
105/// # Specifications
106///
107/// * [ORTC RTCRtpFecParameters](https://draft.ortc.org/#dom-rtcrtpfecparameters)
108/// * [RFC 5109 - RTP Payload Format for Generic FEC](https://www.rfc-editor.org/rfc/rfc5109.html)
109#[derive(Default, Debug, Clone)]
110pub struct RTCRtpFecParameters {
111    /// SSRC for the FEC stream
112    pub ssrc: SSRC,
113}