PipeWire 1.0.5

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
26 enum spa_data_type {
27 SPA_DATA_Invalid,
28 SPA_DATA_MemPtr,
30 SPA_DATA_MemFd,
31 SPA_DATA_DmaBuf,
32 SPA_DATA_MemId,
34 _SPA_DATA_LAST,
35};
36
38 struct spa_chunk {
39 uint32_t offset;
42 uint32_t size;
44 int32_t stride;
45#define SPA_CHUNK_FLAG_NONE 0
46#define SPA_CHUNK_FLAG_CORRUPTED (1u<<0)
47#define SPA_CHUNK_FLAG_EMPTY (1u<<1)
50 int32_t flags;
51};
52
54 struct spa_data {
55 uint32_t type;
63#define SPA_DATA_FLAG_NONE 0
64#define SPA_DATA_FLAG_READABLE (1u<<0)
65#define SPA_DATA_FLAG_WRITABLE (1u<<1)
66#define SPA_DATA_FLAG_DYNAMIC (1u<<2)
67#define SPA_DATA_FLAG_READWRITE (SPA_DATA_FLAG_READABLE|SPA_DATA_FLAG_WRITABLE)
68#define SPA_DATA_FLAG_MAPPABLE (1u<<3)
71 uint32_t flags;
72 int64_t fd;
73 uint32_t mapoffset;
74 uint32_t maxsize;
75 void *data;
76 struct spa_chunk *chunk;
77};
78
80 struct spa_buffer {
81 uint32_t n_metas;
82 uint32_t n_datas;
83 struct spa_meta *metas;
84 struct spa_data *datas;
85};
86
88 static inline struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
89{
90 uint32_t i;
91
92 for (i = 0; i < b->n_metas; i++)
93 if (b->metas[i].type == type)
94 return &b->metas[i];
95
96 return NULL;
97}
98
99 static inline void *spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
100{
101 struct spa_meta *m;
102 if ((m = spa_buffer_find_meta(b, type)) && m->size >= size)
103 return m->data;
104 return NULL;
105}
106
111#ifdef __cplusplus
112} /* extern "C" */
113#endif
114
115#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:113
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:102
spa_data_type
spa_data_type
Definition buffer.h:31
_SPA_DATA_LAST
@ _SPA_DATA_LAST
not part of ABI
Definition buffer.h:39
SPA_DATA_MemFd
@ SPA_DATA_MemFd
generic fd, mmap to get to memory
Definition buffer.h:35
SPA_DATA_MemPtr
@ SPA_DATA_MemPtr
pointer to memory, the data field in struct spa_data is set.
Definition buffer.h:33
SPA_DATA_Invalid
@ SPA_DATA_Invalid
Definition buffer.h:32
SPA_DATA_MemId
@ SPA_DATA_MemId
memory is identified with an id
Definition buffer.h:37
SPA_DATA_DmaBuf
@ SPA_DATA_DmaBuf
fd to dmabuf memory
Definition buffer.h:36
meta.h
spa/buffer/meta.h
spa_buffer
A Buffer.
Definition buffer.h:94
spa_buffer::n_metas
uint32_t n_metas
number of metadata
Definition buffer.h:95
spa_buffer::metas
struct spa_meta * metas
array of metadata
Definition buffer.h:97
spa_buffer::datas
struct spa_data * datas
array of data members
Definition buffer.h:98
spa_buffer::n_datas
uint32_t n_datas
number of data members
Definition buffer.h:96
spa_chunk
Chunk of memory, can change for each buffer.
Definition buffer.h:43
spa_chunk::stride
int32_t stride
stride of valid data
Definition buffer.h:49
spa_chunk::size
uint32_t size
size of valid data.
Definition buffer.h:47
spa_chunk::flags
int32_t flags
chunk flags
Definition buffer.h:58
spa_chunk::offset
uint32_t offset
offset of valid data.
Definition buffer.h:44
spa_data
Data for a buffer this stays constant for a buffer.
Definition buffer.h:62
spa_data::chunk
struct spa_chunk * chunk
valid chunk of memory
Definition buffer.h:90
spa_data::fd
int64_t fd
optional fd for data
Definition buffer.h:86
spa_data::mapoffset
uint32_t mapoffset
offset to map fd at
Definition buffer.h:87
spa_data::flags
uint32_t flags
data flags
Definition buffer.h:85
spa_data::data
void * data
optional data pointer
Definition buffer.h:89
spa_data::maxsize
uint32_t maxsize
max size of data
Definition buffer.h:88
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:63
spa_meta
A metadata element.
Definition meta.h:47
spa_meta::size
uint32_t size
size of metadata
Definition meta.h:49
spa_meta::type
uint32_t type
metadata type, one of enum spa_meta_type
Definition meta.h:48
spa_meta::data
void * data
pointer to metadata
Definition meta.h:50