libcamera: allocate memory according to the number of discontiguous memory

This commit is contained in:
Elliot 2024-10-30 16:35:49 +08:00 committed by Wim Taymans
parent fb2b314660
commit d67882fa10
2 changed files with 26 additions and 1 deletions

View file

@ -109,6 +109,30 @@ static int allocBuffers(struct impl *impl, struct port *port, unsigned int count
}
impl->requestPool.push_back(std::move(request));
}
/* Some devices require data for each output video frame to be
* placed in discontiguous memory buffers. In such cases, one
* video frame has to be addressed using more than one memory.
* address. Therefore, need calculate the number of discontiguous
* memory and allocate the specified amount of memory */
Stream *stream = impl->config->at(0).stream();
const std::vector<std::unique_ptr<FrameBuffer>> &bufs =
impl->allocator->buffers(stream);
const std::vector<libcamera::FrameBuffer::Plane> &planes = bufs[0]->planes();
int fd = -1;
uint32_t buffers_blocks = 0;
for (const FrameBuffer::Plane &plane : planes) {
const int current_fd = plane.fd.get();
if (current_fd >= 0 && current_fd != fd) {
buffers_blocks += 1;
fd = current_fd;
}
}
if (buffers_blocks > 0) {
port->buffers_blocks = buffers_blocks;
}
return res;
}