From patchwork Mon Aug 1 00:05:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16884 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 D876CBE173 for ; Mon, 1 Aug 2022 00:06:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9488563324; Mon, 1 Aug 2022 02:06:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659312360; bh=kZQqKOqEk25DG04dnPMzNXJsFpWWwX0BeBdyUElzE4s=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iWjbYLQgoK5EF5nbYQw6n76F5ZcVenQqpagN8XtGjqHfl0aQUIg65HA5WNAufORWo ZoiZao+yHF4doShKmKnHiLKyUdCf6qZ1+Jg5Sbbcd1EpfLmFUilSF04fi5ZxZy5/Pt uSLk8eZj8YEz8mfh6wgvVyXGmJ85TUqwky52TRcqZuBj1cKH6uzjVl5+orWEfzoSvx /xw4lWiH4l3spYw7lqFkRVMyPlqWlsEZbJWHTdy7h2bzjcRjTZ+xmG66Zh7fmpnjuz qalhP+Yjaj+7EZC2DY0VqNP+odBMbUbdGwSFqdV8TgMjl65PneY4IR6c1CsA2aTQ0A F5EqvqPg2jyqw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D1D563322 for ; Mon, 1 Aug 2022 02:05:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZZjDcquc"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A8F3730B; Mon, 1 Aug 2022 02:05:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659312358; bh=kZQqKOqEk25DG04dnPMzNXJsFpWWwX0BeBdyUElzE4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZZjDcquczei57pn2jrO3mGKLK9A8r0su+d6odTrbBhodyNFrimS6GLpsvqaHxtmQ6 8sszYz1ZO0Zo/CgGjrNz3/w78QeqEwoU+YIA9vHCfYjsMLv44Y4/q/wA3Dgl2exQox Y+uspw+rGDExK0uT0tdE44fpwBOBErqM4M4PYYlE= To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Aug 2022 03:05:37 +0300 Message-Id: <20220801000543.3501-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220801000543.3501-1-laurent.pinchart@ideasonboard.com> References: <20220801000543.3501-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/13] libcamera: v4l2_subdevice: Collect subdev capabilities 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Jacopo Mondi Collect subdev capabilities at open() time. Model the V4L2SubdevCapabilties as V4L2Capability from the video device class. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- Changes on top of Jacopo's initial work: - Rename V4L2SubdevCapabilities to V4L2SubdeviceCapability and make it final, to match the V4L2VideoDevice class - Add V4L2Subdevice::caps() --- include/libcamera/internal/v4l2_subdevice.h | 13 ++++++ src/libcamera/v4l2_subdevice.cpp | 50 ++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 2db392d5e37a..a1d3144c6a7f 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -29,6 +29,17 @@ namespace libcamera { class MediaDevice; +struct V4L2SubdeviceCapability final : v4l2_subdev_capability { + bool isReadOnly() const + { + return capabilities & V4L2_SUBDEV_CAP_RO_SUBDEV; + } + bool hasStreams() const + { + return capabilities & V4L2_SUBDEV_CAP_MPLEXED; + } +}; + struct V4L2SubdeviceFormat { uint32_t mbus_code; Size size; @@ -70,6 +81,7 @@ public: Whence whence = ActiveFormat); const std::string &model(); + const V4L2SubdeviceCapability &caps() const { return caps_; } static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -87,6 +99,7 @@ private: const MediaEntity *entity_; std::string model_; + struct V4L2SubdeviceCapability caps_; }; } /* namespace libcamera */ diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 37960b76a044..a1672b2365f2 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -133,6 +133,30 @@ const std::map formatInfoMap = { } /* namespace */ +/** + * \struct V4L2SubdeviceCapability + * \brief struct v4l2_subdev_capability object wrapper and helpers + * + * The V4L2SubdeviceCapability structure manages the information returned by the + * VIDIOC_SUBDEV_QUERYCAP ioctl. + */ + +/** + * \fn V4L2SubdeviceCapability::isReadOnly() + * \brief Retrieve if a subdevice is registered as read-only + * + * A V4L2 subdevice is registered as read-only if V4L2_SUBDEV_CAP_RO_SUBDEV + * is listed as part of its capabilities. + * + * \return True if the subdevice is registered as read-only, false otherwise + */ + +/** + * \fn V4L2SubdeviceCapability::hasStreams() + * \brief Retrieve if a subdevice supports the V4L2 streams API + * \return True if the subdevice supports the streams API, false otherwise + */ + /** * \struct V4L2SubdeviceFormat * \brief The V4L2 sub-device image format and sizes @@ -284,7 +308,25 @@ V4L2Subdevice::~V4L2Subdevice() */ int V4L2Subdevice::open() { - return V4L2Device::open(O_RDWR); + int ret = V4L2Device::open(O_RDWR); + if (ret) + return ret; + + /* + * Try to query the subdev capabilities. The VIDIOC_SUBDEV_QUERYCAP API + * was introduced in kernel v5.8, ENOTTY errors must be ignored to + * support older kernels. + */ + caps_ = {}; + ret = ioctl(VIDIOC_SUBDEV_QUERYCAP, &caps_); + if (ret < 0 && errno != ENOTTY) { + ret = -errno; + LOG(V4L2, Error) + << "Unable to query capabilities: " << strerror(-ret); + return ret; + } + + return 0; } /** @@ -527,6 +569,12 @@ const std::string &V4L2Subdevice::model() return model_; } +/** + * \fn V4L2Subdevice::caps() + * \brief Retrieve the subdevice V4L2 capabilities + * \return The subdevice V4L2 capabilities + */ + /** * \brief Create a new video subdevice instance from \a entity in media device * \a media