meta: add explicit sync metadata and data type

Change the GenericFd data type to SyncObj. It's probably better to
explicitly state the data type than to make something generic. Otherwise
we would need to transfer the specific fd type somewhere else and there
is no room for that in the buffer and the the metadata is not a good idea
either because it can be modified and corrupted at runtime.

Add the SyncTimeline metadata. This contains 2 points on two timelines
(SyncObj datas in the buffer). The buffer can be accessed when the
acquire_point is signaled on the timeline and when the buffer
can be released, the release_point on the timeline should be signaled.
This commit is contained in:
Wim Taymans 2024-04-02 11:42:09 +02:00
parent 350416768e
commit 99dcf94ad3
6 changed files with 34 additions and 7 deletions

View file

@ -27,9 +27,15 @@ 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_SyncObj, /**< a syncobj, usually requires a spa_meta_sync_timeline metadata
* with timeline points. */
_SPA_DATA_LAST, /**< not part of ABI */
};

View file

@ -28,6 +28,7 @@ enum spa_meta_type {
* associated with the data */
SPA_META_Busy, /**< don't write to buffer when count > 0 */
SPA_META_VideoTransform, /**< struct spa_meta_transform */
SPA_META_SyncTimeline, /**< struct spa_meta_sync_timeline */
_SPA_META_LAST, /**< not part of ABI/API */
};
@ -161,6 +162,21 @@ struct spa_meta_videotransform {
* one of enum spa_meta_videotransform_value */
};
/**
* A timeline point for explicit sync
*
* Metadata to describe the time on the timeline when the buffer
* can be acquired and when it can be reused.
*/
struct spa_meta_sync_timeline {
uint32_t flags;
uint32_t padding;
uint64_t acquire_point; /**< the timeline acquire point, this is when the data
* can be accessed. */
uint64_t release_point; /**< the timeline release point, this timeline point should
* be signaled when the data is no longer accessed. */
};
/**
* \}
*/

View file

@ -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_SyncObj, SPA_TYPE_Int, SPA_TYPE_INFO_DATA_BASE "SyncObj", NULL },
{ 0, 0, NULL, NULL },
};
@ -60,6 +61,7 @@ static const struct spa_type_info spa_type_meta_type[] = {
{ SPA_META_Control, SPA_TYPE_Pointer, SPA_TYPE_INFO_META_BASE "Control", NULL },
{ SPA_META_Busy, SPA_TYPE_Pointer, SPA_TYPE_INFO_META_BASE "Busy", NULL },
{ SPA_META_VideoTransform, SPA_TYPE_Pointer, SPA_TYPE_INFO_META_BASE "VideoTransform", NULL },
{ SPA_META_SyncTimeline, SPA_TYPE_Pointer, SPA_TYPE_INFO_META_BASE "SyncTimeline", NULL },
{ 0, 0, NULL, NULL },
};

View file

@ -31,8 +31,8 @@ enum spa_param_buffers {
/** properties for SPA_TYPE_OBJECT_ParamMeta */
enum spa_param_meta {
SPA_PARAM_META_START,
SPA_PARAM_META_type, /**< the metadata, one of enum spa_meta_type (Id enum spa_meta_type) */
SPA_PARAM_META_size, /**< the expected maximum size the meta (Int) */
SPA_PARAM_META_type, /**< the metadata, one of enum spa_meta_type (Id enum spa_meta_type) */
SPA_PARAM_META_size, /**< the expected maximum size the meta (Int) */
};
/** properties for SPA_TYPE_OBJECT_ParamIO */

View file

@ -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_SyncObj:
{
uint32_t flags = PW_MEMBLOCK_FLAG_DONT_CLOSE;

View file

@ -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_SyncObj, 5);
pwtest_int_eq(_SPA_DATA_LAST, 6);
/* meta */
pwtest_int_eq(SPA_META_Invalid, 0);
@ -29,7 +30,8 @@ PWTEST(buffer_abi_types)
pwtest_int_eq(SPA_META_Control, 6);
pwtest_int_eq(SPA_META_Busy, 7);
pwtest_int_eq(SPA_META_VideoTransform, 8);
pwtest_int_eq(_SPA_META_LAST, 9);
pwtest_int_eq(SPA_META_SyncTimeline, 9);
pwtest_int_eq(_SPA_META_LAST, 10);
return PWTEST_PASS;
}