Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed Aug 10, 2020
2 parents 96b60c1 + 73c6b37 commit 840826c
Show file tree
Hide file tree
Showing 34 changed files with 1,769 additions and 953 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/cxx11-macos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: cxx11_win

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
name: macos-cxx11
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: configure
run: |
mkdir _build && cd _build
cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON
- name: build
run: cd _build && cmake --build ./
- name: test
run: cd _build && ctest --extra-verbose
23 changes: 23 additions & 0 deletions .github/workflows/cxx11-ubuntu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: cxx11_win

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
name: ubuntu-cxx11
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
- name: configure
run: |
mkdir _build && cd _build
cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_UNITTESTS=ON
- name: build
run: cd _build && cmake --build ./
- name: test
run: cd _build && ctest --extra-verbose
1 change: 1 addition & 0 deletions .github/workflows/cxx11-win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
jobs:
build:

name: windows-cxx11
runs-on: windows-latest

steps:
Expand Down
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ addons:
- cmake
- libssl-dev
- build-essential
- ninja-build
sonarcloud:
organization: "haivision"
token:
Expand Down Expand Up @@ -59,7 +60,7 @@ script:
export CXX="x86_64-w64-mingw32-g++";
cmake . -DCMAKE_BUILD_TYPE=$BUILD_TYPE $BUILD_OPTS -DENABLE_UNITTESTS="ON" -DUSE_OPENSSL_PC="OFF" -DOPENSSL_ROOT_DIR="$PWD/openssl" -DCMAKE_SYSTEM_NAME="Windows";
elif [ "$TRAVIS_OS_NAME" == "linux" ]; then
cmake . -DCMAKE_BUILD_TYPE=$BUILD_TYPE $BUILD_OPTS -DENABLE_UNITTESTS="ON";
cmake . -G Ninja -DCMAKE_BUILD_TYPE=$BUILD_TYPE $BUILD_OPTS -DENABLE_UNITTESTS="ON";
elif [ "$TRAVIS_OS_NAME" == "osx" ]; then
export PKG_CONFIG_PATH=$(brew --prefix openssl)"/lib/pkgconfig";
cmake . -DCMAKE_BUILD_TYPE=$BUILD_TYPE $BUILD_OPTS -DENABLE_UNITTESTS="ON";
Expand All @@ -72,6 +73,8 @@ script:
- echo "RUN_SONARCUBE=$RUN_SONARCUBE"
- if (( "$RUN_SONARCUBE" )); then
build-wrapper-linux-x86-64 --out-dir bw-output make;
elif [ -f build.ninja ]; then
ninja -v;
else
make;
fi
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Intel|Clang|AppleClang")
# At the bottom there's information about C++98, which is default up to 6.1 version.
# For all other compilers - including Clang - we state that the default C++ standard is AT LEAST 11.
if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 6.1)
message(STATUS "NOTE: GCC ${CMAKE_CXX_COMPILER_VERSION} is detected with default C++98. Forcing C++11 on applications.")
message(STATUS "NOTE: GCC ${CMAKE_CXX_COMPILER_VERSION} is detected with default C++98. Forcing C++11 on applications.")
set (FORCE_CXX_STANDARD 1)
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang|AppleClang")
message(STATUS "NOTE: CLANG ${CMAKE_CXX_COMPILER_VERSION} detected, unsure if >=C++11 is default, forcing C++11 on applications")
set (FORCE_CXX_STANDARD 1)
else()
message(STATUS "NOTE: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} - assuming default C++11.")
message(STATUS "NOTE: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} - assuming default C++11.")
endif()
else()
message(STATUS "COMPILER: ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER}) - NOT GNU compat")
Expand Down Expand Up @@ -629,7 +629,8 @@ if (ENABLE_CODE_COVERAGE)
endif()
endif()

if (ENABLE_STDCXX_SYNC)
# On Linux pthreads have to be linked even when using C++11 threads
if (ENABLE_STDCXX_SYNC AND NOT LINUX)
message(STATUS "Pthread library: C++11")
elseif (PTHREAD_LIBRARY AND PTHREAD_INCLUDE_DIR)
message(STATUS "Pthread library: ${PTHREAD_LIBRARY}")
Expand Down
3 changes: 2 additions & 1 deletion apps/socketoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ const SocketOption srt_options [] {
{ "snddropdelay", 0, SRTO_SNDDROPDELAY, SocketOption::POST, SocketOption::INT, nullptr},
{ "nakreport", 0, SRTO_NAKREPORT, SocketOption::PRE, SocketOption::BOOL, nullptr},
{ "conntimeo", 0, SRTO_CONNTIMEO, SocketOption::PRE, SocketOption::INT, nullptr},
{ "drifttracer", 0, SRTO_DRIFTTRACER, SocketOption::POST, SocketOption::BOOL, nullptr},
{ "lossmaxttl", 0, SRTO_LOSSMAXTTL, SocketOption::PRE, SocketOption::INT, nullptr},
{ "rcvlatency", 0, SRTO_RCVLATENCY, SocketOption::PRE, SocketOption::INT, nullptr},
{ "peerlatency", 0, SRTO_PEERLATENCY, SocketOption::PRE, SocketOption::INT, nullptr},
Expand All @@ -245,7 +246,7 @@ const SocketOption srt_options [] {
{ "packetfilter", 0, SRTO_PACKETFILTER, SocketOption::PRE, SocketOption::STRING, nullptr },
{ "groupconnect", 0, SRTO_GROUPCONNECT, SocketOption::PRE, SocketOption::INT, nullptr},
{ "groupstabtimeo", 0, SRTO_GROUPSTABTIMEO, SocketOption::PRE, SocketOption::INT, nullptr},
{ "rexmitalgo", 0, SRTO_RETRANSMISSION_ALGORITHM, SocketOption::PRE, SocketOption::INT, nullptr }
{ "retransmitalgo", 0, SRTO_RETRANSMITALGO, SocketOption::PRE, SocketOption::INT, nullptr }
};
}

Expand Down
8 changes: 4 additions & 4 deletions apps/srt-file-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ bool DoUpload(UriParser& ut, string path, string filename,
size_t shift = 0;
while (n > 0)
{
int st = tar->Write(buf.data() + shift, n, out_stats);
int st = tar->Write(buf.data() + shift, n, 0, out_stats);
Verb() << "Upload: " << n << " --> " << st
<< (!shift ? string() : "+" + Sprint(shift));
if (st == SRT_ERROR)
Expand Down Expand Up @@ -574,7 +574,7 @@ bool DoDownload(UriParser& us, string directory, string filename,

if (connected)
{
vector<char> buf(cfg.chunk_size);
MediaPacket packet(cfg.chunk_size);

if (!ofile.is_open())
{
Expand All @@ -591,7 +591,7 @@ bool DoDownload(UriParser& us, string directory, string filename,
cerr << "Writing output to [" << directory << "]" << endl;
}

int n = src->Read(cfg.chunk_size, buf, out_stats);
int n = src->Read(cfg.chunk_size, packet, out_stats);
if (n == SRT_ERROR)
{
cerr << "Download: SRT error: " << srt_getlasterror_str() << endl;
Expand All @@ -607,7 +607,7 @@ bool DoDownload(UriParser& us, string directory, string filename,

// Write to file any amount of data received
Verb() << "Download: --> " << n;
ofile.write(buf.data(), n);
ofile.write(packet.payload.data(), n);
if (!ofile.good())
{
cerr << "Error writing file" << endl;
Expand Down
61 changes: 41 additions & 20 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ struct LiveTransmitConfig
bool log_internal;
string logfile;
int bw_report = 0;
bool srctime = false;
size_t buffering = 10;
int stats_report = 0;
string stats_out;
SrtStatsPrintFormat stats_pf = SRTSTATS_PROFMAT_2COLS;
Expand Down Expand Up @@ -171,6 +173,8 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)
o_autorecon = { "a", "auto", "autoreconnect" },
o_chunk = { "c", "chunk" },
o_bwreport = { "r", "bwreport", "report", "bandwidth-report", "bitrate-report" },
o_srctime = {"st", "srctime", "sourcetime"},
o_buffering = {"buffering"},
o_statsrep = { "s", "stats", "stats-report-frequency" },
o_statsout = { "statsout" },
o_statspf = { "pf", "statspf" },
Expand All @@ -190,6 +194,8 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)
{ o_autorecon, OptionScheme::ARG_ONE },
{ o_chunk, OptionScheme::ARG_ONE },
{ o_bwreport, OptionScheme::ARG_ONE },
{ o_srctime, OptionScheme::ARG_ONE },
{ o_buffering, OptionScheme::ARG_ONE },
{ o_statsrep, OptionScheme::ARG_ONE },
{ o_statsout, OptionScheme::ARG_ONE },
{ o_statspf, OptionScheme::ARG_ONE },
Expand Down Expand Up @@ -236,15 +242,17 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)
PrintOptionHelp(o_timeout, "<timeout=0>", "exit timer in seconds");
PrintOptionHelp(o_timeout_mode, "<mode=0>", "timeout mode (0 - since app start; 1 - like 0, but cancel on connect");
#endif
PrintOptionHelp(o_autorecon, "<enabled=yes>", "auto-reconnect mode [yes|no]");
PrintOptionHelp(o_autorecon, "<enabled=yes>", "auto-reconnect mode {yes, no}");
PrintOptionHelp(o_chunk, "<chunk=1456>", "max size of data read in one step, that can fit one SRT packet");
PrintOptionHelp(o_bwreport, "<every_n_packets=0>", "bandwidth report frequency");
PrintOptionHelp(o_srctime, "<enabled=yes>", "Pass packet time from source to SRT output {yes, no}");
PrintOptionHelp(o_buffering, "<packets=n>", "Buffer up to n incoming packets");
PrintOptionHelp(o_statsrep, "<every_n_packets=0>", "frequency of status report");
PrintOptionHelp(o_statsout, "<filename>", "output stats to file");
PrintOptionHelp(o_statspf, "<format=default>", "stats printing format [json|csv|default]");
PrintOptionHelp(o_statspf, "<format=default>", "stats printing format {json, csv, default}");
PrintOptionHelp(o_statsfull, "", "full counters in stats-report (prints total statistics)");
PrintOptionHelp(o_loglevel, "<level=error>", "log level [fatal,error,info,note,warning]");
PrintOptionHelp(o_logfa, "<fas=general,...>", "log functional area [all,general,bstats,control,data,tsbpd,rexmit]");
PrintOptionHelp(o_loglevel, "<level=error>", "log level {fatal,error,info,note,warning}");
PrintOptionHelp(o_logfa, "<fas=general,...>", "log functional area {all,general,bstats,control,data,tsbpd,rexmit}");
//PrintOptionHelp(o_log_internal, "", "use internal logger");
PrintOptionHelp(o_logfile, "<filename="">", "write logs to file");
PrintOptionHelp(o_quiet, "", "quiet mode (default off)");
Expand Down Expand Up @@ -273,6 +281,17 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)
cfg.timeout = Option<OutNumber>(params, o_timeout);
cfg.timeout_mode = Option<OutNumber>(params, o_timeout_mode);
cfg.chunk_size = Option<OutNumber>(params, "-1", o_chunk);
cfg.srctime = Option<OutBool>(params, cfg.srctime, o_srctime);
const int buffering = Option<OutNumber>(params, "10", o_buffering);
if (buffering <= 0)
{
cerr << "ERROR: Buffering value should be positive. Value provided: " << buffering << "." << endl;
return 1;
}
else
{
cfg.buffering = (size_t) buffering;
}
cfg.bw_report = Option<OutNumber>(params, o_bwreport);
cfg.stats_report = Option<OutNumber>(params, o_statsrep);
cfg.stats_out = Option<OutString>(params, o_statsout);
Expand Down Expand Up @@ -708,15 +727,13 @@ int main(int argc, char** argv)
// read buffers as much as possible on each read event
// note that this implies live streams and does not
// work for cached/file sources
std::list<std::shared_ptr<bytevector>> dataqueue;
std::list<std::shared_ptr<MediaPacket>> dataqueue;
if (src.get() && src->IsOpen() && (srtrfdslen || sysrfdslen))
{
while (dataqueue.size() < 10)
while (dataqueue.size() < cfg.buffering)
{
std::shared_ptr<bytevector> pdata(
new bytevector(transmit_chunk_size));

const int res = src->Read(transmit_chunk_size, *pdata, out_stats);
std::shared_ptr<MediaPacket> pkt(new MediaPacket(transmit_chunk_size));
const int res = src->Read(transmit_chunk_size, *pkt, out_stats);

if (res == SRT_ERROR && src->uri.type() == UriParser::SRT)
{
Expand All @@ -728,28 +745,32 @@ int main(int argc, char** argv)
);
}

if (res == 0 || pdata->empty())
if (res == 0 || pkt->payload.empty())
{
break;
}

dataqueue.push_back(pdata);
receivedBytes += (*pdata).size();
dataqueue.push_back(pkt);
receivedBytes += pkt->payload.size();
}
}

// if no target, let received data fall to the floor
// if there is no target, let the received data be lost
while (!dataqueue.empty())
{
std::shared_ptr<bytevector> pdata = dataqueue.front();
if (!tar.get() || !tar->IsOpen()) {
lostBytes += (*pdata).size();
std::shared_ptr<MediaPacket> pkt = dataqueue.front();
if (!tar.get() || !tar->IsOpen())
{
lostBytes += pkt->payload.size();
}
else if (!tar->Write(pdata->data(), pdata->size(), out_stats)) {
lostBytes += (*pdata).size();
else if (!tar->Write(pkt->payload.data(), pkt->payload.size(), cfg.srctime ? pkt->time : 0, out_stats))
{
lostBytes += pkt->payload.size();
}
else
wroteBytes += (*pdata).size();
{
wroteBytes += pkt->payload.size();
}

dataqueue.pop_front();
}
Expand Down
9 changes: 5 additions & 4 deletions apps/srt-tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,13 @@ void TcpMedium::CreateListener()
{
int backlog = 5; // hardcoded!

m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
ConfigurePre();

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

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

int stat = ::bind(m_socket, sa.get(), sa.size());

if (stat == -1)
{
Expand Down Expand Up @@ -731,7 +732,7 @@ void TcpMedium::Connect()
{
sockaddr_any sa = CreateAddr(m_uri.host(), m_uri.portno());

int st = ::connect(m_socket, sa.get(), sizeof sa);
int st = ::connect(m_socket, sa.get(), sa.size());
if (st == -1)
Error(errno, "connect");

Expand Down
18 changes: 16 additions & 2 deletions apps/transmitbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ extern unsigned long transmit_bw_report;
extern unsigned long transmit_stats_report;
extern unsigned long transmit_chunk_size;

struct MediaPacket
{
bytevector payload;
int64_t time = 0;

MediaPacket(bytevector&& src) : payload(std::move(src)) {}
MediaPacket(bytevector&& src, int64_t stime) : payload(std::move(src)), time(stime) {}

MediaPacket(size_t payload_size) : payload(payload_size), time(0) {}
MediaPacket(const bytevector& src) : payload(src) {}
MediaPacket(const bytevector& src, int64_t stime) : payload(src), time(stime) {}
MediaPacket() {}
};

extern std::shared_ptr<SrtStatsWriter> transmit_stats_writer;

class Location
Expand All @@ -40,7 +54,7 @@ class Location
class Source: public Location
{
public:
virtual int Read(size_t chunk, bytevector& data, std::ostream &out_stats = std::cout) = 0;
virtual int Read(size_t chunk, MediaPacket& pkt, std::ostream &out_stats = std::cout) = 0;
virtual bool IsOpen() = 0;
virtual bool End() = 0;
static std::unique_ptr<Source> Create(const std::string& url);
Expand All @@ -63,7 +77,7 @@ class Source: public Location
class Target: public Location
{
public:
virtual int Write(const char* data, size_t size, std::ostream &out_stats = std::cout) = 0;
virtual int Write(const char* data, size_t size, int64_t src_time, std::ostream &out_stats = std::cout) = 0;
virtual bool IsOpen() = 0;
virtual bool Broken() = 0;
virtual void Close() {}
Expand Down
Loading

0 comments on commit 840826c

Please sign in to comment.