pub struct WebRtcHandle { /* private fields */ }webrtc only.Expand description
Cheaply-cloneable handle for requesting new tracks, completing
renegotiation, and picking up newly-attached tracks — same spirit as
crate::elements::AppSourceHandle. Cloning shares one queue of
pending WebRtcHandle::next_track results, same as any other
multi-consumer channel — only one clone’s call actually receives a
given track, so in practice only one place in the app should be
draining it.
Implementations§
Source§impl WebRtcHandle
impl WebRtcHandle
Sourcepub fn add_track(
&self,
kind: MediaKind,
direction: Direction,
codec: Codec,
) -> Result<TrackId>
pub fn add_track( &self, kind: MediaKind, direction: Direction, codec: Codec, ) -> Result<TrackId>
Requests a new track of kind/direction. Blocks only while the
peer’s bounded command queue is full; once the command is accepted,
returns the locally assigned TrackId. This does not mean SDP
negotiation has completed — receive the attached track through
WebRtcHandle::next_track. Returns WebRtcError::Closed without
yielding a TrackId if the peer loop has already stopped.
codec is what WebRtcTrackSink::consume on the resulting track
will actually be fed (an encoder’s output, or a packet relayed
verbatim from another track) — used to pick the matching payload
type out of whatever this connection negotiates for the track,
instead of guessing. If this connection does not negotiate codec,
consuming a packet returns
WebRtcError::OutboundCodecNotNegotiated.
Declaring one codec and pushing another is not detected anywhere: str0m packetizes whatever bytes it is handed under the payload type chosen here, so the mismatch leaves as a well-formed stream that no receiver can decode. Audio is where this bites — WebRTC negotiates Opus, and there is no AAC payload type to fall back to.
Sourcepub fn next_track(&self) -> Result<AttachedTrack>
pub fn next_track(&self) -> Result<AttachedTrack>
Blocks until the next track attaches — either one requested via
WebRtcHandle::add_track (on either side) once its Mid exists,
or one the remote peer added on its own. Err once WebRtcPeer
(and its run) is gone and every already-attached track has been
drained.
Which track this is has to be established from
AttachedTrack::id: a remote peer adding a track of its own is
delivered through this same queue, so “the call right after my
add_track” is not a guarantee of anything. Match the id against
what add_track returned.
AttachedTrack::endpoints carries only what the track’s
negotiated direction actually permits. That direction is read once,
as the track attaches, and the endpoints are never re-issued — so a
remote peer that renegotiates a different direction afterwards
makes them wrong. That case is reported as
WebRtcError::DirectionChanged on the Bus rather than
silently tolerated; recovering from it means tearing the track down
and adding a new one.
Both endpoints expose their currently negotiated codec lists. A send
endpoint for a track this side requested already selects the codec
passed to WebRtcHandle::add_track. For a track the remote side
added, choose the application’s encoder output from
WebRtcTrackSink::negotiated_codecs and pass it to
WebRtcTrackSink::set_codec before pushing packets. The matching
source separately reports the codec actually received once RTP starts.
Sourcepub fn set_answer(&self, answer: SdpAnswer)
pub fn set_answer(&self, answer: SdpAnswer)
Feeds a remote answer back in, completing a renegotiation started by
WebRtcHandle::add_track. A no-op if WebRtcPeer (and its run)
is already gone.
Sourcepub fn accept_remote_offer(&self, offer: SdpOffer) -> Result<SdpAnswer>
pub fn accept_remote_offer(&self, offer: SdpOffer) -> Result<SdpAnswer>
Accepts a fresh offer from the remote peer (their own
renegotiation) and returns the resulting answer for the caller to
ship back over its own signaling transport. Blocks until
WebRtcPeer::run has actually applied it.
Trait Implementations§
Source§impl Clone for WebRtcHandle
impl Clone for WebRtcHandle
Source§fn clone(&self) -> WebRtcHandle
fn clone(&self) -> WebRtcHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more