summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2019-05-15 11:19:23 +0200
committerWim Taymans <wtaymans@redhat.com>2019-05-15 11:19:23 +0200
commit6ee192dff5a19f95b25b5eaf11be42cf7b9990b5 (patch)
treea7c1630b6681dfc6cbd7f214829d26250d113223
parenta78617c6a82a08027f86a8e388875a6e9735063f (diff)
hooks: use hook to implement the callbacks
This way we get the version check implemented and save some code.
-rw-r--r--spa/include/spa/graph/graph.h22
-rw-r--r--spa/include/spa/monitor/monitor.h11
-rw-r--r--spa/include/spa/node/node.h13
-rw-r--r--spa/include/spa/pod/builder.h21
-rw-r--r--spa/include/spa/utils/hook.h6
-rw-r--r--spa/plugins/alsa/alsa-monitor.c8
-rw-r--r--spa/plugins/alsa/alsa-sink.c3
-rw-r--r--spa/plugins/alsa/alsa-source.c3
-rw-r--r--spa/plugins/alsa/alsa-utils.c8
-rw-r--r--spa/plugins/alsa/alsa-utils.h3
-rw-r--r--spa/plugins/audiotestsrc/audiotestsrc.c8
-rw-r--r--spa/plugins/bluez5/a2dp-sink.c11
-rw-r--r--spa/plugins/bluez5/a2dp-source.c8
-rw-r--r--spa/plugins/bluez5/bluez5-monitor.c10
-rw-r--r--spa/plugins/test/fakesink.c17
-rw-r--r--spa/plugins/test/fakesrc.c18
-rw-r--r--spa/plugins/v4l2/v4l2-monitor.c9
-rw-r--r--spa/plugins/v4l2/v4l2-source.c6
-rw-r--r--spa/plugins/v4l2/v4l2-utils.c2
-rw-r--r--spa/plugins/videotestsrc/videotestsrc.c8
-rw-r--r--spa/tests/test-pod.c2
-rw-r--r--src/gst/gstpipewireformat.c3
-rw-r--r--src/modules/module-client-node/client-node.c9
-rw-r--r--src/modules/module-client-node/client-stream.c8
-rw-r--r--src/modules/module-protocol-native/connection.c7
-rw-r--r--src/pipewire/stream.c8
26 files changed, 121 insertions, 111 deletions
diff --git a/spa/include/spa/graph/graph.h b/spa/include/spa/graph/graph.h
index 5a808d75..068b47ac 100644
--- a/spa/include/spa/graph/graph.h
+++ b/spa/include/spa/graph/graph.h
@@ -31,6 +31,7 @@ extern "C" {
#include <spa/utils/defs.h>
#include <spa/utils/list.h>
+#include <spa/utils/hook.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
@@ -92,8 +93,6 @@ struct spa_graph_node_callbacks {
int (*reuse_buffer) (void *data, struct spa_graph_node *node,
uint32_t port_id, uint32_t buffer_id);
};
-#define spa_graph_node_process(n) ((n)->callbacks->process((n)->callbacks_data,(n)))
-#define spa_graph_node_reuse_buffer(n,p,i) ((n)->callbacks->reuse_buffer((n)->callbacks_data,(n),(p),(i)))
struct spa_graph_node {
struct spa_list link; /**< link in graph nodes list */
@@ -104,11 +103,21 @@ struct spa_graph_node {
struct spa_graph_state *state; /**< state of the node */
struct spa_graph_link graph_link; /**< link in graph */
struct spa_graph *subgraph; /**< subgraph or NULL */
- const struct spa_graph_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
struct spa_list sched_link; /**< link for scheduler */
};
+#define spa_graph_node_call(n,method,version,...) \
+({ \
+ int __res = 0; \
+ spa_hook_call_res(&(n)->callbacks, \
+ struct spa_graph_node_callbacks, __res, \
+ method, version, ##__VA_ARGS__); \
+ __res; \
+})
+
+#define spa_graph_node_process(n) spa_graph_node_call(n, process, 0, n)
+#define spa_graph_node_reuse_buffer(n,p,i) spa_graph_node_call(n, reuse_buffer, 0, n, p, i)
struct spa_graph_port {
struct spa_list link; /**< link in node port list */
@@ -239,10 +248,9 @@ static inline void spa_graph_node_set_subgraph(struct spa_graph_node *node,
static inline void
spa_graph_node_set_callbacks(struct spa_graph_node *node,
const struct spa_graph_node_callbacks *callbacks,
- void *callbacks_data)
+ void *data)
{
- node->callbacks = callbacks;
- node->callbacks_data = callbacks_data;
+ node->callbacks = SPA_HOOK_INIT(callbacks, data);
}
static inline void
diff --git a/spa/include/spa/monitor/monitor.h b/spa/include/spa/monitor/monitor.h
index bbf244c0..f7f7da2b 100644
--- a/spa/include/spa/monitor/monitor.h
+++ b/spa/include/spa/monitor/monitor.h
@@ -86,6 +86,17 @@ struct spa_monitor_callbacks {
int (*event) (void *data, struct spa_event *event);
};
+#define spa_monitor_call(hook,method,version,...) \
+({ \
+ int __res = 0; \
+ spa_hook_call_res(hook, struct spa_monitor_callbacks, __res, \
+ method, version, ##__VA_ARGS__); \
+ __res; \
+})
+
+#define spa_monitor_call_info(hook,i) spa_monitor_call(hook, info, 0, i)
+#define spa_monitor_call_event(hook,e) spa_monitor_call(hook, event, 0, e)
+
/**
* spa_monitor:
*
diff --git a/spa/include/spa/node/node.h b/spa/include/spa/node/node.h
index f2232da7..ba7fc317 100644
--- a/spa/include/spa/node/node.h
+++ b/spa/include/spa/node/node.h
@@ -182,6 +182,7 @@ struct spa_node_events {
*/
struct spa_node_callbacks {
#define SPA_VERSION_NODE_CALLBACKS 0
+ uint32_t version;
/**
* \param node a spa_node
*
@@ -207,6 +208,18 @@ struct spa_node_callbacks {
uint32_t buffer_id);
};
+#define spa_node_call(hook,method,version,...) \
+({ \
+ int __res = 0; \
+ spa_hook_call_res(hook, struct spa_node_callbacks, __res, \
+ method, version, ##__VA_ARGS__); \
+ __res; \
+})
+
+#define spa_node_call_ready(hook,s) spa_node_call(hook, ready, 0, s)
+#define spa_node_call_reuse_buffer(hook,p,b) spa_node_call(hook, reuse_buffer, 0, p, b)
+
+
/** flags that can be passed to set_param and port_set_param functions */
#define SPA_NODE_PARAM_FLAG_TEST_ONLY (1 << 0) /* just check if the param is accepted */
#define SPA_NODE_PARAM_FLAG_FIXATE (1 << 1) /* fixate the non-optional unset fields */
diff --git a/spa/include/spa/pod/builder.h b/spa/include/spa/pod/builder.h
index b3b0f558..eb57b5d8 100644
--- a/spa/include/spa/pod/builder.h
+++ b/spa/include/spa/pod/builder.h
@@ -31,6 +31,7 @@ extern "C" {
#include <stdarg.h>
+#include <spa/utils/hook.h>
#include <spa/pod/iter.h>
#include <spa/pod/vararg.h>
@@ -47,7 +48,8 @@ struct spa_pod_builder;
struct spa_pod_builder_callbacks {
#define SPA_VERSION_POD_BUILDER_CALLBACKS 0
uint32_t version;
- int (*overflow) (void *callbacks_data, uint32_t size);
+
+ int (*overflow) (void *data, uint32_t size);
};
struct spa_pod_builder {
@@ -55,8 +57,7 @@ struct spa_pod_builder {
uint32_t size;
uint32_t _padding;
struct spa_pod_builder_state state;
- const struct spa_pod_builder_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
};
#define SPA_POD_BUILDER_INIT(buffer,size) (struct spa_pod_builder){ buffer, size, }
@@ -68,6 +69,13 @@ spa_pod_builder_get_state(struct spa_pod_builder *builder, struct spa_pod_builde
}
static inline void
+spa_pod_builder_set_callbacks(struct spa_pod_builder *builder,
+ const struct spa_pod_builder_callbacks *callbacks, void *data)
+{
+ builder->callbacks = SPA_HOOK_INIT(callbacks, data);
+}
+
+static inline void
spa_pod_builder_reset(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
{
builder->state = *state;
@@ -118,10 +126,9 @@ static inline int spa_pod_builder_raw(struct spa_pod_builder *builder, const voi
uint32_t offset = builder->state.offset;
if (offset + size > builder->size) {
- if (builder->callbacks && builder->callbacks->overflow)
- res = builder->callbacks->overflow(builder->callbacks_data, offset + size);
- else
- res = -ENOSPC;
+ res = -ENOSPC;
+ spa_hook_call_res(&builder->callbacks, struct spa_pod_builder_callbacks, res,
+ overflow, 0, offset + size);
}
if (res == 0)
memcpy(SPA_MEMBER(builder->data, offset, void), data, size);
diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h
index 3927a59e..f29f42f7 100644
--- a/spa/include/spa/utils/hook.h
+++ b/spa/include/spa/utils/hook.h
@@ -112,14 +112,14 @@ spa_hook_list_join(struct spa_hook_list *list,
#define spa_hook_call(hook,type,method,vers,...) \
({ \
- const type *cb = (hook)->funcs; \
+ const type *cb = (const type *) (hook)->funcs; \
if (cb && cb->version >= vers && cb->method) \
cb->method((hook)->data, ## __VA_ARGS__); \
})
#define spa_hook_call_res(hook,type,res,method,vers,...) \
({ \
- const type *cb = (hook)->funcs; \
+ const type *cb = (const type *) (hook)->funcs; \
if (cb && cb->version >= vers && cb->method) \
res = cb->method((hook)->data, ## __VA_ARGS__); \
res; \
@@ -144,7 +144,7 @@ spa_hook_list_join(struct spa_hook_list *list,
int count = 0; \
spa_list_cursor_start(cursor, s, link); \
spa_list_for_each_cursor(ci, cursor, &list->list, link) { \
- const type *cb = ci->funcs; \
+ const type *cb = (const type *)ci->funcs; \
if (cb && cb->version >= vers && cb->method) { \
cb->method(ci->data, ## __VA_ARGS__); \
count++; \
diff --git a/spa/plugins/alsa/alsa-monitor.c b/spa/plugins/alsa/alsa-monitor.c
index d034752e..be308af2 100644
--- a/spa/plugins/alsa/alsa-monitor.c
+++ b/spa/plugins/alsa/alsa-monitor.c
@@ -51,8 +51,7 @@ struct impl {
struct spa_log *log;
struct spa_loop *main_loop;
- const struct spa_monitor_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
struct udev *udev;
struct udev_monitor *umonitor;
@@ -266,7 +265,7 @@ static int emit_device(struct impl *this, uint32_t id, struct udev_device *dev)
event = spa_pod_builder_add_object(&b, SPA_TYPE_EVENT_Monitor, id);
fill_item(this, dev, &item, &b);
- this->callbacks->event(this->callbacks_data, event);
+ spa_monitor_call_event(&this->callbacks, event);
return 0;
}
@@ -378,8 +377,7 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
if (callbacks) {
if ((res = impl_udev_open(this)) < 0)
diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c
index 652c15ba..a92872ee 100644
--- a/spa/plugins/alsa/alsa-sink.c
+++ b/spa/plugins/alsa/alsa-sink.c
@@ -293,8 +293,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct state, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c
index 8b0d2d7c..6aa3704e 100644
--- a/spa/plugins/alsa/alsa-source.c
+++ b/spa/plugins/alsa/alsa-source.c
@@ -292,8 +292,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct state, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c
index d5a7d24a..647c625f 100644
--- a/spa/plugins/alsa/alsa-utils.c
+++ b/spa/plugins/alsa/alsa-utils.c
@@ -750,7 +750,9 @@ again:
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT);
state->io->buffer_id = b->id;
spa_log_trace_fp(state->log, "alsa-util %p: reuse buffer %u", state, b->id);
- state->callbacks->reuse_buffer(state->callbacks_data, 0, b->id);
+
+ spa_node_call_reuse_buffer(&state->callbacks, 0, b->id);
+
state->ready_offset = 0;
}
written += n_frames;
@@ -953,7 +955,7 @@ static int handle_play(struct state *state, uint64_t nsec, snd_pcm_sframes_t del
state->range->min_size = state->threshold * state->frame_size;
state->range->max_size = state->threshold * state->frame_size;
}
- res = state->callbacks->ready(state->callbacks_data, SPA_STATUS_NEED_BUFFER);
+ res = spa_node_call_ready(&state->callbacks, SPA_STATUS_NEED_BUFFER);
}
else {
res = spa_alsa_write(state, 0);
@@ -987,7 +989,7 @@ static int handle_capture(struct state *state, uint64_t nsec, snd_pcm_sframes_t
io->buffer_id = b->id;
io->status = SPA_STATUS_HAVE_BUFFER;
}
- state->callbacks->ready(state->callbacks_data, SPA_STATUS_HAVE_BUFFER);
+ spa_node_call_ready(&state->callbacks, SPA_STATUS_HAVE_BUFFER);
}
return 0;
}
diff --git a/spa/plugins/alsa/alsa-utils.h b/spa/plugins/alsa/alsa-utils.h
index d307c9a9..42c93585 100644
--- a/spa/plugins/alsa/alsa-utils.h
+++ b/spa/plugins/alsa/alsa-utils.h
@@ -82,8 +82,7 @@ struct state {
snd_output_t *output;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
uint64_t info_all;
struct spa_node_info info;
diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c
index 78a68e75..9c6d95a4 100644
--- a/spa/plugins/audiotestsrc/audiotestsrc.c
+++ b/spa/plugins/audiotestsrc/audiotestsrc.c
@@ -119,8 +119,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
bool async;
struct spa_source timer_source;
@@ -394,7 +393,7 @@ static void on_output(struct spa_source *source)
res = make_buffer(this);
if (res == SPA_STATUS_HAVE_BUFFER)
- this->callbacks->ready(this->callbacks_data, res);
+ spa_node_call_ready(&this->callbacks, res);
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
@@ -511,8 +510,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c
index 2a2b0939..ea7a4c73 100644
--- a/spa/plugins/bluez5/a2dp-sink.c
+++ b/spa/plugins/bluez5/a2dp-sink.c
@@ -92,8 +92,7 @@ struct impl {
struct spa_loop *data_loop;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
uint64_t info_all;
struct spa_node_info info;
@@ -571,7 +570,8 @@ static int flush_data(struct impl *this, uint64_t now_time)
spa_list_remove(&b->link);
b->outstanding = true;
spa_log_trace(this->log, "a2dp-sink %p: reuse buffer %u", this, b->id);
- this->callbacks->reuse_buffer(this->callbacks_data, 0, b->id);
+
+ spa_node_call_reuse_buffer(&this->callbacks, 0, b->id);
port->ready_offset = 0;
}
total_frames += n_frames;
@@ -699,7 +699,7 @@ static void a2dp_on_timeout(struct spa_source *source)
port->range->min_size = this->threshold * port->frame_size;
port->range->max_size = this->write_samples * port->frame_size;
}
- this->callbacks->ready(this->callbacks_data, SPA_STATUS_NEED_BUFFER);
+ spa_node_call_ready(&this->callbacks, SPA_STATUS_NEED_BUFFER);
}
flush_data(this, now_time);
}
@@ -974,8 +974,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
diff --git a/spa/plugins/bluez5/a2dp-source.c b/spa/plugins/bluez5/a2dp-source.c
index fcaa8c2a..5b9416a3 100644
--- a/spa/plugins/bluez5/a2dp-source.c
+++ b/spa/plugins/bluez5/a2dp-source.c
@@ -92,8 +92,7 @@ struct impl {
struct spa_loop *data_loop;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
uint64_t info_all;
struct spa_node_info info;
@@ -379,7 +378,7 @@ static void decode_sbc_data(struct impl *this, uint8_t *src, size_t src_size)
spa_log_debug(this->log, "data decoded successfully for buffer_id=%d", buffer->id);
spa_list_append(&port->ready, &buffer->link);
- this->callbacks->ready(this->callbacks_data, SPA_STATUS_HAVE_BUFFER);
+ spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_BUFFER);
}
static void a2dp_on_ready_read(struct spa_source *source)
@@ -608,8 +607,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
diff --git a/spa/plugins/bluez5/bluez5-monitor.c b/spa/plugins/bluez5/bluez5-monitor.c
index 84fddf5a..a51b180b 100644
--- a/spa/plugins/bluez5/bluez5-monitor.c
+++ b/spa/plugins/bluez5/bluez5-monitor.c
@@ -60,8 +60,7 @@ struct spa_bt_monitor {
struct spa_dbus_connection *dbus_connection;
DBusConnection *conn;
- const struct spa_monitor_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
uint32_t count;
@@ -532,7 +531,7 @@ static int device_add(struct spa_bt_monitor *monitor, struct spa_bt_device *devi
fill_item(monitor, device, &item, &b);
device->added = true;
- monitor->callbacks->event(monitor->callbacks_data, event);
+ spa_monitor_call_event(&monitor->callbacks, event);
return 0;
}
@@ -552,7 +551,7 @@ static int device_remove(struct spa_bt_monitor *monitor, struct spa_bt_device *d
fill_item(monitor, device, &item, &b);
device->added = false;
- monitor->callbacks->event(monitor->callbacks_data, event);
+ spa_monitor_call_event(&monitor->callbacks, event);
return 0;
}
@@ -2051,8 +2050,7 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct spa_bt_monitor, monitor);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
if (callbacks) {
get_managed_objects(this);
diff --git a/spa/plugins/test/fakesink.c b/spa/plugins/test/fakesink.c
index 60734aa5..d76d8f45 100644
--- a/spa/plugins/test/fakesink.c
+++ b/spa/plugins/test/fakesink.c
@@ -85,8 +85,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
struct spa_source timer_source;
struct itimerspec timerspec;
@@ -194,7 +193,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
static void set_timer(struct impl *this, bool enabled)
{
- if ((this->callbacks && this->callbacks->ready) || this->props.live) {
+ if (this->callbacks.funcs || this->props.live) {
if (enabled) {
if (this->props.live) {
uint64_t next_time = this->start_time + this->elapsed_time;
@@ -216,7 +215,7 @@ static inline void read_timer(struct impl *this)
{
uint64_t expirations;
- if ((this->callbacks && this->callbacks->ready) || this->props.live) {
+ if (this->callbacks.funcs || this->props.live) {
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) != sizeof(uint64_t))
perror("read timerfd");
}
@@ -237,8 +236,7 @@ static int consume_buffer(struct impl *this)
if (spa_list_is_empty(&port->ready)) {
io->status = SPA_STATUS_NEED_BUFFER;
- if (this->callbacks->ready)
- this->callbacks->ready(this->callbacks_data, SPA_STATUS_NEED_BUFFER);
+ spa_node_call_ready(&this->callbacks, SPA_STATUS_NEED_BUFFER);
}
if (spa_list_is_empty(&port->ready)) {
spa_log_error(this->log, NAME " %p: no buffers", this);
@@ -391,12 +389,11 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
- if (this->data_loop == NULL && callbacks != NULL && callbacks->ready != NULL) {
+ if (this->data_loop == NULL && callbacks != NULL) {
spa_log_error(this->log, "a data_loop is needed for async operation");
return -EINVAL;
}
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
@@ -700,7 +697,7 @@ static int impl_node_process(struct spa_node *node)
io->buffer_id = SPA_ID_INVALID;
io->status = SPA_STATUS_OK;
}
- if (this->callbacks == NULL || this->callbacks->ready == NULL)
+ if (this->callbacks.funcs == NULL)
return consume_buffer(this);
else
return SPA_STATUS_OK;
diff --git a/spa/plugins/test/fakesrc.c b/spa/plugins/test/fakesrc.c
index 96294bab..1567b955 100644
--- a/spa/plugins/test/fakesrc.c
+++ b/spa/plugins/test/fakesrc.c
@@ -86,8 +86,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
struct spa_source timer_source;
struct itimerspec timerspec;
@@ -212,7 +211,7 @@ static int fill_buffer(struct impl *this, struct buffer *b)
static void set_timer(struct impl *this, bool enabled)
{
- if ((this->callbacks && this->callbacks->ready) || this->props.live) {
+ if (this->callbacks.funcs || this->props.live) {
if (enabled) {
if (this->props.live) {
uint64_t next_time = this->start_time + this->elapsed_time;
@@ -234,7 +233,7 @@ static inline void read_timer(struct impl *this)
{
uint64_t expirations;
- if ((this->callbacks && this->callbacks->ready) || this->props.live) {
+ if (this->callbacks.funcs || this->props.live) {
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) != sizeof(uint64_t))
perror("read timerfd");
}
@@ -292,8 +291,8 @@ static void on_output(struct spa_source *source)
res = make_buffer(this);
- if (res == SPA_STATUS_HAVE_BUFFER && this->callbacks && this->callbacks->ready)
- this->callbacks->ready(this->callbacks_data, res);
+ if (res == SPA_STATUS_HAVE_BUFFER && this->callbacks.funcs)
+ spa_node_call_ready(&this->callbacks, res);
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
@@ -404,12 +403,11 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
- if (this->data_loop == NULL && (callbacks != NULL && callbacks->ready != NULL)) {
+ if (this->data_loop == NULL && callbacks != NULL) {
spa_log_error(this->log, "a data_loop is needed for async operation");
return -EINVAL;
}
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
@@ -737,7 +735,7 @@ static int impl_node_process(struct spa_node *node)
io->buffer_id = SPA_ID_INVALID;
}
- if ((this->callbacks == NULL || this->callbacks->ready == NULL) &&
+ if (this->callbacks.funcs == NULL &&
(io->status == SPA_STATUS_NEED_BUFFER))
return make_buffer(this);
else
diff --git a/spa/plugins/v4l2/v4l2-monitor.c b/spa/plugins/v4l2/v4l2-monitor.c
index 02277543..88989b1e 100644
--- a/spa/plugins/v4l2/v4l2-monitor.c
+++ b/spa/plugins/v4l2/v4l2-monitor.c
@@ -48,8 +48,7 @@ struct impl {
struct spa_log *log;
struct spa_loop *main_loop;
- const struct spa_monitor_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
struct udev *udev;
struct udev_monitor *umonitor;
@@ -175,7 +174,7 @@ static int emit_device(struct impl *this, uint32_t id, struct udev_device *dev)
event = spa_pod_builder_add_object(&b, SPA_TYPE_EVENT_Monitor, id);
fill_item(this, dev, &item, &b);
- this->callbacks->event(this->callbacks_data, event);
+ spa_monitor_call_event(&this->callbacks, event);
return 0;
}
@@ -284,8 +283,8 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
+
if (callbacks) {
if ((res = impl_udev_open(this)) < 0)
return res;
diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c
index f639d6d0..e50e18f3 100644
--- a/spa/plugins/v4l2/v4l2-source.c
+++ b/spa/plugins/v4l2/v4l2-source.c
@@ -134,8 +134,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
struct port out_ports[1];
@@ -384,8 +383,7 @@ static int impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c
index 51494bad..c2113be0 100644
--- a/spa/plugins/v4l2/v4l2-utils.c
+++ b/spa/plugins/v4l2/v4l2-utils.c
@@ -1206,7 +1206,7 @@ static int mmap_read(struct impl *this)
}
spa_log_trace(this->log, "v4l2 %p: now queued %d", this, b->id);
- this->callbacks->ready(this->callbacks_data, SPA_STATUS_HAVE_BUFFER);
+ spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_BUFFER);
return 0;
}
diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c
index b8ac984e..05375864 100644
--- a/spa/plugins/videotestsrc/videotestsrc.c
+++ b/spa/plugins/videotestsrc/videotestsrc.c
@@ -104,8 +104,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
bool async;
struct spa_source timer_source;
@@ -340,7 +339,7 @@ static void on_output(struct spa_source *source)
res = make_buffer(this);
if (res == SPA_STATUS_HAVE_BUFFER)
- this->callbacks->ready(this->callbacks_data, res);
+ spa_node_call_ready(&this->callbacks, res);
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
@@ -456,8 +455,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
diff --git a/spa/tests/test-pod.c b/spa/tests/test-pod.c
index ba5795e8..8f1d9390 100644
--- a/spa/tests/test-pod.c
+++ b/spa/tests/test-pod.c
@@ -72,7 +72,7 @@ static void test_abi(void)
/* builder */
spa_assert(sizeof(struct spa_pod_frame) == 24);
spa_assert(sizeof(struct spa_pod_builder_state) == 16);
- spa_assert(sizeof(struct spa_pod_builder) == 48);
+ spa_assert(sizeof(struct spa_pod_builder) == 80);
/* command */
spa_assert(sizeof(struct spa_command_body) == 8);
diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c
index 761bc1c2..f3d2926b 100644
--- a/src/gst/gstpipewireformat.c
+++ b/src/gst/gstpipewireformat.c
@@ -544,8 +544,7 @@ convert_1 (ConvertData *d)
if (!(d->type = find_media_types (gst_structure_get_name (d->cs))))
return NULL;
- d->b.callbacks = &builder_callbacks;
- d->b.callbacks_data = &d->b;
+ spa_pod_builder_set_callbacks(&d->b, &builder_callbacks, &d->b);
spa_pod_builder_push_object (&d->b, &f, SPA_TYPE_OBJECT_Format, d->id);
diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c
index 7a4548bb..3be61fc3 100644
--- a/src/modules/module-client-node/client-node.c
+++ b/src/modules/module-client-node/client-node.c
@@ -128,8 +128,7 @@ struct node {
struct spa_loop *data_loop;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
struct io ios[MAX_IO];
struct pw_resource *resource;
@@ -521,8 +520,7 @@ impl_node_set_callbacks(struct spa_node *node,
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
@@ -1115,8 +1113,7 @@ static void node_on_data_fd_events(struct spa_source *source)
spa_log_warn(this->log, "node %p: read %"PRIu64" failed %m", this, cmd);
spa_log_trace_fp(this->log, "node %p: got ready", this);
- if (this->callbacks && this->callbacks->ready)
- this->callbacks->ready(this->callbacks_data, SPA_STATUS_HAVE_BUFFER);
+ spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_BUFFER);
}
}
diff --git a/src/modules/module-client-node/client-stream.c b/src/modules/module-client-node/client-stream.c
index adeb3a80..651c8760 100644
--- a/src/modules/module-client-node/client-stream.c
+++ b/src/modules/module-client-node/client-stream.c
@@ -72,8 +72,7 @@ struct node {
struct spa_param_info params[5];
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
};
struct impl {
@@ -378,8 +377,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct node, node);
- this->callbacks = callbacks;
- this->callbacks_data = data;
+ this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
@@ -1234,7 +1232,7 @@ static int node_ready(void *data, int status)
impl_node_process(&impl->node.node);
impl->driver = true;
- return impl->node.callbacks->ready(impl->node.callbacks_data, status);
+ return spa_node_call_ready(&impl->node.callbacks, status);
}
static const struct spa_node_callbacks node_callbacks = {
diff --git a/src/modules/module-protocol-native/connection.c b/src/modules/module-protocol-native/connection.c
index dce4707b..dbb6a3cf 100644
--- a/src/modules/module-protocol-native/connection.c
+++ b/src/modules/module-protocol-native/connection.c
@@ -355,9 +355,9 @@ static inline void *begin_write(struct pw_protocol_native_connection *conn, uint
return SPA_MEMBER(p, HDR_SIZE, void);
}
-static int builder_overflow(void *callbacks_data, uint32_t size)
+static int builder_overflow(void *data, uint32_t size)
{
- struct impl *impl = callbacks_data;
+ struct impl *impl = data;
struct spa_pod_builder *b = &impl->builder;
b->size = SPA_ROUND_UP_N(size, 4096);
@@ -382,8 +382,7 @@ pw_protocol_native_connection_begin(struct pw_protocol_native_connection *conn,
buf->msg.id = id;
buf->msg.opcode = opcode;
impl->builder = SPA_POD_BUILDER_INIT(NULL, 0);
- impl->builder.callbacks = &builder_callbacks;
- impl->builder.callbacks_data = impl;
+ spa_pod_builder_set_callbacks(&impl->builder, &builder_callbacks, impl);
buf->msg.n_fds = 0;
buf->msg.fds = &buf->fds[buf->n_fds];
buf->msg.seq = buf->seq;
diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c
index 66b20af7..4b95572a 100644
--- a/src/pipewire/stream.c
+++ b/src/pipewire/stream.c
@@ -118,8 +118,7 @@ struct stream {
struct spa_node impl_node;
struct spa_hook_list hooks;
- const struct spa_node_callbacks *callbacks;
- void *callbacks_data;
+ struct spa_hook callbacks;
struct spa_io_buffers *io;
struct spa_io_position *position;
uint32_t io_control_size;
@@ -406,8 +405,7 @@ static int impl_set_callbacks(struct spa_node *node,
{
struct stream *d = SPA_CONTAINER_OF(node, struct stream, impl_node);
- d->callbacks = callbacks;
- d->callbacks_data = data;
+ d->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
@@ -1464,7 +1462,7 @@ do_process(struct spa_loop *loop,
{
struct stream *impl = user_data;
int res = impl_node_process_output(&impl->impl_node);
- return impl->callbacks->ready(impl->callbacks_data, res);
+ return spa_node_call_ready(&impl->callbacks, res);
}
static inline int call_trigger(struct stream *impl)