pub struct StreamStats { /* private fields */ }Expand description
Tracks what a stream looked like from here, so a report can be produced.
The counters are the interesting part. Loss is inferred — nothing announces a lost packet — from the difference between how many sequence numbers went by and how many packets arrived. That is why duplicates can make cumulative loss negative, and why the field is signed.
Implementations§
Source§impl StreamStats
impl StreamStats
Sourcepub fn set_ssrc(&mut self, ssrc: u32)
pub fn set_ssrc(&mut self, ssrc: u32)
Name the source these statistics describe.
The far end chooses its synchronisation source at random (RFC 3550 §8) and announces it only in its first packet, so the statistics can exist before the name does. The name goes into every report block: a block that says SSRC 0 describes nobody.
Sourcepub fn on_packet(&mut self, sequence: u16, rtp_timestamp: u32, arrival: u32)
pub fn on_packet(&mut self, sequence: u16, rtp_timestamp: u32, arrival: u32)
Record an arrival.
arrival is the local clock in the same units as the RTP timestamp — for G.711, 8000
per second. Mixing units here is the other way to make jitter meaningless.
Sourcepub fn on_untimed_packet(&mut self, sequence: u16)
pub fn on_untimed_packet(&mut self, sequence: u16)
Record an arrival whose timestamp does not track its sampling instant.
Telephone events are the case in hand: RFC 4733 §2.5.1.2 gives every packet of one event the timestamp of the event’s start while the packets go out one interval apart, so their transit grows per packet by design. RFC 3550 §6.4.1 defines jitter over packets whose timestamps track sampling instants — these still count for loss and sequence continuity, but must not feed the jitter estimate.
Sourcepub fn extended_highest_sequence(&self) -> u32
pub fn extended_highest_sequence(&self) -> u32
The highest sequence number seen, with its wrap count.
Sourcepub fn cumulative_lost(&self) -> i64
pub fn cumulative_lost(&self) -> i64
How many never did. Signed, because duplicates can make it negative.
Sourcepub fn pending_report_block(&self) -> ReportBlock
pub fn pending_report_block(&self) -> ReportBlock
The block a report would carry right now, leaving the interval open.
This is the one to read to look at the numbers. The interval belongs to the reports
actually sent — RFC 3550 §6.4.1 defines fraction_lost as loss since the previous SR or
RR packet, not since somebody last enquired — so closing it is Self::report_block’s
job and reading is free. M-33: while these were the same function, an application
polling for a live display closed windows nobody was told about, and the next real report
described only what had arrived since the display was drawn.
Sourcepub fn report_block(&mut self) -> ReportBlock
pub fn report_block(&mut self) -> ReportBlock
Produce a report block to send, closing the interval and starting the next.
The fraction is loss since the last report, not since the stream began — a call that
lost heavily at the start and is now clean must report clean, or nobody can see it
recover. That is what the &mut is: only the path that puts the block on the wire may
call this, because a caller that only wants to read the numbers and closes an interval
anyway hides that interval’s loss from the far end for good. Read with
Self::pending_report_block instead.