From cc2de9c8abe5b241594c69aa0d011bce72378b37 Mon Sep 17 00:00:00 2001 From: Maxim Sharabayko Date: Thu, 10 Oct 2024 16:27:52 +0200 Subject: [PATCH] Fixed build on GCC 4.8.5. --- xtransmit/misc.hpp | 1 - xtransmit/receive.cpp | 45 ++++++++++++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/xtransmit/misc.hpp b/xtransmit/misc.hpp index 535aea2..59e0c34 100644 --- a/xtransmit/misc.hpp +++ b/xtransmit/misc.hpp @@ -55,7 +55,6 @@ inline std::string print_timestamp_now() #endif // HAS_PUT_TIME - struct stats_config { int stats_freq_ms = 0; diff --git a/xtransmit/receive.cpp b/xtransmit/receive.cpp index 5ebbd3e..a9b148f 100644 --- a/xtransmit/receive.cpp +++ b/xtransmit/receive.cpp @@ -22,7 +22,10 @@ #include "apputil.hpp" #include "uriparser.hpp" -using namespace std; +using std::vector; +using std::unique_ptr; +using std::atomic_bool; +using std::string; using namespace xtransmit; using namespace xtransmit::receive; using namespace std::chrono; @@ -32,33 +35,53 @@ using shared_sock = std::shared_ptr; #define LOG_SC_RECEIVE "RECEIVE " + +namespace xtransmit +{ +namespace details +{ +#if defined(_MSC_VER) || __cplusplus >= 201402L // C++14 and beyond + using std::make_unique; +#else + template + std::unique_ptr make_unique(Args &&... args) + { + static_assert(!std::is_array::value, "arrays are not supported"); + return std::unique_ptr(new T(std::forward(args)...)); + } +#endif +} +} + void trace_message(const size_t bytes, const vector& buffer, SOCKET conn_id) { - ::cout << "RECEIVED MESSAGE length " << bytes << " on conn ID " << conn_id; + using std::cout; + cout << "RECEIVED MESSAGE length " << bytes << " on conn ID " << conn_id; #if 0 if (bytes < 50) { - ::cout << ":\n"; - ::cout << string(buffer.data(), bytes).c_str(); + cout << ":\n"; + cout << string(buffer.data(), bytes).c_str(); } else if (buffer[0] >= '0' && buffer[0] <= 'z') { - ::cout << " (first character):"; - ::cout << buffer[0]; + cout << " (first character):"; + cout << buffer[0]; } #endif - ::cout << endl; + cout << std::endl; // CHandShake hs; // if (hs.load_from(buffer.data(), buffer.size()) < 0) // return; // - //::cout << "SRT HS: " << hs.show() << endl; + //cout << "SRT HS: " << hs.show() << endl; } void run_pipe(shared_sock src, const config& cfg, unique_ptr& metrics, std::function const& on_done, const atomic_bool& force_break) { + using std::make_shared; socket::isocket& sock = *src.get(); const auto conn_id = sock.id(); @@ -128,10 +151,10 @@ void xtransmit::receive::run(const std::vector& src_urls, if (write_metrics) { try { - metrics = make_unique( + metrics = details::make_unique( cfg.metrics_file, milliseconds(cfg.metrics_freq_ms)); } - catch (const runtime_error& e) + catch (const std::runtime_error& e) { spdlog::error(LOG_SC_RECEIVE "{}", e.what()); return; @@ -144,7 +167,7 @@ void xtransmit::receive::run(const std::vector& src_urls, CLI::App* xtransmit::receive::add_subcommand(CLI::App& app, config& cfg, std::vector& src_urls) { - const map to_ms{{"s", 1000}, {"ms", 1}}; + const std::map to_ms{{"s", 1000}, {"ms", 1}}; CLI::App* sc_receive = app.add_subcommand("receive", "Receive data (SRT, UDP)")->fallthrough(); sc_receive->add_option("-i,--input,src", src_urls, "Source URI");