node: add flags to port_use_buffer

Remove the CAN_USE_BUFFERS flag, it is redundant. We can know this
because of the IO params and buffer params.

Add flags to the port_use_buffer call. We also want this call to
replace port_alloc_buffer. Together with a new result event we can
ask the node to (a)synchronously fill up the buffer data for us. This
is part of a plan to let remote nodes provide buffer data.
This commit is contained in:
Wim Taymans 2019-07-25 13:19:39 +02:00
parent b314547702
commit 8590ac158b
33 changed files with 153 additions and 122 deletions

View file

@ -340,7 +340,8 @@ static int impl_port_set_param(void *object,
}
static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id,
struct spa_buffer **buffers, uint32_t n_buffers)
uint32_t flags,
struct spa_buffer **buffers, uint32_t n_buffers)
{
struct data *d = object;
uint32_t i;
@ -527,7 +528,7 @@ int main(int argc, char *argv[])
data.info = SPA_PORT_INFO_INIT();
data.info.change_mask = SPA_PORT_CHANGE_MASK_FLAGS;
data.info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS;
data.info.flags = 0;
data.info.change_mask = SPA_PORT_CHANGE_MASK_PARAMS;
data.params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
data.params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);

View file

@ -304,10 +304,12 @@ static int impl_port_set_param(void *object,
}
static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id,
struct spa_buffer **buffers, uint32_t n_buffers)
uint32_t flags,
struct spa_buffer **buffers, uint32_t n_buffers)
{
struct data *d = object;
uint32_t i;
for (i = 0; i < n_buffers; i++) {
struct buffer *b = &d->buffers[i];
struct spa_data *datas = buffers[i]->datas;
@ -521,7 +523,7 @@ int main(int argc, char *argv[])
SPA_PORT_CHANGE_MASK_PROPS |
SPA_PORT_CHANGE_MASK_PARAMS;
data.info = SPA_PORT_INFO_INIT();
data.info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS;
data.info.flags = 0;
data.items[0] = SPA_DICT_ITEM_INIT(PW_KEY_FORMAT_DSP, "32 bit float mono audio");
data.dict = SPA_DICT_INIT_ARRAY(data.items);
data.info.props = &data.dict;

View file

@ -104,7 +104,7 @@ static int impl_add_listener(void *object,
info = SPA_PORT_INFO_INIT();
info.change_mask = SPA_PORT_CHANGE_MASK_FLAGS;
info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS;
info.flags = 0;
spa_node_emit_port_info(&d->hooks, SPA_DIRECTION_INPUT, 0, &info);
@ -243,7 +243,7 @@ static int impl_port_set_param(void *object,
}
static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id,
struct spa_buffer **buffers, uint32_t n_buffers)
uint32_t flags, struct spa_buffer **buffers, uint32_t n_buffers)
{
struct data *d = object;
uint32_t i;

View file

@ -171,6 +171,7 @@ struct pw_client_node_proxy_events {
enum spa_direction direction,
uint32_t port_id,
uint32_t mix_id,
uint32_t flags,
uint32_t n_buffers,
struct pw_client_node_buffer *buffers);
/**

View file

@ -125,8 +125,8 @@ static void init_port(struct port *p, enum spa_direction direction)
}
static int port_use_buffers(void *data,
struct spa_buffer **buffers,
uint32_t n_buffers)
uint32_t flags,
struct spa_buffer **buffers, uint32_t n_buffers)
{
struct port *p = data;
struct pw_port *port = p->port;
@ -144,15 +144,13 @@ static int port_use_buffers(void *data,
}
res = spa_node_port_use_buffers(port->mix,
pw_direction_reverse(port->direction),
0,
buffers,
n_buffers);
pw_direction_reverse(port->direction), 0,
flags,
buffers, n_buffers);
res = spa_node_port_use_buffers(node->node,
port->direction,
port->port_id,
buffers,
n_buffers);
port->direction, port->port_id,
flags,
buffers, n_buffers);
return res;
}

View file

@ -236,8 +236,7 @@ static int impl_node_add_port(void *object, enum spa_direction direction, uint32
port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
SPA_PORT_CHANGE_MASK_PARAMS;
port->info = SPA_PORT_INFO_INIT();
port->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS |
SPA_PORT_FLAG_NO_REF |
port->info.flags = SPA_PORT_FLAG_NO_REF |
SPA_PORT_FLAG_DYNAMIC_DATA |
SPA_PORT_FLAG_REMOVABLE |
SPA_PORT_FLAG_OPTIONAL;
@ -548,6 +547,7 @@ static int
impl_node_port_use_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
@ -893,8 +893,7 @@ impl_init(const struct spa_handle_factory *factory,
port->id = 0;
port->info = SPA_PORT_INFO_INIT();
port->info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS;
port->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS |
SPA_PORT_FLAG_DYNAMIC_DATA;
port->info.flags = SPA_PORT_FLAG_DYNAMIC_DATA;
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
port->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
port->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);

View file

@ -121,8 +121,8 @@ static void init_port(struct port *p, enum spa_direction direction)
}
static int port_use_buffers(void *data,
struct spa_buffer **buffers,
uint32_t n_buffers)
uint32_t flags,
struct spa_buffer **buffers, uint32_t n_buffers)
{
struct port *p = data;
struct pw_port *port = p->port;
@ -140,15 +140,13 @@ static int port_use_buffers(void *data,
}
res = spa_node_port_use_buffers(port->mix,
pw_direction_reverse(port->direction),
0,
buffers,
n_buffers);
pw_direction_reverse(port->direction), 0,
flags,
buffers, n_buffers);
res = spa_node_port_use_buffers(node->node,
port->direction,
port->port_id,
buffers,
n_buffers);
port->direction, port->port_id,
flags,
buffers, n_buffers);
return res;
}

View file

@ -236,8 +236,7 @@ static int impl_node_add_port(void *object, enum spa_direction direction, uint32
port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
SPA_PORT_CHANGE_MASK_PARAMS;
port->info = SPA_PORT_INFO_INIT();
port->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS |
SPA_PORT_FLAG_NO_REF |
port->info.flags = SPA_PORT_FLAG_NO_REF |
SPA_PORT_FLAG_DYNAMIC_DATA |
SPA_PORT_FLAG_REMOVABLE |
SPA_PORT_FLAG_OPTIONAL;
@ -548,6 +547,7 @@ static int
impl_node_port_use_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
@ -890,8 +890,7 @@ impl_init(const struct spa_handle_factory *factory,
port->id = 0;
port->info = SPA_PORT_INFO_INIT();
port->info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS;
port->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS |
SPA_PORT_FLAG_DYNAMIC_DATA;
port->info.flags = SPA_PORT_FLAG_DYNAMIC_DATA;
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
port->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
port->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);

View file

@ -187,11 +187,13 @@ struct impl {
pw_client_node_resource(r,port_set_io,0,__VA_ARGS__)
#define pw_client_node_resource_set_activation(r,...) \
pw_client_node_resource(r,set_activation,0,__VA_ARGS__)
static int
do_port_use_buffers(struct impl *impl,
enum spa_direction direction,
uint32_t port_id,
uint32_t mix_id,
uint32_t flags,
struct spa_buffer **buffers,
uint32_t n_buffers);
@ -268,7 +270,7 @@ static void mix_clear(struct node *this, struct mix *mix)
if (!mix->valid)
return;
do_port_use_buffers(this->impl, port->direction, port->id,
mix->id, NULL, 0);
mix->id, 0, NULL, 0);
mix->valid = false;
}
@ -695,6 +697,7 @@ do_port_use_buffers(struct impl *impl,
enum spa_direction direction,
uint32_t port_id,
uint32_t mix_id,
uint32_t flags,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
@ -811,7 +814,7 @@ do_port_use_buffers(struct impl *impl,
}
return pw_client_node_resource_port_use_buffers(this->resource,
direction, port_id, mix_id,
direction, port_id, mix_id, flags,
n_buffers, mb);
}
@ -819,6 +822,7 @@ static int
impl_node_port_use_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
@ -830,7 +834,7 @@ impl_node_port_use_buffers(void *object,
impl = this->impl;
return do_port_use_buffers(impl, direction, port_id,
SPA_ID_INVALID, buffers, n_buffers);
SPA_ID_INVALID, flags, buffers, n_buffers);
}
static int
@ -1344,13 +1348,14 @@ static int
impl_mix_port_use_buffers(void *object,
enum spa_direction direction,
uint32_t mix_id,
uint32_t flags,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
struct port *port = object;
struct impl *impl = port->impl;
return do_port_use_buffers(impl, direction, port->id, mix_id, buffers, n_buffers);
return do_port_use_buffers(impl, direction, port->id, mix_id, flags, buffers, n_buffers);
}
static int

View file

@ -413,7 +413,7 @@ static int client_node_demarshal_port_use_buffers(void *object, const struct pw_
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
struct spa_pod_frame f;
uint32_t direction, port_id, mix_id, n_buffers, data_id;
uint32_t direction, port_id, mix_id, flags, n_buffers, data_id;
struct pw_client_node_buffer *buffers;
uint32_t i, j;
@ -423,6 +423,7 @@ static int client_node_demarshal_port_use_buffers(void *object, const struct pw_
SPA_POD_Int(&direction),
SPA_POD_Int(&port_id),
SPA_POD_Int(&mix_id),
SPA_POD_Int(&flags),
SPA_POD_Int(&n_buffers), NULL) < 0)
return -EINVAL;
@ -469,6 +470,7 @@ static int client_node_demarshal_port_use_buffers(void *object, const struct pw_
direction,
port_id,
mix_id,
flags,
n_buffers, buffers);
return 0;
}
@ -673,6 +675,7 @@ client_node_marshal_port_use_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t mix_id,
uint32_t flags,
uint32_t n_buffers, struct pw_client_node_buffer *buffers)
{
struct pw_resource *resource = object;
@ -687,6 +690,7 @@ client_node_marshal_port_use_buffers(void *object,
SPA_POD_Int(direction),
SPA_POD_Int(port_id),
SPA_POD_Int(mix_id),
SPA_POD_Int(flags),
SPA_POD_Int(n_buffers), NULL);
for (i = 0; i < n_buffers; i++) {

View file

@ -496,7 +496,7 @@ static int clear_buffers(struct node_data *data, struct mix *mix)
int res;
pw_log_debug("port %p: clear buffers mix:%d", port, mix->mix_id);
if ((res = pw_port_use_buffers(port, mix->mix_id, NULL, 0)) < 0) {
if ((res = pw_port_use_buffers(port, mix->mix_id, 0, NULL, 0)) < 0) {
pw_log_error("port %p: error clear buffers %s", port, spa_strerror(res));
return res;
}
@ -553,6 +553,7 @@ error_exit:
static int
client_node_port_use_buffers(void *object,
enum spa_direction direction, uint32_t port_id, uint32_t mix_id,
uint32_t flags,
uint32_t n_buffers, struct pw_client_node_buffer *buffers)
{
struct pw_proxy *proxy = object;
@ -666,7 +667,7 @@ client_node_port_use_buffers(void *object,
bufs[i] = b;
}
if ((res = pw_port_use_buffers(mix->port, mix->mix_id, bufs, n_buffers)) < 0)
if ((res = pw_port_use_buffers(mix->port, mix->mix_id, flags, bufs, n_buffers)) < 0)
goto error_exit_cleanup;
return res;

View file

@ -561,6 +561,7 @@ static int do_allocation(struct pw_link *this)
char *error = NULL;
struct pw_port *input, *output;
struct allocation allocation = { NULL, };
bool in_use, out_use;
if (this->info.state > PW_LINK_STATE_ALLOCATING)
return 0;
@ -574,6 +575,7 @@ static int do_allocation(struct pw_link *this)
in_flags = input->spa_flags;
out_flags = output->spa_flags;
in_use = out_use = true;
pw_log_debug("link %p: doing alloc buffers %p %p: in_flags:%08x out_flags:%08x",
this, output->node, input->node, in_flags, out_flags);
@ -683,18 +685,19 @@ static int do_allocation(struct pw_link *this)
goto error;
}
out_res = res;
SPA_FLAG_UNSET(out_flags, SPA_PORT_FLAG_CAN_USE_BUFFERS);
out_use = false;
move_allocation(&allocation, &output->allocation);
pw_log_debug("link %p: allocated %d buffers %p from output port", this,
allocation.n_buffers, allocation.buffers);
}
}
if (out_flags & SPA_PORT_FLAG_CAN_USE_BUFFERS) {
if (out_use) {
pw_log_debug("link %p: using %d buffers %p on output port", this,
allocation.n_buffers, allocation.buffers);
if ((res = pw_port_use_buffers(output,
this->rt.out_mix.port.port_id,
0,
allocation.buffers,
allocation.n_buffers)) < 0) {
asprintf(&error, "link %p: error use output buffers: %s", this,
@ -704,11 +707,12 @@ static int do_allocation(struct pw_link *this)
out_res = res;
move_allocation(&allocation, &output->allocation);
}
if (in_flags & SPA_PORT_FLAG_CAN_USE_BUFFERS) {
if (in_use) {
pw_log_debug("link %p: using %d buffers %p on input port", this,
allocation.n_buffers, allocation.buffers);
if ((res = pw_port_use_buffers(input,
this->rt.in_mix.port.port_id,
0,
allocation.buffers,
allocation.n_buffers)) < 0) {
asprintf(&error, "link %p: error use input buffers: %s", this,
@ -875,7 +879,7 @@ static void clear_port_buffers(struct pw_link *link, struct pw_port *port)
else
mix = &link->rt.in_mix;
if ((res = pw_port_use_buffers(port, mix->port.port_id, NULL, 0)) < 0)
if ((res = pw_port_use_buffers(port, mix->port.port_id, 0, NULL, 0)) < 0)
pw_log_warn("link %p: port %p clear error %s", link, port, spa_strerror(res));
}

View file

@ -1024,7 +1024,7 @@ int pw_port_set_param(struct pw_port *port, uint32_t id, uint32_t flags,
}
SPA_EXPORT
int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id,
int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id, uint32_t flags,
struct spa_buffer **buffers, uint32_t n_buffers)
{
int res = 0;
@ -1045,7 +1045,7 @@ int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id,
{
res = spa_node_port_use_buffers(port->mix,
mix->port.direction, mix->port.port_id,
mix->port.direction, mix->port.port_id, flags,
buffers, n_buffers);
if (res == -ENOTSUP)
res = 0;
@ -1063,7 +1063,8 @@ int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id,
pw_log_debug("port %p: use buffers on node: %p", port,
node->node);
res = spa_node_port_use_buffers(node->node,
port->direction, port->port_id, buffers, n_buffers);
port->direction, port->port_id,
flags, buffers, n_buffers);
if (res < 0)
pw_log_error("port %p: use buffers on node: %d (%s)",
port, res, spa_strerror(res));
@ -1071,7 +1072,7 @@ int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id,
port->allocated = false;
free_allocation(&port->allocation);
res = pw_port_call_use_buffers(port, buffers, n_buffers);
res = pw_port_call_use_buffers(port, flags, buffers, n_buffers);
}
if (n_buffers > 0 && !SPA_RESULT_IS_ASYNC(res)) {

View file

@ -476,7 +476,7 @@ struct pw_port_implementation {
int (*init_mix) (void *data, struct pw_port_mix *mix);
int (*release_mix) (void *data, struct pw_port_mix *mix);
int (*use_buffers) (void *data, struct spa_buffer **buffers, uint32_t n_buffers);
int (*use_buffers) (void *data, uint32_t flags, struct spa_buffer **buffers, uint32_t n_buffers);
int (*alloc_buffers) (void *data, struct spa_pod **params, uint32_t n_params,
struct spa_buffer **buffers, uint32_t *n_buffers);
};
@ -492,7 +492,7 @@ struct pw_port_implementation {
#define pw_port_call_init_mix(p,m) pw_port_call(p,init_mix,0,m)
#define pw_port_call_release_mix(p,m) pw_port_call(p,release_mix,0,m)
#define pw_port_call_use_buffers(p,b,n) pw_port_call(p,use_buffers,0,b,n)
#define pw_port_call_use_buffers(p,f,b,n) pw_port_call(p,use_buffers,0,f,b,n)
#define pw_port_call_alloc_buffers(p,pp,np,b,n) pw_port_call(p,alloc_buffers,0,pp,np,b,n)
#define pw_port_emit(o,m,v,...) spa_hook_list_call(&o->listener_list, struct pw_port_events, m, v, ##__VA_ARGS__)
@ -876,7 +876,7 @@ int pw_port_set_param(struct pw_port *port,
uint32_t id, uint32_t flags, const struct spa_pod *param);
/** Use buffers on a port \memberof pw_port */
int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id,
int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id, uint32_t flags,
struct spa_buffer **buffers, uint32_t n_buffers);
/** Allocate memory for buffers on a port \memberof pw_port */

View file

@ -385,7 +385,7 @@ static void emit_port_info(struct stream *d)
info = SPA_PORT_INFO_INIT();
info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS;
info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS;
info.flags = 0;
info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
info.params = d->params;
info.n_params = 5;
@ -601,12 +601,14 @@ static void clear_buffers(struct pw_stream *stream)
clear_queue(impl, &impl->queued);
}
static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id,
struct spa_buffer **buffers, uint32_t n_buffers)
static int impl_port_use_buffers(void *object,
enum spa_direction direction, uint32_t port_id,
uint32_t flags,
struct spa_buffer **buffers, uint32_t n_buffers)
{
struct stream *impl = object;
struct pw_stream *stream = &impl->this;
uint32_t i, j, flags = impl->flags;
uint32_t i, j, impl_flags = impl->flags;
int prot, res;
int size = 0;
@ -621,7 +623,7 @@ static int impl_port_use_buffers(void *object, enum spa_direction direction, uin
b->flags = 0;
b->id = i;
if (SPA_FLAG_CHECK(flags, PW_STREAM_FLAG_MAP_BUFFERS)) {
if (SPA_FLAG_CHECK(impl_flags, PW_STREAM_FLAG_MAP_BUFFERS)) {
for (j = 0; j < buffers[i]->n_datas; j++) {
struct spa_data *d = &buffers[i]->datas[j];
if (d->type == SPA_DATA_MemFd ||