diff options
Diffstat (limited to 'src/sdp/mod.rs')
-rw-r--r-- | src/sdp/mod.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/sdp/mod.rs b/src/sdp/mod.rs new file mode 100644 index 0000000..635c182 --- /dev/null +++ b/src/sdp/mod.rs @@ -0,0 +1,56 @@ +use anyhow::{anyhow, bail}; +use std::str::FromStr; + +pub struct SessionDescription { + version: String, + originator: String, + session_name: String, + session_information: Option<String>, + description_uri: Option<String>, + email_address: Option<String>, + phone_number: Option<String>, + connection_information: Vec<String>, + bandwidth: Vec<String>, + time_descriptions: Vec<TimeDescription>, + time_zone_adjustments: Option<String>, + encryption_key: Option<String>, + session_attribute: Vec<String>, + media_descriptions: Vec<MediaDescription>, +} + +pub struct TimeDescription { + time: String, + repeat_times: Vec<String>, +} + +pub struct MediaDescription { + name: String, + title: String, + connection_information: String, +} + +impl FromStr for SessionDescription { + type Err = anyhow::Error; + fn from_str(s: &str) -> Result<Self, Self::Err> { + let mut version = None; + let mut originator = None; + let mut session_name = None; + let mut session_information = None; + let mut description_uri = None; + let mut email_address = None; + let mut phone_number = None; + let mut connection_information = Vec::new(); + let mut bandwidth = Vec::new(); + for line in s.lines() { + let (r#type, value) = line.split_once("=").ok_or(anyhow!("sdp line invalid"))?; + match r#type { + "v" => version = Some(value.to_string()), + "o" => originator = Some(value.to_string()), + "s" => session_name = Some(value.to_string()), + "s" => session_name = Some(value.to_string()), + x => bail!("unknown sdp type ({x:?})"), + } + } + Ok(Self {}) + } +} |