[PATCH 05/16] libcamera: software_isp: Allocation of multiple params buffers
Milan Zamazal
mzamazal at redhat.com
Mon Aug 12 13:49:54 CEST 2024
SoftwareIsp::sharedParams_ is changed from a single buffer to a map of
multiple buffer ids and the corresponding buffers. This requires some
code rearranging within SoftwareIsp::allocateBuffers to keep the right
sequence of actions.
Currently, only a single buffer is allocated, this will be changed in a
followup patch.
Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
---
.../internal/software_isp/software_isp.h | 3 +-
src/libcamera/software_isp/software_isp.cpp | 55 +++++++++++--------
2 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h
index 74f5b952..c2fcc307 100644
--- a/include/libcamera/internal/software_isp/software_isp.h
+++ b/include/libcamera/internal/software_isp/software_isp.h
@@ -94,7 +94,8 @@ private:
std::unique_ptr<DebayerCpu> debayer_;
Thread ispWorkerThread_;
- SharedMemObject<DebayerParams> sharedParams_;
+ static constexpr unsigned int kParamStatBufferCount = 1;
+ std::map<uint32_t, SharedMemObject<DebayerParams>> sharedParams_;
DebayerParams debayerParams_;
std::queue<uint32_t> availableParams_;
bool allocateParamsBuffers();
diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp
index a9865398..d78537fc 100644
--- a/src/libcamera/software_isp/software_isp.cpp
+++ b/src/libcamera/software_isp/software_isp.cpp
@@ -57,6 +57,11 @@ LOG_DEFINE_CATEGORY(SoftwareIsp)
* ready
*/
+/**
+ * \var SoftwareIsp::kParamStatBufferCount
+ * \brief The number of stats and params buffers (each of them)
+ */
+
/**
* \brief Constructs SoftwareIsp object
* \param[in] pipe The pipeline handler in use
@@ -104,7 +109,7 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor)
int ret = ipa_->init(IPASettings{ ipaTuningFile, sensor->model() },
debayer_->getStatsFD(),
- sharedParams_.fd(),
+ sharedParams_.begin()->second.fd(),
sensor->controls());
if (ret) {
LOG(SoftwareIsp, Error) << "IPA init failed";
@@ -126,32 +131,36 @@ SoftwareIsp::~SoftwareIsp()
bool SoftwareIsp::allocateParamsBuffers()
{
- /*
- * DebayerParams must be initialized because the initial value is used for
- * the first two frames, i.e. until stats processing starts providing its
- * own parameters.
- *
- * \todo This should be handled in the same place as the related
- * operations, in the IPA module.
- */
std::array<uint8_t, 256> gammaTable;
for (unsigned int i = 0; i < 256; i++)
gammaTable[i] = UINT8_MAX * std::pow(i / 256.0, 0.5);
- for (unsigned int j = 0; j < DebayerParams::kRGBLookupSize; j++) {
- debayerParams_.red[j] = gammaTable[j];
- debayerParams_.green[j] = gammaTable[j];
- debayerParams_.blue[j] = gammaTable[j];
- }
- sharedParams_ = SharedMemObject<DebayerParams>("softIsp_params");
- if (!sharedParams_) {
- LOG(SoftwareIsp, Error) << "Failed to create shared memory for parameters";
- return false;
- }
+ for (unsigned int i = 0; i < kParamStatBufferCount; i++) {
+ auto params = SharedMemObject<DebayerParams>("softIsp_params");
+ if (!params) {
+ LOG(SoftwareIsp, Error) << "Failed to create shared memory for parameters";
+ return false;
+ }
- ASSERT(sharedParams_.fd().get() >= 0);
- const uint32_t bufferId = sharedParams_.fd().get();
- availableParams_.push(bufferId);
+ /*
+ * DebayerParams must be initialized because the initial value is used for
+ * the first two frames, i.e. until stats processing starts providing its
+ * own parameters.
+ *
+ * \todo This should be handled in the same place as the related
+ * operations, in the IPA module.
+ */
+ for (unsigned int j = 0; j < DebayerParams::kRGBLookupSize; j++) {
+ params->red[j] = gammaTable[j];
+ params->green[j] = gammaTable[j];
+ params->blue[j] = gammaTable[j];
+ }
+
+ ASSERT(params.fd().get() >= 0);
+ const uint32_t bufferId = params.fd().get();
+ availableParams_.push(bufferId);
+ sharedParams_.emplace(bufferId, std::move(params));
+ }
return true;
}
@@ -380,7 +389,7 @@ void SoftwareIsp::process(uint32_t frame, FrameBuffer *input, FrameBuffer *outpu
void SoftwareIsp::saveIspParams([[maybe_unused]] uint32_t paramsBufferId)
{
- debayerParams_ = *sharedParams_;
+ debayerParams_ = *sharedParams_.begin()->second;
}
void SoftwareIsp::releaseIspParams(uint32_t paramsBufferId)
--
2.44.1
More information about the libcamera-devel
mailing list