From patchwork Tue Feb 19 16:56:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 585 Return-Path: Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A23FC600FD for ; Tue, 19 Feb 2019 17:56:02 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 242C2E000D; Tue, 19 Feb 2019 16:56:01 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Feb 2019 17:56:18 +0100 Message-Id: <20190219165620.2385-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219165620.2385-1-jacopo@jmondi.org> References: <20190219165620.2385-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: v4l2_subdevice: Implement ENUM_FRAME_SIZES X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2019 16:56:02 -0000 Implement enumFormat() methods to enumerate the available image resolutions on the subdevice. Signed-off-by: Jacopo Mondi --- src/libcamera/include/v4l2_subdevice.h | 11 ++++ src/libcamera/v4l2_subdevice.cpp | 90 ++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 82fa6685ab52..c7045776555c 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -14,6 +14,16 @@ namespace libcamera { class MediaEntity; struct Rectangle; +struct V4L2SubdeviceFormatEnum { + unsigned int index; + uint32_t mbus_code; + + uint32_t minWidth; + uint32_t maxWidth; + uint32_t minHeight; + uint32_t maxHeight; +}; + struct V4L2SubdeviceFormat { uint32_t mbus_code; uint32_t width; @@ -36,6 +46,7 @@ public: int setCrop(unsigned int pad, Rectangle *rect); int setCompose(unsigned int pad, Rectangle *rect); + int enumFormat(unsigned int pad, V4L2SubdeviceFormatEnum *formatEnum); int getFormat(unsigned int pad, V4L2SubdeviceFormat *format); int setFormat(unsigned int pad, V4L2SubdeviceFormat *format); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index b436f73cc75f..5665154a2762 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -26,6 +26,52 @@ namespace libcamera { LOG_DEFINE_CATEGORY(V4L2Subdev) +/** + * \struct V4L2SubdeviceFormatEnum + * \brief The V4L2 sub-device image size enumeration + * + * This structure describes an image resolution as enumerated by the V4L2 + * sub-device. The structure is used as format exchange between the caller and + * the enumFormat() method. The caller is responsible to fill the media bus + * code to use and the index of the format to be enumerated. + */ + +/** + * \var V4L2SubdeviceFormatEnum::index + * \brief The index of the format to be enumerated + */ + +/** + * \var V4L2SubdeviceFormatEnum::mbus_code + * \brief The pixel format identification code for the formats to enumerate + * + * \sa V4L2SubdeviceFormat for media bus format pixel code description. + */ + +/** + * \var V4L2SubdeviceFormatEnum::minWidth + * \brief The minimum width of the enumerated format as reported by the V4L2 + * sub-device + */ + +/** + * \var V4L2SubdeviceFormatEnum::maxWidth + * \brief The maximum width of the enumerated format as reported by the V4L2 + * sub-device + */ + +/** + * \var V4L2SubdeviceFormatEnum::minHeight + * \brief The minimum height of the enumerated format as reported by the V4L2 + * sub-device + */ + +/** + * \var V4L2SubdeviceFormatEnum::maxHeight + * \brief The maximum height of the enumerated format as reported by the V4L2 + * sub-device + */ + /** * \struct V4L2SubdeviceFormat * \brief The V4L2 sub-device image format and sizes @@ -171,6 +217,50 @@ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect) return setSelection(pad, V4L2_SEL_TGT_COMPOSE, rect); } +/** + * \brief Enumerate the sub-device image resolutions + * \param[in] pad The 0-indexed pad number to enumerate formats on + * \param[inout] formatEnum The format enumeration description + * + * The method retrieve the image resolution of the image format with index + * formatEnum.index for the pixel format specified by formatEnum.mbus_code. + * + * To enumerate image resolutions, the caller shall start enumerating all + * formats by setting the formatEnum.index field to 0, and increasing it by + * one for any successive call, until the -EINVAL return code is returned. + * + * \return 0 on success, or a negative error code otherwise + */ +int V4L2Subdevice::enumFormat(unsigned int pad, + V4L2SubdeviceFormatEnum *formatEnum) +{ + struct v4l2_subdev_frame_size_enum sizeEnum = {}; + + sizeEnum.index = formatEnum->index; + sizeEnum.code = formatEnum->mbus_code; + sizeEnum.pad = pad; + sizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE; + + int ret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum); + if (ret) { + ret = -errno; + if (ret == -EINVAL) + return ret; + + LOG(V4L2Subdev, Error) + << "Unable to enumerate format on pad " << pad + << " of " << deviceNode_ << ": " << strerror(-ret); + return ret; + } + + formatEnum->maxWidth = sizeEnum.max_width; + formatEnum->minWidth = sizeEnum.min_width; + formatEnum->maxHeight = sizeEnum.max_height; + formatEnum->minHeight = sizeEnum.min_height; + + return 0; +} + /** * \brief Retrieve the image format set on one of the V4L2 subdevice pads * \param[in] pad The 0-indexed pad number the format is to be retrieved from