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

Commit cdd121f

Browse files
committed
Switched added to hyperion-v4l2 to process the video stream as a 3D SBS or TAB
1 parent 7e4013f commit cdd121f

File tree

4 files changed

+83
-28
lines changed

4 files changed

+83
-28
lines changed

deploy/hyperion.tar.gz

645 Bytes
Binary file not shown.

src/hyperion-v4l2/V4L2Grabber.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ V4L2Grabber::V4L2Grabber(
4242
VideoStandard videoStandard,
4343
int width,
4444
int height,
45-
int cropLeft,
46-
int cropRight,
47-
int cropTop,
48-
int cropBottom,
4945
int frameDecimation,
5046
int horizontalPixelDecimation,
5147
int verticalPixelDecimation) :
@@ -56,13 +52,14 @@ V4L2Grabber::V4L2Grabber(
5652
_pixelFormat(0),
5753
_width(width),
5854
_height(height),
59-
_cropLeft(cropLeft),
60-
_cropRight(cropRight),
61-
_cropTop(cropTop),
62-
_cropBottom(cropBottom),
55+
_cropLeft(0),
56+
_cropRight(0),
57+
_cropTop(0),
58+
_cropBottom(0),
6359
_frameDecimation(std::max(1, frameDecimation)),
6460
_horizontalPixelDecimation(std::max(1, horizontalPixelDecimation)),
6561
_verticalPixelDecimation(std::max(1, verticalPixelDecimation)),
62+
_mode3D(MODE_NONE),
6663
_currentFrame(0),
6764
_callback(nullptr),
6865
_callbackArg(nullptr)
@@ -77,6 +74,19 @@ V4L2Grabber::~V4L2Grabber()
7774
close_device();
7875
}
7976

77+
void V4L2Grabber::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
78+
{
79+
_cropLeft = cropLeft;
80+
_cropRight = cropRight;
81+
_cropTop = cropTop;
82+
_cropBottom = cropBottom;
83+
}
84+
85+
void V4L2Grabber::set3D(Mode3D mode)
86+
{
87+
_mode3D = mode;
88+
}
89+
8090
void V4L2Grabber::setCallback(V4L2Grabber::ImageCallback callback, void *arg)
8191
{
8292
_callback = callback;
@@ -659,14 +669,29 @@ bool V4L2Grabber::process_image(const void *p, int size)
659669

660670
void V4L2Grabber::process_image(const uint8_t * data)
661671
{
662-
int width = (_width - _cropLeft - _cropRight + _horizontalPixelDecimation/2) / _horizontalPixelDecimation;
663-
int height = (_height - _cropTop - _cropBottom + _verticalPixelDecimation/2) / _verticalPixelDecimation;
672+
int width = _width;
673+
int height = _height;
674+
675+
switch (_mode3D)
676+
{
677+
case MODE_3DSBS:
678+
width = _width/2;
679+
break;
680+
case MODE_3DTAB:
681+
height = _height/2;
682+
break;
683+
default:
684+
break;
685+
}
664686

665-
Image<ColorRgb> image(width, height);
687+
// create output structure
688+
int outputWidth = (width - _cropLeft - _cropRight + _horizontalPixelDecimation/2) / _horizontalPixelDecimation;
689+
int outputHeight = (height - _cropTop - _cropBottom + _verticalPixelDecimation/2) / _verticalPixelDecimation;
690+
Image<ColorRgb> image(outputWidth, outputHeight);
666691

667-
for (int ySource = _cropTop + _verticalPixelDecimation/2, yDest = 0; ySource < _height - _cropBottom; ySource += _verticalPixelDecimation, ++yDest)
692+
for (int ySource = _cropTop + _verticalPixelDecimation/2, yDest = 0; ySource < height - _cropBottom; ySource += _verticalPixelDecimation, ++yDest)
668693
{
669-
for (int xSource = _cropLeft + _horizontalPixelDecimation/2, xDest = 0; xSource < _width - _cropRight; xSource += _horizontalPixelDecimation, ++xDest)
694+
for (int xSource = _cropLeft + _horizontalPixelDecimation/2, xDest = 0; xSource < width - _cropRight; xSource += _horizontalPixelDecimation, ++xDest)
670695
{
671696
int index = (_width * ySource + xSource) * 2;
672697
uint8_t y = 0;

src/hyperion-v4l2/V4L2Grabber.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,29 @@ class V4L2Grabber
2020
PAL, NTSC, NO_CHANGE
2121
};
2222

23+
enum Mode3D {
24+
MODE_NONE, MODE_3DSBS, MODE_3DTAB
25+
};
26+
2327
public:
2428
V4L2Grabber(
2529
const std::string & device,
2630
int input,
2731
VideoStandard videoStandard,
2832
int width,
2933
int height,
30-
int cropLeft,
31-
int cropRight,
32-
int cropTop,
33-
int cropBottom,
3434
int frameDecimation,
3535
int horizontalPixelDecimation,
3636
int verticalPixelDecimation);
3737
virtual ~V4L2Grabber();
3838

39+
void setCropping(int cropLeft,
40+
int cropRight,
41+
int cropTop,
42+
int cropBottom);
43+
44+
void set3D(Mode3D mode);
45+
3946
void setCallback(ImageCallback callback, void * arg);
4047

4148
void start();
@@ -96,13 +103,15 @@ class V4L2Grabber
96103
uint32_t _pixelFormat;
97104
int _width;
98105
int _height;
99-
const int _cropLeft;
100-
const int _cropRight;
101-
const int _cropTop;
102-
const int _cropBottom;
103-
const int _frameDecimation;
104-
const int _horizontalPixelDecimation;
105-
const int _verticalPixelDecimation;
106+
int _cropLeft;
107+
int _cropRight;
108+
int _cropTop;
109+
int _cropBottom;
110+
int _frameDecimation;
111+
int _horizontalPixelDecimation;
112+
int _verticalPixelDecimation;
113+
114+
Mode3D _mode3D;
106115

107116
int _currentFrame;
108117

src/hyperion-v4l2/hyperion-v4l2.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ int main(int argc, char** argv)
5454
IntParameter & argFrameDecimation = parameters.add<IntParameter> ('f', "frame-decimator", "Decimation factor for the video frames [default=1]");
5555
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
5656
DoubleParameter & argSignalThreshold = parameters.add<DoubleParameter> ('t', "signal-threshold", "The signal threshold for detecting the presence of a signal. Value should be between 0.0 and 1.0.");
57+
SwitchParameter<> & arg3DSBS = parameters.add<SwitchParameter<>> (0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
58+
SwitchParameter<> & arg3DTAB = parameters.add<SwitchParameter<>> (0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
5759
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
5860
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
5961
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@@ -88,21 +90,38 @@ int main(int argc, char** argv)
8890
if (!argCropTop.isSet()) argCropTop.setDefault(argCropHeight.getValue());
8991
if (!argCropBottom.isSet()) argCropBottom.setDefault(argCropHeight.getValue());
9092

93+
// initialize the grabber
9194
V4L2Grabber grabber(
9295
argDevice.getValue(),
9396
argInput.getValue(),
9497
argVideoStandard.getValue(),
9598
argWidth.getValue(),
9699
argHeight.getValue(),
97-
std::max(0, argCropLeft.getValue()),
98-
std::max(0, argCropRight.getValue()),
99-
std::max(0, argCropTop.getValue()),
100-
std::max(0, argCropBottom.getValue()),
101100
std::max(1, argFrameDecimation.getValue()),
102101
std::max(1, argSizeDecimation.getValue()),
103102
std::max(1, argSizeDecimation.getValue()));
104103

104+
// set cropping values
105+
grabber.setCropping(
106+
std::max(0, argCropLeft.getValue()),
107+
std::max(0, argCropRight.getValue()),
108+
std::max(0, argCropTop.getValue()),
109+
std::max(0, argCropBottom.getValue()));
110+
111+
// set 3D mode if applicable
112+
if (arg3DSBS.isSet())
113+
{
114+
grabber.set3D(V4L2Grabber::MODE_3DSBS);
115+
}
116+
else if (arg3DTAB.isSet())
117+
{
118+
grabber.set3D(V4L2Grabber::MODE_3DTAB);
119+
}
120+
121+
// start the grabber
105122
grabber.start();
123+
124+
// run the grabber
106125
if (argScreenshot.isSet())
107126
{
108127
grabber.setCallback(&saveScreenshot, nullptr);
@@ -114,6 +133,8 @@ int main(int argc, char** argv)
114133
grabber.setCallback(&ImageHandler::imageCallback, &handler);
115134
grabber.capture();
116135
}
136+
137+
// stop the grabber
117138
grabber.stop();
118139
}
119140
catch (const std::runtime_error & e)

0 commit comments

Comments
 (0)