aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-02-22 22:15:44 +0100
committermetamuffin <metamuffin@disroot.org>2025-02-22 22:15:44 +0100
commitd07dcedf8f9601fda14f79ebfbcf858d3794c16c (patch)
tree8a1d71d9a8bc1791323dd4cf800bf169573eb7bc
parent622ed285b029dfa3b65cc3f13b51c1e0b83262b9 (diff)
downloadsip-rs-d07dcedf8f9601fda14f79ebfbcf858d3794c16c.tar
sip-rs-d07dcedf8f9601fda14f79ebfbcf858d3794c16c.tar.bz2
sip-rs-d07dcedf8f9601fda14f79ebfbcf858d3794c16c.tar.zst
progress on rtcp
-rw-r--r--rtp/src/rtcp.rs70
-rw-r--r--sdp/src/lib.rs3
2 files changed, 60 insertions, 13 deletions
diff --git a/rtp/src/rtcp.rs b/rtp/src/rtcp.rs
index 371aa85..925858f 100644
--- a/rtp/src/rtcp.rs
+++ b/rtp/src/rtcp.rs
@@ -31,17 +31,18 @@ pub struct ReceiverReport {
pub reports: Vec<ReportBlock>,
}
pub struct SourceDescription {
- sources: Vec<(SSRC, Vec<SourceDescriptionItem>)>,
+ pub sources: Vec<(SSRC, Vec<(SdesType, String)>)>,
}
-pub enum SourceDescriptionItem {
- CanonicalName(String),
- Name(String),
- Email(String),
- Phone(String),
- Location(String),
- Tool(String),
- Notice(String),
- PrivateExtension(String),
+#[derive(Debug, Clone, Copy)]
+pub enum SdesType {
+ CanonicalName = 1,
+ Name = 2,
+ Email = 3,
+ Phone = 4,
+ Location = 5,
+ Tool = 6,
+ Notice = 7,
+ PrivateExtension = 8,
}
pub struct Bye<'a> {
pub ssrcs: Vec<SSRC>,
@@ -50,6 +51,7 @@ pub struct Bye<'a> {
pub struct Application<'a> {
pub subtype: u8,
pub name: [u8; 4],
+ pub ssrc: SSRC,
pub data: &'a [u8],
}
pub struct SenderInfo {
@@ -134,11 +136,53 @@ impl<'a> RtcpPacket<'a> {
version << 6 | (padding as u8) << 5 | sender_report.reports.len() as u8,
);
out.push(200);
+ todo!()
+ }
+ RtcpPart::ReceiverReport(receiver_report) => {
+ out.push(
+ version << 6 | (padding as u8) << 5 | receiver_report.reports.len() as u8,
+ );
+ out.push(201);
+ out.extend(((receiver_report.reports.len() * 6 + 1) as u16).to_be_bytes());
+ out.extend(receiver_report.sender_ssrc.0.to_be_bytes());
+ for r in &receiver_report.reports {
+ r.write(out);
+ }
+ }
+ RtcpPart::SourceDescription(source_description) => {
+ out.push(
+ version << 6
+ | (padding as u8) << 5
+ | source_description.sources.len() as u8,
+ );
+ out.push(202);
+ let mut buf = Vec::new();
+
+ for (ssrc, items) in &source_description.sources {
+ buf.extend(ssrc.0.to_be_bytes());
+ for (ty, name) in items {
+ buf.push(*ty as u8);
+ buf.push(name.len() as u8);
+ buf.extend(name.as_bytes());
+ }
+ while buf.len() % 4 != 0 {
+ buf.push(0);
+ }
+ }
+
+ out.extend(((buf.len() / 4) as u16).to_be_bytes());
+ out.extend(buf);
}
- RtcpPart::ReceiverReport(receiver_report) => todo!(),
- RtcpPart::SourceDescription(source_description) => todo!(),
RtcpPart::Bye(bye) => todo!(),
- RtcpPart::Application(application) => todo!(),
+ RtcpPart::Application(application) => {
+ assert!(application.data.len() % 4 == 0, "todo");
+ out.push(version << 6 | (padding as u8) << 5 | application.subtype);
+ out.push(204);
+ out.extend(((application.data.len() / 4 + 2) as u16).to_be_bytes());
+ out.extend(application.ssrc.0.to_be_bytes());
+ out.extend(application.name);
+ out.extend(application.data);
+ }
}
}
}
diff --git a/sdp/src/lib.rs b/sdp/src/lib.rs
index 15b4ce2..dc5623d 100644
--- a/sdp/src/lib.rs
+++ b/sdp/src/lib.rs
@@ -1,6 +1,7 @@
use anyhow::{anyhow, bail};
use std::{fmt::Display, str::FromStr};
+#[derive(Debug, Default)]
pub struct SessionDescription {
pub version: String,
pub originator: String,
@@ -18,11 +19,13 @@ pub struct SessionDescription {
pub media_descriptions: Vec<MediaDescription>,
}
+#[derive(Debug)]
pub struct TimeDescription {
pub time: String,
pub repeat_times: Vec<String>,
}
+#[derive(Debug, Default)]
pub struct MediaDescription {
pub name: String,
pub title: Option<String>,