Skip to main content

RtpWrite

Struct RtpWrite 

Source
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

Source

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.

  • pt Payload type. Declared in the Media this encoded stream belongs to.
  • seq_no Extended 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.
  • time Time in whatever the clock rate is for the media in question (normally 90_000 for video and 48_000 for audio).
  • wallclock Real 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.
  • payload RTP 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.

Source

pub fn marker(self, marker: bool) -> Self

Set the RTP marker bit.

Source

pub fn ext_vals(self, ext_vals: ExtensionValues) -> Self

Set RTP header extension values.

Source

pub fn nackable(self, nackable: bool) -> Self

Set whether this RTP packet should respond to incoming NACKs.

Source

pub fn csrc(self, csrc: &[u32]) -> Self

Set contributing source identifiers.

§Panics

Panics if more than 15 entries are supplied.

Source

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.

Trait Implementations§

Source§

impl Debug for RtpWrite

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CryptoSafe for T
where T: Send + Sync + Debug,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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