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_packet_with_redundant(
&mut self,
payload_type: u8,
timestamp: u32,
payload: Bytes,
redundant: Bytes,
) -> Result<RedPacket>
pub fn encode_packet_with_redundant( &mut self, payload_type: u8, timestamp: u32, payload: Bytes, redundant: Bytes, ) -> Result<RedPacket>
As encode_packet, but the later packets carry redundant as
this primary’s redundant copy instead of the primary itself: another encoding of the
same audio, at the primary’s payload type and timestamp, at a lower bitrate (RFC 2198
section 3: “It is expected that the redundant encoding shall use significantly less
bandwidth that the primary encoding”; RFC 8854 section 4.1: “redundant encoding with
reduced-bitrate Opus encodings”). A redundant larger than the primary is not kept
(RFC 2198 section 3: it “MUST NOT be higher bandwidth than the primary”): the primary
is, as encode_packet keeps it.
§Errors
As encode_packet.
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.
Sourcepub fn encode_rtp_with_redundant(
&mut self,
red_payload_type: u8,
primary: &Packet,
redundant: Bytes,
) -> Result<Packet>
pub fn encode_rtp_with_redundant( &mut self, red_payload_type: u8, primary: &Packet, redundant: Bytes, ) -> Result<Packet>
As encode_rtp, the later packets carrying redundant as this
primary’s copy (encode_packet_with_redundant).
§Errors
As encode_rtp.