Skip to content

Commit

Permalink
Updated to latest upstream through Haivision#2594
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed May 8, 2023
2 parents addefb3 + d126e64 commit 380e12f
Show file tree
Hide file tree
Showing 71 changed files with 1,783 additions and 591 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:
name: NDK-R23
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

steps:
- name: Setup Android NDK R23
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "CodeQL"

on:
push:
branches: [ "master", "experimental/socket-groups" ]
pull_request:
branches: [ "master" ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ cpp ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure
run: cmake -DENABLE_HEAVY_LOGGING=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-fpermissive -DENABLE_BONDING=1 .

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Build
run: |
make
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{ matrix.language }}"
2 changes: 1 addition & 1 deletion .github/workflows/cxx11-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: configure
run: |
mkdir _build && cd _build
cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON
cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DUSE_CXX_STD=14
- name: build
run: cd _build && cmake --build ./
- name: test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cxx11-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:
name: ubuntu
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ matrix:
- BUILD_TYPE=Release
- BUILD_OPTS='-DENABLE_MONOTONIC_CLOCK=ON'
script:
- TESTS_IPv6="TestMuxer.IPv4_and_IPv6:TestIPv6.v6_calls_v6*:ReuseAddr.ProtocolVersion" ; # Tests to skip due to lack of IPv6 support
- 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 Down
36 changes: 33 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ else()
message(STATUS "USE_BUSY_WAITING: OFF (default)")
endif()

# Reduce the frequency of some frequent logs, milliseconds
set(SRT_LOG_SLOWDOWN_FREQ_MS_DEFAULT 1000) # 1s
if (NOT DEFINED SRT_LOG_SLOWDOWN_FREQ_MS)
if (ENABLE_HEAVY_LOGGING)
set(SRT_LOG_SLOWDOWN_FREQ_MS 0) # Just show every log message.
else()
set(SRT_LOG_SLOWDOWN_FREQ_MS ${SRT_LOG_SLOWDOWN_FREQ_MS_DEFAULT})
endif()
endif()

if ( CYGWIN AND NOT CYGWIN_USE_POSIX )
set(WIN32 1)
set(CMAKE_LEGACY_CYGWIN_WIN32 1)
Expand Down Expand Up @@ -495,6 +505,15 @@ CheckGCCAtomicIntrinsics()
include(CheckCXXAtomic)
CheckCXXAtomic()

# Check for std::put_time():
# Sets:
# HAVE_CXX_STD_PUT_TIME
include(CheckCXXStdPutTime)
CheckCXXStdPutTime()
if (HAVE_CXX_STD_PUT_TIME)
add_definitions(-DHAVE_CXX_STD_PUT_TIME=1)
endif()

if (DISABLE_CXX11)
set (ENABLE_CXX11 0)
elseif( DEFINED ENABLE_CXX11 )
Expand Down Expand Up @@ -623,6 +642,9 @@ endif()
# add extra warning flags for gccish compilers
if (HAVE_COMPILER_GNU_COMPAT)
set (SRT_GCC_WARN "-Wall -Wextra")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set (SRT_GCC_WARN "${SRT_GCC_WARN} -Wshadow=local")
endif()
else()
# cpp debugging on Windows :D
#set (SRT_GCC_WARN "/showIncludes")
Expand Down Expand Up @@ -1058,6 +1080,8 @@ if (ENABLE_SHARED)
target_compile_definitions(srt_virtual PUBLIC -DSRT_DYNAMIC)
endif()

target_compile_definitions(srt_virtual PRIVATE -DSRT_LOG_SLOWDOWN_FREQ_MS=${SRT_LOG_SLOWDOWN_FREQ_MS})

if (srt_libspec_shared)
if (MICROSOFT)
target_link_libraries(${TARGET_srt}_shared PUBLIC Ws2_32.lib)
Expand All @@ -1082,6 +1106,11 @@ elseif (HAVE_LIBATOMIC AND HAVE_LIBATOMIC_COMPILES_STATIC)
if (srt_libspec_static)
target_link_libraries(${TARGET_srt}_static PUBLIC atomic)
endif()
elseif (LINUX AND HAVE_LIBATOMIC AND HAVE_LIBATOMIC_COMPILES)
# This is a workaround for some older Linux Toolchains.
if (srt_libspec_static)
target_link_libraries(${TARGET_srt}_static PUBLIC atomic)
endif()
endif()

# Cygwin installs the *.dll libraries in bin directory and uses PATH.
Expand Down Expand Up @@ -1423,12 +1452,13 @@ if (ENABLE_UNITTESTS AND ENABLE_CXX11)
NAME test-srt
COMMAND ${CMAKE_BINARY_DIR}/test-srt
)
#set_tests_properties(test-srt PROPERTIES RUN_SERIAL TRUE)
else()
gtest_add_tests(
test-srt
""
AUTO
TEST_LIST tests_srt
TARGET test-srt
)
set_tests_properties(${tests_srt} PROPERTIES RUN_SERIAL TRUE)
endif()

enable_testing()
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ In live streaming configurations, the SRT protocol maintains a constant end-to-e

## Getting Started with SRT

| | | |
|:-----------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------:|
| [The SRT API](./docs#srt-api-documents) | [IETF Internet Draft](https://datatracker.ietf.org/doc/html/draft-sharabayko-srt-01) | [Sample Apps](./docs#sample-applications) |
| Reference documentation for the SRT library API | The SRT Protocol Internet Draft | Instructions for using test apps (`srt-live-transmit`, `srt-file-transmit`, etc.) |
| [SRT Technical Overview](https://github.com/Haivision/srt/files/2489142/SRT_Protocol_TechnicalOverview_DRAFT_2018-10-17.pdf) | [SRT Deployment Guide](https://www.srtalliance.org/srt-deployment-guide/) | [SRT CookBook](https://srtlab.github.io/srt-cookbook) |
| Early draft technical overview (precursor to the Internet Draft) | A comprehensive overview of the protocol with deployment guidelines | Development notes on the SRT protocol |
| [Innovation Labs Blog](https://medium.com/innovation-labs-blog/tagged/secure-reliable-transport) | [SRTLab YouTube Channel](https://www.youtube.com/channel/UCr35JJ32jKKWIYymR1PTdpA) | [Slack](https://srtalliance.slack.com) |
| The blog on Medium with SRT-related technical articles | Technical YouTube channel with useful videos | Slack channels to get the latest updates and ask questions |
| | | |
|:-----------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------:|
| [The SRT API](./docs#srt-api-documents) | [IETF Internet Draft](https://datatracker.ietf.org/doc/html/draft-sharabayko-srt-01) | [Sample Apps](./docs#sample-applications) |
| Reference documentation for the SRT library API | The SRT Protocol Internet Draft | Instructions for using test apps (`srt-live-transmit`, `srt-file-transmit`, etc.) |
| [SRT Technical Overview](https://github.com/Haivision/srt/files/2489142/SRT_Protocol_TechnicalOverview_DRAFT_2018-10-17.pdf) | [SRT Deployment Guide](https://www.srtalliance.org/srt-deployment-guide/) | [SRT CookBook](https://srtlab.github.io/srt-cookbook) |
| Early draft technical overview (precursor to the Internet Draft) | A comprehensive overview of the protocol with deployment guidelines | Development notes on the SRT protocol |
| [Innovation Labs Blog](https://medium.com/innovation-labs-blog/tagged/secure-reliable-transport) | [SRTLab YouTube Channel](https://www.youtube.com/channel/UCr35JJ32jKKWIYymR1PTdpA) | [Slack](https://srtalliance.slack.com) |
| The blog on Medium with SRT-related technical articles | Technical YouTube channel with useful videos | Slack channels to get the latest updates and ask questions <br />[Join SRT Alliance on Slack](https://slackin-srtalliance.azurewebsites.net/) |

### Additional Documentation

Expand Down
7 changes: 5 additions & 2 deletions apps/apputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ int inet_pton(int af, const char * src, void * dst)
ZeroMemory(&ss, sizeof(ss));

// work around non-const API
strncpy(srcCopy, src, INET6_ADDRSTRLEN + 1);
#ifdef _MSC_VER
strncpy_s(srcCopy, INET6_ADDRSTRLEN + 1, src, _TRUNCATE);
#else
strncpy(srcCopy, src, INET6_ADDRSTRLEN);
srcCopy[INET6_ADDRSTRLEN] = '\0';

#endif
if (WSAStringToAddress(
srcCopy, af, NULL, (struct sockaddr *)&ss, &ssSize) != 0)
{
Expand Down
10 changes: 8 additions & 2 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,14 @@ int main(int argc, char** argv)
void TestLogHandler(void* opaque, int level, const char* file, int line, const char* area, const char* message)
{
char prefix[100] = "";
if ( opaque )
strncpy(prefix, (char*)opaque, 99);
if ( opaque ) {
#ifdef _MSC_VER
strncpy_s(prefix, sizeof(prefix), (char*)opaque, _TRUNCATE);
#else
strncpy(prefix, (char*)opaque, sizeof(prefix) - 1);
prefix[sizeof(prefix) - 1] = '\0';
#endif
}
time_t now;
time(&now);
char buf[1024];
Expand Down
18 changes: 9 additions & 9 deletions apps/srt-tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class Tunnel

Tunnel(Tunnelbox* m, std::unique_ptr<Medium>&& acp, std::unique_ptr<Medium>&& clr):
parent_box(m),
med_acp(move(acp)), med_clr(move(clr)),
med_acp(std::move(acp)), med_clr(std::move(clr)),
acp_to_clr(this, med_acp.get(), med_clr.get(), med_acp->id() + ">" + med_clr->id()),
clr_to_acp(this, med_clr.get(), med_acp.get(), med_clr->id() + ">" + med_acp->id())
{
Expand Down Expand Up @@ -649,7 +649,7 @@ void TcpMedium::CreateListener()

sockaddr_any sa = CreateAddr(m_uri.host(), m_uri.portno());

m_socket = socket(sa.get()->sa_family, SOCK_STREAM, IPPROTO_TCP);
m_socket = (int)socket(sa.get()->sa_family, SOCK_STREAM, IPPROTO_TCP);
ConfigurePre();

int stat = ::bind(m_socket, sa.get(), sa.size());
Expand Down Expand Up @@ -694,7 +694,7 @@ unique_ptr<Medium> SrtMedium::Accept()
unique_ptr<Medium> TcpMedium::Accept()
{
sockaddr_any sa;
int s = ::accept(m_socket, (sa.get()), (&sa.syslen()));
int s = (int)::accept(m_socket, (sa.get()), (&sa.syslen()));
if (s == -1)
{
Error(errno, "accept");
Expand Down Expand Up @@ -726,7 +726,7 @@ void SrtMedium::CreateCaller()

void TcpMedium::CreateCaller()
{
m_socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
m_socket = (int)::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
ConfigurePre();
}

Expand Down Expand Up @@ -850,7 +850,7 @@ Medium::ReadStatus Medium::Read(bytevector& w_output)
size_t pred_size = shift + m_chunk;

w_output.resize(pred_size);
int st = ReadInternal((w_output.data() + shift), m_chunk);
int st = ReadInternal((w_output.data() + shift), (int)m_chunk);
if (st == -1)
{
if (IsErrorAgain())
Expand Down Expand Up @@ -884,7 +884,7 @@ Medium::ReadStatus Medium::Read(bytevector& w_output)

void SrtMedium::Write(bytevector& w_buffer)
{
int st = srt_send(m_socket, w_buffer.data(), w_buffer.size());
int st = srt_send(m_socket, w_buffer.data(), (int)w_buffer.size());
if (st == SRT_ERROR)
{
Error(UDT::getlasterror(), "srt_send");
Expand All @@ -907,7 +907,7 @@ void SrtMedium::Write(bytevector& w_buffer)

void TcpMedium::Write(bytevector& w_buffer)
{
int st = ::send(m_socket, w_buffer.data(), w_buffer.size(), DEF_SEND_FLAG);
int st = ::send(m_socket, w_buffer.data(), (int)w_buffer.size(), DEF_SEND_FLAG);
if (st == -1)
{
Error(errno, "send");
Expand Down Expand Up @@ -971,7 +971,7 @@ struct Tunnelbox
lock_guard<std::mutex> lk(access);
Verb() << "Tunnelbox: Starting tunnel: " << acp->uri() << " <-> " << clr->uri();

tunnels.emplace_back(new Tunnel(this, move(acp), move(clr)));
tunnels.emplace_back(new Tunnel(this, std::move(acp), std::move(clr)));
// Note: after this instruction, acp and clr are no longer valid!
auto& it = tunnels.back();

Expand Down Expand Up @@ -1191,7 +1191,7 @@ int main( int argc, char** argv )
Verb() << "Connected. Establishing pipe.";

// No exception, we are free to pass :)
g_tunnels.install(move(accepted), move(caller));
g_tunnels.install(std::move(accepted), std::move(caller));
}
catch (...)
{
Expand Down
18 changes: 7 additions & 11 deletions apps/statswriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include "netinet_any.h"
#include "srt_compat.h"

// Note: std::put_time is supported only in GCC 5 and higher
#if !defined(__GNUC__) || defined(__clang__) || (__GNUC__ >= 5)
#define HAS_PUT_TIME
#endif

using namespace std;

Expand Down Expand Up @@ -100,7 +96,7 @@ string srt_json_cat_names [] = {
"recv"
};

#ifdef HAS_PUT_TIME
#ifdef HAVE_CXX_STD_PUT_TIME
// Follows ISO 8601
std::string SrtStatsWriter::print_timestamp()
{
Expand All @@ -125,10 +121,10 @@ std::string SrtStatsWriter::print_timestamp()

// This is a stub. The error when not defining it would be too
// misleading, so this stub will work if someone mistakenly adds
// the item to the output format without checking that HAS_PUT_TIME.
// the item to the output format without checking that HAVE_CXX_STD_PUT_TIME
string SrtStatsWriter::print_timestamp()
{ return "<NOT IMPLEMENTED>"; }
#endif // HAS_PUT_TIME
#endif // HAVE_CXX_STD_PUT_TIME


class SrtStatsJson : public SrtStatsWriter
Expand Down Expand Up @@ -170,7 +166,7 @@ class SrtStatsJson : public SrtStatsWriter
output << pretty_tab << quotekey("sid") << sid;

// Extra Timepoint is also displayed manually
#ifdef HAS_PUT_TIME
#ifdef HAVE_CXX_STD_PUT_TIME
// NOTE: still assumed SSC_GEN category
output << "," << pretty_cr << pretty_tab
<< quotekey("timepoint") << quote(print_timestamp());
Expand Down Expand Up @@ -246,7 +242,7 @@ class SrtStatsCsv : public SrtStatsWriter
// Header
if (!first_line_printed)
{
#ifdef HAS_PUT_TIME
#ifdef HAVE_CXX_STD_PUT_TIME
output << "Timepoint,";
#endif
output << "Time,SocketID";
Expand All @@ -260,10 +256,10 @@ class SrtStatsCsv : public SrtStatsWriter
}

// Values
#ifdef HAS_PUT_TIME
#ifdef HAVE_CXX_STD_PUT_TIME
// HDR: Timepoint
output << print_timestamp() << ",";
#endif // HAS_PUT_TIME
#endif // HAVE_CXX_STD_PUT_TIME

// HDR: Time,SocketID
output << mon.msTimeStamp << "," << sid;
Expand Down
Loading

0 comments on commit 380e12f

Please sign in to comment.