mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-25 06:59:57 -05:00
simplify things with just 1 process function
Make just one process function in spa node. With the io area states we can do more complicated io patterns.
This commit is contained in:
parent
e8d0281982
commit
9b0a880afb
21 changed files with 202 additions and 359 deletions
|
|
@ -136,21 +136,35 @@ static inline int spa_graph_impl_have_output(void *data, struct spa_graph_node *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline void spa_graph_impl_add_graph(struct spa_graph *g, struct spa_list *pending)
|
||||
{
|
||||
struct spa_graph_node *n;
|
||||
struct spa_graph *sg;
|
||||
|
||||
spa_list_for_each(n, &g->nodes, link) {
|
||||
n->state->pending = n->state->required + 1;
|
||||
spa_debug("graph %p node %p: add %d %d status %d", g, n,
|
||||
n->state->pending, n->state->required, n->state->status);
|
||||
spa_list_append(pending, &n->sched_link);
|
||||
}
|
||||
spa_list_for_each(sg, &g->subgraphs, link)
|
||||
spa_graph_impl_add_graph(sg, pending);
|
||||
}
|
||||
|
||||
static inline int spa_graph_impl_run(void *data)
|
||||
{
|
||||
struct spa_graph_data *d = (struct spa_graph_data *) data;
|
||||
struct spa_graph *g = d->graph;
|
||||
struct spa_graph_node *n;
|
||||
struct spa_graph_node *n, *tmp;
|
||||
struct spa_list pending;
|
||||
|
||||
spa_debug("graph %p run", d->graph);
|
||||
|
||||
spa_list_for_each(n, &g->nodes, link) {
|
||||
n->state->pending = n->state->required + 1;
|
||||
spa_debug("node %p: add %d %d status %d", n,
|
||||
n->state->pending, n->state->required,
|
||||
n->state->status);
|
||||
}
|
||||
spa_list_for_each(n, &g->nodes, link)
|
||||
spa_list_init(&pending);
|
||||
|
||||
spa_graph_impl_add_graph(g, &pending);
|
||||
|
||||
spa_list_for_each_safe(n, tmp, &pending, sched_link)
|
||||
spa_graph_trigger(d->graph, n);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ struct spa_graph_callbacks {
|
|||
|
||||
struct spa_graph {
|
||||
struct spa_list link; /* link for subgraph */
|
||||
#define SPA_GRAPH_FLAG_DRIVER (1 << 0)
|
||||
uint32_t flags; /* flags */
|
||||
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 */
|
||||
|
|
@ -55,25 +57,6 @@ struct spa_graph {
|
|||
void *callbacks_data;
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static inline void spa_graph_remove_subgraph(struct spa_graph *subgraph)
|
||||
{
|
||||
subgraph->parent = NULL;
|
||||
spa_list_remove(&subgraph->link);
|
||||
}
|
||||
|
||||
#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)))
|
||||
#define spa_graph_run(g) ((g)->callbacks->run((g)->callbacks_data))
|
||||
|
|
@ -124,6 +107,8 @@ static inline void spa_graph_init(struct spa_graph *graph)
|
|||
{
|
||||
spa_list_init(&graph->nodes);
|
||||
spa_list_init(&graph->subgraphs);
|
||||
graph->flags = 0;
|
||||
spa_debug("graph %p init", graph);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
@ -135,6 +120,27 @@ spa_graph_set_callbacks(struct spa_graph *graph,
|
|||
graph->callbacks_data = data;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static inline void
|
||||
spa_graph_node_init(struct spa_graph_node *node, struct spa_graph_state *state)
|
||||
{
|
||||
|
|
@ -163,7 +169,7 @@ spa_graph_node_add(struct spa_graph *graph,
|
|||
node->graph = graph;
|
||||
node->sched_link.next = NULL;
|
||||
spa_list_append(&graph->nodes, &node->link);
|
||||
spa_debug("node %p add", node);
|
||||
spa_debug("node %p add to graph %p", node, graph);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
@ -241,15 +247,9 @@ static inline int spa_graph_node_impl_process(void *data, struct spa_graph_node
|
|||
{
|
||||
struct spa_graph *g = node->graph;
|
||||
struct spa_node *n = data;
|
||||
//int old = node->state->status, res = 0;
|
||||
int res = 0;
|
||||
|
||||
// if (old == SPA_STATUS_NEED_BUFFER && n->process_input &&
|
||||
if (n->process_input &&
|
||||
!spa_list_is_empty(&node->ports[SPA_DIRECTION_INPUT]))
|
||||
res = spa_node_process_input(n);
|
||||
else
|
||||
res = spa_node_process_output(n);
|
||||
res = spa_node_process(n);
|
||||
|
||||
spa_debug("node %p: process %d", node, res);
|
||||
|
||||
|
|
@ -258,8 +258,6 @@ static inline int spa_graph_node_impl_process(void *data, struct spa_graph_node
|
|||
if (res == SPA_STATUS_HAVE_BUFFER)
|
||||
spa_graph_have_output(g, node);
|
||||
|
||||
spa_debug("node %p: end %d", node, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -479,81 +479,21 @@ struct spa_node {
|
|||
uint32_t port_id,
|
||||
const struct spa_command *command);
|
||||
/**
|
||||
* Process the input area of the node.
|
||||
* Process the node
|
||||
*
|
||||
* For synchronous nodes, this function is called to start processing data
|
||||
* or when process_output returned SPA_STATUS_NEED_BUFFER
|
||||
* Output io areas with SPA_STATUS_NEED_BUFFER will recycle the
|
||||
* buffers if any.
|
||||
*
|
||||
* For Asynchronous nodes, this function is called when a need_input event
|
||||
* is received from the node.
|
||||
* Input areas with SPA_STATUS_HAVE_BUFFER are consumed if possible
|
||||
* and the status is set to SPA_STATUS_NEED_BUFFER or SPA_STATUS_OK.
|
||||
*
|
||||
* Before calling this function, you must configure spa_port_io structures
|
||||
* on the input ports you want to process data on.
|
||||
* When the node has new output buffers, SPA_STATUS_HAVE_BUFFER
|
||||
* is returned.
|
||||
*
|
||||
* The node will loop through all spa_port_io structures and will
|
||||
* process the buffers. For each port, the port io will be used as:
|
||||
*
|
||||
* - if status is set to SPA_STATUS_HAVE_BUFFER, buffer_id is read and processed.
|
||||
*
|
||||
* The spa_port_io of the port is then updated as follows.
|
||||
*
|
||||
* - buffer_id is set to a buffer id that should be reused. SPA_ID_INVALID
|
||||
* is set when there is no buffer to reuse
|
||||
*
|
||||
* - status is set to SPA_STATUS_OK when no new buffer is needed on the port
|
||||
*
|
||||
* - status is set to SPA_STATUS_NEED_BUFFER when a new buffer is needed
|
||||
* on the port.
|
||||
*
|
||||
* - status is set to a negative errno style error code when the buffer_id
|
||||
* was invalid or any processing error happened on the port.
|
||||
*
|
||||
* This function must be called from the data thread.
|
||||
*
|
||||
* \param node a spa_node
|
||||
* \return SPA_STATUS_OK on success or when the node is asynchronous
|
||||
* SPA_STATUS_HAVE_BUFFER for synchronous nodes when output
|
||||
* can be consumed.
|
||||
* < 0 for errno style errors. One or more of the spa_port_io
|
||||
* areas has an error.
|
||||
* When no new output could be produced, SPA_STATUS_NEED_BUFFER is
|
||||
* returned.
|
||||
*/
|
||||
int (*process_input) (struct spa_node *node);
|
||||
|
||||
/**
|
||||
* Tell the node that output is consumed.
|
||||
*
|
||||
* For synchronous nodes, this function can be called when process_input
|
||||
* returned SPA_STATUS_HAVE_BUFFER and the output on the spa_port_io
|
||||
* areas has been consumed.
|
||||
*
|
||||
* For Asynchronous node, this function is called when a have_output event
|
||||
* is received from the node.
|
||||
*
|
||||
* Before calling this function you must process the buffers
|
||||
* in each of the output ports spa_port_io structure as follows:
|
||||
*
|
||||
* - use the buffer_id from the io for all the ports where the status is
|
||||
* SPA_STATUS_HAVE_BUFFER
|
||||
*
|
||||
* - set buffer_id to a buffer_id you would like to reuse or SPA_ID_INVALID
|
||||
* when no buffer is to be reused.
|
||||
*
|
||||
* - set the status to SPA_STATUS_NEED_BUFFER for all port you want more
|
||||
* output from
|
||||
*
|
||||
* - set the status to SPA_STATUS_OK for the port you don't want more
|
||||
* buffers from.
|
||||
*
|
||||
* This function must be called from the data thread.
|
||||
*
|
||||
* \param node a spa_node
|
||||
* \return SPA_STATUS_OK on success or when the node is asynchronous
|
||||
* SPA_STATUS_NEED_BUFFER for synchronous nodes when input
|
||||
* is needed.
|
||||
* < 0 for errno style errors. One or more of the spa_port_io
|
||||
* areas has an error.
|
||||
*/
|
||||
int (*process_output) (struct spa_node *node);
|
||||
int (*process) (struct spa_node *node);
|
||||
};
|
||||
|
||||
#define spa_node_enum_params(n,...) (n)->enum_params((n),__VA_ARGS__)
|
||||
|
|
@ -572,8 +512,7 @@ struct spa_node {
|
|||
#define spa_node_port_set_io(n,...) (n)->port_set_io((n),__VA_ARGS__)
|
||||
#define spa_node_port_reuse_buffer(n,...) (n)->port_reuse_buffer((n),__VA_ARGS__)
|
||||
#define spa_node_port_send_command(n,...) (n)->port_send_command((n),__VA_ARGS__)
|
||||
#define spa_node_process_input(n) (n)->process_input((n))
|
||||
#define spa_node_process_output(n) (n)->process_output((n))
|
||||
#define spa_node_process(n) (n)->process((n))
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -571,7 +571,7 @@ impl_node_port_send_command(struct spa_node *node,
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int impl_node_process_input(struct spa_node *node)
|
||||
static int impl_node_process(struct spa_node *node)
|
||||
{
|
||||
struct state *this;
|
||||
struct spa_io_buffers *input;
|
||||
|
|
@ -582,13 +582,15 @@ static int impl_node_process_input(struct spa_node *node)
|
|||
input = this->io;
|
||||
spa_return_val_if_fail(input != NULL, -EIO);
|
||||
|
||||
spa_log_trace(this->log, NAME " %p: process input %d %d", this, input->status, input->buffer_id);
|
||||
spa_log_trace(this->log, NAME " %p: process %d %d", this, input->status, input->buffer_id);
|
||||
|
||||
if (input->status == SPA_STATUS_HAVE_BUFFER && input->buffer_id < this->n_buffers) {
|
||||
if (input->status == SPA_STATUS_HAVE_BUFFER &&
|
||||
input->buffer_id < this->n_buffers) {
|
||||
struct buffer *b = &this->buffers[input->buffer_id];
|
||||
|
||||
if (!SPA_FLAG_CHECK(b->flags, BUFFER_FLAG_OUT)) {
|
||||
spa_log_warn(this->log, NAME " %p: buffer %u in use", this, input->buffer_id);
|
||||
spa_log_warn(this->log, NAME " %p: buffer %u in use",
|
||||
this, input->buffer_id);
|
||||
input->status = -EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -599,17 +601,12 @@ static int impl_node_process_input(struct spa_node *node)
|
|||
|
||||
input->status = SPA_STATUS_OK;
|
||||
}
|
||||
|
||||
return SPA_STATUS_OK;
|
||||
}
|
||||
|
||||
static int impl_node_process_output(struct spa_node *node)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static const struct spa_dict_item node_info_items[] = {
|
||||
{ "media.class", "Audio/Sink" },
|
||||
{ "node.driver", "true" },
|
||||
};
|
||||
|
||||
static const struct spa_dict node_info = {
|
||||
|
|
@ -636,8 +633,7 @@ static const struct spa_node impl_node = {
|
|||
impl_node_port_set_io,
|
||||
impl_node_port_reuse_buffer,
|
||||
impl_node_port_send_command,
|
||||
impl_node_process_input,
|
||||
impl_node_process_output,
|
||||
impl_node_process,
|
||||
};
|
||||
|
||||
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
|
||||
|
|
|
|||
|
|
@ -343,8 +343,6 @@ static inline void try_pull(struct state *state, snd_pcm_uframes_t frames,
|
|||
if (spa_list_is_empty(&state->ready) && do_pull) {
|
||||
spa_log_trace(state->log, "alsa-util %p: %d %lu", state, io->status,
|
||||
state->filled + written);
|
||||
if (io->status == SPA_STATUS_NEED_BUFFER)
|
||||
return;
|
||||
io->status = SPA_STATUS_NEED_BUFFER;
|
||||
if (state->range) {
|
||||
state->range->offset = state->sample_count * state->frame_size;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ static void reset_props(struct props *props)
|
|||
#define BUFFER_FLAG_MAPPED (1<<2)
|
||||
|
||||
struct buffer {
|
||||
struct spa_list link;
|
||||
struct spa_buffer *outbuf;
|
||||
struct spa_meta_header *h;
|
||||
uint32_t flags;
|
||||
|
|
@ -174,6 +175,7 @@ struct port {
|
|||
|
||||
struct buffer buffers[MAX_BUFFERS];
|
||||
uint32_t n_buffers;
|
||||
struct spa_list queue;
|
||||
|
||||
struct spa_source source;
|
||||
|
||||
|
|
@ -810,17 +812,13 @@ static int impl_node_port_send_command(struct spa_node *node,
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int impl_node_process_input(struct spa_node *node)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int impl_node_process_output(struct spa_node *node)
|
||||
static int impl_node_process(struct spa_node *node)
|
||||
{
|
||||
struct impl *this;
|
||||
int i, res = SPA_STATUS_OK;
|
||||
int i, res;
|
||||
struct spa_io_buffers *io;
|
||||
struct port *port;
|
||||
struct buffer *b;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
|
|
@ -834,7 +832,9 @@ static int impl_node_process_output(struct spa_node *node)
|
|||
return SPA_STATUS_HAVE_BUFFER;
|
||||
|
||||
if (io->buffer_id < port->n_buffers) {
|
||||
res = spa_v4l2_buffer_recycle(this, io->buffer_id);
|
||||
if ((res = spa_v4l2_buffer_recycle(this, io->buffer_id)) < 0)
|
||||
return res;
|
||||
|
||||
io->buffer_id = SPA_ID_INVALID;
|
||||
}
|
||||
for (i = 0; i < port->n_controls; i++) {
|
||||
|
|
@ -856,7 +856,16 @@ static int impl_node_process_output(struct spa_node *node)
|
|||
control->value = *control->io = c.value;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
if (spa_list_is_empty(&port->queue))
|
||||
return -EPIPE;
|
||||
|
||||
b = spa_list_first(&port->queue, struct buffer, link);
|
||||
spa_list_remove(&b->link);
|
||||
|
||||
io->buffer_id = b->outbuf->id;
|
||||
io->status = SPA_STATUS_HAVE_BUFFER;
|
||||
|
||||
return SPA_STATUS_HAVE_BUFFER;
|
||||
}
|
||||
|
||||
static const struct spa_dict_item info_items[] = {
|
||||
|
|
@ -889,8 +898,7 @@ static const struct spa_node impl_node = {
|
|||
impl_node_port_set_io,
|
||||
impl_node_port_reuse_buffer,
|
||||
impl_node_port_send_command,
|
||||
impl_node_process_input,
|
||||
impl_node_process_output,
|
||||
impl_node_process,
|
||||
};
|
||||
|
||||
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
|
||||
|
|
@ -1012,6 +1020,8 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
|
||||
reset_props(&this->props);
|
||||
|
||||
spa_list_init(&port->queue);
|
||||
|
||||
port->log = this->log;
|
||||
port->info.flags = SPA_PORT_INFO_FLAG_LIVE |
|
||||
SPA_PORT_INFO_FLAG_PHYSICAL |
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ static int spa_v4l2_buffer_recycle(struct impl *this, uint32_t buffer_id)
|
|||
spa_log_error(port->log, "VIDIOC_QBUF: %m");
|
||||
return -err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1145,7 +1146,6 @@ static int mmap_read(struct impl *this)
|
|||
struct buffer *b;
|
||||
struct spa_data *d;
|
||||
int64_t pts;
|
||||
struct spa_io_buffers *io = port->io;
|
||||
|
||||
spa_zero(buf);
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
|
@ -1178,10 +1178,9 @@ static int mmap_read(struct impl *this)
|
|||
d[0].chunk->stride = port->fmt.fmt.pix.bytesperline;
|
||||
|
||||
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUTSTANDING);
|
||||
io->buffer_id = b->outbuf->id;
|
||||
io->status = SPA_STATUS_HAVE_BUFFER;
|
||||
spa_list_append(&port->queue, &b->link);
|
||||
|
||||
spa_log_trace(port->log, "v4l2 %p: have output %d", this, io->buffer_id);
|
||||
spa_log_trace(port->log, "v4l2 %p: have output %d", this, buf.index);
|
||||
this->callbacks->have_output(this->callbacks_data);
|
||||
|
||||
return 0;
|
||||
|
|
@ -1499,10 +1498,12 @@ static int spa_v4l2_stream_off(struct impl *this)
|
|||
struct buffer *b;
|
||||
|
||||
b = &port->buffers[i];
|
||||
if (!SPA_FLAG_CHECK(b->flags, BUFFER_FLAG_OUTSTANDING))
|
||||
if (!SPA_FLAG_CHECK(b->flags, BUFFER_FLAG_OUTSTANDING)) {
|
||||
if (xioctl(port->fd, VIDIOC_QBUF, &b->v4l2_buffer) < 0)
|
||||
spa_log_warn(this->log, "VIDIOC_QBUF: %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
spa_list_init(&port->queue);
|
||||
port->started = false;
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -229,8 +229,8 @@ static void on_sink_pull(struct data *data)
|
|||
{
|
||||
spa_log_trace(data->log, "do sink pull");
|
||||
if (data->mode & MODE_DIRECT) {
|
||||
spa_node_process_output(data->source);
|
||||
spa_node_process_input(data->sink);
|
||||
spa_node_process(data->source);
|
||||
spa_node_process(data->sink);
|
||||
} else {
|
||||
spa_graph_need_input(&data->graph, &data->sink_node);
|
||||
}
|
||||
|
|
@ -240,8 +240,8 @@ static void on_source_push(struct data *data)
|
|||
{
|
||||
spa_log_trace(data->log, "do source push");
|
||||
if (data->mode & MODE_DIRECT) {
|
||||
spa_node_process_output(data->source);
|
||||
spa_node_process_input(data->sink);
|
||||
spa_node_process(data->source);
|
||||
spa_node_process(data->sink);
|
||||
} else {
|
||||
spa_graph_have_output(&data->graph, &data->source_node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,12 +219,12 @@ static void on_sink_need_input(void *_data)
|
|||
struct data *data = _data;
|
||||
int res;
|
||||
|
||||
res = spa_node_process_output(data->source);
|
||||
res = spa_node_process(data->source);
|
||||
if (res != SPA_STATUS_HAVE_BUFFER)
|
||||
printf("got process_output error from source %d\n", res);
|
||||
printf("got process error from source %d\n", res);
|
||||
|
||||
if ((res = spa_node_process_input(data->sink)) < 0)
|
||||
printf("got process_input error from sink %d\n", res);
|
||||
if ((res = spa_node_process(data->sink)) < 0)
|
||||
printf("got process error from sink %d\n", res);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ static void on_source_have_output(void *_data)
|
|||
|
||||
io->status = SPA_STATUS_NEED_BUFFER;
|
||||
|
||||
if ((res = spa_node_process_output(data->source)) < 0)
|
||||
if ((res = spa_node_process(data->source)) < 0)
|
||||
printf("got pull error %d\n", res);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue