PipeWire: spa/buffer/buffer.h Source File

PipeWire 0.3.64

Loading...
Searching...
No Matches
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
28extern "C" {
29#endif
30
31#include <spa/utils/defs.h>
32#include <spa/buffer/meta.h>
33
45enum 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
57struct 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#define SPA_CHUNK_FLAG_EMPTY (1u<<1)
69 int32_t flags;
70};
71
73struct spa_data {
74 uint32_t type;
82#define SPA_DATA_FLAG_NONE 0
83#define SPA_DATA_FLAG_READABLE (1u<<0)
84#define SPA_DATA_FLAG_WRITABLE (1u<<1)
85#define SPA_DATA_FLAG_DYNAMIC (1u<<2)
86#define SPA_DATA_FLAG_READWRITE (SPA_DATA_FLAG_READABLE|SPA_DATA_FLAG_WRITABLE)
87 uint32_t flags;
88 int64_t fd;
89 uint32_t mapoffset;
90 uint32_t maxsize;
91 void *data;
92 struct spa_chunk *chunk;
93};
94
96struct spa_buffer {
97 uint32_t n_metas;
98 uint32_t n_datas;
99 struct spa_meta *metas;
100 struct spa_data *datas;
101};
102
104 static inline struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
105{
106 uint32_t i;
107
108 for (i = 0; i < b->n_metas; i++)
109 if (b->metas[i].type == type)
110 return &b->metas[i];
111
112 return NULL;
113}
114
115static inline void *spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
116{
117 struct spa_meta *m;
118 if ((m = spa_buffer_find_meta(b, type)) && m->size >= size)
119 return m->data;
120 return NULL;
121}
122
127#ifdef __cplusplus
128} /* extern "C" */
129#endif
130
131#endif /* SPA_BUFFER_H */
defs.h
spa/utils/defs.h
spa_buffer_find_meta_data
static void * spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
Definition: buffer.h:128
spa_buffer_find_meta
static struct spa_meta * spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
Find metadata in a buffer.
Definition: buffer.h:117
spa_data_type
spa_data_type
Definition: buffer.h:50
_SPA_DATA_LAST
@ _SPA_DATA_LAST
not part of ABI
Definition: buffer.h:58
SPA_DATA_MemFd
@ SPA_DATA_MemFd
generic fd, mmap to get to memory
Definition: buffer.h:54
SPA_DATA_MemPtr
@ SPA_DATA_MemPtr
pointer to memory, the data field in struct spa_data is set.
Definition: buffer.h:52
SPA_DATA_Invalid
@ SPA_DATA_Invalid
Definition: buffer.h:51
SPA_DATA_MemId
@ SPA_DATA_MemId
memory is identified with an id
Definition: buffer.h:56
SPA_DATA_DmaBuf
@ SPA_DATA_DmaBuf
fd to dmabuf memory
Definition: buffer.h:55
meta.h
spa/buffer/meta.h
spa_buffer
A Buffer.
Definition: buffer.h:109
spa_buffer::n_metas
uint32_t n_metas
number of metadata
Definition: buffer.h:110
spa_buffer::metas
struct spa_meta * metas
array of metadata
Definition: buffer.h:112
spa_buffer::datas
struct spa_data * datas
array of data members
Definition: buffer.h:113
spa_buffer::n_datas
uint32_t n_datas
number of data members
Definition: buffer.h:111
spa_chunk
Chunk of memory, can change for each buffer.
Definition: buffer.h:62
spa_chunk::stride
int32_t stride
stride of valid data
Definition: buffer.h:68
spa_chunk::size
uint32_t size
size of valid data.
Definition: buffer.h:66
spa_chunk::flags
int32_t flags
chunk flags
Definition: buffer.h:77
spa_chunk::offset
uint32_t offset
offset of valid data.
Definition: buffer.h:63
spa_data
Data for a buffer this stays constant for a buffer.
Definition: buffer.h:81
spa_data::chunk
struct spa_chunk * chunk
valid chunk of memory
Definition: buffer.h:105
spa_data::fd
int64_t fd
optional fd for data
Definition: buffer.h:101
spa_data::mapoffset
uint32_t mapoffset
offset to map fd at
Definition: buffer.h:102
spa_data::flags
uint32_t flags
data flags
Definition: buffer.h:100
spa_data::data
void * data
optional data pointer
Definition: buffer.h:104
spa_data::maxsize
uint32_t maxsize
max size of data
Definition: buffer.h:103
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:82
spa_meta
A metadata element.
Definition: meta.h:67
spa_meta::size
uint32_t size
size of metadata
Definition: meta.h:69
spa_meta::type
uint32_t type
metadata type, one of enum spa_meta_type
Definition: meta.h:68
spa_meta::data
void * data
pointer to metadata
Definition: meta.h:70