Skip to content

Commit

Permalink
[core] Use SND buffer delay for TL Packet Drop
Browse files Browse the repository at this point in the history
instead of the timespan between the first and the last packet in the buffer.
  • Loading branch information
maxsharabayko committed Jan 24, 2022
1 parent a31e618 commit 5773901
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
8 changes: 6 additions & 2 deletions srtcore/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,14 @@ int CSndBuffer::getCurrBufSize(int& w_bytes, int& w_timespan)
return m_iCount;
}

CSndBuffer::time_point CSndBuffer::getOldestTime() const
CSndBuffer::duration CSndBuffer::getBufferingDelay(const time_point& tnow) const
{
ScopedLock lck(m_BufLock);
SRT_ASSERT(m_pFirstBlock);
return m_pFirstBlock->m_tsOriginTime;
if (m_iCount == 0)
return duration(0);

return tnow - m_pFirstBlock->m_tsOriginTime;
}

int CSndBuffer::dropLateData(int& w_bytes, int32_t& w_first_msgno, const steady_clock::time_point& too_late_time)
Expand Down
8 changes: 5 additions & 3 deletions srtcore/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ class CSndBuffer
int getAvgBufSize(int& bytes, int& timespan);
int getCurrBufSize(int& bytes, int& timespan);

time_point getOldestTime() const;
/// @brief Get the buffering delay of the oldest message in the buffer.
/// @return the delay value.
duration getBufferingDelay(const time_point& tnow) const;

uint64_t getInRatePeriod() const { return m_InRatePeriod; }

Expand Down Expand Up @@ -207,7 +209,7 @@ class CSndBuffer
static const int INPUTRATE_INITIAL_BYTESPS = BW_INFINITE;

private:
sync::Mutex m_BufLock; // used to synchronize buffer operation
mutable sync::Mutex m_BufLock; // used to synchronize buffer operation

struct Block
{
Expand All @@ -216,7 +218,7 @@ class CSndBuffer

int32_t m_iMsgNoBitset; // message number
int32_t m_iSeqNo; // sequence number for scheduling
time_point m_tsOriginTime; // block origin time (either provided from above or equials the time a message was submitted for sending.
time_point m_tsOriginTime; // block origin time (either provided from above or equals the time a message was submitted for sending.
time_point m_tsRexmitTime; // packet retransmission time
int m_iTTL; // time to live (milliseconds)

Expand Down
25 changes: 11 additions & 14 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6338,31 +6338,28 @@ bool srt::CUDT::checkNeedDrop()
throw CUDTException(MJ_NOTSUP, MN_INVALBUFFERAPI, 0);
}

int bytes, timespan_ms;
// (returns buffer size in buffer units, ignored)
m_pSndBuffer->getCurrBufSize((bytes), (timespan_ms));
const time_point tnow = steady_clock::now();
const int buffdelay_ms = count_milliseconds(m_pSndBuffer->getBufferingDelay(tnow));

// high threshold (msec) at tsbpd_delay plus sender/receiver reaction time (2 * 10ms)
// Minimum value must accomodate an I-Frame (~8 x average frame size)
// >>need picture rate or app to set min treshold
// >>using 1 sec for worse case 1 frame using all bit budget.
// picture rate would be useful in auto SRT setting for min latency
// XXX Make SRT_TLPKTDROP_MINTHRESHOLD_MS option-configurable
int threshold_ms = 0;
if (m_config.iSndDropDelay >= 0)
{
threshold_ms = std::max(m_iPeerTsbPdDelay_ms + m_config.iSndDropDelay, +SRT_TLPKTDROP_MINTHRESHOLD_MS) +
(2 * COMM_SYN_INTERVAL_US / 1000);
}
const int threshold_ms = (m_config.iSndDropDelay >= 0)
? std::max(m_iPeerTsbPdDelay_ms + m_config.iSndDropDelay, +SRT_TLPKTDROP_MINTHRESHOLD_MS)
+ (2 * COMM_SYN_INTERVAL_US / 1000)
: 0;

bool bCongestion = false;
if (threshold_ms && timespan_ms > threshold_ms)
if (threshold_ms && buffdelay_ms > threshold_ms)
{
// protect packet retransmission
enterCS(m_RecvAckLock);
int dbytes;
int32_t first_msgno;
int dpkts = m_pSndBuffer->dropLateData((dbytes), (first_msgno), steady_clock::now() - milliseconds_from(threshold_ms));
int dpkts = m_pSndBuffer->dropLateData((dbytes), (first_msgno), tnow - milliseconds_from(threshold_ms));
if (dpkts > 0)
{
enterCS(m_StatsLock);
Expand All @@ -6385,7 +6382,7 @@ bool srt::CUDT::checkNeedDrop()
}

HLOGC(aslog.Debug, log << "SND-DROP: %(" << realack << "-" << m_iSndCurrSeqNo << ") n="
<< dpkts << "pkt " << dbytes << "B, span=" << timespan_ms << " ms, FIRST #" << first_msgno);
<< dpkts << "pkt " << dbytes << "B, span=" << buffdelay_ms << " ms, FIRST #" << first_msgno);

#if ENABLE_EXPERIMENTAL_BONDING
// This is done with a presumption that the group
Expand Down Expand Up @@ -6413,10 +6410,10 @@ bool srt::CUDT::checkNeedDrop()
bCongestion = true;
leaveCS(m_RecvAckLock);
}
else if (timespan_ms > (m_iPeerTsbPdDelay_ms / 2))
else if (buffdelay_ms > (m_iPeerTsbPdDelay_ms / 2))
{
HLOGC(aslog.Debug,
log << "cong, BYTES " << bytes << ", TMSPAN " << timespan_ms << "ms");
log << "cong TIMESPAN " << buffdelay_ms << "ms");

bCongestion = true;
}
Expand Down

0 comments on commit 5773901

Please sign in to comment.