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
impl RedEncoder
Sourcepub fn new(redundancy: usize, max_payload_size: usize) -> Self
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.
Sourcepub fn redundancy(&self) -> usize
pub fn redundancy(&self) -> usize
The configured redundancy level.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Forgets the earlier primaries (for a stream restart or timestamp jump).
Sourcepub fn encode_packet(
&mut self,
payload_type: u8,
timestamp: u32,
payload: Bytes,
) -> Result<RedPacket>
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).
Sourcepub fn encode_rtp(
&mut self,
red_payload_type: u8,
primary: &Packet,
) -> Result<Packet>
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.