diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-07 01:02:10 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-07 01:02:10 +0200 |
commit | 461cb3b26169562868f46311612b3a61759823ff (patch) | |
tree | 785310c352996260e763977efe4b5ff7f38eaf39 | |
parent | 5f1a995ac4d0965135a297d3c2cb8c2712765e2c (diff) | |
download | sip-rs-461cb3b26169562868f46311612b3a61759823ff.tar sip-rs-461cb3b26169562868f46311612b3a61759823ff.tar.bz2 sip-rs-461cb3b26169562868f46311612b3a61759823ff.tar.zst |
sdp ser
-rw-r--r-- | rtp/src/lib.rs | 24 | ||||
-rw-r--r-- | sdp/src/lib.rs | 89 |
2 files changed, 111 insertions, 2 deletions
diff --git a/rtp/src/lib.rs b/rtp/src/lib.rs index b28b04f..68ca10d 100644 --- a/rtp/src/lib.rs +++ b/rtp/src/lib.rs @@ -1,3 +1,27 @@ +pub struct RtpPacket<'a> { + marked: bool, + payload_type: u8, + extension: Option<(u16, &'a [u8])>, + payload: Option<&'a [u8]>, + sequence: u16, + timestamp: u32, + ssrc: u32, + csrc_count: u8, + csrcs: [u32; 15], +} + +impl<'a> RtpPacket<'a> { + pub fn parse(packet: &'a [u8]) -> RtpPacket<'a> { + todo!() + } + pub fn write(&self, out: &mut Vec<u8>) { + out.push(self.csrc_count | (2 << 6) | 0); // TODO + out.push(self.payload_type | (self.marked as u8 * 0x80)); + out.extend(self.sequence.to_be_bytes()); + out.extend(self.timestamp.to_be_bytes()); + out.extend(self.ssrc.to_be_bytes()); + } +} diff --git a/sdp/src/lib.rs b/sdp/src/lib.rs index 68c3c70..15b4ce2 100644 --- a/sdp/src/lib.rs +++ b/sdp/src/lib.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, bail}; -use std::str::FromStr; +use std::{fmt::Display, str::FromStr}; pub struct SessionDescription { pub version: String, @@ -72,7 +72,7 @@ impl FromStr for SessionDescription { "m" => media_descriptions.push(MediaDescription { connection_information: None, name: value.to_string(), - title: None, + title: None, // TODO never set, forgot it somewhere encryption_key: None, attributes: Vec::new(), bandwidth: Vec::new(), @@ -126,3 +126,88 @@ impl FromStr for SessionDescription { }) } } + +impl Display for SessionDescription { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { + attributes, + bandwidth, + connection_information, + description_uri, + email_address, + encryption_key, + media_descriptions, + originator, + phone_number, + session_information, + session_name, + time_descriptions, + time_zone_adjustments, + version, + } = self; + writeln!(f, "v={version}")?; + writeln!(f, "o={originator}")?; + writeln!(f, "s={session_name}")?; + // TODO check order + if let Some(session_information) = session_information { + writeln!(f, "i={session_information}")?; + } + if let Some(description_uri) = description_uri { + writeln!(f, "u={description_uri}")?; + } + if let Some(email_address) = email_address { + writeln!(f, "e={email_address}")?; + } + if let Some(phone_number) = phone_number { + writeln!(f, "p={phone_number}")?; + } + for TimeDescription { time, repeat_times } in time_descriptions { + writeln!(f, "t={time}")?; + for repeat_time in repeat_times { + writeln!(f, "r={repeat_time}")?; + } + } + if let Some(encryption_key) = encryption_key { + writeln!(f, "k={encryption_key}")?; + } + if let Some(time_zone_adjustments) = time_zone_adjustments { + writeln!(f, "z={time_zone_adjustments}")?; + } + if let Some(connection_information) = connection_information { + writeln!(f, "c={connection_information}")?; + } + for bandwidth in bandwidth { + writeln!(f, "b={bandwidth}")?; + } + for attribute in attributes { + writeln!(f, "a={attribute}")?; + } + for MediaDescription { + name, + title, + connection_information, + bandwidth, + encryption_key, + attributes, + } in media_descriptions + { + writeln!(f, "m={name}")?; + if let Some(title) = title { + writeln!(f, "t={title}")?; // TODO was offline, check param name + } + if let Some(connection_information) = connection_information { + writeln!(f, "c={connection_information}")?; + } + for bandwidth in bandwidth { + writeln!(f, "b={bandwidth}")?; + } + if let Some(encryption_key) = encryption_key { + writeln!(f, "k={encryption_key}")?; + } + for attribute in attributes { + writeln!(f, "a={attribute}")?; + } + } + Ok(()) + } +} |