mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-10 13:30:05 -05:00
spa: make events and commands as objects
So we can serialize and introspect them more easily
This commit is contained in:
parent
4c4c0f2a7f
commit
c951264fff
26 changed files with 423 additions and 327 deletions
|
|
@ -130,13 +130,8 @@ typedef struct
|
|||
static void
|
||||
send_async_complete (SpaProxy *this, uint32_t seq, SpaResult res)
|
||||
{
|
||||
SpaNodeEventAsyncComplete ac;
|
||||
|
||||
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
|
||||
ac.event.size = sizeof (ac);
|
||||
ac.seq = seq;
|
||||
ac.res = res;
|
||||
this->event_cb (&this->node, &ac.event, this->user_data);
|
||||
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
|
||||
this->event_cb (&this->node, (SpaNodeEvent *)&ac, this->user_data);
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -170,11 +165,9 @@ static void
|
|||
send_need_input (SpaProxy *this)
|
||||
{
|
||||
PinosNode *pnode = this->pnode;
|
||||
SpaNodeEvent event;
|
||||
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_NEED_INPUT);
|
||||
uint64_t cmd = 1;
|
||||
|
||||
event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT;
|
||||
event.size = sizeof (event);
|
||||
pinos_transport_add_event (pnode->transport, &event);
|
||||
write (this->data_source.fd, &cmd, 8);
|
||||
}
|
||||
|
|
@ -183,11 +176,9 @@ static void
|
|||
send_have_output (SpaProxy *this)
|
||||
{
|
||||
PinosNode *pnode = this->pnode;
|
||||
SpaNodeEvent event;
|
||||
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
|
||||
uint64_t cmd = 1;
|
||||
|
||||
event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
|
||||
event.size = sizeof (event);
|
||||
pinos_transport_add_event (pnode->transport, &event);
|
||||
write (this->data_source.fd, &cmd, 8);
|
||||
}
|
||||
|
|
@ -207,7 +198,7 @@ spa_proxy_node_send_command (SpaNode *node,
|
|||
if (this->resource == NULL)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
switch (command->type) {
|
||||
switch (SPA_NODE_COMMAND_TYPE (command)) {
|
||||
case SPA_NODE_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
||||
|
|
@ -220,7 +211,7 @@ spa_proxy_node_send_command (SpaNode *node,
|
|||
pinos_client_node_notify_node_command (this->resource,
|
||||
this->seq,
|
||||
command);
|
||||
if (command->type == SPA_NODE_COMMAND_START)
|
||||
if (SPA_NODE_COMMAND_TYPE (command) == SPA_NODE_COMMAND_START)
|
||||
send_need_input (this);
|
||||
|
||||
res = SPA_RESULT_RETURN_ASYNC (this->seq++);
|
||||
|
|
@ -774,7 +765,6 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
|
|||
uint32_t buffer_id)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaNodeEventReuseBuffer rb;
|
||||
PinosNode *pnode;
|
||||
//uint64_t cmd = 1;
|
||||
|
||||
|
|
@ -787,12 +777,11 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
|
|||
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
|
||||
rb.event.size = sizeof (rb);
|
||||
rb.port_id = port_id;
|
||||
rb.buffer_id = buffer_id;
|
||||
pinos_transport_add_event (pnode->transport, &rb.event);
|
||||
//write (this->data_source.fd, &cmd, 8);
|
||||
{
|
||||
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (port_id, buffer_id);
|
||||
pinos_transport_add_event (pnode->transport, (SpaNodeEvent *)&rb);
|
||||
//write (this->data_source.fd, &cmd, 8);
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -811,7 +800,7 @@ spa_proxy_node_port_send_command (SpaNode *node,
|
|||
|
||||
this = SPA_CONTAINER_OF (node, SpaProxy, node);
|
||||
|
||||
switch (command->type) {
|
||||
switch (SPA_NODE_COMMAND_TYPE (command)) {
|
||||
case SPA_NODE_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
||||
|
|
@ -823,7 +812,7 @@ spa_proxy_node_port_send_command (SpaNode *node,
|
|||
break;
|
||||
|
||||
default:
|
||||
spa_log_warn (this->log, "unhandled command %d", command->type);
|
||||
spa_log_warn (this->log, "unhandled command %d", SPA_NODE_COMMAND_TYPE (command));
|
||||
res = SPA_RESULT_NOT_IMPLEMENTED;
|
||||
break;
|
||||
}
|
||||
|
|
@ -864,18 +853,18 @@ static SpaResult
|
|||
handle_node_event (SpaProxy *this,
|
||||
SpaNodeEvent *event)
|
||||
{
|
||||
switch (event->type) {
|
||||
case SPA_NODE_EVENT_TYPE_INVALID:
|
||||
switch (SPA_NODE_EVENT_TYPE (event)) {
|
||||
case SPA_NODE_EVENT_INVALID:
|
||||
break;
|
||||
|
||||
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
|
||||
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
|
||||
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
|
||||
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
|
||||
case SPA_NODE_EVENT_TYPE_ERROR:
|
||||
case SPA_NODE_EVENT_TYPE_BUFFERING:
|
||||
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
|
||||
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE:
|
||||
case SPA_NODE_EVENT_ASYNC_COMPLETE:
|
||||
case SPA_NODE_EVENT_HAVE_OUTPUT:
|
||||
case SPA_NODE_EVENT_NEED_INPUT:
|
||||
case SPA_NODE_EVENT_REUSE_BUFFER:
|
||||
case SPA_NODE_EVENT_ERROR:
|
||||
case SPA_NODE_EVENT_BUFFERING:
|
||||
case SPA_NODE_EVENT_REQUEST_REFRESH:
|
||||
case SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE:
|
||||
this->event_cb (&this->node, event, this->user_data);
|
||||
break;
|
||||
}
|
||||
|
|
@ -1004,7 +993,7 @@ proxy_on_data_fd_events (SpaSource *source)
|
|||
read (this->data_source.fd, &cmd, 8);
|
||||
|
||||
while (pinos_transport_next_event (pnode->transport, &event) == SPA_RESULT_OK) {
|
||||
SpaNodeEvent *ev = alloca (event.size);
|
||||
SpaNodeEvent *ev = alloca (SPA_POD_SIZE (&event));
|
||||
pinos_transport_parse_event (pnode->transport, ev);
|
||||
this->event_cb (&this->node, ev, this->user_data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,17 +161,16 @@ static SpaResult
|
|||
pause_node (PinosNode *this)
|
||||
{
|
||||
SpaResult res;
|
||||
SpaNodeCommand cmd;
|
||||
|
||||
if (this->node->state <= SPA_NODE_STATE_PAUSED)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
pinos_log_debug ("node %p: pause node", this);
|
||||
cmd.type = SPA_NODE_COMMAND_PAUSE;
|
||||
cmd.size = sizeof (cmd);
|
||||
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
||||
pinos_log_debug ("got error %d", res);
|
||||
|
||||
{
|
||||
SpaNodeCommand cmd = SPA_NODE_COMMAND_INIT (SPA_NODE_COMMAND_PAUSE);
|
||||
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
||||
pinos_log_debug ("got error %d", res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -179,14 +178,13 @@ static SpaResult
|
|||
start_node (PinosNode *this)
|
||||
{
|
||||
SpaResult res;
|
||||
SpaNodeCommand cmd;
|
||||
|
||||
pinos_log_debug ("node %p: start node", this);
|
||||
cmd.type = SPA_NODE_COMMAND_START;
|
||||
cmd.size = sizeof (cmd);
|
||||
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
||||
pinos_log_debug ("got error %d", res);
|
||||
|
||||
{
|
||||
SpaNodeCommand cmd = SPA_NODE_COMMAND_INIT (SPA_NODE_COMMAND_START);
|
||||
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
||||
pinos_log_debug ("got error %d", res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -223,30 +221,31 @@ suspend_node (PinosNode *this)
|
|||
static void
|
||||
send_clock_update (PinosNode *this)
|
||||
{
|
||||
SpaNodeCommandClockUpdate cu;
|
||||
SpaResult res;
|
||||
SpaNodeCommandClockUpdate cu =
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_INIT(
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_TIME |
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_SCALE |
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_STATE |
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_LATENCY, /* change_mask */
|
||||
1, /* rate */
|
||||
0, /* ticks */
|
||||
0, /* monotonic_time */
|
||||
0, /* offset */
|
||||
(1 << 16) | 1, /* scale */
|
||||
SPA_CLOCK_STATE_RUNNING, /* state */
|
||||
0, /* flags */
|
||||
0); /* latency */
|
||||
|
||||
cu.command.type = SPA_NODE_COMMAND_CLOCK_UPDATE;
|
||||
cu.command.size = sizeof (cu);
|
||||
cu.flags = 0;
|
||||
cu.change_mask = SPA_NODE_COMMAND_CLOCK_UPDATE_TIME |
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_SCALE |
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_STATE |
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_LATENCY;
|
||||
if (this->clock && this->live) {
|
||||
cu.flags = SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE;
|
||||
res = spa_clock_get_time (this->clock, &cu.rate, &cu.ticks, &cu.monotonic_time);
|
||||
} else {
|
||||
cu.rate = 1;
|
||||
cu.ticks = 0;
|
||||
cu.monotonic_time = 0;
|
||||
cu.body.flags.value = SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE;
|
||||
res = spa_clock_get_time (this->clock,
|
||||
&cu.body.rate.value,
|
||||
&cu.body.ticks.value,
|
||||
&cu.body.monotonic_time.value);
|
||||
}
|
||||
cu.offset = 0;
|
||||
cu.scale = (1 << 16) | 1;
|
||||
cu.state = SPA_CLOCK_STATE_RUNNING;
|
||||
cu.latency = 0;
|
||||
|
||||
if ((res = spa_node_send_command (this->node, &cu.command)) < 0)
|
||||
if ((res = spa_node_send_command (this->node, (SpaNodeCommand *)&cu)) < 0)
|
||||
pinos_log_debug ("got error %d", res);
|
||||
}
|
||||
|
||||
|
|
@ -256,25 +255,25 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
PinosNode *this = user_data;
|
||||
PinosNodeImpl *impl = SPA_CONTAINER_OF (this, PinosNodeImpl, this);
|
||||
|
||||
switch (event->type) {
|
||||
case SPA_NODE_EVENT_TYPE_INVALID:
|
||||
case SPA_NODE_EVENT_TYPE_ERROR:
|
||||
case SPA_NODE_EVENT_TYPE_BUFFERING:
|
||||
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
|
||||
switch (SPA_NODE_EVENT_TYPE (event)) {
|
||||
case SPA_NODE_EVENT_INVALID:
|
||||
case SPA_NODE_EVENT_ERROR:
|
||||
case SPA_NODE_EVENT_BUFFERING:
|
||||
case SPA_NODE_EVENT_REQUEST_REFRESH:
|
||||
break;
|
||||
|
||||
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
|
||||
case SPA_NODE_EVENT_ASYNC_COMPLETE:
|
||||
{
|
||||
SpaNodeEventAsyncComplete *ac = (SpaNodeEventAsyncComplete *) event;
|
||||
|
||||
pinos_log_debug ("node %p: async complete event %d %d", this, ac->seq, ac->res);
|
||||
if (!pinos_work_queue_complete (impl->work, this, ac->seq, ac->res)) {
|
||||
pinos_signal_emit (&this->async_complete, this, ac->seq, ac->res);
|
||||
pinos_log_debug ("node %p: async complete event %d %d", this, ac->body.seq.value, ac->body.res.value);
|
||||
if (!pinos_work_queue_complete (impl->work, this, ac->body.seq.value, ac->body.res.value)) {
|
||||
pinos_signal_emit (&this->async_complete, this, ac->body.seq.value, ac->body.res.value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
|
||||
case SPA_NODE_EVENT_NEED_INPUT:
|
||||
{
|
||||
SpaResult res;
|
||||
int i;
|
||||
|
|
@ -320,7 +319,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
|
||||
case SPA_NODE_EVENT_HAVE_OUTPUT:
|
||||
{
|
||||
SpaResult res;
|
||||
int i;
|
||||
|
|
@ -365,10 +364,10 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
|
||||
case SPA_NODE_EVENT_REUSE_BUFFER:
|
||||
break;
|
||||
|
||||
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE:
|
||||
case SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE:
|
||||
send_clock_update (this);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,10 +206,7 @@ no_mem:
|
|||
static SpaResult
|
||||
pinos_port_pause (PinosPort *port)
|
||||
{
|
||||
SpaNodeCommand cmd;
|
||||
|
||||
cmd.type = SPA_NODE_COMMAND_PAUSE;
|
||||
cmd.size = sizeof (cmd);
|
||||
SpaNodeCommand cmd = SPA_NODE_COMMAND_INIT (SPA_NODE_COMMAND_PAUSE);
|
||||
return spa_node_port_send_command (port->node->node,
|
||||
port->direction,
|
||||
port->port_id,
|
||||
|
|
|
|||
|
|
@ -570,7 +570,7 @@ client_node_marshal_event (void *object,
|
|||
|
||||
spa_pod_builder_add (&b.b,
|
||||
SPA_POD_TYPE_STRUCT, &f,
|
||||
SPA_POD_TYPE_BYTES, event, event->size,
|
||||
SPA_POD_TYPE_POD, event,
|
||||
-SPA_POD_TYPE_STRUCT, &f, 0);
|
||||
|
||||
pinos_connection_end_write (connection, resource->id, 1, b.b.offset);
|
||||
|
|
@ -778,7 +778,7 @@ client_node_marshal_node_command (void *object,
|
|||
spa_pod_builder_add (&b.b,
|
||||
SPA_POD_TYPE_STRUCT, &f,
|
||||
SPA_POD_TYPE_INT, seq,
|
||||
SPA_POD_TYPE_BYTES, command, command->size,
|
||||
SPA_POD_TYPE_POD, command,
|
||||
-SPA_POD_TYPE_STRUCT, &f, 0);
|
||||
|
||||
pinos_connection_end_write (connection, resource->id, 8, b.b.offset);
|
||||
|
|
@ -799,7 +799,7 @@ client_node_marshal_port_command (void *object,
|
|||
spa_pod_builder_add (&b.b,
|
||||
SPA_POD_TYPE_STRUCT, &f,
|
||||
SPA_POD_TYPE_INT, port_id,
|
||||
SPA_POD_TYPE_BYTES, command, command->size,
|
||||
SPA_POD_TYPE_POD, command,
|
||||
-SPA_POD_TYPE_STRUCT, &f, 0);
|
||||
|
||||
pinos_connection_end_write (connection, resource->id, 9, b.b.offset);
|
||||
|
|
@ -959,10 +959,9 @@ client_node_demarshal_event (void *object,
|
|||
PinosResource *resource = object;
|
||||
SpaPODIter it;
|
||||
SpaNodeEvent *event;
|
||||
uint32_t sz;
|
||||
|
||||
if (!spa_pod_iter_struct (&it, data, size) ||
|
||||
!spa_pod_iter_get (&it, SPA_POD_TYPE_BYTES, &event, &sz, 0))
|
||||
!spa_pod_iter_get (&it, SPA_POD_TYPE_OBJECT, &event, 0))
|
||||
return false;
|
||||
|
||||
((PinosClientNodeMethods*)resource->implementation)->event (resource, event);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue