mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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