Patch Detail
Show a patch.
GET /api/1.1/patches/16643/?format=api
{ "id": 16643, "url": "https://patchwork.libcamera.org/api/1.1/patches/16643/?format=api", "web_url": "https://patchwork.libcamera.org/patch/16643/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20220715135007.53574-6-jacopo@jmondi.org>", "date": "2022-07-15T13:50:05", "name": "[libcamera-devel,5/7] libcamera: v4l2_videodevice: Match formats supported by the device", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "adaafe8f51b2ba29f881bd30202b0ee21acc6d4a", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/16643/mbox/", "series": [ { "id": 3288, "url": "https://patchwork.libcamera.org/api/1.1/series/3288/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3288", "date": "2022-07-15T13:50:00", "name": "libcamera: Map multiple V4L2 formats to a single libcamera::format", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3288/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/16643/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/16643/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 9D526BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Jul 2022 13:50:28 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 65A1D63321;\n\tFri, 15 Jul 2022 15:50:28 +0200 (CEST)", "from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::223])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 162FC6331D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Jul 2022 15:50:26 +0200 (CEST)", "(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id D5FDD60010;\n\tFri, 15 Jul 2022 13:50:24 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1657893028;\n\tbh=6mdHx4ftcLUdI3VBL+yXdKQLM6DwYHnxc4PojlzUZlk=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=yqesC1qsR/LhF8XBr6JcKrgpLzSZ1P3b1K9u5FV7HwSTxQ90WiAEpejIRDAu3lZey\n\tOW+r3PAEmlfuyU15q1b4oG2vMK4SN2vMGrJuGX9M6hvhVX1HbRw75JMFqQwj7LO81z\n\tT2t4vM7GWATy73xFdsvj45vBgnib+3Vh0O9VjlD3DTXSlsKrUlHOZ0NqlSZHQS3HUk\n\te6Lxh0ABjUzgymfRbgTvq6X6xymp2Hz/T1x7JhlR3sMMDGoUUoCj2MyKIIOHCKAoCf\n\tRnyzrkcqwcWxVvtd0jQzS1MT8Cvhdwus8RV68N7Vj5yTCWrzKABV/aYpbTWT9IDHmf\n\tXfClwdnvNPlbQ==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 15 Jul 2022 15:50:05 +0200", "Message-Id": "<20220715135007.53574-6-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.36.1", "In-Reply-To": "<20220715135007.53574-1-jacopo@jmondi.org>", "References": "<20220715135007.53574-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 5/7] libcamera: v4l2_videodevice: Match\n\tformats supported by the device", "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>", "From": "Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Jacopo Mondi <jacopo@jmondi.org>", "Cc": "jozef@mlich.cz, Pavel Machek <pavel@ucw.cz>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Now that V4L2PixelFormat::fromPixelFormat() returns a list of formats\nto chose from by checking which ones are actually supported by the video\ndevice.\n\nThe first format found to match one of the device supported ones is\nreturned.\n\nAs V4L2VideoDevice::toV4L2PixelFormat() is a const function which uses\nother functions of the class, those functions has to be made const as\nwell.\n\nIn particular:\n\n- enumPixelformats() and enumSizes() do not modify the class state and\n can safely be made const.\n- formats() uses the above functions and does not itself modify the\n class state and can be made const\n- add a const version of V4L2Device::ioctl() to be used by the now const\n functions\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/internal/v4l2_device.h | 1 +\n include/libcamera/internal/v4l2_videodevice.h | 6 ++--\n src/libcamera/v4l2_device.cpp | 15 +++++++++\n src/libcamera/v4l2_videodevice.cpp | 31 ++++++++++++++-----\n 4 files changed, 43 insertions(+), 10 deletions(-)", "diff": "diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex a52a5f2c99f9..f7ec3c7004a6 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -55,6 +55,7 @@ protected:\n \tint setFd(UniqueFD fd);\n \n \tint ioctl(unsigned long request, void *argp);\n+\tint ioctl(unsigned long request, void *argp) const;\n \n \tint fd() const { return fd_.get(); }\n \ndiff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 29fa0bbaf670..6d8850c99afd 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -205,7 +205,7 @@ public:\n \tint getFormat(V4L2DeviceFormat *format);\n \tint tryFormat(V4L2DeviceFormat *format);\n \tint setFormat(V4L2DeviceFormat *format);\n-\tFormats formats(uint32_t code = 0);\n+\tFormats formats(uint32_t code = 0) const;\n \n \tint setSelection(unsigned int target, Rectangle *rect);\n \n@@ -251,8 +251,8 @@ private:\n \tint getFormatSingleplane(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);\n+\tstd::vector<V4L2PixelFormat> enumPixelformats(uint32_t code) const;\n+\tstd::vector<SizeRange> enumSizes(V4L2PixelFormat pixelFormat) const;\n \n \tint requestBuffers(unsigned int count, enum v4l2_memory memoryType);\n \tint createBuffers(unsigned int count,\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 3fc8438f6579..59f92403db80 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -459,6 +459,21 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n \treturn 0;\n }\n \n+/**\n+ * \\copydoc ioctl()\n+ */\n+int V4L2Device::ioctl(unsigned long request, void *argp) const\n+{\n+\t/*\n+\t * Printing out an error message is usually better performed\n+\t * in the caller, which can provide more context.\n+\t */\n+\tif (::ioctl(fd_.get(), request, argp) < 0)\n+\t\treturn -errno;\n+\n+\treturn 0;\n+}\n+\n /**\n * \\fn V4L2Device::deviceNode()\n * \\brief Retrieve the device node path\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 43c3d0f69266..a3242ba755c0 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1045,7 +1045,7 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n *\n * \\return A list of the supported video device formats\n */\n-V4L2VideoDevice::Formats V4L2VideoDevice::formats(uint32_t code)\n+V4L2VideoDevice::Formats V4L2VideoDevice::formats(uint32_t code) const\n {\n \tFormats formats;\n \n@@ -1067,7 +1067,7 @@ V4L2VideoDevice::Formats V4L2VideoDevice::formats(uint32_t code)\n \treturn formats;\n }\n \n-std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats(uint32_t code)\n+std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats(uint32_t code) const\n {\n \tstd::vector<V4L2PixelFormat> formats;\n \tint ret;\n@@ -1101,7 +1101,7 @@ std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats(uint32_t code)\n \treturn formats;\n }\n \n-std::vector<SizeRange> V4L2VideoDevice::enumSizes(V4L2PixelFormat pixelFormat)\n+std::vector<SizeRange> V4L2VideoDevice::enumSizes(V4L2PixelFormat pixelFormat) const\n {\n \tstd::vector<SizeRange> sizes;\n \tint ret;\n@@ -1990,20 +1990,37 @@ V4L2VideoDevice::fromEntityName(const MediaDevice *media,\n }\n \n /**\n- * \\brief Convert \\a PixelFormat to its corresponding V4L2 FourCC\n+ * \\brief Convert \\a PixelFormat to one of the device supported V4L2 FourCC\n * \\param[in] pixelFormat The PixelFormat to convert\n *\n+ * Convert a\\ pixelformat to a V4L2 FourCC that is known to be supported by\n+ * the video device.\n+ *\n * For multiplanar formats, the V4L2 format variant (contiguous or\n * non-contiguous planes) is selected automatically based on the capabilities\n * of the video device. If the video device supports the V4L2 multiplanar API,\n * non-contiguous formats are preferred.\n *\n- * \\return The V4L2_PIX_FMT_* pixel format code corresponding to \\a pixelFormat\n+ * \\return The V4L2PixelFormat corresponding to \\a pixelFormat or an invalid\n+ * PixelFormat if \\a pixelFormat is not supported by the video device\n */\n V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelFormat) const\n {\n-\treturn V4L2PixelFormat::fromPixelFormat(pixelFormat,\n-\t\t\t\t\t\tcaps_.isMultiplanar())[0];\n+\tstd::vector<V4L2PixelFormat> deviceFormats = enumPixelformats(0);\n+\tstd::vector<V4L2PixelFormat> v4l2PixelFormats =\n+\t\tV4L2PixelFormat::fromPixelFormat(pixelFormat, caps_.isMultiplanar());\n+\n+\tfor (const V4L2PixelFormat &v4l2Format : v4l2PixelFormats) {\n+\t\tauto it = std::find_if(deviceFormats.begin(), deviceFormats.end(),\n+\t\t\t\t [&v4l2Format](const V4L2PixelFormat &deviceFormat) {\n+\t\t\t\t\t return v4l2Format == deviceFormat;\n+\t\t\t\t });\n+\n+\t\tif (it != deviceFormats.end())\n+\t\t\treturn v4l2Format;\n+\t}\n+\n+\treturn {};\n }\n \n /**\n", "prefixes": [ "libcamera-devel", "5/7" ] }