2023-02-08 18:12:00 +01:00
|
|
|
/* Simple Plugin API */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#ifndef SPA_BUFFER_H
|
|
|
|
|
#define SPA_BUFFER_H
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/utils/defs.h>
|
|
|
|
|
#include <spa/buffer/meta.h>
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2021-10-02 20:55:53 +03:00
|
|
|
/** \defgroup spa_buffer Buffers
|
2017-06-09 17:24:18 +02:00
|
|
|
*
|
|
|
|
|
* Buffers describe the data and metadata that is exchanged between
|
|
|
|
|
* ports of a node.
|
|
|
|
|
*/
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2021-05-21 14:03:07 +10:00
|
|
|
/**
|
|
|
|
|
* \addtogroup spa_buffer
|
|
|
|
|
* \{
|
|
|
|
|
*/
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
enum spa_data_type {
|
2018-08-29 18:08:52 +02:00
|
|
|
SPA_DATA_Invalid,
|
2018-08-27 15:03:11 +02:00
|
|
|
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 */
|
2019-07-24 10:33:26 +02:00
|
|
|
SPA_DATA_MemId, /**< memory is identified with an id */
|
2019-01-07 18:00:23 +01:00
|
|
|
|
2021-05-06 10:55:40 +10:00
|
|
|
_SPA_DATA_LAST, /**< not part of ABI */
|
2017-05-25 13:28:15 +02:00
|
|
|
};
|
2017-04-26 18:42:50 +02:00
|
|
|
|
2019-07-25 12:10:05 +02:00
|
|
|
/** Chunk of memory, can change for each buffer */
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_chunk {
|
2017-11-21 12:30:15 +01:00
|
|
|
uint32_t offset; /**< offset of valid data. Should be taken
|
|
|
|
|
* modulo the data maxsize to get the offset
|
|
|
|
|
* in the data memory. */
|
|
|
|
|
uint32_t size; /**< size of valid data. Should be clamped to
|
|
|
|
|
* maxsize. */
|
|
|
|
|
int32_t stride; /**< stride of valid data */
|
2019-07-25 12:10:05 +02:00
|
|
|
#define SPA_CHUNK_FLAG_NONE 0
|
|
|
|
|
#define SPA_CHUNK_FLAG_CORRUPTED (1u<<0) /**< chunk data is corrupted in some way */
|
2022-06-24 11:09:01 +02:00
|
|
|
#define SPA_CHUNK_FLAG_EMPTY (1u<<1) /**< chunk data is empty with media specific
|
|
|
|
|
* neutral data such as silence or black. This
|
|
|
|
|
* could be used to optimize processing. */
|
2019-07-25 12:10:05 +02:00
|
|
|
int32_t flags; /**< chunk flags */
|
2017-05-25 13:28:15 +02:00
|
|
|
};
|
2016-12-15 14:57:34 +01:00
|
|
|
|
2019-07-25 12:10:05 +02:00
|
|
|
/** Data for a buffer this stays constant for a buffer */
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_data {
|
2020-03-02 17:21:16 +01:00
|
|
|
uint32_t type; /**< memory type, one of enum spa_data_type, when
|
|
|
|
|
* allocating memory, the type contains a bitmask
|
2020-10-09 17:39:32 +02:00
|
|
|
* of allowed types. SPA_ID_INVALID is a special
|
|
|
|
|
* value for the allocator to indicate that the
|
|
|
|
|
* other side did not explicitly specify any
|
|
|
|
|
* supported data types. It should probably use
|
|
|
|
|
* a memory type that does not require special
|
|
|
|
|
* handling in addition to simple mmap/munmap. */
|
2018-08-27 15:03:11 +02:00
|
|
|
#define SPA_DATA_FLAG_NONE 0
|
2019-07-25 12:10:05 +02:00
|
|
|
#define SPA_DATA_FLAG_READABLE (1u<<0) /**< data is readable */
|
|
|
|
|
#define SPA_DATA_FLAG_WRITABLE (1u<<1) /**< data is writable */
|
|
|
|
|
#define SPA_DATA_FLAG_DYNAMIC (1u<<2) /**< data pointer can be changed */
|
|
|
|
|
#define SPA_DATA_FLAG_READWRITE (SPA_DATA_FLAG_READABLE|SPA_DATA_FLAG_WRITABLE)
|
2017-06-09 17:24:18 +02:00
|
|
|
uint32_t flags; /**< data flags */
|
2019-02-07 12:22:51 +01:00
|
|
|
int64_t fd; /**< optional fd for data */
|
2017-06-09 17:24:18 +02:00
|
|
|
uint32_t mapoffset; /**< offset to map fd at */
|
|
|
|
|
uint32_t maxsize; /**< max size of data */
|
|
|
|
|
void *data; /**< optional data pointer */
|
|
|
|
|
struct spa_chunk *chunk; /**< valid chunk of memory */
|
2017-05-25 13:28:15 +02:00
|
|
|
};
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-06-09 17:24:18 +02:00
|
|
|
/** A Buffer */
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_buffer {
|
2017-11-20 15:26:44 +01:00
|
|
|
uint32_t n_metas; /**< number of metadata */
|
|
|
|
|
uint32_t n_datas; /**< number of data members */
|
2019-01-07 17:57:03 +01:00
|
|
|
struct spa_meta *metas; /**< array of metadata */
|
|
|
|
|
struct spa_data *datas; /**< array of data members */
|
2016-06-28 12:21:56 +02:00
|
|
|
};
|
|
|
|
|
|
2017-06-09 17:24:18 +02:00
|
|
|
/** Find metadata in a buffer */
|
2018-07-09 12:04:23 +02:00
|
|
|
static inline struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
|
2016-10-04 19:37:44 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
uint32_t i;
|
2016-10-04 19:37:44 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
for (i = 0; i < b->n_metas; i++)
|
|
|
|
|
if (b->metas[i].type == type)
|
2018-07-09 12:04:23 +02:00
|
|
|
return &b->metas[i];
|
2016-08-03 15:59:17 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return NULL;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2018-07-09 12:04:23 +02:00
|
|
|
static inline void *spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
|
|
|
|
|
{
|
|
|
|
|
struct spa_meta *m;
|
|
|
|
|
if ((m = spa_buffer_find_meta(b, type)) && m->size >= size)
|
|
|
|
|
return m->data;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-21 14:03:07 +10:00
|
|
|
/**
|
|
|
|
|
* \}
|
|
|
|
|
*/
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
} /* extern "C" */
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#endif /* SPA_BUFFER_H */
|