diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 633be30b..ce1895d0 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -2,6 +2,7 @@ // stl includes #include +#include // QT includes #include @@ -46,6 +47,7 @@ class Hyperion : public QObject public: /// Type definition of the info structure used by the priority muxer typedef PriorityMuxer::InputInfo InputInfo; + typedef std::map PriorityRegister; /// /// RGB-Color channel enumeration @@ -109,11 +111,24 @@ public: /// @return The list of active effects const std::list &getActiveEffects(); - /// + /// gets the current json config object + /// @return json config const Json::Value& getJsonConfig() { return _jsonConfig; }; - + + /// get filename of configfile + /// @return the current config filename std::string getConfigFileName() { return _configFile; }; + /// register a input source to a priority channel + /// @param name uniq name of input source + /// @param priority priority channel + void registerPriority(const std::string name, const int priority); + + /// unregister a input source to a priority channel + /// @param name uniq name of input source + void unRegisterPriority(const std::string name); + + const PriorityRegister& getPriorityRegister() { return _priorityRegister; } public slots: /// /// Writes a single color to all the leds for the given time and priority @@ -307,4 +322,7 @@ private: /// count of hardware leds unsigned _hwLedCount; + + /// register of input sources and it's prio channel + PriorityRegister _priorityRegister; }; diff --git a/libsrc/boblightserver/BoblightClientConnection.cpp b/libsrc/boblightserver/BoblightClientConnection.cpp index 5ae424b4..d794bc71 100644 --- a/libsrc/boblightserver/BoblightClientConnection.cpp +++ b/libsrc/boblightserver/BoblightClientConnection.cpp @@ -22,15 +22,15 @@ // project includes #include "BoblightClientConnection.h" -BoblightClientConnection::BoblightClientConnection(QTcpSocket *socket, const int priority, Hyperion * hyperion) +BoblightClientConnection::BoblightClientConnection(QTcpSocket *socket, const int priority) : QObject() , _locale(QLocale::C) , _socket(socket) , _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()) - , _hyperion(hyperion) + , _hyperion(Hyperion::getInstance()) , _receiveBuffer() , _priority(priority) - , _ledColors(hyperion->getLedCount(), ColorRgb::BLACK) + , _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb::BLACK) , _log(Logger::getInstance("BOBLIGHT")) { // initalize the locale. Start with the default C-locale diff --git a/libsrc/boblightserver/BoblightClientConnection.h b/libsrc/boblightserver/BoblightClientConnection.h index d73c4960..6f91060c 100644 --- a/libsrc/boblightserver/BoblightClientConnection.h +++ b/libsrc/boblightserver/BoblightClientConnection.h @@ -27,7 +27,7 @@ public: /// @param socket The Socket object for this connection /// @param hyperion The Hyperion server /// - BoblightClientConnection(QTcpSocket * socket, const int priority, Hyperion * hyperion); + BoblightClientConnection(QTcpSocket * socket, const int priority); /// /// Destructor diff --git a/libsrc/boblightserver/BoblightServer.cpp b/libsrc/boblightserver/BoblightServer.cpp index 46f54e27..a8176bf2 100644 --- a/libsrc/boblightserver/BoblightServer.cpp +++ b/libsrc/boblightserver/BoblightServer.cpp @@ -37,6 +37,9 @@ void BoblightServer::start() _isActive = true; emit statusChanged(_isActive); + + _hyperion->registerPriority("Boblight", _priority); + } void BoblightServer::stop() @@ -49,6 +52,9 @@ void BoblightServer::stop() } _isActive = false; emit statusChanged(_isActive); + + _hyperion->unRegisterPriority("Boblight"); + } @@ -64,7 +70,7 @@ void BoblightServer::newConnection() if (socket != nullptr) { Info(_log, "new connection"); - BoblightClientConnection * connection = new BoblightClientConnection(socket, _priority, _hyperion); + BoblightClientConnection * connection = new BoblightClientConnection(socket, _priority); _openConnections.insert(connection); // register slot for cleaning up after the connection closed diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index a22fd3cf..a27261eb 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -181,6 +181,7 @@ int EffectEngine::runEffectScript(const std::string &script, const Json::Value & _activeEffects.push_back(effect); // start the effect + _hyperion->registerPriority("EFFECT: "+script, priority); effect->start(); return 0; @@ -225,4 +226,5 @@ void EffectEngine::effectFinished(Effect *effect) // cleanup the effect effect->deleteLater(); + _hyperion->unRegisterPriority("EFFECT: " + effect->getScript()); } diff --git a/libsrc/grabber/amlogic/AmlogicWrapper.cpp b/libsrc/grabber/amlogic/AmlogicWrapper.cpp index 2506d79b..c4efcc77 100644 --- a/libsrc/grabber/amlogic/AmlogicWrapper.cpp +++ b/libsrc/grabber/amlogic/AmlogicWrapper.cpp @@ -31,6 +31,8 @@ AmlogicWrapper::AmlogicWrapper(const unsigned grabWidth, const unsigned grabHeig // Connect the QTimer to this QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); + + _hyperion->registerPriority("Amlogic Grabber", _priority); } AmlogicWrapper::~AmlogicWrapper() diff --git a/libsrc/grabber/dispmanx/DispmanxWrapper.cpp b/libsrc/grabber/dispmanx/DispmanxWrapper.cpp index cec8ee65..0a070138 100644 --- a/libsrc/grabber/dispmanx/DispmanxWrapper.cpp +++ b/libsrc/grabber/dispmanx/DispmanxWrapper.cpp @@ -31,6 +31,8 @@ DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHe // Connect the QTimer to this QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); + + _hyperion->registerPriority("Dispmanx Grabber", _priority); } DispmanxWrapper::~DispmanxWrapper() diff --git a/libsrc/grabber/framebuffer/FramebufferWrapper.cpp b/libsrc/grabber/framebuffer/FramebufferWrapper.cpp index 57abf697..e3732c29 100644 --- a/libsrc/grabber/framebuffer/FramebufferWrapper.cpp +++ b/libsrc/grabber/framebuffer/FramebufferWrapper.cpp @@ -26,6 +26,8 @@ FramebufferWrapper::FramebufferWrapper(const std::string & device, const unsigne // Connect the QTimer to this QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); + + _hyperion->registerPriority("FrameBuffer Grabber", _priority); } FramebufferWrapper::~FramebufferWrapper() diff --git a/libsrc/grabber/osx/OsxWrapper.cpp b/libsrc/grabber/osx/OsxWrapper.cpp index e891ddb2..b2cda007 100644 --- a/libsrc/grabber/osx/OsxWrapper.cpp +++ b/libsrc/grabber/osx/OsxWrapper.cpp @@ -26,6 +26,8 @@ OsxWrapper::OsxWrapper(const unsigned display, const unsigned grabWidth, const u // Connect the QTimer to this QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); + + _hyperion->registerPriority("OsxFrameGrabber", _priority); } OsxWrapper::~OsxWrapper() diff --git a/libsrc/grabber/v4l2/V4L2Wrapper.cpp b/libsrc/grabber/v4l2/V4L2Wrapper.cpp index ca18df6f..3de05b5b 100644 --- a/libsrc/grabber/v4l2/V4L2Wrapper.cpp +++ b/libsrc/grabber/v4l2/V4L2Wrapper.cpp @@ -15,10 +15,10 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, double redSignalThreshold, double greenSignalThreshold, double blueSignalThreshold, - int hyperionPriority) : - _timeout_ms(1000), - _priority(hyperionPriority), - _grabber(device, + int hyperionPriority) + : _timeout_ms(1000) + , _priority(hyperionPriority) + , _grabber(device, input, videoStandard, pixelFormat, @@ -26,18 +26,16 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, height, frameDecimation, pixelDecimation, - pixelDecimation), - _processor(ImageProcessorFactory::getInstance().newImageProcessor()), - _hyperion(Hyperion::getInstance()), - _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0}), - _timer() + pixelDecimation) + , _processor(ImageProcessorFactory::getInstance().newImageProcessor()) + , _hyperion(Hyperion::getInstance()) + , _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0}) + , _timer() { // set the signal detection threshold of the grabber - _grabber.setSignalThreshold( - redSignalThreshold, - greenSignalThreshold, - blueSignalThreshold, - 50); + _grabber.setSignalThreshold( redSignalThreshold, greenSignalThreshold, blueSignalThreshold, 50); + + _hyperion->registerPriority("V4L2", _priority); // register the image type qRegisterMetaType>("Image"); @@ -55,6 +53,7 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, _hyperion, SLOT(setColors(int,std::vector,int)), Qt::QueuedConnection); + // setup the higher prio source checker // this will disable the v4l2 grabber when a source with hisher priority is active _timer.setInterval(500); diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index ec6405f8..0264fd99 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -541,32 +541,32 @@ MessageForwarder * Hyperion::getForwarder() return _messageForwarder; } -Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile) : - _ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))), - _muxer(_ledString.leds().size()), - _raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])), - _raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"])), - _raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), jsonConfig["color"])), - _device(LedDeviceFactory::construct(jsonConfig["device"])), - _effectEngine(nullptr), - _messageForwarder(createMessageForwarder(jsonConfig["forwarder"])), - _jsonConfig(jsonConfig), - _configFile(configFile), - _timer(), - _log(Logger::getInstance("Core")), - _hwLedCount(_ledString.leds().size()) +Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile) + : _ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))) + , _muxer(_ledString.leds().size()) + , _raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])) + , _raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"])) + , _raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), jsonConfig["color"])) + , _device(LedDeviceFactory::construct(jsonConfig["device"])) + , _effectEngine(nullptr) + , _messageForwarder(createMessageForwarder(jsonConfig["forwarder"])) + , _jsonConfig(jsonConfig) + , _configFile(configFile) + , _timer() + , _log(Logger::getInstance("Core")) + , _hwLedCount(_ledString.leds().size()) { if (!_raw2ledAdjustment->verifyAdjustments()) { - throw std::runtime_error("HYPERION ERROR: Color adjustment incorrectly set"); + throw std::runtime_error("Color adjustment incorrectly set"); } if (!_raw2ledTemperature->verifyCorrections()) { - throw std::runtime_error("HYPERION ERROR: Color temperature incorrectly set"); + throw std::runtime_error("Color temperature incorrectly set"); } if (!_raw2ledTransform->verifyTransforms()) { - throw std::runtime_error("HYPERION ERROR: Color transformation incorrectly set"); + throw std::runtime_error("Color transformation incorrectly set"); } // initialize the image processor factory ImageProcessorFactory::getInstance().init( @@ -614,6 +614,26 @@ unsigned Hyperion::getLedCount() const return _ledString.leds().size(); } +void Hyperion::registerPriority(const std::string name, const int priority) +{ + Info(_log, "Register new input source named '%s' for priority channel '%d'", name.c_str(), priority ); + + for(auto const &entry : _priorityRegister) + { + WarningIf( ( entry.first != name && entry.second == priority), _log, + "Input source '%s' uses same priority channel (%d) as '%s'.", name.c_str(), priority, entry.first.c_str()); + } + + _priorityRegister.emplace(name,priority); +} + +void Hyperion::unRegisterPriority(const std::string name) +{ + Info(_log, "Unregister input source named '%s' from priority register", name.c_str()); + _priorityRegister.erase(name); +} + + void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects) { // create led output diff --git a/libsrc/udplistener/UDPListener.cpp b/libsrc/udplistener/UDPListener.cpp index e7b5483e..74a3f3bc 100644 --- a/libsrc/udplistener/UDPListener.cpp +++ b/libsrc/udplistener/UDPListener.cpp @@ -29,6 +29,9 @@ UDPListener::UDPListener(const int priority, const int timeout, const std::strin // Set trigger for incoming connections connect(_server, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); + + _hyperion->registerPriority("UDPLISTENER", _priority); + } UDPListener::~UDPListener()