DirectApi

Struct DirectApi 

Source
pub struct DirectApi<'a> { /* private fields */ }
Expand description

Direct change strategy.

Makes immediate changes to the Rtc session without any SDP OFFER/ANSWER. This is an alternative to Rtc::sdp_api() for use cases when you don’t want to use SDP (or when you want to write RTP directly).

To use the Direct API together with a browser client, you would need to make the equivalent changes on the browser side by manually generating the correct SDP OFFER/ANSWER to make the RTCPeerConnection match str0m’s state.

To change str0m’s state through the Direct API followed by the SDP API produce an SDP OFFER is not a supported use case. Either pick SDP API and let str0m handle the OFFER/ANSWER or use Direct API and deal with SDP manually. Not both.

This is a low level API.

str0m normally guarantees that user input cannot cause panics. However as an exception, the Direct API does allow the user to configure the session in a way that is internally inconsistent. Such situations can result in panics.

Implementations§

Source§

impl<'a> DirectApi<'a>

Source

pub fn new(rtc: &'a mut Rtc) -> Self

Creates a new instance of the DirectApi struct with the specified Rtc instance.

The DirectApi struct provides a high-level API for interacting with a WebRTC peer connection, and the Rtc instance provides low-level access to the underlying WebRTC functionality.

Source

pub fn set_ice_controlling(&mut self, controlling: bool)

Sets the ICE controlling flag for this peer connection.

If controlling is true, this peer connection is set as the ICE controlling agent, meaning it will take the initiative to send connectivity checks and control the pace of connectivity checks sent between two peers during the ICE session.

If controlling is false, this peer connection is set as the ICE controlled agent, meaning it will respond to connectivity checks sent by the controlling agent.

Source

pub fn local_ice_credentials(&self) -> IceCreds

Returns a reference to the local ICE credentials used by this peer connection.

The ICE credentials consist of the username and password used by the ICE agent during the ICE session to authenticate and exchange connectivity checks with the remote peer.

Source

pub fn set_local_ice_credentials(&mut self, local_ice_credentials: IceCreds)

Sets the local ICE credentials.

Source

pub fn set_remote_ice_credentials(&mut self, remote_ice_credentials: IceCreds)

Sets the remote ICE credentials.

Source

pub fn local_dtls_fingerprint(&self) -> &Fingerprint

Returns a reference to the local DTLS fingerprint used by this peer connection.

The DTLS fingerprint is a hash of the local SSL/TLS certificate used to authenticate the peer connection and establish a secure communication channel between the peers.

Source

pub fn remote_dtls_fingerprint(&self) -> Option<&Fingerprint>

Returns a reference to the remote DTLS fingerprint used by this peer connection.

Source

pub fn set_remote_fingerprint(&mut self, dtls_fingerprint: Fingerprint)

Sets the remote DTLS fingerprint.

Source

pub fn start_dtls(&mut self, active: bool) -> Result<(), RtcError>

Start the DTLS subsystem.

Source

pub fn start_sctp(&mut self, client: bool)

Start the SCTP over DTLS.

Source

pub fn create_data_channel(&mut self, config: ChannelConfig) -> ChannelId

Create a new data channel.

Source

pub fn close_data_channel(&mut self, channel_id: ChannelId)

Close a data channel.

Source

pub fn set_ice_lite(&mut self, ice_lite: bool)

Set whether to enable ice-lite.

Source

pub fn enable_twcc_feedback(&mut self)

Enable twcc feedback.

Source

pub fn new_ssrc(&self) -> Ssrc

Generate a ssrc that is not already used in session

Source

pub fn channel_id_by_sctp_stream_id(&self, id: u16) -> Option<ChannelId>

Get the str0m ChannelId by an sctp_stream_id.

This is useful when using out of band negotiated sctp stream id in Self::create_data_channel()

Source

pub fn sctp_stream_id_by_channel_id(&self, id: ChannelId) -> Option<u16>

Get the sctp_stream_id from a str0m ChannelId.

This is useful when using out of band negotiated sctp stream id in Self::create_data_channel()

Source

pub fn declare_media(&mut self, mid: Mid, kind: MediaKind) -> &mut Media

Create a new Media.

All streams belong to a media identified by a mid. This creates the media without doing any SDP dance.

Source

pub fn remove_media(&mut self, mid: Mid)

Remove Media.

Removes media and all streams belong to a media identified by a mid.

Source

pub fn expect_stream_rx( &mut self, ssrc: Ssrc, rtx: Option<Ssrc>, mid: Mid, rid: Option<Rid>, ) -> &mut StreamRx

Allow incoming traffic from remote peer for the given SSRC.

Can be called multiple times if the rtx is discovered later via RTP header extensions.

Source

pub fn remove_stream_rx(&mut self, ssrc: Ssrc) -> bool

Remove the receive stream for the given SSRC.

Returns true if stream existed and was removed.

Source

pub fn stream_rx(&mut self, ssrc: &Ssrc) -> Option<&mut StreamRx>

Obtain a receive stream.

In RTP mode, the receive stream is used to signal keyframe requests.

The stream must first be declared using DirectApi::expect_stream_rx.

Source

pub fn stream_rx_by_mid( &mut self, mid: Mid, rid: Option<Rid>, ) -> Option<&mut StreamRx>

Obtain a recv stream by looking it up via mid/rid.

Source

pub fn declare_stream_tx( &mut self, ssrc: Ssrc, rtx: Option<Ssrc>, mid: Mid, rid: Option<Rid>, ) -> &mut StreamTx

Declare the intention to send data using the given SSRC.

  • The resend RTX is optional but necessary to do resends. str0m does not do resends without RTX.

Can be called multiple times without changing any internal state. However the RTX value is only picked up the first ever time we see a new SSRC.

Source

pub fn remove_stream_tx(&mut self, ssrc: Ssrc) -> bool

Remove the transmit stream for the given SSRC.

Returns true if stream existed and was removed.

Source

pub fn stream_tx(&mut self, ssrc: &Ssrc) -> Option<&mut StreamTx>

Obtain a send stream to write RTP data directly.

The stream must first be declared using DirectApi::declare_stream_tx.

Source

pub fn stream_tx_by_mid( &mut self, mid: Mid, rid: Option<Rid>, ) -> Option<&mut StreamTx>

Obtain a send stream by looking it up via mid/rid.

Source

pub fn reset_stream_tx( &mut self, mid: Mid, rid: Option<Rid>, new_ssrc: Ssrc, new_rtx: Option<Ssrc>, ) -> Option<&mut StreamTx>

Reset a transmit stream to use a new SSRC and optionally a new RTX SSRC.

This changes the SSRC of an existing stream and resets all relevant state. Use this when you need to change the SSRC of an existing stream without creating a new one.

If the stream has an RTX SSRC, new_rtx must be provided. If the stream doesn’t have an RTX SSRC, new_rtx is ignored.

Returns a reference to the updated stream or None if:

  • No stream was found for the given mid/rid
  • The new SSRC is the same as the current one (no change needed)
  • The new RTX SSRC is the same as the current one (no change needed)

Auto Trait Implementations§

§

impl<'a> Freeze for DirectApi<'a>

§

impl<'a> !RefUnwindSafe for DirectApi<'a>

§

impl<'a> Send for DirectApi<'a>

§

impl<'a> Sync for DirectApi<'a>

§

impl<'a> Unpin for DirectApi<'a>

§

impl<'a> !UnwindSafe for DirectApi<'a>

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<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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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