spa: libcamera: source: remove SPA_DATA_MemPtr support

The current handling of `SPA_DATA_MemPtr` is not entirely correct because
its handling of multi-planar buffers is not appropriate: it leaks memory
mappings because it overwrites `buffer::ptr` for each plane.

Since this data type should not really be in use in normal deployments,
let's remove it for now.
This commit is contained in:
Barnabás Pőcze 2025-08-12 23:36:49 +02:00
parent 3e28f3e859
commit b948ffdb25

View file

@ -53,7 +53,6 @@ namespace {
#define MASK_BUFFERS 31
#define BUFFER_FLAG_OUTSTANDING (1<<0)
#define BUFFER_FLAG_MAPPED (1<<1)
struct buffer {
uint32_t id;
@ -386,11 +385,6 @@ int spa_libcamera_clear_buffers(struct impl *impl, struct port *port)
b = &port->buffers[i];
d = b->outbuf->datas;
if (SPA_FLAG_IS_SET(b->flags, BUFFER_FLAG_MAPPED)) {
munmap(SPA_PTROFF(b->ptr, -d[0].mapoffset, void),
d[0].maxsize - d[0].mapoffset);
}
d[0].type = SPA_ID_INVALID;
}
@ -1225,10 +1219,8 @@ spa_libcamera_alloc_buffers(struct impl *impl, struct port *port,
if (d[0].type != SPA_ID_INVALID && d[0].type & (1u << SPA_DATA_DmaBuf)) {
port->memtype = SPA_DATA_DmaBuf;
} else if (d[0].type != SPA_ID_INVALID && d[0].type & (1u << SPA_DATA_MemFd)) {
} else if (d[0].type & (1u << SPA_DATA_MemFd)) {
port->memtype = SPA_DATA_MemFd;
} else if (d[0].type & (1u << SPA_DATA_MemPtr)) {
port->memtype = SPA_DATA_MemPtr;
} else {
spa_log_error(impl->log, "can't use buffers of type %d", d[0].type);
return -EINVAL;
@ -1299,21 +1291,6 @@ spa_libcamera_alloc_buffers(struct impl *impl, struct port *port,
d[j].fd = bufs[i]->planes()[j].fd.get();
spa_log_debug(impl->log, "Got fd = %" PRId64 " for buffer: #%d", d[j].fd, i);
d[j].data = nullptr;
}
else if (port->memtype == SPA_DATA_MemPtr) {
d[j].fd = -1;
d[j].data = mmap(nullptr,
d[j].maxsize + d[j].mapoffset,
PROT_READ, MAP_SHARED,
bufs[i]->planes()[j].fd.get(),
0);
if (d[j].data == MAP_FAILED) {
spa_log_error(impl->log, "mmap: %m");
continue;
}
b->ptr = d[j].data;
SPA_FLAG_SET(b->flags, BUFFER_FLAG_MAPPED);
spa_log_debug(impl->log, "mmap ptr:%p", d[j].data);
} else {
spa_log_error(impl->log, "invalid buffer type");
return -EIO;