Skip to content

Commit

Permalink
deny missing documentation and implement missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ystreet committed Nov 18, 2024
1 parent 7341e26 commit aac9ba5
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl<'a> RtcpPacketParser<'a> for App<'a> {

impl<'a> App<'a> {
const SUBTYPE_MASK: u8 = Self::MAX_COUNT;
/// The length of the name of an [`App`] packet.
pub const NAME_LEN: usize = 4;

/// The (optional) padding used by this [`App`] packet
Expand Down
19 changes: 19 additions & 0 deletions src/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,28 @@ impl<'a> RtcpPacketWriter for UnknownBuilder<'a> {
/// parse a custom RTCP packet.
#[derive(Debug)]
pub enum Packet<'a> {
/// An [`App`](crate::App) packet.
App(crate::App<'a>),
/// A [`Bye`](crate::Bye) packet.
Bye(crate::Bye<'a>),
/// A [`ReceiverReport`](crate::ReceiverReport) packet.
Rr(crate::ReceiverReport<'a>),
/// A [`Sdes`](crate::Sdes) packet.
Sdes(crate::Sdes<'a>),
/// A [`SenderReport`](crate::SenderReport) packet.
Sr(crate::SenderReport<'a>),
/// A [`TransportFeedback`](crate::TransportFeedback) packet.
TransportFeedback(crate::TransportFeedback<'a>),
/// A [`PayloadFeedback`](crate::PayloadFeedback) packet.
PayloadFeedback(crate::PayloadFeedback<'a>),
/// An [`XR`](crate::Xr) packet.
Xr(crate::Xr<'a>),
/// An [`Unknown`](crate::Unknown) packet.
Unknown(Unknown<'a>),
}

impl<'a> Packet<'a> {
/// Whether the packet is of an unknown type.
pub fn is_unknown(&self) -> bool {
matches!(self, Packet::Unknown(_))
}
Expand Down Expand Up @@ -328,14 +338,23 @@ impl<'a> Iterator for Compound<'a> {
#[derive(Debug)]
#[must_use = "The builder must be built to be used"]
pub enum PacketBuilder<'a> {
/// An [`App`](crate::AppBuilder) packet.
App(crate::app::AppBuilder<'a>),
/// A [`Bye`](crate::ByeBuilder) packet.
Bye(crate::bye::ByeBuilder<'a>),
/// A [`ReceiverReport`](crate::ReceiverReportBuilder) packet.
Rr(crate::receiver::ReceiverReportBuilder),
/// A [`Sdes`](crate::SdesBuilder) packet.
Sdes(crate::sdes::SdesBuilder<'a>),
/// A [`SenderReport`](crate::SenderReportBuilder) packet.
Sr(crate::sender::SenderReportBuilder),
/// A [`TransportFeedback`](crate::TransportFeedbackBuilder) packet.
TransportFeedback(crate::feedback::TransportFeedbackBuilder<'a>),
/// A [`PayloadFeedback`](crate::PayloadFeedbackBuilder) packet.
PayloadFeedback(crate::feedback::PayloadFeedbackBuilder<'a>),
/// An [`XR`](crate::XrBuilder) packet.
Xr(crate::xr::XrBuilder),
/// An [`Unknown`](crate::UnknownBuilder) packet.
Unknown(UnknownBuilder<'a>),
}

Expand Down
5 changes: 5 additions & 0 deletions src/feedback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ pub struct FciFeedbackPacketType {
}

impl FciFeedbackPacketType {
/// No supported feedback type for the FCI data.
pub const NONE: Self = Self {
transport: false,
payload: false,
};
/// [`TransportFeedback`] is supported for the FCI data.
pub const TRANSPORT: Self = Self {
transport: true,
payload: false,
};
/// [`PayloadFeedback`] is supported for the FCI data.
pub const PAYLOAD: Self = Self {
transport: false,
payload: true,
Expand Down Expand Up @@ -420,7 +423,9 @@ impl<'a> RtcpPacketWriter for PayloadFeedbackBuilder<'a> {

/// Trait for parsing FCI data in [`TransportFeedback`] or [`PayloadFeedback`] packets
pub trait FciParser<'a>: Sized {
/// The supported feedback packet/s that the FCI data may be encountered within.
const PACKET_TYPE: FciFeedbackPacketType;
/// The type format of the FCI.
const FCI_FORMAT: u8;

/// Parse the provided FCI data
Expand Down
1 change: 1 addition & 0 deletions src/feedback/pli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Pli<'a> {
}

impl<'a> Pli<'a> {
/// Construct a builder for a [`Pli`] packet.
pub fn builder() -> PliBuilder {
PliBuilder {}
}
Expand Down
4 changes: 4 additions & 0 deletions src/feedback/rpsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ impl<'a> RpsiBuilder<'a> {
self
}

/// Set the codec specific bit string for thie RPSI along with how many bits in the last byte
/// must be ignored.
///
/// This is the owned variant that can leave the calling scope.
pub fn native_data_owned(
self,
data: impl Into<Cow<'a, [u8]>>,
Expand Down
98 changes: 87 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

#![deny(missing_debug_implementations)]
#![deny(missing_docs)]

//! # rtcp-type
//!
//! A crate for parsing and writing RTCP packets as specified in [RFC 3550] and related extensions.
//!
//! [RFC 3550]: https://tools.ietf.org/html/rfc3550

/// A Trait defining RTCP Packet structural data.
pub trait RtcpPacket {
/// RTCP protocol version. The default version of 2 is fine and should not need to be
/// overriden.
const VERSION: u8 = 2;
/// A maximum count that is commonly used across multiple RTCP packet types. A value larger
/// than this will produce a parsing error.
const MAX_COUNT: u8 = 0x1f;
/// The minimum size of a particular RTCP packet. A packet shorter than this value will
/// produce a parsing error.
const MIN_PACKET_LEN: usize;
/// The RTCP type of the particular RTCP packet.
const PACKET_TYPE: u8;
}

Expand All @@ -26,23 +40,30 @@ pub trait RtcpPacketParser<'a>: RtcpPacket + Sized {
fn header_data(&self) -> [u8; 4];
}

/// Extension trait providing helper functions for particular pieces of data in the 4 byte RTCP
/// header provided by [`RtcpPacketParser`].
pub trait RtcpPacketParserExt<'a>: RtcpPacketParser<'a> {
/// The RTCP protocol version.
fn version(&self) -> u8 {
utils::parser::parse_version(&self.header_data())
}

/// The RTCP payload type.
fn type_(&self) -> u8 {
utils::parser::parse_packet_type(&self.header_data())
}

/// The sub type of the RTCP packet. (Same value as [`count`](Self::count)).
fn subtype(&self) -> u8 {
utils::parser::parse_count(&self.header_data())
}

/// The advertsied length (in bytes) of the RTCP packet.
fn length(&self) -> usize {
utils::parser::parse_length(&self.header_data())
}

/// The number of records in this RTCP packet. (Same value as [`subtype`](Self::subtype)).
fn count(&self) -> u8 {
utils::parser::parse_count(&self.header_data())
}
Expand Down Expand Up @@ -76,6 +97,7 @@ pub trait RtcpPacketWriter: std::fmt::Debug {
fn get_padding(&self) -> Option<u8>;
}

/// Extension providing helpders for writing a [`RtcpPacket`].
pub trait RtcpPacketWriterExt: RtcpPacketWriter {
/// Writes the Custom packet into `buf`.
///
Expand Down Expand Up @@ -155,7 +177,12 @@ pub enum RtcpParseError {

/// RTCP Packet type mismatch.
#[error("RTCP Packet type mismatch. Actual: {actual}, requested {requested}")]
PacketTypeMismatch { actual: u8, requested: u8 },
PacketTypeMismatch {
/// The packet type encountered.
actual: u8,
/// The requested packet type.
requested: u8,
},
}

/// Errors produced when writing a packet
Expand All @@ -168,11 +195,19 @@ pub enum RtcpWriteError {

/// The provided padding is not a multiple of 4.
#[error("The provided padding {padding} is not a multiple of 4")]
InvalidPadding { padding: u8 },
InvalidPadding {
/// The padding value encountered.
padding: u8,
},

/// App Subtype was out of range.
#[error("App Subtype {subtype} was out of range (max: {max})")]
AppSubtypeOutOfRange { subtype: u8, max: u8 },
AppSubtypeOutOfRange {
/// The subtype value encountered.
subtype: u8,
/// The maximum allowable value.
max: u8,
},

/// APP Packet Name is invalid. Expecting a sequence of four ASCII characters.
#[error("APP Packet Name is invalid. Expecting a sequence of four ASCII characters.")]
Expand All @@ -184,35 +219,75 @@ pub enum RtcpWriteError {

/// Too many Sources specified.
#[error("Too many Sources specified. Number of Sources: {count}, max: {max}")]
TooManySources { count: usize, max: u8 },
TooManySources {
/// The count of sources encountered.
count: usize,
/// The maximum allowable value.
max: u8,
},

/// Reason length was too large.
#[error("Reason length {len} was too large (max {max})")]
ReasonLenTooLarge { len: usize, max: u8 },
ReasonLenTooLarge {
/// The length value encountered.
len: usize,
/// The maximum allowable value.
max: u8,
},

/// Cumulative Lost was too large.
#[error("Cumulative Lost {value} was too large (max {max})")]
CumulativeLostTooLarge { value: u32, max: u32 },
CumulativeLostTooLarge {
/// The value encountered.
value: u32,
/// The maximum allowable value.
max: u32,
},

/// Too many Report Blocks specified (max 31).
#[error("Too many Report Blocks specified. Number of Report Blocks: {count} max: {max}")]
TooManyReportBlocks { count: usize, max: u8 },
TooManyReportBlocks {
/// The number of report blocks encountered.
count: usize,
/// The maximum allowable value.
max: u8,
},

/// Too many SDES Chunks specified.
#[error("Too many SDES Chunks specified. Number of SDES Chunks: {count}, max: {max}")]
TooManySdesChunks { count: usize, max: u8 },
TooManySdesChunks {
/// The number of SDES chunks encountered.
count: usize,
/// The maximum allowable value.
max: u8,
},

/// SDES Value length was too large.
#[error("SDES Value length {len} was too large (max {max})")]
SdesValueTooLarge { len: usize, max: u8 },
SdesValueTooLarge {
/// The length of the SDES value that was encountered.
len: usize,
/// The maximum allowable value.
max: u8,
},

/// The SDES PRIV prefix was too large.
#[error("The SDES PRIV prefix length {len} too large (max {max})")]
SdesPrivPrefixTooLarge { len: usize, max: u8 },
SdesPrivPrefixTooLarge {
/// The length of the SDES PRIV prefix that was encountered.
len: usize,
/// The maximum allowable value.
max: u8,
},

/// Unknown Count was out of range.
#[error("Unknown Count {count} was out of range (max: {max})")]
CountOutOfRange { count: u8, max: u8 },
CountOutOfRange {
/// The count value that was encountered.
count: u8,
/// The maximum allowable value.
max: u8,
},

/// Non-last Compound packet padding defined.
#[error("Non-last Compound packet padding defined")]
Expand Down Expand Up @@ -301,6 +376,7 @@ pub use xr::{
XrBlockStaticType, XrBuilder,
};

/// Prelude module for defined/implementable traits
pub mod prelude {
pub use super::{
FciBuilder, FciParser, RtcpPacket, RtcpPacketParser, RtcpPacketParserExt, RtcpPacketWriter,
Expand Down
6 changes: 4 additions & 2 deletions src/report_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
use crate::{utils::u32_from_be_bytes, RtcpParseError, RtcpWriteError};

/// A report block as found in a [`SenderReport`](crate::SenderReport) or a
/// [`ReceiverReport`](crate::ReceiverReport) for a received SSRC
/// [`ReceiverReport`](crate::ReceiverReport) for a received SSRC.
#[derive(Debug, PartialEq, Eq)]
pub struct ReportBlock<'a> {
data: &'a [u8; ReportBlock::EXPECTED_SIZE],
}

impl<'a> ReportBlock<'a> {
/// The expected size of a [`ReportBlock`] as stored in a [`SenderReport`](crate::SenderReport)
/// or a [`ReceiverReport`](crate::ReceiverReport).
pub const EXPECTED_SIZE: usize = 24;

/// Parse data into a [`ReportBlock`].
Expand Down Expand Up @@ -86,7 +88,7 @@ pub struct ReportBlockBuilder {
}

impl ReportBlockBuilder {
pub fn new(ssrc: u32) -> Self {
fn new(ssrc: u32) -> Self {
ReportBlockBuilder {
ssrc,
fraction_lost: 0,
Expand Down
14 changes: 11 additions & 3 deletions src/sdes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'a> SdesChunk<'a> {
self.items.iter()
}

/// Create a new [`SdesItemBuilder`]
/// Create a new [`SdesChunkBuilder`]
pub fn builder(ssrc: u32) -> SdesChunkBuilder<'a> {
SdesChunkBuilder::new(ssrc)
}
Expand All @@ -148,13 +148,21 @@ pub struct SdesItem<'a> {
impl<'a> SdesItem<'a> {
const MIN_LEN: usize = 4;
const VALUE_MAX_LEN: u8 = 255;
/// The CNAME item in a SDES.
pub const CNAME: u8 = 0x01;
/// The NAME item in a SDES.
pub const NAME: u8 = 0x02;
/// The EMAIL item in a SDES.
pub const EMAIL: u8 = 0x03;
/// The PHONE item in a SDES.
pub const PHONE: u8 = 0x04;
/// The LOC item in a SDES.
pub const LOC: u8 = 0x05;
/// The TOOL item in a SDES.
pub const TOOL: u8 = 0x06;
/// The NOTE item in a SDES.
pub const NOTE: u8 = 0x07;
/// The PRIV item in a SDES.
pub const PRIV: u8 = 0x08;

fn parse(data: &'a [u8]) -> Result<(Self, usize), RtcpParseError> {
Expand Down Expand Up @@ -353,7 +361,7 @@ pub struct SdesChunkBuilder<'a> {
}

impl<'a> SdesChunkBuilder<'a> {
pub fn new(ssrc: u32) -> Self {
fn new(ssrc: u32) -> Self {
SdesChunkBuilder {
ssrc,
items: Vec::new(),
Expand Down Expand Up @@ -441,7 +449,7 @@ pub struct SdesItemBuilder<'a> {
}

impl<'a> SdesItemBuilder<'a> {
pub fn new(type_: u8, value: impl Into<Cow<'a, str>>) -> SdesItemBuilder<'a> {
fn new(type_: u8, value: impl Into<Cow<'a, str>>) -> SdesItemBuilder<'a> {
SdesItemBuilder {
type_,
prefix: Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Utilites for handling RTCP packets

#[track_caller]
#[inline(always)]
pub(crate) fn u16_from_be_bytes(bytes: &[u8]) -> u16 {
Expand Down
Loading

0 comments on commit aac9ba5

Please sign in to comment.