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:
Wim Taymans 2019-03-01 12:00:42 +01:00
parent 61ce4e77f6
commit 0390969228
53 changed files with 1774 additions and 1307 deletions

View file

@ -58,8 +58,7 @@ struct data {
struct spa_node impl_node;
struct spa_io_buffers *io;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook_list hooks;
struct spa_video_info_raw format;
int32_t stride;
@ -90,22 +89,31 @@ static int impl_send_command(struct spa_node *node, const struct spa_command *co
return 0;
}
static int impl_add_listener(struct spa_node *node,
struct spa_hook *listener,
const struct spa_node_events *events,
void *data)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct spa_port_info info;
struct spa_hook_list save;
spa_hook_list_isolate(&d->hooks, &save, listener, events, data);
info = SPA_PORT_INFO_INIT();
info.change_mask = SPA_PORT_CHANGE_MASK_FLAGS;
info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS;
spa_node_emit_port_info(&d->hooks, SPA_DIRECTION_INPUT, 0, &info);
spa_hook_list_join(&d->hooks, &save);
return 0;
}
static int impl_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks, void *data)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
d->callbacks = callbacks;
d->callbacks_data = data;
if (d->callbacks && d->callbacks->port_info) {
struct spa_port_info info;
info = SPA_PORT_INFO_INIT();
info.change_mask = SPA_PORT_CHANGE_MASK_FLAGS;
info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS;
d->callbacks->port_info(d->callbacks_data, SPA_DIRECTION_INPUT, 0, &info);
}
return 0;
}
@ -133,7 +141,6 @@ static int impl_port_enum_params(struct spa_node *node, int seq,
uint8_t buffer[1024];
struct spa_result_node_params result;
uint32_t count = 0;
int res;
result.id = id;
result.next = start;
@ -184,8 +191,7 @@ static int impl_port_enum_params(struct spa_node *node, int seq,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = d->callbacks->result(d->callbacks_data, seq, 0, &result)) != 0)
return res;
spa_node_emit_result(&d->hooks, seq, 0, &result);
if (++count != num)
goto next;
@ -315,9 +321,10 @@ static int impl_node_process(struct spa_node *node)
static const struct spa_node impl_node = {
SPA_VERSION_NODE,
NULL,
.add_listener = impl_add_listener,
.set_callbacks = impl_set_callbacks,
.set_io = impl_set_io,
.send_command = impl_send_command,
.set_callbacks = impl_set_callbacks,
.port_set_io = impl_port_set_io,
.port_enum_params = impl_port_enum_params,
.port_set_param = impl_port_set_param,
@ -367,6 +374,8 @@ int main(int argc, char *argv[])
data.loop = pw_main_loop_new(NULL);
data.core = pw_core_new(pw_main_loop_get_loop(data.loop), NULL, 0);
spa_hook_list_init(&data.hooks);
pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL, NULL, NULL, NULL);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {