Wait for async changes to complete

This commit is contained in:
Wim Taymans 2016-09-24 18:32:46 +02:00
parent 1ba10cf848
commit 924824d0a3
2 changed files with 26 additions and 8 deletions

View file

@ -228,6 +228,9 @@ on_port_added (PinosNode *node, PinosDirection direction, PinosDaemon *this)
PinosLink *link; PinosLink *link;
props = pinos_node_get_properties (node); props = pinos_node_get_properties (node);
if (props == NULL)
return;
path = pinos_properties_get (props, "pinos.target.node"); path = pinos_properties_get (props, "pinos.target.node");
if (path) { if (path) {

View file

@ -48,6 +48,8 @@ struct _PinosLinkPrivate
PinosLinkState state; PinosLinkState state;
GError *error; GError *error;
uint32_t async_busy;
SpaBuffer *in_buffers[MAX_BUFFERS]; SpaBuffer *in_buffers[MAX_BUFFERS];
unsigned int n_in_buffers; unsigned int n_in_buffers;
SpaBuffer *out_buffers[MAX_BUFFERS]; SpaBuffer *out_buffers[MAX_BUFFERS];
@ -356,7 +358,7 @@ again:
goto error; goto error;
} }
} }
return SPA_RESULT_OK; return res;
error: error:
{ {
@ -531,7 +533,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
goto error; goto error;
} }
return SPA_RESULT_OK; return res;
error: error:
{ {
@ -564,23 +566,27 @@ do_start (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
static SpaResult static SpaResult
check_states (PinosLink *this) check_states (PinosLink *this)
{ {
PinosLinkPrivate *priv = this->priv;
SpaResult res; SpaResult res;
SpaNodeState in_state, out_state; SpaNodeState in_state, out_state;
again: again:
if (priv->async_busy != SPA_ID_INVALID)
return SPA_RESULT_OK;
in_state = this->input_node->node->state; in_state = this->input_node->node->state;
out_state = this->output_node->node->state; out_state = this->output_node->node->state;
g_debug ("link %p: input state %d, output state %d", this, in_state, out_state); g_debug ("link %p: input state %d, output state %d", this, in_state, out_state);
if ((res = do_negotiate (this, in_state, out_state)) < 0) if ((res = do_negotiate (this, in_state, out_state)) != SPA_RESULT_OK)
return res; goto exit;
if ((res = do_allocation (this, in_state, out_state)) < 0) if ((res = do_allocation (this, in_state, out_state)) != SPA_RESULT_OK)
return res; goto exit;
if ((res = do_start (this, in_state, out_state)) < 0) if ((res = do_start (this, in_state, out_state)) != SPA_RESULT_OK)
return res; goto exit;
if (this->input_node->node->state != in_state) if (this->input_node->node->state != in_state)
goto again; goto again;
@ -588,11 +594,20 @@ again:
goto again; goto again;
return SPA_RESULT_OK; return SPA_RESULT_OK;
exit:
if (SPA_RESULT_IS_ASYNC (res)) {
priv->async_busy = SPA_RESULT_ASYNC_SEQ (res);
g_debug ("link %p: waiting for async complete %d", this, priv->async_busy);
}
return res;
} }
static gboolean static gboolean
do_check_states (PinosLink *this) do_check_states (PinosLink *this)
{ {
PinosLinkPrivate *priv = this->priv;
priv->async_busy = SPA_ID_INVALID;
check_states (this); check_states (this);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }