From patchwork Mon Jun 29 11:53:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8495 X-Patchwork-Delegate: jacopo@jmondi.org 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 1CBB2BF415 for ; Mon, 29 Jun 2020 11:50:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B9DC0609DB; Mon, 29 Jun 2020 13:50:11 +0200 (CEST) Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 684A7609C2 for ; Mon, 29 Jun 2020 13:50:11 +0200 (CEST) Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id C6470100002; Mon, 29 Jun 2020 11:50:09 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Jun 2020 13:53:25 +0200 Message-Id: <20200629115328.16273-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200629105037.14706-1-jacopo@jmondi.org> References: <20200629105037.14706-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/4] libcamera: formats: Make ImageFormats a templated class 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" The ImageFormats class was originally designed to be used by both V4L2VideoDevices and V4L2Subdevices. As video devices enumerates their image formats using V4L2PixelFormat instances, the ImageFormats class cannot be used there anymore and it has been replaced by raw maps. Prepare to re-introduce usage of ImageFormats in the V4L2VideoDevice class and its users by making ImageFormats a templated class that indexes the image sizes using on keys of variadic type. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- include/libcamera/internal/camera_sensor.h | 2 +- include/libcamera/internal/formats.h | 11 +++++---- include/libcamera/internal/v4l2_subdevice.h | 2 +- src/libcamera/formats.cpp | 26 ++++++++++++++------- src/libcamera/v4l2_subdevice.cpp | 6 ++--- test/v4l2_subdevice/list_formats.cpp | 2 +- 6 files changed, 29 insertions(+), 20 deletions(-) -- 2.27.0 diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 7f07413f9560..d5814a26a121 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -75,7 +75,7 @@ private: std::string model_; - ImageFormats formats_; + ImageFormats formats_; Size resolution_; std::vector mbusCodes_; std::vector sizes_; diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index f59ac8fe36a1..aba83511179f 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -18,18 +18,19 @@ namespace libcamera { +template class ImageFormats { public: - int addFormat(unsigned int format, const std::vector &sizes); + int addFormat(T format, const std::vector &sizes); bool isEmpty() const; - std::vector formats() const; - const std::vector &sizes(unsigned int format) const; - const std::map> &data() const; + std::vector formats() const; + const std::vector &sizes(T format) const; + const std::map> &data() const; private: - std::map> data_; + std::map> data_; }; class PixelFormatInfo diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index a3ecf123f640..f811d316dada 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -51,7 +51,7 @@ public: int setSelection(unsigned int pad, unsigned int target, Rectangle *rect); - ImageFormats formats(unsigned int pad); + ImageFormats formats(unsigned int pad); int getFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence = ActiveFormat); diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 436672e8bf4f..a5607da3efd4 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -12,6 +12,7 @@ #include #include "libcamera/internal/log.h" +#include "libcamera/internal/v4l2_pixelformat.h" /** * \file internal/formats.h @@ -30,9 +31,8 @@ LOG_DEFINE_CATEGORY(Formats) * corresponding set of image sizes. It is used to describe the formats and * sizes supported by a V4L2Device or V4L2Subdevice. * - * Formats are stored as an integer. When used for a V4L2Device, the image - * formats are fourcc pixel formats. When used for a V4L2Subdevice they are - * media bus codes. Both are defined by the V4L2 specification. + * When used for a V4L2Device, the image formats are V4L2PixelFormat instances. + * When used for a V4L2Subdevice formats are uint32_t media bus codes. * * Sizes are stored as a list of SizeRange. */ @@ -45,7 +45,8 @@ LOG_DEFINE_CATEGORY(Formats) * \return 0 on success or a negative error code otherwise * \retval -EEXIST The format is already described */ -int ImageFormats::addFormat(unsigned int format, const std::vector &sizes) +template +int ImageFormats::addFormat(T format, const std::vector &sizes) { if (data_.find(format) != data_.end()) return -EEXIST; @@ -59,7 +60,8 @@ int ImageFormats::addFormat(unsigned int format, const std::vector &s * \brief Check if the list of devices supported formats is empty * \return True if the list of supported formats is empty */ -bool ImageFormats::isEmpty() const +template +bool ImageFormats::isEmpty() const { return data_.empty(); } @@ -68,9 +70,10 @@ bool ImageFormats::isEmpty() const * \brief Retrieve a list of all supported image formats * \return List of pixel formats or media bus codes */ -std::vector ImageFormats::formats() const +template +std::vector ImageFormats::formats() const { - std::vector formats; + std::vector formats; formats.reserve(data_.size()); /* \todo: Should this be cached instead of computed each time? */ @@ -90,7 +93,8 @@ std::vector ImageFormats::formats() const * \return The list of image sizes supported for \a format, or an empty list if * the format is not supported */ -const std::vector &ImageFormats::sizes(unsigned int format) const +template +const std::vector &ImageFormats::sizes(T format) const { static const std::vector empty; @@ -105,11 +109,15 @@ const std::vector &ImageFormats::sizes(unsigned int format) const * \brief Retrieve the map that associates formats to image sizes * \return The map that associates formats to image sizes */ -const std::map> &ImageFormats::data() const +template +const std::map> &ImageFormats::data() const { return data_; } +template class ImageFormats; +template class ImageFormats; + /** * \class PixelFormatInfo * \brief Information about pixel formats diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 32c6c7acc11a..231473ba3d06 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -340,16 +340,16 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target, * * \return A list of the supported device formats */ -ImageFormats V4L2Subdevice::formats(unsigned int pad) +ImageFormats V4L2Subdevice::formats(unsigned int pad) { - ImageFormats formats; + ImageFormats formats; if (pad >= entity_->pads().size()) { LOG(V4L2, Error) << "Invalid pad: " << pad; return {}; } - for (unsigned int code : enumPadCodes(pad)) { + for (uint32_t code : enumPadCodes(pad)) { std::vector sizes = enumPadSizes(pad, code); if (sizes.empty()) return {}; diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp index a55af1100d9a..3e8d4cdba045 100644 --- a/test/v4l2_subdevice/list_formats.cpp +++ b/test/v4l2_subdevice/list_formats.cpp @@ -47,7 +47,7 @@ void ListFormatsTest::printFormats(unsigned int pad, int ListFormatsTest::run() { /* List all formats available on existing "Scaler" pads. */ - ImageFormats formats; + ImageFormats formats; formats = scaler_->formats(0); if (formats.isEmpty()) { From patchwork Mon Jun 29 11:53:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8496 X-Patchwork-Delegate: jacopo@jmondi.org 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 3D1EEBF415 for ; Mon, 29 Jun 2020 11:50:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F171960AF1; Mon, 29 Jun 2020 13:50:13 +0200 (CEST) Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D723609D6 for ; Mon, 29 Jun 2020 13:50:12 +0200 (CEST) Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 8877310000E; Mon, 29 Jun 2020 11:50:11 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Jun 2020 13:53:26 +0200 Message-Id: <20200629115328.16273-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200629115328.16273-1-jacopo@jmondi.org> References: <20200629105037.14706-1-jacopo@jmondi.org> <20200629115328.16273-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/4] libcamera: v4l2_subdevice: Provide Formats type alias 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" Provide a type definition for ImageFormats to allow users of V4L2Subdevice to refer to it as V4L2Subdevice::Formats. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- include/libcamera/internal/camera_sensor.h | 6 ++---- include/libcamera/internal/v4l2_subdevice.h | 4 +++- src/libcamera/v4l2_subdevice.cpp | 10 ++++++++-- test/v4l2_subdevice/list_formats.cpp | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) -- 2.27.0 diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index d5814a26a121..06c8292ca301 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -16,13 +16,11 @@ #include "libcamera/internal/formats.h" #include "libcamera/internal/log.h" +#include "libcamera/internal/v4l2_subdevice.h" namespace libcamera { class MediaEntity; -class V4L2Subdevice; - -struct V4L2SubdeviceFormat; struct CameraSensorInfo { std::string model; @@ -75,7 +73,7 @@ private: std::string model_; - ImageFormats formats_; + V4L2Subdevice::Formats formats_; Size resolution_; std::vector mbusCodes_; std::vector sizes_; diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index f811d316dada..c678fc87e80f 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -32,6 +32,8 @@ struct V4L2SubdeviceFormat { class V4L2Subdevice : public V4L2Device { public: + using Formats = ImageFormats; + enum Whence { ActiveFormat, TryFormat, @@ -51,7 +53,7 @@ public: int setSelection(unsigned int pad, unsigned int target, Rectangle *rect); - ImageFormats formats(unsigned int pad); + Formats formats(unsigned int pad); int getFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence = ActiveFormat); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 231473ba3d06..372283cbdeb6 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -217,6 +217,12 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const * any device left open will be closed, and any resources released. */ +/** + * \typedef V4L2Subdevice::Formats + * \brief An ImageFormats specialization mapping uint32_t media bus codes to + * image resolutions + */ + /** * \enum V4L2Subdevice::Whence * \brief Specify the type of format for getFormat() and setFormat() operations @@ -340,9 +346,9 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target, * * \return A list of the supported device formats */ -ImageFormats V4L2Subdevice::formats(unsigned int pad) +V4L2Subdevice::Formats V4L2Subdevice::formats(unsigned int pad) { - ImageFormats formats; + Formats formats; if (pad >= entity_->pads().size()) { LOG(V4L2, Error) << "Invalid pad: " << pad; diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp index 3e8d4cdba045..7f0b3333f617 100644 --- a/test/v4l2_subdevice/list_formats.cpp +++ b/test/v4l2_subdevice/list_formats.cpp @@ -47,7 +47,7 @@ void ListFormatsTest::printFormats(unsigned int pad, int ListFormatsTest::run() { /* List all formats available on existing "Scaler" pads. */ - ImageFormats formats; + V4L2Subdevice::Formats formats; formats = scaler_->formats(0); if (formats.isEmpty()) { From patchwork Mon Jun 29 11:53:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8497 X-Patchwork-Delegate: jacopo@jmondi.org 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 8CCC7BF415 for ; Mon, 29 Jun 2020 11:50:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 90B03609D6; Mon, 29 Jun 2020 13:50:14 +0200 (CEST) Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 15B45609C9 for ; Mon, 29 Jun 2020 13:50:13 +0200 (CEST) Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 6DD32100012; Mon, 29 Jun 2020 11:50:12 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Jun 2020 13:53:27 +0200 Message-Id: <20200629115328.16273-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200629115328.16273-1-jacopo@jmondi.org> References: <20200629105037.14706-1-jacopo@jmondi.org> <20200629115328.16273-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/4] libcamera: formats: Add ImageFormats::contains() 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 method to check if a format is part of the formats map. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- include/libcamera/internal/formats.h | 1 + src/libcamera/formats.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) -- 2.27.0 diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index aba83511179f..c3bda8214991 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -25,6 +25,7 @@ public: int addFormat(T format, const std::vector &sizes); bool isEmpty() const; + bool contains(T format) const; std::vector formats() const; const std::vector &sizes(T format) const; const std::map> &data() const; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index a5607da3efd4..61bf7b5cb16d 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -48,7 +48,7 @@ LOG_DEFINE_CATEGORY(Formats) template int ImageFormats::addFormat(T format, const std::vector &sizes) { - if (data_.find(format) != data_.end()) + if (contains(format)) return -EEXIST; data_[format] = sizes; @@ -66,6 +66,17 @@ bool ImageFormats::isEmpty() const return data_.empty(); } +/** + * \brief Check if the formats map contains \a format + * \param[in] format The format + * \return True if the map contains such format, false otherwise + */ +template +bool ImageFormats::contains(T format) const +{ + return data_.find(format) != data_.end(); +} + /** * \brief Retrieve a list of all supported image formats * \return List of pixel formats or media bus codes From patchwork Mon Jun 29 11:53:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8498 X-Patchwork-Delegate: jacopo@jmondi.org 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 3DA93BF415 for ; Mon, 29 Jun 2020 11:50:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 199C160A16; Mon, 29 Jun 2020 13:50:17 +0200 (CEST) Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CEE52609D6 for ; Mon, 29 Jun 2020 13:50:13 +0200 (CEST) Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 3461E100013; Mon, 29 Jun 2020 11:50:13 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Jun 2020 13:53:28 +0200 Message-Id: <20200629115328.16273-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200629115328.16273-1-jacopo@jmondi.org> References: <20200629105037.14706-1-jacopo@jmondi.org> <20200629115328.16273-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/4] libcamera: v4l2_videodevice: Use ImageFormats 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" ImageFormats was meant to be used not only for V4L2Subdevice but for video devices as well. Since the introduction of of V4L2PixelFormat the V4L2VideoDevice class and its users have been using a raw map to enumerate and inspect the V4L2VideoDevice formats. Provide a V4L2VideoDevice::Formats type definition as for V4L2Subdevice and use ImageFormats wherever possible in pipeline handlers. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- include/libcamera/internal/v4l2_videodevice.h | 4 +++- .../pipeline/raspberrypi/raspberrypi.cpp | 21 +++++++++---------- src/libcamera/pipeline/simple/converter.cpp | 2 +- src/libcamera/pipeline/simple/simple.cpp | 7 +++---- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 7 +++---- src/libcamera/v4l2_videodevice.cpp | 14 +++++++++---- 6 files changed, 30 insertions(+), 25 deletions(-) -- 2.27.0 diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 4d21f5a01ec8..06c65e863a99 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -168,6 +168,8 @@ public: class V4L2VideoDevice : public V4L2Device { public: + using Formats = ImageFormats; + explicit V4L2VideoDevice(const std::string &deviceNode); explicit V4L2VideoDevice(const MediaEntity *entity); V4L2VideoDevice(const V4L2VideoDevice &) = delete; @@ -187,7 +189,7 @@ public: int getFormat(V4L2DeviceFormat *format); int setFormat(V4L2DeviceFormat *format); - std::map> formats(uint32_t code = 0); + Formats formats(uint32_t code = 0); int setSelection(unsigned int target, Rectangle *rect); diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 9d887b706c3f..ffb3c5cc45d9 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -37,8 +37,6 @@ namespace libcamera { LOG_DEFINE_CATEGORY(RPI) -using V4L2PixFmtMap = std::map>; - namespace { bool isRaw(PixelFormat &pixFmt) @@ -67,7 +65,7 @@ double scoreFormat(double desired, double actual) return score; } -V4L2DeviceFormat findBestMode(V4L2PixFmtMap &formatsMap, const Size &req) +V4L2DeviceFormat findBestMode(V4L2VideoDevice::Formats &formatsMap, const Size &req) { double bestScore = 9e9, score; V4L2DeviceFormat bestMode = {}; @@ -79,7 +77,7 @@ V4L2DeviceFormat findBestMode(V4L2PixFmtMap &formatsMap, const Size &req) #define PENALTY_UNPACKED 500.0 /* Calculate the closest/best mode from the user requested size. */ - for (const auto &iter : formatsMap) { + for (const auto &iter : formatsMap.data()) { V4L2PixelFormat v4l2Format = iter.first; PixelFormat pixelFormat = v4l2Format.toPixelFormat(); const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat); @@ -427,7 +425,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * Calculate the best sensor mode we can use based on * the user request. */ - V4L2PixFmtMap fmts = data_->unicam_[Unicam::Image].dev()->formats(); + V4L2VideoDevice::Formats fmts = data_->unicam_[Unicam::Image].dev()->formats(); V4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size); PixelFormat sensorPixFormat = sensorFormat.fourcc.toPixelFormat(); if (cfg.size != sensorFormat.size || @@ -481,14 +479,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * */ PixelFormat &cfgPixFmt = config_.at(outSize[i].first).pixelFormat; - V4L2PixFmtMap fmts; + V4L2VideoDevice::Formats fmts; if (i == maxIndex) fmts = data_->isp_[Isp::Output0].dev()->formats(); else fmts = data_->isp_[Isp::Output1].dev()->formats(); - if (fmts.find(V4L2PixelFormat::fromPixelFormat(cfgPixFmt, false)) == fmts.end()) { + if (!fmts.contains(V4L2PixelFormat::fromPixelFormat(cfgPixFmt, false))) { /* If we cannot find a native format, use a default one. */ cfgPixFmt = formats::NV12; status = Adjusted; @@ -518,9 +516,9 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, RPiCameraData *data = cameraData(camera); CameraConfiguration *config = new RPiCameraConfiguration(data); V4L2DeviceFormat sensorFormat; + V4L2VideoDevice::Formats fmts; unsigned int bufferCount; PixelFormat pixelFormat; - V4L2PixFmtMap fmts; Size size; if (roles.empty()) @@ -580,8 +578,9 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, /* Translate the V4L2PixelFormat to PixelFormat. */ std::map> deviceFormats; - std::transform(fmts.begin(), fmts.end(), std::inserter(deviceFormats, deviceFormats.end()), - [&](const decltype(fmts)::value_type &format) { + std::transform(fmts.data().begin(), fmts.data().end(), + std::inserter(deviceFormats, deviceFormats.end()), + [&](const auto &format) { return decltype(deviceFormats)::value_type{ format.first.toPixelFormat(), format.second @@ -638,7 +637,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) } /* First calculate the best sensor mode we can use based on the user request. */ - V4L2PixFmtMap fmts = data->unicam_[Unicam::Image].dev()->formats(); + V4L2VideoDevice::Formats fmts = data->unicam_[Unicam::Image].dev()->formats(); V4L2DeviceFormat sensorFormat = findBestMode(fmts, rawStream ? sensorSize : maxSize); /* diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp index e5e2f0fddb62..701db96138b0 100644 --- a/src/libcamera/pipeline/simple/converter.cpp +++ b/src/libcamera/pipeline/simple/converter.cpp @@ -85,7 +85,7 @@ std::vector SimpleConverter::formats(PixelFormat input) std::vector pixelFormats; - for (const auto &format : m2m_->capture()->formats()) { + for (const auto &format : m2m_->capture()->formats().data()) { PixelFormat pixelFormat = format.first.toPixelFormat(); if (pixelFormat) pixelFormats.push_back(pixelFormat); diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 1ec8d0f7de03..202a7e85375c 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -275,13 +275,12 @@ int SimpleCameraData::init() return ret; } - std::map> videoFormats = - video_->formats(format.mbus_code); + V4L2VideoDevice::Formats videoFormats = video_->formats(format.mbus_code); LOG(SimplePipeline, Debug) << "Adding configuration for " << format.size.toString() << " in pixel formats [ " - << utils::join(videoFormats, ", ", + << utils::join(videoFormats.data(), ", ", [](const auto &f) { return f.first.toString(); }) @@ -294,7 +293,7 @@ int SimpleCameraData::init() * handler currently doesn't care about how a particular * PixelFormat is achieved. */ - for (const auto &videoFormat : videoFormats) { + for (const auto &videoFormat : videoFormats.data()) { PixelFormat pixelFormat = videoFormat.first.toPixelFormat(); if (!pixelFormat) continue; diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 80a0e77ba3fc..4c7812d0fb6b 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -158,12 +158,11 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, if (roles.empty()) return config; - std::map> v4l2Formats = - data->video_->formats(); + V4L2VideoDevice::Formats v4l2Formats = data->video_->formats(); std::map> deviceFormats; - std::transform(v4l2Formats.begin(), v4l2Formats.end(), + std::transform(v4l2Formats.data().begin(), v4l2Formats.data().end(), std::inserter(deviceFormats, deviceFormats.begin()), - [&](const decltype(v4l2Formats)::value_type &format) { + [&](const auto &format) { return decltype(deviceFormats)::value_type{ format.first.toPixelFormat(), format.second diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 3614b2ed1cbc..63e09cf9616a 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -461,6 +461,12 @@ const std::string V4L2DeviceFormat::toString() const * \context This class is \threadbound. */ +/** + * \typedef V4L2VideoDevice::Formats + * \brief An ImageFormats specialization mapping V4L2PixelFormat instances to + * image resolutions + */ + /** * \brief Construct a V4L2VideoDevice * \param[in] deviceNode The file-system path to the video device node @@ -925,23 +931,23 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format) * * \return A list of the supported video device formats */ -std::map> V4L2VideoDevice::formats(uint32_t code) +V4L2VideoDevice::Formats V4L2VideoDevice::formats(uint32_t code) { - std::map> formats; + Formats formats; for (V4L2PixelFormat pixelFormat : enumPixelformats(code)) { std::vector sizes = enumSizes(pixelFormat); if (sizes.empty()) return {}; - if (formats.find(pixelFormat) != formats.end()) { + if (!formats.contains(pixelFormat)) { LOG(V4L2, Error) << "Could not add sizes for pixel format " << pixelFormat; return {}; } - formats.emplace(pixelFormat, sizes); + formats.addFormat(pixelFormat, sizes); } return formats;