rtci_rtcp/lib.rs
1#![warn(rust_2018_idioms)]
2#![warn(missing_docs)]
3#![allow(dead_code)]
4
5//! Package rtcp implements encoding and decoding of RTCP packets according to RFCs 3550 and 5506,
6//! with the feedback messages of RFC 4585 and RFC 5104, the extended reports of RFC 3611 and the
7//! congestion control feedback of RFC 8888.
8//!
9//! RTCP is a sister protocol of the Real-time Transport Protocol (RTP). Its basic functionality
10//! and packet structure is defined in RFC 3550. RTCP provides out-of-band statistics and control
11//! information for an RTP session. It partners with RTP in the delivery and packaging of multimedia data,
12//! but does not transport any media data itself.
13//!
14//! The primary function of RTCP is to provide feedback on the quality of service (QoS)
15//! in media distribution by periodically sending statistics information such as transmitted octet
16//! and packet counts, packet loss, packet delay variation, and round-trip delay time to participants
17//! in a streaming multimedia session. An application may use this information to control quality of
18//! service parameters, perhaps by limiting flow, or using a different codec.
19//!
20//! # Decoding RTCP packets
21//!
22//! One datagram may hold several packets — RTCP is compound — so [`packet::unmarshal`]
23//! consumes the buffer and returns them all. Recover each concrete type by downcasting:
24//!
25//! ```
26//! use bytes::Bytes;
27//! use rtci_rtcp::goodbye::Goodbye;
28//! use rtci_rtcp::packet::unmarshal;
29//! use rtci_rtcp::payload_feedbacks::picture_loss_indication::PictureLossIndication;
30//!
31//! # fn example(rtcp_data: Bytes) -> Result<(), Box<dyn std::error::Error>> {
32//! let mut buf = rtcp_data;
33//! for packet in unmarshal(&mut buf)? {
34//! if let Some(pli) = packet.as_any().downcast_ref::<PictureLossIndication>() {
35//! println!("keyframe requested for ssrc {}", pli.media_ssrc);
36//! } else if let Some(bye) = packet.as_any().downcast_ref::<Goodbye>() {
37//! println!("{:?} left the session", bye.sources);
38//! }
39//! }
40//! # Ok(())
41//! # }
42//! ```
43//!
44//! # Encoding RTCP packets
45//!
46//! Every packet type implements [`Marshal`](shared::marshal::Marshal), so that trait must be
47//! in scope:
48//!
49//! ```
50//! use rtci_rtcp::payload_feedbacks::picture_loss_indication::PictureLossIndication;
51//! use shared::marshal::Marshal;
52//!
53//! # fn example(sender_ssrc: u32, media_ssrc: u32) -> Result<(), Box<dyn std::error::Error>> {
54//! let pli = PictureLossIndication {
55//! sender_ssrc,
56//! media_ssrc,
57//! };
58//! let pli_data = pli.marshal()?;
59//! # Ok(())
60//! # }
61//! ```
62
63/// The APP packet: application-defined data under a four-character name.
64pub mod application_defined;
65/// Compound RTCP packets — the several reports that share one datagram.
66pub mod compound_packet;
67/// Extended reports (XR, [RFC 3611]): loss/discard run lengths, receipt times and per-block
68/// statistics.
69///
70/// [RFC 3611]: https://datatracker.ietf.org/doc/html/rfc3611
71pub mod extended_report;
72/// The checks the fuzz targets in `fuzz/` run, shared with the replay test of
73/// `fuzz/regressions/`. Built with `cfg(fuzzing)` (cargo-fuzz) or for this crate's tests; not
74/// part of the supported API.
75#[cfg(any(fuzzing, test))]
76#[doc(hidden)]
77pub mod fuzz_oracles;
78#[cfg(test)]
79mod fuzz_regressions_test;
80/// The BYE packet, by which a source announces it is leaving.
81pub mod goodbye;
82/// The four-byte header common to every RTCP packet.
83pub mod header;
84/// The [`Packet`] trait every RTCP packet type implements.
85pub mod packet;
86/// Payload-specific feedback (PT 206): PLI, SLI, RPSI, FIR, TSTR, TSTN, VBCM, LRR, REMB and
87/// other application layer feedback.
88pub mod payload_feedbacks;
89/// An unparsed packet, used for types this crate does not model.
90pub mod raw_packet;
91/// The Receiver Report (RR), which reports reception quality back to a sender.
92pub mod receiver_report;
93/// The reception report block carried inside SR and RR packets.
94pub mod reception_report;
95/// The Sender Report (SR), which carries a sender's timing and packet counts.
96pub mod sender_report;
97/// The SDES packet, which carries CNAME and other source metadata.
98pub mod source_description;
99/// Transport-specific feedback (PT 205): NACK, TMMBR, TMMBN, rapid resynchronisation,
100/// transport-wide congestion control and RFC 8888 feedback.
101pub mod transport_feedbacks;
102mod util;
103
104#[cfg(test)]
105mod feedback_rules_test;
106#[cfg(test)]
107mod packet_dispatch_test;
108
109pub use header::Header;
110pub use packet::Packet;