Skip to content

Commit

Permalink
Code improvement, part 1: modules documentation (#549)
Browse files Browse the repository at this point in the history
* Clippy suggestions applied

* Moving out common parts of code

* Links reformatting, added docstrings for modules exported from main

* Fixing Clippy and fmt suggestions

* Fixed code by Clippy lints
  • Loading branch information
ProgramCrafter authored Mar 30, 2024
1 parent cc7e2ba commit a97d49e
Show file tree
Hide file tree
Showing 36 changed files with 151 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mod tests {
&RESIZE_MODE,
]);

let settings = vec![
let settings = [
MediaTrackSettings::from_iter([(&DEVICE_ID, "foo".into())]),
MediaTrackSettings::from_iter([(&DEVICE_ID, "bar".into())]),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {
&RESIZE_MODE,
]);

let settings = vec![
let settings = [
MediaTrackSettings::from_iter([(&DEVICE_ID, "foo".into())]),
MediaTrackSettings::from_iter([(&DEVICE_ID, "bar".into())]),
];
Expand Down
6 changes: 3 additions & 3 deletions constraints/src/algorithms/select_settings/select_optimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod tests {

#[test]
fn monotonic_increasing() {
let settings = vec![
let settings = [
MediaTrackSettings::default(),
MediaTrackSettings::default(),
MediaTrackSettings::default(),
Expand All @@ -72,7 +72,7 @@ mod tests {

#[test]
fn monotonic_decreasing() {
let settings = vec![
let settings = [
MediaTrackSettings::default(),
MediaTrackSettings::default(),
MediaTrackSettings::default(),
Expand All @@ -95,7 +95,7 @@ mod tests {

#[test]
fn alternating() {
let settings = vec![
let settings = [
MediaTrackSettings::default(),
MediaTrackSettings::default(),
MediaTrackSettings::default(),
Expand Down
2 changes: 1 addition & 1 deletion dtls/src/handshake/handshake_message_client_hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl fmt::Debug for HandshakeMessageClientHello {
cipher_suites_str += &cipher_suite.to_string();
cipher_suites_str += " ";
}
let s = vec![
let s = [
format!("version: {:?} random: {:?}", self.version, self.random),
format!("cookie: {:?}", self.cookie),
format!("cipher_suites: {cipher_suites_str:?}"),
Expand Down
2 changes: 1 addition & 1 deletion dtls/src/handshake/handshake_message_server_hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl PartialEq for HandshakeMessageServerHello {

impl fmt::Debug for HandshakeMessageServerHello {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = vec![
let s = [
format!("version: {:?} random: {:?}", self.version, self.random),
format!("cipher_suites: {:?}", self.cipher_suite),
format!("compression_method: {:?}", self.compression_method),
Expand Down
4 changes: 2 additions & 2 deletions ice/src/rand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const RUNES_CANDIDATE_ID_FOUNDATION: &[u8] =
const LEN_UFRAG: usize = 16;
const LEN_PWD: usize = 32;

//TODO: generates a random string for cryptographic usage.
// TODO: cryptographically strong random source
pub fn generate_crypto_random_string(n: usize, runes: &[u8]) -> String {
let mut rng = thread_rng();

Expand All @@ -24,7 +24,7 @@ pub fn generate_crypto_random_string(n: usize, runes: &[u8]) -> String {
rand_string
}

/// https://tools.ietf.org/html/rfc5245#section-15.1
/// <https://tools.ietf.org/html/rfc5245#section-15.1>
/// candidate-id = "candidate" ":" foundation
/// foundation = 1*32ice-char
/// ice-char = ALPHA / DIGIT / "+" / "/"
Expand Down
4 changes: 2 additions & 2 deletions ice/src/udp_mux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl UDPMuxDefault {
.split(':')
.next()
.and_then(|ufrag| conns.get(ufrag))
.map(Clone::clone);
.cloned();

conn
}
Expand All @@ -178,7 +178,7 @@ impl UDPMuxDefault {
.address_map
.read();

address_map.get(&addr).map(Clone::clone)
address_map.get(&addr).cloned()
};

let conn = match conn {
Expand Down
2 changes: 1 addition & 1 deletion ice/src/udp_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl EphemeralUDP {
///
/// In Ephemeral mode sockets are created and bound to random ports during ICE
/// gathering. The ports to use can be restricted by setting [`EphemeralUDP::port_min`] and
/// [`EphemeralEphemeralUDP::port_max`] in which case only ports in this range will be used.
/// [`EphemeralUDP::port_max`] in which case only ports in this range will be used.
///
/// **Muxed**
///
Expand Down
4 changes: 2 additions & 2 deletions interceptor/src/stream_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ pub struct StreamInfo {
}

/// RTCPFeedback signals the connection to use additional RTCP packet types.
/// https://draft.ortc.org/#dom-rtcrtcpfeedback
/// <https://draft.ortc.org/#dom-rtcrtcpfeedback>
#[derive(Default, Debug, Clone)]
pub struct RTCPFeedback {
/// Type is the type of feedback.
/// see: https://draft.ortc.org/#dom-rtcrtcpfeedback
/// see: <https://draft.ortc.org/#dom-rtcrtcpfeedback>
/// valid: ack, ccm, nack, goog-remb, transport-cc
pub typ: String,

Expand Down
2 changes: 1 addition & 1 deletion interceptor/src/twcc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct PktInfo {

/// Recorder records incoming RTP packets and their delays and creates
/// transport wide congestion control feedback reports as specified in
/// https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
/// <https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01>
#[derive(Default, Debug, PartialEq, Clone)]
pub struct Recorder {
received_packets: Vec<PktInfo>,
Expand Down
4 changes: 2 additions & 2 deletions interceptor/src/twcc/receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct ReceiverInternal {
close_rx: Mutex<Option<mpsc::Receiver<()>>>,
}

/// Receiver sends transport wide congestion control reports as specified in:
/// https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
/// Receiver sends transport-wide congestion control reports as specified in:
/// <https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01>
pub struct Receiver {
internal: Arc<ReceiverInternal>,

Expand Down
4 changes: 2 additions & 2 deletions interceptor/src/twcc/twcc_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ fn test_feedback() -> Result<()> {
pkt.packet_chunks
);

let expected_deltas = vec![
let expected_deltas = [
RecvDelta {
type_tcc_packet: SymbolTypeTcc::PacketReceivedSmallDelta,
delta: 0,
Expand Down Expand Up @@ -338,7 +338,7 @@ fn test_feedback() -> Result<()> {
pkt.packet_chunks
);

let expected_deltas = vec![
let expected_deltas = [
RecvDelta {
type_tcc_packet: SymbolTypeTcc::PacketReceivedSmallDelta,
delta: 0,
Expand Down
2 changes: 1 addition & 1 deletion media/src/io/h264_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn is_key_frame(data: &[u8]) -> bool {
/// write the data to an io.Writer.
/// Currently it only supports non-interleaved mode
/// Therefore, only 1-23, 24 (STAP-A), 28 (FU-A) NAL types are allowed.
/// https://tools.ietf.org/html/rfc6184#section-5.2
/// <https://tools.ietf.org/html/rfc6184#section-5.2>
pub struct H264Writer<W: Write + Seek> {
writer: W,
has_key_frame: bool,
Expand Down
4 changes: 2 additions & 2 deletions media/src/io/ivf_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const IVF_FILE_HEADER_SIZE: usize = 32;
pub const IVF_FRAME_HEADER_SIZE: usize = 12;

/// IVFFileHeader 32-byte header for IVF files
/// https://wiki.multimedia.cx/index.php/IVF
/// <https://wiki.multimedia.cx/index.php/IVF>
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct IVFFileHeader {
pub signature: [u8; 4], // 0-3
Expand All @@ -30,7 +30,7 @@ pub struct IVFFileHeader {
}

/// IVFFrameHeader 12-byte header for IVF frames
/// https://wiki.multimedia.cx/index.php/IVF
/// <https://wiki.multimedia.cx/index.php/IVF>
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct IVFFrameHeader {
pub frame_size: u32, // 0-3
Expand Down
4 changes: 2 additions & 2 deletions media/src/io/ogg_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct OggReader<R: Read> {

/// OggHeader is the metadata from the first two pages
/// in the file (ID and Comment)
/// https://tools.ietf.org/html/rfc7845.html#section-3
/// <https://tools.ietf.org/html/rfc7845.html#section-3>
pub struct OggHeader {
pub channel_map: u8,
pub channels: u8,
Expand All @@ -41,7 +41,7 @@ pub struct OggHeader {

/// OggPageHeader is the metadata for a Page
/// Pages are the fundamental unit of multiplexing in an Ogg stream
/// https://tools.ietf.org/html/rfc7845.html#section-1
/// <https://tools.ietf.org/html/rfc7845.html#section-1>
pub struct OggPageHeader {
pub granule_position: u64,

Expand Down
6 changes: 3 additions & 3 deletions media/src/io/sample_builder/sample_builder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,21 +1449,21 @@ fn test_sample_builder_clean_reference() {

#[test]
fn test_sample_builder_push_max_zero() {
let pkts = vec![Packet {
let pkt = Packet {
header: Header {
sequence_number: 0,
timestamp: 0,
marker: true,
..Default::default()
},
payload: bytes!(0x01),
}];
};
let d = FakeDepacketizer {
head_checker: true,
head_bytes: vec![bytes!(0x01)],
};
let mut s = SampleBuilder::new(0, d, 1);
s.push(pkts[0].clone());
s.push(pkt);
assert!(s.pop().is_some(), "Should expect a popped sample.")
}

Expand Down
4 changes: 2 additions & 2 deletions rtp/src/codecs/av1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ mod packetizer;
pub struct Av1Payloader {}

impl Payloader for Av1Payloader {
/// Based on https://chromium.googlesource.com/external/webrtc/+/4e513346ec56c829b3a6010664998469fc237b35/modules/rtp_rtcp/source/rtp_packetizer_av1.cc
/// Reference: https://aomediacodec.github.io/av1-rtp-spec/#45-payload-structure
/// Based on <https://chromium.googlesource.com/external/webrtc/+/4e513346ec56c829b3a6010664998469fc237b35/modules/rtp_rtcp/source/rtp_packetizer_av1.cc>
/// Reference: <https://aomediacodec.github.io/av1-rtp-spec/#45-payload-structure>
fn payload(&mut self, mtu: usize, payload: &Bytes) -> crate::error::Result<Vec<Bytes>> {
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
Expand Down
22 changes: 11 additions & 11 deletions rtp/src/codecs/h265/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ mod h265_test;
///
const H265NALU_HEADER_SIZE: usize = 2;
/// https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2
/// <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2>
const H265NALU_AGGREGATION_PACKET_TYPE: u8 = 48;
/// https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3
/// <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3>
const H265NALU_FRAGMENTATION_UNIT_TYPE: u8 = 49;
/// https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.4
/// <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.4>
const H265NALU_PACI_PACKET_TYPE: u8 = 50;

/// H265NALUHeader is a H265 NAL Unit Header
/// https://datatracker.ietf.org/doc/html/rfc7798#section-1.1.4
/// <https://datatracker.ietf.org/doc/html/rfc7798#section-1.1.4>
/// +---------------+---------------+
/// |0|1|2|3|4|5|6|7|0|1|2|3|4|5|6|7|
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Expand Down Expand Up @@ -97,7 +97,7 @@ impl H265NALUHeader {
/// | :...OPTIONAL RTP padding |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.1
/// Reference: <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.1>
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265SingleNALUnitPacket {
/// payload_header is the header of the H265 packet.
Expand Down Expand Up @@ -186,7 +186,7 @@ impl H265SingleNALUnitPacket {
/// | :
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2
/// Reference: <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2>
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265AggregationUnitFirst {
donl: Option<u16>,
Expand Down Expand Up @@ -226,7 +226,7 @@ impl H265AggregationUnitFirst {
/// | :
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2
/// Reference: <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2>
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265AggregationUnit {
dond: Option<u8>,
Expand Down Expand Up @@ -266,7 +266,7 @@ impl H265AggregationUnit {
/// | :...OPTIONAL RTP padding |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2
/// Reference: <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2>
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265AggregationPacket {
first_unit: Option<H265AggregationUnitFirst>,
Expand Down Expand Up @@ -427,7 +427,7 @@ impl H265FragmentationUnitHeader {
/// | :...OPTIONAL RTP padding |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3
/// Reference: <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3>
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265FragmentationUnitPacket {
/// payload_header is the header of the H265 packet.
Expand Down Expand Up @@ -526,7 +526,7 @@ impl H265FragmentationUnitPacket {
/// | :...OPTIONAL RTP padding |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.4
/// Reference: <https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.4>
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct H265PACIPacket {
/// payload_header is the header of the H265 packet.
Expand Down Expand Up @@ -655,7 +655,7 @@ impl H265PACIPacket {
///
/// H265TSCI is a Temporal Scalability Control Information header extension.
/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.5
/// Reference: <https://datatracker.ietf.org/doc/html/rfc7798#section-4.5>
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct H265TSCI(pub u32);

Expand Down
4 changes: 2 additions & 2 deletions sdp/src/description/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl MediaDescription {

/// RangedPort supports special format for the media field "m=" port value. If
/// it may be necessary to specify multiple transport ports, the protocol allows
/// to write it as: <port>/<number of ports> where number of ports is a an
/// to write it as: `<port>/<number of ports>` where number of ports is a an
/// offsetting range.
#[derive(Debug, Default, Clone)]
pub struct RangedPort {
Expand Down Expand Up @@ -231,7 +231,7 @@ pub struct MediaName {

impl fmt::Display for MediaName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = vec![
let s = [
self.media.clone(),
self.port.to_string(),
self.protos.join("/"),
Expand Down
4 changes: 2 additions & 2 deletions sdp/src/direction/direction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;

#[test]
fn test_new_direction() {
let passingtests = vec![
let passingtests = [
("sendrecv", Direction::SendRecv),
("sendonly", Direction::SendOnly),
("recvonly", Direction::RecvOnly),
Expand All @@ -25,7 +25,7 @@ fn test_new_direction() {

#[test]
fn test_direction_string() {
let tests = vec![
let tests = [
(Direction::Unspecified, DIRECTION_UNSPECIFIED_STR),
(Direction::SendRecv, "sendrecv"),
(Direction::SendOnly, "sendonly"),
Expand Down
2 changes: 1 addition & 1 deletion srtp/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Config {
impl Config {
/// ExtractSessionKeysFromDTLS allows setting the Config SessionKeys by
/// extracting them from DTLS. This behavior is defined in RFC5764:
/// https://tools.ietf.org/html/rfc5764
/// <https://tools.ietf.org/html/rfc5764>
pub async fn extract_session_keys_from_dtls(
&mut self,
exporter: impl KeyingMaterialExporter,
Expand Down
2 changes: 1 addition & 1 deletion turn/src/allocation/allocation_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Manager {
/// Fetches the [`Allocation`] matching the passed [`FiveTuple`].
pub async fn get_allocation(&self, five_tuple: &FiveTuple) -> Option<Arc<Allocation>> {
let allocations = self.allocations.lock().await;
allocations.get(five_tuple).map(Arc::clone)
allocations.get(five_tuple).cloned()
}

/// Creates a new [`Allocation`] and starts relaying.
Expand Down
8 changes: 4 additions & 4 deletions util/src/ifaces/ffi/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,16 @@ unsafe fn map_adapter_addresses(mut adapter_addr: *const IpAdapterAddresses) ->
// For some reason, some IpDadState::IpDadStateDeprecated addresses are return
// These contain BOGUS interface indices and will cause problesm if used
if curr_unicast_addr.dad_state != IpDadState::IpDadStateDeprecated {
if is_ipv4_enabled(&curr_unicast_addr) {
if is_ipv4_enabled(curr_unicast_addr) {
adapter_addresses.push(Interface {
name: "".to_string(),
kind: Kind::Ipv4,
addr: Some(SocketAddr::V4(v4_socket_from_adapter(&curr_unicast_addr))),
addr: Some(SocketAddr::V4(v4_socket_from_adapter(curr_unicast_addr))),
mask: None,
hop: None,
});
} else if is_ipv6_enabled(&curr_unicast_addr) {
let mut v6_sock = v6_socket_from_adapter(&curr_unicast_addr);
} else if is_ipv6_enabled(curr_unicast_addr) {
let mut v6_sock = v6_socket_from_adapter(curr_unicast_addr);
// Make sure the scope id is set for ALL interfaces, not just link-local
v6_sock.set_scope_id(curr_adapter_addr.xp.ipv6_if_index);
adapter_addresses.push(Interface {
Expand Down
Loading

0 comments on commit a97d49e

Please sign in to comment.