mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04: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
|
|
@ -50,6 +50,10 @@ struct buffer {
|
|||
};
|
||||
|
||||
struct port {
|
||||
enum spa_direction direction;
|
||||
uint32_t id;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_port_info info;
|
||||
struct spa_param_info params[8];
|
||||
|
||||
|
|
@ -71,11 +75,11 @@ struct impl {
|
|||
|
||||
struct spa_log *log;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_node_info info;
|
||||
struct spa_param_info params[2];
|
||||
|
||||
const struct spa_node_callbacks *callbacks;
|
||||
void *user_data;
|
||||
struct spa_hook_list hooks;
|
||||
|
||||
struct port in_ports[1];
|
||||
struct port out_ports[1];
|
||||
|
|
@ -124,43 +128,55 @@ 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, enum spa_direction direction, uint32_t id)
|
||||
static void emit_port_info(struct impl *this, struct port *port, bool full)
|
||||
{
|
||||
struct port *port = GET_PORT(this, direction, id);
|
||||
|
||||
if (this->callbacks && this->callbacks->port_info && port->info.change_mask) {
|
||||
this->callbacks->port_info(this->user_data, direction, 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;
|
||||
|
||||
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_IN_PORT(this, 0), true);
|
||||
emit_port_info(this, GET_OUT_PORT(this, 0), 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;
|
||||
|
||||
if (node == NULL)
|
||||
return -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, SPA_DIRECTION_INPUT, 0);
|
||||
emit_port_info(this, SPA_DIRECTION_OUTPUT, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -267,8 +283,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;
|
||||
|
|
@ -426,11 +441,12 @@ impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t bu
|
|||
|
||||
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,
|
||||
|
|
@ -479,29 +495,35 @@ spa_ffmpeg_dec_init(struct spa_handle *handle,
|
|||
this->log = support[i].data;
|
||||
}
|
||||
|
||||
spa_hook_list_init(&this->hooks);
|
||||
|
||||
this->node = impl_node;
|
||||
this->info_all = SPA_NODE_CHANGE_MASK_FLAGS;
|
||||
this->info = SPA_NODE_INFO_INIT();
|
||||
this->info.max_input_ports = 1;
|
||||
this->info.max_output_ports = 1;
|
||||
this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS;
|
||||
this->info.flags = SPA_NODE_FLAG_RT;
|
||||
this->info.params = this->params;
|
||||
|
||||
port = GET_IN_PORT(this, 0);
|
||||
port->direction = SPA_DIRECTION_INPUT;
|
||||
port->id = 0;
|
||||
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 = 0;
|
||||
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_Format, SPA_PARAM_INFO_WRITE);
|
||||
port->info.params = port->params;
|
||||
port->info.n_params = 2;
|
||||
|
||||
port = GET_OUT_PORT(this, 0);
|
||||
port->direction = SPA_DIRECTION_OUTPUT;
|
||||
port->id = 0;
|
||||
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 = 0;
|
||||
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_Format, SPA_PARAM_INFO_WRITE);
|
||||
port->info.params = port->params;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue