From 73994ec6bcc99e8df342d7c076d1b01261848c34 Mon Sep 17 00:00:00 2001 From: Hirokazu Honda Date: Thu, 26 Aug 2021 20:25:34 +0900 Subject: 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 Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/ipa/rkisp1/rkisp1.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src/ipa') 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 #include #include -#include #include #include @@ -24,6 +23,8 @@ #include #include +#include + namespace libcamera { LOG_DEFINE_CATEGORY(IPARkISP1) @@ -54,7 +55,7 @@ private: void metadataReady(unsigned int frame, unsigned int aeState); std::map buffers_; - std::map buffersMemory_; + std::map mappedBuffers_; ControlInfoMap ctrls_; @@ -160,22 +161,13 @@ void IPARkISP1::mapBuffers(const std::vector &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 &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(buffersMemory_[bufferId]); + reinterpret_cast( + 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(buffersMemory_[bufferId]); + reinterpret_cast( + mappedBuffers_.at(bufferId).maps()[0].data()); queueRequest(frame, params, event.controls); break; -- cgit v1.2.1