Add support for async results

Add an async result code and an event to signal the completion.
Use async return values to signal completion of a method and potential
state change.
Add selected format to port update message.
Make it possible to parse into a custom copy of the command memory.
Remove state change events from the elements, we now just update the
state.
Implement async results in the proxy element
Add support for removing buffers in the client.
Fix up pinossink
Deal with async return in the links.
This commit is contained in:
Wim Taymans 2016-09-22 08:55:30 +02:00
parent 27acab7532
commit 68148188fa
25 changed files with 456 additions and 406 deletions

View file

@ -34,7 +34,7 @@
#define PINOS_LINK_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_LINK, PinosLinkPrivate))
#define MAX_BUFFERS 64
#define MAX_BUFFERS 16
struct _PinosLinkPrivate
{
@ -498,7 +498,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
}
g_debug ("allocated out_buffers %p from output port", priv->out_buffers);
}
else if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
g_debug ("using out_buffers %p on input port", priv->out_buffers);
if ((res = spa_node_port_use_buffers (this->input_node->node, this->input_port,
priv->out_buffers, priv->n_out_buffers)) < 0) {
@ -563,6 +563,7 @@ check_states (PinosLink *this)
SpaResult res;
SpaNodeState in_state, out_state;
again:
in_state = this->input_node->node->state;
out_state = this->output_node->node->state;
@ -577,9 +578,21 @@ check_states (PinosLink *this)
if ((res = do_start (this, in_state, out_state)) < 0)
return res;
if (this->input_node->node->state != in_state)
goto again;
if (this->output_node->node->state != out_state)
goto again;
return SPA_RESULT_OK;
}
static gboolean
do_check_states (PinosLink *this)
{
check_states (this);
return G_SOURCE_REMOVE;
}
static void
on_node_state_notify (GObject *obj,
GParamSpec *pspec,
@ -588,7 +601,7 @@ on_node_state_notify (GObject *obj,
PinosLink *this = user_data;
g_debug ("link %p: node %p state change", this, obj);
check_states (this);
g_idle_add ((GSourceFunc) do_check_states, this);
}
static void

View file

@ -311,7 +311,6 @@ suspend_node (PinosNode *this)
if ((res = spa_node_port_set_format (this->node, 0, 0, NULL)) < 0)
g_warning ("error unset format output: %d", res);
}
static void
@ -405,6 +404,23 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
PinosNodePrivate *priv = this->priv;
switch (event->type) {
case SPA_NODE_EVENT_TYPE_INVALID:
case SPA_NODE_EVENT_TYPE_DRAINED:
case SPA_NODE_EVENT_TYPE_MARKER:
case SPA_NODE_EVENT_TYPE_ERROR:
case SPA_NODE_EVENT_TYPE_BUFFERING:
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
break;
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
{
SpaNodeEventAsyncComplete *ac = event->data;
g_debug ("async complete %u %d", ac->seq, ac->res);
if (SPA_RESULT_IS_OK (ac->res))
g_object_notify (G_OBJECT (this), "node-state");
break;
}
case SPA_NODE_EVENT_TYPE_PORT_ADDED:
{
SpaNodeEventPortAdded *pa = event->data;
@ -432,17 +448,6 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
g_main_context_invoke (NULL, (GSourceFunc) do_signal_port_removed, data);
break;
}
case SPA_NODE_EVENT_TYPE_STATE_CHANGE:
{
SpaNodeEventStateChange *sc = event->data;
g_debug ("node %p: update SPA state to %d", this, sc->state);
if (sc->state == SPA_NODE_STATE_CONFIGURE) {
update_port_ids (this, FALSE);
}
g_object_notify (G_OBJECT (this), "node-state");
break;
}
case SPA_NODE_EVENT_TYPE_ADD_POLL:
{
SpaPollItem *poll = event->data;
@ -499,10 +504,13 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
}
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
{
SpaNodeEventHaveOutput *ho = event->data;
SpaPortOutputInfo oinfo[1] = { 0, };
SpaResult res;
guint i;
oinfo[0].port_id = ho->port_id;
if ((res = spa_node_port_pull_output (node, 1, oinfo)) < 0) {
g_warning ("node %p: got pull error %d, %d", this, res, oinfo[0].status);
break;
@ -554,10 +562,6 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE:
send_clock_update (this);
break;
default:
g_debug ("node %p: got event %d", this, event->type);
break;
}
}