Struct str0m::media::Writer

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

Helper obtained by Media::writer() to send media.

This type follows a builder pattern to allow for additional data to be sent as RTP extension headers.

let mut rtc = Rtc::new();

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

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

// Get incoming media data from another peer
let data: MediaData = todo!();
let video_orientation = data.ext_vals.video_orientation.unwrap();

// Match incoming PT to an outgoing PT.
let pt = media.match_params(data.params).unwrap();

// Send data with video orientation added.
media.writer(pt, Instant::now())
    .video_orientation(video_orientation)
    .write(data.network_time, data.time, &data.data).unwrap();

Implementations§

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

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.

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.

Do the actual write of media. This consumed the builder.

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.

Notice that incorrect Pt values would surface as an error here, not when doing Media::writer().

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more