Skip to main content

StreamStats

Struct StreamStats 

Source
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

Source

pub fn new(ssrc: u32) -> Self

Statistics for one source.

Source

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.

Source

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.

Source

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.

Source

pub fn extended_highest_sequence(&self) -> u32

The highest sequence number seen, with its wrap count.

Source

pub fn expected(&self) -> u64

How many packets should have arrived.

Source

pub fn cumulative_lost(&self) -> i64

How many never did. Signed, because duplicates can make it negative.

Source

pub fn jitter(&self) -> u32

The current jitter estimate, in timestamp units.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for StreamStats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.