Skip to main content

Module red

Module red 

Source
Expand description

Redundant audio data, RED (RFC 2198). Redundant audio data, RED (RFC 2198).

A RED payload is a list of block headers followed by the data blocks in the same order, with no padding between them (section 3):

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1|   block PT  |  timestamp offset         |   block length    |   redundant block header
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0|   block PT  |                                                   primary block header
+-+-+-+-+-+-+-+-+

The RTP header of a RED packet (sequence number, timestamp, marker, CSRCs) belongs to the primary block; a redundant block’s timestamp is the RTP timestamp minus its offset, and it must use the same clock rate as the primary. Two things are not carried for redundant data (section 4): the marker bit of a lost primary is lost with it, and the CSRC list of the RED packet that carried a recovered block is the one to apply to it. RedDecoder exposes neither; the caller takes the CSRCs from the RED packet it fed in.

  • RedPacket reads and writes one payload, strictly bounds-checked.
  • RedEncoder builds each payload from a new primary plus copies of the previous ones (section 3: “a copy of the primary MAY be used as the redundancy”, the mode Chrome uses for Opus).
  • RedDecoder returns each packet’s primary and recovers lost earlier primaries from later packets’ redundant blocks.
  • parse_red_fmtp / format_red_fmtp handle the a=fmtp:<pt> 111/111 list (section 5).

An empty primary block is accepted and produced: nothing in RFC 2198 forbids a zero-length block, and RFC 4103 (T.140 text over RED) sends empty primaries while idle.

Structs§

RecoveredBlock
A payload a RedDecoder delivers.
RecoveredMedia
A block RedDecoder::decode_rtp delivers, with what of the RED packet’s header applies to it (RFC 2198 section 4).
RedBlock
One block of a RED payload.
RedDecoder
Unpacks RED packets and recovers lost primaries from later packets’ redundant blocks (RFC 2198 section 3), without delivering anything twice.
RedDepacketizer
Returns a RED payload’s primary data, for audio streams whose RED payload type is depacketized like a codec. Redundant blocks are dropped; use RedDecoder to recover from them.
RedEncoder
Builds RED payloads whose redundancy is copies of the previous primaries (RFC 2198 section 3), the way Chrome sends Opus RED.
RedPacket
One RED payload: redundant blocks in header order, then the primary.

Constants§

RED_DEFAULT_DUPLICATE_WINDOW
The default number of recent deliveries a RedDecoder remembers.
RED_MAX_BLOCKS
The most blocks (redundant ones plus the primary) a RedPacket may have. RFC 2198 sets no limit; one or two levels of redundancy are usual, and 32 bounds the parser’s work.
RED_MAX_BLOCK_LENGTH
The largest redundant block length (10 bits).
RED_MAX_DUPLICATE_WINDOW
The largest duplicate window a RedDecoder accepts.
RED_MAX_PAYLOAD_TYPE
The largest RTP payload type (7 bits).
RED_MAX_TIMESTAMP_OFFSET
The largest timestamp offset (14 bits).
RED_PRIMARY_HEADER_SIZE
Size of the primary block header.
RED_REDUNDANT_HEADER_SIZE
Size of a redundant block header.

Functions§

format_red_fmtp
Formats a RED fmtp list: payload types joined by /.
parse_red_fmtp
Parses the RED fmtp list, a=fmtp:<pt> 111/111 (section 5): the payload types of the primary and then the redundant encodings, slash-separated.