From patchwork Thu Sep 9 08:08:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 13775 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 DFCC9BDC71 for ; Thu, 9 Sep 2021 08:09:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A223169178; Thu, 9 Sep 2021 10:09:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nXv04fz6"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8CEB469177 for ; Thu, 9 Sep 2021 10:09:21 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0307C24F; Thu, 9 Sep 2021 10:09:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1631174961; bh=kcl1JC+vWPyfwvqCjoA5NVVXXDkUDuFfoOec44dSbvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nXv04fz6yrAVpiDW1WnCQet0FN13/hQ5sXdige9ssjfliYjhsxVNa68J3rYC+xT8l lCIL7pRgSjQcX9arJiywxb+vmEJd9CxgI2fWrWBj9wErnTDZ9uFIL0dFWdm0aclzDi c9XNUwEYpELORBO0Tyd+epQ3n9YMWV94CtuWz11E= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Thu, 9 Sep 2021 17:08:59 +0900 Message-Id: <20210909080902.239533-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210909080902.239533-1-paul.elder@ideasonboard.com> References: <20210909080902.239533-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/7] libcamera: v4l2_pixelformat: Add helper function to get the description 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a helper function to V4L2PixelFormat for retrieving the V4L2 description string. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jean-Michel Hautbois --- include/libcamera/internal/v4l2_pixelformat.h | 1 + src/libcamera/v4l2_pixelformat.cpp | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h index 87872542..e3cda699 100644 --- a/include/libcamera/internal/v4l2_pixelformat.h +++ b/include/libcamera/internal/v4l2_pixelformat.h @@ -40,6 +40,7 @@ public: operator uint32_t() const { return fourcc_; } std::string toString() const; + const char *description() const; PixelFormat toPixelFormat() const; static V4L2PixelFormat fromPixelFormat(const PixelFormat &pixelFormat, diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index 2c8167a7..fed31238 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -250,6 +250,27 @@ std::string V4L2PixelFormat::toString() const return ss; } +/** + * \brief Retrieve the V4L2 description for the format + * + * The description matches the value used by the kernel, as would be reported + * by the VIDIOC_ENUM_FMT ioctl. + * + * \return The V4L2 description corresponding to the V4L2 format + */ +const char *V4L2PixelFormat::description() const +{ + const auto iter = vpf2pf.find(*this); + if (iter == vpf2pf.end()) { + LOG(V4L2, Warning) + << "Unsupported V4L2 pixel format " + << toString(); + return "Unsupported format"; + } + + return iter->second.description; +} + /** * \brief Convert the V4L2 pixel format to the corresponding PixelFormat * \return The PixelFormat corresponding to the V4L2 pixel format