Patch Detail
Show a patch.
GET /api/patches/16874/?format=api
{ "id": 16874, "url": "https://patchwork.libcamera.org/api/patches/16874/?format=api", "web_url": "https://patchwork.libcamera.org/patch/16874/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20220729160014.101503-6-jacopo@jmondi.org>", "date": "2022-07-29T16:00:13", "name": "[libcamera-devel,v3,5/6] libcamera: v4l2_videodevice: Match formats supported by the device", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "34996d04ab1e7e1e6689c459ce391a93316f35db", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/16874/mbox/", "series": [ { "id": 3350, "url": "https://patchwork.libcamera.org/api/series/3350/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3350", "date": "2022-07-29T16:00:08", "name": "libcamera: Map multiple V4L2 formats to a single libcamera::format", "version": 3, "mbox": "https://patchwork.libcamera.org/series/3350/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/16874/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/16874/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 DF382C3276\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 29 Jul 2022 16:00:31 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 27E5863325;\n\tFri, 29 Jul 2022 18:00:31 +0200 (CEST)", "from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::222])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4FDCE6330E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Jul 2022 18:00:28 +0200 (CEST)", "(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 5690B4000B;\n\tFri, 29 Jul 2022 16:00:27 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659110431;\n\tbh=xEIkQECEDo9mFcs3lL/UrHQOEcje4O278P0Pke+HUCY=;\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=AZ3Z3eG41+0oktmejd/01g0kg8UWWs9lWtvBESWIeZUK8WQw6LTIKtwWykCFm8acq\n\tgska1Rx5X2hODcCsqdZmJIshiLE+HVPR9JWHm+JORYSNSq+5KZCkNBz0A7Ps8IRwgo\n\tkBd0+o1FFlgGcqy9YEU5rIOwtiN7tJiaYICS8GykJSQ2Tz8I4e6T/tpLZ3CXwsfX5K\n\t2cxKaHmOaa60GO4VVnS9EiXsF6dsSjDgJDob+R34HcWfyFiz/dIrh6ZaU6/RWOk9zn\n\tjv6pYQ4CjnptqTYdQ6t2Q1XSycWorHbgovNju7D1lPwq3ofLFF0kcm44ezPEn555O3\n\t1Ad+3p8hiMYLQ==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 29 Jul 2022 18:00:13 +0200", "Message-Id": "<20220729160014.101503-6-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.37.1", "In-Reply-To": "<20220729160014.101503-1-jacopo@jmondi.org>", "References": "<20220729160014.101503-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 5/6] 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, select the one supported by the video device by matching\nagainst the list of supported pixel formats.\n\nThe first format found to match one of the device supported ones is\nreturned.\n\nAs the list of pixel formats supported by the video device does not\nchange at run-time, cache it at device open() time.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/internal/v4l2_videodevice.h | 1 +\n src/libcamera/v4l2_videodevice.cpp | 28 +++++++++++++++----\n 2 files changed, 24 insertions(+), 5 deletions(-)", "diff": "diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 29fa0bbaf670..6fe81d5e4cf0 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -268,6 +268,7 @@ private:\n \tV4L2Capability caps_;\n \tV4L2DeviceFormat format_;\n \tconst PixelFormatInfo *formatInfo_;\n+\tstd::vector<V4L2PixelFormat> pixelFormats_;\n \n \tenum v4l2_buf_type bufferType_;\n \tenum v4l2_memory memoryType_;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 2ca22f485d45..0aeaae6ad573 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -633,6 +633,8 @@ int V4L2VideoDevice::open()\n \t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n \t\t<< caps_.driver() << \": \" << caps_.card();\n \n+\tpixelFormats_ = enumPixelformats(0);\n+\n \tret = getFormat(&format_);\n \tif (ret) {\n \t\tLOG(V4L2, Error) << \"Failed to get format\";\n@@ -726,6 +728,8 @@ int V4L2VideoDevice::open(SharedFD handle, enum v4l2_buf_type type)\n \t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n \t\t<< caps_.driver() << \": \" << caps_.card();\n \n+\tpixelFormats_ = enumPixelformats(0);\n+\n \tret = getFormat(&format_);\n \tif (ret) {\n \t\tLOG(V4L2, Error) << \"Failed to get format\";\n@@ -1990,17 +1994,31 @@ 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- * The V4L2 format variant the function returns the contiguous version\n- * unconditionally.\n+ * Convert a\\ pixelformat to a V4L2 FourCC that is known to be supported by\n+ * the video device.\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)[0];\n+\tstd::vector<V4L2PixelFormat> v4l2PixelFormats =\n+\t\tV4L2PixelFormat::fromPixelFormat(pixelFormat);\n+\n+\tfor (const V4L2PixelFormat &v4l2Format : v4l2PixelFormats) {\n+\t\tauto it = std::find_if(pixelFormats_.begin(), pixelFormats_.end(),\n+\t\t\t\t [&v4l2Format](const V4L2PixelFormat &devFormat) {\n+\t\t\t\t\t return v4l2Format == devFormat;\n+\t\t\t\t });\n+\n+\t\tif (it != pixelFormats_.end())\n+\t\t\treturn v4l2Format;\n+\t}\n+\n+\treturn {};\n }\n \n /**\n", "prefixes": [ "libcamera-devel", "v3", "5/6" ] }