{"id":17051,"url":"https://patchwork.libcamera.org/api/patches/17051/?format=json","web_url":"https://patchwork.libcamera.org/patch/17051/","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":"<20220809144935.50417-1-jacopo@jmondi.org>","date":"2022-08-09T14:49:35","name":"[libcamera-devel,v2] libcamera: formats: Fix warning for unkown V4L2 pixfmt","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":true,"hash":"191315fb85ad999e40ed5e37864122cf891d8971","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17051/mbox/","series":[{"id":3399,"url":"https://patchwork.libcamera.org/api/series/3399/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3399","date":"2022-08-09T14:49:35","name":"[libcamera-devel,v2] libcamera: formats: Fix warning for unkown V4L2 pixfmt","version":2,"mbox":"https://patchwork.libcamera.org/series/3399/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17051/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17051/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 90CECBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  9 Aug 2022 14:49:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2FA4E6332D;\n\tTue,  9 Aug 2022 16:49:42 +0200 (CEST)","from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::221])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F160761FAA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  9 Aug 2022 16:49:40 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 3BFD224000D;\n\tTue,  9 Aug 2022 14:49:39 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660056582;\n\tbh=V6qQsGIJffd9lwKUlD8MmIVbrOEIjXDWjXTAn79TKBM=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=VWDtioaWuYQ3J1zf0WcWaTiwWwwf7aCiltfki8OKAF1/cfNpQuiSMjephtfQazvG+\n\t/CKZ6Dg0VFq9FImrOqHLlTGgzg+e1KCrRs2wvtX58D8zny9J1FRFrXmtqcby6em0fj\n\t5PuNM2vWpLfVsEn6NM3vhA9rwnwPin7wlUwJkRbwM9hppaps2kwSgyUwcvyGFGuMNo\n\toseUENcCBaMtkQwbbUKt+Ja7Iqv6i3WPGGNN2QdGJtavSBw6iHW7GKTDCw7Ep1LSdw\n\trAFznE7oBIgMn91U1U9dSWXMlFDMK2u8z7IcXl4pAF/rW5ghUSZfzvm+8VeRWxIPkG\n\tFeglwGzEfO1nw==","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  9 Aug 2022 16:49:35 +0200","Message-Id":"<20220809144935.50417-1-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.37.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2] libcamera: formats: Fix warning for\n\tunkown V4L2 pixfmt","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Commit f25ad4a2b16b (\"libcamera: formats: Reimplement V4L2\nPixelFormatInfo::info()\") changed the PixelFormatInfo::info(const\nV4L2PixelFormat &format) function overload to:\n\n\treturn info(format.toPixelFormat());\n\nAs part of the series that contains such commit, the PixelFormatInfo for the\npixel format applied to a video device is now retrieved at\nV4L2VideoDevice::open() time. Some video devices register formats not\navailable to applications, for example metadata formats or, in the case\nof ISP devices, formats to describe the ISP statistics and parameters.\n\nThis causes the\n\n\tformat.toPixelFormat()\n\ncall to output a WARN message, which spams the log and unnecessary alert\nthe users.\n\nAugment V4L2PixelFormat::toPixelFormat() with an optional argument to\nsuppress warnings in the case a V4L2 pixel format is not known, to\nrestore the behaviour preceding commit f25ad4a2b16b and returns an\ninvalid PixelFormatInfo without outputting any unnecessary warning\nmessage.\n\nFixes: f25ad4a2b16b (\"libcamera: formats: Reimplement V4L2 PixelFormatInfo::info()\")\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n\nThis is the version suggested by Laurent of\n[PATCH] libcamera: formats: Search V4L2 format info on map\n\nI don't like it too much but there's a slight performance improvement.\n\n---\n include/libcamera/internal/v4l2_pixelformat.h |  2 +-\n src/libcamera/formats.cpp                     | 10 +++++++++-\n src/libcamera/v4l2_pixelformat.cpp            | 16 ++++++++++++----\n 3 files changed, 22 insertions(+), 6 deletions(-)\n\n--\n2.37.1","diff":"diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h\nindex 34d283db44f4..44439fff73eb 100644\n--- a/include/libcamera/internal/v4l2_pixelformat.h\n+++ b/include/libcamera/internal/v4l2_pixelformat.h\n@@ -45,7 +45,7 @@ public:\n \tstd::string toString() const;\n \tconst char *description() const;\n\n-\tPixelFormat toPixelFormat() const;\n+\tPixelFormat toPixelFormat(bool warn = true) const;\n \tstatic const std::vector<V4L2PixelFormat> &\n \tfromPixelFormat(const PixelFormat &pixelFormat);\n\ndiff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex 0bd0e09ae44c..f5769c489e16 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -852,7 +852,15 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)\n  */\n const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)\n {\n-\treturn info(format.toPixelFormat());\n+\tPixelFormat pixelFormat = format.toPixelFormat(false);\n+\tif (!pixelFormat.isValid())\n+\t\treturn pixelFormatInfoInvalid;\n+\n+\tconst auto iter = pixelFormatInfo.find(pixelFormat);\n+\tif (iter == pixelFormatInfo.end())\n+\t\treturn pixelFormatInfoInvalid;\n+\n+\treturn iter->second;\n }\n\n /**\ndiff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\nindex 3590fb735011..26c9f02c759f 100644\n--- a/src/libcamera/v4l2_pixelformat.cpp\n+++ b/src/libcamera/v4l2_pixelformat.cpp\n@@ -294,15 +294,23 @@ const char *V4L2PixelFormat::description() const\n\n /**\n  * \\brief Convert the V4L2 pixel format to the corresponding PixelFormat\n+ * \\param[in] warn Flag to control the warning message if the format is not\n+ * supported. Default to true, set to false to suppress warning message.\n+ *\n+ * Users of this function might try to convert a V4L2PixelFormat to a PixelFormat\n+ * just to check if the format is supported or not. In that case, they can suppress\n+ * the warning message setting the \\a warn argument to false not not pollute the log\n+ * with unnecessary warning messages.\n+ *\n  * \\return The PixelFormat corresponding to the V4L2 pixel format\n  */\n-PixelFormat V4L2PixelFormat::toPixelFormat() const\n+PixelFormat V4L2PixelFormat::toPixelFormat(bool warn) const\n {\n \tconst auto iter = vpf2pf.find(*this);\n \tif (iter == vpf2pf.end()) {\n-\t\tLOG(V4L2, Warning)\n-\t\t\t<< \"Unsupported V4L2 pixel format \"\n-\t\t\t<< toString();\n+\t\tif (warn)\n+\t\t\tLOG(V4L2, Warning) << \"Unsupported V4L2 pixel format \"\n+\t\t\t\t\t   << toString();\n \t\treturn PixelFormat();\n \t}\n\n","prefixes":["libcamera-devel","v2"]}