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

@ -69,6 +69,7 @@ struct port {
StreamConfiguration streamConfig;
uint32_t memtype = 0;
uint32_t buffers_blocks = 1;
struct buffer buffers[MAX_BUFFERS];
uint32_t n_buffers = 0;
@ -553,7 +554,7 @@ next:
param = (struct spa_pod*)spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamBuffers, id,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(n_buffers, n_buffers, n_buffers),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(port->buffers_blocks),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(port->streamConfig.frameSize),
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->streamConfig.stride));
break;

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;
}