2017-08-04 23:08:15 +02:00
|
|
|
#include <hyperion/Grabber.h>
|
|
|
|
|
|
|
|
|
|
|
|
Grabber::Grabber(QString grabberName, int width, int height, int cropLeft, int cropRight, int cropTop, int cropBottom)
|
|
|
|
: _imageResampler()
|
2017-08-12 07:55:32 +02:00
|
|
|
, _useImageResampler(true)
|
2020-06-28 23:05:32 +02:00
|
|
|
, _videoMode(VideoMode::VIDEO_2D)
|
2017-08-04 23:08:15 +02:00
|
|
|
, _width(width)
|
|
|
|
, _height(height)
|
2020-03-27 23:13:58 +01:00
|
|
|
, _fps(15)
|
2020-06-17 20:55:57 +02:00
|
|
|
, _input(-1)
|
2017-08-12 07:55:32 +02:00
|
|
|
, _cropLeft(0)
|
|
|
|
, _cropRight(0)
|
|
|
|
, _cropTop(0)
|
|
|
|
, _cropBottom(0)
|
2017-09-01 08:50:37 +02:00
|
|
|
, _enabled(true)
|
2017-08-04 23:08:15 +02:00
|
|
|
, _log(Logger::getInstance(grabberName))
|
|
|
|
{
|
2020-06-28 23:05:32 +02:00
|
|
|
Grabber::setVideoMode(VideoMode::VIDEO_2D);
|
2019-06-05 18:19:08 +02:00
|
|
|
Grabber::setCropping(cropLeft, cropRight, cropTop, cropBottom);
|
2017-08-04 23:08:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Grabber::~Grabber()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-01 08:50:37 +02:00
|
|
|
void Grabber::setEnabled(bool enable)
|
|
|
|
{
|
2018-12-28 18:12:45 +01:00
|
|
|
Info(_log,"Capture interface is now %s", enable ? "enabled" : "disabled");
|
2017-09-01 08:50:37 +02:00
|
|
|
_enabled = enable;
|
|
|
|
}
|
2017-08-04 23:08:15 +02:00
|
|
|
|
|
|
|
void Grabber::setVideoMode(VideoMode mode)
|
|
|
|
{
|
2018-12-28 18:12:45 +01:00
|
|
|
Debug(_log,"Set videomode to %d", mode);
|
2017-08-04 23:08:15 +02:00
|
|
|
_videoMode = mode;
|
2017-08-12 07:55:32 +02:00
|
|
|
if ( _useImageResampler )
|
|
|
|
{
|
|
|
|
_imageResampler.setVideoMode(_videoMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-08-12 07:55:32 +02:00
|
|
|
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);
|
|
|
|
}
|
2017-08-04 23:08:15 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-28 18:12:45 +01:00
|
|
|
bool Grabber::setWidthHeight(int width, int height)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
|
|
|
// eval changes with crop
|
2018-12-28 18:12:45 +01:00
|
|
|
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);
|
2018-12-28 18:12:45 +01:00
|
|
|
return false;
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
2018-12-28 18:12:45 +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;
|
2018-12-28 18:12:45 +01:00
|
|
|
return true;
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
2018-12-28 18:12:45 +01:00
|
|
|
return false;
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
2020-03-27 23:13:58 +01:00
|
|
|
|
|
|
|
bool Grabber::setFramerate(int fps)
|
|
|
|
{
|
2020-04-17 16:59:20 +02:00
|
|
|
if((fps > 0) && (_fps != fps))
|
2020-06-17 20:55:57 +02:00
|
|
|
{
|
2020-03-27 23:13:58 +01:00
|
|
|
_fps = fps;
|
2020-06-17 20:55:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-04-17 16:59:20 +02:00
|
|
|
|
2020-06-17 20:55:57 +02:00
|
|
|
return false;
|
2020-04-17 16:59:20 +02:00
|
|
|
}
|