mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added image handler to v4l2 grabber to send colors to Hyperion
Former-commit-id: be6fb4dd8080b3325ba6161f48c093f8a145786d
This commit is contained in:
parent
e58f84d5c8
commit
99fd50805c
@ -73,7 +73,7 @@ private:
|
||||
const int _updateInterval_ms;
|
||||
/// The timeout of the led colors [ms]
|
||||
const int _timeout_ms;
|
||||
/// The priority of the led colors [ms]
|
||||
/// The priority of the led colors
|
||||
const int _priority;
|
||||
|
||||
/// The timer for generating events with the specified update rate
|
||||
|
59
include/grabber/V4L2Wrapper.h
Normal file
59
include/grabber/V4L2Wrapper.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
|
||||
// Grabber includes
|
||||
#include <grabber/V4L2Grabber.h>
|
||||
|
||||
class V4L2Wrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
V4L2Wrapper(const std::string & device,
|
||||
int input,
|
||||
VideoStandard videoStandard,
|
||||
int width,
|
||||
int height,
|
||||
int frameDecimation,
|
||||
int pixelDecimation,
|
||||
Hyperion * hyperion,
|
||||
int hyperionPriority);
|
||||
virtual ~V4L2Wrapper();
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
void setCropping(int cropLeft,
|
||||
int cropRight,
|
||||
int cropTop,
|
||||
int cropBottom);
|
||||
|
||||
void set3D(VideoMode mode);
|
||||
|
||||
private slots:
|
||||
void newFrame(const Image<ColorRgb> & image);
|
||||
|
||||
private:
|
||||
/// The timeout of the led colors [ms]
|
||||
const int _timeout_ms;
|
||||
|
||||
/// The priority of the led colors
|
||||
const int _priority;
|
||||
|
||||
/// The V4L2 grabber
|
||||
V4L2Grabber _grabber;
|
||||
|
||||
/// The processor for transforming images to led colors
|
||||
ImageProcessor * _processor;
|
||||
|
||||
/// The Hyperion instance
|
||||
Hyperion * _hyperion;
|
||||
|
||||
/// The list with computed led colors
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
};
|
@ -4,6 +4,7 @@ SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/v4l2)
|
||||
|
||||
SET(V4L2_QT_HEADERS
|
||||
${CURRENT_HEADER_DIR}/V4L2Grabber.h
|
||||
${CURRENT_HEADER_DIR}/V4L2Wrapper.h
|
||||
)
|
||||
|
||||
SET(V4L2_HEADERS
|
||||
@ -12,6 +13,7 @@ SET(V4L2_HEADERS
|
||||
|
||||
SET(V4L2_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/V4L2Grabber.cpp
|
||||
${CURRENT_SOURCE_DIR}/V4L2Wrapper.cpp
|
||||
)
|
||||
|
||||
QT4_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})
|
||||
|
67
libsrc/grabber/v4l2/V4L2Wrapper.cpp
Normal file
67
libsrc/grabber/v4l2/V4L2Wrapper.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include <grabber/V4L2Wrapper.h>
|
||||
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
|
||||
V4L2Wrapper::V4L2Wrapper(const std::string &device,
|
||||
int input,
|
||||
VideoStandard videoStandard,
|
||||
int width,
|
||||
int height,
|
||||
int frameDecimation,
|
||||
int pixelDecimation,
|
||||
Hyperion *hyperion,
|
||||
int hyperionPriority) :
|
||||
_timeout_ms(1000),
|
||||
_priority(hyperionPriority),
|
||||
_grabber(device,
|
||||
input,
|
||||
videoStandard,
|
||||
width,
|
||||
height,
|
||||
frameDecimation,
|
||||
pixelDecimation,
|
||||
pixelDecimation),
|
||||
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_hyperion(hyperion),
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0})
|
||||
{
|
||||
// connect the new frame signal using a queued connection, because it will be called from a different thread
|
||||
QObject::connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
V4L2Wrapper::~V4L2Wrapper()
|
||||
{
|
||||
delete _processor;
|
||||
}
|
||||
|
||||
void V4L2Wrapper::start()
|
||||
{
|
||||
_grabber.start();
|
||||
}
|
||||
|
||||
void V4L2Wrapper::stop()
|
||||
{
|
||||
_grabber.stop();
|
||||
}
|
||||
|
||||
void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
|
||||
{
|
||||
_grabber.setCropping(cropLeft, cropRight, cropTop, cropBottom);
|
||||
}
|
||||
|
||||
void V4L2Wrapper::set3D(VideoMode mode)
|
||||
{
|
||||
_grabber.set3D(mode);
|
||||
}
|
||||
|
||||
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
|
||||
{
|
||||
// TODO: add a signal detector
|
||||
|
||||
// process the new image
|
||||
_processor->process(image, _ledColors);
|
||||
|
||||
// send colors to Hyperion
|
||||
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#ifdef ENABLE_V4L2
|
||||
// v4l2 grabber
|
||||
#include <grabber/V4L2Grabber.h>
|
||||
#include <grabber/V4L2Wrapper.h>
|
||||
#endif
|
||||
|
||||
// XBMC Video checker includes
|
||||
@ -172,19 +172,20 @@ int main(int argc, char** argv)
|
||||
|
||||
#ifdef ENABLE_V4L2
|
||||
// construct and start the v4l2 grabber if the configuration is present
|
||||
V4L2Grabber * v4l2Grabber = nullptr;
|
||||
V4L2Wrapper * v4l2Grabber = nullptr;
|
||||
if (config.isMember("grabber-v4l2"))
|
||||
{
|
||||
const Json::Value & grabberConfig = config["grabber-v4l2"];
|
||||
v4l2Grabber = new V4L2Grabber(
|
||||
v4l2Grabber = new V4L2Wrapper(
|
||||
grabberConfig.get("device", "/dev/video0").asString(),
|
||||
grabberConfig.get("input", 0).asInt(),
|
||||
parseVideoStandard(grabberConfig.get("standard", "NONE").asString()),
|
||||
parseVideoStandard(grabberConfig.get("standard", "no-change").asString()),
|
||||
grabberConfig.get("width", -1).asInt(),
|
||||
grabberConfig.get("height", -1).asInt(),
|
||||
grabberConfig.get("frameDecimation", 2).asInt(),
|
||||
grabberConfig.get("sizeDecimation", 8).asInt(),
|
||||
grabberConfig.get("sizeDecimation", 8).asInt());
|
||||
&hyperion,
|
||||
grabberConfig.get("priority", 800).asInt());
|
||||
v4l2Grabber->set3D(parse3DMode(grabberConfig.get("mode", "2D").asString()));
|
||||
v4l2Grabber->setCropping(
|
||||
grabberConfig.get("cropLeft", 0).asInt(),
|
||||
@ -192,7 +193,6 @@ int main(int argc, char** argv)
|
||||
grabberConfig.get("cropTop", 0).asInt(),
|
||||
grabberConfig.get("cropBottom", 0).asInt());
|
||||
|
||||
// TODO: create handler
|
||||
v4l2Grabber->start();
|
||||
std::cout << "V4l2 grabber created and started" << std::endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user