mem: remove memory stuff

Remove the memory stuff from the spa API, we can do thing more simple
and efficiently if we always allocate buffers outside of the plugins and
only implement an alloc function on the node when it can do something
clever.
Move serialize code to the props/format/buffer code
Make it possible to copy a format and properties.
This commit is contained in:
Wim Taymans 2016-09-29 18:18:59 +02:00
parent fe37e2bc1b
commit 24108e01c1
46 changed files with 901 additions and 1546 deletions

View file

@ -45,13 +45,11 @@ typedef struct {
bool live;
} SpaVideoTestSrcProps;
#define MAX_BUFFERS 16
typedef struct _VTSBuffer VTSBuffer;
struct _VTSBuffer {
SpaBuffer buffer;
SpaMeta metas[1];
SpaMetaHeader header;
SpaData datas[1];
SpaBuffer *outbuf;
bool outstanding;
VTSBuffer *next;
@ -86,8 +84,7 @@ struct _SpaVideoTestSrc {
size_t bpp;
bool have_buffers;
SpaMemory *alloc_mem;
VTSBuffer *alloc_buffers;
VTSBuffer buffers[MAX_BUFFERS];
unsigned int n_buffers;
bool started;
@ -158,7 +155,7 @@ spa_videotestsrc_node_set_props (SpaNode *node,
if (props == NULL) {
res = reset_videotestsrc_props (p);
} else {
res = spa_props_copy (props, &p->props);
res = spa_props_copy_values (props, &p->props);
}
if (this->props[1].live)
@ -476,13 +473,8 @@ clear_buffers (SpaVideoTestSrc *this)
{
if (this->have_buffers) {
fprintf (stderr, "videotestsrc %p: clear buffers\n", this);
if (this->alloc_mem)
spa_memory_unref (&this->alloc_mem->mem);
this->alloc_mem = NULL;
this->alloc_buffers = NULL;
this->n_buffers = 0;
this->have_buffers = false;
this->info.flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
SPA_QUEUE_INIT (&this->empty);
SPA_QUEUE_INIT (&this->ready);
}
@ -627,23 +619,12 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node,
if (buffers != NULL && n_buffers != 0) {
unsigned int i, j;
this->alloc_mem = spa_memory_alloc_size (SPA_MEMORY_POOL_LOCAL,
NULL,
sizeof (VTSBuffer) * n_buffers);
this->alloc_buffers = spa_memory_ensure_ptr (this->alloc_mem);
for (i = 0; i < n_buffers; i++) {
VTSBuffer *b;
SpaMemoryRef *mem_ref;
SpaMemory *mem;
SpaData *d = SPA_BUFFER_DATAS (buffers[i]);
SpaMeta *m = SPA_BUFFER_METAS (buffers[i]);
VTSBuffer *b = &this->buffers[i];
SpaData *d = buffers[i]->datas;
SpaMeta *m = buffers[i]->metas;
b = &this->alloc_buffers[i];
b->buffer.mem.mem = this->alloc_mem->mem;
b->buffer.mem.offset = sizeof (VTSBuffer) * i;
b->buffer.mem.size = sizeof (VTSBuffer);
b->buffer.id = SPA_ID_INVALID;
b = &this->buffers[i];
b->outbuf = buffers[i];
b->outstanding = true;
b->h = NULL;
@ -651,19 +632,18 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node,
for (j = 0; j < buffers[i]->n_metas; j++) {
switch (m[j].type) {
case SPA_META_TYPE_HEADER:
b->h = SPA_MEMBER (buffers[i], m[j].offset, SpaMetaHeader);
b->h = m[j].data;
break;
default:
break;
}
}
mem_ref = &d[0].mem.mem;
if (!(mem = spa_memory_find (mem_ref))) {
if (d[0].type != SPA_DATA_TYPE_MEMPTR) {
fprintf (stderr, "videotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
continue;
}
b->ptr = SPA_MEMBER (spa_memory_ensure_ptr (mem), d[0].mem.offset, void);
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
b->stride = d[0].stride;
b->next = NULL;
@ -713,7 +693,7 @@ spa_videotestsrc_node_port_alloc_buffers (SpaNode *node,
*n_buffers = SPA_MIN (*n_buffers, this->n_buffers);
for (i = 0; i < *n_buffers; i++)
buffers[i] = this->alloc_buffers[i].outbuf;
buffers[i] = this->buffers[i].outbuf;
return SPA_RESULT_OK;
}
@ -740,7 +720,7 @@ spa_videotestsrc_node_port_reuse_buffer (SpaNode *node,
if (buffer_id >= this->n_buffers)
return SPA_RESULT_INVALID_BUFFER_ID;
b = &this->alloc_buffers[buffer_id];
b = &this->buffers[buffer_id];
if (!b->outstanding)
return SPA_RESULT_OK;