Skip to content

Commit

Permalink
Merge branch 'master' into dev-fix-sync-rexmit
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko authored Aug 17, 2021
2 parents 24ba32d + 675e75d commit bd86d52
Show file tree
Hide file tree
Showing 65 changed files with 3,808 additions and 2,149 deletions.
34 changes: 24 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ if (ENABLE_DEBUG)
endif()


set(ENABLE_STDCXX_SYNC_DEFAULT OFF)
set(ENABLE_MONOTONIC_CLOCK_DEFAULT OFF)
set(MONOTONIC_CLOCK_LINKLIB "")
if (MICROSOFT)
set(ENABLE_STDCXX_SYNC_DEFAULT ON)
elseif (LINUX)
test_requires_clock_gettime(ENABLE_MONOTONIC_CLOCK_DEFAULT MONOTONIC_CLOCK_LINKLIB)
endif()


# options
option(CYGWIN_USE_POSIX "Should the POSIX API be used for cygwin. Ignored if the system isn't cygwin." OFF)
option(ENABLE_CXX11 "Should the c++11 parts (srt-live-transmit) be enabled" ON)
Expand All @@ -129,13 +139,15 @@ option(ENABLE_CXX_DEPS "Extra library dependencies in srt.pc for the CXX librari
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)
option(ENABLE_CODE_COVERAGE "Enable code coverage reporting" OFF)
option(ENABLE_MONOTONIC_CLOCK "Enforced clock_gettime with monotonic clock on GC CV /temporary fix for #729/" OFF)
option(ENABLE_STDCXX_SYNC "Use C++11 chrono and threads for timing instead of pthreads" OFF)
option(ENABLE_MONOTONIC_CLOCK "Enforced clock_gettime with monotonic clock on GC CV" ${ENABLE_MONOTONIC_CLOCK_DEFAULT})
option(ENABLE_STDCXX_SYNC "Use C++11 chrono and threads for timing instead of pthreads" ${ENABLE_STDCXX_SYNC_DEFAULT})
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_CLANG_TSA "Enable Clang Thread Safety Analysis" OFF)

set(TARGET_srt "srt" CACHE STRING "The name for the SRT library")

# Use application-defined group reader
Expand Down Expand Up @@ -263,6 +275,10 @@ if (DEFINED HAVE_INET_PTON)
endif()

if (ENABLE_MONOTONIC_CLOCK)
if (NOT ENABLE_MONOTONIC_CLOCK_DEFAULT)
message(FATAL_ERROR "Your platform does not support CLOCK_MONOTONIC. Build with -DENABLE_MONOTONIC_CLOCK=OFF.")
endif()
set (WITH_EXTRALIBS "${WITH_EXTRALIBS} ${MONOTONIC_CLOCK_LINKLIB}")
add_definitions(-DENABLE_MONOTONIC_CLOCK=1)
endif()

Expand Down Expand Up @@ -433,6 +449,7 @@ elseif (ENABLE_STDCXX_SYNC)
endif()

message(STATUS "STDCXX_SYNC: ${ENABLE_STDCXX_SYNC}")
message(STATUS "MONOTONIC_CLOCK: ${ENABLE_MONOTONIC_CLOCK}")

if (ENABLE_SOCK_CLOEXEC)
add_definitions(-DENABLE_SOCK_CLOEXEC=1)
Expand Down Expand Up @@ -524,14 +541,6 @@ if (USE_STATIC_LIBSTDCXX)
endif()
endif()

# We need clock_gettime, but on some systems this is only provided
# by librt. Check if librt is required.
if (ENABLE_MONOTONIC_CLOCK AND LINUX)
# "requires" - exits on FATAL_ERROR when clock_gettime not available
test_requires_clock_gettime(NEED_CLOCK_GETTIME)
set (WITH_EXTRALIBS "${WITH_EXTRALIBS} ${NEED_CLOCK_GETTIME}")
endif()


# This options is necessary on some systems; on a cross-ARM compiler it
# has been detected, for example, that -lrt is necessary for some applications
Expand Down Expand Up @@ -634,6 +643,11 @@ if (ENABLE_THREAD_CHECK)
)
endif()

if (ENABLE_CLANG_TSA)
list(APPEND SRT_EXTRA_CFLAGS "-Wthread-safety")
message(STATUS "Clang TSA: Enabled")
endif()

if (ENABLE_PROFILE)
if (HAVE_COMPILER_GNU_COMPAT)
# They are actually cflags, not definitions, but CMake is stupid enough.
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ As audio/video packets are streamed from a source to a destination device, SRT d

## Requirements

* cmake (as build system)
* Tcl 8.5 (optional for user-friendly build system)
* OpenSSL
* Pthreads (for POSIX systems it's builtin, for Windows there's a library)

For detailed description of the build system and options, please read [SRT Build Options](docs/build/build-options.md).
* C++03 (or above) compliant compiler.
* CMake 2.8.12 or above (as build system).
* OpenSSL 1.1 (to enable encryption, or build with `-DENABLE_ENCRYPTION=OFF`).
* Multithreading is provided by either of the following:
* C++11: standard library (`std` by `-DENABLE_STDCXX_SYNC=ON` CMake option);
* C++03: Pthreads (for POSIX systems it's built in, for Windows there is a ported library).
* Tcl 8.5 (optional, used by `./configure` script or use CMake directly).

For a detailed description of the build system and options, please refer to [SRT Build Options](docs/build/build-options.md).

### Build on Linux

Expand Down
5 changes: 1 addition & 4 deletions apps/apputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ options_t ProcessOptions(char* const* argv, int argc, std::vector<OptionScheme>
}

// Find the key in the scheme. If not found, treat it as ARG_NONE.
for (auto s: scheme)
for (const auto& s: scheme)
{
if (s.names().count(current_key))
{
Expand Down Expand Up @@ -484,7 +484,6 @@ class SrtStatsJson : public SrtStatsWriter
string WriteStats(int sid, const CBytePerfMon& mon) override
{
std::ostringstream output;
static const string qt = R"(")";

string pretty_cr, pretty_tab;
if (Option("pretty"))
Expand Down Expand Up @@ -540,9 +539,7 @@ class SrtStatsJson : public SrtStatsWriter

// Print the current field
output << quotekey(i->name);
output << qt;
i->PrintValue(output, mon);
output << qt;
}

// Close the previous subcategory
Expand Down
19 changes: 17 additions & 2 deletions apps/apputil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ const int SysAGAIN = EAGAIN;
sockaddr_any CreateAddr(const std::string& name, unsigned short port = 0, int pref_family = AF_UNSPEC);
std::string Join(const std::vector<std::string>& in, std::string sep);

template <class VarType, class ValType>
struct OnReturnSetter
{
VarType& var;
ValType value;

OnReturnSetter(VarType& target, ValType v): var(target), value(v) {}
~OnReturnSetter() { var = value; }
};

template <class VarType, class ValType>
OnReturnSetter<VarType, ValType> OnReturnSet(VarType& target, ValType v)
{ return OnReturnSetter<VarType, ValType>(target, v); }

// ---- OPTIONS MODULE

inline bool CheckTrue(const std::vector<std::string>& in)
{
Expand Down Expand Up @@ -205,7 +220,7 @@ struct OptionScheme

OptionScheme(const OptionName& id, Args tp);

const std::set<std::string>& names();
const std::set<std::string>& names() const;
};

struct OptionName
Expand Down Expand Up @@ -250,7 +265,7 @@ struct OptionName
};

inline OptionScheme::OptionScheme(const OptionName& id, Args tp): pid(&id), type(tp) {}
inline const std::set<std::string>& OptionScheme::names() { return pid->names; }
inline const std::set<std::string>& OptionScheme::names() const { return pid->names; }

template <class OutType, class OutValue> inline
typename OutType::type Option(const options_t&, OutValue deflt=OutValue()) { return deflt; }
Expand Down
31 changes: 31 additions & 0 deletions apps/logsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,35 @@ set<srt_logging::LogFA> SrtParseLogFA(string fa, set<string>* punknown)
return fas;
}

void ParseLogFASpec(const vector<string>& speclist, string& w_on, string& w_off)
{
std::ostringstream son, soff;

for (auto& s: speclist)
{
string name;
bool on = true;
if (s[0] == '+')
name = s.substr(1);
else if (s[0] == '~')
{
name = s.substr(1);
on = false;
}
else
name = s;

if (on)
son << "," << name;
else
soff << "," << name;
}

const string& sons = son.str();
const string& soffs = soff.str();

w_on = sons.empty() ? string() : sons.substr(1);
w_off = soffs.empty() ? string() : soffs.substr(1);
}


2 changes: 2 additions & 0 deletions apps/logsupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

#include <string>
#include <map>
#include <vector>
#include "../srtcore/srt.h"
#include "../srtcore/logging_api.h"

srt_logging::LogLevel::type SrtParseLogLevel(std::string level);
std::set<srt_logging::LogFA> SrtParseLogFA(std::string fa, std::set<std::string>* punknown = nullptr);
void ParseLogFASpec(const std::vector<std::string>& speclist, std::string& w_on, std::string& w_off);
const std::map<std::string, int> SrtLogFAList();

SRT_API extern std::map<std::string, int> srt_level_names;
Expand Down
18 changes: 18 additions & 0 deletions apps/verbose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,29 @@ class ErrLog: public Log
}
};

// terminal
inline void Print(Log& ) {}

template <typename Arg1, typename... Args>
inline void Print(Log& out, Arg1&& arg1, Args&&... args)
{
out << arg1;
Print(out, args...);
}

}

inline Verbose::Log Verb() { return Verbose::Log(); }
inline Verbose::ErrLog Verror() { return Verbose::ErrLog(); }

template <typename... Args>
inline void Verb(Args&&... args)
{
Verbose::Log log;
Verbose::Print(log, args...);
}


// Manipulator tags
static const Verbose::LogNoEol VerbNoEOL;
#if SRT_ENABLE_VERBOSE_LOCK
Expand Down
15 changes: 13 additions & 2 deletions configure-data.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,19 @@ proc postprocess {} {
# Otherwise don't set PKG_CONFIG_PATH and we'll see.
}

if { $::HAVE_DARWIN && !$toolchain_changed} {

set use_brew 0
if { $::HAVE_DARWIN && !$toolchain_changed } {
set use_brew 1
}
if { $use_brew } {
foreach item $::cmakeopt {
if { [string first "Android" $item] != -1 } {
set use_brew 0
break
}
}
}
if { $use_brew } {
if { $have_gnutls } {
# Use gnutls explicitly, as found in brew
set er [catch {exec brew info gnutls} res]
Expand Down
11 changes: 8 additions & 3 deletions docs/API/API-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ calling this function.
| [`SRT_EINVPARAM`](#srt_einvparam) | NULL specified as `listeners` or `nlisteners` < 1 |
| [`SRT_EINVSOCK`](#srt_einvsock) | Any socket in `listeners` designates no valid socket ID. Can also mean *Internal Error* when <br/> an error occurred while creating an accepted socket (:warning: &nbsp; **BUG?**) |
| [`SRT_ENOLISTEN`](#srt_enolisten) | Any socket in `listeners` is not set up as a listener ([`srt_listen`](#srt_listen) not called, or the listener socket <br/> has already been closed) |
| [`SRT_EASYNCRCV`](#srt_easyncrcv) | No connection reported on any listener socket as the timeout has been reached. This error is only <br/> reported when `msTimeOut` is not -1 |
| [`SRT_ETIMEOUT`](#srt_etimeout) | No connection reported on any listener socket as the timeout has been reached. This error is only <br/> reported when `msTimeOut` is not -1 |
| <img width=240px height=1px/> | <img width=710px height=1px/> |


Expand Down Expand Up @@ -1885,8 +1885,13 @@ to be returned does not fit in the buffer, nothing will be received and
the error is reported.

3. In **live mode**, the function behaves as in **file/message mode**, although the
number of bytes retrieved will be at most the size of `SRTO_PAYLOADSIZE`. In this mode,
however, with default settings of [`SRTO_TSBPDMODE`](API-socket-options.md#SRTO_TSBPDMODE)
number of bytes retrieved will be at most the maximum payload of one MTU.
The [`SRTO_PAYLOADSIZE`](API-socket-options.md#SRTO_PAYLOADSIZE) value configured by the sender
is not negotiated, and not known to the receiver.
The [`SRTO_PAYLOADSIZE`](API-socket-options.md#SRTO_PAYLOADSIZE) value set on the SRT receiver
is mainly used for heuristics. However, the receiver is prepared to receive
the whole MTU as configured with [`SRTO_MSS`](API-socket-options.md#SRTO_MSS).
In this mode, however, with default settings of [`SRTO_TSBPDMODE`](API-socket-options.md#SRTO_TSBPDMODE)
and [`SRTO_TLPKTDROP`](API-socket-options.md#SRTO_TLPKTDROP), the message will be
received only when its time to play has come, and until then it will be kept in the
receiver buffer. Also, when the time to play has come for a message that is next to
Expand Down
10 changes: 6 additions & 4 deletions docs/API/API-socket-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ The following table lists SRT API socket options in alphabetical order. Option d
| [`SRTO_RCVSYN`](#SRTO_RCVSYN) | | post | `bool` | | true | | RW | GSI |
| [`SRTO_RCVTIMEO`](#SRTO_RCVTIMEO) | | post | `int32_t` | ms | -1 | -1, 0.. | RW | GSI |
| [`SRTO_RENDEZVOUS`](#SRTO_RENDEZVOUS) | | pre | `bool` | | false | | RW | S |
| [`SRTO_RETRANSMITALGO`](#SRTO_RETRANSMITALGO) | 1.4.2 | pre | `int32_t` | | 0 | [0, 1] | RW | GSD |
| [`SRTO_RETRANSMITALGO`](#SRTO_RETRANSMITALGO) | 1.4.2 | pre | `int32_t` | | 1 | [0, 1] | RW | GSD |
| [`SRTO_REUSEADDR`](#SRTO_REUSEADDR) | | pre-bind | `bool` | | true | | RW | GSD |
| [`SRTO_SENDER`](#SRTO_SENDER) | 1.0.4 | pre | `bool` | | false | | W | S |
| [`SRTO_SNDBUF`](#SRTO_SNDBUF) | | pre-bind | `int32_t` | bytes | 8192 payloads | \* | RW | GSD+ |
Expand Down Expand Up @@ -847,6 +847,8 @@ dedicated network settings. MSS is not to be confused with the size of the UDP
payload or SRT payload - this size is the size of the IP packet, including the
UDP and SRT headers*

THe value of `SRTO_MSS` must not exceed `SRTO_UDP_SNDBUF` or `SRTO_UDP_RCVBUF`.

[Return to list](#list-of-options)

---
Expand Down Expand Up @@ -1273,12 +1275,12 @@ procedure of `srt_bind` and then `srt_connect` (or `srt_rendezvous`) to one anot

| OptName | Since | Restrict | Type | Units | Default | Range | Dir | Entity |
| --------------------- | ----- | -------- | --------- | ------ | ------- | ------ | --- | ------ |
| `SRTO_RETRANSMITALGO` | 1.4.2 | pre | `int32_t` | | 0 | [0, 1] | RW | GSD |
| `SRTO_RETRANSMITALGO` | 1.4.2 | pre | `int32_t` | | 1 | [0, 1] | RW | GSD |

Retransmission algorithm to use (SENDER option):

- 0 - Default (retransmit on every loss report).
- 1 - Reduced retransmissions (not more often than once per RTT); reduced
- 0 - Retransmit on every loss report (higher overhead, but slightly higher chance to recover a lost packet).
- 1 - Reduced retransmissions (retransmit not more often than once per RTT); reduced
bandwidth consumption.

This option is effective only on the sending side. It influences the decision
Expand Down
38 changes: 22 additions & 16 deletions docs/API/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,15 @@ either `FASTREXMIT` or `LATEREXMIT`. This will be explained below.

Setting `SRTO_TRANSTYPE` to `SRTT_LIVE` sets the following [socket options](API-socket-options.md):

- `SRTO_TSBPDMODE` = true
- `SRTO_RCVLATENCY` = 120
- `SRTO_PEERLATENCY` = 0
- `SRTO_TLPKTDROP` = true
- `SRTO_MESSAGEAPI` = true
- `SRTO_NAKREPORT` = true
- `SRTO_PAYLOADSIZE` = 1316
- `SRTO_CONGESTION` = "live"
- [`SRTO_TSBPDMODE`](API-socket-options.md#SRTO_TSBPDMODE) = true
- [`SRTO_RCVLATENCY`](API-socket-options.md#SRTO_RCVLATENCY) = 120
- [`SRTO_PEERLATENCY`](API-socket-options.md#SRTO_PEERLATENCY) = 0
- [`SRTO_TLPKTDROP`](API-socket-options.md#SRTO_TLPKTDROP) = true
- [`SRTO_MESSAGEAPI`](API-socket-options.md#SRTO_MESSAGEAPI) = true
- [`SRTO_NAKREPORT`](API-socket-options.md#SRTO_NAKREPORT) = true
- [`SRTO_RETRANSMITALGO`](API-socket-options.md#SRTO_RETRANSMITALGO) = 1
- [`SRTO_PAYLOADSIZE`](API-socket-options.md#SRTO_PAYLOADSIZE) = 1316
- [`SRTO_CONGESTION`](API-socket-options.md#SRTO_CONGESTION) = "live"

In this mode, every call to a sending function is allowed to send only
so much data, as declared by `SRTO_PAYLOADSIZE`, whose value is still
Expand Down Expand Up @@ -580,6 +581,10 @@ loss report itself was lost. Without it, the loss report will be always reported
just once and never repeated again, and then the lost payload packet will
be probably dropped by the TLPKTDROP mechanism.

- `SRTO_RETRANSMITALGO`: Given the receiver sends periodic NAK reports,
the sender can reduce the retransmission overhead by not retransmitting a loss
more often than once per RTT (value 1).

- `SRTO_PAYLOADSIZE`: Default value is for MPEG TS. If you are going
to use SRT to send any different kind of payload, such as, for example,
wrapping a live stream in very small frames, then you can use a bigger
Expand All @@ -598,14 +603,15 @@ NAKREPORT method is considered so effective that FASTREXMIT isn't necessary.

Setting `SRTO_TRANSTYPE` to `SRTT_FILE` sets the following [socket options](API-socket-options.md):

- `SRTO_TSBPDMODE` = false
- `SRTO_RCVLATENCY` = 0
- `SRTO_PEERLATENCY` = 0
- `SRTO_TLPKTDROP` = false
- `SRTO_MESSAGEAPI` = false
- `SRTO_NAKREPORT` = false
- `SRTO_PAYLOADSIZE` = 0
- `SRTO_CONGESTION` = "file"
- [`SRTO_TSBPDMODE`](API-socket-options.md#SRTO_TSBPDMODE) = false
- [`SRTO_RCVLATENCY`](API-socket-options.md#SRTO_RCVLATENCY) = 0
- [`SRTO_PEERLATENCY`](API-socket-options.md#SRTO_PEERLATENCY) = 0
- [`SRTO_TLPKTDROP`](API-socket-options.md#SRTO_TLPKTDROP) = false
- [`SRTO_MESSAGEAPI`](API-socket-options.md#SRTO_MESSAGEAPI) = false
- [`SRTO_NAKREPORT`](API-socket-options.md#SRTO_NAKREPORT) = false
- [`SRTO_RETRANSMITALGO`](API-socket-options.md#SRTO_RETRANSMITALGO) = 0
- [`SRTO_PAYLOADSIZE`](API-socket-options.md#SRTO_PAYLOADSIZE) = 0
- [`SRTO_CONGESTION`](API-socket-options.md#SRTO_CONGESTION) = "file"

In this mode, calling a sending function is allowed to potentially send
virtually any size of data. The sending function will HANGUP only if the
Expand Down
Loading

0 comments on commit bd86d52

Please sign in to comment.