From patchwork Thu Apr 30 00:52:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3621 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4159D6041C for ; Thu, 30 Apr 2020 02:52:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bKlxZjw3"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D317F521 for ; Thu, 30 Apr 2020 02:52:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1588207951; bh=2078x2Dxc4mWcYrGEoswjkiES9YjkZaknzyImmycANE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bKlxZjw3z5JCSOySqxgcta8vQqmLKGHnMYr++GK62M0F0rIfsTjjVPgzZkl5nI+Ja Jwk5WZPMiVJvHPJ2yjBFsiir4mAty4PCWMqQ9S7ELxwy+zStHonklzfFsLdMwa1VMk x9Q652dAjAAeOKegkhoWwX9xqOcfZhO7bbOwrgT8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Apr 2020 03:52:23 +0300 Message-Id: <20200430005226.18162-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200430005226.18162-1-laurent.pinchart@ideasonboard.com> References: <20200430005226.18162-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] libcamera: v4l2_pixelformat: Move V4L2PixelFormat to a new file 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: Thu, 30 Apr 2020 00:52:31 -0000 Move the V4L2PixelFormat class to a new file to prepare for additional changes that will make it grow. No functional modification is included. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/include/meson.build | 1 + src/libcamera/include/v4l2_pixelformat.h | 45 ++++++++++ src/libcamera/include/v4l2_videodevice.h | 24 +---- src/libcamera/meson.build | 1 + src/libcamera/v4l2_pixelformat.cpp | 106 +++++++++++++++++++++++ src/libcamera/v4l2_videodevice.cpp | 77 ---------------- 6 files changed, 154 insertions(+), 100 deletions(-) create mode 100644 src/libcamera/include/v4l2_pixelformat.h create mode 100644 src/libcamera/v4l2_pixelformat.cpp diff --git a/src/libcamera/include/meson.build b/src/libcamera/include/meson.build index 5aaa99472e4a..683d06133741 100644 --- a/src/libcamera/include/meson.build +++ b/src/libcamera/include/meson.build @@ -27,6 +27,7 @@ libcamera_headers = files([ 'utils.h', 'v4l2_controls.h', 'v4l2_device.h', + 'v4l2_pixelformat.h', 'v4l2_subdevice.h', 'v4l2_videodevice.h', ]) diff --git a/src/libcamera/include/v4l2_pixelformat.h b/src/libcamera/include/v4l2_pixelformat.h new file mode 100644 index 000000000000..4d277569cb8c --- /dev/null +++ b/src/libcamera/include/v4l2_pixelformat.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd. + * + * v4l2_pixelformat.h - V4L2 Pixel Format + */ +#ifndef __LIBCAMERA_V4L2_PIXELFORMAT_H__ +#define __LIBCAMERA_V4L2_PIXELFORMAT_H__ + +#include +#include + +#include + +#include + +namespace libcamera { + +class V4L2PixelFormat +{ +public: + V4L2PixelFormat() + : fourcc_(0) + { + } + + explicit V4L2PixelFormat(uint32_t fourcc) + : fourcc_(fourcc) + { + } + + bool isValid() const { return fourcc_ != 0; } + uint32_t fourcc() const { return fourcc_; } + operator uint32_t() const { return fourcc_; } + + std::string toString() const; + +private: + uint32_t fourcc_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_V4L2_PIXELFORMAT_H__ */ diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index 976ef9b6dc50..ff64bb357c7e 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -23,6 +23,7 @@ #include "formats.h" #include "log.h" #include "v4l2_device.h" +#include "v4l2_pixelformat.h" namespace libcamera { @@ -149,29 +150,6 @@ private: unsigned int missCounter_; }; -class V4L2PixelFormat -{ -public: - V4L2PixelFormat() - : fourcc_(0) - { - } - - explicit V4L2PixelFormat(uint32_t fourcc) - : fourcc_(fourcc) - { - } - - bool isValid() const { return fourcc_ != 0; } - uint32_t fourcc() const { return fourcc_; } - operator uint32_t() const { return fourcc_; } - - std::string toString() const; - -private: - uint32_t fourcc_; -}; - class V4L2DeviceFormat { public: diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 874d25904693..d8b4d7206aba 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -44,6 +44,7 @@ libcamera_sources = files([ 'utils.cpp', 'v4l2_controls.cpp', 'v4l2_device.cpp', + 'v4l2_pixelformat.cpp', 'v4l2_subdevice.cpp', 'v4l2_videodevice.cpp', ]) diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp new file mode 100644 index 000000000000..57d65c380b0d --- /dev/null +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd. + * + * v4l2_pixelformat.cpp - V4L2 Pixel Format + */ + +#include "v4l2_pixelformat.h" + +#include +#include +#include + +#include + +#include + +#include "log.h" + +/** + * \file v4l2_pixelformat.h + * \brief V4L2 Pixel Format + */ +namespace libcamera { + +LOG_DECLARE_CATEGORY(V4L2) + +/** + * \class V4L2PixelFormat + * \brief V4L2 pixel format FourCC wrapper + * + * The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It + * wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with + * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of + * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at + * compile time. + * + * To achieve this goal, construction of a V4L2PixelFormat from an integer value + * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the + * explicit value() and implicit uint32_t conversion operators may be used. + */ + +/** + * \fn V4L2PixelFormat::V4L2PixelFormat() + * \brief Construct a V4L2PixelFormat with an invalid format + * + * V4L2PixelFormat instances constructed with the default constructor are + * invalid, calling the isValid() function returns false. + */ + +/** + * \fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc) + * \brief Construct a V4L2PixelFormat from a FourCC value + * \param[in] fourcc The pixel format FourCC numerical value + */ + +/** + * \fn bool V4L2PixelFormat::isValid() const + * \brief Check if the pixel format is valid + * + * V4L2PixelFormat instances constructed with the default constructor are + * invalid. Instances constructed with a FourCC defined in the V4L2 API are + * valid. The behaviour is undefined otherwise. + * + * \return True if the pixel format is valid, false otherwise + */ + +/** + * \fn uint32_t V4L2PixelFormat::fourcc() const + * \brief Retrieve the pixel format FourCC numerical value + * \return The pixel format FourCC numerical value + */ + +/** + * \fn V4L2PixelFormat::operator uint32_t() const + * \brief Convert to the pixel format FourCC numerical value + * \return The pixel format FourCC numerical value + */ + +/** + * \brief Assemble and return a string describing the pixel format + * \return A string describing the pixel format + */ +std::string V4L2PixelFormat::toString() const +{ + if (fourcc_ == 0) + return ""; + + char ss[8] = { static_cast(fourcc_ & 0x7f), + static_cast((fourcc_ >> 8) & 0x7f), + static_cast((fourcc_ >> 16) & 0x7f), + static_cast((fourcc_ >> 24) & 0x7f) }; + + for (unsigned int i = 0; i < 4; i++) { + if (!isprint(ss[i])) + ss[i] = '.'; + } + + if (fourcc_ & (1 << 31)) + strcat(ss, "-BE"); + + return ss; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index e8d4f17dfdf1..21df4f524212 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -278,83 +278,6 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const return true; } -/** - * \class V4L2PixelFormat - * \brief V4L2 pixel format FourCC wrapper - * - * The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It - * wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with - * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of - * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at - * compile time. - * - * To achieve this goal, construction of a V4L2PixelFormat from an integer value - * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the - * explicit value() and implicit uint32_t conversion operators may be used. - */ - -/** - * \fn V4L2PixelFormat::V4L2PixelFormat() - * \brief Construct a V4L2PixelFormat with an invalid format - * - * V4L2PixelFormat instances constructed with the default constructor are - * invalid, calling the isValid() function returns false. - */ - -/** - * \fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc) - * \brief Construct a V4L2PixelFormat from a FourCC value - * \param[in] fourcc The pixel format FourCC numerical value - */ - -/** - * \fn bool V4L2PixelFormat::isValid() const - * \brief Check if the pixel format is valid - * - * V4L2PixelFormat instances constructed with the default constructor are - * invalid. Instances constructed with a FourCC defined in the V4L2 API are - * valid. The behaviour is undefined otherwise. - * - * \return True if the pixel format is valid, false otherwise - */ - -/** - * \fn uint32_t V4L2PixelFormat::fourcc() const - * \brief Retrieve the pixel format FourCC numerical value - * \return The pixel format FourCC numerical value - */ - -/** - * \fn V4L2PixelFormat::operator uint32_t() const - * \brief Convert to the pixel format FourCC numerical value - * \return The pixel format FourCC numerical value - */ - -/** - * \brief Assemble and return a string describing the pixel format - * \return A string describing the pixel format - */ -std::string V4L2PixelFormat::toString() const -{ - if (fourcc_ == 0) - return ""; - - char ss[8] = { static_cast(fourcc_ & 0x7f), - static_cast((fourcc_ >> 8) & 0x7f), - static_cast((fourcc_ >> 16) & 0x7f), - static_cast((fourcc_ >> 24) & 0x7f) }; - - for (unsigned int i = 0; i < 4; i++) { - if (!isprint(ss[i])) - ss[i] = '.'; - } - - if (fourcc_ & (1 << 31)) - strcat(ss, "-BE"); - - return ss; -} - /** * \class V4L2DeviceFormat * \brief The V4L2 video device image format and sizes