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()) {