PipeWire: buffer.h Source File

PipeWire 0.3.34

buffer/buffer.h
Go to the documentation of this file.
1 /* Simple Plugin API
2 * Copyright © 2018 Wim Taymans
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef SPA_BUFFER_H
25 #define SPA_BUFFER_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include <spa/utils/defs.h>
32 #include <spa/buffer/meta.h>
33
45 enum spa_data_type {
46 SPA_DATA_Invalid,
47 SPA_DATA_MemPtr,
49 SPA_DATA_MemFd,
50 SPA_DATA_DmaBuf,
51 SPA_DATA_MemId,
53 _SPA_DATA_LAST,
54 };
55
57 struct spa_chunk {
58 uint32_t offset;
61 uint32_t size;
63 int32_t stride;
64 #define SPA_CHUNK_FLAG_NONE 0
65 #define SPA_CHUNK_FLAG_CORRUPTED (1u<<0)
66 int32_t flags;
67 };
68
70 struct spa_data {
71 uint32_t type;
79 #define SPA_DATA_FLAG_NONE 0
80 #define SPA_DATA_FLAG_READABLE (1u<<0)
81 #define SPA_DATA_FLAG_WRITABLE (1u<<1)
82 #define SPA_DATA_FLAG_DYNAMIC (1u<<2)
83 #define SPA_DATA_FLAG_READWRITE (SPA_DATA_FLAG_READABLE|SPA_DATA_FLAG_WRITABLE)
84 uint32_t flags;
85 int64_t fd;
86 uint32_t mapoffset;
87 uint32_t maxsize;
88 void *data;
89 struct spa_chunk *chunk;
90 };
91
93 struct spa_buffer {
94 uint32_t n_metas;
95 uint32_t n_datas;
96 struct spa_meta *metas;
97 struct spa_data *datas;
98 };
99
101 /* static */ inline struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
102 {
103 uint32_t i;
104
105 for (i = 0; i < b->n_metas; i++)
106 if (b->metas[i].type == type)
107 return &b->metas[i];
108
109 return NULL;
110 }
111
112 /* static */ inline void *spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
113 {
114 struct spa_meta *m;
115 if ((m = spa_buffer_find_meta(b, type)) && m->size >= size)
116 return m->data;
117 return NULL;
118 }
119
124 #ifdef __cplusplus
125 } /* extern "C" */
126 #endif
127
128 #endif /* SPA_BUFFER_H */
defs.h
spa_buffer_find_meta
struct spa_meta * spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
Find metadata in a buffer.
Definition: buffer/buffer.h:101
spa_buffer_find_meta_data
void * spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
Definition: buffer/buffer.h:112
spa_data_type
spa_data_type
Definition: buffer/buffer.h:45
_SPA_DATA_LAST
@ _SPA_DATA_LAST
not part of ABI
Definition: buffer/buffer.h:53
SPA_DATA_MemFd
@ SPA_DATA_MemFd
generic fd, mmap to get to memory
Definition: buffer/buffer.h:49
SPA_DATA_MemPtr
@ SPA_DATA_MemPtr
pointer to memory, the data field in struct spa_data is set.
Definition: buffer/buffer.h:47
SPA_DATA_Invalid
@ SPA_DATA_Invalid
Definition: buffer/buffer.h:46
SPA_DATA_MemId
@ SPA_DATA_MemId
memory is identified with an id
Definition: buffer/buffer.h:51
SPA_DATA_DmaBuf
@ SPA_DATA_DmaBuf
fd to dmabuf memory
Definition: buffer/buffer.h:50
meta.h
spa_buffer
A Buffer.
Definition: buffer/buffer.h:93
spa_buffer::n_metas
uint32_t n_metas
number of metadata
Definition: buffer/buffer.h:94
spa_buffer::metas
struct spa_meta * metas
array of metadata
Definition: buffer/buffer.h:96
spa_buffer::datas
struct spa_data * datas
array of data members
Definition: buffer/buffer.h:97
spa_buffer::n_datas
uint32_t n_datas
number of data members
Definition: buffer/buffer.h:95
spa_chunk
Chunk of memory, can change for each buffer.
Definition: buffer/buffer.h:57
spa_chunk::stride
int32_t stride
stride of valid data
Definition: buffer/buffer.h:63
spa_chunk::size
uint32_t size
size of valid data.
Definition: buffer/buffer.h:61
spa_chunk::flags
int32_t flags
chunk flags
Definition: buffer/buffer.h:66
spa_chunk::offset
uint32_t offset
offset of valid data.
Definition: buffer/buffer.h:58
spa_data
Data for a buffer this stays constant for a buffer.
Definition: buffer/buffer.h:70
spa_data::chunk
struct spa_chunk * chunk
valid chunk of memory
Definition: buffer/buffer.h:89
spa_data::fd
int64_t fd
optional fd for data
Definition: buffer/buffer.h:85
spa_data::mapoffset
uint32_t mapoffset
offset to map fd at
Definition: buffer/buffer.h:86
spa_data::flags
uint32_t flags
data flags
Definition: buffer/buffer.h:84
spa_data::data
void * data
optional data pointer
Definition: buffer/buffer.h:88
spa_data::maxsize
uint32_t maxsize
max size of data
Definition: buffer/buffer.h:87
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/buffer.h:71
spa_meta
A metadata element.
Definition: meta.h:61
spa_meta::size
uint32_t size
size of metadata
Definition: meta.h:63
spa_meta::type
uint32_t type
metadata type, one of enum spa_meta_type
Definition: meta.h:62
spa_meta::data
void * data
pointer to metadata
Definition: meta.h:64