From 57c2eeadfcb717737cb52827f018ca4237146174 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 3 Aug 2024 19:50:53 +0200 Subject: [PATCH] xmpp-parsers: Convert Jingle RTP to xso --- parsers/src/jingle_rtp.rs | 114 +++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/parsers/src/jingle_rtp.rs b/parsers/src/jingle_rtp.rs index 03eb3a97..2a657044 100644 --- a/parsers/src/jingle_rtp.rs +++ b/parsers/src/jingle_rtp.rs @@ -17,38 +17,42 @@ use crate::ns; #[xml(namespace = ns::JINGLE_RTP, name = "rtcp-mux")] pub struct RtcpMux; -generate_element!( - /// Wrapper element describing an RTP session. - Description, "description", JINGLE_RTP, - attributes: [ - /// Namespace of the encryption scheme used. - media: Required = "media", +/// Wrapper element describing an RTP session. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::JINGLE_RTP, name = "description")] +pub struct Description { + /// Namespace of the encryption scheme used. + #[xml(attribute)] + pub media: String, - /// User-friendly name for the encryption scheme, should be `None` for OTR, - /// legacy OpenPGP and OX. - // XXX: is this a String or an u32?! Refer to RFC 3550. - ssrc: Option = "ssrc", - ], - children: [ - /// List of encodings that can be used for this RTP stream. - payload_types: Vec = ("payload-type", JINGLE_RTP) => PayloadType, + /// User-friendly name for the encryption scheme, should be `None` for OTR, + /// legacy OpenPGP and OX. + // XXX: is this a String or an u32?! Refer to RFC 3550. + #[xml(attribute(default))] + pub ssrc: Option, - /// Specifies the ability to multiplex RTP Data and Control Packets on a single port as - /// described in RFC 5761. - rtcp_mux: Option = ("rtcp-mux", JINGLE_RTP) => RtcpMux, + /// List of encodings that can be used for this RTP stream. + #[xml(child(n = ..))] + pub payload_types: Vec, - /// List of ssrc-group. - ssrc_groups: Vec = ("ssrc-group", JINGLE_SSMA) => Group, + /// Specifies the ability to multiplex RTP Data and Control Packets on a single port as + /// described in RFC 5761. + #[xml(child(default))] + pub rtcp_mux: Option, - /// List of ssrc. - ssrcs: Vec = ("source", JINGLE_SSMA) => Source, + /// List of ssrc-group. + #[xml(child(n = ..))] + pub ssrc_groups: Vec, - /// List of header extensions. - hdrexts: Vec = ("rtp-hdrext", JINGLE_RTP_HDREXT) => RtpHdrext + /// List of ssrc. + #[xml(child(n = ..))] + pub ssrcs: Vec, - // TODO: Add support for and . - ] -); + /// List of header extensions. + #[xml(child(n = ..))] + pub hdrexts: Vec, + // TODO: Add support for and . +} impl Description { /// Create a new RTP description. @@ -73,38 +77,44 @@ generate_attribute!( Default = 1 ); -generate_element!( - /// An encoding that can be used for an RTP stream. - PayloadType, "payload-type", JINGLE_RTP, - attributes: [ - /// The number of channels. - channels: Default = "channels", +/// An encoding that can be used for an RTP stream. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::JINGLE_RTP, name = "payload-type")] +pub struct PayloadType { + /// The number of channels. + #[xml(attribute(default))] + pub channels: Channels, - /// The sampling frequency in Hertz. - clockrate: Option = "clockrate", + /// The sampling frequency in Hertz. + #[xml(attribute(default))] + pub clockrate: Option, - /// The payload identifier. - id: Required = "id", + /// The payload identifier. + #[xml(attribute)] + pub id: u8, - /// Maximum packet time as specified in RFC 4566. - maxptime: Option = "maxptime", + /// Maximum packet time as specified in RFC 4566. + #[xml(attribute(default))] + pub maxptime: Option, - /// The appropriate subtype of the MIME type. - name: Option = "name", + /// The appropriate subtype of the MIME type. + #[xml(attribute(default))] + pub name: Option, - /// Packet time as specified in RFC 4566. - ptime: Option = "ptime", - ], - children: [ - /// List of parameters specifying this payload-type. - /// - /// Their order MUST be ignored. - parameters: Vec = ("parameter", JINGLE_RTP) => Parameter, + /// Packet time as specified in RFC 4566. + #[xml(attribute(default))] + pub ptime: Option, - /// List of rtcp-fb parameters from XEP-0293. - rtcp_fbs: Vec = ("rtcp-fb", JINGLE_RTCP_FB) => RtcpFb - ] -); + /// List of parameters specifying this payload-type. + /// + /// Their order MUST be ignored. + #[xml(child(n = ..))] + pub parameters: Vec, + + /// List of rtcp-fb parameters from XEP-0293. + #[xml(child(n = ..))] + pub rtcp_fbs: Vec, +} impl PayloadType { /// Create a new RTP payload-type.