2016-09-07 20:10:37 +02:00
|
|
|
#include <hyperion/ComponentRegister.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <hyperion/Hyperion.h>
|
|
|
|
|
2022-01-07 14:47:51 +01:00
|
|
|
#include <hyperion/GrabberWrapper.h>
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
using namespace hyperion;
|
|
|
|
|
|
|
|
ComponentRegister::ComponentRegister(Hyperion* hyperion)
|
|
|
|
: _hyperion(hyperion)
|
2022-01-22 17:48:03 +01:00
|
|
|
, _log(nullptr)
|
2016-09-07 20:10:37 +02:00
|
|
|
{
|
2022-01-22 17:48:03 +01:00
|
|
|
QString subComponent = hyperion->property("instance").toString();
|
|
|
|
_log= Logger::getInstance("COMPONENTREG", subComponent);
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// init all comps to false
|
|
|
|
QVector<hyperion::Components> vect;
|
2022-01-07 14:47:51 +01:00
|
|
|
vect << COMP_ALL << COMP_SMOOTHING << COMP_LEDDEVICE;
|
|
|
|
|
|
|
|
bool areScreenGrabberAvailable = !GrabberWrapper::availableGrabbers(GrabberTypeFilter::VIDEO).isEmpty();
|
|
|
|
bool areVideoGrabberAvailable = !GrabberWrapper::availableGrabbers(GrabberTypeFilter::VIDEO).isEmpty();
|
|
|
|
bool flatBufServerAvailable { false };
|
|
|
|
bool protoBufServerAvailable{ false };
|
|
|
|
|
|
|
|
#if defined(ENABLE_FLATBUF_SERVER)
|
|
|
|
flatBufServerAvailable = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ENABLE_PROTOBUF_SERVER)
|
|
|
|
protoBufServerAvailable = true;
|
|
|
|
#endif
|
2021-09-15 10:32:19 +02:00
|
|
|
|
2022-01-07 14:47:51 +01:00
|
|
|
if (areScreenGrabberAvailable)
|
|
|
|
{
|
|
|
|
vect << COMP_GRABBER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (areVideoGrabberAvailable)
|
|
|
|
{
|
|
|
|
vect << COMP_V4L;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (areScreenGrabberAvailable || areVideoGrabberAvailable || flatBufServerAvailable || protoBufServerAvailable)
|
|
|
|
{
|
|
|
|
vect << COMP_BLACKBORDER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_BOBLIGHT_SERVER)
|
2021-09-15 10:32:19 +02:00
|
|
|
vect << COMP_BOBLIGHTSERVER;
|
|
|
|
#endif
|
|
|
|
|
2022-01-07 14:47:51 +01:00
|
|
|
#if defined(ENABLE_FORWARDER)
|
|
|
|
vect << COMP_FORWARDER;
|
|
|
|
#endif
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
for(auto e : vect)
|
|
|
|
{
|
2020-11-14 17:58:56 +01:00
|
|
|
_componentStates.emplace(e, (e == COMP_ALL));
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
|
2020-02-26 18:54:56 +01:00
|
|
|
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &ComponentRegister::handleCompStateChangeRequest);
|
2016-09-07 20:10:37 +02:00
|
|
|
}
|
|
|
|
|
2020-02-26 18:54:56 +01:00
|
|
|
ComponentRegister::~ComponentRegister()
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
int ComponentRegister::isComponentEnabled(hyperion::Components comp) const
|
2016-09-07 20:10:37 +02:00
|
|
|
{
|
2018-12-28 18:12:45 +01:00
|
|
|
return (_componentStates.count(comp)) ? _componentStates.at(comp) : -1;
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
void ComponentRegister::setNewComponentState(hyperion::Components comp, bool activated)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
2022-01-07 14:47:51 +01:00
|
|
|
|
|
|
|
if (_componentStates.count(comp) > 0)
|
2016-09-07 20:10:37 +02:00
|
|
|
{
|
2022-01-07 14:47:51 +01:00
|
|
|
if (_componentStates[comp] != activated)
|
|
|
|
{
|
|
|
|
Debug(_log, "%s: %s", componentToString(comp), (activated ? "enabled" : "disabled"));
|
|
|
|
_componentStates[comp] = activated;
|
|
|
|
// emit component has changed state
|
|
|
|
emit updatedComponentState(comp, activated);
|
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-26 18:54:56 +01:00
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
void ComponentRegister::handleCompStateChangeRequest(hyperion::Components comps, bool activated)
|
2020-02-26 18:54:56 +01:00
|
|
|
{
|
2020-05-25 21:51:11 +02:00
|
|
|
if(comps == COMP_ALL && !_inProgress)
|
2020-02-26 18:54:56 +01:00
|
|
|
{
|
|
|
|
_inProgress = true;
|
|
|
|
if(!activated && _prevComponentStates.empty())
|
|
|
|
{
|
|
|
|
Debug(_log,"Disable Hyperion, store current component states");
|
2020-11-14 17:58:56 +01:00
|
|
|
for(const auto &comp : _componentStates)
|
2020-02-26 18:54:56 +01:00
|
|
|
{
|
|
|
|
// save state
|
|
|
|
_prevComponentStates.emplace(comp.first, comp.second);
|
|
|
|
// disable if enabled
|
|
|
|
if(comp.second)
|
2020-11-14 17:58:56 +01:00
|
|
|
{
|
2020-02-26 18:54:56 +01:00
|
|
|
emit _hyperion->compStateChangeRequest(comp.first, false);
|
2020-11-14 17:58:56 +01:00
|
|
|
}
|
2020-02-26 18:54:56 +01:00
|
|
|
}
|
|
|
|
setNewComponentState(COMP_ALL, false);
|
|
|
|
}
|
2020-11-14 17:58:56 +01:00
|
|
|
else
|
2020-02-26 18:54:56 +01:00
|
|
|
{
|
2020-11-14 17:58:56 +01:00
|
|
|
if(activated && !_prevComponentStates.empty())
|
2020-02-26 18:54:56 +01:00
|
|
|
{
|
2020-11-14 17:58:56 +01:00
|
|
|
Debug(_log,"Enable Hyperion, recover previous component states");
|
|
|
|
for(const auto &comp : _prevComponentStates)
|
|
|
|
{
|
|
|
|
// if comp was enabled, enable again
|
|
|
|
if(comp.second)
|
|
|
|
{
|
|
|
|
emit _hyperion->compStateChangeRequest(comp.first, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_prevComponentStates.clear();
|
|
|
|
setNewComponentState(COMP_ALL, true);
|
2020-02-26 18:54:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_inProgress = false;
|
|
|
|
}
|
2020-03-05 18:29:10 +01:00
|
|
|
}
|