Skip to main content

Crate rtc_rtp

Crate rtc_rtp 

Source
Expand description

RTP packets, header extensions and packetization.

The Real-time Transport Protocol (RFC 3550) wire format, plus the pieces WebRTC needs around it: one-byte and two-byte header extensions (RFC 8285) and per-codec packetizers that turn encoded frames into RTP payloads.

§Structure

  • Packet / Header — the packet and its header: unmarshal one off the wire, marshal one back, get and set header extensions by id.
  • packetizerPacketizer, which fragments a frame into MTU-sized payloads, and the per-codec Payloader implementations in codec (VP8, VP9, H.264, H.265, AV1, Opus, G.711).
  • sequenceSequencer, for sequence numbers that start at a random offset as the RFC requires.
  • extension — the typed header extensions: audio level (RFC 6464), video orientation, transport-wide CC, and the SDES stream ids used for simulcast.

§Example

use bytes::Bytes;
use rtc_rtp::Packet;
use shared::marshal::{Marshal, Unmarshal};

// A minimal RTP packet: version 2, payload type 96, one byte of payload.
let raw = Bytes::from_static(&[
    0x80, 0x60, 0x00, 0x01, // V=2, PT=96, seq=1
    0x00, 0x00, 0x00, 0x20, // timestamp
    0xDE, 0xAD, 0xBE, 0xEF, // ssrc
    0xAA, // payload
]);

let mut buf = raw.clone();
let packet = Packet::unmarshal(&mut buf)?;
assert_eq!(packet.header.payload_type, 96);
assert_eq!(packet.header.sequence_number, 1);
assert_eq!(packet.header.ssrc, 0xDEAD_BEEF);

// Re-encoding reproduces the original bytes.
assert_eq!(packet.marshal()?, raw);

Most applications do not depend on this crate directly — the rtc crate re-exports it as rtc::rtp, and an application usually meets these types when reading or writing media on a track.

Re-exports§

pub use header::Header;
pub use packet::Packet;

Modules§

codec
Per-codec payloaders and depacketizers (VP8, VP9, AV1, H.264, H.265, Opus, G.711).
extension
The typed RTP header extensions (RFC 8285).
header
The RTP header, its extensions, and the bit masks that encode it. The RTP header and its extensions.
packet
A whole RTP packet: header plus payload.
packetizer
Turning encoded frames into RTP packets, and back again.
sequence
Sequence-number generation, starting from a random offset as the RFC requires.