buffer.h
Go to the documentation of this file.
/* Simple Plugin API
* Copyright © 2018 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SPA_BUFFER_H
#define SPA_BUFFER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
#include <spa/buffer/meta.h>
enum spa_data_type {
SPA_DATA_Invalid,
SPA_DATA_MemPtr,
SPA_DATA_MemFd,
SPA_DATA_DmaBuf,
SPA_DATA_MemId,
_SPA_DATA_LAST,
};
struct spa_chunk {
uint32_t offset;
uint32_t size;
int32_t stride;
#define SPA_CHUNK_FLAG_NONE 0
#define SPA_CHUNK_FLAG_CORRUPTED (1u<<0)
int32_t flags;
};
struct spa_data {
uint32_t type;
#define SPA_DATA_FLAG_NONE 0
#define SPA_DATA_FLAG_READABLE (1u<<0)
#define SPA_DATA_FLAG_WRITABLE (1u<<1)
#define SPA_DATA_FLAG_DYNAMIC (1u<<2)
#define SPA_DATA_FLAG_READWRITE (SPA_DATA_FLAG_READABLE|SPA_DATA_FLAG_WRITABLE)
uint32_t flags;
int64_t fd;
uint32_t mapoffset;
uint32_t maxsize;
void *data;
struct spa_chunk *chunk;
};
struct spa_buffer {
uint32_t n_metas;
uint32_t n_datas;
struct spa_meta *metas;
struct spa_data *datas;
};
static inline struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
{
uint32_t i;
for (i = 0; i < b->n_metas; i++)
if (b->metas[i].type == type)
return &b->metas[i];
return NULL;
}
static inline void *spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
{
struct spa_meta *m;
if ((m = spa_buffer_find_meta(b, type)) && m->size >= size)
return m->data;
return NULL;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#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:124
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:113
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:105
spa_buffer::n_metas
uint32_t n_metas
number of metadata
Definition: buffer.h:106
spa_buffer::metas
struct spa_meta * metas
array of metadata
Definition: buffer.h:108
spa_buffer::datas
struct spa_data * datas
array of data members
Definition: buffer.h:109
spa_buffer::n_datas
uint32_t n_datas
number of data members
Definition: buffer.h:107
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:73
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:77
spa_data::chunk
struct spa_chunk * chunk
valid chunk of memory
Definition: buffer.h:101
spa_data::fd
int64_t fd
optional fd for data
Definition: buffer.h:97
spa_data::mapoffset
uint32_t mapoffset
offset to map fd at
Definition: buffer.h:98
spa_data::flags
uint32_t flags
data flags
Definition: buffer.h:96
spa_data::data
void * data
optional data pointer
Definition: buffer.h:100
spa_data::maxsize
uint32_t maxsize
max size of data
Definition: buffer.h:99
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:78
spa_meta
A metadata element.
Definition: meta.h:66
spa_meta::size
uint32_t size
size of metadata
Definition: meta.h:68
spa_meta::type
uint32_t type
metadata type, one of enum spa_meta_type
Definition: meta.h:67
spa_meta::data
void * data
pointer to metadata
Definition: meta.h:69