Merge pull request #606 from Paulchen-Panther/v4l2

V4L2 Grabber fixes
This commit is contained in:
Paulchen Panther 2019-08-21 17:45:29 +02:00 committed by GitHub
commit 1093278d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -496,8 +496,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
// set the video standard if needed and supported // set the video standard if needed and supported
v4l2_std_id std_id; v4l2_std_id std_id;
if (-1 != xioctl(VIDIOC_ENUMSTD, &std_id))
if (0 == xioctl(VIDIOC_QUERYSTD, &std_id))
{ {
switch (videoStandard) switch (videoStandard)
{ {
@ -507,7 +506,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_S_STD, &std_id)) if (-1 == xioctl(VIDIOC_S_STD, &std_id))
{ {
throw_errno_exception("VIDIOC_S_STD"); throw_errno_exception("VIDIOC_S_STD");
return; break;
} }
} }
break; break;
@ -518,7 +517,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_S_STD, &std_id)) if (-1 == xioctl(VIDIOC_S_STD, &std_id))
{ {
throw_errno_exception("VIDIOC_S_STD"); throw_errno_exception("VIDIOC_S_STD");
return; break;
} }
} }
break; break;
@ -529,7 +528,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_S_STD, &std_id)) if (-1 == xioctl(VIDIOC_S_STD, &std_id))
{ {
throw_errno_exception("VIDIOC_S_STD"); throw_errno_exception("VIDIOC_S_STD");
return; break;
} }
} }
break; break;
@ -541,7 +540,6 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
} }
} }
// get the current settings // get the current settings
struct v4l2_format fmt; struct v4l2_format fmt;
CLEAR(fmt); CLEAR(fmt);
@ -582,9 +580,45 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
break; break;
} }
// get maximum video devices resolution
__u32 max_width = 0, max_height = 0;
struct v4l2_fmtdesc fmtdesc;
CLEAR(fmtdesc);
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmtdesc.index = 0;
while (xioctl(VIDIOC_ENUM_FMT, &fmtdesc) >= 0)
{
v4l2_frmsizeenum frmsizeenum;
CLEAR(frmsizeenum);
frmsizeenum.pixel_format = fmtdesc.pixelformat;
frmsizeenum.index = 0;
while (xioctl(VIDIOC_ENUM_FRAMESIZES, &frmsizeenum) >= 0)
{
switch (frmsizeenum.type)
{
case V4L2_FRMSIZE_TYPE_DISCRETE:
{
max_width = std::max(max_width, frmsizeenum.discrete.width);
max_height = std::max(max_height, frmsizeenum.discrete.height);
}
break;
case V4L2_FRMSIZE_TYPE_CONTINUOUS:
case V4L2_FRMSIZE_TYPE_STEPWISE:
{
max_width = std::max(max_width, frmsizeenum.stepwise.max_width);
max_height = std::max(max_height, frmsizeenum.stepwise.max_height);
}
}
frmsizeenum.index++;
}
fmtdesc.index++;
}
// set the settings // set the settings
fmt.fmt.pix.width = _width; fmt.fmt.pix.width = max_width;
fmt.fmt.pix.height = _height; fmt.fmt.pix.height = max_height;
if (-1 == xioctl(VIDIOC_S_FMT, &fmt)) if (-1 == xioctl(VIDIOC_S_FMT, &fmt))
{ {
@ -597,7 +631,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
_height = fmt.fmt.pix.height; _height = fmt.fmt.pix.height;
// display the used width and height // display the used width and height
Debug(_log, "width=%d height=%d", _width, _height ); Debug(_log, "Set resolution to width=%d height=%d", _width, _height );
// Trying to set frame rate // Trying to set frame rate
struct v4l2_streamparm streamparms; struct v4l2_streamparm streamparms;