From patchwork Tue Aug 9 14:49:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 17051 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 90CECBE173 for ; Tue, 9 Aug 2022 14:49:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2FA4E6332D; Tue, 9 Aug 2022 16:49:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660056582; bh=V6qQsGIJffd9lwKUlD8MmIVbrOEIjXDWjXTAn79TKBM=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VWDtioaWuYQ3J1zf0WcWaTiwWwwf7aCiltfki8OKAF1/cfNpQuiSMjephtfQazvG+ /CKZ6Dg0VFq9FImrOqHLlTGgzg+e1KCrRs2wvtX58D8zny9J1FRFrXmtqcby6em0fj 5PuNM2vWpLfVsEn6NM3vhA9rwnwPin7wlUwJkRbwM9hppaps2kwSgyUwcvyGFGuMNo oseUENcCBaMtkQwbbUKt+Ja7Iqv6i3WPGGNN2QdGJtavSBw6iHW7GKTDCw7Ep1LSdw rAFznE7oBIgMn91U1U9dSWXMlFDMK2u8z7IcXl4pAF/rW5ghUSZfzvm+8VeRWxIPkG FeglwGzEfO1nw== Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F160761FAA for ; Tue, 9 Aug 2022 16:49:40 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 3BFD224000D; Tue, 9 Aug 2022 14:49:39 +0000 (UTC) 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 Subject: [libcamera-devel] [PATCH v2] libcamera: formats: Fix warning for unkown V4L2 pixfmt X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Commit f25ad4a2b16b ("libcamera: formats: Reimplement V4L2 PixelFormatInfo::info()") changed the PixelFormatInfo::info(const V4L2PixelFormat &format) function overload to: return info(format.toPixelFormat()); As part of the series that contains such commit, the PixelFormatInfo for the pixel format applied to a video device is now retrieved at V4L2VideoDevice::open() time. Some video devices register formats not available to applications, for example metadata formats or, in the case of ISP devices, formats to describe the ISP statistics and parameters. This causes the format.toPixelFormat() call to output a WARN message, which spams the log and unnecessary alert the users. Augment V4L2PixelFormat::toPixelFormat() with an optional argument to suppress warnings in the case a V4L2 pixel format is not known, to restore the behaviour preceding commit f25ad4a2b16b and returns an invalid PixelFormatInfo without outputting any unnecessary warning message. Fixes: f25ad4a2b16b ("libcamera: formats: Reimplement V4L2 PixelFormatInfo::info()") Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain Tested-by: Naushir Patuck Reviewed-by: Naushir Patuck --- This is the version suggested by Laurent of [PATCH] libcamera: formats: Search V4L2 format info on map I don't like it too much but there's a slight performance improvement. --- include/libcamera/internal/v4l2_pixelformat.h | 2 +- src/libcamera/formats.cpp | 10 +++++++++- src/libcamera/v4l2_pixelformat.cpp | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) -- 2.37.1 diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h index 34d283db44f4..44439fff73eb 100644 --- a/include/libcamera/internal/v4l2_pixelformat.h +++ b/include/libcamera/internal/v4l2_pixelformat.h @@ -45,7 +45,7 @@ public: std::string toString() const; const char *description() const; - PixelFormat toPixelFormat() const; + PixelFormat toPixelFormat(bool warn = true) const; static const std::vector & fromPixelFormat(const PixelFormat &pixelFormat); diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 0bd0e09ae44c..f5769c489e16 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -852,7 +852,15 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format) */ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format) { - return info(format.toPixelFormat()); + PixelFormat pixelFormat = format.toPixelFormat(false); + if (!pixelFormat.isValid()) + return pixelFormatInfoInvalid; + + const auto iter = pixelFormatInfo.find(pixelFormat); + if (iter == pixelFormatInfo.end()) + return pixelFormatInfoInvalid; + + return iter->second; } /** diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index 3590fb735011..26c9f02c759f 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -294,15 +294,23 @@ const char *V4L2PixelFormat::description() const /** * \brief Convert the V4L2 pixel format to the corresponding PixelFormat + * \param[in] warn Flag to control the warning message if the format is not + * supported. Default to true, set to false to suppress warning message. + * + * Users of this function might try to convert a V4L2PixelFormat to a PixelFormat + * just to check if the format is supported or not. In that case, they can suppress + * the warning message setting the \a warn argument to false not not pollute the log + * with unnecessary warning messages. + * * \return The PixelFormat corresponding to the V4L2 pixel format */ -PixelFormat V4L2PixelFormat::toPixelFormat() const +PixelFormat V4L2PixelFormat::toPixelFormat(bool warn) const { const auto iter = vpf2pf.find(*this); if (iter == vpf2pf.end()) { - LOG(V4L2, Warning) - << "Unsupported V4L2 pixel format " - << toString(); + if (warn) + LOG(V4L2, Warning) << "Unsupported V4L2 pixel format " + << toString(); return PixelFormat(); }