node: add driver position struct

Pass driver info to client
use current buffersize and samplerate in client
update the buffer size dynamically based on session
This commit is contained in:
Wim Taymans 2018-05-11 10:13:37 +02:00
parent 2c6ff2dad2
commit bed26040ef
9 changed files with 168 additions and 11 deletions

View file

@ -150,6 +150,8 @@ struct impl {
int fds[2];
int other_fds[2];
struct pw_client_node_position *position;
};
/** \endcond */
@ -890,14 +892,21 @@ impl_node_port_send_command(struct spa_node *node,
static int impl_node_process(struct spa_node *node)
{
struct node *this = SPA_CONTAINER_OF(node, struct node, node);
struct impl *impl = this->impl;
struct pw_driver_quantum *q;
uint64_t cmd = 1;
if (this->impl->this.status != SPA_ID_INVALID) {
spa_log_trace(this->log, "%p: return %d", this, this->impl->this.status);
return this->impl->this.status;
return impl->this.status;
}
spa_log_trace(this->log, "%p: send process", this);
spa_log_trace(this->log, "%p: send process %p", this, impl->this.node->driver_node);
q = impl->this.node->driver_node->rt.quantum;
impl->position->duration = q->size;
impl->position->rate = q->rate;
if (write(this->writefd, &cmd, 8) != 8)
spa_log_warn(this->log, "node %p: error %s", this, strerror(errno));
@ -1148,6 +1157,8 @@ static void node_initialized(void *data)
struct pw_type *t = impl->t;
struct pw_global *global;
uint32_t node_id;
uint32_t area_size, size;
struct mem *m;
if (this->resource == NULL)
return;
@ -1162,14 +1173,20 @@ static void node_initialized(void *data)
spa_loop_add_source(impl->node.data_loop, &impl->node.data_source);
pw_log_debug("client-node %p: transport fd %d %d", node, impl->fds[0], impl->fds[1]);
area_size = sizeof(struct spa_io_buffers) * MAX_AREAS;
size = area_size + sizeof(struct pw_client_node_position);
if (pw_memblock_alloc(PW_MEMBLOCK_FLAG_WITH_FD |
PW_MEMBLOCK_FLAG_MAP_READWRITE |
PW_MEMBLOCK_FLAG_SEAL,
sizeof(struct spa_io_buffers) * MAX_AREAS,
size,
&impl->io_areas) < 0)
return;
ensure_mem(impl, impl->io_areas->fd, t->data.MemFd, impl->io_areas->flags);
impl->position = SPA_MEMBER(impl->io_areas->ptr,
area_size, struct pw_client_node_position);
m = ensure_mem(impl, impl->io_areas->fd, t->data.MemFd, impl->io_areas->flags);
pw_log_debug("client-node %p: io areas %p", node, impl->io_areas->ptr);
if ((global = pw_node_get_global(node)) != NULL)
@ -1181,6 +1198,11 @@ static void node_initialized(void *data)
node_id,
impl->other_fds[0],
impl->other_fds[1]);
pw_client_node_resource_set_position(this->resource,
m->id,
area_size,
sizeof(struct pw_client_node_position));
}
static void node_free(void *data)

View file

@ -98,6 +98,7 @@ struct impl {
struct pw_port_mix client_port_mix;
struct spa_io_buffers *io;
struct spa_io_control_range ctrl;
struct spa_buffer **buffers;
uint32_t n_buffers;
@ -249,16 +250,29 @@ impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t
{
struct node *this;
struct impl *impl;
struct pw_type *t;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
t = impl->t;
if (direction != impl->direction)
return -EINVAL;
return spa_node_add_port(impl->adapter, direction, port_id);
if ((res = spa_node_add_port(impl->adapter, direction, port_id)) < 0)
return res;
if ((res = spa_node_port_set_io(impl->adapter,
direction, port_id,
t->io.ControlRange,
&impl->ctrl,
sizeof(&impl->ctrl))) < 0)
return res;
return res;
}
static int
@ -670,10 +684,16 @@ static int impl_node_process(struct spa_node *node)
struct impl *impl = this->impl;
int status;
spa_log_trace(this->log, "%p: process", this);
impl->client_node->node->driver_node = impl->this.node->driver_node;
impl->ctrl.min_size = impl->ctrl.max_size =
impl->this.node->driver_node->rt.quantum->size;
if (impl->use_converter)
spa_log_trace(this->log, "%p: process %d", this, impl->ctrl.max_size);
if (impl->use_converter) {
status = spa_node_process(impl->adapter);
}
else {
status = SPA_STATUS_HAVE_BUFFER | SPA_STATUS_NEED_BUFFER;
spa_log_trace(this->log, "%p: process %d/%d %d/%d", this,
@ -841,6 +861,7 @@ static void client_node_initialized(void *data)
impl->client_port_mix.io,
sizeof(impl->client_port_mix.io))) < 0)
return;
}
pw_node_register(impl->this.node, NULL, NULL, NULL);

View file

@ -432,6 +432,25 @@ static int client_node_demarshal_port_set_io(void *object, void *data, size_t si
return 0;
}
static int client_node_demarshal_set_position(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
uint32_t memid, off, sz;
spa_pod_parser_init(&prs, data, size, 0);
if (spa_pod_parser_get(&prs,
"["
"i", &memid,
"i", &off,
"i", &sz, NULL) < 0)
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, set_position,
memid, off, sz);
return 0;
}
static void
client_node_marshal_add_mem(void *object,
uint32_t mem_id,
@ -671,6 +690,22 @@ client_node_marshal_port_set_io(void *object,
pw_protocol_native_end_resource(resource, b);
}
static void
client_node_marshal_set_position(void *object,
uint32_t memid,
uint32_t offset,
uint32_t size)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_SET_POSITION);
spa_pod_builder_struct(b,
"i", memid,
"i", offset,
"i", size);
pw_protocol_native_end_resource(resource, b);
}
static int client_node_demarshal_done(void *object, void *data, size_t size)
{
@ -857,6 +892,7 @@ static const struct pw_client_node_proxy_events pw_protocol_native_client_node_e
&client_node_marshal_port_use_buffers,
&client_node_marshal_port_command,
&client_node_marshal_port_set_io,
&client_node_marshal_set_position,
};
static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_event_demarshal[] = {
@ -871,6 +907,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_
{ &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 },
{ &client_node_demarshal_set_position, PW_PROTOCOL_NATIVE_REMAP },
};
static const struct pw_protocol_marshal pw_protocol_native_client_node_marshal = {