restructured project structure: move projects into sub-folders, split dispmanx-grabber from hyperion

This commit is contained in:
johan
2013-08-17 16:12:42 +02:00
parent 16c260b3dc
commit 59e13a2b5f
18 changed files with 85 additions and 56 deletions

View File

@@ -0,0 +1,36 @@
# Find the BCM-package (VC control)
find_package(BCM REQUIRED)
include_directories(${BCM_INCLUDE_DIRS})
# Define the current source locations
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/dispmanx-grabber)
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/dispmanx-grabber)
# Group the headers that go through the MOC compiler
SET(DispmanxGrabberQT_HEADERS
${CURRENT_HEADER_DIR}/DispmanxWrapper.h
)
SET(DispmanxGrabberHEADERS
${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.h
)
SET(DispmanxGrabberSOURCES
${CURRENT_SOURCE_DIR}/DispmanxWrapper.cpp
${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.cpp
)
QT4_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS})
add_library(dispmanx-grabber
${DispmanxGrabberHEADERS}
${DispmanxGrabberQT_HEADERS}
${DispmanxGrabberHEADERS_MOC}
${DispmanxGrabberSOURCES}
)
target_link_libraries(dispmanx-grabber
hyperion
${QT_LIBRARIES}
${BCM_LIBRARIES})

View File

@@ -0,0 +1,56 @@
#include "DispmanxFrameGrabber.h"
DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned height) :
_display(0),
_resource(0),
_width(width),
_height(height)
{
// Initiase BCM
bcm_host_init();
// Open the connection to the display
_display = vc_dispmanx_display_open(0);
int ret = vc_dispmanx_display_get_info(_display, &_info);
// Make the compiler (in release mode) happy by 'using' ret
(void)ret;
assert(ret == 0);
// Create the resources for capturing image
_resource = vc_dispmanx_resource_create(
VC_IMAGE_RGB888,
width,
height,
&_vc_image_ptr);
assert(_resource);
// Define the capture rectangle with the same size
vc_dispmanx_rect_set(&_rectangle, 0, 0, width, height);
_pitch = width * 3;
}
DispmanxFrameGrabber::~DispmanxFrameGrabber()
{
// Clean up resources
vc_dispmanx_resource_delete(_resource);
// Close the displaye
vc_dispmanx_display_close(_display);
// De-init BCM
bcm_host_deinit();
}
void DispmanxFrameGrabber::grabFrame(RgbImage& image)
{
// Sanity check of the given image size
assert(image.width() == _width && image.height() == _height);
void* image_ptr = image.memptr();
// Create the snapshot
vc_dispmanx_snapshot(_display, _resource, VC_IMAGE_ROT0);
// Read the snapshot into the memory (incl down-scaling)
vc_dispmanx_resource_read_data(_resource, &_rectangle, image_ptr, _pitch);
}

View File

@@ -0,0 +1,36 @@
#pragma once
// BCM includes
#pragma GCC system_header
#include <bcm_host.h>
// STL includes
#include <cstdint>
// Utils includes
#include <utils/RgbImage.h>
///
/// The DispmanxFrameGrabber grabs
///
class DispmanxFrameGrabber
{
public:
DispmanxFrameGrabber(const unsigned width, const unsigned height);
~DispmanxFrameGrabber();
void grabFrame(RgbImage& image);
private:
DISPMANX_DISPLAY_HANDLE_T _display;
DISPMANX_MODEINFO_T _info;
DISPMANX_RESOURCE_HANDLE_T _resource;
uint32_t _vc_image_ptr;
VC_RECT_T _rectangle;
unsigned _width;
unsigned _height;
uint32_t _pitch;
};

View File

@@ -0,0 +1,62 @@
// QT includes
#include <QDebug>
#include <QDateTime>
// Hyperion includes
#include <hyperion/Hyperion.h>
#include <hyperion/ImageProcessorFactory.h>
#include <hyperion/ImageProcessor.h>
// Local-dispmanx includes
#include <dispmanx-grabber/DispmanxWrapper.h>
#include "DispmanxFrameGrabber.h"
DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, Hyperion * hyperion) :
_updateInterval_ms(1000/updateRate_Hz),
_timeout_ms(2 * _updateInterval_ms),
_timer(),
_image(grabWidth, grabHeight),
_frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)),
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
_ledColors(hyperion->getLedCount(), RgbColor::BLACK),
_hyperion(hyperion)
{
// Configure the timer to generate events every n milliseconds
_timer.setInterval(_updateInterval_ms);
_timer.setSingleShot(false);
_processor->setSize(grabWidth, grabHeight);
// Connect the QTimer to this
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action()));
}
DispmanxWrapper::~DispmanxWrapper()
{
// Cleanup used resources (ImageProcessor and FrameGrabber)
delete _processor;
delete _frameGrabber;
}
void DispmanxWrapper::start()
{
// Start the timer with the pre configured interval
_timer.start();
}
void DispmanxWrapper::action()
{
// Grab frame into the allocated image
_frameGrabber->grabFrame(_image);
_processor->process(_image, _ledColors);
const int _priority = 100;
_hyperion->setValue(_priority, _ledColors, _timeout_ms);
}
void DispmanxWrapper::stop()
{
// Stop the timer, effectivly stopping the process
_timer.stop();
}