mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-15 07:00:05 -05:00
Work on node creation
Implements the basics of the PORT_UPDATE control message Add the ports to the proxy node with whe PORT_UPDATE control message. Let the proxy node check the events and create dbus objects based on added/removed ports.
This commit is contained in:
parent
ac5d22ec79
commit
de53315f6e
17 changed files with 350 additions and 215 deletions
|
|
@ -38,6 +38,7 @@
|
|||
#include "pinos/server/daemon.h"
|
||||
#include "pinos/server/client-node.h"
|
||||
#include "pinos/server/utils.h"
|
||||
#include "pinos/server/link.h"
|
||||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
|
|
@ -174,8 +175,6 @@ static gboolean
|
|||
on_received_buffer (PinosPort *port, uint32_t buffer_id, GError **error, gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
PinosClientNode *this = PINOS_CLIENT_NODE (node);
|
||||
PinosClientNodePrivate *priv = this->priv;
|
||||
SpaResult res;
|
||||
SpaInputInfo info[1];
|
||||
|
||||
|
|
@ -195,8 +194,6 @@ static gboolean
|
|||
on_received_event (PinosPort *port, SpaEvent *event, GError **error, gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
PinosClientNode *this = PINOS_CLIENT_NODE (node);
|
||||
PinosClientNodePrivate *priv = this->priv;
|
||||
SpaResult res;
|
||||
|
||||
if ((res = spa_node_port_push_event (node->node, port->id, event)) < 0)
|
||||
|
|
@ -271,6 +268,45 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
|||
PinosClientNodePrivate *priv = this->priv;
|
||||
|
||||
switch (event->type) {
|
||||
case SPA_EVENT_TYPE_PORT_ADDED:
|
||||
{
|
||||
SpaEventPortAdded *pa = event->data;
|
||||
PinosPort *port, *target;
|
||||
PinosLink *link;
|
||||
PinosNode *pnode = PINOS_NODE (this);
|
||||
GError *error = NULL;
|
||||
|
||||
port = PINOS_NODE_CLASS (pinos_client_node_parent_class)->add_port (pnode,
|
||||
pa->direction,
|
||||
event->port_id,
|
||||
&error);
|
||||
|
||||
if (port == NULL) {
|
||||
g_warning ("proxy %p: can't create port: %s", this, error->message);
|
||||
g_clear_error (&error);
|
||||
break;
|
||||
}
|
||||
pinos_port_set_received_cb (port, on_received_buffer, on_received_event, this, NULL);
|
||||
|
||||
target = pinos_daemon_find_port (pinos_node_get_daemon (pnode),
|
||||
pinos_direction_reverse (pa->direction),
|
||||
"/org/pinos/node_8",
|
||||
NULL,
|
||||
NULL,
|
||||
&error);
|
||||
if (target == NULL) {
|
||||
g_warning ("proxy %p: can't find port target: %s", this, error->message);
|
||||
g_clear_error (&error);
|
||||
break;
|
||||
}
|
||||
link = pinos_link_new (pinos_node_get_daemon (pnode), port, target, NULL);
|
||||
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_PORT_REMOVED:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_STATE_CHANGE:
|
||||
{
|
||||
SpaEventStateChange *sc = event->data;
|
||||
|
|
|
|||
|
|
@ -187,7 +187,6 @@ handle_create_client_node (PinosDaemon1 *interface,
|
|||
GDBusMethodInvocation *invocation,
|
||||
const gchar *arg_name,
|
||||
GVariant *arg_properties,
|
||||
GVariant *arg_ports,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosDaemon *daemon = user_data;
|
||||
|
|
@ -210,56 +209,11 @@ handle_create_client_node (PinosDaemon1 *interface,
|
|||
arg_name,
|
||||
props);
|
||||
|
||||
client = sender_get_client (daemon, sender);
|
||||
|
||||
{
|
||||
GVariantIter it;
|
||||
guint direction;
|
||||
guint id;
|
||||
const gchar *format_str, *target_node;
|
||||
GVariant *port_props;
|
||||
|
||||
g_variant_iter_init (&it, arg_ports);
|
||||
while (g_variant_iter_loop (&it, "(uu&s@a{sv}&s)", &direction, &id, &format_str, &port_props, &target_node)) {
|
||||
PinosPort *port, *target;
|
||||
PinosProperties *pprops;
|
||||
GBytes *formats;
|
||||
PinosLink *link;
|
||||
|
||||
port = pinos_node_add_port (node, direction, id, &error);
|
||||
if (port == NULL)
|
||||
goto add_failed;
|
||||
|
||||
pprops = pinos_properties_from_variant (port_props);
|
||||
formats = g_bytes_new (format_str, strlen (format_str) + 1);
|
||||
|
||||
g_object_set (port, "possible-formats", formats,
|
||||
"properties", port_props,
|
||||
NULL);
|
||||
|
||||
target = pinos_daemon_find_port (daemon,
|
||||
pinos_direction_reverse (direction),
|
||||
target_node,
|
||||
pprops,
|
||||
formats,
|
||||
&error);
|
||||
if (target == NULL) {
|
||||
g_warning ("daemon %p: can't find port target: %s", daemon, error->message);
|
||||
g_clear_error (&error);
|
||||
continue;
|
||||
}
|
||||
|
||||
// pinos_client_add_object (client, G_OBJECT (target));
|
||||
|
||||
link = pinos_link_new (daemon, port, target, NULL);
|
||||
pinos_client_add_object (client, G_OBJECT (link));
|
||||
}
|
||||
}
|
||||
|
||||
socket = pinos_client_node_get_socket_pair (PINOS_CLIENT_NODE (node), &error);
|
||||
if (socket == NULL)
|
||||
goto no_socket;
|
||||
|
||||
client = sender_get_client (daemon, sender);
|
||||
pinos_client_add_object (client, G_OBJECT (node));
|
||||
|
||||
object_path = pinos_node_get_object_path (PINOS_NODE (node));
|
||||
|
|
@ -279,11 +233,6 @@ no_socket:
|
|||
g_debug ("daemon %p: could not create node %s", daemon, error->message);
|
||||
goto exit_error;
|
||||
}
|
||||
add_failed:
|
||||
{
|
||||
g_debug ("daemon %p: failed to add port %s", daemon, error->message);
|
||||
goto exit_error;
|
||||
}
|
||||
exit_error:
|
||||
{
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
|
|
|
|||
|
|
@ -81,6 +81,12 @@ node_set_state (PinosNode *node,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
do_remove_port (PinosPort *port, PinosNode *node)
|
||||
{
|
||||
pinos_node_remove_port (node, port->id);
|
||||
}
|
||||
|
||||
static PinosPort *
|
||||
node_add_port (PinosNode *node,
|
||||
PinosDirection direction,
|
||||
|
|
@ -96,6 +102,10 @@ node_add_port (PinosNode *node,
|
|||
"direction", direction,
|
||||
"id", id,
|
||||
NULL);
|
||||
if (port) {
|
||||
g_hash_table_insert (priv->ports, GUINT_TO_POINTER (id), port);
|
||||
g_signal_connect (port, "remove", (GCallback) do_remove_port, node);
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
|
|
@ -103,6 +113,9 @@ static gboolean
|
|||
node_remove_port (PinosNode *node,
|
||||
guint id)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
g_debug ("node %p: removed port %u", node, id);
|
||||
g_hash_table_remove (priv->ports, GUINT_TO_POINTER (id));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -670,12 +683,6 @@ pinos_node_remove (PinosNode *node)
|
|||
g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
do_remove_port (PinosPort *port, PinosNode *node)
|
||||
{
|
||||
pinos_node_remove_port (node, port->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_add_port:
|
||||
* @node: a #PinosNode
|
||||
|
|
@ -693,11 +700,9 @@ pinos_node_add_port (PinosNode *node,
|
|||
GError **error)
|
||||
{
|
||||
PinosNodeClass *klass;
|
||||
PinosNodePrivate *priv;
|
||||
PinosPort *port;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
klass = PINOS_NODE_GET_CLASS (node);
|
||||
if (!klass->add_port) {
|
||||
|
|
@ -708,10 +713,6 @@ pinos_node_add_port (PinosNode *node,
|
|||
g_debug ("node %p: add port", node);
|
||||
port = klass->add_port (node, direction, id, error);
|
||||
|
||||
if (port) {
|
||||
g_hash_table_insert (priv->ports, GUINT_TO_POINTER (id), port);
|
||||
g_signal_connect (port, "remove", (GCallback) do_remove_port, node);
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
|
|
@ -727,12 +728,10 @@ pinos_node_add_port (PinosNode *node,
|
|||
gboolean
|
||||
pinos_node_remove_port (PinosNode *node, guint id)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
PinosNodeClass *klass;
|
||||
gboolean res = FALSE;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), FALSE);
|
||||
priv = node->priv;
|
||||
|
||||
klass = PINOS_NODE_GET_CLASS (node);
|
||||
|
||||
|
|
@ -740,10 +739,6 @@ pinos_node_remove_port (PinosNode *node, guint id)
|
|||
return FALSE;
|
||||
|
||||
res = klass->remove_port (node, id);
|
||||
if (res) {
|
||||
g_debug ("node %p: removed port %u", node, id);
|
||||
g_hash_table_remove (priv->ports, GUINT_TO_POINTER (id));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue