From 835f9472a13c7c53dcdc1da3ef1e647814f5c58b Mon Sep 17 00:00:00 2001 From: yngrtc Date: Mon, 18 Mar 2024 14:08:31 -0700 Subject: [PATCH] refactor api --- rtc-sdp/Cargo.toml | 4 +- rtc-sdp/src/description/description_test.rs | 2 +- rtc-sdp/src/description/session.rs | 2 +- rtc-sdp/src/error.rs | 56 -------- rtc-sdp/src/extmap/mod.rs | 2 +- rtc-sdp/src/lexer/mod.rs | 2 +- rtc-sdp/src/lib.rs | 2 - rtc-sdp/src/util/mod.rs | 2 +- rtc-shared/Cargo.toml | 1 + rtc-shared/src/error.rs | 21 +++ rtc/src/api/media_engine/mod.rs | 133 ++++++++---------- rtc/src/api/mod.rs | 60 ++++---- rtc/src/api/setting_engine/mod.rs | 47 +++---- rtc/src/dtls_transport/dtls_role.rs | 2 +- rtc/src/dtls_transport/mod.rs | 6 +- rtc/src/ice_transport/mod.rs | 25 ++-- rtc/src/lib.rs | 8 +- rtc/src/peer_connection/mod.rs | 6 +- rtc/src/peer_connection/sdp/mod.rs | 32 +++-- .../sdp/session_description.rs | 2 +- rtc/src/rtp_transceiver/mod.rs | 26 ++-- rtc/src/rtp_transceiver/rtp_codec.rs | 4 +- 22 files changed, 198 insertions(+), 247 deletions(-) delete mode 100644 rtc-sdp/src/error.rs diff --git a/rtc-sdp/Cargo.toml b/rtc-sdp/Cargo.toml index 328b76c..05ee49c 100644 --- a/rtc-sdp/Cargo.toml +++ b/rtc-sdp/Cargo.toml @@ -10,10 +10,10 @@ homepage = "https://webrtc.rs" repository = "https://github.com/webrtc-rs/rtc" [dependencies] +shared = { version = "0.2.1", path = "../rtc-shared", package = "rtc-shared", default-features = false, features = [] } + url = "2.5.0" rand = "0.8.5" -thiserror = "1.0.57" -substring = "1.4.5" [dev-dependencies] criterion = "0.5.1" diff --git a/rtc-sdp/src/description/description_test.rs b/rtc-sdp/src/description/description_test.rs index 3c16eed..b891d58 100644 --- a/rtc-sdp/src/description/description_test.rs +++ b/rtc-sdp/src/description/description_test.rs @@ -1,7 +1,7 @@ use super::common::*; use super::media::*; use super::session::*; -use crate::error::{Error, Result}; +use shared::error::{Error, Result}; use std::io::Cursor; use url::Url; diff --git a/rtc-sdp/src/description/session.rs b/rtc-sdp/src/description/session.rs index c20a20c..c017ba4 100644 --- a/rtc-sdp/src/description/session.rs +++ b/rtc-sdp/src/description/session.rs @@ -4,9 +4,9 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::{fmt, io}; use url::Url; -use crate::error::{Error, Result}; use crate::lexer::*; use crate::util::*; +use shared::error::{Error, Result}; use super::common::*; use super::media::*; diff --git a/rtc-sdp/src/error.rs b/rtc-sdp/src/error.rs deleted file mode 100644 index f64a335..0000000 --- a/rtc-sdp/src/error.rs +++ /dev/null @@ -1,56 +0,0 @@ -use thiserror::Error; - -use std::io; -use std::num::ParseIntError; -use std::string::FromUtf8Error; -use substring::Substring; - -pub type Result = std::result::Result; - -#[derive(Debug, Error, PartialEq)] -#[non_exhaustive] -pub enum Error { - #[error("codec not found")] - CodecNotFound, - #[error("missing whitespace")] - MissingWhitespace, - #[error("missing colon")] - MissingColon, - #[error("payload type not found")] - PayloadTypeNotFound, - #[error("{0}")] - Io(#[source] IoError), - #[error("utf-8 error: {0}")] - Utf8(#[from] FromUtf8Error), - #[error("SdpInvalidSyntax: {0}")] - SdpInvalidSyntax(String), - #[error("SdpInvalidValue: {0}")] - SdpInvalidValue(String), - #[error("sdp: empty time_descriptions")] - SdpEmptyTimeDescription, - #[error("parse int: {0}")] - ParseInt(#[from] ParseIntError), - #[error("parse url: {0}")] - ParseUrl(#[from] url::ParseError), - #[error("parse extmap: {0}")] - ParseExtMap(String), - #[error("{} --> {} <-- {}", .s.substring(0,*.p), .s.substring(*.p, *.p+1), .s.substring(*.p+1, .s.len()))] - SyntaxError { s: String, p: usize }, -} - -#[derive(Debug, Error)] -#[error("io error: {0}")] -pub struct IoError(#[from] pub io::Error); - -// Workaround for wanting PartialEq for io::Error. -impl PartialEq for IoError { - fn eq(&self, other: &Self) -> bool { - self.0.kind() == other.0.kind() - } -} - -impl From for Error { - fn from(e: io::Error) -> Self { - Error::Io(IoError(e)) - } -} diff --git a/rtc-sdp/src/extmap/mod.rs b/rtc-sdp/src/extmap/mod.rs index f5639f9..b7542b4 100644 --- a/rtc-sdp/src/extmap/mod.rs +++ b/rtc-sdp/src/extmap/mod.rs @@ -2,8 +2,8 @@ mod extmap_test; use super::direction::*; -use super::error::{Error, Result}; use crate::description::common::*; +use shared::error::{Error, Result}; use std::fmt; use std::io; diff --git a/rtc-sdp/src/lexer/mod.rs b/rtc-sdp/src/lexer/mod.rs index 6a5a153..ba34459 100644 --- a/rtc-sdp/src/lexer/mod.rs +++ b/rtc-sdp/src/lexer/mod.rs @@ -1,5 +1,5 @@ use super::description::session::SessionDescription; -use super::error::{Error, Result}; +use shared::error::{Error, Result}; use std::io; use std::io::SeekFrom; diff --git a/rtc-sdp/src/lib.rs b/rtc-sdp/src/lib.rs index a8bea84..90581d3 100644 --- a/rtc-sdp/src/lib.rs +++ b/rtc-sdp/src/lib.rs @@ -6,8 +6,6 @@ pub mod direction; pub mod extmap; pub mod util; -mod error; pub(crate) mod lexer; pub use description::{media::MediaDescription, session::SessionDescription}; -pub use error::Error; diff --git a/rtc-sdp/src/util/mod.rs b/rtc-sdp/src/util/mod.rs index bf3f162..84f6ae4 100644 --- a/rtc-sdp/src/util/mod.rs +++ b/rtc-sdp/src/util/mod.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod util_test; -use super::error::{Error, Result}; +use shared::error::{Error, Result}; use std::collections::HashMap; use std::fmt; diff --git a/rtc-shared/Cargo.toml b/rtc-shared/Cargo.toml index 5abe833..b752da9 100644 --- a/rtc-shared/Cargo.toml +++ b/rtc-shared/Cargo.toml @@ -17,6 +17,7 @@ replay = [] [dependencies] thiserror = "1.0.58" +substring = "1.4.5" bytes = "1.5.0" aes-gcm = { version = "0.10.3", features = ["std"] } url = "2.5.0" diff --git a/rtc-shared/src/error.rs b/rtc-shared/src/error.rs index 9bb5cce..fa2fe73 100644 --- a/rtc-shared/src/error.rs +++ b/rtc-shared/src/error.rs @@ -6,6 +6,7 @@ use std::net::SocketAddr; use std::num::ParseIntError; use std::string::FromUtf8Error; use std::time::SystemTimeError; +use substring::Substring; use thiserror::Error; pub type Result = std::result::Result; @@ -1455,6 +1456,26 @@ pub enum Error { #[error("not long enough to be a RTP Packet")] ErrRTPTooShort, + //SDP + #[error("codec not found")] + CodecNotFound, + #[error("missing whitespace")] + MissingWhitespace, + #[error("missing colon")] + MissingColon, + #[error("payload type not found")] + PayloadTypeNotFound, + #[error("SdpInvalidSyntax: {0}")] + SdpInvalidSyntax(String), + #[error("SdpInvalidValue: {0}")] + SdpInvalidValue(String), + #[error("sdp: empty time_descriptions")] + SdpEmptyTimeDescription, + #[error("parse extmap: {0}")] + ParseExtMap(String), + #[error("{} --> {} <-- {}", .s.substring(0,*.p), .s.substring(*.p, *.p+1), .s.substring(*.p+1, .s.len()))] + SyntaxError { s: String, p: usize }, + //Third Party Error #[error("{0}")] Sec1(#[source] sec1::Error), diff --git a/rtc/src/api/media_engine/mod.rs b/rtc/src/api/media_engine/mod.rs index 8cae27c..8b19b62 100644 --- a/rtc/src/api/media_engine/mod.rs +++ b/rtc/src/api/media_engine/mod.rs @@ -1,15 +1,12 @@ -#[cfg(test)] -mod media_engine_test; +//TODO:#[cfg(test)] +//TODO:mod media_engine_test; use std::collections::HashMap; use std::ops::Range; -use std::sync::atomic::{AtomicBool, Ordering}; use std::time::{SystemTime, UNIX_EPOCH}; use sdp::description::session::SessionDescription; -use util::sync::Mutex as SyncMutex; -use crate::error::{Error, Result}; use crate::peer_connection::sdp::{ codecs_from_media_description, rtp_extensions_from_media_description, }; @@ -20,9 +17,10 @@ use crate::rtp_transceiver::rtp_codec::{ }; use crate::rtp_transceiver::rtp_transceiver_direction::RTCRtpTransceiverDirection; use crate::rtp_transceiver::{fmtp, PayloadType, RTCPFeedback}; -use crate::stats::stats_collector::StatsCollector; +/*TOD:use crate::stats::stats_collector::StatsCollector; use crate::stats::CodecStats; -use crate::stats::StatsReportType::Codec; +use crate::stats::StatsReportType::Codec;*/ +use shared::error::{Error, Result}; /// MIME_TYPE_H264 H264 MIME type. /// Note: Matching should be case insensitive. @@ -82,17 +80,17 @@ impl MediaEngineHeaderExtension { #[derive(Default)] pub struct MediaEngine { // If we have attempted to negotiate a codec type yet. - pub(crate) negotiated_video: AtomicBool, - pub(crate) negotiated_audio: AtomicBool, + pub(crate) negotiated_video: bool, + pub(crate) negotiated_audio: bool, pub(crate) video_codecs: Vec, pub(crate) audio_codecs: Vec, - pub(crate) negotiated_video_codecs: SyncMutex>, - pub(crate) negotiated_audio_codecs: SyncMutex>, + pub(crate) negotiated_video_codecs: Vec, + pub(crate) negotiated_audio_codecs: Vec, header_extensions: Vec, - proposed_header_extensions: SyncMutex>, - pub(crate) negotiated_header_extensions: SyncMutex>, + proposed_header_extensions: HashMap, + pub(crate) negotiated_header_extensions: HashMap, } impl MediaEngine { @@ -417,16 +415,15 @@ 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(crate) fn get_header_extension_id( &self, extension: RTCRtpHeaderExtensionCapability, ) -> (isize, bool, bool) { - let negotiated_header_extensions = self.negotiated_header_extensions.lock(); - if negotiated_header_extensions.is_empty() { + if self.negotiated_header_extensions.is_empty() { return (0, false, false); } - for (id, h) in &*negotiated_header_extensions { + for (id, h) in &self.negotiated_header_extensions { if extension.uri == h.uri { return (*id, h.is_audio, h.is_video); } @@ -446,21 +443,19 @@ impl MediaEngine { } } - pub(crate) async fn get_codec_by_payload( + pub(crate) fn get_codec_by_payload( &self, payload_type: PayloadType, ) -> Result<(RTCRtpCodecParameters, RTPCodecType)> { { - let negotiated_video_codecs = self.negotiated_video_codecs.lock(); - for codec in &*negotiated_video_codecs { + for codec in &self.negotiated_video_codecs { if codec.payload_type == payload_type { return Ok((codec.clone(), RTPCodecType::Video)); } } } { - let negotiated_audio_codecs = self.negotiated_audio_codecs.lock(); - for codec in &*negotiated_audio_codecs { + for codec in &self.negotiated_audio_codecs { if codec.payload_type == payload_type { return Ok((codec.clone(), RTPCodecType::Audio)); } @@ -470,7 +465,8 @@ impl MediaEngine { Err(Error::ErrCodecNotFound) } - pub(crate) async fn collect_stats(&self, collector: &StatsCollector) { + /*TODO: + pub(crate) fn collect_stats(&self, collector: &StatsCollector) { let mut reports = HashMap::new(); for codec in &self.video_codecs { @@ -482,7 +478,7 @@ impl MediaEngine { } collector.merge(reports); - } + }*/ /// Look up a codec and enable if it exists pub(crate) fn match_remote_codec( @@ -539,21 +535,19 @@ impl MediaEngine { } /// Look up a header extension and enable if it exists - pub(crate) async fn update_header_extension( - &self, + pub(crate) fn update_header_extension( + &mut self, id: isize, extension: &str, typ: RTPCodecType, ) -> Result<()> { - let mut negotiated_header_extensions = self.negotiated_header_extensions.lock(); - let mut proposed_header_extensions = self.proposed_header_extensions.lock(); - for local_extension in &self.header_extensions { if local_extension.uri != extension { continue; } - let negotiated_ext = negotiated_header_extensions + let negotiated_ext = self + .negotiated_header_extensions .iter_mut() .find(|(_, ext)| ext.uri == extension); @@ -569,7 +563,7 @@ impl MediaEngine { // We either only have a proposal or we have neither proposal nor a negotiated id // Accept whatevers the peer suggests - if let Some(prev_ext) = negotiated_header_extensions.get(&id) { + if let Some(prev_ext) = self.negotiated_header_extensions.get(&id) { let prev_uri = &prev_ext.uri; log::warn!("Assigning {} to {} would override previous assignment to {}, no action taken", id, extension, prev_uri); } else { @@ -579,43 +573,38 @@ impl MediaEngine { is_video: local_extension.is_video && typ == RTPCodecType::Video, allowed_direction: local_extension.allowed_direction, }; - negotiated_header_extensions.insert(id, h); + self.negotiated_header_extensions.insert(id, h); } } // Clear any proposals we had for this id - proposed_header_extensions.remove(&id); + self.proposed_header_extensions.remove(&id); } Ok(()) } - pub(crate) async fn push_codecs(&self, codecs: Vec, typ: RTPCodecType) { + pub(crate) fn push_codecs(&mut self, codecs: Vec, typ: RTPCodecType) { for codec in codecs { if typ == RTPCodecType::Audio { - let mut negotiated_audio_codecs = self.negotiated_audio_codecs.lock(); - MediaEngine::add_codec(&mut negotiated_audio_codecs, codec); + MediaEngine::add_codec(&mut self.negotiated_audio_codecs, codec); } else if typ == RTPCodecType::Video { - let mut negotiated_video_codecs = self.negotiated_video_codecs.lock(); - MediaEngine::add_codec(&mut negotiated_video_codecs, codec); + MediaEngine::add_codec(&mut self.negotiated_video_codecs, codec); } } } /// Update the MediaEngine from a remote description - pub(crate) async fn update_from_remote_description( - &self, + pub(crate) fn update_from_remote_description( + &mut self, desc: &SessionDescription, ) -> Result<()> { for media in &desc.media_descriptions { - let typ = if !self.negotiated_audio.load(Ordering::SeqCst) - && media.media_name.media.to_lowercase() == "audio" + let typ = if !self.negotiated_audio && media.media_name.media.to_lowercase() == "audio" { - self.negotiated_audio.store(true, Ordering::SeqCst); + self.negotiated_audio = true; RTPCodecType::Audio - } else if !self.negotiated_video.load(Ordering::SeqCst) - && media.media_name.media.to_lowercase() == "video" - { - self.negotiated_video.store(true, Ordering::SeqCst); + } else if !self.negotiated_video && media.media_name.media.to_lowercase() == "video" { + self.negotiated_video = true; RTPCodecType::Video } else { continue; @@ -639,9 +628,9 @@ impl MediaEngine { // use exact matches when they exist, otherwise fall back to partial if !exact_matches.is_empty() { - self.push_codecs(exact_matches, typ).await; + self.push_codecs(exact_matches, typ); } else if !partial_matches.is_empty() { - self.push_codecs(partial_matches, typ).await; + self.push_codecs(partial_matches, typ); } else { // no match, not negotiated continue; @@ -650,7 +639,7 @@ impl MediaEngine { let extensions = rtp_extensions_from_media_description(media)?; for (extension, id) in extensions { - self.update_header_extension(id, &extension, typ).await?; + self.update_header_extension(id, &extension, typ)?; } } @@ -659,16 +648,14 @@ impl MediaEngine { pub(crate) fn get_codecs_by_kind(&self, typ: RTPCodecType) -> Vec { if typ == RTPCodecType::Video { - if self.negotiated_video.load(Ordering::SeqCst) { - let negotiated_video_codecs = self.negotiated_video_codecs.lock(); - negotiated_video_codecs.clone() + if self.negotiated_video { + self.negotiated_video_codecs.clone() } else { self.video_codecs.clone() } } else if typ == RTPCodecType::Audio { - if self.negotiated_audio.load(Ordering::SeqCst) { - let negotiated_audio_codecs = self.negotiated_audio_codecs.lock(); - negotiated_audio_codecs.clone() + if self.negotiated_audio { + self.negotiated_audio_codecs.clone() } else { self.audio_codecs.clone() } @@ -678,17 +665,16 @@ impl MediaEngine { } pub(crate) fn get_rtp_parameters_by_kind( - &self, + &mut self, typ: RTPCodecType, direction: RTCRtpTransceiverDirection, ) -> RTCRtpParameters { let mut header_extensions = vec![]; - if self.negotiated_video.load(Ordering::SeqCst) && typ == RTPCodecType::Video - || self.negotiated_audio.load(Ordering::SeqCst) && typ == RTPCodecType::Audio + if self.negotiated_video && typ == RTPCodecType::Video + || self.negotiated_audio && typ == RTPCodecType::Audio { - let negotiated_header_extensions = self.negotiated_header_extensions.lock(); - for (id, e) in &*negotiated_header_extensions { + for (id, e) in &self.negotiated_header_extensions { if e.is_matching_direction(direction) && (e.is_audio && typ == RTPCodecType::Audio || e.is_video && typ == RTPCodecType::Video) @@ -700,9 +686,6 @@ impl MediaEngine { } } } else { - let mut proposed_header_extensions = self.proposed_header_extensions.lock(); - let mut negotiated_header_extensions = self.negotiated_header_extensions.lock(); - for local_extension in &self.header_extensions { let relevant = local_extension.is_matching_direction(direction) && (local_extension.is_audio && typ == RTPCodecType::Audio @@ -712,7 +695,8 @@ impl MediaEngine { continue; } - if let Some((id, negotiated_extension)) = negotiated_header_extensions + if let Some((id, negotiated_extension)) = self + .negotiated_header_extensions .iter_mut() .find(|(_, e)| e.uri == local_extension.uri) { @@ -729,7 +713,8 @@ impl MediaEngine { continue; } - if let Some((id, negotiated_extension)) = proposed_header_extensions + if let Some((id, negotiated_extension)) = self + .proposed_header_extensions .iter_mut() .find(|(_, e)| e.uri == local_extension.uri) { @@ -744,12 +729,15 @@ impl MediaEngine { // Figure out which (unused id) to propose. let id = VALID_EXT_IDS.clone().find(|id| { - !negotiated_header_extensions.keys().any(|nid| nid == id) - && !proposed_header_extensions.keys().any(|pid| pid == id) + !self + .negotiated_header_extensions + .keys() + .any(|nid| nid == id) + && !self.proposed_header_extensions.keys().any(|pid| pid == id) }); if let Some(id) = id { - proposed_header_extensions.insert( + self.proposed_header_extensions.insert( id, MediaEngineHeaderExtension { uri: local_extension.uri.clone(), @@ -775,16 +763,15 @@ impl MediaEngine { } } - pub(crate) async fn get_rtp_parameters_by_payload_type( + pub(crate) fn get_rtp_parameters_by_payload_type( &self, payload_type: PayloadType, ) -> Result { - let (codec, typ) = self.get_codec_by_payload(payload_type).await?; + let (codec, typ) = self.get_codec_by_payload(payload_type)?; let mut header_extensions = vec![]; { - let negotiated_header_extensions = self.negotiated_header_extensions.lock(); - for (id, e) in &*negotiated_header_extensions { + for (id, e) in &self.negotiated_header_extensions { if e.is_audio && typ == RTPCodecType::Audio || e.is_video && typ == RTPCodecType::Video { diff --git a/rtc/src/api/mod.rs b/rtc/src/api/mod.rs index 2ab99c3..e59fdaa 100644 --- a/rtc/src/api/mod.rs +++ b/rtc/src/api/mod.rs @@ -1,23 +1,18 @@ -#[cfg(test)] -mod api_test; +//TODO: #[cfg(test)] +//TODO: mod api_test; -pub mod interceptor_registry; +//TODO: pub mod interceptor_registry; pub mod media_engine; pub mod setting_engine; -use std::sync::Arc; -use std::time::SystemTime; - -use interceptor::registry::Registry; -use interceptor::Interceptor; +/*TODO: use interceptor::registry::Registry; +use interceptor::Interceptor;*/ use media_engine::*; -use rcgen::KeyPair; use setting_engine::*; -use crate::data_channel::data_channel_parameters::DataChannelParameters; +/*TODO:use crate::data_channel::data_channel_parameters::DataChannelParameters; use crate::data_channel::RTCDataChannel; use crate::dtls_transport::RTCDtlsTransport; -use crate::error::{Error, Result}; use crate::ice_transport::ice_gatherer::{RTCIceGatherOptions, RTCIceGatherer}; use crate::ice_transport::RTCIceTransport; use crate::peer_connection::certificate::RTCCertificate; @@ -28,19 +23,22 @@ use crate::rtp_transceiver::rtp_receiver::RTCRtpReceiver; use crate::rtp_transceiver::rtp_sender::RTCRtpSender; use crate::sctp_transport::RTCSctpTransport; use crate::track::track_local::TrackLocal; +use rcgen::KeyPair; +use shared::error::{Error, Result}; + */ /// API bundles the global functions of the WebRTC and ORTC API. /// Some of these functions are also exported globally using the /// defaultAPI object. Note that the global version of the API /// may be phased out in the future. pub struct API { - pub(crate) setting_engine: Arc, - pub(crate) media_engine: Arc, - pub(crate) interceptor_registry: Registry, + pub(crate) setting_engine: SettingEngine, + pub(crate) media_engine: MediaEngine, + //TODO: pub(crate) interceptor_registry: Registry, } impl API { - /// new_peer_connection creates a new PeerConnection with the provided configuration against the received API object + /*TODO:/// new_peer_connection creates a new PeerConnection with the provided configuration against the received API object pub async fn new_peer_connection( &self, configuration: RTCConfiguration, @@ -166,24 +164,24 @@ impl API { false, ) .await - } + }*/ /// Returns the internal [`SettingEngine`]. - pub fn setting_engine(&self) -> Arc { - Arc::clone(&self.setting_engine) + pub fn setting_engine(&self) -> &SettingEngine { + &self.setting_engine } /// Returns the internal [`MediaEngine`]. - pub fn media_engine(&self) -> Arc { - Arc::clone(&self.media_engine) + pub fn media_engine(&self) -> &MediaEngine { + &self.media_engine } } #[derive(Default)] pub struct APIBuilder { - setting_engine: Option>, - media_engine: Option>, - interceptor_registry: Option, + setting_engine: Option, + media_engine: Option, + //TODO: interceptor_registry: Option, } impl APIBuilder { @@ -196,41 +194,41 @@ impl APIBuilder { setting_engine: if let Some(setting_engine) = self.setting_engine.take() { setting_engine } else { - Arc::new(SettingEngine::default()) + SettingEngine::default() }, media_engine: if let Some(media_engine) = self.media_engine.take() { media_engine } else { - Arc::new(MediaEngine::default()) + MediaEngine::default() }, - interceptor_registry: if let Some(interceptor_registry) = + /*TODO:interceptor_registry: if let Some(interceptor_registry) = self.interceptor_registry.take() { interceptor_registry } else { Registry::new() - }, + },*/ } } /// WithSettingEngine allows providing a SettingEngine to the API. /// Settings should not be changed after passing the engine to an API. pub fn with_setting_engine(mut self, setting_engine: SettingEngine) -> Self { - self.setting_engine = Some(Arc::new(setting_engine)); + self.setting_engine = Some(setting_engine); self } /// WithMediaEngine allows providing a MediaEngine to the API. /// Settings can be changed after passing the engine to an API. pub fn with_media_engine(mut self, media_engine: MediaEngine) -> Self { - self.media_engine = Some(Arc::new(media_engine)); + self.media_engine = Some(media_engine); self } - /// with_interceptor_registry allows providing Interceptors to the API. + /*TODO: /// with_interceptor_registry allows providing Interceptors to the API. /// Settings should not be changed after passing the registry to an API. pub fn with_interceptor_registry(mut self, interceptor_registry: Registry) -> Self { self.interceptor_registry = Some(interceptor_registry); self - } + }*/ } diff --git a/rtc/src/api/setting_engine/mod.rs b/rtc/src/api/setting_engine/mod.rs index 6d909d3..71f2365 100644 --- a/rtc/src/api/setting_engine/mod.rs +++ b/rtc/src/api/setting_engine/mod.rs @@ -1,20 +1,19 @@ -#[cfg(test)] -mod setting_engine_test; +//TODO:#[cfg(test)] +//TODO:mod setting_engine_test; use std::sync::Arc; +use std::time::Duration; use dtls::extension::extension_use_srtp::SrtpProtectionProfile; -use ice::agent::agent_config::{InterfaceFilterFn, IpFilterFn}; +/*TODO:use ice::agent::agent_config::{InterfaceFilterFn, IpFilterFn}; use ice::mdns::MulticastDnsMode; +use ice::udp_network::UDPNetwork;*/ use ice::network_type::NetworkType; -use ice::udp_network::UDPNetwork; -use tokio::time::Duration; -use util::vnet::net::*; use crate::dtls_transport::dtls_role::DTLSRole; -use crate::error::{Error, Result}; use crate::ice_transport::ice_candidate_type::RTCIceCandidateType; use crate::RECEIVE_MTU; +use shared::error::{Error, Result}; #[derive(Default, Clone)] pub struct Detach { @@ -36,12 +35,12 @@ pub struct Timeout { pub struct Candidates { pub ice_lite: bool, pub ice_network_types: Vec, - pub interface_filter: Arc>, - pub ip_filter: Arc>, + /*TODO pub interface_filter: Arc>, + pub ip_filter: Arc>,*/ pub nat_1to1_ips: Vec, pub nat_1to1_ip_candidate_type: RTCIceCandidateType, - pub multicast_dns_mode: MulticastDnsMode, - pub multicast_dns_host_name: String, + /*TODO:pub multicast_dns_mode: MulticastDnsMode, + pub multicast_dns_host_name: String,*/ pub username_fragment: String, pub password: String, } @@ -68,11 +67,7 @@ pub struct SettingEngine { pub(crate) allow_insecure_verification_algorithm: bool, pub(crate) disable_srtp_replay_protection: bool, pub(crate) disable_srtcp_replay_protection: bool, - pub(crate) vnet: Option>, - //BufferFactory :func(packetType packetio.BufferPacketType, ssrc uint32) io.ReadWriteCloser, - //iceTCPMux :ice.TCPMux,? - //iceProxyDialer :proxy.Dialer,? - pub(crate) udp_network: UDPNetwork, + //TODO: pub(crate) udp_network: UDPNetwork, pub(crate) disable_media_engine_copy: bool, pub(crate) srtp_protection_profiles: Vec, pub(crate) receive_mtu: usize, @@ -136,12 +131,12 @@ impl SettingEngine { self.timeout.ice_relay_acceptance_min_wait = t; } - /// set_udp_network allows ICE traffic to come through Ephemeral or UDPMux. + /*TODO:/// set_udp_network allows ICE traffic to come through Ephemeral or UDPMux. /// UDPMux drastically simplifying deployments where ports will need to be opened/forwarded. /// UDPMux should be started prior to creating PeerConnections. pub fn set_udp_network(&mut self, udp_network: UDPNetwork) { self.udp_network = udp_network; - } + }*/ /// set_lite configures whether or not the ice agent should be a lite agent pub fn set_lite(&mut self, lite: bool) { @@ -154,7 +149,7 @@ impl SettingEngine { self.candidates.ice_network_types = candidate_types; } - /// set_interface_filter sets the filtering functions when gathering ICE candidates + /*TODO:/// set_interface_filter sets the filtering functions when gathering ICE candidates /// This can be used to exclude certain network interfaces from ICE. Which may be /// useful if you know a certain interface will never succeed, or if you wish to reduce /// the amount of information you wish to expose to the remote peer @@ -168,7 +163,7 @@ impl SettingEngine { /// the amount of information you wish to expose to the remote peer pub fn set_ip_filter(&mut self, filter: IpFilterFn) { self.candidates.ip_filter = Arc::new(Some(filter)); - } + }*/ /// set_nat_1to1_ips sets a list of external IP addresses of 1:1 (D)NAT /// and a candidate type for which the external IP address is used. @@ -215,15 +210,7 @@ impl SettingEngine { Ok(()) } - /// set_vnet sets the VNet instance that is passed to ice - /// VNet is a virtual network layer, allowing users to simulate - /// different topologies, latency, loss and jitter. This can be useful for - /// learning WebRTC concepts or testing your application in a lab environment - pub fn set_vnet(&mut self, vnet: Option>) { - self.vnet = vnet; - } - - /// set_ice_multicast_dns_mode controls if ice queries and generates mDNS ICE Candidates + /*TODO:/// set_ice_multicast_dns_mode controls if ice queries and generates mDNS ICE Candidates pub fn set_ice_multicast_dns_mode(&mut self, multicast_dns_mode: ice::mdns::MulticastDnsMode) { self.candidates.multicast_dns_mode = multicast_dns_mode } @@ -233,7 +220,7 @@ impl SettingEngine { /// undefined behavior pub fn set_multicast_dns_host_name(&mut self, host_name: String) { self.candidates.multicast_dns_host_name = host_name; - } + }*/ /// set_ice_credentials sets a staic uFrag/uPwd to be used by ice /// This is useful if you want to do signalless WebRTC session, or having a reproducible environment with static credentials diff --git a/rtc/src/dtls_transport/dtls_role.rs b/rtc/src/dtls_transport/dtls_role.rs index 88730c6..3e776fd 100644 --- a/rtc/src/dtls_transport/dtls_role.rs +++ b/rtc/src/dtls_transport/dtls_role.rs @@ -91,7 +91,7 @@ mod test { use std::io::Cursor; use super::*; - use crate::error::Result; + use shared::error::Result; #[test] fn test_dtls_role_string() { diff --git a/rtc/src/dtls_transport/mod.rs b/rtc/src/dtls_transport/mod.rs index 8d6bcf3..5aef4df 100644 --- a/rtc/src/dtls_transport/mod.rs +++ b/rtc/src/dtls_transport/mod.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +/*TODO: use std::collections::HashMap; use std::future::Future; use std::pin::Pin; use std::sync::atomic::{AtomicBool, AtomicU8, Ordering}; @@ -36,8 +36,9 @@ use crate::stats::stats_collector::StatsCollector; mod dtls_transport_test; pub mod dtls_fingerprint; -pub mod dtls_parameters; +pub mod dtls_parameters;*/ pub mod dtls_role; +/* pub mod dtls_transport_state; pub(crate) fn default_srtp_protection_profiles() -> Vec { @@ -614,3 +615,4 @@ impl RTCDtlsTransport { )) } } +*/ diff --git a/rtc/src/ice_transport/mod.rs b/rtc/src/ice_transport/mod.rs index 6bf09c0..df4d2cc 100644 --- a/rtc/src/ice_transport/mod.rs +++ b/rtc/src/ice_transport/mod.rs @@ -1,4 +1,4 @@ -use std::future::Future; +/*TODO:use std::future::Future; use std::pin::Pin; use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::Arc; @@ -27,18 +27,20 @@ use crate::stats::StatsReportType::Transport; mod ice_transport_test; pub mod ice_candidate; -pub mod ice_candidate_pair; +pub mod ice_candidate_pair;*/ pub mod ice_candidate_type; pub mod ice_connection_state; -pub mod ice_credential_type; -pub mod ice_gatherer; -pub mod ice_gatherer_state; -pub mod ice_gathering_state; -pub mod ice_parameters; -pub mod ice_protocol; -pub mod ice_role; -pub mod ice_server; -pub mod ice_transport_state; +pub mod ice_credential_type; /* + pub mod ice_gatherer; + pub mod ice_gatherer_state; + pub mod ice_gathering_state; + pub mod ice_parameters; + pub mod ice_protocol; + pub mod ice_role; + pub mod ice_server; + pub mod ice_transport_state; + */ +/*TODO: pub type OnConnectionStateChangeHdlrFn = Box< dyn (FnMut(RTCIceTransportState) -> Pin + Send + 'static>>) @@ -353,3 +355,4 @@ impl RTCIceTransport { } } } +*/ diff --git a/rtc/src/lib.rs b/rtc/src/lib.rs index bcb17bb..34bcccd 100644 --- a/rtc/src/lib.rs +++ b/rtc/src/lib.rs @@ -4,15 +4,15 @@ /* #[macro_use] extern crate lazy_static; - +*/ pub mod api; -pub mod data_channel; +/*pub mod data_channel;*/ pub mod dtls_transport; pub mod ice_transport; -pub mod mux; +/*pub mod mux;*/ pub mod peer_connection; pub mod rtp_transceiver; -pub mod sctp_transport; +/*pub mod sctp_transport; pub mod stats; pub mod track; diff --git a/rtc/src/peer_connection/mod.rs b/rtc/src/peer_connection/mod.rs index b4989ce..c269808 100644 --- a/rtc/src/peer_connection/mod.rs +++ b/rtc/src/peer_connection/mod.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +/*#[cfg(test)] pub(crate) mod peer_connection_test; pub mod certificate; @@ -7,8 +7,9 @@ pub mod offer_answer_options; pub(crate) mod operation; mod peer_connection_internal; pub mod peer_connection_state; -pub mod policy; +pub mod policy;*/ pub mod sdp; +/* pub mod signaling_state; use std::future::Future; @@ -2106,3 +2107,4 @@ impl RTCPeerConnection { self.internal.add_rtp_transceiver(t).await } } +*/ diff --git a/rtc/src/peer_connection/sdp/mod.rs b/rtc/src/peer_connection/sdp/mod.rs index 21b8275..1abb96b 100644 --- a/rtc/src/peer_connection/sdp/mod.rs +++ b/rtc/src/peer_connection/sdp/mod.rs @@ -1,34 +1,37 @@ +/*TODO: #[cfg(test)] mod sdp_test; use crate::api::media_engine::MediaEngine; use crate::dtls_transport::dtls_fingerprint::RTCDtlsFingerprint; -use crate::error::{Error, Result}; use crate::ice_transport::ice_candidate::RTCIceCandidate; use crate::ice_transport::ice_gatherer::RTCIceGatherer; use crate::ice_transport::ice_gathering_state::RTCIceGatheringState; -use crate::ice_transport::ice_parameters::RTCIceParameters; +use crate::ice_transport::ice_parameters::RTCIceParameters;*/ use crate::rtp_transceiver::rtp_codec::{ - RTCRtpCodecCapability, RTCRtpCodecParameters, RTPCodecType, + RTCRtpCodecCapability, + RTCRtpCodecParameters, //, RTPCodecType, }; -use crate::rtp_transceiver::rtp_transceiver_direction::RTCRtpTransceiverDirection; -use crate::rtp_transceiver::{PayloadType, RTCPFeedback, RTCRtpTransceiver, SSRC}; +//use crate::rtp_transceiver::rtp_transceiver_direction::RTCRtpTransceiverDirection; +use crate::rtp_transceiver::{PayloadType, RTCPFeedback /*RTCRtpTransceiver, SSRC*/}; +use shared::error::Result; +/* pub mod sdp_type; pub mod session_description; - +*/ use std::collections::HashMap; -use std::convert::From; +//use std::convert::From; use std::io::BufReader; -use std::sync::Arc; +/*use std::sync::Arc; use ice::candidate::candidate_base::unmarshal_candidate; use ice::candidate::Candidate; -use sdp::description::common::{Address, ConnectionInformation}; -use sdp::description::media::{MediaDescription, MediaName, RangedPort}; +use sdp::description::common::{Address, ConnectionInformation};*/ +use sdp::description::media::{MediaDescription /*, MediaName, RangedPort*/}; use sdp::description::session::*; use sdp::extmap::ExtMap; -use sdp::util::ConnectionRole; +/*use sdp::util::ConnectionRole; use smol_str::SmolStr; use url::Url; @@ -989,7 +992,7 @@ pub(crate) fn have_data_channel( } None } - +*/ pub(crate) fn codecs_from_media_description( m: &MediaDescription, ) -> Result> { @@ -1007,7 +1010,7 @@ pub(crate) fn codecs_from_media_description( if payload_type == 0 { continue; } - return Err(err.into()); + return Err(err); } }; @@ -1067,7 +1070,7 @@ pub(crate) fn rtp_extensions_from_media_description( Ok(out) } - +/*TODO: /// update_sdp_origin saves sdp.Origin in PeerConnection when creating 1st local SDP; /// for subsequent calling, it updates Origin for SessionDescription from saved one /// and increments session version by one. @@ -1094,3 +1097,4 @@ pub(crate) fn update_sdp_origin(origin: &mut Origin, d: &mut SessionDescription) d.origin.session_version += 1; } } +*/ diff --git a/rtc/src/peer_connection/sdp/session_description.rs b/rtc/src/peer_connection/sdp/session_description.rs index 7085f34..b82f1b1 100644 --- a/rtc/src/peer_connection/sdp/session_description.rs +++ b/rtc/src/peer_connection/sdp/session_description.rs @@ -4,7 +4,7 @@ use sdp::description::session::SessionDescription; use serde::{Deserialize, Serialize}; use super::sdp_type::RTCSdpType; -use crate::error::Result; +use shared::error::Result; /// SessionDescription is used to expose local and remote session descriptions. #[derive(Default, Debug, Clone, Serialize, Deserialize)] diff --git a/rtc/src/rtp_transceiver/mod.rs b/rtc/src/rtp_transceiver/mod.rs index 1edb5fc..4bb5c36 100644 --- a/rtc/src/rtp_transceiver/mod.rs +++ b/rtc/src/rtp_transceiver/mod.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +/*TODO:#[cfg(test)] mod rtp_transceiver_test; use std::fmt; @@ -9,27 +9,30 @@ use std::sync::Arc; use interceptor::stream_info::{RTPHeaderExtension, StreamInfo}; use interceptor::Attributes; -use log::trace; +use log::trace;*/ use serde::{Deserialize, Serialize}; +/* use smol_str::SmolStr; use tokio::sync::{Mutex, OnceCell}; use util::Unmarshal; -use crate::api::media_engine::MediaEngine; -use crate::error::{Error, Result}; +use crate::api::media_engine::MediaEngine;*/ use crate::rtp_transceiver::rtp_codec::*; +/* use crate::rtp_transceiver::rtp_receiver::{RTCRtpReceiver, RTPReceiverInternal}; -use crate::rtp_transceiver::rtp_sender::RTCRtpSender; +use crate::rtp_transceiver::rtp_sender::RTCRtpSender;*/ use crate::rtp_transceiver::rtp_transceiver_direction::RTCRtpTransceiverDirection; +/*use shared::error::{Error, Result}; use crate::track::track_local::TrackLocal; - +*/ pub(crate) mod fmtp; pub mod rtp_codec; +/* pub mod rtp_receiver; -pub mod rtp_sender; +pub mod rtp_sender;*/ pub mod rtp_transceiver_direction; -pub(crate) mod srtp_writer_future; - +/*pub(crate) mod srtp_writer_future; +*/ /// SSRC represents a synchronization source /// A synchronization source is a randomly chosen /// value meant to be globally unique within a particular @@ -93,7 +96,7 @@ pub struct RTCRtpRtxParameters { /// #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct RTCRtpCodingParameters { - pub rid: SmolStr, + pub rid: String, pub ssrc: SSRC, pub payload_type: PayloadType, pub rtx: RTCRtpRtxParameters, @@ -129,6 +132,7 @@ pub struct RTCRtpTransceiverInit { // Streams []*Track } +/*TODO: pub(crate) fn create_stream_info( id: String, ssrc: SSRC, @@ -557,4 +561,4 @@ pub(crate) fn handle_unknown_rtp_packet( }; Ok((mid, rid, srid, payload_type)) -} +}*/ diff --git a/rtc/src/rtp_transceiver/rtp_codec.rs b/rtc/src/rtp_transceiver/rtp_codec.rs index afaa8ef..b71a0f0 100644 --- a/rtc/src/rtp_transceiver/rtp_codec.rs +++ b/rtc/src/rtp_transceiver/rtp_codec.rs @@ -2,8 +2,8 @@ use std::fmt; use super::*; use crate::api::media_engine::*; -use crate::error::{Error, Result}; use crate::rtp_transceiver::fmtp; +use shared::error::{Error, Result}; /// RTPCodecType determines the type of a codec #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] @@ -62,7 +62,7 @@ pub struct RTCRtpCodecCapability { impl RTCRtpCodecCapability { /// Turn codec capability into a `packetizer::Payloader` - pub fn payloader_for_codec(&self) -> Result> { + pub fn payloader_for_codec(&self) -> Result> { let mime_type = self.mime_type.to_lowercase(); if mime_type == MIME_TYPE_H264.to_lowercase() { Ok(Box::::default())