2017-05-18 17:16:48 +02:00
|
|
|
/* Simple Plugin API
|
|
|
|
|
* Copyright (C) 2017 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 __SPA_GRAPH_H__
|
|
|
|
|
#define __SPA_GRAPH_H__
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/utils/defs.h>
|
|
|
|
|
#include <spa/utils/list.h>
|
|
|
|
|
#include <spa/node/node.h>
|
2017-11-21 19:34:37 +01:00
|
|
|
#include <spa/node/io.h>
|
2017-06-30 19:32:11 +02:00
|
|
|
|
2017-09-15 17:26:01 +02:00
|
|
|
#ifndef spa_debug
|
|
|
|
|
#define spa_debug(...)
|
2017-06-30 19:32:11 +02:00
|
|
|
#endif
|
2017-05-18 17:16:48 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_graph;
|
|
|
|
|
struct spa_graph_node;
|
|
|
|
|
struct spa_graph_port;
|
2017-05-18 17:16:48 +02:00
|
|
|
|
2017-08-20 18:33:07 +02:00
|
|
|
struct spa_graph_callbacks {
|
|
|
|
|
#define SPA_VERSION_GRAPH_CALLBACKS 0
|
|
|
|
|
uint32_t version;
|
|
|
|
|
|
|
|
|
|
int (*need_input) (void *data, struct spa_graph_node *node);
|
|
|
|
|
int (*have_output) (void *data, struct spa_graph_node *node);
|
2018-03-16 07:50:22 +01:00
|
|
|
int (*run) (void *data);
|
2017-08-20 18:33:07 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_graph {
|
2018-03-16 12:46:18 +01:00
|
|
|
struct spa_list link; /* link for subgraph */
|
2018-03-16 16:55:25 +01:00
|
|
|
#define SPA_GRAPH_FLAG_DRIVER (1 << 0)
|
|
|
|
|
uint32_t flags; /* flags */
|
2018-03-16 12:46:18 +01:00
|
|
|
struct spa_graph *parent; /* parent graph or NULL when driver */
|
|
|
|
|
struct spa_list nodes; /* list of nodes of this graph */
|
|
|
|
|
struct spa_list subgraphs; /* list of subgraphs */
|
2017-08-20 18:33:07 +02:00
|
|
|
const struct spa_graph_callbacks *callbacks;
|
|
|
|
|
void *callbacks_data;
|
2017-05-18 17:16:48 +02:00
|
|
|
};
|
|
|
|
|
|
2017-08-20 18:33:07 +02:00
|
|
|
#define spa_graph_need_input(g,n) ((g)->callbacks->need_input((g)->callbacks_data, (n)))
|
|
|
|
|
#define spa_graph_have_output(g,n) ((g)->callbacks->have_output((g)->callbacks_data, (n)))
|
2018-03-16 07:50:22 +01:00
|
|
|
#define spa_graph_run(g) ((g)->callbacks->run((g)->callbacks_data))
|
2017-05-18 17:16:48 +02:00
|
|
|
|
2018-03-14 11:52:13 +01:00
|
|
|
struct spa_graph_state {
|
|
|
|
|
int status; /**< status of the node */
|
|
|
|
|
uint32_t required; /**< required number of input nodes */
|
|
|
|
|
uint32_t pending; /**< number of input nodes pending */
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-16 07:50:22 +01:00
|
|
|
struct spa_graph_node_callbacks {
|
|
|
|
|
#define SPA_VERSION_GRAPH_NODE_CALLBACKS 0
|
|
|
|
|
uint32_t version;
|
|
|
|
|
|
|
|
|
|
int (*process) (void *data, struct spa_graph_node *node);
|
|
|
|
|
int (*reuse_buffer) (void *data, struct spa_graph_node *node,
|
|
|
|
|
uint32_t port_id, uint32_t buffer_id);
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_graph_node {
|
2017-08-18 18:54:45 +02:00
|
|
|
struct spa_list link; /**< link in graph nodes list */
|
2017-08-20 18:33:07 +02:00
|
|
|
struct spa_graph *graph; /**< owner graph */
|
2017-08-18 18:54:45 +02:00
|
|
|
struct spa_list ports[2]; /**< list of input and output ports */
|
2018-01-18 15:39:03 +01:00
|
|
|
#define SPA_GRAPH_NODE_FLAG_ASYNC (1 << 0)
|
2017-08-18 18:54:45 +02:00
|
|
|
uint32_t flags; /**< node flags */
|
2018-03-14 11:52:13 +01:00
|
|
|
struct spa_graph_state *state; /**< state of the node */
|
2018-03-16 07:50:22 +01:00
|
|
|
const struct spa_graph_node_callbacks *callbacks;
|
|
|
|
|
void *callbacks_data;
|
2018-03-14 11:52:13 +01:00
|
|
|
struct spa_list sched_link; /**< link for scheduler */
|
2017-08-18 18:54:45 +02:00
|
|
|
void *scheduler_data; /**< scheduler private data */
|
2017-05-18 17:16:48 +02:00
|
|
|
};
|
|
|
|
|
|
2018-03-16 07:50:22 +01:00
|
|
|
#define spa_graph_node_process(n) ((n)->callbacks->process((n)->callbacks_data, (n)))
|
|
|
|
|
#define spa_graph_node_reuse_buffer(n,p,i) ((n)->callbacks->reuse_buffer((n)->callbacks_data, (n),(p),(i)))
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_graph_port {
|
2017-08-18 18:54:45 +02:00
|
|
|
struct spa_list link; /**< link in node port list */
|
|
|
|
|
struct spa_graph_node *node; /**< owner node */
|
|
|
|
|
enum spa_direction direction; /**< port direction */
|
|
|
|
|
uint32_t port_id; /**< port id */
|
|
|
|
|
uint32_t flags; /**< port flags */
|
2017-11-21 19:34:37 +01:00
|
|
|
struct spa_io_buffers *io; /**< io area of the port */
|
2017-08-18 18:54:45 +02:00
|
|
|
struct spa_graph_port *peer; /**< peer */
|
|
|
|
|
void *scheduler_data; /**< scheduler private data */
|
2017-05-18 17:16:48 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static inline void spa_graph_init(struct spa_graph *graph)
|
2017-05-18 17:16:48 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_list_init(&graph->nodes);
|
2018-03-16 12:46:18 +01:00
|
|
|
spa_list_init(&graph->subgraphs);
|
2018-03-16 16:55:25 +01:00
|
|
|
graph->flags = 0;
|
|
|
|
|
spa_debug("graph %p init", graph);
|
2017-05-18 17:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-20 18:33:07 +02:00
|
|
|
static inline void
|
|
|
|
|
spa_graph_set_callbacks(struct spa_graph *graph,
|
|
|
|
|
const struct spa_graph_callbacks *callbacks,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
graph->callbacks = callbacks;
|
|
|
|
|
graph->callbacks_data = data;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-16 16:55:25 +01:00
|
|
|
static inline struct spa_graph *spa_graph_find_root(struct spa_graph *graph)
|
|
|
|
|
{
|
|
|
|
|
while (graph->parent)
|
|
|
|
|
graph = graph->parent;
|
|
|
|
|
return graph;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void spa_graph_add_subgraph(struct spa_graph *graph, struct spa_graph *subgraph)
|
|
|
|
|
{
|
|
|
|
|
subgraph->parent = graph;
|
|
|
|
|
spa_list_append(&graph->subgraphs, &subgraph->link);
|
|
|
|
|
spa_debug("graph %p add subgraph %p", graph, subgraph);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void spa_graph_remove_subgraph(struct spa_graph *subgraph)
|
|
|
|
|
{
|
|
|
|
|
subgraph->parent = NULL;
|
|
|
|
|
spa_list_remove(&subgraph->link);
|
|
|
|
|
spa_debug("graph %p remove subgraph", subgraph);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 17:16:48 +02:00
|
|
|
static inline void
|
2018-03-14 11:52:13 +01:00
|
|
|
spa_graph_node_init(struct spa_graph_node *node, struct spa_graph_state *state)
|
2017-05-18 17:16:48 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_list_init(&node->ports[SPA_DIRECTION_INPUT]);
|
|
|
|
|
spa_list_init(&node->ports[SPA_DIRECTION_OUTPUT]);
|
|
|
|
|
node->flags = 0;
|
2018-03-14 11:52:13 +01:00
|
|
|
node->state = state;
|
|
|
|
|
node->state->required = node->state->pending = 0;
|
|
|
|
|
node->state->status = SPA_STATUS_OK;
|
2017-09-15 17:26:01 +02:00
|
|
|
spa_debug("node %p init", node);
|
2017-07-07 17:55:26 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static inline void
|
2018-03-16 07:50:22 +01:00
|
|
|
spa_graph_node_set_callbacks(struct spa_graph_node *node,
|
|
|
|
|
const struct spa_graph_node_callbacks *callbacks,
|
|
|
|
|
void *callbacks_data)
|
2017-07-11 12:24:03 +02:00
|
|
|
{
|
2018-03-16 07:50:22 +01:00
|
|
|
node->callbacks = callbacks;
|
|
|
|
|
node->callbacks_data = callbacks_data;
|
2017-07-11 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-07 17:55:26 +02:00
|
|
|
static inline void
|
|
|
|
|
spa_graph_node_add(struct spa_graph *graph,
|
|
|
|
|
struct spa_graph_node *node)
|
|
|
|
|
{
|
2017-08-20 18:33:07 +02:00
|
|
|
node->graph = graph;
|
2018-03-14 11:52:13 +01:00
|
|
|
node->sched_link.next = NULL;
|
2017-08-18 18:54:45 +02:00
|
|
|
spa_list_append(&graph->nodes, &node->link);
|
2018-03-16 16:55:25 +01:00
|
|
|
spa_debug("node %p add to graph %p", node, graph);
|
2017-05-18 17:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
2017-07-07 17:55:26 +02:00
|
|
|
spa_graph_port_init(struct spa_graph_port *port,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t flags,
|
2017-11-21 19:34:37 +01:00
|
|
|
struct spa_io_buffers *io)
|
2017-05-18 17:16:48 +02:00
|
|
|
{
|
2017-09-15 17:26:01 +02:00
|
|
|
spa_debug("port %p init type %d id %d", port, direction, port_id);
|
2017-05-26 08:05:01 +02:00
|
|
|
port->direction = direction;
|
|
|
|
|
port->port_id = port_id;
|
|
|
|
|
port->flags = flags;
|
|
|
|
|
port->io = io;
|
2017-07-07 17:55:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
spa_graph_port_add(struct spa_graph_node *node,
|
|
|
|
|
struct spa_graph_port *port)
|
|
|
|
|
{
|
2017-09-15 17:26:01 +02:00
|
|
|
spa_debug("port %p add to node %p", port, node);
|
2017-07-07 17:55:26 +02:00
|
|
|
port->node = node;
|
2017-08-18 18:54:45 +02:00
|
|
|
spa_list_append(&node->ports[port->direction], &port->link);
|
2017-05-18 17:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-07 17:55:26 +02:00
|
|
|
static inline void spa_graph_node_remove(struct spa_graph_node *node)
|
2017-05-18 17:16:48 +02:00
|
|
|
{
|
2017-09-15 17:26:01 +02:00
|
|
|
spa_debug("node %p remove", node);
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_list_remove(&node->link);
|
2018-03-14 11:52:13 +01:00
|
|
|
if (node->sched_link.next)
|
|
|
|
|
spa_list_remove(&node->sched_link);
|
2017-05-18 17:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-07 17:55:26 +02:00
|
|
|
static inline void spa_graph_port_remove(struct spa_graph_port *port)
|
2017-05-18 17:16:48 +02:00
|
|
|
{
|
2017-09-15 17:26:01 +02:00
|
|
|
spa_debug("port %p remove", port);
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_list_remove(&port->link);
|
2018-03-14 11:52:13 +01:00
|
|
|
port->node = NULL;
|
2017-05-18 17:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
2017-07-07 17:55:26 +02:00
|
|
|
spa_graph_port_link(struct spa_graph_port *out, struct spa_graph_port *in)
|
2017-05-18 17:16:48 +02:00
|
|
|
{
|
2018-03-14 11:52:13 +01:00
|
|
|
spa_debug("port %p link to %p %p %p", out, in, in->node, in->node->state);
|
2017-05-26 08:05:01 +02:00
|
|
|
out->peer = in;
|
|
|
|
|
in->peer = out;
|
2018-03-14 11:52:13 +01:00
|
|
|
if (in->direction == SPA_DIRECTION_INPUT)
|
|
|
|
|
in->node->state->required++;
|
|
|
|
|
else
|
|
|
|
|
out->node->state->required++;
|
2017-05-18 17:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
2017-07-07 17:55:26 +02:00
|
|
|
spa_graph_port_unlink(struct spa_graph_port *port)
|
2017-05-18 17:16:48 +02:00
|
|
|
{
|
2018-03-14 11:52:13 +01:00
|
|
|
struct spa_graph_port *out, *in;
|
|
|
|
|
|
2017-09-15 17:26:01 +02:00
|
|
|
spa_debug("port %p unlink from %p", port, port->peer);
|
2018-03-14 11:52:13 +01:00
|
|
|
if (port->direction == SPA_DIRECTION_INPUT) {
|
|
|
|
|
in = port;
|
|
|
|
|
out = port->peer;
|
|
|
|
|
} else {
|
|
|
|
|
out = port;
|
|
|
|
|
in = port->peer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (out && in) {
|
|
|
|
|
in->node->state->required--;
|
|
|
|
|
out->peer = NULL;
|
|
|
|
|
in->peer = NULL;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2017-05-18 17:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-16 07:50:22 +01:00
|
|
|
static inline int spa_graph_node_impl_process(void *data, struct spa_graph_node *node)
|
|
|
|
|
{
|
|
|
|
|
struct spa_graph *g = node->graph;
|
|
|
|
|
struct spa_node *n = data;
|
|
|
|
|
int res = 0;
|
|
|
|
|
|
2018-03-16 16:55:25 +01:00
|
|
|
res = spa_node_process(n);
|
2018-03-16 07:50:22 +01:00
|
|
|
|
|
|
|
|
spa_debug("node %p: process %d", node, res);
|
|
|
|
|
|
|
|
|
|
node->state->status = res;
|
|
|
|
|
|
|
|
|
|
if (res == SPA_STATUS_HAVE_BUFFER)
|
|
|
|
|
spa_graph_have_output(g, node);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int spa_graph_node_impl_reuse_buffer(void *data, struct spa_graph_node *node,
|
|
|
|
|
uint32_t port_id, uint32_t buffer_id)
|
|
|
|
|
{
|
|
|
|
|
struct spa_node *n = data;
|
|
|
|
|
return spa_node_port_reuse_buffer(n, port_id, buffer_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct spa_graph_node_callbacks spa_graph_node_impl_default = {
|
|
|
|
|
SPA_VERSION_GRAPH_NODE_CALLBACKS,
|
|
|
|
|
.process = spa_graph_node_impl_process,
|
|
|
|
|
.reuse_buffer = spa_graph_node_impl_reuse_buffer,
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-18 17:16:48 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
} /* extern "C" */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* __SPA_GRAPH_H__ */
|