mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-20 06:59:58 -05:00
Remove port
Remove the port object. We don't use it as a dbus object and we don't need it, we can use the link and node object directy. Move poll code and event handler to the node.
This commit is contained in:
parent
463954a299
commit
7d3e46e7f9
22 changed files with 689 additions and 1848 deletions
|
|
@ -48,13 +48,6 @@ struct _PinosClientNodePrivate
|
|||
{
|
||||
int fd;
|
||||
GSocket *sockets[2];
|
||||
|
||||
SpaPollFd fds[16];
|
||||
unsigned int n_fds;
|
||||
SpaPollItem poll;
|
||||
|
||||
gboolean running;
|
||||
pthread_t thread;
|
||||
};
|
||||
|
||||
#define PINOS_CLIENT_NODE_GET_PRIVATE(obj) \
|
||||
|
|
@ -170,257 +163,12 @@ create_failed:
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_received_buffer (PinosPort *port, uint32_t buffer_id, GError **error, gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
SpaResult res;
|
||||
SpaInputInfo info[1];
|
||||
|
||||
info[0].port_id = port->id;
|
||||
info[0].buffer_id = buffer_id;
|
||||
info[0].flags = SPA_INPUT_FLAG_NONE;
|
||||
|
||||
if ((res = spa_node_port_push_input (node->node, 1, info)) < 0)
|
||||
g_warning ("client-node %p: error pushing buffer: %d, %d", node, res, info[0].status);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_received_event (PinosPort *port, SpaEvent *event, GError **error, gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
SpaResult res;
|
||||
|
||||
if ((res = spa_node_port_push_event (node->node, port->id, event)) < 0)
|
||||
g_warning ("client-node %p: error pushing event: %d", node, res);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void *
|
||||
loop (void *user_data)
|
||||
{
|
||||
PinosClientNode *this = user_data;
|
||||
PinosClientNodePrivate *priv = this->priv;
|
||||
int r;
|
||||
|
||||
g_debug ("client-node %p: enter thread", this);
|
||||
while (priv->running) {
|
||||
SpaPollNotifyData ndata;
|
||||
|
||||
r = poll ((struct pollfd *) priv->fds, priv->n_fds, -1);
|
||||
if (r < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if (r == 0) {
|
||||
g_debug ("client-node %p: select timeout", this);
|
||||
break;
|
||||
}
|
||||
if (priv->fds[0].revents & POLLIN) {
|
||||
uint64_t u;
|
||||
if (read (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
g_warning ("client-node %p: failed to read fd", strerror (errno));
|
||||
break;
|
||||
}
|
||||
|
||||
if (priv->poll.after_cb) {
|
||||
ndata.fds = priv->poll.fds;
|
||||
ndata.n_fds = priv->poll.n_fds;
|
||||
ndata.user_data = priv->poll.user_data;
|
||||
priv->poll.after_cb (&ndata);
|
||||
}
|
||||
}
|
||||
g_debug ("client-node %p: leave thread", this);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
start_thread (PinosClientNode *this)
|
||||
{
|
||||
PinosClientNodePrivate *priv = this->priv;
|
||||
int err;
|
||||
|
||||
if (!priv->running) {
|
||||
priv->running = true;
|
||||
if ((err = pthread_create (&priv->thread, NULL, loop, this)) != 0) {
|
||||
g_warning ("client-node %p: can't create thread", strerror (err));
|
||||
priv->running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
stop_thread (PinosClientNode *this)
|
||||
{
|
||||
PinosClientNodePrivate *priv = this->priv;
|
||||
|
||||
if (priv->running) {
|
||||
uint64_t u = 1;
|
||||
|
||||
if (write (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
g_warning ("client-node %p: failed to write fd", strerror (errno));
|
||||
|
||||
priv->running = false;
|
||||
pthread_join (priv->thread, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
||||
{
|
||||
PinosClientNode *this = user_data;
|
||||
PinosClientNodePrivate *priv = this->priv;
|
||||
|
||||
switch (event->type) {
|
||||
case SPA_EVENT_TYPE_PORT_ADDED:
|
||||
{
|
||||
SpaEventPortAdded *pa = event->data;
|
||||
PinosPort *port;
|
||||
PinosNode *pnode = PINOS_NODE (this);
|
||||
GError *error = NULL;
|
||||
|
||||
port = PINOS_NODE_CLASS (pinos_client_node_parent_class)->add_port (pnode,
|
||||
pa->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);
|
||||
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_PORT_REMOVED:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_STATE_CHANGE:
|
||||
{
|
||||
SpaEventStateChange *sc = event->data;
|
||||
|
||||
pinos_node_update_node_state (PINOS_NODE (this), sc->state);
|
||||
|
||||
switch (sc->state) {
|
||||
case SPA_NODE_STATE_CONFIGURE:
|
||||
{
|
||||
GList *ports, *walk;
|
||||
|
||||
ports = pinos_node_get_ports (PINOS_NODE (this));
|
||||
for (walk = ports; walk; walk = g_list_next (walk)) {
|
||||
PinosPort *port = walk->data;
|
||||
pinos_port_activate (port);
|
||||
}
|
||||
g_list_free (ports);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_ADD_POLL:
|
||||
{
|
||||
SpaPollItem *poll = event->data;
|
||||
unsigned int i;
|
||||
|
||||
priv->poll = *poll;
|
||||
priv->poll.fds = &priv->fds[priv->n_fds];
|
||||
for (i = 0; i < poll->n_fds; i++)
|
||||
priv->fds[priv->n_fds++] = poll->fds[i];
|
||||
|
||||
start_thread (this);
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_REMOVE_POLL:
|
||||
{
|
||||
stop_thread (this);
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_HAVE_OUTPUT:
|
||||
{
|
||||
PinosPort *port;
|
||||
SpaOutputInfo info[1] = { 0, };
|
||||
SpaResult res;
|
||||
GError *error = NULL;
|
||||
|
||||
if ((res = spa_node_port_pull_output (node, 1, info)) < 0)
|
||||
g_debug ("client-node %p: got pull error %d, %d", this, res, info[0].status);
|
||||
|
||||
port = pinos_node_find_port_by_id (PINOS_NODE (this), info[0].port_id);
|
||||
|
||||
if (!pinos_port_send_buffer (port, info[0].buffer_id, &error)) {
|
||||
g_debug ("send failed: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_REUSE_BUFFER:
|
||||
{
|
||||
PinosPort *port;
|
||||
GError *error = NULL;
|
||||
SpaEventReuseBuffer *rb = event->data;
|
||||
|
||||
port = pinos_node_find_port_by_id (PINOS_NODE (this), rb->port_id);
|
||||
pinos_port_send_event (port, event, &error);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
g_debug ("client-node %p: got event %d", this, event->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setup_node (PinosClientNode *this)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (this);
|
||||
SpaResult res;
|
||||
|
||||
if ((res = spa_node_set_event_callback (node->node, on_node_event, this)) < 0)
|
||||
g_warning ("client-node %p: error setting callback", this);
|
||||
}
|
||||
|
||||
static PinosPort *
|
||||
add_port (PinosNode *node,
|
||||
guint id,
|
||||
GError **error)
|
||||
{
|
||||
PinosPort *port;
|
||||
|
||||
if (spa_node_add_port (node->node, id) < 0)
|
||||
g_warning ("client-node %p: error adding port", node);
|
||||
|
||||
port = PINOS_NODE_CLASS (pinos_client_node_parent_class)->add_port (node, id, error);
|
||||
|
||||
if (port) {
|
||||
pinos_port_set_received_cb (port, on_received_buffer, on_received_event, node, NULL);
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
remove_port (PinosNode *node,
|
||||
PinosPort *port)
|
||||
{
|
||||
if (spa_node_remove_port (node->node, port->id) < 0)
|
||||
g_warning ("client-node %p: error removing port", node);
|
||||
|
||||
return PINOS_NODE_CLASS (pinos_client_node_parent_class)->remove_port (node, port);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_client_node_dispose (GObject * object)
|
||||
{
|
||||
PinosClientNode *this = PINOS_CLIENT_NODE (object);
|
||||
|
||||
g_debug ("client-node %p: dispose", this);
|
||||
stop_thread (this);
|
||||
|
||||
G_OBJECT_CLASS (pinos_client_node_parent_class)->dispose (object);
|
||||
}
|
||||
|
|
@ -446,25 +194,16 @@ static void
|
|||
pinos_client_node_constructed (GObject * object)
|
||||
{
|
||||
PinosClientNode *this = PINOS_CLIENT_NODE (object);
|
||||
PinosClientNodePrivate *priv = this->priv;
|
||||
|
||||
g_debug ("client-node %p: constructed", this);
|
||||
|
||||
G_OBJECT_CLASS (pinos_client_node_parent_class)->constructed (object);
|
||||
|
||||
priv->fds[0].fd = eventfd (0, 0);
|
||||
priv->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
priv->fds[0].revents = 0;
|
||||
priv->n_fds = 1;
|
||||
|
||||
setup_node (this);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_client_node_class_init (PinosClientNodeClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
PinosNodeClass *node_class = PINOS_NODE_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosClientNodePrivate));
|
||||
|
||||
|
|
@ -473,9 +212,6 @@ pinos_client_node_class_init (PinosClientNodeClass * klass)
|
|||
gobject_class->finalize = pinos_client_node_finalize;
|
||||
gobject_class->set_property = pinos_client_node_set_property;
|
||||
gobject_class->get_property = pinos_client_node_get_property;
|
||||
|
||||
node_class->add_port = add_port;
|
||||
node_class->remove_port = remove_port;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -184,11 +184,11 @@ no_node:
|
|||
}
|
||||
|
||||
static void
|
||||
on_port_added (PinosNode *node, PinosPort *port, PinosClient *client)
|
||||
on_port_added (PinosNode *node, PinosDirection direction, guint port_id, PinosClient *client)
|
||||
{
|
||||
PinosDaemon *this;
|
||||
PinosProperties *props;
|
||||
PinosPort *target;
|
||||
PinosNode *target;
|
||||
const gchar *path;
|
||||
GError *error = NULL;
|
||||
PinosLink *link;
|
||||
|
|
@ -199,26 +199,31 @@ on_port_added (PinosNode *node, PinosPort *port, PinosClient *client)
|
|||
path = pinos_properties_get (props, "pinos.target.node");
|
||||
|
||||
if (path) {
|
||||
target = pinos_daemon_find_port (this,
|
||||
pinos_direction_reverse (port->direction),
|
||||
guint new_port;
|
||||
|
||||
target = pinos_daemon_find_node (this,
|
||||
pinos_direction_reverse (direction),
|
||||
path,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
&error);
|
||||
if (target == NULL) {
|
||||
g_warning ("daemon %p: can't find port target: %s", this, error->message);
|
||||
g_warning ("daemon %p: can't find node target: %s", this, error->message);
|
||||
g_clear_error (&error);
|
||||
return;
|
||||
}
|
||||
link = pinos_link_new (pinos_node_get_daemon (node), port, target);
|
||||
|
||||
new_port = pinos_node_get_free_port_id (target, pinos_direction_reverse (direction));
|
||||
link = pinos_node_link (node, port_id, target, new_port, NULL, NULL);
|
||||
|
||||
pinos_client_add_object (client, G_OBJECT (link));
|
||||
g_object_unref (link);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_port_removed (PinosNode *node, PinosPort *port, PinosClient *client)
|
||||
on_port_removed (PinosNode *node, guint port_id, PinosClient *client)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -511,7 +516,7 @@ pinos_daemon_remove_node (PinosDaemon *daemon,
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_daemon_find_port:
|
||||
* pinos_daemon_find_node:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @name: a port name
|
||||
* @props: port properties
|
||||
|
|
@ -523,8 +528,8 @@ pinos_daemon_remove_node (PinosDaemon *daemon,
|
|||
* Returns: a #PinosPort or %NULL when no port could be found. unref the port
|
||||
* after usage.
|
||||
*/
|
||||
PinosPort *
|
||||
pinos_daemon_find_port (PinosDaemon *daemon,
|
||||
PinosNode *
|
||||
pinos_daemon_find_node (PinosDaemon *daemon,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
PinosProperties *props,
|
||||
|
|
@ -533,9 +538,9 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
GError **error)
|
||||
{
|
||||
PinosDaemonPrivate *priv;
|
||||
PinosPort *best = NULL;
|
||||
GList *nodes, *ports, *walk;
|
||||
gboolean have_name, created_port = FALSE;
|
||||
PinosNode *best = NULL;
|
||||
GList *nodes;
|
||||
gboolean have_name;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
||||
priv = daemon->priv;
|
||||
|
|
@ -546,65 +551,25 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
|
||||
for (nodes = priv->nodes; nodes; nodes = g_list_next (nodes)) {
|
||||
PinosNode *n = nodes->data;
|
||||
gboolean node_found = FALSE;
|
||||
|
||||
g_debug ("node path \"%s\"", pinos_node_get_object_path (n));
|
||||
|
||||
/* we found the node */
|
||||
if (have_name) {
|
||||
if (!g_str_has_suffix (pinos_node_get_object_path (n), name))
|
||||
continue;
|
||||
if (!g_str_has_suffix (pinos_node_get_object_path (n), name))
|
||||
continue;
|
||||
|
||||
g_debug ("name \"%s\" matches node %p", name, n);
|
||||
node_found = TRUE;
|
||||
}
|
||||
|
||||
ports = pinos_node_get_ports (n);
|
||||
for (walk = ports; walk; walk = g_list_next (walk)) {
|
||||
PinosPort *p = walk->data;
|
||||
PinosDirection dir;
|
||||
|
||||
g_object_get (p, "direction", &dir, NULL);
|
||||
if (dir != direction)
|
||||
continue;
|
||||
|
||||
if (pinos_port_have_common_format (p, n_format_filters, format_filters, NULL)) {
|
||||
g_debug ("port %p matches filter", p);
|
||||
best = p;
|
||||
node_found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_list_free (ports);
|
||||
|
||||
if (best == NULL && node_found) {
|
||||
guint id;
|
||||
|
||||
id = pinos_node_get_free_port_id (n, direction);
|
||||
if (id != SPA_ID_INVALID) {
|
||||
g_debug ("node %p: making port with id %u", n, id);
|
||||
best = pinos_node_add_port (n, id, NULL);
|
||||
if (best != NULL) {
|
||||
created_port = TRUE;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
g_debug ("node %p: using port with id %u", n, id);
|
||||
best = pinos_node_find_port_by_id (n, id);
|
||||
if (best != NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_debug ("name \"%s\" matches node %p", name, n);
|
||||
best = n;
|
||||
break;
|
||||
}
|
||||
if (best == NULL) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_FOUND,
|
||||
"No matching Port found");
|
||||
} else if (!created_port)
|
||||
"No matching Node found");
|
||||
} else
|
||||
g_object_ref (best);
|
||||
|
||||
return PINOS_PORT (best);
|
||||
return best;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ typedef struct _PinosDaemonClass PinosDaemonClass;
|
|||
typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
|
||||
|
||||
#include <pinos/server/node.h>
|
||||
#include <pinos/server/port.h>
|
||||
#include <pinos/server/node-factory.h>
|
||||
#include <pinos/client/properties.h>
|
||||
|
||||
|
|
@ -77,7 +76,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);
|
||||
|
||||
PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
|
||||
PinosNode * pinos_daemon_find_node (PinosDaemon *daemon,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
PinosProperties *props,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "pinos/client/enumtypes.h"
|
||||
|
||||
#include "pinos/server/link.h"
|
||||
#include "pinos/server/port.h"
|
||||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
|
|
@ -42,28 +41,18 @@ struct _PinosLinkPrivate
|
|||
|
||||
gchar *object_path;
|
||||
|
||||
gulong input_id, output_id;
|
||||
|
||||
gboolean active;
|
||||
gboolean negotiated;
|
||||
gboolean allocated;
|
||||
gboolean started;
|
||||
|
||||
PinosPort *output;
|
||||
PinosPort *input;
|
||||
|
||||
SpaNode *output_node;
|
||||
uint32_t output_port;
|
||||
SpaNode *input_node;
|
||||
uint32_t input_port;
|
||||
|
||||
SpaNodeState input_state;
|
||||
SpaNodeState output_state;
|
||||
|
||||
SpaBuffer *in_buffers[16];
|
||||
unsigned int n_in_buffers;
|
||||
SpaBuffer *out_buffers[16];
|
||||
unsigned int n_out_buffers;
|
||||
|
||||
GPtrArray *format_filter;
|
||||
PinosProperties *properties;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosLink, pinos_link, G_TYPE_OBJECT);
|
||||
|
|
@ -72,83 +61,69 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_DAEMON,
|
||||
PROP_OUTPUT,
|
||||
PROP_INPUT,
|
||||
PROP_OBJECT_PATH,
|
||||
PROP_OUTPUT_NODE,
|
||||
PROP_OUTPUT_PORT,
|
||||
PROP_INPUT_NODE,
|
||||
PROP_INPUT_PORT,
|
||||
PROP_FORMAT_FILTER,
|
||||
PROP_PROPERTIES,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL_REMOVE,
|
||||
SIGNAL_ACTIVATE,
|
||||
SIGNAL_DEACTIVATE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static gboolean
|
||||
on_output_buffer (PinosPort *port, uint32_t buffer_id, GError **error, gpointer user_data)
|
||||
{
|
||||
PinosLink *link = user_data;
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
|
||||
return pinos_port_receive_buffer (priv->input, buffer_id, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_output_event (PinosPort *port, SpaEvent *event, GError **error, gpointer user_data)
|
||||
{
|
||||
PinosLink *link = user_data;
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
|
||||
return pinos_port_receive_event (priv->input, event, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_input_buffer (PinosPort *port, uint32_t buffer_id, GError **error, gpointer user_data)
|
||||
{
|
||||
PinosLink *link = user_data;
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
|
||||
return pinos_port_receive_buffer (priv->output, buffer_id, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_input_event (PinosPort *port, SpaEvent *event, GError **error, gpointer user_data)
|
||||
{
|
||||
PinosLink *link = user_data;
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
|
||||
return pinos_port_receive_event (priv->output, event, error);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_link_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosLink *link = PINOS_LINK (_object);
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
PinosLink *this = PINOS_LINK (_object);
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
g_value_set_object (value, priv->daemon);
|
||||
break;
|
||||
|
||||
case PROP_OUTPUT:
|
||||
g_value_set_object (value, priv->output);
|
||||
break;
|
||||
|
||||
case PROP_INPUT:
|
||||
g_value_set_object (value, priv->input);
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_PATH:
|
||||
g_value_set_string (value, priv->object_path);
|
||||
break;
|
||||
|
||||
case PROP_OUTPUT_NODE:
|
||||
g_value_set_object (value, this->output_node);
|
||||
break;
|
||||
|
||||
case PROP_OUTPUT_PORT:
|
||||
g_value_set_uint (value, this->output_port);
|
||||
break;
|
||||
|
||||
case PROP_INPUT_NODE:
|
||||
g_value_set_object (value, this->input_node);
|
||||
break;
|
||||
|
||||
case PROP_INPUT_PORT:
|
||||
g_value_set_uint (value, this->input_port);
|
||||
break;
|
||||
|
||||
case PROP_FORMAT_FILTER:
|
||||
g_value_set_boxed (value, priv->format_filter);
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
g_value_set_boxed (value, priv->properties);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (link, prop_id, pspec);
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -159,40 +134,52 @@ pinos_link_set_property (GObject *_object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosLink *link = PINOS_LINK (_object);
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
PinosLink *this = PINOS_LINK (_object);
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
priv->daemon = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_OUTPUT:
|
||||
priv->output = g_value_get_object (value);
|
||||
priv->output_node = priv->output->node->node;
|
||||
priv->output_port = priv->output->id;
|
||||
break;
|
||||
|
||||
case PROP_INPUT:
|
||||
priv->input = g_value_get_object (value);
|
||||
priv->input_node = priv->input->node->node;
|
||||
priv->input_port = priv->input->id;
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_PATH:
|
||||
priv->object_path = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_OUTPUT_NODE:
|
||||
this->output_node = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_OUTPUT_PORT:
|
||||
this->output_port = g_value_get_uint (value);
|
||||
break;
|
||||
|
||||
case PROP_INPUT_NODE:
|
||||
this->input_node = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_INPUT_PORT:
|
||||
this->input_port = g_value_get_uint (value);
|
||||
break;
|
||||
|
||||
case PROP_FORMAT_FILTER:
|
||||
priv->format_filter = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
priv->properties = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (link, prop_id, pspec);
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
link_register_object (PinosLink *link)
|
||||
link_register_object (PinosLink *this)
|
||||
{
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
PinosObjectSkeleton *skel;
|
||||
gchar *name;
|
||||
|
||||
|
|
@ -206,15 +193,15 @@ link_register_object (PinosLink *link)
|
|||
priv->object_path = pinos_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_object_unref (skel);
|
||||
|
||||
g_debug ("link %p: register object %s", link, priv->object_path);
|
||||
g_debug ("link %p: register object %s", this, priv->object_path);
|
||||
}
|
||||
|
||||
static void
|
||||
link_unregister_object (PinosLink *link)
|
||||
link_unregister_object (PinosLink *this)
|
||||
{
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
g_debug ("link %p: unregister object", link);
|
||||
g_debug ("link %p: unregister object", this);
|
||||
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
||||
}
|
||||
|
||||
|
|
@ -231,8 +218,8 @@ do_negotiate (PinosLink *this)
|
|||
priv->negotiated = TRUE;
|
||||
|
||||
again:
|
||||
if ((res = spa_node_port_enum_formats (priv->input_node,
|
||||
priv->input_port,
|
||||
if ((res = spa_node_port_enum_formats (this->input_node->node,
|
||||
this->input_port,
|
||||
&filter,
|
||||
NULL,
|
||||
&istate)) < 0) {
|
||||
|
|
@ -241,8 +228,8 @@ again:
|
|||
}
|
||||
spa_debug_format (filter);
|
||||
|
||||
if ((res = spa_node_port_enum_formats (priv->output_node,
|
||||
priv->output_port,
|
||||
if ((res = spa_node_port_enum_formats (this->output_node->node,
|
||||
this->output_port,
|
||||
&format,
|
||||
filter,
|
||||
&ostate)) < 0) {
|
||||
|
|
@ -257,12 +244,12 @@ again:
|
|||
|
||||
spa_debug_format (format);
|
||||
|
||||
if ((res = spa_node_port_set_format (priv->output_node, priv->output_port, 0, format)) < 0) {
|
||||
if ((res = spa_node_port_set_format (this->output_node->node, this->output_port, 0, format)) < 0) {
|
||||
g_warning ("error set format output: %d", res);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((res = spa_node_port_set_format (priv->input_node, priv->input_port, 0, format)) < 0) {
|
||||
if ((res = spa_node_port_set_format (this->input_node->node, this->input_port, 0, format)) < 0) {
|
||||
g_warning ("error set format input: %d", res);
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -284,13 +271,13 @@ do_allocation (PinosLink *this)
|
|||
const SpaPortInfo *iinfo, *oinfo;
|
||||
SpaPortInfoFlags in_flags, out_flags;
|
||||
|
||||
g_debug ("link %p: doing alloc buffers %p %p", this, priv->output_node, priv->input_node);
|
||||
g_debug ("link %p: doing alloc buffers %p %p", this, this->output_node, this->input_node);
|
||||
/* find out what's possible */
|
||||
if ((res = spa_node_port_get_info (priv->output_node, priv->output_port, &oinfo)) < 0) {
|
||||
if ((res = spa_node_port_get_info (this->output_node->node, this->output_port, &oinfo)) < 0) {
|
||||
g_warning ("error get port info: %d", res);
|
||||
goto error;
|
||||
}
|
||||
if ((res = spa_node_port_get_info (priv->input_node, priv->input_port, &iinfo)) < 0) {
|
||||
if ((res = spa_node_port_get_info (this->input_node->node, this->input_port, &iinfo)) < 0) {
|
||||
g_warning ("error get port info: %d", res);
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -335,42 +322,34 @@ do_allocation (PinosLink *this)
|
|||
}
|
||||
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
||||
if ((res = spa_node_port_alloc_buffers (priv->input_node, priv->input_port,
|
||||
if ((res = spa_node_port_alloc_buffers (this->input_node->node, this->input_port,
|
||||
oinfo->params, oinfo->n_params,
|
||||
priv->in_buffers, &priv->n_in_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
priv->input->n_buffers = priv->n_in_buffers;
|
||||
priv->input->buffers = priv->in_buffers;
|
||||
}
|
||||
if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
||||
if ((res = spa_node_port_alloc_buffers (priv->output_node, priv->output_port,
|
||||
if ((res = spa_node_port_alloc_buffers (this->output_node->node, this->output_port,
|
||||
iinfo->params, iinfo->n_params,
|
||||
priv->out_buffers, &priv->n_out_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
priv->output->n_buffers = priv->n_out_buffers;
|
||||
priv->output->buffers = priv->out_buffers;
|
||||
}
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
||||
if ((res = spa_node_port_use_buffers (priv->input_node, priv->input_port,
|
||||
if ((res = spa_node_port_use_buffers (this->input_node->node, this->input_port,
|
||||
priv->out_buffers, priv->n_out_buffers)) < 0) {
|
||||
g_warning ("error use buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
priv->input->n_buffers = priv->n_out_buffers;
|
||||
priv->input->buffers = priv->out_buffers;
|
||||
}
|
||||
if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
||||
if ((res = spa_node_port_use_buffers (priv->output_node, priv->output_port,
|
||||
if ((res = spa_node_port_use_buffers (this->output_node->node, this->output_port,
|
||||
priv->in_buffers, priv->n_in_buffers)) < 0) {
|
||||
g_warning ("error use buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
priv->output->n_buffers = priv->n_in_buffers;
|
||||
priv->output->buffers = priv->in_buffers;
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -389,12 +368,15 @@ do_start (PinosLink *this)
|
|||
SpaCommand cmd;
|
||||
SpaResult res;
|
||||
|
||||
if (priv->started)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
priv->started = TRUE;
|
||||
|
||||
cmd.type = SPA_COMMAND_START;
|
||||
if ((res = spa_node_send_command (priv->input_node, &cmd)) < 0)
|
||||
if ((res = spa_node_send_command (this->input_node->node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
if ((res = spa_node_send_command (priv->output_node, &cmd)) < 0)
|
||||
if ((res = spa_node_send_command (this->output_node->node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
|
||||
return res;
|
||||
|
|
@ -407,12 +389,15 @@ do_pause (PinosLink *this)
|
|||
SpaCommand cmd;
|
||||
SpaResult res;
|
||||
|
||||
if (!priv->started)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
priv->started = FALSE;
|
||||
|
||||
cmd.type = SPA_COMMAND_PAUSE;
|
||||
if ((res = spa_node_send_command (priv->input_node, &cmd)) < 0)
|
||||
if ((res = spa_node_send_command (this->input_node->node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
if ((res = spa_node_send_command (priv->output_node, &cmd)) < 0)
|
||||
if ((res = spa_node_send_command (this->output_node->node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
|
||||
return res;
|
||||
|
|
@ -423,23 +408,27 @@ check_states (PinosLink *this)
|
|||
{
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
SpaResult res;
|
||||
SpaNodeState in_state, out_state;
|
||||
|
||||
g_debug ("link %p: input %d, output %d", this, priv->input_state, priv->output_state);
|
||||
in_state = this->input_node->node_state;
|
||||
out_state = this->output_node->node_state;
|
||||
|
||||
if (priv->input_state >= SPA_NODE_STATE_CONFIGURE &&
|
||||
priv->output_state >= SPA_NODE_STATE_CONFIGURE &&
|
||||
g_debug ("link %p: input %d, output %d", this, in_state, out_state);
|
||||
|
||||
if (in_state == SPA_NODE_STATE_CONFIGURE &&
|
||||
out_state == SPA_NODE_STATE_CONFIGURE &&
|
||||
!priv->negotiated) {
|
||||
if ((res = do_negotiate (this)) < 0)
|
||||
return res;
|
||||
}
|
||||
if (priv->input_state >= SPA_NODE_STATE_READY &&
|
||||
priv->output_state >= SPA_NODE_STATE_READY &&
|
||||
if (in_state == SPA_NODE_STATE_READY &&
|
||||
out_state == SPA_NODE_STATE_READY &&
|
||||
!priv->allocated) {
|
||||
if ((res = do_allocation (this)) < 0)
|
||||
return res;
|
||||
}
|
||||
if (priv->input_state >= SPA_NODE_STATE_PAUSED &&
|
||||
priv->output_state >= SPA_NODE_STATE_PAUSED &&
|
||||
if (in_state == SPA_NODE_STATE_PAUSED &&
|
||||
out_state == SPA_NODE_STATE_PAUSED &&
|
||||
!priv->started) {
|
||||
if ((res = do_start (this)) < 0)
|
||||
return res;
|
||||
|
|
@ -453,57 +442,11 @@ on_node_state_notify (GObject *obj,
|
|||
gpointer user_data)
|
||||
{
|
||||
PinosLink *this = user_data;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
g_debug ("link %p: node %p state change", this, obj);
|
||||
if (obj == G_OBJECT (priv->input->node))
|
||||
priv->input_state = priv->input->node->node_state;
|
||||
else
|
||||
priv->output_state = priv->output->node->node_state;
|
||||
|
||||
check_states (this);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_activate (PinosPort *port, gpointer user_data)
|
||||
{
|
||||
PinosLink *this = user_data;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
if (priv->active)
|
||||
return TRUE;
|
||||
priv->active = TRUE;
|
||||
|
||||
if (priv->input == port)
|
||||
pinos_port_activate (priv->output);
|
||||
else
|
||||
pinos_port_activate (priv->input);
|
||||
|
||||
check_states (this);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_deactivate (PinosPort *port, gpointer user_data)
|
||||
{
|
||||
PinosLink *this = user_data;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
if (!priv->active)
|
||||
return TRUE;
|
||||
priv->active = FALSE;
|
||||
|
||||
if (priv->input == port)
|
||||
pinos_port_deactivate (priv->output);
|
||||
else
|
||||
pinos_port_deactivate (priv->input);
|
||||
|
||||
do_pause (this);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_property_notify (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
|
|
@ -512,17 +455,17 @@ on_property_notify (GObject *obj,
|
|||
PinosLink *this = user_data;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output") == 0) {
|
||||
gchar *port = g_strdup_printf ("%s:%d", pinos_node_get_object_path (priv->output->node),
|
||||
priv->output->id);
|
||||
pinos_link1_set_src_port (priv->iface, port);
|
||||
g_free (port);
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output-node") == 0) {
|
||||
pinos_link1_set_output_node (priv->iface, pinos_node_get_object_path (this->output_node));
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "input") == 0) {
|
||||
gchar *port = g_strdup_printf ("%s:%d", pinos_node_get_object_path (priv->input->node),
|
||||
priv->input->id);
|
||||
pinos_link1_set_dest_port (priv->iface, port);
|
||||
g_free (port);
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output-port") == 0) {
|
||||
pinos_link1_set_output_port (priv->iface, this->output_port);
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "input-node") == 0) {
|
||||
pinos_link1_set_input_node (priv->iface, pinos_node_get_object_path (this->input_node));
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "input-port") == 0) {
|
||||
pinos_link1_set_input_port (priv->iface, this->input_port);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -531,36 +474,17 @@ static void
|
|||
pinos_link_constructed (GObject * object)
|
||||
{
|
||||
PinosLink *this = PINOS_LINK (object);
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
priv->output_id = pinos_port_add_send_cb (priv->output,
|
||||
on_output_buffer,
|
||||
on_output_event,
|
||||
this,
|
||||
NULL);
|
||||
priv->input_id = pinos_port_add_send_cb (priv->input,
|
||||
on_input_buffer,
|
||||
on_input_event,
|
||||
this,
|
||||
NULL);
|
||||
|
||||
priv->input_state = priv->input->node->node_state;
|
||||
priv->output_state = priv->output->node->node_state;
|
||||
|
||||
g_signal_connect (priv->input->node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||
g_signal_connect (priv->output->node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||
|
||||
g_signal_connect (priv->input, "activate", (GCallback) on_activate, this);
|
||||
g_signal_connect (priv->input, "deactivate", (GCallback) on_deactivate, this);
|
||||
g_signal_connect (priv->output, "activate", (GCallback) on_activate, this);
|
||||
g_signal_connect (priv->output, "deactivate", (GCallback) on_deactivate, this);
|
||||
g_signal_connect (this->input_node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||
g_signal_connect (this->output_node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||
|
||||
g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
|
||||
|
||||
G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object);
|
||||
|
||||
on_property_notify (G_OBJECT (this), NULL, this);
|
||||
g_debug ("link %p: constructed", this);
|
||||
g_debug ("link %p: constructed %p:%d -> %p:%d", this, this->output_node, this->output_port,
|
||||
this->input_node, this->input_port);
|
||||
link_register_object (this);
|
||||
}
|
||||
|
||||
|
|
@ -571,23 +495,17 @@ pinos_link_dispose (GObject * object)
|
|||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
g_debug ("link %p: dispose", this);
|
||||
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
|
||||
do_pause (this);
|
||||
g_signal_handlers_disconnect_by_data (this->input_node, this);
|
||||
g_signal_handlers_disconnect_by_data (this->output_node, this);
|
||||
|
||||
g_signal_handlers_disconnect_by_data (priv->input, this);
|
||||
g_signal_handlers_disconnect_by_data (priv->output, this);
|
||||
g_signal_handlers_disconnect_by_data (priv->input->node, this);
|
||||
g_signal_handlers_disconnect_by_data (priv->output->node, this);
|
||||
g_clear_object (&this->input_node);
|
||||
g_clear_object (&this->output_node);
|
||||
|
||||
pinos_port_remove_send_cb (priv->input, priv->input_id);
|
||||
pinos_port_remove_send_cb (priv->output, priv->output_id);
|
||||
if (priv->active) {
|
||||
priv->active = FALSE;
|
||||
pinos_port_deactivate (priv->input);
|
||||
pinos_port_deactivate (priv->output);
|
||||
}
|
||||
priv->input = NULL;
|
||||
priv->output = NULL;
|
||||
link_unregister_object (this);
|
||||
|
||||
G_OBJECT_CLASS (pinos_link_parent_class)->dispose (object);
|
||||
|
|
@ -596,10 +514,10 @@ pinos_link_dispose (GObject * object)
|
|||
static void
|
||||
pinos_link_finalize (GObject * object)
|
||||
{
|
||||
PinosLink *link = PINOS_LINK (object);
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
PinosLink *this = PINOS_LINK (object);
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
g_debug ("link %p: finalize", link);
|
||||
g_debug ("link %p: finalize", this);
|
||||
g_clear_object (&priv->daemon);
|
||||
g_clear_object (&priv->iface);
|
||||
g_free (priv->object_path);
|
||||
|
|
@ -632,25 +550,69 @@ pinos_link_class_init (PinosLinkClass * klass)
|
|||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OUTPUT,
|
||||
g_param_spec_object ("output",
|
||||
"Output",
|
||||
"The output port",
|
||||
PINOS_TYPE_PORT,
|
||||
PROP_OUTPUT_NODE,
|
||||
g_param_spec_object ("output-node",
|
||||
"Output Node",
|
||||
"The output node",
|
||||
PINOS_TYPE_NODE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_INPUT,
|
||||
g_param_spec_object ("input",
|
||||
"Input",
|
||||
"The input port",
|
||||
PINOS_TYPE_PORT,
|
||||
PROP_OUTPUT_PORT,
|
||||
g_param_spec_uint ("output-port",
|
||||
"Output Port",
|
||||
"The output port",
|
||||
0,
|
||||
G_MAXUINT,
|
||||
-1,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_INPUT_NODE,
|
||||
g_param_spec_object ("input-node",
|
||||
"Input Node",
|
||||
"The input node",
|
||||
PINOS_TYPE_NODE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_INPUT_PORT,
|
||||
g_param_spec_uint ("input-port",
|
||||
"Input Port",
|
||||
"The input port",
|
||||
0,
|
||||
G_MAXUINT,
|
||||
-1,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_FORMAT_FILTER,
|
||||
g_param_spec_boxed ("format-filter",
|
||||
"format Filter",
|
||||
"The format filter",
|
||||
G_TYPE_PTR_ARRAY,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
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));
|
||||
|
||||
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
|
|
@ -661,38 +623,35 @@ pinos_link_class_init (PinosLinkClass * klass)
|
|||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
signals[SIGNAL_ACTIVATE] = g_signal_new ("activate",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
signals[SIGNAL_DEACTIVATE] = g_signal_new ("deactivate",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_link_init (PinosLink * link)
|
||||
pinos_link_init (PinosLink * this)
|
||||
{
|
||||
PinosLinkPrivate *priv = link->priv = PINOS_LINK_GET_PRIVATE (link);
|
||||
PinosLinkPrivate *priv = this->priv = PINOS_LINK_GET_PRIVATE (this);
|
||||
|
||||
priv->iface = pinos_link1_skeleton_new ();
|
||||
g_debug ("link %p: new", link);
|
||||
}
|
||||
|
||||
PinosLink *
|
||||
pinos_link_new (PinosDaemon *daemon,
|
||||
PinosPort *output,
|
||||
PinosPort *input)
|
||||
{
|
||||
PinosLink *link;
|
||||
PinosPort *tmp;
|
||||
|
||||
if (output->direction != PINOS_DIRECTION_OUTPUT) {
|
||||
tmp = output;
|
||||
output = input;
|
||||
input = tmp;
|
||||
}
|
||||
|
||||
link = g_object_new (PINOS_TYPE_LINK,
|
||||
"daemon", daemon,
|
||||
"output", output,
|
||||
"input", input,
|
||||
NULL);
|
||||
|
||||
return link;
|
||||
g_debug ("link %p: new", this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -702,12 +661,10 @@ pinos_link_new (PinosDaemon *daemon,
|
|||
* Trigger removal of @link
|
||||
*/
|
||||
void
|
||||
pinos_link_remove (PinosLink *link)
|
||||
pinos_link_remove (PinosLink *this)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_LINK (link));
|
||||
|
||||
g_debug ("link %p: remove", link);
|
||||
g_signal_emit (link, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
g_debug ("link %p: remove", this);
|
||||
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -719,12 +676,32 @@ pinos_link_remove (PinosLink *link)
|
|||
* Returns: the object path of @source.
|
||||
*/
|
||||
const gchar *
|
||||
pinos_link_get_object_path (PinosLink *link)
|
||||
pinos_link_get_object_path (PinosLink *this)
|
||||
{
|
||||
PinosLinkPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_LINK (link), NULL);
|
||||
priv = link->priv;
|
||||
g_return_val_if_fail (PINOS_IS_LINK (this), NULL);
|
||||
priv = this->priv;
|
||||
|
||||
return priv->object_path;
|
||||
}
|
||||
|
||||
gboolean
|
||||
pinos_link_activate (PinosLink *this)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
|
||||
|
||||
g_signal_emit (this, signals[SIGNAL_ACTIVATE], 0, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
pinos_link_deactivate (PinosLink *this)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
|
||||
|
||||
do_pause (this);
|
||||
|
||||
g_signal_emit (this, signals[SIGNAL_DEACTIVATE], 0, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,11 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate;
|
|||
struct _PinosLink {
|
||||
GObject object;
|
||||
|
||||
PinosNode *output_node;
|
||||
guint output_port;
|
||||
PinosNode *input_node;
|
||||
guint input_port;
|
||||
|
||||
PinosLinkPrivate *priv;
|
||||
};
|
||||
|
||||
|
|
@ -62,12 +67,11 @@ struct _PinosLinkClass {
|
|||
/* normal GObject stuff */
|
||||
GType pinos_link_get_type (void);
|
||||
|
||||
PinosLink * pinos_link_new (PinosDaemon *daemon,
|
||||
PinosPort *output,
|
||||
PinosPort *input);
|
||||
|
||||
void pinos_link_remove (PinosLink *link);
|
||||
|
||||
gboolean pinos_link_activate (PinosLink *link);
|
||||
gboolean pinos_link_deactivate (PinosLink *link);
|
||||
|
||||
PinosProperties * pinos_link_get_properties (PinosLink *link);
|
||||
|
||||
const gchar * pinos_link_get_object_path (PinosLink *link);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixfdlist.h>
|
||||
|
|
@ -56,7 +59,14 @@ struct _PinosNodePrivate
|
|||
|
||||
PinosProperties *properties;
|
||||
|
||||
GHashTable *ports;
|
||||
SpaPollFd fds[16];
|
||||
unsigned int n_fds;
|
||||
SpaPollItem poll;
|
||||
|
||||
gboolean running;
|
||||
pthread_t thread;
|
||||
|
||||
GHashTable *links;
|
||||
};
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (PinosNode, pinos_node, G_TYPE_OBJECT);
|
||||
|
|
@ -84,24 +94,21 @@ enum
|
|||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static gboolean
|
||||
node_set_state (PinosNode *node,
|
||||
PinosNodeState state)
|
||||
static PinosDirection
|
||||
get_port_direction (PinosNode *node, guint id)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
PinosDirection direction;
|
||||
|
||||
static void
|
||||
do_remove_port (PinosPort *port, PinosNode *node)
|
||||
{
|
||||
pinos_node_remove_port (node, port);
|
||||
direction = id < priv->max_input_ports ? PINOS_DIRECTION_INPUT : PINOS_DIRECTION_OUTPUT;
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
static void
|
||||
update_port_ids (PinosNode *node, gboolean create)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
guint i;
|
||||
|
||||
if (node->node == NULL)
|
||||
return;
|
||||
|
|
@ -120,147 +127,251 @@ update_port_ids (PinosNode *node, gboolean create)
|
|||
priv->input_port_ids,
|
||||
priv->max_output_ports,
|
||||
priv->output_port_ids);
|
||||
}
|
||||
|
||||
if (create) {
|
||||
for (i = 0; i < priv->n_input_ports; i++)
|
||||
pinos_node_add_port (node, priv->input_port_ids[i], NULL);
|
||||
for (i = 0; i < priv->n_output_ports; i++)
|
||||
pinos_node_add_port (node, priv->output_port_ids[i], NULL);
|
||||
static void *
|
||||
loop (void *user_data)
|
||||
{
|
||||
PinosNode *this = user_data;
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
int r;
|
||||
|
||||
g_debug ("node %p: enter thread", this);
|
||||
while (priv->running) {
|
||||
SpaPollNotifyData ndata;
|
||||
|
||||
r = poll ((struct pollfd *) priv->fds, priv->n_fds, -1);
|
||||
if (r < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if (r == 0) {
|
||||
g_debug ("node %p: select timeout", this);
|
||||
break;
|
||||
}
|
||||
if (priv->fds[0].revents & POLLIN) {
|
||||
uint64_t u;
|
||||
if (read (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
g_warning ("node %p: failed to read fd", strerror (errno));
|
||||
g_debug ("node %p: event signaled", this);
|
||||
break;
|
||||
}
|
||||
|
||||
if (priv->poll.after_cb) {
|
||||
ndata.fds = priv->poll.fds;
|
||||
ndata.n_fds = priv->poll.n_fds;
|
||||
ndata.user_data = priv->poll.user_data;
|
||||
priv->poll.after_cb (&ndata);
|
||||
}
|
||||
}
|
||||
g_debug ("node %p: leave thread", this);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
start_thread (PinosNode *this)
|
||||
{
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
int err;
|
||||
|
||||
if (!priv->running) {
|
||||
priv->running = true;
|
||||
if ((err = pthread_create (&priv->thread, NULL, loop, this)) != 0) {
|
||||
g_warning ("node %p: can't create thread", strerror (err));
|
||||
priv->running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static PinosPort *
|
||||
node_add_port (PinosNode *node,
|
||||
guint id,
|
||||
GError **error)
|
||||
static void
|
||||
stop_thread (PinosNode *this)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
PinosPort *port;
|
||||
PinosDirection direction;
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
|
||||
update_port_ids (node, FALSE);
|
||||
if (priv->running) {
|
||||
uint64_t u = 1;
|
||||
|
||||
direction = id < priv->max_input_ports ? PINOS_DIRECTION_INPUT : PINOS_DIRECTION_OUTPUT;
|
||||
if (write (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
g_warning ("node %p: failed to write fd", strerror (errno));
|
||||
|
||||
port = g_object_new (PINOS_TYPE_PORT,
|
||||
"daemon", priv->daemon,
|
||||
"node", node,
|
||||
"direction", direction,
|
||||
"id", id,
|
||||
NULL);
|
||||
if (port) {
|
||||
g_hash_table_insert (priv->ports, GUINT_TO_POINTER (port->id), port);
|
||||
g_signal_connect (port, "remove", (GCallback) do_remove_port, node);
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_ADDED], 0, port);
|
||||
priv->running = false;
|
||||
pthread_join (priv->thread, NULL);
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
static void
|
||||
pause_node (PinosNode *this)
|
||||
{
|
||||
SpaResult res;
|
||||
SpaCommand cmd;
|
||||
|
||||
g_debug ("node %p: pause node", this);
|
||||
|
||||
cmd.type = SPA_COMMAND_PAUSE;
|
||||
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
||||
g_debug ("got error %d", res);
|
||||
}
|
||||
|
||||
static void
|
||||
suspend_node (PinosNode *this)
|
||||
{
|
||||
SpaResult res;
|
||||
|
||||
g_debug ("node %p: suspend node", this);
|
||||
|
||||
if ((res = spa_node_port_set_format (this->node, 0, 0, NULL)) < 0)
|
||||
g_warning ("error unset format output: %d", res);
|
||||
|
||||
}
|
||||
|
||||
static gboolean
|
||||
node_remove_port (PinosNode *node,
|
||||
PinosPort *port)
|
||||
node_set_state (PinosNode *this,
|
||||
PinosNodeState state)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
g_debug ("node %p: set state %s", this, pinos_node_state_as_string (state));
|
||||
|
||||
g_debug ("node %p: removed port %u", node, port->id);
|
||||
g_object_ref (port);
|
||||
if (g_hash_table_remove (priv->ports, GUINT_TO_POINTER (port->id)))
|
||||
g_signal_emit (node, signals[SIGNAL_PORT_REMOVED], 0, port);
|
||||
g_object_unref (port);
|
||||
switch (state) {
|
||||
case PINOS_NODE_STATE_SUSPENDED:
|
||||
suspend_node (this);
|
||||
break;
|
||||
|
||||
case PINOS_NODE_STATE_INITIALIZING:
|
||||
break;
|
||||
|
||||
case PINOS_NODE_STATE_IDLE:
|
||||
pause_node (this);
|
||||
break;
|
||||
|
||||
case PINOS_NODE_STATE_RUNNING:
|
||||
break;
|
||||
|
||||
case PINOS_NODE_STATE_ERROR:
|
||||
break;
|
||||
}
|
||||
pinos_node_update_state (this, state);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_add_port (PinosNode1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
PinosDirection arg_direction,
|
||||
guint arg_id,
|
||||
gpointer user_data)
|
||||
|
||||
static void
|
||||
on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
const gchar *sender;
|
||||
PinosPort *port;
|
||||
GError *error = NULL;
|
||||
PinosNode *this = user_data;
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
if (g_strcmp0 (priv->sender, sender) != 0)
|
||||
goto not_allowed;
|
||||
switch (event->type) {
|
||||
case SPA_EVENT_TYPE_PORT_ADDED:
|
||||
{
|
||||
SpaEventPortAdded *pa = event->data;
|
||||
|
||||
port = pinos_node_add_port (node, arg_id, &error);
|
||||
if (port == NULL)
|
||||
goto no_port;
|
||||
update_port_ids (this, FALSE);
|
||||
|
||||
g_debug ("node %p: add port %p", node, port);
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("()"));
|
||||
g_signal_emit (this, signals[SIGNAL_PORT_ADDED], 0, get_port_direction (this, pa->port_id),
|
||||
pa->port_id);
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_PORT_REMOVED:
|
||||
{
|
||||
SpaEventPortRemoved *pr = event->data;
|
||||
|
||||
return TRUE;
|
||||
update_port_ids (this, FALSE);
|
||||
|
||||
/* ERRORS */
|
||||
not_allowed:
|
||||
{
|
||||
g_debug ("sender %s is not owner of node with sender %s", sender, priv->sender);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "not node owner");
|
||||
return TRUE;
|
||||
}
|
||||
no_port:
|
||||
{
|
||||
g_debug ("node %p: could create port", node);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "can't create port");
|
||||
return TRUE;
|
||||
g_signal_emit (this, signals[SIGNAL_PORT_REMOVED], 0, pr->port_id);
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_STATE_CHANGE:
|
||||
{
|
||||
SpaEventStateChange *sc = event->data;
|
||||
|
||||
pinos_node_update_node_state (PINOS_NODE (this), sc->state);
|
||||
|
||||
switch (sc->state) {
|
||||
case SPA_NODE_STATE_CONFIGURE:
|
||||
{
|
||||
GList *links, *walk;
|
||||
|
||||
links = pinos_node_get_links (this);
|
||||
for (walk = links; walk; walk = g_list_next (walk)) {
|
||||
PinosLink *link = walk->data;
|
||||
pinos_link_activate (link);
|
||||
}
|
||||
g_list_free (links);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_ADD_POLL:
|
||||
{
|
||||
SpaPollItem *poll = event->data;
|
||||
unsigned int i;
|
||||
|
||||
g_debug ("node %p: add poll %d", this, poll->n_fds);
|
||||
priv->poll = *poll;
|
||||
priv->poll.fds = &priv->fds[priv->n_fds];
|
||||
for (i = 0; i < poll->n_fds; i++)
|
||||
priv->fds[priv->n_fds++] = poll->fds[i];
|
||||
|
||||
start_thread (this);
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_REMOVE_POLL:
|
||||
{
|
||||
SpaPollItem *poll = event->data;
|
||||
|
||||
g_debug ("node %p: remove poll %d", this, poll->n_fds);
|
||||
priv->n_fds -= poll->n_fds;
|
||||
|
||||
stop_thread (this);
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_HAVE_OUTPUT:
|
||||
{
|
||||
PinosLink *link;
|
||||
SpaOutputInfo oinfo[1] = { 0, };
|
||||
SpaResult res;
|
||||
|
||||
if ((res = spa_node_port_pull_output (node, 1, oinfo)) < 0)
|
||||
g_warning ("node %p: got pull error %d, %d", this, res, oinfo[0].status);
|
||||
|
||||
link = g_hash_table_lookup (priv->links, GUINT_TO_POINTER (oinfo[0].port_id));
|
||||
if (link) {
|
||||
SpaInputInfo iinfo[1];
|
||||
|
||||
iinfo[0].port_id = link->input_port;
|
||||
iinfo[0].buffer_id = oinfo[0].buffer_id;
|
||||
iinfo[0].flags = SPA_INPUT_FLAG_NONE;
|
||||
|
||||
if ((res = spa_node_port_push_input (link->input_node->node, 1, iinfo)) < 0)
|
||||
g_warning ("node %p: error pushing buffer: %d, %d", this, res, iinfo[0].status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_REUSE_BUFFER:
|
||||
{
|
||||
PinosLink *link;
|
||||
SpaResult res;
|
||||
SpaEventReuseBuffer *rb = event->data;
|
||||
|
||||
link = g_hash_table_lookup (priv->links, GUINT_TO_POINTER (rb->port_id));
|
||||
if (link) {
|
||||
if ((res = spa_node_port_reuse_buffer (link->output_node->node,
|
||||
link->output_port,
|
||||
rb->buffer_id)) < 0)
|
||||
g_warning ("node %p: error reuse buffer: %d", node, res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
g_debug ("node %p: got event %d", this, event->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_remove_port (PinosNode1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
guint arg_id,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
const gchar *sender;
|
||||
PinosPort *port;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
if (g_strcmp0 (priv->sender, sender) != 0)
|
||||
goto not_allowed;
|
||||
|
||||
port = pinos_node_find_port_by_id (node, arg_id);
|
||||
if (port == NULL)
|
||||
goto no_port;
|
||||
|
||||
if (!pinos_node_remove_port (node, port))
|
||||
goto no_port;
|
||||
|
||||
g_debug ("node %p: remove port %u", node, arg_id);
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("()"));
|
||||
|
||||
|
||||
return TRUE;
|
||||
|
||||
not_allowed:
|
||||
{
|
||||
g_debug ("sender %s is not owner of node with sender %s", sender, priv->sender);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "not node owner");
|
||||
return TRUE;
|
||||
}
|
||||
no_port:
|
||||
{
|
||||
g_debug ("node %p: could remove port", node);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "can't remove port");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
handle_remove (PinosNode1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
|
|
@ -417,22 +528,31 @@ on_property_notify (GObject *obj,
|
|||
static void
|
||||
pinos_node_constructed (GObject * obj)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (obj);
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
PinosNode *this = PINOS_NODE (obj);
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
SpaResult res;
|
||||
|
||||
g_debug ("node %p: constructed", node);
|
||||
g_debug ("node %p: constructed", this);
|
||||
|
||||
g_signal_connect (node, "notify", (GCallback) on_property_notify, node);
|
||||
g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
|
||||
G_OBJECT_CLASS (pinos_node_parent_class)->constructed (obj);
|
||||
|
||||
update_port_ids (node, TRUE);
|
||||
priv->fds[0].fd = eventfd (0, 0);
|
||||
priv->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
priv->fds[0].revents = 0;
|
||||
priv->n_fds = 1;
|
||||
|
||||
if ((res = spa_node_set_event_callback (this->node, on_node_event, this)) < 0)
|
||||
g_warning ("node %p: error setting callback", this);
|
||||
|
||||
update_port_ids (this, TRUE);
|
||||
|
||||
if (priv->sender == NULL) {
|
||||
priv->sender = g_strdup (pinos_daemon_get_sender (priv->daemon));
|
||||
}
|
||||
on_property_notify (G_OBJECT (node), NULL, node);
|
||||
on_property_notify (G_OBJECT (this), NULL, this);
|
||||
|
||||
node_register_object (node);
|
||||
node_register_object (this);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -441,12 +561,13 @@ pinos_node_dispose (GObject * obj)
|
|||
PinosNode *node = PINOS_NODE (obj);
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
||||
|
||||
g_debug ("node %p: dispose", node);
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
||||
stop_thread (node);
|
||||
|
||||
node_unregister_object (node);
|
||||
|
||||
g_hash_table_unref (priv->ports);
|
||||
g_hash_table_unref (priv->links);
|
||||
|
||||
G_OBJECT_CLASS (pinos_node_parent_class)->dispose (obj);
|
||||
}
|
||||
|
|
@ -582,8 +703,9 @@ pinos_node_class_init (PinosNodeClass * klass)
|
|||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
PINOS_TYPE_PORT);
|
||||
2,
|
||||
PINOS_TYPE_DIRECTION,
|
||||
G_TYPE_UINT);
|
||||
signals[SIGNAL_PORT_REMOVED] = g_signal_new ("port-removed",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
|
|
@ -593,11 +715,9 @@ pinos_node_class_init (PinosNodeClass * klass)
|
|||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
PINOS_TYPE_PORT);
|
||||
G_TYPE_UINT);
|
||||
|
||||
node_class->set_state = node_set_state;
|
||||
node_class->add_port = node_add_port;
|
||||
node_class->remove_port = node_remove_port;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -607,22 +727,13 @@ pinos_node_init (PinosNode * node)
|
|||
|
||||
g_debug ("node %p: new", node);
|
||||
priv->iface = pinos_node1_skeleton_new ();
|
||||
g_signal_connect (priv->iface, "handle-add-port",
|
||||
(GCallback) handle_add_port,
|
||||
node);
|
||||
g_signal_connect (priv->iface, "handle-remove-port",
|
||||
(GCallback) handle_remove_port,
|
||||
node);
|
||||
g_signal_connect (priv->iface, "handle-remove",
|
||||
(GCallback) handle_remove,
|
||||
node);
|
||||
priv->state = PINOS_NODE_STATE_SUSPENDED;
|
||||
pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_SUSPENDED);
|
||||
|
||||
priv->ports = g_hash_table_new_full (g_direct_hash,
|
||||
g_direct_equal,
|
||||
NULL,
|
||||
(GDestroyNotify) g_object_unref);
|
||||
priv->links = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -783,65 +894,6 @@ pinos_node_remove (PinosNode *node)
|
|||
g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_add_port:
|
||||
* @node: a #PinosNode
|
||||
* @direction: the direction of the port
|
||||
* @error: location of #GError
|
||||
*
|
||||
* Add the #PinosPort to @node
|
||||
*
|
||||
* Returns: a new #PinosPort or %NULL
|
||||
*/
|
||||
PinosPort *
|
||||
pinos_node_add_port (PinosNode *node,
|
||||
guint id,
|
||||
GError **error)
|
||||
{
|
||||
PinosNodeClass *klass;
|
||||
PinosPort *port;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
|
||||
klass = PINOS_NODE_GET_CLASS (node);
|
||||
if (!klass->add_port) {
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "add-port not implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_debug ("node %p: add port", node);
|
||||
port = klass->add_port (node, id, error);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_remove_port:
|
||||
* @node: a #PinosNode
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Remove @port from @node
|
||||
*
|
||||
* Returns: %TRUE when the port was removed
|
||||
*/
|
||||
gboolean
|
||||
pinos_node_remove_port (PinosNode *node, PinosPort *port)
|
||||
{
|
||||
PinosNodeClass *klass;
|
||||
gboolean res = FALSE;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), FALSE);
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), FALSE);
|
||||
|
||||
klass = PINOS_NODE_GET_CLASS (node);
|
||||
|
||||
if (!klass->remove_port)
|
||||
return FALSE;
|
||||
|
||||
res = klass->remove_port (node, port);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_free_port_id:
|
||||
* @node: a #PinosNode
|
||||
|
|
@ -872,11 +924,15 @@ pinos_node_get_free_port_id (PinosNode *node,
|
|||
ports = priv->output_port_ids;
|
||||
}
|
||||
|
||||
g_debug ("direction %d max %u, n %u\n", direction, max_ports, n_ports);
|
||||
g_debug ("node %p: direction %d max %u, n %u", node, direction, max_ports, n_ports);
|
||||
|
||||
for (i = 0; i < n_ports; i++) {
|
||||
if (free_port < ports[i])
|
||||
break;
|
||||
|
||||
if (g_hash_table_lookup (priv->links, GUINT_TO_POINTER (free_port)) == NULL && free_port < max_ports)
|
||||
return free_port;
|
||||
|
||||
free_port = ports[i] + 1;
|
||||
}
|
||||
if (free_port >= max_ports)
|
||||
|
|
@ -885,43 +941,110 @@ pinos_node_get_free_port_id (PinosNode *node,
|
|||
return free_port;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_find_port_by_id:
|
||||
* @node: a #PinosNode
|
||||
* @id: a #PinosPort id
|
||||
*
|
||||
* Get the port with @id @node.
|
||||
*
|
||||
* Returns: a #PinosPort with @id or %NULL when not found
|
||||
*/
|
||||
PinosPort *
|
||||
pinos_node_find_port_by_id (PinosNode *node, guint id)
|
||||
static void
|
||||
do_remove_link (PinosLink *link, PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
g_hash_table_remove (link->output_node->priv->links, GUINT_TO_POINTER (link->output_port));
|
||||
if (g_hash_table_size (link->output_node->priv->links) == 0)
|
||||
pinos_node_report_idle (link->output_node);
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return g_hash_table_lookup (priv->ports, GUINT_TO_POINTER (id));
|
||||
g_hash_table_remove (link->input_node->priv->links, GUINT_TO_POINTER (link->input_port));
|
||||
if (g_hash_table_size (link->input_node->priv->links) == 0)
|
||||
pinos_node_report_idle (link->input_node);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_ports:
|
||||
* pinos_node_link:
|
||||
* @output_node: a #PinosNode
|
||||
* @output_port: a port
|
||||
* @input_node: a #PinosNode
|
||||
* @input_port: a port
|
||||
* @format_filter: a format filter
|
||||
* @properties: extra properties
|
||||
*
|
||||
* Make a link between @output_node and @input_node on the given ports.
|
||||
*
|
||||
* If the ports were already linked, the existing linke will be returned.
|
||||
*
|
||||
* If the source port was linked to a different destination node or port, it
|
||||
* will be relinked.
|
||||
*
|
||||
* Returns: a new #PinosLink
|
||||
*/
|
||||
PinosLink *
|
||||
pinos_node_link (PinosNode *output_node,
|
||||
guint output_port,
|
||||
PinosNode *input_node,
|
||||
guint input_port,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
PinosLink *link;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (output_node), NULL);
|
||||
g_return_val_if_fail (PINOS_IS_NODE (input_node), NULL);
|
||||
|
||||
if (get_port_direction (output_node, output_port) != PINOS_DIRECTION_OUTPUT) {
|
||||
PinosNode *tmp;
|
||||
guint tmp_port;
|
||||
|
||||
tmp = output_node;
|
||||
output_node = input_node;
|
||||
input_node = tmp;
|
||||
|
||||
tmp_port = output_port;
|
||||
output_port = input_port;
|
||||
input_port = tmp_port;
|
||||
}
|
||||
|
||||
priv = output_node->priv;
|
||||
|
||||
link = g_hash_table_lookup (priv->links, GUINT_TO_POINTER (output_port));
|
||||
if (link) {
|
||||
link->input_node = input_node;
|
||||
link->input_port = input_port;
|
||||
g_object_ref (link);
|
||||
} else {
|
||||
|
||||
link = g_object_new (PINOS_TYPE_LINK,
|
||||
"daemon", priv->daemon,
|
||||
"output-node", output_node,
|
||||
"output-port", output_port,
|
||||
"input-node", input_node,
|
||||
"input-port", input_port,
|
||||
"format-filter", format_filter,
|
||||
"properties", properties,
|
||||
NULL);
|
||||
|
||||
g_signal_connect (link,
|
||||
"remove",
|
||||
(GCallback) do_remove_link,
|
||||
output_node);
|
||||
|
||||
g_hash_table_insert (priv->links, GUINT_TO_POINTER (output_port), link);
|
||||
g_hash_table_insert (input_node->priv->links, GUINT_TO_POINTER (input_port), link);
|
||||
}
|
||||
return link;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_links:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Get the ports in @node.
|
||||
* Get the links in @node.
|
||||
*
|
||||
* Returns: a #GList of ports g_list_free after usage.
|
||||
* Returns: a #GList of #PinosLink g_list_free after usage.
|
||||
*/
|
||||
GList *
|
||||
pinos_node_get_ports (PinosNode *node)
|
||||
pinos_node_get_links (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return g_hash_table_get_values (priv->ports);
|
||||
return g_hash_table_get_values (priv->links);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ typedef struct _PinosNodePrivate PinosNodePrivate;
|
|||
|
||||
#include <pinos/client/introspect.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
#include <pinos/server/port.h>
|
||||
#include <pinos/server/link.h>
|
||||
|
||||
#define PINOS_TYPE_NODE (pinos_node_get_type ())
|
||||
#define PINOS_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE))
|
||||
|
|
@ -68,12 +68,6 @@ struct _PinosNodeClass {
|
|||
|
||||
gboolean (*set_state) (PinosNode *node,
|
||||
PinosNodeState state);
|
||||
|
||||
PinosPort * (*add_port) (PinosNode *node,
|
||||
guint id,
|
||||
GError **error);
|
||||
gboolean (*remove_port) (PinosNode *node,
|
||||
PinosPort *port);
|
||||
};
|
||||
|
||||
/* normal GObject stuff */
|
||||
|
|
@ -95,14 +89,15 @@ const gchar * pinos_node_get_object_path (PinosNode *node);
|
|||
|
||||
guint pinos_node_get_free_port_id (PinosNode *node,
|
||||
PinosDirection direction);
|
||||
PinosPort * pinos_node_add_port (PinosNode *node,
|
||||
guint id,
|
||||
GError **error);
|
||||
gboolean pinos_node_remove_port (PinosNode *node,
|
||||
PinosPort *port);
|
||||
PinosPort * pinos_node_find_port_by_id (PinosNode *node,
|
||||
guint id);
|
||||
GList * pinos_node_get_ports (PinosNode *node);
|
||||
|
||||
PinosLink * pinos_node_link (PinosNode *output_node,
|
||||
guint output_port,
|
||||
PinosNode *input_node,
|
||||
guint input_port,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties);
|
||||
GList * pinos_node_get_links (PinosNode *node);
|
||||
|
||||
|
||||
PinosNodeState pinos_node_get_state (PinosNode *node);
|
||||
gboolean pinos_node_set_state (PinosNode *node, PinosNodeState state);
|
||||
|
|
|
|||
|
|
@ -1,545 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/client/enumtypes.h"
|
||||
|
||||
#include "pinos/server/port.h"
|
||||
#include "pinos/server/node.h"
|
||||
|
||||
#define PINOS_PORT_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_PORT, PinosPortPrivate))
|
||||
|
||||
#if 0
|
||||
#define PINOS_DEBUG_TRANSPORT(format,args...) g_debug(format,##args)
|
||||
#else
|
||||
#define PINOS_DEBUG_TRANSPORT(format,args...)
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
gulong id;
|
||||
PinosBufferCallback send_buffer_cb;
|
||||
PinosEventCallback send_event_cb;
|
||||
gpointer send_data;
|
||||
GDestroyNotify send_notify;
|
||||
} SendData;
|
||||
|
||||
struct _PinosPortPrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
|
||||
gulong data_id;
|
||||
|
||||
PinosBufferCallback received_buffer_cb;
|
||||
PinosEventCallback received_event_cb;
|
||||
gpointer received_data;
|
||||
GDestroyNotify received_notify;
|
||||
|
||||
gint active_count;
|
||||
|
||||
GList *send_datas;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosPort, pinos_port, G_TYPE_OBJECT);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DAEMON,
|
||||
PROP_NODE,
|
||||
PROP_DIRECTION,
|
||||
PROP_ID,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL_REMOVE,
|
||||
SIGNAL_ACTIVATE,
|
||||
SIGNAL_DEACTIVATE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
|
||||
void
|
||||
pinos_port_set_received_cb (PinosPort *port,
|
||||
PinosBufferCallback buffer_cb,
|
||||
PinosEventCallback event_cb,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
priv = port->priv;
|
||||
|
||||
g_debug ("port %p: set receive callback", port);
|
||||
|
||||
if (priv->received_notify)
|
||||
priv->received_notify (priv->received_data);;
|
||||
priv->received_buffer_cb = buffer_cb;
|
||||
priv->received_event_cb = event_cb;
|
||||
priv->received_data = user_data;
|
||||
priv->received_notify = notify;
|
||||
}
|
||||
|
||||
gulong
|
||||
pinos_port_add_send_cb (PinosPort *port,
|
||||
PinosBufferCallback buffer_cb,
|
||||
PinosEventCallback event_cb,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
SendData *data;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), -1);
|
||||
g_return_val_if_fail (buffer_cb != NULL, -1);
|
||||
g_return_val_if_fail (event_cb != NULL, -1);
|
||||
priv = port->priv;
|
||||
|
||||
g_debug ("port %p: add send callback", port);
|
||||
|
||||
data = g_slice_new (SendData);
|
||||
data->id = priv->data_id++;
|
||||
data->send_buffer_cb = buffer_cb;
|
||||
data->send_event_cb = event_cb;
|
||||
data->send_data = user_data;
|
||||
data->send_notify = notify;
|
||||
priv->send_datas = g_list_prepend (priv->send_datas, data);
|
||||
|
||||
return data->id;
|
||||
}
|
||||
|
||||
void
|
||||
pinos_port_remove_send_cb (PinosPort *port,
|
||||
gulong id)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
GList *walk;
|
||||
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
priv = port->priv;
|
||||
|
||||
g_debug ("port %p: remove send callback %lu", port, id);
|
||||
for (walk = priv->send_datas; walk; walk = g_list_next (walk)) {
|
||||
SendData *data = walk->data;
|
||||
|
||||
if (data->id == id) {
|
||||
if (data->send_notify)
|
||||
data->send_notify (data->send_data);;
|
||||
g_slice_free (SendData, data);
|
||||
priv->send_datas = g_list_delete_link (priv->send_datas, walk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (_object);
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
g_value_set_object (value, priv->daemon);
|
||||
break;
|
||||
|
||||
case PROP_NODE:
|
||||
g_value_set_object (value, port->node);
|
||||
break;
|
||||
|
||||
case PROP_DIRECTION:
|
||||
g_value_set_enum (value, port->direction);
|
||||
break;
|
||||
|
||||
case PROP_ID:
|
||||
g_value_set_uint (value, port->id);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (port, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_set_property (GObject *_object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (_object);
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
priv->daemon = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_NODE:
|
||||
port->node = g_value_get_object (value);
|
||||
break;
|
||||
|
||||
case PROP_DIRECTION:
|
||||
port->direction = g_value_get_enum (value);
|
||||
break;
|
||||
|
||||
case PROP_ID:
|
||||
port->id = g_value_get_uint (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (port, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_constructed (GObject * object)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (object);
|
||||
|
||||
g_debug ("port %p: constructed", port);
|
||||
|
||||
G_OBJECT_CLASS (pinos_port_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_dispose (GObject * object)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (object);
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
g_debug ("port %p: dispose %d", port, priv->active_count);
|
||||
if (priv->active_count == 1)
|
||||
g_signal_emit (port, signals[SIGNAL_DEACTIVATE], 0, NULL);
|
||||
|
||||
G_OBJECT_CLASS (pinos_port_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_finalize (GObject * object)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (object);
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
GList *walk;
|
||||
|
||||
g_debug ("port %p: finalize", port);
|
||||
if (priv->received_notify)
|
||||
priv->received_notify (priv->received_data);
|
||||
for (walk = priv->send_datas; walk; walk = g_list_next (walk)) {
|
||||
SendData *data = walk->data;
|
||||
if (data->send_notify)
|
||||
data->send_notify (data->send_data);
|
||||
g_slice_free (SendData, data);
|
||||
}
|
||||
g_list_free (priv->send_datas);
|
||||
|
||||
g_clear_object (&priv->daemon);
|
||||
|
||||
G_OBJECT_CLASS (pinos_port_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_class_init (PinosPortClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
//PinosPortClass *port_class = PINOS_PORT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosPortPrivate));
|
||||
|
||||
gobject_class->constructed = pinos_port_constructed;
|
||||
gobject_class->dispose = pinos_port_dispose;
|
||||
gobject_class->finalize = pinos_port_finalize;
|
||||
gobject_class->set_property = pinos_port_set_property;
|
||||
gobject_class->get_property = pinos_port_get_property;
|
||||
|
||||
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,
|
||||
PROP_NODE,
|
||||
g_param_spec_object ("node",
|
||||
"Node",
|
||||
"The Node",
|
||||
PINOS_TYPE_NODE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DIRECTION,
|
||||
g_param_spec_enum ("direction",
|
||||
"Direction",
|
||||
"The direction of the port",
|
||||
PINOS_TYPE_DIRECTION,
|
||||
PINOS_DIRECTION_INVALID,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ID,
|
||||
g_param_spec_uint ("id",
|
||||
"Id",
|
||||
"The id of the port",
|
||||
0,
|
||||
G_MAXUINT,
|
||||
0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
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);
|
||||
signals[SIGNAL_ACTIVATE] = g_signal_new ("activate",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
signals[SIGNAL_DEACTIVATE] = g_signal_new ("deactivate",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_init (PinosPort * port)
|
||||
{
|
||||
port->priv = PINOS_PORT_GET_PRIVATE (port);
|
||||
|
||||
g_debug ("port %p: new", port);
|
||||
port->direction = PINOS_DIRECTION_INVALID;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_remove:
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Trigger removal of @port
|
||||
*/
|
||||
void
|
||||
pinos_port_remove (PinosPort *port)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
|
||||
g_debug ("port %p: remove", port);
|
||||
g_signal_emit (port, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* pinos_port_have_common_format:
|
||||
* @port: a #PinosPort
|
||||
* @error: a #GError or %NULL
|
||||
*
|
||||
* Check if @port accepts any of the give formats
|
||||
*
|
||||
* Returns: %TRUE if there exists a matching format
|
||||
*/
|
||||
gboolean
|
||||
pinos_port_have_common_format (PinosPort *port,
|
||||
guint n_filter_formats,
|
||||
SpaFormat **filter_formats,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
pinos_port_activate (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
priv = port->priv;
|
||||
g_return_if_fail (priv->active_count >= 0);
|
||||
|
||||
g_debug ("port %p: activate count now %d", port, priv->active_count);
|
||||
|
||||
if (priv->active_count++ == 0)
|
||||
g_signal_emit (port, signals[SIGNAL_ACTIVATE], 0, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
pinos_port_deactivate (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
priv = port->priv;
|
||||
g_return_if_fail (priv->active_count > 0);
|
||||
|
||||
g_debug ("port %p: deactivate count now %d", port, priv->active_count);
|
||||
|
||||
if (--priv->active_count == 0)
|
||||
g_signal_emit (port, signals[SIGNAL_DEACTIVATE], 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_receive_buffer:
|
||||
* @port: a #PinosPort
|
||||
* @buffer_id: a buffer id
|
||||
* @error: a #GError or %NULL
|
||||
*
|
||||
* Receive @buffer on @port
|
||||
*
|
||||
* Returns: %TRUE on success. @error is set when %FALSE is returned.
|
||||
*/
|
||||
gboolean
|
||||
pinos_port_receive_buffer (PinosPort *port,
|
||||
uint32_t buffer_id,
|
||||
GError **error)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
PINOS_DEBUG_TRANSPORT ("port %p: receive buffer %d", port, buffer_id);
|
||||
|
||||
if (priv->received_buffer_cb)
|
||||
res = priv->received_buffer_cb (port, buffer_id, error, priv->received_data);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_receive_event:
|
||||
* @port: a #PinosPort
|
||||
* @event: a #SpaEvent
|
||||
* @error: a #GError or %NULL
|
||||
*
|
||||
* Receive @event on @port
|
||||
*
|
||||
* Returns: %TRUE on success. @error is set when %FALSE is returned.
|
||||
*/
|
||||
gboolean
|
||||
pinos_port_receive_event (PinosPort *port,
|
||||
SpaEvent *event,
|
||||
GError **error)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
PINOS_DEBUG_TRANSPORT ("port %p: receive event %p", port, event);
|
||||
|
||||
if (priv->received_event_cb)
|
||||
res = priv->received_event_cb (port, event, error, priv->received_data);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_send_buffer:
|
||||
* @port: a #PinosPort
|
||||
* @buffer_id: a buffer id
|
||||
* @error: a #GError or %NULL
|
||||
*
|
||||
* Send @buffer out on @port.
|
||||
*
|
||||
* Returns: %TRUE on success. @error is set when %FALSE is returned.
|
||||
*/
|
||||
gboolean
|
||||
pinos_port_send_buffer (PinosPort *port,
|
||||
uint32_t buffer_id,
|
||||
GError **error)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
PinosPortPrivate *priv;
|
||||
GList *walk;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), FALSE);
|
||||
|
||||
PINOS_DEBUG_TRANSPORT ("port %p: send buffer %d", port, buffer_id);
|
||||
|
||||
priv = port->priv;
|
||||
|
||||
for (walk = priv->send_datas; walk; walk = g_list_next (walk)) {
|
||||
SendData *data = walk->data;
|
||||
data->send_buffer_cb (port, buffer_id, error, data->send_data);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_send_event:
|
||||
* @port: a #PinosPort
|
||||
* @event: a #SpaEvent
|
||||
* @error: a #GError or %NULL
|
||||
*
|
||||
* Send @event out on @port.
|
||||
*
|
||||
* Returns: %TRUE on success. @error is set when %FALSE is returned.
|
||||
*/
|
||||
gboolean
|
||||
pinos_port_send_event (PinosPort *port,
|
||||
SpaEvent *event,
|
||||
GError **error)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
PinosPortPrivate *priv;
|
||||
GList *walk;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), FALSE);
|
||||
|
||||
PINOS_DEBUG_TRANSPORT ("port %p: send event %p", port, event);
|
||||
|
||||
priv = port->priv;
|
||||
|
||||
for (walk = priv->send_datas; walk; walk = g_list_next (walk)) {
|
||||
SendData *data = walk->data;
|
||||
data->send_event_cb (port, event, error, data->send_data);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef __PINOS_PORT_H__
|
||||
#define __PINOS_PORT_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _PinosPort PinosPort;
|
||||
typedef struct _PinosPortClass PinosPortClass;
|
||||
typedef struct _PinosPortPrivate PinosPortPrivate;
|
||||
|
||||
#include <spa/include/spa/buffer.h>
|
||||
|
||||
#include <pinos/client/introspect.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
|
||||
|
||||
#define PINOS_TYPE_PORT (pinos_port_get_type ())
|
||||
#define PINOS_IS_PORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_PORT))
|
||||
#define PINOS_IS_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_PORT))
|
||||
#define PINOS_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_PORT, PinosPortClass))
|
||||
#define PINOS_PORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_PORT, PinosPort))
|
||||
#define PINOS_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_PORT, PinosPortClass))
|
||||
#define PINOS_PORT_CAST(obj) ((PinosPort*)(obj))
|
||||
#define PINOS_PORT_CLASS_CAST(klass)((PinosPortClass*)(klass))
|
||||
|
||||
/**
|
||||
* PinosPort:
|
||||
*
|
||||
* Pinos port object class.
|
||||
*/
|
||||
struct _PinosPort {
|
||||
GObject object;
|
||||
|
||||
PinosDirection direction;
|
||||
uint32_t id;
|
||||
PinosNode *node;
|
||||
|
||||
SpaBuffer **buffers;
|
||||
guint n_buffers;
|
||||
|
||||
PinosPortPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosPortClass:
|
||||
*
|
||||
* Pinos port object class.
|
||||
*/
|
||||
struct _PinosPortClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*get_ringbuffer) (PinosPort *port,
|
||||
PinosProperties *props,
|
||||
GTask *task);
|
||||
};
|
||||
|
||||
typedef gboolean (*PinosBufferCallback) (PinosPort *port, uint32_t buffer_id, GError **error, gpointer user_data);
|
||||
typedef gboolean (*PinosEventCallback) (PinosPort *port, SpaEvent *event, GError **error, gpointer user_data);
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_port_get_type (void);
|
||||
|
||||
void pinos_port_set_received_cb (PinosPort *port,
|
||||
PinosBufferCallback buffer_cb,
|
||||
PinosEventCallback event_cb,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify);
|
||||
gulong pinos_port_add_send_cb (PinosPort *port,
|
||||
PinosBufferCallback buffer_cb,
|
||||
PinosEventCallback event_cb,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify);
|
||||
void pinos_port_remove_send_cb (PinosPort *port,
|
||||
gulong id);
|
||||
|
||||
void pinos_port_remove (PinosPort *port);
|
||||
|
||||
gboolean pinos_port_have_common_format (PinosPort *port,
|
||||
guint n_filter_formats,
|
||||
SpaFormat **filter_formats,
|
||||
GError **error);
|
||||
|
||||
void pinos_port_activate (PinosPort *port);
|
||||
void pinos_port_deactivate (PinosPort *port);
|
||||
|
||||
gboolean pinos_port_send_buffer (PinosPort *port,
|
||||
uint32_t buffer_id,
|
||||
GError **error);
|
||||
gboolean pinos_port_send_event (PinosPort *port,
|
||||
SpaEvent *event,
|
||||
GError **error);
|
||||
gboolean pinos_port_receive_buffer (PinosPort *port,
|
||||
uint32_t buffer_id,
|
||||
GError **error);
|
||||
gboolean pinos_port_receive_event (PinosPort *port,
|
||||
SpaEvent *event,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_PORT_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue