diff --git a/constraints/src/algorithms/select_settings/apply_advanced.rs b/constraints/src/algorithms/select_settings/apply_advanced.rs index 5e2467b20..b7adfbe51 100644 --- a/constraints/src/algorithms/select_settings/apply_advanced.rs +++ b/constraints/src/algorithms/select_settings/apply_advanced.rs @@ -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())]), ]; diff --git a/constraints/src/algorithms/select_settings/apply_mandatory.rs b/constraints/src/algorithms/select_settings/apply_mandatory.rs index 36a8d7a61..a9bba70e8 100644 --- a/constraints/src/algorithms/select_settings/apply_mandatory.rs +++ b/constraints/src/algorithms/select_settings/apply_mandatory.rs @@ -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())]), ]; diff --git a/constraints/src/algorithms/select_settings/select_optimal.rs b/constraints/src/algorithms/select_settings/select_optimal.rs index 30585479a..dbc631053 100644 --- a/constraints/src/algorithms/select_settings/select_optimal.rs +++ b/constraints/src/algorithms/select_settings/select_optimal.rs @@ -49,7 +49,7 @@ mod tests { #[test] fn monotonic_increasing() { - let settings = vec![ + let settings = [ MediaTrackSettings::default(), MediaTrackSettings::default(), MediaTrackSettings::default(), @@ -72,7 +72,7 @@ mod tests { #[test] fn monotonic_decreasing() { - let settings = vec![ + let settings = [ MediaTrackSettings::default(), MediaTrackSettings::default(), MediaTrackSettings::default(), @@ -95,7 +95,7 @@ mod tests { #[test] fn alternating() { - let settings = vec![ + let settings = [ MediaTrackSettings::default(), MediaTrackSettings::default(), MediaTrackSettings::default(), diff --git a/dtls/src/handshake/handshake_message_client_hello.rs b/dtls/src/handshake/handshake_message_client_hello.rs index ad4ca6fc7..f98340e03 100644 --- a/dtls/src/handshake/handshake_message_client_hello.rs +++ b/dtls/src/handshake/handshake_message_client_hello.rs @@ -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:?}"), diff --git a/dtls/src/handshake/handshake_message_server_hello.rs b/dtls/src/handshake/handshake_message_server_hello.rs index fd38b2488..6be32e458 100644 --- a/dtls/src/handshake/handshake_message_server_hello.rs +++ b/dtls/src/handshake/handshake_message_server_hello.rs @@ -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), diff --git a/ice/src/rand/mod.rs b/ice/src/rand/mod.rs index 84001a811..db041ef0b 100644 --- a/ice/src/rand/mod.rs +++ b/ice/src/rand/mod.rs @@ -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(); @@ -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 +/// /// candidate-id = "candidate" ":" foundation /// foundation = 1*32ice-char /// ice-char = ALPHA / DIGIT / "+" / "/" diff --git a/ice/src/udp_mux/mod.rs b/ice/src/udp_mux/mod.rs index b2ef39cdd..59560ca43 100644 --- a/ice/src/udp_mux/mod.rs +++ b/ice/src/udp_mux/mod.rs @@ -153,7 +153,7 @@ impl UDPMuxDefault { .split(':') .next() .and_then(|ufrag| conns.get(ufrag)) - .map(Clone::clone); + .cloned(); conn } @@ -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 { diff --git a/ice/src/udp_network.rs b/ice/src/udp_network.rs index fecb8aa5e..e2077bdf7 100644 --- a/ice/src/udp_network.rs +++ b/ice/src/udp_network.rs @@ -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** /// diff --git a/interceptor/src/stream_info.rs b/interceptor/src/stream_info.rs index 139cdbc38..5e9f93d5e 100644 --- a/interceptor/src/stream_info.rs +++ b/interceptor/src/stream_info.rs @@ -23,11 +23,11 @@ pub struct StreamInfo { } /// RTCPFeedback signals the connection to use additional RTCP packet types. -/// 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: /// valid: ack, ccm, nack, goog-remb, transport-cc pub typ: String, diff --git a/interceptor/src/twcc/mod.rs b/interceptor/src/twcc/mod.rs index 463200079..856530385 100644 --- a/interceptor/src/twcc/mod.rs +++ b/interceptor/src/twcc/mod.rs @@ -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 +/// #[derive(Default, Debug, PartialEq, Clone)] pub struct Recorder { received_packets: Vec, diff --git a/interceptor/src/twcc/receiver/mod.rs b/interceptor/src/twcc/receiver/mod.rs index 7caf4a140..aaaf81369 100644 --- a/interceptor/src/twcc/receiver/mod.rs +++ b/interceptor/src/twcc/receiver/mod.rs @@ -68,8 +68,8 @@ struct ReceiverInternal { close_rx: Mutex>>, } -/// 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: +/// pub struct Receiver { internal: Arc, diff --git a/interceptor/src/twcc/twcc_test.rs b/interceptor/src/twcc/twcc_test.rs index 93652c607..2bef1ffda 100644 --- a/interceptor/src/twcc/twcc_test.rs +++ b/interceptor/src/twcc/twcc_test.rs @@ -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, @@ -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, diff --git a/media/src/io/h264_writer/mod.rs b/media/src/io/h264_writer/mod.rs index 94dfd3ec7..a79db29a6 100644 --- a/media/src/io/h264_writer/mod.rs +++ b/media/src/io/h264_writer/mod.rs @@ -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 +/// pub struct H264Writer { writer: W, has_key_frame: bool, diff --git a/media/src/io/ivf_reader/mod.rs b/media/src/io/ivf_reader/mod.rs index 5c6c1391c..62f314917 100644 --- a/media/src/io/ivf_reader/mod.rs +++ b/media/src/io/ivf_reader/mod.rs @@ -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 +/// #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] pub struct IVFFileHeader { pub signature: [u8; 4], // 0-3 @@ -30,7 +30,7 @@ pub struct IVFFileHeader { } /// IVFFrameHeader 12-byte header for IVF frames -/// https://wiki.multimedia.cx/index.php/IVF +/// #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] pub struct IVFFrameHeader { pub frame_size: u32, // 0-3 diff --git a/media/src/io/ogg_reader/mod.rs b/media/src/io/ogg_reader/mod.rs index 16f2369be..4a1051622 100644 --- a/media/src/io/ogg_reader/mod.rs +++ b/media/src/io/ogg_reader/mod.rs @@ -29,7 +29,7 @@ pub struct OggReader { /// OggHeader is the metadata from the first two pages /// in the file (ID and Comment) -/// https://tools.ietf.org/html/rfc7845.html#section-3 +/// pub struct OggHeader { pub channel_map: u8, pub channels: u8, @@ -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 +/// pub struct OggPageHeader { pub granule_position: u64, diff --git a/media/src/io/sample_builder/sample_builder_test.rs b/media/src/io/sample_builder/sample_builder_test.rs index 005bc2cd8..097a82d6d 100644 --- a/media/src/io/sample_builder/sample_builder_test.rs +++ b/media/src/io/sample_builder/sample_builder_test.rs @@ -1449,7 +1449,7 @@ 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, @@ -1457,13 +1457,13 @@ fn test_sample_builder_push_max_zero() { ..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.") } diff --git a/rtp/src/codecs/av1/mod.rs b/rtp/src/codecs/av1/mod.rs index f5cae92ac..42358c3b0 100644 --- a/rtp/src/codecs/av1/mod.rs +++ b/rtp/src/codecs/av1/mod.rs @@ -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 + /// Reference: fn payload(&mut self, mtu: usize, payload: &Bytes) -> crate::error::Result> { // 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 diff --git a/rtp/src/codecs/h265/mod.rs b/rtp/src/codecs/h265/mod.rs index a06c8b512..d4aa8d282 100644 --- a/rtp/src/codecs/h265/mod.rs +++ b/rtp/src/codecs/h265/mod.rs @@ -11,15 +11,15 @@ mod h265_test; /// const H265NALU_HEADER_SIZE: usize = 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 +/// const H265NALU_FRAGMENTATION_UNIT_TYPE: u8 = 49; -/// 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 +/// /// +---------------+---------------+ /// |0|1|2|3|4|5|6|7|0|1|2|3|4|5|6|7| /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -97,7 +97,7 @@ impl H265NALUHeader { /// | :...OPTIONAL RTP padding | /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// -/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.1 +/// Reference: #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct H265SingleNALUnitPacket { /// payload_header is the header of the H265 packet. @@ -186,7 +186,7 @@ impl H265SingleNALUnitPacket { /// | : /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// -/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2 +/// Reference: #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct H265AggregationUnitFirst { donl: Option, @@ -226,7 +226,7 @@ impl H265AggregationUnitFirst { /// | : /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// -/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2 +/// Reference: #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct H265AggregationUnit { dond: Option, @@ -266,7 +266,7 @@ impl H265AggregationUnit { /// | :...OPTIONAL RTP padding | /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// -/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.2 +/// Reference: #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct H265AggregationPacket { first_unit: Option, @@ -427,7 +427,7 @@ impl H265FragmentationUnitHeader { /// | :...OPTIONAL RTP padding | /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// -/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3 +/// Reference: #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct H265FragmentationUnitPacket { /// payload_header is the header of the H265 packet. @@ -526,7 +526,7 @@ impl H265FragmentationUnitPacket { /// | :...OPTIONAL RTP padding | /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// -/// Reference: https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.4 +/// Reference: #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct H265PACIPacket { /// payload_header is the header of the H265 packet. @@ -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: #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] pub struct H265TSCI(pub u32); diff --git a/sdp/src/description/media.rs b/sdp/src/description/media.rs index 12c370549..d6c973cc2 100644 --- a/sdp/src/description/media.rs +++ b/sdp/src/description/media.rs @@ -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: / where number of ports is a an +/// to write it as: `/` where number of ports is a an /// offsetting range. #[derive(Debug, Default, Clone)] pub struct RangedPort { @@ -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("/"), diff --git a/sdp/src/direction/direction_test.rs b/sdp/src/direction/direction_test.rs index 6e25d4535..ff543f754 100644 --- a/sdp/src/direction/direction_test.rs +++ b/sdp/src/direction/direction_test.rs @@ -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), @@ -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"), diff --git a/srtp/src/config.rs b/srtp/src/config.rs index d2f771e18..8fbab5f22 100644 --- a/srtp/src/config.rs +++ b/srtp/src/config.rs @@ -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 + /// pub async fn extract_session_keys_from_dtls( &mut self, exporter: impl KeyingMaterialExporter, diff --git a/turn/src/allocation/allocation_manager.rs b/turn/src/allocation/allocation_manager.rs index 47951292c..f3c443689 100644 --- a/turn/src/allocation/allocation_manager.rs +++ b/turn/src/allocation/allocation_manager.rs @@ -76,7 +76,7 @@ impl Manager { /// Fetches the [`Allocation`] matching the passed [`FiveTuple`]. pub async fn get_allocation(&self, five_tuple: &FiveTuple) -> Option> { 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. diff --git a/util/src/ifaces/ffi/windows/mod.rs b/util/src/ifaces/ffi/windows/mod.rs index b0fdac0f5..415a73e98 100644 --- a/util/src/ifaces/ffi/windows/mod.rs +++ b/util/src/ifaces/ffi/windows/mod.rs @@ -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 { diff --git a/util/src/vnet/nat.rs b/util/src/vnet/nat.rs index 24e682c0c..c65d73fc5 100644 --- a/util/src/vnet/nat.rs +++ b/util/src/vnet/nat.rs @@ -400,7 +400,7 @@ impl NetworkAddressTranslator { } let outbound_map = self.outbound_map.lock().await; - outbound_map.get(o_key).map(Arc::clone) + outbound_map.get(o_key).cloned() } // caller must hold the mutex @@ -439,7 +439,7 @@ impl NetworkAddressTranslator { } let inbound_map = self.inbound_map.lock().await; - inbound_map.get(i_key).map(Arc::clone) + inbound_map.get(i_key).cloned() } // caller must hold the mutex diff --git a/webrtc/src/api/media_engine/mod.rs b/webrtc/src/api/media_engine/mod.rs index 8cae27c5f..529e6d876 100644 --- a/webrtc/src/api/media_engine/mod.rs +++ b/webrtc/src/api/media_engine/mod.rs @@ -349,7 +349,7 @@ impl MediaEngine { } /// Adds a header extension to the MediaEngine - /// To determine the negotiated value use [`get_header_extension_id`] after signaling is complete. + /// To determine the negotiated value use [`MediaEngine::get_header_extension_id`] after signaling is complete. /// /// The `allowed_direction` controls for which transceiver directions the extension matches. If /// set to `None` it matches all directions. The `SendRecv` direction would match all transceiver @@ -417,7 +417,7 @@ impl MediaEngine { /// get_header_extension_id returns the negotiated ID for a header extension. /// If the Header Extension isn't enabled ok will be false - pub(crate) async fn get_header_extension_id( + pub async fn get_header_extension_id( &self, extension: RTCRtpHeaderExtensionCapability, ) -> (isize, bool, bool) { diff --git a/webrtc/src/error.rs b/webrtc/src/error.rs index c1abe0afa..89a8ffac9 100644 --- a/webrtc/src/error.rs +++ b/webrtc/src/error.rs @@ -10,6 +10,8 @@ use tokio::sync::mpsc::error::SendError as MpscSendError; use crate::peer_connection::sdp::sdp_type::RTCSdpType; use crate::peer_connection::signaling_state::RTCSignalingState; use crate::rtp_transceiver::rtp_receiver; +#[cfg(doc)] +use crate::rtp_transceiver::rtp_sender; pub type Result = std::result::Result; @@ -128,13 +130,13 @@ pub enum Error { #[error("protocol is larger then 65535 bytes")] ErrProtocolTooLarge, - /// ErrSenderNotCreatedByConnection indicates remove_track was called with a RtpSender not created - /// by this PeerConnection + /// ErrSenderNotCreatedByConnection indicates remove_track was called with a + /// [`rtp_sender::RTCRtpSender`] not created by this PeerConnection #[error("RtpSender not created by this PeerConnection")] ErrSenderNotCreatedByConnection, /// ErrSenderInitialTrackIdAlreadySet indicates a second call to - /// [`RtpSender::set_initial_track_id`] which is not allowed. + /// `RTCRtpSender::set_initial_track_id` which is not allowed. Purely internal error, should not happen in practice. #[error("RtpSender's initial_track_id has already been set")] ErrSenderInitialTrackIdAlreadySet, diff --git a/webrtc/src/ice_transport/ice_candidate.rs b/webrtc/src/ice_transport/ice_candidate.rs index d9cb74b1a..9eab74dae 100644 --- a/webrtc/src/ice_transport/ice_candidate.rs +++ b/webrtc/src/ice_transport/ice_candidate.rs @@ -65,36 +65,29 @@ impl From<&Arc> for RTCIceCandidate { impl RTCIceCandidate { pub(crate) fn to_ice(&self) -> Result { let candidate_id = self.stats_id.clone(); + let base_config = CandidateBaseConfig { + candidate_id, + network: self.protocol.to_string(), + address: self.address.clone(), + port: self.port, + component: self.component, + //tcp_type: ice.NewTCPType(c.TCPType), + foundation: self.foundation.clone(), + priority: self.priority, + ..Default::default() + }; + let c = match self.typ { RTCIceCandidateType::Host => { let config = CandidateHostConfig { - base_config: CandidateBaseConfig { - candidate_id, - network: self.protocol.to_string(), - address: self.address.clone(), - port: self.port, - component: self.component, - //tcp_type: ice.NewTCPType(c.TCPType), - foundation: self.foundation.clone(), - priority: self.priority, - ..Default::default() - }, + base_config, ..Default::default() }; config.new_candidate_host()? } RTCIceCandidateType::Srflx => { let config = CandidateServerReflexiveConfig { - base_config: CandidateBaseConfig { - candidate_id, - network: self.protocol.to_string(), - address: self.address.clone(), - port: self.port, - component: self.component, - foundation: self.foundation.clone(), - priority: self.priority, - ..Default::default() - }, + base_config, rel_addr: self.related_address.clone(), rel_port: self.related_port, }; @@ -102,16 +95,7 @@ impl RTCIceCandidate { } RTCIceCandidateType::Prflx => { let config = CandidatePeerReflexiveConfig { - base_config: CandidateBaseConfig { - candidate_id, - network: self.protocol.to_string(), - address: self.address.clone(), - port: self.port, - component: self.component, - foundation: self.foundation.clone(), - priority: self.priority, - ..Default::default() - }, + base_config, rel_addr: self.related_address.clone(), rel_port: self.related_port, }; @@ -119,16 +103,7 @@ impl RTCIceCandidate { } RTCIceCandidateType::Relay => { let config = CandidateRelayConfig { - base_config: CandidateBaseConfig { - candidate_id, - network: self.protocol.to_string(), - address: self.address.clone(), - port: self.port, - component: self.component, - foundation: self.foundation.clone(), - priority: self.priority, - ..Default::default() - }, + base_config, rel_addr: self.related_address.clone(), rel_port: self.related_port, relay_client: None, //TODO? diff --git a/webrtc/src/lib.rs b/webrtc/src/lib.rs index c414d0f3d..f1c1bd110 100644 --- a/webrtc/src/lib.rs +++ b/webrtc/src/lib.rs @@ -1,19 +1,32 @@ #![warn(rust_2018_idioms)] #![allow(dead_code)] -// re-export sub-crates pub use {data, dtls, ice, interceptor, mdns, media, rtcp, rtp, sctp, sdp, srtp, stun, turn, util}; -pub mod api; +/// [`peer_connection::RTCPeerConnection`] allows to establish connection between two peers given RTC configuration. Its API is similar to one in JavaScript. +pub mod peer_connection; + +/// The utilities defining transport between peers. Contains [`ice_transport::ice_server::RTCIceServer`] struct which describes how peer does ICE (Interactive Connectivity Establishment). +pub mod ice_transport; + +/// WebRTC DataChannel can be used for peer-to-peer transmitting arbitrary binary data. pub mod data_channel; -pub mod dtls_transport; + +/// Module responsible for multiplexing data streams of different protocols on one socket. Custom [`mux::endpoint::Endpoint`] with [`mux::mux_func::MatchFunc`] can be used for parsing your application-specific byte stream. +pub mod mux; // TODO: why is this public? does someone really extend WebRTC stack? + +/// Measuring connection statistics, such as amount of data transmitted or round trip time. +pub mod stats; + +/// [`Error`] enumerates WebRTC problems, [`error::OnErrorHdlrFn`] defines type for callback-logger. pub mod error; -pub mod ice_transport; -pub mod mux; -pub mod peer_connection; + +/// Set of constructors for WebRTC primitives. Subject to deprecation in future. +pub mod api; + +pub mod dtls_transport; pub mod rtp_transceiver; pub mod sctp_transport; -pub mod stats; pub mod track; pub use error::Error; diff --git a/webrtc/src/mux/mux_func.rs b/webrtc/src/mux/mux_func.rs index ae81907e4..dfc30eefc 100644 --- a/webrtc/src/mux/mux_func.rs +++ b/webrtc/src/mux/mux_func.rs @@ -31,13 +31,13 @@ pub fn match_range(lower: u8, upper: u8) -> MatchFunc { /// | [128..191] -+--> forward to RTP/RTCP /// +----------------+ /// match_dtls is a MatchFunc that accepts packets with the first byte in [20..63] -/// as defied in RFC7983 +/// as defined in RFC7983 pub fn match_dtls(b: &[u8]) -> bool { match_range(20, 63)(b) } // match_srtp_or_srtcp is a MatchFunc that accepts packets with the first byte in [128..191] -// as defied in RFC7983 +// as defined in RFC7983 pub fn match_srtp_or_srtcp(b: &[u8]) -> bool { match_range(128, 191)(b) } diff --git a/webrtc/src/peer_connection/certificate.rs b/webrtc/src/peer_connection/certificate.rs index 6efa90528..ac8bfe5de 100644 --- a/webrtc/src/peer_connection/certificate.rs +++ b/webrtc/src/peer_connection/certificate.rs @@ -151,7 +151,7 @@ impl RTCCertificate { /// new one for each DTLS connection). /// /// NOTE: ID used for statistics will be different as it's neither derived from the given - /// certificate nor persisted along it when using [`serialize_pem`]. + /// certificate nor persisted along it when using [`RTCCertificate::serialize_pem`]. pub fn from_existing(dtls_certificate: dtls::crypto::Certificate, expires: SystemTime) -> Self { Self { dtls_certificate, @@ -162,7 +162,7 @@ impl RTCCertificate { } /// Serializes the certificate (including the private key) in PKCS#8 format in PEM. - #[cfg(feature = "pem")] + #[cfg(any(doc, feature = "pem"))] pub fn serialize_pem(&self) -> String { // Encode `expires` as a PEM block. // diff --git a/webrtc/src/peer_connection/mod.rs b/webrtc/src/peer_connection/mod.rs index b4989cef4..3ce7af37f 100644 --- a/webrtc/src/peer_connection/mod.rs +++ b/webrtc/src/peer_connection/mod.rs @@ -1,14 +1,18 @@ #[cfg(test)] pub(crate) mod peer_connection_test; +/// Custom media-related options, such as `voice_activity_detection`, which are negotiated while establishing connection. +pub mod offer_answer_options; + +/// [`RTCSessionDescription`] - wrapper for SDP text and negotiations stage ([`RTCSdpType`]: offer - pranswer - answer - rollback). +pub mod sdp; + pub mod certificate; pub mod configuration; -pub mod offer_answer_options; pub(crate) mod operation; mod peer_connection_internal; pub mod peer_connection_state; pub mod policy; -pub mod sdp; pub mod signaling_state; use std::future::Future; diff --git a/webrtc/src/peer_connection/sdp/sdp_test.rs b/webrtc/src/peer_connection/sdp/sdp_test.rs index 753007f61..3b26f927a 100644 --- a/webrtc/src/peer_connection/sdp/sdp_test.rs +++ b/webrtc/src/peer_connection/sdp/sdp_test.rs @@ -51,11 +51,10 @@ fn test_extract_fingerprint() -> Result<()> { { let s = SessionDescription::default(); - if let Err(err) = extract_fingerprint(&s) { - assert_eq!(err, Error::ErrSessionDescriptionNoFingerprint); - } else { - panic!(); - } + assert_eq!( + extract_fingerprint(&s).expect_err("fingerprint absence must be detected"), + Error::ErrSessionDescriptionNoFingerprint + ); } //"Invalid Fingerprint" @@ -68,11 +67,10 @@ fn test_extract_fingerprint() -> Result<()> { ..Default::default() }; - if let Err(err) = extract_fingerprint(&s) { - assert_eq!(err, Error::ErrSessionDescriptionInvalidFingerprint); - } else { - panic!(); - } + assert_eq!( + extract_fingerprint(&s).expect_err("invalid fingerprint text must be detected"), + Error::ErrSessionDescriptionInvalidFingerprint + ); } //"Conflicting Fingerprint" @@ -92,11 +90,10 @@ fn test_extract_fingerprint() -> Result<()> { ..Default::default() }; - if let Err(err) = extract_fingerprint(&s) { - assert_eq!(err, Error::ErrSessionDescriptionConflictingFingerprints); - } else { - panic!(); - } + assert_eq!( + extract_fingerprint(&s).expect_err("mismatching fingerprint texts must be detected"), + Error::ErrSessionDescriptionConflictingFingerprints + ); } Ok(()) @@ -120,11 +117,12 @@ async fn test_extract_ice_details() -> Result<()> { ..Default::default() }; - if let Err(err) = extract_ice_details(&s).await { - assert_eq!(err, Error::ErrSessionDescriptionMissingIcePwd); - } else { - panic!(); - } + assert_eq!( + extract_ice_details(&s) + .await + .expect_err("ICE requires password for authentication"), + Error::ErrSessionDescriptionMissingIcePwd + ); } //"Missing ice-ufrag" @@ -140,11 +138,12 @@ async fn test_extract_ice_details() -> Result<()> { ..Default::default() }; - if let Err(err) = extract_ice_details(&s).await { - assert_eq!(err, Error::ErrSessionDescriptionMissingIceUfrag); - } else { - panic!(); - } + assert_eq!( + extract_ice_details(&s) + .await + .expect_err("ICE requires 'user fragment' for authentication"), + Error::ErrSessionDescriptionMissingIceUfrag + ); } //"ice details at session level" @@ -216,11 +215,12 @@ async fn test_extract_ice_details() -> Result<()> { ..Default::default() }; - if let Err(err) = extract_ice_details(&s).await { - assert_eq!(err, Error::ErrSessionDescriptionConflictingIceUfrag); - } else { - panic!(); - } + assert_eq!( + extract_ice_details(&s) + .await + .expect_err("mismatching ICE ufrags must be detected"), + Error::ErrSessionDescriptionConflictingIceUfrag + ); } //"Conflict pwd" @@ -246,11 +246,12 @@ async fn test_extract_ice_details() -> Result<()> { ..Default::default() }; - if let Err(err) = extract_ice_details(&s).await { - assert_eq!(err, Error::ErrSessionDescriptionConflictingIcePwd); - } else { - panic!(); - } + assert_eq!( + extract_ice_details(&s) + .await + .expect_err("mismatching ICE passwords must be detected"), + Error::ErrSessionDescriptionConflictingIcePwd + ); } Ok(()) diff --git a/webrtc/src/rtp_transceiver/mod.rs b/webrtc/src/rtp_transceiver/mod.rs index 1edb5fc99..19bcdf52e 100644 --- a/webrtc/src/rtp_transceiver/mod.rs +++ b/webrtc/src/rtp_transceiver/mod.rs @@ -301,7 +301,7 @@ impl RTCRtpTransceiver { /// mid gets the Transceiver's mid value. When not already set, this value will be set in CreateOffer or create_answer. pub fn mid(&self) -> Option { - self.mid.get().map(Clone::clone) + self.mid.get().cloned() } /// kind returns RTPTransceiver's kind. diff --git a/webrtc/src/rtp_transceiver/rtp_receiver/mod.rs b/webrtc/src/rtp_transceiver/rtp_receiver/mod.rs index 6d1983923..8a2f40f24 100644 --- a/webrtc/src/rtp_transceiver/rtp_receiver/mod.rs +++ b/webrtc/src/rtp_transceiver/rtp_receiver/mod.rs @@ -493,6 +493,8 @@ impl RTCRtpReceiver { if tracks.len() != 1 { None } else { + // Clippy bug (reported at https://github.com/rust-lang/rust-clippy/issues/12560) suggests .first().cloned() + #[allow(clippy::map_clone)] tracks.first().map(|t| Arc::clone(&t.track)) } } diff --git a/webrtc/src/stats/serialize.rs b/webrtc/src/stats/serialize.rs index 2db43c4b0..8d324a622 100644 --- a/webrtc/src/stats/serialize.rs +++ b/webrtc/src/stats/serialize.rs @@ -1,10 +1,10 @@ +/// Serializes a `tokio::time::Instant` to an approximation of epoch time in the form +/// of an `f64` where the integer portion is seconds and the decimal portion is milliseconds. +/// For instance, `Monday, May 30, 2022 10:45:26.456 PM UTC` converts to `1653950726.456`. +/// +/// Note that an `Instant` is not connected to real world time, so this conversion is +/// approximate. pub mod instant_to_epoch_seconds { - // Serializes a `tokio::time::Instant` to an approximation of epoch time in the form - // of an `f64` where the integer portion is seconds and the decimal portion is milliseconds. - // For instance, `Monday, May 30, 2022 10:45:26.456 PM UTC` converts to `1653950726.456`. - // - // Note that an `Instant` is not connected to real world time, so this conversion is - // approximate. use std::time::{SystemTime, UNIX_EPOCH}; use serde::{Serialize, Serializer}; diff --git a/webrtc/src/track/track_remote/mod.rs b/webrtc/src/track/track_remote/mod.rs index b5cd4f58d..823834598 100644 --- a/webrtc/src/track/track_remote/mod.rs +++ b/webrtc/src/track/track_remote/mod.rs @@ -212,7 +212,7 @@ impl TrackRemote { /// Reads data from the track. /// /// **Cancel Safety:** This method is not cancel safe. Dropping the resulting [`Future`] before - /// it returns [`Poll::Ready`] will cause data loss. + /// it returns [`std::task::Poll::Ready`] will cause data loss. pub async fn read(&self, b: &mut [u8]) -> Result<(rtp::packet::Packet, Attributes)> { { // Internal lock scope