Skip to content

Commit c18fc85

Browse files
author
Rusty Rain
authored
Merge pull request #8 from algesten/clippy
fix clippy warnings
2 parents 810c8e4 + 703856c commit c18fc85

File tree

6 files changed

+272
-273
lines changed

6 files changed

+272
-273
lines changed

crates/sdp/src/extmap.rs

Lines changed: 117 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,117 @@
1-
#[cfg(test)]
2-
mod extmap_test;
3-
4-
use super::common_description::*;
5-
use super::direction::*;
6-
use super::error::{Error, Result};
7-
8-
use std::fmt;
9-
use std::io;
10-
use url::Url;
11-
12-
/// Default ext values
13-
pub const DEF_EXT_MAP_VALUE_ABS_SEND_TIME: usize = 1;
14-
pub const DEF_EXT_MAP_VALUE_TRANSPORT_CC: usize = 2;
15-
pub const DEF_EXT_MAP_VALUE_SDES_MID: usize = 3;
16-
pub const DEF_EXT_MAP_VALUE_SDES_RTP_STREAM_ID: usize = 4;
17-
18-
pub const ABS_SEND_TIME_URI: &str = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
19-
pub const TRANSPORT_CC_URI: &str =
20-
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
21-
pub const SDES_MID_URI: &str = "urn:ietf:params:rtp-hdrext:sdes:mid";
22-
pub const SDES_RTP_STREAM_ID_URI: &str = "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
23-
pub const AUDIO_LEVEL_URI: &str = "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
24-
25-
/// ExtMap represents the activation of a single RTP header extension
26-
#[derive(Debug, Clone, Default)]
27-
pub struct ExtMap {
28-
pub value: isize,
29-
pub direction: Direction,
30-
pub uri: Option<Url>,
31-
pub ext_attr: Option<String>,
32-
}
33-
34-
impl fmt::Display for ExtMap {
35-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36-
let mut output = format!("{}", self.value);
37-
let dirstring = self.direction.to_string();
38-
if dirstring != DIRECTION_UNKNOWN_STR {
39-
output += format!("/{}", dirstring).as_str();
40-
}
41-
42-
if let Some(uri) = &self.uri {
43-
output += format!(" {}", uri).as_str();
44-
}
45-
46-
if let Some(ext_attr) = &self.ext_attr {
47-
output += format!(" {}", ext_attr).as_str();
48-
}
49-
50-
write!(f, "{}", output)
51-
}
52-
}
53-
54-
impl ExtMap {
55-
/// converts this object to an Attribute
56-
pub fn convert(&self) -> Attribute {
57-
Attribute {
58-
key: "extmap".to_string(),
59-
value: Some(self.to_string()),
60-
}
61-
}
62-
63-
/// unmarshal creates an Extmap from a string
64-
pub fn unmarshal<R: io::BufRead>(reader: &mut R) -> Result<Self> {
65-
let mut line = String::new();
66-
reader.read_line(&mut line)?;
67-
let parts: Vec<&str> = line.trim().splitn(2, ':').collect();
68-
if parts.len() != 2 {
69-
return Err(Error::ExtMapParse(line).into());
70-
}
71-
72-
let fields: Vec<&str> = parts[1].split_whitespace().collect();
73-
if fields.len() < 2 {
74-
return Err(Error::ExtMapParse(line).into());
75-
}
76-
77-
let valdir: Vec<&str> = fields[0].split('/').collect();
78-
let value = valdir[0].parse::<isize>()?;
79-
if !(1..=246).contains(&value) {
80-
return Err(Error::ExtMapParse(format!(
81-
"{} -- extmap key must be in the range 1-256",
82-
valdir[0]
83-
))
84-
.into());
85-
}
86-
87-
let mut direction = Direction::DirectionUnknown;
88-
if valdir.len() == 2 {
89-
direction = Direction::new(valdir[1]);
90-
if direction == Direction::DirectionUnknown {
91-
return Err(
92-
Error::ExtMapParse(format!("unknown direction from {}", valdir[1])).into(),
93-
);
94-
}
95-
}
96-
97-
let uri = Some(Url::parse(fields[1])?);
98-
99-
let ext_attr = if fields.len() == 3 {
100-
Some(fields[2].to_owned())
101-
} else {
102-
None
103-
};
104-
105-
Ok(ExtMap {
106-
value,
107-
direction,
108-
uri,
109-
ext_attr,
110-
})
111-
}
112-
113-
/// marshal creates a string from an ExtMap
114-
pub fn marshal(&self) -> String {
115-
"extmap:".to_string() + self.to_string().as_str()
116-
}
117-
}
1+
#[cfg(test)]
2+
mod extmap_test;
3+
4+
use super::common_description::*;
5+
use super::direction::*;
6+
use super::error::{Error, Result};
7+
8+
use std::fmt;
9+
use std::io;
10+
use url::Url;
11+
12+
/// Default ext values
13+
pub const DEF_EXT_MAP_VALUE_ABS_SEND_TIME: usize = 1;
14+
pub const DEF_EXT_MAP_VALUE_TRANSPORT_CC: usize = 2;
15+
pub const DEF_EXT_MAP_VALUE_SDES_MID: usize = 3;
16+
pub const DEF_EXT_MAP_VALUE_SDES_RTP_STREAM_ID: usize = 4;
17+
18+
pub const ABS_SEND_TIME_URI: &str = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
19+
pub const TRANSPORT_CC_URI: &str =
20+
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
21+
pub const SDES_MID_URI: &str = "urn:ietf:params:rtp-hdrext:sdes:mid";
22+
pub const SDES_RTP_STREAM_ID_URI: &str = "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
23+
pub const AUDIO_LEVEL_URI: &str = "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
24+
25+
/// ExtMap represents the activation of a single RTP header extension
26+
#[derive(Debug, Clone, Default)]
27+
pub struct ExtMap {
28+
pub value: isize,
29+
pub direction: Direction,
30+
pub uri: Option<Url>,
31+
pub ext_attr: Option<String>,
32+
}
33+
34+
impl fmt::Display for ExtMap {
35+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36+
let mut output = format!("{}", self.value);
37+
let dirstring = self.direction.to_string();
38+
if dirstring != DIRECTION_UNKNOWN_STR {
39+
output += format!("/{}", dirstring).as_str();
40+
}
41+
42+
if let Some(uri) = &self.uri {
43+
output += format!(" {}", uri).as_str();
44+
}
45+
46+
if let Some(ext_attr) = &self.ext_attr {
47+
output += format!(" {}", ext_attr).as_str();
48+
}
49+
50+
write!(f, "{}", output)
51+
}
52+
}
53+
54+
impl ExtMap {
55+
/// converts this object to an Attribute
56+
pub fn convert(&self) -> Attribute {
57+
Attribute {
58+
key: "extmap".to_string(),
59+
value: Some(self.to_string()),
60+
}
61+
}
62+
63+
/// unmarshal creates an Extmap from a string
64+
pub fn unmarshal<R: io::BufRead>(reader: &mut R) -> Result<Self> {
65+
let mut line = String::new();
66+
reader.read_line(&mut line)?;
67+
let parts: Vec<&str> = line.trim().splitn(2, ':').collect();
68+
if parts.len() != 2 {
69+
return Err(Error::ExtMapParse(line));
70+
}
71+
72+
let fields: Vec<&str> = parts[1].split_whitespace().collect();
73+
if fields.len() < 2 {
74+
return Err(Error::ExtMapParse(line));
75+
}
76+
77+
let valdir: Vec<&str> = fields[0].split('/').collect();
78+
let value = valdir[0].parse::<isize>()?;
79+
if !(1..=246).contains(&value) {
80+
return Err(Error::ExtMapParse(format!(
81+
"{} -- extmap key must be in the range 1-256",
82+
valdir[0]
83+
)));
84+
}
85+
86+
let mut direction = Direction::DirectionUnknown;
87+
if valdir.len() == 2 {
88+
direction = Direction::new(valdir[1]);
89+
if direction == Direction::DirectionUnknown {
90+
return Err(Error::ExtMapParse(format!(
91+
"unknown direction from {}",
92+
valdir[1]
93+
)));
94+
}
95+
}
96+
97+
let uri = Some(Url::parse(fields[1])?);
98+
99+
let ext_attr = if fields.len() == 3 {
100+
Some(fields[2].to_owned())
101+
} else {
102+
None
103+
};
104+
105+
Ok(ExtMap {
106+
value,
107+
direction,
108+
uri,
109+
ext_attr,
110+
})
111+
}
112+
113+
/// marshal creates a string from an ExtMap
114+
pub fn marshal(&self) -> String {
115+
"extmap:".to_string() + self.to_string().as_str()
116+
}
117+
}

crates/sdp/src/extmap/extmap_test.rs

Lines changed: 78 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,78 @@
1-
use super::*;
2-
use crate::util::{ATTRIBUTE_KEY, END_LINE};
3-
4-
use std::io::BufReader;
5-
use std::iter::Iterator;
6-
7-
const EXAMPLE_ATTR_EXTMAP1: &'static str = "extmap:1 http://example.com/082005/ext.htm#ttime";
8-
const EXAMPLE_ATTR_EXTMAP2: &'static str =
9-
"extmap:2/sendrecv http://example.com/082005/ext.htm#xmeta short";
10-
const FAILING_ATTR_EXTMAP1: &'static str =
11-
"extmap:257/sendrecv http://example.com/082005/ext.htm#xmeta short";
12-
const FAILING_ATTR_EXTMAP2: &'static str =
13-
"extmap:2/blorg http://example.com/082005/ext.htm#xmeta short";
14-
15-
#[test]
16-
fn test_extmap() -> Result<()> {
17-
let example_attr_extmap1_line = EXAMPLE_ATTR_EXTMAP1;
18-
let example_attr_extmap2_line = EXAMPLE_ATTR_EXTMAP2;
19-
let failing_attr_extmap1_line =
20-
format!("{}{}{}", ATTRIBUTE_KEY, FAILING_ATTR_EXTMAP1, END_LINE);
21-
let failing_attr_extmap2_line =
22-
format!("{}{}{}", ATTRIBUTE_KEY, FAILING_ATTR_EXTMAP2, END_LINE);
23-
let passingtests = vec![
24-
(EXAMPLE_ATTR_EXTMAP1, example_attr_extmap1_line),
25-
(EXAMPLE_ATTR_EXTMAP2, example_attr_extmap2_line),
26-
];
27-
let failingtests = vec![
28-
(FAILING_ATTR_EXTMAP1, failing_attr_extmap1_line),
29-
(FAILING_ATTR_EXTMAP2, failing_attr_extmap2_line),
30-
];
31-
32-
for (i, u) in passingtests.iter().enumerate() {
33-
let mut reader = BufReader::new(u.1.as_bytes());
34-
let actual = ExtMap::unmarshal(&mut reader)?;
35-
assert_eq!(
36-
u.1,
37-
actual.marshal(),
38-
"{}: {} vs {}",
39-
i,
40-
u.1,
41-
actual.marshal()
42-
);
43-
}
44-
45-
for u in failingtests {
46-
let mut reader = BufReader::new(u.1.as_bytes());
47-
let actual = ExtMap::unmarshal(&mut reader);
48-
assert!(actual.is_err());
49-
}
50-
51-
Ok(())
52-
}
53-
54-
#[test]
55-
fn test_transport_cc_extmap() -> Result<()> {
56-
//a=extmap:<value>["/"<direction>] <URI> <extensionattributes>
57-
//a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
58-
let uri = Some(Url::parse(
59-
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
60-
)?);
61-
let e = ExtMap {
62-
value: 3,
63-
uri,
64-
direction: Direction::DirectionUnknown,
65-
ext_attr: None,
66-
};
67-
68-
let s = e.marshal();
69-
if s == "3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01" {
70-
assert!(false, "TestTransportCC failed");
71-
} else {
72-
assert_eq!(
73-
s,
74-
"extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
75-
)
76-
}
77-
78-
Ok(())
79-
}
1+
use super::*;
2+
use crate::util::{ATTRIBUTE_KEY, END_LINE};
3+
4+
use std::io::BufReader;
5+
use std::iter::Iterator;
6+
7+
const EXAMPLE_ATTR_EXTMAP1: &str = "extmap:1 http://example.com/082005/ext.htm#ttime";
8+
const EXAMPLE_ATTR_EXTMAP2: &str =
9+
"extmap:2/sendrecv http://example.com/082005/ext.htm#xmeta short";
10+
const FAILING_ATTR_EXTMAP1: &str =
11+
"extmap:257/sendrecv http://example.com/082005/ext.htm#xmeta short";
12+
const FAILING_ATTR_EXTMAP2: &str = "extmap:2/blorg http://example.com/082005/ext.htm#xmeta short";
13+
14+
#[test]
15+
fn test_extmap() -> Result<()> {
16+
let example_attr_extmap1_line = EXAMPLE_ATTR_EXTMAP1;
17+
let example_attr_extmap2_line = EXAMPLE_ATTR_EXTMAP2;
18+
let failing_attr_extmap1_line =
19+
format!("{}{}{}", ATTRIBUTE_KEY, FAILING_ATTR_EXTMAP1, END_LINE);
20+
let failing_attr_extmap2_line =
21+
format!("{}{}{}", ATTRIBUTE_KEY, FAILING_ATTR_EXTMAP2, END_LINE);
22+
let passingtests = vec![
23+
(EXAMPLE_ATTR_EXTMAP1, example_attr_extmap1_line),
24+
(EXAMPLE_ATTR_EXTMAP2, example_attr_extmap2_line),
25+
];
26+
let failingtests = vec![
27+
(FAILING_ATTR_EXTMAP1, failing_attr_extmap1_line),
28+
(FAILING_ATTR_EXTMAP2, failing_attr_extmap2_line),
29+
];
30+
31+
for (i, u) in passingtests.iter().enumerate() {
32+
let mut reader = BufReader::new(u.1.as_bytes());
33+
let actual = ExtMap::unmarshal(&mut reader)?;
34+
assert_eq!(
35+
u.1,
36+
actual.marshal(),
37+
"{}: {} vs {}",
38+
i,
39+
u.1,
40+
actual.marshal()
41+
);
42+
}
43+
44+
for u in failingtests {
45+
let mut reader = BufReader::new(u.1.as_bytes());
46+
let actual = ExtMap::unmarshal(&mut reader);
47+
assert!(actual.is_err());
48+
}
49+
50+
Ok(())
51+
}
52+
53+
#[test]
54+
fn test_transport_cc_extmap() -> Result<()> {
55+
//a=extmap:<value>["/"<direction>] <URI> <extensionattributes>
56+
//a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
57+
let uri = Some(Url::parse(
58+
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
59+
)?);
60+
let e = ExtMap {
61+
value: 3,
62+
uri,
63+
direction: Direction::DirectionUnknown,
64+
ext_attr: None,
65+
};
66+
67+
let s = e.marshal();
68+
if s == "3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01" {
69+
assert!(false, "TestTransportCC failed");
70+
} else {
71+
assert_eq!(
72+
s,
73+
"extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
74+
)
75+
}
76+
77+
Ok(())
78+
}

0 commit comments

Comments
 (0)