mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-22 06:59:59 -05:00
Cleanups
spa_serialize -> pinos_serialize Improve PinosPort, move links to the object and make it part of PinosNode Work on improving signals to react to changes in the graph Error when a client-node becomes unlinked, like when removing a camera.
This commit is contained in:
parent
70fb53cdc6
commit
98dbb6424d
13 changed files with 350 additions and 339 deletions
|
|
@ -334,15 +334,15 @@ do_update_port (SpaProxy *this,
|
|||
port->n_formats = pu->n_possible_formats;
|
||||
port->formats = realloc (port->formats, port->n_formats * sizeof (SpaFormat *));
|
||||
for (i = 0; i < port->n_formats; i++) {
|
||||
size = spa_serialize_format_get_size (pu->possible_formats[i]);
|
||||
port->formats[i] = spa_serialize_format_copy_into (malloc (size), pu->possible_formats[i]);
|
||||
size = pinos_serialize_format_get_size (pu->possible_formats[i]);
|
||||
port->formats[i] = pinos_serialize_format_copy_into (malloc (size), pu->possible_formats[i]);
|
||||
}
|
||||
}
|
||||
if (pu->change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT) {
|
||||
if (port->format)
|
||||
free (port->format);
|
||||
size = spa_serialize_format_get_size (pu->format);
|
||||
port->format = spa_serialize_format_copy_into (malloc (size), pu->format);
|
||||
size = pinos_serialize_format_get_size (pu->format);
|
||||
port->format = pinos_serialize_format_copy_into (malloc (size), pu->format);
|
||||
}
|
||||
|
||||
if (pu->change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_PROPS) {
|
||||
|
|
@ -351,8 +351,8 @@ do_update_port (SpaProxy *this,
|
|||
if (pu->change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_INFO && pu->info) {
|
||||
if (port->info)
|
||||
free (port->info);
|
||||
size = spa_serialize_port_info_get_size (pu->info);
|
||||
port->info = spa_serialize_port_info_copy_into (malloc (size), pu->info);
|
||||
size = pinos_serialize_port_info_get_size (pu->info);
|
||||
port->info = pinos_serialize_port_info_copy_into (malloc (size), pu->info);
|
||||
}
|
||||
|
||||
if (!port->valid) {
|
||||
|
|
@ -654,7 +654,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
b->buffer.datas = b->datas;
|
||||
b->buffer.metas = b->metas;
|
||||
|
||||
b->size = spa_serialize_buffer_get_size (buffers[i]);
|
||||
b->size = pinos_serialize_buffer_get_size (buffers[i]);
|
||||
b->offset = size;
|
||||
|
||||
for (j = 0; j < buffers[i]->n_metas; j++) {
|
||||
|
|
@ -724,7 +724,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
SpaMeta *sbm;
|
||||
SpaData *sbd;
|
||||
|
||||
spa_serialize_buffer_serialize (p, &b->buffer);
|
||||
pinos_serialize_buffer_serialize (p, &b->buffer);
|
||||
|
||||
sb = p;
|
||||
b->buffer.datas = SPA_MEMBER (sb, SPA_PTR_TO_INT (sb->datas), SpaData);
|
||||
|
|
|
|||
|
|
@ -152,20 +152,14 @@ handle_create_node (PinosDaemon1 *interface,
|
|||
props = pinos_properties_from_variant (arg_properties);
|
||||
|
||||
factory = g_hash_table_lookup (priv->node_factories, arg_factory_name);
|
||||
if (factory != NULL) {
|
||||
node = pinos_node_factory_create_node (factory,
|
||||
daemon,
|
||||
client,
|
||||
arg_name,
|
||||
props);
|
||||
} else {
|
||||
node = pinos_node_new (daemon,
|
||||
client,
|
||||
arg_name,
|
||||
props,
|
||||
NULL);
|
||||
}
|
||||
if (factory == NULL)
|
||||
goto no_factory;
|
||||
|
||||
node = pinos_node_factory_create_node (factory,
|
||||
daemon,
|
||||
client,
|
||||
arg_name,
|
||||
props);
|
||||
pinos_properties_free (props);
|
||||
|
||||
if (node == NULL)
|
||||
|
|
@ -187,6 +181,13 @@ handle_create_node (PinosDaemon1 *interface,
|
|||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
no_factory:
|
||||
{
|
||||
g_debug ("daemon %p: could find factory named %s", daemon, arg_factory_name);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "can't find factory");
|
||||
return TRUE;
|
||||
}
|
||||
no_node:
|
||||
{
|
||||
g_debug ("daemon %p: could create node named %s from factory %s", daemon, arg_name, arg_factory_name);
|
||||
|
|
@ -196,6 +197,29 @@ no_node:
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_remove_signal (PinosNode *node,
|
||||
PinosDaemon *daemon)
|
||||
{
|
||||
g_debug ("daemon %p: node %p remove", daemon, node);
|
||||
}
|
||||
|
||||
static void
|
||||
on_link_input_unlinked (PinosLink *link,
|
||||
PinosPort *port,
|
||||
PinosDaemon *daemon)
|
||||
{
|
||||
g_debug ("daemon %p: link %p: input unlinked", daemon, link);
|
||||
}
|
||||
|
||||
static void
|
||||
on_link_output_unlinked (PinosLink *link,
|
||||
PinosPort *port,
|
||||
PinosDaemon *daemon)
|
||||
{
|
||||
g_debug ("daemon %p: link %p: output unlinked", daemon, link);
|
||||
}
|
||||
|
||||
static void
|
||||
on_link_state_notify (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
|
|
@ -209,20 +233,29 @@ on_link_state_notify (GObject *obj,
|
|||
switch (state) {
|
||||
case PINOS_LINK_STATE_ERROR:
|
||||
{
|
||||
g_warning ("daemon %p: link %p: state error: %s", daemon, link, error->message);
|
||||
g_debug ("daemon %p: link %p: state error: %s", daemon, link, error->message);
|
||||
|
||||
if (link->input->node) {
|
||||
if (link->input && link->input->node)
|
||||
pinos_node_report_error (link->input->node, g_error_copy (error));
|
||||
}
|
||||
if (link->output->node) {
|
||||
if (link->output && link->output->node)
|
||||
pinos_node_report_error (link->output->node, g_error_copy (error));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case PINOS_LINK_STATE_UNLINKED:
|
||||
g_warning ("daemon %p: link %p: unlinked", daemon, link);
|
||||
g_debug ("daemon %p: link %p: unlinked", daemon, link);
|
||||
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_LINK,
|
||||
"error node unlinked");
|
||||
|
||||
if (link->input && link->input->node)
|
||||
pinos_node_report_error (link->input->node, g_error_copy (error));
|
||||
if (link->output && link->output->node)
|
||||
pinos_node_report_error (link->output->node, g_error_copy (error));
|
||||
break;
|
||||
|
||||
case PINOS_LINK_STATE_INIT:
|
||||
case PINOS_LINK_STATE_NEGOTIATING:
|
||||
case PINOS_LINK_STATE_ALLOCATING:
|
||||
|
|
@ -233,14 +266,14 @@ on_link_state_notify (GObject *obj,
|
|||
}
|
||||
|
||||
static void
|
||||
on_port_added (PinosNode *node, PinosDirection direction, PinosDaemon *this)
|
||||
on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
|
||||
{
|
||||
PinosClient *client;
|
||||
PinosProperties *props;
|
||||
PinosNode *target;
|
||||
const gchar *path;
|
||||
GError *error = NULL;
|
||||
PinosLink *link;
|
||||
PinosDirection direction = port->direction;
|
||||
|
||||
props = pinos_node_get_properties (node);
|
||||
if (props == NULL)
|
||||
|
|
@ -249,10 +282,9 @@ on_port_added (PinosNode *node, PinosDirection direction, PinosDaemon *this)
|
|||
path = pinos_properties_get (props, "pinos.target.node");
|
||||
|
||||
if (path) {
|
||||
guint target_port;
|
||||
guint node_port;
|
||||
PinosPort *target;
|
||||
|
||||
target = pinos_daemon_find_node (this,
|
||||
target = pinos_daemon_find_port (this,
|
||||
pinos_direction_reverse (direction),
|
||||
path,
|
||||
NULL,
|
||||
|
|
@ -262,36 +294,21 @@ on_port_added (PinosNode *node, PinosDirection direction, PinosDaemon *this)
|
|||
if (target == NULL)
|
||||
goto error;
|
||||
|
||||
target_port = pinos_node_get_free_port (target, pinos_direction_reverse (direction));
|
||||
if (target_port == SPA_ID_INVALID) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_PORT,
|
||||
"can't get free port from target %s", pinos_node_get_object_path (target));
|
||||
goto error;
|
||||
}
|
||||
node_port = pinos_node_get_free_port (node, direction);
|
||||
if (node_port == SPA_ID_INVALID) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_PORT,
|
||||
"can't get free port from node %s", pinos_node_get_object_path (node));
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (direction == PINOS_DIRECTION_OUTPUT)
|
||||
link = pinos_node_link (node, node_port, target, target_port, NULL, NULL, &error);
|
||||
link = pinos_node_link (node, port, target, NULL, NULL, &error);
|
||||
else
|
||||
link = pinos_node_link (target, target_port, node, node_port, NULL, NULL, &error);
|
||||
link = pinos_node_link (target->node, target, port, NULL, NULL, &error);
|
||||
|
||||
if (link == NULL)
|
||||
goto error;
|
||||
|
||||
client = pinos_node_get_client (node);
|
||||
if (client) {
|
||||
if (client)
|
||||
pinos_client_add_object (client, G_OBJECT (link));
|
||||
}
|
||||
|
||||
g_signal_connect (target->node, "remove", (GCallback) on_node_remove_signal, daemon);
|
||||
g_signal_connect (link, "input-unlinked", (GCallback) on_link_input_unlinked, daemon);
|
||||
g_signal_connect (link, "output-unlinked", (GCallback) on_link_output_unlinked, daemon);
|
||||
g_signal_connect (link, "notify::state", (GCallback) on_link_state_notify, daemon);
|
||||
pinos_link_activate (link);
|
||||
|
||||
|
|
@ -307,21 +324,29 @@ error:
|
|||
}
|
||||
|
||||
static void
|
||||
on_port_removed (PinosNode *node, PinosDaemon *daemon)
|
||||
on_port_removed (PinosNode *node, PinosPort *port, PinosDaemon *daemon)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
handle_node_connections (PinosDaemon *daemon,
|
||||
PinosNode *node)
|
||||
on_node_created (PinosNode *node,
|
||||
PinosDaemon *daemon)
|
||||
{
|
||||
PinosDirection direction;
|
||||
GList *ports, *walk;
|
||||
|
||||
direction = node->have_inputs ? PINOS_DIRECTION_INPUT : PINOS_DIRECTION_OUTPUT;
|
||||
ports = pinos_node_get_ports (node, PINOS_DIRECTION_INPUT);
|
||||
for (walk = ports; walk; walk = g_list_next (walk))
|
||||
on_port_added (node, walk->data, daemon);
|
||||
|
||||
on_port_added (node, direction, daemon);
|
||||
ports = pinos_node_get_ports (node, PINOS_DIRECTION_OUTPUT);
|
||||
for (walk = ports; walk; walk = g_list_next (walk))
|
||||
on_port_added (node, walk->data, daemon);
|
||||
|
||||
g_signal_connect (node, "port-added", (GCallback) on_port_added, daemon);
|
||||
g_signal_connect (node, "port-removed", (GCallback) on_port_removed, daemon);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
on_node_state_change (PinosNode *node,
|
||||
PinosNodeState old,
|
||||
|
|
@ -333,7 +358,7 @@ on_node_state_change (PinosNode *node,
|
|||
pinos_node_state_as_string (state));
|
||||
|
||||
if (old == PINOS_NODE_STATE_CREATING && state == PINOS_NODE_STATE_SUSPENDED)
|
||||
handle_node_connections (daemon, node);
|
||||
on_node_created (node, daemon);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -350,17 +375,14 @@ on_node_added (PinosDaemon *daemon, PinosNode *node)
|
|||
|
||||
state = pinos_node_get_state (node);
|
||||
if (state > PINOS_NODE_STATE_CREATING) {
|
||||
handle_node_connections (daemon, node);
|
||||
on_node_created (node, daemon);
|
||||
}
|
||||
g_signal_connect (node, "port-added", (GCallback) on_port_added, daemon);
|
||||
g_signal_connect (node, "port-removed", (GCallback) on_port_removed, daemon);
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_removed (PinosDaemon *daemon, PinosNode *node)
|
||||
{
|
||||
g_debug ("daemon %p: node %p removed", daemon, node);
|
||||
|
||||
g_signal_handlers_disconnect_by_data (node, daemon);
|
||||
}
|
||||
|
||||
|
|
@ -703,7 +725,7 @@ pinos_daemon_remove_node (PinosDaemon *daemon,
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_daemon_find_node:
|
||||
* pinos_daemon_find_port:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @name: a port name
|
||||
* @props: port properties
|
||||
|
|
@ -714,8 +736,8 @@ pinos_daemon_remove_node (PinosDaemon *daemon,
|
|||
*
|
||||
* Returns: a #PinosPort or %NULL when no port could be found.
|
||||
*/
|
||||
PinosNode *
|
||||
pinos_daemon_find_node (PinosDaemon *daemon,
|
||||
PinosPort *
|
||||
pinos_daemon_find_port (PinosDaemon *daemon,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
PinosProperties *props,
|
||||
|
|
@ -724,7 +746,7 @@ pinos_daemon_find_node (PinosDaemon *daemon,
|
|||
GError **error)
|
||||
{
|
||||
PinosDaemonPrivate *priv;
|
||||
PinosNode *best = NULL;
|
||||
PinosPort *best = NULL;
|
||||
GList *nodes;
|
||||
gboolean have_name;
|
||||
|
||||
|
|
@ -740,12 +762,16 @@ pinos_daemon_find_node (PinosDaemon *daemon,
|
|||
|
||||
g_debug ("node path \"%s\"", pinos_node_get_object_path (n));
|
||||
|
||||
if (have_name && g_str_has_suffix (pinos_node_get_object_path (n), name)) {
|
||||
g_debug ("name \"%s\" matches node %p", name, n);
|
||||
best = n;
|
||||
break;
|
||||
}
|
||||
if (have_name) {
|
||||
if (g_str_has_suffix (pinos_node_get_object_path (n), name)) {
|
||||
g_debug ("name \"%s\" matches node %p", name, n);
|
||||
|
||||
best = pinos_node_get_free_port (n, direction);
|
||||
if (best)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
if (best == NULL) {
|
||||
g_set_error (error,
|
||||
|
|
@ -1025,7 +1051,6 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
|
||||
priv->main_loop.size = sizeof (SpaPoll);
|
||||
priv->main_loop.info = NULL;
|
||||
priv->main_loop.info = NULL;
|
||||
priv->main_loop.add_item = do_add_item;
|
||||
priv->main_loop.update_item = do_update_item;
|
||||
priv->main_loop.remove_item = do_remove_item;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ void pinos_daemon_unexport (PinosDaemon *daemon, const gch
|
|||
void pinos_daemon_add_node (PinosDaemon *daemon, PinosNode *node);
|
||||
void pinos_daemon_remove_node (PinosDaemon *daemon, PinosNode *node);
|
||||
|
||||
PinosNode * pinos_daemon_find_node (PinosDaemon *daemon,
|
||||
PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
PinosProperties *props,
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ enum
|
|||
enum
|
||||
{
|
||||
SIGNAL_REMOVE,
|
||||
SIGNAL_INPUT_UNLINKED,
|
||||
SIGNAL_OUTPUT_UNLINKED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
|
|
@ -735,12 +737,22 @@ on_property_notify (GObject *obj,
|
|||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output-port") == 0) {
|
||||
pinos_link1_set_output_node (priv->iface, pinos_node_get_object_path (this->output->node));
|
||||
pinos_link1_set_output_port (priv->iface, this->output->port);
|
||||
if (this->output) {
|
||||
pinos_link1_set_output_node (priv->iface, pinos_node_get_object_path (this->output->node));
|
||||
pinos_link1_set_output_port (priv->iface, this->output->port);
|
||||
} else {
|
||||
pinos_link1_set_output_node (priv->iface, "/");
|
||||
pinos_link1_set_output_port (priv->iface, -1);
|
||||
}
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "input-port") == 0) {
|
||||
pinos_link1_set_input_node (priv->iface, pinos_node_get_object_path (this->input->node));
|
||||
pinos_link1_set_input_port (priv->iface, this->input->port);
|
||||
if (this->input) {
|
||||
pinos_link1_set_input_node (priv->iface, pinos_node_get_object_path (this->input->node));
|
||||
pinos_link1_set_input_port (priv->iface, this->input->port);
|
||||
} else {
|
||||
pinos_link1_set_input_node (priv->iface, "/");
|
||||
pinos_link1_set_input_port (priv->iface, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -756,15 +768,20 @@ on_node_remove (PinosNode *node, PinosLink *this)
|
|||
priv->n_buffers = 0;
|
||||
}
|
||||
this->input = NULL;
|
||||
g_object_notify (G_OBJECT (this), "input-port");
|
||||
g_signal_emit (this, signals[SIGNAL_INPUT_UNLINKED], 0, node);
|
||||
} else {
|
||||
if (this->output->allocated) {
|
||||
priv->buffers = NULL;
|
||||
priv->n_buffers = 0;
|
||||
}
|
||||
this->output = NULL;
|
||||
g_object_notify (G_OBJECT (this), "output-port");
|
||||
g_signal_emit (this, signals[SIGNAL_OUTPUT_UNLINKED], 0, node);
|
||||
}
|
||||
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_UNLINKED);
|
||||
if (this->input == NULL || this->output == NULL)
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_UNLINKED);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -796,9 +813,9 @@ pinos_link_dispose (GObject * object)
|
|||
|
||||
g_debug ("link %p: dispose", this);
|
||||
|
||||
if (this->input->node)
|
||||
if (this->input && this->input->node)
|
||||
g_signal_handlers_disconnect_by_data (this->input->node, this);
|
||||
if (this->output->node)
|
||||
if (this->output && this->output->node)
|
||||
g_signal_handlers_disconnect_by_data (this->output->node, this);
|
||||
|
||||
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
|
|
@ -929,6 +946,26 @@ pinos_link_class_init (PinosLinkClass * klass)
|
|||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
signals[SIGNAL_INPUT_UNLINKED] = g_signal_new ("input-unlinked",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
G_TYPE_POINTER);
|
||||
signals[SIGNAL_OUTPUT_UNLINKED] = g_signal_new ("output-unlinked",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
G_TYPE_POINTER);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -41,15 +41,6 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate;
|
|||
#define PINOS_LINK_CAST(obj) ((PinosLink*)(obj))
|
||||
#define PINOS_LINK_CLASS_CAST(klass)((PinosLinkClass*)(klass))
|
||||
|
||||
typedef struct {
|
||||
PinosNode *node;
|
||||
uint32_t port;
|
||||
gboolean allocated;
|
||||
PinosMemblock buffer_mem;
|
||||
SpaBuffer **buffers;
|
||||
guint n_buffers;
|
||||
} PinosPort;
|
||||
|
||||
/**
|
||||
* PinosLink:
|
||||
*
|
||||
|
|
|
|||
|
|
@ -33,36 +33,32 @@
|
|||
#define PINOS_NODE_GET_PRIVATE(node) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((node), PINOS_TYPE_NODE, PinosNodePrivate))
|
||||
|
||||
typedef struct {
|
||||
PinosPort port;
|
||||
GPtrArray *links;
|
||||
} NodePort;
|
||||
|
||||
static NodePort *
|
||||
new_node_port (PinosNode *node, uint32_t port)
|
||||
static PinosPort *
|
||||
new_pinos_port (PinosNode *node, PinosDirection direction, uint32_t port)
|
||||
{
|
||||
NodePort *np;
|
||||
np = g_slice_new0 (NodePort);
|
||||
np->port.node = node;
|
||||
np->port.port = port;
|
||||
PinosPort *np;
|
||||
np = g_slice_new0 (PinosPort);
|
||||
np->node = node;
|
||||
np->direction = direction;
|
||||
np->port = port;
|
||||
np->links = g_ptr_array_new ();
|
||||
return np;
|
||||
}
|
||||
|
||||
static void
|
||||
free_node_port (NodePort *np)
|
||||
free_node_port (PinosPort *np)
|
||||
{
|
||||
g_ptr_array_free (np->links, TRUE);
|
||||
g_slice_free (NodePort, np);
|
||||
g_slice_free (PinosPort, np);
|
||||
}
|
||||
|
||||
static NodePort *
|
||||
static PinosPort *
|
||||
find_node_port (GList *ports, PinosNode *node, uint32_t port)
|
||||
{
|
||||
GList *walk;
|
||||
for (walk = ports; walk; walk = g_list_next (walk)) {
|
||||
NodePort *np = walk->data;
|
||||
if (np->port.node == node && np->port.port == port)
|
||||
PinosPort *np = walk->data;
|
||||
if (np->node == node && np->port == port)
|
||||
return np;
|
||||
}
|
||||
return NULL;
|
||||
|
|
@ -162,33 +158,33 @@ update_port_ids (PinosNode *node, gboolean create)
|
|||
i = 0;
|
||||
ports = priv->input_ports;
|
||||
while (true) {
|
||||
NodePort *p = (ports ? ports->data : NULL);
|
||||
PinosPort *p = (ports ? ports->data : NULL);
|
||||
|
||||
if (p && i < n_input_ports && p->port.port == input_port_ids[i]) {
|
||||
if (p && i < n_input_ports && p->port == input_port_ids[i]) {
|
||||
i++;
|
||||
ports = g_list_next (ports);
|
||||
} else if ((p && i < n_input_ports && input_port_ids[i] < p->port.port) || i < n_input_ports) {
|
||||
NodePort *np;
|
||||
} else if ((p && i < n_input_ports && input_port_ids[i] < p->port) || i < n_input_ports) {
|
||||
PinosPort *np;
|
||||
g_debug ("node %p: input port added %d", node, input_port_ids[i]);
|
||||
|
||||
np = new_node_port (node, input_port_ids[i]);
|
||||
np = new_pinos_port (node, PINOS_DIRECTION_INPUT, input_port_ids[i]);
|
||||
priv->input_ports = g_list_insert_before (priv->input_ports, ports, np);
|
||||
|
||||
if (!priv->async_init)
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_ADDED], 0, PINOS_DIRECTION_INPUT);
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_ADDED], 0, np);
|
||||
i++;
|
||||
} else if (p) {
|
||||
GList *next;
|
||||
g_debug ("node %p: input port removed %d", node, p->port.port);
|
||||
g_debug ("node %p: input port removed %d", node, p->port);
|
||||
|
||||
next = g_list_next (ports);
|
||||
priv->input_ports = g_list_delete_link (priv->input_ports, ports);
|
||||
ports = next;
|
||||
|
||||
free_node_port (p);
|
||||
|
||||
if (!priv->async_init)
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_REMOVED], 0, PINOS_DIRECTION_INPUT);
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_REMOVED], 0, p);
|
||||
|
||||
free_node_port (p);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
|
@ -196,33 +192,33 @@ update_port_ids (PinosNode *node, gboolean create)
|
|||
i = 0;
|
||||
ports = priv->output_ports;
|
||||
while (true) {
|
||||
NodePort *p = (ports ? ports->data : NULL);
|
||||
PinosPort *p = (ports ? ports->data : NULL);
|
||||
|
||||
if (p && i < n_output_ports && p->port.port == output_port_ids[i]) {
|
||||
if (p && i < n_output_ports && p->port == output_port_ids[i]) {
|
||||
i++;
|
||||
ports = g_list_next (ports);
|
||||
} else if ((p && i < n_output_ports && output_port_ids[i] < p->port.port) || i < n_output_ports) {
|
||||
NodePort *np;
|
||||
} else if ((p && i < n_output_ports && output_port_ids[i] < p->port) || i < n_output_ports) {
|
||||
PinosPort *np;
|
||||
g_debug ("node %p: output port added %d", node, output_port_ids[i]);
|
||||
|
||||
np = new_node_port (node, output_port_ids[i]);
|
||||
np = new_pinos_port (node, PINOS_DIRECTION_OUTPUT, output_port_ids[i]);
|
||||
priv->output_ports = g_list_insert_before (priv->output_ports, ports, np);
|
||||
|
||||
if (!priv->async_init)
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_ADDED], 0, PINOS_DIRECTION_INPUT);
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_ADDED], 0, np);
|
||||
i++;
|
||||
} else if (p) {
|
||||
GList *next;
|
||||
g_debug ("node %p: output port removed %d", node, p->port.port);
|
||||
g_debug ("node %p: output port removed %d", node, p->port);
|
||||
|
||||
next = g_list_next (ports);
|
||||
priv->output_ports = g_list_delete_link (priv->output_ports, ports);
|
||||
ports = next;
|
||||
|
||||
free_node_port (p);
|
||||
|
||||
if (!priv->async_init)
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_REMOVED], 0, PINOS_DIRECTION_INPUT);
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_REMOVED], 0, p);
|
||||
|
||||
free_node_port (p);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
|
@ -281,24 +277,24 @@ suspend_node (PinosNode *this)
|
|||
g_debug ("node %p: suspend node", this);
|
||||
|
||||
for (walk = priv->input_ports; walk; walk = g_list_next (walk)) {
|
||||
NodePort *p = walk->data;
|
||||
if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_INPUT, p->port.port, 0, NULL)) < 0)
|
||||
PinosPort *p = walk->data;
|
||||
if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_INPUT, p->port, 0, NULL)) < 0)
|
||||
g_warning ("error unset format output: %d", res);
|
||||
p->port.buffers = NULL;
|
||||
p->port.n_buffers = 0;
|
||||
if (p->port.allocated)
|
||||
pinos_memblock_free (&p->port.buffer_mem);
|
||||
p->port.allocated = FALSE;
|
||||
p->buffers = NULL;
|
||||
p->n_buffers = 0;
|
||||
if (p->allocated)
|
||||
pinos_memblock_free (&p->buffer_mem);
|
||||
p->allocated = FALSE;
|
||||
}
|
||||
for (walk = priv->output_ports; walk; walk = g_list_next (walk)) {
|
||||
NodePort *p = walk->data;
|
||||
if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_OUTPUT, p->port.port, 0, NULL)) < 0)
|
||||
PinosPort *p = walk->data;
|
||||
if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_OUTPUT, p->port, 0, NULL)) < 0)
|
||||
g_warning ("error unset format output: %d", res);
|
||||
p->port.buffers = NULL;
|
||||
p->port.n_buffers = 0;
|
||||
if (p->port.allocated)
|
||||
pinos_memblock_free (&p->port.buffer_mem);
|
||||
p->port.allocated = FALSE;
|
||||
p->buffers = NULL;
|
||||
p->n_buffers = 0;
|
||||
if (p->allocated)
|
||||
pinos_memblock_free (&p->buffer_mem);
|
||||
p->allocated = FALSE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -457,7 +453,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
|
||||
{
|
||||
SpaNodeEventNeedInput *ni = event->data;
|
||||
NodePort *p;
|
||||
PinosPort *p;
|
||||
guint i;
|
||||
|
||||
if (!(p = find_node_port (priv->input_ports, this, ni->port_id)))
|
||||
|
|
@ -477,7 +473,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
SpaPortOutputInfo oinfo[1] = { 0, };
|
||||
SpaResult res;
|
||||
gboolean pushed = FALSE;
|
||||
NodePort *p;
|
||||
PinosPort *p;
|
||||
guint i;
|
||||
|
||||
oinfo[0].port_id = ho->port_id;
|
||||
|
|
@ -513,7 +509,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
{
|
||||
SpaResult res;
|
||||
SpaNodeEventReuseBuffer *rb = event->data;
|
||||
NodePort *p;
|
||||
PinosPort *p;
|
||||
guint i;
|
||||
|
||||
if (!(p = find_node_port (priv->input_ports, this, rb->port_id)))
|
||||
|
|
@ -912,7 +908,7 @@ pinos_node_class_init (PinosNodeClass * klass)
|
|||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
PINOS_TYPE_DIRECTION);
|
||||
G_TYPE_POINTER);
|
||||
signals[SIGNAL_PORT_REMOVED] = g_signal_new ("port-removed",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
|
|
@ -922,7 +918,7 @@ pinos_node_class_init (PinosNodeClass * klass)
|
|||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
PINOS_TYPE_DIRECTION);
|
||||
G_TYPE_POINTER);
|
||||
signals[SIGNAL_ASYNC_COMPLETE] = g_signal_new ("async-complete",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
|
|
@ -953,35 +949,6 @@ pinos_node_init (PinosNode * node)
|
|||
pinos_node1_set_state (priv->iface, priv->state);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_new:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @client: the client owner
|
||||
* @name: a name
|
||||
* @properties: extra properties
|
||||
*
|
||||
* Create a new #PinosNode.
|
||||
*
|
||||
* Returns: a new #PinosNode
|
||||
*/
|
||||
PinosNode *
|
||||
pinos_node_new (PinosDaemon *daemon,
|
||||
PinosClient *client,
|
||||
const gchar *name,
|
||||
PinosProperties *properties,
|
||||
SpaNode *node)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
||||
|
||||
return g_object_new (PINOS_TYPE_NODE,
|
||||
"daemon", daemon,
|
||||
"client", client,
|
||||
"name", name,
|
||||
"properties", properties,
|
||||
"node", node,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_name:
|
||||
* @node: a #PinosNode
|
||||
|
|
@ -1120,15 +1087,16 @@ pinos_node_remove (PinosNode *node)
|
|||
*
|
||||
* Returns: the new port id or %SPA_ID_INVALID on error
|
||||
*/
|
||||
guint
|
||||
PinosPort *
|
||||
pinos_node_get_free_port (PinosNode *node,
|
||||
PinosDirection direction)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
guint free_port, n_ports, max_ports;
|
||||
GList *ports, *walk;
|
||||
PinosPort *port = NULL;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), SPA_ID_INVALID);
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
if (direction == PINOS_DIRECTION_INPUT) {
|
||||
|
|
@ -1147,26 +1115,25 @@ pinos_node_get_free_port (PinosNode *node,
|
|||
for (walk = ports; walk; walk = g_list_next (walk)) {
|
||||
PinosPort *p = walk->data;
|
||||
|
||||
if (free_port < p->port)
|
||||
if (free_port < p->port) {
|
||||
port = p;
|
||||
break;
|
||||
|
||||
}
|
||||
free_port = p->port + 1;
|
||||
}
|
||||
if (free_port >= max_ports && ports) {
|
||||
PinosPort *p = ports->data;
|
||||
|
||||
free_port = p->port;
|
||||
port = ports->data;
|
||||
} else
|
||||
return SPA_ID_INVALID;
|
||||
return NULL;
|
||||
|
||||
return free_port;
|
||||
return port;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
do_remove_link (PinosLink *link, PinosNode *node)
|
||||
{
|
||||
NodePort *p;
|
||||
PinosPort *p;
|
||||
PinosNode *n;
|
||||
|
||||
if (link->output) {
|
||||
|
|
@ -1195,13 +1162,12 @@ do_remove_link (PinosLink *link, PinosNode *node)
|
|||
* pinos_node_link:
|
||||
* @output_node: a #PinosNode
|
||||
* @output_port: an output port
|
||||
* @input_node: a #PinosNode
|
||||
* @input_port: an input port
|
||||
* @format_filter: a format filter
|
||||
* @properties: extra properties
|
||||
* @error: an error or %NULL
|
||||
*
|
||||
* Make a link between @output_node and @input_node with the given ids
|
||||
* Make a link between @output_port and @input_port with the given ids
|
||||
*
|
||||
* If the ports were already linked, the existing links will be returned.
|
||||
*
|
||||
|
|
@ -1212,47 +1178,41 @@ do_remove_link (PinosLink *link, PinosNode *node)
|
|||
*/
|
||||
PinosLink *
|
||||
pinos_node_link (PinosNode *output_node,
|
||||
guint output_port,
|
||||
PinosNode *input_node,
|
||||
guint input_port,
|
||||
PinosPort *output_port,
|
||||
PinosPort *input_port,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties,
|
||||
GError **error)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
NodePort *onp, *inp;
|
||||
PinosNode *input_node;
|
||||
PinosLink *link = NULL;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (output_node), NULL);
|
||||
g_return_val_if_fail (PINOS_IS_NODE (input_node), NULL);
|
||||
g_return_val_if_fail (output_port != NULL, NULL);
|
||||
g_return_val_if_fail (input_port != NULL, NULL);
|
||||
|
||||
priv = output_node->priv;
|
||||
input_node = input_port->node;
|
||||
|
||||
g_debug ("node %p: link %u %p:%u", output_node, output_port, input_node, input_port);
|
||||
g_debug ("node %p: link %u %p:%u", output_node, output_port->port, input_node, input_port->port);
|
||||
|
||||
if (output_node == input_node)
|
||||
goto same_node;
|
||||
|
||||
onp = find_node_port (priv->output_ports, output_node, output_port);
|
||||
if (onp == NULL)
|
||||
goto no_output_ports;
|
||||
|
||||
for (i = 0; i < onp->links->len; i++) {
|
||||
PinosLink *pl = g_ptr_array_index (onp->links, i);
|
||||
if (pl->input->node == input_node && pl->input->port == input_port) {
|
||||
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) {
|
||||
link = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
inp = find_node_port (input_node->priv->input_ports, input_node, input_port);
|
||||
if (inp == NULL)
|
||||
goto no_input_ports;
|
||||
|
||||
if (link) {
|
||||
/* FIXME */
|
||||
link->input->node = input_node;
|
||||
link->input->port = input_port;
|
||||
link->input = input_port;
|
||||
g_object_ref (link);
|
||||
} else {
|
||||
input_node->live = output_node->live;
|
||||
|
|
@ -1262,14 +1222,14 @@ pinos_node_link (PinosNode *output_node,
|
|||
|
||||
link = g_object_new (PINOS_TYPE_LINK,
|
||||
"daemon", priv->daemon,
|
||||
"output-port", &onp->port,
|
||||
"input-port", &inp->port,
|
||||
"output-port", output_port,
|
||||
"input-port", input_port,
|
||||
"format-filter", format_filter,
|
||||
"properties", properties,
|
||||
NULL);
|
||||
|
||||
g_ptr_array_add (onp->links, link);
|
||||
g_ptr_array_add (inp->links, link);
|
||||
g_ptr_array_add (output_port->links, link);
|
||||
g_ptr_array_add (input_port->links, link);
|
||||
|
||||
g_signal_connect (link,
|
||||
"remove",
|
||||
|
|
@ -1289,37 +1249,32 @@ same_node:
|
|||
"can't link a node to itself");
|
||||
return NULL;
|
||||
}
|
||||
no_input_ports:
|
||||
{
|
||||
g_set_error (error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_LINK,
|
||||
"can't get an input port to link to");
|
||||
return NULL;
|
||||
}
|
||||
no_output_ports:
|
||||
{
|
||||
g_set_error (error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_LINK,
|
||||
"can't get an output port to link to");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_links:
|
||||
* pinos_node_get_ports:
|
||||
* @node: a #PinosNode
|
||||
* @direction: a #PinosDirection
|
||||
*
|
||||
* Get the links in @node.
|
||||
* Get the port in @node.
|
||||
*
|
||||
* Returns: a #GList of #PinosLink g_list_free after usage.
|
||||
* Returns: a #GList of #PinosPort g_list_free after usage.
|
||||
*/
|
||||
GList *
|
||||
pinos_node_get_links (PinosNode *node)
|
||||
pinos_node_get_ports (PinosNode *node, PinosDirection direction)
|
||||
{
|
||||
GList *ports;
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
return NULL;
|
||||
priv = node->priv;
|
||||
|
||||
if (direction == PINOS_DIRECTION_INPUT) {
|
||||
ports = priv->input_ports;
|
||||
} else {
|
||||
ports = priv->output_ports;
|
||||
}
|
||||
return ports;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _PinosPort PinosPort;
|
||||
typedef struct _PinosNode PinosNode;
|
||||
typedef struct _PinosNodeClass PinosNodeClass;
|
||||
typedef struct _PinosNodePrivate PinosNodePrivate;
|
||||
|
|
@ -34,6 +35,18 @@ typedef struct _PinosNodePrivate PinosNodePrivate;
|
|||
#include <pinos/server/daemon.h>
|
||||
#include <pinos/server/link.h>
|
||||
#include <pinos/server/client.h>
|
||||
#include <pinos/server/utils.h>
|
||||
|
||||
struct _PinosPort {
|
||||
PinosNode *node;
|
||||
PinosDirection direction;
|
||||
uint32_t port;
|
||||
gboolean allocated;
|
||||
PinosMemblock buffer_mem;
|
||||
SpaBuffer **buffers;
|
||||
guint n_buffers;
|
||||
GPtrArray *links;
|
||||
};
|
||||
|
||||
#define PINOS_TYPE_NODE (pinos_node_get_type ())
|
||||
#define PINOS_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE))
|
||||
|
|
@ -79,11 +92,6 @@ struct _PinosNodeClass {
|
|||
/* normal GObject stuff */
|
||||
GType pinos_node_get_type (void);
|
||||
|
||||
PinosNode * pinos_node_new (PinosDaemon *daemon,
|
||||
PinosClient *client,
|
||||
const gchar *name,
|
||||
PinosProperties *properties,
|
||||
SpaNode *node);
|
||||
void pinos_node_remove (PinosNode *node);
|
||||
|
||||
const gchar * pinos_node_get_name (PinosNode *node);
|
||||
|
|
@ -93,18 +101,17 @@ PinosDaemon * pinos_node_get_daemon (PinosNode *node);
|
|||
PinosClient * pinos_node_get_client (PinosNode *node);
|
||||
const gchar * pinos_node_get_object_path (PinosNode *node);
|
||||
|
||||
guint pinos_node_get_free_port (PinosNode *node,
|
||||
PinosPort * pinos_node_get_free_port (PinosNode *node,
|
||||
PinosDirection direction);
|
||||
|
||||
PinosLink * pinos_node_link (PinosNode *output_node,
|
||||
guint output_id,
|
||||
PinosNode *input_node,
|
||||
guint input_id,
|
||||
PinosPort *output_port,
|
||||
PinosPort *input_port,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties,
|
||||
GError **error);
|
||||
GList * pinos_node_get_links (PinosNode *node);
|
||||
|
||||
GList * pinos_node_get_ports (PinosNode *node,
|
||||
PinosDirection direction);
|
||||
|
||||
PinosNodeState pinos_node_get_state (PinosNode *node);
|
||||
gboolean pinos_node_set_state (PinosNode *node, PinosNodeState state);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue