From 26154befa47b122c31fb961f902d5c6a6e53550e Mon Sep 17 00:00:00 2001 From: redPanther Date: Fri, 17 Feb 2017 08:33:34 +0100 Subject: [PATCH] avhai cleanup + grabber list (#402) * - cleanup shared_avahi stuff - add a list of avilable grabbers to json server info * fix compile --- CMakeLists.txt | 13 ++----- include/hyperion/GrabberWrapper.h | 8 +++- libsrc/bonjour/CMakeLists.txt | 33 ++++++++-------- libsrc/grabber/v4l2/V4L2Wrapper.cpp | 2 +- libsrc/hyperion/GrabberWrapper.cpp | 44 +++++++++++++++++++--- libsrc/jsonserver/JsonClientConnection.cpp | 19 ++++++++-- 6 files changed, 81 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ccd9756..f892dc58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,7 @@ -# Define the main-project name -project(hyperion) - -# define the minimum cmake version (as required by cmake) cmake_minimum_required(VERSION 2.8) +PROJECT(hyperion) + IF ( POLICY CMP0026 ) CMAKE_POLICY( SET CMP0026 OLD ) ENDIF() @@ -23,8 +21,7 @@ SET ( DEFAULT_DISPMANX OFF ) SET ( DEFAULT_OSX OFF ) SET ( DEFAULT_X11 OFF ) SET ( DEFAULT_WS281XPWM OFF ) -SET ( DEFAULT_USE_SHARED_AVAHI_LIBS OFF ) -SET ( DEFAULT_USE_AVAHI_LIBS ON ) +SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON ) SET ( DEFAULT_USE_SYSTEM_PROTO_LIBS OFF ) SET ( DEFAULT_TESTS OFF ) @@ -73,7 +70,6 @@ if ( "${PLATFORM}" MATCHES "osx" ) SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/usr/local/opt/qt5" CACHE STRING "path to your QT5 files" ) include_directories("/opt/X11/include/") SET ( DEFAULT_OSX ON ) - SET ( DEFAULT_USE_AVAHI_LIBS OFF ) elseif ( "${PLATFORM}" STREQUAL "rpi" ) SET ( DEFAULT_DISPMANX ON ) SET ( DEFAULT_WS281XPWM ON ) @@ -81,11 +77,8 @@ elseif ( "${PLATFORM}" STREQUAL "amlogic" ) SET ( DEFAULT_AMLOGIC ON ) elseif ( "${PLATFORM}" STREQUAL "amlogic64" ) SET ( DEFAULT_AMLOGIC ON ) - SET ( DEFAULT_USE_SYSTEM_PROTO_LIBS ON ) - SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON ) elseif ( "${PLATFORM}" MATCHES "x86" ) SET ( DEFAULT_X11 ON ) - SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON ) if ( "${PLATFORM}" STREQUAL "x86-dev" ) SET ( DEFAULT_AMLOGIC ON) SET ( DEFAULT_WS281XPWM ON ) diff --git a/include/hyperion/GrabberWrapper.h b/include/hyperion/GrabberWrapper.h index 4ed93cf8..b066d814 100644 --- a/include/hyperion/GrabberWrapper.h +++ b/include/hyperion/GrabberWrapper.h @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include @@ -15,7 +17,7 @@ class GrabberWrapper : public QObject { Q_OBJECT public: - GrabberWrapper(std::string grabberName, const int priority, hyperion::Components grabberComponentId=hyperion::COMP_GRABBER); + GrabberWrapper(QString grabberName, const int priority, hyperion::Components grabberComponentId=hyperion::COMP_GRABBER); virtual ~GrabberWrapper(); @@ -29,6 +31,8 @@ public: /// virtual void stop(); + static QStringList availableGrabbers(); + public slots: void componentStateChanged(const hyperion::Components component, bool enable); @@ -49,7 +53,7 @@ signals: protected: void setColors(const std::vector &ledColors, const int timeout_ms); - std::string _grabberName; + QString _grabberName; /// Pointer to Hyperion for writing led values Hyperion * _hyperion; diff --git a/libsrc/bonjour/CMakeLists.txt b/libsrc/bonjour/CMakeLists.txt index 7f1f8ccd..8d77aa76 100644 --- a/libsrc/bonjour/CMakeLists.txt +++ b/libsrc/bonjour/CMakeLists.txt @@ -37,20 +37,21 @@ target_link_libraries(bonjour hyperion-utils ${QT_LIBRARIES}) -set(USE_SHARED_AVAHI_LIBS ${DEFAULT_USE_SHARED_AVAHI_LIBS} CACHE BOOL "use avahi libraries from system") +IF (NOT APPLE) + set(USE_SHARED_AVAHI_LIBS ${DEFAULT_USE_SHARED_AVAHI_LIBS} CACHE BOOL "use avahi libraries from system") -if (USE_SHARED_AVAHI_LIBS) - target_link_libraries(bonjour - dns_sd - avahi-client - avahi-common - avahi-core - dbus-1) -elseif (DEFAULT_USE_AVAHI_LIBS) - target_link_libraries(bonjour - libdns_sd.a - libavahi-client.a - libavahi-common.a - libavahi-core.a - dbus-1) -endif() + if (USE_SHARED_AVAHI_LIBS) + target_link_libraries(bonjour + dns_sd + avahi-client + avahi-common + avahi-core) + else() + target_link_libraries(bonjour + libdns_sd.a + libavahi-client.a + libavahi-common.a + libavahi-core.a) + endif() + target_link_libraries(bonjour dbus-1) +ENDIF() diff --git a/libsrc/grabber/v4l2/V4L2Wrapper.cpp b/libsrc/grabber/v4l2/V4L2Wrapper.cpp index ae1fcc2d..2358528c 100644 --- a/libsrc/grabber/v4l2/V4L2Wrapper.cpp +++ b/libsrc/grabber/v4l2/V4L2Wrapper.cpp @@ -16,7 +16,7 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, double greenSignalThreshold, double blueSignalThreshold, const int priority) - : GrabberWrapper("V4L2:"+device, priority, hyperion::COMP_V4L) + : GrabberWrapper("V4L2:"+QString::fromStdString(device), priority, hyperion::COMP_V4L) , _timeout_ms(1000) , _grabber(device, input, diff --git a/libsrc/hyperion/GrabberWrapper.cpp b/libsrc/hyperion/GrabberWrapper.cpp index dcdd28de..3647cc03 100644 --- a/libsrc/hyperion/GrabberWrapper.cpp +++ b/libsrc/hyperion/GrabberWrapper.cpp @@ -2,14 +2,15 @@ #include #include #include +#include - -GrabberWrapper::GrabberWrapper(std::string grabberName, const int priority, hyperion::Components grabberComponentId) +#define QSTRING_CSTR(str) str.toLocal8Bit().constData() +GrabberWrapper::GrabberWrapper(QString grabberName, const int priority, hyperion::Components grabberComponentId) : _grabberName(grabberName) , _hyperion(Hyperion::getInstance()) , _priority(priority) , _timer() - , _log(Logger::getInstance(grabberName.c_str())) + , _log(Logger::getInstance(grabberName)) , _forward(true) , _processor(ImageProcessorFactory::getInstance().newImageProcessor()) , _grabberComponentId(grabberComponentId) @@ -28,7 +29,7 @@ GrabberWrapper::GrabberWrapper(std::string grabberName, const int priority, hype GrabberWrapper::~GrabberWrapper() { stop(); - Debug(_log,"Close grabber: %s", _grabberName.c_str()); + Debug(_log,"Close grabber: %s", QSTRING_CSTR(_grabberName)); delete _processor; } @@ -36,7 +37,7 @@ bool GrabberWrapper::start() { // Start the timer with the pre configured interval _timer.start(); - _hyperion->registerPriority(_grabberName,_priority); + _hyperion->registerPriority(_grabberName.toStdString(), _priority); return _timer.isActive(); } @@ -45,7 +46,7 @@ void GrabberWrapper::stop() { // Stop the timer, effectivly stopping the process _timer.stop(); - _hyperion->unRegisterPriority(_grabberName); + _hyperion->unRegisterPriority(_grabberName.toStdString()); } void GrabberWrapper::componentStateChanged(const hyperion::Components component, bool enable) @@ -105,3 +106,34 @@ void GrabberWrapper::setColors(const std::vector &ledColors, const int { _hyperion->setColors(_priority, ledColors, timeout_ms, true, _grabberComponentId); } + +QStringList GrabberWrapper::availableGrabbers() +{ + QStringList grabbers; + + #ifdef ENABLE_DISPMANX + grabbers << "dispmanx"; + #endif + + #ifdef ENABLE_V4L2 + grabbers << "v4l2"; + #endif + + #ifdef ENABLE_FB + grabbers << "framebuffer"; + #endif + + #ifdef ENABLE_AMLOGIC + grabbers << "amlogic"; + #endif + + #ifdef ENABLE_OSX + grabbers << "osx"; + #endif + + #ifdef ENABLE_X11 + grabbers << "x11"; + #endif + + return grabbers; +} diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index eab44f77..6fa626ae 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -761,15 +762,27 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt // get available led devices QJsonObject ledDevices; ledDevices["active"] = QString::fromStdString(LedDevice::activeDevice()); - QJsonArray available; + QJsonArray availableLedDevices; for (auto dev: LedDevice::getDeviceMap()) { - available.append(QString::fromStdString(dev.first)); + availableLedDevices.append(QString::fromStdString(dev.first)); } - ledDevices["available"] = available; + ledDevices["available"] = availableLedDevices; info["ledDevices"] = ledDevices; + // get available grabbers + QJsonObject grabbers; + //grabbers["active"] = ????; + QJsonArray availableGrabbers; + for (auto grabber: GrabberWrapper::availableGrabbers()) + { + availableGrabbers.append(grabber); + } + + grabbers["available"] = availableGrabbers; + info["grabbers"] = grabbers; + // get available components QJsonArray component; std::map components = _hyperion->getComponentRegister().getRegister();