Skip to main content

RedEncoder

Struct RedEncoder 

Source
pub struct RedEncoder { /* private fields */ }
Expand description

Builds RED payloads whose redundancy is copies of the previous primaries (RFC 2198 section 3), the way Chrome sends Opus RED.

It keeps the last redundancy primaries with their timestamps. Each encode puts the still-usable ones before the new primary, oldest first, dropping (oldest first) those whose offset would be 0 or exceed 0x3FFF, whose length exceeds 0x3FF, or that do not fit max_payload_size. Deterministic and bounded.

Implementations§

Source§

impl RedEncoder

Source

pub fn new(redundancy: usize, max_payload_size: usize) -> Self

An encoder carrying up to redundancy earlier primaries (capped at RED_MAX_BLOCKS - 1) in payloads of at most max_payload_size bytes.

Source

pub fn redundancy(&self) -> usize

The configured redundancy level.

Source

pub fn reset(&mut self)

Forgets the earlier primaries (for a stream restart or timestamp jump).

Source

pub fn encode_packet( &mut self, payload_type: u8, timestamp: u32, payload: Bytes, ) -> Result<RedPacket>

The RED packet for a new primary at RTP timestamp. The caller sends it with the RED payload type, this timestamp and the primary’s marker bit.

§Errors

Fails on a payload type above 127, or a primary that alone does not fit max_payload_size (nothing is remembered then).

Source

pub fn encode_rtp( &mut self, red_payload_type: u8, primary: &Packet, ) -> Result<Packet>

The RED RTP packet for the media packet primary (RFC 2198 section 3): “a standard RTP header … where the payload type field indicates the redundant encoding” and the other fields (sequence number, timestamp, marker, SSRC, CSRCs, extensions) are those of the primary. Its payload is encode_packet of the primary’s.

§Errors

As encode_packet, and for a RED payload type above 127.

Source

pub fn encode( &mut self, payload_type: u8, timestamp: u32, payload: Bytes, ) -> Result<Bytes>

As encode_packet, marshalled.

§Errors

As encode_packet.

Trait Implementations§

Source§

impl Clone for RedEncoder

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 RedEncoder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for RedEncoder

§

impl Freeze for RedEncoder
where *const u8 is !null: Freeze, PhantomData<(u32, u8, Bytes)>: Freeze,

§

impl Move for RedEncoder

§

impl RefUnwindSafe for RedEncoder

§

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

§

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

§

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

§

impl UnsafeUnpin for RedEncoder

§

impl UnwindSafe for RedEncoder
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.