spa: simplify start/pause

Use the sync option in invoke to implement stop.
This commit is contained in:
Wim Taymans 2018-01-18 11:57:23 +01:00
parent 67b06d4ad2
commit 155243a27c
6 changed files with 501 additions and 729 deletions

View file

@ -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)