2016-05-12 17:06:48 +02:00
|
|
|
/* Pinos
|
|
|
|
|
* Copyright (C) 2015 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
2016-09-02 19:51:23 +02:00
|
|
|
#include <errno.h>
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
#include "pinos/client/pinos.h"
|
|
|
|
|
#include "pinos/client/enumtypes.h"
|
|
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
#include "pinos/server/node.h"
|
2016-10-20 16:26:55 +02:00
|
|
|
#include "pinos/server/data-loop.h"
|
|
|
|
|
#include "pinos/server/main-loop.h"
|
2016-07-18 17:40:58 +02:00
|
|
|
#include "pinos/server/daemon.h"
|
2016-05-12 17:06:48 +02:00
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
#include "pinos/dbus/org-pinos.h"
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
#define PINOS_NODE_GET_PRIVATE(node) \
|
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((node), PINOS_TYPE_NODE, PinosNodePrivate))
|
|
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
static PinosPort *
|
|
|
|
|
new_pinos_port (PinosNode *node, PinosDirection direction, uint32_t port)
|
2016-09-28 10:42:36 +02:00
|
|
|
{
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *np;
|
|
|
|
|
np = g_slice_new0 (PinosPort);
|
|
|
|
|
np->node = node;
|
|
|
|
|
np->direction = direction;
|
|
|
|
|
np->port = port;
|
2016-09-28 10:42:36 +02:00
|
|
|
np->links = g_ptr_array_new ();
|
|
|
|
|
return np;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-10-19 17:18:30 +02:00
|
|
|
free_node_port (PinosPort *np)
|
2016-09-28 10:42:36 +02:00
|
|
|
{
|
|
|
|
|
g_ptr_array_free (np->links, TRUE);
|
2016-10-19 17:18:30 +02:00
|
|
|
g_slice_free (PinosPort, np);
|
2016-09-28 10:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
static PinosPort *
|
2016-09-28 10:42:36 +02:00
|
|
|
find_node_port (GList *ports, PinosNode *node, uint32_t port)
|
|
|
|
|
{
|
|
|
|
|
GList *walk;
|
|
|
|
|
for (walk = ports; walk; walk = g_list_next (walk)) {
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *np = walk->data;
|
|
|
|
|
if (np->node == node && np->port == port)
|
2016-09-28 10:42:36 +02:00
|
|
|
return np;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2016-09-12 18:29:59 +02:00
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
struct _PinosNodePrivate
|
|
|
|
|
{
|
2016-07-18 17:40:58 +02:00
|
|
|
PinosDaemon *daemon;
|
|
|
|
|
PinosNode1 *iface;
|
|
|
|
|
|
2016-09-27 16:59:45 +02:00
|
|
|
PinosClient *client;
|
2016-07-18 17:40:58 +02:00
|
|
|
gchar *object_path;
|
2016-05-12 17:06:48 +02:00
|
|
|
gchar *name;
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
gboolean async_init;
|
2016-08-29 18:31:53 +02:00
|
|
|
unsigned int max_input_ports;
|
|
|
|
|
unsigned int max_output_ports;
|
|
|
|
|
unsigned int n_input_ports;
|
|
|
|
|
unsigned int n_output_ports;
|
2016-09-28 10:42:36 +02:00
|
|
|
GList *input_ports;
|
|
|
|
|
GList *output_ports;
|
|
|
|
|
guint n_used_output_links;
|
|
|
|
|
guint n_used_input_links;
|
2016-08-29 18:31:53 +02:00
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
PinosNodeState state;
|
|
|
|
|
GError *error;
|
|
|
|
|
guint idle_timeout;
|
|
|
|
|
|
|
|
|
|
PinosProperties *properties;
|
|
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
PinosDataLoop *data_loop;
|
|
|
|
|
PinosMainLoop *main_loop;
|
2016-10-24 18:01:04 +02:00
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
GPtrArray *links;
|
|
|
|
|
} rt;
|
2016-05-12 17:06:48 +02:00
|
|
|
};
|
|
|
|
|
|
2016-09-15 17:51:34 +02:00
|
|
|
G_DEFINE_TYPE (PinosNode, pinos_node, G_TYPE_OBJECT);
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
2016-07-18 17:40:58 +02:00
|
|
|
PROP_DAEMON,
|
2016-09-27 16:59:45 +02:00
|
|
|
PROP_CLIENT,
|
2016-10-20 16:26:55 +02:00
|
|
|
PROP_DATA_LOOP,
|
2016-07-18 17:40:58 +02:00
|
|
|
PROP_OBJECT_PATH,
|
2016-05-12 17:06:48 +02:00
|
|
|
PROP_NAME,
|
|
|
|
|
PROP_PROPERTIES,
|
2016-08-02 16:34:44 +02:00
|
|
|
PROP_NODE,
|
2016-10-12 17:27:29 +02:00
|
|
|
PROP_CLOCK,
|
2016-05-12 17:06:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
SIGNAL_REMOVE,
|
2016-09-23 17:08:20 +02:00
|
|
|
SIGNAL_STATE_CHANGE,
|
2016-08-08 22:10:57 +02:00
|
|
|
SIGNAL_PORT_ADDED,
|
|
|
|
|
SIGNAL_PORT_REMOVED,
|
2016-09-23 17:08:20 +02:00
|
|
|
SIGNAL_ASYNC_COMPLETE,
|
2016-05-12 17:06:48 +02:00
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
static void init_complete (PinosNode *this);
|
2016-09-02 19:51:23 +02:00
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2016-08-29 18:31:53 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_port_ids (PinosNode *node, gboolean create)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv = node->priv;
|
2016-09-28 10:42:36 +02:00
|
|
|
uint32_t *input_port_ids, *output_port_ids;
|
|
|
|
|
guint n_input_ports, n_output_ports, max_input_ports, max_output_ports;
|
|
|
|
|
guint i;
|
|
|
|
|
GList *ports;
|
2016-08-29 18:31:53 +02:00
|
|
|
|
|
|
|
|
if (node->node == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
spa_node_get_n_ports (node->node,
|
2016-09-28 10:42:36 +02:00
|
|
|
&n_input_ports,
|
|
|
|
|
&max_input_ports,
|
|
|
|
|
&n_output_ports,
|
|
|
|
|
&max_output_ports);
|
2016-08-29 18:31:53 +02:00
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
input_port_ids = g_alloca (sizeof (uint32_t) * n_input_ports);
|
|
|
|
|
output_port_ids = g_alloca (sizeof (uint32_t) * n_output_ports);
|
2016-08-29 18:31:53 +02:00
|
|
|
|
|
|
|
|
spa_node_get_port_ids (node->node,
|
2016-09-28 10:42:36 +02:00
|
|
|
max_input_ports,
|
|
|
|
|
input_port_ids,
|
|
|
|
|
max_output_ports,
|
|
|
|
|
output_port_ids);
|
|
|
|
|
|
|
|
|
|
g_debug ("node %p: update_port ids %u/%u, %u/%u", node,
|
|
|
|
|
n_input_ports, max_input_ports, n_output_ports, max_output_ports);
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
i = 0;
|
|
|
|
|
ports = priv->input_ports;
|
2016-09-23 17:08:20 +02:00
|
|
|
while (true) {
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *p = (ports ? ports->data : NULL);
|
2016-09-28 10:42:36 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
if (p && i < n_input_ports && p->port == input_port_ids[i]) {
|
2016-09-23 17:08:20 +02:00
|
|
|
i++;
|
2016-09-28 10:42:36 +02:00
|
|
|
ports = g_list_next (ports);
|
2016-10-19 17:18:30 +02:00
|
|
|
} else if ((p && i < n_input_ports && input_port_ids[i] < p->port) || i < n_input_ports) {
|
|
|
|
|
PinosPort *np;
|
2016-09-28 10:42:36 +02:00
|
|
|
g_debug ("node %p: input port added %d", node, input_port_ids[i]);
|
|
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
np = new_pinos_port (node, PINOS_DIRECTION_INPUT, input_port_ids[i]);
|
2016-09-28 10:42:36 +02:00
|
|
|
priv->input_ports = g_list_insert_before (priv->input_ports, ports, np);
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
if (!priv->async_init)
|
2016-10-19 17:18:30 +02:00
|
|
|
g_signal_emit (node, signals[SIGNAL_PORT_ADDED], 0, np);
|
2016-09-23 17:08:20 +02:00
|
|
|
i++;
|
2016-09-28 10:42:36 +02:00
|
|
|
} else if (p) {
|
|
|
|
|
GList *next;
|
2016-10-19 17:18:30 +02:00
|
|
|
g_debug ("node %p: input port removed %d", node, p->port);
|
2016-09-28 10:42:36 +02:00
|
|
|
|
|
|
|
|
next = g_list_next (ports);
|
|
|
|
|
priv->input_ports = g_list_delete_link (priv->input_ports, ports);
|
|
|
|
|
ports = next;
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
if (!priv->async_init)
|
2016-10-19 17:18:30 +02:00
|
|
|
g_signal_emit (node, signals[SIGNAL_PORT_REMOVED], 0, p);
|
|
|
|
|
|
|
|
|
|
free_node_port (p);
|
2016-09-23 17:08:20 +02:00
|
|
|
} else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-28 10:42:36 +02:00
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
ports = priv->output_ports;
|
2016-09-23 17:08:20 +02:00
|
|
|
while (true) {
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *p = (ports ? ports->data : NULL);
|
2016-09-28 10:42:36 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
if (p && i < n_output_ports && p->port == output_port_ids[i]) {
|
2016-09-23 17:08:20 +02:00
|
|
|
i++;
|
2016-09-28 10:42:36 +02:00
|
|
|
ports = g_list_next (ports);
|
2016-10-19 17:18:30 +02:00
|
|
|
} else if ((p && i < n_output_ports && output_port_ids[i] < p->port) || i < n_output_ports) {
|
|
|
|
|
PinosPort *np;
|
2016-09-28 10:42:36 +02:00
|
|
|
g_debug ("node %p: output port added %d", node, output_port_ids[i]);
|
|
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
np = new_pinos_port (node, PINOS_DIRECTION_OUTPUT, output_port_ids[i]);
|
2016-09-28 10:42:36 +02:00
|
|
|
priv->output_ports = g_list_insert_before (priv->output_ports, ports, np);
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
if (!priv->async_init)
|
2016-10-19 17:18:30 +02:00
|
|
|
g_signal_emit (node, signals[SIGNAL_PORT_ADDED], 0, np);
|
2016-09-23 17:08:20 +02:00
|
|
|
i++;
|
2016-09-28 10:42:36 +02:00
|
|
|
} else if (p) {
|
|
|
|
|
GList *next;
|
2016-10-19 17:18:30 +02:00
|
|
|
g_debug ("node %p: output port removed %d", node, p->port);
|
2016-09-28 10:42:36 +02:00
|
|
|
|
|
|
|
|
next = g_list_next (ports);
|
|
|
|
|
priv->output_ports = g_list_delete_link (priv->output_ports, ports);
|
|
|
|
|
ports = next;
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
if (!priv->async_init)
|
2016-10-19 17:18:30 +02:00
|
|
|
g_signal_emit (node, signals[SIGNAL_PORT_REMOVED], 0, p);
|
|
|
|
|
|
|
|
|
|
free_node_port (p);
|
2016-09-23 17:08:20 +02:00
|
|
|
} else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-28 10:42:36 +02:00
|
|
|
|
|
|
|
|
priv->max_input_ports = max_input_ports;
|
|
|
|
|
priv->max_output_ports = max_output_ports;
|
|
|
|
|
priv->n_input_ports = n_input_ports;
|
|
|
|
|
priv->n_output_ports = n_output_ports;
|
|
|
|
|
|
|
|
|
|
node->have_inputs = priv->n_input_ports > 0;
|
|
|
|
|
node->have_outputs = priv->n_output_ports > 0;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
static SpaResult
|
2016-09-02 19:51:23 +02:00
|
|
|
pause_node (PinosNode *this)
|
2016-07-18 17:40:58 +02:00
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
SpaResult res;
|
2016-09-06 16:43:37 +02:00
|
|
|
SpaNodeCommand cmd;
|
2016-08-08 22:10:57 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("node %p: pause node", this);
|
|
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
cmd.type = SPA_NODE_COMMAND_PAUSE;
|
2016-10-24 15:30:15 +02:00
|
|
|
cmd.size = sizeof (cmd);
|
2016-09-02 19:51:23 +02:00
|
|
|
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
|
|
|
|
g_debug ("got error %d", res);
|
2016-09-23 17:08:20 +02:00
|
|
|
|
|
|
|
|
return res;
|
2016-09-02 19:51:23 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
static SpaResult
|
2016-09-13 10:34:32 +02:00
|
|
|
start_node (PinosNode *this)
|
|
|
|
|
{
|
|
|
|
|
SpaResult res;
|
|
|
|
|
SpaNodeCommand cmd;
|
|
|
|
|
|
|
|
|
|
g_debug ("node %p: start node", this);
|
|
|
|
|
|
|
|
|
|
cmd.type = SPA_NODE_COMMAND_START;
|
2016-10-24 15:30:15 +02:00
|
|
|
cmd.size = sizeof (cmd);
|
2016-09-13 10:34:32 +02:00
|
|
|
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
|
|
|
|
g_debug ("got error %d", res);
|
2016-09-23 17:08:20 +02:00
|
|
|
|
|
|
|
|
return res;
|
2016-09-13 10:34:32 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
static SpaResult
|
2016-09-02 19:51:23 +02:00
|
|
|
suspend_node (PinosNode *this)
|
|
|
|
|
{
|
2016-09-26 12:15:52 +02:00
|
|
|
PinosNodePrivate *priv = this->priv;
|
|
|
|
|
SpaResult res = SPA_RESULT_OK;
|
2016-09-28 10:42:36 +02:00
|
|
|
GList *walk;
|
2016-09-02 19:51:23 +02:00
|
|
|
|
|
|
|
|
g_debug ("node %p: suspend node", this);
|
|
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
for (walk = priv->input_ports; walk; walk = g_list_next (walk)) {
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *p = walk->data;
|
|
|
|
|
if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_INPUT, p->port, 0, NULL)) < 0)
|
2016-09-26 12:15:52 +02:00
|
|
|
g_warning ("error unset format output: %d", res);
|
2016-10-19 17:18:30 +02:00
|
|
|
p->buffers = NULL;
|
|
|
|
|
p->n_buffers = 0;
|
|
|
|
|
if (p->allocated)
|
|
|
|
|
pinos_memblock_free (&p->buffer_mem);
|
|
|
|
|
p->allocated = FALSE;
|
2016-09-26 12:15:52 +02:00
|
|
|
}
|
2016-09-28 10:42:36 +02:00
|
|
|
for (walk = priv->output_ports; walk; walk = g_list_next (walk)) {
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *p = walk->data;
|
|
|
|
|
if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_OUTPUT, p->port, 0, NULL)) < 0)
|
2016-09-26 12:15:52 +02:00
|
|
|
g_warning ("error unset format output: %d", res);
|
2016-10-19 17:18:30 +02:00
|
|
|
p->buffers = NULL;
|
|
|
|
|
p->n_buffers = 0;
|
|
|
|
|
if (p->allocated)
|
|
|
|
|
pinos_memblock_free (&p->buffer_mem);
|
|
|
|
|
p->allocated = FALSE;
|
2016-09-26 12:15:52 +02:00
|
|
|
}
|
2016-09-23 17:08:20 +02:00
|
|
|
return res;
|
2016-07-18 17:40:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-12 12:28:51 +02:00
|
|
|
static void
|
|
|
|
|
send_clock_update (PinosNode *this)
|
|
|
|
|
{
|
2016-09-13 17:43:57 +02:00
|
|
|
SpaNodeCommandClockUpdate cu;
|
|
|
|
|
SpaResult res;
|
|
|
|
|
|
2016-10-24 15:30:15 +02:00
|
|
|
cu.command.type = SPA_NODE_COMMAND_CLOCK_UPDATE;
|
|
|
|
|
cu.command.size = sizeof (cu);
|
2016-09-13 17:43:57 +02:00
|
|
|
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;
|
2016-09-19 19:17:59 +02:00
|
|
|
if (this->clock && this->live) {
|
2016-09-13 17:43:57 +02:00
|
|
|
cu.flags = SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE;
|
2016-09-19 19:17:59 +02:00
|
|
|
res = spa_clock_get_time (this->clock, &cu.rate, &cu.ticks, &cu.monotonic_time);
|
2016-09-13 17:43:57 +02:00
|
|
|
} else {
|
|
|
|
|
cu.rate = 1;
|
|
|
|
|
cu.ticks = 0;
|
|
|
|
|
cu.monotonic_time = 0;
|
2016-09-12 12:28:51 +02:00
|
|
|
}
|
2016-09-13 17:43:57 +02:00
|
|
|
cu.scale = (1 << 16) | 1;
|
|
|
|
|
cu.state = SPA_CLOCK_STATE_RUNNING;
|
|
|
|
|
|
2016-10-24 15:30:15 +02:00
|
|
|
if ((res = spa_node_send_command (this->node, &cu.command)) < 0)
|
2016-09-13 17:43:57 +02:00
|
|
|
g_debug ("got error %d", res);
|
2016-09-12 12:28:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-25 11:15:15 +02:00
|
|
|
static SpaResult
|
|
|
|
|
do_read_link (SpaPoll *poll,
|
|
|
|
|
bool async,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
size_t size,
|
|
|
|
|
void *data,
|
|
|
|
|
void *user_data)
|
2016-09-06 16:43:37 +02:00
|
|
|
{
|
2016-10-25 11:15:15 +02:00
|
|
|
PinosNode *this = user_data;
|
|
|
|
|
PinosLink *link = ((PinosLink**)data)[0];
|
|
|
|
|
size_t offset;
|
2016-09-23 17:08:20 +02:00
|
|
|
SpaResult res;
|
|
|
|
|
|
2016-10-25 11:15:15 +02:00
|
|
|
if (spa_ringbuffer_get_read_offset (&link->ringbuffer, &offset) > 0) {
|
2016-09-23 17:08:20 +02:00
|
|
|
SpaPortInputInfo iinfo[1];
|
|
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
if (link->in_ready <= 0 || link->input == NULL)
|
2016-10-25 11:15:15 +02:00
|
|
|
return SPA_RESULT_OK;
|
2016-09-23 17:08:20 +02:00
|
|
|
|
|
|
|
|
link->in_ready--;
|
|
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
iinfo[0].port_id = link->input->port;
|
2016-10-25 11:15:15 +02:00
|
|
|
iinfo[0].buffer_id = link->queue[offset];
|
2016-09-23 17:08:20 +02:00
|
|
|
iinfo[0].flags = SPA_PORT_INPUT_FLAG_NONE;
|
|
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
if ((res = spa_node_port_push_input (link->input->node->node, 1, iinfo)) < 0)
|
2016-09-23 17:08:20 +02:00
|
|
|
g_warning ("node %p: error pushing buffer: %d, %d", this, res, iinfo[0].status);
|
|
|
|
|
|
|
|
|
|
spa_ringbuffer_read_advance (&link->ringbuffer, 1);
|
|
|
|
|
}
|
2016-10-25 11:15:15 +02:00
|
|
|
return SPA_RESULT_OK;
|
2016-09-06 16:43:37 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-25 11:15:15 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
static void
|
2016-09-06 16:43:37 +02:00
|
|
|
on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
2016-07-22 17:17:44 +02:00
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosNode *this = user_data;
|
|
|
|
|
PinosNodePrivate *priv = this->priv;
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
switch (event->type) {
|
2016-09-22 08:55:30 +02:00
|
|
|
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:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
|
|
|
|
|
{
|
2016-10-24 15:30:15 +02:00
|
|
|
SpaNodeEventAsyncComplete *ac = (SpaNodeEventAsyncComplete *) event;
|
2016-08-29 18:31:53 +02:00
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
g_debug ("node %p: async complete event %d %d", this, ac->seq, ac->res);
|
|
|
|
|
pinos_main_loop_defer_complete (priv->main_loop, this, ac->seq, ac->res);
|
|
|
|
|
g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res);
|
2016-09-02 19:51:23 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-09-09 16:05:58 +02:00
|
|
|
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
|
|
|
|
|
{
|
2016-10-24 15:30:15 +02:00
|
|
|
SpaNodeEventNeedInput *ni = (SpaNodeEventNeedInput *) event;
|
2016-09-28 10:42:36 +02:00
|
|
|
guint i;
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
for (i = 0; i < priv->rt.links->len; i++) {
|
|
|
|
|
PinosLink *link = g_ptr_array_index (priv->rt.links, i);
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
if (link->input == NULL || link->input->port != ni->port_id)
|
|
|
|
|
continue;
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
link->in_ready++;
|
2016-10-25 11:15:15 +02:00
|
|
|
spa_poll_invoke (&link->input->node->priv->data_loop->poll,
|
|
|
|
|
do_read_link,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
sizeof (PinosLink *),
|
|
|
|
|
&link,
|
|
|
|
|
link->input->node);
|
2016-09-23 17:08:20 +02:00
|
|
|
}
|
2016-09-09 16:05:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2016-09-06 16:43:37 +02:00
|
|
|
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
|
2016-09-02 19:51:23 +02:00
|
|
|
{
|
2016-10-24 15:30:15 +02:00
|
|
|
SpaNodeEventHaveOutput *ho = (SpaNodeEventHaveOutput *) event;
|
2016-09-06 16:43:37 +02:00
|
|
|
SpaPortOutputInfo oinfo[1] = { 0, };
|
2016-09-02 19:51:23 +02:00
|
|
|
SpaResult res;
|
2016-09-23 17:08:20 +02:00
|
|
|
gboolean pushed = FALSE;
|
2016-09-28 10:42:36 +02:00
|
|
|
guint i;
|
2016-09-02 19:51:23 +02:00
|
|
|
|
2016-09-22 08:55:30 +02:00
|
|
|
oinfo[0].port_id = ho->port_id;
|
|
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
if ((res = spa_node_port_pull_output (node, 1, oinfo)) < 0) {
|
2016-09-02 19:51:23 +02:00
|
|
|
g_warning ("node %p: got pull error %d, %d", this, res, oinfo[0].status);
|
2016-09-06 16:43:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2016-09-02 19:51:23 +02:00
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
for (i = 0; i < priv->rt.links->len; i++) {
|
|
|
|
|
PinosLink *link = g_ptr_array_index (priv->rt.links, i);
|
2016-10-25 11:15:15 +02:00
|
|
|
size_t offset;
|
2016-09-12 18:29:59 +02:00
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
if (link->output == NULL || link->output->port != ho->port_id)
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-10-25 11:15:15 +02:00
|
|
|
if (spa_ringbuffer_get_write_offset (&link->ringbuffer, &offset) > 0) {
|
|
|
|
|
link->queue[offset] = oinfo[0].buffer_id;
|
2016-09-28 10:42:36 +02:00
|
|
|
spa_ringbuffer_write_advance (&link->ringbuffer, 1);
|
2016-09-13 17:43:57 +02:00
|
|
|
|
2016-10-25 11:15:15 +02:00
|
|
|
spa_poll_invoke (&link->input->node->priv->data_loop->poll,
|
|
|
|
|
do_read_link,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
sizeof (PinosLink *),
|
|
|
|
|
&link,
|
|
|
|
|
link->input->node);
|
|
|
|
|
pushed = TRUE;
|
2016-09-23 17:08:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!pushed) {
|
|
|
|
|
g_debug ("node %p: discarded buffer %u", this, oinfo[0].buffer_id);
|
|
|
|
|
if ((res = spa_node_port_reuse_buffer (node, oinfo[0].port_id, oinfo[0].buffer_id)) < 0)
|
|
|
|
|
g_warning ("node %p: error reuse buffer: %d", node, res);
|
2016-09-02 19:51:23 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-06 16:43:37 +02:00
|
|
|
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
|
2016-09-02 19:51:23 +02:00
|
|
|
{
|
|
|
|
|
SpaResult res;
|
2016-10-24 15:30:15 +02:00
|
|
|
SpaNodeEventReuseBuffer *rb = (SpaNodeEventReuseBuffer *) event;
|
2016-09-12 18:29:59 +02:00
|
|
|
guint i;
|
|
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
for (i = 0; i < priv->rt.links->len; i++) {
|
|
|
|
|
PinosLink *link = g_ptr_array_index (priv->rt.links, i);
|
2016-09-02 19:51:23 +02:00
|
|
|
|
2016-10-25 11:15:15 +02:00
|
|
|
if (link->input == NULL || link->input->port != rb->port_id)
|
2016-10-20 16:26:55 +02:00
|
|
|
continue;
|
|
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
if ((res = spa_node_port_reuse_buffer (link->output->node->node,
|
|
|
|
|
link->output->port,
|
2016-09-02 19:51:23 +02:00
|
|
|
rb->buffer_id)) < 0)
|
|
|
|
|
g_warning ("node %p: error reuse buffer: %d", node, res);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-09 16:05:58 +02:00
|
|
|
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE:
|
2016-09-12 12:28:51 +02:00
|
|
|
send_clock_update (this);
|
2016-09-09 16:05:58 +02:00
|
|
|
break;
|
2016-07-22 17:17:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
static gboolean
|
|
|
|
|
handle_remove (PinosNode1 *interface,
|
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2016-09-26 17:27:04 +02:00
|
|
|
PinosNode *this = user_data;
|
2016-07-18 17:40:58 +02:00
|
|
|
|
2016-09-26 17:27:04 +02:00
|
|
|
g_debug ("node %p: remove", this);
|
|
|
|
|
pinos_node_remove (this);
|
2016-07-18 17:40:58 +02:00
|
|
|
|
|
|
|
|
g_dbus_method_invocation_return_value (invocation,
|
|
|
|
|
g_variant_new ("()"));
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
static void
|
|
|
|
|
pinos_node_get_property (GObject *_object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2016-09-26 17:27:04 +02:00
|
|
|
PinosNode *this = PINOS_NODE (_object);
|
|
|
|
|
PinosNodePrivate *priv = this->priv;
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2016-07-18 17:40:58 +02:00
|
|
|
case PROP_DAEMON:
|
|
|
|
|
g_value_set_object (value, priv->daemon);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-27 16:59:45 +02:00
|
|
|
case PROP_CLIENT:
|
|
|
|
|
g_value_set_object (value, priv->client);
|
2016-07-18 17:40:58 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
case PROP_DATA_LOOP:
|
|
|
|
|
g_value_set_object (value, priv->data_loop);
|
2016-09-26 17:27:04 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
case PROP_OBJECT_PATH:
|
|
|
|
|
g_value_set_string (value, priv->object_path);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
case PROP_NAME:
|
|
|
|
|
g_value_set_string (value, priv->name);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_PROPERTIES:
|
|
|
|
|
g_value_set_boxed (value, priv->properties);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-08-02 16:34:44 +02:00
|
|
|
case PROP_NODE:
|
2016-09-26 17:27:04 +02:00
|
|
|
g_value_set_pointer (value, this->node);
|
2016-08-02 16:34:44 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
case PROP_CLOCK:
|
|
|
|
|
g_value_set_pointer (value, this->clock);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
default:
|
2016-09-26 17:27:04 +02:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
2016-05-12 17:06:48 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_node_set_property (GObject *_object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2016-09-26 17:27:04 +02:00
|
|
|
PinosNode *this = PINOS_NODE (_object);
|
|
|
|
|
PinosNodePrivate *priv = this->priv;
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2016-07-18 17:40:58 +02:00
|
|
|
case PROP_DAEMON:
|
|
|
|
|
priv->daemon = g_value_dup_object (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-27 16:59:45 +02:00
|
|
|
case PROP_CLIENT:
|
|
|
|
|
priv->client = g_value_get_object (value);
|
2016-07-18 17:40:58 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
case PROP_DATA_LOOP:
|
2016-09-26 17:27:04 +02:00
|
|
|
{
|
|
|
|
|
SpaResult res;
|
|
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
if (priv->data_loop)
|
|
|
|
|
g_object_unref (priv->data_loop);
|
|
|
|
|
priv->data_loop = g_value_dup_object (value);
|
2016-09-26 17:27:04 +02:00
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
if (priv->data_loop) {
|
2016-09-26 17:27:04 +02:00
|
|
|
if ((res = spa_node_set_event_callback (this->node, on_node_event, this)) < 0)
|
|
|
|
|
g_warning ("node %p: error setting callback", this);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
case PROP_NAME:
|
|
|
|
|
priv->name = g_value_dup_string (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_PROPERTIES:
|
|
|
|
|
if (priv->properties)
|
|
|
|
|
pinos_properties_free (priv->properties);
|
|
|
|
|
priv->properties = g_value_dup_boxed (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-08-02 16:34:44 +02:00
|
|
|
case PROP_NODE:
|
2016-09-09 16:05:58 +02:00
|
|
|
{
|
2016-09-26 17:27:04 +02:00
|
|
|
this->node = g_value_get_pointer (value);
|
2016-08-02 16:34:44 +02:00
|
|
|
break;
|
2016-09-09 16:05:58 +02:00
|
|
|
}
|
2016-10-12 17:27:29 +02:00
|
|
|
case PROP_CLOCK:
|
|
|
|
|
this->clock = g_value_get_pointer (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
default:
|
2016-09-26 17:27:04 +02:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
2016-05-12 17:06:48 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
static void
|
2016-09-26 17:27:04 +02:00
|
|
|
node_register_object (PinosNode *this)
|
2016-07-18 17:40:58 +02:00
|
|
|
{
|
2016-09-26 17:27:04 +02:00
|
|
|
PinosNodePrivate *priv = this->priv;
|
2016-07-18 17:40:58 +02:00
|
|
|
PinosDaemon *daemon = priv->daemon;
|
|
|
|
|
PinosObjectSkeleton *skel;
|
|
|
|
|
|
|
|
|
|
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_NODE);
|
|
|
|
|
|
|
|
|
|
pinos_object_skeleton_set_node1 (skel, priv->iface);
|
|
|
|
|
|
|
|
|
|
g_free (priv->object_path);
|
|
|
|
|
priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
|
|
|
|
|
g_object_unref (skel);
|
|
|
|
|
|
2016-09-26 17:27:04 +02:00
|
|
|
g_debug ("node %p: register object %s", this, priv->object_path);
|
|
|
|
|
pinos_daemon_add_node (daemon, this);
|
2016-07-18 17:40:58 +02:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-09-26 17:27:04 +02:00
|
|
|
node_unregister_object (PinosNode *this)
|
2016-07-18 17:40:58 +02:00
|
|
|
{
|
2016-09-26 17:27:04 +02:00
|
|
|
PinosNodePrivate *priv = this->priv;
|
2016-07-18 17:40:58 +02:00
|
|
|
|
2016-09-26 17:27:04 +02:00
|
|
|
g_debug ("node %p: unregister object %s", this, priv->object_path);
|
2016-07-18 17:40:58 +02:00
|
|
|
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
2016-09-01 10:04:25 +02:00
|
|
|
g_clear_pointer (&priv->object_path, g_free);
|
2016-09-26 17:27:04 +02:00
|
|
|
pinos_daemon_remove_node (priv->daemon, this);
|
2016-07-18 17:40:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_property_notify (GObject *obj,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2016-09-26 17:27:04 +02:00
|
|
|
PinosNode *this = user_data;
|
|
|
|
|
PinosNodePrivate *priv = this->priv;
|
2016-07-18 17:40:58 +02:00
|
|
|
|
2016-09-27 16:59:45 +02:00
|
|
|
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "client") == 0) {
|
|
|
|
|
if (priv->client)
|
|
|
|
|
pinos_node1_set_owner (priv->iface, pinos_client_get_object_path (priv->client));
|
|
|
|
|
else
|
|
|
|
|
pinos_node1_set_owner (priv->iface, pinos_daemon_get_object_path (priv->daemon));
|
2016-07-18 17:40:58 +02:00
|
|
|
}
|
|
|
|
|
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "name") == 0) {
|
2016-09-26 17:27:04 +02:00
|
|
|
pinos_node1_set_name (priv->iface, pinos_node_get_name (this));
|
2016-07-18 17:40:58 +02:00
|
|
|
}
|
|
|
|
|
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "properties") == 0) {
|
2016-09-26 17:27:04 +02:00
|
|
|
PinosProperties *props = pinos_node_get_properties (this);
|
2016-07-18 17:40:58 +02:00
|
|
|
pinos_node1_set_properties (priv->iface, props ? pinos_properties_to_variant (props) : NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
static void
|
|
|
|
|
init_complete (PinosNode *this)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv = this->priv;
|
|
|
|
|
|
|
|
|
|
update_port_ids (this, FALSE);
|
|
|
|
|
g_debug ("node %p: init completed", this);
|
|
|
|
|
priv->async_init = FALSE;
|
|
|
|
|
on_property_notify (G_OBJECT (this), NULL, this);
|
|
|
|
|
pinos_node_update_state (this, PINOS_NODE_STATE_SUSPENDED);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
static void
|
|
|
|
|
pinos_node_constructed (GObject * obj)
|
|
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosNode *this = PINOS_NODE (obj);
|
|
|
|
|
PinosNodePrivate *priv = this->priv;
|
2016-05-12 17:06:48 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("node %p: constructed", this);
|
2016-05-12 17:06:48 +02:00
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
priv->main_loop = priv->daemon->main_loop;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
|
2016-05-12 17:06:48 +02:00
|
|
|
G_OBJECT_CLASS (pinos_node_parent_class)->constructed (obj);
|
2016-07-18 17:40:58 +02:00
|
|
|
|
2016-09-15 17:51:34 +02:00
|
|
|
if (this->node->info) {
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
if (priv->properties == NULL)
|
|
|
|
|
priv->properties = pinos_properties_new (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < this->node->info->n_items; i++)
|
|
|
|
|
pinos_properties_set (priv->properties,
|
|
|
|
|
this->node->info->items[i].key,
|
|
|
|
|
this->node->info->items[i].value);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
if (this->node->state > SPA_NODE_STATE_INIT) {
|
|
|
|
|
init_complete (this);
|
|
|
|
|
} else {
|
|
|
|
|
priv->async_init = TRUE;
|
2016-10-20 16:26:55 +02:00
|
|
|
pinos_main_loop_defer (priv->main_loop,
|
|
|
|
|
this,
|
|
|
|
|
SPA_RESULT_RETURN_ASYNC (0),
|
|
|
|
|
(PinosDeferFunc) init_complete,
|
2016-10-24 12:20:44 +02:00
|
|
|
NULL,
|
2016-10-20 16:26:55 +02:00
|
|
|
NULL);
|
2016-09-23 17:08:20 +02:00
|
|
|
}
|
2016-09-02 19:51:23 +02:00
|
|
|
node_register_object (this);
|
2016-05-12 17:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_node_dispose (GObject * obj)
|
|
|
|
|
{
|
|
|
|
|
PinosNode *node = PINOS_NODE (obj);
|
2016-10-20 19:36:26 +02:00
|
|
|
PinosNodePrivate *priv = node->priv;
|
2016-05-12 17:06:48 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("node %p: dispose", node);
|
2016-05-17 09:38:30 +02:00
|
|
|
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
2016-07-18 17:40:58 +02:00
|
|
|
|
|
|
|
|
node_unregister_object (node);
|
|
|
|
|
|
2016-10-20 19:36:26 +02:00
|
|
|
pinos_main_loop_defer_cancel (priv->main_loop, node, 0);
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
G_OBJECT_CLASS (pinos_node_parent_class)->dispose (obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_node_finalize (GObject * obj)
|
|
|
|
|
{
|
|
|
|
|
PinosNode *node = PINOS_NODE (obj);
|
|
|
|
|
PinosNodePrivate *priv = node->priv;
|
|
|
|
|
|
|
|
|
|
g_debug ("node %p: finalize", node);
|
2016-07-18 17:40:58 +02:00
|
|
|
g_clear_object (&priv->daemon);
|
|
|
|
|
g_clear_object (&priv->iface);
|
2016-10-20 16:26:55 +02:00
|
|
|
g_clear_object (&priv->data_loop);
|
2016-05-12 17:06:48 +02:00
|
|
|
g_free (priv->name);
|
|
|
|
|
g_clear_error (&priv->error);
|
|
|
|
|
if (priv->properties)
|
|
|
|
|
pinos_properties_free (priv->properties);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (pinos_node_parent_class)->finalize (obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_node_class_init (PinosNodeClass * klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (PinosNodePrivate));
|
|
|
|
|
|
|
|
|
|
gobject_class->constructed = pinos_node_constructed;
|
|
|
|
|
gobject_class->dispose = pinos_node_dispose;
|
|
|
|
|
gobject_class->finalize = pinos_node_finalize;
|
|
|
|
|
gobject_class->set_property = pinos_node_set_property;
|
|
|
|
|
gobject_class->get_property = pinos_node_get_property;
|
|
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_DAEMON,
|
|
|
|
|
g_param_spec_object ("daemon",
|
|
|
|
|
"Daemon",
|
|
|
|
|
"The Daemon",
|
|
|
|
|
PINOS_TYPE_DAEMON,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
2016-09-27 16:59:45 +02:00
|
|
|
PROP_CLIENT,
|
|
|
|
|
g_param_spec_object ("client",
|
|
|
|
|
"Client",
|
|
|
|
|
"The Client",
|
|
|
|
|
PINOS_TYPE_CLIENT,
|
2016-07-18 17:40:58 +02:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_OBJECT_PATH,
|
|
|
|
|
g_param_spec_string ("object-path",
|
|
|
|
|
"Object Path",
|
|
|
|
|
"The object path",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_NAME,
|
|
|
|
|
g_param_spec_string ("name",
|
|
|
|
|
"Name",
|
|
|
|
|
"The node name",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_PROPERTIES,
|
|
|
|
|
g_param_spec_boxed ("properties",
|
|
|
|
|
"Properties",
|
|
|
|
|
"The properties of the node",
|
|
|
|
|
PINOS_TYPE_PROPERTIES,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2016-08-02 16:34:44 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_NODE,
|
|
|
|
|
g_param_spec_pointer ("node",
|
|
|
|
|
"Node",
|
|
|
|
|
"The SPA node",
|
|
|
|
|
G_PARAM_READWRITE |
|
2016-10-12 17:27:29 +02:00
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_CLOCK,
|
|
|
|
|
g_param_spec_pointer ("clock",
|
|
|
|
|
"Clock",
|
|
|
|
|
"The SPA clock",
|
|
|
|
|
G_PARAM_READWRITE |
|
2016-08-02 16:34:44 +02:00
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2016-09-26 17:27:04 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
2016-10-20 16:26:55 +02:00
|
|
|
PROP_DATA_LOOP,
|
|
|
|
|
g_param_spec_object ("data-loop",
|
|
|
|
|
"Data Loop",
|
|
|
|
|
"The Data Loop",
|
|
|
|
|
PINOS_TYPE_DATA_LOOP,
|
2016-09-26 17:27:04 +02:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
0,
|
|
|
|
|
G_TYPE_NONE);
|
2016-09-23 17:08:20 +02:00
|
|
|
signals[SIGNAL_STATE_CHANGE] = g_signal_new ("state-change",
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
2,
|
|
|
|
|
PINOS_TYPE_NODE_STATE,
|
|
|
|
|
PINOS_TYPE_NODE_STATE);
|
2016-08-08 22:10:57 +02:00
|
|
|
signals[SIGNAL_PORT_ADDED] = g_signal_new ("port-added",
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
2016-09-23 17:08:20 +02:00
|
|
|
1,
|
2016-10-19 17:18:30 +02:00
|
|
|
G_TYPE_POINTER);
|
2016-08-08 22:10:57 +02:00
|
|
|
signals[SIGNAL_PORT_REMOVED] = g_signal_new ("port-removed",
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
2016-08-09 14:35:44 +02:00
|
|
|
1,
|
2016-10-19 17:18:30 +02:00
|
|
|
G_TYPE_POINTER);
|
2016-09-23 17:08:20 +02:00
|
|
|
signals[SIGNAL_ASYNC_COMPLETE] = g_signal_new ("async-complete",
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
2,
|
|
|
|
|
G_TYPE_UINT,
|
2016-09-02 19:51:23 +02:00
|
|
|
G_TYPE_UINT);
|
2016-05-12 17:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_node_init (PinosNode * node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv = node->priv = PINOS_NODE_GET_PRIVATE (node);
|
|
|
|
|
|
|
|
|
|
g_debug ("node %p: new", node);
|
2016-07-18 17:40:58 +02:00
|
|
|
priv->iface = pinos_node1_skeleton_new ();
|
|
|
|
|
g_signal_connect (priv->iface, "handle-remove",
|
|
|
|
|
(GCallback) handle_remove,
|
|
|
|
|
node);
|
2016-09-23 17:08:20 +02:00
|
|
|
priv->state = PINOS_NODE_STATE_CREATING;
|
|
|
|
|
pinos_node1_set_state (priv->iface, priv->state);
|
2016-10-24 18:01:04 +02:00
|
|
|
priv->rt.links = g_ptr_array_new_full (256, NULL);
|
2016-07-18 17:40:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-17 09:38:30 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_node_get_name:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
|
|
|
|
* Get the name of @node
|
|
|
|
|
*
|
|
|
|
|
* Returns: the name of @node
|
|
|
|
|
*/
|
|
|
|
|
const gchar *
|
|
|
|
|
pinos_node_get_name (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
|
|
|
|
return priv->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_node_get_state:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
|
|
|
|
* Get the state of @node
|
|
|
|
|
*
|
|
|
|
|
* Returns: the state of @node
|
|
|
|
|
*/
|
|
|
|
|
PinosNodeState
|
|
|
|
|
pinos_node_get_state (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), PINOS_NODE_STATE_ERROR);
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
|
|
|
|
return priv->state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_node_get_properties:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
|
|
|
|
* Get the properties of @node
|
|
|
|
|
*
|
|
|
|
|
* Returns: the properties of @node
|
|
|
|
|
*/
|
|
|
|
|
PinosProperties *
|
|
|
|
|
pinos_node_get_properties (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
|
|
|
|
return priv->properties;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_node_get_daemon:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
|
|
|
|
* Get the daemon of @node.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the daemon of @node.
|
|
|
|
|
*/
|
|
|
|
|
PinosDaemon *
|
|
|
|
|
pinos_node_get_daemon (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
|
|
|
|
return priv->daemon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-09-27 16:59:45 +02:00
|
|
|
* pinos_node_get_client:
|
2016-07-18 17:40:58 +02:00
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
2016-09-27 16:59:45 +02:00
|
|
|
* Get the owner client of @node.
|
2016-07-18 17:40:58 +02:00
|
|
|
*
|
2016-09-27 16:59:45 +02:00
|
|
|
* Returns: the owner client of @node.
|
2016-07-18 17:40:58 +02:00
|
|
|
*/
|
2016-09-27 16:59:45 +02:00
|
|
|
PinosClient *
|
|
|
|
|
pinos_node_get_client (PinosNode *node)
|
2016-07-18 17:40:58 +02:00
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
2016-09-27 16:59:45 +02:00
|
|
|
return priv->client;
|
2016-07-18 17:40:58 +02:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* pinos_node_get_object_path:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
|
|
|
|
* Get the object path of @node.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the object path of @node.
|
|
|
|
|
*/
|
|
|
|
|
const gchar *
|
|
|
|
|
pinos_node_get_object_path (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
|
|
|
|
return priv->object_path;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_node_remove:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
|
|
|
|
* Remove @node. This will stop the transfer on the node and
|
|
|
|
|
* free the resources allocated by @node.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pinos_node_remove (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (PINOS_IS_NODE (node));
|
|
|
|
|
|
2016-06-02 10:37:37 +02:00
|
|
|
g_debug ("node %p: remove", node);
|
2016-05-12 17:06:48 +02:00
|
|
|
g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_node_get_free_port:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
* @direction: a #PinosDirection
|
|
|
|
|
*
|
|
|
|
|
* Find a new unused port id in @node with @direction
|
|
|
|
|
*
|
|
|
|
|
* Returns: the new port id or %SPA_ID_INVALID on error
|
|
|
|
|
*/
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *
|
2016-09-12 18:29:59 +02:00
|
|
|
pinos_node_get_free_port (PinosNode *node,
|
|
|
|
|
PinosDirection direction)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
2016-09-28 10:42:36 +02:00
|
|
|
guint free_port, n_ports, max_ports;
|
|
|
|
|
GList *ports, *walk;
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *port = NULL;
|
2016-09-12 18:29:59 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
2016-09-12 18:29:59 +02:00
|
|
|
priv = node->priv;
|
|
|
|
|
|
|
|
|
|
if (direction == PINOS_DIRECTION_INPUT) {
|
2016-09-28 10:42:36 +02:00
|
|
|
max_ports = priv->max_input_ports;
|
|
|
|
|
n_ports = priv->n_input_ports;
|
|
|
|
|
ports = priv->input_ports;
|
2016-09-12 18:29:59 +02:00
|
|
|
} else {
|
2016-09-28 10:42:36 +02:00
|
|
|
max_ports = priv->max_output_ports;
|
|
|
|
|
n_ports = priv->n_output_ports;
|
|
|
|
|
ports = priv->output_ports;
|
2016-09-12 18:29:59 +02:00
|
|
|
}
|
2016-10-03 19:43:42 +02:00
|
|
|
free_port = 0;
|
2016-09-12 18:29:59 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
g_debug ("node %p: direction %d max %u, n %u, free_port %u", node, direction, max_ports, n_ports, free_port);
|
2016-09-28 10:42:36 +02:00
|
|
|
|
|
|
|
|
for (walk = ports; walk; walk = g_list_next (walk)) {
|
|
|
|
|
PinosPort *p = walk->data;
|
|
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
if (free_port < p->port) {
|
|
|
|
|
port = p;
|
2016-09-28 10:42:36 +02:00
|
|
|
break;
|
2016-10-19 17:18:30 +02:00
|
|
|
}
|
2016-09-28 10:42:36 +02:00
|
|
|
free_port = p->port + 1;
|
2016-09-12 18:29:59 +02:00
|
|
|
}
|
2016-09-28 10:42:36 +02:00
|
|
|
if (free_port >= max_ports && ports) {
|
2016-10-19 17:18:30 +02:00
|
|
|
port = ports->data;
|
2016-09-28 10:42:36 +02:00
|
|
|
} else
|
2016-10-19 17:18:30 +02:00
|
|
|
return NULL;
|
2016-09-28 10:42:36 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
return port;
|
2016-09-28 10:42:36 +02:00
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
static SpaResult
|
|
|
|
|
do_remove_link (SpaPoll *poll,
|
|
|
|
|
bool async,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
size_t size,
|
|
|
|
|
void *data,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
PinosNode *this = user_data;
|
|
|
|
|
PinosNodePrivate *priv = this->priv;
|
|
|
|
|
PinosLink *link = ((PinosLink**)data)[0];
|
|
|
|
|
|
|
|
|
|
g_ptr_array_remove_fast (priv->rt.links, link);
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
static void
|
2016-10-24 18:01:04 +02:00
|
|
|
on_remove_link (PinosLink *link, PinosNode *node)
|
2016-09-02 19:51:23 +02:00
|
|
|
{
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *p;
|
2016-09-28 10:42:36 +02:00
|
|
|
PinosNode *n;
|
|
|
|
|
|
|
|
|
|
if (link->output) {
|
|
|
|
|
n = link->output->node;
|
|
|
|
|
if ((p = find_node_port (n->priv->output_ports, n, link->output->port)))
|
|
|
|
|
if (g_ptr_array_remove_fast (p->links, link))
|
|
|
|
|
n->priv->n_used_output_links--;
|
|
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
spa_poll_invoke (&n->priv->data_loop->poll,
|
|
|
|
|
do_remove_link,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
sizeof (PinosLink *),
|
|
|
|
|
&link,
|
|
|
|
|
n);
|
|
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
if (n->priv->n_used_output_links == 0 &&
|
|
|
|
|
n->priv->n_used_input_links == 0)
|
|
|
|
|
pinos_node_report_idle (n);
|
2016-09-12 18:29:59 +02:00
|
|
|
}
|
2016-09-28 10:42:36 +02:00
|
|
|
if (link->input->node) {
|
|
|
|
|
n = link->input->node;
|
|
|
|
|
if ((p = find_node_port (n->priv->input_ports, n, link->input->port)))
|
|
|
|
|
if (g_ptr_array_remove_fast (p->links, link))
|
|
|
|
|
n->priv->n_used_input_links--;
|
|
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
spa_poll_invoke (&n->priv->data_loop->poll,
|
|
|
|
|
do_remove_link,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
sizeof (PinosLink *),
|
|
|
|
|
&link,
|
|
|
|
|
n);
|
|
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
if (n->priv->n_used_output_links == 0 &&
|
|
|
|
|
n->priv->n_used_input_links == 0)
|
|
|
|
|
pinos_node_report_idle (n);
|
2016-09-12 18:29:59 +02:00
|
|
|
}
|
2016-09-02 19:51:23 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
static SpaResult
|
|
|
|
|
do_add_link (SpaPoll *poll,
|
|
|
|
|
bool async,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
size_t size,
|
|
|
|
|
void *data,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
PinosNode *this = user_data;
|
|
|
|
|
PinosNodePrivate *priv = this->priv;
|
|
|
|
|
PinosLink *link = ((PinosLink**)data)[0];
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (priv->rt.links, link);
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 18:31:53 +02:00
|
|
|
/**
|
2016-09-02 19:51:23 +02:00
|
|
|
* pinos_node_link:
|
|
|
|
|
* @output_node: a #PinosNode
|
2016-09-28 10:42:36 +02:00
|
|
|
* @output_port: an output port
|
|
|
|
|
* @input_port: an input port
|
2016-09-02 19:51:23 +02:00
|
|
|
* @format_filter: a format filter
|
|
|
|
|
* @properties: extra properties
|
2016-09-16 13:13:41 +02:00
|
|
|
* @error: an error or %NULL
|
2016-07-22 17:17:44 +02:00
|
|
|
*
|
2016-10-19 17:18:30 +02:00
|
|
|
* Make a link between @output_port and @input_port with the given ids
|
2016-07-22 17:17:44 +02:00
|
|
|
*
|
2016-09-16 13:13:41 +02:00
|
|
|
* If the ports were already linked, the existing links will be returned.
|
2016-09-02 19:51:23 +02:00
|
|
|
*
|
2016-09-16 13:13:41 +02:00
|
|
|
* If the output id was linked to a different input node or id, it
|
2016-09-02 19:51:23 +02:00
|
|
|
* will be relinked.
|
|
|
|
|
*
|
2016-09-16 13:13:41 +02:00
|
|
|
* Returns: a new #PinosLink or %NULL and @error is set.
|
2016-07-22 17:17:44 +02:00
|
|
|
*/
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosLink *
|
|
|
|
|
pinos_node_link (PinosNode *output_node,
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *output_port,
|
|
|
|
|
PinosPort *input_port,
|
2016-09-02 19:51:23 +02:00
|
|
|
GPtrArray *format_filter,
|
2016-09-16 13:13:41 +02:00
|
|
|
PinosProperties *properties,
|
|
|
|
|
GError **error)
|
2016-07-22 17:17:44 +02:00
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosNode *input_node;
|
2016-09-28 10:42:36 +02:00
|
|
|
PinosLink *link = NULL;
|
|
|
|
|
guint i;
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (output_node), NULL);
|
2016-10-19 17:18:30 +02:00
|
|
|
g_return_val_if_fail (output_port != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (input_port != NULL, NULL);
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
priv = output_node->priv;
|
2016-10-19 17:18:30 +02:00
|
|
|
input_node = input_port->node;
|
2016-09-02 19:51:23 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
g_debug ("node %p: link %u %p:%u", output_node, output_port->port, input_node, input_port->port);
|
2016-09-02 19:51:23 +02:00
|
|
|
|
2016-09-16 13:13:41 +02:00
|
|
|
if (output_node == input_node)
|
|
|
|
|
goto same_node;
|
|
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
for (i = 0; i < output_port->links->len; i++) {
|
|
|
|
|
PinosLink *pl = g_ptr_array_index (output_port->links, i);
|
|
|
|
|
if (pl->input->node == input_node && pl->input == input_port) {
|
2016-09-28 10:42:36 +02:00
|
|
|
link = pl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-12 18:29:59 +02:00
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
if (link) {
|
|
|
|
|
/* FIXME */
|
|
|
|
|
link->input->node = input_node;
|
2016-10-19 17:18:30 +02:00
|
|
|
link->input = input_port;
|
2016-09-28 10:42:36 +02:00
|
|
|
g_object_ref (link);
|
|
|
|
|
} else {
|
2016-09-19 19:17:59 +02:00
|
|
|
input_node->live = output_node->live;
|
|
|
|
|
if (output_node->clock)
|
|
|
|
|
input_node->clock = output_node->clock;
|
|
|
|
|
g_debug ("node %p: clock %p", output_node, output_node->clock);
|
2016-09-28 10:42:36 +02:00
|
|
|
|
|
|
|
|
link = g_object_new (PINOS_TYPE_LINK,
|
2016-09-12 18:29:59 +02:00
|
|
|
"daemon", priv->daemon,
|
2016-10-19 17:18:30 +02:00
|
|
|
"output-port", output_port,
|
|
|
|
|
"input-port", input_port,
|
2016-09-12 18:29:59 +02:00
|
|
|
"format-filter", format_filter,
|
|
|
|
|
"properties", properties,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2016-09-28 10:42:36 +02:00
|
|
|
g_signal_connect (link,
|
2016-09-02 19:51:23 +02:00
|
|
|
"remove",
|
2016-10-24 18:01:04 +02:00
|
|
|
(GCallback) on_remove_link,
|
2016-09-02 19:51:23 +02:00
|
|
|
output_node);
|
|
|
|
|
|
2016-10-24 18:01:04 +02:00
|
|
|
g_ptr_array_add (output_port->links, link);
|
|
|
|
|
g_ptr_array_add (input_port->links, link);
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
output_node->priv->n_used_output_links++;
|
|
|
|
|
input_node->priv->n_used_input_links++;
|
2016-10-24 18:01:04 +02:00
|
|
|
|
|
|
|
|
spa_poll_invoke (&priv->data_loop->poll,
|
|
|
|
|
do_add_link,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
sizeof (PinosLink *),
|
|
|
|
|
&link,
|
|
|
|
|
output_node);
|
|
|
|
|
spa_poll_invoke (&input_node->priv->data_loop->poll,
|
|
|
|
|
do_add_link,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
sizeof (PinosLink *),
|
|
|
|
|
&link,
|
|
|
|
|
input_node);
|
2016-09-02 19:51:23 +02:00
|
|
|
}
|
2016-09-28 10:42:36 +02:00
|
|
|
return link;
|
2016-09-16 13:13:41 +02:00
|
|
|
|
|
|
|
|
same_node:
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
PINOS_ERROR,
|
|
|
|
|
PINOS_ERROR_NODE_LINK,
|
|
|
|
|
"can't link a node to itself");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2016-05-12 17:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-10-19 17:18:30 +02:00
|
|
|
* pinos_node_get_ports:
|
2016-05-12 17:06:48 +02:00
|
|
|
* @node: a #PinosNode
|
2016-10-19 17:18:30 +02:00
|
|
|
* @direction: a #PinosDirection
|
2016-05-12 17:06:48 +02:00
|
|
|
*
|
2016-10-19 17:18:30 +02:00
|
|
|
* Get the port in @node.
|
2016-05-12 17:06:48 +02:00
|
|
|
*
|
2016-10-19 17:18:30 +02:00
|
|
|
* Returns: a #GList of #PinosPort g_list_free after usage.
|
2016-05-12 17:06:48 +02:00
|
|
|
*/
|
|
|
|
|
GList *
|
2016-10-19 17:18:30 +02:00
|
|
|
pinos_node_get_ports (PinosNode *node, PinosDirection direction)
|
2016-05-12 17:06:48 +02:00
|
|
|
{
|
2016-10-19 17:18:30 +02:00
|
|
|
GList *ports;
|
|
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
2016-10-19 17:18:30 +02:00
|
|
|
priv = node->priv;
|
|
|
|
|
|
|
|
|
|
if (direction == PINOS_DIRECTION_INPUT) {
|
|
|
|
|
ports = priv->input_ports;
|
|
|
|
|
} else {
|
|
|
|
|
ports = priv->output_ports;
|
|
|
|
|
}
|
|
|
|
|
return ports;
|
2016-05-12 17:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_idle_timeout (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv = node->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->idle_timeout) {
|
|
|
|
|
g_source_remove (priv->idle_timeout);
|
|
|
|
|
priv->idle_timeout = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 14:57:01 +02:00
|
|
|
static void
|
2016-10-24 12:20:44 +02:00
|
|
|
on_state_complete (PinosNode *node,
|
|
|
|
|
gpointer data,
|
|
|
|
|
SpaResult res)
|
2016-10-21 14:57:01 +02:00
|
|
|
{
|
2016-10-24 12:20:44 +02:00
|
|
|
PinosNodeState state = GPOINTER_TO_INT (data);
|
|
|
|
|
|
|
|
|
|
if (SPA_RESULT_IS_ERROR (res)) {
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
g_set_error (&error,
|
|
|
|
|
PINOS_ERROR,
|
|
|
|
|
PINOS_ERROR_NODE_STATE,
|
|
|
|
|
"error changing node state: %d", res);
|
|
|
|
|
pinos_node_report_error (node, error);
|
|
|
|
|
} else
|
|
|
|
|
pinos_node_update_state (node, state);
|
2016-10-21 14:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 17:06:48 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_node_set_state:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
* @state: a #PinosNodeState
|
|
|
|
|
*
|
|
|
|
|
* Set the state of @node to @state.
|
|
|
|
|
*
|
2016-10-21 14:57:01 +02:00
|
|
|
* Returns: a #SpaResult
|
2016-05-12 17:06:48 +02:00
|
|
|
*/
|
2016-10-21 14:57:01 +02:00
|
|
|
SpaResult
|
2016-05-12 17:06:48 +02:00
|
|
|
pinos_node_set_state (PinosNode *node,
|
|
|
|
|
PinosNodeState state)
|
|
|
|
|
{
|
2016-10-21 14:57:01 +02:00
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
SpaResult res = SPA_RESULT_OK;
|
2016-05-12 17:06:48 +02:00
|
|
|
|
2016-10-21 14:57:01 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_NODE (node), SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
priv = node->priv;
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
remove_idle_timeout (node);
|
|
|
|
|
|
2016-10-21 14:57:01 +02:00
|
|
|
g_debug ("node %p: set state %s", node, pinos_node_state_as_string (state));
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
case PINOS_NODE_STATE_CREATING:
|
|
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
|
|
|
|
|
|
case PINOS_NODE_STATE_SUSPENDED:
|
|
|
|
|
res = suspend_node (node);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PINOS_NODE_STATE_INITIALIZING:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PINOS_NODE_STATE_IDLE:
|
|
|
|
|
res = pause_node (node);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PINOS_NODE_STATE_RUNNING:
|
|
|
|
|
send_clock_update (node);
|
|
|
|
|
res = start_node (node);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PINOS_NODE_STATE_ERROR:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (SPA_RESULT_IS_ERROR (res))
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
|
|
pinos_main_loop_defer (priv->main_loop,
|
|
|
|
|
node,
|
|
|
|
|
res,
|
|
|
|
|
(PinosDeferFunc) on_state_complete,
|
2016-10-24 12:20:44 +02:00
|
|
|
GINT_TO_POINTER (state),
|
|
|
|
|
NULL);
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_node_update_state:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
* @state: a #PinosNodeState
|
|
|
|
|
*
|
|
|
|
|
* Update the state of a node. This method is used from
|
|
|
|
|
* inside @node itself.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pinos_node_update_state (PinosNode *node,
|
|
|
|
|
PinosNodeState state)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
2016-09-23 17:08:20 +02:00
|
|
|
PinosNodeState old;
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
g_return_if_fail (PINOS_IS_NODE (node));
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
old = priv->state;
|
|
|
|
|
if (old != state) {
|
|
|
|
|
g_debug ("node %p: update state from %s -> %s", node,
|
|
|
|
|
pinos_node_state_as_string (old),
|
|
|
|
|
pinos_node_state_as_string (state));
|
2016-05-12 17:06:48 +02:00
|
|
|
priv->state = state;
|
2016-07-20 18:04:34 +02:00
|
|
|
pinos_node1_set_state (priv->iface, state);
|
2016-09-23 17:08:20 +02:00
|
|
|
g_signal_emit (node, signals[SIGNAL_STATE_CHANGE], 0, old, priv->state);
|
2016-05-12 17:06:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_node_report_error:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
* @error: a #GError
|
|
|
|
|
*
|
|
|
|
|
* Report an error from within @node.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pinos_node_report_error (PinosNode *node,
|
|
|
|
|
GError *error)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
2016-09-26 17:27:04 +02:00
|
|
|
PinosNodeState old;
|
2016-05-12 17:06:48 +02:00
|
|
|
|
|
|
|
|
g_return_if_fail (PINOS_IS_NODE (node));
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
2016-09-26 17:27:04 +02:00
|
|
|
old = priv->state;
|
2016-05-12 17:06:48 +02:00
|
|
|
g_clear_error (&priv->error);
|
|
|
|
|
remove_idle_timeout (node);
|
|
|
|
|
priv->error = error;
|
|
|
|
|
priv->state = PINOS_NODE_STATE_ERROR;
|
2016-05-18 12:01:57 +02:00
|
|
|
g_debug ("node %p: got error state %s", node, error->message);
|
2016-09-16 13:13:41 +02:00
|
|
|
pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_ERROR);
|
2016-09-26 17:27:04 +02:00
|
|
|
g_signal_emit (node, signals[SIGNAL_STATE_CHANGE], 0, old, priv->state);
|
2016-05-12 17:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
idle_timeout (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv = node->priv;
|
|
|
|
|
|
|
|
|
|
priv->idle_timeout = 0;
|
2016-05-18 12:01:57 +02:00
|
|
|
g_debug ("node %p: idle timeout", node);
|
2016-05-12 17:06:48 +02:00
|
|
|
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
|
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_node_report_idle:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
|
|
|
|
* Mark @node as being idle. This will start a timeout that will
|
|
|
|
|
* set the node to SUSPENDED.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pinos_node_report_idle (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
PinosNodePrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (PINOS_IS_NODE (node));
|
|
|
|
|
priv = node->priv;
|
|
|
|
|
|
2016-05-18 12:01:57 +02:00
|
|
|
g_debug ("node %p: report idle", node);
|
2016-05-12 17:06:48 +02:00
|
|
|
pinos_node_set_state (node, PINOS_NODE_STATE_IDLE);
|
|
|
|
|
|
|
|
|
|
priv->idle_timeout = g_timeout_add_seconds (3,
|
|
|
|
|
(GSourceFunc) idle_timeout,
|
|
|
|
|
node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_node_report_busy:
|
|
|
|
|
* @node: a #PinosNode
|
|
|
|
|
*
|
|
|
|
|
* Mark @node as being busy. This will set the state of the node
|
|
|
|
|
* to the RUNNING state.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pinos_node_report_busy (PinosNode *node)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (PINOS_IS_NODE (node));
|
|
|
|
|
|
2016-05-18 12:01:57 +02:00
|
|
|
g_debug ("node %p: report busy", node);
|
2016-05-12 17:06:48 +02:00
|
|
|
pinos_node_set_state (node, PINOS_NODE_STATE_RUNNING);
|
|
|
|
|
}
|