Skip to content

Commit

Permalink
Merged and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed Sep 14, 2023
2 parents 88b9f33 + 09f35c0 commit 185276c
Show file tree
Hide file tree
Showing 56 changed files with 1,346 additions and 606 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ matrix:
- BUILD_TYPE=Release
- BUILD_OPTS='-DENABLE_MONOTONIC_CLOCK=ON'
script:
- TESTS_IPv6="TestMuxer.IPv4_and_IPv6:TestIPv6.v6_calls_v6*:ReuseAddr.ProtocolVersion:ReuseAddr.*6" ; # Tests to skip due to lack of IPv6 support
- if [ "$TRAVIS_COMPILER" == "x86_64-w64-mingw32-g++" ]; then
export CC="x86_64-w64-mingw32-gcc";
export CXX="x86_64-w64-mingw32-g++";
Expand All @@ -95,7 +94,7 @@ script:
fi
- if [ "$TRAVIS_COMPILER" != "x86_64-w64-mingw32-g++" ]; then
ulimit -c unlimited;
./test-srt --gtest_filter="-$TESTS_IPv6";
./test-srt -disable-ipv6;
SUCCESS=$?;
if [ -f core ]; then gdb -batch ./test-srt -c core -ex bt -ex "info thread" -ex quit; else echo "NO CORE - NO CRY!"; fi;
test $SUCCESS == 0;
Expand Down
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#

cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
set (SRT_VERSION 1.5.2)
set (SRT_VERSION 1.5.3)

set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/scripts")
include(haiUtil) # needed for set_version_variables
Expand Down Expand Up @@ -153,6 +153,7 @@ option(ENABLE_GETNAMEINFO "In-logs sockaddr-to-string should do rev-dns" OFF)
option(ENABLE_UNITTESTS "Enable unit tests" OFF)
option(ENABLE_ENCRYPTION "Enable encryption in SRT" ON)
option(ENABLE_AEAD_API_PREVIEW "Enable AEAD API preview in SRT" Off)
option(ENABLE_MAXREXMITBW "Enable SRTO_MAXREXMITBW (v1.6.0 API preview)" Off)
option(ENABLE_CXX_DEPS "Extra library dependencies in srt.pc for the CXX libraries useful with C language" ON)
option(USE_STATIC_LIBSTDCXX "Should use static rather than shared libstdc++" OFF)
option(ENABLE_INET_PTON "Set to OFF to prevent usage of inet_pton when building against modern SDKs while still requiring compatibility with older Windows versions, such as Windows XP, Windows Server 2003 etc." ON)
Expand Down Expand Up @@ -299,7 +300,13 @@ if(WIN32)
if(ENABLE_INET_PTON)
set(CMAKE_REQUIRED_LIBRARIES ws2_32)
check_function_exists(inet_pton HAVE_INET_PTON)
add_definitions(-D_WIN32_WINNT=0x0600)
try_compile(AT_LEAST_VISTA
${CMAKE_BINARY_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/test_vista.c")
if(NOT AT_LEAST_VISTA)
# force targeting Vista
add_definitions(-D_WIN32_WINNT=0x0600)
endif()
else()
add_definitions(-D_WIN32_WINNT=0x0501)
endif()
Expand Down Expand Up @@ -460,6 +467,13 @@ if (USE_GNUSTL)
set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ${GNUSTL_LIBRARIES} ${GNUSTL_LDFLAGS})
endif()

if (ENABLE_MAXREXMITBW)
add_definitions(-DENABLE_MAXREXMITBW)
message(STATUS "MAXREXMITBW API: ENABLED")
else()
message(STATUS "MAXREXMITBW API: DISABLED")
endif()

if (USING_DEFAULT_COMPILER_PREFIX)
# Detect if the compiler is GNU compatible for flags
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Intel|Clang|AppleClang")
Expand Down
17 changes: 12 additions & 5 deletions apps/socketoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,27 @@ struct SocketOption
bool applyt(Object socket, std::string value) const;

template <Domain D, typename Object>
static int setso(Object socket, int protocol, int symbol, const void* data, size_t size);
static int setso(Object socket, int protocol, int symbol, const void* data, size_t size)
{
typename Object::wrong_version error;
return -1;
}

template<Type T>
bool extract(std::string value, OptionValue& val) const;
};

template<>
inline int SocketOption::setso<SocketOption::SRT, int>(int socket, int /*ignored*/, int sym, const void* data, size_t size)
inline int SocketOption::setso<SocketOption::SRT, SRTSOCKET>(SRTSOCKET socket, int /*ignored*/, int sym, const void* data, size_t size)
{
return (int)srt_setsockopt(SRTSOCKET(socket), 0, SRT_SOCKOPT(sym), data, (int) size);
return (int)srt_setsockopt(socket, 0, SRT_SOCKOPT(sym), data, (int) size);
}

#if ENABLE_BONDING
template<>
inline int SocketOption::setso<SocketOption::SRT, SRT_SOCKOPT_CONFIG*>(SRT_SOCKOPT_CONFIG* obj, int /*ignored*/, int sym, const void* data, size_t size)
{
return srt_config_add(obj, SRT_SOCKOPT(sym), data, (int) size);
return (int)srt_config_add(obj, SRT_SOCKOPT(sym), data, (int) size);
}
#endif

Expand Down Expand Up @@ -184,7 +188,7 @@ inline bool SocketOption::applyt(Object socket, std::string value) const
int result = -1;
if (extract<T>(value, o))
result = setso<D>(socket, protocol, symbol, o.value, o.size);
return result != -1;
return result != int(SRT_ERROR);
}


Expand Down Expand Up @@ -258,6 +262,9 @@ const SocketOption srt_options [] {
#ifdef ENABLE_AEAD_API_PREVIEW
,{ "cryptomode", 0, SRTO_CRYPTOMODE, SocketOption::PRE, SocketOption::INT, nullptr }
#endif
#ifdef ENABLE_MAXREXMITBW
,{ "maxrexmitbw", 0, SRTO_MAXREXMITBW, SocketOption::POST, SocketOption::INT64, nullptr }
#endif
};
}

Expand Down
6 changes: 3 additions & 3 deletions apps/statswriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class SrtStatsJson : public SrtStatsWriter
}

public:
string WriteStats(int sid, const CBytePerfMon& mon) override
string WriteStats(SRTSOCKET sid, const CBytePerfMon& mon) override
{
std::ostringstream output;

Expand Down Expand Up @@ -235,7 +235,7 @@ class SrtStatsCsv : public SrtStatsWriter
public:
SrtStatsCsv() : first_line_printed(false) {}

string WriteStats(int sid, const CBytePerfMon& mon) override
string WriteStats(SRTSOCKET sid, const CBytePerfMon& mon) override
{
std::ostringstream output;

Expand Down Expand Up @@ -286,7 +286,7 @@ class SrtStatsCsv : public SrtStatsWriter
class SrtStatsCols : public SrtStatsWriter
{
public:
string WriteStats(int sid, const CBytePerfMon& mon) override
string WriteStats(SRTSOCKET sid, const CBytePerfMon& mon) override
{
std::ostringstream output;
output << "======= SRT STATS: sid=" << sid << endl;
Expand Down
2 changes: 1 addition & 1 deletion apps/statswriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct SrtStatDataType: public SrtStatData
class SrtStatsWriter
{
public:
virtual std::string WriteStats(int sid, const CBytePerfMon& mon) = 0;
virtual std::string WriteStats(SRTSOCKET sid, const CBytePerfMon& mon) = 0;
virtual std::string WriteBandwidth(double mbpsBandwidth) = 0;
virtual ~SrtStatsWriter() {}

Expand Down
69 changes: 34 additions & 35 deletions apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ void SrtCommon::InitParameters(string host, map<string,string> par)
void SrtCommon::PrepareListener(string host, int port, int backlog)
{
m_bindsock = srt_create_socket();
if ( m_bindsock == SRT_ERROR )
if (m_bindsock == SRT_INVALID_SOCK)
Error("srt_create_socket");

int stat = ConfigurePre(m_bindsock);
if ( stat == SRT_ERROR )
SRTSTATUS stat = ConfigurePre(m_bindsock);
if (stat == SRT_ERROR)
Error("ConfigurePre");

sockaddr_any sa = CreateAddr(host, port);
sockaddr* psa = sa.get();
Verb() << "Binding a server on " << host << ":" << port << " ...";

stat = srt_bind(m_bindsock, psa, sizeof sa);
if ( stat == SRT_ERROR )
if (stat == SRT_ERROR)
{
srt_close(m_bindsock);
Error("srt_bind");
Expand All @@ -229,7 +229,7 @@ void SrtCommon::PrepareListener(string host, int port, int backlog)
Verb() << " listen...";

stat = srt_listen(m_bindsock, backlog);
if ( stat == SRT_ERROR )
if (stat == SRT_ERROR)
{
srt_close(m_bindsock);
Error("srt_listen");
Expand Down Expand Up @@ -272,8 +272,8 @@ bool SrtCommon::AcceptNewClient()

// ConfigurePre is done on bindsock, so any possible Pre flags
// are DERIVED by sock. ConfigurePost is done exclusively on sock.
int stat = ConfigurePost(m_sock);
if ( stat == SRT_ERROR )
SRTSTATUS stat = ConfigurePost(m_sock);
if (stat == SRT_ERROR)
Error("ConfigurePost");

return true;
Expand All @@ -299,14 +299,14 @@ void SrtCommon::Init(string host, int port, map<string,string> par, bool dir_out
}
}

int SrtCommon::ConfigurePost(SRTSOCKET sock)
SRTSTATUS SrtCommon::ConfigurePost(SRTSOCKET sock)
{
bool no = false;
int result = 0;
SRTSTATUS result = SRT_STATUS_OK;
if ( m_output_direction )
{
result = srt_setsockopt(sock, 0, SRTO_SNDSYN, &no, sizeof no);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;

if ( m_timeout )
Expand All @@ -315,7 +315,7 @@ int SrtCommon::ConfigurePost(SRTSOCKET sock)
else
{
result = srt_setsockopt(sock, 0, SRTO_RCVSYN, &no, sizeof no);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;

if ( m_timeout )
Expand All @@ -339,23 +339,23 @@ int SrtCommon::ConfigurePost(SRTSOCKET sock)
}
}

return 0;
return SRT_STATUS_OK;
}

int SrtCommon::ConfigurePre(SRTSOCKET sock)
SRTSTATUS SrtCommon::ConfigurePre(SRTSOCKET sock)
{
int result = 0;
SRTSTATUS result = SRT_STATUS_OK;

bool no = false;
if ( !m_tsbpdmode )
{
result = srt_setsockopt(sock, 0, SRTO_TSBPDMODE, &no, sizeof no);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;
}

result = srt_setsockopt(sock, 0, SRTO_RCVSYN, &no, sizeof no);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;


Expand All @@ -380,14 +380,14 @@ int SrtCommon::ConfigurePre(SRTSOCKET sock)
return SRT_ERROR;
}

return 0;
return SRT_STATUS_OK;
}

void SrtCommon::SetupAdapter(const string& host, int port)
{
sockaddr_any localsa = CreateAddr(host, port);
sockaddr* psa = localsa.get();
int stat = srt_bind(m_sock, psa, sizeof localsa);
SRTSTATUS stat = srt_bind(m_sock, psa, sizeof localsa);
if ( stat == SRT_ERROR )
Error("srt_bind");
}
Expand All @@ -407,31 +407,30 @@ void SrtCommon::OpenClient(string host, int port)
void SrtCommon::PrepareClient()
{
m_sock = srt_create_socket();
if ( m_sock == SRT_ERROR )
if ( m_sock == SRT_INVALID_SOCK)
Error("srt_create_socket");

int stat = ConfigurePre(m_sock);
SRTSTATUS stat = ConfigurePre(m_sock);
if ( stat == SRT_ERROR )
Error("ConfigurePre");
}


void SrtCommon::ConnectClient(string host, int port)
{

sockaddr_any sa = CreateAddr(host, port);
sockaddr* psa = sa.get();

Verb() << "Connecting to " << host << ":" << port;

int stat = srt_connect(m_sock, psa, sizeof sa);
if ( stat == SRT_ERROR )
SRTSOCKET cstat = srt_connect(m_sock, psa, sizeof sa);
if (cstat == SRT_INVALID_SOCK)
{
srt_close(m_sock);
Error("srt_connect");
}

stat = ConfigurePost(m_sock);
SRTSTATUS stat = ConfigurePost(m_sock);
if ( stat == SRT_ERROR )
Error("ConfigurePost");
}
Expand All @@ -449,13 +448,13 @@ void SrtCommon::Error(string src)
void SrtCommon::OpenRendezvous(string adapter, string host, int port)
{
m_sock = srt_create_socket();
if ( m_sock == SRT_ERROR )
if (m_sock == SRT_INVALID_SOCK)
Error("srt_create_socket");

bool yes = true;
srt_setsockopt(m_sock, 0, SRTO_RENDEZVOUS, &yes, sizeof yes);

int stat = ConfigurePre(m_sock);
SRTSTATUS stat = ConfigurePre(m_sock);
if ( stat == SRT_ERROR )
Error("ConfigurePre");

Expand All @@ -480,8 +479,8 @@ void SrtCommon::OpenRendezvous(string adapter, string host, int port)

Verb() << "Connecting to " << host << ":" << port;

stat = srt_connect(m_sock, sa.get(), sizeof sa);
if ( stat == SRT_ERROR )
SRTSOCKET cstat = srt_connect(m_sock, sa.get(), sizeof sa);
if ( cstat == SRT_INVALID_SOCK)
{
srt_close(m_sock);
Error("srt_connect");
Expand Down Expand Up @@ -565,10 +564,10 @@ int SrtSource::Read(size_t chunk, MediaPacket& pkt, ostream &out_stats)
return stat;
}

int SrtTarget::ConfigurePre(SRTSOCKET sock)
SRTSTATUS SrtTarget::ConfigurePre(SRTSOCKET sock)
{
int result = SrtCommon::ConfigurePre(sock);
if ( result == -1 )
SRTSTATUS result = SrtCommon::ConfigurePre(sock);
if ( result == SRT_ERROR )
return result;

int yes = 1;
Expand All @@ -577,10 +576,10 @@ int SrtTarget::ConfigurePre(SRTSOCKET sock)
// In HSv4 this setting is obligatory; otherwise the SRT handshake
// extension will not be done at all.
result = srt_setsockopt(sock, 0, SRTO_SENDER, &yes, sizeof yes);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;

return 0;
return SRT_STATUS_OK;
}

int SrtTarget::Write(const char* data, size_t size, int64_t src_time, ostream &out_stats)
Expand All @@ -590,7 +589,7 @@ int SrtTarget::Write(const char* data, size_t size, int64_t src_time, ostream &o
SRT_MSGCTRL ctrl = srt_msgctrl_default;
ctrl.srctime = src_time;
int stat = srt_sendmsg2(m_sock, data, (int) size, &ctrl);
if (stat == SRT_ERROR)
if (stat == int(SRT_ERROR))
{
return stat;
}
Expand Down Expand Up @@ -848,7 +847,6 @@ class UdpCommon

if (is_multicast)
{
ip_mreq_source mreq_ssm;
ip_mreq mreq;
sockaddr_any maddr (AF_INET);
int opt_name;
Expand All @@ -872,6 +870,7 @@ class UdpCommon
if (attr.count("source"))
{
#ifdef IP_ADD_SOURCE_MEMBERSHIP
ip_mreq_source mreq_ssm;
/* this is an ssm. we need to use the right struct and opt */
opt_name = IP_ADD_SOURCE_MEMBERSHIP;
mreq_ssm.imr_multiaddr.s_addr = sadr.sin.sin_addr.s_addr;
Expand Down
Loading

0 comments on commit 185276c

Please sign in to comment.