2016-05-30 22:38:40 +02:00
|
|
|
#include <unistd.h>
|
2016-06-29 11:18:32 +02:00
|
|
|
#include <cassert>
|
2013-08-22 22:06:13 +02:00
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
#include <QCoreApplication>
|
2013-08-24 11:51:52 +02:00
|
|
|
#include <QResource>
|
2014-01-28 22:27:02 +01:00
|
|
|
#include <QLocale>
|
2016-05-24 19:56:43 +02:00
|
|
|
#include <QFile>
|
2016-06-17 01:25:40 +02:00
|
|
|
#include <QHostInfo>
|
2016-06-25 15:15:23 +02:00
|
|
|
#include <QHostAddress>
|
2016-06-20 23:41:07 +02:00
|
|
|
#include <cstdint>
|
|
|
|
#include <limits>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-11-19 23:02:41 +01:00
|
|
|
#include "HyperionConfig.h"
|
|
|
|
|
2013-08-14 10:54:49 +02:00
|
|
|
#include <utils/jsonschema/JsonFactory.h>
|
|
|
|
|
|
|
|
#include <hyperion/Hyperion.h>
|
2013-11-24 16:10:48 +01:00
|
|
|
#include <effectengine/EffectEngine.h>
|
2016-05-31 22:55:11 +02:00
|
|
|
#include <bonjour/bonjourserviceregister.h>
|
|
|
|
#include <bonjour/bonjourrecord.h>
|
2013-08-17 15:39:29 +02:00
|
|
|
#include <jsonserver/JsonServer.h>
|
2016-06-12 22:27:24 +02:00
|
|
|
#include <protoserver/ProtoServer.h>
|
|
|
|
#include <boblightserver/BoblightServer.h>
|
2016-06-20 08:38:12 +02:00
|
|
|
#include <udplistener/UDPListener.h>
|
2016-05-30 22:38:40 +02:00
|
|
|
|
2016-06-17 01:25:40 +02:00
|
|
|
#include "hyperiond.h"
|
2013-11-08 22:18:10 +01:00
|
|
|
|
2013-08-22 22:06:13 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, _log(Logger::getInstance("MAIN"))
|
2016-07-10 22:04:31 +02:00
|
|
|
, _kodiVideoChecker(nullptr)
|
2016-06-19 00:56:47 +02:00
|
|
|
, _jsonServer(nullptr)
|
|
|
|
, _protoServer(nullptr)
|
|
|
|
, _boblightServer(nullptr)
|
2016-06-20 08:38:12 +02:00
|
|
|
, _udpListener(nullptr)
|
2016-06-19 00:56:47 +02:00
|
|
|
, _v4l2Grabber(nullptr)
|
|
|
|
, _dispmanx(nullptr)
|
|
|
|
, _amlGrabber(nullptr)
|
|
|
|
, _fbGrabber(nullptr)
|
|
|
|
, _osxGrabber(nullptr)
|
2016-06-20 09:10:23 +02:00
|
|
|
, _hyperion(nullptr)
|
2016-06-19 00:56:47 +02:00
|
|
|
{
|
|
|
|
loadConfig(configFile);
|
2016-06-20 09:10:23 +02:00
|
|
|
_hyperion = Hyperion::initInstance(_config, configFile);
|
2016-06-27 23:56:21 +02:00
|
|
|
|
|
|
|
if (Logger::getLogLevel() == Logger::WARNING)
|
|
|
|
{
|
|
|
|
if (_config.isMember("logger"))
|
|
|
|
{
|
|
|
|
const Json::Value & logConfig = _config["logger"];
|
|
|
|
std::string level = logConfig.get("level", "warn").asString(); // silent warn verbose debug
|
|
|
|
if (level == "silent") Logger::setLogLevel(Logger::OFF);
|
|
|
|
else if (level == "warn") Logger::setLogLevel(Logger::WARNING);
|
|
|
|
else if (level == "verbose") Logger::setLogLevel(Logger::INFO);
|
|
|
|
else if (level == "debug") Logger::setLogLevel(Logger::DEBUG);
|
|
|
|
else Error(Logger::getInstance("LOGGER"), "log level '%s' used in config is unknown. valid: silent warn verbose debug", level.c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WarningIf(_config.isMember("logger"), Logger::getInstance("LOGGER"), "Logger settings overriden by command line argument");
|
|
|
|
}
|
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
Info(_log, "Hyperion started and initialised");
|
|
|
|
}
|
|
|
|
|
|
|
|
HyperionDaemon::~HyperionDaemon()
|
|
|
|
{
|
|
|
|
delete _amlGrabber;
|
|
|
|
delete _dispmanx;
|
|
|
|
delete _fbGrabber;
|
|
|
|
delete _osxGrabber;
|
|
|
|
delete _v4l2Grabber;
|
2016-07-10 22:04:31 +02:00
|
|
|
delete _kodiVideoChecker;
|
2016-06-19 00:56:47 +02:00
|
|
|
delete _jsonServer;
|
|
|
|
delete _protoServer;
|
|
|
|
delete _boblightServer;
|
2016-06-20 08:38:12 +02:00
|
|
|
delete _udpListener;
|
2016-06-20 09:10:23 +02:00
|
|
|
delete _hyperion;
|
2016-06-19 00:56:47 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperionDaemon::run()
|
|
|
|
{
|
2016-06-20 23:41:07 +02:00
|
|
|
startInitialEffect();
|
2016-07-10 22:04:31 +02:00
|
|
|
createKODIVideoChecker();
|
2016-06-19 00:56:47 +02:00
|
|
|
|
|
|
|
// ---- network services -----
|
|
|
|
startNetworkServices();
|
|
|
|
|
|
|
|
// ---- grabber -----
|
|
|
|
createGrabberV4L2();
|
|
|
|
createGrabberDispmanx();
|
|
|
|
createGrabberAmlogic();
|
|
|
|
createGrabberFramebuffer();
|
|
|
|
|
|
|
|
#if !defined(ENABLE_DISPMANX) && !defined(ENABLE_OSX) && !defined(ENABLE_FB)
|
2016-06-20 23:41:07 +02:00
|
|
|
ErrorIf(_config.isMember("framegrabber"), _log, "No grabber can be instantiated, because all grabbers have been left out from the build");
|
2016-06-19 00:56:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperionDaemon::loadConfig(const std::string & configFile)
|
|
|
|
{
|
|
|
|
Info(_log, "Selected configuration file: %s", configFile.c_str() );
|
|
|
|
// make sure the resources are loaded (they may be left out after static linking)
|
|
|
|
Q_INIT_RESOURCE(resource);
|
|
|
|
|
|
|
|
// read the json schema from the resource
|
|
|
|
QResource schemaData(":/hyperion-schema");
|
|
|
|
assert(schemaData.isValid());
|
|
|
|
|
|
|
|
Json::Reader jsonReader;
|
|
|
|
Json::Value schemaJson;
|
|
|
|
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("ERROR: Json schema wrong: " + jsonReader.getFormattedErrorMessages()) ;
|
|
|
|
}
|
|
|
|
JsonSchemaChecker schemaChecker;
|
|
|
|
schemaChecker.setSchema(schemaJson);
|
|
|
|
|
|
|
|
_config = JsonFactory::readJson(configFile);
|
|
|
|
schemaChecker.validate(_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-20 23:41:07 +02:00
|
|
|
void HyperionDaemon::startInitialEffect()
|
2013-08-24 11:51:52 +02:00
|
|
|
{
|
2016-06-17 01:25:40 +02:00
|
|
|
Hyperion *hyperion = Hyperion::getInstance();
|
2013-08-24 11:51:52 +02:00
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// create boot sequence if the configuration is present
|
2016-06-20 23:41:07 +02:00
|
|
|
if (_config.isMember("initialEffect"))
|
2013-08-25 18:20:19 +02:00
|
|
|
{
|
2016-06-20 23:41:07 +02:00
|
|
|
const Json::Value effectConfig = _config["initialEffect"];
|
|
|
|
const int HIGHEST_PRIORITY = 0;
|
|
|
|
const int DURATION_INFINITY = 0;
|
|
|
|
const int LOWEST_PRIORITY = std::numeric_limits<int>::max()-1;
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-03-12 19:21:47 +01:00
|
|
|
// clear the leds
|
2016-06-20 23:41:07 +02:00
|
|
|
hyperion->setColor(HIGHEST_PRIORITY, ColorRgb::BLACK, DURATION_INFINITY, false);
|
2016-01-31 22:38:30 +01:00
|
|
|
|
2016-06-20 23:41:07 +02:00
|
|
|
// initial foreground effect/color
|
|
|
|
const Json::Value fgEffectConfig = effectConfig["foreground-effect"];
|
|
|
|
int default_fg_duration_ms = 3000;
|
|
|
|
int fg_duration_ms = effectConfig.get("foreground-effect-duration_ms",default_fg_duration_ms).asUInt();
|
|
|
|
if (fg_duration_ms == DURATION_INFINITY)
|
2016-01-31 22:38:30 +01:00
|
|
|
{
|
2016-06-20 23:41:07 +02:00
|
|
|
fg_duration_ms = default_fg_duration_ms;
|
|
|
|
Warning(_log, "foreground effect duration 'infinity' is forbidden, set to default value %d ms",default_fg_duration_ms);
|
2013-12-13 19:59:01 +01:00
|
|
|
}
|
2016-06-20 23:41:07 +02:00
|
|
|
if ( ! fgEffectConfig.isNull() && fgEffectConfig.isArray() && fgEffectConfig.size() == 3 )
|
2013-12-13 19:59:01 +01:00
|
|
|
{
|
2016-06-20 23:41:07 +02:00
|
|
|
ColorRgb fg_color = {
|
|
|
|
(uint8_t)fgEffectConfig[0].asUInt(),
|
|
|
|
(uint8_t)fgEffectConfig[1].asUInt(),
|
|
|
|
(uint8_t)fgEffectConfig[2].asUInt()
|
2016-03-12 19:21:47 +01:00
|
|
|
};
|
2016-06-20 23:41:07 +02:00
|
|
|
hyperion->setColor(HIGHEST_PRIORITY, fg_color, fg_duration_ms, false);
|
|
|
|
Info(_log,"Inital foreground color set (%d %d %d)",fg_color.red,fg_color.green,fg_color.blue);
|
|
|
|
}
|
|
|
|
else if (! fgEffectConfig.isNull() && fgEffectConfig.isString())
|
|
|
|
{
|
|
|
|
const std::string bgEffectName = fgEffectConfig.asString();
|
|
|
|
int result = effectConfig.isMember("foreground-effect-args")
|
|
|
|
? hyperion->setEffect(bgEffectName, effectConfig["foreground-effect-args"], HIGHEST_PRIORITY, fg_duration_ms)
|
|
|
|
: hyperion->setEffect(bgEffectName, HIGHEST_PRIORITY, fg_duration_ms);
|
|
|
|
Info(_log,"Inital foreground effect '%s' %s", bgEffectName.c_str(), ((result == 0) ? "started" : "failed"));
|
2013-10-16 18:04:43 +02:00
|
|
|
}
|
2016-03-12 19:21:47 +01:00
|
|
|
|
2016-06-20 23:41:07 +02:00
|
|
|
// initial background effect/color
|
|
|
|
const Json::Value bgEffectConfig = effectConfig["background-effect"];
|
|
|
|
if ( ! bgEffectConfig.isNull() && bgEffectConfig.isArray() && bgEffectConfig.size() == 3 )
|
|
|
|
{
|
|
|
|
ColorRgb bg_color = {
|
|
|
|
(uint8_t)bgEffectConfig[0].asUInt(),
|
|
|
|
(uint8_t)bgEffectConfig[1].asUInt(),
|
|
|
|
(uint8_t)bgEffectConfig[2].asUInt()
|
|
|
|
};
|
|
|
|
hyperion->setColor(LOWEST_PRIORITY, bg_color, DURATION_INFINITY, false);
|
|
|
|
Info(_log,"Inital background color set (%d %d %d)",bg_color.red,bg_color.green,bg_color.blue);
|
|
|
|
}
|
|
|
|
else if (! bgEffectConfig.isNull() && bgEffectConfig.isString())
|
|
|
|
{
|
|
|
|
const std::string bgEffectName = bgEffectConfig.asString();
|
|
|
|
int result = effectConfig.isMember("background-effect-args")
|
|
|
|
? hyperion->setEffect(bgEffectName, effectConfig["background-effect-args"], LOWEST_PRIORITY, DURATION_INFINITY)
|
|
|
|
: hyperion->setEffect(bgEffectName, LOWEST_PRIORITY, DURATION_INFINITY);
|
|
|
|
Info(_log,"Inital background effect '%s' %s", bgEffectName.c_str(), ((result == 0) ? "started" : "failed"));
|
|
|
|
}
|
2013-08-25 18:20:19 +02:00
|
|
|
}
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2013-08-23 18:24:10 +02:00
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
// create KODI video checker if the _configuration is present
|
|
|
|
void HyperionDaemon::createKODIVideoChecker()
|
2016-05-30 22:38:40 +02:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
bool kodiCheckerConfigured = _config.isMember("kodiVideoChecker");
|
|
|
|
|
|
|
|
const Json::Value & videoCheckerConfig = _config["kodiVideoChecker"];
|
|
|
|
_kodiVideoChecker = KODIVideoChecker::initInstance(
|
|
|
|
videoCheckerConfig.get("kodiAddress","127.0.0.1").asString(),
|
|
|
|
videoCheckerConfig.get("kodiTcpPort",9090).asUInt(),
|
|
|
|
videoCheckerConfig.get("grabVideo",true).asBool(),
|
|
|
|
videoCheckerConfig.get("grabPictures",true).asBool(),
|
|
|
|
videoCheckerConfig.get("grabAudio",true).asBool(),
|
|
|
|
videoCheckerConfig.get("grabMenu",false).asBool(),
|
|
|
|
videoCheckerConfig.get("grabPause", true).asBool(),
|
|
|
|
videoCheckerConfig.get("grabScreensaver", false).asBool(),
|
|
|
|
videoCheckerConfig.get("enable3DDetection", true).asBool());
|
|
|
|
Debug(_log, "KODI checker created ");
|
|
|
|
|
|
|
|
if( kodiCheckerConfigured && videoCheckerConfig.get("enable", true).asBool() )
|
2013-10-13 14:48:59 +02:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
_kodiVideoChecker->start();
|
2013-08-24 11:51:52 +02:00
|
|
|
}
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2013-08-23 20:44:53 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
void HyperionDaemon::startNetworkServices()
|
2016-05-30 22:38:40 +02:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
KODIVideoChecker* kodiVideoChecker = KODIVideoChecker::getInstance();
|
2016-06-17 01:25:40 +02:00
|
|
|
|
2016-02-16 15:41:40 +01:00
|
|
|
// Create Json server if configuration is present
|
2016-06-08 11:53:01 +02:00
|
|
|
unsigned int jsonPort = 19444;
|
2016-06-19 00:56:47 +02:00
|
|
|
if (_config.isMember("jsonServer"))
|
2016-02-16 15:41:40 +01:00
|
|
|
{
|
2016-06-19 00:56:47 +02:00
|
|
|
const Json::Value & jsonServerConfig = _config["jsonServer"];
|
2016-06-08 11:53:01 +02:00
|
|
|
//jsonEnable = jsonServerConfig.get("enable", true).asBool();
|
2016-06-14 20:14:06 +02:00
|
|
|
jsonPort = jsonServerConfig.get("port", jsonPort).asUInt();
|
2016-02-16 15:41:40 +01:00
|
|
|
}
|
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
_jsonServer = new JsonServer(jsonPort );
|
|
|
|
Info(_log, "Json server created and started on port %d", _jsonServer->getPort());
|
2016-06-08 11:53:01 +02:00
|
|
|
|
2016-02-16 15:41:40 +01:00
|
|
|
// Create Proto server if configuration is present
|
2016-06-08 11:53:01 +02:00
|
|
|
unsigned int protoPort = 19445;
|
2016-06-19 00:56:47 +02:00
|
|
|
if (_config.isMember("protoServer"))
|
2016-02-16 15:41:40 +01:00
|
|
|
{
|
2016-06-19 00:56:47 +02:00
|
|
|
const Json::Value & protoServerConfig = _config["protoServer"];
|
2016-06-08 11:53:01 +02:00
|
|
|
//protoEnable = protoServerConfig.get("enable", true).asBool();
|
2016-06-14 20:14:06 +02:00
|
|
|
protoPort = protoServerConfig.get("port", protoPort).asUInt();
|
2016-06-08 11:53:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
_protoServer = new ProtoServer(protoPort );
|
2016-07-10 22:04:31 +02:00
|
|
|
if (kodiVideoChecker != nullptr)
|
2016-06-08 11:53:01 +02:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
QObject::connect(kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _protoServer, SIGNAL(grabbingMode(GrabbingMode)));
|
|
|
|
QObject::connect(kodiVideoChecker, SIGNAL(videoMode(VideoMode)), _protoServer, SIGNAL(videoMode(VideoMode)));
|
2016-06-08 11:53:01 +02:00
|
|
|
}
|
2016-06-19 00:56:47 +02:00
|
|
|
Info(_log, "Proto server created and started on port %d", _protoServer->getPort());
|
2016-06-04 19:26:34 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
// Create Boblight server if configuration is present
|
|
|
|
if (_config.isMember("boblightServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & boblightServerConfig = _config["boblightServer"];
|
2016-06-27 22:43:43 +02:00
|
|
|
_boblightServer = new BoblightServer(
|
|
|
|
boblightServerConfig.get("priority",900).asInt(),
|
|
|
|
boblightServerConfig["port"].asUInt()
|
|
|
|
);
|
|
|
|
Debug(_log, "Boblight server created");
|
|
|
|
|
2016-06-20 15:17:29 +02:00
|
|
|
if ( boblightServerConfig.get("enable", true).asBool() )
|
|
|
|
{
|
2016-06-27 22:43:43 +02:00
|
|
|
_boblightServer->start();
|
2016-06-20 15:17:29 +02:00
|
|
|
}
|
2016-06-19 00:56:47 +02:00
|
|
|
}
|
2016-06-08 11:53:01 +02:00
|
|
|
|
2016-06-20 23:41:07 +02:00
|
|
|
// Create UDP listener if configuration is present
|
|
|
|
if (_config.isMember("udpListener"))
|
|
|
|
{
|
|
|
|
const Json::Value & udpListenerConfig = _config["udpListener"];
|
2016-06-27 09:27:11 +02:00
|
|
|
_udpListener = new UDPListener(
|
|
|
|
udpListenerConfig.get("priority",700).asInt(),
|
|
|
|
udpListenerConfig.get("timeout",10000).asInt(),
|
|
|
|
udpListenerConfig.get("address", "").asString(),
|
|
|
|
udpListenerConfig.get("port", 2801).asUInt(),
|
|
|
|
udpListenerConfig.get("shared", false).asBool()
|
|
|
|
);
|
2016-06-27 22:43:43 +02:00
|
|
|
Debug(_log, "UDP listener created");
|
2016-06-27 09:27:11 +02:00
|
|
|
|
2016-06-20 15:17:29 +02:00
|
|
|
if ( udpListenerConfig.get("enable", true).asBool() )
|
|
|
|
{
|
2016-06-27 09:27:11 +02:00
|
|
|
_udpListener->start();
|
2016-06-20 15:17:29 +02:00
|
|
|
}
|
2016-06-20 23:41:07 +02:00
|
|
|
}
|
2016-06-20 08:38:12 +02:00
|
|
|
|
2016-06-20 15:17:29 +02:00
|
|
|
// zeroconf description - $leddevicename@$hostname
|
2016-06-19 00:56:47 +02:00
|
|
|
const Json::Value & deviceConfig = _config["device"];
|
2016-06-20 15:17:29 +02:00
|
|
|
const std::string mDNSDescr = ( deviceConfig.get("name", "").asString()
|
|
|
|
+ "@" +
|
|
|
|
QHostInfo::localHostName().toStdString()
|
|
|
|
);
|
|
|
|
|
|
|
|
// zeroconf udp listener
|
|
|
|
if (_udpListener != nullptr) {
|
|
|
|
BonjourServiceRegister *bonjourRegister_udp = new BonjourServiceRegister();
|
|
|
|
bonjourRegister_udp->registerService(
|
|
|
|
BonjourRecord(mDNSDescr.c_str(), "_hyperiond-rgbled._udp", QString()),
|
|
|
|
_udpListener->getPort()
|
|
|
|
);
|
|
|
|
Info(_log, "UDP LIstener mDNS responder started");
|
|
|
|
}
|
2016-06-19 00:56:47 +02:00
|
|
|
|
|
|
|
// zeroconf json
|
2016-06-14 20:14:06 +02:00
|
|
|
BonjourServiceRegister *bonjourRegister_json = new BonjourServiceRegister();
|
2016-06-20 15:17:29 +02:00
|
|
|
bonjourRegister_json->registerService(
|
|
|
|
BonjourRecord(mDNSDescr.c_str(), "_hyperiond-json._tcp", QString()),
|
|
|
|
_jsonServer->getPort()
|
|
|
|
);
|
2016-06-19 00:56:47 +02:00
|
|
|
Info(_log, "Json mDNS responder started");
|
2016-06-08 11:53:01 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
// zeroconf proto
|
2016-06-14 20:14:06 +02:00
|
|
|
BonjourServiceRegister *bonjourRegister_proto = new BonjourServiceRegister();
|
2016-06-20 15:17:29 +02:00
|
|
|
bonjourRegister_proto->registerService(
|
|
|
|
BonjourRecord(mDNSDescr.c_str(), "_hyperiond-proto._tcp", QString()),
|
|
|
|
_protoServer->getPort()
|
|
|
|
);
|
2016-06-19 00:56:47 +02:00
|
|
|
Info(_log, "Proto mDNS responder started");
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2016-02-16 15:41:40 +01:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
void HyperionDaemon::createGrabberDispmanx()
|
2016-05-30 22:38:40 +02:00
|
|
|
{
|
2016-06-17 01:25:40 +02:00
|
|
|
#ifdef ENABLE_DISPMANX
|
2013-10-13 14:48:59 +02:00
|
|
|
// Construct and start the frame-grabber if the configuration is present
|
2016-06-19 00:56:47 +02:00
|
|
|
if (_config.isMember("framegrabber"))
|
2013-10-13 14:48:59 +02:00
|
|
|
{
|
2016-06-19 00:56:47 +02:00
|
|
|
const Json::Value & frameGrabberConfig = _config["framegrabber"];
|
|
|
|
_dispmanx = new DispmanxWrapper(
|
2013-08-25 18:20:19 +02:00
|
|
|
frameGrabberConfig["width"].asUInt(),
|
|
|
|
frameGrabberConfig["height"].asUInt(),
|
|
|
|
frameGrabberConfig["frequency_Hz"].asUInt(),
|
2016-06-17 01:25:40 +02:00
|
|
|
frameGrabberConfig.get("priority",900).asInt());
|
2016-06-19 00:56:47 +02:00
|
|
|
_dispmanx->setCropping(
|
2016-05-18 11:26:25 +02:00
|
|
|
frameGrabberConfig.get("cropLeft", 0).asInt(),
|
|
|
|
frameGrabberConfig.get("cropRight", 0).asInt(),
|
|
|
|
frameGrabberConfig.get("cropTop", 0).asInt(),
|
|
|
|
frameGrabberConfig.get("cropBottom", 0).asInt());
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _dispmanx, SLOT(setGrabbingMode(GrabbingMode)));
|
|
|
|
QObject::connect(_kodiVideoChecker, SIGNAL(videoMode(VideoMode)), _dispmanx, SLOT(setVideoMode(VideoMode)));
|
2016-06-19 00:56:47 +02:00
|
|
|
QObject::connect(_dispmanx, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
2016-02-17 00:44:06 +01:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
_dispmanx->start();
|
|
|
|
Info(_log, "Frame grabber created and started");
|
2013-10-13 14:48:59 +02:00
|
|
|
}
|
2016-06-19 00:56:47 +02:00
|
|
|
#else
|
|
|
|
ErrorIf(_config.isMember("framegrabber"), _log, "The dispmanx framegrabber can not be instantiated, because it has been left out from the build");
|
2015-01-18 00:04:45 +01:00
|
|
|
#endif
|
2016-06-17 01:25:40 +02:00
|
|
|
}
|
2013-10-13 14:48:59 +02:00
|
|
|
|
2016-06-17 01:25:40 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
void HyperionDaemon::createGrabberV4L2()
|
2016-05-30 22:38:40 +02:00
|
|
|
{
|
2014-02-21 22:30:34 +01:00
|
|
|
// construct and start the v4l2 grabber if the configuration is present
|
2016-06-17 01:25:40 +02:00
|
|
|
#ifdef ENABLE_V4L2
|
2016-06-19 00:56:47 +02:00
|
|
|
if (_config.isMember("grabber-v4l2"))
|
2014-02-21 22:30:34 +01:00
|
|
|
{
|
2016-06-19 00:56:47 +02:00
|
|
|
const Json::Value & grabberConfig = _config["grabber-v4l2"];
|
2016-07-10 13:36:05 +02:00
|
|
|
if (grabberConfig.get("enable", true).asBool())
|
|
|
|
{
|
|
|
|
_v4l2Grabber = new V4L2Wrapper(
|
|
|
|
grabberConfig.get("device", "/dev/video0").asString(),
|
|
|
|
grabberConfig.get("input", 0).asInt(),
|
|
|
|
parseVideoStandard(grabberConfig.get("standard", "no-change").asString()),
|
|
|
|
parsePixelFormat(grabberConfig.get("pixelFormat", "no-change").asString()),
|
|
|
|
grabberConfig.get("width", -1).asInt(),
|
|
|
|
grabberConfig.get("height", -1).asInt(),
|
|
|
|
grabberConfig.get("frameDecimation", 2).asInt(),
|
|
|
|
grabberConfig.get("sizeDecimation", 8).asInt(),
|
|
|
|
grabberConfig.get("redSignalThreshold", 0.0).asDouble(),
|
|
|
|
grabberConfig.get("greenSignalThreshold", 0.0).asDouble(),
|
|
|
|
grabberConfig.get("blueSignalThreshold", 0.0).asDouble(),
|
|
|
|
grabberConfig.get("priority", 900).asInt());
|
|
|
|
_v4l2Grabber->set3D(parse3DMode(grabberConfig.get("mode", "2D").asString()));
|
|
|
|
_v4l2Grabber->setCropping(
|
|
|
|
grabberConfig.get("cropLeft", 0).asInt(),
|
|
|
|
grabberConfig.get("cropRight", 0).asInt(),
|
|
|
|
grabberConfig.get("cropTop", 0).asInt(),
|
|
|
|
grabberConfig.get("cropBottom", 0).asInt());
|
|
|
|
|
|
|
|
QObject::connect(_v4l2Grabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
|
|
|
|
|
|
|
_v4l2Grabber->start();
|
|
|
|
Info(_log, "V4L2 grabber created and started");
|
|
|
|
}
|
2014-02-21 22:30:34 +01:00
|
|
|
}
|
2016-06-19 00:56:47 +02:00
|
|
|
#else
|
|
|
|
ErrorIf(_config.isMember("grabber-v4l2"), _log, "The v4l2 grabber can not be instantiated, because it has been left out from the build");
|
2014-02-21 22:30:34 +01:00
|
|
|
#endif
|
2016-06-17 01:25:40 +02:00
|
|
|
}
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
void HyperionDaemon::createGrabberAmlogic()
|
2016-05-30 22:38:40 +02:00
|
|
|
{
|
2016-06-17 01:25:40 +02:00
|
|
|
#ifdef ENABLE_AMLOGIC
|
2015-08-20 09:51:44 +02:00
|
|
|
// Construct and start the framebuffer grabber if the configuration is present
|
2016-06-19 00:56:47 +02:00
|
|
|
if (_config.isMember("amlgrabber"))
|
2015-08-20 09:51:44 +02:00
|
|
|
{
|
2016-06-19 00:56:47 +02:00
|
|
|
const Json::Value & grabberConfig = _config["amlgrabber"];
|
|
|
|
_amlGrabber = new AmlogicWrapper(
|
2015-08-20 09:51:44 +02:00
|
|
|
grabberConfig["width"].asUInt(),
|
|
|
|
grabberConfig["height"].asUInt(),
|
|
|
|
grabberConfig["frequency_Hz"].asUInt(),
|
2016-06-17 01:25:40 +02:00
|
|
|
grabberConfig.get("priority",900).asInt());
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _amlGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
|
|
|
QObject::connect(_kodiVideoChecker, SIGNAL(videoMode(VideoMode)), _amlGrabber, SLOT(setVideoMode(VideoMode)));
|
2016-06-19 00:56:47 +02:00
|
|
|
QObject::connect(_amlGrabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
2016-02-24 14:42:25 +01:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
_amlGrabber->start();
|
|
|
|
Info(_log, "AMLOGIC grabber created and started");
|
2015-08-20 09:51:44 +02:00
|
|
|
}
|
2016-06-19 00:56:47 +02:00
|
|
|
#else
|
|
|
|
ErrorIf(_config.isMember("amlgrabber"), _log, "The AMLOGIC grabber can not be instantiated, because it has been left out from the build");
|
2015-08-20 09:51:44 +02:00
|
|
|
#endif
|
2016-06-17 01:25:40 +02:00
|
|
|
}
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
void HyperionDaemon::createGrabberFramebuffer()
|
2016-05-30 22:38:40 +02:00
|
|
|
{
|
2016-06-17 01:25:40 +02:00
|
|
|
#ifdef ENABLE_FB
|
2015-01-18 00:04:45 +01:00
|
|
|
// Construct and start the framebuffer grabber if the configuration is present
|
2016-06-19 00:56:47 +02:00
|
|
|
if (_config.isMember("framebuffergrabber") || _config.isMember("framegrabber"))
|
2015-01-18 00:04:45 +01:00
|
|
|
{
|
2016-06-19 00:56:47 +02:00
|
|
|
const Json::Value & grabberConfig = _config.isMember("framebuffergrabber")? _config["framebuffergrabber"] : _config["framegrabber"];
|
|
|
|
_fbGrabber = new FramebufferWrapper(
|
2015-01-18 00:04:45 +01:00
|
|
|
grabberConfig.get("device", "/dev/fb0").asString(),
|
|
|
|
grabberConfig["width"].asUInt(),
|
|
|
|
grabberConfig["height"].asUInt(),
|
|
|
|
grabberConfig["frequency_Hz"].asUInt(),
|
2016-06-17 01:25:40 +02:00
|
|
|
grabberConfig.get("priority",900).asInt());
|
2015-01-18 00:04:45 +01:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _fbGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
|
|
|
QObject::connect(_kodiVideoChecker, SIGNAL(videoMode(VideoMode)), _fbGrabber, SLOT(setVideoMode(VideoMode)));
|
2016-06-19 00:56:47 +02:00
|
|
|
QObject::connect(_fbGrabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
2016-02-17 00:44:06 +01:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
_fbGrabber->start();
|
|
|
|
Info(_log, "Framebuffer grabber created and started");
|
2015-01-18 00:04:45 +01:00
|
|
|
}
|
2016-06-19 00:56:47 +02:00
|
|
|
#else
|
|
|
|
ErrorIf(_config.isMember("framebuffergrabber"), _log, "The framebuffer grabber can not be instantiated, because it has been left out from the build");
|
2015-01-18 00:04:45 +01:00
|
|
|
#endif
|
2016-06-17 01:25:40 +02:00
|
|
|
}
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
void HyperionDaemon::createGrabberOsx()
|
2016-05-30 22:38:40 +02:00
|
|
|
{
|
2016-06-17 01:25:40 +02:00
|
|
|
#ifdef ENABLE_OSX
|
2015-08-20 09:51:44 +02:00
|
|
|
// Construct and start the osx grabber if the configuration is present
|
2016-06-19 00:56:47 +02:00
|
|
|
if (_config.isMember("framegrabber"))
|
2015-08-20 09:51:44 +02:00
|
|
|
{
|
2016-06-19 00:56:47 +02:00
|
|
|
const Json::Value & grabberConfig = _config.isMember("osxgrabber")? _config["osxgrabber"] : _config["framegrabber"];
|
|
|
|
_osxGrabber = new OsxWrapper(
|
2016-03-08 17:31:56 +01:00
|
|
|
grabberConfig.get("display", 0).asUInt(),
|
|
|
|
grabberConfig["width"].asUInt(),
|
|
|
|
grabberConfig["height"].asUInt(),
|
|
|
|
grabberConfig["frequency_Hz"].asUInt(),
|
2016-06-17 01:25:40 +02:00
|
|
|
grabberConfig.get("priority",900).asInt());
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _osxGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
|
|
|
QObject::connect(_kodiVideoChecker, SIGNAL(videoMode(VideoMode)), _osxGrabber, SLOT(setVideoMode(VideoMode)));
|
2016-06-19 00:56:47 +02:00
|
|
|
QObject::connect(_osxGrabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
_osxGrabber->start();
|
|
|
|
Info(_log, "OSX grabber created and started");
|
2015-08-20 09:51:44 +02:00
|
|
|
}
|
2016-06-19 00:56:47 +02:00
|
|
|
#else
|
|
|
|
ErrorIf(_config.isMember("osxgrabber"), _log, "The osx grabber can not be instantiated, because it has been left out from the build");
|
2016-05-30 22:38:40 +02:00
|
|
|
#endif
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|