mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -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
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue