summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2016-12-14 14:56:50 +0100
committerWim Taymans <wtaymans@redhat.com>2016-12-14 14:56:50 +0100
commita9ba35359c302280c66ddd28596ffae11ddde071 (patch)
treec23f239837e084b06bc2b16c41ae5591eec7e6f0
parent5e8a3afe17d954dc278eed6a7f1dab16daa49701 (diff)
another mem testmem2
-rw-r--r--pinos/client/connection.h2
-rw-r--r--pinos/client/serialize.c12
-rw-r--r--pinos/client/stream.c32
-rw-r--r--pinos/gst/gstpinossink.c24
-rw-r--r--pinos/gst/gstpinossrc.c24
-rw-r--r--pinos/server/client-node.c68
-rw-r--r--pinos/server/link.c38
-rw-r--r--spa/include/spa/buffer.h138
-rw-r--r--spa/lib/debug.c38
-rw-r--r--spa/plugins/alsa/alsa-sink.c10
-rw-r--r--spa/plugins/alsa/alsa-source.c10
-rw-r--r--spa/plugins/alsa/alsa-utils.c21
-rw-r--r--spa/plugins/audiomixer/audiomixer.c8
-rw-r--r--spa/plugins/audiotestsrc/audiotestsrc.c14
-rw-r--r--spa/plugins/v4l2/v4l2-utils.c73
-rw-r--r--spa/plugins/videotestsrc/videotestsrc.c14
-rw-r--r--spa/plugins/volume/volume.c10
17 files changed, 316 insertions, 220 deletions
diff --git a/pinos/client/connection.h b/pinos/client/connection.h
index 96d34b7d..6cff09db 100644
--- a/pinos/client/connection.h
+++ b/pinos/client/connection.h
@@ -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;
diff --git a/pinos/client/serialize.c b/pinos/client/serialize.c
index 0b8f949e..4a8acfe7 100644
--- a/pinos/client/serialize.c
+++ b/pinos/client/serialize.c
@@ -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);
diff --git a/pinos/client/stream.c b/pinos/client/stream.c
index 41f53935..de5c5cf2 100644
--- a/pinos/client/stream.c
+++ b/pinos/client/stream.c
@@ -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;
diff --git a/pinos/gst/gstpinossink.c b/pinos/gst/gstpinossink.c
index 5233a97b..6bfd0cd7 100644
--- a/pinos/gst/gstpinossink.c
+++ b/pinos/gst/gstpinossink.c
@@ -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);
diff --git a/pinos/gst/gstpinossrc.c b/pinos/gst/gstpinossrc.c
index 0c015412..8607400e 100644
--- a/pinos/gst/gstpinossrc.c
+++ b/pinos/gst/gstpinossrc.c
@@ -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);
diff --git a/pinos/server/client-node.c b/pinos/server/client-node.c
index 2816d7a6..20ed43cd 100644
--- a/pinos/server/client-node.c
+++ b/pinos/server/client-node.c
@@ -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));
}
}
}
diff --git a/pinos/server/link.c b/pinos/server/link.c
index 2f23f56f..03fc421f 100644
--- a/pinos/server/link.c
+++ b/pinos/server/link.c
@@ -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);
diff --git a/spa/include/spa/buffer.h b/spa/include/spa/buffer.h
index 1b58c56a..aea6b21c 100644
--- a/spa/include/spa/buffer.h
+++ b/spa/include/spa/buffer.h
@@ -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>
@@ -120,46 +120,114 @@ typedef struct {
} 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;
}
diff --git a/spa/lib/debug.c b/spa/lib/debug.c
index 02e8bb32..900f6f29 100644
--- a/spa/lib/debug.c
+++ b/spa/lib/debug.c
@@ -34,9 +34,9 @@ struct meta_type_name {
};
#define META_TYPE_NAME(t) meta_type_names[SPA_CLAMP(t,0,SPA_N_ELEMENTS(meta_type_names)-1)].name
-struct data_type_name {
+struct mem_type_name {
const char *name;
-} data_type_names[] = {
+} mem_type_names[] = {
{ "invalid" },
{ "memptr" },
{ "memfd" },
@@ -44,7 +44,7 @@ struct data_type_name {
{ "ID" },
{ "invalid" },
};
-#define DATA_TYPE_NAME(t) data_type_names[SPA_CLAMP(t,0,SPA_N_ELEMENTS(data_type_names)-1)].name
+#define MEM_TYPE_NAME(t) mem_type_names[SPA_CLAMP(t,0,SPA_N_ELEMENTS(mem_type_names)-1)].name
SpaResult
spa_debug_port_info (const SpaPortInfo *info)
@@ -130,11 +130,12 @@ spa_debug_buffer (const SpaBuffer *buffer)
fprintf (stderr, " n_metas: %u (at %p)\n", buffer->n_metas, buffer->metas);
for (i = 0; i < buffer->n_metas; i++) {
SpaMeta *m = &buffer->metas[i];
- fprintf (stderr, " meta %d: type %d (%s), data %p, size %zd:\n", i, m->type, META_TYPE_NAME (m->type), m->data, m->size);
+ fprintf (stderr, " meta %d: type %d (%s), data %p, size %zd:\n",
+ i, m->type, META_TYPE_NAME (m->type), m->mem.ptr, m->mem.size);
switch (m->type) {
case SPA_META_TYPE_HEADER:
{
- SpaMetaHeader *h = m->data;
+ SpaMetaHeader *h = m->mem.ptr;
fprintf (stderr, " SpaMetaHeader:\n");
fprintf (stderr, " flags: %08x\n", h->flags);
fprintf (stderr, " seq: %u\n", h->seq);
@@ -144,16 +145,16 @@ spa_debug_buffer (const SpaBuffer *buffer)
}
case SPA_META_TYPE_POINTER:
{
- SpaMetaPointer *h = m->data;
+ SpaMetaPointer *h = m->mem.ptr;
fprintf (stderr, " SpaMetaPointer:\n");
fprintf (stderr, " ptr_type: %s\n", h->ptr_type);
fprintf (stderr, " ptr: %p\n", h->ptr);
- spa_debug_dump_mem (m->data, m->size);
+ spa_debug_dump_mem (m->mem.ptr, m->mem.size);
break;
}
case SPA_META_TYPE_VIDEO_CROP:
{
- SpaMetaVideoCrop *h = m->data;
+ SpaMetaVideoCrop *h = m->mem.ptr;
fprintf (stderr, " SpaMetaVideoCrop:\n");
fprintf (stderr, " x: %d\n", h->x);
fprintf (stderr, " y: %d\n", h->y);
@@ -163,7 +164,7 @@ spa_debug_buffer (const SpaBuffer *buffer)
}
case SPA_META_TYPE_RINGBUFFER:
{
- SpaMetaRingbuffer *h = m->data;
+ SpaMetaRingbuffer *h = m->mem.ptr;
fprintf (stderr, " SpaMetaRingbuffer:\n");
fprintf (stderr, " readindex: %zd\n", h->ringbuffer.readindex);
fprintf (stderr, " writeindex: %zd\n", h->ringbuffer.writeindex);
@@ -173,21 +174,22 @@ spa_debug_buffer (const SpaBuffer *buffer)
break;
}
default:
- spa_debug_dump_mem (m->data, m->size);
+ spa_debug_dump_mem (m->mem.ptr, m->mem.size);
break;
}
}
fprintf (stderr, " n_datas: \t%u (at %p)\n", buffer->n_datas, buffer->datas);
for (i = 0; i < buffer->n_datas; i++) {
SpaData *d = &buffer->datas[i];
- fprintf (stderr, " type: %d (%s)\n", d->type, DATA_TYPE_NAME (d->type));
- fprintf (stderr, " flags: %d\n", d->flags);
- fprintf (stderr, " data: %p\n", d->data);
- fprintf (stderr, " fd: %d\n", d->fd);
- fprintf (stderr, " maxsize: %zd\n", d->maxsize);
- fprintf (stderr, " offset: %zd\n", d->offset);
- fprintf (stderr, " size: %zd\n", d->size);
- fprintf (stderr, " stride: %zd\n", d->stride);
+ fprintf (stderr, " type: %d (%s)\n", d->mem.mem->type, MEM_TYPE_NAME (d->mem.mem->type));
+ fprintf (stderr, " flags: %d\n", d->mem.mem->flags);
+ fprintf (stderr, " fd: %d\n", d->mem.mem->fd);
+ fprintf (stderr, " offset: %zd\n", d->mem.mem->offset);
+ fprintf (stderr, " size: %zd\n", d->mem.mem->size);
+ fprintf (stderr, " ptr: %p\n", d->mem.mem->ptr);
+ fprintf (stderr, " offset: %zd\n", d->chunk.chunk->offset);
+ fprintf (stderr, " size: %zd\n", d->chunk.chunk->size);
+ fprintf (stderr, " stride: %zd\n", d->chunk.chunk->stride);
}
return SPA_RESULT_OK;
}
diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c
index 736ab3b2..969051da 100644
--- a/spa/plugins/alsa/alsa-sink.c
+++ b/spa/plugins/alsa/alsa-sink.c
@@ -544,11 +544,11 @@ spa_alsa_sink_node_port_use_buffers (SpaNode *node,
if (b->rb)
this->ringbuffer = b;
- switch (buffers[i]->datas[0].type) {
- case SPA_DATA_TYPE_MEMFD:
- case SPA_DATA_TYPE_DMABUF:
- case SPA_DATA_TYPE_MEMPTR:
- if (buffers[i]->datas[0].data == NULL) {
+ switch (SPA_DATA_MEM_TYPE (&buffers[i]->datas[0])) {
+ case SPA_MEM_TYPE_MEMFD:
+ case SPA_MEM_TYPE_DMABUF:
+ case SPA_MEM_TYPE_MEMPTR:
+ if (SPA_DATA_MEM_PTR (&buffers[i]->datas[0]) == NULL) {
spa_log_error (this->log, "alsa-source: need mapped memory");
continue;
}
diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c
index 9c79791d..eb34a63a 100644
--- a/spa/plugins/alsa/alsa-source.c
+++ b/spa/plugins/alsa/alsa-source.c
@@ -578,11 +578,11 @@ spa_alsa_source_node_port_use_buffers (SpaNode *node,
b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER);
- switch (buffers[i]->datas[0].type) {
- case SPA_DATA_TYPE_MEMFD:
- case SPA_DATA_TYPE_DMABUF:
- case SPA_DATA_TYPE_MEMPTR:
- if (buffers[i]->datas[0].data == NULL) {
+ switch (SPA_DATA_MEM_TYPE (&buffers[i]->datas[0])) {
+ case SPA_MEM_TYPE_MEMFD:
+ case SPA_MEM_TYPE_DMABUF:
+ case SPA_MEM_TYPE_MEMPTR:
+ if (SPA_DATA_MEM_PTR (&buffers[i]->datas[0]) == NULL) {
spa_log_error (this->log, "alsa-source: need mapped memory");
continue;
}
diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c
index 4fa72e06..994c0a91 100644
--- a/spa/plugins/alsa/alsa-utils.c
+++ b/spa/plugins/alsa/alsa-utils.c
@@ -272,18 +272,20 @@ pull_frames_queue (SpaALSAState *state,
uint8_t *src, *dst;
size_t n_bytes;
SpaALSABuffer *b;
+ SpaData *d;
b = spa_list_first (&state->ready, SpaALSABuffer, list);
+ d = &b->outbuf->datas[0];
- src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset + state->ready_offset, uint8_t);
+ src = SPA_MEMBER (SPA_DATA_CHUNK_PTR (d), state->ready_offset, uint8_t);
dst = SPA_MEMBER (my_areas[0].addr, offset * state->frame_size, uint8_t);
- n_bytes = SPA_MIN (b->outbuf->datas[0].size - state->ready_offset, frames * state->frame_size);
+ n_bytes = SPA_MIN (SPA_DATA_CHUNK_SIZE (d) - state->ready_offset, frames * state->frame_size);
frames = SPA_MIN (frames, n_bytes / state->frame_size);
memcpy (dst, src, n_bytes);
state->ready_offset += n_bytes;
- if (state->ready_offset >= b->outbuf->datas[0].size) {
+ if (state->ready_offset >= SPA_DATA_CHUNK_SIZE (d)) {
SpaNodeEventReuseBuffer rb;
spa_list_remove (&b->list);
@@ -315,10 +317,12 @@ pull_frames_ringbuffer (SpaALSAState *state,
SpaALSABuffer *b;
uint8_t *src, *dst;
SpaNodeEventReuseBuffer rb;
+ SpaData *d;
b = state->ringbuffer;
+ d = &b->outbuf->datas[0];
- src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void);
+ src = SPA_DATA_CHUNK_PTR (d);
dst = SPA_MEMBER (my_areas[0].addr, offset * state->frame_size, uint8_t);
avail = spa_ringbuffer_get_read_areas (&b->rb->ringbuffer, areas);
@@ -420,6 +424,7 @@ mmap_read (SpaALSAState *state)
int64_t now;
uint8_t *dest = NULL;
size_t destsize;
+ SpaData *d;
snd_pcm_status_alloca(&status);
@@ -442,8 +447,10 @@ mmap_read (SpaALSAState *state)
b = spa_list_first (&state->free, SpaALSABuffer, list);
spa_list_remove (&b->list);
- dest = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void);
- destsize = b->outbuf->datas[0].size;
+ d = &b->outbuf->datas[0];
+
+ dest = SPA_DATA_CHUNK_PTR (d);
+ destsize = SPA_DATA_CHUNK_SIZE (d);
if (b->h) {
b->h->seq = state->sample_count;
@@ -484,7 +491,7 @@ mmap_read (SpaALSAState *state)
SpaData *d;
d = b->outbuf->datas;
- d[0].size = avail * state->frame_size;
+ SPA_DATA_CHUNK_SIZE (&d[0]) = avail * state->frame_size;
spa_list_insert (state->ready.prev, &b->list);
diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c
index 654745a8..f1bc1922 100644
--- a/spa/plugins/audiomixer/audiomixer.c
+++ b/spa/plugins/audiomixer/audiomixer.c
@@ -598,12 +598,12 @@ add_port_data (SpaAudioMixer *this, SpaBuffer *out, SpaAudioMixerPort *port)
while (true) {
if (op == NULL) {
- op = (uint8_t*)odatas[oi].data + odatas[oi].offset;
- os = odatas[oi].size;
+ op = SPA_DATA_CHUNK_PTR (&odatas[oi]);
+ os = SPA_DATA_CHUNK_SIZE (&odatas[oi]);
}
if (ip == NULL) {
- ip = (uint8_t*)idatas[port->buffer_index].data + idatas[port->buffer_index].offset;
- is = idatas[port->buffer_index].size;
+ ip = SPA_DATA_CHUNK_PTR (&idatas[port->buffer_index]);
+ is = SPA_DATA_CHUNK_SIZE (&idatas[port->buffer_index]);
ip += port->buffer_offset;
is -= port->buffer_offset;
}
diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c
index 11a024b6..cc8a1cdc 100644
--- a/spa/plugins/audiotestsrc/audiotestsrc.c
+++ b/spa/plugins/audiotestsrc/audiotestsrc.c
@@ -682,16 +682,16 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
b->outstanding = true;
b->h = spa_buffer_find_meta (buffers[i], SPA_META_TYPE_HEADER);
- switch (d[0].type) {
- case SPA_DATA_TYPE_MEMPTR:
- case SPA_DATA_TYPE_MEMFD:
- case SPA_DATA_TYPE_DMABUF:
- if (d[0].data == NULL) {
+ switch (SPA_DATA_MEM_TYPE (&d[0])) {
+ case SPA_MEM_TYPE_MEMPTR:
+ case SPA_MEM_TYPE_MEMFD:
+ case SPA_MEM_TYPE_DMABUF:
+ if (SPA_DATA_MEM_PTR (&d[0]) == NULL) {
spa_log_error (this->log, "audiotestsrc %p: invalid memory on buffer %p", this, buffers[i]);
continue;
}
- b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
- b->size = d[0].size;
+ b->ptr = SPA_DATA_CHUNK_PTR (&d[0]);
+ b->size = SPA_DATA_CHUNK_SIZE (&d[0]);
break;
default:
break;
diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c
index de291aa1..d3f3510e 100644
--- a/spa/plugins/v4l2/v4l2-utils.c
+++ b/spa/plugins/v4l2/v4l2-utils.c
@@ -108,19 +108,19 @@ spa_v4l2_clear_buffers (SpaV4l2Source *this)
return SPA_RESULT_OK;
for (i = 0; i < state->n_buffers; i++) {
- V4l2Buffer *b;
+ V4l2Buffer *b = &state->buffers[i];
+ SpaData *d = &b->outbuf->datas[0];
- b = &state->buffers[i];
if (b->outstanding) {
spa_log_info (state->log, "v4l2: queueing outstanding buffer %p", b);
spa_v4l2_buffer_recycle (this, i);
}
if (b->allocated) {
- if (b->outbuf->datas[0].data)
- munmap (b->outbuf->datas[0].data, b->outbuf->datas[0].maxsize);
- if (b->outbuf->datas[0].fd != -1)
- close (b->outbuf->datas[0].fd);
- b->outbuf->datas[0].type = SPA_DATA_TYPE_INVALID;
+ if (SPA_DATA_MEM_PTR (d))
+ munmap (SPA_DATA_MEM_PTR (d), SPA_DATA_MEM_SIZE (d));
+ if (SPA_DATA_MEM_FD (d) != -1)
+ close (SPA_DATA_MEM_FD (d));
+ SPA_DATA_MEM_TYPE (d) = SPA_MEM_TYPE_INVALID;
}
}
@@ -876,7 +876,8 @@ mmap_read (SpaV4l2Source *this)
}
d = b->outbuf->datas;
- d[0].size = buf.bytesused;
+ SPA_DATA_CHUNK_OFFSET (&d[0]) = 0;
+ SPA_DATA_CHUNK_SIZE (&d[0]) = buf.bytesused;
spa_list_insert (state->ready.prev, &b->list);
@@ -913,12 +914,12 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
SpaData *d;
if (n_buffers > 0) {
- switch (buffers[0]->datas[0].type) {
- case SPA_DATA_TYPE_MEMPTR:
- case SPA_DATA_TYPE_MEMFD:
+ switch (SPA_DATA_MEM_TYPE (&buffers[0]->datas[0])) {
+ case SPA_MEM_TYPE_MEMPTR:
+ case SPA_MEM_TYPE_MEMFD:
state->memtype = V4L2_MEMORY_USERPTR;
break;
- case SPA_DATA_TYPE_DMABUF:
+ case SPA_MEM_TYPE_DMABUF:
state->memtype = V4L2_MEMORY_DMABUF;
break;
default:
@@ -963,18 +964,18 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
b->v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
b->v4l2_buffer.memory = state->memtype;
b->v4l2_buffer.index = i;
- switch (d[0].type) {
- case SPA_DATA_TYPE_MEMPTR:
- case SPA_DATA_TYPE_MEMFD:
- if (d[0].data == NULL) {
+ switch (SPA_DATA_MEM_TYPE (&d[0])) {
+ case SPA_MEM_TYPE_MEMPTR:
+ case SPA_MEM_TYPE_MEMFD:
+ if (SPA_DATA_MEM_PTR (&d[0]) == NULL) {
spa_log_error (state->log, "v4l2: need mmaped memory");
continue;
}
- b->v4l2_buffer.m.userptr = (unsigned long) SPA_MEMBER (d[0].data, d[0].offset, void *);
- b->v4l2_buffer.length = d[0].size;
+ b->v4l2_buffer.m.userptr = (unsigned long) SPA_DATA_CHUNK_PTR (&d[0]);
+ b->v4l2_buffer.length = SPA_DATA_CHUNK_SIZE (&d[0]);
break;
- case SPA_DATA_TYPE_DMABUF:
- b->v4l2_buffer.m.fd = d[0].fd;
+ case SPA_MEM_TYPE_DMABUF:
+ b->v4l2_buffer.m.fd = SPA_DATA_MEM_FD (&d[0]);
break;
default:
break;
@@ -1045,10 +1046,10 @@ mmap_init (SpaV4l2Source *this,
}
d = buffers[i]->datas;
- d[0].offset = 0;
- d[0].size = b->v4l2_buffer.length;
- d[0].maxsize = b->v4l2_buffer.length;
- d[0].stride = state->fmt.fmt.pix.bytesperline;
+ SPA_DATA_MEM_SIZE (&d[0]) = b->v4l2_buffer.length;
+ SPA_DATA_CHUNK_OFFSET (&d[0]) = 0;
+ SPA_DATA_CHUNK_SIZE (&d[0]) = b->v4l2_buffer.length;
+ SPA_DATA_CHUNK_STRIDE (&d[0]) = state->fmt.fmt.pix.bytesperline;
if (state->export_buf) {
struct v4l2_exportbuffer expbuf;
@@ -1061,19 +1062,19 @@ mmap_init (SpaV4l2Source *this,
perror("VIDIOC_EXPBUF");
continue;
}
- d[0].type = SPA_DATA_TYPE_DMABUF;
- d[0].fd = expbuf.fd;
- d[0].data = NULL;
+ SPA_DATA_MEM_TYPE (&d[0]) = SPA_MEM_TYPE_DMABUF;
+ SPA_DATA_MEM_FD (&d[0]) = expbuf.fd;
+ SPA_DATA_MEM_PTR (&d[0]) = NULL;
} else {
- d[0].type = SPA_DATA_TYPE_MEMPTR;
- d[0].fd = -1;
- d[0].data = mmap (NULL,
- b->v4l2_buffer.length,
- PROT_READ,
- MAP_SHARED,
- state->fd,
- b->v4l2_buffer.m.offset);
- if (d[0].data == MAP_FAILED) {
+ SPA_DATA_MEM_TYPE (&d[0]) = SPA_MEM_TYPE_MEMPTR;
+ SPA_DATA_MEM_FD (&d[0]) = -1;
+ SPA_DATA_MEM_PTR (&d[0]) = mmap (NULL,
+ b->v4l2_buffer.length,
+ PROT_READ,
+ MAP_SHARED,
+ state->fd,
+ b->v4l2_buffer.m.offset);
+ if (SPA_DATA_MEM_PTR (&d[0]) == MAP_FAILED) {
perror ("mmap");
continue;
}
diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c
index be8cf93b..3f8cbd24 100644
--- a/spa/plugins/videotestsrc/videotestsrc.c
+++ b/spa/plugins/videotestsrc/videotestsrc.c
@@ -649,16 +649,16 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node,
b->outstanding = true;
b->h = spa_buffer_find_meta (buffers[i], SPA_META_TYPE_HEADER);
- switch (d[0].type) {
- case SPA_DATA_TYPE_MEMPTR:
- case SPA_DATA_TYPE_MEMFD:
- case SPA_DATA_TYPE_DMABUF:
- if (d[0].data == NULL) {
+ switch (SPA_DATA_MEM_TYPE (&d[0])) {
+ case SPA_MEM_TYPE_MEMPTR:
+ case SPA_MEM_TYPE_MEMFD:
+ case SPA_MEM_TYPE_DMABUF:
+ if (SPA_DATA_MEM_PTR (&d[0]) == NULL) {
spa_log_error (this->log, "videotestsrc %p: invalid memory on buffer %p", this, buffers[i]);
continue;
}
- b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
- b->stride = d[0].stride;
+ b->ptr = SPA_DATA_CHUNK_PTR (&d[0]);
+ b->stride = SPA_DATA_CHUNK_STRIDE (&d[0]);
break;
default:
break;
diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c
index 4a64e8d4..9e1c7220 100644
--- a/spa/plugins/volume/volume.c
+++ b/spa/plugins/volume/volume.c
@@ -582,10 +582,10 @@ spa_volume_node_process_output (SpaNode *node)
sd = &sbuf->datas[si];
dd = &dbuf->datas[di];
- src = (uint16_t*) ((uint8_t*)sd->data + sd->offset + soff);
- dst = (uint16_t*) ((uint8_t*)dd->data + dd->offset + doff);
+ src = (uint16_t*) ((uint8_t*)SPA_DATA_CHUNK_PTR (sd) + soff);
+ dst = (uint16_t*) ((uint8_t*)SPA_DATA_CHUNK_PTR (dd) + doff);
- n_bytes = SPA_MIN (sd->size - soff, dd->size - doff);
+ n_bytes = SPA_MIN (SPA_DATA_CHUNK_SIZE (sd) - soff, SPA_DATA_CHUNK_SIZE (dd) - doff);
n_samples = n_bytes / sizeof (uint16_t);
for (i = 0; i < n_samples; i++)
@@ -594,11 +594,11 @@ spa_volume_node_process_output (SpaNode *node)
soff += n_bytes;
doff += n_bytes;
- if (soff >= sd->size) {
+ if (soff >= SPA_DATA_CHUNK_SIZE (sd)) {
si++;
soff = 0;
}
- if (doff >= dd->size) {
+ if (doff >= SPA_DATA_CHUNK_SIZE (dd)) {
di++;
doff = 0;
}