Skip to content

Commit

Permalink
Some further improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Dec 23, 2022
1 parent a9bfed1 commit ec6a45b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 12 additions & 10 deletions srtcore/buffer_snd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)
int32_t& w_seqno = w_mctrl.pktseq;
int64_t& w_srctime = w_mctrl.srctime;
const int& ttl = w_mctrl.msgttl;
const int iPktLen = m_iBlockLen - m_iAuthTagSize; // Payload length per packet.
const int iNumBlocks = (len + iPktLen - 1) / iPktLen;
const int iPktLen = getMaxPacketLen();
const int iNumBlocks = countNumPacketsRequired(len, iPktLen);

HLOGC(bslog.Debug,
log << "addBuffer: needs=" << iNumBlocks << " buffers for " << len << " bytes. Taken=" << m_iCount << "/" << m_iSize);
Expand Down Expand Up @@ -237,10 +237,8 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)

int CSndBuffer::addBufferFromFile(fstream& ifs, int len)
{
const int iPktLen = m_iBlockLen - m_iAuthTagSize; // Payload length per packet.
int iNumBlocks = len / iPktLen;
if ((len % m_iBlockLen) != 0)
++iNumBlocks;
const int iPktLen = getMaxPacketLen();
const int iNumBlocks = countNumPacketsRequired(len, iPktLen);

HLOGC(bslog.Debug,
log << "addBufferFromFile: size=" << m_iCount << " reserved=" << m_iSize << " needs=" << iPktLen
Expand Down Expand Up @@ -556,14 +554,18 @@ int CSndBuffer::getCurrBufSize() const

int CSndBuffer::getMaxPacketLen() const
{
return m_iBlockLen - m_iAuthTagSize;
return m_iBlockLen - m_iAuthTagSize;
}

int CSndBuffer::countNumPacketsRequired(int iPldLen) const
{
const int iPktLen = getMaxPacketLen();
const int iNumBlocks = (iPldLen + iPktLen - 1) / iPktLen;
return iNumBlocks;
const int iPktLen = getMaxPacketLen();
return countNumPacketsRequired(iPldLen, iPktLen);
}

int CSndBuffer::countNumPacketsRequired(int iPldLen, int iPktLen) const
{
return (iPldLen + iPktLen - 1) / iPktLen;
}

namespace {
Expand Down
6 changes: 6 additions & 0 deletions srtcore/buffer_snd.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ class CSndBuffer
/// @return the number of required data packets.
int countNumPacketsRequired(int iPldLen) const;

/// @brief Count the number of required packets to store the payload (message).
/// @param iPldLen the length of the payload to check.
/// @param iMaxPktLen the maximum payload length of the packet (the value returned from getMaxPacketLen()).
/// @return the number of required data packets.
int countNumPacketsRequired(int iPldLen, int iMaxPktLen) const;

/// @brief Get the buffering delay of the oldest message in the buffer.
/// @return the delay value.
SRT_ATTR_EXCLUDES(m_BufLock)
Expand Down

0 comments on commit ec6a45b

Please sign in to comment.