mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
2f573a117f
* Allow build, if no grabbers are enabled * Align available functions to right Qt version * Update to next development version * Align available functions to right Qt version * fix workflows (apt/nightly) * Disable QNetworkConfigurationManager deprecation warnings * Initial go on Smart Pointers * Add Deallocation * Correct QT_WARNING_DISABLE_DEPRECATED (available since 5.9) * Cluster Build Variables * Hyperion Light * Address build warnings * Hyperion Light - UI * Update Protobuf to latest master * Removed compiler warnings * Added restart ability to systray * Correct Protobuf * Ignore 'no-return' warning on protobuf build * hyperion-remote: Fix auto discovery of hyperion server * Fix Qt version override * Update changelog * Remove Grabber Components, if no Grabber exists * Standalone Grabber - Fix fps default * Remote Control - Have Source Selction accrosswhole screen * Enable Blackborder detection only, if relevant input sources available * Enable Blackborder detection only, if relevant input sources available * Remote UI - rearrange containers * - QT5/6 path for arm64 added - Remove ZLib Dependency - Fix macOS bundle info details - Cleanup Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com> Co-authored-by: Paulchen Panther <Paulchen-Panter@protonmail.com>
269 lines
6.3 KiB
C++
269 lines
6.3 KiB
C++
// Hyperion includes
|
|
#include <hyperion/GrabberWrapper.h>
|
|
#include <hyperion/Grabber.h>
|
|
#include <HyperionConfig.h>
|
|
|
|
// utils includes
|
|
#include <utils/GlobalSignals.h>
|
|
|
|
// qt
|
|
#include <QTimer>
|
|
|
|
GrabberWrapper* GrabberWrapper::instance = nullptr;
|
|
const int GrabberWrapper::DEFAULT_RATE_HZ = 25;
|
|
const int GrabberWrapper::DEFAULT_MIN_GRAB_RATE_HZ = 1;
|
|
const int GrabberWrapper::DEFAULT_MAX_GRAB_RATE_HZ = 30;
|
|
const int GrabberWrapper::DEFAULT_PIXELDECIMATION = 8;
|
|
|
|
/// Map of Hyperion instances with grabber name that requested screen capture
|
|
QMap<int, QString> GrabberWrapper::GRABBER_SYS_CLIENTS = QMap<int, QString>();
|
|
QMap<int, QString> GrabberWrapper::GRABBER_V4L_CLIENTS = QMap<int, QString>();
|
|
bool GrabberWrapper::GLOBAL_GRABBER_SYS_ENABLE = false;
|
|
bool GrabberWrapper::GLOBAL_GRABBER_V4L_ENABLE = false;
|
|
|
|
GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber * ggrabber, int updateRate_Hz)
|
|
: _grabberName(grabberName)
|
|
, _log(Logger::getInstance(grabberName.toUpper()))
|
|
, _timer(new QTimer(this))
|
|
, _updateInterval_ms(1000/updateRate_Hz)
|
|
, _ggrabber(ggrabber)
|
|
, _image(0,0)
|
|
{
|
|
GrabberWrapper::instance = this;
|
|
|
|
// Configure the timer to generate events every n milliseconds
|
|
_timer->setTimerType(Qt::PreciseTimer);
|
|
_timer->setInterval(_updateInterval_ms);
|
|
|
|
connect(_timer, &QTimer::timeout, this, &GrabberWrapper::action);
|
|
|
|
// connect the image forwarding
|
|
(_grabberName.startsWith("V4L"))
|
|
? connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setV4lImage)
|
|
: connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setSystemImage);
|
|
|
|
// listen for source requests
|
|
connect(GlobalSignals::getInstance(), &GlobalSignals::requestSource, this, &GrabberWrapper::handleSourceRequest);
|
|
}
|
|
|
|
GrabberWrapper::~GrabberWrapper()
|
|
{
|
|
Debug(_log,"Close grabber: %s", QSTRING_CSTR(_grabberName));
|
|
}
|
|
|
|
bool GrabberWrapper::start()
|
|
{
|
|
bool rc = false;
|
|
if ( open() )
|
|
{
|
|
if (!_timer->isActive())
|
|
{
|
|
// Start the timer with the pre configured interval
|
|
Debug(_log,"Grabber start()");
|
|
_timer->start();
|
|
}
|
|
|
|
rc = _timer->isActive();
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
void GrabberWrapper::stop()
|
|
{
|
|
if (_timer->isActive())
|
|
{
|
|
// Stop the timer, effectively stopping the process
|
|
Debug(_log,"Grabber stop()");
|
|
_timer->stop();
|
|
}
|
|
}
|
|
|
|
bool GrabberWrapper::isActive() const
|
|
{
|
|
return _timer->isActive();
|
|
}
|
|
|
|
QStringList GrabberWrapper::getActive(int inst, GrabberTypeFilter type) const
|
|
{
|
|
QStringList result = QStringList();
|
|
|
|
if (type == GrabberTypeFilter::SCREEN || type == GrabberTypeFilter::ALL)
|
|
{
|
|
if (GRABBER_SYS_CLIENTS.contains(inst))
|
|
result << GRABBER_SYS_CLIENTS.value(inst);
|
|
}
|
|
|
|
if (type == GrabberTypeFilter::VIDEO || type == GrabberTypeFilter::ALL)
|
|
{
|
|
if (GRABBER_V4L_CLIENTS.contains(inst))
|
|
result << GRABBER_V4L_CLIENTS.value(inst);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
QStringList GrabberWrapper::availableGrabbers(GrabberTypeFilter type)
|
|
{
|
|
QStringList grabbers;
|
|
|
|
if (type == GrabberTypeFilter::SCREEN || type == GrabberTypeFilter::ALL)
|
|
{
|
|
#ifdef ENABLE_DISPMANX
|
|
grabbers << "dispmanx";
|
|
#endif
|
|
|
|
#ifdef ENABLE_FB
|
|
grabbers << "framebuffer";
|
|
#endif
|
|
|
|
#ifdef ENABLE_AMLOGIC
|
|
grabbers << "amlogic";
|
|
#endif
|
|
|
|
#ifdef ENABLE_OSX
|
|
grabbers << "osx";
|
|
#endif
|
|
|
|
#ifdef ENABLE_X11
|
|
grabbers << "x11";
|
|
#endif
|
|
|
|
#ifdef ENABLE_XCB
|
|
grabbers << "xcb";
|
|
#endif
|
|
|
|
#ifdef ENABLE_QT
|
|
grabbers << "qt";
|
|
#endif
|
|
|
|
#ifdef ENABLE_DX
|
|
grabbers << "dx";
|
|
#endif
|
|
}
|
|
|
|
if (type == GrabberTypeFilter::VIDEO || type == GrabberTypeFilter::ALL)
|
|
{
|
|
#if defined(ENABLE_V4L2) || defined(ENABLE_MF)
|
|
grabbers << "v4l2";
|
|
#endif
|
|
}
|
|
|
|
return grabbers;
|
|
}
|
|
|
|
void GrabberWrapper::setVideoMode(VideoMode mode)
|
|
{
|
|
if (_ggrabber != nullptr)
|
|
{
|
|
Info(_log,"setVideoMode");
|
|
_ggrabber->setVideoMode(mode);
|
|
}
|
|
}
|
|
|
|
void GrabberWrapper::setFlipMode(const QString& flipMode)
|
|
{
|
|
_ggrabber->setFlipMode(parseFlipMode(flipMode));
|
|
}
|
|
|
|
void GrabberWrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
|
|
{
|
|
_ggrabber->setCropping(cropLeft, cropRight, cropTop, cropBottom);
|
|
}
|
|
|
|
void GrabberWrapper::updateTimer(int interval)
|
|
{
|
|
if(_updateInterval_ms != interval)
|
|
{
|
|
_updateInterval_ms = interval;
|
|
|
|
const bool& timerWasActive = _timer->isActive();
|
|
_timer->stop();
|
|
_timer->setInterval(_updateInterval_ms);
|
|
|
|
if(timerWasActive)
|
|
_timer->start();
|
|
}
|
|
}
|
|
|
|
void GrabberWrapper::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
|
{ if(type == settings::SYSTEMCAPTURE && !_grabberName.startsWith("V4L"))
|
|
{
|
|
// extract settings
|
|
const QJsonObject& obj = config.object();
|
|
|
|
// save current state
|
|
bool isEnabled = getSysGrabberState();
|
|
|
|
// set global grabber state
|
|
setSysGrabberState(obj["enable"].toBool(false));
|
|
|
|
if (getSysGrabberState())
|
|
{
|
|
// width/height
|
|
_ggrabber->setWidthHeight(obj["width"].toInt(96), obj["height"].toInt(96));
|
|
|
|
// display index for MAC
|
|
_ggrabber->setDisplayIndex(obj["input"].toInt(0));
|
|
|
|
// pixel decimation for x11
|
|
_ggrabber->setPixelDecimation(obj["pixelDecimation"].toInt(DEFAULT_PIXELDECIMATION));
|
|
|
|
// crop for system capture
|
|
_ggrabber->setCropping(
|
|
obj["cropLeft"].toInt(0),
|
|
obj["cropRight"].toInt(0),
|
|
obj["cropTop"].toInt(0),
|
|
obj["cropBottom"].toInt(0));
|
|
|
|
_ggrabber->setFramerate(obj["fps"].toInt(DEFAULT_RATE_HZ));
|
|
// eval new update time
|
|
updateTimer(_ggrabber->getUpdateInterval());
|
|
|
|
// start if current state is not true
|
|
if (!isEnabled)
|
|
{
|
|
start();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
stop();
|
|
}
|
|
}
|
|
}
|
|
|
|
void GrabberWrapper::handleSourceRequest(hyperion::Components component, int hyperionInd, bool listen)
|
|
{
|
|
if(component == hyperion::Components::COMP_GRABBER && !_grabberName.startsWith("V4L"))
|
|
{
|
|
if(listen)
|
|
GRABBER_SYS_CLIENTS.insert(hyperionInd, _grabberName);
|
|
else
|
|
GRABBER_SYS_CLIENTS.remove(hyperionInd);
|
|
|
|
if(GRABBER_SYS_CLIENTS.empty() || !getSysGrabberState())
|
|
stop();
|
|
else
|
|
start();
|
|
}
|
|
else if(component == hyperion::Components::COMP_V4L && _grabberName.startsWith("V4L"))
|
|
{
|
|
if(listen)
|
|
GRABBER_V4L_CLIENTS.insert(hyperionInd, _grabberName);
|
|
else
|
|
GRABBER_V4L_CLIENTS.remove(hyperionInd);
|
|
|
|
if(GRABBER_V4L_CLIENTS.empty() || !getV4lGrabberState())
|
|
stop();
|
|
else
|
|
start();
|
|
}
|
|
}
|
|
|
|
void GrabberWrapper::tryStart()
|
|
{
|
|
// verify start condition
|
|
if(!_grabberName.startsWith("V4L") && !GRABBER_SYS_CLIENTS.empty() && getSysGrabberState())
|
|
start();
|
|
}
|