Skip to main content

Crate rtci_rtp

Crate rtci_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.
  • packetizer — Packetizer, 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), with the payload formats an application drives itself: telephone-event (RFC 4733), comfort noise (RFC 3389) and RED (RFC 2198).
  • sequence — Sequencer, 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.
  • header::validity and sequence::SourceSequence — the validity checks of RFC 3550 Appendix A.1.
  • clock_rate — the rules for a stream that changes clock rate (RFC 7160).

§Example

use bytes::Bytes;
use rtci_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 rtci crate re-exports it as rtci::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§

clock_rate
Several clock rates in one RTP session (RFC 7160): the SSRC, timestamp and jitter rules.
codec
Per-codec payloaders and depacketizers (VP8, VP9, AV1, H.264, H.265, Opus, G.711), and telephone-event, comfort noise and RED.
extension
The typed RTP header extensions (RFC 8285).
header
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.