From patchwork Mon Jul 12 13:16:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 12912 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 3533DC3225 for ; Mon, 12 Jul 2021 13:16:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7550168524; Mon, 12 Jul 2021 15:16:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Q9Kt5cxX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F3F8B68521 for ; Mon, 12 Jul 2021 15:16:35 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:8515:881:eba9:bd61]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A3EFFCC; Mon, 12 Jul 2021 15:16:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626095795; bh=5y59I+QOvMANoWNw+lKLAIekraM98dQs6W9KlRAlfdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q9Kt5cxXm2n4i21TmWSBxUNAiFyxIEBGk1eIPtbn7zwbHHDcCqUNtgynGYyziJiRK GzVT8DPM2G/q0ioVg541Vk5f28cvR5XdYeex7z2V15fOdrWUumnMoVYS4oSF1WQoZZ CMtgjBbIx4DfSiZldzAaNJJdaLXALf3XG1DoKzAc= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Mon, 12 Jul 2021 15:16:29 +0200 Message-Id: <20210712131630.73914-2-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210712131630.73914-1-jeanmichel.hautbois@ideasonboard.com> References: <20210712131630.73914-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] ipa: libipa: Introduce Metadata 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 Metadata class comes from RPi from which a bit has been removed because we don't need it for now. All functions are inlined in metadata.h because of the template usage. Signed-off-by: Jean-Michel Hautbois --- src/ipa/ipu3/ipu3.cpp | 1 + src/ipa/libipa/meson.build | 6 ++- src/ipa/libipa/metadata.cpp | 101 ++++++++++++++++++++++++++++++++++++ src/ipa/libipa/metadata.h | 90 ++++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 src/ipa/libipa/metadata.cpp create mode 100644 src/ipa/libipa/metadata.h diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 71698d36..091856f5 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -25,6 +25,7 @@ #include "ipu3_agc.h" #include "ipu3_awb.h" #include "libipa/camera_sensor_helper.h" +#include "libipa/metadata.h" static constexpr uint32_t kMaxCellWidthPerSet = 160; static constexpr uint32_t kMaxCellHeightPerSet = 56; diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build index 3fda7c00..cc4e1cc9 100644 --- a/src/ipa/libipa/meson.build +++ b/src/ipa/libipa/meson.build @@ -3,13 +3,15 @@ libipa_headers = files([ 'algorithm.h', 'camera_sensor_helper.h', - 'histogram.h' + 'histogram.h', + 'metadata.h' ]) libipa_sources = files([ 'algorithm.cpp', 'camera_sensor_helper.cpp', - 'histogram.cpp' + 'histogram.cpp', + 'metadata.cpp' ]) libipa_includes = include_directories('..') diff --git a/src/ipa/libipa/metadata.cpp b/src/ipa/libipa/metadata.cpp new file mode 100644 index 00000000..b6aef897 --- /dev/null +++ b/src/ipa/libipa/metadata.cpp @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Based on the implementation from the Raspberry Pi IPA, + * Copyright (C) 2019-2021, Raspberry Pi (Trading) Ltd. + * Copyright (C) 2021, Ideas On Board + * + * metadata.cpp - libipa metadata class + */ + +#include "metadata.h" + +/** + * \file metadata.h + * \brief A metadata class to share objects + */ + +namespace libcamera { + +namespace ipa { + +/** + * \class Metadata + * \brief A simple class for carrying arbitrary metadata, for example + * about an image. It is used to exchange data between algorithms. + */ + +/** + * \fn Metadata::Metadata(Metadata const &other) + * \param[in] other A Metadata object + * + * Stores the data from one Metadata to another one + */ + +/** + * \fn Metadata::set(std::string const &tag, T const &value) + * \param[in] tag A string used as the key in a map + * \param[in] value The value to set into the map + * + * Sets the value in the map to the tag key. The mutex is + * taken for the duration of the block. + */ + +/** + * \fn Metadata::get(std::string const &tag, T &value) + * \param[in] tag A string used as the key in a map + * \param[in] value The value to set into the map + * + * Gets the value in the map of the tag key. The mutex is + * taken for the duration of the block. + * + * \return 0 if value is found, -1 if not existent + */ + +/** + * \fn Metadata::clear() + * Clear the Metadata map. The mutex is taken for the duration of + * the block. + */ + +/** + * \fn Metadata::merge(Metadata &other) + * \param[in] other A metadata to merge with + * Merge two Metadata maps. The mutex is taken for the duration of + * the block. + */ + +/** + * \fn Metadata::getLocked(std::string const &tag) + * \param[in] tag A string used as the key in a map + * + * Get the value of the tag key in the map. + * This allows in-place access to the Metadata contents, + * for which you should be holding the lock. + */ + +/** + * \fn Metadata::setLocked(std::string const &tag, T const &value) + * \param[in] tag A string used as the key in a map + * \param[in] value The value to set into the map + * + * Set the value to the tag key in the map. + * This allows in-place access to the Metadata contents, + * for which you should be holding the lock. + */ + +/** + * \fn Metadata::lock() + * Lock the mutex with the standard classes. + * e.g. std::lock_guard lock(metadata) + */ + +/** + * \fn Metadata::unlock() + * Unlock the mutex with the standard classes. + * e.g. std::lock_guard lock(metadata) + */ + +} /* namespace ipa */ + +} /* namespace libcamera */ + diff --git a/src/ipa/libipa/metadata.h b/src/ipa/libipa/metadata.h new file mode 100644 index 00000000..9801bece --- /dev/null +++ b/src/ipa/libipa/metadata.h @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Based on the implementation from the Raspberry Pi IPA, + * Copyright (C) 2019-2021, Raspberry Pi (Trading) Ltd. + * Copyright (C) 2021, Ideas On Board + * + * metadata.h - libipa metadata class + */ +#ifndef __LIBCAMERA_IPA_LIBIPA_METADATA_H__ +#define __LIBCAMERA_IPA_LIBIPA_METADATA_H__ + +#include +#include +#include +#include +#include + +namespace libcamera { + +namespace ipa { + +class Metadata +{ +public: + Metadata() = default; + + Metadata(Metadata const &other) + { + std::scoped_lock other_lock(other.mutex_); + data_ = other.data_; + } + + template + void set(std::string const &tag, T const &value) + { + std::scoped_lock lock(mutex_); + data_[tag] = value; + } + + template + int get(std::string const &tag, T &value) const + { + std::scoped_lock lock(mutex_); + auto it = data_.find(tag); + if (it == data_.end()) + return -1; + value = std::any_cast(it->second); + return 0; + } + + void clear() + { + std::scoped_lock lock(mutex_); + data_.clear(); + } + + void merge(Metadata &other) + { + std::scoped_lock lock(mutex_, other.mutex_); + data_.merge(other.data_); + } + + template + T *getLocked(std::string const &tag) + { + auto it = data_.find(tag); + if (it == data_.end()) + return nullptr; + return std::any_cast(&it->second); + } + + template + void setLocked(std::string const &tag, T const &value) + { + data_[tag] = value; + } + + void lock() { mutex_.lock(); } + void unlock() { mutex_.unlock(); } + +private: + mutable std::mutex mutex_; + std::map data_; +}; + +} /* namespace ipa */ + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_IPA_LIBIPA_METADATA_H__ */