Skip to main content

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 BYE packet, by which a source announces it is leaving.
73pub mod goodbye;
74/// The four-byte header common to every RTCP packet.
75pub mod header;
76/// The [`Packet`] trait every RTCP packet type implements.
77pub mod packet;
78/// Payload-specific feedback (PT 206): PLI, SLI, RPSI, FIR, TSTR, TSTN, VBCM, LRR, REMB and
79/// other application layer feedback.
80pub mod payload_feedbacks;
81/// An unparsed packet, used for types this crate does not model.
82pub mod raw_packet;
83/// The Receiver Report (RR), which reports reception quality back to a sender.
84pub mod receiver_report;
85/// The reception report block carried inside SR and RR packets.
86pub mod reception_report;
87/// The Sender Report (SR), which carries a sender's timing and packet counts.
88pub mod sender_report;
89/// The SDES packet, which carries CNAME and other source metadata.
90pub mod source_description;
91/// Transport-specific feedback (PT 205): NACK, TMMBR, TMMBN, rapid resynchronisation,
92/// transport-wide congestion control and RFC 8888 feedback.
93pub mod transport_feedbacks;
94mod util;
95
96#[cfg(test)]
97mod feedback_rules_test;
98#[cfg(test)]
99mod packet_dispatch_test;
100
101pub use header::Header;
102pub use packet::Packet;