Skip to content

Commit

Permalink
[core] New receiver buffer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Oct 22, 2021
1 parent 8f2d318 commit 276a841
Show file tree
Hide file tree
Showing 12 changed files with 1,683 additions and 17 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ option(USE_OPENSSL_PC "Use pkg-config to find OpenSSL libraries" ON)
option(USE_BUSY_WAITING "Enable more accurate sending times at a cost of potentially higher CPU load" OFF)
option(USE_GNUSTL "Get c++ library/headers from the gnustl.pc" OFF)
option(ENABLE_SOCK_CLOEXEC "Enable setting SOCK_CLOEXEC on a socket" ON)
option(ENABLE_NEW_RCVBUFFER "Enable new receiver buffer implementation" ON)

option(ENABLE_CLANG_TSA "Enable Clang Thread Safety Analysis" OFF)

Expand Down Expand Up @@ -204,7 +205,6 @@ if (NOT USE_ENCLIB)
else()
set (USE_ENCLIB openssl)
endif()

endif()

set(USE_ENCLIB "${USE_ENCLIB}" CACHE STRING "The crypto library that SRT uses")
Expand Down Expand Up @@ -486,6 +486,14 @@ if (ENABLE_SOCK_CLOEXEC)
add_definitions(-DENABLE_SOCK_CLOEXEC=1)
endif()

if (ENABLE_NEW_RCVBUFFER)
add_definitions(-DENABLE_NEW_RCVBUFFER=1)
message(STATUS "RECEIVER_BUFFER: NEW")
else()
remove_definitions(-DENABLE_NEW_RCVBUFFER)
message(STATUS "RECEIVER_BUFFER: OLD")
endif()

if (CMAKE_MAJOR_VERSION LESS 3)
set (FORCE_CXX_STANDARD_GNUONLY 1)
endif()
Expand Down Expand Up @@ -1291,6 +1299,7 @@ if (ENABLE_UNITTESTS AND ENABLE_CXX11)
endif()

MafReadDir(test filelist.maf
HEADERS SOURCES_unittests
SOURCES SOURCES_unittests
)

Expand Down
5 changes: 5 additions & 0 deletions docs/build/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ will be removed when the problem is fixed globally.
This option enables the standard C++ `thread` and `chrono` libraries (available since C++11)
to be used by SRT instead of the `pthreads`.

**`--enable-new-rcvbuffer`** (default: ON)

This option enables the new implementation of the receiver buffer with behavior and code improvements.
The new receiver buffer is to remain the only one. For the transition period there is a possibility to
fall back to the old one.

**`--enable-profile`** (default: OFF)

Expand Down
6 changes: 6 additions & 0 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ void srt::CUDTSocket::setBrokenClosed()

bool srt::CUDTSocket::readReady()
{
// TODO: Use m_RcvBufferLock here (CUDT::isRcvReadReady())?
if (m_UDT.m_bConnected && m_UDT.m_pRcvBuffer->isRcvDataReady())
return true;

if (m_UDT.m_bListening)
return !m_QueuedSockets.empty();

Expand Down Expand Up @@ -2622,7 +2624,11 @@ void srt::CUDTUnited::checkBrokenSockets()
// NOT WHETHER THEY ARE ALSO READY TO PLAY at the time when
// this function is called (isRcvDataReady also checks if the
// available data is "ready to play").
#if ENABLE_NEW_RCVBUFFER
&& s->core().m_pRcvBuffer->hasAvailablePackets())
#else
&& s->core().m_pRcvBuffer->isRcvDataAvailable())
#endif
{
const int bc = s->core().m_iBrokenCounter.load();
if (bc > 0)
Expand Down
4 changes: 4 additions & 0 deletions srtcore/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ void CSndBuffer::increase()

////////////////////////////////////////////////////////////////////////////////

#if (!ENABLE_NEW_RCVBUFFER)

/*
* RcvBuffer (circular buffer):
*
Expand Down Expand Up @@ -2289,4 +2291,6 @@ bool CRcvBuffer::scanMsg(int& w_p, int& w_q, bool& w_passack)
return found;
}

#endif // !ENABLE_NEW_RCVBUFFER

} // namespace srt
4 changes: 4 additions & 0 deletions srtcore/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ class CSndBuffer

////////////////////////////////////////////////////////////////////////////////

#if (!ENABLE_NEW_RCVBUFFER)

class CRcvBuffer
{
typedef sync::steady_clock::time_point time_point;
Expand Down Expand Up @@ -562,6 +564,8 @@ class CRcvBuffer
CRcvBuffer& operator=(const CRcvBuffer&);
};

#endif // !ENABLE_NEW_RCVBUFFER

} // namespace srt

#endif
Loading

0 comments on commit 276a841

Please sign in to comment.