Skip to main content

Header

Struct Header 

Source
pub struct Header {
Show 13 fields pub version: u8, pub padding: bool, pub extension: bool, pub marker: bool, pub payload_type: u8, pub sequence_number: u16, pub timestamp: u32, pub ssrc: u32, pub csrc: Vec<u32>, pub extension_profile: u16, pub extensions: Vec<Extension>, pub extensions_padding: usize, pub padding_size: u8,
}
Expand description

Header represents an RTP packet header NOTE: PayloadOffset is populated by Marshal/Unmarshal and should not be modified

Fields§

§version: u8

The RTP version, always 2. Header::default sets it; marshal and unmarshal refuse any other value (RFC 3550 section 5.1).

§padding: bool

Whether the payload is followed by padding octets, the last giving the padding length.

§extension: bool

Whether a header-extension block follows the fixed header.

§marker: bool

The marker bit: the last packet of a video frame, or the start of a talk spurt for audio.

§payload_type: u8

The payload type, which identifies the codec as negotiated in SDP.

§sequence_number: u16

Increments by one per packet sent; used to detect loss and restore order.

§timestamp: u32

The sampling instant of the first octet, in the codec’s clock rate.

§ssrc: u32

The synchronization source — the identifier of the stream this packet belongs to.

§csrc: Vec<u32>

The contributing sources, listed when a mixer combined several streams.

§extension_profile: u16

Which header-extension form is in use: EXTENSION_PROFILE_ONE_BYTE or EXTENSION_PROFILE_TWO_BYTE.

§extensions: Vec<Extension>

The header extensions present on this packet.

§extensions_padding: usize

Padding bytes appended to the extension block so it ends on a 32-bit boundary.

§padding_size: u8

How many padding octets follow the payload when padding is set, the count octet included (RFC 3550 5.1). Filled in by Packet unmarshal so a packet re-marshals with the padding it arrived with; 0 lets marshal pad to the next 32-bit boundary, as it always did.

Implementations§

Source§

impl Header

Source

pub fn get_extension_payload_len(&self) -> usize

The total encoded length of the extension payloads, padding excluded.

Source

pub fn extension_form(&self) -> Option<ExtensionForm>

The form of this header’s extension block, or None when it has none.

Source

pub fn set_extension(&mut self, id: u8, payload: Bytes) -> Result<()>

Sets an RTP header extension, keeping the form the header already has.

A header that has no extension yet takes the one-byte form when the element fits it (id 1 to 14, 1 to 16 bytes) and the two-byte form otherwise (RFC 8285 section 4.2: an id above 14 is never sent in the one-byte form; section 4.1.2: the two-byte form is not used when everything fits the one-byte form).

A header that already has extensions keeps its form, because a stream carries one form only unless a=extmap-allow-mixed was negotiated (RFC 8285 sections 4.1.2 and 6). Use Header::set_extension_upgrading when mixing is allowed, or Header::upgrade_to_two_byte on every packet of a stream that is two-byte throughout.

§Errors

Fails when the id or the length does not fit the header’s form, or no RFC 8285 form at all (id 0 on a header without extensions, more than 255 bytes).

Source

pub fn set_extension_upgrading(&mut self, id: u8, payload: Bytes) -> Result<()>

Sets an RTP header extension, converting a one-byte header to the two-byte form when the element needs it (an id above 14, an empty element or one over 16 bytes).

The conversion changes the form of this packet only. RFC 8285 section 4.1.2 lets a stream mix the forms only when a=extmap-allow-mixed was negotiated (section 6), so call this when it was, or when the element is set on every packet of the stream (the stream is then two-byte throughout).

§Errors

Fails when the element fits neither form (id 0, more than 255 bytes), or the header carries an RFC 3550 extension that is not RFC 8285.

Source

pub fn upgrade_to_two_byte(&mut self) -> Result<()>

Converts a one-byte extension block to the two-byte form, with appbits 0. Every one-byte element is valid in the two-byte form (RFC 8285 section 4.3: one id space). A header without extensions, or already two-byte, is left as it is.

§Errors

Fails for a header whose extension is not RFC 8285.

Source

pub fn get_extension_ids(&self) -> Vec<u8> ⓘ

returns an extension id array

Source

pub fn get_extension(&self, id: u8) -> Option<Bytes>

returns an RTP header extension

Source

pub fn del_extension(&mut self, id: u8) -> Result<()>

Removes an RTP Header extension.

Removing the last element removes the extension block too: the X bit is cleared, since the block is present only when the packet carries at least one element (RFC 8285 section 4.1.1).

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Header

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Header

Source§

fn default() -> Self

A header of version 2 with every other field zero or empty.

Source§

impl Eq for Header

Source§

impl Marshal for Header

Source§

fn marshal_to(&self, buf: &mut [u8]) -> Result<usize>

Marshal serializes the header and writes to the buffer.

Source§

fn marshal(&self) -> Result<BytesMut, Error>

Encodes into a freshly allocated buffer sized by MarshalSize::marshal_size. Read more
Source§

impl MarshalSize for Header

Source§

fn marshal_size(&self) -> usize

MarshalSize returns the size of the packet once marshaled.

Source§

impl PartialEq for Header

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Header

Source§

impl Unmarshal for Header

Source§

fn unmarshal<B>(raw_packet: &mut B) -> Result<Self>
where Self: Sized, B: Buf,

Unmarshal parses the passed byte slice and stores the result in the Header this method is called upon

Auto Trait Implementations§

§

impl Forget for Header

§

impl Freeze for Header

§

impl Move for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header
where RawVecInner: Send, Bytes: Send,

§

impl Sync for Header
where RawVecInner: Sync, Bytes: Sync,

§

impl Unpin for Header
where *const u8 is !null: Unpin, *const u8: Unpin, Align8<*mut ()>: Unpin, &'static Vtable: Unpin,

§

impl UnsafeUnpin for Header

§

impl UnwindSafe for Header
where RawVecInner: UnwindSafe, *const u8: UnwindSafe, Align8<*mut ()>: UnwindSafe, &'static Vtable: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.