{"id":8719,"url":"https://patchwork.libcamera.org/api/patches/8719/?format=json","web_url":"https://patchwork.libcamera.org/patch/8719/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200709132835.112593-5-paul.elder@ideasonboard.com>","date":"2020-07-09T13:28:16","name":"[libcamera-devel,v5,04/23] libcamera: V4L2VideoDevice: Add tryFormat","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"00499d3722dfc3cd41e2d5bdfab7611d7cae1b80","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8719/mbox/","series":[{"id":1093,"url":"https://patchwork.libcamera.org/api/series/1093/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1093","date":"2020-07-09T13:28:12","name":"Clean up formats in v4l2-compat and pipeline handlers","version":5,"mbox":"https://patchwork.libcamera.org/series/1093/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8719/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8719/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 029EDBD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jul 2020 13:29:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C500861218;\n\tThu,  9 Jul 2020 15:29:00 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D0FD261184\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jul 2020 15:28:58 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A163525;\n\tThu,  9 Jul 2020 15:28:56 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"qvuyi2Le\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594301338;\n\tbh=PxDSet/16HucKK+x7HS6TY+XJlYm0Q10XoAIslw2Nlc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=qvuyi2LeobF0VNAPgLMxW3T9cAYoC7bL32A7YEoSo2NLytMMlNgS7C159w5/5hlBE\n\tip3ByCeW533tHKa0Pqj8Vl49r3fKGVjqQc1wenFog7XaMvdPGsdWzKdDNsVFWTkkho\n\t1yDz9kgkLdS+Ys2Ep1GUu6oU1voNM9TKa/d/uwZg=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  9 Jul 2020 22:28:16 +0900","Message-Id":"<20200709132835.112593-5-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200709132835.112593-1-paul.elder@ideasonboard.com>","References":"<20200709132835.112593-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v5 04/23] libcamera: V4L2VideoDevice: Add\n\ttryFormat","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add tryFormat and its variations (meta, single-plane, multi-plane) to\nV4L2VideoDevice.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\n---\nCosmetic change in v5\n\nChanges in v4:\n- merge tryFormat{Meta,Multiplane,SinglePlane} into setFormat with a\n  flag\n\nNew in v3\n---\n include/libcamera/internal/v4l2_videodevice.h |  7 +--\n src/libcamera/v4l2_videodevice.cpp            | 50 ++++++++++++++-----\n 2 files changed, 42 insertions(+), 15 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 4d21f5a..fb4c0aa 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -186,6 +186,7 @@ public:\n \tconst V4L2Capability &caps() const { return caps_; }\n \n \tint getFormat(V4L2DeviceFormat *format);\n+\tint tryFormat(V4L2DeviceFormat *format);\n \tint setFormat(V4L2DeviceFormat *format);\n \tstd::map<V4L2PixelFormat, std::vector<SizeRange>> formats(uint32_t code = 0);\n \n@@ -217,13 +218,13 @@ protected:\n \n private:\n \tint getFormatMeta(V4L2DeviceFormat *format);\n-\tint setFormatMeta(V4L2DeviceFormat *format);\n+\tint trySetFormatMeta(V4L2DeviceFormat *format, bool set);\n \n \tint getFormatMultiplane(V4L2DeviceFormat *format);\n-\tint setFormatMultiplane(V4L2DeviceFormat *format);\n+\tint trySetFormatMultiplane(V4L2DeviceFormat *format, bool set);\n \n \tint getFormatSingleplane(V4L2DeviceFormat *format);\n-\tint setFormatSingleplane(V4L2DeviceFormat *format);\n+\tint trySetFormatSingleplane(V4L2DeviceFormat *format, bool set);\n \n \tstd::vector<V4L2PixelFormat> enumPixelformats(uint32_t code);\n \tstd::vector<SizeRange> enumSizes(V4L2PixelFormat pixelFormat);\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 3614b2e..e0d2201 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -723,6 +723,26 @@ int V4L2VideoDevice::getFormat(V4L2DeviceFormat *format)\n \t\treturn getFormatSingleplane(format);\n }\n \n+/**\n+ * \\brief Try an image format on the V4L2 video device\n+ * \\param[inout] format The image format to test applicability to the video device\n+ *\n+ * Try the supplied \\a format on the video device without applying it, returning\n+ * the format that would be applied. This is equivalent to setFormat(), except\n+ * that the device configuration is not changed.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2VideoDevice::tryFormat(V4L2DeviceFormat *format)\n+{\n+\tif (caps_.isMeta())\n+\t\treturn trySetFormatMeta(format, false);\n+\telse if (caps_.isMultiplanar())\n+\t\treturn trySetFormatMultiplane(format, false);\n+\telse\n+\t\treturn trySetFormatSingleplane(format, false);\n+}\n+\n /**\n  * \\brief Configure an image format on the V4L2 video device\n  * \\param[inout] format The image format to apply to the video device\n@@ -735,11 +755,11 @@ int V4L2VideoDevice::getFormat(V4L2DeviceFormat *format)\n int V4L2VideoDevice::setFormat(V4L2DeviceFormat *format)\n {\n \tif (caps_.isMeta())\n-\t\treturn setFormatMeta(format);\n+\t\treturn trySetFormatMeta(format, true);\n \telse if (caps_.isMultiplanar())\n-\t\treturn setFormatMultiplane(format);\n+\t\treturn trySetFormatMultiplane(format, true);\n \telse\n-\t\treturn setFormatSingleplane(format);\n+\t\treturn trySetFormatSingleplane(format, true);\n }\n \n int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n@@ -765,7 +785,7 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n \treturn 0;\n }\n \n-int V4L2VideoDevice::setFormatMeta(V4L2DeviceFormat *format)\n+int V4L2VideoDevice::trySetFormatMeta(V4L2DeviceFormat *format, bool set)\n {\n \tstruct v4l2_format v4l2Format = {};\n \tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n@@ -774,9 +794,11 @@ int V4L2VideoDevice::setFormatMeta(V4L2DeviceFormat *format)\n \tv4l2Format.type = bufferType_;\n \tpix->dataformat = format->fourcc;\n \tpix->buffersize = format->planes[0].size;\n-\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n+\tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Unable to \" << (set ? \"set\" : \"try\")\n+\t\t\t<< \" format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n \n@@ -820,7 +842,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n \treturn 0;\n }\n \n-int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format)\n+int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n {\n \tstruct v4l2_format v4l2Format = {};\n \tstruct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp;\n@@ -838,9 +860,11 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format)\n \t\tpix->plane_fmt[i].sizeimage = format->planes[i].size;\n \t}\n \n-\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n+\tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Unable to \" << (set ? \"set\" : \"try\")\n+\t\t\t<< \" format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n \n@@ -883,7 +907,7 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n \treturn 0;\n }\n \n-int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n+int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n {\n \tstruct v4l2_format v4l2Format = {};\n \tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n@@ -895,9 +919,11 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n \tpix->pixelformat = format->fourcc;\n \tpix->bytesperline = format->planes[0].bpl;\n \tpix->field = V4L2_FIELD_NONE;\n-\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n+\tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Unable to \" << (set ? \"set\" : \"try\")\n+\t\t\t<< \" format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n \n","prefixes":["libcamera-devel","v5","04/23"]}