spa: make events and commands as objects

So we can serialize and introspect them more easily
This commit is contained in:
Wim Taymans 2017-03-15 16:21:05 +01:00
parent 4c4c0f2a7f
commit c951264fff
26 changed files with 423 additions and 327 deletions

View file

@ -578,7 +578,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);
@ -633,11 +633,10 @@ client_node_demarshal_event (void *object,
PinosProxy *proxy = object;
SpaPODIter it;
const SpaNodeEvent *event;
uint32_t s;
if (!spa_pod_iter_struct (&it, data, size) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_BYTES, &event, &s,
SPA_POD_TYPE_OBJECT, &event,
0))
return false;
@ -855,12 +854,12 @@ client_node_demarshal_node_command (void *object,
PinosProxy *proxy = object;
SpaPODIter it;
const SpaNodeCommand *command;
uint32_t seq, s;
uint32_t seq;
if (!spa_pod_iter_struct (&it, data, size) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &seq,
SPA_POD_TYPE_BYTES, &command, &s,
SPA_POD_TYPE_OBJECT, &command,
0))
return false;
@ -876,12 +875,12 @@ client_node_demarshal_port_command (void *object,
PinosProxy *proxy = object;
SpaPODIter it;
const SpaNodeCommand *command;
uint32_t port_id, s;
uint32_t port_id;
if (!spa_pod_iter_struct (&it, data, size) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &port_id,
SPA_POD_TYPE_BYTES, &command, &s,
SPA_POD_TYPE_OBJECT, &command,
0))
return false;

View file

@ -360,7 +360,7 @@ send_need_input (PinosStream *stream)
pinos_log_debug ("stream %p: need input", stream);
ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT;
ni.event.type = SPA_NODE_EVENT_NEED_INPUT;
ni.event.size = sizeof (ni);
pinos_transport_add_event (impl->trans, &ni.event);
write (impl->rtfd, &cmd, 8);
@ -377,7 +377,7 @@ send_have_output (PinosStream *stream)
pinos_log_debug ("stream %p: have output", stream);
ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
ho.event.type = SPA_NODE_EVENT_HAVE_OUTPUT;
ho.event.size = sizeof (ho);
pinos_transport_add_event (impl->trans, &ho.event);
write (impl->rtfd, &cmd, 8);
@ -388,15 +388,10 @@ static void
add_request_clock_update (PinosStream *stream, bool flush)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
SpaNodeEventRequestClockUpdate rcu;
SpaNodeEventRequestClockUpdate rcu =
SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_INIT (SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_TIME, 0, 0);
rcu.event.type = SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE;
rcu.event.size = sizeof (rcu);
rcu.update_mask = SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_TIME;
rcu.timestamp = 0;
rcu.offset = 0;
pinos_client_node_do_event (impl->node_proxy,
&rcu.event);
pinos_client_node_do_event (impl->node_proxy, (SpaNodeEvent*)&rcu);
}
static void
@ -406,14 +401,8 @@ add_async_complete (PinosStream *stream,
bool flush)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
SpaNodeEventAsyncComplete ac;
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
ac.event.size = sizeof (ac);
ac.seq = seq;
ac.res = res;
pinos_client_node_do_event (impl->node_proxy,
&ac.event);
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT(seq, res);
pinos_client_node_do_event (impl->node_proxy, (SpaNodeEvent*)&ac);
}
static void
@ -478,8 +467,8 @@ handle_rtnode_event (PinosStream *stream,
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
switch (event->type) {
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
switch (SPA_NODE_EVENT_TYPE (event)) {
case SPA_NODE_EVENT_HAVE_OUTPUT:
{
int i;
@ -498,29 +487,29 @@ handle_rtnode_event (PinosStream *stream,
break;
}
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
case SPA_NODE_EVENT_NEED_INPUT:
//pinos_log_debug ("stream %p: need input", stream);
pinos_signal_emit (&stream->need_buffer, stream);
break;
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
case SPA_NODE_EVENT_REUSE_BUFFER:
{
SpaNodeEventReuseBuffer *p = (SpaNodeEventReuseBuffer *) event;
BufferId *bid;
if (p->port_id != impl->port_id)
if (p->body.port_id.value != impl->port_id)
break;
if (impl->direction != SPA_DIRECTION_OUTPUT)
break;
if ((bid = find_buffer (stream, p->buffer_id)) && bid->used) {
if ((bid = find_buffer (stream, p->body.buffer_id.value)) && bid->used) {
bid->used = false;
pinos_signal_emit (&stream->new_buffer, stream, p->buffer_id);
pinos_signal_emit (&stream->new_buffer, stream, p->body.buffer_id.value);
}
break;
}
default:
pinos_log_warn ("unexpected node event %d", event->type);
pinos_log_warn ("unexpected node event %d", SPA_NODE_EVENT_TYPE (event));
break;
}
}
@ -547,7 +536,7 @@ on_rtsocket_condition (SpaSource *source,
read (impl->rtfd, &cmd, 8);
while (pinos_transport_next_event (impl->trans, &event) == SPA_RESULT_OK) {
SpaNodeEvent *ev = alloca (event.size);
SpaNodeEvent *ev = alloca (SPA_POD_SIZE (&event));
pinos_transport_parse_event (impl->trans, ev);
handle_rtnode_event (stream, ev);
}
@ -585,17 +574,17 @@ static void
handle_node_event (PinosStream *stream,
const SpaNodeEvent *event)
{
switch (event->type) {
case SPA_NODE_EVENT_TYPE_INVALID:
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
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:
pinos_log_warn ("unhandled node event %d", event->type);
switch (SPA_NODE_EVENT_TYPE (event)) {
case SPA_NODE_EVENT_INVALID:
case SPA_NODE_EVENT_HAVE_OUTPUT:
case SPA_NODE_EVENT_NEED_INPUT:
case SPA_NODE_EVENT_ASYNC_COMPLETE:
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:
pinos_log_warn ("unhandled node event %d", SPA_NODE_EVENT_TYPE (event));
break;
}
}
@ -607,7 +596,7 @@ handle_node_command (PinosStream *stream,
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
break;
case SPA_NODE_COMMAND_PAUSE:
@ -635,22 +624,22 @@ handle_node_command (PinosStream *stream,
case SPA_NODE_COMMAND_DRAIN:
case SPA_NODE_COMMAND_MARKER:
{
pinos_log_warn ("unhandled node command %d", command->type);
pinos_log_warn ("unhandled node command %d", SPA_NODE_COMMAND_TYPE (command));
add_async_complete (stream, seq, SPA_RESULT_NOT_IMPLEMENTED, true);
break;
}
case SPA_NODE_COMMAND_CLOCK_UPDATE:
{
SpaNodeCommandClockUpdate *cu = (SpaNodeCommandClockUpdate *) command;
if (cu->flags & SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE) {
if (cu->body.flags.value & SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE) {
pinos_properties_set (stream->properties,
"pinos.latency.is-live", "1");
pinos_properties_setf (stream->properties,
"pinos.latency.min", "%"PRId64, cu->latency);
"pinos.latency.min", "%"PRId64, cu->body.latency.value);
}
impl->last_ticks = cu->ticks;
impl->last_rate = cu->rate;
impl->last_monotonic = cu->monotonic_time;
impl->last_ticks = cu->body.ticks.value;
impl->last_rate = cu->body.rate.value;
impl->last_monotonic = cu->body.monotonic_time.value;
break;
}
}
@ -1000,7 +989,6 @@ pinos_stream_connect (PinosStream *stream,
"client-node",
&stream->properties->dict,
impl->node_proxy->id);
return true;
}
@ -1156,14 +1144,10 @@ pinos_stream_recycle_buffer (PinosStream *stream,
uint32_t id)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
SpaNodeEventReuseBuffer rb;
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (impl->port_id, id);
uint64_t cmd = 1;
rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
rb.event.size = sizeof (rb);
rb.port_id = impl->port_id;
rb.buffer_id = id;
pinos_transport_add_event (impl->trans, &rb.event);
pinos_transport_add_event (impl->trans, (SpaNodeEvent *)&rb);
write (impl->rtfd, &cmd, 8);
return true;

View file

@ -181,6 +181,10 @@ pinos_transport_destroy (PinosTransport *trans)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
pinos_log_debug ("transport %p: destroy", trans);
pinos_signal_emit (&trans->destroy_signal, trans);
pinos_memblock_free (&impl->mem);
free (impl);
}
@ -204,21 +208,22 @@ pinos_transport_add_event (PinosTransport *trans,
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
SpaRingbufferArea areas[2];
size_t avail;
size_t avail, size;
if (impl == NULL || event == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
size = SPA_POD_SIZE (event);
avail = spa_ringbuffer_get_write_areas (trans->output_buffer, areas);
if (avail < event->size)
if (avail < size)
return SPA_RESULT_ERROR;
spa_ringbuffer_write_data (trans->output_buffer,
trans->output_data,
areas,
event,
event->size);
spa_ringbuffer_write_advance (trans->output_buffer, event->size);
size);
spa_ringbuffer_write_advance (trans->output_buffer, size);
return SPA_RESULT_OK;
}
@ -253,16 +258,19 @@ pinos_transport_parse_event (PinosTransport *trans,
void *event)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
uint32_t size;
if (impl == NULL || event == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
size = SPA_POD_SIZE (&impl->current);
spa_ringbuffer_read_data (trans->input_buffer,
trans->input_data,
impl->areas,
event,
impl->current.size);
spa_ringbuffer_read_advance (trans->input_buffer, impl->current.size);
size);
spa_ringbuffer_read_advance (trans->input_buffer, size);
return SPA_RESULT_OK;
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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,

View file

@ -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);

View file

@ -130,8 +130,10 @@ typedef void (*SpaNotify) (void *data);
#ifdef __GNUC__
# define SPA_PRINTF_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
# define SPA_ALIGNED(align) __attribute__ ((aligned (align)))
#else
# define SPA_PRINTF_FUNC(fmt, arg1)
# define SPA_ALIGNED(align)
#endif
#define SPA_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))

View file

@ -49,11 +49,25 @@ typedef enum {
SPA_NODE_COMMAND_CLOCK_UPDATE
} SpaNodeCommandType;
#define SPA_NODE_COMMAND_TYPE(cmd) ((cmd)->body.body.type)
typedef struct {
SpaPODObjectBody body;
} SpaNodeCommandBody;
struct _SpaNodeCommand {
SpaNodeCommandType type;
uint32_t size;
SpaPOD pod;
SpaNodeCommandBody body;
};
#define SPA_NODE_COMMAND_INIT(type) \
{ { sizeof (SpaNodeCommandBody), SPA_POD_TYPE_OBJECT }, \
{ { 0, type } } } \
#define SPA_NODE_COMMAND_INIT_COMPLEX(size,type,...) \
{ { size, SPA_POD_TYPE_OBJECT }, \
{ { 0, type }, __VA_ARGS__ } } \
/**
* SpaNodeCommandClockUpdate:
* @change_mask: marks which fields are updated
@ -67,23 +81,41 @@ struct _SpaNodeCommand {
* @state: the new clock state, when @change_mask = 1<<2
*/
typedef struct {
SpaNodeCommand command;
SpaPODObjectBody body;
#define SPA_NODE_COMMAND_CLOCK_UPDATE_TIME (1 << 0)
#define SPA_NODE_COMMAND_CLOCK_UPDATE_SCALE (1 << 1)
#define SPA_NODE_COMMAND_CLOCK_UPDATE_STATE (1 << 2)
#define SPA_NODE_COMMAND_CLOCK_UPDATE_LATENCY (1 << 3)
uint32_t change_mask;
int32_t rate;
int64_t ticks;
int64_t monotonic_time;
int64_t offset;
int32_t scale;
SpaClockState state;
SpaPODInt change_mask SPA_ALIGNED (8);
SpaPODInt rate SPA_ALIGNED (8);
SpaPODLong ticks SPA_ALIGNED (8);
SpaPODLong monotonic_time SPA_ALIGNED (8);
SpaPODLong offset SPA_ALIGNED (8);
SpaPODInt scale SPA_ALIGNED (8);
SpaPODInt state SPA_ALIGNED (8);
#define SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE (1 << 0)
uint32_t flags;
int64_t latency;
SpaPODInt flags SPA_ALIGNED (8);
SpaPODLong latency SPA_ALIGNED (8);
} SpaNodeCommandClockUpdateBody;
typedef struct {
SpaPOD pod;
SpaNodeCommandClockUpdateBody body;
} SpaNodeCommandClockUpdate;
#define SPA_NODE_COMMAND_CLOCK_UPDATE_INIT(change_mask,rate,ticks,monotonic_time,offset,scale,state,flags,latency) \
SPA_NODE_COMMAND_INIT_COMPLEX (sizeof (SpaNodeCommandClockUpdateBody), \
SPA_NODE_COMMAND_CLOCK_UPDATE, \
SPA_POD_INT_INIT (change_mask), \
SPA_POD_INT_INIT (rate), \
SPA_POD_LONG_INIT (ticks), \
SPA_POD_LONG_INIT (monotonic_time), \
SPA_POD_LONG_INIT (offset), \
SPA_POD_INT_INIT (scale), \
SPA_POD_INT_INIT (state), \
SPA_POD_INT_INIT (flags), \
SPA_POD_LONG_INIT (latency))
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -43,55 +43,103 @@ typedef struct _SpaNodeEvent SpaNodeEvent;
/**
* SpaEventType:
* @SPA_NODE_EVENT_TYPE_INVALID: invalid event, should be ignored
* @SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE: an async operation completed
* @SPA_NODE_EVENT_TYPE_HAVE_OUTPUT: emited when an async node has output that can be pulled
* @SPA_NODE_EVENT_TYPE_NEED_INPUT: emited when more data can be pushed to an async node
* @SPA_NODE_EVENT_TYPE_REUSE_BUFFER: emited when a buffer can be reused
* @SPA_NODE_EVENT_TYPE_ERROR: emited when error occured
* @SPA_NODE_EVENT_TYPE_BUFFERING: emited when buffering is in progress
* @SPA_NODE_EVENT_TYPE_REQUEST_REFRESH: emited when a keyframe refresh is needed
* @SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE: the element asks for a clock update
* @SPA_NODE_EVENT_INVALID: invalid event, should be ignored
* @SPA_NODE_EVENT_ASYNC_COMPLETE: an async operation completed
* @SPA_NODE_EVENT_HAVE_OUTPUT: emited when an async node has output that can be pulled
* @SPA_NODE_EVENT_NEED_INPUT: emited when more data can be pushed to an async node
* @SPA_NODE_EVENT_REUSE_BUFFER: emited when a buffer can be reused
* @SPA_NODE_EVENT_ERROR: emited when error occured
* @SPA_NODE_EVENT_BUFFERING: emited when buffering is in progress
* @SPA_NODE_EVENT_REQUEST_REFRESH: emited when a keyframe refresh is needed
* @SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE: the element asks for a clock update
*/
typedef enum {
SPA_NODE_EVENT_TYPE_INVALID = 0,
SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE,
SPA_NODE_EVENT_TYPE_HAVE_OUTPUT,
SPA_NODE_EVENT_TYPE_NEED_INPUT,
SPA_NODE_EVENT_TYPE_REUSE_BUFFER,
SPA_NODE_EVENT_TYPE_ERROR,
SPA_NODE_EVENT_TYPE_BUFFERING,
SPA_NODE_EVENT_TYPE_REQUEST_REFRESH,
SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE,
SPA_NODE_EVENT_INVALID = 0,
SPA_NODE_EVENT_ASYNC_COMPLETE,
SPA_NODE_EVENT_HAVE_OUTPUT,
SPA_NODE_EVENT_NEED_INPUT,
SPA_NODE_EVENT_REUSE_BUFFER,
SPA_NODE_EVENT_ERROR,
SPA_NODE_EVENT_BUFFERING,
SPA_NODE_EVENT_REQUEST_REFRESH,
SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE,
} SpaNodeEventType;
#define SPA_NODE_EVENT_TYPE(ev) ((ev)->body.body.type)
typedef struct {
SpaPODObjectBody body;
} SpaNodeEventBody;
struct _SpaNodeEvent {
SpaNodeEventType type;
uint32_t size;
SpaPOD pod;
SpaNodeEventBody body;
};
#define SPA_NODE_EVENT_INIT(type) \
{ { sizeof (SpaNodeEventBody), SPA_POD_TYPE_OBJECT }, \
{ { 0, type } } } \
#define SPA_NODE_EVENT_INIT_COMPLEX(size,type,...) \
{ { size, SPA_POD_TYPE_OBJECT }, \
{ { 0, type }, __VA_ARGS__ } } \
typedef struct {
SpaNodeEvent event;
uint32_t seq;
SpaResult res;
SpaPODObjectBody body;
SpaPODInt seq SPA_ALIGNED (8);
SpaPODInt res SPA_ALIGNED (8);
} SpaNodeEventAsyncCompleteBody;
typedef struct {
SpaPOD pod;
SpaNodeEventAsyncCompleteBody body;
} SpaNodeEventAsyncComplete;
typedef struct {
SpaNodeEvent event;
uint32_t port_id;
uint32_t buffer_id;
} SpaNodeEventReuseBuffer;
#define SPA_NODE_EVENT_ASYNC_COMPLETE_INIT(seq,res) \
SPA_NODE_EVENT_INIT_COMPLEX (sizeof (SpaNodeEventAsyncCompleteBody), \
SPA_NODE_EVENT_ASYNC_COMPLETE, \
SPA_POD_INT_INIT (seq), \
SPA_POD_INT_INIT (res))
typedef struct {
SpaNodeEvent event;
SpaPODObjectBody body;
SpaPODInt port_id;
SpaPODInt buffer_id;
} SpaNodeEventReuseBufferBody;
typedef struct {
SpaPOD pod;
SpaNodeEventReuseBufferBody body;
} SpaNodeEventReuseBuffer;
#define SPA_NODE_EVENT_REUSE_BUFFER_INIT(port_id,buffer_id) \
SPA_NODE_EVENT_INIT_COMPLEX (sizeof (SpaNodeEventReuseBufferBody), \
SPA_NODE_EVENT_REUSE_BUFFER, \
SPA_POD_INT_INIT (port_id), \
SPA_POD_INT_INIT (buffer_id))
typedef struct {
SpaPODObjectBody body;
#define SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_TIME (1 << 0)
#define SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_SCALE (1 << 1)
#define SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_STATE (1 << 2)
uint32_t update_mask;
int64_t timestamp;
int64_t offset;
SpaPODInt update_mask SPA_ALIGNED (8);
SpaPODLong timestamp SPA_ALIGNED (8);
SpaPODLong offset SPA_ALIGNED (8);
} SpaNodeEventRequestClockUpdateBody;
typedef struct {
SpaPOD pod;
SpaNodeEventRequestClockUpdateBody body;
} SpaNodeEventRequestClockUpdate;
#define SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_INIT(update_mask,timestamp,offset) \
SPA_NODE_EVENT_INIT_COMPLEX (sizeof (SpaNodeEventRequestClockUpdateBody), \
SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE, \
SPA_POD_INT_INIT (update_mask), \
SPA_POD_LONG_INIT (timestamp), \
SPA_POD_LONG_INIT (offset))
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -147,52 +147,66 @@ spa_pod_builder_primitive (SpaPODBuilder *builder, const SpaPOD *p)
return ref;
}
#define SPA_POD_BOOL_INIT(val) { { sizeof (uint32_t), SPA_POD_TYPE_BOOL }, val ? 1 : 0 }
static inline uint32_t
spa_pod_builder_bool (SpaPODBuilder *builder, bool val)
{
const SpaPODBool p = { { sizeof (uint32_t), SPA_POD_TYPE_BOOL }, val ? 1 : 0 };
const SpaPODBool p = SPA_POD_BOOL_INIT (val);
return spa_pod_builder_primitive (builder, &p.pod);
}
#define SPA_POD_URI_INIT(val) { { sizeof (uint32_t), SPA_POD_TYPE_URI }, val }
static inline uint32_t
spa_pod_builder_uri (SpaPODBuilder *builder, uint32_t val)
{
const SpaPODURI p = { { sizeof (uint32_t), SPA_POD_TYPE_URI }, val };
const SpaPODURI p = SPA_POD_URI_INIT (val);
return spa_pod_builder_primitive (builder, &p.pod);
}
#define SPA_POD_INT_INIT(val) { { sizeof (uint32_t), SPA_POD_TYPE_INT }, val }
static inline uint32_t
spa_pod_builder_int (SpaPODBuilder *builder, int32_t val)
{
const SpaPODInt p = { { sizeof (uint32_t), SPA_POD_TYPE_INT }, val };
const SpaPODInt p = SPA_POD_INT_INIT (val);
return spa_pod_builder_primitive (builder, &p.pod);
}
#define SPA_POD_LONG_INIT(val) { { sizeof (uint64_t), SPA_POD_TYPE_LONG }, val }
static inline uint32_t
spa_pod_builder_long (SpaPODBuilder *builder, int64_t val)
{
const SpaPODLong p = { { sizeof (val), SPA_POD_TYPE_LONG }, val };
const SpaPODLong p = SPA_POD_LONG_INIT (val);
return spa_pod_builder_primitive (builder, &p.pod);
}
#define SPA_POD_FLOAT_INIT(val) { { sizeof (float), SPA_POD_TYPE_FLOAT }, val }
static inline uint32_t
spa_pod_builder_float (SpaPODBuilder *builder, float val)
{
const SpaPODFloat p = { { sizeof (val), SPA_POD_TYPE_FLOAT }, val };
const SpaPODFloat p = SPA_POD_FLOAT_INIT (val);
return spa_pod_builder_primitive (builder, &p.pod);
}
#define SPA_POD_DOUBLE_INIT(val) { { sizeof (double), SPA_POD_TYPE_DOUBLE }, val }
static inline uint32_t
spa_pod_builder_double (SpaPODBuilder *builder, double val)
{
const SpaPODDouble p = { { sizeof (val), SPA_POD_TYPE_DOUBLE }, val };
const SpaPODDouble p = SPA_POD_DOUBLE_INIT (val);
return spa_pod_builder_primitive (builder, &p.pod);
}
#define SPA_POD_STRING_INIT(len) { { len, SPA_POD_TYPE_STRING } }
static inline uint32_t
spa_pod_builder_string_len (SpaPODBuilder *builder, const char *str, uint32_t len)
{
const SpaPODString p = { { len, SPA_POD_TYPE_STRING } };
const SpaPODString p = SPA_POD_STRING_INIT (len);
uint32_t ref = spa_pod_builder_raw (builder, &p, sizeof (p));
if (spa_pod_builder_raw_padded (builder, str, len) == -1)
ref = -1;
@ -206,27 +220,33 @@ spa_pod_builder_string (SpaPODBuilder *builder, const char *str)
return spa_pod_builder_string_len (builder, str ? str : "", len + 1);
}
#define SPA_POD_BYTES_INIT(len) { { len, SPA_POD_TYPE_BYTES } }
static inline uint32_t
spa_pod_builder_bytes (SpaPODBuilder *builder, const void *bytes, uint32_t len)
{
const SpaPODBytes p = { { len, SPA_POD_TYPE_BYTES } };
const SpaPODBytes p = SPA_POD_BYTES_INIT (len);
uint32_t ref = spa_pod_builder_raw (builder, &p, sizeof (p));
if (spa_pod_builder_raw_padded (builder, bytes, len) == -1)
ref = -1;
return ref;
}
#define SPA_POD_RECTANGLE_INIT(width,height) { { sizeof (SpaRectangle), SPA_POD_TYPE_RECTANGLE }, { width, height } }
static inline uint32_t
spa_pod_builder_rectangle (SpaPODBuilder *builder, uint32_t width, uint32_t height)
{
const SpaPODRectangle p = { { sizeof (SpaRectangle), SPA_POD_TYPE_RECTANGLE }, { width, height } };
const SpaPODRectangle p = SPA_POD_RECTANGLE_INIT (width, height);
return spa_pod_builder_primitive (builder, &p.pod);
}
#define SPA_POD_FRACTION_INIT(num,denom) { { sizeof (SpaFraction), SPA_POD_TYPE_FRACTION }, { num, denom } }
static inline uint32_t
spa_pod_builder_fraction (SpaPODBuilder *builder, uint32_t num, uint32_t denom)
{
const SpaPODFraction p = { { sizeof (SpaFraction), SPA_POD_TYPE_FRACTION }, { num, denom } };
const SpaPODFraction p = SPA_POD_FRACTION_INIT (num, denom);
return spa_pod_builder_primitive (builder, &p.pod);
}
@ -247,31 +267,35 @@ spa_pod_builder_array (SpaPODBuilder *builder,
const void *elems)
{
const SpaPODArray p = {
{ (uint32_t)(sizeof (SpaPODArrayBody) + n_elems * child_size), SPA_POD_TYPE_ARRAY },
{ sizeof (SpaPODArrayBody) + n_elems * child_size, SPA_POD_TYPE_ARRAY },
{ { child_size, child_type } }
};
uint32_t ref = spa_pod_builder_raw_padded (builder, &p, sizeof(p));
uint32_t ref = spa_pod_builder_raw (builder, &p, sizeof(p));
if (spa_pod_builder_raw_padded (builder, elems, child_size * n_elems) == -1)
ref = -1;
return ref;
}
#define SPA_POD_STRUCT_INIT(size) { { size, SPA_POD_TYPE_STRUCT } }
static inline uint32_t
spa_pod_builder_push_struct (SpaPODBuilder *builder,
SpaPODFrame *frame)
{
const SpaPODStruct p = { { 0, SPA_POD_TYPE_STRUCT } };
const SpaPODStruct p = SPA_POD_STRUCT_INIT (0);
return spa_pod_builder_push (builder, frame, &p.pod,
spa_pod_builder_raw (builder, &p, sizeof(p)));
}
#define SPA_POD_OBJECT_INIT(size,id,type) { { size, SPA_POD_TYPE_OBJECT }, { id, type } }
static inline uint32_t
spa_pod_builder_push_object (SpaPODBuilder *builder,
SpaPODFrame *frame,
uint32_t id,
uint32_t type)
{
const SpaPODObject p = { { sizeof (SpaPODObjectBody), SPA_POD_TYPE_OBJECT }, { id, type } };
const SpaPODObject p = SPA_POD_OBJECT_INIT (sizeof (SpaPODObjectBody), id, type);
return spa_pod_builder_push (builder, frame, &p.pod,
spa_pod_builder_raw (builder, &p, sizeof(p)));
}

View file

@ -80,6 +80,7 @@ spa_pod_iter_pod (SpaPODIter *iter, SpaPOD *pod)
size = SPA_POD_CONTENTS_SIZE (SpaPODObject, pod);
break;
default:
spa_pod_iter_contents (iter, NULL, 0);
return false;
}
spa_pod_iter_contents (iter, data, size);
@ -101,6 +102,15 @@ spa_pod_iter_next (SpaPODIter *iter)
return res;
}
static inline SpaPOD *
spa_pod_iter_first (SpaPODIter *iter, SpaPOD *pod)
{
if (!spa_pod_iter_pod (iter, pod) ||
!spa_pod_iter_has_next (iter))
return false;
return spa_pod_iter_next (iter);
}
static inline bool
spa_pod_iter_getv (SpaPODIter *iter,
uint32_t type,

View file

@ -112,7 +112,7 @@ typedef struct {
typedef struct {
SpaPOD pod;
/* array of uint32_t follows with the bitmap */
/* array of uint8_t follows with the bitmap */
} SpaPODBitmap;
typedef struct {
@ -182,9 +182,9 @@ typedef struct {
SPA_POD_FOREACH(SPA_MEMBER ((pod), (offset), SpaPOD),SPA_POD_SIZE (pod),iter)
#define SPA_POD_OBJECT_BODY_FOREACH(body, size, iter) \
for ((iter) = SPA_MEMBER ((body), sizeof (SpaPODObjectBody), SpaPODProp); \
(iter) < SPA_MEMBER ((body), (size), SpaPODProp); \
(iter) = SPA_MEMBER ((iter), SPA_ROUND_UP_N (SPA_POD_SIZE (iter), 8), SpaPODProp))
for ((iter) = SPA_MEMBER ((body), sizeof (SpaPODObjectBody), SpaPOD); \
(iter) < SPA_MEMBER ((body), (size), SpaPOD); \
(iter) = SPA_MEMBER ((iter), SPA_ROUND_UP_N (SPA_POD_SIZE (iter), 8), SpaPOD))
#define SPA_POD_OBJECT_FOREACH(obj, iter) \
SPA_POD_OBJECT_BODY_FOREACH(&obj->body, SPA_POD_BODY_SIZE(obj), iter)

View file

@ -395,11 +395,11 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
case SPA_POD_TYPE_OBJECT:
{
SpaPODObjectBody *b = body;
SpaPODProp *p;
SpaPOD *p;
printf ("%-*sObject: size %d\n", prefix, "", size);
printf ("%-*sObject: size %d, id %d, type %d\n", prefix, "", size, b->id, b->type);
SPA_POD_OBJECT_BODY_FOREACH (b, size, p)
print_pod_value (p->pod.size, p->pod.type, SPA_POD_BODY (p), prefix + 6);
print_pod_value (p->size, p->type, SPA_POD_BODY (p), prefix + 2);
break;
}
case SPA_POD_TYPE_PROP:
@ -408,18 +408,18 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
void *alt;
int i;
printf ("%-*sProp: key %d, flags %d\n", prefix + 2, "", b->key, b->flags);
printf ("%-*sProp: key %d, flags %d\n", prefix, "", b->key, b->flags);
if (b->flags & SPA_POD_PROP_FLAG_UNSET)
printf ("%-*sUnset (Default):\n", prefix + 4, "");
printf ("%-*sUnset (Default):\n", prefix + 2, "");
else
printf ("%-*sValue: size %u\n", prefix + 4, "", b->value.size);
print_pod_value (b->value.size, b->value.type, SPA_POD_BODY (&b->value), prefix + 6);
printf ("%-*sValue: size %u\n", prefix + 2, "", b->value.size);
print_pod_value (b->value.size, b->value.type, SPA_POD_BODY (&b->value), prefix + 4);
i = 0;
SPA_POD_PROP_ALTERNATIVE_FOREACH (b, size, alt) {
if (i == 0)
printf ("%-*sAlternatives:\n", prefix + 4, "");
print_pod_value (b->value.size, b->value.type, alt, prefix + 6);
printf ("%-*sAlternatives:\n", prefix + 2, "");
print_pod_value (b->value.size, b->value.type, alt, prefix + 4);
i++;
}
break;
@ -429,7 +429,7 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
spa_debug_dump_mem (body, size);
break;
default:
printf ("unhandled prop type %d\n", type);
printf ("unhandled POD type %d\n", type);
break;
}
}

View file

@ -32,7 +32,7 @@
typedef struct _SpaALSAState SpaALSASink;
static const char default_device[] = "default";
static const uint32_t default_period_size = 32;
static const uint32_t default_period_size = 128;
static const uint32_t default_periods = 2;
static const bool default_period_event = 0;
@ -136,9 +136,15 @@ spa_alsa_sink_node_set_props (SpaNode *node,
reset_alsa_sink_props (&this->props);
return SPA_RESULT_OK;
} else {
SpaPODProp *pr;
SpaPOD *p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, pr) {
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, p) {
SpaPODProp *pr;
if (p->type != SPA_POD_TYPE_PROP)
continue;
pr = (SpaPODProp *) p;
switch (pr->body.key) {
case PROP_ID_DEVICE:
strncpy (this->props.device, SPA_POD_CONTENTS (SpaPODProp, pr), 63);
@ -184,9 +190,8 @@ do_command (SpaLoop *loop,
SpaALSASink *this = user_data;
SpaResult res;
SpaNodeCommand *cmd = data;
SpaNodeEventAsyncComplete ac;
switch (cmd->type) {
switch (SPA_NODE_COMMAND_TYPE (cmd)) {
case SPA_NODE_COMMAND_START:
case SPA_NODE_COMMAND_PAUSE:
res = spa_node_port_send_command (&this->node,
@ -200,10 +205,7 @@ do_command (SpaLoop *loop,
}
if (async) {
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
ac.seq = seq;
ac.res = res;
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
spa_loop_invoke (this->main_loop,
do_send_event,
SPA_ID_INVALID,
@ -225,7 +227,7 @@ spa_alsa_sink_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaALSASink, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
@ -241,7 +243,7 @@ spa_alsa_sink_node_send_command (SpaNode *node,
return spa_loop_invoke (this->data_loop,
do_command,
++this->seq,
command->size,
SPA_POD_SIZE (command),
command,
this);
@ -680,7 +682,7 @@ spa_alsa_sink_node_port_send_command (SpaNode *node,
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_PAUSE:
{
if (SPA_RESULT_IS_OK (res = spa_alsa_pause (this, false))) {

View file

@ -135,9 +135,16 @@ spa_alsa_source_node_set_props (SpaNode *node,
reset_alsa_props (&this->props);
return SPA_RESULT_OK;
} else {
SpaPODProp *pr;
SpaPOD *p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, p) {
SpaPODProp *pr;
if (p->type != SPA_POD_TYPE_PROP)
continue;
pr = (SpaPODProp *) p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, pr) {
switch (pr->body.key) {
case PROP_ID_DEVICE:
strncpy (this->props.device, SPA_POD_CONTENTS (SpaPODProp, pr), 63);
@ -183,17 +190,13 @@ do_start (SpaLoop *loop,
{
SpaALSASource *this = user_data;
SpaResult res;
SpaNodeEventAsyncComplete ac;
if (SPA_RESULT_IS_OK (res = spa_alsa_start (this, false))) {
update_state (this, SPA_NODE_STATE_STREAMING);
}
if (async) {
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
ac.seq = seq;
ac.res = res;
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
spa_loop_invoke (this->main_loop,
do_send_event,
SPA_ID_INVALID,
@ -214,17 +217,13 @@ do_pause (SpaLoop *loop,
{
SpaALSASource *this = user_data;
SpaResult res;
SpaNodeEventAsyncComplete ac;
if (SPA_RESULT_IS_OK (res = spa_alsa_pause (this, false))) {
update_state (this, SPA_NODE_STATE_PAUSED);
}
if (async) {
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
ac.seq = seq;
ac.res = res;
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
spa_loop_invoke (this->main_loop,
do_send_event,
SPA_ID_INVALID,
@ -246,7 +245,7 @@ spa_alsa_source_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
@ -736,7 +735,7 @@ spa_alsa_source_node_port_send_command (SpaNode *node,
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_PAUSE:
{
if (SPA_RESULT_IS_OK (res = spa_alsa_pause (this, false))) {

View file

@ -272,10 +272,7 @@ pull_frames_queue (SpaALSAState *state,
snd_pcm_uframes_t frames)
{
if (spa_list_is_empty (&state->ready)) {
SpaNodeEvent event;
event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT;
event.size = sizeof (event);
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_NEED_INPUT);
state->event_cb (&state->node, &event, state->user_data);
}
if (!spa_list_is_empty (&state->ready)) {
@ -299,16 +296,12 @@ pull_frames_queue (SpaALSAState *state,
state->ready_offset += n_bytes;
if (state->ready_offset >= size) {
SpaNodeEventReuseBuffer rb;
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (0, b->outbuf->id);
spa_list_remove (&b->link);
b->outstanding = true;
rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
rb.event.size = sizeof (rb);
rb.port_id = 0;
rb.buffer_id = b->outbuf->id;
state->event_cb (&state->node, &rb.event, state->user_data);
state->event_cb (&state->node, (SpaNodeEvent *)&rb, state->user_data);
state->ready_offset = 0;
}
@ -329,7 +322,6 @@ pull_frames_ringbuffer (SpaALSAState *state,
size_t size, avail;
SpaALSABuffer *b;
uint8_t *src, *dst;
SpaNodeEventReuseBuffer rb;
b = state->ringbuffer;
@ -357,11 +349,10 @@ pull_frames_ringbuffer (SpaALSAState *state,
}
b->outstanding = true;
rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
rb.event.size = sizeof (rb);
rb.port_id = 0;
rb.buffer_id = b->outbuf->id;
state->event_cb (&state->node, &rb.event, state->user_data);
{
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (0, b->outbuf->id);
state->event_cb (&state->node, (SpaNodeEvent*)&rb, state->user_data);
}
return frames;
}
@ -493,7 +484,6 @@ mmap_read (SpaALSAState *state)
}
if (b) {
SpaNodeEvent event;
SpaData *d;
SpaPortOutput *output;
@ -507,9 +497,10 @@ mmap_read (SpaALSAState *state)
output->buffer_id = b->outbuf->id;
output->status = SPA_RESULT_OK;
}
event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
event.size = sizeof (event);
state->event_cb (&state->node, &event, state->user_data);
{
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
state->event_cb (&state->node, &event, state->user_data);
}
}
return 0;
}

View file

@ -117,7 +117,7 @@ spa_audiomixer_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;

View file

@ -195,9 +195,16 @@ spa_audiotestsrc_node_set_props (SpaNode *node,
if (props == NULL) {
reset_audiotestsrc_props (&this->props);
} else {
SpaPODProp *pr;
SpaPOD *p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, p) {
SpaPODProp *pr;
if (p->type != SPA_POD_TYPE_PROP)
continue;
pr = (SpaPODProp *) p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, pr) {
switch (pr->body.key) {
case PROP_ID_LIVE:
this->props.live = ((SpaPODBool*)&pr->body.value)->value;
@ -226,11 +233,9 @@ spa_audiotestsrc_node_set_props (SpaNode *node,
static SpaResult
send_have_output (SpaAudioTestSrc *this)
{
SpaNodeEvent event;
if (this->event_cb) {
event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
event.size = sizeof (event);
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
this->event_cb (&this->node, &event, this->user_data);
}
@ -324,7 +329,7 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;

View file

@ -106,7 +106,7 @@ spa_ffmpeg_dec_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaFFMpegDec, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;

View file

@ -111,7 +111,7 @@ spa_ffmpeg_enc_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaFFMpegEnc, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;

View file

@ -200,9 +200,16 @@ spa_v4l2_source_node_set_props (SpaNode *node,
reset_v4l2_source_props (&this->props);
return SPA_RESULT_OK;
} else {
SpaPODProp *pr;
SpaPOD *p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, p) {
SpaPODProp *pr;
if (p->type != SPA_POD_TYPE_PROP)
continue;
pr = (SpaPODProp *)p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, pr) {
switch (pr->body.key) {
case PROP_ID_DEVICE:
strncpy (this->props.device, SPA_POD_CONTENTS (SpaPODProp, pr), 63);
@ -225,15 +232,14 @@ do_pause_done (SpaLoop *loop,
SpaV4l2State *state = &this->state[0];
SpaNodeEventAsyncComplete *ac = data;
if (SPA_RESULT_IS_OK (ac->body.res.value))
ac->body.res.value = spa_v4l2_stream_off (this);
if (SPA_RESULT_IS_OK (ac->res))
ac->res = spa_v4l2_stream_off (this);
if (SPA_RESULT_IS_OK (ac->res)) {
if (SPA_RESULT_IS_OK (ac->body.res.value)) {
state->started = false;
update_state (this, SPA_NODE_STATE_PAUSED);
}
this->event_cb (&this->node, &ac->event, this->user_data);
this->event_cb (&this->node, (SpaNodeEvent *)ac, this->user_data);
return SPA_RESULT_OK;
}
@ -248,7 +254,6 @@ do_pause (SpaLoop *loop,
{
SpaV4l2Source *this = user_data;
SpaResult res;
SpaNodeEventAsyncComplete ac;
SpaNodeCommand *cmd = data;
res = spa_node_port_send_command (&this->node,
@ -257,10 +262,7 @@ do_pause (SpaLoop *loop,
cmd);
if (async) {
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
ac.seq = seq;
ac.res = res;
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
spa_loop_invoke (this->state[0].main_loop,
do_pause_done,
seq,
@ -283,11 +285,11 @@ do_start_done (SpaLoop *loop,
SpaV4l2State *state = &this->state[0];
SpaNodeEventAsyncComplete *ac = data;
if (SPA_RESULT_IS_OK (ac->res)) {
if (SPA_RESULT_IS_OK (ac->body.res.value)) {
state->started = true;
update_state (this, SPA_NODE_STATE_STREAMING);
}
this->event_cb (&this->node, &ac->event, this->user_data);
this->event_cb (&this->node, (SpaNodeEvent *)ac, this->user_data);
return SPA_RESULT_OK;
}
@ -302,7 +304,6 @@ do_start (SpaLoop *loop,
{
SpaV4l2Source *this = user_data;
SpaResult res;
SpaNodeEventAsyncComplete ac;
SpaNodeCommand *cmd = data;
res = spa_node_port_send_command (&this->node,
@ -311,10 +312,7 @@ do_start (SpaLoop *loop,
cmd);
if (async) {
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
ac.seq = seq;
ac.res = res;
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
spa_loop_invoke (this->state[0].main_loop,
do_start_done,
seq,
@ -337,7 +335,7 @@ spa_v4l2_source_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
@ -361,7 +359,7 @@ spa_v4l2_source_node_send_command (SpaNode *node,
return spa_loop_invoke (this->state[0].data_loop,
do_start,
++this->seq,
command->size,
SPA_POD_SIZE (command),
command,
this);
}
@ -381,7 +379,7 @@ spa_v4l2_source_node_send_command (SpaNode *node,
return spa_loop_invoke (this->state[0].data_loop,
do_pause,
++this->seq,
command->size,
SPA_POD_SIZE (command),
command,
this);
}
@ -844,7 +842,7 @@ spa_v4l2_source_node_port_send_command (SpaNode *node,
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_PAUSE:
res = spa_v4l2_port_set_enabled (this, false);
break;

View file

@ -924,7 +924,6 @@ static void
v4l2_on_fd_events (SpaSource *source)
{
SpaV4l2Source *this = source->data;
SpaNodeEvent event;
if (source->rmask & SPA_IO_ERR)
return;
@ -935,9 +934,10 @@ v4l2_on_fd_events (SpaSource *source)
if (mmap_read (this) < 0)
return;
event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
event.size = sizeof (event);
this->event_cb (&this->node, &event, this->user_data);
{
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
this->event_cb (&this->node, &event, this->user_data);
}
}
static SpaResult

View file

@ -171,9 +171,15 @@ spa_videotestsrc_node_set_props (SpaNode *node,
if (props == NULL) {
reset_videotestsrc_props (&this->props);
} else {
SpaPODProp *pr;
SpaPOD *p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, pr) {
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, p) {
SpaPODProp *pr;
if (p->type != SPA_POD_TYPE_PROP)
continue;
pr = (SpaPODProp *) p;
switch (pr->body.key) {
case PROP_ID_LIVE:
this->props.live = ((SpaPODBool*)&pr->body.value)->value;
@ -196,14 +202,11 @@ spa_videotestsrc_node_set_props (SpaNode *node,
static SpaResult
send_have_output (SpaVideoTestSrc *this)
{
SpaNodeEvent event;
if (this->event_cb) {
event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
event.size = sizeof (event);
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
this->event_cb (&this->node, &event, this->user_data);
}
return SPA_RESULT_OK;
}
@ -289,7 +292,7 @@ spa_videotestsrc_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaVideoTestSrc, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;

View file

@ -161,9 +161,15 @@ spa_volume_node_set_props (SpaNode *node,
if (props == NULL) {
reset_volume_props (&this->props);
} else {
SpaPODProp *pr;
SpaPOD *p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, pr) {
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, p) {
SpaPODProp *pr;
if (p->type != SPA_POD_TYPE_PROP)
continue;
pr = (SpaPODProp *) p;
switch (pr->body.key) {
case PROP_ID_VOLUME:
this->props.volume = ((SpaPODDouble*)&pr->body.value)->value;
@ -188,7 +194,7 @@ spa_volume_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaVolume, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
@ -663,13 +669,8 @@ find_free_buffer (SpaVolume *this, SpaVolumePort *port)
static void
release_buffer (SpaVolume *this, SpaBuffer *buffer)
{
SpaNodeEventReuseBuffer rb;
rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
rb.event.size = sizeof (rb);
rb.port_id = 0;
rb.buffer_id = buffer->id;
this->event_cb (&this->node, &rb.event, this->user_data);
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (0, buffer->id);
this->event_cb (&this->node, (SpaNodeEvent *)&rb, this->user_data);
}
static void

View file

@ -166,9 +166,15 @@ spa_xv_sink_node_set_props (SpaNode *node,
if (props == NULL) {
reset_xv_sink_props (&this->props);
} else {
SpaPODProp *pr;
SpaPOD *p;
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, pr) {
SPA_POD_OBJECT_BODY_FOREACH (&props->body, props->pod.size, p) {
SpaPODProp *pr;
if (p->type != SPA_POD_TYPE_PROP)
continue;
pr = (SpaPODProp *) p;
switch (pr->body.key) {
case PROP_ID_DEVICE:
strncpy (this->props.device, SPA_POD_CONTENTS (SpaPODProp, pr), 63);
@ -190,7 +196,7 @@ spa_xv_sink_node_send_command (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
switch (command->type) {
switch (SPA_NODE_COMMAND_TYPE (command)) {
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;