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

Commit ab98c7b

Browse files
committed
V4L2: Fix error with frame size of RGB32
1 parent d6ec015 commit ab98c7b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

deploy/hyperion.tar.gz

223 Bytes
Binary file not shown.

include/grabber/V4L2Grabber.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ private slots:
108108
PixelFormat _pixelFormat;
109109
int _width;
110110
int _height;
111+
int _frameByteSize;
111112
int _cropLeft;
112113
int _cropRight;
113114
int _cropTop;

libsrc/grabber/v4l2/V4L2Grabber.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ V4L2Grabber::V4L2Grabber(const std::string & device,
5252
_pixelFormat(pixelFormat),
5353
_width(width),
5454
_height(height),
55+
_frameByteSize(-1),
5556
_cropLeft(0),
5657
_cropRight(0),
5758
_cropTop(0),
@@ -426,32 +427,35 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
426427
throw_errno_exception("VIDIOC_G_FMT");
427428
}
428429

429-
// check pixel format
430+
// store width & height
431+
_width = fmt.fmt.pix.width;
432+
_height = fmt.fmt.pix.height;
433+
434+
// print the eventually used width and height
435+
std::cout << "V4L2 width=" << _width << " height=" << _height << std::endl;
436+
437+
// check pixel format and frame size
430438
switch (fmt.fmt.pix.pixelformat)
431439
{
432440
case V4L2_PIX_FMT_UYVY:
433441
_pixelFormat = PIXELFORMAT_UYVY;
442+
_frameByteSize = _width * _height * 2;
434443
std::cout << "V4L2 pixel format=UYVY" << std::endl;
435444
break;
436445
case V4L2_PIX_FMT_YUYV:
437446
_pixelFormat = PIXELFORMAT_YUYV;
447+
_frameByteSize = _width * _height * 2;
438448
std::cout << "V4L2 pixel format=YUYV" << std::endl;
439449
break;
440450
case V4L2_PIX_FMT_RGB32:
441451
_pixelFormat = PIXELFORMAT_RGB32;
452+
_frameByteSize = _width * _height * 4;
442453
std::cout << "V4L2 pixel format=RGB32" << std::endl;
443454
break;
444455
default:
445456
throw_exception("Only pixel formats UYVY, YUYV, and RGB32 are supported");
446457
}
447458

448-
// store width & height
449-
_width = fmt.fmt.pix.width;
450-
_height = fmt.fmt.pix.height;
451-
452-
// print the eventually used width and height
453-
std::cout << "V4L2 width=" << _width << " height=" << _height << std::endl;
454-
455459
switch (_ioMethod) {
456460
case IO_METHOD_READ:
457461
init_read(fmt.fmt.pix.sizeimage);
@@ -667,9 +671,9 @@ bool V4L2Grabber::process_image(const void *p, int size)
667671
{
668672
// We do want a new frame...
669673

670-
if (size != 2*_width*_height)
674+
if (size != _frameByteSize)
671675
{
672-
std::cout << "Frame too small: " << size << " != " << (2*_width*_height) << std::endl;
676+
std::cout << "Frame too small: " << size << " != " << _frameByteSize << std::endl;
673677
}
674678
else
675679
{

0 commit comments

Comments
 (0)