|
| 1 | +use super::*; |
| 2 | + |
| 3 | +/// DLRRReportBlock encodes a DLRR Report Block as described in |
| 4 | +/// RFC 3611 section 4.5. |
| 5 | +/// |
| 6 | +/// 0 1 2 3 |
| 7 | +/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 8 | +/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 9 | +/// | BT=5 | reserved | block length | |
| 10 | +/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
| 11 | +/// | SSRC_1 (ssrc of first receiver) | sub- |
| 12 | +/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block |
| 13 | +/// | last RR (LRR) | 1 |
| 14 | +/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 15 | +/// | delay since last RR (DLRR) | |
| 16 | +/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
| 17 | +/// | SSRC_2 (ssrc of second receiver) | sub- |
| 18 | +/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block |
| 19 | +/// : ... : 2 |
| 20 | +/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
| 21 | +#[derive(Debug, Default, PartialEq, Clone)] |
| 22 | +pub struct DLRRReportBlock { |
| 23 | + pub xr_header: XRHeader, |
| 24 | + pub reports: Vec<DLRRReport>, |
| 25 | +} |
| 26 | + |
| 27 | +impl fmt::Display for DLRRReportBlock { |
| 28 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 29 | + write!(f, "{:?}", self) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +/// DLRRReport encodes a single report inside a DLRRReportBlock. |
| 34 | +#[derive(Debug, Default, PartialEq, Clone)] |
| 35 | +pub struct DLRRReport { |
| 36 | + pub ssrc: u32, |
| 37 | + pub last_rr: u32, |
| 38 | + pub dlrr: u32, |
| 39 | +} |
| 40 | + |
| 41 | +impl fmt::Display for DLRRReport { |
| 42 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 43 | + write!(f, "{:?}", self) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +impl ReportBlock for DLRRReportBlock { |
| 48 | + /// destination_ssrc returns an array of ssrc values that this report block refers to. |
| 49 | + fn destination_ssrc(&self) -> Vec<u32> { |
| 50 | + let mut ssrc = Vec::with_capacity(self.reports.len()); |
| 51 | + for r in &self.reports { |
| 52 | + ssrc.push(r.ssrc); |
| 53 | + } |
| 54 | + ssrc |
| 55 | + } |
| 56 | + |
| 57 | + fn setup_block_header(&mut self) { |
| 58 | + self.xr_header.block_type = ReportBlockType::DLRR; |
| 59 | + self.xr_header.type_specific = 0; |
| 60 | + self.xr_header.block_length = (self.raw_size() / 4 - 1) as u16; |
| 61 | + } |
| 62 | + |
| 63 | + fn unpack_block_header(&mut self) {} |
| 64 | + |
| 65 | + fn raw_size(&self) -> usize { |
| 66 | + 4 + self.reports.len() * 4 * 3 |
| 67 | + } |
| 68 | + |
| 69 | + fn as_any(&self) -> &(dyn Any + Send + Sync) { |
| 70 | + self |
| 71 | + } |
| 72 | + fn equal(&self, other: &(dyn ReportBlock + Send + Sync)) -> bool { |
| 73 | + other |
| 74 | + .as_any() |
| 75 | + .downcast_ref::<DLRRReportBlock>() |
| 76 | + .map_or(false, |a| self == a) |
| 77 | + } |
| 78 | + fn cloned(&self) -> Box<dyn ReportBlock + Send + Sync> { |
| 79 | + Box::new(self.clone()) |
| 80 | + } |
| 81 | +} |
0 commit comments