Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves the documentation of the webrtc crate #482

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion ice/src/tcp_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod tcp_type_test;
use std::fmt;

// TCPType is the type of ICE TCP candidate as described in
// ttps://tools.ietf.org/html/rfc6544#section-4.5
// https://tools.ietf.org/html/rfc6544#section-4.5
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum TcpType {
/// The default value. For example UDP candidates do not need this field.
Expand Down
2 changes: 1 addition & 1 deletion ice/src/udp_mux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl UDPMuxDefault {

let s = match String::from_utf8(attr.value) {
// Per the RFC this shouldn't happen
// https://datatracker.ietf.org/doc/html/rfc5389#section-15.3
// https://tools.ietf.org/html/rfc5389#section-15.3
Err(err) => {
log::warn!(
"Failed to decode USERNAME from STUN message as UTF-8: {}",
Expand Down
2 changes: 1 addition & 1 deletion interceptor/src/stats/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ impl RTPWriter for RTPWriteRecorder {
}

/// Calculate the round trip time for a given peer as described in
/// [RFC3550 6.4.1](https://datatracker.ietf.org/doc/html/rfc3550#section-6.4.1).
/// [RFC3550 6.4.1](https://tools.ietf.org/html/rfc3550#section-6.4.1).
///
/// ## Params
///
Expand Down
2 changes: 1 addition & 1 deletion interceptor/src/stats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ mod outbound {
remote_round_trip_time_measurements: u64,

/// The fraction of packets lost reported for this stream.
/// Calculated as defined in [RFC3550](https://www.rfc-editor.org/rfc/rfc3550) section 6.4.1 and Appendix A.3.
/// Calculated as defined in [RFC3550](https://tools.ietf.org/html/rfc3550) section 6.4.1 and Appendix A.3.
remote_fraction_lost: Option<f64>,
}

Expand Down
2 changes: 1 addition & 1 deletion interceptor/src/twcc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct PktInfo {

/// Recorder records incoming RTP packets and their delays and creates
/// transport wide congestion control feedback reports as specified in
/// https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
/// https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
#[derive(Default, Debug, PartialEq, Clone)]
pub struct Recorder {
received_packets: Vec<PktInfo>,
Expand Down
2 changes: 1 addition & 1 deletion interceptor/src/twcc/receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct ReceiverInternal {
}

/// Receiver sends transport wide congestion control reports as specified in:
/// https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
/// https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
pub struct Receiver {
internal: Arc<ReceiverInternal>,

Expand Down
22 changes: 11 additions & 11 deletions rtp/src/codecs/h265/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ mod h265_test;
///

const H265NALU_HEADER_SIZE: usize = 2;
/// https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2
/// https://tools.ietf.org/html/rfc7798#section-4.4.2
const H265NALU_AGGREGATION_PACKET_TYPE: u8 = 48;
/// https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3
/// https://tools.ietf.org/html/rfc7798#section-4.4.3
const H265NALU_FRAGMENTATION_UNIT_TYPE: u8 = 49;
/// https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.4
/// https://tools.ietf.org/html/rfc7798#section-4.4.4
const H265NALU_PACI_PACKET_TYPE: u8 = 50;

/// H265NALUHeader is a H265 NAL Unit Header
/// https://datatracker.ietf.org/doc/html/rfc7798#section-1.1.4
/// https://tools.ietf.org/html/rfc7798#section-1.1.4
/// +---------------+---------------+
/// |0|1|2|3|4|5|6|7|0|1|2|3|4|5|6|7|
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Expand Down Expand Up @@ -97,7 +97,7 @@ impl H265NALUHeader {
/// | :...OPTIONAL RTP padding |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.1
/// Reference: https://tools.ietf.org/html/rfc7798#section-4.4.1
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265SingleNALUnitPacket {
/// payload_header is the header of the H265 packet.
Expand Down Expand Up @@ -186,7 +186,7 @@ impl H265SingleNALUnitPacket {
/// | :
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2
/// Reference: https://tools.ietf.org/html/rfc7798#section-4.4.2
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265AggregationUnitFirst {
donl: Option<u16>,
Expand Down Expand Up @@ -226,7 +226,7 @@ impl H265AggregationUnitFirst {
/// | :
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2
/// Reference: https://tools.ietf.org/html/rfc7798#section-4.4.2
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265AggregationUnit {
dond: Option<u8>,
Expand Down Expand Up @@ -266,7 +266,7 @@ impl H265AggregationUnit {
/// | :...OPTIONAL RTP padding |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2
/// Reference: https://tools.ietf.org/html/rfc7798#section-4.4.2
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265AggregationPacket {
first_unit: Option<H265AggregationUnitFirst>,
Expand Down Expand Up @@ -427,7 +427,7 @@ impl H265FragmentationUnitHeader {
/// | :...OPTIONAL RTP padding |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3
/// Reference: https://tools.ietf.org/html/rfc7798#section-4.4.3
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265FragmentationUnitPacket {
/// payload_header is the header of the H265 packet.
Expand Down Expand Up @@ -526,7 +526,7 @@ impl H265FragmentationUnitPacket {
/// | :...OPTIONAL RTP padding |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.4
/// Reference: https://tools.ietf.org/html/rfc7798#section-4.4.4
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265PACIPacket {
/// payload_header is the header of the H265 packet.
Expand Down Expand Up @@ -655,7 +655,7 @@ impl H265PACIPacket {
///

/// H265TSCI is a Temporal Scalability Control Information header extension.
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.5
/// Reference: https://tools.ietf.org/html/rfc7798#section-4.5
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct H265TSCI(pub u32);

Expand Down
4 changes: 2 additions & 2 deletions sctp/src/association/association_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ impl AssociationInternal {
..Default::default()
};

// According to RFC https://datatracker.ietf.org/doc/html/rfc4960#section-3.2.2
// According to RFC https://tools.ietf.org/html/rfc4960#section-3.2.2
// We report unknown parameters with a paramtype with bit 14 set as unrecognized
let unrecognized_params_from_init = i
.params
Expand Down Expand Up @@ -2174,7 +2174,7 @@ impl AssociationInternal {
self.handle_shutdown_complete(c).await?
} else {
/*
https://datatracker.ietf.org/doc/html/rfc4960#section-3
https://tools.ietf.org/html/rfc4960#section-3

00 - Stop processing this SCTP packet and discard it, do not
process any further chunks within it.
Expand Down
2 changes: 1 addition & 1 deletion sctp/src/param/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) fn build_param(raw_param: &Bytes) -> Result<Box<dyn Param + Send + Sy
ParamType::OutSsnResetReq => Ok(Box::new(ParamOutgoingResetRequest::unmarshal(raw_param)?)),
ParamType::ReconfigResp => Ok(Box::new(ParamReconfigResponse::unmarshal(raw_param)?)),
_ => {
// According to RFC https://datatracker.ietf.org/doc/html/rfc4960#section-3.2.1
// According to RFC https://tools.ietf.org/html/rfc4960#section-3.2.1
let stop_processing = ((raw_type >> 15) & 0x01) == 0;
if stop_processing {
Err(Error::ErrParamTypeUnhandled { typ: raw_type })
Expand Down
87 changes: 52 additions & 35 deletions webrtc/src/ice_transport/ice_connection_state.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,61 @@
use std::fmt;

/// RTCIceConnectionState indicates signaling state of the ICE Connection.
/// Indicates the signaling state of the ICE Connection.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub enum RTCIceConnectionState {
#[default]
Unspecified,

/// ICEConnectionStateNew indicates that any of the ICETransports are
/// in the "new" state and none of them are in the "checking", "disconnected"
/// or "failed" state, or all ICETransports are in the "closed" state, or
/// there are no transports.
New,
/// Indicates that the [`RTCPeerConnection`] is closed
///
/// [`RTCPeerConnection`]: crate::peer_connection::RTCPeerConnection
Closed,

/// ICEConnectionStateChecking indicates that any of the ICETransports
/// are in the "checking" state and none of them are in the "disconnected"
/// or "failed" state.
Checking,
/// Indicates all of the following:
/// - the previous state does not apply
/// - any of the [`RTCIceTransport`]s are in the `failed` state
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
Failed,

/// ICEConnectionStateConnected indicates that all ICETransports are
/// in the "connected", "completed" or "closed" state and at least one of
/// them is in the "connected" state.
Connected,
/// Indicates all of the following:
/// - none of the previous states apply
/// - any of the [`RTCIceTransport`]s are in the `disconnected` state
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
Disconnected,

/// ICEConnectionStateCompleted indicates that all ICETransports are
/// in the "completed" or "closed" state and at least one of them is in the
/// "completed" state.
Completed,
/// Indicates all of the following:
/// - none of the previous states apply
/// - all of the [`RTCIceTransport`]s are in the `new` or
/// `closed` state, or
/// - there are no transports
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
New,

/// ICEConnectionStateDisconnected indicates that any of the
/// ICETransports are in the "disconnected" state and none of them are
/// in the "failed" state.
Disconnected,
/// Indicates all of the following:
/// - none of the previous states apply
/// - any of the [`RTCIceTransport`]s are in the `new` or `checking` state
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
Checking,

/// ICEConnectionStateFailed indicates that any of the ICETransports
/// are in the "failed" state.
Failed,
/// Indicates all of the following:
/// - none of the previous states apply
/// - all of the [`RTCIceTransport`]s are in the `completed` or
/// `closed` state
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
Completed,

/// ICEConnectionStateClosed indicates that the PeerConnection's
/// isClosed is true.
Closed,
/// Indicates all of the following:
/// - none of the previous states apply
/// - all of the [`RTCIceTransport`]s are in the `connected`, `completed`, or
/// `closed` state
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
Connected,
}

const ICE_CONNECTION_STATE_NEW_STR: &str = "new";
Expand Down Expand Up @@ -68,13 +85,13 @@ impl From<&str> for RTCIceConnectionState {
impl From<u8> for RTCIceConnectionState {
fn from(v: u8) -> Self {
match v {
1 => RTCIceConnectionState::New,
2 => RTCIceConnectionState::Checking,
3 => RTCIceConnectionState::Connected,
4 => RTCIceConnectionState::Completed,
5 => RTCIceConnectionState::Disconnected,
6 => RTCIceConnectionState::Failed,
7 => RTCIceConnectionState::Closed,
1 => RTCIceConnectionState::Closed,
2 => RTCIceConnectionState::Failed,
3 => RTCIceConnectionState::Disconnected,
4 => RTCIceConnectionState::New,
5 => RTCIceConnectionState::Checking,
6 => RTCIceConnectionState::Completed,
7 => RTCIceConnectionState::Connected,
_ => RTCIceConnectionState::Unspecified,
}
}
Expand Down
22 changes: 14 additions & 8 deletions webrtc/src/ice_transport/ice_gathering_state.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
use std::fmt;

/// ICEGatheringState describes the state of the candidate gathering process.
/// Describes the state of the ICE candidate gathering process.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub enum RTCIceGatheringState {
#[default]
Unspecified,

/// ICEGatheringStateNew indicates that any of the ICETransports are
/// in the "new" gathering state and none of the transports are in the
/// "gathering" state, or there are no transports.
/// Any of the [`RTCIceTransport`]s are
/// in the `new` gathering state and none of the transports are in the
/// `gathering` state, or there are no transports.
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
New,

/// ICEGatheringStateGathering indicates that any of the ICETransports
/// are in the "gathering" state.
/// Any of the [`RTCIceTransport`]s
/// are in the `gathering` state.
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
Gathering,

/// ICEGatheringStateComplete indicates that at least one ICETransport
/// exists, and all ICETransports are in the "completed" gathering state.
/// At least one [`RTCIceTransport`]
/// exists, and all [`RTCIceTransport`]s are in the `complete` gathering state.
///
/// [`RTCIceTransport`]: crate::ice_transport::RTCIceTransport
Complete,
}

Expand Down
26 changes: 24 additions & 2 deletions webrtc/src/ice_transport/ice_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@ use serde::{Deserialize, Serialize};
use crate::error::{Error, Result};
use crate::ice_transport::ice_credential_type::RTCIceCredentialType;

/// ICEServer describes a single STUN and TURN server that can be used by
/// the ICEAgent to establish a connection with a peer.
/// Describes a single STUN or TURN server that can be used by
/// the ICE Agent to establish a connection with a peer.
#[derive(Default, Debug, Clone, Serialize, Deserialize, Hash)]
pub struct RTCIceServer {
/// A sequence of [STUN](https://tools.ietf.org/html/rfc5389)
/// or [TURN](https://tools.ietf.org/html/rfc5928) URIs to be used by
/// the ICE Agent to establish a connection with a peer.
///
/// STUN URIs (defined in [RFC7064](https://tools.ietf.org/html/rfc7064))
/// allow for the discovery of server-reflexive candidates.
///
/// TURN URIs (defined in [RFC7065](https://tools.ietf.org/html/rfc7065))
/// allow for the discovery of relayed candidates.
pub urls: Vec<String>,

/// If this [`RTCIceServer`] object represents a TURN server, then this attribute
/// specifies the username to use during the authentication process with the
/// TURN server.
pub username: String,

/// If this [`RTCIceServer`] object represents a TURN server, then this attribute
/// specifies the credential to use during the authentication process with the
/// TURN server. It represents a long-term authentication password, as described
/// in [RFC5389](https://tools.ietf.org/html/rfc5389).
pub credential: String,

/// **NOT IN SPEC:** If this [`RTCIceServer`] object represents a TURN server,
/// then this attribute indicates the type of credential to use to connect
/// to the TURN server.
pub credential_type: RTCIceCredentialType,
}

Expand Down
Loading