mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
spa: simplify start/pause
Use the sync option in invoke to implement stop.
This commit is contained in:
parent
67b06d4ad2
commit
155243a27c
6 changed files with 501 additions and 729 deletions
|
|
@ -141,7 +141,6 @@ struct port {
|
|||
struct buffer buffers[MAX_BUFFERS];
|
||||
uint32_t n_buffers;
|
||||
|
||||
bool source_enabled;
|
||||
struct spa_source source;
|
||||
|
||||
struct spa_port_info info;
|
||||
|
|
@ -290,92 +289,10 @@ static int impl_node_set_param(struct spa_node *node,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int do_pause_done(struct spa_loop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
const void *data,
|
||||
size_t size,
|
||||
void *user_data)
|
||||
{
|
||||
struct impl *this = user_data;
|
||||
int res = *(int*)data;
|
||||
|
||||
if (SPA_RESULT_IS_OK(res))
|
||||
res = spa_v4l2_stream_off(this);
|
||||
|
||||
this->callbacks->done(this->callbacks_data, seq, res);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_pause(struct spa_loop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
const void *data,
|
||||
size_t size,
|
||||
void *user_data)
|
||||
{
|
||||
struct impl *this = user_data;
|
||||
int res;
|
||||
const struct spa_command *cmd = data;
|
||||
|
||||
res = spa_node_port_send_command(&this->node, SPA_DIRECTION_OUTPUT, 0, cmd);
|
||||
|
||||
if (async) {
|
||||
spa_loop_invoke(this->out_ports[0].main_loop,
|
||||
do_pause_done,
|
||||
seq,
|
||||
&res,
|
||||
sizeof(res),
|
||||
false,
|
||||
this);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int do_start_done(struct spa_loop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
const void *data,
|
||||
size_t size,
|
||||
void *user_data)
|
||||
{
|
||||
struct impl *this = user_data;
|
||||
int res = *(int*)data;
|
||||
|
||||
this->callbacks->done(this->callbacks_data, seq, res);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_start(struct spa_loop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
const void *data,
|
||||
size_t size,
|
||||
void *user_data)
|
||||
{
|
||||
struct impl *this = user_data;
|
||||
int res;
|
||||
const struct spa_command *cmd = data;
|
||||
|
||||
res = spa_node_port_send_command(&this->node, SPA_DIRECTION_OUTPUT, 0, cmd);
|
||||
|
||||
if (async) {
|
||||
spa_loop_invoke(this->out_ports[0].main_loop,
|
||||
do_start_done,
|
||||
seq,
|
||||
&res,
|
||||
sizeof(res),
|
||||
false,
|
||||
this);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
|
||||
{
|
||||
struct impl *this;
|
||||
int res;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(command != NULL, -EINVAL);
|
||||
|
|
@ -384,7 +301,6 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
|
||||
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
|
||||
struct port *port = &this->out_ports[0];
|
||||
int res;
|
||||
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
|
|
@ -394,32 +310,13 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
if ((res = spa_v4l2_stream_on(this)) < 0)
|
||||
return res;
|
||||
|
||||
return spa_loop_invoke(this->out_ports[0].data_loop,
|
||||
do_start,
|
||||
++this->seq,
|
||||
command,
|
||||
SPA_POD_SIZE(command),
|
||||
false,
|
||||
this);
|
||||
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
|
||||
struct port *port = &this->out_ports[0];
|
||||
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (port->n_buffers == 0)
|
||||
return -EIO;
|
||||
|
||||
return spa_loop_invoke(this->out_ports[0].data_loop,
|
||||
do_pause,
|
||||
++this->seq,
|
||||
command,
|
||||
SPA_POD_SIZE(command),
|
||||
false,
|
||||
this);
|
||||
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.ClockUpdate) {
|
||||
return 0;
|
||||
if ((res = spa_v4l2_stream_off(this)) < 0)
|
||||
return res;
|
||||
} else
|
||||
return -ENOTSUP;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int impl_node_set_callbacks(struct spa_node *node,
|
||||
|
|
@ -852,23 +749,7 @@ static int impl_node_port_send_command(struct spa_node *node,
|
|||
uint32_t port_id,
|
||||
const struct spa_command *command)
|
||||
{
|
||||
struct impl *this;
|
||||
int res;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
|
||||
res = spa_v4l2_port_set_enabled(this, false);
|
||||
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
|
||||
res = spa_v4l2_port_set_enabled(this, true);
|
||||
} else
|
||||
res = -ENOTSUP;
|
||||
|
||||
return res;
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int impl_node_process_input(struct spa_node *node)
|
||||
|
|
|
|||
|
|
@ -158,20 +158,6 @@ static int spa_v4l2_clear_buffers(struct impl *this)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int spa_v4l2_port_set_enabled(struct impl *this, bool enabled)
|
||||
{
|
||||
struct port *port = &this->out_ports[0];
|
||||
if (port->source_enabled != enabled) {
|
||||
spa_log_info(port->log, "v4l2: enabled %d", enabled);
|
||||
port->source_enabled = enabled;
|
||||
if (enabled)
|
||||
spa_loop_add_source(port->data_loop, &port->source);
|
||||
else
|
||||
spa_loop_remove_source(port->data_loop, &port->source);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int spa_v4l2_close(struct impl *this)
|
||||
{
|
||||
struct port *port = &this->out_ports[0];
|
||||
|
|
@ -182,8 +168,6 @@ static int spa_v4l2_close(struct impl *this)
|
|||
if (port->n_buffers > 0)
|
||||
return 0;
|
||||
|
||||
spa_v4l2_port_set_enabled(this, false);
|
||||
|
||||
spa_log_info(port->log, "v4l2: close");
|
||||
|
||||
if (close(port->fd))
|
||||
|
|
@ -1148,11 +1132,15 @@ static void v4l2_on_fd_events(struct spa_source *source)
|
|||
{
|
||||
struct impl *this = source->data;
|
||||
|
||||
if (source->rmask & SPA_IO_ERR)
|
||||
if (source->rmask & SPA_IO_ERR) {
|
||||
spa_log_warn(this->log, "v4l2 %p: error %d", this, source->rmask);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(source->rmask & SPA_IO_IN))
|
||||
if (!(source->rmask & SPA_IO_IN)) {
|
||||
spa_log_warn(this->log, "v4l2 %p: spurious wakeup %d", this, source->rmask);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mmap_read(this) < 0)
|
||||
return;
|
||||
|
|
@ -1370,29 +1358,54 @@ static int spa_v4l2_stream_on(struct impl *this)
|
|||
struct port *state = &this->out_ports[0];
|
||||
enum v4l2_buf_type type;
|
||||
|
||||
if (!state->opened)
|
||||
return -EIO;
|
||||
|
||||
if (state->started)
|
||||
return 0;
|
||||
|
||||
spa_log_debug(this->log, "starting");
|
||||
|
||||
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (xioctl(state->fd, VIDIOC_STREAMON, &type) < 0) {
|
||||
spa_log_error(this->log, "VIDIOC_STREAMON: %s", strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
|
||||
spa_loop_add_source(state->data_loop, &state->source);
|
||||
|
||||
state->started = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_remove_source(struct spa_loop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
const void *data,
|
||||
size_t size,
|
||||
void *user_data)
|
||||
{
|
||||
struct port *state = user_data;
|
||||
spa_loop_remove_source(state->data_loop, &state->source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int spa_v4l2_stream_off(struct impl *this)
|
||||
{
|
||||
struct port *state = &this->out_ports[0];
|
||||
enum v4l2_buf_type type;
|
||||
int i;
|
||||
|
||||
if (!state->opened)
|
||||
return -EIO;
|
||||
|
||||
if (!state->started)
|
||||
return 0;
|
||||
|
||||
spa_v4l2_port_set_enabled(this, false);
|
||||
spa_log_debug(this->log, "stopping");
|
||||
|
||||
spa_loop_invoke(state->data_loop, do_remove_source, 0, NULL, 0, true, state);
|
||||
|
||||
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (xioctl(state->fd, VIDIOC_STREAMOFF, &type) < 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue