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§
source§impl<'a> Writer<'a>
impl<'a> Writer<'a>
sourcepub fn rid(self, rid: Rid) -> Self
pub fn rid(self, rid: Rid) -> Self
Add on an Rtp Stream Id. This is typically used to separate simulcast layers.
sourcepub fn audio_level(self, audio_level: i8, voice_activity: bool) -> Self
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.
sourcepub fn video_orientation(self, o: VideoOrientation) -> Self
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.
sourcepub fn write(
self,
wallclock: Instant,
rtp_time: MediaTime,
data: &[u8]
) -> Result<usize, RtcError>
pub fn write(
self,
wallclock: Instant,
rtp_time: MediaTime,
data: &[u8]
) -> Result<usize, RtcError>
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()
.