mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Fix Memory leaks (#1678)
* Refactor to fix #1671
* Add GUI/NonGUI mode to info page
* Do not show lock config, if in non-UI mode
* Updae Changelog
* Correct includes
* Ensure key member initialization - RGB Channels
* Ensure key member initialization - WebServer
* Update RGBChannels
* Fix initialization order
* Fix key when inserting new logger in LoggerMap,
Prepare logBuffer-JSON snapshot view in LoggerManager,
Increase buffered loglines to 500
* Fix Memory leak in GrabberWrapper
* Fix Memory leak in BlackBorderProcessor
* Fix Memory leak in BlackBorderProcessor
* use ninja generator under macos
* Fix BGEffectHandler destruction
* Fix Mdns code
* Clear list after applying qDeleteAll
* Fix deletion of CecHandler
* Fix memory leak caused by wrong buffer allocation
* Remove extra pixel consistently
* Change mDNS to Qt SmartPointers
* Correct removal
* Fix usage of _width/_height (they are the output resolution, not the screen resolution)
That avoids unnecessary resizing of the output image with every transferFrame call
* Move main non Thread Objects to Smart Pointers
* Revert "Move main non Thread Objects to Smart Pointers"
This reverts commit 26102ca963
.
* Add missing deletes
* Revert MdnsBrowser chnage
* Revert MdnsBrowser change
* Fix memory leaks related standalone grabber
* Address CodeQL finding
* delete pointer OsxFrameGrabber
---------
Co-authored-by: Paulchen-Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
@@ -1983,24 +1983,10 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg)
|
||||
if (!_streaming_logging_activated)
|
||||
{
|
||||
_streaming_logging_activated = true;
|
||||
const QList<Logger::T_LOG_MESSAGE> *logBuffer = LoggerManager::getInstance()->getLogMessageBuffer();
|
||||
for (int i = 0; i < logBuffer->length(); i++)
|
||||
{
|
||||
//Only present records of the current log-level
|
||||
if ( logBuffer->at(i).level >= _log->getLogLevel())
|
||||
{
|
||||
message["loggerName"] = logBuffer->at(i).loggerName;
|
||||
message["loggerSubName"] = logBuffer->at(i).loggerSubName;
|
||||
message["function"] = logBuffer->at(i).function;
|
||||
message["line"] = QString::number(logBuffer->at(i).line);
|
||||
message["fileName"] = logBuffer->at(i).fileName;
|
||||
message["message"] = logBuffer->at(i).message;
|
||||
message["levelString"] = logBuffer->at(i).levelString;
|
||||
message["utime"] = QString::number(logBuffer->at(i).utime);
|
||||
|
||||
messageArray.append(message);
|
||||
}
|
||||
}
|
||||
QMetaObject::invokeMethod(LoggerManager::getInstance(), "getLogMessageBuffer",
|
||||
Qt::DirectConnection,
|
||||
Q_RETURN_ARG(QJsonArray, messageArray),
|
||||
Q_ARG(Logger::LogLevel, _log->getLogLevel()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -35,12 +35,7 @@ BlackBorderProcessor::BlackBorderProcessor(Hyperion* hyperion, QObject* parent)
|
||||
// listen for component state changes
|
||||
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &BlackBorderProcessor::handleCompStateChangeRequest);
|
||||
|
||||
_detector = new BlackBorderDetector(_oldThreshold);
|
||||
}
|
||||
|
||||
BlackBorderProcessor::~BlackBorderProcessor()
|
||||
{
|
||||
delete _detector;
|
||||
_detector = std::make_unique<BlackBorderDetector>(_oldThreshold);
|
||||
}
|
||||
|
||||
void BlackBorderProcessor::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
||||
@@ -66,10 +61,7 @@ void BlackBorderProcessor::handleSettingsUpdate(settings::type type, const QJson
|
||||
if (fabs(_oldThreshold - newThreshold) > std::numeric_limits<double>::epsilon())
|
||||
{
|
||||
_oldThreshold = newThreshold;
|
||||
|
||||
delete _detector;
|
||||
|
||||
_detector = new BlackBorderDetector(newThreshold);
|
||||
_detector = std::make_unique<BlackBorderDetector>(_oldThreshold);
|
||||
}
|
||||
|
||||
Debug(Logger::getInstance("BLACKBORDER", "I"+QString::number(_hyperion->getInstanceIndex())), "Set mode to: %s", QSTRING_CSTR(_detectionMode));
|
||||
|
@@ -63,6 +63,7 @@ void BoblightServer::stop()
|
||||
return;
|
||||
|
||||
qDeleteAll(_openConnections);
|
||||
_openConnections.clear();
|
||||
|
||||
_server->close();
|
||||
|
||||
|
@@ -5,6 +5,7 @@ using namespace commandline;
|
||||
Parser::~Parser()
|
||||
{
|
||||
qDeleteAll(_options);
|
||||
_options.clear();
|
||||
}
|
||||
|
||||
bool Parser::parse(const QStringList &arguments)
|
||||
|
@@ -178,7 +178,7 @@ void AudioGrabber::processAudioFrame(int16_t* buffer, int length)
|
||||
}
|
||||
|
||||
// Convert to Image<ColorRGB>
|
||||
Image<ColorRgb> finalImage (static_cast<unsigned>(image.width()), static_cast<unsigned>(image.height()));
|
||||
Image<ColorRgb> finalImage (image.width(),image.height());
|
||||
for (int y = 0; y < image.height(); y++)
|
||||
{
|
||||
memcpy((unsigned char*)finalImage.memptr() + y * image.width() * 3, static_cast<unsigned char*>(image.scanLine(y)), image.width() * 3);
|
||||
|
@@ -5,7 +5,6 @@
|
||||
|
||||
AudioWrapper::AudioWrapper()
|
||||
: GrabberWrapper("AudioGrabber", &_grabber)
|
||||
, _grabber()
|
||||
{
|
||||
// register the image type
|
||||
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
|
||||
|
@@ -124,6 +124,7 @@ bool OsxFrameGrabber::setDisplayIndex(int index)
|
||||
CGImageRelease(image);
|
||||
}
|
||||
}
|
||||
delete[] activeDspys;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -201,7 +202,7 @@ QJsonObject OsxFrameGrabber::discover(const QJsonObject& params)
|
||||
defaults["video_input"] = video_inputs_default;
|
||||
inputsDiscovered["default"] = defaults;
|
||||
}
|
||||
delete [] activeDspys;
|
||||
delete[] activeDspys;
|
||||
}
|
||||
|
||||
if (inputsDiscovered.isEmpty())
|
||||
|
@@ -22,8 +22,8 @@ const bool verbose = false;
|
||||
QtGrabber::QtGrabber(int display, int cropLeft, int cropRight, int cropTop, int cropBottom)
|
||||
: Grabber("QTGRABBER", cropLeft, cropRight, cropTop, cropBottom)
|
||||
, _display(display)
|
||||
, _calculatedWidth(0)
|
||||
, _calculatedHeight(0)
|
||||
, _screenWidth(0)
|
||||
, _screenHeight(0)
|
||||
, _src_x(0)
|
||||
, _src_y(0)
|
||||
, _src_x_max(0)
|
||||
@@ -233,8 +233,8 @@ int QtGrabber::grabFrame(Image<ColorRgb>& image)
|
||||
}
|
||||
else
|
||||
{
|
||||
QImage imageFrame = originalPixmap.toImage().scaled(_calculatedWidth, _calculatedHeight).convertToFormat(QImage::Format_RGB888);
|
||||
image.resize(static_cast<uint>(_calculatedWidth), static_cast<uint>(_calculatedHeight));
|
||||
QImage imageFrame = originalPixmap.toImage().scaled(_width, _height).convertToFormat(QImage::Format_RGB888);
|
||||
image.resize(_width, _height);
|
||||
|
||||
for (int y = 0; y < imageFrame.height(); y++)
|
||||
{
|
||||
@@ -263,27 +263,27 @@ int QtGrabber::updateScreenDimensions(bool force)
|
||||
{
|
||||
geo = _screen->geometry();
|
||||
}
|
||||
if (!force && _width == geo.width() && _height == geo.height())
|
||||
if (!force && _screenWidth == geo.width() && _height == geo.height())
|
||||
{
|
||||
// No update required
|
||||
return 0;
|
||||
}
|
||||
|
||||
Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _width, _height, geo.width(), geo.height());
|
||||
_width = geo.width();
|
||||
_height = geo.height();
|
||||
Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _screenWidth, _screenHeight, geo.width(), geo.height());
|
||||
_screenWidth = geo.width();
|
||||
_screenHeight = geo.height();
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
// Image scaling is performed by Qt
|
||||
width = (_width > (_cropLeft + _cropRight))
|
||||
? ((_width - _cropLeft - _cropRight) / _pixelDecimation)
|
||||
: (_width / _pixelDecimation);
|
||||
width = (_screenWidth > (_cropLeft + _cropRight))
|
||||
? ((_screenWidth - _cropLeft - _cropRight) / _pixelDecimation)
|
||||
: (_screenWidth / _pixelDecimation);
|
||||
|
||||
height = (_height > (_cropTop + _cropBottom))
|
||||
? ((_height - _cropTop - _cropBottom) / _pixelDecimation)
|
||||
: (_height / _pixelDecimation);
|
||||
height = (_screenHeight > (_cropTop + _cropBottom))
|
||||
? ((_screenHeight - _cropTop - _cropBottom) / _pixelDecimation)
|
||||
: (_screenHeight / _pixelDecimation);
|
||||
|
||||
// calculate final image dimensions and adjust top/left cropping in 3D modes
|
||||
if (_isVirtual)
|
||||
@@ -300,33 +300,33 @@ int QtGrabber::updateScreenDimensions(bool force)
|
||||
switch (_videoMode)
|
||||
{
|
||||
case VideoMode::VIDEO_3DSBS:
|
||||
_calculatedWidth = width / 2;
|
||||
_calculatedHeight = height;
|
||||
_width = width / 2;
|
||||
_height = height;
|
||||
_src_x = _src_x + (_cropLeft / 2);
|
||||
_src_y = _src_y + _cropTop;
|
||||
_src_x_max = (_width / 2) - _cropRight - _cropLeft;
|
||||
_src_y_max = _height - _cropBottom - _cropTop;
|
||||
_src_x_max = (_screenWidth / 2) - _cropRight - _cropLeft;
|
||||
_src_y_max = _screenHeight - _cropBottom - _cropTop;
|
||||
break;
|
||||
case VideoMode::VIDEO_3DTAB:
|
||||
_calculatedWidth = width;
|
||||
_calculatedHeight = height / 2;
|
||||
_width = width;
|
||||
_height = height / 2;
|
||||
_src_x = _src_x + _cropLeft;
|
||||
_src_y = _src_y + (_cropTop / 2);
|
||||
_src_x_max = _width - _cropRight - _cropLeft;
|
||||
_src_y_max = (_height / 2) - _cropBottom - _cropTop;
|
||||
_src_x_max = _screenWidth - _cropRight - _cropLeft;
|
||||
_src_y_max = (_screenHeight / 2) - _cropBottom - _cropTop;
|
||||
break;
|
||||
case VideoMode::VIDEO_2D:
|
||||
default:
|
||||
_calculatedWidth = width;
|
||||
_calculatedHeight = height;
|
||||
_width = width;
|
||||
_height = height;
|
||||
_src_x = _src_x + _cropLeft;
|
||||
_src_y = _src_y + _cropTop;
|
||||
_src_x_max = _width - _cropRight - _cropLeft;
|
||||
_src_y_max = _height - _cropBottom - _cropTop;
|
||||
_src_x_max = _screenWidth - _cropRight - _cropLeft;
|
||||
_src_y_max = _screenHeight - _cropBottom - _cropTop;
|
||||
break;
|
||||
}
|
||||
|
||||
Info(_log, "Update output image resolution to [%dx%d]", _calculatedWidth, _calculatedHeight);
|
||||
Info(_log, "Update output image resolution to [%dx%d]", _width, _height);
|
||||
Debug(_log, "Grab screen area: %d,%d,%d,%d", _src_x, _src_y, _src_x_max, _src_y_max);
|
||||
|
||||
return 1;
|
||||
@@ -433,10 +433,10 @@ QJsonObject QtGrabber::discover(const QJsonObject& params)
|
||||
|
||||
if (screens.at(0)->size() != screens.at(0)->virtualSize())
|
||||
{
|
||||
QJsonObject in;
|
||||
in["name"] = "All Displays";
|
||||
in["inputIdx"] = screens.size();
|
||||
in["virtual"] = true;
|
||||
QJsonObject input;
|
||||
input["name"] = "All Displays";
|
||||
input["inputIdx"] = screens.size();
|
||||
input["virtual"] = true;
|
||||
|
||||
QJsonArray formats;
|
||||
QJsonObject format;
|
||||
@@ -454,15 +454,19 @@ QJsonObject QtGrabber::discover(const QJsonObject& params)
|
||||
format["resolutions"] = resolutionArray;
|
||||
formats.append(format);
|
||||
|
||||
in["formats"] = formats;
|
||||
video_inputs.append(in);
|
||||
input["formats"] = formats;
|
||||
video_inputs.append(input);
|
||||
}
|
||||
inputsDiscovered["video_inputs"] = video_inputs;
|
||||
|
||||
QJsonObject defaults, video_inputs_default, resolution_default;
|
||||
QJsonObject resolution_default;
|
||||
resolution_default["fps"] = _fps;
|
||||
|
||||
QJsonObject video_inputs_default;
|
||||
video_inputs_default["resolution"] = resolution_default;
|
||||
video_inputs_default["inputIdx"] = 0;
|
||||
|
||||
QJsonObject defaults;
|
||||
defaults["video_input"] = video_inputs_default;
|
||||
inputsDiscovered["default"] = defaults;
|
||||
}
|
||||
|
@@ -318,7 +318,7 @@ void EncoderThread::processImageMjpeg()
|
||||
}
|
||||
}
|
||||
|
||||
Image<ColorRgb> srcImage(static_cast<unsigned>(_width), static_cast<unsigned>(_height));
|
||||
Image<ColorRgb> srcImage(_width, _height);
|
||||
|
||||
if (tjDecompress2(_tjInstance, _localData , _size,
|
||||
reinterpret_cast<unsigned char*>(srcImage.memptr()), _width, 0, _height,
|
||||
|
@@ -18,16 +18,15 @@ X11Grabber::X11Grabber(int cropLeft, int cropRight, int cropTop, int cropBottom)
|
||||
, _dstFormat(nullptr)
|
||||
, _srcPicture(None)
|
||||
, _dstPicture(None)
|
||||
, _calculatedWidth(0)
|
||||
, _calculatedHeight(0)
|
||||
, _screenWidth(0)
|
||||
, _screenHeight(0)
|
||||
, _src_x(cropLeft)
|
||||
, _src_y(cropTop)
|
||||
, _XShmAvailable(false)
|
||||
, _XRenderAvailable(false)
|
||||
, _XRandRAvailable(false)
|
||||
, _xShmAvailable(false)
|
||||
, _xRenderAvailable(false)
|
||||
, _xRandRAvailable(false)
|
||||
, _isWayland (false)
|
||||
, _logger{}
|
||||
, _image(0,0)
|
||||
{
|
||||
_logger = Logger::getInstance("X11");
|
||||
|
||||
@@ -53,17 +52,17 @@ void X11Grabber::freeResources()
|
||||
{
|
||||
XDestroyImage(_xImage);
|
||||
}
|
||||
if (_XRandRAvailable)
|
||||
if (_xRandRAvailable)
|
||||
{
|
||||
qApp->removeNativeEventFilter(this);
|
||||
}
|
||||
if(_XShmAvailable)
|
||||
if(_xShmAvailable)
|
||||
{
|
||||
XShmDetach(_x11Display, &_shminfo);
|
||||
shmdt(_shminfo.shmaddr);
|
||||
shmctl(_shminfo.shmid, IPC_RMID, 0);
|
||||
shmctl(_shminfo.shmid, IPC_RMID, nullptr);
|
||||
}
|
||||
if (_XRenderAvailable)
|
||||
if (_xRenderAvailable)
|
||||
{
|
||||
XRenderFreePicture(_x11Display, _srcPicture);
|
||||
XRenderFreePicture(_x11Display, _dstPicture);
|
||||
@@ -73,41 +72,41 @@ void X11Grabber::freeResources()
|
||||
|
||||
void X11Grabber::setupResources()
|
||||
{
|
||||
if (_XRandRAvailable)
|
||||
if (_xRandRAvailable)
|
||||
{
|
||||
qApp->installNativeEventFilter(this);
|
||||
}
|
||||
|
||||
if(_XShmAvailable)
|
||||
if(_xShmAvailable)
|
||||
{
|
||||
_xImage = XShmCreateImage(_x11Display, _windowAttr.visual, _windowAttr.depth, ZPixmap, NULL, &_shminfo, _calculatedWidth, _calculatedHeight);
|
||||
_xImage = XShmCreateImage(_x11Display, _windowAttr.visual, _windowAttr.depth, ZPixmap, nullptr, &_shminfo, _width, _height);
|
||||
_shminfo.shmid = shmget(IPC_PRIVATE, (size_t) _xImage->bytes_per_line * _xImage->height, IPC_CREAT|0777);
|
||||
_xImage->data = (char*)shmat(_shminfo.shmid,0,0);
|
||||
_xImage->data = (char*)shmat(_shminfo.shmid,nullptr,0);
|
||||
_shminfo.shmaddr = _xImage->data;
|
||||
_shminfo.readOnly = False;
|
||||
XShmAttach(_x11Display, &_shminfo);
|
||||
}
|
||||
|
||||
if (_XRenderAvailable)
|
||||
if (_xRenderAvailable)
|
||||
{
|
||||
_useImageResampler = false;
|
||||
_imageResampler.setHorizontalPixelDecimation(1);
|
||||
_imageResampler.setVerticalPixelDecimation(1);
|
||||
|
||||
if(_XShmPixmapAvailable)
|
||||
if(_xShmPixmapAvailable)
|
||||
{
|
||||
_pixmap = XShmCreatePixmap(_x11Display, _window, _xImage->data, &_shminfo, _calculatedWidth, _calculatedHeight, _windowAttr.depth);
|
||||
_pixmap = XShmCreatePixmap(_x11Display, _window, _xImage->data, &_shminfo, _width, _height, _windowAttr.depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
_pixmap = XCreatePixmap(_x11Display, _window, _calculatedWidth, _calculatedHeight, _windowAttr.depth);
|
||||
_pixmap = XCreatePixmap(_x11Display, _window, _width, _height, _windowAttr.depth);
|
||||
}
|
||||
_srcFormat = XRenderFindVisualFormat(_x11Display, _windowAttr.visual);
|
||||
_dstFormat = XRenderFindVisualFormat(_x11Display, _windowAttr.visual);
|
||||
_srcPicture = XRenderCreatePicture(_x11Display, _window, _srcFormat, CPRepeat, &_pictAttr);
|
||||
_dstPicture = XRenderCreatePicture(_x11Display, _pixmap, _dstFormat, CPRepeat, &_pictAttr);
|
||||
|
||||
XRenderSetPictureFilter(_x11Display, _srcPicture, FilterBilinear, NULL, 0);
|
||||
XRenderSetPictureFilter(_x11Display, _srcPicture, FilterBilinear, nullptr, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -162,19 +161,20 @@ bool X11Grabber::setupDisplay()
|
||||
{
|
||||
_window = DefaultRootWindow(_x11Display);
|
||||
|
||||
int dummy, pixmaps_supported;
|
||||
int dummy;
|
||||
int pixmaps_supported;
|
||||
|
||||
_XRandRAvailable = XRRQueryExtension(_x11Display, &_XRandREventBase, &dummy);
|
||||
_XRenderAvailable = XRenderQueryExtension(_x11Display, &dummy, &dummy);
|
||||
_XShmAvailable = XShmQueryExtension(_x11Display);
|
||||
_xRandRAvailable = (XRRQueryExtension(_x11Display, &_xRandREventBase, &dummy) != 0);
|
||||
_xRenderAvailable = (XRenderQueryExtension(_x11Display, &dummy, &dummy) != 0);
|
||||
_xShmAvailable = (XShmQueryExtension(_x11Display) != 0);
|
||||
XShmQueryVersion(_x11Display, &dummy, &dummy, &pixmaps_supported);
|
||||
_XShmPixmapAvailable = pixmaps_supported && XShmPixmapFormat(_x11Display) == ZPixmap;
|
||||
_xShmPixmapAvailable = (pixmaps_supported != 0) && XShmPixmapFormat(_x11Display) == ZPixmap;
|
||||
|
||||
Info(_log, "%s", QSTRING_CSTR(QString("XRandR=[%1] XRender=[%2] XShm=[%3] XPixmap=[%4]")
|
||||
.arg(_XRandRAvailable ? "available" : "unavailable",
|
||||
_XRenderAvailable ? "available" : "unavailable",
|
||||
_XShmAvailable ? "available" : "unavailable",
|
||||
_XShmPixmapAvailable ? "available" : "unavailable"))
|
||||
.arg(_xRandRAvailable ? "available" : "unavailable",
|
||||
_xRenderAvailable ? "available" : "unavailable",
|
||||
_xShmAvailable ? "available" : "unavailable",
|
||||
_xShmPixmapAvailable ? "available" : "unavailable"))
|
||||
);
|
||||
|
||||
result = (updateScreenDimensions(true) >=0);
|
||||
@@ -186,12 +186,17 @@ bool X11Grabber::setupDisplay()
|
||||
|
||||
int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate)
|
||||
{
|
||||
if (!_isEnabled) return 0;
|
||||
if (!_isEnabled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (forceUpdate)
|
||||
{
|
||||
updateScreenDimensions(forceUpdate);
|
||||
}
|
||||
|
||||
if (_XRenderAvailable)
|
||||
if (_xRenderAvailable)
|
||||
{
|
||||
double scale_x = static_cast<double>(_windowAttr.width / _pixelDecimation) / static_cast<double>(_windowAttr.width);
|
||||
double scale_y = static_cast<double>(_windowAttr.height / _pixelDecimation) / static_cast<double>(_windowAttr.height);
|
||||
@@ -224,20 +229,20 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate)
|
||||
// src_y = cropTop, mask_x, mask_y, dest_x, dest_y, width, height
|
||||
XRenderComposite(
|
||||
_x11Display, PictOpSrc, _srcPicture, None, _dstPicture, ( _src_x/_pixelDecimation),
|
||||
(_src_y/_pixelDecimation), 0, 0, 0, 0, _calculatedWidth, _calculatedHeight);
|
||||
(_src_y/_pixelDecimation), 0, 0, 0, 0, _width, _height);
|
||||
|
||||
XSync(_x11Display, False);
|
||||
|
||||
if (_XShmAvailable)
|
||||
if (_xShmAvailable)
|
||||
{
|
||||
XShmGetImage(_x11Display, _pixmap, _xImage, 0, 0, AllPlanes);
|
||||
}
|
||||
else
|
||||
{
|
||||
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _calculatedWidth, _calculatedHeight, AllPlanes, ZPixmap);
|
||||
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _width, _height, AllPlanes, ZPixmap);
|
||||
}
|
||||
}
|
||||
else if (_XShmAvailable)
|
||||
else if (_xShmAvailable)
|
||||
{
|
||||
// use xshm
|
||||
XShmGetImage(_x11Display, _window, _xImage, _src_x, _src_y, AllPlanes);
|
||||
@@ -245,7 +250,7 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate)
|
||||
else
|
||||
{
|
||||
// all things done by xgetimage
|
||||
_xImage = XGetImage(_x11Display, _window, _src_x, _src_y, _calculatedWidth, _calculatedHeight, AllPlanes, ZPixmap);
|
||||
_xImage = XGetImage(_x11Display, _window, _src_x, _src_y, _width, _height, AllPlanes, ZPixmap);
|
||||
}
|
||||
|
||||
if (_xImage == nullptr)
|
||||
@@ -268,46 +273,46 @@ int X11Grabber::updateScreenDimensions(bool force)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!force && _width == _windowAttr.width && _height == _windowAttr.height)
|
||||
if (!force && _screenWidth == _windowAttr.width && _screenHeight == _windowAttr.height)
|
||||
{
|
||||
// No update required
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_width || _height)
|
||||
if ((_screenWidth != 0) || _screenHeight != 0)
|
||||
{
|
||||
freeResources();
|
||||
}
|
||||
|
||||
Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _width, _height, _windowAttr.width, _windowAttr.height);
|
||||
_width = _windowAttr.width;
|
||||
_height = _windowAttr.height;
|
||||
Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _screenWidth, _screenHeight, _windowAttr.width, _windowAttr.height);
|
||||
_screenWidth = _windowAttr.width;
|
||||
_screenHeight = _windowAttr.height;
|
||||
|
||||
int width=0;
|
||||
int height=0;
|
||||
|
||||
// Image scaling is performed by XRender when available, otherwise by ImageResampler
|
||||
if (_XRenderAvailable)
|
||||
if (_xRenderAvailable)
|
||||
{
|
||||
width = (_width > (_cropLeft + _cropRight))
|
||||
? ((_width - _cropLeft - _cropRight) / _pixelDecimation)
|
||||
: _width / _pixelDecimation;
|
||||
width = (_screenWidth > (_cropLeft + _cropRight))
|
||||
? ((_screenWidth - _cropLeft - _cropRight) / _pixelDecimation)
|
||||
: _screenWidth / _pixelDecimation;
|
||||
|
||||
height = (_height > (_cropTop + _cropBottom))
|
||||
? ((_height - _cropTop - _cropBottom) / _pixelDecimation)
|
||||
: _height / _pixelDecimation;
|
||||
height = (_screenHeight > (_cropTop + _cropBottom))
|
||||
? ((_screenHeight - _cropTop - _cropBottom) / _pixelDecimation)
|
||||
: _screenHeight / _pixelDecimation;
|
||||
|
||||
Info(_log, "Using XRender for grabbing");
|
||||
}
|
||||
else
|
||||
{
|
||||
width = (_width > (_cropLeft + _cropRight))
|
||||
? (_width - _cropLeft - _cropRight)
|
||||
: _width;
|
||||
width = (_screenWidth > (_cropLeft + _cropRight))
|
||||
? (_screenWidth - _cropLeft - _cropRight)
|
||||
: _screenWidth;
|
||||
|
||||
height = (_height > (_cropTop + _cropBottom))
|
||||
? (_height - _cropTop - _cropBottom)
|
||||
: _height;
|
||||
height = (_screenHeight > (_cropTop + _cropBottom))
|
||||
? (_screenHeight - _cropTop - _cropBottom)
|
||||
: _screenHeight;
|
||||
|
||||
Info(_log, "Using XGetImage for grabbing");
|
||||
}
|
||||
@@ -316,29 +321,28 @@ int X11Grabber::updateScreenDimensions(bool force)
|
||||
switch (_videoMode)
|
||||
{
|
||||
case VideoMode::VIDEO_3DSBS:
|
||||
_calculatedWidth = width /2;
|
||||
_calculatedHeight = height;
|
||||
_width = width /2;
|
||||
_height = height;
|
||||
_src_x = _cropLeft / 2;
|
||||
_src_y = _cropTop;
|
||||
break;
|
||||
case VideoMode::VIDEO_3DTAB:
|
||||
_calculatedWidth = width;
|
||||
_calculatedHeight = height / 2;
|
||||
_width = width;
|
||||
_height = height / 2;
|
||||
_src_x = _cropLeft;
|
||||
_src_y = _cropTop / 2;
|
||||
break;
|
||||
case VideoMode::VIDEO_2D:
|
||||
default:
|
||||
_calculatedWidth = width;
|
||||
_calculatedHeight = height;
|
||||
_width = width;
|
||||
_height = height;
|
||||
_src_x = _cropLeft;
|
||||
_src_y = _cropTop;
|
||||
break;
|
||||
}
|
||||
|
||||
Info(_log, "Update output image resolution: [%dx%d] to [%dx%d]", _image.width(), _image.height(), _calculatedWidth, _calculatedHeight);
|
||||
|
||||
_image.resize(_calculatedWidth, _calculatedHeight);
|
||||
Info(_log, "Update output image resolution to [%dx%d]", _width, _height);
|
||||
_image.resize(_width, _height);
|
||||
setupResources();
|
||||
|
||||
return 1;
|
||||
@@ -384,14 +388,14 @@ bool X11Grabber::nativeEventFilter(const QByteArray & eventType, void * message,
|
||||
bool X11Grabber::nativeEventFilter(const QByteArray & eventType, void * message, long int * /*result*/)
|
||||
#endif
|
||||
{
|
||||
if (!_XRandRAvailable || eventType != "xcb_generic_event_t") {
|
||||
if (!_xRandRAvailable || eventType != "xcb_generic_event_t") {
|
||||
return false;
|
||||
}
|
||||
|
||||
xcb_generic_event_t *e = static_cast<xcb_generic_event_t*>(message);
|
||||
const uint8_t xEventType = XCB_EVENT_RESPONSE_TYPE(e);
|
||||
xcb_generic_event_t *event = static_cast<xcb_generic_event_t*>(message);
|
||||
const uint8_t xEventType = XCB_EVENT_RESPONSE_TYPE(event);
|
||||
|
||||
if (xEventType == _XRandREventBase + XCB_RANDR_SCREEN_CHANGE_NOTIFY)
|
||||
if (xEventType == _xRandREventBase + XCB_RANDR_SCREEN_CHANGE_NOTIFY)
|
||||
{
|
||||
updateScreenDimensions(true);
|
||||
}
|
||||
@@ -428,7 +432,7 @@ QJsonObject X11Grabber::discover(const QJsonObject& params)
|
||||
}
|
||||
else
|
||||
{
|
||||
QJsonObject in;
|
||||
QJsonObject input;
|
||||
|
||||
QString displayName;
|
||||
char* name;
|
||||
@@ -440,8 +444,8 @@ QJsonObject X11Grabber::discover(const QJsonObject& params)
|
||||
displayName = QString("Display:%1").arg(i);
|
||||
}
|
||||
|
||||
in["name"] = displayName;
|
||||
in["inputIdx"] = i;
|
||||
input["name"] = displayName;
|
||||
input["inputIdx"] = i;
|
||||
|
||||
QJsonArray formats;
|
||||
QJsonArray resolutionArray;
|
||||
@@ -457,19 +461,22 @@ QJsonObject X11Grabber::discover(const QJsonObject& params)
|
||||
format["resolutions"] = resolutionArray;
|
||||
formats.append(format);
|
||||
|
||||
in["formats"] = formats;
|
||||
video_inputs.append(in);
|
||||
input["formats"] = formats;
|
||||
video_inputs.append(input);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !video_inputs.isEmpty() )
|
||||
{
|
||||
inputsDiscovered["video_inputs"] = video_inputs;
|
||||
|
||||
QJsonObject defaults, video_inputs_default, resolution_default;
|
||||
QJsonObject resolution_default;
|
||||
resolution_default["fps"] = _fps;
|
||||
|
||||
QJsonObject video_inputs_default;
|
||||
video_inputs_default["resolution"] = resolution_default;
|
||||
video_inputs_default["inputIdx"] = 0;
|
||||
|
||||
QJsonObject defaults;
|
||||
defaults["video_input"] = video_inputs_default;
|
||||
inputsDiscovered["default"] = defaults;
|
||||
}
|
||||
|
@@ -27,26 +27,33 @@ bool GrabberWrapper::GLOBAL_GRABBER_AUDIO_ENABLE = false;
|
||||
GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber * ggrabber, int updateRate_Hz)
|
||||
: _grabberName(grabberName)
|
||||
, _log(Logger::getInstance(grabberName.toUpper()))
|
||||
, _timer(new QTimer(this))
|
||||
, _timer(nullptr)
|
||||
, _updateInterval_ms(1000/updateRate_Hz)
|
||||
, _ggrabber(ggrabber)
|
||||
, _image(0,0)
|
||||
{
|
||||
GrabberWrapper::instance = this;
|
||||
|
||||
_timer.reset(new QTimer(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(_timer.get(), &QTimer::timeout, this, &GrabberWrapper::action);
|
||||
|
||||
// connect the image forwarding
|
||||
if (_grabberName.startsWith("V4L"))
|
||||
{
|
||||
connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setV4lImage);
|
||||
}
|
||||
else if (_grabberName.startsWith("Audio"))
|
||||
{
|
||||
connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setAudioImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setSystemImage);
|
||||
}
|
||||
|
||||
// listen for source requests
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::requestSource, this, &GrabberWrapper::handleSourceRequest);
|
||||
@@ -56,6 +63,7 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber * ggrabber, i
|
||||
|
||||
GrabberWrapper::~GrabberWrapper()
|
||||
{
|
||||
_timer->stop();
|
||||
GrabberWrapper::instance = nullptr;
|
||||
}
|
||||
|
||||
@@ -103,19 +111,25 @@ QStringList GrabberWrapper::getActive(int inst, GrabberTypeFilter type) const
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == GrabberTypeFilter::AUDIO || type == GrabberTypeFilter::ALL)
|
||||
{
|
||||
if (GRABBER_AUDIO_CLIENTS.contains(inst))
|
||||
{
|
||||
result << GRABBER_AUDIO_CLIENTS.value(inst);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -207,7 +221,9 @@ void GrabberWrapper::updateTimer(int interval)
|
||||
_timer->setInterval(_updateInterval_ms);
|
||||
|
||||
if(timerWasActive)
|
||||
{
|
||||
_timer->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,40 +284,64 @@ void GrabberWrapper::handleSourceRequest(hyperion::Components component, int hyp
|
||||
!_grabberName.startsWith("Audio"))
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
else if (component == hyperion::Components::COMP_AUDIO &&
|
||||
_grabberName.startsWith("Audio"))
|
||||
{
|
||||
if (listen)
|
||||
{
|
||||
GRABBER_AUDIO_CLIENTS.insert(hyperionInd, _grabberName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GRABBER_AUDIO_CLIENTS.remove(hyperionInd);
|
||||
}
|
||||
|
||||
if (GRABBER_AUDIO_CLIENTS.empty() || !getAudioGrabberState())
|
||||
{
|
||||
stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -200,13 +200,16 @@ void Hyperion::stop()
|
||||
|
||||
void Hyperion::freeObjects()
|
||||
{
|
||||
//delete Background effect first that it does not kick in when other priorities are stopped
|
||||
delete _BGEffectHandler;
|
||||
//Disconnect Background effect first that it does not kick in when other priorities are stopped
|
||||
_BGEffectHandler->disconnect();
|
||||
|
||||
//Remove all priorities to switch off all leds
|
||||
clear(-1,true);
|
||||
|
||||
// delete components on exit of hyperion core
|
||||
|
||||
delete _BGEffectHandler;
|
||||
|
||||
#if defined(ENABLE_BOBLIGHT_SERVER)
|
||||
delete _boblightServer;
|
||||
#endif
|
||||
|
@@ -35,6 +35,7 @@ JsonServer::JsonServer(const QJsonDocument& config)
|
||||
JsonServer::~JsonServer()
|
||||
{
|
||||
qDeleteAll(_openConnections);
|
||||
_openConnections.clear();
|
||||
}
|
||||
|
||||
void JsonServer::initServer()
|
||||
|
@@ -2,9 +2,8 @@
|
||||
#include <qmdnsengine/message.h>
|
||||
#include <qmdnsengine/service.h>
|
||||
|
||||
//Qt includes
|
||||
// Qt includes
|
||||
#include <QThread>
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
@@ -19,7 +18,8 @@
|
||||
|
||||
namespace {
|
||||
const bool verboseBrowser = false;
|
||||
} //End of constants
|
||||
const int SERVICE_LOOKUP_RETRIES = 5;
|
||||
} // End of constants
|
||||
|
||||
MdnsBrowser::MdnsBrowser(QObject* parent)
|
||||
: QObject(parent)
|
||||
@@ -30,7 +30,7 @@ MdnsBrowser::MdnsBrowser(QObject* parent)
|
||||
|
||||
MdnsBrowser::~MdnsBrowser()
|
||||
{
|
||||
qDeleteAll(_browsedServiceTypes);
|
||||
_browsedServiceTypes.clear();
|
||||
}
|
||||
|
||||
void MdnsBrowser::browseForServiceType(const QByteArray& serviceType)
|
||||
@@ -38,11 +38,11 @@ void MdnsBrowser::browseForServiceType(const QByteArray& serviceType)
|
||||
if (!_browsedServiceTypes.contains(serviceType))
|
||||
{
|
||||
DebugIf(verboseBrowser, _log, "Start new mDNS browser for serviceType [%s], Thread: %s", serviceType.constData(), QSTRING_CSTR(QThread::currentThread()->objectName()));
|
||||
QMdnsEngine::Browser* newBrowser = new QMdnsEngine::Browser(&_server, serviceType, &_cache);
|
||||
QSharedPointer<QMdnsEngine::Browser> newBrowser = QSharedPointer<QMdnsEngine::Browser>::create(&_server, serviceType, &_cache);
|
||||
|
||||
QObject::connect(newBrowser, &QMdnsEngine::Browser::serviceAdded, this, &MdnsBrowser::onServiceAdded);
|
||||
QObject::connect(newBrowser, &QMdnsEngine::Browser::serviceUpdated, this, &MdnsBrowser::onServiceUpdated);
|
||||
QObject::connect(newBrowser, &QMdnsEngine::Browser::serviceRemoved, this, &MdnsBrowser::onServiceRemoved);
|
||||
QObject::connect(newBrowser.get(), &QMdnsEngine::Browser::serviceAdded, this, &MdnsBrowser::onServiceAdded);
|
||||
QObject::connect(newBrowser.get(), &QMdnsEngine::Browser::serviceUpdated, this, &MdnsBrowser::onServiceUpdated);
|
||||
QObject::connect(newBrowser.get(), &QMdnsEngine::Browser::serviceRemoved, this, &MdnsBrowser::onServiceRemoved);
|
||||
|
||||
_browsedServiceTypes.insert(serviceType, newBrowser);
|
||||
}
|
||||
@@ -124,8 +124,8 @@ QHostAddress MdnsBrowser::getHostFirstAddress(const QByteArray& hostname)
|
||||
{
|
||||
DebugIf(verboseBrowser, _log, "IP-address for hostname [%s] not yet in cache, start resolver.", toBeResolvedHostName.constData());
|
||||
qRegisterMetaType<QMdnsEngine::Message>("Message");
|
||||
auto* resolver = new QMdnsEngine::Resolver(&_server, toBeResolvedHostName, &_cache);
|
||||
connect(resolver, &QMdnsEngine::Resolver::resolved, this, &MdnsBrowser::onHostNameResolved);
|
||||
_resolver.reset(new QMdnsEngine::Resolver(&_server, toBeResolvedHostName, &_cache));
|
||||
connect(_resolver.get(), &QMdnsEngine::Resolver::resolved, this, &MdnsBrowser::onHostNameResolved);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ void MdnsBrowser::onHostNameResolved(const QHostAddress& address)
|
||||
|
||||
bool MdnsBrowser::resolveAddress(Logger* log, const QString& hostname, QHostAddress& hostAddress, std::chrono::milliseconds timeout)
|
||||
{
|
||||
DebugIf(verboseBrowser, _log, "Get address for hostname [%s], Thread: %s", QSTRING_CSTR(hostname), QSTRING_CSTR(QThread::currentThread()->objectName()));
|
||||
DebugIf(verboseBrowser, log, "Get address for hostname [%s], Thread: %s", QSTRING_CSTR(hostname), QSTRING_CSTR(QThread::currentThread()->objectName()));
|
||||
|
||||
bool isHostAddressOK{ false };
|
||||
if (hostname.endsWith(".local") || hostname.endsWith(".local."))
|
||||
@@ -158,20 +158,20 @@ bool MdnsBrowser::resolveAddress(Logger* log, const QString& hostname, QHostAddr
|
||||
|
||||
if (hostAddress.isNull())
|
||||
{
|
||||
DebugIf(verboseBrowser, _log, "Wait for resolver on hostname [%s]", QSTRING_CSTR(hostname));
|
||||
DebugIf(verboseBrowser, log, "Wait for resolver on hostname [%s]", QSTRING_CSTR(hostname));
|
||||
|
||||
QEventLoop loop;
|
||||
QTimer t;
|
||||
QObject::connect(&MdnsBrowser::getInstance(), &MdnsBrowser::addressResolved, &loop, &QEventLoop::quit);
|
||||
QTimer timer;
|
||||
|
||||
QObject::connect(&MdnsBrowser::getInstance(), &MdnsBrowser::addressResolved, &loop, &QEventLoop::quit);
|
||||
weakConnect(&MdnsBrowser::getInstance(), &MdnsBrowser::addressResolved,
|
||||
[&hostAddress, hostname](const QHostAddress& resolvedAddress) {
|
||||
DebugIf(verboseBrowser, Logger::getInstance("MDNS"), "Resolver resolved hostname [%s] to address [%s], Thread: %s", QSTRING_CSTR(hostname), QSTRING_CSTR(resolvedAddress.toString()), QSTRING_CSTR(QThread::currentThread()->objectName()));
|
||||
[&hostAddress, hostname, log](const QHostAddress& resolvedAddress) {
|
||||
DebugIf(verboseBrowser, log, "Resolver resolved hostname [%s] to address [%s], Thread: %s", QSTRING_CSTR(hostname), QSTRING_CSTR(resolvedAddress.toString()), QSTRING_CSTR(QThread::currentThread()->objectName()));
|
||||
hostAddress = resolvedAddress;
|
||||
});
|
||||
|
||||
QTimer::connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
t.start(static_cast<int>(timeout.count()));
|
||||
QTimer::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
timer.start(static_cast<int>(timeout.count()));
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
@@ -206,8 +206,8 @@ QMdnsEngine::Record MdnsBrowser::getServiceInstanceRecord(const QByteArray& serv
|
||||
}
|
||||
|
||||
QMdnsEngine::Record srvRecord;
|
||||
bool found{ false };
|
||||
int retries = 5;
|
||||
bool found { false };
|
||||
int retries { SERVICE_LOOKUP_RETRIES };
|
||||
do
|
||||
{
|
||||
if (_cache.lookupRecord(service, QMdnsEngine::SRV, srvRecord))
|
||||
@@ -393,10 +393,10 @@ QJsonArray MdnsBrowser::getServicesDiscoveredJson(const QByteArray& serviceType,
|
||||
QMap<QByteArray, QByteArray> txtAttributes = txtRecord.attributes();
|
||||
|
||||
QVariantMap txtMap;
|
||||
QMapIterator<QByteArray, QByteArray> i(txtAttributes);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
txtMap.insert(i.key(), i.value());
|
||||
QMapIterator<QByteArray, QByteArray> iterator(txtAttributes);
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
txtMap.insert(iterator.key(), iterator.value());
|
||||
}
|
||||
obj.insert("txt", QJsonObject::fromVariantMap(txtMap));
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <mdns/MdnsProvider.h>
|
||||
#include <mdns/MdnsServiceRegister.h>
|
||||
|
||||
//Qt includes
|
||||
// Qt includes
|
||||
#include <QHostInfo>
|
||||
#include <QThread>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace {
|
||||
const bool verboseProvider = false;
|
||||
} //End of constants
|
||||
} // End of constants
|
||||
|
||||
MdnsProvider::MdnsProvider(QObject* parent)
|
||||
: QObject(parent)
|
||||
@@ -24,58 +24,59 @@ MdnsProvider::MdnsProvider(QObject* parent)
|
||||
|
||||
void MdnsProvider::init()
|
||||
{
|
||||
_server = new QMdnsEngine::Server();
|
||||
_hostname = new QMdnsEngine::Hostname(_server);
|
||||
_server.reset(new QMdnsEngine::Server());
|
||||
_hostname.reset(new QMdnsEngine::Hostname(_server.data()));
|
||||
|
||||
connect(_hostname, &QMdnsEngine::Hostname::hostnameChanged, this, &MdnsProvider::onHostnameChanged);
|
||||
connect(_hostname.data(), &QMdnsEngine::Hostname::hostnameChanged, this, &MdnsProvider::onHostnameChanged);
|
||||
DebugIf(verboseProvider, _log, "Hostname [%s], isRegistered [%d]", _hostname->hostname().constData(), _hostname->isRegistered());
|
||||
}
|
||||
|
||||
MdnsProvider::~MdnsProvider()
|
||||
{
|
||||
qDeleteAll(_providedServiceTypes);
|
||||
|
||||
_hostname->deleteLater();
|
||||
_server->deleteLater();
|
||||
_providedServiceTypes.clear();
|
||||
}
|
||||
|
||||
void MdnsProvider::publishService(const QString& serviceType, quint16 servicePort, const QByteArray& serviceName)
|
||||
{
|
||||
QMdnsEngine::Provider* provider(nullptr);
|
||||
|
||||
QByteArray type = MdnsServiceRegister::getServiceType(serviceType);
|
||||
|
||||
if (!type.isEmpty())
|
||||
{
|
||||
DebugIf(verboseProvider, _log, "Publish new mDNS serviceType [%s], Thread: %s", type.constData(), QSTRING_CSTR(QThread::currentThread()->objectName()));
|
||||
|
||||
if (!_providedServiceTypes.contains(type))
|
||||
{
|
||||
provider = new QMdnsEngine::Provider(_server, _hostname);
|
||||
_providedServiceTypes.insert(type, provider);
|
||||
QSharedPointer<QMdnsEngine::Provider> newProvider = QSharedPointer<QMdnsEngine::Provider>::create(_server.data(), _hostname.data());
|
||||
_providedServiceTypes.insert(type, newProvider);
|
||||
|
||||
}
|
||||
|
||||
QSharedPointer<QMdnsEngine::Provider> provider = _providedServiceTypes.value(type);
|
||||
if (!provider.isNull())
|
||||
{
|
||||
QMdnsEngine::Service service;
|
||||
service.setType(type);
|
||||
service.setPort(servicePort);
|
||||
|
||||
QByteArray name(QHostInfo::localHostName().toUtf8());
|
||||
if (!serviceName.isEmpty())
|
||||
{
|
||||
name.prepend(serviceName + "@");
|
||||
}
|
||||
service.setName(name);
|
||||
|
||||
QByteArray uuid = AuthManager::getInstance()->getID().toUtf8();
|
||||
const QMap<QByteArray, QByteArray> attributes = {{"id", uuid}, {"version", HYPERION_VERSION}};
|
||||
service.setAttributes(attributes);
|
||||
|
||||
DebugIf(verboseProvider, _log, "[%s], Name: [%s], Port: [%u] ", service.type().constData(), service.name().constData(), service.port());
|
||||
|
||||
provider->update(service);
|
||||
}
|
||||
else
|
||||
{
|
||||
provider = _providedServiceTypes[type];
|
||||
Error(_log, "Not able to get hold of mDNS serviceType [%s]", type.constData());
|
||||
}
|
||||
|
||||
QMdnsEngine::Service service;
|
||||
service.setType(type);
|
||||
service.setPort(servicePort);
|
||||
|
||||
QByteArray name(QHostInfo::localHostName().toUtf8());
|
||||
if (!serviceName.isEmpty())
|
||||
{
|
||||
name.prepend(serviceName + "@");
|
||||
}
|
||||
service.setName(name);
|
||||
|
||||
QByteArray id = AuthManager::getInstance()->getID().toUtf8();
|
||||
const QMap<QByteArray, QByteArray> attributes = { {"id", id}, {"version", HYPERION_VERSION} };
|
||||
service.setAttributes(attributes);
|
||||
|
||||
DebugIf(verboseProvider, _log, "[%s], Name: [%s], Port: [%u] ", service.type().constData(), service.name().constData(), service.port());
|
||||
|
||||
provider->update(service);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -159,10 +159,8 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#ifdef HAVE_TURBO_JPEG
|
||||
case PixelFormat::MJPEG:
|
||||
break;
|
||||
#endif
|
||||
case PixelFormat::NO_CHANGE:
|
||||
Error(Logger::getInstance("ImageResampler"), "Invalid pixel format given");
|
||||
break;
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#include <utils/FileUtils.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <syslog.h>
|
||||
@@ -15,7 +14,8 @@
|
||||
#include <QFileInfo>
|
||||
#include <QMutexLocker>
|
||||
#include <QThreadStorage>
|
||||
#include <time.h>
|
||||
#include <QJsonObject>
|
||||
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QRecursiveMutex Logger::MapLock;
|
||||
@@ -38,6 +38,7 @@ const size_t MAX_IDENTIFICATION_LENGTH = 22;
|
||||
QAtomicInteger<unsigned int> LoggerCount = 0;
|
||||
QAtomicInteger<unsigned int> LoggerId = 0;
|
||||
|
||||
const int MAX_LOG_MSG_BUFFERED = 500;
|
||||
const int MaxRepeatCountSize = 200;
|
||||
QThreadStorage<int> RepeatCount;
|
||||
QThreadStorage<Logger::T_LOG_MESSAGE> RepeatMessage;
|
||||
@@ -51,8 +52,7 @@ Logger* Logger::getInstance(const QString & name, const QString & subName, Logge
|
||||
if (log == nullptr)
|
||||
{
|
||||
log = new Logger(name, subName, minLevel);
|
||||
LoggerMap.insert(name, log); // compat version, replace it with following line if we have 100% c++11
|
||||
//LoggerMap.emplace(name, log); // not compat with older linux distro's e.g. wheezy
|
||||
LoggerMap.insert(name + subName, log);
|
||||
connect(log, &Logger::newLogMessage, LoggerManager::getInstance(), &LoggerManager::handleNewLogMessage);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ Logger::LogLevel Logger::getLogLevel(const QString & name, const QString & subNa
|
||||
Logger::Logger (const QString & name, const QString & subName, LogLevel minLevel)
|
||||
: QObject()
|
||||
, _name(name)
|
||||
, _subname(subName)
|
||||
, _subName(subName)
|
||||
, _syslogEnabled(true)
|
||||
, _loggerId(LoggerId++)
|
||||
, _minLevel(static_cast<int>(minLevel))
|
||||
@@ -161,7 +161,7 @@ void Logger::write(const Logger::T_LOG_MESSAGE & message)
|
||||
.toStdString()
|
||||
<< std::endl;
|
||||
|
||||
newLogMessage(message);
|
||||
emit newLogMessage(message);
|
||||
}
|
||||
|
||||
void Logger::Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...)
|
||||
@@ -195,7 +195,7 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u
|
||||
};
|
||||
|
||||
if (RepeatMessage.localData().loggerName == _name &&
|
||||
RepeatMessage.localData().loggerSubName == _subname &&
|
||||
RepeatMessage.localData().loggerSubName == _subName &&
|
||||
RepeatMessage.localData().function == func &&
|
||||
RepeatMessage.localData().message == msg &&
|
||||
RepeatMessage.localData().line == line)
|
||||
@@ -213,7 +213,7 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u
|
||||
Logger::T_LOG_MESSAGE logMsg;
|
||||
|
||||
logMsg.loggerName = _name;
|
||||
logMsg.loggerSubName = _subname;
|
||||
logMsg.loggerSubName = _subName;
|
||||
logMsg.function = QString(func);
|
||||
logMsg.line = line;
|
||||
logMsg.fileName = FileUtils::getBaseName(sourceFile);
|
||||
@@ -233,11 +233,36 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u
|
||||
|
||||
LoggerManager::LoggerManager()
|
||||
: QObject()
|
||||
, _loggerMaxMsgBufferSize(200)
|
||||
, _loggerMaxMsgBufferSize(MAX_LOG_MSG_BUFFERED)
|
||||
{
|
||||
_logMessageBuffer.reserve(_loggerMaxMsgBufferSize);
|
||||
}
|
||||
|
||||
QJsonArray LoggerManager::getLogMessageBuffer(Logger::LogLevel filter) const
|
||||
{
|
||||
QJsonArray messageArray;
|
||||
{
|
||||
for (const auto &logLine : std::as_const(_logMessageBuffer))
|
||||
{
|
||||
if (logLine.level >= filter)
|
||||
{
|
||||
QJsonObject message;
|
||||
message["loggerName"] = logLine.loggerName;
|
||||
message["loggerSubName"] = logLine.loggerSubName;
|
||||
message["function"] = logLine.function;
|
||||
message["line"] = QString::number(logLine.line);
|
||||
message["fileName"] = logLine.fileName;
|
||||
message["message"] = logLine.message;
|
||||
message["levelString"] = logLine.levelString;
|
||||
message["utime"] = QString::number(logLine.utime);
|
||||
|
||||
messageArray.append(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return messageArray;
|
||||
}
|
||||
|
||||
void LoggerManager::handleNewLogMessage(const Logger::T_LOG_MESSAGE & msg)
|
||||
{
|
||||
_logMessageBuffer.push_back(msg);
|
||||
|
@@ -1,16 +1,14 @@
|
||||
#include <utils/RgbChannelAdjustment.h>
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(QString channelName)
|
||||
: _channelName(channelName)
|
||||
, _log(Logger::getInstance(channelName))
|
||||
, _brightness(0)
|
||||
: RgbChannelAdjustment(0, 0, 0, channelName)
|
||||
{
|
||||
resetInitialized();
|
||||
}
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName)
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName )
|
||||
: _channelName(channelName)
|
||||
, _log(Logger::getInstance(channelName))
|
||||
, _log(Logger::getInstance("CHANNEL_" + channelName.toUpper()))
|
||||
, _brightness(0)
|
||||
{
|
||||
setAdjustment(adjustR, adjustG, adjustB);
|
||||
}
|
||||
|
@@ -2,13 +2,15 @@
|
||||
#include <utils/RgbTransform.h>
|
||||
|
||||
RgbTransform::RgbTransform()
|
||||
: RgbTransform::RgbTransform(1.0, 1.0, 1.0, 0.0, false, 100, 100)
|
||||
{
|
||||
init(1.0, 1.0, 1.0, 0.0, false, 100, 100);
|
||||
}
|
||||
|
||||
RgbTransform::RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation)
|
||||
: _brightness(brightness)
|
||||
, _brightnessCompensation(brightnessCompensation)
|
||||
{
|
||||
init(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness, brightnessCompensation);
|
||||
init(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, _brightness, _brightnessCompensation);
|
||||
}
|
||||
|
||||
void RgbTransform::init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation)
|
||||
|
@@ -16,6 +16,13 @@ namespace {
|
||||
const char HTTPS_SERVICE_TYPE[] = "https";
|
||||
const char HYPERION_SERVICENAME[] = "Hyperion";
|
||||
|
||||
const char WEBSERVER_DEFAULT_PATH[] = ":/webconfig";
|
||||
const char WEBSERVER_DEFAULT_CRT_PATH[] = ":/hyperion.crt";
|
||||
const char WEBSERVER_DEFAULT_KEY_PATH[] = ":/hyperion.key";
|
||||
|
||||
quint16 WEBSERVER_DEFAULT_PORT = 8090;
|
||||
quint16 WBSERVERR_DEFAULT_SSL_PORT = 8092;
|
||||
|
||||
} //End of constants
|
||||
|
||||
WebServer::WebServer(const QJsonDocument& config, bool useSsl, QObject* parent)
|
||||
@@ -23,6 +30,7 @@ WebServer::WebServer(const QJsonDocument& config, bool useSsl, QObject* parent)
|
||||
, _config(config)
|
||||
, _useSsl(useSsl)
|
||||
, _log(Logger::getInstance("WEBSERVER"))
|
||||
, _port(WEBSERVER_DEFAULT_PORT)
|
||||
, _server()
|
||||
{
|
||||
}
|
||||
@@ -41,7 +49,6 @@ void WebServer::initServer()
|
||||
if (_useSsl)
|
||||
{
|
||||
_server->setUseSecure();
|
||||
WEBSERVER_DEFAULT_PORT = 8092;
|
||||
}
|
||||
|
||||
connect(_server, &QtHttpServer::started, this, &WebServer::onServerStarted);
|
||||
@@ -111,7 +118,7 @@ void WebServer::handleSettingsUpdate(settings::type type, const QJsonDocument& c
|
||||
_staticFileServing->setBaseUrl(_baseUrl);
|
||||
|
||||
// ssl different port
|
||||
quint16 newPort = _useSsl ? obj["sslPort"].toInt(WEBSERVER_DEFAULT_PORT) : obj["port"].toInt(WEBSERVER_DEFAULT_PORT);
|
||||
quint16 newPort = _useSsl ? obj["sslPort"].toInt(WBSERVERR_DEFAULT_SSL_PORT) : obj["port"].toInt(WEBSERVER_DEFAULT_PORT);
|
||||
if (_port != newPort)
|
||||
{
|
||||
_port = newPort;
|
||||
|
Reference in New Issue
Block a user