event: make events dynamic

Use uri for the events.
This commit is contained in:
Wim Taymans 2017-03-21 20:39:20 +01:00
parent 5bccb1aeea
commit 4d9f2c5161
23 changed files with 299 additions and 285 deletions

View file

@ -160,7 +160,7 @@ typedef struct {
void (*state_change) (void *object,
SpaNodeState state);
void (*event) (void *object,
SpaNodeEvent *event);
SpaEvent *event);
void (*destroy) (void *object);
} PinosClientNodeMethods;
@ -173,8 +173,8 @@ typedef struct {
typedef struct {
void (*done) (void *object,
int datafd);
void (*event) (void *object,
const SpaNodeEvent *event);
void (*event) (void *object,
const SpaEvent *event);
void (*add_port) (void *object,
uint32_t seq,
SpaDirection direction,

View file

@ -557,8 +557,8 @@ client_node_marshal_state_change (void *object,
}
static void
client_node_marshal_event (void *object,
SpaNodeEvent *event)
client_node_marshal_event (void *object,
SpaEvent *event)
{
PinosProxy *proxy = object;
PinosConnection *connection = proxy->context->protocol_private;
@ -617,7 +617,7 @@ client_node_demarshal_event (void *object,
{
PinosProxy *proxy = object;
SpaPODIter it;
const SpaNodeEvent *event;
const SpaEvent *event;
if (!spa_pod_iter_struct (&it, data, size) ||
!spa_pod_iter_get (&it,

View file

@ -388,9 +388,10 @@ add_request_clock_update (PinosStream *stream, bool flush)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
SpaNodeEventRequestClockUpdate rcu =
SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_INIT (SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_TIME, 0, 0);
SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_INIT (stream->context->uri.node_events.RequestClockUpdate,
SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_TIME, 0, 0);
pinos_client_node_do_event (impl->node_proxy, (SpaNodeEvent*)&rcu);
pinos_client_node_do_event (impl->node_proxy, (SpaEvent*)&rcu);
}
static void
@ -400,8 +401,10 @@ add_async_complete (PinosStream *stream,
bool flush)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT(seq, res);
pinos_client_node_do_event (impl->node_proxy, (SpaNodeEvent*)&ac);
SpaNodeEventAsyncComplete ac =
SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (stream->context->uri.node_events.AsyncComplete,
seq, res);
pinos_client_node_do_event (impl->node_proxy, (SpaEvent*)&ac);
}
static void
@ -462,54 +465,47 @@ find_buffer (PinosStream *stream, uint32_t id)
static void
handle_rtnode_event (PinosStream *stream,
SpaNodeEvent *event)
SpaEvent *event)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
PinosContext *context = impl->this.context;
switch (SPA_NODE_EVENT_TYPE (event)) {
case SPA_NODE_EVENT_HAVE_OUTPUT:
{
int i;
if (SPA_EVENT_TYPE (event) == context->uri.node_events.HaveOutput) {
int i;
//pinos_log_debug ("stream %p: have output", stream);
//pinos_log_debug ("stream %p: have output", stream);
for (i = 0; i < impl->trans->area->n_inputs; i++) {
SpaPortInput *input = &impl->trans->inputs[i];
for (i = 0; i < impl->trans->area->n_inputs; i++) {
SpaPortInput *input = &impl->trans->inputs[i];
if (input->buffer_id == SPA_ID_INVALID)
continue;
if (input->buffer_id == SPA_ID_INVALID)
continue;
pinos_signal_emit (&stream->new_buffer, stream, input->buffer_id);
input->buffer_id = SPA_ID_INVALID;
}
send_need_input (stream);
break;
pinos_signal_emit (&stream->new_buffer, stream, input->buffer_id);
input->buffer_id = SPA_ID_INVALID;
}
send_need_input (stream);
}
else if (SPA_EVENT_TYPE (event) == context->uri.node_events.NeedInput) {
//pinos_log_debug ("stream %p: need input", stream);
pinos_signal_emit (&stream->need_buffer, stream);
}
else if (SPA_EVENT_TYPE (event) == context->uri.node_events.ReuseBuffer) {
SpaNodeEventReuseBuffer *p = (SpaNodeEventReuseBuffer *) event;
BufferId *bid;
case SPA_NODE_EVENT_NEED_INPUT:
//pinos_log_debug ("stream %p: need input", stream);
pinos_signal_emit (&stream->need_buffer, stream);
break;
if (p->body.port_id.value != impl->port_id)
return;
if (impl->direction != SPA_DIRECTION_OUTPUT)
return;
case SPA_NODE_EVENT_REUSE_BUFFER:
{
SpaNodeEventReuseBuffer *p = (SpaNodeEventReuseBuffer *) event;
BufferId *bid;
if (p->body.port_id.value != impl->port_id)
break;
if (impl->direction != SPA_DIRECTION_OUTPUT)
break;
if ((bid = find_buffer (stream, p->body.buffer_id.value)) && bid->used) {
bid->used = false;
pinos_signal_emit (&stream->new_buffer, stream, p->body.buffer_id.value);
}
break;
if ((bid = find_buffer (stream, p->body.buffer_id.value)) && bid->used) {
bid->used = false;
pinos_signal_emit (&stream->new_buffer, stream, p->body.buffer_id.value);
}
default:
pinos_log_warn ("unexpected node event %d", SPA_NODE_EVENT_TYPE (event));
break;
}
else {
pinos_log_warn ("unexpected node event %d", SPA_EVENT_TYPE (event));
}
}
@ -529,13 +525,13 @@ on_rtsocket_condition (SpaSource *source,
}
if (mask & SPA_IO_IN) {
SpaNodeEvent event;
SpaEvent event;
uint64_t cmd;
read (impl->rtfd, &cmd, 8);
while (pinos_transport_next_event (impl->trans, &event) == SPA_RESULT_OK) {
SpaNodeEvent *ev = alloca (SPA_POD_SIZE (&event));
SpaEvent *ev = alloca (SPA_POD_SIZE (&event));
pinos_transport_parse_event (impl->trans, ev);
handle_rtnode_event (stream, ev);
}
@ -570,22 +566,10 @@ handle_socket (PinosStream *stream, int rtfd)
}
static void
handle_node_event (PinosStream *stream,
const SpaNodeEvent *event)
handle_node_event (PinosStream *stream,
const SpaEvent *event)
{
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;
}
pinos_log_warn ("unhandled node event %d", SPA_EVENT_TYPE (event));
}
static bool
@ -658,8 +642,8 @@ client_node_done (void *object,
}
static void
client_node_event (void *object,
const SpaNodeEvent *event)
client_node_event (void *object,
const SpaEvent *event)
{
PinosProxy *proxy = object;
PinosStream *stream = proxy->user_data;
@ -1154,10 +1138,11 @@ pinos_stream_recycle_buffer (PinosStream *stream,
uint32_t id)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (impl->port_id, id);
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (stream->context->uri.node_events.ReuseBuffer,
impl->port_id, id);
uint64_t cmd = 1;
pinos_transport_add_event (impl->trans, (SpaNodeEvent *)&rb);
pinos_transport_add_event (impl->trans, (SpaEvent *)&rb);
write (impl->rtfd, &cmd, 8);
return true;

View file

@ -39,7 +39,7 @@ typedef struct {
size_t offset;
SpaRingbufferArea areas[2];
SpaNodeEvent current;
SpaEvent current;
} PinosTransportImpl;
static size_t
@ -204,7 +204,7 @@ pinos_transport_get_info (PinosTransport *trans,
SpaResult
pinos_transport_add_event (PinosTransport *trans,
SpaNodeEvent *event)
SpaEvent *event)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
SpaRingbufferArea areas[2];
@ -230,7 +230,7 @@ pinos_transport_add_event (PinosTransport *trans,
SpaResult
pinos_transport_next_event (PinosTransport *trans,
SpaNodeEvent *event)
SpaEvent *event)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
size_t avail;
@ -239,14 +239,14 @@ pinos_transport_next_event (PinosTransport *trans,
return SPA_RESULT_INVALID_ARGUMENTS;
avail = spa_ringbuffer_get_read_areas (trans->input_buffer, impl->areas);
if (avail < sizeof (SpaNodeEvent))
if (avail < sizeof (SpaEvent))
return SPA_RESULT_ENUM_END;
spa_ringbuffer_read_data (trans->input_buffer,
trans->input_data,
impl->areas,
&impl->current,
sizeof (SpaNodeEvent));
sizeof (SpaEvent));
*event = impl->current;

View file

@ -77,10 +77,10 @@ SpaResult pinos_transport_get_info (PinosTransport *trans,
PinosTransportInfo *info);
SpaResult pinos_transport_add_event (PinosTransport *trans,
SpaNodeEvent *event);
SpaEvent *event);
SpaResult pinos_transport_next_event (PinosTransport *trans,
SpaNodeEvent *event);
SpaEvent *event);
SpaResult pinos_transport_parse_event (PinosTransport *trans,
void *event);

View file

@ -48,4 +48,6 @@ pinos_uri_init (PinosURI *uri)
uri->spa_node = spa_id_map_get_id (uri->map, SPA_NODE_URI);
uri->spa_clock = spa_id_map_get_id (uri->map, SPA_CLOCK_URI);
uri->spa_monitor = spa_id_map_get_id (uri->map, SPA_MONITOR_URI);
spa_node_events_map (uri->map, &uri->node_events);
}

View file

@ -29,6 +29,7 @@ extern "C" {
#include <pinos/client/map.h>
#include <spa/include/spa/id-map.h>
#include <spa/include/spa/node-event.h>
typedef struct _PinosURI PinosURI;
@ -52,6 +53,8 @@ struct _PinosURI {
uint32_t spa_node;
uint32_t spa_clock;
uint32_t spa_monitor;
SpaNodeEvents node_events;
};
void pinos_uri_init (PinosURI *uri);

View file

@ -129,8 +129,10 @@ typedef struct
static void
send_async_complete (SpaProxy *this, uint32_t seq, SpaResult res)
{
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
this->event_cb (&this->node, (SpaNodeEvent *)&ac, this->user_data);
PinosCore *core = this->pnode->core;
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (core->uri.node_events.AsyncComplete,
seq, res);
this->event_cb (&this->node, (SpaEvent *)&ac, this->user_data);
}
static SpaResult
@ -164,7 +166,7 @@ static void
send_need_input (SpaProxy *this)
{
PinosNode *pnode = this->pnode;
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_NEED_INPUT);
SpaEvent event = SPA_EVENT_INIT (pnode->core->uri.node_events.NeedInput);
uint64_t cmd = 1;
pinos_transport_add_event (pnode->transport, &event);
@ -175,7 +177,7 @@ static void
send_have_output (SpaProxy *this)
{
PinosNode *pnode = this->pnode;
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
SpaEvent event = SPA_EVENT_INIT (pnode->core->uri.node_events.HaveOutput);
uint64_t cmd = 1;
pinos_transport_add_event (pnode->transport, &event);
@ -775,8 +777,9 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
return SPA_RESULT_INVALID_PORT;
{
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (port_id, buffer_id);
pinos_transport_add_event (pnode->transport, (SpaNodeEvent *)&rb);
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (pnode->core->uri.node_events.ReuseBuffer,
port_id, buffer_id);
pinos_transport_add_event (pnode->transport, (SpaEvent *)&rb);
//write (this->data_source.fd, &cmd, 8);
}
@ -847,25 +850,10 @@ spa_proxy_node_process_output (SpaNode *node)
}
static SpaResult
handle_node_event (SpaProxy *this,
SpaNodeEvent *event)
handle_node_event (SpaProxy *this,
SpaEvent *event)
{
switch (SPA_NODE_EVENT_TYPE (event)) {
case SPA_NODE_EVENT_INVALID:
break;
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;
}
this->event_cb (&this->node, event, this->user_data);
return SPA_RESULT_OK;
}
@ -945,8 +933,8 @@ client_node_state_change (void *object,
}
static void
client_node_event (void *object,
SpaNodeEvent *event)
client_node_event (void *object,
SpaEvent *event)
{
PinosResource *resource = object;
PinosClientNode *node = resource->object;
@ -984,13 +972,13 @@ proxy_on_data_fd_events (SpaSource *source)
}
if (source->rmask & SPA_IO_IN) {
SpaNodeEvent event;
SpaEvent event;
uint64_t cmd;
read (this->data_source.fd, &cmd, 8);
while (pinos_transport_next_event (pnode->transport, &event) == SPA_RESULT_OK) {
SpaNodeEvent *ev = alloca (SPA_POD_SIZE (&event));
SpaEvent *ev = alloca (SPA_POD_SIZE (&event));
pinos_transport_parse_event (pnode->transport, ev);
this->event_cb (&this->node, ev, this->user_data);
}

View file

@ -250,126 +250,108 @@ send_clock_update (PinosNode *this)
}
static void
on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
{
PinosNode *this = user_data;
PinosNodeImpl *impl = SPA_CONTAINER_OF (this, PinosNodeImpl, this);
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;
if (SPA_EVENT_TYPE (event) == this->core->uri.node_events.AsyncComplete) {
SpaNodeEventAsyncComplete *ac = (SpaNodeEventAsyncComplete *) event;
case SPA_NODE_EVENT_ASYNC_COMPLETE:
{
SpaNodeEventAsyncComplete *ac = (SpaNodeEventAsyncComplete *) event;
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;
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);
}
}
else if (SPA_EVENT_TYPE (event) == this->core->uri.node_events.NeedInput) {
SpaResult res;
int i;
bool processed = false;
case SPA_NODE_EVENT_NEED_INPUT:
{
SpaResult res;
int i;
bool processed = false;
for (i = 0; i < this->transport->area->n_inputs; i++) {
PinosLink *link;
PinosPort *inport, *outport;
SpaPortInput *pi;
SpaPortOutput *po;
for (i = 0; i < this->transport->area->n_inputs; i++) {
PinosLink *link;
PinosPort *inport, *outport;
SpaPortInput *pi;
SpaPortOutput *po;
pi = &this->transport->inputs[i];
if (pi->buffer_id != SPA_ID_INVALID)
continue;
pi = &this->transport->inputs[i];
if (pi->buffer_id != SPA_ID_INVALID)
inport = this->input_port_map[i];
spa_list_for_each (link, &inport->rt.links, rt.input_link) {
if (link->rt.input == NULL || link->rt.output == NULL)
continue;
inport = this->input_port_map[i];
spa_list_for_each (link, &inport->rt.links, rt.input_link) {
if (link->rt.input == NULL || link->rt.output == NULL)
continue;
outport = link->rt.output;
po = &outport->node->transport->outputs[outport->port_id];
if (po->buffer_id != SPA_ID_INVALID) {
processed = true;
pi->buffer_id = po->buffer_id;
if ((res = spa_node_port_reuse_buffer (outport->node->node,
outport->port_id,
po->buffer_id)) < 0)
pinos_log_warn ("node %p: error reuse buffer: %d", outport->node, res);
po->buffer_id = SPA_ID_INVALID;
}
if ((res = spa_node_process_output (outport->node->node)) < 0)
pinos_log_warn ("node %p: got process output %d", outport->node, res);
}
}
if (processed) {
if ((res = spa_node_process_input (this->node)) < 0)
pinos_log_warn ("node %p: got process input %d", this, res);
}
break;
}
case SPA_NODE_EVENT_HAVE_OUTPUT:
{
SpaResult res;
int i;
bool processed = false;
for (i = 0; i < this->transport->area->n_outputs; i++) {
PinosLink *link;
PinosPort *inport, *outport;
SpaPortInput *pi;
SpaPortOutput *po;
po = &this->transport->outputs[i];
if (po->buffer_id == SPA_ID_INVALID)
continue;
outport = this->output_port_map[i];
spa_list_for_each (link, &outport->rt.links, rt.output_link) {
if (link->rt.input == NULL || link->rt.output == NULL)
continue;
inport = link->rt.input;
pi = &inport->node->transport->inputs[inport->port_id];
outport = link->rt.output;
po = &outport->node->transport->outputs[outport->port_id];
if (po->buffer_id != SPA_ID_INVALID) {
processed = true;
pi->buffer_id = po->buffer_id;
if ((res = spa_node_port_reuse_buffer (outport->node->node,
outport->port_id,
po->buffer_id)) < 0)
pinos_log_warn ("node %p: error reuse buffer: %d", outport->node, res);
if ((res = spa_node_process_input (inport->node->node)) < 0)
pinos_log_warn ("node %p: got process input %d", inport->node, res);
po->buffer_id = SPA_ID_INVALID;
}
if ((res = spa_node_port_reuse_buffer (this->node,
outport->port_id,
po->buffer_id)) < 0)
pinos_log_warn ("node %p: error reuse buffer: %d", this, res);
po->buffer_id = SPA_ID_INVALID;
if ((res = spa_node_process_output (outport->node->node)) < 0)
pinos_log_warn ("node %p: got process output %d", outport->node, res);
}
if (processed) {
if ((res = spa_node_process_output (this->node)) < 0)
pinos_log_warn ("node %p: got process output %d", this, res);
}
break;
}
case SPA_NODE_EVENT_REUSE_BUFFER:
break;
if (processed) {
if ((res = spa_node_process_input (this->node)) < 0)
pinos_log_warn ("node %p: got process input %d", this, res);
}
}
else if (SPA_EVENT_TYPE (event) == this->core->uri.node_events.HaveOutput) {
SpaResult res;
int i;
bool processed = false;
case SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE:
send_clock_update (this);
break;
for (i = 0; i < this->transport->area->n_outputs; i++) {
PinosLink *link;
PinosPort *inport, *outport;
SpaPortInput *pi;
SpaPortOutput *po;
po = &this->transport->outputs[i];
if (po->buffer_id == SPA_ID_INVALID)
continue;
outport = this->output_port_map[i];
spa_list_for_each (link, &outport->rt.links, rt.output_link) {
if (link->rt.input == NULL || link->rt.output == NULL)
continue;
inport = link->rt.input;
pi = &inport->node->transport->inputs[inport->port_id];
processed = true;
pi->buffer_id = po->buffer_id;
if ((res = spa_node_process_input (inport->node->node)) < 0)
pinos_log_warn ("node %p: got process input %d", inport->node, res);
}
if ((res = spa_node_port_reuse_buffer (this->node,
outport->port_id,
po->buffer_id)) < 0)
pinos_log_warn ("node %p: error reuse buffer: %d", this, res);
po->buffer_id = SPA_ID_INVALID;
}
if (processed) {
if ((res = spa_node_process_output (this->node)) < 0)
pinos_log_warn ("node %p: got process output %d", this, res);
}
}
else if (SPA_EVENT_TYPE (event) == this->core->uri.node_events.RequestClockUpdate) {
send_clock_update (this);
}
}

View file

@ -546,8 +546,8 @@ client_node_marshal_done (void *object,
}
static void
client_node_marshal_event (void *object,
const SpaNodeEvent *event)
client_node_marshal_event (void *object,
const SpaEvent *event)
{
PinosResource *resource = object;
PinosConnection *connection = resource->client->protocol_private;
@ -930,7 +930,7 @@ client_node_demarshal_event (void *object,
{
PinosResource *resource = object;
SpaPODIter it;
SpaNodeEvent *event;
SpaEvent *event;
if (!spa_pod_iter_struct (&it, data, size) ||
!spa_pod_iter_get (&it, SPA_POD_TYPE_OBJECT, &event, 0))

55
spa/include/spa/event.h Normal file
View file

@ -0,0 +1,55 @@
/* Simple Plugin API
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __SPA_EVENT_H__
#define __SPA_EVENT_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaEvent SpaEvent;
#include <spa/defs.h>
#include <spa/pod-utils.h>
#define SPA_EVENT_TYPE(ev) ((ev)->body.body.type)
typedef struct {
SpaPODObjectBody body;
} SpaEventBody;
struct _SpaEvent {
SpaPOD pod;
SpaEventBody body;
};
#define SPA_EVENT_INIT(type) \
{ { sizeof (SpaEventBody), SPA_POD_TYPE_OBJECT }, \
{ { 0, type } } } \
#define SPA_EVENT_INIT_COMPLEX(size,type,...) \
{ { size, SPA_POD_TYPE_OBJECT }, \
{ { 0, type }, __VA_ARGS__ } } \
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_EVENT_H__ */

View file

@ -4,6 +4,7 @@ spa_headers = [
'clock.h',
'defs.h',
'dict.h',
'event.h',
'format.h',
'id-map.h',
'list.h',

View file

@ -24,9 +24,9 @@
extern "C" {
#endif
typedef struct _SpaNodeEvent SpaNodeEvent;
#include <spa/defs.h>
#include <spa/event.h>
#include <spa/id-map.h>
#include <spa/node.h>
#define SPA_NODE_EVENT_URI "http://spaplug.in/ns/node-event"
@ -41,48 +41,31 @@ typedef struct _SpaNodeEvent SpaNodeEvent;
#define SPA_NODE_EVENT__RequestRefresh SPA_NODE_EVENT_PREFIX "RequestRefresh"
#define SPA_NODE_EVENT__RequestClockUpdate SPA_NODE_EVENT_PREFIX "RequestClockUpdate"
/**
* SpaEventType:
* @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_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;
uint32_t AsyncComplete;
uint32_t HaveOutput;
uint32_t NeedInput;
uint32_t ReuseBuffer;
uint32_t Error;
uint32_t Buffering;
uint32_t RequestRefresh;
uint32_t RequestClockUpdate;
} SpaNodeEvents;
struct _SpaNodeEvent {
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__ } } \
static inline void
spa_node_events_map (SpaIDMap *map, SpaNodeEvents *types)
{
if (types->AsyncComplete == 0) {
types->AsyncComplete = spa_id_map_get_id (map, SPA_NODE_EVENT__AsyncComplete);
types->HaveOutput = spa_id_map_get_id (map, SPA_NODE_EVENT__HaveOutput);
types->NeedInput = spa_id_map_get_id (map, SPA_NODE_EVENT__NeedInput);
types->ReuseBuffer = spa_id_map_get_id (map, SPA_NODE_EVENT__ReuseBuffer);
types->Error = spa_id_map_get_id (map, SPA_NODE_EVENT__Error);
types->Buffering = spa_id_map_get_id (map, SPA_NODE_EVENT__Buffering);
types->RequestRefresh = spa_id_map_get_id (map, SPA_NODE_EVENT__RequestRefresh);
types->RequestClockUpdate = spa_id_map_get_id (map, SPA_NODE_EVENT__RequestClockUpdate);
}
}
typedef struct {
SpaPODObjectBody body;
@ -95,9 +78,8 @@ typedef struct {
SpaNodeEventAsyncCompleteBody body;
} SpaNodeEventAsyncComplete;
#define SPA_NODE_EVENT_ASYNC_COMPLETE_INIT(seq,res) \
SPA_NODE_EVENT_INIT_COMPLEX (sizeof (SpaNodeEventAsyncCompleteBody), \
SPA_NODE_EVENT_ASYNC_COMPLETE, \
#define SPA_NODE_EVENT_ASYNC_COMPLETE_INIT(type,seq,res) \
SPA_EVENT_INIT_COMPLEX (sizeof (SpaNodeEventAsyncCompleteBody), type, \
SPA_POD_INT_INIT (seq), \
SPA_POD_INT_INIT (res))
@ -112,9 +94,8 @@ typedef struct {
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, \
#define SPA_NODE_EVENT_REUSE_BUFFER_INIT(type,port_id,buffer_id) \
SPA_EVENT_INIT_COMPLEX (sizeof (SpaNodeEventReuseBufferBody), type, \
SPA_POD_INT_INIT (port_id), \
SPA_POD_INT_INIT (buffer_id))
@ -133,11 +114,10 @@ typedef struct {
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), \
#define SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_INIT(type,update_mask,timestamp,offset) \
SPA_EVENT_INIT_COMPLEX (sizeof (SpaNodeEventRequestClockUpdateBody), type, \
SPA_POD_INT_INIT (update_mask), \
SPA_POD_LONG_INIT (timestamp), \
SPA_POD_LONG_INIT (offset))
#ifdef __cplusplus

View file

@ -107,13 +107,13 @@ typedef struct {
* requested.
*/
typedef struct {
uint32_t state;
uint32_t state;
#define SPA_PORT_OUTPUT_FLAG_NONE 0
uint32_t flags;
uint32_t buffer_id;
uint32_t status;
uint64_t latency;
SpaNodeEvent *event;
uint32_t flags;
uint32_t buffer_id;
uint32_t status;
uint64_t latency;
SpaEvent *event;
} SpaPortOutput;
/**
@ -125,9 +125,9 @@ typedef struct {
* This will be called when an out-of-bound event is notified
* on @node.
*/
typedef void (*SpaNodeEventCallback) (SpaNode *node,
SpaNodeEvent *event,
void *user_data);
typedef void (*SpaNodeEventCallback) (SpaNode *node,
SpaEvent *event,
void *user_data);
/**
* SpaNode:

View file

@ -171,7 +171,8 @@ do_command (SpaLoop *loop,
}
if (async) {
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (this->uri.node_events.AsyncComplete,
seq, res);
spa_loop_invoke (this->main_loop,
do_send_event,
SPA_ID_INVALID,
@ -800,6 +801,7 @@ alsa_sink_init (const SpaHandleFactory *factory,
spa_media_subtypes_audio_map (this->map, &this->uri.media_subtypes_audio);
spa_prop_audio_map (this->map, &this->uri.prop_audio);
spa_audio_formats_map (this->map, &this->uri.audio_formats);
spa_node_events_map (this->map, &this->uri.node_events);
this->node = alsasink_node;
this->stream = SND_PCM_STREAM_PLAYBACK;

View file

@ -164,7 +164,8 @@ do_start (SpaLoop *loop,
}
if (async) {
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (this->uri.node_events.AsyncComplete,
seq, res);
spa_loop_invoke (this->main_loop,
do_send_event,
SPA_ID_INVALID,
@ -191,7 +192,8 @@ do_pause (SpaLoop *loop,
}
if (async) {
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (this->uri.node_events.AsyncComplete,
seq, res);
spa_loop_invoke (this->main_loop,
do_send_event,
SPA_ID_INVALID,
@ -866,6 +868,7 @@ alsa_source_init (const SpaHandleFactory *factory,
spa_media_subtypes_audio_map (this->map, &this->uri.media_subtypes_audio);
spa_prop_audio_map (this->map, &this->uri.prop_audio);
spa_audio_formats_map (this->map, &this->uri.audio_formats);
spa_node_events_map (this->map, &this->uri.node_events);
this->node = alsasource_node;
this->clock = alsasource_clock;

View file

@ -270,7 +270,7 @@ pull_frames_queue (SpaALSAState *state,
snd_pcm_uframes_t frames)
{
if (spa_list_is_empty (&state->ready)) {
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_NEED_INPUT);
SpaEvent event = SPA_EVENT_INIT (state->uri.node_events.NeedInput);
state->event_cb (&state->node, &event, state->user_data);
}
if (!spa_list_is_empty (&state->ready)) {
@ -294,12 +294,13 @@ pull_frames_queue (SpaALSAState *state,
state->ready_offset += n_bytes;
if (state->ready_offset >= size) {
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (0, b->outbuf->id);
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (state->uri.node_events.ReuseBuffer,
0, b->outbuf->id);
spa_list_remove (&b->link);
b->outstanding = true;
state->event_cb (&state->node, (SpaNodeEvent *)&rb, state->user_data);
state->event_cb (&state->node, (SpaEvent *)&rb, state->user_data);
state->ready_offset = 0;
}
@ -348,8 +349,9 @@ pull_frames_ringbuffer (SpaALSAState *state,
b->outstanding = true;
{
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (0, b->outbuf->id);
state->event_cb (&state->node, (SpaNodeEvent*)&rb, state->user_data);
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (state->uri.node_events.ReuseBuffer,
0, b->outbuf->id);
state->event_cb (&state->node, (SpaEvent*)&rb, state->user_data);
}
return frames;
@ -496,7 +498,7 @@ mmap_read (SpaALSAState *state)
output->status = SPA_RESULT_OK;
}
{
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
SpaEvent event = SPA_EVENT_INIT (state->uri.node_events.HaveOutput);
state->event_cb (&state->node, &event, state->user_data);
}
}

View file

@ -67,6 +67,7 @@ typedef struct {
SpaMediaSubtypesAudio media_subtypes_audio;
SpaPropAudio prop_audio;
SpaAudioFormats audio_formats;
SpaNodeEvents node_events;
} URI;
struct _SpaALSAState {

View file

@ -43,6 +43,7 @@ typedef struct {
SpaMediaSubtypes media_subtypes;
SpaPropAudio prop_audio;
SpaAudioFormats audio_formats;
SpaNodeEvents node_events;
} URI;
typedef struct _SpaAudioTestSrc SpaAudioTestSrc;
@ -215,7 +216,7 @@ send_have_output (SpaAudioTestSrc *this)
{
if (this->event_cb) {
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
SpaEvent event = SPA_EVENT_INIT (this->uri.node_events.HaveOutput);
this->event_cb (&this->node, &event, this->user_data);
}
@ -960,6 +961,7 @@ audiotestsrc_init (const SpaHandleFactory *factory,
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_prop_audio_map (this->map, &this->uri.prop_audio);
spa_audio_formats_map (this->map, &this->uri.audio_formats);
spa_node_events_map (this->map, &this->uri.node_events);
this->node = audiotestsrc_node;
this->clock = audiotestsrc_clock;

View file

@ -70,6 +70,7 @@ typedef struct {
SpaMediaSubtypesVideo media_subtypes_video;
SpaPropVideo prop_video;
SpaVideoFormats video_formats;
SpaNodeEvents node_events;
} URI;
typedef struct {
@ -232,7 +233,7 @@ do_pause_done (SpaLoop *loop,
state->started = false;
update_state (this, SPA_NODE_STATE_PAUSED);
}
this->event_cb (&this->node, (SpaNodeEvent *)ac, this->user_data);
this->event_cb (&this->node, (SpaEvent *)ac, this->user_data);
return SPA_RESULT_OK;
}
@ -255,7 +256,8 @@ do_pause (SpaLoop *loop,
cmd);
if (async) {
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (this->uri.node_events.AsyncComplete,
seq, res);
spa_loop_invoke (this->state[0].main_loop,
do_pause_done,
seq,
@ -282,7 +284,7 @@ do_start_done (SpaLoop *loop,
state->started = true;
update_state (this, SPA_NODE_STATE_STREAMING);
}
this->event_cb (&this->node, (SpaNodeEvent *)ac, this->user_data);
this->event_cb (&this->node, (SpaEvent *)ac, this->user_data);
return SPA_RESULT_OK;
}
@ -305,7 +307,8 @@ do_start (SpaLoop *loop,
cmd);
if (async) {
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (seq, res);
SpaNodeEventAsyncComplete ac = SPA_NODE_EVENT_ASYNC_COMPLETE_INIT (this->uri.node_events.AsyncComplete,
seq, res);
spa_loop_invoke (this->state[0].main_loop,
do_start_done,
seq,
@ -974,6 +977,7 @@ v4l2_source_init (const SpaHandleFactory *factory,
spa_media_subtypes_video_map (this->map, &this->uri.media_subtypes_video);
spa_prop_video_map (this->map, &this->uri.prop_video);
spa_video_formats_map (this->map, &this->uri.video_formats);
spa_node_events_map (this->map, &this->uri.node_events);
this->node = v4l2source_node;
this->clock = v4l2source_clock;

View file

@ -979,7 +979,7 @@ v4l2_on_fd_events (SpaSource *source)
return;
{
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
SpaEvent event = SPA_EVENT_INIT (this->uri.node_events.HaveOutput);
this->event_cb (&this->node, &event, this->user_data);
}
}

View file

@ -43,6 +43,7 @@ typedef struct {
SpaMediaSubtypes media_subtypes;
SpaPropVideo prop_video;
SpaVideoFormats video_formats;
SpaNodeEvents node_events;
} URI;
typedef struct _SpaVideoTestSrc SpaVideoTestSrc;
@ -204,7 +205,7 @@ send_have_output (SpaVideoTestSrc *this)
{
if (this->event_cb) {
SpaNodeEvent event = SPA_NODE_EVENT_INIT (SPA_NODE_EVENT_HAVE_OUTPUT);
SpaEvent event = SPA_EVENT_INIT (this->uri.node_events.HaveOutput);
this->event_cb (&this->node, &event, this->user_data);
}
return SPA_RESULT_OK;
@ -962,6 +963,7 @@ videotestsrc_init (const SpaHandleFactory *factory,
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_prop_video_map (this->map, &this->uri.prop_video);
spa_video_formats_map (this->map, &this->uri.video_formats);
spa_node_events_map (this->map, &this->uri.node_events);
this->node = videotestsrc_node;
this->clock = videotestsrc_clock;

View file

@ -67,6 +67,7 @@ typedef struct {
SpaMediaSubtypes media_subtypes;
SpaPropAudio prop_audio;
SpaAudioFormats audio_formats;
SpaNodeEvents node_events;
} URI;
struct _SpaVolume {
@ -651,8 +652,9 @@ find_free_buffer (SpaVolume *this, SpaVolumePort *port)
static void
release_buffer (SpaVolume *this, SpaBuffer *buffer)
{
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (0, buffer->id);
this->event_cb (&this->node, (SpaNodeEvent *)&rb, this->user_data);
SpaNodeEventReuseBuffer rb = SPA_NODE_EVENT_REUSE_BUFFER_INIT (this->uri.node_events.ReuseBuffer,
0, buffer->id);
this->event_cb (&this->node, (SpaEvent *)&rb, this->user_data);
}
static void