webrtc_rtp_stats (webrtc v0.1.0)
View SourceRTP receiver and sender statistics (RFC 3550 §6.4, Appendix A).
Receiver side, one state per remote source:
rx_packet/4runs the sequence number validation of Appendix A.1 (probation ofmin_sequentialpackets,max_dropout,max_misorder, 16-bit cycle counting) and, for packets it accepts, the interarrival jitter estimate of Appendix A.8.report_block/2builds a reception report block with the cumulative and interval loss of Appendix A.3 and LSR / DLSR from the last SR passed torx_sender_report/3.
Times (Now) are integers in time_unit ticks per second (default 1000, i.e. milliseconds) on any monotonic clock. The jitter needs the media clock rate.
Sender side: tx_packet/2 counts packets and payload octets for the SR sender info (§6.4.1); sender_report/5 builds the SR.
rtt/3 computes the round-trip time from a report block's LSR and DLSR (§6.4.1) or an XR DLRR sub-block (RFC 3611 §4.5). NTP helpers convert between Unix microseconds and 64-bit NTP timestamps.
Summary
Functions
64-bit NTP timestamp from microseconds since the Unix epoch.
The middle 32 bits of a 64-bit NTP timestamp (LSR format).
Microseconds since the Unix epoch from a 64-bit NTP timestamp (era 0).
Build a reception report block and start a new reporting interval (Appendix A.3).
Round-trip time in microseconds from the LSR and DLSR of a report block (or the LRR and DLRR of an XR DLRR sub-block) and the 64-bit NTP time at which the report arrived: A - LSR - DLSR in 1/65536 s (RFC 3550 §6.4.1). undefined when LSR is 0 (no SR received yet by the reporter). A negative result, caused by clock drift, is reported as 0.
Current receiver statistics. jitter is in RTP timestamp units.
New receiver state for Ssrc. Defaults are the values of RFC 3550 Appendix A.1: min_sequential 2, max_dropout 3000, max_misorder 100.
Account for a received packet. Returns valid when Appendix A.1 accepts the sequence number (the packet can be delivered) and invalid during probation or after a large jump.
Remember an SR received from this source, for LSR and DLSR.
Build an SR. RtpTs is the RTP timestamp corresponding to the same instant as Ntp. Counts wrap modulo 2^32 as on the wire.
Count one sent RTP packet carrying PayloadOctets octets of payload (header and padding excluded, RFC 3550 §6.4.1).
Types
-type rtcp_u32() :: 0..4294967295.
-opaque rx()
-type rx_opts() :: #{clock_rate := pos_integer(), time_unit => pos_integer(), min_sequential => non_neg_integer(), max_dropout => pos_integer(), max_misorder => pos_integer()}.
-opaque tx()
Functions
-spec ntp_from_us(non_neg_integer()) -> 0..18446744073709551615.
64-bit NTP timestamp from microseconds since the Unix epoch.
-spec ntp_middle(0..18446744073709551615) -> 0..4294967295.
The middle 32 bits of a 64-bit NTP timestamp (LSR format).
-spec ntp_to_us(0..18446744073709551615) -> integer().
Microseconds since the Unix epoch from a 64-bit NTP timestamp (era 0).
-spec report_block(integer(), rx()) -> {#rtcp_rb{ssrc :: rtcp_u32(), fraction_lost :: 0..255, lost :: -8388608..8388607, ext_seq :: rtcp_u32(), jitter :: rtcp_u32(), lsr :: rtcp_u32(), dlsr :: rtcp_u32()}, rx()}.
Build a reception report block and start a new reporting interval (Appendix A.3).
-spec rtt(0..4294967295, 0..4294967295, 0..18446744073709551615) -> {ok, non_neg_integer()} | undefined.
Round-trip time in microseconds from the LSR and DLSR of a report block (or the LRR and DLRR of an XR DLRR sub-block) and the 64-bit NTP time at which the report arrived: A - LSR - DLSR in 1/65536 s (RFC 3550 §6.4.1). undefined when LSR is 0 (no SR received yet by the reporter). A negative result, caused by clock drift, is reported as 0.
-spec rx_info(rx()) -> #{ssrc := 0..4294967295, valid := boolean(), received := non_neg_integer(), expected := integer(), lost := integer(), ext_max_seq := non_neg_integer(), cycles := non_neg_integer(), jitter := non_neg_integer()}.
Current receiver statistics. jitter is in RTP timestamp units.
New receiver state for Ssrc. Defaults are the values of RFC 3550 Appendix A.1: min_sequential 2, max_dropout 3000, max_misorder 100.
Account for a received packet. Returns valid when Appendix A.1 accepts the sequence number (the packet can be delivered) and invalid during probation or after a large jump.
-spec rx_sender_report(#rtcp_sr{ssrc :: rtcp_u32(), ntp :: 0..18446744073709551615, rtp_ts :: rtcp_u32(), packets :: rtcp_u32(), octets :: rtcp_u32(), reports :: [#rtcp_rb{ssrc :: rtcp_u32(), fraction_lost :: 0..255, lost :: -8388608..8388607, ext_seq :: rtcp_u32(), jitter :: rtcp_u32(), lsr :: rtcp_u32(), dlsr :: rtcp_u32()}], ext :: binary()}, integer(), rx()) -> rx().
Remember an SR received from this source, for LSR and DLSR.
-spec sender_report(0..4294967295, 0..18446744073709551615, 0..4294967295, tx(), [#rtcp_rb{ssrc :: rtcp_u32(), fraction_lost :: 0..255, lost :: -8388608..8388607, ext_seq :: rtcp_u32(), jitter :: rtcp_u32(), lsr :: rtcp_u32(), dlsr :: rtcp_u32()}]) -> #rtcp_sr{ssrc :: rtcp_u32(), ntp :: 0..18446744073709551615, rtp_ts :: rtcp_u32(), packets :: rtcp_u32(), octets :: rtcp_u32(), reports :: [#rtcp_rb{ssrc :: rtcp_u32(), fraction_lost :: 0..255, lost :: -8388608..8388607, ext_seq :: rtcp_u32(), jitter :: rtcp_u32(), lsr :: rtcp_u32(), dlsr :: rtcp_u32()}], ext :: binary()}.
Build an SR. RtpTs is the RTP timestamp corresponding to the same instant as Ntp. Counts wrap modulo 2^32 as on the wire.
-spec tx_info(tx()) -> #{packets := non_neg_integer(), octets := non_neg_integer()}.
-spec tx_new() -> tx().
-spec tx_packet(non_neg_integer(), tx()) -> tx().
Count one sent RTP packet carrying PayloadOctets octets of payload (header and padding excluded, RFC 3550 §6.4.1).