PipeWire 1.4.10

Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_BUFFER_H
6#define SPA_BUFFER_H
7
8#ifdef __cplusplus
9 extern "C" {
10#endif
11
12#include <spa/utils/defs.h>
13#include <spa/buffer/meta.h>
14
15#ifndef SPA_API_BUFFER
16 #ifdef SPA_API_IMPL
17 #define SPA_API_BUFFER SPA_API_IMPL
18 #else
19 #define SPA_API_BUFFER static inline
20 #endif
21#endif
22
28
33
34 enum spa_data_type {
35 SPA_DATA_Invalid,
36 SPA_DATA_MemPtr,
38 SPA_DATA_MemFd,
39 SPA_DATA_DmaBuf,
41 * normally be handled with DMABUF apis. */
42 SPA_DATA_MemId,
45 SPA_DATA_SyncObj,
47
48 _SPA_DATA_LAST,
49};
50
52 struct spa_chunk {
53 uint32_t offset;
56 uint32_t size;
57
58 int32_t stride;
59#define SPA_CHUNK_FLAG_NONE 0
60#define SPA_CHUNK_FLAG_CORRUPTED (1u<<0)
61#define SPA_CHUNK_FLAG_EMPTY (1u<<1)
64 int32_t flags;
65};
66
68 struct spa_data {
69 uint32_t type;
76
77#define SPA_DATA_FLAG_NONE 0
78#define SPA_DATA_FLAG_READABLE (1u<<0)
79#define SPA_DATA_FLAG_WRITABLE (1u<<1)
80#define SPA_DATA_FLAG_DYNAMIC (1u<<2)
81#define SPA_DATA_FLAG_READWRITE (SPA_DATA_FLAG_READABLE|SPA_DATA_FLAG_WRITABLE)
82#define SPA_DATA_FLAG_MAPPABLE (1u<<3)
85 uint32_t flags;
86 int64_t fd;
87 uint32_t mapoffset;
88 uint32_t maxsize;
89 void *data;
90 struct spa_chunk *chunk;
91};
92
94 struct spa_buffer {
95 uint32_t n_metas;
96 uint32_t n_datas;
97 struct spa_meta *metas;
98 struct spa_data *datas;
99};
100
102 SPA_API_BUFFER struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
103{
104 uint32_t i;
105
106 for (i = 0; i < b->n_metas; i++)
107 if (b->metas[i].type == type)
108 return &b->metas[i];
109
110 return NULL;
111}
112
113 SPA_API_BUFFER void *spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
114{
115 struct spa_meta *m;
116 if ((m = spa_buffer_find_meta(b, type)) && m->size >= size)
117 return m->data;
118 return NULL;
119}
120
124
125#ifdef __cplusplus
126} /* extern "C" */
127#endif
128
129#endif /* SPA_BUFFER_H */
SPA_API_BUFFER
#define SPA_API_BUFFER
Definition buffer.h:26
defs.h
spa/utils/defs.h
spa_buffer_find_meta
SPA_API_BUFFER struct spa_meta * spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
Find metadata in a buffer.
Definition buffer.h:118
spa_buffer_find_meta_data
SPA_API_BUFFER void * spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
Definition buffer.h:129
spa_data_type
spa_data_type
Definition buffer.h:41
_SPA_DATA_LAST
@ _SPA_DATA_LAST
not part of ABI
Definition buffer.h:55
SPA_DATA_MemFd
@ SPA_DATA_MemFd
memfd, mmap to get to memory.
Definition buffer.h:45
SPA_DATA_MemPtr
@ SPA_DATA_MemPtr
pointer to memory, the data field in struct spa_data is set.
Definition buffer.h:43
SPA_DATA_SyncObj
@ SPA_DATA_SyncObj
a syncobj, usually requires a spa_meta_sync_timeline metadata with timeline points.
Definition buffer.h:52
SPA_DATA_Invalid
@ SPA_DATA_Invalid
Definition buffer.h:42
SPA_DATA_MemId
@ SPA_DATA_MemId
memory is identified with an id.
Definition buffer.h:49
SPA_DATA_DmaBuf
@ SPA_DATA_DmaBuf
fd to dmabuf memory.
Definition buffer.h:46
meta.h
spa/buffer/meta.h
spa_buffer
A Buffer.
Definition buffer.h:110
spa_buffer::n_metas
uint32_t n_metas
number of metadata
Definition buffer.h:111
spa_buffer::metas
struct spa_meta * metas
array of metadata
Definition buffer.h:113
spa_buffer::datas
struct spa_data * datas
array of data members
Definition buffer.h:114
spa_buffer::n_datas
uint32_t n_datas
number of data members
Definition buffer.h:112
spa_chunk
Chunk of memory, can change for each buffer.
Definition buffer.h:59
spa_chunk::stride
int32_t stride
stride of valid data
Definition buffer.h:65
spa_chunk::size
uint32_t size
size of valid data.
Definition buffer.h:63
spa_chunk::flags
int32_t flags
chunk flags
Definition buffer.h:74
spa_chunk::offset
uint32_t offset
offset of valid data.
Definition buffer.h:60
spa_data
Data for a buffer this stays constant for a buffer.
Definition buffer.h:78
spa_data::chunk
struct spa_chunk * chunk
valid chunk of memory
Definition buffer.h:106
spa_data::fd
int64_t fd
optional fd for data
Definition buffer.h:102
spa_data::mapoffset
uint32_t mapoffset
offset to map fd at, this is page aligned
Definition buffer.h:103
spa_data::flags
uint32_t flags
data flags
Definition buffer.h:101
spa_data::maxsize
uint32_t maxsize
max size of data
Definition buffer.h:104
spa_data::type
uint32_t type
memory type, one of enum spa_data_type, when allocating memory, the type contains a bitmask of allowe...
Definition buffer.h:79
spa_meta
A metadata element.
Definition meta.h:58
spa_meta::size
uint32_t size
size of metadata
Definition meta.h:60
spa_meta::type
uint32_t type
metadata type, one of enum spa_meta_type
Definition meta.h:59
spa_meta::data
void * data
pointer to metadata
Definition meta.h:61