summaryrefslogtreecommitdiff
path: root/src/ipa
diff options
context:
space:
mode:
authorHirokazu Honda <hiroh@chromium.org>2021-08-26 20:25:34 +0900
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-08-30 18:08:02 +0300
commit73994ec6bcc99e8df342d7c076d1b01261848c34 (patch)
tree014c5ae727f1601055c9098773d960bbf4bf6e80 /src/ipa
parent470513b6a7734ced9beea2e1d673a37ba0f82b35 (diff)
ipa: rkisp1: Use offset in mapping IPABuffer
IPABuffer is represented by FrameBuffer. FrameBuffer::Plane has now an offset. This uses the offset variable to map the IPABuffer. The mapped IPABuffer is represented and managed as MappedFrameBuffer. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/ipa')
-rw-r--r--src/ipa/rkisp1/rkisp1.cpp33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
index 06fb9640..046816e0 100644
--- a/src/ipa/rkisp1/rkisp1.cpp
+++ b/src/ipa/rkisp1/rkisp1.cpp
@@ -10,7 +10,6 @@
#include <queue>
#include <stdint.h>
#include <string.h>
-#include <sys/mman.h>
#include <linux/rkisp1-config.h>
#include <linux/v4l2-controls.h>
@@ -24,6 +23,8 @@
#include <libcamera/ipa/rkisp1_ipa_interface.h>
#include <libcamera/request.h>
+#include <libcamera/internal/mapped_framebuffer.h>
+
namespace libcamera {
LOG_DEFINE_CATEGORY(IPARkISP1)
@@ -54,7 +55,7 @@ private:
void metadataReady(unsigned int frame, unsigned int aeState);
std::map<unsigned int, FrameBuffer> buffers_;
- std::map<unsigned int, void *> buffersMemory_;
+ std::map<unsigned int, MappedFrameBuffer> mappedBuffers_;
ControlInfoMap ctrls_;
@@ -160,22 +161,13 @@ void IPARkISP1::mapBuffers(const std::vector<IPABuffer> &buffers)
std::forward_as_tuple(buffer.planes));
const FrameBuffer &fb = elem.first->second;
- /*
- * \todo Provide a helper to mmap() buffers (possibly exposed
- * to applications).
- */
- buffersMemory_[buffer.id] = mmap(NULL,
- fb.planes()[0].length,
- PROT_READ | PROT_WRITE,
- MAP_SHARED,
- fb.planes()[0].fd.fd(),
- 0);
-
- if (buffersMemory_[buffer.id] == MAP_FAILED) {
- int ret = -errno;
+ MappedFrameBuffer mappedBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite);
+ if (!mappedBuffer.isValid()) {
LOG(IPARkISP1, Fatal) << "Failed to mmap buffer: "
- << strerror(-ret);
+ << strerror(mappedBuffer.error());
}
+
+ mappedBuffers_.emplace(buffer.id, std::move(mappedBuffer));
}
}
@@ -186,8 +178,7 @@ void IPARkISP1::unmapBuffers(const std::vector<unsigned int> &ids)
if (fb == buffers_.end())
continue;
- munmap(buffersMemory_[id], fb->second.planes()[0].length);
- buffersMemory_.erase(id);
+ mappedBuffers_.erase(id);
buffers_.erase(id);
}
}
@@ -200,7 +191,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event)
unsigned int bufferId = event.bufferId;
const rkisp1_stat_buffer *stats =
- static_cast<rkisp1_stat_buffer *>(buffersMemory_[bufferId]);
+ reinterpret_cast<rkisp1_stat_buffer *>(
+ mappedBuffers_.at(bufferId).maps()[0].data());
updateStatistics(frame, stats);
break;
@@ -210,7 +202,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event)
unsigned int bufferId = event.bufferId;
rkisp1_params_cfg *params =
- static_cast<rkisp1_params_cfg *>(buffersMemory_[bufferId]);
+ reinterpret_cast<rkisp1_params_cfg *>(
+ mappedBuffers_.at(bufferId).maps()[0].data());
queueRequest(frame, params, event.controls);
break;