rtci-rtp 0.2.0

RTP packets, header extensions (RFC 3550, RFC 8285) and codec payload formats for WebRTC
Documentation
#![warn(rust_2018_idioms)]
#![warn(missing_docs)]
#![allow(dead_code)]

//! 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`](packetizer::Packetizer), which fragments a frame into
//!   MTU-sized payloads, and the per-codec [`Payloader`](packetizer::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`](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};
//!
//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // 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);
//! # Ok(())
//! # }
//! ```
//!
//! Most applications do not depend on this crate directly — the
//! [`rtci`](https://docs.rs/rtc) crate re-exports it as `rtci::rtp`, and an application
//! usually meets these types when reading or writing media on a track.
//!
//! [RFC 3550]: https://datatracker.ietf.org/doc/html/rfc3550
//! [RFC 8285]: https://datatracker.ietf.org/doc/html/rfc8285
//! [RFC 6464]: https://datatracker.ietf.org/doc/html/rfc6464
//! [RFC 4733]: https://datatracker.ietf.org/doc/html/rfc4733
//! [RFC 3389]: https://datatracker.ietf.org/doc/html/rfc3389
//! [RFC 2198]: https://datatracker.ietf.org/doc/html/rfc2198
//! [RFC 7160]: https://datatracker.ietf.org/doc/html/rfc7160

/// Several clock rates in one RTP session ([RFC 7160]): the SSRC, timestamp and jitter rules.
///
/// [RFC 7160]: https://datatracker.ietf.org/doc/html/rfc7160
pub mod clock_rate;
/// Per-codec payloaders and depacketizers (VP8, VP9, AV1, H.264, H.265, Opus, G.711), and
/// telephone-event, comfort noise and RED.
pub mod codec;
/// The typed RTP header extensions ([RFC 8285]).
///
/// [RFC 8285]: https://datatracker.ietf.org/doc/html/rfc8285
pub mod extension;
/// Entry points for stateful fuzz targets. Gated behind `cfg(fuzzing)`; not part of the
/// supported API.
#[cfg(fuzzing)]
pub mod fuzzing;
pub mod header;
/// A whole RTP packet: header plus payload.
pub mod packet;
/// Turning encoded frames into RTP packets, and back again.
pub mod packetizer;
/// Sequence-number generation, starting from a random offset as the RFC requires.
pub mod sequence;

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