From patchwork Mon Jun 8 23:28:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3996 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2BB8D61687 for ; Tue, 9 Jun 2020 01:25:25 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 891F0240004; Mon, 8 Jun 2020 23:25:24 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Jun 2020 01:28:39 +0200 Message-Id: <20200608232844.10150-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200608232844.10150-1-jacopo@jmondi.org> References: <20200608232844.10150-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/6] 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: , X-List-Received-Date: Mon, 08 Jun 2020 23:25:25 -0000 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. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 2 +- include/libcamera/internal/formats.h | 11 ++++----- include/libcamera/internal/v4l2_subdevice.h | 2 +- src/libcamera/formats.cpp | 25 +++++++++++++-------- src/libcamera/v4l2_subdevice.cpp | 6 ++--- test/v4l2_subdevice/list_formats.cpp | 2 +- 6 files changed, 28 insertions(+), 20 deletions(-) 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 4b172efc6588..5668f3744c5d 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 2ac3b412ecdb..62fd46686d7d 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -28,9 +28,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. */ @@ -43,7 +42,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; @@ -57,7 +57,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(); } @@ -66,9 +67,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? */ @@ -88,7 +90,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; @@ -103,11 +106,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 7aefc1be032d..9fa20e84a904 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -320,16 +320,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 8 23:28:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3997 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 07F5D63CBF for ; Tue, 9 Jun 2020 01:25:25 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 5501F240004; Mon, 8 Jun 2020 23:25:25 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Jun 2020 01:28:40 +0200 Message-Id: <20200608232844.10150-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200608232844.10150-1-jacopo@jmondi.org> References: <20200608232844.10150-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/6] libcamera: v4l2_subdevice: Provide Formats typedef 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-List-Received-Date: Mon, 08 Jun 2020 23:25:26 -0000 Provide a type definition for ImageFormats to allow users of V4L2Subdevice to refer to it as V4L2Subdevice::Formats. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- 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(-) 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 9fa20e84a904..de7d0c0db2b6 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -197,6 +197,12 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const * any device left open will be closed, and any resources released. */ +/** + * \typedef V4L2Subdevice::Formats + * \brief Enumeration of uint32_t media bus codes associated to image + * resolutions + */ + /** * \enum V4L2Subdevice::Whence * \brief Specify the type of format for getFormat() and setFormat() operations @@ -320,9 +326,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 8 23:28:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3998 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E219461687 for ; Tue, 9 Jun 2020 01:25:26 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 2D81C240004; Mon, 8 Jun 2020 23:25:25 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Jun 2020 01:28:41 +0200 Message-Id: <20200608232844.10150-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200608232844.10150-1-jacopo@jmondi.org> References: <20200608232844.10150-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/6] libcamera: formats: Make ImageFormats iterable 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-List-Received-Date: Mon, 08 Jun 2020 23:25:27 -0000 Make ImageFormats an iterable class by exposing the type definitions for forward iterators and begin() and end() function from the internal formats map. Signed-off-by: Jacopo Mondi --- include/libcamera/internal/formats.h | 8 +++++++ src/libcamera/formats.cpp | 36 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 5668f3744c5d..cb840014cbd7 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -22,6 +22,14 @@ template class ImageFormats { public: + using iterator = typename std::map>::iterator; + using const_iterator = typename std::map>::const_iterator; + + iterator begin() { return data_.begin(); } + const_iterator begin() const { return data_.begin(); } + iterator end() { return data_.end(); } + const_iterator end() const { return data_.end(); } + int addFormat(T format, const std::vector &sizes); bool isEmpty() const; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 62fd46686d7d..fe50b9aaa1f2 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -34,6 +34,42 @@ LOG_DEFINE_CATEGORY(Formats) * Sizes are stored as a list of SizeRange. */ +/** + * \typedef ImageFormats::iterator + * \brief Iterator for the formats map + */ + +/** + * \typedef ImageFormats::const_iterator + * \brief Const iterator for the formats map + */ + +/** + * \fn iterator ImageFormats::begin() + * \brief Retrieve an iterator to the first element in the formats map + * \return An iterator to the first format map + */ + +/** + * \fn const_iterator ImageFormats::begin() const + * \brief Retrieve an const iterator to the first element in the formats map + * \return A const iterator to the first format map + */ + +/** + * \fn iterator ImageFormats::end() + * \brief Retrieve an iterator pointing to the past-the-end element in the + * formats map + * \return An iterator to the element following the last format + */ + +/** + * \fn const_iterator ImageFormats::end() const + * \brief Retrieve a const iterator pointing to the past-the-end element in the + * formats map + * \return A const iterator to the element following the last format + */ + /** * \brief Add a format and corresponding sizes to the description * \param[in] format Pixel format or media bus code to describe From patchwork Mon Jun 8 23:28:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3999 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BF4361687 for ; Tue, 9 Jun 2020 01:25:27 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 0FB46240004; Mon, 8 Jun 2020 23:25:26 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Jun 2020 01:28:42 +0200 Message-Id: <20200608232844.10150-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200608232844.10150-1-jacopo@jmondi.org> References: <20200608232844.10150-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/6] libcamera: formats: Add ImageFormats::contain() 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-List-Received-Date: Mon, 08 Jun 2020 23:25:27 -0000 Add a method to check if a format is part of the formats enumeration. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/internal/formats.h | 1 + src/libcamera/formats.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index cb840014cbd7..914fdde27d0c 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -33,6 +33,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 fe50b9aaa1f2..9f46f82c9059 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -99,6 +99,17 @@ bool ImageFormats::isEmpty() const return data_.empty(); } +/** + * \brief Check if the formats enumeration contains \a format + * \param[in] format The format + * \return True if the enumeration 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 8 23:28:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 4000 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 58EC463CC7 for ; Tue, 9 Jun 2020 01:25:28 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id CD218240004; Mon, 8 Jun 2020 23:25:27 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Jun 2020 01:28:43 +0200 Message-Id: <20200608232844.10150-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200608232844.10150-1-jacopo@jmondi.org> References: <20200608232844.10150-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/6] libcamera: formats: Expose std::map::value_type 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-List-Received-Date: Mon, 08 Jun 2020 23:25:29 -0000 In order to prepare to replace usage of custom map in pipeline handlers, expose the formats map value_type type definition, to allow pipeline handlers to use STL functions to iterate the class. Signed-off-by: Jacopo Mondi --- include/libcamera/internal/formats.h | 2 ++ src/libcamera/formats.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 914fdde27d0c..1361b55d63d2 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -22,6 +22,8 @@ template class ImageFormats { public: + using value_type = typename std::map>::value_type; + using iterator = typename std::map>::iterator; using const_iterator = typename std::map>::const_iterator; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 9f46f82c9059..5037c5928669 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -34,6 +34,11 @@ LOG_DEFINE_CATEGORY(Formats) * Sizes are stored as a list of SizeRange. */ +/** + * \typedef ImageFormats::value_type + * \brief Value type of the entries in the formats map + */ + /** * \typedef ImageFormats::iterator * \brief Iterator for the formats map From patchwork Mon Jun 8 23:28:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 4001 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E0F161687 for ; Tue, 9 Jun 2020 01:25:29 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 8043C240004; Mon, 8 Jun 2020 23:25:28 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Jun 2020 01:28:44 +0200 Message-Id: <20200608232844.10150-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200608232844.10150-1-jacopo@jmondi.org> References: <20200608232844.10150-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/6] 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: , X-List-Received-Date: Mon, 08 Jun 2020 23:25:29 -0000 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. Signed-off-by: Jacopo Mondi --- include/libcamera/internal/v4l2_videodevice.h | 4 +++- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 14 ++++++-------- src/libcamera/pipeline/simple/simple.cpp | 3 +-- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 3 +-- src/libcamera/v4l2_videodevice.cpp | 14 ++++++++++---- 5 files changed, 21 insertions(+), 17 deletions(-) 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 b9b88506c646..861d0864f9f7 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 = {}; @@ -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 = PixelFormat(DRM_FORMAT_NV12); status = Adjusted; @@ -518,7 +516,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, RPiCameraData *data = cameraData(camera); CameraConfiguration *config = new RPiCameraConfiguration(data); V4L2DeviceFormat sensorFormat; - V4L2PixFmtMap fmts; + V4L2VideoDevice::Formats fmts; if (roles.empty()) return config; @@ -605,7 +603,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/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 1ec8d0f7de03..59c4a6da1ee9 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -275,8 +275,7 @@ 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() diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index a074909499f1..9e41cbd50c1a 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -159,8 +159,7 @@ 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::inserter(deviceFormats, deviceFormats.begin()), diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 3614b2ed1cbc..077e150ceda6 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 Enumeration of V4L2PixelFormat instances associated 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;