PipeWire  0.3.63
buffer.h
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 {
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 #define SPA_CHUNK_FLAG_EMPTY (1u<<1)
69  int32_t flags;
70 };
71 
73 struct 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 
96 struct spa_buffer {
97  uint32_t n_metas;
98  uint32_t n_datas;
99  struct spa_meta *metas;
100  struct spa_data *datas;
101 };
104 static inline struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
105 {
106  uint32_t i;
108  for (i = 0; i < b->n_metas; i++)
109  if (b->metas[i].type == type)
110  return &b->metas[i];
112  return NULL;
113 }
115 static 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
131 #endif /* SPA_BUFFER_H */
struct spa_meta * metas
array of metadata
Definition: buffer.h:114
static struct spa_meta * spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
Find metadata in a buffer.
Definition: buffer.h:119
int32_t stride
stride of valid data
Definition: buffer.h:68
uint32_t offset
offset of valid data.
Definition: buffer.h:63
not part of ABI
Definition: buffer.h:58
fd to dmabuf memory
Definition: buffer.h:55
pointer to memory, the data field in struct spa_data is set.
Definition: buffer.h:52
spa_data_type
Definition: buffer.h:50
A Buffer.
Definition: buffer.h:111
uint32_t type
metadata type, one of enum spa_meta_type
Definition: meta.h:68
Data for a buffer this stays constant for a buffer.
Definition: buffer.h:83
Definition: buffer.h:51
generic fd, mmap to get to memory
Definition: buffer.h:54
uint32_t size
size of valid data.
Definition: buffer.h:66
int32_t flags
chunk flags
Definition: buffer.h:79
Chunk of memory, can change for each buffer.
Definition: buffer.h:62
uint32_t n_metas
number of metadata
Definition: buffer.h:112
uint32_t size
size of metadata
Definition: meta.h:69
memory is identified with an id
Definition: buffer.h:56
static void * spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
Definition: buffer.h:130
void * data
pointer to metadata
Definition: meta.h:70
A metadata element.
Definition: meta.h:67