QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RtpPacketCounter Class Reference

Counts one RTP stream's packets from their headers, as RFC 3550 (appendix A.1) has a receiver do, for a stream that no jitter buffer counts. More...

#include <RtpPacketCounter.h>

Public Member Functions

 RtpPacketCounter (int clockRate)
 clockRate: of the RTP timestamps, in Hz. Jitter is measured only with one.
void add (quint16 sequence, quint32 timestamp, quint32 ssrc, std::optional< qint64 > arrivalNs)
quint64 packetsReceived () const
quint64 packetsLost () const
 Shrinks when a packet counted as lost arrives late.
std::optional< qint64 > jitterNs () const
 The interarrival jitter (RFC 3550 appendix A.8): nullopt until two packets of a sequence had arrival times.

Static Public Attributes

static constexpr int kDefaultMaxDropout = 3000
static constexpr int kMaxDropoutSeconds = 10
static constexpr int kMinDropout = 30
static constexpr int kReorderWindow = 1024

Detailed Description

Counts one RTP stream's packets from their headers, as RFC 3550 (appendix A.1) has a receiver do, for a stream that no jitter buffer counts.

Lost packets are the sequence numbers missing between the first packet and the highest one, across the 16-bit wraparounds. A packet that arrives late is therefore no longer lost, and one that arrives twice counts once, both as far back as kReorderWindow packets.

A sender that starts over begins a new sequence: with another SSRC, or with sequence numbers too far from the last ones to be loss or reordering. Either way it starts with the second packet that goes on from the first, so a single stray packet changes nothing. The totals go on across sequences, without the packets lost between them, which nothing tells.

How far ahead is too far for loss follows the sender's packet rate, measured from the RTP timestamps: what it sends in kMaxDropoutSeconds, as rtpbin does (its "max-dropout-time").

Not thread-safe: the thread the packets arrive on adds them.

Definition at line 24 of file RtpPacketCounter.h.

Constructor & Destructor Documentation

◆ RtpPacketCounter()

RtpPacketCounter::RtpPacketCounter ( int clockRate)
explicit

clockRate: of the RTP timestamps, in Hz. Jitter is measured only with one.

Definition at line 19 of file RtpPacketCounter.cc.

Member Function Documentation

◆ add()

void RtpPacketCounter::add ( quint16 sequence,
quint32 timestamp,
quint32 ssrc,
std::optional< qint64 > arrivalNs )

One packet, in arrival order: the sequence number, timestamp and SSRC of its header, and when it arrived on a monotonic clock, if known.

Definition at line 23 of file RtpPacketCounter.cc.

◆ jitterNs()

std::optional< qint64 > RtpPacketCounter::jitterNs ( ) const
inline

The interarrival jitter (RFC 3550 appendix A.8): nullopt until two packets of a sequence had arrival times.

Definition at line 52 of file RtpPacketCounter.h.

◆ packetsLost()

quint64 RtpPacketCounter::packetsLost ( ) const
inline

Shrinks when a packet counted as lost arrives late.

Definition at line 49 of file RtpPacketCounter.h.

◆ packetsReceived()

quint64 RtpPacketCounter::packetsReceived ( ) const
inline

Definition at line 46 of file RtpPacketCounter.h.

Member Data Documentation

◆ kDefaultMaxDropout

int RtpPacketCounter::kDefaultMaxDropout = 3000
staticconstexpr

A packet this far ahead of the highest sequence number, or further, isn't the next one after a loss (RFC 3550's MAX_DROPOUT), while the packet rate isn't known: before a second of the stream, and without a clock rate.

Definition at line 29 of file RtpPacketCounter.h.

◆ kMaxDropoutSeconds

int RtpPacketCounter::kMaxDropoutSeconds = 10
staticconstexpr

With a packet rate, that is as many packets as the sender sends in this time, but kMinDropout at least. A receiver gives up on a stream that is silent for a few seconds, well before this.

Definition at line 32 of file RtpPacketCounter.h.

◆ kMinDropout

int RtpPacketCounter::kMinDropout = 30
staticconstexpr

Definition at line 33 of file RtpPacketCounter.h.

◆ kReorderWindow

int RtpPacketCounter::kReorderWindow = 1024
staticconstexpr

A packet less than this far behind the highest sequence number is a late one or a duplicate, which the packets seen there tell apart. RFC 3550's MAX_MISORDER, 100, is for audio's tens of packets a second, where video sends hundreds to thousands.

Definition at line 37 of file RtpPacketCounter.h.


The documentation for this class was generated from the following files: