diff options
author | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-11-25 22:14:40 +0100 |
---|---|---|
committer | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2020-01-12 16:10:37 +0100 |
commit | 007517618c8440d09cfd39db5dbf451e87ef703a (patch) | |
tree | c946dbcd940f14988881c48ac03b37c50796db18 /src/ipa/rkisp1/rkisp1.cpp | |
parent | de9243bdc1986c57bee4dae3a5ba4fc8fc4293fe (diff) |
ipa: Switch to FrameBuffer interface
Switch the IPA interfaces and implementations to use the Framebuffer
interface.
- The IPA interface is switched to use the simpler FrameBuffer::Plane
container when carrying dmabuf descriptions (fd and length) over the
pipeline/IPA boundary.
- The RkISP1 IPA implementation takes advantage of the new simpler and
safer (better control over file descriptors) FrameBuffer interface.
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/ipa/rkisp1/rkisp1.cpp')
-rw-r--r-- | src/ipa/rkisp1/rkisp1.cpp | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 744a16ae..74b29220 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -10,6 +10,7 @@ #include <queue> #include <stdint.h> #include <string.h> +#include <sys/mman.h> #include <linux/rkisp1-config.h> @@ -48,7 +49,8 @@ private: void setControls(unsigned int frame); void metadataReady(unsigned int frame, unsigned int aeState); - std::map<unsigned int, BufferMemory> bufferInfo_; + std::map<unsigned int, FrameBuffer> buffers_; + std::map<unsigned int, void *> buffersMemory_; ControlInfoMap ctrls_; @@ -102,15 +104,39 @@ void IPARkISP1::configure(const std::map<unsigned int, IPAStream> &streamConfig, void IPARkISP1::mapBuffers(const std::vector<IPABuffer> &buffers) { for (const IPABuffer &buffer : buffers) { - bufferInfo_[buffer.id] = buffer.memory; - bufferInfo_[buffer.id].planes()[0].mem(); + auto elem = buffers_.emplace(buffer.id, 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; + LOG(IPARkISP1, Fatal) << "Failed to mmap buffer: " + << strerror(-ret); + } } } void IPARkISP1::unmapBuffers(const std::vector<unsigned int> &ids) { - for (unsigned int id : ids) - bufferInfo_.erase(id); + for (unsigned int id : ids) { + const auto fb = buffers_.find(id); + if (fb == buffers_.end()) + continue; + + munmap(buffersMemory_[id], fb->second.planes()[0].length); + buffersMemory_.erase(id); + buffers_.erase(id); + } } void IPARkISP1::processEvent(const IPAOperationData &event) @@ -121,7 +147,7 @@ void IPARkISP1::processEvent(const IPAOperationData &event) unsigned int bufferId = event.data[1]; const rkisp1_stat_buffer *stats = - static_cast<rkisp1_stat_buffer *>(bufferInfo_[bufferId].planes()[0].mem()); + static_cast<rkisp1_stat_buffer *>(buffersMemory_[bufferId]); updateStatistics(frame, stats); break; @@ -131,7 +157,7 @@ void IPARkISP1::processEvent(const IPAOperationData &event) unsigned int bufferId = event.data[1]; rkisp1_isp_params_cfg *params = - static_cast<rkisp1_isp_params_cfg *>(bufferInfo_[bufferId].planes()[0].mem()); + static_cast<rkisp1_isp_params_cfg *>(buffersMemory_[bufferId]); queueRequest(frame, params, event.controls[0]); break; |