2018-12-27 23:11:32 +01:00
|
|
|
#include <hyperion/CaptureCont.h>
|
|
|
|
|
2019-01-01 19:47:07 +01:00
|
|
|
// hyperion includes
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <hyperion/Hyperion.h>
|
2019-01-01 19:47:07 +01:00
|
|
|
|
|
|
|
// utils includes
|
|
|
|
#include <utils/GlobalSignals.h>
|
|
|
|
|
|
|
|
// qt includes
|
2018-12-28 18:12:45 +01:00
|
|
|
#include <QTimer>
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
CaptureCont::CaptureCont(Hyperion* hyperion)
|
|
|
|
: QObject()
|
|
|
|
, _hyperion(hyperion)
|
|
|
|
, _systemCaptEnabled(false)
|
2018-12-31 15:48:29 +01:00
|
|
|
, _systemInactiveTimer(new QTimer(this))
|
2018-12-27 23:11:32 +01:00
|
|
|
, _v4lCaptEnabled(false)
|
2018-12-28 18:12:45 +01:00
|
|
|
, _v4lInactiveTimer(new QTimer(this))
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
|
|
|
// settings changes
|
|
|
|
connect(_hyperion, &Hyperion::settingsChanged, this, &CaptureCont::handleSettingsUpdate);
|
|
|
|
|
|
|
|
// comp changes
|
|
|
|
connect(_hyperion, &Hyperion::componentStateChanged, this, &CaptureCont::componentStateChanged);
|
|
|
|
|
2018-12-31 15:48:29 +01:00
|
|
|
// inactive timer system
|
|
|
|
connect(_systemInactiveTimer, &QTimer::timeout, this, &CaptureCont::setSystemInactive);
|
|
|
|
_systemInactiveTimer->setSingleShot(true);
|
|
|
|
_systemInactiveTimer->setInterval(5000);
|
|
|
|
|
2018-12-28 18:12:45 +01:00
|
|
|
// inactive timer v4l
|
|
|
|
connect(_v4lInactiveTimer, &QTimer::timeout, this, &CaptureCont::setV4lInactive);
|
|
|
|
_v4lInactiveTimer->setSingleShot(true);
|
|
|
|
_v4lInactiveTimer->setInterval(1000);
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// init
|
|
|
|
handleSettingsUpdate(settings::INSTCAPTURE, _hyperion->getSetting(settings::INSTCAPTURE));
|
|
|
|
}
|
|
|
|
|
|
|
|
CaptureCont::~CaptureCont()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaptureCont::handleV4lImage(const Image<ColorRgb> & image)
|
|
|
|
{
|
2018-12-28 18:12:45 +01:00
|
|
|
_v4lInactiveTimer->start();
|
2018-12-27 23:11:32 +01:00
|
|
|
_hyperion->setInputImage(_v4lCaptPrio, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaptureCont::handleSystemImage(const Image<ColorRgb>& image)
|
|
|
|
{
|
2018-12-31 15:48:29 +01:00
|
|
|
_systemInactiveTimer->start();
|
2018-12-27 23:11:32 +01:00
|
|
|
_hyperion->setInputImage(_systemCaptPrio, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CaptureCont::setSystemCaptureEnable(const bool& enable)
|
|
|
|
{
|
|
|
|
if(_systemCaptEnabled != enable)
|
|
|
|
{
|
|
|
|
if(enable)
|
|
|
|
{
|
2018-12-28 18:12:45 +01:00
|
|
|
_hyperion->registerInput(_systemCaptPrio, hyperion::COMP_GRABBER);
|
2019-01-01 19:47:07 +01:00
|
|
|
connect(GlobalSignals::getInstance(), &GlobalSignals::setSystemImage, this, &CaptureCont::handleSystemImage);
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-01 19:47:07 +01:00
|
|
|
disconnect(GlobalSignals::getInstance(), &GlobalSignals::setSystemImage, 0, 0);
|
2018-12-27 23:11:32 +01:00
|
|
|
_hyperion->clear(_systemCaptPrio);
|
|
|
|
}
|
|
|
|
_systemCaptEnabled = enable;
|
|
|
|
_hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_GRABBER, enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaptureCont::setV4LCaptureEnable(const bool& enable)
|
|
|
|
{
|
|
|
|
if(_v4lCaptEnabled != enable)
|
|
|
|
{
|
|
|
|
if(enable)
|
|
|
|
{
|
2018-12-28 18:12:45 +01:00
|
|
|
_hyperion->registerInput(_v4lCaptPrio, hyperion::COMP_V4L);
|
2019-01-01 19:47:07 +01:00
|
|
|
connect(GlobalSignals::getInstance(), &GlobalSignals::setV4lImage, this, &CaptureCont::handleV4lImage);
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-01 19:47:07 +01:00
|
|
|
disconnect(GlobalSignals::getInstance(), &GlobalSignals::setV4lImage, 0, 0);
|
2018-12-27 23:11:32 +01:00
|
|
|
_hyperion->clear(_v4lCaptPrio);
|
2018-12-28 18:12:45 +01:00
|
|
|
_v4lInactiveTimer->stop();
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
|
|
|
_v4lCaptEnabled = enable;
|
|
|
|
_hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_V4L, enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaptureCont::handleSettingsUpdate(const settings::type& type, const QJsonDocument& config)
|
|
|
|
{
|
|
|
|
if(type == settings::INSTCAPTURE)
|
|
|
|
{
|
|
|
|
const QJsonObject& obj = config.object();
|
|
|
|
if(_v4lCaptPrio != obj["v4lPriority"].toInt(240))
|
|
|
|
{
|
|
|
|
setV4LCaptureEnable(false); // clear prio
|
|
|
|
_v4lCaptPrio = obj["v4lPriority"].toInt(240);
|
|
|
|
}
|
|
|
|
if(_systemCaptPrio != obj["systemPriority"].toInt(250))
|
|
|
|
{
|
|
|
|
setSystemCaptureEnable(false); // clear prio
|
|
|
|
_systemCaptPrio = obj["systemPriority"].toInt(250);
|
|
|
|
}
|
|
|
|
|
|
|
|
setV4LCaptureEnable(obj["v4lEnable"].toBool(true));
|
|
|
|
setSystemCaptureEnable(obj["systemEnable"].toBool(true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaptureCont::componentStateChanged(const hyperion::Components component, bool enable)
|
|
|
|
{
|
|
|
|
if(component == hyperion::COMP_GRABBER)
|
|
|
|
{
|
|
|
|
setSystemCaptureEnable(enable);
|
|
|
|
}
|
|
|
|
else if(component == hyperion::COMP_V4L)
|
|
|
|
{
|
|
|
|
setV4LCaptureEnable(enable);
|
|
|
|
}
|
|
|
|
}
|
2018-12-28 18:12:45 +01:00
|
|
|
|
|
|
|
void CaptureCont::setV4lInactive()
|
|
|
|
{
|
|
|
|
_hyperion->setInputInactive(_v4lCaptPrio);
|
|
|
|
}
|
2018-12-31 15:48:29 +01:00
|
|
|
|
|
|
|
void CaptureCont::setSystemInactive()
|
|
|
|
{
|
|
|
|
_hyperion->setInputInactive(_systemCaptPrio);
|
|
|
|
}
|