2013-08-22 22:06:13 +02:00
|
|
|
// C++ includes
|
2013-11-11 10:00:37 +01:00
|
|
|
#include <cassert>
|
2013-08-22 22:06:13 +02:00
|
|
|
#include <csignal>
|
2016-02-08 16:56:23 +01:00
|
|
|
#include <vector>
|
2016-05-30 22:38:40 +02:00
|
|
|
#include <unistd.h>
|
2013-08-22 22:06:13 +02:00
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// QT includes
|
|
|
|
#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>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
// getoptPlusPLus includes
|
|
|
|
#include <getoptPlusPlus/getoptpp.h>
|
|
|
|
|
2013-11-19 23:02:41 +01:00
|
|
|
// config includes
|
|
|
|
#include "HyperionConfig.h"
|
|
|
|
|
2013-08-14 10:54:49 +02:00
|
|
|
// Json-Schema includes
|
|
|
|
#include <utils/jsonschema/JsonFactory.h>
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// Hyperion includes
|
2013-08-14 10:54:49 +02:00
|
|
|
#include <hyperion/Hyperion.h>
|
2013-08-25 18:20:19 +02:00
|
|
|
|
2013-11-19 23:02:41 +01:00
|
|
|
#ifdef ENABLE_DISPMANX
|
2013-08-17 16:12:42 +02:00
|
|
|
// Dispmanx grabber includes
|
2014-02-07 21:11:50 +01:00
|
|
|
#include <grabber/DispmanxWrapper.h>
|
2013-11-19 23:02:41 +01:00
|
|
|
#endif
|
2013-08-17 16:12:42 +02:00
|
|
|
|
2014-02-21 22:30:34 +01:00
|
|
|
#ifdef ENABLE_V4L2
|
|
|
|
// v4l2 grabber
|
2014-02-23 22:39:23 +01:00
|
|
|
#include <grabber/V4L2Wrapper.h>
|
2014-02-21 22:30:34 +01:00
|
|
|
#endif
|
|
|
|
|
2015-01-18 00:04:45 +01:00
|
|
|
#ifdef ENABLE_FB
|
|
|
|
// Framebuffer grabber includes
|
|
|
|
#include <grabber/FramebufferWrapper.h>
|
|
|
|
#endif
|
|
|
|
|
2015-08-20 09:51:44 +02:00
|
|
|
#ifdef ENABLE_AMLOGIC
|
|
|
|
#include <grabber/AmlogicWrapper.h>
|
|
|
|
#endif
|
|
|
|
|
2015-01-24 23:42:22 +01:00
|
|
|
#ifdef ENABLE_OSX
|
|
|
|
// OSX grabber includes
|
|
|
|
#include <grabber/OsxWrapper.h>
|
|
|
|
#endif
|
|
|
|
|
2013-08-23 20:44:53 +02:00
|
|
|
// XBMC Video checker includes
|
|
|
|
#include <xbmcvideochecker/XBMCVideoChecker.h>
|
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
// Effect engine includes
|
|
|
|
#include <effectengine/EffectEngine.h>
|
|
|
|
|
2016-05-31 22:55:11 +02:00
|
|
|
#ifdef ENABLE_ZEROCONF
|
|
|
|
#include <bonjour/bonjourserviceregister.h>
|
|
|
|
#include <bonjour/bonjourrecord.h>
|
|
|
|
#include <QHostInfo>
|
|
|
|
#endif
|
|
|
|
|
2013-08-17 15:39:29 +02:00
|
|
|
// JsonServer includes
|
|
|
|
#include <jsonserver/JsonServer.h>
|
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// ProtoServer includes
|
|
|
|
#include <protoserver/ProtoServer.h>
|
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
// BoblightServer includes
|
|
|
|
#include <boblightserver/BoblightServer.h>
|
2016-05-30 22:38:40 +02:00
|
|
|
#include <sys/prctl.h>
|
|
|
|
|
|
|
|
using namespace vlofgren;
|
2013-11-08 22:18:10 +01:00
|
|
|
|
2013-08-22 22:06:13 +02:00
|
|
|
void signal_handler(const int signum)
|
|
|
|
{
|
|
|
|
QCoreApplication::quit();
|
2013-11-09 10:33:16 +01:00
|
|
|
|
|
|
|
// reset signal handler to default (in case this handler is not capable of stopping)
|
|
|
|
signal(signum, SIG_DFL);
|
2013-08-22 22:06:13 +02:00
|
|
|
}
|
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
Json::Value loadConfig(const std::string & configFile)
|
|
|
|
{
|
|
|
|
// 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))
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
throw std::runtime_error("ERROR: Json schema wrong: " + jsonReader.getFormattedErrorMessages()) ;
|
2013-08-24 11:51:52 +02:00
|
|
|
}
|
|
|
|
JsonSchemaChecker schemaChecker;
|
|
|
|
schemaChecker.setSchema(schemaJson);
|
|
|
|
|
|
|
|
const Json::Value jsonConfig = JsonFactory::readJson(configFile);
|
|
|
|
schemaChecker.validate(jsonConfig);
|
|
|
|
|
|
|
|
return jsonConfig;
|
|
|
|
}
|
|
|
|
|
2014-01-28 22:27:02 +01:00
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
void startNewHyperion(int parentPid, std::string hyperionFile, std::string configFile)
|
|
|
|
{
|
|
|
|
if ( fork() == 0 )
|
2016-05-24 19:56:43 +02:00
|
|
|
{
|
2016-05-30 22:38:40 +02:00
|
|
|
sleep(3);
|
|
|
|
execl(hyperionFile.c_str(), hyperionFile.c_str(), "--parent", QString::number(parentPid).toStdString().c_str(), configFile.c_str(), NULL);
|
|
|
|
exit(0);
|
2016-05-24 19:56:43 +02:00
|
|
|
}
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2016-05-24 19:56:43 +02:00
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
void startBootsequence(const Json::Value &config, Hyperion &hyperion)
|
|
|
|
{
|
2013-10-13 14:48:59 +02:00
|
|
|
// create boot sequence if the configuration is present
|
|
|
|
if (config.isMember("bootsequence"))
|
2013-08-25 18:20:19 +02:00
|
|
|
{
|
2013-12-13 15:55:34 +01:00
|
|
|
const Json::Value effectConfig = config["bootsequence"];
|
|
|
|
|
|
|
|
// Get the parameters for the bootsequence
|
|
|
|
const std::string effectName = effectConfig["effect"].asString();
|
|
|
|
const unsigned duration_ms = effectConfig["duration_ms"].asUInt();
|
2016-05-23 11:01:52 +02:00
|
|
|
const int priority = (duration_ms != 0) ? 0 : effectConfig.get("priority",990).asInt();
|
|
|
|
const int bootcolor_priority = (priority > 990) ? priority+1 : 990;
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-03-12 19:21:47 +01:00
|
|
|
// clear the leds
|
|
|
|
ColorRgb boot_color = ColorRgb::BLACK;
|
|
|
|
hyperion.setColor(bootcolor_priority, boot_color, 0, false);
|
2016-01-31 22:38:30 +01:00
|
|
|
|
2016-03-12 19:21:47 +01:00
|
|
|
// start boot effect
|
|
|
|
if ( ! effectName.empty() )
|
2016-01-31 22:38:30 +01:00
|
|
|
{
|
2016-03-12 19:21:47 +01:00
|
|
|
int result;
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: Boot sequence '" << effectName << "' ";
|
2016-03-12 19:21:47 +01:00
|
|
|
if (effectConfig.isMember("args"))
|
2014-09-22 20:19:58 +02:00
|
|
|
{
|
2016-03-12 19:21:47 +01:00
|
|
|
std::cout << " (with user defined arguments) ";
|
|
|
|
const Json::Value effectConfigArgs = effectConfig["args"];
|
|
|
|
result = hyperion.setEffect(effectName, effectConfigArgs, priority, duration_ms);
|
2014-09-22 20:19:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-12 19:21:47 +01:00
|
|
|
result = hyperion.setEffect(effectName, priority, duration_ms);
|
2014-09-22 20:19:58 +02:00
|
|
|
}
|
2016-03-12 19:21:47 +01:00
|
|
|
std::cout << ((result == 0) ? "started" : "failed") << std::endl;
|
2013-12-13 19:59:01 +01:00
|
|
|
}
|
2016-03-12 19:21:47 +01:00
|
|
|
|
|
|
|
// static color
|
|
|
|
if ( ! effectConfig["color"].isNull() && effectConfig["color"].isArray() && effectConfig["color"].size() == 3 )
|
2013-12-13 19:59:01 +01:00
|
|
|
{
|
2016-03-12 19:21:47 +01:00
|
|
|
boot_color = {
|
|
|
|
(uint8_t)effectConfig["color"][0].asUInt(),
|
|
|
|
(uint8_t)effectConfig["color"][1].asUInt(),
|
|
|
|
(uint8_t)effectConfig["color"][2].asUInt()
|
|
|
|
};
|
2013-10-16 18:04:43 +02:00
|
|
|
}
|
2016-03-12 19:21:47 +01:00
|
|
|
|
|
|
|
hyperion.setColor(bootcolor_priority, boot_color, 0, false);
|
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
|
|
|
|
|
|
|
// create XBMC video checker if the configuration is present
|
|
|
|
void startXBMCVideoChecker(const Json::Value &config, XBMCVideoChecker* xbmcVideoChecker)
|
|
|
|
{
|
2013-10-13 14:48:59 +02:00
|
|
|
if (config.isMember("xbmcVideoChecker"))
|
|
|
|
{
|
|
|
|
const Json::Value & videoCheckerConfig = config["xbmcVideoChecker"];
|
|
|
|
xbmcVideoChecker = new XBMCVideoChecker(
|
2013-09-24 21:45:27 +02:00
|
|
|
videoCheckerConfig["xbmcAddress"].asString(),
|
|
|
|
videoCheckerConfig["xbmcTcpPort"].asUInt(),
|
|
|
|
videoCheckerConfig["grabVideo"].asBool(),
|
|
|
|
videoCheckerConfig["grabPictures"].asBool(),
|
|
|
|
videoCheckerConfig["grabAudio"].asBool(),
|
2013-12-21 14:32:30 +01:00
|
|
|
videoCheckerConfig["grabMenu"].asBool(),
|
|
|
|
videoCheckerConfig.get("grabScreensaver", true).asBool(),
|
|
|
|
videoCheckerConfig.get("enable3DDetection", true).asBool());
|
2013-10-13 14:48:59 +02:00
|
|
|
|
|
|
|
xbmcVideoChecker->start();
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: Kodi checker created and started" << std::endl;
|
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-05-30 22:38:40 +02:00
|
|
|
void startNetworkServices(const Json::Value &config, Hyperion &hyperion, JsonServer* jsonServer, ProtoServer* protoServer, BoblightServer* boblightServer)
|
|
|
|
{
|
2016-02-16 15:41:40 +01:00
|
|
|
// Create Json server if configuration is present
|
|
|
|
if (config.isMember("jsonServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & jsonServerConfig = config["jsonServer"];
|
|
|
|
jsonServer = new JsonServer(&hyperion, jsonServerConfig["port"].asUInt());
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: Json server created and started on port " << jsonServer->getPort() << std::endl;
|
2016-05-31 22:55:11 +02:00
|
|
|
#ifdef ENABLE_ZEROCONF
|
|
|
|
const Json::Value & deviceConfig = config["device"];
|
|
|
|
const std::string deviceName = deviceConfig.get("name", "").asString();
|
|
|
|
|
|
|
|
const std::string hostname = QHostInfo::localHostName().toStdString();
|
|
|
|
const std::string mDNSDescr = jsonServerConfig.get("mDNSDescr", hostname).asString();
|
|
|
|
const std::string mDNSService = jsonServerConfig.get("mDNSService", "_hyperiond_json._tcp").asString();
|
|
|
|
BonjourServiceRegister *bonjourRegister_json;
|
|
|
|
bonjourRegister_json = new BonjourServiceRegister();
|
|
|
|
bonjourRegister_json->registerService(BonjourRecord((deviceName + " @ " + mDNSDescr).c_str(), mDNSService.c_str(),
|
|
|
|
QString()), jsonServerConfig["port"].asUInt());
|
|
|
|
std::cout << "INFO: Json mDNS responder started" << std::endl;
|
|
|
|
#endif
|
2016-02-16 15:41:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create Proto server if configuration is present
|
|
|
|
if (config.isMember("protoServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & protoServerConfig = config["protoServer"];
|
|
|
|
protoServer = new ProtoServer(&hyperion, protoServerConfig["port"].asUInt() );
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: Proto server created and started on port " << protoServer->getPort() << std::endl;
|
2016-05-31 22:55:11 +02:00
|
|
|
#ifdef ENABLE_ZEROCONF
|
|
|
|
const Json::Value & deviceConfig = config["device"];
|
|
|
|
const std::string deviceName = deviceConfig.get("name", "").asString();
|
|
|
|
|
|
|
|
const std::string hostname = QHostInfo::localHostName().toStdString();
|
|
|
|
const std::string mDNSDescr = protoServerConfig.get("mDNSDescr", hostname).asString();
|
|
|
|
const std::string mDNSService = protoServerConfig.get("mDNSService", "_hyperiond_proto._tcp").asString();
|
|
|
|
BonjourServiceRegister *bonjourRegister_proto;
|
|
|
|
bonjourRegister_proto = new BonjourServiceRegister();
|
|
|
|
bonjourRegister_proto->registerService(BonjourRecord((deviceName + " @ " + mDNSDescr).c_str(), mDNSService.c_str(),
|
|
|
|
QString()), protoServerConfig["port"].asUInt());
|
|
|
|
std::cout << "INFO: Proto mDNS responder started" << std::endl;
|
|
|
|
#endif
|
2016-02-16 15:41:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create Boblight server if configuration is present
|
|
|
|
if (config.isMember("boblightServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & boblightServerConfig = config["boblightServer"];
|
2016-03-08 17:31:56 +01:00
|
|
|
boblightServer = new BoblightServer(&hyperion, boblightServerConfig.get("priority",900).asInt(), boblightServerConfig["port"].asUInt());
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: Boblight server created and started on port " << boblightServer->getPort() << std::endl;
|
2016-02-16 15:41:40 +01:00
|
|
|
}
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2016-02-16 15:41:40 +01:00
|
|
|
|
2013-11-19 23:02:41 +01:00
|
|
|
#ifdef ENABLE_DISPMANX
|
2016-05-30 22:38:40 +02:00
|
|
|
void startGrabberDispmanx(const Json::Value &config, Hyperion &hyperion, ProtoServer * protoServer, XBMCVideoChecker* xbmcVideoChecker, DispmanxWrapper * dispmanx)
|
|
|
|
{
|
2013-10-13 14:48:59 +02:00
|
|
|
// Construct and start the frame-grabber if the configuration is present
|
|
|
|
if (config.isMember("framegrabber"))
|
|
|
|
{
|
|
|
|
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-03-08 17:31:56 +01:00
|
|
|
frameGrabberConfig.get("priority",900).asInt(),
|
2013-08-25 18:20:19 +02:00
|
|
|
&hyperion);
|
2016-05-18 11:26:25 +02:00
|
|
|
dispmanx->setCropping(
|
|
|
|
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
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
if (xbmcVideoChecker != nullptr)
|
|
|
|
{
|
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), dispmanx, SLOT(setGrabbingMode(GrabbingMode)));
|
2013-12-21 14:32:30 +01:00
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(videoMode(VideoMode)), dispmanx, SLOT(setVideoMode(VideoMode)));
|
2013-10-13 14:48:59 +02:00
|
|
|
}
|
|
|
|
|
2016-02-17 00:44:06 +01:00
|
|
|
QObject::connect(dispmanx, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
dispmanx->start();
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: Frame grabber created and started" << std::endl;
|
2013-10-13 14:48:59 +02:00
|
|
|
}
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2015-01-18 00:04:45 +01:00
|
|
|
#endif
|
2013-10-13 14:48:59 +02:00
|
|
|
|
2014-02-21 22:30:34 +01:00
|
|
|
#ifdef ENABLE_V4L2
|
2016-05-30 22:38:40 +02:00
|
|
|
void startGrabberV4L2(const Json::Value &config, Hyperion &hyperion, ProtoServer * protoServer, V4L2Wrapper * v4l2Grabber )
|
|
|
|
{
|
2014-02-21 22:30:34 +01:00
|
|
|
// construct and start the v4l2 grabber if the configuration is present
|
|
|
|
if (config.isMember("grabber-v4l2"))
|
|
|
|
{
|
|
|
|
const Json::Value & grabberConfig = config["grabber-v4l2"];
|
2014-02-23 22:39:23 +01:00
|
|
|
v4l2Grabber = new V4L2Wrapper(
|
2014-02-21 22:30:34 +01:00
|
|
|
grabberConfig.get("device", "/dev/video0").asString(),
|
|
|
|
grabberConfig.get("input", 0).asInt(),
|
2014-02-23 22:39:23 +01:00
|
|
|
parseVideoStandard(grabberConfig.get("standard", "no-change").asString()),
|
2014-03-31 17:36:36 +02:00
|
|
|
parsePixelFormat(grabberConfig.get("pixelFormat", "no-change").asString()),
|
2014-02-21 22:30:34 +01:00
|
|
|
grabberConfig.get("width", -1).asInt(),
|
|
|
|
grabberConfig.get("height", -1).asInt(),
|
|
|
|
grabberConfig.get("frameDecimation", 2).asInt(),
|
|
|
|
grabberConfig.get("sizeDecimation", 8).asInt(),
|
2014-03-04 22:04:15 +01:00
|
|
|
grabberConfig.get("redSignalThreshold", 0.0).asDouble(),
|
|
|
|
grabberConfig.get("greenSignalThreshold", 0.0).asDouble(),
|
|
|
|
grabberConfig.get("blueSignalThreshold", 0.0).asDouble(),
|
2014-02-23 22:39:23 +01:00
|
|
|
&hyperion,
|
2016-03-08 17:31:56 +01:00
|
|
|
grabberConfig.get("priority", 900).asInt());
|
2014-02-23 21:36:39 +01:00
|
|
|
v4l2Grabber->set3D(parse3DMode(grabberConfig.get("mode", "2D").asString()));
|
2014-02-21 22:30:34 +01:00
|
|
|
v4l2Grabber->setCropping(
|
|
|
|
grabberConfig.get("cropLeft", 0).asInt(),
|
|
|
|
grabberConfig.get("cropRight", 0).asInt(),
|
|
|
|
grabberConfig.get("cropTop", 0).asInt(),
|
|
|
|
grabberConfig.get("cropBottom", 0).asInt());
|
|
|
|
|
2016-02-16 15:41:40 +01:00
|
|
|
QObject::connect(v4l2Grabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
|
|
|
|
2014-02-21 22:30:34 +01:00
|
|
|
v4l2Grabber->start();
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: V4L2 grabber created and started" << std::endl;
|
2014-02-21 22:30:34 +01:00
|
|
|
}
|
2016-02-16 15:41:40 +01:00
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2014-02-21 22:30:34 +01:00
|
|
|
#endif
|
2015-08-20 09:51:44 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_AMLOGIC
|
2016-05-30 22:38:40 +02:00
|
|
|
void startGrabberAmlogic(const Json::Value &config, Hyperion &hyperion, ProtoServer * protoServer, XBMCVideoChecker* xbmcVideoChecker, AmlogicWrapper * amlGrabber)
|
|
|
|
{
|
2015-08-20 09:51:44 +02:00
|
|
|
// Construct and start the framebuffer grabber if the configuration is present
|
|
|
|
if (config.isMember("amlgrabber"))
|
|
|
|
{
|
|
|
|
const Json::Value & grabberConfig = config["amlgrabber"];
|
|
|
|
amlGrabber = new AmlogicWrapper(
|
|
|
|
grabberConfig["width"].asUInt(),
|
|
|
|
grabberConfig["height"].asUInt(),
|
|
|
|
grabberConfig["frequency_Hz"].asUInt(),
|
2016-03-08 17:31:56 +01:00
|
|
|
grabberConfig.get("priority",900).asInt(),
|
2015-08-20 09:51:44 +02:00
|
|
|
&hyperion);
|
|
|
|
|
|
|
|
if (xbmcVideoChecker != nullptr)
|
|
|
|
{
|
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), amlGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(videoMode(VideoMode)), amlGrabber, SLOT(setVideoMode(VideoMode)));
|
|
|
|
}
|
|
|
|
|
2016-02-24 14:42:25 +01:00
|
|
|
QObject::connect(amlGrabber, 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
|
|
|
amlGrabber->start();
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: AMLOGIC grabber created and started" << std::endl;
|
2015-08-20 09:51:44 +02:00
|
|
|
}
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2015-08-20 09:51:44 +02:00
|
|
|
#endif
|
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
|
2015-01-18 00:04:45 +01:00
|
|
|
#ifdef ENABLE_FB
|
2016-05-30 22:38:40 +02:00
|
|
|
void startGrabberFramebuffer(const Json::Value &config, Hyperion &hyperion, ProtoServer * protoServer, XBMCVideoChecker* xbmcVideoChecker, FramebufferWrapper * fbGrabber)
|
|
|
|
{
|
2015-01-18 00:04:45 +01:00
|
|
|
// Construct and start the framebuffer grabber if the configuration is present
|
2015-08-20 10:14:19 +02:00
|
|
|
if (config.isMember("framebuffergrabber") || config.isMember("framegrabber"))
|
2015-01-18 00:04:45 +01:00
|
|
|
{
|
2015-09-03 21:37:49 +02:00
|
|
|
const Json::Value & grabberConfig = config.isMember("framebuffergrabber")? config["framebuffergrabber"] : config["framegrabber"];
|
2015-01-18 00:04:45 +01:00
|
|
|
fbGrabber = new FramebufferWrapper(
|
|
|
|
grabberConfig.get("device", "/dev/fb0").asString(),
|
|
|
|
grabberConfig["width"].asUInt(),
|
|
|
|
grabberConfig["height"].asUInt(),
|
|
|
|
grabberConfig["frequency_Hz"].asUInt(),
|
2016-03-08 17:31:56 +01:00
|
|
|
grabberConfig.get("priority",900).asInt(),
|
2015-01-18 00:04:45 +01:00
|
|
|
&hyperion);
|
|
|
|
|
|
|
|
if (xbmcVideoChecker != nullptr)
|
|
|
|
{
|
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), fbGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(videoMode(VideoMode)), fbGrabber, SLOT(setVideoMode(VideoMode)));
|
|
|
|
}
|
|
|
|
|
2016-02-17 00:44:06 +01:00
|
|
|
QObject::connect(fbGrabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)) );
|
|
|
|
|
2015-01-18 00:04:45 +01:00
|
|
|
fbGrabber->start();
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: Framebuffer grabber created and started" << std::endl;
|
2015-01-18 00:04:45 +01:00
|
|
|
}
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
2015-01-18 00:04:45 +01:00
|
|
|
#endif
|
2015-08-20 09:51:44 +02:00
|
|
|
|
2016-05-30 22:38:40 +02:00
|
|
|
|
2015-01-24 23:42:22 +01:00
|
|
|
#ifdef ENABLE_OSX
|
2016-05-30 22:38:40 +02:00
|
|
|
void startGrabberOsx(const Json::Value &config, Hyperion &hyperion, ProtoServer * protoServer, XBMCVideoChecker* xbmcVideoChecker, OsxWrapper * osxGrabber)
|
|
|
|
{
|
2015-08-20 09:51:44 +02:00
|
|
|
// Construct and start the osx grabber if the configuration is present
|
2015-08-20 10:14:19 +02:00
|
|
|
if (config.isMember("osxgrabber") || config.isMember("framegrabber"))
|
2015-08-20 09:51:44 +02:00
|
|
|
{
|
2015-08-20 10:14:19 +02:00
|
|
|
const Json::Value & grabberConfig = config.isMember("osxgrabber")? config["osxgrabber"] : config["framegrabber"];
|
2015-08-20 09:51:44 +02:00
|
|
|
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(),
|
|
|
|
grabberConfig.get("priority",900).asInt(),
|
|
|
|
&hyperion );
|
2015-08-20 09:51:44 +02:00
|
|
|
|
|
|
|
if (xbmcVideoChecker != nullptr)
|
|
|
|
{
|
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), osxGrabber, SLOT(setGrabbingMode(GrabbingMode)));
|
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(videoMode(VideoMode)), osxGrabber, SLOT(setVideoMode(VideoMode)));
|
|
|
|
}
|
2016-02-17 00:44:06 +01: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
|
|
|
|
|
|
|
osxGrabber->start();
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: OSX grabber created and started" << std::endl;
|
2015-08-20 09:51:44 +02:00
|
|
|
}
|
2016-05-30 22:38:40 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
std::cout
|
|
|
|
<< "Hyperion Ambilight Deamon (" << getpid() << ")" << std::endl
|
|
|
|
<< "\tVersion : " << HYPERION_VERSION_ID << std::endl
|
|
|
|
<< "\tBuild Time: " << __DATE__ << " " << __TIME__ << std::endl;
|
|
|
|
|
|
|
|
// Initialising QCoreApplication
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
signal(SIGCHLD, signal_handler);
|
|
|
|
|
|
|
|
// force the locale
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
QLocale::setDefault(QLocale::c());
|
|
|
|
|
|
|
|
OptionsParser optionParser("X11 capture application for Hyperion");
|
|
|
|
ParameterSet & parameters = optionParser.getParameters();
|
|
|
|
|
|
|
|
IntParameter & argParentPid = parameters.add<IntParameter> (0x0, "parent", "pid of parent hyperiond");
|
|
|
|
|
|
|
|
argParentPid.setDefault(0);
|
|
|
|
optionParser.parse(argc, const_cast<const char **>(argv));
|
|
|
|
const std::vector<std::string> configFiles = optionParser.getFiles();
|
|
|
|
|
|
|
|
if (configFiles.size() == 0)
|
|
|
|
{
|
|
|
|
std::cout << "ERROR: Missing required configuration file. Usage:" << std::endl;
|
|
|
|
std::cout << "hyperiond <options ...> [config.file ...]" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argParentPid.getValue() > 0 )
|
|
|
|
{
|
|
|
|
std::cout << "hyperiond client, parent is pid " << argParentPid.getValue() << std::endl;
|
|
|
|
prctl(PR_SET_PDEATHSIG, SIGHUP);
|
|
|
|
}
|
|
|
|
|
|
|
|
int argvId = -1;
|
|
|
|
for(size_t idx=0; idx < configFiles.size(); idx++) {
|
|
|
|
if ( QFile::exists(configFiles[idx].c_str()))
|
|
|
|
{
|
|
|
|
if (argvId < 0) argvId=idx;
|
|
|
|
else startNewHyperion(getpid(), argv[0], configFiles[idx].c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( argvId < 0)
|
|
|
|
{
|
|
|
|
std::cout << "ERROR: No valid config found " << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string configFile = configFiles[argvId];
|
|
|
|
std::cout << "INFO: Selected configuration file: " << configFile.c_str() << std::endl;
|
|
|
|
const Json::Value config = loadConfig(configFile);
|
|
|
|
|
|
|
|
Hyperion hyperion(config);
|
|
|
|
std::cout << "INFO: Hyperion started and initialised" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
startBootsequence(config, hyperion);
|
|
|
|
|
|
|
|
XBMCVideoChecker * xbmcVideoChecker = nullptr;
|
|
|
|
startXBMCVideoChecker(config, xbmcVideoChecker);
|
|
|
|
|
|
|
|
// ---- network services -----
|
|
|
|
JsonServer * jsonServer = nullptr;
|
|
|
|
ProtoServer * protoServer = nullptr;
|
|
|
|
BoblightServer * boblightServer = nullptr;
|
|
|
|
startNetworkServices(config, hyperion, jsonServer, protoServer, boblightServer);
|
|
|
|
|
|
|
|
|
|
|
|
// ---- grabber -----
|
|
|
|
|
|
|
|
#ifdef ENABLE_DISPMANX
|
|
|
|
DispmanxWrapper * dispmanx = nullptr;
|
|
|
|
startGrabberDispmanx(config, hyperion, protoServer, xbmcVideoChecker, dispmanx);
|
|
|
|
#else
|
|
|
|
#if !defined(ENABLE_OSX) && !defined(ENABLE_FB)
|
|
|
|
if (config.isMember("framegrabber"))
|
|
|
|
{
|
|
|
|
std::cerr << "ERRROR: The dispmanx framegrabber can not be instantiated, because it has been left out from the build" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_V4L2
|
|
|
|
V4L2Wrapper * v4l2Grabber = nullptr;
|
|
|
|
startGrabberV4L2(config, hyperion, protoServer, v4l2Grabber);
|
|
|
|
#else
|
|
|
|
if (config.isMember("grabber-v4l2"))
|
|
|
|
{
|
|
|
|
std::cerr << "ERROR: The v4l2 grabber can not be instantiated, because it has been left out from the build" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_AMLOGIC
|
|
|
|
// Construct and start the framebuffer grabber if the configuration is present
|
|
|
|
AmlogicWrapper * amlGrabber = nullptr;
|
|
|
|
startGrabberAmlogic(config, hyperion, protoServer, xbmcVideoChecker, amlGrabber);
|
|
|
|
#else
|
|
|
|
if (config.isMember("amlgrabber"))
|
|
|
|
{
|
|
|
|
std::cerr << "ERROR: The AMLOGIC grabber can not be instantiated, because it has been left out from the build" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_FB
|
|
|
|
// Construct and start the framebuffer grabber if the configuration is present
|
|
|
|
FramebufferWrapper * fbGrabber = nullptr;
|
|
|
|
startGrabberFramebuffer(config, hyperion, protoServer, xbmcVideoChecker, fbGrabber);
|
|
|
|
#else
|
|
|
|
if (config.isMember("framebuffergrabber"))
|
|
|
|
{
|
|
|
|
std::cerr << "ERROR: The framebuffer grabber can not be instantiated, because it has been left out from the build" << std::endl;
|
|
|
|
}
|
|
|
|
#if !defined(ENABLE_DISPMANX) && !defined(ENABLE_OSX)
|
|
|
|
else if (config.isMember("framegrabber"))
|
|
|
|
{
|
|
|
|
std::cerr << "ERROR: The framebuffer grabber can not be instantiated, because it has been left out from the build" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_OSX
|
|
|
|
// Construct and start the osx grabber if the configuration is present
|
|
|
|
OsxWrapper * osxGrabber = nullptr;
|
|
|
|
startGrabberDispmanx(config, hyperion, protoServer, xbmcVideoChecker, osxGrabber);
|
2015-01-24 23:42:22 +01:00
|
|
|
#else
|
2015-08-20 10:14:19 +02:00
|
|
|
if (config.isMember("osxgrabber"))
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cerr << "ERROR: The osx grabber can not be instantiated, because it has been left out from the build" << std::endl;
|
2015-08-20 10:14:19 +02:00
|
|
|
}
|
2015-01-24 23:42:22 +01:00
|
|
|
#if !defined(ENABLE_DISPMANX) && !defined(ENABLE_FB)
|
2015-08-20 10:14:19 +02:00
|
|
|
else if (config.isMember("framegrabber"))
|
2015-08-20 09:51:44 +02:00
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cerr << "ERROR: The osx grabber can not be instantiated, because it has been left out from the build" << std::endl;
|
2015-08-20 09:51:44 +02:00
|
|
|
}
|
2015-01-24 23:42:22 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2014-02-21 22:30:34 +01:00
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
// run the application
|
|
|
|
int rc = app.exec();
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "INFO: Application closed with code " << rc << std::endl;
|
2013-08-25 18:20:19 +02:00
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// Delete all component
|
2013-11-19 23:02:41 +01:00
|
|
|
#ifdef ENABLE_DISPMANX
|
2013-10-13 14:48:59 +02:00
|
|
|
delete dispmanx;
|
2014-02-21 22:30:34 +01:00
|
|
|
#endif
|
2015-01-18 00:04:45 +01:00
|
|
|
#ifdef ENABLE_FB
|
|
|
|
delete fbGrabber;
|
|
|
|
#endif
|
2015-01-24 23:42:22 +01:00
|
|
|
#ifdef ENABLE_OSX
|
2015-08-20 09:51:44 +02:00
|
|
|
delete osxGrabber;
|
2015-01-24 23:42:22 +01:00
|
|
|
#endif
|
2014-02-21 22:30:34 +01:00
|
|
|
#ifdef ENABLE_V4L2
|
|
|
|
delete v4l2Grabber;
|
2013-11-19 23:02:41 +01:00
|
|
|
#endif
|
2013-10-13 14:48:59 +02:00
|
|
|
delete xbmcVideoChecker;
|
|
|
|
delete jsonServer;
|
|
|
|
delete protoServer;
|
2013-11-24 16:10:48 +01:00
|
|
|
delete boblightServer;
|
2013-10-13 14:48:59 +02:00
|
|
|
|
|
|
|
// leave application
|
2013-08-24 11:51:52 +02:00
|
|
|
return rc;
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|