rtci-rtcp 0.4.1

RTCP packet parsing and serialization (RFC 3550, RFC 4585, RFC 5104, RFC 3611, RFC 8888) for WebRTC
Documentation
#![warn(rust_2018_idioms)]
#![warn(missing_docs)]
#![allow(dead_code)]

//! Package rtcp implements encoding and decoding of RTCP packets according to RFCs 3550 and 5506,
//! with the feedback messages of RFC 4585 and RFC 5104, the extended reports of RFC 3611 and the
//! congestion control feedback of RFC 8888.
//!
//! RTCP is a sister protocol of the Real-time Transport Protocol (RTP). Its basic functionality
//! and packet structure is defined in RFC 3550. RTCP provides out-of-band statistics and control
//! information for an RTP session. It partners with RTP in the delivery and packaging of multimedia data,
//! but does not transport any media data itself.
//!
//! The primary function of RTCP is to provide feedback on the quality of service (QoS)
//! in media distribution by periodically sending statistics information such as transmitted octet
//! and packet counts, packet loss, packet delay variation, and round-trip delay time to participants
//! in a streaming multimedia session. An application may use this information to control quality of
//! service parameters, perhaps by limiting flow, or using a different codec.
//!
//! # Decoding RTCP packets
//!
//! One datagram may hold several packets — RTCP is compound — so [`packet::unmarshal`]
//! consumes the buffer and returns them all. Recover each concrete type by downcasting:
//!
//! ```
//! use bytes::Bytes;
//! use rtci_rtcp::goodbye::Goodbye;
//! use rtci_rtcp::packet::unmarshal;
//! use rtci_rtcp::payload_feedbacks::picture_loss_indication::PictureLossIndication;
//!
//! # fn example(rtcp_data: Bytes) -> Result<(), Box<dyn std::error::Error>> {
//! let mut buf = rtcp_data;
//! for packet in unmarshal(&mut buf)? {
//!     if let Some(pli) = packet.as_any().downcast_ref::<PictureLossIndication>() {
//!         println!("keyframe requested for ssrc {}", pli.media_ssrc);
//!     } else if let Some(bye) = packet.as_any().downcast_ref::<Goodbye>() {
//!         println!("{:?} left the session", bye.sources);
//!     }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Encoding RTCP packets
//!
//! Every packet type implements [`Marshal`](shared::marshal::Marshal), so that trait must be
//! in scope:
//!
//! ```
//! use rtci_rtcp::payload_feedbacks::picture_loss_indication::PictureLossIndication;
//! use shared::marshal::Marshal;
//!
//! # fn example(sender_ssrc: u32, media_ssrc: u32) -> Result<(), Box<dyn std::error::Error>> {
//! let pli = PictureLossIndication {
//!     sender_ssrc,
//!     media_ssrc,
//! };
//! let pli_data = pli.marshal()?;
//! # Ok(())
//! # }
//! ```

/// The APP packet: application-defined data under a four-character name.
pub mod application_defined;
/// Compound RTCP packets — the several reports that share one datagram.
pub mod compound_packet;
/// Extended reports (XR, [RFC 3611]): loss/discard run lengths, receipt times and per-block
/// statistics.
///
/// [RFC 3611]: https://datatracker.ietf.org/doc/html/rfc3611
pub mod extended_report;
/// The BYE packet, by which a source announces it is leaving.
pub mod goodbye;
/// The four-byte header common to every RTCP packet.
pub mod header;
/// The [`Packet`] trait every RTCP packet type implements.
pub mod packet;
/// Payload-specific feedback (PT 206): PLI, SLI, RPSI, FIR, TSTR, TSTN, VBCM, LRR, REMB and
/// other application layer feedback.
pub mod payload_feedbacks;
/// An unparsed packet, used for types this crate does not model.
pub mod raw_packet;
/// The Receiver Report (RR), which reports reception quality back to a sender.
pub mod receiver_report;
/// The reception report block carried inside SR and RR packets.
pub mod reception_report;
/// The Sender Report (SR), which carries a sender's timing and packet counts.
pub mod sender_report;
/// The SDES packet, which carries CNAME and other source metadata.
pub mod source_description;
/// Transport-specific feedback (PT 205): NACK, TMMBR, TMMBN, rapid resynchronisation,
/// transport-wide congestion control and RFC 8888 feedback.
pub mod transport_feedbacks;
mod util;

#[cfg(test)]
mod feedback_rules_test;
#[cfg(test)]
mod packet_dispatch_test;

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