mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
JsonCpp to QTJson (Part 2) (#147)
* Replace std::string with QString * Replace std::string with QString * Replace std::string with QString * Replace std::string with QString * Convert JsonCPP Code to QTJson Not all JsonCPP Code is converted to QTJson Code. See Pull Request for Details. * Convert JsonCPP Code to QTJson Not all JsonCPP Code is converted to QTJson Code. See Pull Request for Details.
This commit is contained in:
parent
0e2f0127fd
commit
f183032270
@ -30,11 +30,11 @@ class KODIVideoChecker : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static KODIVideoChecker* initInstance(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection);
|
static KODIVideoChecker* initInstance(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection);
|
||||||
static KODIVideoChecker* getInstance();
|
static KODIVideoChecker* getInstance();
|
||||||
|
|
||||||
~KODIVideoChecker();
|
~KODIVideoChecker();
|
||||||
void setConfig(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection);
|
void setConfig(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
///
|
///
|
||||||
@ -83,7 +83,7 @@ private:
|
|||||||
/// @param grabScreensaver Whether or not to grab when the KODI screensaver is activated
|
/// @param grabScreensaver Whether or not to grab when the KODI screensaver is activated
|
||||||
/// @param enable3DDetection Wheter or not to enable the detection of 3D movies playing
|
/// @param enable3DDetection Wheter or not to enable the detection of 3D movies playing
|
||||||
///
|
///
|
||||||
KODIVideoChecker(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection);
|
KODIVideoChecker(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection);
|
||||||
|
|
||||||
/// Set the grabbing mode
|
/// Set the grabbing mode
|
||||||
void setGrabbingMode(GrabbingMode grabbingMode);
|
void setGrabbingMode(GrabbingMode grabbingMode);
|
||||||
|
@ -27,7 +27,7 @@ public:
|
|||||||
/// @param hyperion Hyperion instance
|
/// @param hyperion Hyperion instance
|
||||||
/// @param port port number on which to start listening for connections
|
/// @param port port number on which to start listening for connections
|
||||||
///
|
///
|
||||||
UDPListener(const int priority, const int timeout, const std::string& address, quint16 listenPort, bool shared);
|
UDPListener(const int priority, const int timeout, const QString& address, quint16 listenPort, bool shared);
|
||||||
~UDPListener();
|
~UDPListener();
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
KODIVideoChecker* KODIVideoChecker::_kodichecker = nullptr;
|
KODIVideoChecker* KODIVideoChecker::_kodichecker = nullptr;
|
||||||
|
|
||||||
KODIVideoChecker* KODIVideoChecker::initInstance(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
KODIVideoChecker* KODIVideoChecker::initInstance(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
||||||
{
|
{
|
||||||
if ( KODIVideoChecker::_kodichecker != nullptr )
|
if ( KODIVideoChecker::_kodichecker != nullptr )
|
||||||
throw std::runtime_error("KODIVideoChecker::initInstance can be called only one time");
|
throw std::runtime_error("KODIVideoChecker::initInstance can be called only one time");
|
||||||
@ -39,9 +39,9 @@ KODIVideoChecker* KODIVideoChecker::getInstance()
|
|||||||
// {"jsonrpc":"2.0","method":"GUI.GetProperties","params":{"properties":["stereoscopicmode"]},"id":669}
|
// {"jsonrpc":"2.0","method":"GUI.GetProperties","params":{"properties":["stereoscopicmode"]},"id":669}
|
||||||
// {"id":669,"jsonrpc":"2.0","result":{"stereoscopicmode":{"label":"Nebeneinander","mode":"split_vertical"}}}
|
// {"id":669,"jsonrpc":"2.0","result":{"stereoscopicmode":{"label":"Nebeneinander","mode":"split_vertical"}}}
|
||||||
|
|
||||||
KODIVideoChecker::KODIVideoChecker(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
KODIVideoChecker::KODIVideoChecker(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
||||||
: QObject()
|
: QObject()
|
||||||
, _address(QString::fromStdString(address))
|
, _address(address)
|
||||||
, _port(port)
|
, _port(port)
|
||||||
, _activePlayerRequest(R"({"jsonrpc":"2.0","method":"Player.GetActivePlayers", "id":666})")
|
, _activePlayerRequest(R"({"jsonrpc":"2.0","method":"Player.GetActivePlayers", "id":666})")
|
||||||
, _currentPlayingItemRequest(R"({"id":667,"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":%1,"properties":["file"]}})")
|
, _currentPlayingItemRequest(R"({"id":667,"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":%1,"properties":["file"]}})")
|
||||||
@ -78,9 +78,9 @@ KODIVideoChecker::~KODIVideoChecker()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KODIVideoChecker::setConfig(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
void KODIVideoChecker::setConfig(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
||||||
{
|
{
|
||||||
_address = QString::fromStdString(address);
|
_address = address;
|
||||||
_port = port;
|
_port = port;
|
||||||
_grabVideo = grabVideo;
|
_grabVideo = grabVideo;
|
||||||
_grabPhoto = grabPhoto;
|
_grabPhoto = grabPhoto;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "utils/ColorRgb.h"
|
#include "utils/ColorRgb.h"
|
||||||
#include "HyperionConfig.h"
|
#include "HyperionConfig.h"
|
||||||
|
|
||||||
UDPListener::UDPListener(const int priority, const int timeout, const std::string& address, quint16 listenPort, bool shared) :
|
UDPListener::UDPListener(const int priority, const int timeout, const QString& address, quint16 listenPort, bool shared) :
|
||||||
QObject(),
|
QObject(),
|
||||||
_hyperion(Hyperion::getInstance()),
|
_hyperion(Hyperion::getInstance()),
|
||||||
_server(),
|
_server(),
|
||||||
@ -23,9 +23,9 @@ UDPListener::UDPListener(const int priority, const int timeout, const std::strin
|
|||||||
_bondage(shared ? QAbstractSocket::ShareAddress : QAbstractSocket::DefaultForPlatform)
|
_bondage(shared ? QAbstractSocket::ShareAddress : QAbstractSocket::DefaultForPlatform)
|
||||||
{
|
{
|
||||||
_server = new QUdpSocket(this);
|
_server = new QUdpSocket(this);
|
||||||
_listenAddress = address.empty()
|
_listenAddress = address.isEmpty()
|
||||||
? QHostAddress::AnyIPv4
|
? QHostAddress::AnyIPv4
|
||||||
: QHostAddress( QString::fromStdString(address) );
|
: QHostAddress(address);
|
||||||
|
|
||||||
// Set trigger for incoming connections
|
// Set trigger for incoming connections
|
||||||
connect(_server, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
|
connect(_server, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
|
||||||
|
@ -8,12 +8,17 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
#include <QString>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonValue>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "HyperionConfig.h"
|
#include "HyperionConfig.h"
|
||||||
|
|
||||||
#include <utils/jsonschema/JsonFactory.h>
|
#include <utils/jsonschema/JsonFactory.h> // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson
|
||||||
|
#include <utils/jsonschema/QJsonFactory.h>
|
||||||
|
|
||||||
#include <hyperion/Hyperion.h>
|
#include <hyperion/Hyperion.h>
|
||||||
#include <effectengine/EffectEngine.h>
|
#include <effectengine/EffectEngine.h>
|
||||||
@ -43,15 +48,17 @@ HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent)
|
|||||||
, _osxGrabber(nullptr)
|
, _osxGrabber(nullptr)
|
||||||
, _hyperion(nullptr)
|
, _hyperion(nullptr)
|
||||||
{
|
{
|
||||||
loadConfig(configFile);
|
loadConfig(configFile); // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson
|
||||||
|
loadConfig(QString::fromStdString(configFile));
|
||||||
|
|
||||||
_hyperion = Hyperion::initInstance(_config, configFile);
|
_hyperion = Hyperion::initInstance(_config, configFile);
|
||||||
|
|
||||||
if (Logger::getLogLevel() == Logger::WARNING)
|
if (Logger::getLogLevel() == Logger::WARNING)
|
||||||
{
|
{
|
||||||
if (_config.isMember("logger"))
|
if (_qconfig.contains("logger"))
|
||||||
{
|
{
|
||||||
const Json::Value & logConfig = _config["logger"];
|
const QJsonObject & logConfig = _qconfig["logger"].toObject();
|
||||||
std::string level = logConfig.get("level", "warn").asString(); // silent warn verbose debug
|
std::string level = logConfig["level"].toString("warn").toStdString(); // silent warn verbose debug
|
||||||
if (level == "silent") Logger::setLogLevel(Logger::OFF);
|
if (level == "silent") Logger::setLogLevel(Logger::OFF);
|
||||||
else if (level == "warn") Logger::setLogLevel(Logger::WARNING);
|
else if (level == "warn") Logger::setLogLevel(Logger::WARNING);
|
||||||
else if (level == "verbose") Logger::setLogLevel(Logger::INFO);
|
else if (level == "verbose") Logger::setLogLevel(Logger::INFO);
|
||||||
@ -62,7 +69,7 @@ HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WarningIf(_config.isMember("logger"), Logger::getInstance("LOGGER"), "Logger settings overriden by command line argument");
|
WarningIf(_qconfig.contains("logger"), Logger::getInstance("LOGGER"), "Logger settings overriden by command line argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
Info(_log, "Hyperion started and initialised");
|
Info(_log, "Hyperion started and initialised");
|
||||||
@ -97,12 +104,12 @@ void HyperionDaemon::run()
|
|||||||
createSystemFrameGrabber();
|
createSystemFrameGrabber();
|
||||||
|
|
||||||
#if !defined(ENABLE_DISPMANX) && !defined(ENABLE_OSX) && !defined(ENABLE_FB) && !defined(ENABLE_X11) && !defined(ENABLE_AMLOGIC)
|
#if !defined(ENABLE_DISPMANX) && !defined(ENABLE_OSX) && !defined(ENABLE_FB) && !defined(ENABLE_X11) && !defined(ENABLE_AMLOGIC)
|
||||||
WarningIf(_config.isMember("framegrabber"), _log, "No grabber can be instantiated, because all grabbers have been left out from the build");
|
WarningIf(_qconfig.contains("framegrabber"), _log, "No grabber can be instantiated, because all grabbers have been left out from the build");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyperionDaemon::loadConfig(const std::string & configFile)
|
void HyperionDaemon::loadConfig(const std::string & configFile) // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson
|
||||||
{
|
{
|
||||||
Info(_log, "Selected configuration file: %s", configFile.c_str() );
|
Info(_log, "Selected configuration file: %s", configFile.c_str() );
|
||||||
// make sure the resources are loaded (they may be left out after static linking)
|
// make sure the resources are loaded (they may be left out after static linking)
|
||||||
@ -125,6 +132,61 @@ void HyperionDaemon::loadConfig(const std::string & configFile)
|
|||||||
schemaChecker.validate(_config);
|
schemaChecker.validate(_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HyperionDaemon::loadConfig(const QString & configFile)
|
||||||
|
{
|
||||||
|
// Info(_log, "Selected configuration file: %s", configFile.toStdString().c_str()); // uncommend this line only if JsonCpp is removed. Otherwise appears this line twice in the debug output
|
||||||
|
|
||||||
|
// make sure the resources are loaded (they may be left out after static linking)
|
||||||
|
Q_INIT_RESOURCE(resource);
|
||||||
|
QJsonParseError error;
|
||||||
|
|
||||||
|
// read the json schema from the resource
|
||||||
|
QFile schemaData(":/hyperion-schema");
|
||||||
|
if (!schemaData.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
std::stringstream error;
|
||||||
|
error << "Schema not found: " << schemaData.errorString().toStdString();
|
||||||
|
throw std::runtime_error(error.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray schema = schemaData.readAll();
|
||||||
|
QJsonDocument schemaJson = QJsonDocument::fromJson(schema, &error);
|
||||||
|
|
||||||
|
if (error.error != QJsonParseError::NoError)
|
||||||
|
{
|
||||||
|
// report to the user the failure and their locations in the document.
|
||||||
|
int errorLine(0), errorColumn(0);
|
||||||
|
|
||||||
|
for( int i=0, count=qMin( error.offset,schema.size()); i<count; ++i )
|
||||||
|
{
|
||||||
|
++errorColumn;
|
||||||
|
if(schema.at(i) == '\n' )
|
||||||
|
{
|
||||||
|
errorColumn = 0;
|
||||||
|
++errorLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream sstream;
|
||||||
|
sstream << "ERROR: Json schema wrong: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||||
|
|
||||||
|
throw std::runtime_error(sstream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonSchemaChecker schemaChecker;
|
||||||
|
schemaChecker.setSchema(schemaJson.object());
|
||||||
|
|
||||||
|
_qconfig = QJsonFactory::readJson(configFile);
|
||||||
|
if (!schemaChecker.validate(_qconfig))
|
||||||
|
{
|
||||||
|
for (std::list<std::string>::const_iterator i = schemaChecker.getMessages().begin(); i != schemaChecker.getMessages().end(); ++i)
|
||||||
|
{
|
||||||
|
std::cout << *i << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::runtime_error("ERROR: Json validation failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HyperionDaemon::startInitialEffect()
|
void HyperionDaemon::startInitialEffect()
|
||||||
{
|
{
|
||||||
@ -196,22 +258,22 @@ void HyperionDaemon::startInitialEffect()
|
|||||||
// create KODI video checker if the _configuration is present
|
// create KODI video checker if the _configuration is present
|
||||||
void HyperionDaemon::createKODIVideoChecker()
|
void HyperionDaemon::createKODIVideoChecker()
|
||||||
{
|
{
|
||||||
bool kodiCheckerConfigured = _config.isMember("kodiVideoChecker");
|
bool kodiCheckerConfigured = _qconfig.contains("kodiVideoChecker");
|
||||||
|
|
||||||
const Json::Value & videoCheckerConfig = _config["kodiVideoChecker"];
|
const QJsonObject & videoCheckerConfig = _qconfig["kodiVideoChecker"].toObject();
|
||||||
_kodiVideoChecker = KODIVideoChecker::initInstance(
|
_kodiVideoChecker = KODIVideoChecker::initInstance(
|
||||||
videoCheckerConfig.get("kodiAddress","127.0.0.1").asString(),
|
videoCheckerConfig["kodiAddress"].toString("127.0.0.1"),
|
||||||
videoCheckerConfig.get("kodiTcpPort",9090).asUInt(),
|
videoCheckerConfig["kodiTcpPort"].toInt(9090),
|
||||||
videoCheckerConfig.get("grabVideo",true).asBool(),
|
videoCheckerConfig["grabVideo"].toBool(true),
|
||||||
videoCheckerConfig.get("grabPictures",true).asBool(),
|
videoCheckerConfig["grabPictures"].toBool(true),
|
||||||
videoCheckerConfig.get("grabAudio",true).asBool(),
|
videoCheckerConfig["grabAudio"].toBool(true),
|
||||||
videoCheckerConfig.get("grabMenu",false).asBool(),
|
videoCheckerConfig["grabMenu"].toBool(false),
|
||||||
videoCheckerConfig.get("grabPause", true).asBool(),
|
videoCheckerConfig["grabPause"].toBool(true),
|
||||||
videoCheckerConfig.get("grabScreensaver", false).asBool(),
|
videoCheckerConfig["grabScreensaver"].toBool(false),
|
||||||
videoCheckerConfig.get("enable3DDetection", true).asBool());
|
videoCheckerConfig["enable3DDetection"].toBool(true));
|
||||||
Debug(_log, "KODI checker created ");
|
Debug(_log, "KODI checker created ");
|
||||||
|
|
||||||
if( kodiCheckerConfigured && videoCheckerConfig.get("enable", true).asBool() )
|
if( kodiCheckerConfigured && videoCheckerConfig["enable"].toBool(true))
|
||||||
{
|
{
|
||||||
_kodiVideoChecker->start();
|
_kodiVideoChecker->start();
|
||||||
}
|
}
|
||||||
@ -223,26 +285,26 @@ void HyperionDaemon::startNetworkServices()
|
|||||||
|
|
||||||
// Create Json server if configuration is present
|
// Create Json server if configuration is present
|
||||||
unsigned int jsonPort = 19444;
|
unsigned int jsonPort = 19444;
|
||||||
if (_config.isMember("jsonServer"))
|
if (_qconfig.contains("jsonServer"))
|
||||||
{
|
{
|
||||||
const Json::Value & jsonServerConfig = _config["jsonServer"];
|
const QJsonObject & jsonServerConfig = _qconfig["jsonServer"].toObject();
|
||||||
//jsonEnable = jsonServerConfig.get("enable", true).asBool();
|
//jsonEnable = jsonServerConfig.get("enable", true).asBool();
|
||||||
jsonPort = jsonServerConfig.get("port", jsonPort).asUInt();
|
jsonPort = jsonServerConfig["port"].toInt(jsonPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
_jsonServer = new JsonServer(jsonPort );
|
_jsonServer = new JsonServer(jsonPort);
|
||||||
Info(_log, "Json server created and started on port %d", _jsonServer->getPort());
|
Info(_log, "Json server created and started on port %d", _jsonServer->getPort());
|
||||||
|
|
||||||
// Create Proto server if configuration is present
|
// Create Proto server if configuration is present
|
||||||
unsigned int protoPort = 19445;
|
unsigned int protoPort = 19445;
|
||||||
if (_config.isMember("protoServer"))
|
if (_qconfig.contains("protoServer"))
|
||||||
{
|
{
|
||||||
const Json::Value & protoServerConfig = _config["protoServer"];
|
const QJsonObject & protoServerConfig = _qconfig["protoServer"].toObject();
|
||||||
//protoEnable = protoServerConfig.get("enable", true).asBool();
|
//protoEnable = protoServerConfig.get("enable", true).asBool();
|
||||||
protoPort = protoServerConfig.get("port", protoPort).asUInt();
|
protoPort = protoServerConfig["port"].toInt(protoPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
_protoServer = new ProtoServer(protoPort );
|
_protoServer = new ProtoServer(protoPort);
|
||||||
if (kodiVideoChecker != nullptr)
|
if (kodiVideoChecker != nullptr)
|
||||||
{
|
{
|
||||||
QObject::connect(kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _protoServer, SIGNAL(grabbingMode(GrabbingMode)));
|
QObject::connect(kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _protoServer, SIGNAL(grabbingMode(GrabbingMode)));
|
||||||
@ -251,43 +313,43 @@ void HyperionDaemon::startNetworkServices()
|
|||||||
Info(_log, "Proto server created and started on port %d", _protoServer->getPort());
|
Info(_log, "Proto server created and started on port %d", _protoServer->getPort());
|
||||||
|
|
||||||
// Create Boblight server if configuration is present
|
// Create Boblight server if configuration is present
|
||||||
if (_config.isMember("boblightServer"))
|
if (_qconfig.contains("boblightServer"))
|
||||||
{
|
{
|
||||||
const Json::Value & boblightServerConfig = _config["boblightServer"];
|
const QJsonObject & boblightServerConfig = _qconfig["boblightServer"].toObject();
|
||||||
_boblightServer = new BoblightServer(
|
_boblightServer = new BoblightServer(
|
||||||
boblightServerConfig.get("priority",710).asInt(),
|
boblightServerConfig["priority"].toInt(710),
|
||||||
boblightServerConfig["port"].asUInt()
|
boblightServerConfig["port"].toInt()
|
||||||
);
|
);
|
||||||
Debug(_log, "Boblight server created");
|
Debug(_log, "Boblight server created");
|
||||||
|
|
||||||
if ( boblightServerConfig.get("enable", true).asBool() )
|
if ( boblightServerConfig["enable"].toBool(true))
|
||||||
{
|
{
|
||||||
_boblightServer->start();
|
_boblightServer->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create UDP listener if configuration is present
|
// Create UDP listener if configuration is present
|
||||||
if (_config.isMember("udpListener"))
|
if (_qconfig.contains("udpListener"))
|
||||||
{
|
{
|
||||||
const Json::Value & udpListenerConfig = _config["udpListener"];
|
const QJsonObject & udpListenerConfig = _qconfig["udpListener"].toObject();
|
||||||
_udpListener = new UDPListener(
|
_udpListener = new UDPListener(
|
||||||
udpListenerConfig.get("priority",700).asInt(),
|
udpListenerConfig["priority"].toInt(700),
|
||||||
udpListenerConfig.get("timeout",10000).asInt(),
|
udpListenerConfig["timeout"].toInt(10000),
|
||||||
udpListenerConfig.get("address", "").asString(),
|
udpListenerConfig["address"].toString(""),
|
||||||
udpListenerConfig.get("port", 2801).asUInt(),
|
udpListenerConfig["port"].toInt(2801),
|
||||||
udpListenerConfig.get("shared", false).asBool()
|
udpListenerConfig["shared"].toBool(false));
|
||||||
);
|
|
||||||
Debug(_log, "UDP listener created");
|
Debug(_log, "UDP listener created");
|
||||||
|
|
||||||
if ( udpListenerConfig.get("enable", true).asBool() )
|
if ( udpListenerConfig["enable"].toBool(true))
|
||||||
{
|
{
|
||||||
_udpListener->start();
|
_udpListener->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// zeroconf description - $leddevicename@$hostname
|
// zeroconf description - $leddevicename@$hostname
|
||||||
const Json::Value & deviceConfig = _config["device"];
|
const QJsonObject & deviceConfig = _qconfig["device"].toObject();
|
||||||
const std::string mDNSDescr = ( deviceConfig.get("name", "").asString()
|
const std::string mDNSDescr = ( deviceConfig["name"].toString("").toStdString()
|
||||||
+ "@" +
|
+ "@" +
|
||||||
QHostInfo::localHostName().toStdString()
|
QHostInfo::localHostName().toStdString()
|
||||||
);
|
);
|
||||||
@ -322,25 +384,25 @@ void HyperionDaemon::startNetworkServices()
|
|||||||
|
|
||||||
void HyperionDaemon::createSystemFrameGrabber()
|
void HyperionDaemon::createSystemFrameGrabber()
|
||||||
{
|
{
|
||||||
if (_config.isMember("framegrabber"))
|
if (_qconfig.contains("framegrabber"))
|
||||||
{
|
{
|
||||||
const Json::Value & grabberConfig = _config["framegrabber"];
|
const QJsonObject & grabberConfig = _qconfig["framegrabber"].toObject();
|
||||||
if (grabberConfig.get("enable", true).asBool())
|
if (grabberConfig["enable"].toBool(true))
|
||||||
{
|
{
|
||||||
_grabber_width = grabberConfig.get("width", 96).asUInt();
|
_grabber_width = grabberConfig["width"].toInt(96);
|
||||||
_grabber_height = grabberConfig.get("height", 96).asUInt();
|
_grabber_height = grabberConfig["height"].toInt(96);
|
||||||
_grabber_frequency = grabberConfig.get("frequency_Hz",10).asUInt();
|
_grabber_frequency = grabberConfig["frequency_Hz"].toInt(10);
|
||||||
_grabber_priority = grabberConfig.get("priority",900).asInt();
|
_grabber_priority = grabberConfig["priority"].toInt(900);
|
||||||
|
|
||||||
_grabber_cropLeft = grabberConfig.get("cropLeft", 0).asUInt();
|
_grabber_cropLeft = grabberConfig["cropLeft"].toInt(0);
|
||||||
_grabber_cropRight = grabberConfig.get("cropRight", 0).asUInt();
|
_grabber_cropRight = grabberConfig["cropRight"].toInt(0);
|
||||||
_grabber_cropTop = grabberConfig.get("cropTop", 0).asUInt();
|
_grabber_cropTop = grabberConfig["cropTop"].toInt(0);
|
||||||
_grabber_cropBottom = grabberConfig.get("cropBottom", 0).asUInt();
|
_grabber_cropBottom = grabberConfig["cropBottom"].toInt(0);
|
||||||
|
|
||||||
#ifdef ENABLE_OSX
|
#ifdef ENABLE_OSX
|
||||||
std::string type = "osx";
|
QString type = "osx";
|
||||||
#else
|
#else
|
||||||
std::string type = grabberConfig.get("type", "auto").asString();
|
QString type = grabberConfig["type"].toString("auto");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QFile amvideo("/dev/amvideo");
|
QFile amvideo("/dev/amvideo");
|
||||||
@ -372,7 +434,7 @@ void HyperionDaemon::createSystemFrameGrabber()
|
|||||||
{
|
{
|
||||||
type == "framebuffer";
|
type == "framebuffer";
|
||||||
}
|
}
|
||||||
Info( _log, "set screen capture device to '%s'", type.c_str());
|
Info( _log, "set screen capture device to '%s'", type.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == "framebuffer") createGrabberFramebuffer(grabberConfig);
|
if (type == "framebuffer") createGrabberFramebuffer(grabberConfig);
|
||||||
@ -380,7 +442,7 @@ void HyperionDaemon::createSystemFrameGrabber()
|
|||||||
else if (type == "amlogic") { createGrabberAmlogic(); createGrabberFramebuffer(grabberConfig); }
|
else if (type == "amlogic") { createGrabberAmlogic(); createGrabberFramebuffer(grabberConfig); }
|
||||||
else if (type == "osx") createGrabberOsx(grabberConfig);
|
else if (type == "osx") createGrabberOsx(grabberConfig);
|
||||||
else if (type == "x11") createGrabberX11(grabberConfig);
|
else if (type == "x11") createGrabberX11(grabberConfig);
|
||||||
else WarningIf( type != "", _log, "unknown framegrabber type '%s'", type.c_str());
|
else WarningIf( type != "", _log, "unknown framegrabber type '%s'", type.constData());
|
||||||
InfoIf( type == "", _log, "screen capture device disabled");
|
InfoIf( type == "", _log, "screen capture device disabled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,7 +462,7 @@ void HyperionDaemon::createGrabberDispmanx()
|
|||||||
_dispmanx->start();
|
_dispmanx->start();
|
||||||
Info(_log, "DISPMANX frame grabber created and started");
|
Info(_log, "DISPMANX frame grabber created and started");
|
||||||
#else
|
#else
|
||||||
ErrorIf(_config.isMember("framegrabber"), _log, "The dispmanx framegrabber can not be instantiated, because it has been left out from the build");
|
ErrorIf(_qconfig.contains("framegrabber"), _log, "The dispmanx framegrabber can not be instantiated, because it has been left out from the build");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,14 +483,14 @@ void HyperionDaemon::createGrabberAmlogic()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyperionDaemon::createGrabberX11(const Json::Value & grabberConfig)
|
void HyperionDaemon::createGrabberX11(const QJsonObject & grabberConfig)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_X11
|
#ifdef ENABLE_X11
|
||||||
_x11Grabber = new X11Wrapper(
|
_x11Grabber = new X11Wrapper(
|
||||||
grabberConfig.get("useXGetImage",false).asBool(),
|
grabberConfig["useXGetImage"].toBool(false),
|
||||||
_grabber_cropLeft, _grabber_cropRight, _grabber_cropTop, _grabber_cropBottom,
|
_grabber_cropLeft, _grabber_cropRight, _grabber_cropTop, _grabber_cropBottom,
|
||||||
grabberConfig.get("horizontalPixelDecimation", 8).asInt(),
|
grabberConfig["horizontalPixelDecimation"].toInt(8),
|
||||||
grabberConfig.get("verticalPixelDecimation", 8).asInt(),
|
grabberConfig["verticalPixelDecimation"].toInt(8),
|
||||||
_grabber_frequency, _grabber_priority );
|
_grabber_frequency, _grabber_priority );
|
||||||
|
|
||||||
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _x11Grabber, SLOT(setGrabbingMode(GrabbingMode)));
|
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _x11Grabber, SLOT(setGrabbingMode(GrabbingMode)));
|
||||||
@ -443,12 +505,12 @@ void HyperionDaemon::createGrabberX11(const Json::Value & grabberConfig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HyperionDaemon::createGrabberFramebuffer(const Json::Value & grabberConfig)
|
void HyperionDaemon::createGrabberFramebuffer(const QJsonObject & grabberConfig)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_FB
|
#ifdef ENABLE_FB
|
||||||
// Construct and start the framebuffer grabber if the configuration is present
|
// Construct and start the framebuffer grabber if the configuration is present
|
||||||
_fbGrabber = new FramebufferWrapper(
|
_fbGrabber = new FramebufferWrapper(
|
||||||
grabberConfig.get("device", "/dev/fb0").asString(),
|
grabberConfig["device"].toString("/dev/fb0").toStdString(),
|
||||||
_grabber_width, _grabber_height, _grabber_frequency, _grabber_priority);
|
_grabber_width, _grabber_height, _grabber_frequency, _grabber_priority);
|
||||||
|
|
||||||
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _fbGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _fbGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
||||||
@ -463,12 +525,12 @@ void HyperionDaemon::createGrabberFramebuffer(const Json::Value & grabberConfig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HyperionDaemon::createGrabberOsx(const Json::Value & grabberConfig)
|
void HyperionDaemon::createGrabberOsx(const QJsonObject & grabberConfig)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_OSX
|
#ifdef ENABLE_OSX
|
||||||
// Construct and start the osx grabber if the configuration is present
|
// Construct and start the osx grabber if the configuration is present
|
||||||
_osxGrabber = new OsxWrapper(
|
_osxGrabber = new OsxWrapper(
|
||||||
grabberConfig.get("display", 0).asUInt(),
|
grabberConfig["display"].toInt(0),
|
||||||
_grabber_width, _grabber_height, _grabber_frequency, _grabber_priority);
|
_grabber_width, _grabber_height, _grabber_frequency, _grabber_priority);
|
||||||
|
|
||||||
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _osxGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _osxGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
||||||
@ -487,37 +549,37 @@ void HyperionDaemon::createGrabberV4L2()
|
|||||||
{
|
{
|
||||||
// construct and start the v4l2 grabber if the configuration is present
|
// construct and start the v4l2 grabber if the configuration is present
|
||||||
#ifdef ENABLE_V4L2
|
#ifdef ENABLE_V4L2
|
||||||
if (_config.isMember("grabber-v4l2"))
|
if (_qconfig.contains("grabber-v4l2"))
|
||||||
{
|
{
|
||||||
const Json::Value & grabberConfig = _config["grabber-v4l2"];
|
const QJsonObject & grabberConfig = _qconfig["grabber-v4l2"].toObject();
|
||||||
_v4l2Grabber = new V4L2Wrapper(
|
_v4l2Grabber = new V4L2Wrapper(
|
||||||
grabberConfig.get("device", "/dev/video0").asString(),
|
grabberConfig["device"].toString("/dev/video0").toStdString(),
|
||||||
grabberConfig.get("input", 0).asInt(),
|
grabberConfig["input"].toInt(0),
|
||||||
parseVideoStandard(grabberConfig.get("standard", "no-change").asString()),
|
parseVideoStandard(grabberConfig["standard"].toString("no-change").toStdString()),
|
||||||
parsePixelFormat(grabberConfig.get("pixelFormat", "no-change").asString()),
|
parsePixelFormat(grabberConfig["pixelFormat"].toString("no-change").toStdString()),
|
||||||
grabberConfig.get("width", -1).asInt(),
|
grabberConfig["width"].toInt(-1),
|
||||||
grabberConfig.get("height", -1).asInt(),
|
grabberConfig["height"].toInt(-1),
|
||||||
grabberConfig.get("frameDecimation", 2).asInt(),
|
grabberConfig["frameDecimation"].toInt(2),
|
||||||
grabberConfig.get("sizeDecimation", 8).asInt(),
|
grabberConfig["sizeDecimation"].toInt(8),
|
||||||
grabberConfig.get("redSignalThreshold", 0.0).asDouble(),
|
grabberConfig["redSignalThreshold"].toDouble(0.0),
|
||||||
grabberConfig.get("greenSignalThreshold", 0.0).asDouble(),
|
grabberConfig["greenSignalThreshold"].toDouble(0.0),
|
||||||
grabberConfig.get("blueSignalThreshold", 0.0).asDouble(),
|
grabberConfig["blueSignalThreshold"].toDouble(0.0),
|
||||||
grabberConfig.get("priority", 890).asInt());
|
grabberConfig["priority"].toInt(890));
|
||||||
_v4l2Grabber->set3D(parse3DMode(grabberConfig.get("mode", "2D").asString()));
|
_v4l2Grabber->set3D(parse3DMode(grabberConfig["mode"].toString("2D").toStdString()));
|
||||||
_v4l2Grabber->setCropping(
|
_v4l2Grabber->setCropping(
|
||||||
grabberConfig.get("cropLeft", 0).asInt(),
|
grabberConfig["cropLeft"].toInt(0),
|
||||||
grabberConfig.get("cropRight", 0).asInt(),
|
grabberConfig["cropRight"].toInt(0),
|
||||||
grabberConfig.get("cropTop", 0).asInt(),
|
grabberConfig["cropTop"].toInt(0),
|
||||||
grabberConfig.get("cropBottom", 0).asInt());
|
grabberConfig["cropBottom"].toInt(0));
|
||||||
Debug(_log, "V4L2 grabber created");
|
Debug(_log, "V4L2 grabber created");
|
||||||
|
|
||||||
QObject::connect(_v4l2Grabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
QObject::connect(_v4l2Grabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
||||||
if (grabberConfig.get("enable", true).asBool() && _v4l2Grabber->start())
|
if (grabberConfig["enable"].toBool(true) && _v4l2Grabber->start())
|
||||||
{
|
{
|
||||||
Info(_log, "V4L2 grabber started");
|
Info(_log, "V4L2 grabber started");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
ErrorIf(_config.isMember("grabber-v4l2"), _log, "The v4l2 grabber can not be instantiated, because it has been left out from the build");
|
ErrorIf(_qconfig.contains("grabber-v4l2"), _log, "The v4l2 grabber can not be instantiated, because it has been left out from the build");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include <boblightserver/BoblightServer.h>
|
#include <boblightserver/BoblightServer.h>
|
||||||
#include <webconfig/WebConfig.h>
|
#include <webconfig/WebConfig.h>
|
||||||
#include <udplistener/UDPListener.h>
|
#include <udplistener/UDPListener.h>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
class HyperionDaemon : public QObject
|
class HyperionDaemon : public QObject
|
||||||
{
|
{
|
||||||
@ -53,7 +54,8 @@ public:
|
|||||||
HyperionDaemon(std::string configFile, QObject *parent=nullptr);
|
HyperionDaemon(std::string configFile, QObject *parent=nullptr);
|
||||||
~HyperionDaemon();
|
~HyperionDaemon();
|
||||||
|
|
||||||
void loadConfig(const std::string & configFile);
|
void loadConfig(const std::string & configFile); // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson
|
||||||
|
void loadConfig(const QString & configFile);
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
void startInitialEffect();
|
void startInitialEffect();
|
||||||
@ -67,12 +69,13 @@ public:
|
|||||||
private:
|
private:
|
||||||
void createGrabberDispmanx();
|
void createGrabberDispmanx();
|
||||||
void createGrabberAmlogic();
|
void createGrabberAmlogic();
|
||||||
void createGrabberFramebuffer(const Json::Value & grabberConfig);
|
void createGrabberFramebuffer(const QJsonObject & grabberConfig);
|
||||||
void createGrabberOsx(const Json::Value & grabberConfig);
|
void createGrabberOsx(const QJsonObject & grabberConfig);
|
||||||
void createGrabberX11(const Json::Value & grabberConfig);
|
void createGrabberX11(const QJsonObject & grabberConfig);
|
||||||
|
|
||||||
Logger* _log;
|
Logger* _log;
|
||||||
Json::Value _config;
|
Json::Value _config; // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson
|
||||||
|
QJsonObject _qconfig;
|
||||||
KODIVideoChecker* _kodiVideoChecker;
|
KODIVideoChecker* _kodiVideoChecker;
|
||||||
JsonServer* _jsonServer;
|
JsonServer* _jsonServer;
|
||||||
ProtoServer* _protoServer;
|
ProtoServer* _protoServer;
|
||||||
|
Loading…
Reference in New Issue
Block a user