client-node: move to per node memory

Remove the per-port memory and only use per-node memory. This will
make it possible to share memory between ports in the future.
Keep refs to memory on the buffers and free (close) the memory
when no longer used.
This commit is contained in:
Wim Taymans 2017-12-01 17:24:03 +01:00
parent 4019da39c1
commit c1aa3b4625
6 changed files with 218 additions and 199 deletions

View file

@ -68,8 +68,6 @@ struct buffer {
struct spa_buffer buffer;
struct spa_meta metas[4];
struct spa_data datas[4];
off_t offset;
size_t size;
bool outstanding;
};
@ -540,11 +538,10 @@ spa_proxy_node_port_set_io(struct spa_node *node,
if ((mem = pw_memblock_find(data)) == NULL)
return -EINVAL;
pw_client_node_resource_port_add_mem(this->resource,
direction, port_id,
memid,
t->data.MemFd,
mem->fd, mem->flags);
pw_client_node_resource_add_mem(this->resource,
memid,
t->data.MemFd,
mem->fd, mem->flags);
pw_client_node_resource_port_set_io(this->resource,
this->seq,
@ -567,7 +564,6 @@ spa_proxy_node_port_use_buffers(struct spa_node *node,
struct impl *impl;
struct port *port;
uint32_t i, j;
size_t n_mem;
struct pw_client_node_buffer *mb;
struct pw_type *t;
@ -598,11 +594,10 @@ spa_proxy_node_port_use_buffers(struct spa_node *node,
if (this->resource == NULL)
return 0;
n_mem = this->membase;
for (i = 0; i < n_buffers; i++) {
struct buffer *b = &port->buffers[i];
struct pw_memblock *m;
size_t data_size;
size_t data_size, size;
void *baseptr;
b->outbuf = buffers[i];
@ -632,21 +627,20 @@ spa_proxy_node_port_use_buffers(struct spa_node *node,
}
mb[i].buffer = &b->buffer;
mb[i].mem_id = n_mem++;
mb[i].mem_id = this->membase++;
mb[i].offset = SPA_PTRDIFF(baseptr, m->ptr + m->offset);
mb[i].size = data_size;
pw_client_node_resource_port_add_mem(this->resource,
direction,
port_id,
mb[i].mem_id,
t->data.MemFd,
m->fd, m->flags);
pw_client_node_resource_add_mem(this->resource,
mb[i].mem_id,
t->data.MemFd,
m->fd, m->flags);
for (j = 0; j < buffers[i]->n_metas; j++)
memcpy(&b->buffer.metas[j], &buffers[i]->metas[j], sizeof(struct spa_meta));
b->buffer.n_metas = j;
size = 0;
for (j = 0; j < buffers[i]->n_datas; j++) {
struct spa_data *d = &buffers[i]->datas[j];
@ -654,18 +648,16 @@ spa_proxy_node_port_use_buffers(struct spa_node *node,
if (d->type == t->data.DmaBuf ||
d->type == t->data.MemFd) {
pw_client_node_resource_port_add_mem(this->resource,
direction,
port_id,
n_mem,
d->type,
d->fd,
d->flags);
b->buffer.datas[j].data = SPA_UINT32_TO_PTR(n_mem);
n_mem++;
pw_client_node_resource_add_mem(this->resource,
this->membase,
d->type,
d->fd,
d->flags);
b->buffer.datas[j].data = SPA_UINT32_TO_PTR(this->membase);
this->membase++;
} else if (d->type == t->data.MemPtr) {
b->buffer.datas[j].data = SPA_INT_TO_PTR(b->size);
b->size += d->maxsize;
b->buffer.datas[j].data = SPA_INT_TO_PTR(size);
size += d->maxsize;
} else {
b->buffer.datas[j].type = SPA_ID_INVALID;
b->buffer.datas[j].data = 0;

View file

@ -149,6 +149,31 @@ static void client_node_marshal_destroy(void *object)
pw_protocol_native_end_proxy(proxy, b);
}
static bool client_node_demarshal_add_mem(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
uint32_t mem_id, type, memfd_idx, flags;
int memfd;
spa_pod_parser_init(&prs, data, size, 0);
if (spa_pod_parser_get(&prs,
"["
"i", &mem_id,
"I", &type,
"i", &memfd_idx,
"i", &flags, NULL) < 0)
return false;
memfd = pw_protocol_native_get_proxy_fd(proxy, memfd_idx);
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, add_mem,
mem_id,
type,
memfd, flags);
return true;
}
static bool client_node_demarshal_transport(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
@ -294,34 +319,6 @@ static bool client_node_demarshal_port_set_param(void *object, void *data, size_
return true;
}
static bool client_node_demarshal_port_add_mem(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
uint32_t direction, port_id, mem_id, type, memfd_idx, flags;
int memfd;
spa_pod_parser_init(&prs, data, size, 0);
if (spa_pod_parser_get(&prs,
"["
"i", &direction,
"i", &port_id,
"i", &mem_id,
"I", &type,
"i", &memfd_idx,
"i", &flags, NULL) < 0)
return false;
memfd = pw_protocol_native_get_proxy_fd(proxy, memfd_idx);
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, port_add_mem, direction,
port_id,
mem_id,
type,
memfd, flags);
return true;
}
static bool client_node_demarshal_port_use_buffers(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
@ -432,6 +429,26 @@ static bool client_node_demarshal_port_set_io(void *object, void *data, size_t s
return true;
}
static void
client_node_marshal_add_mem(void *object,
uint32_t mem_id,
uint32_t type,
int memfd, uint32_t flags)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_ADD_MEM);
spa_pod_builder_struct(b,
"i", mem_id,
"I", type,
"i", pw_protocol_native_add_resource_fd(resource, memfd),
"i", flags);
pw_protocol_native_end_resource(resource, b);
}
static void client_node_marshal_transport(void *object, uint32_t node_id, int readfd, int writefd,
struct pw_client_node_transport *transport)
{
@ -556,30 +573,6 @@ client_node_marshal_port_set_param(void *object,
pw_protocol_native_end_resource(resource, b);
}
static void
client_node_marshal_port_add_mem(void *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t mem_id,
uint32_t type,
int memfd, uint32_t flags)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_PORT_ADD_MEM);
spa_pod_builder_struct(b,
"i", direction,
"i", port_id,
"i", mem_id,
"I", type,
"i", pw_protocol_native_add_resource_fd(resource, memfd),
"i", flags);
pw_protocol_native_end_resource(resource, b);
}
static void
client_node_marshal_port_use_buffers(void *object,
uint32_t seq,
@ -838,6 +831,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_
static const struct pw_client_node_proxy_events pw_protocol_native_client_node_event_marshal = {
PW_VERSION_CLIENT_NODE_PROXY_EVENTS,
&client_node_marshal_add_mem,
&client_node_marshal_transport,
&client_node_marshal_set_param,
&client_node_marshal_event_event,
@ -845,13 +839,13 @@ static const struct pw_client_node_proxy_events pw_protocol_native_client_node_e
&client_node_marshal_add_port,
&client_node_marshal_remove_port,
&client_node_marshal_port_set_param,
&client_node_marshal_port_add_mem,
&client_node_marshal_port_use_buffers,
&client_node_marshal_port_command,
&client_node_marshal_port_set_io,
};
static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_event_demarshal[] = {
{ &client_node_demarshal_add_mem, PW_PROTOCOL_NATIVE_REMAP },
{ &client_node_demarshal_transport, 0 },
{ &client_node_demarshal_set_param, PW_PROTOCOL_NATIVE_REMAP },
{ &client_node_demarshal_event_event, PW_PROTOCOL_NATIVE_REMAP },
@ -859,7 +853,6 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_
{ &client_node_demarshal_add_port, 0 },
{ &client_node_demarshal_remove_port, 0 },
{ &client_node_demarshal_port_set_param, PW_PROTOCOL_NATIVE_REMAP },
{ &client_node_demarshal_port_add_mem, PW_PROTOCOL_NATIVE_REMAP },
{ &client_node_demarshal_port_use_buffers, PW_PROTOCOL_NATIVE_REMAP },
{ &client_node_demarshal_port_command, PW_PROTOCOL_NATIVE_REMAP },
{ &client_node_demarshal_port_set_io, PW_PROTOCOL_NATIVE_REMAP },