hyperion.ng/libsrc/hyperion/Grabber.cpp

155 lines
3.7 KiB
C++
Raw Normal View History

#include <hyperion/Grabber.h>
Grabber::Grabber(const QString& grabberName, int width, int height, int cropLeft, int cropRight, int cropTop, int cropBottom)
: _grabberName(grabberName)
, _imageResampler()
, _useImageResampler(true)
, _videoMode(VideoMode::VIDEO_2D)
, _videoStandard(VideoStandard::NO_CHANGE)
, _pixelDecimation(8)
, _flipMode(FlipMode::NO_CHANGE)
, _width(width)
, _height(height)
, _fps(15)
, _fpsSoftwareDecimation(0)
2020-06-17 20:55:57 +02:00
, _input(-1)
, _cropLeft(0)
, _cropRight(0)
, _cropTop(0)
, _cropBottom(0)
, _enabled(true)
, _log(Logger::getInstance(_grabberName.toUpper()))
{
Grabber::setCropping(cropLeft, cropRight, cropTop, cropBottom);
}
void Grabber::setEnabled(bool enable)
{
Info(_log,"Capture interface is now %s", enable ? "enabled" : "disabled");
_enabled = enable;
}
void Grabber::setVideoMode(VideoMode mode)
{
2021-01-27 18:55:21 +01:00
Debug(_log,"Set videomode to %s", QSTRING_CSTR(videoMode2String(mode)));
_videoMode = mode;
if ( _useImageResampler )
{
_imageResampler.setVideoMode(_videoMode);
}
}
void Grabber::setVideoStandard(VideoStandard videoStandard)
{
if (_videoStandard != videoStandard)
_videoStandard = videoStandard;
}
bool Grabber::setPixelDecimation(int pixelDecimation)
{
if (_pixelDecimation != pixelDecimation)
{
Debug(_log,"Set image size decimation to %d", pixelDecimation);
_pixelDecimation = pixelDecimation;
_imageResampler.setHorizontalPixelDecimation(pixelDecimation);
_imageResampler.setVerticalPixelDecimation(pixelDecimation);
return true;
}
return false;
}
void Grabber::setFlipMode(FlipMode mode)
{
Debug(_log,"Set flipmode to %s", QSTRING_CSTR(flipModeToString(mode)));
_flipMode = mode;
if ( _useImageResampler )
{
_imageResampler.setFlipMode(_flipMode);
}
}
void Grabber::setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom)
{
if (_width>0 && _height>0)
{
if (cropLeft + cropRight >= (unsigned)_width || cropTop + cropBottom >= (unsigned)_height)
{
2018-12-27 23:11:32 +01:00
Error(_log, "Rejecting invalid crop values: left: %d, right: %d, top: %d, bottom: %d, higher than height/width %d/%d", cropLeft, cropRight, cropTop, cropBottom, _height, _width);
return;
}
}
_cropLeft = cropLeft;
_cropRight = cropRight;
_cropTop = cropTop;
_cropBottom = cropBottom;
if ( _useImageResampler )
{
_imageResampler.setCropping(cropLeft, cropRight, cropTop, cropBottom);
}
else
{
_imageResampler.setCropping(0, 0, 0, 0);
}
if (cropLeft > 0 || cropRight > 0 || cropTop > 0 || cropBottom > 0)
{
Info(_log, "Cropping image: width=%d height=%d; crop: left=%d right=%d top=%d bottom=%d ", _width, _height, cropLeft, cropRight, cropTop, cropBottom);
}
}
2018-12-27 23:11:32 +01:00
2020-06-17 20:55:57 +02:00
bool Grabber::setInput(int input)
{
if((input >= 0) && (_input != input))
{
_input = input;
return true;
}
return false;
}
bool Grabber::setWidthHeight(int width, int height)
2018-12-27 23:11:32 +01:00
{
// eval changes with crop
if ( (width>0 && height>0) && (_width != width || _height != height) )
2018-12-27 23:11:32 +01:00
{
if (_cropLeft + _cropRight >= width || _cropTop + _cropBottom >= height)
{
Error(_log, "Rejecting invalid width/height values as it collides with image cropping: width: %d, height: %d", width, height);
return false;
2018-12-27 23:11:32 +01:00
}
2021-01-27 18:55:21 +01:00
Debug(_log, "Set new width: %d, height: %d for capture", width, height);
2018-12-27 23:11:32 +01:00
_width = width;
_height = height;
return true;
2018-12-27 23:11:32 +01:00
}
return false;
2018-12-27 23:11:32 +01:00
}
bool Grabber::setFramerate(int fps)
{
if((fps > 0) && (_fps != fps))
2020-06-17 20:55:57 +02:00
{
Debug(_log,"Set new frames per second to: %i fps", fps);
_fps = fps;
2020-06-17 20:55:57 +02:00
return true;
}
2020-06-17 20:55:57 +02:00
return false;
}
void Grabber::setFpsSoftwareDecimation(int decimation)
{
if((_fpsSoftwareDecimation != decimation))
{
_fpsSoftwareDecimation = decimation;
if(decimation > 0)
Debug(_log,"Skip %i frame per second", decimation);
}
}