node: add support for multiple input and output ports

Make it possible to have a mixer/spliter and converter for the gstreamer
sources and sinks.
Add logic to make a new input/output port when the existing ports are
not of the required format.
This commit is contained in:
Wim Taymans 2016-07-05 12:24:51 +02:00
parent e7e141a31d
commit ca4f3d84cd
12 changed files with 568 additions and 186 deletions

View file

@ -344,14 +344,38 @@ pinos_node_create_port_finish (PinosNode *node,
priv = node->priv;
port = g_task_propagate_pointer (G_TASK (res), error);
if (port) {
priv->ports = g_list_append (priv->ports, port);
g_signal_connect (port, "remove", (GCallback) handle_remove_port, node);
if (port != NULL) {
pinos_node_add_port (node, port);
}
g_debug ("node %p: created port %p", node, port);
return port;
}
/**
* pinos_node_add_port:
* @node: a #PinosNode
* @port: (transfer full): a #PinosPort
*
* Add the #PinosPort to @node
*/
void
pinos_node_add_port (PinosNode *node, PinosPort *port)
{
PinosNodePrivate *priv;
GList *find;
g_return_if_fail (PINOS_IS_NODE (node));
g_return_if_fail (PINOS_IS_PORT (port));
priv = node->priv;
find = g_list_find (priv->ports, port);
if (find == NULL) {
g_debug ("node %p: add port %p", node, port);
priv->ports = g_list_append (priv->ports, port);
g_signal_connect (port, "remove", (GCallback) handle_remove_port, node);
}
}
/**
* pinos_node_remove_port:
* @node: a #PinosNode

View file

@ -97,6 +97,8 @@ PinosPort * pinos_node_create_port_finish (PinosNode *node
GAsyncResult *res,
GError **error);
void pinos_node_add_port (PinosNode *node,
PinosPort *port);
void pinos_node_remove_port (PinosNode *node,
PinosPort *port);
GList * pinos_node_get_ports (PinosNode *node);

View file

@ -614,6 +614,8 @@ update_peer_paths (PinosPort *port)
gboolean
pinos_port_link (PinosPort *source, PinosPort *destination)
{
gboolean res = TRUE;
g_return_val_if_fail (PINOS_IS_PORT (source), FALSE);
g_return_val_if_fail (PINOS_IS_PORT (destination), FALSE);
g_return_val_if_fail (source->priv->direction != destination->priv->direction, FALSE);
@ -630,16 +632,20 @@ pinos_port_link (PinosPort *source, PinosPort *destination)
destination = tmp;
}
g_signal_emit (source, signals[SIGNAL_LINKED], 0, destination, &res);
if (!res)
return FALSE;
g_signal_emit (destination, signals[SIGNAL_LINKED], 0, source, &res);
if (!res)
return FALSE;
g_debug ("port %p: linked to %p", source, destination);
g_ptr_array_add (source->priv->peers, destination);
g_ptr_array_add (destination->priv->peers, source);
update_peer_paths (source);
update_peer_paths (destination);
g_debug ("port %p: linked to %p", source, destination);
g_signal_emit (source, signals[SIGNAL_LINKED], 0, destination);
g_signal_emit (destination, signals[SIGNAL_LINKED], 0, source);
if (source->priv->format) {
PinosBufferBuilder builder;
PinosBuffer pbuf;
@ -1114,6 +1120,27 @@ pinos_port_finalize (GObject * object)
G_OBJECT_CLASS (pinos_port_parent_class)->finalize (object);
}
static gboolean
signal_linked_handler (PinosPort *port, PinosPort *peer, gpointer user_data)
{
return TRUE;
}
static gboolean
signal_linked_accum (GSignalInvocationHint *ihint,
GValue *return_accu,
const GValue *handler_return,
gpointer data)
{
if (!g_value_get_boolean (handler_return)) {
g_value_set_boolean (return_accu, FALSE);
return FALSE;
}
g_value_set_boolean (return_accu, TRUE);
return TRUE;
}
static void
pinos_port_class_init (PinosPortClass * klass)
{
@ -1238,14 +1265,14 @@ pinos_port_class_init (PinosPortClass * klass)
G_TYPE_NONE,
0,
G_TYPE_NONE);
signals[SIGNAL_LINKED] = g_signal_new ("linked",
signals[SIGNAL_LINKED] = g_signal_new_class_handler ("linked",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL,
(GCallback) signal_linked_handler,
signal_linked_accum,
NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
G_TYPE_BOOLEAN,
1,
PINOS_TYPE_PORT);
signals[SIGNAL_UNLINKED] = g_signal_new ("unlinked",

View file

@ -666,6 +666,9 @@ on_node_created (GObject *source_object,
else
pinos_properties_set (priv->properties, "autoconnect", "0");
if (priv->path)
pinos_properties_set (priv->properties, "target-path", priv->path);
pinos_node_create_port (priv->node,
priv->direction,
"client-port",