Bug 1467502: Merged Rsdparser changes from github to mozilla central. r=drno
authorJohannes Willbold <j.willbold@mozilla.com>
Fri, 08 Jun 2018 09:27:34 -0700
changeset 478722 862fbe128aee3b3a0de3fddad683d43c1b19080d
parent 478721 e2c7f43bb2072060a3c2ee8543768b8db5892d5a
child 478723 fe5ded10511fb958871ad2dd8e2b04ec8a4e0071
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno
bugs1467502
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1467502: Merged Rsdparser changes from github to mozilla central. r=drno Merged Rsdparser changes from github to mozilla central. This includes: Syntax fixes for older rust versions The TransportCC parameter for rtcp-fb Serialization marcos and code MozReview-Commit-ID: JqYttvTx2QS
media/webrtc/signaling/src/sdp/rsdparsa/src/attribute_type.rs
media/webrtc/signaling/src/sdp/rsdparsa/src/error.rs
media/webrtc/signaling/src/sdp/rsdparsa/src/lib.rs
media/webrtc/signaling/src/sdp/rsdparsa/src/media_type.rs
--- a/media/webrtc/signaling/src/sdp/rsdparsa/src/attribute_type.rs
+++ b/media/webrtc/signaling/src/sdp/rsdparsa/src/attribute_type.rs
@@ -3,43 +3,48 @@ use std::str::FromStr;
 use std::fmt;
 
 use SdpType;
 use error::SdpParserInternalError;
 use network::{parse_nettype, parse_addrtype, parse_unicast_addr};
 
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttributePayloadType {
     PayloadType(u8),
     Wildcard, // Wildcard means "*",
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttributeCandidateTransport {
     Udp,
     Tcp,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttributeCandidateType {
     Host,
     Srflx,
     Prflx,
     Relay,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttributeCandidateTcpType {
     Active,
     Passive,
     Simultaneous,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeCandidate {
     pub foundation: String,
     pub component: u32,
     pub transport: SdpAttributeCandidateTransport,
     pub priority: u64,
     pub address: IpAddr,
     pub port: u32,
     pub c_type: SdpAttributeCandidateType,
@@ -98,23 +103,25 @@ impl SdpAttributeCandidate {
     }
 
     fn set_network_cost(&mut self, n: u32) {
         self.networkcost = Some(n)
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeRemoteCandidate {
     pub component: u32,
     pub address: IpAddr,
     pub port: u32,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeSimulcastId {
     pub id: String,
     pub paused: bool,
 }
 
 impl SdpAttributeSimulcastId {
     pub fn new(idstr: String) -> SdpAttributeSimulcastId {
         if idstr.starts_with('~') {
@@ -127,16 +134,17 @@ impl SdpAttributeSimulcastId {
                 id: idstr,
                 paused: false,
             }
         }
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeSimulcastAlternatives {
     pub ids: Vec<SdpAttributeSimulcastId>,
 }
 
 impl SdpAttributeSimulcastAlternatives {
     pub fn new(idlist: String) -> SdpAttributeSimulcastAlternatives {
         SdpAttributeSimulcastAlternatives {
             ids: idlist
@@ -144,16 +152,17 @@ impl SdpAttributeSimulcastAlternatives {
                 .map(|x| x.to_string())
                 .map(SdpAttributeSimulcastId::new)
                 .collect(),
         }
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeSimulcast {
     pub send: Vec<SdpAttributeSimulcastAlternatives>,
     pub receive: Vec<SdpAttributeSimulcastAlternatives>,
 }
 
 impl SdpAttributeSimulcast {
     fn parse_ids(&mut self, direction: SdpAttributeDirection, idlist: String) {
         let list = idlist
@@ -166,16 +175,17 @@ impl SdpAttributeSimulcast {
             SdpAttributeDirection::Recvonly => self.receive = list,
             SdpAttributeDirection::Sendonly => self.send = list,
             _ => (),
         }
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeRtcp {
     pub port: u16,
     pub unicast_addr: Option<IpAddr>,
 }
 
 impl SdpAttributeRtcp {
     pub fn new(port: u16) -> SdpAttributeRtcp {
         SdpAttributeRtcp {
@@ -185,98 +195,111 @@ impl SdpAttributeRtcp {
     }
 
     fn set_addr(&mut self, addr: IpAddr) {
         self.unicast_addr = Some(addr)
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttributeRtcpFbType {
     Ack = 0,
     Ccm = 2, // This is explicitly 2 to make the conversion to the
              // enum used in the glue-code possible. The glue code has "app"
              // in the place of 1
     Nack,
     TrrInt,
-    Remb
+    Remb,
+    TransCC
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeRtcpFb {
     pub payload_type: SdpAttributePayloadType,
     pub feedback_type: SdpAttributeRtcpFbType,
     pub parameter: String,
     pub extra: String,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttributeDirection {
     Recvonly,
     Sendonly,
     Sendrecv,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeExtmap {
     pub id: u16,
     pub direction: Option<SdpAttributeDirection>,
     pub url: String,
     pub extension_attributes: Option<String>,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeFmtp {
     pub payload_type: u8,
     pub tokens: Vec<String>,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeFingerprint {
     // TODO turn the supported hash algorithms into an enum?
     pub hash_algorithm: String,
     pub fingerprint: String,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeSctpmap {
     pub port: u16,
     pub channels: u32,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttributeGroupSemantic {
     LipSynchronization,
     FlowIdentification,
     SingleReservationFlow,
     AlternateNetworkAddressType,
     ForwardErrorCorrection,
     DecodingDependency,
     Bundle,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeGroup {
     pub semantics: SdpAttributeGroupSemantic,
     pub tags: Vec<String>,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeMsid {
     pub id: String,
     pub appdata: Option<String>,
 }
 
 #[derive(Clone, Debug)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeMsidSemantic {
     pub semantic: String,
     pub msids: Vec<String>,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeRtpmap {
     pub payload_type: u8,
     pub codec_name: String,
     pub frequency: u32,
     pub channels: Option<u32>,
 }
 
 impl SdpAttributeRtpmap {
@@ -290,24 +313,26 @@ impl SdpAttributeRtpmap {
     }
 
     fn set_channels(&mut self, c: u32) {
         self.channels = Some(c)
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttributeSetup {
     Active,
     Actpass,
     Holdconn,
     Passive,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpAttributeSsrc {
     pub id: u32,
     pub attribute: Option<String>,
     pub value: Option<String>,
 }
 
 impl SdpAttributeSsrc {
     pub fn new(id: u32) -> SdpAttributeSsrc {
@@ -325,16 +350,17 @@ impl SdpAttributeSsrc {
             let v: Vec<&str> = a.splitn(2, ':').collect();
             self.attribute = Some(v[0].to_string());
             self.value = Some(v[1].to_string());
         }
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpAttribute {
     BundleOnly,
     Candidate(SdpAttributeCandidate),
     EndOfCandidates,
     Extmap(SdpAttributeExtmap),
     Fingerprint(SdpAttributeFingerprint),
     Fmtp(SdpAttributeFmtp),
     Group(SdpAttributeGroup),
@@ -1061,16 +1087,17 @@ fn parse_rtcp_fb(to_parse: &str) -> Resu
     // Parse this in advance to use it later in the parameter switch
     let feedback_type = match tokens.get(1) {
         Some(x) => match x.as_ref(){
             "ack" => SdpAttributeRtcpFbType::Ack,
             "ccm" => SdpAttributeRtcpFbType::Ccm,
             "nack" => SdpAttributeRtcpFbType::Nack,
             "trr-int" => SdpAttributeRtcpFbType::TrrInt,
             "goog-remb" => SdpAttributeRtcpFbType::Remb,
+            "transport-cc" => SdpAttributeRtcpFbType::TransCC,
             _ => {
                 return Err(SdpParserInternalError::Unsupported(
                     format!("Unknown rtcpfb feedback type: {:?}",x).to_string()
                 ))
             }
         },
         None => {
             return Err(SdpParserInternalError::Generic(
@@ -1084,68 +1111,78 @@ fn parse_rtcp_fb(to_parse: &str) -> Resu
         &SdpAttributeRtcpFbType::Ack => match tokens.get(2) {
             Some(x) => match x.as_ref() {
                 "rpsi" | "app"  => x.to_string(),
                 _ => {
                     return Err(SdpParserInternalError::Unsupported(
                         format!("Unknown rtcpfb ack parameter: {:?}",x).to_string()
                     ))
                 },
-            }
+            },
             None => {
                 return Err(SdpParserInternalError::Unsupported(
                     format!("The rtcpfb ack feeback type needs a parameter:").to_string()
                 ))
             }
         },
         &SdpAttributeRtcpFbType::Ccm => match tokens.get(2) {
             Some(x) => match x.as_ref() {
                 "fir" | "tmmbr" | "tstr" | "vbcm"  => x.to_string(),
                 _ => {
                     return Err(SdpParserInternalError::Unsupported(
                         format!("Unknown rtcpfb ccm parameter: {:?}",x).to_string()
                     ))
                 },
-            }
+            },
             None => "".to_string(),
         },
         &SdpAttributeRtcpFbType::Nack => match tokens.get(2) {
             Some(x) => match x.as_ref() {
                 "sli" | "pli" | "rpsi" | "app"  => x.to_string(),
                 _ => {
                     return Err(SdpParserInternalError::Unsupported(
                         format!("Unknown rtcpfb nack parameter: {:?}",x).to_string()
                     ))
                 },
-            }
+            },
             None => "".to_string(),
         },
         &SdpAttributeRtcpFbType::TrrInt => match tokens.get(2) {
             Some(x) => match x {
                 _ if x.parse::<u32>().is_ok() => x.to_string(),
                 _ => {
                     return Err(SdpParserInternalError::Generic(
                         format!("Unknown rtcpfb trr-int parameter: {:?}",x).to_string()
                     ))
                 },
-            }
+            },
             None => {
                     return Err(SdpParserInternalError::Generic(
                         format!("The rtcpfb trr-int feedback type needs a parameter").to_string()
                     ))
             }
         },
         &SdpAttributeRtcpFbType::Remb => match tokens.get(2) {
             Some(x) => match x {
                 _ => {
                     return Err(SdpParserInternalError::Unsupported(
                         format!("Unknown rtcpfb remb parameter: {:?}",x).to_string()
                     ))
                 },
-            }
+            },
+            None => "".to_string(),
+        },
+        &SdpAttributeRtcpFbType::TransCC => match tokens.get(2) {
+            Some(x) => match x {
+                _ => {
+                    return Err(SdpParserInternalError::Unsupported(
+                        format!("Unknown rtcpfb transport-cc parameter: {:?}",x).to_string()
+                    ))
+                },
+            },
             None => "".to_string(),
         }
     };
 
 
     Ok(SdpAttribute::Rtcpfb(SdpAttributeRtcpFb {
                                 payload_type: parse_payload_type(tokens[0])?,
 
--- a/media/webrtc/signaling/src/sdp/rsdparsa/src/error.rs
+++ b/media/webrtc/signaling/src/sdp/rsdparsa/src/error.rs
@@ -1,13 +1,16 @@
 use std::num::ParseIntError;
 use std::net::AddrParseError;
 use std::fmt;
 use std::error;
 use std::error::Error;
+#[cfg(feature = "serialize")]
+use serde::ser::{Serializer, Serialize, SerializeStruct};
+
 
 #[derive(Debug)]
 pub enum SdpParserInternalError {
     Generic(String),
     Unsupported(String),
     Integer(ParseIntError),
     Address(AddrParseError),
 }
@@ -106,16 +109,48 @@ pub enum SdpParserError {
     Unsupported {
         error: SdpParserInternalError,
         line: String,
         line_number: usize,
     },
     Sequence { message: String, line_number: usize },
 }
 
+#[cfg(feature = "serialize")]
+impl Serialize for SdpParserError {
+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
+        let mut state = serializer.serialize_struct("error", match self {
+            &SdpParserError::Sequence{..} => 3,
+            _ => 4
+        })?;
+        match self {
+            &SdpParserError::Line {ref error, ref line, ..} => {
+                state.serialize_field("type", "Line")?;
+                state.serialize_field("message", &format!("{}", error))?;
+                state.serialize_field("line", &line)?
+            },
+            &SdpParserError::Unsupported {ref error, ref line, ..} => {
+                state.serialize_field("type", "Unsupported")?;
+                state.serialize_field("message", &format!("{}", error))?;
+                state.serialize_field("line", &line)?
+            },
+            &SdpParserError::Sequence {ref message, ..} => {
+                state.serialize_field("type", "Sequence")?;
+                state.serialize_field("message", &message)?;
+            }
+        };
+        state.serialize_field("line_number", &match self {
+            &SdpParserError::Line {line_number, ..} => line_number,
+            &SdpParserError::Unsupported {line_number, ..} => line_number,
+            &SdpParserError::Sequence {line_number, ..} => line_number,
+        })?;
+        state.end()
+    }
+}
+
 impl fmt::Display for SdpParserError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             SdpParserError::Line {
                 ref error,
                 ref line,
                 ref line_number,
             } => {
--- a/media/webrtc/signaling/src/sdp/rsdparsa/src/lib.rs
+++ b/media/webrtc/signaling/src/sdp/rsdparsa/src/lib.rs
@@ -1,10 +1,16 @@
 #![cfg_attr(feature="clippy", feature(plugin))]
 
+#[cfg(feature="serialize")]
+#[macro_use]
+extern crate serde_derive;
+#[cfg(feature="serialize")]
+extern crate serde;
+
 use std::net::IpAddr;
 use std::fmt;
 
 pub mod attribute_type;
 pub mod error;
 pub mod media_type;
 pub mod network;
 pub mod unsupported_types;
@@ -12,31 +18,34 @@ pub mod unsupported_types;
 use attribute_type::{SdpAttribute, SdpAttributeType, parse_attribute};
 use error::{SdpParserInternalError, SdpParserError};
 use media_type::{SdpMedia, SdpMediaLine, parse_media, parse_media_vector};
 use network::{parse_addrtype, parse_nettype, parse_unicast_addr};
 use unsupported_types::{parse_email, parse_information, parse_key, parse_phone, parse_repeat,
                         parse_uri, parse_zone};
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpBandwidth {
     As(u32),
     Ct(u32),
     Tias(u32),
     Unknown(String, u32),
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpConnection {
     pub addr: IpAddr,
     pub ttl: Option<u8>,
     pub amount: Option<u32>,
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpOrigin {
     pub username: String,
     pub session_id: u64,
     pub session_version: u64,
     pub unicast_addr: IpAddr,
 }
 
 impl fmt::Display for SdpOrigin {
@@ -46,21 +55,23 @@ impl fmt::Display for SdpOrigin {
                self.username,
                self.session_id,
                self.session_version,
                self.unicast_addr)
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpTiming {
     pub start: u64,
     pub stop: u64,
 }
 
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpType {
     Attribute(SdpAttribute),
     Bandwidth(SdpBandwidth),
     Connection(SdpConnection),
     Email(String),
     Information(String),
     Key(String),
     Media(SdpMediaLine),
@@ -69,21 +80,23 @@ pub enum SdpType {
     Repeat(String),
     Session(String),
     Timing(SdpTiming),
     Uri(String),
     Version(u64),
     Zone(String),
 }
 
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpLine {
     pub line_number: usize,
     pub sdp_type: SdpType,
 }
 
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpSession {
     pub version: u64,
     pub origin: SdpOrigin,
     pub session: String,
     pub connection: Option<SdpConnection>,
     pub bandwidth: Vec<SdpBandwidth>,
     pub timing: Option<SdpTiming>,
     pub attribute: Vec<SdpAttribute>,
--- a/media/webrtc/signaling/src/sdp/rsdparsa/src/media_type.rs
+++ b/media/webrtc/signaling/src/sdp/rsdparsa/src/media_type.rs
@@ -1,23 +1,25 @@
 use std::fmt;
 use {SdpType, SdpLine, SdpBandwidth, SdpConnection};
 use attribute_type::{SdpAttribute, SdpAttributeType, SdpAttributeRtpmap};
 use error::{SdpParserError, SdpParserInternalError};
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpMediaLine {
     pub media: SdpMediaValue,
     pub port: u32,
     pub port_count: u32,
     pub proto: SdpProtocolValue,
     pub formats: SdpFormatList,
 }
 
 #[derive(Clone,Debug,PartialEq)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpMediaValue {
     Audio,
     Video,
     Application,
 }
 
 impl fmt::Display for SdpMediaValue {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -26,16 +28,17 @@ impl fmt::Display for SdpMediaValue {
             SdpMediaValue::Video => "Video",
             SdpMediaValue::Application => "Application",
         };
         write!(f, "{}", printable)
     }
 }
 
 #[derive(Clone,Debug,PartialEq)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpProtocolValue {
     RtpSavpf,
     UdpTlsRtpSavpf,
     TcpTlsRtpSavpf,
     DtlsSctp,
     UdpDtlsSctp,
     TcpDtlsSctp,
 }
@@ -50,30 +53,32 @@ impl fmt::Display for SdpProtocolValue {
             SdpProtocolValue::UdpDtlsSctp => "Udp/Dtls/Sctp",
             SdpProtocolValue::TcpDtlsSctp => "Tcp/Dtls/Sctp",
         };
         write!(f, "{}", printable)
     }
 }
 
 #[derive(Clone)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub enum SdpFormatList {
     Integers(Vec<u32>),
     Strings(Vec<String>),
 }
 
 impl fmt::Display for SdpFormatList {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             SdpFormatList::Integers(ref x) => write!(f, "{:?}", x),
             SdpFormatList::Strings(ref x) => write!(f, "{:?}", x),
         }
     }
 }
 
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub struct SdpMedia {
     media: SdpMediaLine,
     connection: Option<SdpConnection>,
     bandwidth: Vec<SdpBandwidth>,
     attribute: Vec<SdpAttribute>,
     // unsupported values:
     // information: Option<String>,
     // key: Option<String>,
@@ -186,16 +191,17 @@ impl SdpMedia {
                                .to_string(),
                        ));
         }
         Ok(self.connection = Some(c.clone()))
     }
 }
 
 #[cfg(test)]
+#[cfg_attr(feature="serialize", derive(Serialize))]
 pub fn create_dummy_media_section() -> SdpMedia {
     let media_line = SdpMediaLine {
         media: SdpMediaValue::Audio,
         port: 9,
         port_count: 0,
         proto: SdpProtocolValue::RtpSavpf,
         formats: SdpFormatList::Integers(Vec::new()),
     };