grabber api and feature unification (#462)

* 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
This commit is contained in:
redPanther
2017-08-12 07:55:32 +02:00
committed by GitHub
parent 317a903b14
commit 9eff6384cc
61 changed files with 830 additions and 748 deletions

View File

@@ -29,14 +29,17 @@ public:
/// height)
/// @return Zero on success else negative
///
int grabFrame(Image<ColorBgr> & image);
int grabFrame(Image<ColorRgb> & image);
private:
/**
* Returns true if video is playing over the amlogic chip
* @return True if video is playing else false
*/
bool isVideoPlaying();
private:
/** The snapshot/capture device of the amlogic video chip */
int _amlogicCaptureDev;
Image<ColorBgr> _image;
};

View File

@@ -1,16 +1,7 @@
#pragma once
// Utils includes
#include <utils/Image.h>
#include <utils/ColorBgr.h>
#include <utils/ColorRgb.h>
#include <utils/VideoMode.h>
#include <hyperion/GrabberWrapper.h>
// Forward class declaration
class AmlogicGrabber;
class Hyperion;
class ImageProcessor;
#include <grabber/AmlogicGrabber.h>
///
/// The DispmanxWrapper uses an instance of the DispmanxFrameGrabber to obtain ImageRgb's from the
@@ -34,7 +25,7 @@ public:
///
/// Destructor of this dispmanx frame grabber. Releases any claimed resources.
///
virtual ~AmlogicWrapper();
virtual ~AmlogicWrapper() {};
public slots:
///
@@ -42,19 +33,7 @@ public slots:
///
virtual void action();
virtual void setVideoMode(const VideoMode mode);
private:
/// The update rate [Hz]
const int _updateInterval_ms;
/// The timeout of the led colors [ms]
const int _timeout_ms;
/// The image used for grabbing frames
Image<ColorBgr> _image;
/// The actual grabber
AmlogicGrabber * _grabber;
/// The list with computed led colors
std::vector<ColorRgb> _ledColors;
AmlogicGrabber _grabber;
};

View File

@@ -1,10 +1,15 @@
#pragma once
// BCM includes
#pragma GCC system_header
#include <bcm_host.h>
#ifdef PLATFORM_RPI
#pragma GCC system_header
#include <bcm_host.h>
#else
#include <grabber/DispmanxFrameGrabberMock.h>
#endif
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgba.h>
#include <hyperion/Grabber.h>
@@ -24,15 +29,6 @@ public:
DispmanxFrameGrabber(const unsigned width, const unsigned height);
~DispmanxFrameGrabber();
///
/// Updates the frame-grab flags as used by the VC library for frame grabbing
///
/// @param vc_flags The snapshot grabbing mask
///
void setFlags(const int vc_flags);
void setCropping(const unsigned cropLeft, const unsigned cropRight,
const unsigned cropTop, const unsigned cropBottom);
///
/// Captures a single snapshot of the display and writes the data to the given image. The
@@ -42,9 +38,16 @@ public:
/// @param[out] image The snapped screenshot (should be initialized with correct width and
/// height)
///
void grabFrame(Image<ColorRgba> & image);
int grabFrame(Image<ColorRgb> & image);
private:
///
/// Updates the frame-grab flags as used by the VC library for frame grabbing
///
/// @param vc_flags The snapshot grabbing mask
///
void setFlags(const int vc_flags);
/// Handle to the display that is being captured
DISPMANX_DISPLAY_HANDLE_T _vc_display;
@@ -63,4 +66,8 @@ private:
// size of the capture buffer in Pixels
unsigned _captureBufferSize;
// rgba output buffer
Image<ColorRgba> _image_rgba;
};

View File

@@ -0,0 +1,40 @@
#pragma once
#ifndef PLATFORM_RPI
#include <QRect>
#include <utils/Image.h>
#include <utils/ColorRgba.h>
typedef int DISPMANX_DISPLAY_HANDLE_T;
typedef Image<ColorRgba> DISPMANX_RESOURCE;
typedef DISPMANX_RESOURCE* DISPMANX_RESOURCE_HANDLE_T;
const int VC_IMAGE_RGBA32 = 1;
const int DISPMANX_SNAPSHOT_FILL = 1;
typedef int DISPMANX_TRANSFORM_T;
struct DISPMANX_MODEINFO_T {
int width;
int height;
};
struct VC_RECT_T {
int left;
int top;
int width;
int height;
};
void bcm_host_init();
void bcm_host_deinit();
int vc_dispmanx_display_open(int);
void vc_dispmanx_display_close(int);
int vc_dispmanx_display_get_info(int, DISPMANX_MODEINFO_T *vc_info);
DISPMANX_RESOURCE_HANDLE_T vc_dispmanx_resource_create(int,int width,int height, uint32_t *);
void vc_dispmanx_resource_delete(DISPMANX_RESOURCE_HANDLE_T resource);
int vc_dispmanx_resource_read_data(DISPMANX_RESOURCE_HANDLE_T vc_resource, VC_RECT_T *rectangle, void* capturePtr, unsigned capturePitch);
void vc_dispmanx_rect_set(VC_RECT_T *rectangle, int left, int top, int width, int height);
int vc_dispmanx_snapshot(int, DISPMANX_RESOURCE_HANDLE_T resource, int vc_flags);
#endif

View File

@@ -1,16 +1,9 @@
#pragma once
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/ColorRgba.h>
#include <utils/GrabbingMode.h>
#include <utils/VideoMode.h>
#include <hyperion/GrabberWrapper.h>
// Forward class declaration
class DispmanxFrameGrabber;
class ImageProcessor;
#include <grabber/DispmanxFrameGrabber.h>
///
/// The DispmanxWrapper uses an instance of the DispmanxFrameGrabber to obtain ImageRgb's from the
@@ -34,7 +27,7 @@ public:
///
/// Destructor of this dispmanx frame grabber. Releases any claimed resources.
///
virtual ~DispmanxWrapper();
virtual ~DispmanxWrapper() {};
public slots:
///
@@ -42,25 +35,7 @@ public slots:
///
virtual void action();
void setCropping(const unsigned cropLeft, const unsigned cropRight, const unsigned cropTop, const unsigned cropBottom);
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
private:
/// The update rate [Hz]
const int _updateInterval_ms;
/// The timeout of the led colors [ms]
const int _timeout_ms;
/// The image used for grabbing frames
Image<ColorRgba> _image;
/// The actual grabber
DispmanxFrameGrabber * _grabber;
/// The list with computed led colors
std::vector<ColorRgb> _ledColors;
DispmanxFrameGrabber _grabber;
};

View File

@@ -28,7 +28,7 @@ public:
/// @param[out] image The snapped screenshot (should be initialized with correct width and
/// height)
///
void grabFrame(Image<ColorRgb> & image);
int grabFrame(Image<ColorRgb> & image);
private:
/// Framebuffer file descriptor

View File

@@ -1,15 +1,7 @@
#pragma once
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/GrabbingMode.h>
#include <utils/VideoMode.h>
#include <hyperion/GrabberWrapper.h>
// Forward class declaration
class FramebufferFrameGrabber;
class ImageProcessor;
#include <grabber/FramebufferFrameGrabber.h>
///
/// The FramebufferWrapper uses an instance of the FramebufferFrameGrabber to obtain ImageRgb's from the
@@ -33,7 +25,7 @@ public:
///
/// Destructor of this framebuffer frame grabber. Releases any claimed resources.
///
virtual ~FramebufferWrapper();
virtual ~FramebufferWrapper() {};
public slots:
///
@@ -41,23 +33,7 @@ public slots:
///
virtual void action();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
private:
/// The update rate [Hz]
const int _updateInterval_ms;
/// The timeout of the led colors [ms]
const int _timeout_ms;
/// The image used for grabbing frames
Image<ColorRgb> _image;
/// The actual grabber
FramebufferFrameGrabber * _grabber;
/// The list with computed led colors
std::vector<ColorRgb> _ledColors;
FramebufferFrameGrabber _grabber;
};

View File

@@ -1,7 +1,11 @@
#pragma once
// OSX includes
#ifdef __APPLE__
#include <CoreGraphics/CoreGraphics.h>
#else
#include <grabber/OsxFrameGrabberMock.h>
#endif
// Utils includes
#include <utils/ColorRgb.h>
@@ -31,7 +35,7 @@ public:
/// @param[out] image The snapped screenshot (should be initialized with correct width and
/// height)
///
void grabFrame(Image<ColorRgb> & image);
int grabFrame(Image<ColorRgb> & image);
private:
/// display

View File

@@ -0,0 +1,34 @@
#pragma once
#ifndef __APPLE__
/*
* this is a mock up for compiling and testing osx wrapper on no osx platform.
* this will show a test image and rotate the colors.
*
*/
#include <utils/Image.h>
#include <utils/ColorRgb.h>
typedef int CGDirectDisplayID;
typedef Image<ColorRgb> CGImage;
typedef CGImage* CGImageRef;
typedef unsigned char CFData;
typedef CFData* CFDataRef;
typedef unsigned CGDisplayCount;
const int kCGDirectMainDisplay = 0;
void CGGetActiveDisplayList(int max, CGDirectDisplayID *displays, CGDisplayCount *displayCount);
CGImageRef CGDisplayCreateImage(CGDirectDisplayID display);
void CGImageRelease(CGImageRef image);
CGImageRef CGImageGetDataProvider(CGImageRef image);
CFDataRef CGDataProviderCopyData(CGImageRef image);
unsigned char* CFDataGetBytePtr(CFDataRef imgData);
unsigned CGImageGetWidth(CGImageRef image);
unsigned CGImageGetHeight(CGImageRef image);
unsigned CGImageGetBitsPerPixel(CGImageRef image);
unsigned CGImageGetBytesPerRow(CGImageRef image);
void CFRelease(CFDataRef imgData);
#endif

View File

@@ -1,16 +1,7 @@
#pragma once
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/ColorRgba.h>
#include <utils/GrabbingMode.h>
#include <utils/VideoMode.h>
#include <hyperion/GrabberWrapper.h>
// Forward class declaration
class OsxFrameGrabber;
class ImageProcessor;
#include <grabber/OsxFrameGrabber.h>
///
/// The OsxWrapper uses an instance of the OsxFrameGrabber to obtain ImageRgb's from the
@@ -35,7 +26,7 @@ public:
///
/// Destructor of this osx frame grabber. Releases any claimed resources.
///
virtual ~OsxWrapper();
virtual ~OsxWrapper() {};
public slots:
///
@@ -43,23 +34,7 @@ public slots:
///
virtual void action();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
private:
/// The update rate [Hz]
const int _updateInterval_ms;
/// The timeout of the led colors [ms]
const int _timeout_ms;
/// The image used for grabbing frames
Image<ColorRgb> _image;
/// The actual grabber
OsxFrameGrabber * _grabber;
/// The list with computed led colors
std::vector<ColorRgb> _ledColors;
OsxFrameGrabber _grabber;
};

View File

@@ -10,11 +10,8 @@
#include <QRectF>
// util includes
#include <utils/ColorRgb.h>
#include <utils/PixelFormat.h>
#include <hyperion/Grabber.h>
// grabber includes
#include <grabber/VideoStandard.h>
/// Capture class for V4L2 devices
@@ -28,8 +25,8 @@ public:
V4L2Grabber(const QString & device,
int input,
VideoStandard videoStandard, PixelFormat pixelFormat,
int width,
int height,
unsigned width,
unsigned height,
int frameDecimation,
int horizontalPixelDecimation,
int verticalPixelDecimation
@@ -39,12 +36,9 @@ public:
QRectF getSignalDetectionOffset();
bool getSignalDetectionEnabled();
int grabFrame(Image<ColorRgb> &);
public slots:
void setCropping(int cropLeft,
int cropRight,
int cropTop,
int cropBottom);
void setSignalThreshold(
double redSignalThreshold,
double greenSignalThreshold,

View File

@@ -1,11 +1,6 @@
#pragma once
// Hyperion includes
#include <hyperion/Hyperion.h>
#include <hyperion/ImageProcessor.h>
#include <hyperion/GrabberWrapper.h>
// Grabber includes
#include <grabber/V4L2Grabber.h>
class V4L2Wrapper : public GrabberWrapper
@@ -17,8 +12,8 @@ public:
int input,
VideoStandard videoStandard,
PixelFormat pixelFormat,
int width,
int height,
unsigned width,
unsigned height,
int frameDecimation,
int pixelDecimation,
double redSignalThreshold,
@@ -26,7 +21,7 @@ public:
double blueSignalThreshold,
const int priority,
bool useGrabbingMode);
virtual ~V4L2Wrapper();
virtual ~V4L2Wrapper() {};
bool getSignalDetectionEnable();
@@ -36,7 +31,6 @@ public slots:
void setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom);
void setSignalDetectionOffset(double verticalMin, double horizontalMin, double verticalMax, double horizontalMax);
void setVideoMode(VideoMode mode);
void setSignalDetectionEnable(bool enable);
// signals:
@@ -50,12 +44,6 @@ private slots:
void checkSources();
private:
/// The timeout of the led colors [ms]
const int _timeout_ms;
/// The V4L2 grabber
V4L2Grabber _grabber;
/// The list with computed led colors
std::vector<ColorRgb> _ledColors;
};

View File

@@ -22,8 +22,6 @@ public:
virtual ~X11Grabber();
bool Setup();
Image<ColorRgb> & grab();
///
/// Captures a single snapshot of the display and writes the data to the given image. The
@@ -33,11 +31,13 @@ public:
/// @param[out] image The snapped screenshot (should be initialized with correct width and
/// height)
///
int grabFrame(Image<ColorRgb> & image);
virtual int grabFrame(Image<ColorRgb> & image, bool forceUpdate=false);
///
/// update dimension according current screen
int updateScreenDimensions();
int updateScreenDimensions(bool force=false);
virtual void setVideoMode(VideoMode mode);
private:
bool _useXGetImage, _XShmAvailable, _XShmPixmapAvailable, _XRenderAvailable;
@@ -63,6 +63,8 @@ private:
unsigned _screenWidth;
unsigned _screenHeight;
unsigned _src_x;
unsigned _src_y;
Image<ColorRgb> _image;

View File

@@ -1,14 +1,12 @@
#pragma once
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/VideoMode.h>
#include <hyperion/GrabberWrapper.h>
#include <grabber/X11Grabber.h>
// some include of xorg defines "None" this is also used by QT and has to be undefined to avoid collisions
#ifdef None
#undef None
#endif
// Forward class declaration
class X11Grabber;
class ImageProcessor;
///
/// The X11Wrapper uses an instance of the X11Grabber to obtain ImageRgb's from the
@@ -31,42 +29,18 @@ public:
///
/// Destructor of this framebuffer frame grabber. Releases any claimed resources.
///
virtual ~X11Wrapper();
virtual ~X11Wrapper() {};
public slots:
///
/// Starts the grabber wich produces led values with the specified update rate
///
bool start();
///
/// Performs a single frame grab and computes the led-colors
///
virtual void action();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
private:
/// The update rate [Hz]
const int _updateInterval_ms;
/// The timeout of the led colors [ms]
const int _timeout_ms;
/// The image used for grabbing frames
Image<ColorRgb> _image;
/// The actual grabber
X11Grabber * _grabber;
/// The list with computed led colors
std::vector<ColorRgb> _ledColors;
X11Grabber _grabber;
bool _init;
bool _x11SetupSuccess;
};