mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	Logging for dispmanx, framebuffer, x11, v4l2, osx (#103)
* dispmanx * typi * Framebuffer * fix attempt * x11 * osx * V4L2
This commit is contained in:
		@@ -11,6 +11,7 @@
 | 
			
		||||
#include <utils/Image.h>
 | 
			
		||||
#include <utils/ColorRgba.h>
 | 
			
		||||
#include <utils/VideoMode.h>
 | 
			
		||||
#include <utils/Logger.h>
 | 
			
		||||
 | 
			
		||||
///
 | 
			
		||||
/// The DispmanxFrameGrabber is used for creating snapshots of the display (screenshots) with a
 | 
			
		||||
@@ -84,4 +85,6 @@ private:
 | 
			
		||||
 | 
			
		||||
	// size of the capture buffer in Pixels
 | 
			
		||||
	unsigned _captureBufferSize;
 | 
			
		||||
	
 | 
			
		||||
	Logger * _log;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@
 | 
			
		||||
#include <utils/ColorRgb.h>
 | 
			
		||||
#include <utils/VideoMode.h>
 | 
			
		||||
#include <utils/ImageResampler.h>
 | 
			
		||||
#include <utils/Logger.h>
 | 
			
		||||
 | 
			
		||||
///
 | 
			
		||||
/// The FramebufferFrameGrabber is used for creating snapshots of the display (screenshots) 
 | 
			
		||||
@@ -56,4 +57,6 @@ private:
 | 
			
		||||
 | 
			
		||||
	/// Image resampler for downscaling the image
 | 
			
		||||
	ImageResampler * _imgResampler;
 | 
			
		||||
	
 | 
			
		||||
	Logger * _log;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
#include <utils/ColorRgb.h>
 | 
			
		||||
#include <utils/VideoMode.h>
 | 
			
		||||
#include <utils/ImageResampler.h>
 | 
			
		||||
#include <utils/Logger.h>
 | 
			
		||||
 | 
			
		||||
///
 | 
			
		||||
/// The OsxFrameGrabber is used for creating snapshots of the display (screenshots) 
 | 
			
		||||
@@ -56,4 +57,6 @@ private:
 | 
			
		||||
	
 | 
			
		||||
	/// Image resampler for downscaling the image
 | 
			
		||||
	ImageResampler * _imgResampler;
 | 
			
		||||
	
 | 
			
		||||
	Logger * _log;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@
 | 
			
		||||
#include <utils/PixelFormat.h>
 | 
			
		||||
#include <utils/VideoMode.h>
 | 
			
		||||
#include <utils/ImageResampler.h>
 | 
			
		||||
#include <utils/Logger.h>
 | 
			
		||||
 | 
			
		||||
// grabber includes
 | 
			
		||||
#include <grabber/VideoStandard.h>
 | 
			
		||||
@@ -122,4 +123,6 @@ private:
 | 
			
		||||
	QSocketNotifier * _streamNotifier;
 | 
			
		||||
 | 
			
		||||
	ImageResampler _imageResampler;
 | 
			
		||||
	
 | 
			
		||||
	Logger * _log;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,8 @@ DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned
 | 
			
		||||
	_cropTop(0),
 | 
			
		||||
	_cropBottom(0),
 | 
			
		||||
	_captureBuffer(new ColorRgba[0]),
 | 
			
		||||
	_captureBufferSize(0)
 | 
			
		||||
	_captureBufferSize(0),
 | 
			
		||||
	_log(Logger::getInstance("DISPMANXGRABBER"))
 | 
			
		||||
{
 | 
			
		||||
	// Initiase BCM
 | 
			
		||||
	bcm_host_init();
 | 
			
		||||
@@ -35,7 +36,7 @@ DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned
 | 
			
		||||
		// Keep compiler happy in 'release' mode
 | 
			
		||||
		(void)result;
 | 
			
		||||
		assert(result == 0);
 | 
			
		||||
		std::cout << "DISPMANXGRABBER INFO: Display opened with resolution: " << vc_info.width << "x" << vc_info.height << std::endl;
 | 
			
		||||
		Info(_log, "Display opened with resolution: %dx%d", vc_info.width, vc_info.height);
 | 
			
		||||
 | 
			
		||||
		// Close the displaye
 | 
			
		||||
		vc_dispmanx_display_close(_vc_display);
 | 
			
		||||
@@ -79,13 +80,7 @@ void DispmanxFrameGrabber::setCropping(unsigned cropLeft, unsigned cropRight, un
 | 
			
		||||
{
 | 
			
		||||
	if (cropLeft + cropRight >= _width || cropTop + cropBottom >= _height)
 | 
			
		||||
	{
 | 
			
		||||
		std::cout
 | 
			
		||||
			<< "DISPMANXGRABBER ERROR: Rejecting invalid crop values"
 | 
			
		||||
			<< " left: " << cropLeft
 | 
			
		||||
			<< " right: " << cropRight
 | 
			
		||||
			<< " top: " << cropTop
 | 
			
		||||
			<< " bottom: " << cropBottom
 | 
			
		||||
			<< std::endl;
 | 
			
		||||
		Error(_log, "Rejecting invalid crop values: left: %d, right: %d, top: %d, bottom: %d", cropLeft, cropRight, cropTop, cropBottom);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	_cropLeft = cropLeft;
 | 
			
		||||
@@ -95,13 +90,7 @@ void DispmanxFrameGrabber::setCropping(unsigned cropLeft, unsigned cropRight, un
 | 
			
		||||
 | 
			
		||||
	if (cropLeft > 0 || cropRight > 0 || cropTop > 0 || cropBottom > 0)
 | 
			
		||||
	{
 | 
			
		||||
		std::cout
 | 
			
		||||
			<< "DISPMANXGRABBER INFO: Cropping " << _width << "x" << _height << " image"
 | 
			
		||||
			<< " left: " << cropLeft
 | 
			
		||||
			<< " right: " << cropRight
 | 
			
		||||
			<< " top: " << cropTop
 | 
			
		||||
			<< " bottom: " << cropBottom
 | 
			
		||||
			<< std::endl;
 | 
			
		||||
		Info(_log, "Cropping image: width=%d height=%d; crop: left=%d right=%d top=%d bottom=%d ", _width, _height, cropLeft, cropRight, cropTop, cropBottom);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -151,7 +140,7 @@ void DispmanxFrameGrabber::grabFrame(Image<ColorRgba> & image)
 | 
			
		||||
	_vc_display = vc_dispmanx_display_open(0);
 | 
			
		||||
	if (_vc_display < 0)
 | 
			
		||||
	{
 | 
			
		||||
		std::cout << "DISPMANXGRABBER ERROR: Cannot open display: " << _vc_display << std::endl;
 | 
			
		||||
		Error(_log, "Cannot open display: %d", _vc_display);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -159,7 +148,7 @@ void DispmanxFrameGrabber::grabFrame(Image<ColorRgba> & image)
 | 
			
		||||
	ret = vc_dispmanx_snapshot(_vc_display, _vc_resource, (DISPMANX_TRANSFORM_T) _vc_flags);
 | 
			
		||||
	if (ret < 0)
 | 
			
		||||
	{
 | 
			
		||||
		std::cout << "DISPMANXGRABBER ERROR: Snapshot failed: " << ret << std::endl;
 | 
			
		||||
		Error(_log, "Snapshot failed: %d", ret);
 | 
			
		||||
		vc_dispmanx_display_close(_vc_display);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
@@ -193,7 +182,7 @@ void DispmanxFrameGrabber::grabFrame(Image<ColorRgba> & image)
 | 
			
		||||
	ret = vc_dispmanx_resource_read_data(_vc_resource, &_rectangle, capturePtr, capturePitch);
 | 
			
		||||
	if (ret < 0)
 | 
			
		||||
	{
 | 
			
		||||
		std::cout << "DISPMANXGRABBER ERROR: vc_dispmanx_resource_read_data failed: " << ret << std::endl;
 | 
			
		||||
		Error(_log, "vc_dispmanx_resource_read_data failed: %d", ret);
 | 
			
		||||
		vc_dispmanx_display_close(_vc_display);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,8 @@ FramebufferFrameGrabber::FramebufferFrameGrabber(const std::string & device, con
 | 
			
		||||
	_fbDevice(device),
 | 
			
		||||
	_width(width),
 | 
			
		||||
	_height(height),
 | 
			
		||||
	_imgResampler(new ImageResampler())
 | 
			
		||||
	_imgResampler(new ImageResampler()),
 | 
			
		||||
	_log(Logger::getInstance("FRAMEBUFFERGRABBER"))
 | 
			
		||||
{
 | 
			
		||||
	int result;
 | 
			
		||||
	struct fb_var_screeninfo vinfo;
 | 
			
		||||
@@ -27,7 +28,7 @@ FramebufferFrameGrabber::FramebufferFrameGrabber(const std::string & device, con
 | 
			
		||||
	_fbfd = open(_fbDevice.c_str(), O_RDONLY);
 | 
			
		||||
	if (_fbfd == 0)
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr << "FRAMEBUFFERGRABBER ERROR: Error openning " << _fbDevice << std::endl;
 | 
			
		||||
		Error(_log, "Error openning %s", _fbDevice.c_str());
 | 
			
		||||
	}
 | 
			
		||||
	else 
 | 
			
		||||
	{
 | 
			
		||||
@@ -35,11 +36,11 @@ FramebufferFrameGrabber::FramebufferFrameGrabber(const std::string & device, con
 | 
			
		||||
		result = ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);
 | 
			
		||||
		if (result != 0)
 | 
			
		||||
		{
 | 
			
		||||
			std::cerr << "FRAMEBUFFERGRABBER ERROR: Could not get screen information" << std::endl;
 | 
			
		||||
			Error(_log, "Could not get screen information");
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			std::cout << "FRAMEBUFFERGRABBER INFO: opened with resolution: " << vinfo.xres << "x" << vinfo.yres << "@" << vinfo.bits_per_pixel << "bit" << std::endl;			
 | 
			
		||||
			Error(_log, "Display opened with resolution: %dx%d@%dbit", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);			
 | 
			
		||||
		}
 | 
			
		||||
		close(_fbfd);
 | 
			
		||||
	}
 | 
			
		||||
@@ -84,7 +85,7 @@ void FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr << "FRAMEBUFFERGRABBER ERROR: Unknown pixel format: " << vinfo.bits_per_pixel << " bits per pixel" << std::endl;
 | 
			
		||||
		Error(_log, "Unknown pixel format: %d bits per pixel", vinfo.bits_per_pixel);
 | 
			
		||||
		close(_fbfd);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,8 @@ OsxFrameGrabber::OsxFrameGrabber(const unsigned display, const unsigned width, c
 | 
			
		||||
	_screenIndex(display),
 | 
			
		||||
	_width(width),
 | 
			
		||||
	_height(height),
 | 
			
		||||
	_imgResampler(new ImageResampler())
 | 
			
		||||
	_imgResampler(new ImageResampler()),
 | 
			
		||||
	_log(Logger::getInstance("OSXGRABBER"))
 | 
			
		||||
{
 | 
			
		||||
	CGImageRef image;
 | 
			
		||||
	CGDisplayCount displayCount;
 | 
			
		||||
@@ -19,7 +20,7 @@ OsxFrameGrabber::OsxFrameGrabber(const unsigned display, const unsigned width, c
 | 
			
		||||
	CGGetActiveDisplayList(8, displays, &displayCount);
 | 
			
		||||
	if (_screenIndex + 1 > displayCount)
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr << "OSXGRABBER ERROR: display with index " << _screenIndex << " is not available. Using main display" << std::endl;
 | 
			
		||||
		Error(_log, "Display with index %d is not available. Using main display", _screenIndex);
 | 
			
		||||
		_display = kCGDirectMainDisplay;
 | 
			
		||||
	} else {
 | 
			
		||||
		_display = displays[_screenIndex];
 | 
			
		||||
@@ -28,7 +29,7 @@ OsxFrameGrabber::OsxFrameGrabber(const unsigned display, const unsigned width, c
 | 
			
		||||
	image = CGDisplayCreateImage(_display);
 | 
			
		||||
	assert(image != NULL);
 | 
			
		||||
 | 
			
		||||
	std::cout << "OSXGRABBER INFO: display opened with resolution: " << CGImageGetWidth(image) << "x" << CGImageGetHeight(image) << "@" << CGImageGetBitsPerPixel(image) << "bit" << std::endl;
 | 
			
		||||
	Info(_log, "Display opened with resolution: %dx%d@%dbit", CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerPixel(image));
 | 
			
		||||
 | 
			
		||||
	CGImageRelease(image);
 | 
			
		||||
}
 | 
			
		||||
@@ -59,7 +60,7 @@ void OsxFrameGrabber::grabFrame(Image<ColorRgb> & image)
 | 
			
		||||
		// no displays connected, return
 | 
			
		||||
		if (dispImage == NULL)
 | 
			
		||||
		{
 | 
			
		||||
			std::cerr << "OSXGRABBER ERROR: no display connected..." << std::endl;
 | 
			
		||||
			Error(_log, "No display connected...");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,8 @@ V4L2Grabber::V4L2Grabber(const std::string & device,
 | 
			
		||||
	_currentFrame(0),
 | 
			
		||||
	_noSignalCounter(0),
 | 
			
		||||
	_streamNotifier(nullptr),
 | 
			
		||||
	_imageResampler()
 | 
			
		||||
	_imageResampler(),
 | 
			
		||||
	_log(Logger::getInstance("V4L2GRABBER"))
 | 
			
		||||
{
 | 
			
		||||
	_imageResampler.setHorizontalPixelDecimation(std::max(1, horizontalPixelDecimation));
 | 
			
		||||
	_imageResampler.setVerticalPixelDecimation(std::max(1, verticalPixelDecimation));
 | 
			
		||||
@@ -76,7 +77,7 @@ void V4L2Grabber::setSignalThreshold(double redSignalThreshold, double greenSign
 | 
			
		||||
	_noSignalThresholdColor.blue = uint8_t(255*blueSignalThreshold);
 | 
			
		||||
	_noSignalCounterThreshold = std::max(1, noSignalCounterThreshold);
 | 
			
		||||
 | 
			
		||||
	std::cout << "V4L2GRABBER INFO: signal threshold set to: " << _noSignalThresholdColor << std::endl;
 | 
			
		||||
	Info(_log, "Signal threshold set to: %d", _noSignalThresholdColor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void V4L2Grabber::start()
 | 
			
		||||
@@ -85,7 +86,7 @@ void V4L2Grabber::start()
 | 
			
		||||
	{
 | 
			
		||||
		_streamNotifier->setEnabled(true);
 | 
			
		||||
		start_capturing();
 | 
			
		||||
		std::cout << "V4L2GRABBER INFO: started" << std::endl;
 | 
			
		||||
		Info(_log, "Started");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -95,7 +96,7 @@ void V4L2Grabber::stop()
 | 
			
		||||
	{
 | 
			
		||||
		stop_capturing();
 | 
			
		||||
		_streamNotifier->setEnabled(false);
 | 
			
		||||
		std::cout << "V4L2GRABBER INFO: stopped" << std::endl;
 | 
			
		||||
		Info(_log, "Stopped");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -420,17 +421,17 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
 | 
			
		||||
	case V4L2_PIX_FMT_UYVY:
 | 
			
		||||
		_pixelFormat = PIXELFORMAT_UYVY;
 | 
			
		||||
		_frameByteSize = _width * _height * 2;
 | 
			
		||||
		std::cout << "V4L2GRABBER INFO: pixel format=UYVY" << std::endl;
 | 
			
		||||
		Debug(_log, "Pixel format=UYVY");
 | 
			
		||||
		break;
 | 
			
		||||
	case V4L2_PIX_FMT_YUYV:
 | 
			
		||||
		_pixelFormat = PIXELFORMAT_YUYV;
 | 
			
		||||
		_frameByteSize = _width * _height * 2;
 | 
			
		||||
		std::cout << "V4L2GRABBER INFO: pixel format=YUYV" << std::endl;
 | 
			
		||||
		Debug(_log, "Pixel format=YUYV");
 | 
			
		||||
		break;
 | 
			
		||||
	case V4L2_PIX_FMT_RGB32:
 | 
			
		||||
		_pixelFormat = PIXELFORMAT_RGB32;
 | 
			
		||||
		_frameByteSize = _width * _height * 4;
 | 
			
		||||
		std::cout << "V4L2GRABBER INFO: pixel format=RGB32" << std::endl;
 | 
			
		||||
		Debug(_log, "Pixel format=RGB32");
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		throw_exception("V4L2GRABBER ERROR: Only pixel formats UYVY, YUYV, and RGB32 are supported");
 | 
			
		||||
@@ -653,7 +654,7 @@ bool V4L2Grabber::process_image(const void *p, int size)
 | 
			
		||||
 | 
			
		||||
		if (size != _frameByteSize)
 | 
			
		||||
		{
 | 
			
		||||
			std::cout << "V4L2GRABBER ERROR: Frame too small: " << size << " != " << _frameByteSize << std::endl;
 | 
			
		||||
			Error(_log, "Frame too small: %d != %d", size, _frameByteSize);
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
@@ -694,7 +695,7 @@ void V4L2Grabber::process_image(const uint8_t * data)
 | 
			
		||||
	{
 | 
			
		||||
		if (_noSignalCounter >= _noSignalCounterThreshold)
 | 
			
		||||
		{
 | 
			
		||||
			std::cout << "V4L2GRABBER INFO: " << "Signal detected" << std::endl;
 | 
			
		||||
			Info(_log, "Signal detected");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		_noSignalCounter = 0;
 | 
			
		||||
@@ -706,7 +707,7 @@ void V4L2Grabber::process_image(const uint8_t * data)
 | 
			
		||||
	}
 | 
			
		||||
	else if (_noSignalCounter == _noSignalCounterThreshold)
 | 
			
		||||
	{
 | 
			
		||||
		std::cout << "V4L2GRABBER INFO: " << "Signal lost" << std::endl;
 | 
			
		||||
		Info(_log, "Signal lost");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -177,7 +177,7 @@ int X11Grabber::updateScreenDimensions()
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	std::cout << "X11GRABBER INFO: Update of screen resolution: [" << _screenWidth << "x" << _screenHeight <<"] => ";
 | 
			
		||||
	Info(_log, "Update of screen resolution: [%dx%d]", _screenWidth, _screenHeight);
 | 
			
		||||
 | 
			
		||||
	if (_screenWidth || _screenHeight) {
 | 
			
		||||
		freeResources();
 | 
			
		||||
@@ -186,7 +186,7 @@ int X11Grabber::updateScreenDimensions()
 | 
			
		||||
	_screenWidth  = _windowAttr.width;
 | 
			
		||||
	_screenHeight = _windowAttr.height;
 | 
			
		||||
	
 | 
			
		||||
	std::cout << "[" << _screenWidth << "x" << _screenHeight <<"]" << std::endl;
 | 
			
		||||
	Info(_log, " to [%dx%d]", _screenWidth, _screenHeight);
 | 
			
		||||
	
 | 
			
		||||
	_croppedWidth  =  (_screenWidth > unsigned(_cropLeft + _cropRight))
 | 
			
		||||
		? (_screenWidth - _cropLeft - _cropRight)
 | 
			
		||||
@@ -196,12 +196,10 @@ int X11Grabber::updateScreenDimensions()
 | 
			
		||||
		? (_screenHeight - _cropTop - _cropBottom)
 | 
			
		||||
		: _screenHeight;
 | 
			
		||||
 | 
			
		||||
	std::cout << "X11GRABBER INFO: Using ";
 | 
			
		||||
 | 
			
		||||
	if (_XRenderAvailable && !_useXGetImage) {
 | 
			
		||||
		std::cout << "XRender for grabbing" << std::endl;
 | 
			
		||||
		Info(_log, "Using XRender for grabbing");
 | 
			
		||||
	} else {
 | 
			
		||||
		std::cout << "XGetImage for grabbing" << std::endl;
 | 
			
		||||
		Info(_log, "Using XGetImage for grabbing");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	setupResources();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user