PipeWire  0.3.45
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 {
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 */
spa/utils/defs.h
static void * spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
Definition: buffer.h:124
static struct spa_meta * spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
Find metadata in a buffer.
Definition: buffer.h:113
spa_data_type
Definition: buffer.h:50
@ _SPA_DATA_LAST
not part of ABI
Definition: buffer.h:58
@ SPA_DATA_MemFd
generic fd, mmap to get to memory
Definition: buffer.h:54
@ SPA_DATA_MemPtr
pointer to memory, the data field in struct spa_data is set.
Definition: buffer.h:52
@ SPA_DATA_Invalid
Definition: buffer.h:51
@ SPA_DATA_MemId
memory is identified with an id
Definition: buffer.h:56
@ SPA_DATA_DmaBuf
fd to dmabuf memory
Definition: buffer.h:55
spa/buffer/meta.h
A Buffer.
Definition: buffer.h:105
uint32_t n_metas
number of metadata
Definition: buffer.h:106
struct spa_meta * metas
array of metadata
Definition: buffer.h:108
struct spa_data * datas
array of data members
Definition: buffer.h:109
uint32_t n_datas
number of data members
Definition: buffer.h:107
Chunk of memory, can change for each buffer.
Definition: buffer.h:62
int32_t stride
stride of valid data
Definition: buffer.h:68
uint32_t size
size of valid data.
Definition: buffer.h:66
int32_t flags
chunk flags
Definition: buffer.h:73
uint32_t offset
offset of valid data.
Definition: buffer.h:63
Data for a buffer this stays constant for a buffer.
Definition: buffer.h:77
struct spa_chunk * chunk
valid chunk of memory
Definition: buffer.h:101
int64_t fd
optional fd for data
Definition: buffer.h:97
uint32_t mapoffset
offset to map fd at
Definition: buffer.h:98
uint32_t flags
data flags
Definition: buffer.h:96
void * data
optional data pointer
Definition: buffer.h:100
uint32_t maxsize
max size of data
Definition: buffer.h:99
uint32_t type
memory type, one of enum spa_data_type, when allocating memory, the type contains a bitmask of allowe...
Definition: buffer.h:78
A metadata element.
Definition: meta.h:66
uint32_t size
size of metadata
Definition: meta.h:68
uint32_t type
metadata type, one of enum spa_meta_type
Definition: meta.h:67
void * data
pointer to metadata
Definition: meta.h:69