PipeWire 0.3.65
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
28extern "C" {
29#endif
30
31#include <spa/utils/defs.h>
32#include <spa/buffer/meta.h>
33
45enum spa_data_type {
54};
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;
104static inline struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
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];
112 return NULL;
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 */
spa/utils/defs.h
static void * spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
Definition: buffer/buffer.h:128
static struct spa_meta * spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
Find metadata in a buffer.
Definition: buffer/buffer.h:117
spa_data_type
Definition: buffer/buffer.h:50
@ _SPA_DATA_LAST
not part of ABI
Definition: buffer/buffer.h:58
@ SPA_DATA_MemFd
generic fd, mmap to get to memory
Definition: buffer/buffer.h:54
@ SPA_DATA_MemPtr
pointer to memory, the data field in struct spa_data is set.
Definition: buffer/buffer.h:52
@ SPA_DATA_Invalid
Definition: buffer/buffer.h:51
@ SPA_DATA_MemId
memory is identified with an id
Definition: buffer/buffer.h:56
@ SPA_DATA_DmaBuf
fd to dmabuf memory
Definition: buffer/buffer.h:55
spa/buffer/meta.h
A Buffer.
Definition: buffer/buffer.h:109
uint32_t n_metas
number of metadata
Definition: buffer/buffer.h:110
struct spa_meta * metas
array of metadata
Definition: buffer/buffer.h:112
struct spa_data * datas
array of data members
Definition: buffer/buffer.h:113
uint32_t n_datas
number of data members
Definition: buffer/buffer.h:111
Chunk of memory, can change for each buffer.
Definition: buffer/buffer.h:62
int32_t stride
stride of valid data
Definition: buffer/buffer.h:68
uint32_t size
size of valid data.
Definition: buffer/buffer.h:66
int32_t flags
chunk flags
Definition: buffer/buffer.h:77
uint32_t offset
offset of valid data.
Definition: buffer/buffer.h:63
Data for a buffer this stays constant for a buffer.
Definition: buffer/buffer.h:81
struct spa_chunk * chunk
valid chunk of memory
Definition: buffer/buffer.h:105
int64_t fd
optional fd for data
Definition: buffer/buffer.h:101
uint32_t mapoffset
offset to map fd at
Definition: buffer/buffer.h:102
uint32_t flags
data flags
Definition: buffer/buffer.h:100
void * data
optional data pointer
Definition: buffer/buffer.h:104
uint32_t maxsize
max size of data
Definition: buffer/buffer.h:103
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:82
A metadata element.
Definition: meta.h:67
uint32_t size
size of metadata
Definition: meta.h:69
uint32_t type
metadata type, one of enum spa_meta_type
Definition: meta.h:68
void * data
pointer to metadata
Definition: meta.h:70