Make events and command specific to the node
Remove some unused code
Improve state changes
Use easier fixate by just taking the element default value
Fix reuse buffer in the proxy
This commit is contained in:
Wim Taymans 2016-09-06 16:43:37 +02:00
parent ac3cd24d5c
commit 8ada6736c0
29 changed files with 686 additions and 708 deletions

View file

@ -215,8 +215,11 @@ on_port_added (PinosNode *node, PinosDirection direction, guint port_id, PinosCl
}
new_port = pinos_node_get_free_port_id (target, pinos_direction_reverse (direction));
if (new_port == SPA_ID_INVALID) {
g_debug ("daemon %p: can't create free port", this);
return;
}
link = pinos_node_link (node, port_id, target, new_port, NULL, NULL);
pinos_client_add_object (client, G_OBJECT (link));
g_object_unref (link);
}

View file

@ -40,19 +40,13 @@ struct _PinosLinkPrivate
PinosLink1 *iface;
gchar *object_path;
gboolean active;
gboolean negotiated;
gboolean allocated;
gboolean started;
GPtrArray *format_filter;
PinosProperties *properties;
SpaBuffer *in_buffers[16];
unsigned int n_in_buffers;
SpaBuffer *out_buffers[16];
unsigned int n_out_buffers;
GPtrArray *format_filter;
PinosProperties *properties;
};
G_DEFINE_TYPE (PinosLink, pinos_link, G_TYPE_OBJECT);
@ -73,8 +67,6 @@ enum
enum
{
SIGNAL_REMOVE,
SIGNAL_ACTIVATE,
SIGNAL_DEACTIVATE,
LAST_SIGNAL
};
@ -206,71 +198,89 @@ link_unregister_object (PinosLink *this)
}
static SpaResult
do_negotiate (PinosLink *this)
do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
{
PinosLinkPrivate *priv = this->priv;
SpaResult res;
SpaFormat *filter, *format;
void *istate = NULL, *ostate = NULL;
g_debug ("link %p: doing set format", this);
priv->negotiated = TRUE;
/* both ports need a format */
if (in_state == SPA_NODE_STATE_CONFIGURE && out_state == SPA_NODE_STATE_CONFIGURE) {
g_debug ("link %p: doing negotiate format", this);
again:
if ((res = spa_node_port_enum_formats (this->input_node->node,
this->input_port,
&filter,
NULL,
&istate)) < 0) {
g_warning ("error input enum formats: %d", res);
goto error;
}
spa_debug_format (filter);
if ((res = spa_node_port_enum_formats (this->output_node->node,
this->output_port,
&format,
filter,
&ostate)) < 0) {
if (res == SPA_RESULT_ENUM_END) {
ostate = NULL;
goto again;
if ((res = spa_node_port_enum_formats (this->input_node->node,
this->input_port,
&filter,
NULL,
&istate)) < 0) {
g_warning ("error input enum formats: %d", res);
goto error;
}
g_warning ("error output enum formats: %d", res);
goto error;
}
spa_format_fixate (format);
spa_debug_format (filter);
if ((res = spa_node_port_enum_formats (this->output_node->node,
this->output_port,
&format,
filter,
&ostate)) < 0) {
if (res == SPA_RESULT_ENUM_END) {
ostate = NULL;
goto again;
}
g_warning ("error output enum formats: %d", res);
goto error;
}
spa_format_fixate (format);
} else if (in_state == SPA_NODE_STATE_CONFIGURE) {
/* only input needs format */
if ((res = spa_node_port_get_format (this->output_node->node, this->output_port, (const SpaFormat **)&format)) < 0) {
g_warning ("error get format output: %d", res);
goto error;
}
} else if (out_state == SPA_NODE_STATE_CONFIGURE) {
/* only output needs format */
if ((res = spa_node_port_get_format (this->input_node->node, this->input_port, (const SpaFormat **)&format)) < 0) {
g_warning ("error get format input: %d", res);
goto error;
}
} else
return SPA_RESULT_OK;
g_debug ("link %p: doing set format", this);
spa_debug_format (format);
if ((res = spa_node_port_set_format (this->output_node->node, this->output_port, 0, format)) < 0) {
g_warning ("error set format output: %d", res);
goto error;
if (out_state == SPA_NODE_STATE_CONFIGURE) {
if ((res = spa_node_port_set_format (this->output_node->node, this->output_port, 0, format)) < 0) {
g_warning ("error set format output: %d", res);
goto error;
}
}
if ((res = spa_node_port_set_format (this->input_node->node, this->input_port, 0, format)) < 0) {
g_warning ("error set format input: %d", res);
goto error;
if (in_state == SPA_NODE_STATE_CONFIGURE) {
if ((res = spa_node_port_set_format (this->input_node->node, this->input_port, 0, format)) < 0) {
g_warning ("error set format input: %d", res);
goto error;
}
}
return SPA_RESULT_OK;
error:
{
priv->negotiated = FALSE;
return res;
}
}
static SpaResult
do_allocation (PinosLink *this)
do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
{
PinosLinkPrivate *priv = this->priv;
SpaResult res;
const SpaPortInfo *iinfo, *oinfo;
SpaPortInfoFlags in_flags, out_flags;
if (in_state != SPA_NODE_STATE_READY || out_state != SPA_NODE_STATE_READY)
return SPA_RESULT_OK;
g_debug ("link %p: doing alloc buffers %p %p", this, this->output_node, this->input_node);
/* find out what's possible */
if ((res = spa_node_port_get_info (this->output_node->node, this->output_port, &oinfo)) < 0) {
@ -282,8 +292,6 @@ do_allocation (PinosLink *this)
goto error;
}
priv->allocated = TRUE;
spa_debug_port_info (oinfo);
spa_debug_port_info (iinfo);
@ -356,49 +364,25 @@ do_allocation (PinosLink *this)
error:
{
priv->allocated = FALSE;
return res;
}
}
static SpaResult
do_start (PinosLink *this)
do_start (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
{
PinosLinkPrivate *priv = this->priv;
SpaCommand cmd;
SpaResult res;
SpaNodeCommand cmd;
SpaResult res = SPA_RESULT_OK;
if (priv->started)
return SPA_RESULT_OK;
priv->started = TRUE;
cmd.type = SPA_COMMAND_START;
if ((res = spa_node_send_command (this->input_node->node, &cmd)) < 0)
g_warning ("got error %d", res);
if ((res = spa_node_send_command (this->output_node->node, &cmd)) < 0)
g_warning ("got error %d", res);
return res;
}
static SpaResult
do_pause (PinosLink *this)
{
PinosLinkPrivate *priv = this->priv;
SpaCommand cmd;
SpaResult res;
if (!priv->started)
return SPA_RESULT_OK;
priv->started = FALSE;
cmd.type = SPA_COMMAND_PAUSE;
if ((res = spa_node_send_command (this->input_node->node, &cmd)) < 0)
g_warning ("got error %d", res);
if ((res = spa_node_send_command (this->output_node->node, &cmd)) < 0)
g_warning ("got error %d", res);
cmd.type = SPA_NODE_COMMAND_START;
if (in_state == SPA_NODE_STATE_PAUSED) {
if ((res = spa_node_send_command (this->input_node->node, &cmd)) < 0)
g_warning ("got error %d", res);
}
if (out_state == SPA_NODE_STATE_PAUSED) {
if ((res = spa_node_send_command (this->output_node->node, &cmd)) < 0)
g_warning ("got error %d", res);
}
return res;
}
@ -406,7 +390,6 @@ do_pause (PinosLink *this)
static SpaResult
check_states (PinosLink *this)
{
PinosLinkPrivate *priv = this->priv;
SpaResult res;
SpaNodeState in_state, out_state;
@ -415,24 +398,15 @@ check_states (PinosLink *this)
g_debug ("link %p: input %d, output %d", this, in_state, out_state);
if (in_state == SPA_NODE_STATE_CONFIGURE &&
out_state == SPA_NODE_STATE_CONFIGURE &&
!priv->negotiated) {
if ((res = do_negotiate (this)) < 0)
return res;
}
if (in_state == SPA_NODE_STATE_READY &&
out_state == SPA_NODE_STATE_READY &&
!priv->allocated) {
if ((res = do_allocation (this)) < 0)
return res;
}
if (in_state == SPA_NODE_STATE_PAUSED &&
out_state == SPA_NODE_STATE_PAUSED &&
!priv->started) {
if ((res = do_start (this)) < 0)
return res;
}
if ((res = do_negotiate (this, in_state, out_state)) < 0)
return res;
if ((res = do_allocation (this, in_state, out_state)) < 0)
return res;
if ((res = do_start (this, in_state, out_state)) < 0)
return res;
return SPA_RESULT_OK;
}
@ -486,26 +460,25 @@ pinos_link_constructed (GObject * object)
g_debug ("link %p: constructed %p:%d -> %p:%d", this, this->output_node, this->output_port,
this->input_node, this->input_port);
link_register_object (this);
check_states (this);
}
static void
pinos_link_dispose (GObject * object)
{
PinosLink *this = PINOS_LINK (object);
PinosLinkPrivate *priv = this->priv;
g_debug ("link %p: dispose", this);
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
g_signal_handlers_disconnect_by_data (this->input_node, this);
g_signal_handlers_disconnect_by_data (this->output_node, this);
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
g_clear_object (&this->input_node);
g_clear_object (&this->output_node);
if (priv->active) {
priv->active = FALSE;
}
link_unregister_object (this);
G_OBJECT_CLASS (pinos_link_parent_class)->dispose (object);
@ -623,26 +596,6 @@ pinos_link_class_init (PinosLinkClass * klass)
G_TYPE_NONE,
0,
G_TYPE_NONE);
signals[SIGNAL_ACTIVATE] = g_signal_new ("activate",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL,
NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
0,
G_TYPE_NONE);
signals[SIGNAL_DEACTIVATE] = g_signal_new ("deactivate",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL,
NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
0,
G_TYPE_NONE);
}
static void
@ -685,23 +638,3 @@ pinos_link_get_object_path (PinosLink *this)
return priv->object_path;
}
gboolean
pinos_link_activate (PinosLink *this)
{
g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
g_signal_emit (this, signals[SIGNAL_ACTIVATE], 0, NULL);
return TRUE;
}
gboolean
pinos_link_deactivate (PinosLink *this)
{
g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
do_pause (this);
g_signal_emit (this, signals[SIGNAL_DEACTIVATE], 0, NULL);
return TRUE;
}

View file

@ -69,9 +69,6 @@ GType pinos_link_get_type (void);
void pinos_link_remove (PinosLink *link);
gboolean pinos_link_activate (PinosLink *link);
gboolean pinos_link_deactivate (PinosLink *link);
PinosProperties * pinos_link_get_properties (PinosLink *link);
const gchar * pinos_link_get_object_path (PinosLink *link);

View file

@ -269,11 +269,11 @@ static void
pause_node (PinosNode *this)
{
SpaResult res;
SpaCommand cmd;
SpaNodeCommand cmd;
g_debug ("node %p: pause node", this);
cmd.type = SPA_COMMAND_PAUSE;
cmd.type = SPA_NODE_COMMAND_PAUSE;
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
g_debug ("got error %d", res);
}
@ -319,64 +319,78 @@ node_set_state (PinosNode *this,
}
typedef struct {
PinosNode *node;
PinosDirection direction;
guint port_id;
} PortData;
static gboolean
do_signal_port_added (PortData *data)
{
g_signal_emit (data->node, signals[SIGNAL_PORT_ADDED], 0, data->direction, data->port_id);
g_slice_free (PortData, data);
return FALSE;
}
static gboolean
do_signal_port_removed (PortData *data)
{
g_signal_emit (data->node, signals[SIGNAL_PORT_REMOVED], 0, data->port_id);
g_slice_free (PortData, data);
return FALSE;
}
static void
on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
{
PinosNode *this = user_data;
PinosNodePrivate *priv = this->priv;
switch (event->type) {
case SPA_EVENT_TYPE_PORT_ADDED:
case SPA_NODE_EVENT_TYPE_PORT_ADDED:
{
SpaEventPortAdded *pa = event->data;
SpaNodeEventPortAdded *pa = event->data;
PortData *data;
update_port_ids (this, FALSE);
g_signal_emit (this, signals[SIGNAL_PORT_ADDED], 0, get_port_direction (this, pa->port_id),
pa->port_id);
data = g_slice_new (PortData);
data->node = this;
data->direction = get_port_direction (this, pa->port_id);
data->port_id = pa->port_id;
g_main_context_invoke (NULL, (GSourceFunc) do_signal_port_added, data);
break;
}
case SPA_EVENT_TYPE_PORT_REMOVED:
case SPA_NODE_EVENT_TYPE_PORT_REMOVED:
{
SpaEventPortRemoved *pr = event->data;
SpaNodeEventPortRemoved *pr = event->data;
PortData *data;
update_port_ids (this, FALSE);
g_signal_emit (this, signals[SIGNAL_PORT_REMOVED], 0, pr->port_id);
data = g_slice_new (PortData);
data->node = this;
data->port_id = pr->port_id;
g_main_context_invoke (NULL, (GSourceFunc) do_signal_port_removed, data);
break;
}
case SPA_EVENT_TYPE_STATE_CHANGE:
case SPA_NODE_EVENT_TYPE_STATE_CHANGE:
{
SpaEventStateChange *sc = event->data;
SpaNodeEventStateChange *sc = event->data;
g_debug ("node %p: update SPA state to %d", this, sc->state);
g_object_notify (G_OBJECT (this), "node-state");
if (sc->state == SPA_NODE_STATE_CONFIGURE) {
update_port_ids (this, FALSE);
}
switch (sc->state) {
case SPA_NODE_STATE_CONFIGURE:
{
GList *links, *walk;
links = pinos_node_get_links (this);
for (walk = links; walk; walk = g_list_next (walk)) {
PinosLink *link = walk->data;
pinos_link_activate (link);
}
g_list_free (links);
}
default:
break;
}
g_object_notify (G_OBJECT (this), "node-state");
break;
}
case SPA_EVENT_TYPE_ADD_POLL:
case SPA_NODE_EVENT_TYPE_ADD_POLL:
{
SpaPollItem *poll = event->data;
g_debug ("node %p: add poll %d", this, poll->n_fds);
g_debug ("node %p: add poll %d, n_fds %d", this, poll->id, poll->n_fds);
priv->poll[priv->n_poll] = *poll;
priv->n_poll++;
if (poll->n_fds)
@ -386,7 +400,7 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
start_thread (this);
break;
}
case SPA_EVENT_TYPE_UPDATE_POLL:
case SPA_NODE_EVENT_TYPE_UPDATE_POLL:
{
unsigned int i;
SpaPollItem *poll = event->data;
@ -400,12 +414,12 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
wakeup_thread (this);
break;
}
case SPA_EVENT_TYPE_REMOVE_POLL:
case SPA_NODE_EVENT_TYPE_REMOVE_POLL:
{
SpaPollItem *poll = event->data;
unsigned int i;
g_debug ("node %p: remove poll %d", this, poll->n_fds);
g_debug ("node %p: remove poll %d %d", this, poll->n_fds, priv->n_poll);
for (i = 0; i < priv->n_poll; i++) {
if (priv->poll[i].id == poll->id) {
priv->n_poll--;
@ -422,33 +436,35 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
}
break;
}
case SPA_EVENT_TYPE_HAVE_OUTPUT:
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
{
PinosLink *link;
SpaOutputInfo oinfo[1] = { 0, };
SpaPortOutputInfo oinfo[1] = { 0, };
SpaResult res;
if ((res = spa_node_port_pull_output (node, 1, oinfo)) < 0)
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;
}
link = g_hash_table_lookup (priv->links, GUINT_TO_POINTER (oinfo[0].port_id));
if (link) {
SpaInputInfo iinfo[1];
SpaPortInputInfo iinfo[1];
iinfo[0].port_id = link->input_port;
iinfo[0].buffer_id = oinfo[0].buffer_id;
iinfo[0].flags = SPA_INPUT_FLAG_NONE;
iinfo[0].flags = SPA_PORT_INPUT_FLAG_NONE;
if ((res = spa_node_port_push_input (link->input_node->node, 1, iinfo)) < 0)
g_warning ("node %p: error pushing buffer: %d, %d", this, res, iinfo[0].status);
}
break;
}
case SPA_EVENT_TYPE_REUSE_BUFFER:
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
{
PinosLink *link;
SpaResult res;
SpaEventReuseBuffer *rb = event->data;
SpaNodeEventReuseBuffer *rb = event->data;
link = g_hash_table_lookup (priv->links, GUINT_TO_POINTER (rb->port_id));
if (link) {