From 3c5732d04a879d71d928e200d399c8d61b0da27a Mon Sep 17 00:00:00 2001 From: Umang Jain Date: Sat, 14 Aug 2021 10:39:11 +0530 Subject: ipa: vimc: Map and unmap buffers VIMC pipeline handler has dmabuf-backed mock FrameBuffers which are specifically targetted mimicking IPA buffers (parameter and statistics). Map these mock buffers to the VIMC IPA that would enable exercising IPA IPC code paths. This will provide leverage to our test suite to test IPA IPC code paths, which are common to various platforms. Signed-off-by: Umang Jain Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart --- src/ipa/vimc/vimc.cpp | 27 +++++++++++++++++++++++++++ src/libcamera/pipeline/vimc/vimc.cpp | 14 ++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'src') diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp index fb134084..7d9d22d0 100644 --- a/src/ipa/vimc/vimc.cpp +++ b/src/ipa/vimc/vimc.cpp @@ -19,6 +19,8 @@ #include #include +#include "libcamera/internal/mapped_framebuffer.h" + namespace libcamera { LOG_DEFINE_CATEGORY(IPAVimc) @@ -38,11 +40,15 @@ public: const std::map &streamConfig, const std::map &entityControls) override; + void mapBuffers(const std::vector &buffers) override; + void unmapBuffers(const std::vector &ids) override; + private: void initTrace(); void trace(enum ipa::vimc::IPAOperationCode operation); int fd_; + std::map buffers_; }; IPAVimc::IPAVimc() @@ -99,6 +105,27 @@ int IPAVimc::configure([[maybe_unused]] const IPACameraSensorInfo &sensorInfo, return 0; } +void IPAVimc::mapBuffers(const std::vector &buffers) +{ + for (const IPABuffer &buffer : buffers) { + const FrameBuffer fb(buffer.planes); + buffers_.emplace(std::piecewise_construct, + std::forward_as_tuple(buffer.id), + std::forward_as_tuple(&fb, MappedFrameBuffer::MapFlag::Read)); + } +} + +void IPAVimc::unmapBuffers(const std::vector &ids) +{ + for (unsigned int id : ids) { + auto it = buffers_.find(id); + if (it == buffers_.end()) + continue; + + buffers_.erase(it); + } +} + void IPAVimc::initTrace() { struct stat fifoStat; diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 90e0d558..e434cfbe 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -334,6 +334,14 @@ int PipelineHandlerVimc::start(Camera *camera, [[maybe_unused]] const ControlLis if (ret < 0) return ret; + /* Map the mock IPA buffers to VIMC IPA to exercise IPC code paths. */ + std::vector ipaBuffers; + for (auto [i, buffer] : utils::enumerate(data->mockIPABufs_)) { + buffer->setCookie(i + 1); + ipaBuffers.emplace_back(buffer->cookie(), buffer->planes()); + } + data->ipa_->mapBuffers(ipaBuffers); + ret = data->ipa_->start(); if (ret) { data->video_->releaseBuffers(); @@ -354,7 +362,13 @@ void PipelineHandlerVimc::stop(Camera *camera) { VimcCameraData *data = cameraData(camera); data->video_->streamOff(); + + std::vector ids; + for (const std::unique_ptr &buffer : data->mockIPABufs_) + ids.push_back(buffer->cookie()); + data->ipa_->unmapBuffers(ids); data->ipa_->stop(); + data->video_->releaseBuffers(); } -- cgit v1.2.1