mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
node: make add_listener method
Make struct spa_node_events for events emited from the main thread and keep the spa_node_callbacks for the data thread callbacks. The add_listener method installs the events and it's possible to install multiple handles. Adding a listener first emits the info and port_info events when installed, similar to how the PipeWire proxy bind works. This removes the need for the spa_pending_queue and makes it easier to implement the _sync versions. Add some helpers to make it easier for plugins to emit all the info to new listeners. Use the listeners for devices as well.
This commit is contained in:
parent
61ce4e77f6
commit
0390969228
53 changed files with 1774 additions and 1307 deletions
|
|
@ -76,6 +76,7 @@ struct port {
|
|||
struct spa_io_buffers *io;
|
||||
struct spa_io_range *range;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_port_info info;
|
||||
struct spa_param_info params[8];
|
||||
|
||||
|
|
@ -95,11 +96,11 @@ struct impl {
|
|||
|
||||
struct spa_log *log;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_node_info info;
|
||||
struct spa_param_info params[8];
|
||||
|
||||
const struct spa_node_callbacks *callbacks;
|
||||
void *user_data;
|
||||
struct spa_hook_list hooks;
|
||||
|
||||
uint32_t port_count;
|
||||
uint32_t last_port;
|
||||
|
|
@ -163,43 +164,58 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void emit_node_info(struct impl *this)
|
||||
static void emit_node_info(struct impl *this, bool full)
|
||||
{
|
||||
if (this->callbacks && this->callbacks->info && this->info.change_mask) {
|
||||
this->callbacks->info(this->user_data, &this->info);
|
||||
if (full)
|
||||
this->info.change_mask = this->info_all;
|
||||
if (this->info.change_mask) {
|
||||
spa_node_emit_info(&this->hooks, &this->info);
|
||||
this->info.change_mask = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void emit_port_info(struct impl *this, struct port *port)
|
||||
static void emit_port_info(struct impl *this, struct port *port, bool full)
|
||||
{
|
||||
if (this->callbacks && this->callbacks->port_info && port->info.change_mask) {
|
||||
this->callbacks->port_info(this->user_data, port->direction, port->id, &port->info);
|
||||
if (full)
|
||||
port->info.change_mask = port->info_all;
|
||||
if (port->info.change_mask) {
|
||||
spa_node_emit_port_info(&this->hooks,
|
||||
port->direction, port->id, &port->info);
|
||||
port->info.change_mask = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int impl_node_add_listener(struct spa_node *node,
|
||||
struct spa_hook *listener,
|
||||
const struct spa_node_events *events,
|
||||
void *data)
|
||||
{
|
||||
struct impl *this;
|
||||
struct spa_hook_list save;
|
||||
uint32_t i;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
|
||||
|
||||
emit_node_info(this, true);
|
||||
emit_port_info(this, GET_OUT_PORT(this, 0), true);
|
||||
for (i = 0; i < this->last_port; i++) {
|
||||
if (this->in_ports[i].valid)
|
||||
emit_port_info(this, GET_IN_PORT(this, i), true);
|
||||
}
|
||||
|
||||
spa_hook_list_join(&this->hooks, &save);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
impl_node_set_callbacks(struct spa_node *node,
|
||||
const struct spa_node_callbacks *callbacks,
|
||||
void *user_data)
|
||||
{
|
||||
struct impl *this;
|
||||
uint32_t i;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
|
||||
this->callbacks = callbacks;
|
||||
this->user_data = user_data;
|
||||
|
||||
emit_node_info(this);
|
||||
emit_port_info(this, GET_OUT_PORT(this, 0));
|
||||
for (i = 0; i < this->last_port; i++) {
|
||||
if (this->in_ports[i].valid)
|
||||
emit_port_info(this, GET_IN_PORT(this, i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -222,13 +238,13 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio
|
|||
port_props_reset(&port->props);
|
||||
|
||||
spa_list_init(&port->queue);
|
||||
port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
|
||||
SPA_PORT_CHANGE_MASK_PARAMS;
|
||||
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_REMOVABLE |
|
||||
SPA_PORT_FLAG_OPTIONAL |
|
||||
SPA_PORT_FLAG_IN_PLACE;
|
||||
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);
|
||||
port->params[2] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ);
|
||||
|
|
@ -243,7 +259,7 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio
|
|||
port->valid = true;
|
||||
|
||||
spa_log_info(this->log, NAME " %p: add port %d %d", this, port_id, this->last_port);
|
||||
emit_port_info(this, port);
|
||||
emit_port_info(this, port, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -281,8 +297,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
|
|||
}
|
||||
spa_log_info(this->log, NAME " %p: remove port %d %d", this, port_id, this->last_port);
|
||||
|
||||
if (this->callbacks && this->callbacks->port_info)
|
||||
this->callbacks->port_info(this->user_data, direction, port_id, NULL);
|
||||
spa_node_emit_port_info(&this->hooks, direction, port_id, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -335,7 +350,6 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
|||
spa_return_val_if_fail(num != 0, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
spa_return_val_if_fail(this->callbacks && this->callbacks->result, -EIO);
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
|
|
@ -425,8 +439,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
|||
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
||||
goto next;
|
||||
|
||||
if ((res = this->callbacks->result(this->user_data, seq, 0, &result)) != 0)
|
||||
return res;
|
||||
spa_node_emit_result(&this->hooks, seq, 0, &result);
|
||||
|
||||
if (++count != num)
|
||||
goto next;
|
||||
|
|
@ -521,16 +534,15 @@ static int port_set_format(struct spa_node *node,
|
|||
this, direction, port_id);
|
||||
}
|
||||
}
|
||||
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
||||
if (port->have_format) {
|
||||
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
||||
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
|
||||
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
|
||||
} else {
|
||||
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
||||
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
||||
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
||||
}
|
||||
emit_port_info(this, port);
|
||||
emit_port_info(this, port, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -830,11 +842,12 @@ static int impl_node_process(struct spa_node *node)
|
|||
|
||||
static const struct spa_node impl_node = {
|
||||
SPA_VERSION_NODE,
|
||||
.add_listener = impl_node_add_listener,
|
||||
.set_callbacks = impl_node_set_callbacks,
|
||||
.enum_params = impl_node_enum_params,
|
||||
.set_param = impl_node_set_param,
|
||||
.set_io = impl_node_set_io,
|
||||
.send_command = impl_node_send_command,
|
||||
.set_callbacks = impl_node_set_callbacks,
|
||||
.add_port = impl_node_add_port,
|
||||
.remove_port = impl_node_remove_port,
|
||||
.port_enum_params = impl_node_port_enum_params,
|
||||
|
|
@ -899,6 +912,8 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this->log = support[i].data;
|
||||
}
|
||||
|
||||
spa_hook_list_init(&this->hooks);
|
||||
|
||||
this->node = impl_node;
|
||||
this->info = SPA_NODE_INFO_INIT();
|
||||
this->info.max_input_ports = MAX_PORTS;
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ struct node {
|
|||
struct spa_log *log;
|
||||
struct spa_loop *data_loop;
|
||||
|
||||
struct spa_hook_list hooks;
|
||||
const struct spa_node_callbacks *callbacks;
|
||||
void *callbacks_data;
|
||||
struct io ios[MAX_IO];
|
||||
|
|
@ -363,13 +364,11 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
|
|||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_result_node_params result;
|
||||
uint32_t count = 0;
|
||||
int res;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(num != 0, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct node, node);
|
||||
spa_return_val_if_fail(this->callbacks && this->callbacks->result, -EIO);
|
||||
|
||||
result.id = id;
|
||||
result.next = start;
|
||||
|
|
@ -391,8 +390,7 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
|
|||
continue;
|
||||
|
||||
pw_log_debug("client-node %p: %d param %u", this, seq, result.index);
|
||||
if ((res = this->callbacks->result(this->callbacks_data, seq, 0, &result)) != 0)
|
||||
return res;
|
||||
spa_node_emit_result(&this->hooks, seq, 0, &result);
|
||||
|
||||
if (++count == num)
|
||||
break;
|
||||
|
|
@ -481,27 +479,24 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
|
||||
static void emit_port_info(struct node *this, struct port *port)
|
||||
{
|
||||
if (this->callbacks && this->callbacks->port_info)
|
||||
this->callbacks->port_info(this->callbacks_data,
|
||||
spa_node_emit_port_info(&this->hooks,
|
||||
port->direction, port->id, &port->info);
|
||||
}
|
||||
|
||||
static int
|
||||
impl_node_set_callbacks(struct spa_node *node,
|
||||
const struct spa_node_callbacks *callbacks,
|
||||
void *data)
|
||||
static int impl_node_add_listener(struct spa_node *node,
|
||||
struct spa_hook *listener,
|
||||
const struct spa_node_events *events,
|
||||
void *data)
|
||||
{
|
||||
struct node *this;
|
||||
struct spa_hook_list save;
|
||||
uint32_t i;
|
||||
int res = 0;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct node, node);
|
||||
this->callbacks = callbacks;
|
||||
this->callbacks_data = data;
|
||||
|
||||
pw_log_debug("client-node %p: callbacks %p", this, callbacks);
|
||||
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
|
||||
|
||||
for (i = 0; i < MAX_INPUTS; i++) {
|
||||
if (this->in_ports[i])
|
||||
|
|
@ -511,12 +506,30 @@ impl_node_set_callbacks(struct spa_node *node,
|
|||
if (this->out_ports[i])
|
||||
emit_port_info(this, this->out_ports[i]);
|
||||
}
|
||||
if (callbacks && this->resource)
|
||||
if (this->resource)
|
||||
res = pw_resource_sync(this->resource, 0);
|
||||
|
||||
spa_hook_list_join(&this->hooks, &save);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
impl_node_set_callbacks(struct spa_node *node,
|
||||
const struct spa_node_callbacks *callbacks,
|
||||
void *data)
|
||||
{
|
||||
struct node *this;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct node, node);
|
||||
this->callbacks = callbacks;
|
||||
this->callbacks_data = data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
impl_node_sync(struct spa_node *node, int seq)
|
||||
{
|
||||
|
|
@ -561,6 +574,8 @@ do_update_port(struct node *this,
|
|||
pw_properties_free(port->properties);
|
||||
port->properties = NULL;
|
||||
port->info.props = NULL;
|
||||
port->info.n_params = 0;
|
||||
port->info.params = NULL;
|
||||
|
||||
if (info) {
|
||||
port->info = *info;
|
||||
|
|
@ -603,8 +618,7 @@ clear_port(struct node *this, struct port *port)
|
|||
this->n_outputs--;
|
||||
}
|
||||
}
|
||||
if (this->callbacks && this->callbacks->port_info)
|
||||
this->callbacks->port_info(this->callbacks_data, port->direction, port->id, NULL);
|
||||
spa_node_emit_port_info(&this->hooks, port->direction, port->id, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -646,13 +660,11 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
|||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_result_node_params result;
|
||||
uint32_t count = 0;
|
||||
int res;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(num != 0, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct node, node);
|
||||
spa_return_val_if_fail(this->callbacks && this->callbacks->result, -EIO);
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
|
|
@ -681,8 +693,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
|||
continue;
|
||||
|
||||
pw_log_debug("client-node %p: %d param %u", this, seq, result.index);
|
||||
if ((res = this->callbacks->result(this->callbacks_data, seq, 0, &result)) != 0)
|
||||
return res;
|
||||
spa_node_emit_result(&this->hooks, seq, 0, &result);
|
||||
|
||||
if (++count == num)
|
||||
break;
|
||||
|
|
@ -1056,9 +1067,8 @@ client_node_port_update(void *data,
|
|||
n_params, params,
|
||||
info);
|
||||
|
||||
if (this->callbacks && this->callbacks->port_info &&
|
||||
info && (change_mask & PW_CLIENT_NODE_PORT_UPDATE_INFO))
|
||||
this->callbacks->port_info(this->callbacks_data, direction, port_id, info);
|
||||
if (info && (change_mask & PW_CLIENT_NODE_PORT_UPDATE_INFO))
|
||||
spa_node_emit_port_info(&this->hooks, direction, port_id, info);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1073,8 +1083,7 @@ static int client_node_event(void *data, struct spa_event *event)
|
|||
{
|
||||
struct impl *impl = data;
|
||||
struct node *this = &impl->node;
|
||||
if (this->callbacks && this->callbacks->event)
|
||||
this->callbacks->event(this->callbacks_data, event);
|
||||
spa_node_emit_event(&this->hooks, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1110,6 +1119,7 @@ static void node_on_data_fd_events(struct spa_source *source)
|
|||
static const struct spa_node impl_node = {
|
||||
SPA_VERSION_NODE,
|
||||
NULL,
|
||||
.add_listener = impl_node_add_listener,
|
||||
.set_callbacks = impl_node_set_callbacks,
|
||||
.sync = impl_node_sync,
|
||||
.enum_params = impl_node_enum_params,
|
||||
|
|
@ -1153,6 +1163,7 @@ node_init(struct node *this,
|
|||
}
|
||||
|
||||
this->node = impl_node;
|
||||
spa_hook_list_init(&this->hooks);
|
||||
spa_list_init(&this->pending_list);
|
||||
|
||||
init_ios(this->ios);
|
||||
|
|
@ -1222,7 +1233,7 @@ static void client_node_resource_error(void *data, int seq, int res, const char
|
|||
|
||||
pw_log_error("client-node %p: error seq:%d %d (%s)", this, seq, res, message);
|
||||
result.message = message;
|
||||
this->callbacks->result(this->callbacks_data, seq, res, &result);
|
||||
spa_node_emit_result(&this->hooks, seq, res, &result);
|
||||
}
|
||||
|
||||
static void client_node_resource_done(void *data, int seq)
|
||||
|
|
@ -1231,7 +1242,7 @@ static void client_node_resource_done(void *data, int seq)
|
|||
struct node *this = &impl->node;
|
||||
|
||||
pw_log_debug("client-node %p: emit result %d", this, seq);
|
||||
this->callbacks->result(this->callbacks_data, seq, 0, NULL);
|
||||
spa_node_emit_result(&this->hooks, seq, 0, NULL);
|
||||
}
|
||||
|
||||
void pw_client_node_registered(struct pw_client_node *this, uint32_t node_id)
|
||||
|
|
|
|||
|
|
@ -67,8 +67,7 @@ struct node {
|
|||
|
||||
struct spa_log *log;
|
||||
|
||||
const struct spa_node_callbacks *callbacks;
|
||||
void *callbacks_data;
|
||||
struct spa_hook_list hooks;
|
||||
};
|
||||
|
||||
struct impl {
|
||||
|
|
@ -87,6 +86,7 @@ struct impl {
|
|||
|
||||
struct spa_node *cnode;
|
||||
struct spa_node *adapter;
|
||||
struct spa_hook adapter_listener;
|
||||
struct spa_node *adapter_mix;
|
||||
uint32_t adapter_mix_flags;
|
||||
uint32_t adapter_mix_port;
|
||||
|
|
@ -103,8 +103,6 @@ struct impl {
|
|||
struct spa_buffer **buffers;
|
||||
uint32_t n_buffers;
|
||||
struct pw_memblock *mem;
|
||||
|
||||
struct spa_pending client_node_pending;
|
||||
};
|
||||
|
||||
/** \endcond */
|
||||
|
|
@ -126,7 +124,6 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
|
|||
spa_return_val_if_fail(num != 0, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct node, node);
|
||||
spa_return_val_if_fail(this->callbacks && this->callbacks->result, -EIO);
|
||||
impl = this->impl;
|
||||
|
||||
result.id = id;
|
||||
|
|
@ -142,8 +139,7 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
|
|||
return 0;
|
||||
|
||||
if ((res = spa_node_enum_params_sync(impl->adapter,
|
||||
id, &start, filter, ¶m, &b,
|
||||
impl->this.node->pending)) != 1)
|
||||
id, &start, filter, ¶m, &b)) != 1)
|
||||
return res;
|
||||
break;
|
||||
|
||||
|
|
@ -151,8 +147,7 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
|
|||
case SPA_PARAM_Format:
|
||||
if ((res = spa_node_port_enum_params_sync(impl->cnode,
|
||||
impl->direction, 0,
|
||||
id, &start, filter, ¶m, &b,
|
||||
impl->client_node->node->pending)) != 1)
|
||||
id, &start, filter, ¶m, &b)) != 1)
|
||||
return res;
|
||||
break;
|
||||
|
||||
|
|
@ -163,8 +158,7 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
|
|||
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
||||
goto next;
|
||||
|
||||
if ((res = this->callbacks->result(this->callbacks_data, seq, 0, &result)) != 0)
|
||||
return res;
|
||||
spa_node_emit_result(&this->hooks, seq, 0, &result);
|
||||
|
||||
if (++count != num)
|
||||
goto next;
|
||||
|
|
@ -221,7 +215,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
|
|||
if (impl->started)
|
||||
return -EIO;
|
||||
pw_log_debug("set profile %d", id);
|
||||
if (impl->adapter != impl->cnode) {
|
||||
if (impl->adapter && impl->adapter != impl->cnode) {
|
||||
if ((res = spa_node_set_param(impl->adapter, id, flags, param)) < 0)
|
||||
return res;
|
||||
|
||||
|
|
@ -229,7 +223,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
|
|||
}
|
||||
break;
|
||||
case SPA_PARAM_Props:
|
||||
if (impl->adapter != impl->cnode) {
|
||||
if (impl->adapter && impl->adapter != impl->cnode) {
|
||||
if ((res = spa_node_set_param(impl->adapter, id, flags, param)) < 0)
|
||||
return res;
|
||||
}
|
||||
|
|
@ -292,44 +286,73 @@ static int adapter_port_info(void *data,
|
|||
struct impl *impl = data;
|
||||
struct node *this = &impl->node;
|
||||
|
||||
if (this->callbacks && this->callbacks->port_info) {
|
||||
if (direction == impl->direction) {
|
||||
this->callbacks->port_info(this->callbacks_data, direction, port_id, info);
|
||||
}
|
||||
}
|
||||
if (direction == impl->direction)
|
||||
spa_node_emit_port_info(&this->hooks, direction, port_id, info);
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int adapter_result(void *data, int seq, int res, const void *result)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct node *this = &impl->node;
|
||||
return this->callbacks->result(this->callbacks_data, seq, res, result);
|
||||
pw_log_debug("%p: result %d %d", this, seq, res);
|
||||
spa_node_emit_result(&this->hooks, seq, res, result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spa_node_callbacks adapter_node_callbacks = {
|
||||
SPA_VERSION_NODE_CALLBACKS,
|
||||
static const struct spa_node_events adapter_node_events = {
|
||||
SPA_VERSION_NODE_EVENTS,
|
||||
.port_info = adapter_port_info,
|
||||
.result = adapter_result,
|
||||
};
|
||||
|
||||
static void emit_node_info(struct node *this)
|
||||
{
|
||||
if (this->callbacks && this->callbacks->info) {
|
||||
struct spa_node_info info;
|
||||
struct spa_param_info params[4];
|
||||
struct spa_node_info info;
|
||||
struct spa_param_info params[4];
|
||||
|
||||
info = SPA_NODE_INFO_INIT();
|
||||
info.max_input_ports = 0;
|
||||
info.max_output_ports = 0;
|
||||
info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS;
|
||||
params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
||||
params[1] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_READWRITE);
|
||||
params[2] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READ);
|
||||
params[3] = SPA_PARAM_INFO(SPA_PARAM_Profile, SPA_PARAM_INFO_WRITE);
|
||||
info.params = params;
|
||||
info.n_params = 4;
|
||||
this->callbacks->info(this->callbacks_data, &info);
|
||||
info = SPA_NODE_INFO_INIT();
|
||||
info.max_input_ports = 0;
|
||||
info.max_output_ports = 0;
|
||||
info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS;
|
||||
params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
||||
params[1] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_READWRITE);
|
||||
params[2] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READ);
|
||||
params[3] = SPA_PARAM_INFO(SPA_PARAM_Profile, SPA_PARAM_INFO_WRITE);
|
||||
info.params = params;
|
||||
info.n_params = 4;
|
||||
spa_node_emit_info(&this->hooks, &info);
|
||||
}
|
||||
|
||||
static int impl_node_add_listener(struct spa_node *node,
|
||||
struct spa_hook *listener,
|
||||
const struct spa_node_events *events,
|
||||
void *data)
|
||||
{
|
||||
struct node *this;
|
||||
struct impl *impl;
|
||||
struct spa_hook l;
|
||||
struct spa_hook_list save;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct node, node);
|
||||
impl = this->impl;
|
||||
|
||||
pw_log_debug("%p: add listener %p", this, listener);
|
||||
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
|
||||
|
||||
emit_node_info(this);
|
||||
|
||||
if (impl->adapter && impl->adapter != impl->cnode) {
|
||||
spa_zero(l);
|
||||
spa_node_add_listener(impl->adapter, &l, &adapter_node_events, impl);
|
||||
spa_hook_remove(&l);
|
||||
}
|
||||
|
||||
spa_hook_list_join(&this->hooks, &save);
|
||||
|
||||
return spa_node_sync(impl->cnode, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -337,23 +360,7 @@ impl_node_set_callbacks(struct spa_node *node,
|
|||
const struct spa_node_callbacks *callbacks,
|
||||
void *data)
|
||||
{
|
||||
struct node *this;
|
||||
struct impl *impl;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct node, node);
|
||||
impl = this->impl;
|
||||
|
||||
this->callbacks = callbacks;
|
||||
this->callbacks_data = data;
|
||||
|
||||
emit_node_info(this);
|
||||
|
||||
if (this->callbacks && impl->adapter && impl->adapter != impl->cnode)
|
||||
spa_node_set_callbacks(impl->adapter, &adapter_node_callbacks, impl);
|
||||
|
||||
return spa_node_sync(impl->cnode, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -429,7 +436,6 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
|||
spa_return_val_if_fail(num != 0, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct node, node);
|
||||
spa_return_val_if_fail(this->callbacks && this->callbacks->result, -EIO);
|
||||
impl = this->impl;
|
||||
|
||||
if (direction != impl->direction)
|
||||
|
|
@ -459,8 +465,7 @@ static int debug_params(struct impl *impl, struct spa_node *node,
|
|||
res = spa_node_port_enum_params_sync(node,
|
||||
direction, port_id,
|
||||
id, &state,
|
||||
NULL, ¶m, &b,
|
||||
impl->this.node->pending);
|
||||
NULL, ¶m, &b);
|
||||
if (res != 1) {
|
||||
if (res < 0)
|
||||
spa_log_error(this->log, " error: %s", spa_strerror(res));
|
||||
|
|
@ -495,8 +500,7 @@ static int negotiate_format(struct impl *impl)
|
|||
SPA_DIRECTION_REVERSE(impl->direction),
|
||||
impl->adapter_mix_port,
|
||||
SPA_PARAM_EnumFormat, &state,
|
||||
NULL, &format, &b,
|
||||
impl->this.node->pending)) != 1) {
|
||||
NULL, &format, &b)) != 1) {
|
||||
debug_params(impl, impl->adapter_mix,
|
||||
SPA_DIRECTION_REVERSE(impl->direction),
|
||||
impl->adapter_mix_port,
|
||||
|
|
@ -508,8 +512,7 @@ static int negotiate_format(struct impl *impl)
|
|||
if ((res = spa_node_port_enum_params_sync(impl->cnode,
|
||||
impl->direction, 0,
|
||||
SPA_PARAM_EnumFormat, &state,
|
||||
format, &format, &b,
|
||||
impl->client_node->node->pending)) != 1) {
|
||||
format, &format, &b)) != 1) {
|
||||
debug_params(impl, impl->cnode, impl->direction, 0,
|
||||
SPA_PARAM_EnumFormat, format);
|
||||
return -ENOTSUP;
|
||||
|
|
@ -561,8 +564,7 @@ static int negotiate_buffers(struct impl *impl)
|
|||
SPA_DIRECTION_REVERSE(impl->direction),
|
||||
impl->adapter_mix_port,
|
||||
SPA_PARAM_Buffers, &state,
|
||||
param, ¶m, &b,
|
||||
impl->this.node->pending)) != 1) {
|
||||
param, ¶m, &b)) != 1) {
|
||||
debug_params(impl, impl->adapter_mix,
|
||||
SPA_DIRECTION_REVERSE(impl->direction),
|
||||
impl->adapter_mix_port,
|
||||
|
|
@ -576,8 +578,7 @@ static int negotiate_buffers(struct impl *impl)
|
|||
if ((res = spa_node_port_enum_params_sync(impl->cnode,
|
||||
impl->direction, 0,
|
||||
SPA_PARAM_Buffers, &state,
|
||||
param, ¶m, &b,
|
||||
impl->client_node->node->pending)) < 0) {
|
||||
param, ¶m, &b)) < 0) {
|
||||
debug_params(impl, impl->cnode, impl->direction, 0,
|
||||
SPA_PARAM_Buffers, param);
|
||||
return res;
|
||||
|
|
@ -866,6 +867,7 @@ static int impl_node_process(struct spa_node *node)
|
|||
|
||||
static const struct spa_node impl_node = {
|
||||
SPA_VERSION_NODE,
|
||||
.add_listener = impl_node_add_listener,
|
||||
.set_callbacks = impl_node_set_callbacks,
|
||||
.sync = impl_node_sync,
|
||||
.enum_params = impl_node_enum_params,
|
||||
|
|
@ -896,6 +898,8 @@ node_init(struct node *this,
|
|||
this->log = support[i].data;
|
||||
}
|
||||
this->node = impl_node;
|
||||
spa_hook_list_init(&this->hooks);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -910,21 +914,16 @@ static int do_port_info(void *data, struct pw_port *port)
|
|||
info.flags = port->spa_flags;
|
||||
info.props = &port->properties->dict;
|
||||
|
||||
node->callbacks->port_info(node->callbacks_data,
|
||||
spa_node_emit_port_info(&node->hooks,
|
||||
impl->direction, port->port_id, &info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void emit_port_info(struct impl *impl)
|
||||
{
|
||||
struct node *node = &impl->node;
|
||||
|
||||
if (node->callbacks && node->callbacks->port_info) {
|
||||
pw_node_for_each_port(impl->client_node->node,
|
||||
impl->direction,
|
||||
do_port_info,
|
||||
impl);
|
||||
}
|
||||
pw_node_for_each_port(impl->client_node->node,
|
||||
impl->direction,
|
||||
do_port_info, impl);
|
||||
}
|
||||
|
||||
static void client_node_initialized(void *data)
|
||||
|
|
@ -992,8 +991,7 @@ static void client_node_initialized(void *data)
|
|||
if ((res = spa_node_port_enum_params_sync(impl->cnode,
|
||||
impl->direction, 0,
|
||||
SPA_PARAM_EnumFormat, &state,
|
||||
NULL, &format, &b,
|
||||
impl->client_node->node->pending)) != 1) {
|
||||
NULL, &format, &b)) != 1) {
|
||||
pw_log_warn("client-stream %p: no format given", &impl->this);
|
||||
impl->adapter = impl->cnode;
|
||||
impl->adapter_mix = impl->client_port->mix;
|
||||
|
|
@ -1038,8 +1036,8 @@ static void client_node_initialized(void *data)
|
|||
impl->adapter_mix = impl->adapter;
|
||||
impl->adapter_mix_port = 0;
|
||||
impl->use_converter = true;
|
||||
if (impl->node.callbacks != NULL)
|
||||
spa_node_set_callbacks(impl->adapter, &adapter_node_callbacks, impl);
|
||||
spa_node_add_listener(impl->adapter, &impl->adapter_listener,
|
||||
&adapter_node_events, impl);
|
||||
}
|
||||
else {
|
||||
impl->adapter = impl->cnode;
|
||||
|
|
@ -1116,7 +1114,7 @@ static void client_node_result(void *data, int seq, int res, const void *result)
|
|||
struct impl *impl = data;
|
||||
struct node *node = &impl->node;
|
||||
pw_log_debug("client-stream %p: result %d %d", &impl->this, seq, res);
|
||||
node->callbacks->result(node->callbacks_data, seq, res, result);
|
||||
spa_node_emit_result(&node->hooks, seq, res, result);
|
||||
}
|
||||
|
||||
static void client_node_active_changed(void *data, bool active)
|
||||
|
|
|
|||
|
|
@ -420,8 +420,7 @@ static int add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32_
|
|||
if (spa_node_port_enum_params_sync(port->node->node,
|
||||
port->direction, port->port_id,
|
||||
id, &idx2,
|
||||
NULL, ¶m, &b,
|
||||
port->node->pending) != 1)
|
||||
NULL, ¶m, &b) != 1)
|
||||
break;
|
||||
|
||||
params = realloc(params, sizeof(struct spa_pod *) * (n_params + 1));
|
||||
|
|
@ -434,7 +433,7 @@ static int add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32_
|
|||
SPA_PORT_CHANGE_MASK_RATE |
|
||||
SPA_PORT_CHANGE_MASK_PROPS;
|
||||
pi.flags = port->spa_flags;
|
||||
pi.rate = 0;
|
||||
pi.rate = SPA_FRACTION(0, 1);
|
||||
pi.props = &port->properties->dict;
|
||||
pi.flags &= ~SPA_PORT_FLAG_CAN_ALLOC_BUFFERS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,17 +170,6 @@ void *pw_spa_node_get_user_data(struct pw_node *node)
|
|||
return impl->user_data;
|
||||
}
|
||||
|
||||
static int on_node_result(void *data, int seq, int res, const void *result)
|
||||
{
|
||||
struct spa_pending_queue *pending = data;
|
||||
return spa_pending_queue_complete(pending, seq, res, result);
|
||||
}
|
||||
|
||||
static const struct spa_node_callbacks node_callbacks = {
|
||||
SPA_VERSION_NODE_CALLBACKS,
|
||||
.result = on_node_result,
|
||||
};
|
||||
|
||||
static int
|
||||
setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_properties *pw_props)
|
||||
{
|
||||
|
|
@ -192,15 +181,11 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
|
|||
uint8_t buf[2048];
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
|
||||
const struct spa_pod_prop *prop = NULL;
|
||||
struct spa_pending_queue pending;
|
||||
|
||||
spa_pending_queue_init(&pending);
|
||||
|
||||
spa_node_set_callbacks(spa_node, &node_callbacks, &pending);
|
||||
|
||||
if ((res = spa_node_enum_params_sync(spa_node,
|
||||
res = spa_node_enum_params_sync(spa_node,
|
||||
SPA_PARAM_Props, &index, NULL, &props,
|
||||
&b, &pending)) != 1) {
|
||||
&b);
|
||||
if (res != 1) {
|
||||
if (res < 0)
|
||||
pw_log_debug("spa_node_get_props failed: %d", res);
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue