summaryrefslogtreecommitdiff
path: root/src/libcamera/pipeline/ipu3/frames.cpp
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-11-02 23:46:44 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2021-02-05 01:20:32 +0100
commitd2bc3eb7b69a2ae7e2e4bd69950247141668666c (patch)
tree2d970a67e6ae2315559171935d2c1b66238fa92e /src/libcamera/pipeline/ipu3/frames.cpp
parent82549ae253302bf612978282ea3858821465e8ed (diff)
libcamera: ipu3: Add helper for parameter and statistic buffers
Add a helper class to aid in associating a parameter and statistic buffer with each request queued to the pipeline. The helper helps with tracking the state of the extra buffers and in completing the request once all extra processing is done. This change only adds the helper more work is needed to integrate it with the pipeline and an IPA. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/pipeline/ipu3/frames.cpp')
-rw-r--r--src/libcamera/pipeline/ipu3/frames.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp
new file mode 100644
index 00000000..37932dc7
--- /dev/null
+++ b/src/libcamera/pipeline/ipu3/frames.cpp
@@ -0,0 +1,136 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2020, Google Inc.
+ *
+ * frames.cpp - Intel IPU3 Frames helper
+ */
+
+#include "frames.h"
+
+#include <libcamera/buffer.h>
+#include <libcamera/request.h>
+
+#include "libcamera/internal/pipeline_handler.h"
+#include "libcamera/internal/v4l2_videodevice.h"
+
+namespace libcamera {
+
+LOG_DECLARE_CATEGORY(IPU3)
+
+IPU3Frames::IPU3Frames()
+ : nextId_(0)
+{
+}
+
+void IPU3Frames::init(const std::vector<std::unique_ptr<FrameBuffer>> &paramBuffers,
+ const std::vector<std::unique_ptr<FrameBuffer>> &statBuffers)
+{
+ for (const std::unique_ptr<FrameBuffer> &buffer : paramBuffers)
+ availableParamBuffers_.push(buffer.get());
+
+ for (const std::unique_ptr<FrameBuffer> &buffer : statBuffers)
+ availableStatBuffers_.push(buffer.get());
+
+ nextId_ = 0;
+ frameInfo_.clear();
+}
+
+void IPU3Frames::clear()
+{
+ availableParamBuffers_ = {};
+ availableStatBuffers_ = {};
+}
+
+IPU3Frames::Info *IPU3Frames::create(Request *request)
+{
+ unsigned int id = nextId_++;
+
+ if (availableParamBuffers_.empty()) {
+ LOG(IPU3, Error) << "Parameters buffer underrun";
+ return nullptr;
+ }
+ FrameBuffer *paramBuffer = availableParamBuffers_.front();
+
+ if (availableStatBuffers_.empty()) {
+ LOG(IPU3, Error) << "Statisitc buffer underrun";
+ return nullptr;
+ }
+ FrameBuffer *statBuffer = availableStatBuffers_.front();
+
+ availableParamBuffers_.pop();
+ availableStatBuffers_.pop();
+
+ /* \todo Remove the dynamic allocation of Info */
+ std::unique_ptr<Info> info = std::make_unique<Info>();
+
+ info->id = id;
+ info->request = request;
+ info->rawBuffer = nullptr;
+ info->paramBuffer = paramBuffer;
+ info->statBuffer = statBuffer;
+ info->paramDequeued = false;
+ info->metadataProcessed = false;
+
+ frameInfo_[id] = std::move(info);
+
+ return frameInfo_[id].get();
+}
+
+void IPU3Frames::remove(IPU3Frames::Info *info)
+{
+ /* Return params and stat buffer for reuse. */
+ availableParamBuffers_.push(info->paramBuffer);
+ availableStatBuffers_.push(info->statBuffer);
+
+ /* Delete the extended frame information. */
+ frameInfo_.erase(info->id);
+}
+
+bool IPU3Frames::tryComplete(IPU3Frames::Info *info)
+{
+ Request *request = info->request;
+
+ if (request->hasPendingBuffers())
+ return false;
+
+ if (!info->metadataProcessed)
+ return false;
+
+ if (!info->paramDequeued)
+ return false;
+
+ remove(info);
+
+ return true;
+}
+
+IPU3Frames::Info *IPU3Frames::find(unsigned int id)
+{
+ const auto &itInfo = frameInfo_.find(id);
+
+ if (itInfo != frameInfo_.end())
+ return itInfo->second.get();
+
+ LOG(IPU3, Error) << "Can't find tracking informaton for frame " << id;
+ return nullptr;
+}
+
+IPU3Frames::Info *IPU3Frames::find(FrameBuffer *buffer)
+{
+ for (auto const &itInfo : frameInfo_) {
+ Info *info = itInfo.second.get();
+
+ for (auto const itBuffers : info->request->buffers())
+ if (itBuffers.second == buffer)
+ return info;
+
+ if (info->rawBuffer == buffer || info->paramBuffer == buffer ||
+ info->statBuffer == buffer)
+ return info;
+ }
+
+ LOG(IPU3, Error) << "Can't find tracking informaton from buffer";
+ return nullptr;
+}
+
+} /* namespace libcamera */