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 From patchwork Tue Feb 19 16:56:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 586 X-Patchwork-Delegate: jacopo@jmondi.org 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 4682F600FD for ; Tue, 19 Feb 2019 17:56:03 +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 D1088E000C; Tue, 19 Feb 2019 16:56:02 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Feb 2019 17:56:19 +0100 Message-Id: <20190219165620.2385-3-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 2/3] libcamera: v4l2_subdevice: Add subdevice name 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:03 -0000 Add a deviceName_ field that contains the human readable name of the subdevice, which is created using the name of the associated media entity. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/include/v4l2_subdevice.h | 2 ++ src/libcamera/v4l2_subdevice.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index c7045776555c..40becd0ca99b 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -42,6 +42,7 @@ public: void close(); std::string deviceNode() const { return deviceNode_; } + std::string deviceName() const { return deviceName_; } int setCrop(unsigned int pad, Rectangle *rect); int setCompose(unsigned int pad, Rectangle *rect); @@ -55,6 +56,7 @@ private: Rectangle *rect); std::string deviceNode_; + std::string deviceName_; int fd_; }; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 5665154a2762..4411ffa51460 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -134,7 +134,7 @@ LOG_DEFINE_CATEGORY(V4L2Subdev) * path */ V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity) - : deviceNode_(entity->deviceNode()), fd_(-1) + : deviceNode_(entity->deviceNode()), deviceName_(entity->name()), fd_(-1) { } @@ -193,6 +193,13 @@ void V4L2Subdevice::close() * \return The subdevice's device node system path */ +/** + * \fn V4L2Subdevice::deviceName() + * \brief Retrieve the name of the media entity associated with the subdevice + * + * \return The name of the media entity the subdevice is associated to + */ + /** * \brief Set a crop rectangle on one of the V4L2 subdevice pads * \param[in] pad The 0-indexed pad number the rectangle is to be applied to From patchwork Tue Feb 19 16:56:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 587 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 DA5BE601E3 for ; Tue, 19 Feb 2019 17:56:03 +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 6B014E0009; Tue, 19 Feb 2019 16:56:03 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Feb 2019 17:56:20 +0100 Message-Id: <20190219165620.2385-4-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 3/3] libcamera: v4l2_device: Add support for META_CAPTURE devices 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:04 -0000 Add support for devices that provides video meta-data to v4l2_device.cpp Signed-off-by: Jacopo Mondi --- src/libcamera/include/v4l2_device.h | 4 ++++ src/libcamera/v4l2_device.cpp | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 1d31d1b403bc..52eb6785cc15 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -53,6 +53,10 @@ struct V4L2Capability final : v4l2_capability { return device_caps() & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE); } + bool isMeta() const + { + return device_caps() & V4L2_CAP_META_CAPTURE; + } bool isOutput() const { return device_caps() & (V4L2_CAP_VIDEO_OUTPUT | diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 24e115554a99..7fe6476bf035 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -79,6 +79,12 @@ LOG_DEFINE_CATEGORY(V4L2) * \return True if the device can output video frames */ +/** + * \fn bool V4L2Capability::isMeta() + * \brief Identify if the device is capable of providing video meta-data + * \return True if the device can provide video meta-data + */ + /** * \fn bool V4L2Capability::hasStreaming() * \brief Determine if the device can perform Streaming I/O @@ -280,7 +286,7 @@ int V4L2Device::open() << "Opened device " << caps_.bus_info() << ": " << caps_.driver() << ": " << caps_.card(); - if (!caps_.isCapture() && !caps_.isOutput()) { + if (!caps_.isCapture() && !caps_.isOutput() && !caps_.isMeta()) { LOG(V4L2, Debug) << "Device is not a supported type"; return -EINVAL; } @@ -294,10 +300,12 @@ int V4L2Device::open() bufferType_ = caps_.isMultiplanar() ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : V4L2_BUF_TYPE_VIDEO_CAPTURE; - else + else if (caps_.isOutput()) bufferType_ = caps_.isMultiplanar() ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : V4L2_BUF_TYPE_VIDEO_OUTPUT; + else + bufferType_ = V4L2_BUF_TYPE_META_CAPTURE; /* * We wait for Read notifications on CAPTURE devices (POLLIN), and