12 #ifndef hifi_SequenceNumberStats_h
13 #define hifi_SequenceNumberStats_h
15 #include "SharedUtil.h"
16 #include "RingBufferHistory.h"
19 const int MAX_REASONABLE_SEQUENCE_GAP = 1000;
22 class PacketStreamStats {
34 PacketStreamStats operator-(
const PacketStreamStats& rhs)
const {
35 PacketStreamStats diff;
36 diff._received = _received - rhs._received;
37 diff._unreasonable = _unreasonable - rhs._unreasonable;
38 diff._early = _early - rhs._early;
39 diff._late = _late - rhs._late;
40 diff._lost = _lost - rhs._lost;
41 diff._recovered = _recovered - rhs._recovered;
42 diff._expectedReceived = _expectedReceived - rhs._expectedReceived;
46 float getLostRate()
const;
49 quint32 _unreasonable;
54 quint32 _expectedReceived;
57 class SequenceNumberStats {
68 ArrivalStatus _status;
69 int _seqDiffFromExpected;
73 SequenceNumberStats(
int statsHistoryLength = 0,
bool canDetectOutOfSync =
true);
76 ArrivalInfo sequenceNumberReceived(quint16 incoming, NetworkLocalID senderID = NULL_LOCAL_ID,
const bool wantExtraDebugging =
false);
77 void pruneMissingSet(
const bool wantExtraDebugging =
false);
78 void pushStatsToHistory() { _statsHistory.insert(_stats); }
80 quint32 getReceived()
const {
return _stats._received; }
81 quint32 getExpectedReceived()
const {
return _stats._expectedReceived; }
82 quint32 getUnreasonable()
const {
return _stats._unreasonable; }
83 quint32 getOutOfOrder()
const {
return _stats._early + _stats._late; }
84 quint32 getEarly()
const {
return _stats._early; }
85 quint32 getLate()
const {
return _stats._late; }
86 quint32 getLost()
const {
return _stats._lost; }
87 quint32 getRecovered()
const {
return _stats._recovered; }
89 const PacketStreamStats& getStats()
const {
return _stats; }
90 PacketStreamStats getStatsForHistoryWindow()
const;
91 PacketStreamStats getStatsForLastHistoryInterval()
const;
92 const QSet<quint16>& getMissingSet()
const {
return _missingSet; }
95 void receivedUnreasonable(quint16 incoming);
98 quint16 _lastReceivedSequence;
99 QSet<quint16> _missingSet;
101 PacketStreamStats _stats;
103 NetworkLocalID _lastSenderID;
104 static const NetworkLocalID NULL_LOCAL_ID = (NetworkLocalID) 0;
106 RingBufferHistory<PacketStreamStats> _statsHistory;
108 quint16 _lastUnreasonableSequence;
109 int _consecutiveUnreasonableOnTime;