Skip to content

Commit

Permalink
[core] Stats: do not count discarded packets as dropped.
Browse files Browse the repository at this point in the history
Valid for a broadcast group member dropping existing packets from the RCV buffer because they were read from another member.
  • Loading branch information
maxsharabayko committed Apr 19, 2024
1 parent cf13200 commit d83c780
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
13 changes: 10 additions & 3 deletions srtcore/buffer_rcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int CRcvBuffer::insert(CUnit* unit)
return 0;
}

int CRcvBuffer::dropUpTo(int32_t seqno)
std::pair<int, int> CRcvBuffer::dropUpTo(int32_t seqno)
{
IF_RCVBUF_DEBUG(ScopedLog scoped_log);
IF_RCVBUF_DEBUG(scoped_log.ss << "CRcvBuffer::dropUpTo: seqno " << seqno << " m_iStartSeqNo " << m_iStartSeqNo);
Expand All @@ -222,9 +222,16 @@ int CRcvBuffer::dropUpTo(int32_t seqno)
if (m_iMaxPosOff < 0)
m_iMaxPosOff = 0;

const int iDropCnt = len;
int iNumDropped = 0; // Number of dropped packets that were missing.
int iNumDiscarded = 0; // The number of dropped packets that existed in the buffer.
while (len > 0)
{
// Note! Dropping a EntryState_Read must not be counted as a drop because it was read.
// Note! Dropping a EntryState_Drop must not be counted as a drop because it was already dropped and counted earlier.
if (m_entries[m_iStartPos].status == EntryState_Avail)
++iNumDiscarded;
else if (m_entries[m_iStartPos].status == EntryState_Empty)
++iNumDropped;
dropUnitInPos(m_iStartPos);
m_entries[m_iStartPos].status = EntryState_Empty;
SRT_ASSERT(m_entries[m_iStartPos].pUnit == NULL && m_entries[m_iStartPos].status == EntryState_Empty);
Expand All @@ -246,7 +253,7 @@ int CRcvBuffer::dropUpTo(int32_t seqno)
}
if (!m_tsbpd.isEnabled() && m_bMessageAPI)
updateFirstReadableOutOfOrder();
return iDropCnt;
return std::make_pair(iNumDropped, iNumDiscarded);
}

int CRcvBuffer::dropAll()
Expand Down
4 changes: 2 additions & 2 deletions srtcore/buffer_rcv.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class CRcvBuffer

/// Drop packets in the receiver buffer from the current position up to the seqno (excluding seqno).
/// @param [in] seqno drop units up to this sequence number
/// @return number of dropped packets.
int dropUpTo(int32_t seqno);
/// @return number of dropped (missing) and discarded (available) packets as a pair(dropped, discarded).
std::pair<int, int> dropUpTo(int32_t seqno);

/// @brief Drop all the packets in the receiver buffer.
/// The starting position and seqno are shifted right after the last packet in the buffer.
Expand Down
7 changes: 5 additions & 2 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5584,7 +5584,10 @@ int srt::CUDT::rcvDropTooLateUpTo(int seqno)

dropFromLossLists(SRT_SEQNO_NONE, CSeqNo::decseq(seqno));

const int iDropCnt = m_pRcvBuffer->dropUpTo(seqno);
const std::pair<int, int> iDropDiscardedPkts = m_pRcvBuffer->dropUpTo(seqno);
const int iDropCnt = iDropDiscardedPkts.first;
const int iDiscardedCnt = iDropDiscardedPkts.second;
const int iDropCntTotal = iDropCnt + iDiscardedCnt;
if (iDropCnt > 0)
{
enterCS(m_StatsLock);
Expand All @@ -5593,7 +5596,7 @@ int srt::CUDT::rcvDropTooLateUpTo(int seqno)
m_stats.rcvr.dropped.count(stats::BytesPackets(iDropCnt * avgpayloadsz, (uint32_t) iDropCnt));
leaveCS(m_StatsLock);
}
return iDropCnt;
return iDropCntTotal;
}

void srt::CUDT::setInitialRcvSeq(int32_t isn)
Expand Down

0 comments on commit d83c780

Please sign in to comment.