diff options
author | Wim Taymans <wtaymans@redhat.com> | 2016-12-14 09:52:23 +0100 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2016-12-14 09:52:23 +0100 |
commit | 265c852c3870b702f801ccf7a887cddc366e87ee (patch) | |
tree | fa08d6c9252c4600c7d815b55f277e28374fb7fd | |
parent | 5e8a3afe17d954dc278eed6a7f1dab16daa49701 (diff) |
Try a different way of doing buffer memorymem1
-rw-r--r-- | pinos/client/connection.h | 22 | ||||
-rw-r--r-- | pinos/client/serialize.c | 26 | ||||
-rw-r--r-- | pinos/client/stream.c | 46 | ||||
-rw-r--r-- | pinos/gst/gstpinossink.c | 30 | ||||
-rw-r--r-- | pinos/gst/gstpinossrc.c | 30 | ||||
-rw-r--r-- | pinos/server/client-node.c | 80 | ||||
-rw-r--r-- | pinos/server/link.c | 77 | ||||
-rw-r--r-- | spa/include/spa/buffer.h | 114 | ||||
-rw-r--r-- | spa/lib/debug.c | 23 | ||||
-rw-r--r-- | spa/plugins/alsa/alsa-sink.c | 10 | ||||
-rw-r--r-- | spa/plugins/alsa/alsa-source.c | 10 | ||||
-rw-r--r-- | spa/plugins/alsa/alsa-utils.c | 20 | ||||
-rw-r--r-- | spa/plugins/audiomixer/audiomixer.c | 20 | ||||
-rw-r--r-- | spa/plugins/audiotestsrc/audiotestsrc.c | 16 | ||||
-rw-r--r-- | spa/plugins/ffmpeg/ffmpeg-enc.c | 2 | ||||
-rw-r--r-- | spa/plugins/v4l2/v4l2-source.c | 1 | ||||
-rw-r--r-- | spa/plugins/v4l2/v4l2-utils.c | 85 | ||||
-rw-r--r-- | spa/plugins/videotestsrc/videotestsrc.c | 16 | ||||
-rw-r--r-- | spa/plugins/volume/volume.c | 18 | ||||
-rw-r--r-- | spa/plugins/xv/xv-sink.c | 2 |
20 files changed, 371 insertions, 277 deletions
diff --git a/pinos/client/connection.h b/pinos/client/connection.h index 96d34b7d..84e06c07 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; @@ -291,13 +291,31 @@ typedef struct { size_t size; } PinosMessageMemRef; +typedef struct { + SpaMetaType type; + PinosMessageMemRef meta; +} PinosMessageBufferMeta; + +typedef struct { + PinosMessageMemRef mem; + PinosMessageMemRef chunk; +} PinosMessageBufferMem; + +typedef struct { + uint32_t id; + uint32_t n_metas; + PinosMessageBufferMeta *metas; + uint32_t n_mems; + PinosMessageBufferMem *mems; +} PinosMessageBuffer; + /* PINOS_MESSAGE_USE_BUFFERS */ typedef struct { uint32_t seq; SpaDirection direction; uint32_t port_id; unsigned int n_buffers; - PinosMessageMemRef *buffers; + PinosMessageBuffer *buffers; } PinosMessageUseBuffers; PinosConnection * pinos_connection_new (int fd); diff --git a/pinos/client/serialize.c b/pinos/client/serialize.c index 0b8f949e..482b7378 100644 --- a/pinos/client/serialize.c +++ b/pinos/client/serialize.c @@ -31,8 +31,8 @@ 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; - for (i = 0; i < buffer->n_datas; i++) - size += sizeof (SpaData); + for (i = 0; i < buffer->n_mems; i++) + size += sizeof (SpaMem); return size; } @@ -41,7 +41,7 @@ pinos_serialize_buffer_serialize (void *dest, const SpaBuffer *buffer) { SpaBuffer *tb; SpaMeta *mp; - SpaData *dp; + SpaMem *dp; void *p; unsigned int i; @@ -51,11 +51,11 @@ pinos_serialize_buffer_serialize (void *dest, const SpaBuffer *buffer) tb = dest; memcpy (tb, buffer, sizeof (SpaBuffer)); mp = SPA_MEMBER (tb, sizeof(SpaBuffer), SpaMeta); - dp = SPA_MEMBER (mp, sizeof(SpaMeta) * tb->n_metas, SpaData); - p = SPA_MEMBER (dp, sizeof(SpaData) * tb->n_datas, void); + dp = SPA_MEMBER (mp, sizeof(SpaMeta) * tb->n_metas, SpaMem); + p = SPA_MEMBER (dp, sizeof(SpaMem) * tb->n_mems, void); tb->metas = SPA_INT_TO_PTR (SPA_PTRDIFF (mp, tb)); - tb->datas = SPA_INT_TO_PTR (SPA_PTRDIFF (dp, tb)); + tb->mems = SPA_INT_TO_PTR (SPA_PTRDIFF (dp, tb)); for (i = 0; i < tb->n_metas; i++) { memcpy (&mp[i], &buffer->metas[i], sizeof (SpaMeta)); @@ -63,8 +63,8 @@ pinos_serialize_buffer_serialize (void *dest, const SpaBuffer *buffer) mp[i].data = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tb)); p += mp[i].size; } - for (i = 0; i < tb->n_datas; i++) - memcpy (&dp[i], &buffer->datas[i], sizeof (SpaData)); + for (i = 0; i < tb->n_mems; i++) + memcpy (&dp[i], &buffer->mems[i], sizeof (SpaMem)); return SPA_PTRDIFF (p, tb); } @@ -83,9 +83,13 @@ pinos_serialize_buffer_deserialize (void *src, off_t offset) if (m->data) m->data = SPA_MEMBER (b, SPA_PTR_TO_INT (m->data), void); } - if (b->datas) - b->datas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->datas), SpaData); - + if (b->mems) + b->mems = SPA_MEMBER (b, SPA_PTR_TO_INT (b->mems), SpaMem); + for (i = 0; i < b->n_mems; i++) { + SpaMem *m = &b->mems[i]; + if (m->chunk) + m->chunk = SPA_MEMBER (b, SPA_PTR_TO_INT (m->chunk), void); + } return b; } diff --git a/pinos/client/stream.c b/pinos/client/stream.c index 41f53935..f80e1c3f 100644 --- a/pinos/client/stream.c +++ b/pinos/client/stream.c @@ -52,7 +52,7 @@ typedef struct { bool used; void *buf_ptr; SpaBuffer *buf; - SpaData *datas; + SpaMem *mems; } BufferId; typedef struct @@ -462,8 +462,8 @@ on_rtsocket_condition (SpaSource *source, continue; 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; + for (i = 0; i < bid->buf->n_mems; i++) { + SPA_BUFFER_SIZE (bid->buf, i) = SPA_BUFFER_SIZE (bid, i); } pinos_signal_emit (&stream->new_buffer, stream, bid->id); } @@ -703,17 +703,17 @@ stream_dispatch_func (void *object, 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; - for (i = 0; i < b->n_datas; i++) - size += sizeof (SpaData); + for (i = 0; i < b->n_mems; i++) + size += sizeof (SpaMem); b = bid->buf = malloc (size); memcpy (b, bid->buf_ptr, size); if (b->metas) b->metas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta); - if (b->datas) { - bid->datas = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (b->datas), SpaData); - b->datas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->datas), SpaData); + if (b->mems) { + bid->mems = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (b->mems), SpaMem); + b->mems = SPA_MEMBER (b, SPA_PTR_TO_INT (b->mems), SpaMem); } } @@ -731,28 +731,28 @@ stream_dispatch_func (void *object, m->data = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (m->data), void); } - for (j = 0; j < b->n_datas; j++) { - SpaData *d = &b->datas[j]; + for (j = 0; j < b->n_mems; j++) { + SpaMem *m = &b->mems[j]; - switch (d->type) { - case SPA_DATA_TYPE_ID: + switch (m->type) { + 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 (m->ptr)); + m->type = SPA_MEM_TYPE_MEMFD; + m->ptr = NULL; + m->fd = 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); + m->ptr = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (m->ptr), void); + m->fd = -1; + pinos_log_debug (" data %d %u -> mem %p", j, bid->id, m->ptr); break; } default: - pinos_log_warn ("unknown buffer data type %d", d->type); + pinos_log_warn ("unknown buffer data type %d", m->type); break; } } @@ -1096,8 +1096,8 @@ pinos_stream_send_buffer (PinosStream *stream, uint8_t cmd = PINOS_TRANSPORT_CMD_HAVE_DATA; bid->used = true; - for (i = 0; i < bid->buf->n_datas; i++) { - bid->datas[i].size = bid->buf->datas[i].size; + for (i = 0; i < bid->buf->n_mems; i++) { + SPA_BUFFER_SIZE (bid, i) = SPA_BUFFER_SIZE (bid->buf, 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..2773a986 100644 --- a/pinos/gst/gstpinossink.c +++ b/pinos/gst/gstpinossink.c @@ -394,22 +394,22 @@ on_add_buffer (PinosListener *listener, break; } } - for (i = 0; i < b->n_datas; i++) { - SpaData *d = &b->datas[i]; + for (i = 0; i < b->n_mems; i++) { + SpaMem *m = &b->mems[i]; GstMemory *gmem = NULL; - switch (d->type) { - case SPA_DATA_TYPE_MEMFD: - case SPA_DATA_TYPE_DMABUF: + switch (m->type) { + 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 (m->fd), + m->size, GST_FD_MEMORY_FLAG_NONE); + gst_memory_resize (gmem, m->offset + m->chunk->offset, m->chunk->size); 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, m->ptr, m->size, m->chunk->offset, + m->chunk->size, NULL, NULL); break; default: break; @@ -641,11 +641,11 @@ gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer) data->header->pts = GST_BUFFER_PTS (buffer); data->header->dts_offset = GST_BUFFER_DTS (buffer); } - for (i = 0; i < data->buf->n_datas; i++) { - SpaData *d = &data->buf->datas[i]; + for (i = 0; i < data->buf->n_mems; i++) { + SpaMem *m = &data->buf->mems[i]; GstMemory *mem = gst_buffer_peek_memory (buffer, i); - d->offset = mem->offset; - d->size = mem->size; + m->chunk->offset = mem->offset; + m->chunk->size = mem->size; } gst_buffer_ref (buffer); diff --git a/pinos/gst/gstpinossrc.c b/pinos/gst/gstpinossrc.c index 0c015412..44a53065 100644 --- a/pinos/gst/gstpinossrc.c +++ b/pinos/gst/gstpinossrc.c @@ -408,22 +408,22 @@ on_add_buffer (PinosListener *listener, break; } } - for (i = 0; i < b->n_datas; i++) { - SpaData *d = &b->datas[i]; + for (i = 0; i < b->n_mems; i++) { + SpaMem *m = &b->mems[i]; GstMemory *gmem = NULL; - switch (d->type) { - case SPA_DATA_TYPE_MEMFD: - case SPA_DATA_TYPE_DMABUF: + switch (m->type) { + 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 (m->fd), + m->size, GST_FD_MEMORY_FLAG_NONE); + gst_memory_resize (gmem, m->offset + m->chunk->offset, m->chunk->size); 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, m->ptr, m->size, m->chunk->offset, + m->chunk->size, NULL, NULL); default: break; } @@ -485,11 +485,11 @@ on_new_buffer (PinosListener *listener, } GST_BUFFER_OFFSET (buf) = h->seq; } - for (i = 0; i < data->buf->n_datas; i++) { - SpaData *d = &data->buf->datas[i]; + for (i = 0; i < data->buf->n_mems; i++) { + SpaMem *m = &data->buf->mems[i]; GstMemory *mem = gst_buffer_peek_memory (buf, i); - mem->offset = d->offset; - mem->size = d->size; + mem->offset = m->chunk->offset; + mem->size = m->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..659743e0 100644 --- a/pinos/server/client-node.c +++ b/pinos/server/client-node.c @@ -62,7 +62,7 @@ struct _ProxyBuffer { SpaBuffer *outbuf; SpaBuffer buffer; SpaMeta metas[4]; - SpaData datas[4]; + SpaMem mems[4]; off_t offset; size_t size; bool outstanding; @@ -638,8 +638,8 @@ spa_proxy_node_port_use_buffers (SpaNode *node, b->outbuf = buffers[i]; memcpy (&b->buffer, buffers[i], sizeof (SpaBuffer)); - b->buffer.datas = b->datas; b->buffer.metas = b->metas; + b->buffer.mems = b->mems; b->size = SPA_ROUND_UP_N (pinos_serialize_buffer_get_size (buffers[i]), 64); b->offset = size; @@ -648,38 +648,37 @@ spa_proxy_node_port_use_buffers (SpaNode *node, memcpy (&b->buffer.metas[j], &buffers[i]->metas[j], sizeof (SpaMeta)); } - for (j = 0; j < buffers[i]->n_datas; j++) { - SpaData *d = &buffers[i]->datas[j]; + for (j = 0; j < buffers[i]->n_mems; j++) { + SpaMem *m = &buffers[i]->mems[j]; - memcpy (&b->buffer.datas[j], d, sizeof (SpaData)); + memcpy (&b->buffer.mems[j], m, sizeof (SpaMem)); - switch (d->type) { - case SPA_DATA_TYPE_DMABUF: - case SPA_DATA_TYPE_MEMFD: + switch (m->type) { + 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 = m->type; + am.memfd = m->fd; + am.flags = m->flags; + am.offset = m->offset; + am.size = m->size; 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); + b->buffer.mems[j].type = SPA_MEM_TYPE_ID; + b->buffer.mems[j].ptr = 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: + b->buffer.mems[j].ptr = SPA_INT_TO_PTR (b->size); 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); + b->buffer.mems[j].type = SPA_MEM_TYPE_INVALID; + b->buffer.mems[j].ptr = 0; + spa_log_error (this->log, "invalid memory type %d", m->type); break; } } @@ -703,29 +702,32 @@ spa_proxy_node_port_use_buffers (SpaNode *node, ProxyBuffer *b = &port->buffers[i]; SpaBuffer *sb; SpaMeta *sbm; - SpaData *sbd; + SpaMem *sbmem; pinos_serialize_buffer_serialize (p, &b->buffer); sb = p; - b->buffer.datas = SPA_MEMBER (sb, SPA_PTR_TO_INT (sb->datas), SpaData); + b->buffer.mems = SPA_MEMBER (sb, SPA_PTR_TO_INT (sb->mems), SpaMem); sbm = SPA_MEMBER (sb, SPA_PTR_TO_INT (sb->metas), SpaMeta); - sbd = SPA_MEMBER (sb, SPA_PTR_TO_INT (sb->datas), SpaData); + sbmem = SPA_MEMBER (sb, SPA_PTR_TO_INT (sb->mems), SpaMem); for (j = 0; j < b->buffer.n_metas; j++) b->metas[j].data = SPA_MEMBER (sb, SPA_PTR_TO_INT (sbm[j].data), 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); + for (j = 0; j < b->buffer.n_mems; j++) { + if (b->mems[j].type == SPA_MEM_TYPE_MEMPTR) + b->mems[j].ptr = SPA_MEMBER (sb, SPA_PTR_TO_INT (sbmem[j].ptr), void); } p += b->size; + + spa_debug_buffer (b->outbuf); + spa_debug_buffer (&b->buffer); } 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 +797,15 @@ 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]; + spa_log_info (this->log, "%d/%d memcpy meta %p -> %p %zd", i, b->outbuf->n_metas, + sm->data, dm->data, dm->size); memcpy (dm->data, sm->data, dm->size); } - 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); + for (i = 0; i < b->outbuf->n_mems; i++) { + SPA_BUFFER_SIZE (b->outbuf, i) = SPA_BUFFER_SIZE (&b->buffer, i); + if (SPA_BUFFER_MEM_TYPE (b->outbuf, i) == SPA_MEM_TYPE_MEMPTR) { + spa_log_info (this->log, "memcpy in %zd", SPA_BUFFER_SIZE (&b->buffer, i)); + memcpy (b->outbuf->mems[i].ptr, b->mems[i].ptr, SPA_BUFFER_SIZE (&b->buffer, i)); } } } @@ -817,11 +821,11 @@ copy_meta_out (SpaProxy *this, SpaProxyPort *port, uint32_t buffer_id) SpaMeta *dm = &b->buffer.metas[i]; memcpy (dm->data, sm->data, dm->size); } - 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); + for (i = 0; i < b->outbuf->n_mems; i++) { + SPA_BUFFER_SIZE (&b->buffer, i) = SPA_BUFFER_SIZE (b->outbuf, i); + if (b->mems[i].type == SPA_MEM_TYPE_MEMPTR) { + spa_log_info (this->log, "memcpy out %zd", SPA_BUFFER_SIZE (b->outbuf, i)); + memcpy (b->mems[i].ptr, b->outbuf->mems[i].ptr, SPA_BUFFER_SIZE (b->outbuf, i)); } } } diff --git a/pinos/server/link.c b/pinos/server/link.c index 2f23f56f..c5b31caf 100644 --- a/pinos/server/link.c +++ b/pinos/server/link.c @@ -318,54 +318,69 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) pinos_log_debug ("reusing %d output buffers %p", impl->n_buffers, impl->buffers); } else { unsigned int i, j; - size_t hdr_size, buf_size, arr_size; - void *p; - unsigned int n_metas, n_datas; + size_t hdr_size, buf_size, arr_size, meta_size; + void *meta_p, *chunk_p, *data_p; + unsigned int n_metas, n_mems; n_metas = 0; - n_datas = 1; + n_mems = 1; - hdr_size = sizeof (SpaBuffer); - hdr_size += n_datas * sizeof (SpaData); + impl->n_buffers = max_buffers; + + /* buffer size contains, the data + metadata + chunk info. This allocated + * in shared memory. */ + buf_size = minsize * blocks; + buf_size += n_mems * sizeof (SpaMemChunk); + + meta_size = 0; for (i = 0; i < oinfo->n_params; i++) { SpaAllocParam *ap = oinfo->params[i]; if (ap->type == SPA_ALLOC_PARAM_TYPE_META_ENABLE) { SpaAllocParamMetaEnable *pme = (SpaAllocParamMetaEnable *) ap; - hdr_size += spa_meta_type_get_size (pme->type); + meta_size += spa_meta_type_get_size (pme->type); n_metas++; } } - hdr_size += n_metas * sizeof (SpaMeta); - - buf_size = SPA_ROUND_UP_N (hdr_size + (minsize * blocks), 64); + buf_size += meta_size; + buf_size = SPA_ROUND_UP_N (buf_size, 64); - impl->n_buffers = max_buffers; pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD | PINOS_MEMBLOCK_FLAG_MAP_READWRITE | PINOS_MEMBLOCK_FLAG_SEAL, - impl->n_buffers * (sizeof (SpaBuffer*) + buf_size), + buf_size * impl->n_buffers, &impl->buffer_mem); + meta_p = SPA_MEMBER (impl->buffer_mem.ptr, 0, void); + chunk_p = SPA_MEMBER (meta_p, impl->n_buffers * meta_size, void); + data_p = SPA_MEMBER (chunk_p, impl->n_buffers * n_mems * sizeof (SpaMemChunk), void); + + /* header conatain the buffer, mem and metadata headers along with + * the array of buffers. This is allocated in local memory */ + hdr_size = sizeof (SpaBuffer); + hdr_size += n_metas * sizeof (SpaMeta); + hdr_size += n_mems * sizeof (SpaMem); + + impl->buffers = calloc (impl->n_buffers, sizeof (SpaBuffer *) + hdr_size); + arr_size = impl->n_buffers * sizeof (SpaBuffer*); - impl->buffers = p = impl->buffer_mem.ptr; - p = SPA_MEMBER (p, arr_size, void); for (i = 0; i < impl->n_buffers; i++) { SpaBuffer *b; - SpaData *d; + SpaMem *m; void *pd; unsigned int mi; - b = impl->buffers[i] = SPA_MEMBER (p, buf_size * i, SpaBuffer); + b = impl->buffers[i] = SPA_MEMBER (impl->buffers, arr_size + (hdr_size * i), SpaBuffer); b->id = i; b->n_metas = n_metas; b->metas = SPA_MEMBER (b, sizeof (SpaBuffer), SpaMeta); - b->n_datas = n_datas; - b->datas = SPA_MEMBER (b->metas, sizeof (SpaMeta) * n_metas, SpaData); - pd = SPA_MEMBER (b->datas, sizeof (SpaData) * n_datas, void); + b->n_mems = n_mems; + b->mems = SPA_MEMBER (b->metas, sizeof (SpaMeta) * n_metas, SpaMem); + + pd = SPA_MEMBER (meta_p, meta_size * i, void); for (j = 0, mi = 0; j < oinfo->n_params; j++) { SpaAllocParam *ap = oinfo->params[j]; @@ -392,20 +407,22 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) } } - d = &b->datas[0]; + m = &b->mems[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; + m->type = SPA_MEM_TYPE_MEMFD; + m->flags = SPA_MEM_FLAG_NONE; + m->fd = impl->buffer_mem.fd; + m->offset = SPA_PTRDIFF (data_p, impl->buffer_mem.ptr) + (minsize * blocks) * i; + m->size = impl->buffer_mem.size; + m->ptr = SPA_MEMBER (impl->buffer_mem.ptr, m->offset, void); + m->chunk->offset = 0, + m->chunk->size = minsize; + m->chunk->stride = stride; } else { - d->type = SPA_DATA_TYPE_INVALID; - d->data = NULL; + m->type = SPA_MEM_TYPE_INVALID; + m->ptr = NULL; } + spa_debug_buffer (b); } pinos_log_debug ("allocated %d buffers %p %zd", impl->n_buffers, impl->buffers, minsize); impl->allocated = true; diff --git a/spa/include/spa/buffer.h b/spa/include/spa/buffer.h index 1b58c56a..cb0fa61d 100644 --- a/spa/include/spa/buffer.h +++ b/spa/include/spa/buffer.h @@ -43,24 +43,37 @@ typedef enum { SPA_META_TYPE_POINTER, SPA_META_TYPE_VIDEO_CROP, SPA_META_TYPE_RINGBUFFER, + SPA_META_TYPE_SHARED, } 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 ptr, should be ignored + * @SPA_MEM_TYPE_MEMPTR: ptr points to CPU accessible memory + * @SPA_MEM_TYPE_MEMFD: fd is memfd, ptr can be mmapped + * @SPA_MEM_TYPE_DMABUF: fd is dmabuf, ptr can be mmapped + * @SPA_MEM_TYPE_ID: ptr 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; + +/** + * SpaMemFlag: + * @SPA_MEM_FLAG_NONE: no flags + * @SPA_MEM_FLAG_READ: mem is readable + * @SPA_MEM_FLAG_WRITE: mem is writable + */ +typedef enum { + SPA_MEM_FLAG_NONE = 0, + SPA_MEM_FLAG_READ = (1 << 0), + SPA_MEM_FLAG_WRITE = (1 << 1), +} SpaMemFlag; #include <spa/defs.h> #include <spa/port.h> @@ -132,43 +145,79 @@ typedef struct { } SpaMeta; /** - * 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 + * SpaMemArea: + * @offset: offset of start of data + * @size: size of the data + * @stride: stride of data + * + * The valid data in a data block. Offset and size are clamped + * to the maxsize of the data block. */ typedef struct { - SpaDataType type; - int flags; - void *data; - int fd; - size_t maxsize; off_t offset; size_t size; ssize_t stride; -} SpaData; +} SpaMemChunk; + +/** + * SpaMem: + * @type: memory type + * @flags: memory flags + * @fd: file descriptor, can be -1 + * @offset: offset in @fd + * @size: maximum size of the memory + * @ptr: pointer to memory, can be NULL + * @chunk: valid memory chunk + * + * A memory block. + */ +typedef struct { + SpaMemType type; + SpaMemFlag flags; + int fd; + off_t offset; + size_t size; + void *ptr; +} SpaMem; + +typedef struct { + SpaMem mem; + SpaMemChunk *chunk; +} SpaMemRef; /** * SpaBuffer: * @id: buffer id * @n_metas: number of metadata - * @metas: offset of array of @n_metas metadata - * @n_datas: number of data pointers - * @datas: offset of array of @n_datas data pointers + * @metas: array of @n_metas metadata + * @n_mems: number of memory blocks + * @mems: array of @n_mems memory blocks */ struct _SpaBuffer { uint32_t id; unsigned int n_metas; SpaMeta *metas; - unsigned int n_datas; - SpaData *datas; + unsigned int n_mems; + SpaMemRef *mems; }; +typedef struct { + SpaMem meta_mem; + SpaMem chunk_mem; +} SpaMetaShared; + +#define SPA_BUFFER_MEM_TYPE(b,n) ((b)->mems[n].mem.type) +#define SPA_BUFFER_MEM_FLAGS(b,n) ((b)->mems[n].mem.flags) +#define SPA_BUFFER_MEM_FD(b,n) ((b)->mems[n].mem.fd) +#define SPA_BUFFER_MEM_OFFSET(b,n) ((b)->mems[n].mem.offset) +#define SPA_BUFFER_MEM_SIZE(b,n) ((b)->mems[n].mem.size) +#define SPA_BUFFER_MEM_PTR(b,n) ((b)->mems[n].mem.ptr) + +#define SPA_BUFFER_OFFSET(b,n) ((b)->mems[n].chunk->offset) +#define SPA_BUFFER_SIZE(b,n) ((b)->mems[n].chunk->size) +#define SPA_BUFFER_STRIDE(b,n) ((b)->mems[n].chunk->stride) +#define SPA_BUFFER_DATA(b,n) (SPA_BUFFER_MEM_PTR (b,n) + SPA_BUFFER_OFFSET (b,n)) + static inline void * spa_buffer_find_meta (SpaBuffer *b, SpaMetaType type) { @@ -189,6 +238,7 @@ spa_meta_type_get_size (SpaMetaType type) sizeof (SpaMetaPointer), sizeof (SpaMetaVideoCrop), sizeof (SpaMetaRingbuffer), + sizeof (SpaMetaShared), }; if (type <= 0 || type >= SPA_N_ELEMENTS (header_sizes)) return 0; diff --git a/spa/lib/debug.c b/spa/lib/debug.c index 02e8bb32..535777f7 100644 --- a/spa/lib/debug.c +++ b/spa/lib/debug.c @@ -177,17 +177,18 @@ spa_debug_buffer (const SpaBuffer *buffer) 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, " n_datas: \t%u (at %p)\n", buffer->n_mems, buffer->mems); + for (i = 0; i < buffer->n_mems; i++) { + SpaMemRef *m = &buffer->mems[i]; + fprintf (stderr, " type: %d (%s)\n", m->mem.type, DATA_TYPE_NAME (m->mem.type)); + fprintf (stderr, " flags: %d\n", m->mem.flags); + fprintf (stderr, " fd: %d\n", m->mem.fd); + fprintf (stderr, " fd_offset: %zd\n", m->mem.offset); + fprintf (stderr, " fd_size: %zd\n", m->mem.size); + fprintf (stderr, " ptr: %p\n", m->mem.ptr); + fprintf (stderr, " offset: %zd\n", m->chunk->offset); + fprintf (stderr, " size: %zd\n", m->chunk->size); + fprintf (stderr, " stride: %zd\n", m->chunk->stride); } return SPA_RESULT_OK; } diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index 736ab3b2..b28bc1e8 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 (buffers[i]->mems[0].type) { + case SPA_MEM_TYPE_MEMFD: + case SPA_MEM_TYPE_DMABUF: + case SPA_MEM_TYPE_MEMPTR: + if (buffers[i]->mems[0].ptr == 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..4f68eab8 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_BUFFER_MEM_TYPE (buffers[i], 0)) { + case SPA_MEM_TYPE_MEMFD: + case SPA_MEM_TYPE_DMABUF: + case SPA_MEM_TYPE_MEMPTR: + if (buffers[i]->mems[0].ptr == 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..1ff8d30c 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -275,15 +275,15 @@ pull_frames_queue (SpaALSAState *state, b = spa_list_first (&state->ready, SpaALSABuffer, list); - src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset + state->ready_offset, uint8_t); + src = SPA_MEMBER (SPA_BUFFER_DATA (b->outbuf, 0), 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_BUFFER_SIZE (b->outbuf, 0) - 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_BUFFER_SIZE (b->outbuf, 0)) { SpaNodeEventReuseBuffer rb; spa_list_remove (&b->list); @@ -318,7 +318,7 @@ pull_frames_ringbuffer (SpaALSAState *state, b = state->ringbuffer; - src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void); + src = SPA_BUFFER_DATA (b->outbuf, 0); dst = SPA_MEMBER (my_areas[0].addr, offset * state->frame_size, uint8_t); avail = spa_ringbuffer_get_read_areas (&b->rb->ringbuffer, areas); @@ -442,8 +442,8 @@ 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; + dest = SPA_BUFFER_DATA (b->outbuf, 0); + destsize = SPA_BUFFER_SIZE (b->outbuf, 0); if (b->h) { b->h->seq = state->sample_count; @@ -481,10 +481,12 @@ mmap_read (SpaALSAState *state) if (b) { SpaNodeEventHaveOutput ho; - SpaData *d; + SpaMemChunk *c; - d = b->outbuf->datas; - d[0].size = avail * state->frame_size; + c = b->outbuf->mems[0].chunk; + c->offset = 0; + c->size = avail * state->frame_size; + c->stride = 0; spa_list_insert (state->ready.prev, &b->list); diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index 654745a8..ae6b7844 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -42,9 +42,9 @@ typedef struct _MixerBuffer MixerBuffer; struct _MixerBuffer { SpaBuffer buffer; - SpaMeta meta[1]; + SpaMeta metas[1]; SpaMetaHeader header; - SpaData data[1]; + SpaMem mems[1]; uint16_t samples[4096]; }; @@ -591,19 +591,19 @@ add_port_data (SpaAudioMixer *this, SpaBuffer *out, SpaAudioMixerPort *port) int i, oi = 0; uint8_t *op, *ip; size_t os, is, chunk; - SpaData *odatas = out->datas; - SpaData *idatas = port->buffer->datas; + SpaMem *omems = out->mems; + SpaMem *imems = port->buffer->mems; op = ip = NULL; while (true) { if (op == NULL) { - op = (uint8_t*)odatas[oi].data + odatas[oi].offset; - os = odatas[oi].size; + op = (uint8_t*)omems[oi].ptr + omems[oi].chunk->offset; + os = omems[oi].chunk->size; } if (ip == NULL) { - ip = (uint8_t*)idatas[port->buffer_index].data + idatas[port->buffer_index].offset; - is = idatas[port->buffer_index].size; + ip = (uint8_t*)imems[port->buffer_index].ptr + imems[port->buffer_index].chunk->offset; + is = imems[port->buffer_index].chunk->size; ip += port->buffer_offset; is -= port->buffer_offset; } @@ -614,7 +614,7 @@ add_port_data (SpaAudioMixer *this, SpaBuffer *out, SpaAudioMixerPort *port) op[i] += ip[i]; if ((is -= chunk) == 0) { - if (++port->buffer_index == port->buffer->n_datas) { + if (++port->buffer_index == port->buffer->n_mems) { port->buffer = NULL; ((SpaPortInput*)port->io)->flags = SPA_PORT_STATUS_FLAG_NEED_INPUT; ((SpaPortOutput*)this->out_ports[0].io)->flags = SPA_PORT_STATUS_FLAG_HAVE_OUTPUT; @@ -628,7 +628,7 @@ add_port_data (SpaAudioMixer *this, SpaBuffer *out, SpaAudioMixerPort *port) port->buffer_queued -= chunk; if ((os -= chunk) == 0) { - if (++oi == out->n_datas) + if (++oi == out->n_mems) break; op = NULL; } diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 11a024b6..8f8879d7 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -675,23 +675,23 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node, for (i = 0; i < n_buffers; i++) { ATSBuffer *b; - SpaData *d = buffers[i]->datas; + SpaMem *m = buffers[i]->mems; b = &this->buffers[i]; b->outbuf = buffers[i]; 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 (m[0].type) { + case SPA_MEM_TYPE_MEMPTR: + case SPA_MEM_TYPE_MEMFD: + case SPA_MEM_TYPE_DMABUF: + if (m[0].ptr == 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 = m[0].ptr; + b->size = m[0].size; break; default: break; diff --git a/spa/plugins/ffmpeg/ffmpeg-enc.c b/spa/plugins/ffmpeg/ffmpeg-enc.c index b555c437..c6152aaa 100644 --- a/spa/plugins/ffmpeg/ffmpeg-enc.c +++ b/spa/plugins/ffmpeg/ffmpeg-enc.c @@ -48,7 +48,7 @@ struct _FFMpegBuffer { SpaBuffer buffer; SpaMeta metas[1]; SpaMetaHeader header; - SpaData datas[1]; + SpaMem mems[1]; SpaFFMpegEnc *enc; SpaBuffer *imported; bool outstanding; diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index 9dafb5f9..cbd717e6 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -61,7 +61,6 @@ struct _V4l2Buffer { bool outstanding; bool allocated; struct v4l2_buffer v4l2_buffer; -// V4l2Buffer *next; SpaList list; }; diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index de291aa1..79a40beb 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -116,11 +116,11 @@ spa_v4l2_clear_buffers (SpaV4l2Source *this) 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 (b->outbuf->mems[0].ptr) + munmap (b->outbuf->mems[0].ptr, b->outbuf->mems[0].size); + if (b->outbuf->mems[0].fd != -1) + close (b->outbuf->mems[0].fd); + b->outbuf->mems[0].type = SPA_MEM_TYPE_INVALID; } } @@ -840,7 +840,7 @@ mmap_read (SpaV4l2Source *this) SpaV4l2State *state = &this->state[0]; struct v4l2_buffer buf; V4l2Buffer *b; - SpaData *d; + SpaMemChunk *mc; int64_t pts; CLEAR(buf); @@ -875,8 +875,10 @@ mmap_read (SpaV4l2Source *this) b->h->pts = pts; } - d = b->outbuf->datas; - d[0].size = buf.bytesused; + mc = b->outbuf->mems[0].chunk; + mc->offset = 0; + mc->size = buf.bytesused; + mc->stride = state->fmt.fmt.pix.bytesperline; spa_list_insert (state->ready.prev, &b->list); @@ -910,15 +912,14 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe SpaV4l2State *state = &this->state[0]; struct v4l2_requestbuffers reqbuf; int i; - SpaData *d; if (n_buffers > 0) { - switch (buffers[0]->datas[0].type) { - case SPA_DATA_TYPE_MEMPTR: - case SPA_DATA_TYPE_MEMFD: + switch (buffers[0]->mems[0].type) { + 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: @@ -944,6 +945,7 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe for (i = 0; i < reqbuf.count; i++) { V4l2Buffer *b; + SpaMem *m; b = &state->buffers[i]; b->outbuf = buffers[i]; @@ -953,28 +955,28 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe spa_log_info (state->log, "v4l2: import buffer %p", buffers[i]); - if (buffers[i]->n_datas < 1) { + if (buffers[i]->n_mems < 1) { spa_log_error (state->log, "v4l2: invalid memory on buffer %p", buffers[i]); continue; } - d = buffers[i]->datas; + m = buffers[i]->mems; CLEAR (b->v4l2_buffer); 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 (m[0].type) { + case SPA_MEM_TYPE_MEMPTR: + case SPA_MEM_TYPE_MEMFD: + if (m[0].ptr == 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_MEMBER (m[0].ptr, m[0].offset, void *); + b->v4l2_buffer.length = m[0].size; break; - case SPA_DATA_TYPE_DMABUF: - b->v4l2_buffer.m.fd = d[0].fd; + case SPA_MEM_TYPE_DMABUF: + b->v4l2_buffer.m.fd = m[0].fd; break; default: break; @@ -1021,9 +1023,9 @@ mmap_init (SpaV4l2Source *this, for (i = 0; i < reqbuf.count; i++) { V4l2Buffer *b; - SpaData *d; + SpaMem *m; - if (buffers[i]->n_datas < 1) { + if (buffers[i]->n_mems < 1) { spa_log_error (state->log, "v4l2: invalid buffer data"); return SPA_RESULT_ERROR; } @@ -1044,11 +1046,9 @@ mmap_init (SpaV4l2Source *this, return SPA_RESULT_ERROR; } - 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; + m = buffers[i]->mems; + m[0].flags = SPA_MEM_FLAG_READ; + m[0].size = b->v4l2_buffer.length; if (state->export_buf) { struct v4l2_exportbuffer expbuf; @@ -1061,19 +1061,20 @@ mmap_init (SpaV4l2Source *this, perror("VIDIOC_EXPBUF"); continue; } - d[0].type = SPA_DATA_TYPE_DMABUF; - d[0].fd = expbuf.fd; - d[0].data = NULL; + m[0].type = SPA_MEM_TYPE_DMABUF; + m[0].fd = expbuf.fd; + m[0].offset = 0; + m[0].ptr = 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) { + m[0].type = SPA_MEM_TYPE_MEMPTR; + m[0].fd = -1; + m[0].ptr = mmap (NULL, + b->v4l2_buffer.length, + PROT_READ, + MAP_SHARED, + state->fd, + b->v4l2_buffer.m.offset); + if (m[0].ptr == MAP_FAILED) { perror ("mmap"); continue; } diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index be8cf93b..7a2dfecd 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -57,7 +57,6 @@ struct _VTSBuffer { bool outstanding; SpaMetaHeader *h; void *ptr; - size_t stride; SpaList list; }; @@ -642,23 +641,22 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node, for (i = 0; i < n_buffers; i++) { VTSBuffer *b = &this->buffers[i]; - SpaData *d = buffers[i]->datas; + SpaMem *m = buffers[i]->mems; b = &this->buffers[i]; b->outbuf = buffers[i]; 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 (m[0].type) { + case SPA_MEM_TYPE_MEMPTR: + case SPA_MEM_TYPE_MEMFD: + case SPA_MEM_TYPE_DMABUF: + if (m[0].ptr == 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 = m[0].ptr; break; default: break; diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index 4a64e8d4..b5318ddd 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -543,7 +543,7 @@ spa_volume_node_process_output (SpaNode *node) SpaVolumePort *port; unsigned int si, di, i, n_samples, n_bytes, soff, doff ; SpaBuffer *sbuf, *dbuf; - SpaData *sd, *dd; + SpaMem *sm, *dm; uint16_t *src, *dst; double volume; SpaPortInput *input; @@ -576,16 +576,16 @@ spa_volume_node_process_output (SpaNode *node) soff = doff = 0; while (true) { - if (si == sbuf->n_datas || di == dbuf->n_datas) + if (si == sbuf->n_mems || di == dbuf->n_mems) break; - sd = &sbuf->datas[si]; - dd = &dbuf->datas[di]; + sm = &sbuf->mems[si]; + dm = &sbuf->mems[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*)sm->ptr + sm->chunk->offset + soff); + dst = (uint16_t*) ((uint8_t*)dm->ptr + dm->chunk->offset + doff); - n_bytes = SPA_MIN (sd->size - soff, dd->size - doff); + n_bytes = SPA_MIN (sm->chunk->size - soff, dm->chunk->size - 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 >= sm->chunk->size) { si++; soff = 0; } - if (doff >= dd->size) { + if (doff >= dm->chunk->size) { di++; doff = 0; } diff --git a/spa/plugins/xv/xv-sink.c b/spa/plugins/xv/xv-sink.c index 12e0a593..f1be7700 100644 --- a/spa/plugins/xv/xv-sink.c +++ b/spa/plugins/xv/xv-sink.c @@ -55,7 +55,7 @@ struct _XvBuffer { SpaBuffer buffer; SpaMeta meta[1]; SpaMetaHeader header; - SpaData data[1]; + SpaMem mems[1]; XvBuffer *next; uint32_t index; SpaXvSink *sink; |