pub struct RtpWrite { /* private fields */ }Expand description
RTP packet data to enqueue on a direct RTP send stream.
The payload is the RTP payload only, without the RTP header.
Optional RTP fields default to the common unmarked non-nackable packet with no header extension values, no CSRC entries and no VP8 rewrite.
Implementations§
Source§impl RtpWrite
impl RtpWrite
Sourcepub fn new(
pt: Pt,
seq_no: SeqNo,
time: u32,
wallclock: Instant,
payload: impl Into<Arc<[u8]>>,
) -> Self
pub fn new( pt: Pt, seq_no: SeqNo, time: u32, wallclock: Instant, payload: impl Into<Arc<[u8]>>, ) -> Self
Create a direct RTP write command.
The payload argument is expected to be only the RTP payload, not the
RTP packet header.
ptPayload type. Declared in theMediathis encoded stream belongs to.seq_noExtended sequence number to use for this packet. Only the low 16 bits are carried in the RTP header. The upper bits (seq_no.roc()) supply the SRTP rollover counter (ROC) used for the per-packet IV and authentication. See below for initializing a stream with a nonzero ROC.timeTime in whatever the clock rate is for the media in question (normally 90_000 for video and 48_000 for audio).wallclockReal world time that corresponds to the media time in the RTP packet. For an SFU, this can be hard to know because 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. For better synchronization the SFU probably needs to weigh in clock drifts and data provided via the statistics, receiver reports etc.payloadRTP packet payload, without header.
Optional fields default to an unmarked packet with no header extension
values, no CSRC entries, no VP8 patch and no NACK support.
RtpWrite::marker for video frame boundaries,
RtpWrite::ext_vals for RTP header extension values,
RtpWrite::nackable for packets that may answer incoming NACKs,
RtpWrite::csrc for contributing source identifiers,
RtpWrite::vp8_patch to apply a prevalidated VP8 payload descriptor patch during RTP serialization.
§Initializing the rollover counter
The ROC is not carried in the RTP header or transmitted by str0m in the SRTP packet. A fresh receiver starts at ROC 0. To start a stream with a higher ROC, the application must communicate that ROC and the stream’s SSRC to the receiver out of band, for example through its signaling channel, and initialize the receiver before sending media. Otherwise, sender and receiver use different packet indices and SRTP authentication fails. See RFC 3711 section 3.3.1.
On the sender, the extended sequence number determines the ROC:
let seq_no: SeqNo = 100_000.into();
assert_eq!(seq_no.roc(), 1);
assert_eq!(seq_no.as_u16(), 34_464);
// First communicate (stream.ssrc(), seq_no.roc()) out of band and
// arrange for the receiver to initialize its ROC as shown below.
stream.write_rtp(RtpWrite::new(pt, seq_no, 0, wallclock, payload));On a str0m receiver, use StreamRx::reset_roc
with the signaled ROC before handling the first SRTP packet. This example
assumes the media identified by mid has already been declared:
// `ssrc` and `signaled_roc` come from the application's signaling channel.
let mut direct = rtc.direct_api();
let stream = direct.expect_stream_rx(ssrc, None, mid, None);
stream.reset_roc(signaled_roc); // 1 for the sender example above.Continue supplying extended sequence numbers on the sender across
rollovers; the receiver tracks subsequent rollovers automatically.
Without out-of-band ROC initialization, start the outgoing stream with
seq_no < 65_536. In particular, forwarding a long-running source’s
extended sequence numbers to a new receiver requires either signaling
its initial ROC or rebasing the outgoing sequence numbers for that receiver.
Sourcepub fn ext_vals(self, ext_vals: ExtensionValues) -> Self
pub fn ext_vals(self, ext_vals: ExtensionValues) -> Self
Set RTP header extension values.
Sourcepub fn nackable(self, nackable: bool) -> Self
pub fn nackable(self, nackable: bool) -> Self
Set whether this RTP packet should respond to incoming NACKs.
Sourcepub fn vp8_patch(self, patch: Vp8Patch) -> Self
pub fn vp8_patch(self, patch: Vp8Patch) -> Self
Apply a prevalidated VP8 payload descriptor patch during RTP serialization.
Build the patch with Vp8Descriptor::patch
when the caller already parsed the VP8 payload descriptor before
constructing this write command.