From e55f0d7aeec0016cd55434d5e586ee5d98f6f6a3 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Tue, 7 Jul 2020 12:01:28 -0700 Subject: [PATCH] transcoder management for 'none' --- src/ccodecstream.cpp | 17 +++++++++------ src/cdmriddir.cpp | 2 +- src/cgatekeeper.cpp | 2 +- src/cprotocols.cpp | 1 + src/creflector.cpp | 52 ++++++++++++++++++++------------------------ src/ctranscoder.cpp | 18 +++++++++------ src/cysfnodedir.cpp | 2 +- 7 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/ccodecstream.cpp b/src/ccodecstream.cpp index 33f1304..7600a71 100644 --- a/src/ccodecstream.cpp +++ b/src/ccodecstream.cpp @@ -90,30 +90,34 @@ CCodecStream::~CCodecStream() bool CCodecStream::Init(uint16 uiPort) { - // reset stop flag - m_bConnected = keep_running = true; + m_bConnected = keep_running = false; // prepare for the worst // create server's IP m_uiPort = uiPort; auto s = g_Reflector.GetTranscoderIp(); m_Ip.Initialize(strchr(s, ':') ? AF_INET6 : AF_INET, m_uiPort, s); + if (0 == strncasecmp(s, "none", 4)) + { + return true; // the user has disabled the transcoder + } + // create our socket if (m_Ip.IsSet()) { if (! m_Socket.Open(m_Ip)) { - std::cerr << "Error opening socket on port UDP" << uiPort << " on ip " << m_Ip << std::endl; + std::cerr << "Error opening socket on IP address " << m_Ip << std::endl; return false; } } else { - std::cerr << "Could not initialize Codec Stream on " << m_Ip << std::endl; + std::cerr << "Could not initialize Codec Stream on " << s << std::endl; return false; } + keep_running = m_bConnected = true; m_pThread = new std::thread(CCodecStream::Thread, this); - m_bConnected = true; return true; } @@ -121,11 +125,10 @@ bool CCodecStream::Init(uint16 uiPort) void CCodecStream::Close(void) { // close socket - m_bConnected = false; + keep_running = m_bConnected = false; m_Socket.Close(); // kill threads - keep_running = false; if ( m_pThread != NULL ) { m_pThread->join(); diff --git a/src/cdmriddir.cpp b/src/cdmriddir.cpp index 273204c..32ef787 100644 --- a/src/cdmriddir.cpp +++ b/src/cdmriddir.cpp @@ -59,7 +59,7 @@ bool CDmridDir::Init(void) // load content Reload(); - // reset stop flag + // reset run flag keep_running = true; // start thread; diff --git a/src/cgatekeeper.cpp b/src/cgatekeeper.cpp index 93b0213..2e21a8e 100644 --- a/src/cgatekeeper.cpp +++ b/src/cgatekeeper.cpp @@ -67,7 +67,7 @@ bool CGateKeeper::Init(void) m_NodeBlackList.LoadFromFile(BLACKLIST_PATH); m_PeerList.LoadFromFile(INTERLINKLIST_PATH); - // reset stop flag + // reset run flag keep_running = true; // start thread; diff --git a/src/cprotocols.cpp b/src/cprotocols.cpp index 3355f18..b205016 100644 --- a/src/cprotocols.cpp +++ b/src/cprotocols.cpp @@ -4,6 +4,7 @@ // // Created by Jean-Luc Deltombe (LX3JL) on 01/11/2015. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// Copyright © 2020 Thomas A. Early, N7TAE // // ---------------------------------------------------------------------------- // This file is part of xlxd. diff --git a/src/creflector.cpp b/src/creflector.cpp index 7682a09..9d961fa 100644 --- a/src/creflector.cpp +++ b/src/creflector.cpp @@ -97,48 +97,42 @@ CReflector::~CReflector() bool CReflector::Start(void) { - bool ok = true; - - // reset stop flag + // let's go! keep_running = true; - // init gate keeper - ok &= g_GateKeeper.Init(); + // init gate keeper. It can only return true! + g_GateKeeper.Init(); - // init dmrid directory + // init dmrid directory. No need to check the return value. g_DmridDir.Init(); - // init wiresx node directory + // init wiresx node directory. Likewise with the return vale. g_YsfNodeDir.Init(); // init the transcoder - g_Transcoder.Init(); + if (! g_Transcoder.Init()) + return false; // create protocols - ok &= m_Protocols.Init(); - - // if ok, start threads - if ( ok ) - { - // start one thread per reflector module - for ( int i = 0; i < NB_OF_MODULES; i++ ) - { - m_RouterThreads[i] = new std::thread(CReflector::RouterThread, this, &(m_Streams[i])); - } - - // start the reporting threads - m_XmlReportThread = new std::thread(CReflector::XmlReportThread, this); + if (! m_Protocols.Init()) + { + m_Protocols.Close(); + return false; + } + + // start one thread per reflector module + for ( int i = 0; i < NB_OF_MODULES; i++ ) + { + m_RouterThreads[i] = new std::thread(CReflector::RouterThread, this, &(m_Streams[i])); + } + + // start the reporting threads + m_XmlReportThread = new std::thread(CReflector::XmlReportThread, this); #ifdef JSON_MONITOR - m_JsonReportThread = new std::thread(CReflector::JsonReportThread, this); + m_JsonReportThread = new std::thread(CReflector::JsonReportThread, this); #endif - } - else - { - m_Protocols.Close(); - } - // done - return ok; + return true; } void CReflector::Stop(void) diff --git a/src/ctranscoder.cpp b/src/ctranscoder.cpp index 1991f5c..717ab26 100644 --- a/src/ctranscoder.cpp +++ b/src/ctranscoder.cpp @@ -69,15 +69,17 @@ CTranscoder::~CTranscoder() bool CTranscoder::Init(void) { - bool ok; - - // reset stop flag - keep_running = true; - // create server's IP auto s = g_Reflector.GetTranscoderIp(); m_Ip.Initialize(strchr(s, ':') ? AF_INET6 : AF_INET, TRANSCODER_PORT, s); + // does the user not want to use a transcoder? + if (0 == strncasecmp(s, "none", 4)) + { + std::cout << "Transcoder will not be enabled beacuse the transcoder IP addess is 'none'" << std::endl; + return true; + } + // create our socket if (m_Ip.IsSet()) { @@ -88,11 +90,13 @@ bool CTranscoder::Init(void) } else { - std::cerr << "Could not initialize transcoder socket on " << m_Ip << std::endl; + // something bad was specified for the transcoder IP? + std::cerr << "Could not initialize transcoder socket on '" << s << "'" << std::endl; return false; } - // start thread; + // start thread + keep_running = true; m_pThread = new std::thread(CTranscoder::Thread, this); return true; diff --git a/src/cysfnodedir.cpp b/src/cysfnodedir.cpp index e654f30..39e2e24 100644 --- a/src/cysfnodedir.cpp +++ b/src/cysfnodedir.cpp @@ -58,7 +58,7 @@ bool CYsfNodeDir::Init(void) // load content Reload(); - // reset stop flag + // reset run flag keep_running = true; // start thread;