Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 7700878

Browse files
author
Rain Liu
committed
add rrt
1 parent e359327 commit 7700878

File tree

2 files changed

+72
-17
lines changed

2 files changed

+72
-17
lines changed

src/extended_report/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ mod extended_report_test;
33

44
pub mod dlrr;
55
pub mod prt;
6-
pub mod rle; /*
7-
pub mod rrt;
8-
pub mod ssr;
9-
pub mod vm;*/
6+
pub mod rle;
7+
pub mod rrt;
8+
/*pub mod ssr;
9+
pub mod vm;*/
1010
pub mod unknown;
1111

1212
pub use unknown::UnknownReportBlock;

src/extended_report/rrt.rs

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::*;
22

3+
const RRT_REPORT_BLOCK_MIN_LENGTH: u16 = 8;
4+
35
/// ReceiverReferenceTimeReportBlock encodes a Receiver Reference Time
46
/// report block as described in RFC 3611 section 4.4.
57
///
@@ -14,7 +16,6 @@ use super::*;
1416
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1517
#[derive(Debug, Default, PartialEq, Clone)]
1618
pub struct ReceiverReferenceTimeReportBlock {
17-
pub xr_header: XRHeader,
1819
pub ntp_timestamp: u64,
1920
}
2021

@@ -24,34 +25,88 @@ impl fmt::Display for ReceiverReferenceTimeReportBlock {
2425
}
2526
}
2627

27-
impl ReportBlock for ReceiverReferenceTimeReportBlock {
28-
/// destination_ssrc returns an array of ssrc values that this report block refers to.
29-
fn destination_ssrc(&self) -> Vec<u32> {
30-
vec![]
28+
impl ReceiverReferenceTimeReportBlock {
29+
pub fn xr_header(&self) -> XRHeader {
30+
XRHeader {
31+
block_type: BlockType::ReceiverReferenceTime,
32+
type_specific: 0,
33+
block_length: (self.raw_size() / 4 - 1) as u16,
34+
}
3135
}
36+
}
3237

33-
fn setup_block_header(&mut self) {
34-
self.xr_header.block_type = ReportBlockType::ReceiverReferenceTime;
35-
self.xr_header.type_specific = 0;
36-
self.xr_header.block_length = (self.raw_size() / 4 - 1) as u16;
38+
impl Packet for ReceiverReferenceTimeReportBlock {
39+
fn header(&self) -> Header {
40+
Header::default()
3741
}
3842

39-
fn unpack_block_header(&mut self) {}
43+
/// destination_ssrc returns an array of ssrc values that this report block refers to.
44+
fn destination_ssrc(&self) -> Vec<u32> {
45+
vec![]
46+
}
4047

4148
fn raw_size(&self) -> usize {
42-
4 + 8
49+
XR_HEADER_LENGTH + RRT_REPORT_BLOCK_MIN_LENGTH as usize
4350
}
4451

4552
fn as_any(&self) -> &(dyn Any + Send + Sync) {
4653
self
4754
}
48-
fn equal(&self, other: &(dyn ReportBlock + Send + Sync)) -> bool {
55+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
4956
other
5057
.as_any()
5158
.downcast_ref::<ReceiverReferenceTimeReportBlock>()
5259
.map_or(false, |a| self == a)
5360
}
54-
fn cloned(&self) -> Box<dyn ReportBlock + Send + Sync> {
61+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
5562
Box::new(self.clone())
5663
}
5764
}
65+
66+
impl MarshalSize for ReceiverReferenceTimeReportBlock {
67+
fn marshal_size(&self) -> usize {
68+
self.raw_size()
69+
}
70+
}
71+
72+
impl Marshal for ReceiverReferenceTimeReportBlock {
73+
/// marshal_to encodes the PacketReceiptTimesReportBlock in binary
74+
fn marshal_to(&self, mut buf: &mut [u8]) -> Result<usize> {
75+
if buf.remaining_mut() < self.marshal_size() {
76+
return Err(error::Error::BufferTooShort.into());
77+
}
78+
79+
let h = self.xr_header();
80+
let n = h.marshal_to(buf)?;
81+
buf = &mut buf[n..];
82+
83+
buf.put_u64(self.ntp_timestamp);
84+
85+
Ok(self.marshal_size())
86+
}
87+
}
88+
89+
impl Unmarshal for ReceiverReferenceTimeReportBlock {
90+
/// Unmarshal decodes the PacketReceiptTimesReportBlock from binary
91+
fn unmarshal<B>(raw_packet: &mut B) -> Result<Self>
92+
where
93+
Self: Sized,
94+
B: Buf,
95+
{
96+
if raw_packet.remaining() < XR_HEADER_LENGTH {
97+
return Err(error::Error::PacketTooShort.into());
98+
}
99+
100+
let xr_header = XRHeader::unmarshal(raw_packet)?;
101+
102+
if xr_header.block_length != RRT_REPORT_BLOCK_MIN_LENGTH
103+
|| raw_packet.remaining() < xr_header.block_length as usize
104+
{
105+
return Err(error::Error::PacketTooShort.into());
106+
}
107+
108+
let ntp_timestamp = raw_packet.get_u64();
109+
110+
Ok(ReceiverReferenceTimeReportBlock { ntp_timestamp })
111+
}
112+
}

0 commit comments

Comments
 (0)