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>
|
2014-01-28 00:39:04 +01:00
|
|
|
#include <clocale>
|
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>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
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
|
|
|
|
|
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>
|
|
|
|
|
2013-08-17 15:39:29 +02:00
|
|
|
// JsonServer includes
|
|
|
|
#include <jsonserver/JsonServer.h>
|
|
|
|
|
2014-09-08 16:16:02 +02:00
|
|
|
#ifdef ENABLE_PROTOBUF
|
2013-10-13 14:48:59 +02:00
|
|
|
// ProtoServer includes
|
|
|
|
#include <protoserver/ProtoServer.h>
|
2014-09-08 16:16:02 +02:00
|
|
|
#endif
|
2013-10-13 14:48:59 +02:00
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
// BoblightServer includes
|
|
|
|
#include <boblightserver/BoblightServer.h>
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Schema error: " + jsonReader.getFormattedErrorMessages()) ;
|
|
|
|
}
|
|
|
|
JsonSchemaChecker schemaChecker;
|
|
|
|
schemaChecker.setSchema(schemaJson);
|
|
|
|
|
|
|
|
const Json::Value jsonConfig = JsonFactory::readJson(configFile);
|
|
|
|
schemaChecker.validate(jsonConfig);
|
|
|
|
|
|
|
|
return jsonConfig;
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2013-10-21 20:29:30 +02:00
|
|
|
std::cout << "Application build time: " << __DATE__ << " " << __TIME__ << std::endl;
|
|
|
|
|
2013-08-15 21:11:02 +02:00
|
|
|
// Initialising QCoreApplication
|
2013-08-13 11:10:45 +02:00
|
|
|
QCoreApplication app(argc, argv);
|
2013-08-15 21:11:02 +02:00
|
|
|
std::cout << "QCoreApplication initialised" << std::endl;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-22 22:06:13 +02:00
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
|
2014-01-28 22:27:02 +01:00
|
|
|
// force the locale
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
QLocale::setDefault(QLocale::c());
|
|
|
|
|
2013-08-21 16:25:27 +02:00
|
|
|
if (argc < 2)
|
2013-08-14 10:54:49 +02:00
|
|
|
{
|
2013-08-21 16:25:27 +02:00
|
|
|
std::cout << "Missing required configuration file. Usage:" << std::endl;
|
|
|
|
std::cout << "hyperiond [config.file]" << std::endl;
|
2013-10-10 09:51:18 +02:00
|
|
|
return 1;
|
2013-08-14 10:54:49 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 07:57:46 +02:00
|
|
|
const std::string configFile = argv[1];
|
2013-08-21 16:25:27 +02:00
|
|
|
std::cout << "Selected configuration file: " << configFile.c_str() << std::endl;
|
2013-08-24 11:51:52 +02:00
|
|
|
const Json::Value config = loadConfig(configFile);
|
2013-08-21 16:25:27 +02:00
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
Hyperion hyperion(config);
|
2013-08-15 21:11:02 +02:00
|
|
|
std::cout << "Hyperion created and initialised" << std::endl;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
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();
|
|
|
|
const int priority = 0;
|
2014-05-06 18:36:34 +02:00
|
|
|
|
|
|
|
if (effectConfig.isMember("args"))
|
2013-10-16 18:04:43 +02:00
|
|
|
{
|
2014-05-06 18:36:34 +02:00
|
|
|
const Json::Value effectConfigArgs = effectConfig["args"];
|
|
|
|
if (hyperion.setEffect(effectName, effectConfigArgs, priority, duration_ms) == 0)
|
|
|
|
{
|
|
|
|
std::cout << "Boot sequence(" << effectName << ") with user-defined arguments created and started" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "Failed to start boot sequence: " << effectName << " with user-defined arguments" << std::endl;
|
|
|
|
}
|
|
|
|
|
2013-12-13 19:59:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-06 18:36:34 +02:00
|
|
|
|
|
|
|
if (hyperion.setEffect(effectName, priority, duration_ms) == 0)
|
|
|
|
{
|
|
|
|
std::cout << "Boot sequence(" << effectName << ") created and started" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "Failed to start boot sequence: " << effectName << std::endl;
|
|
|
|
}
|
2013-10-16 18:04:43 +02:00
|
|
|
}
|
2013-08-25 18:20:19 +02:00
|
|
|
}
|
2013-08-23 18:24:10 +02:00
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// create XBMC video checker if the configuration is present
|
|
|
|
XBMCVideoChecker * xbmcVideoChecker = nullptr;
|
|
|
|
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();
|
2013-08-24 11:51:52 +02:00
|
|
|
std::cout << "XBMC video checker created and started" << std::endl;
|
|
|
|
}
|
2013-08-23 20:44:53 +02:00
|
|
|
|
2013-11-19 23:02:41 +01:00
|
|
|
#ifdef ENABLE_DISPMANX
|
2013-10-13 14:48:59 +02:00
|
|
|
// Construct and start the frame-grabber if the configuration is present
|
|
|
|
DispmanxWrapper * dispmanx = nullptr;
|
|
|
|
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(),
|
|
|
|
&hyperion);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
dispmanx->start();
|
|
|
|
std::cout << "Frame grabber created and started" << std::endl;
|
|
|
|
}
|
2013-11-19 23:02:41 +01:00
|
|
|
#else
|
|
|
|
if (config.isMember("framegrabber"))
|
|
|
|
{
|
|
|
|
std::cerr << "The dispmanx framegrabber can not be instantiated, becuse it has been left out from the build" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
2013-10-13 14:48:59 +02:00
|
|
|
|
2014-02-21 22:30:34 +01:00
|
|
|
#ifdef ENABLE_V4L2
|
|
|
|
// construct and start the v4l2 grabber if the configuration is present
|
2014-02-23 22:39:23 +01:00
|
|
|
V4L2Wrapper * v4l2Grabber = nullptr;
|
2014-02-21 22:30:34 +01:00
|
|
|
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,
|
|
|
|
grabberConfig.get("priority", 800).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());
|
|
|
|
|
|
|
|
v4l2Grabber->start();
|
|
|
|
std::cout << "V4l2 grabber created and started" << std::endl;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (config.isMember("grabber-v4l2"))
|
|
|
|
{
|
|
|
|
std::cerr << "The v4l2 grabber can not be instantiated, becuse it has been left out from the build" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// Create Json server if configuration is present
|
|
|
|
JsonServer * jsonServer = nullptr;
|
|
|
|
if (config.isMember("jsonServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & jsonServerConfig = config["jsonServer"];
|
|
|
|
jsonServer = new JsonServer(&hyperion, jsonServerConfig["port"].asUInt());
|
|
|
|
std::cout << "Json server created and started on port " << jsonServer->getPort() << std::endl;
|
|
|
|
}
|
|
|
|
|
2014-09-08 16:16:02 +02:00
|
|
|
#ifdef ENABLE_PROTOBUF
|
2013-10-13 14:48:59 +02:00
|
|
|
// Create Proto server if configuration is present
|
|
|
|
ProtoServer * protoServer = nullptr;
|
|
|
|
if (config.isMember("protoServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & protoServerConfig = config["protoServer"];
|
|
|
|
protoServer = new ProtoServer(&hyperion, protoServerConfig["port"].asUInt());
|
|
|
|
std::cout << "Proto server created and started on port " << protoServer->getPort() << std::endl;
|
|
|
|
}
|
2014-09-08 16:16:02 +02:00
|
|
|
#endif
|
2013-08-17 15:39:29 +02:00
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
// Create Boblight server if configuration is present
|
|
|
|
BoblightServer * boblightServer = nullptr;
|
|
|
|
if (config.isMember("boblightServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & boblightServerConfig = config["boblightServer"];
|
|
|
|
boblightServer = new BoblightServer(&hyperion, boblightServerConfig["port"].asUInt());
|
|
|
|
std::cout << "Boblight server created and started on port " << boblightServer->getPort() << std::endl;
|
|
|
|
}
|
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
// run the application
|
|
|
|
int rc = app.exec();
|
2013-10-16 23:19:40 +02:00
|
|
|
std::cout << "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
|
|
|
|
#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;
|
2014-09-08 16:16:02 +02:00
|
|
|
#ifdef ENABLE_PROTOBUF
|
2013-10-13 14:48:59 +02:00
|
|
|
delete protoServer;
|
2014-09-08 16:16:02 +02:00
|
|
|
#endif
|
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
|
|
|
}
|