Struct RtpReader

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

Wrapper around a byte-slice of RTP data, providing accessor methods for the RTP header fields.

Implementations§

Source§

impl<'a> RtpReader<'a>

Source

pub const MIN_HEADER_LEN: usize = 12usize

An RTP packet header is no fewer than 12 bytes long

Source

pub fn new(b: &'a [u8]) -> Result<RtpReader<'_>, RtpReaderError>

Tries to construct a new RtpHeader instance, or an RtpReaderError if the RTP data is malformed.

In particular, if there is too little data in the given buffer, such that some later attempt to access an RTP header field would need to access bytes that are not available, then this method will fail up front, rather than allowing attempts to access any header field to fail later on.

Source

pub fn version(&self) -> u8

Version field value (currently only version 2 is supported, so other values will not be seen from this release of rtp-rs.

Source

pub fn padding(&self) -> Option<u8>

Returns the size of the padding at the end of this packet, or None if the padding flag is not set in the packet header

Source

pub fn csrc_count(&self) -> u8

A count of the number of CSRC fields present in the RTP headers - may be 0.

See csrc().

Source

pub fn mark(&self) -> bool

A ‘marker’, which may have some definition in the specific RTP profile in use

Source

pub fn payload_type(&self) -> u8

Indicates the type of content carried in this RTP packet.

A few types-values are defined in the standard, but in many applications of RTP the value of this field needs to be agreed between sender and receiver by some mechanism outside of RTP itself.

Source

pub fn sequence_number(&self) -> Seq

The sequence number of this particular packet.

Sequence numbers are 16 bits, and will wrap back to 0 after reaching the maximum 16-bit value of 65535.

Receivers can identify packet losses or reordering by inspecting the value of this field across a sequence of received packets. The Seq wrapper type helps calling code reason about sequence number problems in the face of any wraparound that might have legitimately happened.

Source

pub fn timestamp(&self) -> u32

The timestamp of this packet, given in a timebase that relates to the particular payload_type in use.

It is perfectly possible for successive packets in a sequence to have the same value, or to have values that differ by arbitrarily large amounts.

Timestamps are 32 bits, and will wrap back to 0 after reaching the maximum 32 bit value of 4294967295.

Source

pub fn ssrc(&self) -> u32

The synchronisation source for this packet. Many applications of RTP do not use this field.

Source

pub fn csrc(&self) -> impl Iterator<Item = u32> + '_

A potentially empty list of contributing sources for this packet. Many applications of RTP do not use this field.

Source

pub fn payload_offset(&self) -> usize

Returns the offset of the payload for the packet

Source

pub fn payload(&self) -> &'a [u8]

Returns the payload data of this RTP packet, excluding the packet’s headers and any optional trailing padding.

Source

pub fn extension(&self) -> Option<(u16, &'a [u8])>

Returns details of the optional RTP header extension field. If there is an extension, the first component of the resulting tuple is the extension id, and the second is a byte-slice for the extension data value, to be interpreted by the application.

Source

pub fn create_builder(&self) -> RtpPacketBuilder<'a>

Create a RtpPacketBuilder from this packet. Note that padding from the original packet will not be used by default, and must be defined on the resulting RtpPacketBuilder if required.

The padding is not copied from the original since, while we do know how many padding bytes were present, we don’t know if the intent was to round to 2 bytes, 4 bytes, etc. Blindly copying the padding could result in an incorrect result if the payload is subsequently changed for one with a different length.

If you know your output packets don’t need padding, there is nothing more to do, since that is the default for the resulting RtpPacketBulder.

If you know you output packets need padding to 4 bytes, then you must explicitly specify this using builder.padded(Pad::round_to(4)) even if the source packet was already padded to a 4 byte boundary.

Trait Implementations§

Source§

impl<'a> Debug for RtpReader<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RtpReader<'a>

§

impl<'a> RefUnwindSafe for RtpReader<'a>

§

impl<'a> Send for RtpReader<'a>

§

impl<'a> Sync for RtpReader<'a>

§

impl<'a> Unpin for RtpReader<'a>

§

impl<'a> UnwindSafe for RtpReader<'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, 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, 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.