summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-01-07 17:47:09 +0100
committerJacopo Mondi <jacopo@jmondi.org>2020-01-08 11:05:39 +0100
commitfce110c6d961c3bb645289184c59d9443d56e224 (patch)
tree73b68b2081f9aabce910f880d36fac926d637b17 /src
parent769ca0a5503ce99fd9687aa3a3a96eea6242116c (diff)
v4l2: camera_proxy: Break out try_fmt
Calling vidioc_s_fmt() calls vidioc_try_fmt() duplicating prinouts. Breakout try format procedure and call it from both functions. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r--src/v4l2/v4l2_camera_proxy.cpp54
-rw-r--r--src/v4l2/v4l2_camera_proxy.h1
2 files changed, 31 insertions, 24 deletions
diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index 0f1d5ea4..f3a49fea 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -235,13 +235,39 @@ int V4L2CameraProxy::vidioc_g_fmt(struct v4l2_format *arg)
return 0;
}
+void V4L2CameraProxy::tryFormat(struct v4l2_format *arg)
+{
+ PixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat);
+ const std::vector<PixelFormat> &formats =
+ streamConfig_.formats().pixelformats();
+ if (std::find(formats.begin(), formats.end(), format) == formats.end())
+ format = streamConfig_.formats().pixelformats()[0];
+
+ Size size(arg->fmt.pix.width, arg->fmt.pix.height);
+ const std::vector<Size> &sizes = streamConfig_.formats().sizes(format);
+ if (std::find(sizes.begin(), sizes.end(), size) == sizes.end())
+ size = streamConfig_.formats().sizes(format)[0];
+
+ arg->fmt.pix.width = size.width;
+ arg->fmt.pix.height = size.height;
+ arg->fmt.pix.pixelformat = drmToV4L2(format);
+ arg->fmt.pix.field = V4L2_FIELD_NONE;
+ arg->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) *
+ arg->fmt.pix.width;
+ arg->fmt.pix.sizeimage = imageSize(drmToV4L2(format),
+ arg->fmt.pix.width,
+ arg->fmt.pix.height);
+ arg->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
+}
+
int V4L2CameraProxy::vidioc_s_fmt(struct v4l2_format *arg)
{
LOG(V4L2Compat, Debug) << "Servicing vidioc_s_fmt";
- int ret = vidioc_try_fmt(arg);
- if (ret < 0)
- return ret;
+ if (!validateBufferType(arg->type))
+ return -EINVAL;
+
+ tryFormat(arg);
Size size(arg->fmt.pix.width, arg->fmt.pix.height);
ret = vcam_->invokeMethod(&V4L2Camera::configure,
@@ -269,27 +295,7 @@ int V4L2CameraProxy::vidioc_try_fmt(struct v4l2_format *arg)
if (!validateBufferType(arg->type))
return -EINVAL;
- PixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat);
- const std::vector<PixelFormat> &formats =
- streamConfig_.formats().pixelformats();
- if (std::find(formats.begin(), formats.end(), format) == formats.end())
- format = streamConfig_.formats().pixelformats()[0];
-
- Size size(arg->fmt.pix.width, arg->fmt.pix.height);
- const std::vector<Size> &sizes = streamConfig_.formats().sizes(format);
- if (std::find(sizes.begin(), sizes.end(), size) == sizes.end())
- size = streamConfig_.formats().sizes(format)[0];
-
- arg->fmt.pix.width = size.width;
- arg->fmt.pix.height = size.height;
- arg->fmt.pix.pixelformat = drmToV4L2(format);
- arg->fmt.pix.field = V4L2_FIELD_NONE;
- arg->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) *
- arg->fmt.pix.width;
- arg->fmt.pix.sizeimage = imageSize(drmToV4L2(format),
- arg->fmt.pix.width,
- arg->fmt.pix.height);
- arg->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
+ tryFormat(arg);
return 0;
}
diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h
index 3d702084..b59d19d7 100644
--- a/src/v4l2/v4l2_camera_proxy.h
+++ b/src/v4l2/v4l2_camera_proxy.h
@@ -39,6 +39,7 @@ private:
void setFmtFromConfig(StreamConfiguration &streamConfig);
unsigned int calculateSizeImage(StreamConfiguration &streamConfig);
void querycap(std::shared_ptr<Camera> camera);
+ void tryFormat(struct v4l2_format *arg);
void updateBuffers();
int freeBuffers();