2016-07-21 18:38:24 +02:00
|
|
|
/* Pinos
|
|
|
|
|
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
2016-08-02 16:34:44 +02:00
|
|
|
#include <spa/include/spa/video/format.h>
|
2016-08-09 15:53:12 +02:00
|
|
|
#include <spa/include/spa/debug.h>
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2016-07-21 18:38:24 +02:00
|
|
|
#include "pinos/client/pinos.h"
|
|
|
|
|
#include "pinos/client/enumtypes.h"
|
|
|
|
|
|
|
|
|
|
#include "pinos/server/link.h"
|
|
|
|
|
|
|
|
|
|
#include "pinos/dbus/org-pinos.h"
|
|
|
|
|
|
|
|
|
|
#define PINOS_LINK_GET_PRIVATE(obj) \
|
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_LINK, PinosLinkPrivate))
|
|
|
|
|
|
|
|
|
|
struct _PinosLinkPrivate
|
|
|
|
|
{
|
|
|
|
|
PinosDaemon *daemon;
|
|
|
|
|
PinosLink1 *iface;
|
|
|
|
|
|
|
|
|
|
gchar *object_path;
|
2016-09-06 16:43:37 +02:00
|
|
|
GPtrArray *format_filter;
|
|
|
|
|
PinosProperties *properties;
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
SpaBuffer *in_buffers[16];
|
|
|
|
|
unsigned int n_in_buffers;
|
|
|
|
|
SpaBuffer *out_buffers[16];
|
|
|
|
|
unsigned int n_out_buffers;
|
2016-07-21 18:38:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (PinosLink, pinos_link, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_DAEMON,
|
|
|
|
|
PROP_OBJECT_PATH,
|
2016-09-02 19:51:23 +02:00
|
|
|
PROP_OUTPUT_NODE,
|
2016-09-12 18:29:59 +02:00
|
|
|
PROP_OUTPUT_ID,
|
2016-09-02 19:51:23 +02:00
|
|
|
PROP_OUTPUT_PORT,
|
|
|
|
|
PROP_INPUT_NODE,
|
2016-09-12 18:29:59 +02:00
|
|
|
PROP_INPUT_ID,
|
2016-09-02 19:51:23 +02:00
|
|
|
PROP_INPUT_PORT,
|
|
|
|
|
PROP_FORMAT_FILTER,
|
|
|
|
|
PROP_PROPERTIES,
|
2016-07-21 18:38:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
SIGNAL_REMOVE,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_link_get_property (GObject *_object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosLink *this = PINOS_LINK (_object);
|
|
|
|
|
PinosLinkPrivate *priv = this->priv;
|
2016-07-21 18:38:24 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_DAEMON:
|
|
|
|
|
g_value_set_object (value, priv->daemon);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
case PROP_OBJECT_PATH:
|
|
|
|
|
g_value_set_string (value, priv->object_path);
|
2016-07-22 17:17:44 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
case PROP_OUTPUT_NODE:
|
|
|
|
|
g_value_set_object (value, this->output_node);
|
2016-07-22 17:17:44 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
case PROP_OUTPUT_ID:
|
|
|
|
|
g_value_set_uint (value, this->output_id);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
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;
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
case PROP_INPUT_ID:
|
|
|
|
|
g_value_set_uint (value, this->input_id);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
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);
|
2016-07-21 18:38:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2016-09-02 19:51:23 +02:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
2016-07-21 18:38:24 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_link_set_property (GObject *_object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosLink *this = PINOS_LINK (_object);
|
|
|
|
|
PinosLinkPrivate *priv = this->priv;
|
2016-07-21 18:38:24 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_DAEMON:
|
|
|
|
|
priv->daemon = g_value_dup_object (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
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);
|
2016-07-22 17:17:44 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
case PROP_OUTPUT_ID:
|
|
|
|
|
this->output_id = g_value_get_uint (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
case PROP_OUTPUT_PORT:
|
|
|
|
|
this->output_port = g_value_get_uint (value);
|
2016-07-22 17:17:44 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
case PROP_INPUT_NODE:
|
|
|
|
|
this->input_node = g_value_dup_object (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
case PROP_INPUT_ID:
|
|
|
|
|
this->input_id = g_value_get_uint (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
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);
|
2016-07-21 18:38:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2016-09-02 19:51:23 +02:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
2016-07-21 18:38:24 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-09-02 19:51:23 +02:00
|
|
|
link_register_object (PinosLink *this)
|
2016-07-21 18:38:24 +02:00
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosLinkPrivate *priv = this->priv;
|
2016-07-21 18:38:24 +02:00
|
|
|
PinosObjectSkeleton *skel;
|
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
|
|
name = g_strdup_printf (PINOS_DBUS_OBJECT_LINK);
|
|
|
|
|
skel = pinos_object_skeleton_new (name);
|
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
|
|
pinos_object_skeleton_set_link1 (skel, priv->iface);
|
|
|
|
|
|
|
|
|
|
g_free (priv->object_path);
|
|
|
|
|
priv->object_path = pinos_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel));
|
|
|
|
|
g_object_unref (skel);
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("link %p: register object %s", this, priv->object_path);
|
2016-07-21 18:38:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-09-02 19:51:23 +02:00
|
|
|
link_unregister_object (PinosLink *this)
|
2016-07-21 18:38:24 +02:00
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosLinkPrivate *priv = this->priv;
|
2016-07-21 18:38:24 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("link %p: unregister object", this);
|
2016-07-21 18:38:24 +02:00
|
|
|
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-02 16:34:44 +02:00
|
|
|
static SpaResult
|
2016-09-06 16:43:37 +02:00
|
|
|
do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
2016-08-02 16:34:44 +02:00
|
|
|
{
|
|
|
|
|
SpaResult res;
|
2016-08-09 15:53:12 +02:00
|
|
|
SpaFormat *filter, *format;
|
|
|
|
|
void *istate = NULL, *ostate = NULL;
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
/* both ports need a format */
|
|
|
|
|
if (in_state == SPA_NODE_STATE_CONFIGURE && out_state == SPA_NODE_STATE_CONFIGURE) {
|
|
|
|
|
g_debug ("link %p: doing negotiate format", this);
|
2016-08-09 15:53:12 +02:00
|
|
|
again:
|
2016-09-06 16:43:37 +02:00
|
|
|
if ((res = spa_node_port_enum_formats (this->input_node->node,
|
|
|
|
|
this->input_port,
|
|
|
|
|
&filter,
|
|
|
|
|
NULL,
|
|
|
|
|
&istate)) < 0) {
|
|
|
|
|
g_warning ("error input enum formats: %d", res);
|
|
|
|
|
goto error;
|
2016-08-09 15:53:12 +02:00
|
|
|
}
|
2016-09-06 16:43:37 +02:00
|
|
|
spa_debug_format (filter);
|
|
|
|
|
|
|
|
|
|
if ((res = spa_node_port_enum_formats (this->output_node->node,
|
|
|
|
|
this->output_port,
|
|
|
|
|
&format,
|
|
|
|
|
filter,
|
|
|
|
|
&ostate)) < 0) {
|
|
|
|
|
if (res == SPA_RESULT_ENUM_END) {
|
|
|
|
|
ostate = NULL;
|
|
|
|
|
goto again;
|
|
|
|
|
}
|
|
|
|
|
g_warning ("error output enum formats: %d", res);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2016-09-07 13:43:14 +02:00
|
|
|
spa_debug_format (format);
|
2016-09-06 16:43:37 +02:00
|
|
|
spa_format_fixate (format);
|
|
|
|
|
} else if (in_state == SPA_NODE_STATE_CONFIGURE) {
|
|
|
|
|
/* only input needs format */
|
|
|
|
|
if ((res = spa_node_port_get_format (this->output_node->node, this->output_port, (const SpaFormat **)&format)) < 0) {
|
|
|
|
|
g_warning ("error get format output: %d", res);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else if (out_state == SPA_NODE_STATE_CONFIGURE) {
|
|
|
|
|
/* only output needs format */
|
|
|
|
|
if ((res = spa_node_port_get_format (this->input_node->node, this->input_port, (const SpaFormat **)&format)) < 0) {
|
|
|
|
|
g_warning ("error get format input: %d", res);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-08-25 14:10:38 +02:00
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
g_debug ("link %p: doing set format", this);
|
2016-08-26 17:43:48 +02:00
|
|
|
spa_debug_format (format);
|
|
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
if (out_state == SPA_NODE_STATE_CONFIGURE) {
|
2016-09-12 15:25:53 +02:00
|
|
|
g_debug ("link %p: doing set format on output", this);
|
2016-09-06 16:43:37 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2016-09-12 15:25:53 +02:00
|
|
|
} else if (in_state == SPA_NODE_STATE_CONFIGURE) {
|
|
|
|
|
g_debug ("link %p: doing set format on input", this);
|
2016-09-06 16:43:37 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-08-26 17:43:48 +02:00
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
{
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-09-06 16:43:37 +02:00
|
|
|
do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
2016-08-02 16:34:44 +02:00
|
|
|
{
|
|
|
|
|
PinosLinkPrivate *priv = this->priv;
|
|
|
|
|
SpaResult res;
|
2016-08-11 11:20:12 +02:00
|
|
|
const SpaPortInfo *iinfo, *oinfo;
|
2016-08-24 16:26:58 +02:00
|
|
|
SpaPortInfoFlags in_flags, out_flags;
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
if (in_state < SPA_NODE_STATE_READY || out_state < SPA_NODE_STATE_READY)
|
2016-09-06 16:43:37 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("link %p: doing alloc buffers %p %p", this, this->output_node, this->input_node);
|
2016-08-11 11:20:12 +02:00
|
|
|
/* find out what's possible */
|
2016-09-02 19:51:23 +02:00
|
|
|
if ((res = spa_node_port_get_info (this->output_node->node, this->output_port, &oinfo)) < 0) {
|
2016-08-11 11:20:12 +02:00
|
|
|
g_warning ("error get port info: %d", res);
|
2016-08-26 17:43:48 +02:00
|
|
|
goto error;
|
2016-08-11 11:20:12 +02:00
|
|
|
}
|
2016-09-02 19:51:23 +02:00
|
|
|
if ((res = spa_node_port_get_info (this->input_node->node, this->input_port, &iinfo)) < 0) {
|
2016-08-11 11:20:12 +02:00
|
|
|
g_warning ("error get port info: %d", res);
|
2016-08-26 17:43:48 +02:00
|
|
|
goto error;
|
2016-08-11 11:20:12 +02:00
|
|
|
}
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
spa_debug_port_info (oinfo);
|
|
|
|
|
spa_debug_port_info (iinfo);
|
|
|
|
|
|
|
|
|
|
if ((oinfo->flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) &&
|
|
|
|
|
(iinfo->flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS)) {
|
|
|
|
|
out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
|
|
|
|
in_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
|
|
|
|
} else if ((oinfo->flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) &&
|
|
|
|
|
(iinfo->flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS)) {
|
|
|
|
|
out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
|
|
|
|
in_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
|
|
|
|
} else if ((oinfo->flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) &&
|
|
|
|
|
(iinfo->flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS)) {
|
2016-09-12 18:29:59 +02:00
|
|
|
priv->n_in_buffers = 16;
|
2016-08-24 16:26:58 +02:00
|
|
|
out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
|
|
|
|
in_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
|
|
|
|
|
|
|
|
|
if ((res = spa_buffer_alloc (oinfo->params, oinfo->n_params,
|
|
|
|
|
priv->in_buffers,
|
|
|
|
|
&priv->n_in_buffers)) < 0) {
|
|
|
|
|
g_warning ("error alloc buffers: %d", res);
|
2016-08-26 17:43:48 +02:00
|
|
|
goto error;
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
|
|
|
|
memcpy (priv->out_buffers, priv->in_buffers, priv->n_in_buffers * sizeof (SpaBuffer*));
|
|
|
|
|
priv->n_out_buffers = priv->n_in_buffers;
|
|
|
|
|
} else if ((oinfo->flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) &&
|
|
|
|
|
(iinfo->flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS)) {
|
|
|
|
|
out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
|
|
|
|
in_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
|
|
|
|
} else {
|
|
|
|
|
g_warning ("error no common allocation found");
|
2016-08-26 17:43:48 +02:00
|
|
|
res = SPA_RESULT_ERROR;
|
|
|
|
|
goto error;
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
if (in_state > SPA_NODE_STATE_READY)
|
|
|
|
|
in_flags &= ~SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
|
|
|
|
if (out_state > SPA_NODE_STATE_READY)
|
|
|
|
|
out_flags &= ~SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
|
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
2016-09-12 18:29:59 +02:00
|
|
|
priv->n_in_buffers = 16;
|
2016-09-02 19:51:23 +02:00
|
|
|
if ((res = spa_node_port_alloc_buffers (this->input_node->node, this->input_port,
|
2016-08-24 16:26:58 +02:00
|
|
|
oinfo->params, oinfo->n_params,
|
|
|
|
|
priv->in_buffers, &priv->n_in_buffers)) < 0) {
|
|
|
|
|
g_warning ("error alloc buffers: %d", res);
|
2016-08-26 17:43:48 +02:00
|
|
|
goto error;
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
2016-09-12 18:29:59 +02:00
|
|
|
priv->n_out_buffers = 16;
|
2016-09-02 19:51:23 +02:00
|
|
|
if ((res = spa_node_port_alloc_buffers (this->output_node->node, this->output_port,
|
2016-08-24 16:26:58 +02:00
|
|
|
iinfo->params, iinfo->n_params,
|
|
|
|
|
priv->out_buffers, &priv->n_out_buffers)) < 0) {
|
|
|
|
|
g_warning ("error alloc buffers: %d", res);
|
2016-08-26 17:43:48 +02:00
|
|
|
goto error;
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
2016-09-02 19:51:23 +02:00
|
|
|
if ((res = spa_node_port_use_buffers (this->input_node->node, this->input_port,
|
2016-08-24 16:26:58 +02:00
|
|
|
priv->out_buffers, priv->n_out_buffers)) < 0) {
|
|
|
|
|
g_warning ("error use buffers: %d", res);
|
2016-08-26 17:43:48 +02:00
|
|
|
goto error;
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
2016-09-02 19:51:23 +02:00
|
|
|
if ((res = spa_node_port_use_buffers (this->output_node->node, this->output_port,
|
2016-08-24 16:26:58 +02:00
|
|
|
priv->in_buffers, priv->n_in_buffers)) < 0) {
|
|
|
|
|
g_warning ("error use buffers: %d", res);
|
2016-08-26 17:43:48 +02:00
|
|
|
goto error;
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-08-26 17:43:48 +02:00
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
{
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
static SpaResult
|
2016-09-06 16:43:37 +02:00
|
|
|
do_start (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
2016-08-24 16:26:58 +02:00
|
|
|
{
|
2016-09-06 16:43:37 +02:00
|
|
|
SpaNodeCommand cmd;
|
|
|
|
|
SpaResult res = SPA_RESULT_OK;
|
2016-08-26 17:43:48 +02:00
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
cmd.type = SPA_NODE_COMMAND_START;
|
2016-09-12 15:25:53 +02:00
|
|
|
cmd.data = NULL;
|
|
|
|
|
cmd.size = 0;
|
2016-09-06 16:43:37 +02:00
|
|
|
if (in_state == SPA_NODE_STATE_PAUSED) {
|
|
|
|
|
if ((res = spa_node_send_command (this->input_node->node, &cmd)) < 0)
|
|
|
|
|
g_warning ("got error %d", res);
|
|
|
|
|
}
|
|
|
|
|
if (out_state == SPA_NODE_STATE_PAUSED) {
|
|
|
|
|
if ((res = spa_node_send_command (this->output_node->node, &cmd)) < 0)
|
|
|
|
|
g_warning ("got error %d", res);
|
|
|
|
|
}
|
2016-08-24 16:26:58 +02:00
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
check_states (PinosLink *this)
|
|
|
|
|
{
|
|
|
|
|
SpaResult res;
|
2016-09-02 19:51:23 +02:00
|
|
|
SpaNodeState in_state, out_state;
|
|
|
|
|
|
2016-09-05 16:23:40 +02:00
|
|
|
in_state = this->input_node->node->state;
|
|
|
|
|
out_state = this->output_node->node->state;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-09-12 15:25:53 +02:00
|
|
|
g_debug ("link %p: input state %d, output state %d", this, in_state, out_state);
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
if ((res = do_negotiate (this, in_state, out_state)) < 0)
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
|
|
if ((res = do_allocation (this, in_state, out_state)) < 0)
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
|
|
if ((res = do_start (this, in_state, out_state)) < 0)
|
|
|
|
|
return res;
|
|
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_node_state_notify (GObject *obj,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
PinosLink *this = user_data;
|
|
|
|
|
|
|
|
|
|
g_debug ("link %p: node %p state change", this, obj);
|
|
|
|
|
check_states (this);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-18 12:17:31 +02:00
|
|
|
static void
|
|
|
|
|
on_property_notify (GObject *obj,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2016-08-24 16:26:58 +02:00
|
|
|
PinosLink *this = user_data;
|
|
|
|
|
PinosLinkPrivate *priv = this->priv;
|
2016-08-18 12:17:31 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
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), "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));
|
2016-08-18 12:17:31 +02:00
|
|
|
}
|
2016-09-02 19:51:23 +02:00
|
|
|
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "input-port") == 0) {
|
|
|
|
|
pinos_link1_set_input_port (priv->iface, this->input_port);
|
2016-08-18 12:17:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-07-21 18:38:24 +02:00
|
|
|
static void
|
|
|
|
|
pinos_link_constructed (GObject * object)
|
|
|
|
|
{
|
2016-08-24 16:26:58 +02:00
|
|
|
PinosLink *this = PINOS_LINK (object);
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
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);
|
2016-07-21 18:38:24 +02:00
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
|
2016-07-21 18:38:24 +02:00
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object);
|
2016-08-18 12:17:31 +02:00
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
on_property_notify (G_OBJECT (this), NULL, this);
|
2016-09-12 18:29:59 +02:00
|
|
|
g_debug ("link %p: constructed %p:%d:%d -> %p:%d:%d", this,
|
|
|
|
|
this->output_node, this->output_id, this->output_port,
|
|
|
|
|
this->input_node, this->input_id, this->input_port);
|
2016-08-24 16:26:58 +02:00
|
|
|
link_register_object (this);
|
2016-09-06 16:43:37 +02:00
|
|
|
|
|
|
|
|
check_states (this);
|
2016-07-21 18:38:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_link_dispose (GObject * object)
|
|
|
|
|
{
|
2016-08-26 17:43:48 +02:00
|
|
|
PinosLink *this = PINOS_LINK (object);
|
|
|
|
|
|
|
|
|
|
g_debug ("link %p: dispose", this);
|
2016-07-21 18:38:24 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_signal_handlers_disconnect_by_data (this->input_node, this);
|
|
|
|
|
g_signal_handlers_disconnect_by_data (this->output_node, this);
|
2016-09-01 10:04:25 +02:00
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_clear_object (&this->input_node);
|
|
|
|
|
g_clear_object (&this->output_node);
|
2016-07-25 10:46:29 +02:00
|
|
|
|
2016-08-26 17:43:48 +02:00
|
|
|
link_unregister_object (this);
|
2016-07-21 18:38:24 +02:00
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (pinos_link_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_link_finalize (GObject * object)
|
|
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosLink *this = PINOS_LINK (object);
|
|
|
|
|
PinosLinkPrivate *priv = this->priv;
|
2016-07-21 18:38:24 +02:00
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("link %p: finalize", this);
|
2016-07-21 18:38:24 +02:00
|
|
|
g_clear_object (&priv->daemon);
|
|
|
|
|
g_clear_object (&priv->iface);
|
|
|
|
|
g_free (priv->object_path);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (pinos_link_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pinos_link_class_init (PinosLinkClass * klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
//PinosLinkClass *link_class = PINOS_LINK_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (PinosLinkPrivate));
|
|
|
|
|
|
|
|
|
|
gobject_class->constructed = pinos_link_constructed;
|
|
|
|
|
gobject_class->dispose = pinos_link_dispose;
|
|
|
|
|
gobject_class->finalize = pinos_link_finalize;
|
|
|
|
|
gobject_class->set_property = pinos_link_set_property;
|
|
|
|
|
gobject_class->get_property = pinos_link_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));
|
|
|
|
|
|
2016-07-22 17:17:44 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
2016-09-02 19:51:23 +02:00
|
|
|
PROP_OUTPUT_NODE,
|
|
|
|
|
g_param_spec_object ("output-node",
|
|
|
|
|
"Output Node",
|
|
|
|
|
"The output node",
|
|
|
|
|
PINOS_TYPE_NODE,
|
2016-07-22 17:17:44 +02:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_OUTPUT_ID,
|
|
|
|
|
g_param_spec_uint ("output-id",
|
|
|
|
|
"Output Id",
|
|
|
|
|
"The output id",
|
|
|
|
|
0,
|
|
|
|
|
G_MAXUINT,
|
|
|
|
|
-1,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2016-07-22 17:17:44 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
2016-09-02 19:51:23 +02:00
|
|
|
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,
|
2016-07-22 17:17:44 +02:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2016-09-12 18:29:59 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_INPUT_ID,
|
|
|
|
|
g_param_spec_uint ("input-id",
|
|
|
|
|
"Input Id",
|
|
|
|
|
"The input id",
|
|
|
|
|
0,
|
|
|
|
|
G_MAXUINT,
|
|
|
|
|
-1,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
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));
|
|
|
|
|
|
2016-07-21 18:38:24 +02:00
|
|
|
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
0,
|
|
|
|
|
G_TYPE_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-09-02 19:51:23 +02:00
|
|
|
pinos_link_init (PinosLink * this)
|
2016-07-21 18:38:24 +02:00
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
PinosLinkPrivate *priv = this->priv = PINOS_LINK_GET_PRIVATE (this);
|
2016-07-21 18:38:24 +02:00
|
|
|
|
|
|
|
|
priv->iface = pinos_link1_skeleton_new ();
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("link %p: new", this);
|
2016-07-22 17:17:44 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-21 18:38:24 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_link_remove:
|
|
|
|
|
* @link: a #PinosLink
|
|
|
|
|
*
|
|
|
|
|
* Trigger removal of @link
|
|
|
|
|
*/
|
|
|
|
|
void
|
2016-09-02 19:51:23 +02:00
|
|
|
pinos_link_remove (PinosLink *this)
|
2016-07-21 18:38:24 +02:00
|
|
|
{
|
2016-09-02 19:51:23 +02:00
|
|
|
g_debug ("link %p: remove", this);
|
|
|
|
|
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
|
2016-07-21 18:38:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_link_get_object_path:
|
|
|
|
|
* @link: a #PinosLink
|
|
|
|
|
*
|
|
|
|
|
* Get the object patch of @link
|
|
|
|
|
*
|
|
|
|
|
* Returns: the object path of @source.
|
|
|
|
|
*/
|
|
|
|
|
const gchar *
|
2016-09-02 19:51:23 +02:00
|
|
|
pinos_link_get_object_path (PinosLink *this)
|
2016-07-21 18:38:24 +02:00
|
|
|
{
|
|
|
|
|
PinosLinkPrivate *priv;
|
|
|
|
|
|
2016-09-02 19:51:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_LINK (this), NULL);
|
|
|
|
|
priv = this->priv;
|
2016-07-21 18:38:24 +02:00
|
|
|
|
|
|
|
|
return priv->object_path;
|
|
|
|
|
}
|