mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added code for amlogic grabber.
Former-commit-id: fdb9c1c5d8ce02d531d2008057e22f1ae8f7d04e
This commit is contained in:
87
libsrc/grabber/amlogic/AmlogicGrabber.cpp
Normal file
87
libsrc/grabber/amlogic/AmlogicGrabber.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
// Linux includes
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
// Local includes
|
||||
#include "AmlogicGrabber.h"
|
||||
|
||||
// Flags copied from 'linux/amlogic/amports/amvideocap.h' at https://github.com/codesnake/linux-amlogic/
|
||||
#define AMVIDEOCAP_IOC_MAGIC 'V'
|
||||
#define AMVIDEOCAP_IOW_SET_WANTFRAME_WIDTH _IOW(AMVIDEOCAP_IOC_MAGIC, 0x02, int)
|
||||
#define AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT _IOW(AMVIDEOCAP_IOC_MAGIC, 0x03, int)
|
||||
|
||||
AmlogicGrabber::AmlogicGrabber(const unsigned width, const unsigned height) :
|
||||
_width(width),
|
||||
_height(height),
|
||||
_amlogicCaptureDev(-1)
|
||||
{
|
||||
_amlogicCaptureDev = open("/dev/amvideocap0", O_RDONLY, 0);
|
||||
if (_amlogicCaptureDev == -1)
|
||||
{
|
||||
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Failed to open the AMLOGIC device (" << errno << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ioctl(_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_WIDTH, _width) == -1 ||
|
||||
ioctl(_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, _height) == -1)
|
||||
{
|
||||
// Failed to configure frame width
|
||||
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Failed to configure capture size (" << errno << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
AmlogicGrabber::~AmlogicGrabber()
|
||||
{
|
||||
if (_amlogicCaptureDev != -1)
|
||||
{
|
||||
if (close(_amlogicCaptureDev) == -1)
|
||||
{
|
||||
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Failed to close AMLOGIC device (" << errno << ")" << std::endl;
|
||||
}
|
||||
_amlogicCaptureDev = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void AmlogicGrabber::setVideoMode(const VideoMode videoMode)
|
||||
{
|
||||
switch (videoMode) {
|
||||
case VIDEO_3DSBS:
|
||||
//vc_dispmanx_rect_set(&_rectangle, 0, 0, _width/2, _height);
|
||||
break;
|
||||
case VIDEO_3DTAB:
|
||||
//vc_dispmanx_rect_set(&_rectangle, 0, 0, _width, _height/2);
|
||||
break;
|
||||
case VIDEO_2D:
|
||||
default:
|
||||
//vc_dispmanx_rect_set(&_rectangle, 0, 0, _width, _height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AmlogicGrabber::grabFrame(Image<ColorRgb> & image)
|
||||
{
|
||||
// resize the given image if needed
|
||||
if (image.width() != unsigned(_rectangle.width) || image.height() != unsigned(_rectangle.height))
|
||||
{
|
||||
image.resize(_rectangle.width, _rectangle.height);
|
||||
}
|
||||
|
||||
// Read the snapshot into the memory
|
||||
void * image_ptr = image.memptr();
|
||||
const size_t bytesToRead = _width * _height * sizeof(ColorRgb);
|
||||
const size_t bytesRead = pread(amlogicCaptureDev, image_ptr, bytesToRead, 0)
|
||||
if (bytesToRead != bytesRead)
|
||||
{
|
||||
// Read of snapshot failed
|
||||
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Capture failed to grab entire image [bytesToRead(" << bytesToRead << ") != bytesRead(" << bytesRead << ")]" << std::endl;
|
||||
}
|
||||
}
|
52
libsrc/grabber/amlogic/AmlogicGrabber.h
Normal file
52
libsrc/grabber/amlogic/AmlogicGrabber.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/Image.h>
|
||||
#include <utils/ColorRgba.h>
|
||||
#include <utils/VideoMode.h>
|
||||
|
||||
///
|
||||
/// The DispmanxFrameGrabber is used for creating snapshots of the display (screenshots) with a
|
||||
/// downsized and scaled resolution.
|
||||
///
|
||||
class AmlogicGrabber
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Construct a AmlogicGrabber that will capture snapshots with specified dimensions.
|
||||
///
|
||||
/// @param[in] width The width of the captured screenshot
|
||||
/// @param[in] height The heigth of the captured screenshot
|
||||
///
|
||||
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
|
||||
/// _height)
|
||||
///
|
||||
/// @param[out] image The snapped screenshot (should be initialized with correct width and
|
||||
/// height)
|
||||
///
|
||||
void grabFrame(Image<ColorRgba> & image);
|
||||
|
||||
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;
|
||||
};
|
88
libsrc/grabber/amlogic/AmlogicWrapper.cpp
Normal file
88
libsrc/grabber/amlogic/AmlogicWrapper.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// QT includes
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
|
||||
// Amlogic grabber includes
|
||||
#include <grabber/AmlogicWrapper.h>
|
||||
#include "AmlogicGrabber.h"
|
||||
|
||||
|
||||
AmlogicWrapper::AmlogicWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, Hyperion * hyperion) :
|
||||
_updateInterval_ms(1000/updateRate_Hz),
|
||||
_timeout_ms(2 * _updateInterval_ms),
|
||||
_priority(1000),
|
||||
_timer(),
|
||||
_image(grabWidth, grabHeight),
|
||||
_frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)),
|
||||
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}),
|
||||
_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()));
|
||||
}
|
||||
|
||||
AmlogicWrapper::~AmlogicWrapper()
|
||||
{
|
||||
// Cleanup used resources (ImageProcessor and FrameGrabber)
|
||||
delete _processor;
|
||||
delete _frameGrabber;
|
||||
}
|
||||
|
||||
void AmlogicWrapper::start()
|
||||
{
|
||||
// Start the timer with the pre configured interval
|
||||
_timer.start();
|
||||
}
|
||||
|
||||
void AmlogicWrapper::action()
|
||||
{
|
||||
// Grab frame into the allocated image
|
||||
_frameGrabber->grabFrame(_image);
|
||||
|
||||
_processor->process(_image, _ledColors);
|
||||
|
||||
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
|
||||
}
|
||||
void AmlogicWrapper::stop()
|
||||
{
|
||||
// Stop the timer, effectivly stopping the process
|
||||
_timer.stop();
|
||||
}
|
||||
|
||||
void AmlogicWrapper::setGrabbingMode(const GrabbingMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case GRABBINGMODE_VIDEO:
|
||||
// _frameGrabber->setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL);
|
||||
start();
|
||||
break;
|
||||
case GRABBINGMODE_AUDIO:
|
||||
case GRABBINGMODE_PHOTO:
|
||||
case GRABBINGMODE_MENU:
|
||||
case GRABBINGMODE_INVALID:
|
||||
// _frameGrabber->setFlags(0);
|
||||
start();
|
||||
break;
|
||||
case GRABBINGMODE_OFF:
|
||||
stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AmlogicWrapper::setVideoMode(const VideoMode mode)
|
||||
{
|
||||
_frameGrabber->setVideoMode(mode);
|
||||
}
|
29
libsrc/grabber/amlogic/CMakeLists.txt
Normal file
29
libsrc/grabber/amlogic/CMakeLists.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
# Define the current source locations
|
||||
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/grabber)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/amlogic)
|
||||
|
||||
# Group the headers that go through the MOC compiler
|
||||
SET(AmlogicQT_HEADERS ${CURRENT_HEADER_DIR}/AmlogicWrapper.h)
|
||||
|
||||
SET(AmlogicHEADERS
|
||||
${CURRENT_SOURCE_DIR}/AmlogicGrabber.h
|
||||
)
|
||||
|
||||
SET(AmlogicSOURCES
|
||||
${CURRENT_SOURCE_DIR}/AmlogicWrapper.cpp
|
||||
${CURRENT_SOURCE_DIR}/AmlogicFrameGrabber.cpp
|
||||
)
|
||||
|
||||
QT4_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})
|
||||
|
||||
add_library(amlogic-grabber
|
||||
${AmlogicHEADERS}
|
||||
${AmlogicQT_HEADERS}
|
||||
${AmlogicHEADERS_MOC}
|
||||
${AmlogicSOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(amlogic-grabber
|
||||
hyperion
|
||||
${QT_LIBRARIES})
|
Reference in New Issue
Block a user