From patchwork Mon May 27 00:15:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 1298 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 45CC9618F5 for ; Mon, 27 May 2019 02:16:08 +0200 (CEST) X-Halon-ID: 9d973116-8014-11e9-8ab4-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 9d973116-8014-11e9-8ab4-005056917a89; Mon, 27 May 2019 02:16:04 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 27 May 2019 02:15:31 +0200 Message-Id: <20190527001543.13593-6-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190527001543.13593-1-niklas.soderlund@ragnatech.se> References: <20190527001543.13593-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/17] libcamera: formats: Add V4L2DeviceFormats and V4L2DeviceFormats 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: Mon, 27 May 2019 00:16:08 -0000 Add two new objects to hold v4l2 format information for v4l2 devices and subdevices. There is much code which can be shared between the two so have both of them inherit from a base class to reduce code duplication. Signed-off-by: Niklas Söderlund --- src/libcamera/formats.cpp | 158 ++++++++++++++++++++++++++++++++ src/libcamera/include/formats.h | 35 +++++++ 2 files changed, 193 insertions(+) diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 56f4ddb51ffad4d3..f5841b38cea5686c 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -24,4 +24,162 @@ namespace libcamera { * resolutions represented by SizeRange items. */ + +/** + * \class DeviceFormats + * \brief Base class for V4L2Device and V4L2SubDevice Formats + * + * The base class holds common functionallity between V4L2DeviceFormats and + * V4L2SubDeviceForamts. + * + * \sa V4L2DeviceFormats + * \sa V4L2SubDeviceForamts + */ + +/** + * \brief Create an empty DeviceFormats + */ +DeviceFormats::DeviceFormats() +{ +} + +/** + * \brief Create a DeviceFormats with data + */ +DeviceFormats::DeviceFormats(const std::map> &data) + : data_(data) +{ +} + +DeviceFormats::~DeviceFormats() +{ +} + +/** + * \brief Retrieve all sizes for a specific format + * \param[in] format A pixelformat or mbus code + * + * Retrieves all SizeRanges for a specific format. For V4L2Device \a format is a + * pixelformoat while for a V4L2Subdevice \a format is a media bus code. + * + * \return List of SizeRanges for \a format, empty list if format is not valid + */ +std::vector DeviceFormats::sizes(unsigned int format) const +{ + auto const &it = data_.find(format); + if (it == data_.end()) + return {}; + + return it->second; +} + +/** + * \brief Check if the device formats is empty + * \return True if the formats are empty + */ +bool DeviceFormats::empty() const +{ + return data_.empty(); +} + +/** + * \brief Retrieve the raw dataA + * \return Raw map containgin formats to SizeRanges + */ +const std::map> &DeviceFormats::data() +{ + return data_; +} + +/** + * \brief Retrieve a list all contained formats + * + * This is a helper function intended to be used by V4L2DeviceFormats and + * V4L2SubdeviceFormats. + * + * \return A list of formats contained + */ +std::vector DeviceFormats::formats() const +{ + std::vector formats; + + for (auto const &it : data_) + formats.push_back(it.first); + + return formats; +} + +/** + * \var DeviceFormats::data_ + * \brief The map holding format and SizeRange information + */ + +/** + * \class V4L2SubdeviceFormats + * \brief Holds media bus codes to frame sizes information for a v4l2 subdevice + * + * Hold media bus codes and frame sizes which describes a v4l2 subdevice. The + * intended user of this object is pipeline handlers which can create it + * from a V4L2Subdevice and use it to describe and validate formats. + */ + +/** + * \brief Create an empty V4L2SubdeviceFormats + */ +V4L2SubdeviceFormats::V4L2SubdeviceFormats() + : DeviceFormats() +{ +} + +/** + * \brief Create an V4L2SubdeviceFormats with data + */ +V4L2SubdeviceFormats::V4L2SubdeviceFormats(const std::map> &data) + : DeviceFormats(data) +{ +} + +/** + * \brief Retrieve media bus codes which are described + * \return List of media bus codes + */ +std::vector V4L2SubdeviceFormats::codes() const +{ + return formats(); +} + +/** + * \class V4L2DeviceFormats + * \brief Holds pixelformats to frame sizes information for a v4l2 device + * + * Hold pixelformats and frame sizes which describes a v4l2 device. The + * intended user of this object is pipeline handlers which can create it + * from a V4L2Device and use it to describe and validate formats. + */ + +/** + * \brief Create an empty V4L2DeviceFormats + */ +V4L2DeviceFormats::V4L2DeviceFormats() + : DeviceFormats() +{ +} + +/** + * \brief Create an V4L2DeviceFormats with data + */ +V4L2DeviceFormats::V4L2DeviceFormats(const std::map> &data) + : DeviceFormats(data) +{ +} + +/** + * \brief Retrieve pixelformats which are described + * \return List of pixelformats + */ +std::vector V4L2DeviceFormats::pixelformats() const +{ + return formats(); +} + } /* namespace libcamera */ diff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h index a73772b1eda068b4..372f6e6d71b236dd 100644 --- a/src/libcamera/include/formats.h +++ b/src/libcamera/include/formats.h @@ -17,6 +17,41 @@ namespace libcamera { typedef std::map> FormatEnum; +class DeviceFormats +{ +public: + virtual ~DeviceFormats(); + + std::vector sizes(unsigned int format) const; + bool empty() const; + const std::map> &data(); + +protected: + DeviceFormats(); + DeviceFormats(const std::map> &data); + std::vector formats() const; + + std::map> data_; +}; + +class V4L2SubdeviceFormats : public DeviceFormats +{ +public: + V4L2SubdeviceFormats(); + V4L2SubdeviceFormats(const std::map> &data); + + std::vector codes() const; +}; + +class V4L2DeviceFormats : public DeviceFormats +{ +public: + V4L2DeviceFormats(); + V4L2DeviceFormats(const std::map> &data); + + std::vector pixelformats() const; +}; + } /* namespace libcamera */ #endif /* __LIBCAMERA_FORMATS_H__ */