diff --git a/crates/sdp-types/src/attributes/ice.rs b/crates/sdp-types/src/attributes/ice.rs index 87bd717..0b8b5c3 100644 --- a/crates/sdp-types/src/attributes/ice.rs +++ b/crates/sdp-types/src/attributes/ice.rs @@ -74,12 +74,6 @@ impl IceUsernameFragment { } } -impl fmt::Display for IceUsernameFragment { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "a=ice-ufrag:{}", self.ufrag) - } -} - /// Ice password attribute (`a=ice-pwd`) /// /// Session and Media Level attribute @@ -104,9 +98,3 @@ impl IcePassword { )(i) } } - -impl fmt::Display for IcePassword { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "a=ice-pwd:{}", self.pwd) - } -} diff --git a/crates/sdp-types/src/connection.rs b/crates/sdp-types/src/connection.rs index 3b7127e..0a82c32 100644 --- a/crates/sdp-types/src/connection.rs +++ b/crates/sdp-types/src/connection.rs @@ -53,7 +53,7 @@ impl Connection { impl fmt::Display for Connection { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "c={}", self.address)?; + write!(f, "{}", self.address)?; match self.address { TaggedAddress::IP4(_) | TaggedAddress::IP4FQDN(_) => { diff --git a/crates/sdp-types/src/media.rs b/crates/sdp-types/src/media.rs index ed51d6b..61e35ff 100644 --- a/crates/sdp-types/src/media.rs +++ b/crates/sdp-types/src/media.rs @@ -127,7 +127,7 @@ impl Media { impl fmt::Display for Media { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "m={}", self.media_type)?; + write!(f, "{}", self.media_type)?; if let Some(ports_num) = &self.ports_num { write!(f, " {}/{} ", self.port, ports_num)?; diff --git a/crates/sdp-types/src/media_description.rs b/crates/sdp-types/src/media_description.rs index bc72c75..8e7ce2c 100644 --- a/crates/sdp-types/src/media_description.rs +++ b/crates/sdp-types/src/media_description.rs @@ -2,8 +2,8 @@ use crate::connection::Connection; use crate::media::Media; use crate::{bandwidth::Bandwidth, Rtcp}; use crate::{ - Direction, ExtMap, Fmtp, IceCandidate, IcePassword, IceUsernameFragment, RtpMap, SrtpCrypto, - UnknownAttribute, + Direction, ExtMap, Fmtp, IceCandidate, IcePassword, IceUsernameFragment, MediaType, RtpMap, + SrtpCrypto, TransportProtocol, UnknownAttribute, }; use bytesstr::BytesStr; use std::fmt::{self, Debug}; @@ -67,10 +67,10 @@ pub struct MediaDescription { impl fmt::Display for MediaDescription { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}\r\n", self.media)?; + write!(f, "m={}\r\n", self.media)?; if let Some(conn) = &self.connection { - write!(f, "{}\r\n", conn)?; + write!(f, "c={}\r\n", conn)?; } for bw in &self.bandwidth { @@ -100,11 +100,11 @@ impl fmt::Display for MediaDescription { } if let Some(ufrag) = &self.ice_ufrag { - write!(f, "{}\r\n", ufrag)?; + write!(f, "a=ice-ufrag:{}\r\n", ufrag.ufrag)?; } if let Some(pwd) = &self.ice_pwd { - write!(f, "{}\r\n", pwd)?; + write!(f, "a=ice-pwd:{}\r\n", pwd.pwd)?; } for candidate in &self.ice_candidates { @@ -134,3 +134,34 @@ impl fmt::Display for MediaDescription { Ok(()) } } + +impl MediaDescription { + /// Create media description which signals rejected media + pub fn rejected(media_type: MediaType) -> Self { + MediaDescription { + media: Media { + media_type, + port: 0, + ports_num: None, + proto: TransportProtocol::RtpAvp, + fmts: vec![], + }, + connection: None, + bandwidth: vec![], + direction: Direction::Inactive, + rtcp: None, + rtcp_mux: false, + mid: None, + rtpmap: vec![], + fmtp: vec![], + ice_ufrag: None, + ice_pwd: None, + ice_candidates: vec![], + ice_end_of_candidates: false, + crypto: vec![], + extmap: vec![], + extmap_allow_mixed: false, + attributes: vec![], + } + } +} diff --git a/crates/sdp-types/src/parser.rs b/crates/sdp-types/src/parser.rs index 0093433..2001c3d 100644 --- a/crates/sdp-types/src/parser.rs +++ b/crates/sdp-types/src/parser.rs @@ -109,7 +109,7 @@ impl Parser { ice_end_of_candidates: false, crypto: vec![], extmap: vec![], - // inherit extmap allow mixed attribute + // inherit extmap allow mixed atr extmap_allow_mixed: self.extmap_allow_mixed, attributes: vec![], }); @@ -127,7 +127,7 @@ impl Parser { line: &str, ) -> Result<(), ParseSessionDescriptionError> { if let Some((name, value)) = line.split_once(':') { - self.parse_attribute_with_value(src, line, name, value)?; + self.parse_attribute_with_value(src, name, value)?; } else { self.parse_attribute_without_value(src, line); } @@ -138,7 +138,6 @@ impl Parser { fn parse_attribute_with_value( &mut self, src: &BytesStr, - line: &str, name: &str, value: &str, ) -> Result<(), ParseSessionDescriptionError> { @@ -207,7 +206,7 @@ impl Parser { } } "candidate" => { - let (_, candidate) = IceCandidate::parse(src.as_ref(), line).finish()?; + let (_, candidate) = IceCandidate::parse(src.as_ref(), value).finish()?; if let Some(media_description) = self.media_descriptions.last_mut() { media_description.ice_candidates.push(candidate); @@ -266,7 +265,7 @@ impl Parser { self.extmap_allow_mixed = true; if let Some(media_description) = self.media_descriptions.last_mut() { - media_description.extmap_allow_mixed = true; + media_description.rtcp_mux = true; } } "rtcp-mux" => { diff --git a/crates/sdp-types/src/session_description.rs b/crates/sdp-types/src/session_description.rs index 1f49223..39e7477 100644 --- a/crates/sdp-types/src/session_description.rs +++ b/crates/sdp-types/src/session_description.rs @@ -84,14 +84,14 @@ impl fmt::Display for SessionDescription { write!(f, "s={}\r\n", self.name)?; if let Some(conn) = &self.connection { - write!(f, "{conn}\r\n")?; + write!(f, "c={conn}\r\n")?; } for bw in &self.bandwidth { write!(f, "b={bw}\r\n")?; } - write!(f, "{}\r\n", self.time)?; + write!(f, "t={}\r\n", self.time)?; // omit direction here, since it is always written in media descriptions @@ -116,11 +116,11 @@ impl fmt::Display for SessionDescription { } if let Some(ufrag) = &self.ice_ufrag { - write!(f, "{ufrag}\r\n")?; + write!(f, "a=ice-ufrag:{}\r\n", ufrag.ufrag)?; } if let Some(pwd) = &self.ice_pwd { - write!(f, "{pwd}\r\n")?; + write!(f, "a=ice-pwd:{}\r\n", pwd.pwd)?; } for attr in &self.attributes { diff --git a/crates/sdp-types/src/time.rs b/crates/sdp-types/src/time.rs index 1bd7abe..4f4483e 100644 --- a/crates/sdp-types/src/time.rs +++ b/crates/sdp-types/src/time.rs @@ -42,7 +42,7 @@ impl Time { impl fmt::Display for Time { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "t={} {}", self.start, self.stop) + write!(f, "{} {}", self.start, self.stop) } }