Commit a9ba3535 authored by Wim Taymans's avatar Wim Taymans
Browse files

another mem test

parent 5e8a3afe
......@@ -278,7 +278,7 @@ typedef struct {
SpaDirection direction;
uint32_t port_id;
uint32_t mem_id;
SpaDataType type;
SpaMemType type;
int memfd;
uint32_t flags;
off_t offset;
......
......@@ -30,7 +30,7 @@ pinos_serialize_buffer_get_size (const SpaBuffer *buffer)
size = sizeof (SpaBuffer);
for (i = 0; i < buffer->n_metas; i++)
size += sizeof (SpaMeta) + buffer->metas[i].size;
size += sizeof (SpaMeta) + SPA_META_SIZE (&buffer->metas[i]);
for (i = 0; i < buffer->n_datas; i++)
size += sizeof (SpaData);
return size;
......@@ -59,9 +59,9 @@ pinos_serialize_buffer_serialize (void *dest, const SpaBuffer *buffer)
for (i = 0; i < tb->n_metas; i++) {
memcpy (&mp[i], &buffer->metas[i], sizeof (SpaMeta));
memcpy (p, mp[i].data, mp[i].size);
mp[i].data = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tb));
p += mp[i].size;
memcpy (p, SPA_META_PTR (&mp[i]), SPA_META_SIZE (&mp[i]));
SPA_META_PTR (&mp[i]) = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tb));
p += SPA_META_SIZE (&mp[i]);
}
for (i = 0; i < tb->n_datas; i++)
memcpy (&dp[i], &buffer->datas[i], sizeof (SpaData));
......@@ -80,8 +80,8 @@ pinos_serialize_buffer_deserialize (void *src, off_t offset)
b->metas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta);
for (i = 0; i < b->n_metas; i++) {
SpaMeta *m = &b->metas[i];
if (m->data)
m->data = SPA_MEMBER (b, SPA_PTR_TO_INT (m->data), void);
if (SPA_META_PTR (m))
SPA_META_PTR (m) = SPA_MEMBER (b, SPA_PTR_TO_INT (SPA_META_PTR (m)), void);
}
if (b->datas)
b->datas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->datas), SpaData);
......
......@@ -463,7 +463,7 @@ on_rtsocket_condition (SpaSource *source,
if ((bid = find_buffer (stream, input->buffer_id))) {
for (i = 0; i < bid->buf->n_datas; i++) {
bid->buf->datas[i].size = bid->datas[i].size;
bid->buf->datas[i].mem.size = bid->datas[i].mem.size;
}
pinos_signal_emit (&stream->new_buffer, stream, bid->id);
}
......@@ -702,7 +702,7 @@ stream_dispatch_func (void *object,
size = sizeof (SpaBuffer);
m = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta);
for (i = 0; i < b->n_metas; i++)
size += sizeof (SpaMeta) + m[i].size;
size += sizeof (SpaMeta) + m[i].mem.size;
for (i = 0; i < b->n_datas; i++)
size += sizeof (SpaData);
......@@ -727,32 +727,32 @@ stream_dispatch_func (void *object,
for (j = 0; j < b->n_metas; j++) {
SpaMeta *m = &b->metas[j];
if (m->data)
m->data = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (m->data), void);
if (m->mem.ptr)
m->mem.ptr = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (m->mem.ptr), void);
}
for (j = 0; j < b->n_datas; j++) {
SpaData *d = &b->datas[j];
switch (d->type) {
case SPA_DATA_TYPE_ID:
switch (SPA_DATA_MEM_TYPE (d)) {
case SPA_MEM_TYPE_ID:
{
MemId *bmid = find_mem (stream, SPA_PTR_TO_UINT32 (d->data));
d->type = SPA_DATA_TYPE_MEMFD;
d->data = NULL;
d->fd = bmid->fd;
MemId *bmid = find_mem (stream, SPA_PTR_TO_UINT32 (d->mem.mem->ptr));
SPA_DATA_MEM_TYPE (d) = SPA_MEM_TYPE_MEMFD;
SPA_DATA_MEM_PTR (d) = NULL;
SPA_DATA_MEM_FD (d) = bmid->fd;
pinos_log_debug (" data %d %u -> fd %d", j, bmid->id, bmid->fd);
break;
}
case SPA_DATA_TYPE_MEMPTR:
case SPA_MEM_TYPE_MEMPTR:
{
d->data = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (d->data), void);
d->fd = -1;
pinos_log_debug (" data %d %u -> mem %p", j, bid->id, d->data);
SPA_DATA_MEM_PTR (d) = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (d->mem.mem->ptr), void);
SPA_DATA_MEM_FD (d) = -1;
pinos_log_debug (" data %d %u -> mem %p", j, bid->id, SPA_DATA_MEM_PTR (d));
break;
}
default:
pinos_log_warn ("unknown buffer data type %d", d->type);
pinos_log_warn ("unknown buffer data type %d", SPA_DATA_MEM_TYPE (d));
break;
}
}
......@@ -1097,7 +1097,7 @@ pinos_stream_send_buffer (PinosStream *stream,
bid->used = true;
for (i = 0; i < bid->buf->n_datas; i++) {
bid->datas[i].size = bid->buf->datas[i].size;
SPA_DATA_CHUNK_SIZE (&bid->datas[i]) = SPA_DATA_CHUNK_SIZE (&bid->buf->datas[i]);
}
impl->trans->outputs[0].buffer_id = id;
impl->trans->outputs[0].status = SPA_RESULT_OK;
......
......@@ -388,7 +388,7 @@ on_add_buffer (PinosListener *listener,
switch (m->type) {
case SPA_META_TYPE_HEADER:
data.header = m->data;
data.header = m->mem.ptr;
break;
default:
break;
......@@ -398,18 +398,18 @@ on_add_buffer (PinosListener *listener,
SpaData *d = &b->datas[i];
GstMemory *gmem = NULL;
switch (d->type) {
case SPA_DATA_TYPE_MEMFD:
case SPA_DATA_TYPE_DMABUF:
switch (SPA_DATA_MEM_TYPE (d)) {
case SPA_MEM_TYPE_MEMFD:
case SPA_MEM_TYPE_DMABUF:
{
gmem = gst_fd_allocator_alloc (pinossink->allocator, dup (d->fd),
d->maxsize, GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (gmem, d->offset, d->size);
gmem = gst_fd_allocator_alloc (pinossink->allocator, dup (SPA_DATA_MEM_FD (d)),
SPA_DATA_MEM_SIZE (d), GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (gmem, SPA_DATA_CHUNK_OFFSET (d), SPA_DATA_CHUNK_SIZE (d));
break;
}
case SPA_DATA_TYPE_MEMPTR:
gmem = gst_memory_new_wrapped (0, d->data, d->maxsize, d->offset,
d->size, NULL, NULL);
case SPA_MEM_TYPE_MEMPTR:
gmem = gst_memory_new_wrapped (0, SPA_DATA_MEM_PTR (d), SPA_DATA_MEM_SIZE (d),
SPA_DATA_CHUNK_OFFSET (d), SPA_DATA_CHUNK_SIZE (d), NULL, NULL);
break;
default:
break;
......@@ -644,8 +644,8 @@ gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
for (i = 0; i < data->buf->n_datas; i++) {
SpaData *d = &data->buf->datas[i];
GstMemory *mem = gst_buffer_peek_memory (buffer, i);
d->offset = mem->offset;
d->size = mem->size;
d->chunk.chunk->offset = mem->offset;
d->chunk.chunk->size = mem->size;
}
gst_buffer_ref (buffer);
......
......@@ -402,7 +402,7 @@ on_add_buffer (PinosListener *listener,
switch (m->type) {
case SPA_META_TYPE_HEADER:
data.header = m->data;
data.header = m->mem.ptr;
break;
default:
break;
......@@ -412,18 +412,18 @@ on_add_buffer (PinosListener *listener,
SpaData *d = &b->datas[i];
GstMemory *gmem = NULL;
switch (d->type) {
case SPA_DATA_TYPE_MEMFD:
case SPA_DATA_TYPE_DMABUF:
switch (SPA_DATA_MEM_TYPE (d)) {
case SPA_MEM_TYPE_MEMFD:
case SPA_MEM_TYPE_DMABUF:
{
gmem = gst_fd_allocator_alloc (pinossrc->fd_allocator, dup (d->fd),
d->maxsize, GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (gmem, d->offset, d->size);
gmem = gst_fd_allocator_alloc (pinossrc->fd_allocator, dup (SPA_DATA_MEM_FD (d)),
SPA_DATA_MEM_SIZE (d), GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (gmem, SPA_DATA_CHUNK_OFFSET (d), SPA_DATA_CHUNK_SIZE (d));
break;
}
case SPA_DATA_TYPE_MEMPTR:
gmem = gst_memory_new_wrapped (0, d->data, d->maxsize, d->offset,
d->size, NULL, NULL);
case SPA_MEM_TYPE_MEMPTR:
gmem = gst_memory_new_wrapped (0, SPA_DATA_MEM_PTR (d), SPA_DATA_MEM_SIZE (d),
SPA_DATA_CHUNK_OFFSET (d), SPA_DATA_CHUNK_SIZE (d), NULL, NULL);
default:
break;
}
......@@ -488,8 +488,8 @@ on_new_buffer (PinosListener *listener,
for (i = 0; i < data->buf->n_datas; i++) {
SpaData *d = &data->buf->datas[i];
GstMemory *mem = gst_buffer_peek_memory (buf, i);
mem->offset = d->offset;
mem->size = d->size;
mem->offset = d->chunk.chunk->offset;
mem->size = d->chunk.chunk->size;
}
g_queue_push_tail (&pinossrc->queue, buf);
......
......@@ -653,33 +653,33 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
memcpy (&b->buffer.datas[j], d, sizeof (SpaData));
switch (d->type) {
case SPA_DATA_TYPE_DMABUF:
case SPA_DATA_TYPE_MEMFD:
switch (SPA_DATA_MEM_TYPE (d)) {
case SPA_MEM_TYPE_DMABUF:
case SPA_MEM_TYPE_MEMFD:
am.direction = direction;
am.port_id = port_id;
am.mem_id = n_mem;
am.type = d->type;
am.memfd = d->fd;
am.flags = d->flags;
am.offset = d->offset;
am.size = d->maxsize;
am.type = SPA_DATA_MEM_TYPE (d);
am.memfd = SPA_DATA_MEM_FD (d);
am.flags = SPA_DATA_MEM_FLAGS (d);
am.offset = SPA_DATA_MEM_OFFSET (d);
am.size = SPA_DATA_MEM_SIZE (d);
pinos_resource_send_message (this->resource,
PINOS_MESSAGE_ADD_MEM,
&am,
false);
b->buffer.datas[j].type = SPA_DATA_TYPE_ID;
b->buffer.datas[j].data = SPA_UINT32_TO_PTR (n_mem);
SPA_DATA_MEM_TYPE (&b->buffer.datas[j]) = SPA_MEM_TYPE_ID;
SPA_DATA_MEM_PTR (&b->buffer.datas[j]) = SPA_UINT32_TO_PTR (n_mem);
n_mem++;
break;
case SPA_DATA_TYPE_MEMPTR:
b->buffer.datas[j].data = SPA_INT_TO_PTR (b->size);
b->size += d->size;
case SPA_MEM_TYPE_MEMPTR:
SPA_DATA_MEM_PTR (&b->buffer.datas[j]) = SPA_INT_TO_PTR (b->size);
b->size += SPA_DATA_MEM_SIZE (d);
break;
default:
b->buffer.datas[j].type = SPA_DATA_TYPE_INVALID;
b->buffer.datas[j].data = 0;
spa_log_error (this->log, "invalid memory type %d", d->type);
SPA_DATA_MEM_TYPE (&b->buffer.datas[j]) = SPA_MEM_TYPE_INVALID;
SPA_DATA_MEM_PTR (&b->buffer.datas[j]) = 0;
spa_log_error (this->log, "invalid memory type %d", SPA_DATA_MEM_TYPE (d));
break;
}
}
......@@ -713,11 +713,11 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
sbd = SPA_MEMBER (sb, SPA_PTR_TO_INT (sb->datas), SpaData);
for (j = 0; j < b->buffer.n_metas; j++)
b->metas[j].data = SPA_MEMBER (sb, SPA_PTR_TO_INT (sbm[j].data), void);
SPA_META_MEM_PTR (&b->metas[j]) = SPA_MEMBER (sb, SPA_PTR_TO_INT (SPA_META_MEM_PTR (&sbm[j])), void);
for (j = 0; j < b->buffer.n_datas; j++) {
if (b->datas[j].type == SPA_DATA_TYPE_MEMPTR)
b->datas[j].data = SPA_MEMBER (sb, SPA_PTR_TO_INT (sbd[j].data), void);
if (SPA_DATA_MEM_TYPE (&b->datas[j]) == SPA_MEM_TYPE_MEMPTR)
SPA_DATA_MEM_PTR (&b->datas[j]) = SPA_MEMBER (sb, SPA_PTR_TO_INT (SPA_DATA_MEM_PTR (&sbd[j])), void);
}
p += b->size;
}
......@@ -725,7 +725,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
am.direction = direction;
am.port_id = port_id;
am.mem_id = port->buffer_mem_id;
am.type = SPA_DATA_TYPE_MEMFD;
am.type = SPA_MEM_TYPE_MEMFD;
am.memfd = port->buffer_mem.fd;
am.flags = 0;
am.offset = 0;
......@@ -795,13 +795,17 @@ copy_meta_in (SpaProxy *this, SpaProxyPort *port, uint32_t buffer_id)
for (i = 0; i < b->outbuf->n_metas; i++) {
SpaMeta *sm = &b->buffer.metas[i];
SpaMeta *dm = &b->outbuf->metas[i];
memcpy (dm->data, sm->data, dm->size);
memcpy (SPA_META_PTR (dm), SPA_META_PTR (sm), SPA_META_SIZE (dm));
}
for (i = 0; i < b->outbuf->n_datas; i++) {
b->outbuf->datas[i].size = b->buffer.datas[i].size;
if (b->outbuf->datas[i].type == SPA_DATA_TYPE_MEMPTR) {
spa_log_info (this->log, "memcpy in %zd", b->buffer.datas[i].size);
memcpy (b->outbuf->datas[i].data, b->datas[i].data, b->buffer.datas[i].size);
SpaData *dd = &b->outbuf->datas[i];
SPA_DATA_CHUNK_SIZE (dd) = SPA_DATA_CHUNK_SIZE (&b->buffer.datas[i]);
if (SPA_DATA_MEM_TYPE (dd) == SPA_MEM_TYPE_MEMPTR) {
spa_log_info (this->log, "memcpy in %zd", SPA_DATA_CHUNK_SIZE (&b->buffer.datas[i]));
memcpy (SPA_DATA_CHUNK_PTR (dd),
SPA_DATA_CHUNK_PTR (&b->datas[i]),
SPA_DATA_CHUNK_SIZE (dd));
}
}
}
......@@ -815,13 +819,17 @@ copy_meta_out (SpaProxy *this, SpaProxyPort *port, uint32_t buffer_id)
for (i = 0; i < b->outbuf->n_metas; i++) {
SpaMeta *sm = &b->outbuf->metas[i];
SpaMeta *dm = &b->buffer.metas[i];
memcpy (dm->data, sm->data, dm->size);
memcpy (SPA_META_PTR (dm), SPA_META_PTR (sm), SPA_META_SIZE (dm));
}
for (i = 0; i < b->outbuf->n_datas; i++) {
b->buffer.datas[i].size = b->outbuf->datas[i].size;
if (b->datas[i].type == SPA_DATA_TYPE_MEMPTR) {
spa_log_info (this->log, "memcpy out %zd", b->outbuf->datas[i].size);
memcpy (b->datas[i].data, b->outbuf->datas[i].data, b->outbuf->datas[i].size);
SpaData *sd = &b->outbuf->datas[i];
SPA_DATA_CHUNK_SIZE (&b->buffer.datas[i]) = SPA_DATA_CHUNK_SIZE (sd);
if (SPA_DATA_MEM_TYPE (&b->datas[i]) == SPA_MEM_TYPE_MEMPTR) {
spa_log_info (this->log, "memcpy out %zd", SPA_DATA_CHUNK_SIZE (sd));
memcpy (SPA_DATA_CHUNK_PTR (&b->datas[i]),
SPA_DATA_CHUNK_PTR (sd),
SPA_DATA_CHUNK_SIZE (sd));
}
}
}
......
......@@ -321,6 +321,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
size_t hdr_size, buf_size, arr_size;
void *p;
unsigned int n_metas, n_datas;
SpaMem mem;
n_metas = 0;
n_datas = 1;
......@@ -352,6 +353,13 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
impl->buffers = p = impl->buffer_mem.ptr;
p = SPA_MEMBER (p, arr_size, void);
mem.type = SPA_MEM_TYPE_MEMFD;
mem.flags = 0;
mem.fd = impl->buffer_mem.fd;
mem.offset = 0;
mem.size = impl->buffer_mem.size;
mem.ptr = impl->buffer_mem.ptr;
for (i = 0; i < impl->n_buffers; i++) {
SpaBuffer *b;
SpaData *d;
......@@ -373,9 +381,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
if (ap->type == SPA_ALLOC_PARAM_TYPE_META_ENABLE) {
SpaAllocParamMetaEnable *pme = (SpaAllocParamMetaEnable *) ap;
b->metas[mi].type = pme->type;
b->metas[mi].data = pd;
b->metas[mi].size = spa_meta_type_get_size (pme->type);
SPA_META_MEMREF_MEM (&b->metas[mi]) = &mem;
SPA_META_TYPE (&b->metas[mi]) = pme->type;
SPA_META_PTR (&b->metas[mi]) = pd;
SPA_META_SIZE (&b->metas[mi]) = spa_meta_type_get_size (pme->type);
switch (pme->type) {
case SPA_META_TYPE_RINGBUFFER:
......@@ -387,24 +396,25 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
default:
break;
}
pd = SPA_MEMBER (pd, b->metas[mi].size, void);
pd = SPA_MEMBER (pd, SPA_META_SIZE (&b->metas[mi]), void);
mi++;
}
}
d = &b->datas[0];
if (minsize > 0) {
d->type = SPA_DATA_TYPE_MEMFD;
d->flags = 0;
d->data = impl->buffer_mem.ptr;
d->fd = impl->buffer_mem.fd;
d->maxsize = impl->buffer_mem.size;
d->offset = arr_size + hdr_size + (buf_size * i);
d->size = minsize;
d->stride = stride;
SPA_DATA_MEMREF_MEM (d) = &mem;
SPA_DATA_MEMREF_OFFSET (d) = arr_size + hdr_size + (buf_size * i);
SPA_DATA_MEMREF_SIZE (d) = minsize;
SPA_DATA_MEMREF_PTR (d) = SPA_MEMBER (SPA_DATA_MEM_PTR (d), SPA_DATA_MEMREF_OFFSET (d), void);
SPA_DATA_CHUNK_OFFSET (d) = 0;
SPA_DATA_CHUNK_SIZE (d) = minsize;
SPA_DATA_CHUNK_STRIDE (d) = stride;
} else {
d->type = SPA_DATA_TYPE_INVALID;
d->data = NULL;
SPA_DATA_MEMREF_MEM (d) = &mem;
SPA_DATA_MEM_TYPE (d) = SPA_MEM_TYPE_INVALID;
SPA_DATA_MEM_PTR (d) = NULL;
}
}
pinos_log_debug ("allocated %d buffers %p %zd", impl->n_buffers, impl->buffers, minsize);
......
......@@ -46,21 +46,21 @@ typedef enum {
} SpaMetaType;
/**
* SpaDataType:
* @SPA_DATA_TYPE_INVALID: invalid data, should be ignored
* @SPA_DATA_TYPE_MEMPTR: data points to CPU accessible memory
* @SPA_DATA_TYPE_MEMFD: fd is memfd, data can be mmapped
* @SPA_DATA_TYPE_DMABUF: fd is dmabuf, data can be mmapped
* @SPA_DATA_TYPE_ID: data is an id use SPA_PTR_TO_INT32. The definition of
* SpaMemType:
* @SPA_MEM_TYPE_INVALID: invalid data, should be ignored
* @SPA_MEM_TYPE_MEMPTR: data points to CPU accessible memory
* @SPA_MEM_TYPE_MEMFD: fd is memfd, data can be mmapped
* @SPA_MEM_TYPE_DMABUF: fd is dmabuf, data can be mmapped
* @SPA_MEM_TYPE_ID: data is an id use SPA_PTR_TO_INT32. The definition of
* the ID is conveyed in some other way
*/
typedef enum {
SPA_DATA_TYPE_INVALID = 0,
SPA_DATA_TYPE_MEMPTR,
SPA_DATA_TYPE_MEMFD,
SPA_DATA_TYPE_DMABUF,
SPA_DATA_TYPE_ID,
} SpaDataType;
SPA_MEM_TYPE_INVALID = 0,
SPA_MEM_TYPE_MEMPTR,
SPA_MEM_TYPE_MEMFD,
SPA_MEM_TYPE_DMABUF,
SPA_MEM_TYPE_ID,
} SpaMemType;
#include <spa/defs.h>
#include <spa/port.h>
......@@ -119,47 +119,115 @@ typedef struct {
SpaRingbuffer ringbuffer;
} SpaMetaRingbuffer;
/**
* SpaMem:
* @type: memory type
* @flags: memory flags
* @fd: file descriptor
* @offset: offset in @fd
* @size: size of the memory
* @ptr: pointer to memory
*/
typedef struct {
SpaMemType type;
int flags;
int fd;
off_t offset;
size_t size;
void *ptr;
} SpaMem;
/**
* SpaMemRef:
* @mem_id: the SpaMem id
* @offset: offset in @mem_id
* @size: size in @mem_id
* @ptr: pointer to mem
*
* A reference to a block of memory
*/
typedef struct {
SpaMem *mem;
off_t offset;
size_t size;
void *ptr;
} SpaMemRef;
/**
* SpaMeta:
* @type: metadata type
* @data: pointer to metadata
* @size: size of metadata
* @mem: reference to the memory holding the metadata
*/
typedef struct {
SpaMetaType type;
void *data;
size_t size;
SpaMemRef mem;
} SpaMeta;
#define SPA_META_MEM_TYPE(m) ((m)->mem.mem->type)
#define SPA_META_MEM_FLAGS(m) ((m)->mem.mem->flags)
#define SPA_META_MEM_FD(m) ((m)->mem.mem->fd)
#define SPA_META_MEM_OFFSET(m) ((m)->mem.mem->offset)
#define SPA_META_MEM_SIZE(m) ((m)->mem.mem->size)
#define SPA_META_MEM_PTR(m) ((m)->mem.mem->ptr)
#define SPA_META_MEMREF_MEM(m) ((m)->mem.mem)
#define SPA_META_MEMREF_OFFSET(m) ((m)->mem.offset)
#define SPA_META_MEMREF_SIZE(m) ((m)->mem.size)
#define SPA_META_MEMREF_PTR(m) ((m)->mem.ptr)
#define SPA_META_TYPE(m) ((m)->type)
#define SPA_META_PTR(m) SPA_META_MEMREF_PTR(m)
#define SPA_META_SIZE(m) SPA_META_MEMREF_SIZE(m)
typedef struct {
off_t offset;
size_t size;
ssize_t stride;
} SpaChunk;
typedef struct {
SpaMem *mem;
off_t offset;
size_t size;
SpaChunk *chunk;
} SpaChunkRef;
/**
* SpaData:
* @type: memory type
* @flags: memory flags
* @data: pointer to memory
* @fd: file descriptor
* @maxsize: maximum size of the memory
* @offset: offset in @data
* @size: valid size of @data
* @stride: stride of data if applicable
* @mem: reference to memory holding the data
* @chunk: reference to valid chunk of memory
*/
typedef struct {
SpaDataType type;
int flags;
void *data;
int fd;
size_t maxsize;
off_t offset;
size_t size;
ssize_t stride;
SpaMemRef mem;
SpaChunkRef chunk;
} SpaData;
#define SPA_DATA_MEM_TYPE(d) ((d)->mem.mem->type)
#define SPA_DATA_MEM_FLAGS(d) ((d)->mem.mem->flags)
#define SPA_DATA_MEM_FD(d) ((d)->mem.mem->fd)
#define SPA_DATA_MEM_OFFSET(d) ((d)->mem.mem->offset)
#define SPA_DATA_MEM_SIZE(d) ((d)->mem.mem->size)
#define SPA_DATA_MEM_PTR(d) ((d)->mem.mem->ptr)
#define SPA_DATA_MEMREF_MEM(d) ((d)->mem.mem)
#define SPA_DATA_MEMREF_OFFSET(d) ((d)->mem.offset)
#define SPA_DATA_MEMREF_SIZE(d) ((d)->mem.size)
#define SPA_DATA_MEMREF_PTR(d) ((d)->mem.ptr)
#define SPA_DATA_CHUNK_OFFSET(d) ((d)->chunk.chunk->offset)
#define SPA_DATA_CHUNK_SIZE(d) ((d)->chunk.chunk->size)
#define SPA_DATA_CHUNK_STRIDE(d) ((d)->chunk.chunk->stride)
#define SPA_DATA_CHUNK_PTR(d) (SPA_DATA_MEMREF_PTR(d) + SPA_DATA_CHUNK_OFFSET(d))
/**
* SpaBuffer:
* @id: buffer id
* @n_mems: number of mem
* @mems: array of @n_mems memory blocks
* @n_metas: number of metadata
* @metas: offset of array of @n_metas metadata
* @metas: array of @n_metas metadata
* @n_datas: number of data pointers
* @datas: offset of array of @n_datas data pointers
* @datas: array of @n_datas data pointers
*/
struct _SpaBuffer {
uint32_t id;
......@@ -176,7 +244,7 @@ spa_buffer_find_meta (SpaBuffer *b, SpaMetaType type)
for (i = 0; i < b->n_metas; i++)
if (b->metas[i].type == type)
return b->metas[i].data;
return b->metas[i].mem.ptr;
return NULL;
}
......
......@@ -34,9 +34,9 @@ struct meta_type_name {
};