Updated the snapshot creation based on the latest release of VideoCore (included backwards compatibility if correct)

Former-commit-id: 5bb8d6d7cd673ac8c08a2c9a8f1995231074d327
This commit is contained in:
T. van der Zwan 2013-10-02 07:46:12 +00:00
parent 2b4060c1b1
commit 79be6ea4a2
5 changed files with 54 additions and 7 deletions

View File

@ -55,10 +55,10 @@ public slots:
void stop(); void stop();
/// ///
/// \brief Set the grabbing mode /// Set the grabbing mode
/// \param mode The new grabbing mode /// @param[in] mode The new grabbing mode
/// ///
void setGrabbingMode(GrabbingMode mode); void setGrabbingMode(const GrabbingMode mode);
private: private:
/// The update rate [Hz] /// The update rate [Hz]

View File

@ -1,8 +1,13 @@
#pragma once #pragma once
/**
* Enumeration of the possible modes in which frame-grabbing is performed.
*/
enum GrabbingMode enum GrabbingMode
{ {
/** Frame grabbing is switched off */
GRABBINGMODE_OFF, GRABBINGMODE_OFF,
/** Frame grabbing during video */
GRABBINGMODE_VIDEO, GRABBINGMODE_VIDEO,
GRABBINGMODE_PHOTO, GRABBINGMODE_PHOTO,
GRABBINGMODE_AUDIO, GRABBINGMODE_AUDIO,

View File

@ -1,9 +1,22 @@
#include "DispmanxFrameGrabber.h" #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) : DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned height) :
_vc_display(0), _vc_display(0),
_vc_resource(0), _vc_resource(0),
_vc_flags(0),
_width(width), _width(width),
_height(height) _height(height)
{ {
@ -50,6 +63,11 @@ DispmanxFrameGrabber::~DispmanxFrameGrabber()
bcm_host_deinit(); bcm_host_deinit();
} }
void DispmanxFrameGrabber::setFlags(const int vc_flags)
{
_vc_flags = vc_flags;
}
void DispmanxFrameGrabber::grabFrame(RgbImage& image) void DispmanxFrameGrabber::grabFrame(RgbImage& image)
{ {
// Sanity check of the given image size // Sanity check of the given image size
@ -59,7 +77,7 @@ void DispmanxFrameGrabber::grabFrame(RgbImage& image)
_vc_display = vc_dispmanx_display_open(0); _vc_display = vc_dispmanx_display_open(0);
// Create the snapshot (incl down-scaling) // 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 // Read the snapshot into the memory
void* image_ptr = image.memptr(); void* image_ptr = image.memptr();

View File

@ -26,6 +26,13 @@ public:
DispmanxFrameGrabber(const unsigned width, const unsigned height); DispmanxFrameGrabber(const unsigned width, const unsigned height);
~DispmanxFrameGrabber(); ~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 /// 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 /// 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 /// Rectangle of the captured resource that is transfered to user space
VC_RECT_T _rectangle; VC_RECT_T _rectangle;
/// Flags (transforms) for creating snapshots
int _vc_flags;
/// With of the captured snapshot [pixels] /// With of the captured snapshot [pixels]
unsigned _width; unsigned _width;
/// Height of the captured snapshot [pixels] /// Height of the captured snapshot [pixels]
unsigned _height; unsigned _height;
}; };

View File

@ -61,10 +61,23 @@ void DispmanxWrapper::stop()
_timer.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(); start();
else case GRABBINGMODE_AUDIO:
case GRABBINGMODE_PHOTO:
case GRABBINGMODE_MENU:
_frameGrabber->setFlags(0);
start();
break;
case GRABBINGMODE_OFF:
stop(); stop();
break;
case GRABBINGMODE_INVALID:
break;
}
} }