mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -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
|
|
@ -215,7 +215,6 @@ libpinoscore_@PINOS_MAJORMINOR@_la_SOURCES = \
|
||||||
server/link.c server/link.h \
|
server/link.c server/link.h \
|
||||||
server/module.c server/module.h \
|
server/module.c server/module.h \
|
||||||
server/node.c server/node.h \
|
server/node.c server/node.h \
|
||||||
server/port.c server/port.h \
|
|
||||||
server/node-factory.c server/node-factory.h \
|
server/node-factory.c server/node-factory.h \
|
||||||
dbus/org-pinos.c dbus/org-pinos.h
|
dbus/org-pinos.c dbus/org-pinos.h
|
||||||
|
|
||||||
|
|
@ -236,8 +235,6 @@ module_LTLIBRARIES += module-gst.la
|
||||||
module_gst_la_SOURCES = \
|
module_gst_la_SOURCES = \
|
||||||
modules/gst/gst-manager.c \
|
modules/gst/gst-manager.c \
|
||||||
modules/gst/gst-node-factory.c \
|
modules/gst/gst-node-factory.c \
|
||||||
modules/gst/gst-sink.c \
|
|
||||||
modules/gst/gst-source.c \
|
|
||||||
modules/gst/module.c
|
modules/gst/module.c
|
||||||
module_gst_la_CFLAGS = $(AM_CFLAGS) $(GST_CFLAGS)
|
module_gst_la_CFLAGS = $(AM_CFLAGS) $(GST_CFLAGS)
|
||||||
module_gst_la_LDFLAGS = $(MODULE_LDFLAGS)
|
module_gst_la_LDFLAGS = $(MODULE_LDFLAGS)
|
||||||
|
|
|
||||||
|
|
@ -442,8 +442,10 @@ link_fill_info (PinosLinkInfo *info, GDBusProxy *proxy)
|
||||||
info->link_path = g_dbus_proxy_get_object_path (proxy);
|
info->link_path = g_dbus_proxy_get_object_path (proxy);
|
||||||
|
|
||||||
info->change_mask = 0;
|
info->change_mask = 0;
|
||||||
SET_STRING ("SrcPort", source_port_path, 0);
|
SET_STRING ("OutputNode", output_node_path, 0);
|
||||||
SET_STRING ("DestPort", destination_port_path, 1);
|
SET_UINT32 ("OutputPort", output_port, 1, -1);
|
||||||
|
SET_STRING ("InputNode", input_node_path, 2);
|
||||||
|
SET_UINT32 ("InputPort", input_port, 3, -1);
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
g_hash_table_remove_all (changed);
|
g_hash_table_remove_all (changed);
|
||||||
|
|
|
||||||
|
|
@ -247,8 +247,10 @@ void pinos_context_get_node_info_by_id (PinosContext *context,
|
||||||
* @id: generic id of the link
|
* @id: generic id of the link
|
||||||
* @link_path: the unique path of the link
|
* @link_path: the unique path of the link
|
||||||
* @change_mask: bitfield of changed fields since last call
|
* @change_mask: bitfield of changed fields since last call
|
||||||
* @source_port_path: the source port
|
* @output_node_path: the output node
|
||||||
* @destination_port_path: the destination port
|
* @output_port: the output port
|
||||||
|
* @input_node_path: the input node
|
||||||
|
* @input_port: the input port
|
||||||
*
|
*
|
||||||
* The link information. Extra information can be added in later
|
* The link information. Extra information can be added in later
|
||||||
* versions.
|
* versions.
|
||||||
|
|
@ -257,8 +259,10 @@ typedef struct {
|
||||||
gpointer id;
|
gpointer id;
|
||||||
const char *link_path;
|
const char *link_path;
|
||||||
guint64 change_mask;
|
guint64 change_mask;
|
||||||
const char *source_port_path;
|
const char *output_node_path;
|
||||||
const char *destination_port_path;
|
guint output_port;
|
||||||
|
const char *input_node_path;
|
||||||
|
guint input_port;
|
||||||
} PinosLinkInfo;
|
} PinosLinkInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -52,15 +52,6 @@
|
||||||
<arg type='h' name='fd' direction='out'/>
|
<arg type='h' name='fd' direction='out'/>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
<method name='LinkNodes'>
|
|
||||||
<arg type='s' name='src_port' direction='in' />
|
|
||||||
<arg type='s' name='dest_port' direction='in' />
|
|
||||||
<arg type='s' name='format_filter' direction='in'/>
|
|
||||||
<arg type='a{sv}' name='properties' direction='in'/>
|
|
||||||
<arg type='o' name='link' direction='out' />
|
|
||||||
</method>
|
|
||||||
|
|
||||||
|
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
<interface name='org.pinos.Client1'>
|
<interface name='org.pinos.Client1'>
|
||||||
|
|
@ -86,16 +77,13 @@
|
||||||
|
|
||||||
<property name='Ports' type='a(uu)' access='read' />
|
<property name='Ports' type='a(uu)' access='read' />
|
||||||
|
|
||||||
<method name='AddPort'>
|
<method name='Link'>
|
||||||
<arg type='u' name='direction' direction='in'/>
|
<arg type='o' name='input_node' direction='in' />
|
||||||
<arg type='u' name='id' direction='in'/>
|
<arg type='s' name='format_filter' direction='in'/>
|
||||||
|
<arg type='a{sv}' name='properties' direction='in'/>
|
||||||
|
<arg type='o' name='link' direction='out' />
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
<method name='RemovePort'>
|
|
||||||
<arg type='u' name='id' direction='in'/>
|
|
||||||
</method>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- state: state of the node
|
<!-- state: state of the node
|
||||||
-1 = the node is in error
|
-1 = the node is in error
|
||||||
0 = the node is suspended, this means that the node is not
|
0 = the node is suspended, this means that the node is not
|
||||||
|
|
@ -128,8 +116,10 @@
|
||||||
<!-- Owner: the owner path of this link -->
|
<!-- Owner: the owner path of this link -->
|
||||||
<property name='Owner' type='s' access='read' />
|
<property name='Owner' type='s' access='read' />
|
||||||
|
|
||||||
<property name='SrcPort' type='s' access='read' />
|
<property name='OutputNode' type='o' access='read' />
|
||||||
<property name='DestPort' type='s' access='read' />
|
<property name='OutputPort' type='u' access='read' />
|
||||||
|
<property name='InputNode' type='o' access='read' />
|
||||||
|
<property name='InputPort' type='u' access='read' />
|
||||||
|
|
||||||
<property name='Properties' type='a{sv}' access='read' />
|
<property name='Properties' type='a{sv}' access='read' />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -512,8 +512,6 @@ pinos_gst_sink_class_init (PinosGstSinkClass * klass)
|
||||||
G_PARAM_CONSTRUCT_ONLY |
|
G_PARAM_CONSTRUCT_ONLY |
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
node_class->set_state = set_state;
|
node_class->set_state = set_state;
|
||||||
node_class->add_port = add_port;
|
|
||||||
node_class->remove_port = remove_port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@
|
||||||
|
|
||||||
struct _PinosSpaAlsaSinkPrivate
|
struct _PinosSpaAlsaSinkPrivate
|
||||||
{
|
{
|
||||||
PinosProperties *props;
|
|
||||||
PinosRingbuffer *ringbuffer;
|
PinosRingbuffer *ringbuffer;
|
||||||
|
|
||||||
SpaPollFd fds[16];
|
SpaPollFd fds[16];
|
||||||
|
|
@ -329,25 +328,7 @@ set_property (GObject *object,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
#if 0
|
||||||
on_activate (PinosPort *port, gpointer user_data)
|
|
||||||
{
|
|
||||||
PinosNode *node = user_data;
|
|
||||||
|
|
||||||
g_debug ("port %p: activate", port);
|
|
||||||
|
|
||||||
pinos_node_report_busy (node);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
on_deactivate (PinosPort *port, gpointer user_data)
|
|
||||||
{
|
|
||||||
PinosNode *node = user_data;
|
|
||||||
|
|
||||||
g_debug ("port %p: deactivate", port);
|
|
||||||
pinos_node_report_idle (node);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
on_received_buffer (PinosPort *port,
|
on_received_buffer (PinosPort *port,
|
||||||
uint32_t buffer_id,
|
uint32_t buffer_id,
|
||||||
|
|
@ -357,7 +338,7 @@ on_received_buffer (PinosPort *port,
|
||||||
PinosSpaAlsaSink *this = user_data;
|
PinosSpaAlsaSink *this = user_data;
|
||||||
PinosSpaAlsaSinkPrivate *priv = this->priv;
|
PinosSpaAlsaSinkPrivate *priv = this->priv;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
SpaBuffer *buffer = port->buffers[buffer_id];
|
SpaBuffer *buffer = NULL; //port->buffers[buffer_id];
|
||||||
|
|
||||||
for (i = 0; i < buffer->n_datas; i++) {
|
for (i = 0; i < buffer->n_datas; i++) {
|
||||||
SpaData *d = SPA_BUFFER_DATAS (buffer);
|
SpaData *d = SPA_BUFFER_DATAS (buffer);
|
||||||
|
|
@ -387,43 +368,7 @@ on_received_buffer (PinosPort *port,
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
static gboolean
|
|
||||||
on_received_event (PinosPort *port,
|
|
||||||
SpaEvent *event,
|
|
||||||
GError **error,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PinosPort *
|
|
||||||
add_port (PinosNode *node,
|
|
||||||
guint id,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
PinosSpaAlsaSink *sink = PINOS_SPA_ALSA_SINK (node);
|
|
||||||
PinosPort *port;
|
|
||||||
|
|
||||||
port = PINOS_NODE_CLASS (pinos_spa_alsa_sink_parent_class)
|
|
||||||
->add_port (node, id, error);
|
|
||||||
|
|
||||||
pinos_port_set_received_cb (port, on_received_buffer, on_received_event, sink, NULL);
|
|
||||||
|
|
||||||
g_debug ("connecting signals");
|
|
||||||
g_signal_connect (port, "activate", (GCallback) on_activate, sink);
|
|
||||||
g_signal_connect (port, "deactivate", (GCallback) on_deactivate, sink);
|
|
||||||
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
remove_port (PinosNode *node,
|
|
||||||
PinosPort *port)
|
|
||||||
{
|
|
||||||
return PINOS_NODE_CLASS (pinos_spa_alsa_sink_parent_class)
|
|
||||||
->remove_port (node, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sink_constructed (GObject * object)
|
sink_constructed (GObject * object)
|
||||||
|
|
@ -439,10 +384,8 @@ static void
|
||||||
sink_finalize (GObject * object)
|
sink_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
PinosSpaAlsaSink *sink = PINOS_SPA_ALSA_SINK (object);
|
PinosSpaAlsaSink *sink = PINOS_SPA_ALSA_SINK (object);
|
||||||
PinosSpaAlsaSinkPrivate *priv = sink->priv;
|
|
||||||
|
|
||||||
destroy_pipeline (sink);
|
destroy_pipeline (sink);
|
||||||
pinos_properties_free (priv->props);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (pinos_spa_alsa_sink_parent_class)->finalize (object);
|
G_OBJECT_CLASS (pinos_spa_alsa_sink_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
@ -461,15 +404,12 @@ pinos_spa_alsa_sink_class_init (PinosSpaAlsaSinkClass * klass)
|
||||||
gobject_class->set_property = set_property;
|
gobject_class->set_property = set_property;
|
||||||
|
|
||||||
node_class->set_state = set_state;
|
node_class->set_state = set_state;
|
||||||
node_class->add_port = add_port;
|
|
||||||
node_class->remove_port = remove_port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pinos_spa_alsa_sink_init (PinosSpaAlsaSink * sink)
|
pinos_spa_alsa_sink_init (PinosSpaAlsaSink * sink)
|
||||||
{
|
{
|
||||||
PinosSpaAlsaSinkPrivate *priv = sink->priv = PINOS_SPA_ALSA_SINK_GET_PRIVATE (sink);
|
sink->priv = PINOS_SPA_ALSA_SINK_GET_PRIVATE (sink);
|
||||||
priv->props = pinos_properties_new (NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PinosNode *
|
PinosNode *
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,7 @@
|
||||||
|
|
||||||
struct _PinosSpaV4l2SourcePrivate
|
struct _PinosSpaV4l2SourcePrivate
|
||||||
{
|
{
|
||||||
SpaPollFd fds[16];
|
gint dummy;
|
||||||
unsigned int n_fds;
|
|
||||||
SpaPollItem poll;
|
|
||||||
|
|
||||||
gboolean running;
|
|
||||||
pthread_t thread;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
@ -98,108 +93,6 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
||||||
return SPA_RESULT_ERROR;
|
return SPA_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
|
||||||
loop (void *user_data)
|
|
||||||
{
|
|
||||||
PinosSpaV4l2Source *this = user_data;
|
|
||||||
PinosSpaV4l2SourcePrivate *priv = this->priv;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
g_debug ("spa-v4l2-source %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 ("spa-v4l2-source %p: select timeout", 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 ("spa-v4l2-source %p: leave thread", this);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
on_source_event (SpaNode *node, SpaEvent *event, void *user_data)
|
|
||||||
{
|
|
||||||
PinosSpaV4l2Source *this = user_data;
|
|
||||||
PinosSpaV4l2SourcePrivate *priv = this->priv;
|
|
||||||
|
|
||||||
switch (event->type) {
|
|
||||||
case SPA_EVENT_TYPE_HAVE_OUTPUT:
|
|
||||||
{
|
|
||||||
SpaOutputInfo info[1] = { 0, };
|
|
||||||
SpaResult res;
|
|
||||||
GList *ports, *walk;
|
|
||||||
|
|
||||||
if ((res = spa_node_port_pull_output (node, 1, info)) < 0)
|
|
||||||
g_debug ("spa-v4l2-source %p: got pull error %d, %d", this, res, info[0].status);
|
|
||||||
|
|
||||||
ports = pinos_node_get_ports (PINOS_NODE (this));
|
|
||||||
for (walk = ports; walk; walk = g_list_next (walk)) {
|
|
||||||
PinosPort *port = walk->data;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
if (!pinos_port_send_buffer (port, info[0].buffer_id, &error)) {
|
|
||||||
g_debug ("send failed: %s", error->message);
|
|
||||||
g_clear_error (&error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_list_free (ports);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SPA_EVENT_TYPE_ADD_POLL:
|
|
||||||
{
|
|
||||||
SpaPollItem *poll = event->data;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
priv->poll = *poll;
|
|
||||||
priv->fds[0] = poll->fds[0];
|
|
||||||
priv->n_fds = 1;
|
|
||||||
priv->poll.fds = priv->fds;
|
|
||||||
|
|
||||||
if (!priv->running) {
|
|
||||||
priv->running = true;
|
|
||||||
if ((err = pthread_create (&priv->thread, NULL, loop, this)) != 0) {
|
|
||||||
g_debug ("spa-v4l2-source %p: can't create thread: %s", this, strerror (err));
|
|
||||||
priv->running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SPA_EVENT_TYPE_REMOVE_POLL:
|
|
||||||
{
|
|
||||||
if (priv->running) {
|
|
||||||
priv->running = false;
|
|
||||||
pthread_join (priv->thread, NULL);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SPA_EVENT_TYPE_STATE_CHANGE:
|
|
||||||
{
|
|
||||||
SpaEventStateChange *sc = event->data;
|
|
||||||
|
|
||||||
pinos_node_update_node_state (PINOS_NODE (this), sc->state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
g_debug ("got event %d", event->type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setup_node (PinosSpaV4l2Source *this)
|
setup_node (PinosSpaV4l2Source *this)
|
||||||
{
|
{
|
||||||
|
|
@ -208,8 +101,6 @@ setup_node (PinosSpaV4l2Source *this)
|
||||||
SpaProps *props;
|
SpaProps *props;
|
||||||
SpaPropValue value;
|
SpaPropValue value;
|
||||||
|
|
||||||
spa_node_set_event_callback (node->node, on_source_event, this);
|
|
||||||
|
|
||||||
if ((res = spa_node_get_props (node->node, &props)) < 0)
|
if ((res = spa_node_get_props (node->node, &props)) < 0)
|
||||||
g_debug ("got get_props error %d", res);
|
g_debug ("got get_props error %d", res);
|
||||||
|
|
||||||
|
|
@ -222,69 +113,12 @@ setup_node (PinosSpaV4l2Source *this)
|
||||||
g_debug ("got set_props error %d", res);
|
g_debug ("got set_props error %d", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
pause_pipeline (PinosSpaV4l2Source *this)
|
|
||||||
{
|
|
||||||
PinosNode *node = PINOS_NODE (this);
|
|
||||||
SpaResult res;
|
|
||||||
SpaCommand cmd;
|
|
||||||
|
|
||||||
g_debug ("spa-v4l2-source %p: pause pipeline", this);
|
|
||||||
|
|
||||||
cmd.type = SPA_COMMAND_PAUSE;
|
|
||||||
if ((res = spa_node_send_command (node->node, &cmd)) < 0)
|
|
||||||
g_debug ("got error %d", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
suspend_pipeline (PinosSpaV4l2Source *this)
|
|
||||||
{
|
|
||||||
PinosNode *node = PINOS_NODE (this);
|
|
||||||
SpaResult res;
|
|
||||||
|
|
||||||
g_debug ("spa-v4l2-source %p: suspend pipeline", this);
|
|
||||||
|
|
||||||
if ((res = spa_node_port_set_format (node->node, 0, 0, NULL)) < 0) {
|
|
||||||
g_warning ("error unset format output: %d", res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_pipeline (PinosSpaV4l2Source *this)
|
destroy_pipeline (PinosSpaV4l2Source *this)
|
||||||
{
|
{
|
||||||
g_debug ("spa-v4l2-source %p: destroy pipeline", this);
|
g_debug ("spa-v4l2-source %p: destroy pipeline", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
set_state (PinosNode *node,
|
|
||||||
PinosNodeState state)
|
|
||||||
{
|
|
||||||
PinosSpaV4l2Source *this = PINOS_SPA_V4L2_SOURCE (node);
|
|
||||||
|
|
||||||
g_debug ("spa-source %p: set state %s", node, pinos_node_state_as_string (state));
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case PINOS_NODE_STATE_SUSPENDED:
|
|
||||||
suspend_pipeline (this);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PINOS_NODE_STATE_INITIALIZING:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PINOS_NODE_STATE_IDLE:
|
|
||||||
pause_pipeline (this);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PINOS_NODE_STATE_RUNNING:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PINOS_NODE_STATE_ERROR:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pinos_node_update_state (node, state);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_property (GObject *object,
|
get_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
|
|
@ -311,32 +145,6 @@ set_property (GObject *object,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
on_activate (PinosPort *port, gpointer user_data)
|
|
||||||
{
|
|
||||||
PinosSpaV4l2Source *source = user_data;
|
|
||||||
|
|
||||||
pinos_node_report_busy (PINOS_NODE (source));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
on_deactivate (PinosPort *port, gpointer user_data)
|
|
||||||
{
|
|
||||||
PinosSpaV4l2Source *source = user_data;
|
|
||||||
|
|
||||||
pinos_node_report_idle (PINOS_NODE (source));
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
remove_port (PinosNode *node,
|
|
||||||
PinosPort *port)
|
|
||||||
{
|
|
||||||
return PINOS_NODE_CLASS (pinos_spa_v4l2_source_parent_class)
|
|
||||||
->remove_port (node, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
source_constructed (GObject * object)
|
source_constructed (GObject * object)
|
||||||
{
|
{
|
||||||
|
|
@ -362,63 +170,10 @@ source_finalize (GObject * object)
|
||||||
G_OBJECT_CLASS (pinos_spa_v4l2_source_parent_class)->finalize (object);
|
G_OBJECT_CLASS (pinos_spa_v4l2_source_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
on_received_buffer (PinosPort *port, uint32_t buffer_id, GError **error, gpointer user_data)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
on_received_event (PinosPort *port, SpaEvent *event, GError **error, gpointer user_data)
|
|
||||||
{
|
|
||||||
PinosNode *node = user_data;
|
|
||||||
SpaResult res;
|
|
||||||
|
|
||||||
switch (event->type) {
|
|
||||||
case SPA_EVENT_TYPE_REUSE_BUFFER:
|
|
||||||
{
|
|
||||||
SpaEventReuseBuffer *rb = event->data;
|
|
||||||
|
|
||||||
if ((res = spa_node_port_reuse_buffer (node->node,
|
|
||||||
rb->port_id,
|
|
||||||
rb->buffer_id)) < 0)
|
|
||||||
g_warning ("client-node %p: error reuse buffer: %d", node, res);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
if ((res = spa_node_port_push_event (node->node, port->id, event)) < 0)
|
|
||||||
g_warning ("client-node %p: error pushing event: %d", node, res);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static PinosPort *
|
|
||||||
add_port (PinosNode *node,
|
|
||||||
guint id,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
PinosSpaV4l2Source *source = PINOS_SPA_V4L2_SOURCE (node);
|
|
||||||
PinosPort *port;
|
|
||||||
|
|
||||||
port = PINOS_NODE_CLASS (pinos_spa_v4l2_source_parent_class)
|
|
||||||
->add_port (node, id, error);
|
|
||||||
|
|
||||||
pinos_port_set_received_cb (port, on_received_buffer, on_received_event, node, NULL);
|
|
||||||
|
|
||||||
g_debug ("connecting signals");
|
|
||||||
g_signal_connect (port, "activate", (GCallback) on_activate, source);
|
|
||||||
g_signal_connect (port, "deactivate", (GCallback) on_deactivate, source);
|
|
||||||
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pinos_spa_v4l2_source_class_init (PinosSpaV4l2SourceClass * klass)
|
pinos_spa_v4l2_source_class_init (PinosSpaV4l2SourceClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
PinosNodeClass *node_class = PINOS_NODE_CLASS (klass);
|
|
||||||
|
|
||||||
g_type_class_add_private (klass, sizeof (PinosSpaV4l2SourcePrivate));
|
g_type_class_add_private (klass, sizeof (PinosSpaV4l2SourcePrivate));
|
||||||
|
|
||||||
|
|
@ -426,10 +181,6 @@ pinos_spa_v4l2_source_class_init (PinosSpaV4l2SourceClass * klass)
|
||||||
gobject_class->finalize = source_finalize;
|
gobject_class->finalize = source_finalize;
|
||||||
gobject_class->get_property = get_property;
|
gobject_class->get_property = get_property;
|
||||||
gobject_class->set_property = set_property;
|
gobject_class->set_property = set_property;
|
||||||
|
|
||||||
node_class->set_state = set_state;
|
|
||||||
node_class->add_port = add_port;
|
|
||||||
node_class->remove_port = remove_port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -48,13 +48,6 @@ struct _PinosClientNodePrivate
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
GSocket *sockets[2];
|
GSocket *sockets[2];
|
||||||
|
|
||||||
SpaPollFd fds[16];
|
|
||||||
unsigned int n_fds;
|
|
||||||
SpaPollItem poll;
|
|
||||||
|
|
||||||
gboolean running;
|
|
||||||
pthread_t thread;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PINOS_CLIENT_NODE_GET_PRIVATE(obj) \
|
#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
|
static void
|
||||||
pinos_client_node_dispose (GObject * object)
|
pinos_client_node_dispose (GObject * object)
|
||||||
{
|
{
|
||||||
PinosClientNode *this = PINOS_CLIENT_NODE (object);
|
PinosClientNode *this = PINOS_CLIENT_NODE (object);
|
||||||
|
|
||||||
g_debug ("client-node %p: dispose", this);
|
g_debug ("client-node %p: dispose", this);
|
||||||
stop_thread (this);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (pinos_client_node_parent_class)->dispose (object);
|
G_OBJECT_CLASS (pinos_client_node_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
@ -446,25 +194,16 @@ static void
|
||||||
pinos_client_node_constructed (GObject * object)
|
pinos_client_node_constructed (GObject * object)
|
||||||
{
|
{
|
||||||
PinosClientNode *this = PINOS_CLIENT_NODE (object);
|
PinosClientNode *this = PINOS_CLIENT_NODE (object);
|
||||||
PinosClientNodePrivate *priv = this->priv;
|
|
||||||
|
|
||||||
g_debug ("client-node %p: constructed", this);
|
g_debug ("client-node %p: constructed", this);
|
||||||
|
|
||||||
G_OBJECT_CLASS (pinos_client_node_parent_class)->constructed (object);
|
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
|
static void
|
||||||
pinos_client_node_class_init (PinosClientNodeClass * klass)
|
pinos_client_node_class_init (PinosClientNodeClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
PinosNodeClass *node_class = PINOS_NODE_CLASS (klass);
|
|
||||||
|
|
||||||
g_type_class_add_private (klass, sizeof (PinosClientNodePrivate));
|
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->finalize = pinos_client_node_finalize;
|
||||||
gobject_class->set_property = pinos_client_node_set_property;
|
gobject_class->set_property = pinos_client_node_set_property;
|
||||||
gobject_class->get_property = pinos_client_node_get_property;
|
gobject_class->get_property = pinos_client_node_get_property;
|
||||||
|
|
||||||
node_class->add_port = add_port;
|
|
||||||
node_class->remove_port = remove_port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -184,11 +184,11 @@ no_node:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
PinosDaemon *this;
|
||||||
PinosProperties *props;
|
PinosProperties *props;
|
||||||
PinosPort *target;
|
PinosNode *target;
|
||||||
const gchar *path;
|
const gchar *path;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
PinosLink *link;
|
PinosLink *link;
|
||||||
|
|
@ -199,26 +199,31 @@ on_port_added (PinosNode *node, PinosPort *port, PinosClient *client)
|
||||||
path = pinos_properties_get (props, "pinos.target.node");
|
path = pinos_properties_get (props, "pinos.target.node");
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
target = pinos_daemon_find_port (this,
|
guint new_port;
|
||||||
pinos_direction_reverse (port->direction),
|
|
||||||
|
target = pinos_daemon_find_node (this,
|
||||||
|
pinos_direction_reverse (direction),
|
||||||
path,
|
path,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
&error);
|
&error);
|
||||||
if (target == NULL) {
|
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);
|
g_clear_error (&error);
|
||||||
return;
|
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));
|
pinos_client_add_object (client, G_OBJECT (link));
|
||||||
g_object_unref (link);
|
g_object_unref (link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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
|
* @daemon: a #PinosDaemon
|
||||||
* @name: a port name
|
* @name: a port name
|
||||||
* @props: port properties
|
* @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
|
* Returns: a #PinosPort or %NULL when no port could be found. unref the port
|
||||||
* after usage.
|
* after usage.
|
||||||
*/
|
*/
|
||||||
PinosPort *
|
PinosNode *
|
||||||
pinos_daemon_find_port (PinosDaemon *daemon,
|
pinos_daemon_find_node (PinosDaemon *daemon,
|
||||||
PinosDirection direction,
|
PinosDirection direction,
|
||||||
const gchar *name,
|
const gchar *name,
|
||||||
PinosProperties *props,
|
PinosProperties *props,
|
||||||
|
|
@ -533,9 +538,9 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
PinosDaemonPrivate *priv;
|
PinosDaemonPrivate *priv;
|
||||||
PinosPort *best = NULL;
|
PinosNode *best = NULL;
|
||||||
GList *nodes, *ports, *walk;
|
GList *nodes;
|
||||||
gboolean have_name, created_port = FALSE;
|
gboolean have_name;
|
||||||
|
|
||||||
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
||||||
priv = daemon->priv;
|
priv = daemon->priv;
|
||||||
|
|
@ -546,65 +551,25 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
||||||
|
|
||||||
for (nodes = priv->nodes; nodes; nodes = g_list_next (nodes)) {
|
for (nodes = priv->nodes; nodes; nodes = g_list_next (nodes)) {
|
||||||
PinosNode *n = nodes->data;
|
PinosNode *n = nodes->data;
|
||||||
gboolean node_found = FALSE;
|
|
||||||
|
|
||||||
g_debug ("node path \"%s\"", pinos_node_get_object_path (n));
|
g_debug ("node path \"%s\"", pinos_node_get_object_path (n));
|
||||||
|
|
||||||
/* we found the node */
|
if (!g_str_has_suffix (pinos_node_get_object_path (n), name))
|
||||||
if (have_name) {
|
continue;
|
||||||
if (!g_str_has_suffix (pinos_node_get_object_path (n), name))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
g_debug ("name \"%s\" matches node %p", name, n);
|
g_debug ("name \"%s\" matches node %p", name, n);
|
||||||
node_found = TRUE;
|
best = n;
|
||||||
}
|
break;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (best == NULL) {
|
if (best == NULL) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_NOT_FOUND,
|
G_IO_ERROR_NOT_FOUND,
|
||||||
"No matching Port found");
|
"No matching Node found");
|
||||||
} else if (!created_port)
|
} else
|
||||||
g_object_ref (best);
|
g_object_ref (best);
|
||||||
|
|
||||||
return PINOS_PORT (best);
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ typedef struct _PinosDaemonClass PinosDaemonClass;
|
||||||
typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
|
typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
|
||||||
|
|
||||||
#include <pinos/server/node.h>
|
#include <pinos/server/node.h>
|
||||||
#include <pinos/server/port.h>
|
|
||||||
#include <pinos/server/node-factory.h>
|
#include <pinos/server/node-factory.h>
|
||||||
#include <pinos/client/properties.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_add_node (PinosDaemon *daemon, PinosNode *node);
|
||||||
void pinos_daemon_remove_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,
|
PinosDirection direction,
|
||||||
const gchar *name,
|
const gchar *name,
|
||||||
PinosProperties *props,
|
PinosProperties *props,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@
|
||||||
#include "pinos/client/enumtypes.h"
|
#include "pinos/client/enumtypes.h"
|
||||||
|
|
||||||
#include "pinos/server/link.h"
|
#include "pinos/server/link.h"
|
||||||
#include "pinos/server/port.h"
|
|
||||||
|
|
||||||
#include "pinos/dbus/org-pinos.h"
|
#include "pinos/dbus/org-pinos.h"
|
||||||
|
|
||||||
|
|
@ -42,28 +41,18 @@ struct _PinosLinkPrivate
|
||||||
|
|
||||||
gchar *object_path;
|
gchar *object_path;
|
||||||
|
|
||||||
gulong input_id, output_id;
|
|
||||||
|
|
||||||
gboolean active;
|
gboolean active;
|
||||||
gboolean negotiated;
|
gboolean negotiated;
|
||||||
gboolean allocated;
|
gboolean allocated;
|
||||||
gboolean started;
|
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];
|
SpaBuffer *in_buffers[16];
|
||||||
unsigned int n_in_buffers;
|
unsigned int n_in_buffers;
|
||||||
SpaBuffer *out_buffers[16];
|
SpaBuffer *out_buffers[16];
|
||||||
unsigned int n_out_buffers;
|
unsigned int n_out_buffers;
|
||||||
|
|
||||||
|
GPtrArray *format_filter;
|
||||||
|
PinosProperties *properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (PinosLink, pinos_link, G_TYPE_OBJECT);
|
G_DEFINE_TYPE (PinosLink, pinos_link, G_TYPE_OBJECT);
|
||||||
|
|
@ -72,83 +61,69 @@ enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_DAEMON,
|
PROP_DAEMON,
|
||||||
PROP_OUTPUT,
|
|
||||||
PROP_INPUT,
|
|
||||||
PROP_OBJECT_PATH,
|
PROP_OBJECT_PATH,
|
||||||
|
PROP_OUTPUT_NODE,
|
||||||
|
PROP_OUTPUT_PORT,
|
||||||
|
PROP_INPUT_NODE,
|
||||||
|
PROP_INPUT_PORT,
|
||||||
|
PROP_FORMAT_FILTER,
|
||||||
|
PROP_PROPERTIES,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
SIGNAL_REMOVE,
|
SIGNAL_REMOVE,
|
||||||
|
SIGNAL_ACTIVATE,
|
||||||
|
SIGNAL_DEACTIVATE,
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
static guint signals[LAST_SIGNAL] = { 0 };
|
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
|
static void
|
||||||
pinos_link_get_property (GObject *_object,
|
pinos_link_get_property (GObject *_object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
PinosLink *link = PINOS_LINK (_object);
|
PinosLink *this = PINOS_LINK (_object);
|
||||||
PinosLinkPrivate *priv = link->priv;
|
PinosLinkPrivate *priv = this->priv;
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_DAEMON:
|
case PROP_DAEMON:
|
||||||
g_value_set_object (value, priv->daemon);
|
g_value_set_object (value, priv->daemon);
|
||||||
break;
|
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:
|
case PROP_OBJECT_PATH:
|
||||||
g_value_set_string (value, priv->object_path);
|
g_value_set_string (value, priv->object_path);
|
||||||
break;
|
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:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (link, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -159,40 +134,52 @@ pinos_link_set_property (GObject *_object,
|
||||||
const GValue *value,
|
const GValue *value,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
PinosLink *link = PINOS_LINK (_object);
|
PinosLink *this = PINOS_LINK (_object);
|
||||||
PinosLinkPrivate *priv = link->priv;
|
PinosLinkPrivate *priv = this->priv;
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_DAEMON:
|
case PROP_DAEMON:
|
||||||
priv->daemon = g_value_dup_object (value);
|
priv->daemon = g_value_dup_object (value);
|
||||||
break;
|
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:
|
case PROP_OBJECT_PATH:
|
||||||
priv->object_path = g_value_dup_string (value);
|
priv->object_path = g_value_dup_string (value);
|
||||||
break;
|
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:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (link, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
link_register_object (PinosLink *link)
|
link_register_object (PinosLink *this)
|
||||||
{
|
{
|
||||||
PinosLinkPrivate *priv = link->priv;
|
PinosLinkPrivate *priv = this->priv;
|
||||||
PinosObjectSkeleton *skel;
|
PinosObjectSkeleton *skel;
|
||||||
gchar *name;
|
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));
|
priv->object_path = pinos_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||||
g_object_unref (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
|
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);
|
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,8 +218,8 @@ do_negotiate (PinosLink *this)
|
||||||
priv->negotiated = TRUE;
|
priv->negotiated = TRUE;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
if ((res = spa_node_port_enum_formats (priv->input_node,
|
if ((res = spa_node_port_enum_formats (this->input_node->node,
|
||||||
priv->input_port,
|
this->input_port,
|
||||||
&filter,
|
&filter,
|
||||||
NULL,
|
NULL,
|
||||||
&istate)) < 0) {
|
&istate)) < 0) {
|
||||||
|
|
@ -241,8 +228,8 @@ again:
|
||||||
}
|
}
|
||||||
spa_debug_format (filter);
|
spa_debug_format (filter);
|
||||||
|
|
||||||
if ((res = spa_node_port_enum_formats (priv->output_node,
|
if ((res = spa_node_port_enum_formats (this->output_node->node,
|
||||||
priv->output_port,
|
this->output_port,
|
||||||
&format,
|
&format,
|
||||||
filter,
|
filter,
|
||||||
&ostate)) < 0) {
|
&ostate)) < 0) {
|
||||||
|
|
@ -257,12 +244,12 @@ again:
|
||||||
|
|
||||||
spa_debug_format (format);
|
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);
|
g_warning ("error set format output: %d", res);
|
||||||
goto error;
|
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);
|
g_warning ("error set format input: %d", res);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
@ -284,13 +271,13 @@ do_allocation (PinosLink *this)
|
||||||
const SpaPortInfo *iinfo, *oinfo;
|
const SpaPortInfo *iinfo, *oinfo;
|
||||||
SpaPortInfoFlags in_flags, out_flags;
|
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 */
|
/* 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);
|
g_warning ("error get port info: %d", res);
|
||||||
goto error;
|
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);
|
g_warning ("error get port info: %d", res);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
@ -335,42 +322,34 @@ do_allocation (PinosLink *this)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
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,
|
oinfo->params, oinfo->n_params,
|
||||||
priv->in_buffers, &priv->n_in_buffers)) < 0) {
|
priv->in_buffers, &priv->n_in_buffers)) < 0) {
|
||||||
g_warning ("error alloc buffers: %d", res);
|
g_warning ("error alloc buffers: %d", res);
|
||||||
goto error;
|
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 (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,
|
iinfo->params, iinfo->n_params,
|
||||||
priv->out_buffers, &priv->n_out_buffers)) < 0) {
|
priv->out_buffers, &priv->n_out_buffers)) < 0) {
|
||||||
g_warning ("error alloc buffers: %d", res);
|
g_warning ("error alloc buffers: %d", res);
|
||||||
goto error;
|
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 (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) {
|
priv->out_buffers, priv->n_out_buffers)) < 0) {
|
||||||
g_warning ("error use buffers: %d", res);
|
g_warning ("error use buffers: %d", res);
|
||||||
goto error;
|
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 (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) {
|
priv->in_buffers, priv->n_in_buffers)) < 0) {
|
||||||
g_warning ("error use buffers: %d", res);
|
g_warning ("error use buffers: %d", res);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
priv->output->n_buffers = priv->n_in_buffers;
|
|
||||||
priv->output->buffers = priv->in_buffers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SPA_RESULT_OK;
|
return SPA_RESULT_OK;
|
||||||
|
|
@ -389,12 +368,15 @@ do_start (PinosLink *this)
|
||||||
SpaCommand cmd;
|
SpaCommand cmd;
|
||||||
SpaResult res;
|
SpaResult res;
|
||||||
|
|
||||||
|
if (priv->started)
|
||||||
|
return SPA_RESULT_OK;
|
||||||
|
|
||||||
priv->started = TRUE;
|
priv->started = TRUE;
|
||||||
|
|
||||||
cmd.type = SPA_COMMAND_START;
|
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);
|
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);
|
g_warning ("got error %d", res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -407,12 +389,15 @@ do_pause (PinosLink *this)
|
||||||
SpaCommand cmd;
|
SpaCommand cmd;
|
||||||
SpaResult res;
|
SpaResult res;
|
||||||
|
|
||||||
|
if (!priv->started)
|
||||||
|
return SPA_RESULT_OK;
|
||||||
|
|
||||||
priv->started = FALSE;
|
priv->started = FALSE;
|
||||||
|
|
||||||
cmd.type = SPA_COMMAND_PAUSE;
|
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);
|
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);
|
g_warning ("got error %d", res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -423,23 +408,27 @@ check_states (PinosLink *this)
|
||||||
{
|
{
|
||||||
PinosLinkPrivate *priv = this->priv;
|
PinosLinkPrivate *priv = this->priv;
|
||||||
SpaResult res;
|
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 &&
|
g_debug ("link %p: input %d, output %d", this, in_state, out_state);
|
||||||
priv->output_state >= SPA_NODE_STATE_CONFIGURE &&
|
|
||||||
|
if (in_state == SPA_NODE_STATE_CONFIGURE &&
|
||||||
|
out_state == SPA_NODE_STATE_CONFIGURE &&
|
||||||
!priv->negotiated) {
|
!priv->negotiated) {
|
||||||
if ((res = do_negotiate (this)) < 0)
|
if ((res = do_negotiate (this)) < 0)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (priv->input_state >= SPA_NODE_STATE_READY &&
|
if (in_state == SPA_NODE_STATE_READY &&
|
||||||
priv->output_state >= SPA_NODE_STATE_READY &&
|
out_state == SPA_NODE_STATE_READY &&
|
||||||
!priv->allocated) {
|
!priv->allocated) {
|
||||||
if ((res = do_allocation (this)) < 0)
|
if ((res = do_allocation (this)) < 0)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (priv->input_state >= SPA_NODE_STATE_PAUSED &&
|
if (in_state == SPA_NODE_STATE_PAUSED &&
|
||||||
priv->output_state >= SPA_NODE_STATE_PAUSED &&
|
out_state == SPA_NODE_STATE_PAUSED &&
|
||||||
!priv->started) {
|
!priv->started) {
|
||||||
if ((res = do_start (this)) < 0)
|
if ((res = do_start (this)) < 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -453,57 +442,11 @@ on_node_state_notify (GObject *obj,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
PinosLink *this = user_data;
|
PinosLink *this = user_data;
|
||||||
PinosLinkPrivate *priv = this->priv;
|
|
||||||
|
|
||||||
g_debug ("link %p: node %p state change", this, obj);
|
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);
|
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
|
static void
|
||||||
on_property_notify (GObject *obj,
|
on_property_notify (GObject *obj,
|
||||||
GParamSpec *pspec,
|
GParamSpec *pspec,
|
||||||
|
|
@ -512,17 +455,17 @@ on_property_notify (GObject *obj,
|
||||||
PinosLink *this = user_data;
|
PinosLink *this = user_data;
|
||||||
PinosLinkPrivate *priv = this->priv;
|
PinosLinkPrivate *priv = this->priv;
|
||||||
|
|
||||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output") == 0) {
|
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output-node") == 0) {
|
||||||
gchar *port = g_strdup_printf ("%s:%d", pinos_node_get_object_path (priv->output->node),
|
pinos_link1_set_output_node (priv->iface, pinos_node_get_object_path (this->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), "input") == 0) {
|
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output-port") == 0) {
|
||||||
gchar *port = g_strdup_printf ("%s:%d", pinos_node_get_object_path (priv->input->node),
|
pinos_link1_set_output_port (priv->iface, this->output_port);
|
||||||
priv->input->id);
|
}
|
||||||
pinos_link1_set_dest_port (priv->iface, port);
|
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "input-node") == 0) {
|
||||||
g_free (port);
|
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)
|
pinos_link_constructed (GObject * object)
|
||||||
{
|
{
|
||||||
PinosLink *this = PINOS_LINK (object);
|
PinosLink *this = PINOS_LINK (object);
|
||||||
PinosLinkPrivate *priv = this->priv;
|
|
||||||
|
|
||||||
priv->output_id = pinos_port_add_send_cb (priv->output,
|
g_signal_connect (this->input_node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||||
on_output_buffer,
|
g_signal_connect (this->output_node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||||
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, "notify", (GCallback) on_property_notify, this);
|
g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
|
||||||
|
|
||||||
G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object);
|
G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object);
|
||||||
|
|
||||||
on_property_notify (G_OBJECT (this), NULL, this);
|
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);
|
link_register_object (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -571,23 +495,17 @@ pinos_link_dispose (GObject * object)
|
||||||
PinosLinkPrivate *priv = this->priv;
|
PinosLinkPrivate *priv = this->priv;
|
||||||
|
|
||||||
g_debug ("link %p: dispose", this);
|
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_clear_object (&this->input_node);
|
||||||
g_signal_handlers_disconnect_by_data (priv->output, this);
|
g_clear_object (&this->output_node);
|
||||||
g_signal_handlers_disconnect_by_data (priv->input->node, this);
|
|
||||||
g_signal_handlers_disconnect_by_data (priv->output->node, this);
|
|
||||||
|
|
||||||
pinos_port_remove_send_cb (priv->input, priv->input_id);
|
|
||||||
pinos_port_remove_send_cb (priv->output, priv->output_id);
|
|
||||||
if (priv->active) {
|
if (priv->active) {
|
||||||
priv->active = FALSE;
|
priv->active = FALSE;
|
||||||
pinos_port_deactivate (priv->input);
|
|
||||||
pinos_port_deactivate (priv->output);
|
|
||||||
}
|
}
|
||||||
priv->input = NULL;
|
|
||||||
priv->output = NULL;
|
|
||||||
link_unregister_object (this);
|
link_unregister_object (this);
|
||||||
|
|
||||||
G_OBJECT_CLASS (pinos_link_parent_class)->dispose (object);
|
G_OBJECT_CLASS (pinos_link_parent_class)->dispose (object);
|
||||||
|
|
@ -596,10 +514,10 @@ pinos_link_dispose (GObject * object)
|
||||||
static void
|
static void
|
||||||
pinos_link_finalize (GObject * object)
|
pinos_link_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
PinosLink *link = PINOS_LINK (object);
|
PinosLink *this = PINOS_LINK (object);
|
||||||
PinosLinkPrivate *priv = link->priv;
|
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->daemon);
|
||||||
g_clear_object (&priv->iface);
|
g_clear_object (&priv->iface);
|
||||||
g_free (priv->object_path);
|
g_free (priv->object_path);
|
||||||
|
|
@ -632,25 +550,69 @@ pinos_link_class_init (PinosLinkClass * klass)
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_OUTPUT,
|
PROP_OUTPUT_NODE,
|
||||||
g_param_spec_object ("output",
|
g_param_spec_object ("output-node",
|
||||||
"Output",
|
"Output Node",
|
||||||
"The output port",
|
"The output node",
|
||||||
PINOS_TYPE_PORT,
|
PINOS_TYPE_NODE,
|
||||||
G_PARAM_READWRITE |
|
G_PARAM_READWRITE |
|
||||||
G_PARAM_CONSTRUCT |
|
G_PARAM_CONSTRUCT |
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_INPUT,
|
PROP_OUTPUT_PORT,
|
||||||
g_param_spec_object ("input",
|
g_param_spec_uint ("output-port",
|
||||||
"Input",
|
"Output Port",
|
||||||
"The input port",
|
"The output port",
|
||||||
PINOS_TYPE_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_READWRITE |
|
||||||
G_PARAM_CONSTRUCT |
|
G_PARAM_CONSTRUCT |
|
||||||
G_PARAM_STATIC_STRINGS));
|
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",
|
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
||||||
G_TYPE_FROM_CLASS (klass),
|
G_TYPE_FROM_CLASS (klass),
|
||||||
G_SIGNAL_RUN_LAST,
|
G_SIGNAL_RUN_LAST,
|
||||||
|
|
@ -661,38 +623,35 @@ pinos_link_class_init (PinosLinkClass * klass)
|
||||||
G_TYPE_NONE,
|
G_TYPE_NONE,
|
||||||
0,
|
0,
|
||||||
G_TYPE_NONE);
|
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
|
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 ();
|
priv->iface = pinos_link1_skeleton_new ();
|
||||||
g_debug ("link %p: new", link);
|
g_debug ("link %p: new", this);
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -702,12 +661,10 @@ pinos_link_new (PinosDaemon *daemon,
|
||||||
* Trigger removal of @link
|
* Trigger removal of @link
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
pinos_link_remove (PinosLink *link)
|
pinos_link_remove (PinosLink *this)
|
||||||
{
|
{
|
||||||
g_return_if_fail (PINOS_IS_LINK (link));
|
g_debug ("link %p: remove", this);
|
||||||
|
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
|
||||||
g_debug ("link %p: remove", link);
|
|
||||||
g_signal_emit (link, signals[SIGNAL_REMOVE], 0, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -719,12 +676,32 @@ pinos_link_remove (PinosLink *link)
|
||||||
* Returns: the object path of @source.
|
* Returns: the object path of @source.
|
||||||
*/
|
*/
|
||||||
const gchar *
|
const gchar *
|
||||||
pinos_link_get_object_path (PinosLink *link)
|
pinos_link_get_object_path (PinosLink *this)
|
||||||
{
|
{
|
||||||
PinosLinkPrivate *priv;
|
PinosLinkPrivate *priv;
|
||||||
|
|
||||||
g_return_val_if_fail (PINOS_IS_LINK (link), NULL);
|
g_return_val_if_fail (PINOS_IS_LINK (this), NULL);
|
||||||
priv = link->priv;
|
priv = this->priv;
|
||||||
|
|
||||||
return priv->object_path;
|
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 {
|
struct _PinosLink {
|
||||||
GObject object;
|
GObject object;
|
||||||
|
|
||||||
|
PinosNode *output_node;
|
||||||
|
guint output_port;
|
||||||
|
PinosNode *input_node;
|
||||||
|
guint input_port;
|
||||||
|
|
||||||
PinosLinkPrivate *priv;
|
PinosLinkPrivate *priv;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -62,12 +67,11 @@ struct _PinosLinkClass {
|
||||||
/* normal GObject stuff */
|
/* normal GObject stuff */
|
||||||
GType pinos_link_get_type (void);
|
GType pinos_link_get_type (void);
|
||||||
|
|
||||||
PinosLink * pinos_link_new (PinosDaemon *daemon,
|
|
||||||
PinosPort *output,
|
|
||||||
PinosPort *input);
|
|
||||||
|
|
||||||
void pinos_link_remove (PinosLink *link);
|
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);
|
PinosProperties * pinos_link_get_properties (PinosLink *link);
|
||||||
|
|
||||||
const gchar * pinos_link_get_object_path (PinosLink *link);
|
const gchar * pinos_link_get_object_path (PinosLink *link);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/eventfd.h>
|
||||||
|
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <gio/gunixfdlist.h>
|
#include <gio/gunixfdlist.h>
|
||||||
|
|
@ -56,7 +59,14 @@ struct _PinosNodePrivate
|
||||||
|
|
||||||
PinosProperties *properties;
|
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);
|
G_DEFINE_ABSTRACT_TYPE (PinosNode, pinos_node, G_TYPE_OBJECT);
|
||||||
|
|
@ -84,24 +94,21 @@ enum
|
||||||
|
|
||||||
static guint signals[LAST_SIGNAL] = { 0 };
|
static guint signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
static gboolean
|
static PinosDirection
|
||||||
node_set_state (PinosNode *node,
|
get_port_direction (PinosNode *node, guint id)
|
||||||
PinosNodeState state)
|
|
||||||
{
|
{
|
||||||
return FALSE;
|
PinosNodePrivate *priv = node->priv;
|
||||||
}
|
PinosDirection direction;
|
||||||
|
|
||||||
static void
|
direction = id < priv->max_input_ports ? PINOS_DIRECTION_INPUT : PINOS_DIRECTION_OUTPUT;
|
||||||
do_remove_port (PinosPort *port, PinosNode *node)
|
|
||||||
{
|
return direction;
|
||||||
pinos_node_remove_port (node, port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_port_ids (PinosNode *node, gboolean create)
|
update_port_ids (PinosNode *node, gboolean create)
|
||||||
{
|
{
|
||||||
PinosNodePrivate *priv = node->priv;
|
PinosNodePrivate *priv = node->priv;
|
||||||
guint i;
|
|
||||||
|
|
||||||
if (node->node == NULL)
|
if (node->node == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
@ -120,147 +127,251 @@ update_port_ids (PinosNode *node, gboolean create)
|
||||||
priv->input_port_ids,
|
priv->input_port_ids,
|
||||||
priv->max_output_ports,
|
priv->max_output_ports,
|
||||||
priv->output_port_ids);
|
priv->output_port_ids);
|
||||||
|
}
|
||||||
|
|
||||||
if (create) {
|
static void *
|
||||||
for (i = 0; i < priv->n_input_ports; i++)
|
loop (void *user_data)
|
||||||
pinos_node_add_port (node, priv->input_port_ids[i], NULL);
|
{
|
||||||
for (i = 0; i < priv->n_output_ports; i++)
|
PinosNode *this = user_data;
|
||||||
pinos_node_add_port (node, priv->output_port_ids[i], NULL);
|
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 *
|
static void
|
||||||
node_add_port (PinosNode *node,
|
stop_thread (PinosNode *this)
|
||||||
guint id,
|
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
PinosNodePrivate *priv = node->priv;
|
PinosNodePrivate *priv = this->priv;
|
||||||
PinosPort *port;
|
|
||||||
PinosDirection direction;
|
|
||||||
|
|
||||||
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,
|
priv->running = false;
|
||||||
"daemon", priv->daemon,
|
pthread_join (priv->thread, NULL);
|
||||||
"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);
|
|
||||||
}
|
}
|
||||||
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
|
static gboolean
|
||||||
node_remove_port (PinosNode *node,
|
node_set_state (PinosNode *this,
|
||||||
PinosPort *port)
|
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);
|
switch (state) {
|
||||||
g_object_ref (port);
|
case PINOS_NODE_STATE_SUSPENDED:
|
||||||
if (g_hash_table_remove (priv->ports, GUINT_TO_POINTER (port->id)))
|
suspend_node (this);
|
||||||
g_signal_emit (node, signals[SIGNAL_PORT_REMOVED], 0, port);
|
break;
|
||||||
g_object_unref (port);
|
|
||||||
|
|
||||||
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
handle_add_port (PinosNode1 *interface,
|
static void
|
||||||
GDBusMethodInvocation *invocation,
|
on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
||||||
PinosDirection arg_direction,
|
|
||||||
guint arg_id,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
PinosNode *node = user_data;
|
PinosNode *this = user_data;
|
||||||
PinosNodePrivate *priv = node->priv;
|
PinosNodePrivate *priv = this->priv;
|
||||||
const gchar *sender;
|
|
||||||
PinosPort *port;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
switch (event->type) {
|
||||||
if (g_strcmp0 (priv->sender, sender) != 0)
|
case SPA_EVENT_TYPE_PORT_ADDED:
|
||||||
goto not_allowed;
|
{
|
||||||
|
SpaEventPortAdded *pa = event->data;
|
||||||
|
|
||||||
port = pinos_node_add_port (node, arg_id, &error);
|
update_port_ids (this, FALSE);
|
||||||
if (port == NULL)
|
|
||||||
goto no_port;
|
|
||||||
|
|
||||||
g_debug ("node %p: add port %p", node, port);
|
g_signal_emit (this, signals[SIGNAL_PORT_ADDED], 0, get_port_direction (this, pa->port_id),
|
||||||
g_dbus_method_invocation_return_value (invocation,
|
pa->port_id);
|
||||||
g_variant_new ("()"));
|
break;
|
||||||
|
}
|
||||||
|
case SPA_EVENT_TYPE_PORT_REMOVED:
|
||||||
|
{
|
||||||
|
SpaEventPortRemoved *pr = event->data;
|
||||||
|
|
||||||
return TRUE;
|
update_port_ids (this, FALSE);
|
||||||
|
|
||||||
/* ERRORS */
|
g_signal_emit (this, signals[SIGNAL_PORT_REMOVED], 0, pr->port_id);
|
||||||
not_allowed:
|
break;
|
||||||
{
|
}
|
||||||
g_debug ("sender %s is not owner of node with sender %s", sender, priv->sender);
|
case SPA_EVENT_TYPE_STATE_CHANGE:
|
||||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
{
|
||||||
"org.pinos.Error", "not node owner");
|
SpaEventStateChange *sc = event->data;
|
||||||
return TRUE;
|
|
||||||
}
|
pinos_node_update_node_state (PINOS_NODE (this), sc->state);
|
||||||
no_port:
|
|
||||||
{
|
switch (sc->state) {
|
||||||
g_debug ("node %p: could create port", node);
|
case SPA_NODE_STATE_CONFIGURE:
|
||||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
{
|
||||||
"org.pinos.Error", "can't create port");
|
GList *links, *walk;
|
||||||
return TRUE;
|
|
||||||
|
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
|
static gboolean
|
||||||
handle_remove (PinosNode1 *interface,
|
handle_remove (PinosNode1 *interface,
|
||||||
GDBusMethodInvocation *invocation,
|
GDBusMethodInvocation *invocation,
|
||||||
|
|
@ -417,22 +528,31 @@ on_property_notify (GObject *obj,
|
||||||
static void
|
static void
|
||||||
pinos_node_constructed (GObject * obj)
|
pinos_node_constructed (GObject * obj)
|
||||||
{
|
{
|
||||||
PinosNode *node = PINOS_NODE (obj);
|
PinosNode *this = PINOS_NODE (obj);
|
||||||
PinosNodePrivate *priv = node->priv;
|
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);
|
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) {
|
if (priv->sender == NULL) {
|
||||||
priv->sender = g_strdup (pinos_daemon_get_sender (priv->daemon));
|
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
|
static void
|
||||||
|
|
@ -441,12 +561,13 @@ pinos_node_dispose (GObject * obj)
|
||||||
PinosNode *node = PINOS_NODE (obj);
|
PinosNode *node = PINOS_NODE (obj);
|
||||||
PinosNodePrivate *priv = node->priv;
|
PinosNodePrivate *priv = node->priv;
|
||||||
|
|
||||||
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
|
||||||
|
|
||||||
g_debug ("node %p: dispose", node);
|
g_debug ("node %p: dispose", node);
|
||||||
|
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
||||||
|
stop_thread (node);
|
||||||
|
|
||||||
node_unregister_object (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);
|
G_OBJECT_CLASS (pinos_node_parent_class)->dispose (obj);
|
||||||
}
|
}
|
||||||
|
|
@ -582,8 +703,9 @@ pinos_node_class_init (PinosNodeClass * klass)
|
||||||
NULL,
|
NULL,
|
||||||
g_cclosure_marshal_generic,
|
g_cclosure_marshal_generic,
|
||||||
G_TYPE_NONE,
|
G_TYPE_NONE,
|
||||||
1,
|
2,
|
||||||
PINOS_TYPE_PORT);
|
PINOS_TYPE_DIRECTION,
|
||||||
|
G_TYPE_UINT);
|
||||||
signals[SIGNAL_PORT_REMOVED] = g_signal_new ("port-removed",
|
signals[SIGNAL_PORT_REMOVED] = g_signal_new ("port-removed",
|
||||||
G_TYPE_FROM_CLASS (klass),
|
G_TYPE_FROM_CLASS (klass),
|
||||||
G_SIGNAL_RUN_LAST,
|
G_SIGNAL_RUN_LAST,
|
||||||
|
|
@ -593,11 +715,9 @@ pinos_node_class_init (PinosNodeClass * klass)
|
||||||
g_cclosure_marshal_generic,
|
g_cclosure_marshal_generic,
|
||||||
G_TYPE_NONE,
|
G_TYPE_NONE,
|
||||||
1,
|
1,
|
||||||
PINOS_TYPE_PORT);
|
G_TYPE_UINT);
|
||||||
|
|
||||||
node_class->set_state = node_set_state;
|
node_class->set_state = node_set_state;
|
||||||
node_class->add_port = node_add_port;
|
|
||||||
node_class->remove_port = node_remove_port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -607,22 +727,13 @@ pinos_node_init (PinosNode * node)
|
||||||
|
|
||||||
g_debug ("node %p: new", node);
|
g_debug ("node %p: new", node);
|
||||||
priv->iface = pinos_node1_skeleton_new ();
|
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",
|
g_signal_connect (priv->iface, "handle-remove",
|
||||||
(GCallback) handle_remove,
|
(GCallback) handle_remove,
|
||||||
node);
|
node);
|
||||||
priv->state = PINOS_NODE_STATE_SUSPENDED;
|
priv->state = PINOS_NODE_STATE_SUSPENDED;
|
||||||
pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_SUSPENDED);
|
pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_SUSPENDED);
|
||||||
|
|
||||||
priv->ports = g_hash_table_new_full (g_direct_hash,
|
priv->links = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
g_direct_equal,
|
|
||||||
NULL,
|
|
||||||
(GDestroyNotify) g_object_unref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -783,65 +894,6 @@ pinos_node_remove (PinosNode *node)
|
||||||
g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL);
|
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:
|
* pinos_node_get_free_port_id:
|
||||||
* @node: a #PinosNode
|
* @node: a #PinosNode
|
||||||
|
|
@ -872,11 +924,15 @@ pinos_node_get_free_port_id (PinosNode *node,
|
||||||
ports = priv->output_port_ids;
|
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++) {
|
for (i = 0; i < n_ports; i++) {
|
||||||
if (free_port < ports[i])
|
if (free_port < ports[i])
|
||||||
break;
|
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;
|
free_port = ports[i] + 1;
|
||||||
}
|
}
|
||||||
if (free_port >= max_ports)
|
if (free_port >= max_ports)
|
||||||
|
|
@ -885,43 +941,110 @@ pinos_node_get_free_port_id (PinosNode *node,
|
||||||
return free_port;
|
return free_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static void
|
||||||
* pinos_node_find_port_by_id:
|
do_remove_link (PinosLink *link, PinosNode *node)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
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);
|
g_hash_table_remove (link->input_node->priv->links, GUINT_TO_POINTER (link->input_port));
|
||||||
priv = node->priv;
|
if (g_hash_table_size (link->input_node->priv->links) == 0)
|
||||||
|
pinos_node_report_idle (link->input_node);
|
||||||
return g_hash_table_lookup (priv->ports, GUINT_TO_POINTER (id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @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 *
|
GList *
|
||||||
pinos_node_get_ports (PinosNode *node)
|
pinos_node_get_links (PinosNode *node)
|
||||||
{
|
{
|
||||||
PinosNodePrivate *priv;
|
PinosNodePrivate *priv;
|
||||||
|
|
||||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||||
priv = node->priv;
|
priv = node->priv;
|
||||||
|
|
||||||
return g_hash_table_get_values (priv->ports);
|
return g_hash_table_get_values (priv->links);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ typedef struct _PinosNodePrivate PinosNodePrivate;
|
||||||
|
|
||||||
#include <pinos/client/introspect.h>
|
#include <pinos/client/introspect.h>
|
||||||
#include <pinos/server/daemon.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_TYPE_NODE (pinos_node_get_type ())
|
||||||
#define PINOS_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE))
|
#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,
|
gboolean (*set_state) (PinosNode *node,
|
||||||
PinosNodeState state);
|
PinosNodeState state);
|
||||||
|
|
||||||
PinosPort * (*add_port) (PinosNode *node,
|
|
||||||
guint id,
|
|
||||||
GError **error);
|
|
||||||
gboolean (*remove_port) (PinosNode *node,
|
|
||||||
PinosPort *port);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* normal GObject stuff */
|
/* 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,
|
guint pinos_node_get_free_port_id (PinosNode *node,
|
||||||
PinosDirection direction);
|
PinosDirection direction);
|
||||||
PinosPort * pinos_node_add_port (PinosNode *node,
|
|
||||||
guint id,
|
PinosLink * pinos_node_link (PinosNode *output_node,
|
||||||
GError **error);
|
guint output_port,
|
||||||
gboolean pinos_node_remove_port (PinosNode *node,
|
PinosNode *input_node,
|
||||||
PinosPort *port);
|
guint input_port,
|
||||||
PinosPort * pinos_node_find_port_by_id (PinosNode *node,
|
GPtrArray *format_filter,
|
||||||
guint id);
|
PinosProperties *properties);
|
||||||
GList * pinos_node_get_ports (PinosNode *node);
|
GList * pinos_node_get_links (PinosNode *node);
|
||||||
|
|
||||||
|
|
||||||
PinosNodeState pinos_node_get_state (PinosNode *node);
|
PinosNodeState pinos_node_get_state (PinosNode *node);
|
||||||
gboolean pinos_node_set_state (PinosNode *node, PinosNodeState state);
|
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__ */
|
|
||||||
|
|
@ -107,8 +107,10 @@ dump_link_info (PinosContext *c, const PinosLinkInfo *info, gpointer user_data)
|
||||||
g_print ("\tid: %p\n", info->id);
|
g_print ("\tid: %p\n", info->id);
|
||||||
g_print ("\tlink-path: \"%s\"\n", info->link_path);
|
g_print ("\tlink-path: \"%s\"\n", info->link_path);
|
||||||
if (data->print_all) {
|
if (data->print_all) {
|
||||||
g_print ("%c\tsource-port-path: \"%s\"\n", MARK_CHANGE (0), info->source_port_path);
|
g_print ("%c\toutput-node-path: \"%s\"\n", MARK_CHANGE (0), info->output_node_path);
|
||||||
g_print ("%c\tdestination-port-path: \"%s\"\n", MARK_CHANGE (1), info->destination_port_path);
|
g_print ("%c\toutput-port: %u\n", MARK_CHANGE (1), info->output_port);
|
||||||
|
g_print ("%c\tinput-node-path: \"%s\"\n", MARK_CHANGE (2), info->input_node_path);
|
||||||
|
g_print ("%c\tinput-port: %u\n", MARK_CHANGE (3), info->input_port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -958,6 +958,10 @@ write_format (void *p, const SpaFormat *format)
|
||||||
tf = p;
|
tf = p;
|
||||||
tf->media_type = format->media_type;
|
tf->media_type = format->media_type;
|
||||||
tf->media_subtype = format->media_subtype;
|
tf->media_subtype = format->media_subtype;
|
||||||
|
tf->mem.mem.pool_id = SPA_ID_INVALID;
|
||||||
|
tf->mem.mem.id = SPA_ID_INVALID;
|
||||||
|
tf->mem.offset = 0;
|
||||||
|
tf->mem.size = 0;
|
||||||
|
|
||||||
p = SPA_MEMBER (tf, offsetof (SpaFormat, props), void);
|
p = SPA_MEMBER (tf, offsetof (SpaFormat, props), void);
|
||||||
return write_props (p, &format->props, sizeof (SpaFormat));
|
return write_props (p, &format->props, sizeof (SpaFormat));
|
||||||
|
|
@ -971,6 +975,9 @@ write_port_info (void *p, const SpaPortInfo *info)
|
||||||
int i;
|
int i;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
if (info == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
tp = p;
|
tp = p;
|
||||||
memcpy (tp, info, sizeof (SpaPortInfo));
|
memcpy (tp, info, sizeof (SpaPortInfo));
|
||||||
|
|
||||||
|
|
@ -1086,8 +1093,11 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
|
||||||
sf = p;
|
sf = p;
|
||||||
|
|
||||||
p = SPA_MEMBER (sf, sizeof (SpaControlCmdSetFormat), void);
|
p = SPA_MEMBER (sf, sizeof (SpaControlCmdSetFormat), void);
|
||||||
len = write_format (p, sf->format);
|
if (sf->format) {
|
||||||
sf->format = SPA_INT_TO_PTR (SPA_PTRDIFF (p, sf));
|
len = write_format (p, sf->format);
|
||||||
|
sf->format = SPA_INT_TO_PTR (SPA_PTRDIFF (p, sf));
|
||||||
|
} else
|
||||||
|
sf->format = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,8 @@ spa_debug_dump_mem (const void *mem, size_t size)
|
||||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
|
if (i % 16 == 0)
|
||||||
|
printf ("%p: ", &t[i]);
|
||||||
printf ("%02x ", t[i]);
|
printf ("%02x ", t[i]);
|
||||||
if (i % 16 == 15 || i == size - 1)
|
if (i % 16 == 15 || i == size - 1)
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ do_update_port (SpaProxy *this,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!port->valid) {
|
if (!port->valid) {
|
||||||
fprintf (stderr, "%p: adding port %d\n", this, pu->port_id);
|
fprintf (stderr, "proxy %p: adding port %d\n", this, pu->port_id);
|
||||||
port->format = NULL;
|
port->format = NULL;
|
||||||
port->valid = true;
|
port->valid = true;
|
||||||
|
|
||||||
|
|
@ -381,7 +381,7 @@ do_uninit_port (SpaProxy *this,
|
||||||
SpaProxyPort *port;
|
SpaProxyPort *port;
|
||||||
SpaEventPortRemoved pr;
|
SpaEventPortRemoved pr;
|
||||||
|
|
||||||
fprintf (stderr, "%p: removing port %d\n", this, port_id);
|
fprintf (stderr, "proxy %p: removing port %d\n", this, port_id);
|
||||||
port = &this->ports[port_id];
|
port = &this->ports[port_id];
|
||||||
|
|
||||||
if (port_id < MAX_INPUTS)
|
if (port_id < MAX_INPUTS)
|
||||||
|
|
@ -784,6 +784,7 @@ spa_proxy_node_port_push_input (SpaNode *node,
|
||||||
|
|
||||||
for (i = 0; i < n_info; i++) {
|
for (i = 0; i < n_info; i++) {
|
||||||
if (!CHECK_PORT_ID_IN (this, info[i].port_id)) {
|
if (!CHECK_PORT_ID_IN (this, info[i].port_id)) {
|
||||||
|
printf ("invalid port %d\n", info[i].port_id);
|
||||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||||
have_error = true;
|
have_error = true;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ struct _V4l2Format {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool export_buf;
|
bool export_buf;
|
||||||
bool have_buffers;
|
bool have_buffers;
|
||||||
|
bool started;
|
||||||
|
|
||||||
bool next_fmtdesc;
|
bool next_fmtdesc;
|
||||||
struct v4l2_fmtdesc fmtdesc;
|
struct v4l2_fmtdesc fmtdesc;
|
||||||
|
|
@ -381,8 +382,6 @@ spa_v4l2_source_node_port_enum_formats (SpaNode *node,
|
||||||
|
|
||||||
this = (SpaV4l2Source *) node->handle;
|
this = (SpaV4l2Source *) node->handle;
|
||||||
|
|
||||||
fprintf (stderr, "%d\n", port_id);
|
|
||||||
|
|
||||||
if (port_id != 0)
|
if (port_id != 0)
|
||||||
return SPA_RESULT_INVALID_PORT;
|
return SPA_RESULT_INVALID_PORT;
|
||||||
|
|
||||||
|
|
@ -414,6 +413,7 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
|
||||||
state = &this->state[port_id];
|
state = &this->state[port_id];
|
||||||
|
|
||||||
if (format == NULL) {
|
if (format == NULL) {
|
||||||
|
spa_v4l2_pause (this);
|
||||||
spa_v4l2_clear_buffers (this);
|
spa_v4l2_clear_buffers (this);
|
||||||
spa_v4l2_close (this);
|
spa_v4l2_close (this);
|
||||||
state->current_format = NULL;
|
state->current_format = NULL;
|
||||||
|
|
|
||||||
|
|
@ -402,6 +402,7 @@ again:
|
||||||
fmt->fmt.props.prop_info = fmt->infos;
|
fmt->fmt.props.prop_info = fmt->infos;
|
||||||
fmt->fmt.props.n_prop_info = pi = 0;
|
fmt->fmt.props.n_prop_info = pi = 0;
|
||||||
fmt->fmt.props.unset_mask = 0;
|
fmt->fmt.props.unset_mask = 0;
|
||||||
|
fmt->fmt.mem.mem.pool_id = SPA_ID_INVALID;
|
||||||
|
|
||||||
if (info->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
|
if (info->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
|
||||||
spa_prop_info_fill_video (&fmt->infos[pi],
|
spa_prop_info_fill_video (&fmt->infos[pi],
|
||||||
|
|
@ -850,6 +851,9 @@ spa_v4l2_start (SpaV4l2Source *this)
|
||||||
enum v4l2_buf_type type;
|
enum v4l2_buf_type type;
|
||||||
SpaEvent event;
|
SpaEvent event;
|
||||||
|
|
||||||
|
if (state->started)
|
||||||
|
return SPA_RESULT_OK;
|
||||||
|
|
||||||
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||||
if (xioctl (state->fd, VIDIOC_STREAMON, &type) < 0) {
|
if (xioctl (state->fd, VIDIOC_STREAMON, &type) < 0) {
|
||||||
perror ("VIDIOC_STREAMON");
|
perror ("VIDIOC_STREAMON");
|
||||||
|
|
@ -873,6 +877,8 @@ spa_v4l2_start (SpaV4l2Source *this)
|
||||||
state->poll.user_data = this;
|
state->poll.user_data = this;
|
||||||
this->event_cb (&this->node, &event, this->user_data);
|
this->event_cb (&this->node, &event, this->user_data);
|
||||||
|
|
||||||
|
state->started = true;
|
||||||
|
|
||||||
return SPA_RESULT_OK;
|
return SPA_RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -883,11 +889,16 @@ spa_v4l2_pause (SpaV4l2Source *this)
|
||||||
enum v4l2_buf_type type;
|
enum v4l2_buf_type type;
|
||||||
SpaEvent event;
|
SpaEvent event;
|
||||||
|
|
||||||
|
if (!state->started)
|
||||||
|
return SPA_RESULT_OK;
|
||||||
|
|
||||||
event.type = SPA_EVENT_TYPE_REMOVE_POLL;
|
event.type = SPA_EVENT_TYPE_REMOVE_POLL;
|
||||||
event.data = &state->poll;
|
event.data = &state->poll;
|
||||||
event.size = sizeof (state->poll);
|
event.size = sizeof (state->poll);
|
||||||
this->event_cb (&this->node, &event, this->user_data);
|
this->event_cb (&this->node, &event, this->user_data);
|
||||||
|
|
||||||
|
state->started = false;
|
||||||
|
|
||||||
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||||
if (xioctl (state->fd, VIDIOC_STREAMOFF, &type) < 0) {
|
if (xioctl (state->fd, VIDIOC_STREAMOFF, &type) < 0) {
|
||||||
perror ("VIDIOC_STREAMOFF");
|
perror ("VIDIOC_STREAMOFF");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue