pub struct RtcConfig { /* private fields */ }Expand description
Implementations§
Source§impl RtcConfig
impl RtcConfig
Sourcepub fn local_ice_credentials(&self) -> &Option<IceCreds>
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.
Sourcepub fn set_local_ice_credentials(self, local_ice_credentials: IceCreds) -> Self
pub fn set_local_ice_credentials(self, local_ice_credentials: IceCreds) -> Self
Explicitly sets local ICE credentials.
Sourcepub fn set_crypto_provider(self, p: Arc<CryptoProvider>) -> Self
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().
Sourcepub fn crypto_provider(&self) -> Option<&Arc<CryptoProvider>>
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.
Sourcepub fn dtls_cert(&self) -> Option<&DtlsCert>
pub fn dtls_cert(&self) -> Option<&DtlsCert>
Returns the configured DTLS certificate, if set.
If not set, a certificate will be generated automatically.
Sourcepub fn set_dtls_cert(self, cert: DtlsCert) -> Self
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);Sourcepub fn set_ice_lite(self, enabled: bool) -> Self
pub fn set_ice_lite(self, enabled: bool) -> Self
Sourcepub fn set_initial_stun_rto(&mut self, rto: Duration)
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.
Sourcepub fn set_max_stun_rto(&mut self, rto: Duration)
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.
Sourcepub fn set_max_stun_retransmits(&mut self, num: usize)
pub fn set_max_stun_retransmits(&mut self, num: usize)
Sets the maximum number of retransmits for STUN messages.
Defaults to 9.
Sourcepub fn fingerprint_verification(&self) -> bool
pub fn fingerprint_verification(&self) -> bool
Get fingerprint verification mode.
let config = Rtc::builder();
// Defaults to true.
assert!(config.fingerprint_verification());Sourcepub fn set_fingerprint_verification(self, enabled: bool) -> Self
pub fn set_fingerprint_verification(self, enabled: bool) -> Self
Toggle certificate fingerprint verification.
By default the certificate fingerprint is verified.
Sourcepub fn ice_lite(&self) -> bool
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);Sourcepub fn codec_config(&mut self) -> &mut CodecConfig
pub fn codec_config(&mut self) -> &mut CodecConfig
Lower level access to precise configuration of codecs (payload types).
Sourcepub fn clear_codecs(self) -> Self
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());Sourcepub fn enable_opus(self, enabled: bool, use_red: bool) -> Self
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.
Sourcepub fn set_red_distances(self, distances: &[u32]) -> Self
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.
Sourcepub fn enable_pcmu(self, enabled: bool, use_red: bool) -> Self
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
Sourcepub fn enable_pcma(self, enabled: bool, use_red: bool) -> Self
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
Sourcepub fn enable_g722(self, enabled: bool, use_red: bool) -> Self
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.
Sourcepub fn enable_comfort_noise(self, enabled: bool) -> Self
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.
Sourcepub fn enable_amr_wb(self, enabled: bool) -> Self
pub fn enable_amr_wb(self, enabled: bool) -> Self
Enable AMR-WB audio codec.
Disabled by default.
Sourcepub fn enable_vp8(self, enabled: bool) -> Self
pub fn enable_vp8(self, enabled: bool) -> Self
Enable VP8 video codec.
Enabled by default.
Sourcepub fn enable_h264(self, enabled: bool) -> Self
pub fn enable_h264(self, enabled: bool) -> Self
Enable H264 video codec.
Enabled by default.
Sourcepub fn enable_h265(self, enabled: bool) -> Self
pub fn enable_h265(self, enabled: bool) -> Self
Enable H265 video codec.
Enabled by default.
Sourcepub fn enable_h266(self, enabled: bool) -> Self
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.
Sourcepub fn enable_vp9(self, enabled: bool) -> Self
pub fn enable_vp9(self, enabled: bool) -> Self
Enable VP9 video codec.
Enabled by default.
Sourcepub fn enable_av1(self, enabled: bool) -> Self
pub fn enable_av1(self, enabled: bool) -> Self
Enable AV1 video codec.
Enabled by default.
Sourcepub fn extension_map(&mut self) -> &mut ExtensionMap
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));Sourcepub fn set_extension_map(self, exts: ExtensionMap) -> Self
pub fn set_extension_map(self, exts: ExtensionMap) -> Self
Set the extension map replacing the existing.
Sourcepub fn clear_extension_map(self) -> Self
pub fn clear_extension_map(self) -> Self
Clear out the standard extension mappings.
Sourcepub fn set_extension(self, id: u8, ext: Extension) -> Self
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).
Sourcepub fn set_stats_interval(self, interval: Option<Duration>) -> Self
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
Sourcepub fn stats_interval(&self) -> Option<Duration>
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);Sourcepub fn set_rtcp_report_interval_audio(self, interval: Duration) -> Self
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.
Sourcepub fn rtcp_report_interval_audio(&self) -> Duration
pub fn rtcp_report_interval_audio(&self) -> Duration
Returns the interval between RTCP sender/receiver reports for audio streams.
Sourcepub fn set_rtcp_report_interval_video(self, interval: Duration) -> Self
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.
Sourcepub fn rtcp_report_interval_video(&self) -> Duration
pub fn rtcp_report_interval_video(&self) -> Duration
Returns the interval between RTCP sender/receiver reports for video streams.
Sourcepub fn enable_bwe(self, initial_estimate: Option<Bitrate>) -> Self
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.
Sourcepub fn bwe_initial_bitrate(&self) -> Option<Bitrate>
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);Sourcepub fn set_reordering_size_audio(self, size: usize) -> Self
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.
Sourcepub fn reordering_size_audio(&self) -> usize
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.
Sourcepub fn set_reordering_timeout_audio(self, timeout: Option<Duration>) -> Self
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.
Sourcepub fn reordering_timeout_audio(&self) -> Option<Duration>
pub fn reordering_timeout_audio(&self) -> Option<Duration>
Returns the configured audio reordering timeout.
Sourcepub fn set_reordering_size_video(self, size: usize) -> Self
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.
Sourcepub fn reordering_size_video(&self) -> usize
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.
Sourcepub fn set_pause_threshold(self, threshold: Duration) -> Self
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.
Sourcepub fn pause_threshold(&self) -> Duration
pub fn pause_threshold(&self) -> Duration
Returns the incoming stream pause threshold.
Sourcepub fn set_send_buffer_audio(self, size: usize) -> Self
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.
Sourcepub fn send_buffer_audio(&self) -> usize
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);Sourcepub fn set_send_buffer_video(self, size: usize) -> Self
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.
Sourcepub fn send_buffer_video(&self) -> usize
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);Sourcepub fn set_sctp_max_buffered_amount(self, bytes: usize) -> Self
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.
Sourcepub fn sctp_max_buffered_amount(&self) -> usize
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);Sourcepub fn set_sctp_max_message_size(self, bytes: u32) -> Self
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.
Sourcepub fn sctp_max_message_size(&self) -> u32
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);Sourcepub fn set_rtp_mode(self, enabled: bool) -> Self
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.
Sourcepub fn rtp_mode(&self) -> bool
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);Sourcepub fn enable_raw_packets(self, enabled: bool) -> Self
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.
Sourcepub fn set_snap_enabled(self, enabled: bool) -> Self
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).
Default: false
Sourcepub fn set_dtls_version(self, version: DtlsVersion) -> Self
pub fn set_dtls_version(self, version: DtlsVersion) -> Self
Set which DTLS version to use.
Defaults to DtlsVersion::Dtls12.
Sourcepub fn dtls_version(&self) -> DtlsVersion
pub fn dtls_version(&self) -> DtlsVersion
Get the configured DTLS version.
Sourcepub fn set_mtu(self, range: RangeInclusive<usize>) -> Self
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.
Sourcepub fn mtu_warn(&self) -> usize
pub fn mtu_warn(&self) -> usize
Get the configured warn threshold above which outgoing packets trigger a warning trace.
Sourcepub fn set_vp9_packetizer_mode(self, mode: Vp9PacketizerMode) -> Self
pub fn set_vp9_packetizer_mode(self, mode: Vp9PacketizerMode) -> Self
Set the VP9 packetizer mode.
VP9 supports two RTP payload descriptor formats:
Vp9PacketizerMode::NonFlexible(default) — 5-6 byte header with layer indices and scalability structure. Compatible with all major browsers including Safari.Vp9PacketizerMode::Flexible— minimal 3-byte header. Simpler but may cause issues with Safari which drops inter-frames.
Sourcepub fn vp9_packetizer_mode(&self) -> Vp9PacketizerMode
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);