implement set videomode via json api (#457)

* implement set videomode via json api

* refactor grabbers:
- new base class
- move shared code to base class

* fix osx

* rework all cmakelist files with auto file collection. except leddevices (need further restructuring)

* store current video and grabbing mode

* add json stuff

* remove grabbingmode - we do not want to expose it
This commit is contained in:
redPanther
2017-08-04 23:08:15 +02:00
committed by GitHub
parent 3612ccda75
commit 569e59110e
54 changed files with 375 additions and 659 deletions

View File

@@ -1,18 +1,14 @@
#pragma once
// STL includes
#include <cstdint>
#include <utils/Logger.h>
// Utils includes
#include <utils/Image.h>
#include <utils/ColorBgr.h>
#include <utils/VideoMode.h>
#include <hyperion/Grabber.h>
///
/// The DispmanxFrameGrabber is used for creating snapshots of the display (screenshots) with a
/// downsized and scaled resolution.
///
class AmlogicGrabber
class AmlogicGrabber : public Grabber
{
public:
///
@@ -24,12 +20,6 @@ public:
AmlogicGrabber(const unsigned width, const unsigned height);
~AmlogicGrabber();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
///
/// Captures a single snapshot of the display and writes the data to the given image. The
/// provided image should have the same dimensions as the configured values (_width and
@@ -47,14 +37,6 @@ public:
*/
bool isVideoPlaying();
private:
/// With of the captured snapshot [pixels]
const unsigned _width;
/// Height of the captured snapshot [pixels]
const unsigned _height;
/** The snapshot/capture device of the amlogic video chip */
int _amlogicCaptureDev;
Logger * _log;
};

View File

@@ -42,11 +42,7 @@ public slots:
///
virtual void action();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
virtual void setVideoMode(const VideoMode mode);
private:
/// The update rate [Hz]

View File

@@ -4,20 +4,15 @@
#pragma GCC system_header
#include <bcm_host.h>
// STL includes
#include <cstdint>
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgba.h>
#include <utils/VideoMode.h>
#include <utils/Logger.h>
#include <hyperion/Grabber.h>
///
/// The DispmanxFrameGrabber is used for creating snapshots of the display (screenshots) with a
/// downsized and scaled resolution.
///
class DispmanxFrameGrabber
class DispmanxFrameGrabber : public Grabber
{
public:
///
@@ -36,12 +31,6 @@ public:
///
void setFlags(const int vc_flags);
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
void setCropping(const unsigned cropLeft, const unsigned cropRight,
const unsigned cropTop, const unsigned cropBottom);
@@ -68,23 +57,10 @@ private:
/// Flags (transforms) for creating snapshots
int _vc_flags;
/// With of the captured snapshot [pixels]
const unsigned _width;
/// Height of the captured snapshot [pixels]
const unsigned _height;
// the selected VideoMode
VideoMode _videoMode;
// number of pixels to crop after capturing
unsigned _cropLeft, _cropRight, _cropTop, _cropBottom;
// temp buffer when capturing with unsupported pitch size or
// when we need to crop the image
ColorRgba* _captureBuffer;
// size of the capture buffer in Pixels
unsigned _captureBufferSize;
Logger * _log;
};

View File

@@ -1,16 +1,13 @@
#pragma once
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/VideoMode.h>
#include <utils/ImageResampler.h>
#include <utils/Logger.h>
#include <hyperion/Grabber.h>
///
/// The FramebufferFrameGrabber is used for creating snapshots of the display (screenshots)
///
class FramebufferFrameGrabber
class FramebufferFrameGrabber : public Grabber
{
public:
///
@@ -23,12 +20,6 @@ public:
FramebufferFrameGrabber(const QString & device, const unsigned width, const unsigned height);
~FramebufferFrameGrabber();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
///
/// Captures a single snapshot of the display and writes the data to the given image. The
/// provided image should have the same dimensions as the configured values (_width and
@@ -48,15 +39,4 @@ private:
/// Framebuffer device e.g. /dev/fb0
const QString _fbDevice;
/// With of the captured snapshot [pixels]
const unsigned _width;
/// Height of the captured snapshot [pixels]
const unsigned _height;
/// Image resampler for downscaling the image
ImageResampler * _imgResampler;
Logger * _log;
};

View File

@@ -4,16 +4,13 @@
#include <CoreGraphics/CoreGraphics.h>
// Utils includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/VideoMode.h>
#include <utils/ImageResampler.h>
#include <utils/Logger.h>
#include <hyperion/Grabber.h>
///
/// The OsxFrameGrabber is used for creating snapshots of the display (screenshots)
///
class OsxFrameGrabber
class OsxFrameGrabber : public Grabber
{
public:
///
@@ -26,12 +23,6 @@ public:
OsxFrameGrabber(const unsigned display, const unsigned width, const unsigned height);
~OsxFrameGrabber();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
///
/// Captures a single snapshot of the display and writes the data to the given image. The
/// provided image should have the same dimensions as the configured values (_width and
@@ -46,17 +37,6 @@ private:
/// display
const unsigned _screenIndex;
/// With of the captured snapshot [pixels]
const unsigned _width;
/// Height of the captured snapshot [pixels]
const unsigned _height;
/// Reference to the captured diaplay
CGDirectDisplayID _display;
/// Image resampler for downscaling the image
ImageResampler * _imgResampler;
Logger * _log;
};

View File

@@ -10,12 +10,9 @@
#include <QRectF>
// util includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/PixelFormat.h>
#include <utils/VideoMode.h>
#include <utils/ImageResampler.h>
#include <utils/Logger.h>
#include <hyperion/Grabber.h>
// grabber includes
#include <grabber/VideoStandard.h>
@@ -23,7 +20,7 @@
/// Capture class for V4L2 devices
///
/// @see http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html
class V4L2Grabber : public QObject
class V4L2Grabber : public Grabber
{
Q_OBJECT
@@ -48,8 +45,6 @@ public slots:
int cropTop,
int cropBottom);
void set3D(VideoMode mode);
void setSignalThreshold(
double redSignalThreshold,
double greenSignalThreshold,
@@ -124,18 +119,16 @@ private:
private:
QString _deviceName;
std::map<QString,QString> _v4lDevices;
int _input;
VideoStandard _videoStandard;
io_method _ioMethod;
int _fileDescriptor;
int _input;
VideoStandard _videoStandard;
io_method _ioMethod;
int _fileDescriptor;
std::vector<buffer> _buffers;
PixelFormat _pixelFormat;
int _width;
int _height;
int _lineLength;
int _frameByteSize;
int _frameDecimation;
int _lineLength;
int _frameByteSize;
int _frameDecimation;
// signal detection
int _noSignalCounterThreshold;
@@ -151,11 +144,6 @@ private:
QSocketNotifier * _streamNotifier;
ImageResampler _imageResampler;
Logger * _log;
bool _initialized;
bool _deviceAutoDiscoverEnabled;
};

View File

@@ -24,7 +24,8 @@ public:
double redSignalThreshold,
double greenSignalThreshold,
double blueSignalThreshold,
const int priority);
const int priority,
bool useGrabbingMode);
virtual ~V4L2Wrapper();
bool getSignalDetectionEnable();
@@ -35,7 +36,7 @@ public slots:
void setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom);
void setSignalDetectionOffset(double verticalMin, double horizontalMin, double verticalMax, double horizontalMax);
void set3D(VideoMode mode);
void setVideoMode(VideoMode mode);
void setSignalDetectionEnable(bool enable);
// signals:

View File

@@ -1,9 +1,11 @@
#pragma once
#include <QObject>
// Hyperion-utils includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/ImageResampler.h>
#include <utils/Logger.h>
#include <hyperion/Grabber.h>
// X11 includes
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
@@ -11,7 +13,7 @@
#include <sys/ipc.h>
#include <sys/shm.h>
class X11Grabber
class X11Grabber : public Grabber
{
public:
@@ -19,12 +21,6 @@ public:
virtual ~X11Grabber();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(const VideoMode videoMode);
bool Setup();
Image<ColorRgb> & grab();
@@ -43,21 +39,9 @@ public:
/// update dimension according current screen
int updateScreenDimensions();
/// gets resulting height of image
const unsigned getImageWidth() { return _croppedWidth; };
/// gets resulting width of image
const unsigned getImageHeight() { return _croppedHeight; };
private:
ImageResampler _imageResampler;
bool _useXGetImage, _XShmAvailable, _XShmPixmapAvailable, _XRenderAvailable;
int _cropLeft;
int _cropRight;
int _cropTop;
int _cropBottom;
XImage* _xImage;
XShmSegmentInfo _shminfo;
@@ -79,14 +63,9 @@ private:
unsigned _screenWidth;
unsigned _screenHeight;
unsigned _croppedWidth;
unsigned _croppedHeight;
Image<ColorRgb> _image;
void freeResources();
void setupResources();
Logger * _log;
};

View File

@@ -17,7 +17,6 @@ class ImageProcessor;
///
class X11Wrapper: public GrabberWrapper
{
Q_OBJECT
public:
///
/// Constructs the framebuffer frame grabber with a specified grab size and update rate.

View File

@@ -0,0 +1,53 @@
#pragma once
#include <QObject>
#include <cstdint>
#include <utils/Image.h>
#include <utils/VideoMode.h>
#include <utils/GrabbingMode.h>
#include <utils/ImageResampler.h>
#include <utils/Logger.h>
class Grabber : public QObject
{
Q_OBJECT
public:
Grabber(QString grabberName, int width=0, int height=0, int cropLeft=0, int cropRight=0, int cropTop=0, int cropBottom=0);
~Grabber();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(VideoMode mode);
/// gets resulting height of image
const int getImageWidth() { return _width; };
/// gets resulting width of image
const int getImageHeight() { return _height; };
protected:
ImageResampler _imageResampler;
/// the selected VideoMode
VideoMode _videoMode;
/// With of the captured snapshot [pixels]
int _width;
/// Height of the captured snapshot [pixels]
int _height;
// number of pixels to crop after capturing
int _cropLeft, _cropRight, _cropTop, _cropBottom;
/// logger instance
Logger * _log;
};

View File

@@ -46,6 +46,13 @@ public slots:
///
void setGrabbingMode(const GrabbingMode mode);
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
virtual void setVideoMode(const VideoMode videoMode) = 0;
signals:
void emitImage(int priority, const Image<ColorRgb> & image, const int timeout_ms);

View File

@@ -21,6 +21,8 @@
#include <utils/ColorRgb.h>
#include <utils/Logger.h>
#include <utils/Components.h>
#include <utils/VideoMode.h>
#include <utils/GrabbingMode.h>
// Hyperion includes
#include <hyperion/LedString.h>
@@ -192,6 +194,9 @@ public:
/// forward smoothing config
unsigned addSmoothingConfig(int settlingTime_ms, double ledUpdateFrequency_hz=25.0, unsigned updateDelay=0);
VideoMode getCurrentVideoMode() { return _videoMode; };
GrabbingMode getCurrentGrabbingMode() { return _grabbingMode; };
public slots:
///
/// Writes a single color to all the leds for the given time and priority
@@ -280,6 +285,19 @@ public slots:
/// Slot which is called, when state of hyperion has been changed
void hyperionStateChanged();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(VideoMode mode);
///
/// Set the grabbing mode
/// @param[in] mode The new grabbing mode
///
void setGrabbingMode(const GrabbingMode mode);
public:
static Hyperion *_hyperion;
@@ -324,6 +342,11 @@ signals:
/// Signal which is emitted, after the hyperionStateChanged has been processed with a emit count blocker (250ms interval)
void sendServerInfo();
/// Signal emitted when a 3D movie is detected
void videoMode(VideoMode mode);
void grabbingMode(GrabbingMode mode);
private slots:
///
/// Updates the priority muxer with the current time and (re)writes the led color with applied
@@ -432,4 +455,7 @@ private:
/// timers to handle severinfo blocking
QTimer _fsi_timer;
QTimer _fsi_blockTimer;
VideoMode _videoMode;
GrabbingMode _grabbingMode;
};

View File

@@ -1,5 +1,7 @@
#pragma once
#include <QString>
/**
* Enumeration of the possible modes in which frame-grabbing is performed.
*/
@@ -16,3 +18,18 @@ enum GrabbingMode
GRABBINGMODE_SCREENSAVER,
GRABBINGMODE_INVALID
};
inline QString grabbingMode2String(GrabbingMode mode)
{
switch(mode)
{
case GRABBINGMODE_OFF: return "OFF";
case GRABBINGMODE_VIDEO: return "VIDEO";
case GRABBINGMODE_PAUSE: return "PAUSE";
case GRABBINGMODE_PHOTO: return "PHOTO";
case GRABBINGMODE_AUDIO: return "AUDIO";
case GRABBINGMODE_MENU: return "MENU";
case GRABBINGMODE_SCREENSAVER: return "SCREENSAVER";
default: return "INVALID";
}
}

View File

@@ -244,6 +244,12 @@ private:
///
void handleProcessingCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON VideoMode message
///
/// @param message the incoming message
///
void handleVideoModeCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON message of unknown type
///

View File

@@ -14,8 +14,8 @@ enum VideoMode
inline VideoMode parse3DMode(QString videoMode)
{
// convert to lower case
videoMode = videoMode.toLower();
// convert to upper case
videoMode = videoMode.toUpper();
if (videoMode == "3DTAB")
{
@@ -29,3 +29,14 @@ inline VideoMode parse3DMode(QString videoMode)
// return the default 2D
return VIDEO_2D;
}
inline QString videoMode2String(VideoMode mode)
{
switch(mode)
{
case VIDEO_3DTAB: return "3DTAB";
case VIDEO_3DSBS: return "3DSBS";
case VIDEO_2D: return "2D";
default: return "INVALID";
}
}