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

Commit 858ca23

Browse files
committed
Reduce copying of data
1 parent f9dc759 commit 858ca23

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

include/grabber/V4L2Wrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public slots:
3535

3636
void set3D(VideoMode mode);
3737

38+
signals:
39+
void emitColors(int priority, const std::vector<ColorRgb> &ledColors, const int timeout_ms);
40+
3841
private slots:
3942
void newFrame(const Image<ColorRgb> & image);
4043

libsrc/grabber/v4l2/V4L2Wrapper.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,19 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
2929
{
3030
// register the image type
3131
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
32+
qRegisterMetaType<std::vector<ColorRgb>>("std::vector<ColorRgb>");
3233

33-
// connect the new frame signal using a queued connection, because it will be called from a different thread
34-
QObject::connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::QueuedConnection);
34+
// Handle the image in the captured thread using a direct connection
35+
QObject::connect(
36+
&_grabber, SIGNAL(newFrame(Image<ColorRgb>)),
37+
this, SLOT(newFrame(Image<ColorRgb>)),
38+
Qt::DirectConnection);
39+
40+
// send color data to Hyperion using a queued connection to handle the data over to the main event loop
41+
QObject::connect(
42+
this, SIGNAL(emitColors(int,std::vector<ColorRgb>,int)),
43+
_hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)),
44+
Qt::QueuedConnection);
3545
}
3646

3747
V4L2Wrapper::~V4L2Wrapper()
@@ -67,6 +77,6 @@ void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
6777
_processor->process(image, _ledColors);
6878

6979
// send colors to Hyperion
70-
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
80+
emit emitColors(_priority, _ledColors, _timeout_ms);
7181
}
7282

0 commit comments

Comments
 (0)