Skip to main content

RtcConfig

Struct RtcConfig 

Source
pub struct RtcConfig { /* private fields */ }
Expand description

Customized config for creating an Rtc instance.

use std::time::Instant;
use str0m::RtcConfig;

let rtc = RtcConfig::new()
    .set_ice_lite(true)
    .build(Instant::now());

Configs implement Clone to help create multiple Rtc instances.

Implementations§

Source§

impl RtcConfig

Source

pub fn new() -> Self

Creates a new default config.

Source

pub fn local_ice_credentials(&self) -> &Option<IceCreds>

Get the local ICE credentials, if set.

If not specified, local credentials will be randomly generated when building the Rtc instance.

Source

pub fn set_local_ice_credentials(self, local_ice_credentials: IceCreds) -> Self

Explicitly sets local ICE credentials.

Source

pub fn set_crypto_provider(self, p: Arc<CryptoProvider>) -> Self

Set the crypto provider.

This overrides what is set in crate::crypto::CryptoProvider::install_process_default().

Source

pub fn crypto_provider(&self) -> Option<&Arc<CryptoProvider>>

The configured crypto provider, if explicitly set.

Returns None if not explicitly set via Self::set_crypto_provider(). When None, the process default will be checked when building the Rtc instance.

Source

pub fn dtls_cert(&self) -> Option<&DtlsCert>

Returns the configured DTLS certificate, if set.

If not set, a certificate will be generated automatically.

Source

pub fn set_dtls_cert(self, cert: DtlsCert) -> Self

Set a pregenerated DTLS certificate.

If not set, a certificate will be generated automatically using the configured crypto provider.


let provider = crypto::from_feature_flags();
let cert = provider.dtls_provider.generate_certificate().unwrap();
let rtc_config = RtcConfig::default()
    .set_dtls_cert(cert);
Source

pub fn set_ice_lite(self, enabled: bool) -> Self

Toggle ice lite. Ice lite is a mode for WebRTC servers with public IP address. An Rtc instance in ice lite mode will not make STUN binding requests, but only answer to requests from the remote peer.

See ICE RFC

Source

pub fn set_initial_stun_rto(&mut self, rto: Duration)

Sets the initial STUN retransmission timeout (RTO).

This is the initial wait time before a STUN request is retransmitted. The timeout will double with each retry, starting from this value.

Defaults to 250ms.

Source

pub fn set_max_stun_rto(&mut self, rto: Duration)

Sets the maximum STUN retransmission timeout for the ICE agent.

This is the upper bound for how long to wait between retransmissions. It also controls how often successful bindings are checked.

Defaults to 3000ms.

Source

pub fn set_max_stun_retransmits(&mut self, num: usize)

Sets the maximum number of retransmits for STUN messages.

Defaults to 9.

Source

pub fn fingerprint_verification(&self) -> bool

Get fingerprint verification mode.

let config = Rtc::builder();

// Defaults to true.
assert!(config.fingerprint_verification());
Source

pub fn set_fingerprint_verification(self, enabled: bool) -> Self

Toggle certificate fingerprint verification.

By default the certificate fingerprint is verified.

Source

pub fn ice_lite(&self) -> bool

Tells whether ice lite is enabled.

let config = Rtc::builder();

// Defaults to false.
assert_eq!(config.ice_lite(), false);
Source

pub fn codec_config(&mut self) -> &mut CodecConfig

Lower level access to precise configuration of codecs (payload types).

Source

pub fn clear_codecs(self) -> Self

Clear all configured codecs.

// For the session to use only OPUS and VP8.
let mut rtc = RtcConfig::default()
    .clear_codecs()
    .enable_opus(true, false)
    .enable_vp8(true)
    .build(Instant::now());
Source

pub fn enable_opus(self, enabled: bool, use_red: bool) -> Self

Enable opus audio codec, optionally with RFC 2198 RED (redundant audio).

Enabled by default (without RED). use_red folds a RED payload type onto Opus so the receiver can recover packet loss without retransmission, at the cost of extra audio payload size. Each audio codec carries its own RED payload type. The redundancy depth is set with Self::set_red_distances (default one level, the previous frame), and wrapping can be toggled at runtime on the send side without renegotiation via DirectApi::set_red_send.

Source

pub fn set_red_distances(self, distances: &[u32]) -> Self

Set the RFC 2198 RED send-side redundancy pattern: how many packets back each redundant level carries. [1] (the default) sends one level, the previous frame, as browsers do; [1, 3, 5] sends three levels for higher loss at the cost of more bandwidth.

The pattern is sanitised (zeros and values deeper than the recovery depth are dropped, then sorted and de-duped) and always includes distance 1 as the recovery anchor (so [2, 4] becomes [1, 2, 4]), falling back to [1] if empty. This only sets the pattern; enable RED via the use_red argument of an audio codec (e.g. Self::enable_opus) for it to take effect.

Source

pub fn enable_pcmu(self, enabled: bool, use_red: bool) -> Self

Enable PCM μ-law audio codec, optionally with RFC 2198 RED (see Self::enable_opus for use_red).

This is 14-bit audio compressed to 8-bit as specified by G.711

Source

pub fn enable_pcma(self, enabled: bool, use_red: bool) -> Self

Enable PCM a-law audio codec, optionally with RFC 2198 RED (see Self::enable_opus for use_red).

This is 13-bit audio compressed to 8-bit as specified by G.711

Source

pub fn enable_g722(self, enabled: bool, use_red: bool) -> Self

Enable G722 audio codec.

This is 16 kHz audio compressed to 64 kbit/s as specified by G.722. Note that per RFC 3551 §4.5.2 the RTP clock rate on the wire is 8000 Hz even though the codec samples at 16 kHz. str0m treats G722 as a 16 kHz codec in the API and handles the 8 kHz RTP timestamp mapping internally. See https://en.wikipedia.org/wiki/RTP_payload_formats#cite_note-55

See Self::enable_opus for use_red.

Source

pub fn enable_comfort_noise(self, enabled: bool) -> Self

Enable the RFC 3389 Comfort Noise payload at 8000 Hz.

Disabled by default. Higher clock rates require a dynamic payload type and can be added through RtcConfig::codec_config.

Source

pub fn enable_amr_wb(self, enabled: bool) -> Self

Enable AMR-WB audio codec.

Disabled by default.

Source

pub fn enable_vp8(self, enabled: bool) -> Self

Enable VP8 video codec.

Enabled by default.

Source

pub fn enable_h264(self, enabled: bool) -> Self

Enable H264 video codec.

Enabled by default.

Source

pub fn enable_h265(self, enabled: bool) -> Self

Enable H265 video codec.

Enabled by default.

Source

pub fn enable_h266(self, enabled: bool) -> Self

Enable H266 (VVC) video codec.

Disabled by default: no major browser (Chrome, Safari, Firefox) currently supports H.266/VVC, so it is opt-in.

Source

pub fn enable_vp9(self, enabled: bool) -> Self

Enable VP9 video codec.

Enabled by default.

Source

pub fn enable_av1(self, enabled: bool) -> Self

Enable AV1 video codec.

Enabled by default.

Source

pub fn extension_map(&mut self) -> &mut ExtensionMap

Configure the RTP extension mappings.

The default extension map is

let exts = ExtensionMap::standard();

assert_eq!(exts.id_of(Extension::AudioLevel), Some(1));
assert_eq!(exts.id_of(Extension::AbsoluteSendTime), Some(2));
assert_eq!(exts.id_of(Extension::TransportSequenceNumber), Some(3));
assert_eq!(exts.id_of(Extension::RtpMid), Some(4));
assert_eq!(exts.id_of(Extension::RtpStreamId), Some(10));
assert_eq!(exts.id_of(Extension::RepairedRtpStreamId), Some(11));
assert_eq!(exts.id_of(Extension::VideoOrientation), Some(13));
Source

pub fn set_extension_map(self, exts: ExtensionMap) -> Self

Set the extension map replacing the existing.

Source

pub fn clear_extension_map(self) -> Self

Clear out the standard extension mappings.

Source

pub fn set_extension(self, id: u8, ext: Extension) -> Self

Set an extension mapping on session level.

The media level will be capped by the extension enabled on session level.

The id must be 1-14 inclusive (1-indexed).

Source

pub fn set_stats_interval(self, interval: Option<Duration>) -> Self

Set the interval between statistics events.

None turns off the stats events.

This includes MediaEgressStats, MediaIngressStats

Source

pub fn stats_interval(&self) -> Option<Duration>

The configured statistics interval.

None means statistics are disabled.

let config = Rtc::builder();

// Defaults to None.
assert_eq!(config.stats_interval(), None);
Source

pub fn set_rtcp_report_interval_audio(self, interval: Duration) -> Self

Sets the interval between RTCP sender/receiver reports for audio streams.

Defaults to 5 seconds.

§Panics

Panics if interval is zero.

Source

pub fn rtcp_report_interval_audio(&self) -> Duration

Returns the interval between RTCP sender/receiver reports for audio streams.

Source

pub fn set_rtcp_report_interval_video(self, interval: Duration) -> Self

Sets the interval between RTCP sender/receiver reports for video streams.

Defaults to 1 second.

§Panics

Panics if interval is zero.

Source

pub fn rtcp_report_interval_video(&self) -> Duration

Returns the interval between RTCP sender/receiver reports for video streams.

Source

pub fn enable_bwe(self, initial_estimate: Option<Bitrate>) -> Self

Enables estimation of available bandwidth (BWE).

None disables the BWE. This is an estimation of the send bandwidth, not receive.

This includes setting the initial estimate to start with.

Source

pub fn bwe_initial_bitrate(&self) -> Option<Bitrate>

The initial bitrate as set by Self::enable_bwe().

let config = Rtc::builder();

// Defaults to None - BWE off.
assert_eq!(config.bwe_initial_bitrate(), None);
Source

pub fn set_reordering_size_audio(self, size: usize) -> Self

Sets the number of packets held back for reordering audio packets.

Str0m tries to deliver the frames in order. This number determines how many packets to “wait” before releasing media contiguous: false.

This setting is ignored in RTP mode where RTP packets can arrive out of order.

Source

pub fn reordering_size_audio(&self) -> usize

Returns the setting for audio reordering size.

let config = Rtc::builder();

// Defaults to 15.
assert_eq!(config.reordering_size_audio(), 15);

This setting is ignored in RTP mode where RTP packets can arrive out of order.

Source

pub fn set_reordering_timeout_audio(self, timeout: Option<Duration>) -> Self

Sets how long the oldest audio frame may wait to finish or for missing earlier packets.

On expiry, an incomplete frame is dropped; a complete frame can move past a gap. Later frames stay buffered and retain their own deadlines. The default is 1 second. None disables this deadline and keeps count-based waiting only. Applies to audio streams in frame mode, not RTP mode.

Source

pub fn reordering_timeout_audio(&self) -> Option<Duration>

Returns the configured audio reordering timeout.

Source

pub fn set_reordering_size_video(self, size: usize) -> Self

Sets the number of packets held back for reordering video packets.

Str0m tries to deliver the frames in order. This number determines how many packets to “wait” before releasing media with gaps.

This must be at least as big as the number of packets the biggest keyframe can be split over.

WARNING: video is very different to audio. Setting this value too low will result in missing video data. The 0 (as described for audio) is not relevant for video.

Video recovery waits for a complete successor and missing packets’ NACK attempts plus three RTTs. When NACK timing is unavailable, it waits three RTTs from the complete candidate’s earliest receipt instead (100 ms RTT until measured). An incomplete frame without a complete successor has no age deadline.

Default: 30

This setting is ignored in RTP mode where RTP packets can arrive out of order.

Source

pub fn reordering_size_video(&self) -> usize

Returns the setting for video reordering size.

let config = Rtc::builder();

// Defaults to 30.
assert_eq!(config.reordering_size_video(), 30);

This setting is ignored in RTP mode where RTP packets can arrive out of order.

Source

pub fn set_pause_threshold(self, threshold: Duration) -> Self

Sets how long an incoming stream may receive no packets before it is reported paused. Defaults to 1.5 seconds and applies to all incoming streams created by this Rtc.

Source

pub fn pause_threshold(&self) -> Duration

Returns the incoming stream pause threshold.

Source

pub fn set_send_buffer_audio(self, size: usize) -> Self

Sets the buffer size for outgoing audio packets.

This must be larger than 0. The value configures an internal ring buffer used as a temporary holding space between calling Writer::write and Rtc::poll_output.

For audio one call to write() typically results in one RTP packet since the entire payload fits in one. If you can guarantee that every write() is a single RTP packet, and is always followed by a poll_output(), it might be possible to set this value to 1. But that would give no margins for unexpected patterns.

panics if set to 0.

Source

pub fn send_buffer_audio(&self) -> usize

Returns the setting for audio resend size.

let config = Rtc::builder();

// Defaults to 50.
assert_eq!(config.send_buffer_audio(), 50);
Source

pub fn set_send_buffer_video(self, size: usize) -> Self

Sets the buffer size for outgoing video packets and resends.

This must be larger than 0. The value configures an internal ring buffer that is both used as a temporary holding space between calling Writer::write and Rtc::poll_output as well as for fulfilling resends.

For video, this buffer is used for more than for audio. First, a call to write() often results in multiple RTP packets since large frames don’t fit in one payload. That means the buffer must be at least as large to hold all those packets. Second, when the remote requests resends (NACK), those are fulfilled from this buffer. Third, for Bandwidth Estimation (BWE), when probing for available bandwidth, packets from this buffer are used to do “spurious resends”, i.e. we do resends for packets that were not asked for.

Source

pub fn send_buffer_video(&self) -> usize

Returns the setting for video resend size.

let config = Rtc::builder();

// Defaults to 1000.
assert_eq!(config.send_buffer_video(), 1000);
Source

pub fn set_sctp_max_buffered_amount(self, bytes: usize) -> Self

Sets how many bytes the data channels can buffer for sending, summed over all channels.

Channel::write() does not accept a message (returns false) that would take the total buffered amount above this limit. A message larger than the limit is never accepted.

Written data counts as buffered until the remote peer acknowledges it, including after it has been sent. The limit therefore also caps the data in flight, and with it the data channel throughput at about this many bytes per round trip. The SCTP congestion window and the remote peer’s advertised receive window can limit the data in flight further.

Raising the limit helps a sender whose data rate times the round trip time exceeds it. Beyond what the network path holds, a higher limit only adds queueing delay, and accepted data is kept in memory until it is acknowledged.

Defaults to 128 KiB.

Source

pub fn sctp_max_buffered_amount(&self) -> usize

Returns how many bytes the data channels can buffer for sending.

let config = Rtc::builder();

// Defaults to 128 KiB.
assert_eq!(config.sctp_max_buffered_amount(), 128 * 1024);
Source

pub fn set_sctp_max_message_size(self, bytes: u32) -> Self

Sets the maximum data channel message size this peer can receive, in bytes.

This limit is advertised in SDP as a=max-message-size and applied to SCTP, including when using the direct API or SNAP. It does not change the remote peer’s receive limit or the local send buffer limit.

The SCTP receive storage budget is at least 1 MiB and large enough to reassemble one message at this limit. Storage is allocated as data arrives.

A value of 0 advertises unlimited message size, subject to local capacity. Internally, both the message limit and receive storage budget are u32::MAX.

Defaults to 256 KiB.

Source

pub fn sctp_max_message_size(&self) -> u32

Returns the maximum data channel message size this peer can receive, in bytes.

let config = RtcConfig::new().set_sctp_max_message_size(512 * 1024);
assert_eq!(config.sctp_max_message_size(), 512 * 1024);
Source

pub fn set_rtp_mode(self, enabled: bool) -> Self

Make the entire Rtc be in RTP mode.

This means all media, read from RtpPacket and written to StreamTx::write_rtp are RTP packetized. It bypasses all internal packetization/depacketization inside str0m.

WARNING: This is a low level API and is not str0m’s primary use case.

Source

pub fn rtp_mode(&self) -> bool

Checks if RTP mode is set.

let config = Rtc::builder();

// Defaults to false.
assert_eq!(config.rtp_mode(), false);
Source

pub fn enable_raw_packets(self, enabled: bool) -> Self

Enable the Event::RawPacket event.

This clones data, and is therefore expensive. Should not be enabled outside of tests and troubleshooting.

Source

pub fn set_snap_enabled(self, enabled: bool) -> Self

Enable SNAP (SCTP Negotiation Acceleration Protocol).

When enabled, the a=sctp-init attribute is included in outgoing SDP offers, allowing the SCTP association to skip the 4-way handshake and go directly to established state. This saves up to two network round-trip times when establishing data channels.

If the remote answer does not accept SNAP, str0m logs a warning and falls back to the regular SCTP handshake.

When this is false, outgoing SDP offers will not include a=sctp-init. However, incoming offers that contain a=sctp-init will still be reciprocated in answers, since str0m always supports the extension at the protocol level (per §5.4 of draft-hancke-tsvwg-snap).

See draft-hancke-tsvwg-snap.

Default: false

Source

pub fn set_dtls_version(self, version: DtlsVersion) -> Self

Set which DTLS version to use.

Defaults to DtlsVersion::Dtls12.

Source

pub fn dtls_version(&self) -> DtlsVersion

Get the configured DTLS version.

Source

pub fn set_mtu(self, range: RangeInclusive<usize>) -> Self

Set the MTU as a target..=warn inclusive range.

  • *range.start() is the target MTU: the size str0m aims for when fragmenting outgoing packets. Must be within [DATAGRAM_MTU_TARGET_MIN, DATAGRAM_MTU_TARGET_MAX].
  • *range.end() is the warn threshold: packets whose length exceeds the target trigger a warning.

Set as target..=target to warn packets bigger than target. Set as target..=usize::MAX to disable warning.

Defaults to DATAGRAM_MTU_TARGET..=DATAGRAM_MTU_WARN.

Source

pub fn mtu(&self) -> usize

Get the configured target MTU (the value str0m aims for).

Source

pub fn mtu_warn(&self) -> usize

Get the configured warn threshold above which outgoing packets trigger a warning trace.

Source

pub fn set_vp9_packetizer_mode(self, mode: Vp9PacketizerMode) -> Self

Set the VP9 packetizer mode.

VP9 supports two RTP payload descriptor formats:

Source

pub fn vp9_packetizer_mode(&self) -> Vp9PacketizerMode

Returns the configured VP9 packetizer mode.

let config = Rtc::builder();

// Defaults to NonFlexible.
assert_eq!(config.vp9_packetizer_mode(), Vp9PacketizerMode::NonFlexible);
Source

pub fn build(self, start: Instant) -> Rtc

Create a Rtc from the configuration.

Trait Implementations§

Source§

impl Clone for RtcConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RtcConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RtcConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CryptoSafe for T
where T: Send + Sync + Debug,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more