Struct Writer

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

Writer of sample level data.

Obtained via Rtc::writer.

This is the Sample Level API. For RTP level see DirectApi::stream_tx.

Implementations§

Source§

impl<'a> Writer<'a>

Source

pub fn payload_params(&self) -> impl Iterator<Item = &PayloadParams>

Get the configured payload parameters for the mid this writer is for.

For the Writer::write() call, the pt must be set correctly.

Source

pub fn match_params(&self, params: PayloadParams) -> Option<Pt>

Match the given parameters to the configured parameters for this Media.

In a server scenario, a certain codec configuration might not have the same payload type (PT) for two different peers. We will have incoming data with one PT and need to match that against the PT of the outgoing Media.

This call performs matching and if a match is found, returns the local PT that can be used for sending media.

Source

pub fn rid(self, rid: Rid) -> Self

Add on an Rtp Stream Id. This is typically used to separate simulcast layers.

Source

pub fn audio_level(self, audio_level: i8, voice_activity: bool) -> Self

Add on audio level and voice activity. These values are communicated in the same RTP header extension, hence it makes sense setting both at the same time.

Audio level is measured in negative decibel. 0 is max and a “normal” value might be -30.

Source

pub fn video_orientation(self, o: VideoOrientation) -> Self

Add video orientation. This can be used by a player on the receiver end to decide whether the video requires to be rotated to show correctly.

Source

pub fn user_extension_value<T: Send + Sync + 'static>(self, val: T) -> Self

Set a user extension value.

Source

pub fn write( self, pt: Pt, wallclock: Instant, rtp_time: MediaTime, data: impl Into<Vec<u8>>, ) -> Result<(), RtcError>

Write media.

This operation fails if the PT doesn’t match a negotiated codec, or the RID (None or a value) does not match anything negotiated.

Regarding wallclock and rtp_time, the wallclock is the real world time that corresponds to the MediaTime. For an SFU, this can be hard to know, since RTP packets typically only contain the media time (RTP time). In the simplest SFU setup, the wallclock could simply be the arrival time of the incoming RTP data (see MediaData::network_time). For better synchronization the SFU probably needs to weigh in clock drifts and data provided via the statistics.

If you write media before IceConnectionState is Connected it will be dropped.

Panics if RtcConfig::set_rtp_mode() is true.

Source

pub fn is_request_keyframe_possible(&self, kind: KeyframeRequestKind) -> bool

Test if the kind of keyframe request is possible.

Sending a keyframe request requires the mechanic to be negotiated as a feedback mechanic in the SDP offer/answer dance first.

Specifically these SDP lines would enable FIR and PLI respectively (for payload type 96).

a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack pli
Source

pub fn request_keyframe( &mut self, rid: Option<Rid>, kind: KeyframeRequestKind, ) -> Result<(), RtcError>

Request a keyframe from a remote peer sending media data.

For SDP: This can fail if the kind of request (PLI or FIR), as specified by the KeyframeRequestKind, is not negotiated in the SDP answer/offer for this m-line.

To ensure the call will not fail, use Writer::is_request_keyframe_possible() to check whether the feedback mechanism is enabled.

§Example
let mut rtc = Rtc::new();

// add candidates, do SDP negotiation
let mid: Mid = todo!(); // obtain mid from Event::MediaAdded.

let writer = rtc.writer(mid).unwrap();

writer.request_keyframe(None, KeyframeRequestKind::Pli).unwrap();

Auto Trait Implementations§

§

impl<'a> Freeze for Writer<'a>

§

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

§

impl<'a> Send for Writer<'a>

§

impl<'a> Sync for Writer<'a>

§

impl<'a> Unpin for Writer<'a>

§

impl<'a> !UnwindSafe for Writer<'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