Fixed compile errors in amlogic grabber

Former-commit-id: b56a72681edbf442a28fb3106a4ca445b6e6aaa8
This commit is contained in:
T.van der Zwan 2015-08-08 08:13:59 +02:00
parent 1447209846
commit 348e0c1ee8
4 changed files with 26 additions and 20 deletions

View File

@ -24,19 +24,6 @@ AmlogicGrabber::AmlogicGrabber(const unsigned width, const unsigned height) :
_height(height), _height(height),
_amlogicCaptureDev(-1) _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() AmlogicGrabber::~AmlogicGrabber()
@ -70,18 +57,37 @@ void AmlogicGrabber::setVideoMode(const VideoMode videoMode)
void AmlogicGrabber::grabFrame(Image<ColorRgb> & image) void AmlogicGrabber::grabFrame(Image<ColorRgb> & image)
{ {
// resize the given image if needed // resize the given image if needed
if (image.width() != unsigned(_rectangle.width) || image.height() != unsigned(_rectangle.height)) if (image.width() != _width || image.height() != _height)
{ {
image.resize(_rectangle.width, _rectangle.height); image.resize(_width, _height);
} }
_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;
return;
}
std::cout << "AMLOGIC grabber created (size " << _width << "x" << _height << ")" << std::endl;
// Read the snapshot into the memory // Read the snapshot into the memory
void * image_ptr = image.memptr(); void * image_ptr = image.memptr();
const size_t bytesToRead = _width * _height * sizeof(ColorRgb); const size_t bytesToRead = _width * _height * sizeof(ColorRgb);
const size_t bytesRead = pread(amlogicCaptureDev, image_ptr, bytesToRead, 0) const size_t bytesRead = pread(_amlogicCaptureDev, image_ptr, bytesToRead, 0);
if (bytesToRead != bytesRead) if (bytesToRead != bytesRead)
{ {
// Read of snapshot failed // Read of snapshot failed
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Capture failed to grab entire image [bytesToRead(" << bytesToRead << ") != bytesRead(" << bytesRead << ")]" << std::endl; std::cerr << "[" << __PRETTY_FUNCTION__ << "] Capture failed to grab entire image [bytesToRead(" << bytesToRead << ") != bytesRead(" << bytesRead << ")]" << std::endl;
} }
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
} }

View File

@ -5,7 +5,7 @@
// Utils includes // Utils includes
#include <utils/Image.h> #include <utils/Image.h>
#include <utils/ColorRgba.h> #include <utils/ColorRgb.h>
#include <utils/VideoMode.h> #include <utils/VideoMode.h>
/// ///
@ -38,7 +38,7 @@ public:
/// @param[out] image The snapped screenshot (should be initialized with correct width and /// @param[out] image The snapped screenshot (should be initialized with correct width and
/// height) /// height)
/// ///
void grabFrame(Image<ColorRgba> & image); void grabFrame(Image<ColorRgb> & image);
private: private:

View File

@ -18,7 +18,7 @@ AmlogicWrapper::AmlogicWrapper(const unsigned grabWidth, const unsigned grabHeig
_priority(1000), _priority(1000),
_timer(), _timer(),
_image(grabWidth, grabHeight), _image(grabWidth, grabHeight),
_frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)), _frameGrabber(new AmlogicGrabber(grabWidth, grabHeight)),
_processor(ImageProcessorFactory::getInstance().newImageProcessor()), _processor(ImageProcessorFactory::getInstance().newImageProcessor()),
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}), _ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}),
_hyperion(hyperion) _hyperion(hyperion)

View File

@ -12,7 +12,7 @@ SET(AmlogicHEADERS
SET(AmlogicSOURCES SET(AmlogicSOURCES
${CURRENT_SOURCE_DIR}/AmlogicWrapper.cpp ${CURRENT_SOURCE_DIR}/AmlogicWrapper.cpp
${CURRENT_SOURCE_DIR}/AmlogicFrameGrabber.cpp ${CURRENT_SOURCE_DIR}/AmlogicGrabber.cpp
) )
QT4_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS}) QT4_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})