diff --git a/include/dispmanx-grabber/DispmanxWrapper.h b/include/dispmanx-grabber/DispmanxWrapper.h index 6dc433cd..b5487945 100644 --- a/include/dispmanx-grabber/DispmanxWrapper.h +++ b/include/dispmanx-grabber/DispmanxWrapper.h @@ -55,10 +55,10 @@ public slots: void stop(); /// - /// \brief Set the grabbing mode - /// \param mode The new grabbing mode + /// Set the grabbing mode + /// @param[in] mode The new grabbing mode /// - void setGrabbingMode(GrabbingMode mode); + void setGrabbingMode(const GrabbingMode mode); private: /// The update rate [Hz] diff --git a/include/utils/GrabbingMode.h b/include/utils/GrabbingMode.h index 7e7a8786..fe3b09ee 100644 --- a/include/utils/GrabbingMode.h +++ b/include/utils/GrabbingMode.h @@ -1,8 +1,13 @@ #pragma once +/** + * Enumeration of the possible modes in which frame-grabbing is performed. + */ enum GrabbingMode { + /** Frame grabbing is switched off */ GRABBINGMODE_OFF, + /** Frame grabbing during video */ GRABBINGMODE_VIDEO, GRABBINGMODE_PHOTO, GRABBINGMODE_AUDIO, diff --git a/libsrc/dispmanx-grabber/DispmanxFrameGrabber.cpp b/libsrc/dispmanx-grabber/DispmanxFrameGrabber.cpp index d497b876..204346fe 100644 --- a/libsrc/dispmanx-grabber/DispmanxFrameGrabber.cpp +++ b/libsrc/dispmanx-grabber/DispmanxFrameGrabber.cpp @@ -1,9 +1,22 @@ #include "DispmanxFrameGrabber.h" +// Because the shapshot function is incompatible between versions (use of different enum as +// third argument) and no proper version number is available as preprocessor define we cast the +// function to the same function with the third argument as 'int'. +// This way we can call the function in both versions of the VideoCore library without +// switching. +static int my_vc_dispmanx_snapshot(DISPMANX_DISPLAY_HANDLE_T display, DISPMANX_RESOURCE_HANDLE_T snapshot_resource, int transform) +{ + typedef int (*SnapshotFunctionPtr)(DISPMANX_DISPLAY_HANDLE_T, DISPMANX_RESOURCE_HANDLE_T, int); + SnapshotFunctionPtr snapshot = (SnapshotFunctionPtr) &vc_dispmanx_snapshot; + return (*snapshot)(display, snapshot_resource, transform); +} + DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned height) : _vc_display(0), _vc_resource(0), + _vc_flags(0), _width(width), _height(height) { @@ -50,6 +63,11 @@ DispmanxFrameGrabber::~DispmanxFrameGrabber() bcm_host_deinit(); } +void DispmanxFrameGrabber::setFlags(const int vc_flags) +{ + _vc_flags = vc_flags; +} + void DispmanxFrameGrabber::grabFrame(RgbImage& image) { // Sanity check of the given image size @@ -59,7 +77,7 @@ void DispmanxFrameGrabber::grabFrame(RgbImage& image) _vc_display = vc_dispmanx_display_open(0); // Create the snapshot (incl down-scaling) - vc_dispmanx_snapshot(_vc_display, _vc_resource, VC_IMAGE_ROT0); + my_vc_dispmanx_snapshot(_vc_display, _vc_resource, _vc_flags); // Read the snapshot into the memory void* image_ptr = image.memptr(); diff --git a/libsrc/dispmanx-grabber/DispmanxFrameGrabber.h b/libsrc/dispmanx-grabber/DispmanxFrameGrabber.h index 50c90ce4..fee6be91 100644 --- a/libsrc/dispmanx-grabber/DispmanxFrameGrabber.h +++ b/libsrc/dispmanx-grabber/DispmanxFrameGrabber.h @@ -26,6 +26,13 @@ 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); + /// /// 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,8 +53,12 @@ private: /// Rectangle of the captured resource that is transfered to user space VC_RECT_T _rectangle; + /// Flags (transforms) for creating snapshots + int _vc_flags; + /// With of the captured snapshot [pixels] unsigned _width; /// Height of the captured snapshot [pixels] unsigned _height; + }; diff --git a/libsrc/dispmanx-grabber/DispmanxWrapper.cpp b/libsrc/dispmanx-grabber/DispmanxWrapper.cpp index f04e3dce..ba4bd1f1 100644 --- a/libsrc/dispmanx-grabber/DispmanxWrapper.cpp +++ b/libsrc/dispmanx-grabber/DispmanxWrapper.cpp @@ -61,10 +61,23 @@ void DispmanxWrapper::stop() _timer.stop(); } -void DispmanxWrapper::setGrabbingMode(GrabbingMode mode) +void DispmanxWrapper::setGrabbingMode(const GrabbingMode mode) { - if (mode == GRABBINGMODE_VIDEO) + switch (mode) + { + case GRABBINGMODE_VIDEO: + _frameGrabber->setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL); start(); - else + case GRABBINGMODE_AUDIO: + case GRABBINGMODE_PHOTO: + case GRABBINGMODE_MENU: + _frameGrabber->setFlags(0); + start(); + break; + case GRABBINGMODE_OFF: stop(); + break; + case GRABBINGMODE_INVALID: + break; + } }