From f3fe20bdde5b7d19b5fe94c83445ce477eade432 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 2 Apr 2024 11:42:09 +0200 Subject: [PATCH] buffer: add GenericFd memory type Add a Generic fd type. These could be eventfd or timerfd, the meaning can depend on extra metadata. --- spa/include/spa/buffer/buffer.h | 14 +++++++++++--- spa/include/spa/buffer/type-info.h | 1 + src/modules/module-client-node/client-node.c | 1 + test/test-spa-buffer.c | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spa/include/spa/buffer/buffer.h b/spa/include/spa/buffer/buffer.h index 8c02e9e08..e29be088a 100644 --- a/spa/include/spa/buffer/buffer.h +++ b/spa/include/spa/buffer/buffer.h @@ -27,9 +27,17 @@ enum spa_data_type { SPA_DATA_Invalid, SPA_DATA_MemPtr, /**< pointer to memory, the data field in * struct spa_data is set. */ - SPA_DATA_MemFd, /**< generic fd, mmap to get to memory */ - SPA_DATA_DmaBuf, /**< fd to dmabuf memory */ - SPA_DATA_MemId, /**< memory is identified with an id */ + SPA_DATA_MemFd, /**< memfd, mmap to get to memory. */ + SPA_DATA_DmaBuf, /**< fd to dmabuf memory. This might not be readily + * mappable (unless the MAPPABLE flag is set) and should + * normally be handled with DMABUF apis. */ + SPA_DATA_MemId, /**< memory is identified with an id. The actual memory + * can be obtained in some other way and can be identified + * with this id. */ + SPA_DATA_GenericFd, /**< generic fd, type and usage might be in metadata. If + * there is a size and MAPPABLE flag, this can be mmapped + * to obtain a memory region. The semantics of memfd might + * not be available (SEALING, ...) */ _SPA_DATA_LAST, /**< not part of ABI */ }; diff --git a/spa/include/spa/buffer/type-info.h b/spa/include/spa/buffer/type-info.h index 83dce2b80..bb4103f3f 100644 --- a/spa/include/spa/buffer/type-info.h +++ b/spa/include/spa/buffer/type-info.h @@ -35,6 +35,7 @@ static const struct spa_type_info spa_type_data_type[] = { { SPA_DATA_MemFd, SPA_TYPE_Int, SPA_TYPE_INFO_DATA_FD_BASE "MemFd", NULL }, { SPA_DATA_DmaBuf, SPA_TYPE_Int, SPA_TYPE_INFO_DATA_FD_BASE "DmaBuf", NULL }, { SPA_DATA_MemId, SPA_TYPE_Int, SPA_TYPE_INFO_DATA_BASE "MemId", NULL }, + { SPA_DATA_GenericFd, SPA_TYPE_Int, SPA_TYPE_INFO_DATA_BASE "GenericFd", NULL }, { 0, 0, NULL, NULL }, }; diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index 45ab83627..a3b70810b 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -855,6 +855,7 @@ do_port_use_buffers(struct impl *impl, switch (d->type) { case SPA_DATA_DmaBuf: case SPA_DATA_MemFd: + case SPA_DATA_GenericFd: { uint32_t flags = PW_MEMBLOCK_FLAG_DONT_CLOSE; diff --git a/test/test-spa-buffer.c b/test/test-spa-buffer.c index d0c0e0bb9..eb4076951 100644 --- a/test/test-spa-buffer.c +++ b/test/test-spa-buffer.c @@ -17,7 +17,8 @@ PWTEST(buffer_abi_types) pwtest_int_eq(SPA_DATA_MemFd, 2); pwtest_int_eq(SPA_DATA_DmaBuf, 3); pwtest_int_eq(SPA_DATA_MemId, 4); - pwtest_int_eq(_SPA_DATA_LAST, 5); + pwtest_int_eq(SPA_DATA_GenericFd, 5); + pwtest_int_eq(_SPA_DATA_LAST, 6); /* meta */ pwtest_int_eq(SPA_META_Invalid, 0);