QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RtpPacketCounter.h
Go to the documentation of this file.
1#pragma once
2
3#include <bitset>
4#include <optional>
5
6#include <QtCore/QtTypes>
7
25{
26public:
29 static constexpr int kDefaultMaxDropout = 3000;
32 static constexpr int kMaxDropoutSeconds = 10;
33 static constexpr int kMinDropout = 30;
37 static constexpr int kReorderWindow = 1024;
38
40 explicit RtpPacketCounter(int clockRate);
41
44 void add(quint16 sequence, quint32 timestamp, quint32 ssrc, std::optional<qint64> arrivalNs);
45
46 quint64 packetsReceived() const { return _receivedBefore + _received; }
47
49 quint64 packetsLost() const { return _lostBefore + _sequenceLost(); }
50
52 std::optional<qint64> jitterNs() const { return _jitterNs; }
53
54private:
55 void _startSequence(quint16 sequence, quint32 ssrc);
58 bool _continueSequence(quint16 sequence, quint32 ssrc);
59 quint64 _sequenceLost() const;
60 qint64 _maxDropout() const;
61 void _notePacketRate(quint32 timestamp);
62 void _noteArrival(quint32 timestamp, qint64 arrivalNs);
63
64 const int _clockRate;
65
67 std::optional<quint32> _ssrc = std::nullopt;
69 qint64 _baseSeq = 0;
70 qint64 _maxSeq = 0;
72 quint64 _received = 0;
74 std::bitset<kReorderWindow> _seen;
75
76 struct Restart
77 {
78 quint32 ssrc;
79 quint16 sequence;
80 };
81
84 std::optional<Restart> _restart = std::nullopt;
85
87 qint64 _packetRate = 0;
89 std::optional<qint64> _rateSeq = std::nullopt;
90 quint32 _rateTimestamp = 0;
91
93 quint64 _receivedBefore = 0;
94 quint64 _lostBefore = 0;
95
97 std::optional<qint64> _lastArrivalNs = std::nullopt;
98 quint32 _lastTimestamp = 0;
99 std::optional<qint64> _jitterNs = std::nullopt;
100};
static constexpr int kMinDropout
quint64 packetsReceived() const
quint64 packetsLost() const
Shrinks when a packet counted as lost arrives late.
RtpPacketCounter(int clockRate)
clockRate: of the RTP timestamps, in Hz. Jitter is measured only with one.
static constexpr int kDefaultMaxDropout
std::optional< qint64 > jitterNs() const
The interarrival jitter (RFC 3550 appendix A.8): nullopt until two packets of a sequence had arrival ...
void add(quint16 sequence, quint32 timestamp, quint32 ssrc, std::optional< qint64 > arrivalNs)
static constexpr int kMaxDropoutSeconds
static constexpr int kReorderWindow