From e50b490bb3ebeceb5eb0f05b5c4574340c231793 Mon Sep 17 00:00:00 2001 From: Maxim Sharabayko Date: Thu, 5 Nov 2020 18:48:45 +0100 Subject: [PATCH] Group connection works now --- xtransmit/receive.cpp | 48 ++++++++++++++++++++-------------- xtransmit/receive.hpp | 2 +- xtransmit/srt_socket_group.cpp | 13 +++------ xtransmit/xtransmit-app.cpp | 2 +- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/xtransmit/receive.cpp b/xtransmit/receive.cpp index ee71fcd..15f532a 100644 --- a/xtransmit/receive.cpp +++ b/xtransmit/receive.cpp @@ -138,9 +138,19 @@ void run_pipe(shared_sock src, const config &cfg, const atomic_bool &force_break } } -void xtransmit::receive::run(const string &src_url, const config &cfg, const atomic_bool &force_break) +void xtransmit::receive::run(const vector &src_urls, const config &cfg, const atomic_bool &force_break) { - const UriParser uri(src_url); + if (src_urls.empty()) + { + spdlog::error(LOG_SC_RECEIVE "No destination URI was provided"); + return; + } + + vector urls; + for (const string& url : src_urls) + { + urls.emplace_back(url); + } shared_sock socket; shared_sock connection; @@ -154,29 +164,27 @@ void xtransmit::receive::run(const string &src_url, const config &cfg, const ato : nullptr; do { - if (uri.proto() == "udp") - { - connection = make_shared(uri); - } - else if (cfg.inputs.empty()) + if (urls.size() == 1) { - socket = make_shared(uri); - socket::srt* s = static_cast(socket.get()); - const bool accept = s->mode() == socket::srt::LISTENER; - if (accept) - s->listen(); - connection = accept ? s->accept() : s->connect(); + if (urls[0].proto() == "udp") + { + connection = make_shared(urls[0]); + } + else + { + socket = make_shared(urls[0]); + socket::srt* s = static_cast(socket.get()); + const bool accept = s->mode() == socket::srt::LISTENER; + if (accept) + s->listen(); + connection = accept ? s->accept() : s->connect(); + } } else { - vector urls; - urls.push_back(src_url); - for (auto u : cfg.inputs) - urls.push_back(u); - - socket = make_shared(urls); + socket = make_shared(urls); socket::srt_group* s = static_cast(socket.get()); - const bool accept = s->mode() == socket::srt_group::LISTENER; + const bool accept = s->mode() == socket::srt_group::LISTENER; if (accept) s->listen(); connection = accept ? s->accept() : s->connect(); diff --git a/xtransmit/receive.hpp b/xtransmit/receive.hpp index d5041e0..9c3dc2b 100644 --- a/xtransmit/receive.hpp +++ b/xtransmit/receive.hpp @@ -27,7 +27,7 @@ namespace xtransmit { - void run(const std::string& url, const config& cfg, + void run(const std::vector& urls, const config& cfg, const std::atomic_bool& force_break); CLI::App* add_subcommand(CLI::App& app, config& cfg, std::vector& src_urls); diff --git a/xtransmit/srt_socket_group.cpp b/xtransmit/srt_socket_group.cpp index acbaaf5..1525703 100644 --- a/xtransmit/srt_socket_group.cpp +++ b/xtransmit/srt_socket_group.cpp @@ -112,11 +112,6 @@ socket::srt_group::srt_group(const vector& uris) // Will throw an exception if invalid options were provided. srt::assert_options_valid(m_options); - if (this->mode() == CALLER) - { - m_bind_socket = srt_create_group(SRT_GTYPE_BROADCAST); - } - // Create SRT socket group if (m_mode == LISTENER) { @@ -154,7 +149,7 @@ void socket::srt_group::create_listeners(const vector& src_uri) sockaddr_any sa = CreateAddr(url.host(), url.portno()); SRTSOCKET s = srt_create_socket(); - if (m_bind_socket == SRT_INVALID_SOCK) + if (s == SRT_INVALID_SOCK) throw socket::exception(srt_getlasterror_str()); int gcon = 1; @@ -173,7 +168,7 @@ void socket::srt_group::create_callers(const vector& uris) { m_bind_socket = srt_create_group(SRT_GTYPE_BROADCAST); if (m_bind_socket == SRT_INVALID_SOCK) - throw ; + raise_exception("srt_create_group"); for (const auto& uri :uris) { @@ -255,7 +250,7 @@ void socket::srt_group::release_targets() shared_srt_group socket::srt_group::connect() { const int st = srt_connect_group(m_bind_socket, m_targets.data(), m_targets.size()); - if (st != SRT_SUCCESS) + if (st == SRT_ERROR) raise_exception("srt_group::connect"); release_targets(); @@ -265,7 +260,7 @@ shared_srt_group socket::srt_group::connect() int socket::srt_group::configure_pre(SRTSOCKET sock) { int maybe = m_blocking_mode ? 1 : 0; - int result = srt_setsockopt(sock, 0, SRTO_RCVSYN, &maybe, sizeof maybe); + const int result = srt_setsockopt(sock, 0, SRTO_RCVSYN, &maybe, sizeof maybe); if (result == -1) return result; diff --git a/xtransmit/xtransmit-app.cpp b/xtransmit/xtransmit-app.cpp index 3b187e8..901eac2 100644 --- a/xtransmit/xtransmit-app.cpp +++ b/xtransmit/xtransmit-app.cpp @@ -171,7 +171,7 @@ int main(int argc, char **argv) { cout << "URL: " << url << "\n"; } - xtransmit::receive::run(src, cfg_receive, force_break); + xtransmit::receive::run(src_urls, cfg_receive, force_break); return 0; } else if (sc_route->parsed())