aboutsummaryrefslogtreecommitdiff
path: root/src/sdp/mod.rs
blob: 635c182caa8e0829b863bbe553fcce43789b93c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 {})
    }
}