From 3ad93f0bf2bdd229aac8f079763e791a311c3624 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 27 Nov 2020 20:50:30 +0100 Subject: [PATCH] xmpp-parsers: Add support for Jingle RTP Header Extensions Negotiation (XEP-0294). --- xmpp-parsers/doap.xml | 9 +++ xmpp-parsers/src/jingle_rtp_hdrext.rs | 86 +++++++++++++++++++++++++++ xmpp-parsers/src/lib.rs | 3 + xmpp-parsers/src/ns.rs | 3 + 4 files changed, 101 insertions(+) create mode 100644 xmpp-parsers/src/jingle_rtp_hdrext.rs diff --git a/xmpp-parsers/doap.xml b/xmpp-parsers/doap.xml index 48c0df9a..96877c3f 100644 --- a/xmpp-parsers/doap.xml +++ b/xmpp-parsers/doap.xml @@ -370,6 +370,15 @@ Only supported in payload-type, and only for rtcp-fb. + + + + partial + 1.0 + NEXT + Parameters aren’t yet implemented. + + diff --git a/xmpp-parsers/src/jingle_rtp_hdrext.rs b/xmpp-parsers/src/jingle_rtp_hdrext.rs new file mode 100644 index 00000000..199b4399 --- /dev/null +++ b/xmpp-parsers/src/jingle_rtp_hdrext.rs @@ -0,0 +1,86 @@ +// Copyright (c) 2020 Emmanuel Gil Peyrot +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +generate_attribute!( + /// Which party is allowed to send the negotiated RTP Header Extensions. + Senders, "senders", { + /// Both parties can send them. + Both => "both", + + /// Only the initiator can send them. + Initiator => "initiator", + + /// Only the responder can send them. + Responder => "responder", + }, Default = Both +); + +generate_element!( + /// Header extensions to be used in a RTP description. + RtpHdrext, "rtp-hdrext", JINGLE_RTP_HDREXT, + attributes: [ + /// The ID of the extensions. + id: Required = "id", + + /// The URI that defines the extension. + uri: Required = "uri", + + /// Which party is allowed to send the negotiated RTP Header Extensions. + senders: Default = "senders", + ] +); + +impl RtpHdrext { + /// Create a new RTP header extension element. + pub fn new(id: String, uri: String) -> RtpHdrext { + RtpHdrext { + id, + uri, + senders: Default::default(), + } + } + + /// Set the senders. + pub fn with_senders(mut self, senders: Senders) -> RtpHdrext { + self.senders = senders; + self + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::Element; + use std::convert::TryFrom; + + #[cfg(target_pointer_width = "32")] + #[test] + fn test_size() { + assert_size!(Senders, 1); + assert_size!(RtpHdrext, 28); + } + + #[cfg(target_pointer_width = "64")] + #[test] + fn test_size() { + assert_size!(Senders, 1); + assert_size!(RtpHdrext, 56); + } + + #[test] + fn parse_exthdr() { + let elem: Element = " + " + .parse() + .unwrap(); + let rtp_hdrext = RtpHdrext::try_from(elem).unwrap(); + assert_eq!(rtp_hdrext.id, "1"); + assert_eq!(rtp_hdrext.uri, "urn:ietf:params:rtp-hdrext:toffset"); + assert_eq!(rtp_hdrext.senders, Senders::Both); + } +} diff --git a/xmpp-parsers/src/lib.rs b/xmpp-parsers/src/lib.rs index 7e6f201c..e65349fe 100644 --- a/xmpp-parsers/src/lib.rs +++ b/xmpp-parsers/src/lib.rs @@ -165,6 +165,9 @@ pub mod carbons; /// XEP-0293: Jingle RTP Feedback Negotiation pub mod jingle_rtcp_fb; +/// XEP-0294: Jingle RTP Header Extensions Negociation +pub mod jingle_rtp_hdrext; + /// XEP-0297: Stanza Forwarding pub mod forwarding; diff --git a/xmpp-parsers/src/ns.rs b/xmpp-parsers/src/ns.rs index a431a3d6..6e4c4a4d 100644 --- a/xmpp-parsers/src/ns.rs +++ b/xmpp-parsers/src/ns.rs @@ -162,6 +162,9 @@ pub const CARBONS: &str = "urn:xmpp:carbons:2"; /// XEP-0293: Jingle RTP Feedback Negotiation pub const JINGLE_RTCP_FB: &str = "urn:xmpp:jingle:apps:rtp:rtcp-fb:0"; +/// XEP-0294: Jingle RTP Header Extensions Negociation +pub const JINGLE_RTP_HDREXT: &str = "urn:xmpp:jingle:apps:rtp:rtp-hdrext:0"; + /// XEP-0297: Stanza Forwarding pub const FORWARD: &str = "urn:xmpp:forward:0";