mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
* move setvideomode to common place * implement more croping and 3d support * more api unification * more refactoring * osx fix * next step * add a mock for osx grabber. Now it is possible to test compile on none osx platforms. * more unifications ... * remove obsolete includes and grabbers are not dyn allocated. dispmanx needs rework an probaly not work atm * first version of dispmanx mock. it compiles, but outputs a black image * now dispmanx mock works! * activate mocks in travis linux build prepare dispmanx to rgb image out * dispmanx now with image rgb output fix deadlock with w/h -1 in grabber v4l cleanups * fix json * fix some runtime stuff * Update FramebufferWrapper.cpp fix missing code * unify grabframe * 3d and croping for amlogic * fix setimage not working * make use of templates save some codelines * save more code lines
93 lines
2.3 KiB
C++
Executable File
93 lines
2.3 KiB
C++
Executable File
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <linux/fb.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
// STL includes
|
|
#include <iostream>
|
|
|
|
// Local includes
|
|
#include <grabber/FramebufferFrameGrabber.h>
|
|
|
|
FramebufferFrameGrabber::FramebufferFrameGrabber(const QString & device, const unsigned width, const unsigned height)
|
|
: Grabber("FRAMEBUFFERGRABBER", width, height)
|
|
, _fbfd(0)
|
|
, _fbp(0)
|
|
, _fbDevice(device)
|
|
{
|
|
int result;
|
|
struct fb_var_screeninfo vinfo;
|
|
|
|
// Check if the framebuffer device can be opened and display the current resolution
|
|
_fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
|
|
if (_fbfd == 0)
|
|
{
|
|
Error(_log, "Error openning %s", QSTRING_CSTR(_fbDevice));
|
|
}
|
|
else
|
|
{
|
|
// get variable screen information
|
|
result = ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);
|
|
if (result != 0)
|
|
{
|
|
Error(_log, "Could not get screen information");
|
|
}
|
|
else
|
|
{
|
|
Error(_log, "Display opened with resolution: %dx%d@%dbit", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
|
|
}
|
|
close(_fbfd);
|
|
}
|
|
}
|
|
|
|
FramebufferFrameGrabber::~FramebufferFrameGrabber()
|
|
{
|
|
}
|
|
|
|
int FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
|
|
{
|
|
struct fb_var_screeninfo vinfo;
|
|
unsigned capSize, bytesPerPixel;
|
|
PixelFormat pixelFormat;
|
|
|
|
/* Open the framebuffer device */
|
|
_fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
|
|
|
|
/* get variable screen information */
|
|
ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);
|
|
|
|
bytesPerPixel = vinfo.bits_per_pixel / 8;
|
|
capSize = vinfo.xres * vinfo.yres * bytesPerPixel;
|
|
|
|
switch (vinfo.bits_per_pixel)
|
|
{
|
|
case 16: pixelFormat = PIXELFORMAT_BGR16; break;
|
|
case 24: pixelFormat = PIXELFORMAT_BGR24; break;
|
|
case 32: pixelFormat = PIXELFORMAT_BGR32; break;
|
|
default:
|
|
Error(_log, "Unknown pixel format: %d bits per pixel", vinfo.bits_per_pixel);
|
|
close(_fbfd);
|
|
return -1;
|
|
}
|
|
|
|
/* map the device to memory */
|
|
_fbp = (unsigned char*)mmap(0, capSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, _fbfd, 0);
|
|
|
|
_imageResampler.setHorizontalPixelDecimation(vinfo.xres/_width);
|
|
_imageResampler.setVerticalPixelDecimation(vinfo.yres/_height);
|
|
_imageResampler.processImage(_fbp,
|
|
vinfo.xres,
|
|
vinfo.yres,
|
|
vinfo.xres * bytesPerPixel,
|
|
pixelFormat,
|
|
image);
|
|
|
|
munmap(_fbp, capSize);
|
|
close(_fbfd);
|
|
|
|
return 0;
|
|
}
|