From d07dcedf8f9601fda14f79ebfbcf858d3794c16c Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 22 Feb 2025 22:15:44 +0100 Subject: progress on rtcp --- rtp/src/rtcp.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 13 deletions(-) (limited to 'rtp/src/rtcp.rs') 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, } pub struct SourceDescription { - sources: Vec<(SSRC, Vec)>, + 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, @@ -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); + } } } } -- cgit v1.2.3-70-g09d2