Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit be6fb4d

Browse files
committed
Added image handler to v4l2 grabber to send colors to Hyperion
1 parent 97b281c commit be6fb4d

File tree

5 files changed

+135
-7
lines changed

5 files changed

+135
-7
lines changed

include/grabber/DispmanxWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public slots:
7373
const int _updateInterval_ms;
7474
/// The timeout of the led colors [ms]
7575
const int _timeout_ms;
76-
/// The priority of the led colors [ms]
76+
/// The priority of the led colors
7777
const int _priority;
7878

7979
/// The timer for generating events with the specified update rate

include/grabber/V4L2Wrapper.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#pragma once
2+
3+
// Hyperion includes
4+
#include <hyperion/Hyperion.h>
5+
#include <hyperion/ImageProcessor.h>
6+
7+
// Grabber includes
8+
#include <grabber/V4L2Grabber.h>
9+
10+
class V4L2Wrapper : public QObject
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
V4L2Wrapper(const std::string & device,
16+
int input,
17+
VideoStandard videoStandard,
18+
int width,
19+
int height,
20+
int frameDecimation,
21+
int pixelDecimation,
22+
Hyperion * hyperion,
23+
int hyperionPriority);
24+
virtual ~V4L2Wrapper();
25+
26+
public slots:
27+
void start();
28+
29+
void stop();
30+
31+
void setCropping(int cropLeft,
32+
int cropRight,
33+
int cropTop,
34+
int cropBottom);
35+
36+
void set3D(VideoMode mode);
37+
38+
private slots:
39+
void newFrame(const Image<ColorRgb> & image);
40+
41+
private:
42+
/// The timeout of the led colors [ms]
43+
const int _timeout_ms;
44+
45+
/// The priority of the led colors
46+
const int _priority;
47+
48+
/// The V4L2 grabber
49+
V4L2Grabber _grabber;
50+
51+
/// The processor for transforming images to led colors
52+
ImageProcessor * _processor;
53+
54+
/// The Hyperion instance
55+
Hyperion * _hyperion;
56+
57+
/// The list with computed led colors
58+
std::vector<ColorRgb> _ledColors;
59+
};

libsrc/grabber/v4l2/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/v4l2)
44

55
SET(V4L2_QT_HEADERS
66
${CURRENT_HEADER_DIR}/V4L2Grabber.h
7+
${CURRENT_HEADER_DIR}/V4L2Wrapper.h
78
)
89

910
SET(V4L2_HEADERS
@@ -12,6 +13,7 @@ SET(V4L2_HEADERS
1213

1314
SET(V4L2_SOURCES
1415
${CURRENT_SOURCE_DIR}/V4L2Grabber.cpp
16+
${CURRENT_SOURCE_DIR}/V4L2Wrapper.cpp
1517
)
1618

1719
QT4_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})

libsrc/grabber/v4l2/V4L2Wrapper.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <grabber/V4L2Wrapper.h>
2+
3+
#include <hyperion/ImageProcessorFactory.h>
4+
5+
V4L2Wrapper::V4L2Wrapper(const std::string &device,
6+
int input,
7+
VideoStandard videoStandard,
8+
int width,
9+
int height,
10+
int frameDecimation,
11+
int pixelDecimation,
12+
Hyperion *hyperion,
13+
int hyperionPriority) :
14+
_timeout_ms(1000),
15+
_priority(hyperionPriority),
16+
_grabber(device,
17+
input,
18+
videoStandard,
19+
width,
20+
height,
21+
frameDecimation,
22+
pixelDecimation,
23+
pixelDecimation),
24+
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
25+
_hyperion(hyperion),
26+
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0})
27+
{
28+
// connect the new frame signal using a queued connection, because it will be called from a different thread
29+
QObject::connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::QueuedConnection);
30+
}
31+
32+
V4L2Wrapper::~V4L2Wrapper()
33+
{
34+
delete _processor;
35+
}
36+
37+
void V4L2Wrapper::start()
38+
{
39+
_grabber.start();
40+
}
41+
42+
void V4L2Wrapper::stop()
43+
{
44+
_grabber.stop();
45+
}
46+
47+
void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
48+
{
49+
_grabber.setCropping(cropLeft, cropRight, cropTop, cropBottom);
50+
}
51+
52+
void V4L2Wrapper::set3D(VideoMode mode)
53+
{
54+
_grabber.set3D(mode);
55+
}
56+
57+
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
58+
{
59+
// TODO: add a signal detector
60+
61+
// process the new image
62+
_processor->process(image, _ledColors);
63+
64+
// send colors to Hyperion
65+
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
66+
}
67+

src/hyperiond/hyperiond.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#ifdef ENABLE_V4L2
2626
// v4l2 grabber
27-
#include <grabber/V4L2Grabber.h>
27+
#include <grabber/V4L2Wrapper.h>
2828
#endif
2929

3030
// XBMC Video checker includes
@@ -172,27 +172,27 @@ int main(int argc, char** argv)
172172

173173
#ifdef ENABLE_V4L2
174174
// construct and start the v4l2 grabber if the configuration is present
175-
V4L2Grabber * v4l2Grabber = nullptr;
175+
V4L2Wrapper * v4l2Grabber = nullptr;
176176
if (config.isMember("grabber-v4l2"))
177177
{
178178
const Json::Value & grabberConfig = config["grabber-v4l2"];
179-
v4l2Grabber = new V4L2Grabber(
179+
v4l2Grabber = new V4L2Wrapper(
180180
grabberConfig.get("device", "/dev/video0").asString(),
181181
grabberConfig.get("input", 0).asInt(),
182-
parseVideoStandard(grabberConfig.get("standard", "NONE").asString()),
182+
parseVideoStandard(grabberConfig.get("standard", "no-change").asString()),
183183
grabberConfig.get("width", -1).asInt(),
184184
grabberConfig.get("height", -1).asInt(),
185185
grabberConfig.get("frameDecimation", 2).asInt(),
186186
grabberConfig.get("sizeDecimation", 8).asInt(),
187-
grabberConfig.get("sizeDecimation", 8).asInt());
187+
&hyperion,
188+
grabberConfig.get("priority", 800).asInt());
188189
v4l2Grabber->set3D(parse3DMode(grabberConfig.get("mode", "2D").asString()));
189190
v4l2Grabber->setCropping(
190191
grabberConfig.get("cropLeft", 0).asInt(),
191192
grabberConfig.get("cropRight", 0).asInt(),
192193
grabberConfig.get("cropTop", 0).asInt(),
193194
grabberConfig.get("cropBottom", 0).asInt());
194195

195-
// TODO: create handler
196196
v4l2Grabber->start();
197197
std::cout << "V4l2 grabber created and started" << std::endl;
198198
}

0 commit comments

Comments
 (0)