mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-13 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
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue