rtp-packet 0.3.0

RTP fixed header + CSRC list + generic header extension (RFC 3550 §5.1/§5.3.1) — spec-complete parse/serialize, no_std.
Documentation

rtp-packet

Crates.io docs.rs

RFC 3550 §5.1 RTP fixed header + CSRC list + §5.3.1 generic header extension — spec-complete parse/serialize, no_std.

rtp-packet is a shared low-level wire crate (in the same spirit as mpeg-ts/mpeg-pes/mpeg-ps): a single, spec-complete implementation of the RTP fixed header meant to be consumed by every higher-level crate that speaks RTP (transmux's RTP spoke today; the upcoming SMPTE ST 2110-40 ANC-over-RTP work next), instead of each crate re-implementing its own header codec.

  • [RtpPacket] — version (validated == 2 on parse, always written 2 on serialize), padding (the trailing pad-count octet correctly stripped/re-appended), the CSRC identifier list (0–15 entries, CC always derived from the list length), marker, payload type, sequence number, timestamp, SSRC, an optional [HeaderExtension], and the payload.
  • [HeaderExtension] — the §5.3.1 generic header extension: a 16-bit profile-specific identifier + opaque profile-specific data (the length field, in 32-bit words, is always derived from the data length).

See docs/rtp-header.md for the curated RFC 3550 §5.1/§5.3.1 transcription this crate implements field-for-field.

The optional rfc8285 feature adds rfc8285::parse_extensions, decoding RFC 8285's one-byte/two-byte multiplexed extension elements out of a HeaderExtension's opaque data (the profile-specific interpretation RFC 3550 itself leaves to the profile). See docs/rfc8285_header_ext.md for the curated transcription.

#![no_std] + alloc; depends only on broadcast-common.

Quick start

use broadcast_common::{Parse, Serialize};
use rtp_packet::RtpPacket;

let pkt = RtpPacket {
    marker: true,
    payload_type: 96,
    sequence_number: 1,
    timestamp: 3600,
    ssrc: 0x1234_5678,
    csrc: vec![],
    extension: None,
    padding: None,
    payload: &[0xDE, 0xAD, 0xBE, 0xEF],
};
let mut bytes = vec![0u8; pkt.serialized_len()];
pkt.serialize_into(&mut bytes).unwrap();
assert_eq!(RtpPacket::parse(&bytes).unwrap(), pkt);

Examples

cargo run -p rtp-packet --example build_packet
cargo run -p rtp-packet --example parse_packet
cargo run -p rtp-packet --example rfc8285_extensions --features rfc8285

Features

Feature Default Description
std yes Link the standard library. Without it the crate is #![no_std] + alloc.
serde no serde::Serialize derives on public types.
rfc8285 no RFC 8285 one-byte/two-byte multiplexed header-extension element decoding (rfc8285 module).

Minimum Supported Rust Version

1.86

License

MIT OR Apache-2.0