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

@ -97,8 +97,6 @@ struct data {
bool rebuild_fds;
struct pollfd fds[16];
unsigned int n_fds;
struct spa_pending_queue pending;
};
#define MIN_LATENCY 1024
@ -377,8 +375,7 @@ static int negotiate_formats(struct data *data)
if ((res = spa_node_port_enum_params_sync(data->sink,
SPA_DIRECTION_INPUT, 0,
SPA_PARAM_EnumFormat, &state,
filter, &format, &b,
&data->pending)) != 1)
filter, &format, &b)) != 1)
return -EBADF;
spa_log_debug(&default_log.log, "sink set_param");
@ -514,8 +511,6 @@ int main(int argc, char *argv[])
data.data_loop.remove_source = do_remove_source;
data.data_loop.invoke = do_invoke;
spa_pending_queue_init(&data.pending);
if ((str = getenv("SPA_DEBUG")))
data.log->level = atoi(str);

View file

@ -68,6 +68,7 @@ struct data {
uint32_t n_support;
struct spa_node *source;
struct spa_hook listener;
struct spa_io_buffers source_output[1];
SDL_Renderer *renderer;
@ -89,8 +90,6 @@ struct data {
struct spa_buffer *bp[MAX_BUFFERS];
struct buffer buffers[MAX_BUFFERS];
unsigned int n_buffers;
struct spa_pending_queue pending;
};
static int load_handle(struct data *data, struct spa_handle **handle, const char *lib, const char *name)
@ -242,16 +241,9 @@ static int on_source_ready(void *_data, int status)
return 0;
}
static int on_source_result(void *_data, int seq, int res, const void *result)
{
struct data *data = _data;
return spa_pending_queue_complete(&data->pending, seq, res, result);
}
static const struct spa_node_callbacks source_callbacks = {
SPA_VERSION_NODE_CALLBACKS,
.ready = on_source_ready,
.result = on_source_result,
};
static int make_nodes(struct data *data, const char *device)
@ -273,7 +265,7 @@ static int make_nodes(struct data *data, const char *device)
index = 0;
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if ((res = spa_node_enum_params_sync(data->source, SPA_PARAM_Props,
&index, NULL, &props, &b, &data->pending)) == 1) {
&index, NULL, &props, &b)) == 1) {
spa_debug_pod(0, NULL, props);
}
@ -477,8 +469,6 @@ int main(int argc, char *argv[])
struct spa_handle *handle = NULL;
void *iface;
spa_pending_queue_init(&data.pending);
if ((res = load_handle(&data, &handle, PATH "support/libspa-support.so", "loop")) < 0)
return res;