From 84bd4b7ea923f33f1f1cf3b58d8aa20079bebc1b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 19 Nov 2024 19:57:37 +0100 Subject: [PATCH] spa: use static inline for interfaces instead of macro It gives better typechecking and a path to make a library of functions. --- spa/include/spa/filter-graph/filter-graph.h | 75 ++++-- spa/include/spa/interfaces/audio/aec.h | 83 ++++-- spa/include/spa/monitor/device.h | 42 ++- spa/include/spa/node/node.h | 152 ++++++++--- spa/include/spa/support/cpu.h | 40 +-- spa/include/spa/support/dbus.h | 39 ++- spa/include/spa/support/i18n.h | 16 +- spa/include/spa/support/log.h | 30 ++- spa/include/spa/support/loop.h | 244 ++++++++++-------- spa/include/spa/support/plugin-loader.h | 16 +- spa/include/spa/support/plugin.h | 40 ++- spa/include/spa/support/system.h | 136 +++++++--- spa/include/spa/support/thread.h | 30 +-- spa/include/spa/utils/hook.h | 63 +++++ spa/plugins/audioconvert/fmt-ops.h | 2 +- spa/plugins/audiomixer/mix-ops.h | 2 +- spa/plugins/filter-graph/audio-dsp.h | 139 +++++++--- spa/plugins/filter-graph/audio-plugin.h | 26 +- .../videoconvert/videoconvert-ffmpeg.c | 2 +- src/pipewire/client.h | 43 ++- src/pipewire/core.h | 110 ++++---- src/pipewire/device.h | 43 ++- src/pipewire/extensions/client-node.h | 65 +++-- src/pipewire/extensions/metadata.h | 37 ++- src/pipewire/extensions/profiler.h | 19 +- src/pipewire/extensions/security-context.h | 29 ++- src/pipewire/factory.h | 19 +- src/pipewire/link.h | 19 +- src/pipewire/module.h | 19 +- src/pipewire/node.h | 51 ++-- src/pipewire/port.h | 35 ++- src/tools/pw-top.c | 2 + 32 files changed, 1087 insertions(+), 581 deletions(-) diff --git a/spa/include/spa/filter-graph/filter-graph.h b/spa/include/spa/filter-graph/filter-graph.h index 966f46942..4047993f1 100644 --- a/spa/include/spa/filter-graph/filter-graph.h +++ b/spa/include/spa/filter-graph/filter-graph.h @@ -83,28 +83,59 @@ struct spa_filter_graph_methods { struct spa_filter_graph_chunk out[], uint32_t n_out); }; -#define spa_filter_graph_method_r(o,method,version,...) \ -({ \ - volatile int _res = -ENOTSUP; \ - struct spa_filter_graph *_o = o; \ - spa_interface_call_fast_res(&_o->iface, \ - struct spa_filter_graph_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_filter_graph_add_listener(o,...) spa_filter_graph_method_r(o,add_listener,0,__VA_ARGS__) - -#define spa_filter_graph_enum_prop_info(o,...) spa_filter_graph_method_r(o,enum_prop_info,0,__VA_ARGS__) -#define spa_filter_graph_get_props(o,...) spa_filter_graph_method_r(o,get_props,0,__VA_ARGS__) -#define spa_filter_graph_set_props(o,...) spa_filter_graph_method_r(o,set_props,0,__VA_ARGS__) - -#define spa_filter_graph_activate(o,...) spa_filter_graph_method_r(o,activate,0,__VA_ARGS__) -#define spa_filter_graph_deactivate(o) spa_filter_graph_method_r(o,deactivate,0) - -#define spa_filter_graph_reset(o) spa_filter_graph_method_r(o,reset,0) - -#define spa_filter_graph_process(o,...) spa_filter_graph_method_r(o,process,0,__VA_ARGS__) +static inline int spa_filter_graph_add_listener(struct spa_filter_graph *object, + struct spa_hook *listener, + const struct spa_filter_graph_events *events, void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_filter_graph, &object->iface, add_listener, 0, listener, + events, data); +} + +static inline int spa_filter_graph_enum_prop_info(struct spa_filter_graph *object, + uint32_t idx, struct spa_pod_builder *b) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_filter_graph, &object->iface, enum_prop_info, 0, idx, b); +} +static inline int spa_filter_graph_get_props(struct spa_filter_graph *object, + struct spa_pod_builder *b, const struct spa_pod **props) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_filter_graph, &object->iface, get_props, 0, b, props); +} + +static inline int spa_filter_graph_set_props(struct spa_filter_graph *object, + enum spa_direction direction, const struct spa_pod *props) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_filter_graph, &object->iface, set_props, 0, direction, props); +} + +static inline int spa_filter_graph_activate(struct spa_filter_graph *object, const struct spa_fraction *rate) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_filter_graph, &object->iface, activate, 0, rate); +} +static inline int spa_filter_graph_deactivate(struct spa_filter_graph *object) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_filter_graph, &object->iface, deactivate, 0); +} + +static inline int spa_filter_graph_reset(struct spa_filter_graph *object) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_filter_graph, &object->iface, reset, 0); +} + +static inline int spa_filter_graph_process(struct spa_filter_graph *object, + const struct spa_filter_graph_chunk in[], uint32_t n_in, + struct spa_filter_graph_chunk out[], uint32_t n_out) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_filter_graph, &object->iface, process, 0, in, n_in, out, n_out); +} /** * \} diff --git a/spa/include/spa/interfaces/audio/aec.h b/spa/include/spa/interfaces/audio/aec.h index 67319f1df..d1f571d6c 100644 --- a/spa/include/spa/interfaces/audio/aec.h +++ b/spa/include/spa/interfaces/audio/aec.h @@ -68,26 +68,69 @@ struct spa_audio_aec_methods { struct spa_audio_info_raw *out_info); }; -#define spa_audio_aec_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - struct spa_audio_aec *_o = (o); \ - spa_interface_call_res(&_o->iface, \ - struct spa_audio_aec_methods, _res, \ - method, (version), ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_audio_aec_add_listener(o,...) spa_audio_aec_method(o, add_listener, 0, __VA_ARGS__) -#define spa_audio_aec_init(o,...) spa_audio_aec_method(o, init, 0, __VA_ARGS__) -#define spa_audio_aec_run(o,...) spa_audio_aec_method(o, run, 0, __VA_ARGS__) -#define spa_audio_aec_set_props(o,...) spa_audio_aec_method(o, set_props, 0, __VA_ARGS__) -#define spa_audio_aec_activate(o) spa_audio_aec_method(o, activate, 1) -#define spa_audio_aec_deactivate(o) spa_audio_aec_method(o, deactivate, 1) -#define spa_audio_aec_enum_props(o,...) spa_audio_aec_method(o, enum_props, 2, __VA_ARGS__) -#define spa_audio_aec_get_params(o,...) spa_audio_aec_method(o, get_params, 2, __VA_ARGS__) -#define spa_audio_aec_set_params(o,...) spa_audio_aec_method(o, set_params, 2, __VA_ARGS__) -#define spa_audio_aec_init2(o,...) spa_audio_aec_method(o, init2, 3, __VA_ARGS__) +static inline int spa_audio_aec_add_listener(struct spa_audio_aec *object, + struct spa_hook *listener, + const struct spa_audio_aec_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, add_listener, 0, listener, events, data); +} + +static inline int spa_audio_aec_init(struct spa_audio_aec *object, + const struct spa_dict *args, const struct spa_audio_info_raw *info) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, init, 0, args, info); +} +static inline int spa_audio_aec_run(struct spa_audio_aec *object, + const float *rec[], const float *play[], float *out[], uint32_t n_samples) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, run, 0, rec, play, out, n_samples); +} +static inline int spa_audio_aec_set_props(struct spa_audio_aec *object, const struct spa_dict *args) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, set_props, 0, args); +} +static inline int spa_audio_aec_activate(struct spa_audio_aec *object) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, activate, 1); +} +static inline int spa_audio_aec_deactivate(struct spa_audio_aec *object) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, deactivate, 1); +} +static inline int spa_audio_aec_enum_props(struct spa_audio_aec *object, + int index, struct spa_pod_builder* builder) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, enum_props, 2, index, builder); +} +static inline int spa_audio_aec_get_params(struct spa_audio_aec *object, + struct spa_pod_builder* builder) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, get_params, 2, builder); +} +static inline int spa_audio_aec_set_params(struct spa_audio_aec *object, + const struct spa_pod *args) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, set_params, 2, args); +} +static inline int spa_audio_aec_init2(struct spa_audio_aec *object, + const struct spa_dict *args, + struct spa_audio_info_raw *play_info, + struct spa_audio_info_raw *rec_info, + struct spa_audio_info_raw *out_info) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_audio_aec, &object->iface, init2, 3, args, play_info, rec_info, out_info); +} #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/monitor/device.h b/spa/include/spa/monitor/device.h index 2201ffdb8..b16a6c5fe 100644 --- a/spa/include/spa/monitor/device.h +++ b/spa/include/spa/monitor/device.h @@ -220,20 +220,34 @@ struct spa_device_methods { const struct spa_pod *param); }; -#define spa_device_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - struct spa_device *_o = (o); \ - spa_interface_call_res(&_o->iface, \ - struct spa_device_methods, _res, \ - method, (version), ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_device_add_listener(d,...) spa_device_method(d, add_listener, 0, __VA_ARGS__) -#define spa_device_sync(d,...) spa_device_method(d, sync, 0, __VA_ARGS__) -#define spa_device_enum_params(d,...) spa_device_method(d, enum_params, 0, __VA_ARGS__) -#define spa_device_set_param(d,...) spa_device_method(d, set_param, 0, __VA_ARGS__) +static inline int spa_device_add_listener(struct spa_device *object, + struct spa_hook *listener, + const struct spa_device_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, add_listener, 0, + listener, events, data); + +} +static inline int spa_device_sync(struct spa_device *object, int seq) +{ + return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, sync, 0, + seq); +} +static inline int spa_device_enum_params(struct spa_device *object, int seq, + uint32_t id, uint32_t index, uint32_t max, + const struct spa_pod *filter) +{ + return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, enum_params, 0, + seq, id, index, max, filter); +} +static inline int spa_device_set_param(struct spa_device *object, + uint32_t id, uint32_t flags, + const struct spa_pod *param) +{ + return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, set_param, 0, + id, flags, param); +} #define SPA_KEY_DEVICE_ENUM_API "device.enum.api" /**< the api used to discover this * device */ diff --git a/spa/include/spa/node/node.h b/spa/include/spa/node/node.h index 44e45da83..d75ea2c33 100644 --- a/spa/include/spa/node/node.h +++ b/spa/include/spa/node/node.h @@ -633,44 +633,120 @@ struct spa_node_methods { int (*process) (void *object); }; -#define spa_node_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - struct spa_node *_n = o; \ - spa_interface_call_res(&_n->iface, \ - struct spa_node_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_node_method_fast(o,method,version,...) \ -({ \ - int _res; \ - struct spa_node *_n = o; \ - spa_interface_call_fast_res(&_n->iface, \ - struct spa_node_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_node_add_listener(n,...) spa_node_method(n, add_listener, 0, __VA_ARGS__) -#define spa_node_set_callbacks(n,...) spa_node_method(n, set_callbacks, 0, __VA_ARGS__) -#define spa_node_sync(n,...) spa_node_method(n, sync, 0, __VA_ARGS__) -#define spa_node_enum_params(n,...) spa_node_method(n, enum_params, 0, __VA_ARGS__) -#define spa_node_set_param(n,...) spa_node_method(n, set_param, 0, __VA_ARGS__) -#define spa_node_set_io(n,...) spa_node_method(n, set_io, 0, __VA_ARGS__) -#define spa_node_send_command(n,...) spa_node_method(n, send_command, 0, __VA_ARGS__) -#define spa_node_add_port(n,...) spa_node_method(n, add_port, 0, __VA_ARGS__) -#define spa_node_remove_port(n,...) spa_node_method(n, remove_port, 0, __VA_ARGS__) -#define spa_node_port_enum_params(n,...) spa_node_method(n, port_enum_params, 0, __VA_ARGS__) -#define spa_node_port_set_param(n,...) spa_node_method(n, port_set_param, 0, __VA_ARGS__) -#define spa_node_port_use_buffers(n,...) spa_node_method(n, port_use_buffers, 0, __VA_ARGS__) -#define spa_node_port_set_io(n,...) spa_node_method(n, port_set_io, 0, __VA_ARGS__) - -#define spa_node_port_reuse_buffer(n,...) spa_node_method(n, port_reuse_buffer, 0, __VA_ARGS__) -#define spa_node_port_reuse_buffer_fast(n,...) spa_node_method_fast(n, port_reuse_buffer, 0, __VA_ARGS__) -#define spa_node_process(n) spa_node_method(n, process, 0) -#define spa_node_process_fast(n) spa_node_method_fast(n, process, 0) + +static inline int spa_node_add_listener(struct spa_node *object, + struct spa_hook *listener, + const struct spa_node_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, add_listener, 0, + listener, events, data); +} +static inline int spa_node_set_callbacks(struct spa_node *object, + const struct spa_node_callbacks *callbacks, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_callbacks, 0, + callbacks, data); +} +static inline int spa_node_sync(struct spa_node *object, int seq) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, sync, 0, + seq); +} +static inline int spa_node_enum_params(struct spa_node *object, int seq, + uint32_t id, uint32_t start, uint32_t max, + const struct spa_pod *filter) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, enum_params, 0, + seq, id, start, max, filter); +} +static inline int spa_node_set_param(struct spa_node *object, + uint32_t id, uint32_t flags, + const struct spa_pod *param) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_param, 0, + id, flags, param); +} +static inline int spa_node_set_io(struct spa_node *object, + uint32_t id, void *data, size_t size) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_io, 0, + id, data, size); +} +static inline int spa_node_send_command(struct spa_node *object, + const struct spa_command *command) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, send_command, 0, + command); +} +static inline int spa_node_add_port(struct spa_node *object, + enum spa_direction direction, uint32_t port_id, + const struct spa_dict *props) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, add_port, 0, + direction, port_id, props); +} +static inline int spa_node_remove_port(struct spa_node *object, + enum spa_direction direction, uint32_t port_id) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, remove_port, 0, + direction, port_id); +} +static inline int spa_node_port_enum_params(struct spa_node *object, int seq, + enum spa_direction direction, uint32_t port_id, + uint32_t id, uint32_t start, uint32_t max, + const struct spa_pod *filter) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_enum_params, 0, + seq, direction, port_id, id, start, max, filter); +} +static inline int spa_node_port_set_param(struct spa_node *object, + enum spa_direction direction, + uint32_t port_id, + uint32_t id, uint32_t flags, + const struct spa_pod *param) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_set_param, 0, + direction, port_id, id, flags, param); +} +static inline int spa_node_port_use_buffers(struct spa_node *object, + enum spa_direction direction, + uint32_t port_id, + uint32_t flags, + struct spa_buffer **buffers, + uint32_t n_buffers) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_use_buffers, 0, + direction, port_id, flags, buffers, n_buffers); +} +static inline int spa_node_port_set_io(struct spa_node *object, + enum spa_direction direction, + uint32_t port_id, + uint32_t id, void *data, size_t size) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_set_io, 0, + direction, port_id, id, data, size); +} + +static inline int spa_node_port_reuse_buffer(struct spa_node *object, uint32_t port_id, uint32_t buffer_id) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_reuse_buffer, 0, + port_id, buffer_id); +} +static inline int spa_node_port_reuse_buffer_fast(struct spa_node *object, uint32_t port_id, uint32_t buffer_id) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_node, &object->iface, port_reuse_buffer, 0, + port_id, buffer_id); +} +static inline int spa_node_process(struct spa_node *object) +{ + return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, process, 0); +} +static inline int spa_node_process_fast(struct spa_node *object) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_node, &object->iface, process, 0); +} /** * \} diff --git a/spa/include/spa/support/cpu.h b/spa/include/spa/support/cpu.h index 072b9be07..4f61bd0c3 100644 --- a/spa/include/spa/support/cpu.h +++ b/spa/include/spa/support/cpu.h @@ -10,6 +10,7 @@ extern "C" { #endif #include +#include #include #include @@ -159,21 +160,30 @@ struct spa_cpu_methods { int (*zero_denormals) (void *object, bool enable); }; -#define spa_cpu_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - struct spa_cpu *_c = o; \ - spa_interface_call_res(&_c->iface, \ - struct spa_cpu_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) -#define spa_cpu_get_flags(c) spa_cpu_method(c, get_flags, 0) -#define spa_cpu_force_flags(c,f) spa_cpu_method(c, force_flags, 0, f) -#define spa_cpu_get_count(c) spa_cpu_method(c, get_count, 0) -#define spa_cpu_get_max_align(c) spa_cpu_method(c, get_max_align, 0) -#define spa_cpu_get_vm_type(c) spa_cpu_method(c, get_vm_type, 1) -#define spa_cpu_zero_denormals(c,e) spa_cpu_method(c, zero_denormals, 2, e) +static inline uint32_t spa_cpu_get_flags(struct spa_cpu *c) +{ + return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_flags, 0); +} +static inline int spa_cpu_force_flags(struct spa_cpu *c, uint32_t flags) +{ + return spa_api_method_r(int, -ENOTSUP, spa_cpu, &c->iface, force_flags, 0, flags); +} +static inline uint32_t spa_cpu_get_count(struct spa_cpu *c) +{ + return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_count, 0); +} +static inline uint32_t spa_cpu_get_max_align(struct spa_cpu *c) +{ + return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_max_align, 0); +} +static inline uint32_t spa_cpu_get_vm_type(struct spa_cpu *c) +{ + return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_vm_type, 1); +} +static inline int spa_cpu_zero_denormals(struct spa_cpu *c, bool enable) +{ + return spa_api_method_r(int, -ENOTSUP, spa_cpu, &c->iface, zero_denormals, 2, enable); +} /** keys can be given when initializing the cpu handle */ #define SPA_KEY_CPU_FORCE "cpu.force" /**< force cpu flags */ diff --git a/spa/include/spa/support/dbus.h b/spa/include/spa/support/dbus.h index 83deb1d6e..52da0457b 100644 --- a/spa/include/spa/support/dbus.h +++ b/spa/include/spa/support/dbus.h @@ -79,29 +79,27 @@ struct spa_dbus_connection { void *data); }; -#define spa_dbus_connection_call(c,method,vers,...) \ -({ \ - if (SPA_LIKELY(SPA_CALLBACK_CHECK(c,method,vers))) \ - c->method((c), ## __VA_ARGS__); \ -}) - -#define spa_dbus_connection_call_vp(c,method,vers,...) \ -({ \ - void *_res = NULL; \ - if (SPA_LIKELY(SPA_CALLBACK_CHECK(c,method,vers))) \ - _res = c->method((c), ## __VA_ARGS__); \ - _res; \ -}) - /** \copydoc spa_dbus_connection.get * \sa spa_dbus_connection.get */ -#define spa_dbus_connection_get(c) spa_dbus_connection_call_vp(c,get,0) +static inline void *spa_dbus_connection_get(struct spa_dbus_connection *conn) +{ + return spa_api_func_r(void *, NULL, conn, get, 0); +} /** \copydoc spa_dbus_connection.destroy * \sa spa_dbus_connection.destroy */ -#define spa_dbus_connection_destroy(c) spa_dbus_connection_call(c,destroy,0) +static inline void spa_dbus_connection_destroy(struct spa_dbus_connection *conn) +{ + spa_api_func_v(conn, destroy, 0); +} /** \copydoc spa_dbus_connection.add_listener * \sa spa_dbus_connection.add_listener */ -#define spa_dbus_connection_add_listener(c,...) spa_dbus_connection_call(c,add_listener,1,__VA_ARGS__) +static inline void spa_dbus_connection_add_listener(struct spa_dbus_connection *conn, + struct spa_hook *listener, + const struct spa_dbus_connection_events *events, + void *data) +{ + spa_api_func_v(conn, add_listener, 1, listener, events, data); +} struct spa_dbus_methods { #define SPA_VERSION_DBUS_METHODS 0 @@ -129,11 +127,8 @@ struct spa_dbus_methods { static inline struct spa_dbus_connection * spa_dbus_get_connection(struct spa_dbus *dbus, enum spa_dbus_type type) { - struct spa_dbus_connection *res = NULL; - spa_interface_call_res(&dbus->iface, - struct spa_dbus_methods, res, - get_connection, 0, type); - return res; + return spa_api_method_r(struct spa_dbus_connection *, NULL, + spa_dbus, &dbus->iface, get_connection, 0, type); } /** diff --git a/spa/include/spa/support/i18n.h b/spa/include/spa/support/i18n.h index 56660e68d..b53ce42d7 100644 --- a/spa/include/spa/support/i18n.h +++ b/spa/include/spa/support/i18n.h @@ -56,24 +56,16 @@ SPA_FORMAT_ARG_FUNC(2) static inline const char * spa_i18n_text(struct spa_i18n *i18n, const char *msgid) { - const char *res = msgid; - if (SPA_LIKELY(i18n != NULL)) - spa_interface_call_res(&i18n->iface, - struct spa_i18n_methods, res, - text, 0, msgid); - return res; + return spa_api_method_null_r(const char *, msgid, spa_i18n, &i18n->iface, + text, 0, msgid); } static inline const char * spa_i18n_ntext(struct spa_i18n *i18n, const char *msgid, const char *msgid_plural, unsigned long int n) { - const char *res = n == 1 ? msgid : msgid_plural; - if (SPA_LIKELY(i18n != NULL)) - spa_interface_call_res(&i18n->iface, - struct spa_i18n_methods, res, - ntext, 0, msgid, msgid_plural, n); - return res; + return spa_api_method_null_r(const char *, n == 1 ? msgid : msgid_plural, + spa_i18n, &i18n->iface, ntext, 0, msgid, msgid_plural, n); } /** diff --git a/spa/include/spa/support/log.h b/spa/include/spa/support/log.h index fba50e75b..640a1cd01 100644 --- a/spa/include/spa/support/log.h +++ b/spa/include/spa/support/log.h @@ -255,20 +255,22 @@ static inline bool spa_log_level_topic_enabled(const struct spa_log *log, }) /* Transparently calls to version 0 logv if v1 is not supported */ -#define spa_log_logtv(l,lev,topic,...) \ -({ \ - struct spa_log *_l = l; \ - if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \ - struct spa_interface *_if = &_l->iface; \ - if (!spa_interface_call(_if, \ - struct spa_log_methods, logtv, 1, \ - lev, topic, \ - __VA_ARGS__)) \ - spa_interface_call(_if, \ - struct spa_log_methods, logv, 0, \ - lev, __VA_ARGS__); \ - } \ -}) +SPA_PRINTF_FUNC(7, 0) +static inline void spa_log_logtv(struct spa_log *l, enum spa_log_level level, + const struct spa_log_topic *topic, const char *file, int line, + const char *func, const char *fmt, va_list args) +{ + if (SPA_UNLIKELY(spa_log_level_topic_enabled(l, topic, level))) { + struct spa_interface *i = &l->iface; + if (!spa_interface_call(i, + struct spa_log_methods, logtv, 1, + level, topic, + file, line, func, fmt, args)) + spa_interface_call(i, + struct spa_log_methods, logv, 0, + level, file, line, func, fmt, args); + } +} #define spa_logt_lev(l,lev,t,...) \ spa_log_logt(l,lev,t,__FILE__,__LINE__,__func__,__VA_ARGS__) diff --git a/spa/include/spa/support/loop.h b/spa/include/spa/support/loop.h index 7dc55f3ae..4dd532cc7 100644 --- a/spa/include/spa/support/loop.h +++ b/spa/include/spa/support/loop.h @@ -9,6 +9,8 @@ extern "C" { #endif +#include + #include #include #include @@ -125,21 +127,29 @@ struct spa_loop_methods { void *user_data); }; -#define spa_loop_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - struct spa_loop *_o = o; \ - spa_interface_call_res(&_o->iface, \ - struct spa_loop_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_loop_add_source(l,...) spa_loop_method(l,add_source,0,##__VA_ARGS__) -#define spa_loop_update_source(l,...) spa_loop_method(l,update_source,0,##__VA_ARGS__) -#define spa_loop_remove_source(l,...) spa_loop_method(l,remove_source,0,##__VA_ARGS__) -#define spa_loop_invoke(l,...) spa_loop_method(l,invoke,0,##__VA_ARGS__) - +static inline int spa_loop_add_source(struct spa_loop *object, struct spa_source *source) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop, &object->iface, add_source, 0, source); +} +static inline int spa_loop_update_source(struct spa_loop *object, struct spa_source *source) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop, &object->iface, update_source, 0, source); +} +static inline int spa_loop_remove_source(struct spa_loop *object, struct spa_source *source) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop, &object->iface, remove_source, 0, source); +} +static inline int spa_loop_invoke(struct spa_loop *object, + spa_invoke_func_t func, uint32_t seq, const void *data, + size_t size, bool block, void *user_data) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop, &object->iface, invoke, 0, func, seq, data, + size, block, user_data); +} /** Control hooks. These hooks can't be removed from their * callbacks and must be removed from a safe place (when the loop @@ -155,21 +165,19 @@ struct spa_loop_control_hooks { void (*after) (void *data); }; -#define spa_loop_control_hook_before(l) \ -({ \ - struct spa_hook_list *_l = l; \ - struct spa_hook *_h; \ - spa_list_for_each_reverse(_h, &_l->list, link) \ - spa_callbacks_call_fast(&_h->cb, struct spa_loop_control_hooks, before, 0); \ -}) - -#define spa_loop_control_hook_after(l) \ -({ \ - struct spa_hook_list *_l = l; \ - struct spa_hook *_h; \ - spa_list_for_each(_h, &_l->list, link) \ - spa_callbacks_call_fast(&_h->cb, struct spa_loop_control_hooks, after, 0); \ -}) +static inline void spa_loop_control_hook_before(struct spa_hook_list *l) +{ + struct spa_hook *h; + spa_list_for_each_reverse(h, &l->list, link) + spa_callbacks_call_fast(&h->cb, struct spa_loop_control_hooks, before, 0); +} + +static inline void spa_loop_control_hook_after(struct spa_hook_list *l) +{ + struct spa_hook *h; + spa_list_for_each(h, &l->list, link) + spa_callbacks_call_fast(&h->cb, struct spa_loop_control_hooks, after, 0); +} /** * Control an event loop @@ -231,42 +239,43 @@ struct spa_loop_control_methods { int (*check) (void *object); }; -#define spa_loop_control_method_v(o,method,version,...) \ -({ \ - struct spa_loop_control *_o = o; \ - spa_interface_call(&_o->iface, \ - struct spa_loop_control_methods, \ - method, version, ##__VA_ARGS__); \ -}) - -#define spa_loop_control_method_r(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - struct spa_loop_control *_o = o; \ - spa_interface_call_res(&_o->iface, \ - struct spa_loop_control_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_loop_control_method_fast_r(o,method,version,...) \ -({ \ - int _res; \ - struct spa_loop_control *_o = o; \ - spa_interface_call_fast_res(&_o->iface, \ - struct spa_loop_control_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_loop_control_get_fd(l) spa_loop_control_method_r(l,get_fd,0) -#define spa_loop_control_add_hook(l,...) spa_loop_control_method_v(l,add_hook,0,__VA_ARGS__) -#define spa_loop_control_enter(l) spa_loop_control_method_v(l,enter,0) -#define spa_loop_control_leave(l) spa_loop_control_method_v(l,leave,0) -#define spa_loop_control_iterate(l,...) spa_loop_control_method_r(l,iterate,0,__VA_ARGS__) -#define spa_loop_control_check(l) spa_loop_control_method_r(l,check,1) - -#define spa_loop_control_iterate_fast(l,...) spa_loop_control_method_fast_r(l,iterate,0,__VA_ARGS__) +static inline int spa_loop_control_get_fd(struct spa_loop_control *object) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop_control, &object->iface, get_fd, 0); +} +static inline void spa_loop_control_add_hook(struct spa_loop_control *object, + struct spa_hook *hook, const struct spa_loop_control_hooks *hooks, + void *data) +{ + spa_api_method_v(spa_loop_control, &object->iface, add_hook, 0, + hook, hooks, data); +} +static inline void spa_loop_control_enter(struct spa_loop_control *object) +{ + spa_api_method_v(spa_loop_control, &object->iface, enter, 0); +} +static inline void spa_loop_control_leave(struct spa_loop_control *object) +{ + spa_api_method_v(spa_loop_control, &object->iface, leave, 0); +} +static inline int spa_loop_control_iterate(struct spa_loop_control *object, + int timeout) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop_control, &object->iface, iterate, 0, timeout); +} +static inline int spa_loop_control_iterate_fast(struct spa_loop_control *object, + int timeout) +{ + return spa_api_method_fast_r(int, -ENOTSUP, + spa_loop_control, &object->iface, iterate, 0, timeout); +} +static inline int spa_loop_control_check(struct spa_loop_control *object) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop_control, &object->iface, check, 1); +} typedef void (*spa_source_io_func_t) (void *data, int fd, uint32_t mask); typedef void (*spa_source_idle_func_t) (void *data); @@ -317,44 +326,71 @@ struct spa_loop_utils_methods { void (*destroy_source) (void *object, struct spa_source *source); }; -#define spa_loop_utils_method_v(o,method,version,...) \ -({ \ - struct spa_loop_utils *_o = o; \ - spa_interface_call(&_o->iface, \ - struct spa_loop_utils_methods, \ - method, version, ##__VA_ARGS__); \ -}) - -#define spa_loop_utils_method_r(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - struct spa_loop_utils *_o = o; \ - spa_interface_call_res(&_o->iface, \ - struct spa_loop_utils_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) -#define spa_loop_utils_method_s(o,method,version,...) \ -({ \ - struct spa_source *_res = NULL; \ - struct spa_loop_utils *_o = o; \ - spa_interface_call_res(&_o->iface, \ - struct spa_loop_utils_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - - -#define spa_loop_utils_add_io(l,...) spa_loop_utils_method_s(l,add_io,0,__VA_ARGS__) -#define spa_loop_utils_update_io(l,...) spa_loop_utils_method_r(l,update_io,0,__VA_ARGS__) -#define spa_loop_utils_add_idle(l,...) spa_loop_utils_method_s(l,add_idle,0,__VA_ARGS__) -#define spa_loop_utils_enable_idle(l,...) spa_loop_utils_method_r(l,enable_idle,0,__VA_ARGS__) -#define spa_loop_utils_add_event(l,...) spa_loop_utils_method_s(l,add_event,0,__VA_ARGS__) -#define spa_loop_utils_signal_event(l,...) spa_loop_utils_method_r(l,signal_event,0,__VA_ARGS__) -#define spa_loop_utils_add_timer(l,...) spa_loop_utils_method_s(l,add_timer,0,__VA_ARGS__) -#define spa_loop_utils_update_timer(l,...) spa_loop_utils_method_r(l,update_timer,0,__VA_ARGS__) -#define spa_loop_utils_add_signal(l,...) spa_loop_utils_method_s(l,add_signal,0,__VA_ARGS__) -#define spa_loop_utils_destroy_source(l,...) spa_loop_utils_method_v(l,destroy_source,0,__VA_ARGS__) +static inline struct spa_source * +spa_loop_utils_add_io(struct spa_loop_utils *object, int fd, uint32_t mask, + bool close, spa_source_io_func_t func, void *data) +{ + return spa_api_method_r(struct spa_source *, NULL, + spa_loop_utils, &object->iface, add_io, 0, fd, mask, close, func, data); +} +static inline int spa_loop_utils_update_io(struct spa_loop_utils *object, + struct spa_source *source, uint32_t mask) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop_utils, &object->iface, update_io, 0, source, mask); +} +static inline struct spa_source * +spa_loop_utils_add_idle(struct spa_loop_utils *object, bool enabled, + spa_source_idle_func_t func, void *data) +{ + return spa_api_method_r(struct spa_source *, NULL, + spa_loop_utils, &object->iface, add_idle, 0, enabled, func, data); +} +static inline int spa_loop_utils_enable_idle(struct spa_loop_utils *object, + struct spa_source *source, bool enabled) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop_utils, &object->iface, enable_idle, 0, source, enabled); +} +static inline struct spa_source * +spa_loop_utils_add_event(struct spa_loop_utils *object, spa_source_event_func_t func, void *data) +{ + return spa_api_method_r(struct spa_source *, NULL, + spa_loop_utils, &object->iface, add_event, 0, func, data); +} +static inline int spa_loop_utils_signal_event(struct spa_loop_utils *object, + struct spa_source *source) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop_utils, &object->iface, signal_event, 0, source); +} +static inline struct spa_source * +spa_loop_utils_add_timer(struct spa_loop_utils *object, spa_source_timer_func_t func, void *data) +{ + return spa_api_method_r(struct spa_source *, NULL, + spa_loop_utils, &object->iface, add_timer, 0, func, data); +} +static inline int spa_loop_utils_update_timer(struct spa_loop_utils *object, + struct spa_source *source, struct timespec *value, + struct timespec *interval, bool absolute) +{ + return spa_api_method_r(int, -ENOTSUP, + spa_loop_utils, &object->iface, update_timer, 0, source, + value, interval, absolute); +} +static inline struct spa_source * +spa_loop_utils_add_signal(struct spa_loop_utils *object, int signal_number, + spa_source_signal_func_t func, void *data) +{ + return spa_api_method_r(struct spa_source *, NULL, + spa_loop_utils, &object->iface, add_signal, 0, + signal_number, func, data); +} +static inline void spa_loop_utils_destroy_source(struct spa_loop_utils *object, + struct spa_source *source) +{ + spa_api_method_v(spa_loop_utils, &object->iface, destroy_source, 0, source); +} /** * \} diff --git a/spa/include/spa/support/plugin-loader.h b/spa/include/spa/support/plugin-loader.h index 9b32ebe15..e8519be69 100644 --- a/spa/include/spa/support/plugin-loader.h +++ b/spa/include/spa/support/plugin-loader.h @@ -51,23 +51,15 @@ struct spa_plugin_loader_methods { static inline struct spa_handle * spa_plugin_loader_load(struct spa_plugin_loader *loader, const char *factory_name, const struct spa_dict *info) { - struct spa_handle *res = NULL; - if (SPA_LIKELY(loader != NULL)) - spa_interface_call_res(&loader->iface, - struct spa_plugin_loader_methods, res, - load, 0, factory_name, info); - return res; + return spa_api_method_null_r(struct spa_handle *, NULL, spa_plugin_loader, &loader->iface, + load, 0, factory_name, info); } static inline int spa_plugin_loader_unload(struct spa_plugin_loader *loader, struct spa_handle *handle) { - int res = -1; - if (SPA_LIKELY(loader != NULL)) - spa_interface_call_res(&loader->iface, - struct spa_plugin_loader_methods, res, - unload, 0, handle); - return res; + return spa_api_method_null_r(int, -1, spa_plugin_loader, &loader->iface, + unload, 0, handle); } /** diff --git a/spa/include/spa/support/plugin.h b/spa/include/spa/support/plugin.h index e9fb32874..12ab8140a 100644 --- a/spa/include/spa/support/plugin.h +++ b/spa/include/spa/support/plugin.h @@ -9,7 +9,10 @@ extern "C" { #endif +#include + #include +#include #include /** @@ -51,8 +54,17 @@ struct spa_handle { int (*clear) (struct spa_handle *handle); }; -#define spa_handle_get_interface(h,...) (h)->get_interface((h),__VA_ARGS__) -#define spa_handle_clear(h) (h)->clear((h)) +static inline int +spa_handle_get_interface(struct spa_handle *object, + const char *type, void **iface) +{ + return spa_api_func_r(int, -ENOTSUP, object, get_interface, 0, type, iface); +} +static inline int +spa_handle_clear(struct spa_handle *object) +{ + return spa_api_func_r(int, -ENOTSUP, object, clear, 0); +} /** * This structure lists the information about available interfaces on @@ -158,9 +170,27 @@ struct spa_handle_factory { uint32_t *index); }; -#define spa_handle_factory_get_size(h,...) (h)->get_size((h),__VA_ARGS__) -#define spa_handle_factory_init(h,...) (h)->init((h),__VA_ARGS__) -#define spa_handle_factory_enum_interface_info(h,...) (h)->enum_interface_info((h),__VA_ARGS__) +static inline size_t +spa_handle_factory_get_size(const struct spa_handle_factory *object, + const struct spa_dict *params) +{ + return spa_api_func_r(size_t, 0, object, get_size, 1, params); +} +static inline int +spa_handle_factory_init(const struct spa_handle_factory *object, + struct spa_handle *handle, const struct spa_dict *info, + const struct spa_support *support, uint32_t n_support) +{ + return spa_api_func_r(int, -ENOTSUP, object, init, 1, handle, info, + support, n_support); +} +static inline int +spa_handle_factory_enum_interface_info(const struct spa_handle_factory *object, + const struct spa_interface_info **info, uint32_t *index) +{ + return spa_api_func_r(int, -ENOTSUP, object, enum_interface_info, 1, + info, index); +} /** * The function signature of the entry point in a plugin. diff --git a/spa/include/spa/support/system.h b/spa/include/spa/support/system.h index 9ea41bce8..88d3a6eef 100644 --- a/spa/include/spa/support/system.h +++ b/spa/include/spa/support/system.h @@ -12,6 +12,7 @@ extern "C" { struct itimerspec; #include +#include #include #include @@ -97,41 +98,106 @@ struct spa_system_methods { int (*signalfd_read) (void *object, int fd, int *signal); }; -#define spa_system_method_r(o,method,version,...) \ -({ \ - volatile int _res = -ENOTSUP; \ - struct spa_system *_o = o; \ - spa_interface_call_fast_res(&_o->iface, \ - struct spa_system_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_system_read(s,...) spa_system_method_r(s,read,0,__VA_ARGS__) -#define spa_system_write(s,...) spa_system_method_r(s,write,0,__VA_ARGS__) -#define spa_system_ioctl(s,...) spa_system_method_r(s,ioctl,0,__VA_ARGS__) -#define spa_system_close(s,...) spa_system_method_r(s,close,0,__VA_ARGS__) - -#define spa_system_clock_gettime(s,...) spa_system_method_r(s,clock_gettime,0,__VA_ARGS__) -#define spa_system_clock_getres(s,...) spa_system_method_r(s,clock_getres,0,__VA_ARGS__) - -#define spa_system_pollfd_create(s,...) spa_system_method_r(s,pollfd_create,0,__VA_ARGS__) -#define spa_system_pollfd_add(s,...) spa_system_method_r(s,pollfd_add,0,__VA_ARGS__) -#define spa_system_pollfd_mod(s,...) spa_system_method_r(s,pollfd_mod,0,__VA_ARGS__) -#define spa_system_pollfd_del(s,...) spa_system_method_r(s,pollfd_del,0,__VA_ARGS__) -#define spa_system_pollfd_wait(s,...) spa_system_method_r(s,pollfd_wait,0,__VA_ARGS__) - -#define spa_system_timerfd_create(s,...) spa_system_method_r(s,timerfd_create,0,__VA_ARGS__) -#define spa_system_timerfd_settime(s,...) spa_system_method_r(s,timerfd_settime,0,__VA_ARGS__) -#define spa_system_timerfd_gettime(s,...) spa_system_method_r(s,timerfd_gettime,0,__VA_ARGS__) -#define spa_system_timerfd_read(s,...) spa_system_method_r(s,timerfd_read,0,__VA_ARGS__) - -#define spa_system_eventfd_create(s,...) spa_system_method_r(s,eventfd_create,0,__VA_ARGS__) -#define spa_system_eventfd_write(s,...) spa_system_method_r(s,eventfd_write,0,__VA_ARGS__) -#define spa_system_eventfd_read(s,...) spa_system_method_r(s,eventfd_read,0,__VA_ARGS__) - -#define spa_system_signalfd_create(s,...) spa_system_method_r(s,signalfd_create,0,__VA_ARGS__) -#define spa_system_signalfd_read(s,...) spa_system_method_r(s,signalfd_read,0,__VA_ARGS__) +static inline ssize_t spa_system_read(struct spa_system *object, int fd, void *buf, size_t count) +{ + return spa_api_method_fast_r(ssize_t, -ENOTSUP, spa_system, &object->iface, read, 0, fd, buf, count); +} +static inline ssize_t spa_system_write(struct spa_system *object, int fd, const void *buf, size_t count) +{ + return spa_api_method_fast_r(ssize_t, -ENOTSUP, spa_system, &object->iface, write, 0, fd, buf, count); +} +#define spa_system_ioctl(object,fd,request,...) \ + spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, ioctl, 0, fd, request, ##__VA_ARGS__) + +static inline int spa_system_close(struct spa_system *object, int fd) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, close, 0, fd); +} +static inline int spa_system_clock_gettime(struct spa_system *object, + int clockid, struct timespec *value) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, clock_gettime, 0, clockid, value); +} +static inline int spa_system_clock_getres(struct spa_system *object, + int clockid, struct timespec *res) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, clock_getres, 0, clockid, res); +} + +static inline int spa_system_pollfd_create(struct spa_system *object, int flags) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_create, 0, flags); +} +static inline int spa_system_pollfd_add(struct spa_system *object, int pfd, int fd, uint32_t events, void *data) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_add, 0, pfd, fd, events, data); +} +static inline int spa_system_pollfd_mod(struct spa_system *object, int pfd, int fd, uint32_t events, void *data) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_mod, 0, pfd, fd, events, data); +} +static inline int spa_system_pollfd_del(struct spa_system *object, int pfd, int fd) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_del, 0, pfd, fd); +} +static inline int spa_system_pollfd_wait(struct spa_system *object, int pfd, + struct spa_poll_event *ev, int n_ev, int timeout) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_wait, 0, pfd, ev, n_ev, timeout); +} + +static inline int spa_system_timerfd_create(struct spa_system *object, int clockid, int flags) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_create, 0, clockid, flags); +} + +static inline int spa_system_timerfd_settime(struct spa_system *object, + int fd, int flags, + const struct itimerspec *new_value, + struct itimerspec *old_value) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_settime, 0, + fd, flags, new_value, old_value); +} + +static inline int spa_system_timerfd_gettime(struct spa_system *object, + int fd, struct itimerspec *curr_value) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_gettime, 0, + fd, curr_value); +} +static inline int spa_system_timerfd_read(struct spa_system *object, int fd, uint64_t *expirations) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_read, 0, + fd, expirations); +} + +static inline int spa_system_eventfd_create(struct spa_system *object, int flags) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_create, 0, flags); +} +static inline int spa_system_eventfd_write(struct spa_system *object, int fd, uint64_t count) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_write, 0, + fd, count); +} +static inline int spa_system_eventfd_read(struct spa_system *object, int fd, uint64_t *count) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_read, 0, + fd, count); +} + +static inline int spa_system_signalfd_create(struct spa_system *object, int signal, int flags) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, signalfd_create, 0, + signal, flags); +} + +static inline int spa_system_signalfd_read(struct spa_system *object, int fd, int *signal) +{ + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, signalfd_read, 0, + fd, signal); +} /** * \} diff --git a/spa/include/spa/support/thread.h b/spa/include/spa/support/thread.h index f691e3a30..29baa5882 100644 --- a/spa/include/spa/support/thread.h +++ b/spa/include/spa/support/thread.h @@ -61,11 +61,9 @@ struct spa_thread_utils_methods { static inline struct spa_thread *spa_thread_utils_create(struct spa_thread_utils *o, const struct spa_dict *props, void *(*start_routine)(void*), void *arg) { - struct spa_thread *res = NULL; - spa_interface_call_res(&o->iface, - struct spa_thread_utils_methods, res, create, 0, + return spa_api_method_r(struct spa_thread *, NULL, + spa_thread_utils, &o->iface, create, 0, props, start_routine, arg); - return res; } /** \copydoc spa_thread_utils_methods.join @@ -73,11 +71,9 @@ static inline struct spa_thread *spa_thread_utils_create(struct spa_thread_utils static inline int spa_thread_utils_join(struct spa_thread_utils *o, struct spa_thread *thread, void **retval) { - int res = -ENOTSUP; - spa_interface_call_res(&o->iface, - struct spa_thread_utils_methods, res, join, 0, + return spa_api_method_r(int, -ENOTSUP, + spa_thread_utils, &o->iface, join, 0, thread, retval); - return res; } /** \copydoc spa_thread_utils_methods.get_rt_range @@ -85,11 +81,9 @@ static inline int spa_thread_utils_join(struct spa_thread_utils *o, static inline int spa_thread_utils_get_rt_range(struct spa_thread_utils *o, const struct spa_dict *props, int *min, int *max) { - int res = -ENOTSUP; - spa_interface_call_res(&o->iface, - struct spa_thread_utils_methods, res, get_rt_range, 0, + return spa_api_method_r(int, -ENOTSUP, + spa_thread_utils, &o->iface, get_rt_range, 0, props, min, max); - return res; } /** \copydoc spa_thread_utils_methods.acquire_rt @@ -97,11 +91,9 @@ static inline int spa_thread_utils_get_rt_range(struct spa_thread_utils *o, static inline int spa_thread_utils_acquire_rt(struct spa_thread_utils *o, struct spa_thread *thread, int priority) { - int res = -ENOTSUP; - spa_interface_call_res(&o->iface, - struct spa_thread_utils_methods, res, acquire_rt, 0, + return spa_api_method_r(int, -ENOTSUP, + spa_thread_utils, &o->iface, acquire_rt, 0, thread, priority); - return res; } /** \copydoc spa_thread_utils_methods.drop_rt @@ -109,10 +101,8 @@ static inline int spa_thread_utils_acquire_rt(struct spa_thread_utils *o, static inline int spa_thread_utils_drop_rt(struct spa_thread_utils *o, struct spa_thread *thread) { - int res = -ENOTSUP; - spa_interface_call_res(&o->iface, - struct spa_thread_utils_methods, res, drop_rt, 0, thread); - return res; + return spa_api_method_r(int, -ENOTSUP, + spa_thread_utils, &o->iface, drop_rt, 0, thread); } #define SPA_KEY_THREAD_NAME "thread.name" /* the thread name */ diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h index aea18d28e..785b42099 100644 --- a/spa/include/spa/utils/hook.h +++ b/spa/include/spa/utils/hook.h @@ -245,6 +245,69 @@ struct spa_interface { #define spa_interface_call_fast_res(iface,method_type,res,method,vers,...) \ spa_callbacks_call_fast_res(&(iface)->cb,method_type,res,method,vers,##__VA_ARGS__) + +#define spa_api_func_v(o,method,version,...) \ +({ \ + if (SPA_LIKELY(SPA_CALLBACK_CHECK(o,method,version))) \ + (o)->method(o, ##__VA_ARGS__); \ +}) +#define spa_api_func_r(rtype,def,o,method,version,...) \ +({ \ + rtype _res = def; \ + if (SPA_LIKELY(SPA_CALLBACK_CHECK(o,method,version))) \ + _res = (o)->method(o, ##__VA_ARGS__); \ + _res; \ +}) +#define spa_api_func_fast(o,method,...) \ +({ \ + (o)->method(o, ##__VA_ARGS__); \ +}) + +#define spa_api_method_v(type,o,method,version,...) \ +({ \ + struct spa_interface *_i = o; \ + spa_interface_call(_i, struct type ##_methods, \ + method, version, ##__VA_ARGS__); \ +}) +#define spa_api_method_r(rtype,def,type,o,method,version,...) \ +({ \ + rtype _res = def; \ + struct spa_interface *_i = o; \ + spa_interface_call_res(_i, struct type ##_methods, \ + _res, method, version, ##__VA_ARGS__); \ + _res; \ +}) +#define spa_api_method_null_v(type,o,method,version,...) \ +({ \ + struct spa_interface *_i = o; \ + if (SPA_LIKELY(_i != NULL)) \ + spa_interface_call(_i, struct type ##_methods, \ + method, version, ##__VA_ARGS__); \ +}) +#define spa_api_method_null_r(rtype,def,type,o,method,version,...) \ +({ \ + rtype _res = def; \ + struct spa_interface *_i = o; \ + if (SPA_LIKELY(_i != NULL)) \ + spa_interface_call_res(_i, struct type ##_methods, \ + _res, method, version, ##__VA_ARGS__); \ + _res; \ +}) +#define spa_api_method_fast_v(type,o,method,version,...) \ +({ \ + struct spa_interface *_i = o; \ + spa_interface_call_fast(_i, struct type ##_methods, \ + method, version, ##__VA_ARGS__); \ +}) +#define spa_api_method_fast_r(rtype,def,type,o,method,version,...) \ +({ \ + rtype _res = def; \ + struct spa_interface *_i = o; \ + spa_interface_call_fast_res(_i, struct type ##_methods, \ + _res, method, version, ##__VA_ARGS__); \ + _res; \ +}) + /** * \} */ diff --git a/spa/plugins/audioconvert/fmt-ops.h b/spa/plugins/audioconvert/fmt-ops.h index 506703031..d115bcad6 100644 --- a/spa/plugins/audioconvert/fmt-ops.h +++ b/spa/plugins/audioconvert/fmt-ops.h @@ -15,7 +15,7 @@ #define FTOI(type,v,scale,offs,noise,min,max) \ (type)f32_round(SPA_CLAMPF((v) * (scale) + (offs) + (noise), min, max)) -#define FMT_OPS_MAX_ALIGN 32 +#define FMT_OPS_MAX_ALIGN 32u #define U8_MIN 0u #define U8_MAX 255u diff --git a/spa/plugins/audiomixer/mix-ops.h b/spa/plugins/audiomixer/mix-ops.h index 221474048..0d9559636 100644 --- a/spa/plugins/audiomixer/mix-ops.h +++ b/spa/plugins/audiomixer/mix-ops.h @@ -123,7 +123,7 @@ void mix_##name##_##arch(struct mix_ops *ops, void * SPA_RESTRICT dst, \ const void * SPA_RESTRICT src[], uint32_t n_src, \ uint32_t n_samples) \ -#define MIX_OPS_MAX_ALIGN 32 +#define MIX_OPS_MAX_ALIGN 32u DEFINE_FUNCTION(s8, c); DEFINE_FUNCTION(u8, c); diff --git a/spa/plugins/filter-graph/audio-dsp.h b/spa/plugins/filter-graph/audio-dsp.h index 8519b830b..c8b338fc3 100644 --- a/spa/plugins/filter-graph/audio-dsp.h +++ b/spa/plugins/filter-graph/audio-dsp.h @@ -61,43 +61,108 @@ struct spa_fga_dsp_methods { float *dst, const float *src, uint32_t n_samples); }; -#define spa_fga_dsp_method_r(o,type,method,version,...) \ -({ \ - type _res = NULL; \ - struct spa_fga_dsp *_o = o; \ - spa_interface_call_fast_res(&_o->iface, \ - struct spa_fga_dsp_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) +static inline void spa_fga_dsp_clear(struct spa_fga_dsp *obj, void * SPA_RESTRICT dst, uint32_t n_samples) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, clear, 0, + dst, n_samples); +} +static inline void spa_fga_dsp_copy(struct spa_fga_dsp *obj, + void * SPA_RESTRICT dst, + const void * SPA_RESTRICT src, uint32_t n_samples) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, copy, 0, + dst, src, n_samples); +} +static inline void spa_fga_dsp_mix_gain(struct spa_fga_dsp *obj, + void * SPA_RESTRICT dst, + const void * SPA_RESTRICT src[], + float gain[], uint32_t n_src, uint32_t n_samples) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, mix_gain, 0, + dst, src, gain, n_src, n_samples); +} +static inline void spa_fga_dsp_sum(struct spa_fga_dsp *obj, + float * dst, const float * SPA_RESTRICT a, + const float * SPA_RESTRICT b, uint32_t n_samples) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, sum, 0, + dst, a, b, n_samples); +} - -#define spa_fga_dsp_method(o,method,version,...) \ -({ \ - struct spa_fga_dsp *_o = o; \ - spa_interface_call_fast(&_o->iface, \ - struct spa_fga_dsp_methods, \ - method, version, ##__VA_ARGS__); \ -}) - - -#define spa_fga_dsp_clear(o,...) spa_fga_dsp_method(o,clear,0,__VA_ARGS__) -#define spa_fga_dsp_copy(o,...) spa_fga_dsp_method(o,copy,0,__VA_ARGS__) -#define spa_fga_dsp_mix_gain(o,...) spa_fga_dsp_method(o,mix_gain,0,__VA_ARGS__) -#define spa_fga_dsp_biquad_run(o,...) spa_fga_dsp_method(o,biquad_run,0,__VA_ARGS__) -#define spa_fga_dsp_sum(o,...) spa_fga_dsp_method(o,sum,0,__VA_ARGS__) -#define spa_fga_dsp_linear(o,...) spa_fga_dsp_method(o,linear,0,__VA_ARGS__) -#define spa_fga_dsp_mult(o,...) spa_fga_dsp_method(o,mult,0,__VA_ARGS__) -#define spa_fga_dsp_delay(o,...) spa_fga_dsp_method(o,delay,0,__VA_ARGS__) - -#define spa_fga_dsp_fft_new(o,...) spa_fga_dsp_method_r(o,void*,fft_new,0,__VA_ARGS__) -#define spa_fga_dsp_fft_free(o,...) spa_fga_dsp_method(o,fft_free,0,__VA_ARGS__) -#define spa_fga_dsp_fft_memalloc(o,...) spa_fga_dsp_method_r(o,void*,fft_memalloc,0,__VA_ARGS__) -#define spa_fga_dsp_fft_memfree(o,...) spa_fga_dsp_method(o,fft_memfree,0,__VA_ARGS__) -#define spa_fga_dsp_fft_memclear(o,...) spa_fga_dsp_method(o,fft_memclear,0,__VA_ARGS__) -#define spa_fga_dsp_fft_run(o,...) spa_fga_dsp_method(o,fft_run,0,__VA_ARGS__) -#define spa_fga_dsp_fft_cmul(o,...) spa_fga_dsp_method(o,fft_cmul,0,__VA_ARGS__) -#define spa_fga_dsp_fft_cmul(o,...) spa_fga_dsp_method(o,fft_cmul,0,__VA_ARGS__) -#define spa_fga_dsp_fft_cmuladd(o,...) spa_fga_dsp_method(o,fft_cmuladd,0,__VA_ARGS__) +static inline void *spa_fga_dsp_fft_new(struct spa_fga_dsp *obj, uint32_t size, bool real) +{ + return spa_api_method_r(void *, NULL, spa_fga_dsp, &obj->iface, fft_new, 0, + size, real); +} +static inline void spa_fga_dsp_fft_free(struct spa_fga_dsp *obj, void *fft) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, fft_free, 0, + fft); +} +static inline void *spa_fga_dsp_fft_memalloc(struct spa_fga_dsp *obj, uint32_t size, bool real) +{ + return spa_api_method_r(void *, NULL, spa_fga_dsp, &obj->iface, fft_memalloc, 0, + size, real); +} +static inline void spa_fga_dsp_fft_memfree(struct spa_fga_dsp *obj, void *mem) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, fft_memfree, 0, + mem); +} +static inline void spa_fga_dsp_fft_memclear(struct spa_fga_dsp *obj, void *mem, uint32_t size, bool real) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, fft_memclear, 0, + mem, size, real); +} +static inline void spa_fga_dsp_fft_run(struct spa_fga_dsp *obj, void *fft, int direction, + const float * SPA_RESTRICT src, float * SPA_RESTRICT dst) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, fft_run, 0, + fft, direction, src, dst); +} +static inline void spa_fga_dsp_fft_cmul(struct spa_fga_dsp *obj, void *fft, + float * SPA_RESTRICT dst, const float * SPA_RESTRICT a, + const float * SPA_RESTRICT b, uint32_t len, const float scale) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, fft_cmul, 0, + fft, dst, a, b, len, scale); +} +static inline void spa_fga_dsp_fft_cmuladd(struct spa_fga_dsp *obj, void *fft, + float * dst, const float * src, + const float * SPA_RESTRICT a, const float * SPA_RESTRICT b, + uint32_t len, const float scale) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, fft_cmuladd, 0, + fft, dst, src, a, b, len, scale); +} +static inline void spa_fga_dsp_linear(struct spa_fga_dsp *obj, + float * dst, const float * SPA_RESTRICT src, + const float mult, const float add, uint32_t n_samples) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, linear, 0, + dst, src, mult, add, n_samples); +} +static inline void spa_fga_dsp_mult(struct spa_fga_dsp *obj, + void * SPA_RESTRICT dst, + const void * SPA_RESTRICT src[], uint32_t n_src, uint32_t n_samples) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, mult, 0, + dst, src, n_src, n_samples); +} +static inline void spa_fga_dsp_biquad_run(struct spa_fga_dsp *obj, + struct biquad *bq, uint32_t n_bq, uint32_t bq_stride, + float * SPA_RESTRICT out[], const float * SPA_RESTRICT in[], + uint32_t n_src, uint32_t n_samples) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, biquad_run, 0, + bq, n_bq, bq_stride, out, in, n_src, n_samples); +} +static inline void spa_fga_dsp_delay(struct spa_fga_dsp *obj, + float *buffer, uint32_t *pos, uint32_t n_buffer, uint32_t delay, + float *dst, const float *src, uint32_t n_samples) +{ + spa_api_method_v(spa_fga_dsp, &obj->iface, delay, 0, + buffer, pos, n_buffer, delay, dst, src, n_samples); +} #endif /* SPA_FGA_DSP_H */ diff --git a/spa/plugins/filter-graph/audio-plugin.h b/spa/plugins/filter-graph/audio-plugin.h index 1e2e31051..e05d7a80a 100644 --- a/spa/plugins/filter-graph/audio-plugin.h +++ b/spa/plugins/filter-graph/audio-plugin.h @@ -78,26 +78,12 @@ static inline void spa_fga_descriptor_free(const struct spa_fga_descriptor *desc desc->free(desc); } -#define spa_fga_plugin_method_r(o,method,version,...) \ -({ \ - const void * _res = NULL; \ - struct spa_fga_plugin *_o = o; \ - spa_interface_call_fast_res(&_o->iface, \ - struct spa_fga_plugin_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define spa_fga_plugin_method(o,method,version,...) \ -({ \ - struct spa_fga_plugin *_o = o; \ - spa_interface_call_fast(&_o->iface, \ - struct spa_fga_plugin_methods, \ - method, version, ##__VA_ARGS__); \ -}) - - -#define spa_fga_plugin_make_desc(o,...) spa_fga_plugin_method_r(o,make_desc,0,__VA_ARGS__) +static inline const struct spa_fga_descriptor * +spa_fga_plugin_make_desc(struct spa_fga_plugin *plugin, const char *name) +{ + return spa_api_method_r(const struct spa_fga_descriptor *, NULL, + spa_fga_plugin, &plugin->iface, make_desc, 0, name); +} typedef struct spa_fga_plugin *(spa_filter_graph_audio_plugin_load_func_t)(const struct spa_support *support, uint32_t n_support, const char *path, const struct spa_dict *info); diff --git a/spa/plugins/videoconvert/videoconvert-ffmpeg.c b/spa/plugins/videoconvert/videoconvert-ffmpeg.c index 413dd45aa..955bfa93a 100644 --- a/spa/plugins/videoconvert/videoconvert-ffmpeg.c +++ b/spa/plugins/videoconvert/videoconvert-ffmpeg.c @@ -41,7 +41,7 @@ #define SPA_LOG_TOPIC_DEFAULT &log_topic SPA_LOG_TOPIC_DEFINE_STATIC(log_topic, "spa.videoconvert.ffmpeg"); -#define MAX_ALIGN 64 +#define MAX_ALIGN 64u #define MAX_BUFFERS 32 #define MAX_DATAS 4 #define MAX_PORTS (1+1) diff --git a/src/pipewire/client.h b/src/pipewire/client.h index cd119643e..a08eb271f 100644 --- a/src/pipewire/client.h +++ b/src/pipewire/client.h @@ -150,20 +150,35 @@ struct pw_client_methods { const struct pw_permission *permissions); }; -#define pw_client_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_client_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_client_add_listener(c,...) pw_client_method(c,add_listener,0,__VA_ARGS__) -#define pw_client_error(c,...) pw_client_method(c,error,0,__VA_ARGS__) -#define pw_client_update_properties(c,...) pw_client_method(c,update_properties,0,__VA_ARGS__) -#define pw_client_get_permissions(c,...) pw_client_method(c,get_permissions,0,__VA_ARGS__) -#define pw_client_update_permissions(c,...) pw_client_method(c,update_permissions,0,__VA_ARGS__) +static inline int pw_client_add_listener(struct pw_client *object, + struct spa_hook *listener, + const struct pw_client_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} +static inline int pw_client_error(struct pw_client *object, uint32_t id, int res, const char *message) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client, (struct spa_interface*)object, error, 0, + id, res, message); +} +static inline int pw_client_update_properties(struct pw_client *object, const struct spa_dict *props) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client, (struct spa_interface*)object, update_properties, 0, + props); +} +static inline int pw_client_get_permissions(struct pw_client *object, uint32_t index, uint32_t num) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client, (struct spa_interface*)object, get_permissions, 0, + index, num); +} +static inline int pw_client_update_permissions(struct pw_client *object, uint32_t n_permissions, + const struct pw_permission *permissions) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client, (struct spa_interface*)object, update_permissions, 0, + n_permissions, permissions); +} /** * \} diff --git a/src/pipewire/core.h b/src/pipewire/core.h index 171d35d68..e5a0f02aa 100644 --- a/src/pipewire/core.h +++ b/src/pipewire/core.h @@ -334,22 +334,40 @@ struct pw_core_methods { int (*destroy) (void *object, void *proxy); }; -#define pw_core_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_core_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__) -#define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__) -#define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__) -#define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__) -#define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__) - +static inline int pw_core_add_listener(struct pw_core *object, + struct spa_hook *listener, + const struct pw_core_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_core, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} +static inline int pw_core_hello(struct pw_core *object, uint32_t version) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_core, (struct spa_interface*)object, hello, 0, + version); +} +static inline int pw_core_sync(struct pw_core *object, uint32_t id, int seq) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_core, (struct spa_interface*)object, sync, 0, + id, seq); +} +static inline int pw_core_pong(struct pw_core *object, uint32_t id, int seq) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_core, (struct spa_interface*)object, pong, 0, + id, seq); +} +static inline int pw_core_error(struct pw_core *object, uint32_t id, int seq, int res, const char *message) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_core, (struct spa_interface*)object, error, 0, + id, seq, res, message); +} static inline SPA_PRINTF_FUNC(5, 0) int pw_core_errorv(struct pw_core *core, uint32_t id, int seq, @@ -377,13 +395,10 @@ pw_core_errorf(struct pw_core *core, uint32_t id, int seq, static inline struct pw_registry * pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size) { - struct pw_registry *res = NULL; - spa_interface_call_res((struct spa_interface*)core, - struct pw_core_methods, res, - get_registry, 0, version, user_data_size); - return res; + return spa_api_method_r(struct pw_registry*, NULL, + pw_core, (struct spa_interface*)core, get_registry, 0, + version, user_data_size); } - static inline void * pw_core_create_object(struct pw_core *core, const char *factory_name, @@ -392,15 +407,16 @@ pw_core_create_object(struct pw_core *core, const struct spa_dict *props, size_t user_data_size) { - void *res = NULL; - spa_interface_call_res((struct spa_interface*)core, - struct pw_core_methods, res, - create_object, 0, factory_name, - type, version, props, user_data_size); - return res; + return spa_api_method_r(void*, NULL, + pw_core, (struct spa_interface*)core, create_object, 0, + factory_name, type, version, props, user_data_size); +} +static inline void +pw_core_destroy(struct pw_core *core, void *proxy) +{ + spa_api_method_v(pw_core, (struct spa_interface*)core, destroy, 0, + proxy); } - -#define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__) /** * \} @@ -516,31 +532,31 @@ struct pw_registry_methods { int (*destroy) (void *object, uint32_t id); }; -#define pw_registry_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_registry_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - /** Registry */ -#define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__) - +static inline int pw_registry_add_listener(struct pw_registry *registry, + struct spa_hook *listener, + const struct pw_registry_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_registry, (struct spa_interface*)registry, add_listener, 0, + listener, events, data); +} static inline void * pw_registry_bind(struct pw_registry *registry, uint32_t id, const char *type, uint32_t version, size_t user_data_size) { - void *res = NULL; - spa_interface_call_res((struct spa_interface*)registry, - struct pw_registry_methods, res, - bind, 0, id, type, version, user_data_size); - return res; + return spa_api_method_r(void*, NULL, + pw_registry, (struct spa_interface*)registry, bind, 0, + id, type, version, user_data_size); +} +static inline int +pw_registry_destroy(struct pw_registry *registry, uint32_t id) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_registry, (struct spa_interface*)registry, destroy, 0, id); } - -#define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__) /** * \} diff --git a/src/pipewire/device.h b/src/pipewire/device.h index 4b546b994..7c5520eee 100644 --- a/src/pipewire/device.h +++ b/src/pipewire/device.h @@ -141,19 +141,36 @@ struct pw_device_methods { const struct spa_pod *param); }; -#define pw_device_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_device_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_device_add_listener(c,...) pw_device_method(c,add_listener,0,__VA_ARGS__) -#define pw_device_subscribe_params(c,...) pw_device_method(c,subscribe_params,0,__VA_ARGS__) -#define pw_device_enum_params(c,...) pw_device_method(c,enum_params,0,__VA_ARGS__) -#define pw_device_set_param(c,...) pw_device_method(c,set_param,0,__VA_ARGS__) +static inline int pw_device_add_listener(struct pw_device *object, + struct spa_hook *listener, + const struct pw_device_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_device, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} +static inline int pw_device_subscribe_params(struct pw_device *object, uint32_t *ids, uint32_t n_ids) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_device, (struct spa_interface*)object, subscribe_params, 0, + ids, n_ids); +} +static inline int pw_device_enum_params(struct pw_device *object, + int seq, uint32_t id, uint32_t start, uint32_t num, + const struct spa_pod *filter) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_device, (struct spa_interface*)object, enum_params, 0, + seq, id, start, num, filter); +} +static inline int pw_device_set_param(struct pw_device *object, uint32_t id, uint32_t flags, + const struct spa_pod *param) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_device, (struct spa_interface*)object, set_param, 0, + id, flags, param); +} /** * \} diff --git a/src/pipewire/extensions/client-node.h b/src/pipewire/extensions/client-node.h index d1c6e7338..65d5a4df2 100644 --- a/src/pipewire/extensions/client-node.h +++ b/src/pipewire/extensions/client-node.h @@ -303,33 +303,54 @@ struct pw_client_node_methods { struct spa_buffer **buffers); }; - -#define pw_client_node_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_client_node_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_client_node_add_listener(c,...) pw_client_node_method(c,add_listener,0,__VA_ARGS__) - +static inline int pw_client_node_add_listener(struct pw_client_node *object, + struct spa_hook *listener, + const struct pw_client_node_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client_node, (struct spa_interface*)object, + add_listener, 0, listener, events, data); +} static inline struct pw_node * pw_client_node_get_node(struct pw_client_node *p, uint32_t version, size_t user_data_size) { - struct pw_node *res = NULL; - spa_interface_call_res((struct spa_interface*)p, - struct pw_client_node_methods, res, + return spa_api_method_r(struct pw_node*, NULL, pw_client_node, (struct spa_interface*)p, get_node, 0, version, user_data_size); - return res; } - -#define pw_client_node_update(c,...) pw_client_node_method(c,update,0,__VA_ARGS__) -#define pw_client_node_port_update(c,...) pw_client_node_method(c,port_update,0,__VA_ARGS__) -#define pw_client_node_set_active(c,...) pw_client_node_method(c,set_active,0,__VA_ARGS__) -#define pw_client_node_event(c,...) pw_client_node_method(c,event,0,__VA_ARGS__) -#define pw_client_node_port_buffers(c,...) pw_client_node_method(c,port_buffers,0,__VA_ARGS__) +static inline int pw_client_node_update(struct pw_client_node *object, + uint32_t change_mask, + uint32_t n_params, const struct spa_pod **params, + const struct spa_node_info *info) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client_node, (struct spa_interface*)object, + update, 0, change_mask, n_params, params, info); +} +static inline int pw_client_node_port_update(struct pw_client_node *object, + enum spa_direction direction, uint32_t port_id, + uint32_t change_mask, + uint32_t n_params, const struct spa_pod **params, + const struct spa_port_info *info) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client_node, (struct spa_interface*)object, + port_update, 0, direction, port_id, change_mask, n_params, params, info); +} +static inline int pw_client_node_set_active(struct pw_client_node *object, bool active) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client_node, (struct spa_interface*)object, + set_active, 0, active); +} +static inline int pw_client_node_event(struct pw_client_node *object, const struct spa_event *event) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client_node, (struct spa_interface*)object, + event, 0, event); +} +static inline int pw_client_node_port_buffers(struct pw_client_node *object, + enum spa_direction direction, uint32_t port_id, + uint32_t mix_id, uint32_t n_buffers, struct spa_buffer **buffers) +{ + return spa_api_method_r(int, -ENOTSUP, pw_client_node, (struct spa_interface*)object, + port_buffers, 0, direction, port_id, mix_id, n_buffers, buffers); +} /** * \} diff --git a/src/pipewire/extensions/metadata.h b/src/pipewire/extensions/metadata.h index 8c0641fbb..0504ae5fe 100644 --- a/src/pipewire/extensions/metadata.h +++ b/src/pipewire/extensions/metadata.h @@ -89,19 +89,30 @@ struct pw_metadata_methods { int (*clear) (void *object); }; - -#define pw_metadata_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_metadata_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_metadata_add_listener(c,...) pw_metadata_method(c,add_listener,0,__VA_ARGS__) -#define pw_metadata_set_property(c,...) pw_metadata_method(c,set_property,0,__VA_ARGS__) -#define pw_metadata_clear(c) pw_metadata_method(c,clear,0) +static inline int pw_metadata_add_listener(struct pw_metadata *object, + struct spa_hook *listener, + const struct pw_metadata_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_metadata, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} +static inline int pw_metadata_set_property(struct pw_metadata *object, + uint32_t subject, + const char *key, + const char *type, + const char *value) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_metadata, (struct spa_interface*)object, set_property, 0, + subject, key, type, value); +} +static inline int pw_metadata_clear(struct pw_metadata *object) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_metadata, (struct spa_interface*)object, clear, 0); +} #define PW_KEY_METADATA_NAME "metadata.name" #define PW_KEY_METADATA_VALUES "metadata.values" diff --git a/src/pipewire/extensions/profiler.h b/src/pipewire/extensions/profiler.h index 81e997b4c..fc0b56626 100644 --- a/src/pipewire/extensions/profiler.h +++ b/src/pipewire/extensions/profiler.h @@ -53,16 +53,15 @@ struct pw_profiler_methods { void *data); }; -#define pw_profiler_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_profiler_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_profiler_add_listener(c,...) pw_profiler_method(c,add_listener,0,__VA_ARGS__) +static inline int pw_profiler_add_listener(struct pw_profiler *object, + struct spa_hook *listener, + const struct pw_profiler_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_profiler, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} #define PW_KEY_PROFILER_NAME "profiler.name" diff --git a/src/pipewire/extensions/security-context.h b/src/pipewire/extensions/security-context.h index e21b5a3d9..347ed6fb2 100644 --- a/src/pipewire/extensions/security-context.h +++ b/src/pipewire/extensions/security-context.h @@ -94,18 +94,23 @@ struct pw_security_context_methods { const struct spa_dict *props); }; - -#define pw_security_context_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_security_context_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_security_context_add_listener(c,...) pw_security_context_method(c,add_listener,0,__VA_ARGS__) -#define pw_security_context_create(c,...) pw_security_context_method(c,create,0,__VA_ARGS__) +static inline int pw_security_context_add_listener(struct pw_security_context *object, + struct spa_hook *listener, + const struct pw_security_context_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_security_context, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} + +static inline int pw_security_context_create(struct pw_security_context *object, + int listen_fd, int close_fd, const struct spa_dict *props) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_security_context, (struct spa_interface*)object, create, 0, + listen_fd, close_fd, props); +} /** * \} diff --git a/src/pipewire/factory.h b/src/pipewire/factory.h index 6eda0420d..517407120 100644 --- a/src/pipewire/factory.h +++ b/src/pipewire/factory.h @@ -83,16 +83,15 @@ struct pw_factory_methods { void *data); }; -#define pw_factory_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_factory_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_factory_add_listener(c,...) pw_factory_method(c,add_listener,0,__VA_ARGS__) +static inline int pw_factory_add_listener(struct pw_factory *object, + struct spa_hook *listener, + const struct pw_factory_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_factory, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} /** * \} diff --git a/src/pipewire/link.h b/src/pipewire/link.h index ef96dfe21..7ce0cb592 100644 --- a/src/pipewire/link.h +++ b/src/pipewire/link.h @@ -108,16 +108,15 @@ struct pw_link_methods { void *data); }; -#define pw_link_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_link_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_link_add_listener(c,...) pw_link_method(c,add_listener,0,__VA_ARGS__) +static inline int pw_link_add_listener(struct pw_link *object, + struct spa_hook *listener, + const struct pw_link_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_link, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} /** * \} diff --git a/src/pipewire/module.h b/src/pipewire/module.h index bd4eca616..3bb4d6b4e 100644 --- a/src/pipewire/module.h +++ b/src/pipewire/module.h @@ -81,16 +81,15 @@ struct pw_module_methods { void *data); }; -#define pw_module_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_module_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_module_add_listener(c,...) pw_module_method(c,add_listener,0,__VA_ARGS__) +static inline int pw_module_add_listener(struct pw_module *object, + struct spa_hook *listener, + const struct pw_module_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_module, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} /** * \} diff --git a/src/pipewire/node.h b/src/pipewire/node.h index 87ba1a06e..408a3e67b 100644 --- a/src/pipewire/node.h +++ b/src/pipewire/node.h @@ -179,21 +179,42 @@ struct pw_node_methods { int (*send_command) (void *object, const struct spa_command *command); }; -#define pw_node_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_node_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -/** Node */ -#define pw_node_add_listener(c,...) pw_node_method(c,add_listener,0,__VA_ARGS__) -#define pw_node_subscribe_params(c,...) pw_node_method(c,subscribe_params,0,__VA_ARGS__) -#define pw_node_enum_params(c,...) pw_node_method(c,enum_params,0,__VA_ARGS__) -#define pw_node_set_param(c,...) pw_node_method(c,set_param,0,__VA_ARGS__) -#define pw_node_send_command(c,...) pw_node_method(c,send_command,0,__VA_ARGS__) + +static inline int pw_node_add_listener(struct pw_node *object, + struct spa_hook *listener, + const struct pw_node_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_node, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} +static inline int pw_node_subscribe_params(struct pw_node *object, uint32_t *ids, uint32_t n_ids) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_node, (struct spa_interface*)object, subscribe_params, 0, + ids, n_ids); +} +static inline int pw_node_enum_params(struct pw_node *object, + int seq, uint32_t id, uint32_t start, uint32_t num, + const struct spa_pod *filter) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_node, (struct spa_interface*)object, enum_params, 0, + seq, id, start, num, filter); +} +static inline int pw_node_set_param(struct pw_node *object, uint32_t id, uint32_t flags, + const struct spa_pod *param) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_node, (struct spa_interface*)object, set_param, 0, + id, flags, param); +} +static inline int pw_node_send_command(struct pw_node *object, const struct spa_command *command) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_node, (struct spa_interface*)object, send_command, 0, command); +} /** * \} diff --git a/src/pipewire/port.h b/src/pipewire/port.h index d0ada8b73..6af7de5a5 100644 --- a/src/pipewire/port.h +++ b/src/pipewire/port.h @@ -141,18 +141,29 @@ struct pw_port_methods { const struct spa_pod *filter); }; -#define pw_port_method(o,method,version,...) \ -({ \ - int _res = -ENOTSUP; \ - spa_interface_call_res((struct spa_interface*)o, \ - struct pw_port_methods, _res, \ - method, version, ##__VA_ARGS__); \ - _res; \ -}) - -#define pw_port_add_listener(c,...) pw_port_method(c,add_listener,0,__VA_ARGS__) -#define pw_port_subscribe_params(c,...) pw_port_method(c,subscribe_params,0,__VA_ARGS__) -#define pw_port_enum_params(c,...) pw_port_method(c,enum_params,0,__VA_ARGS__) +static inline int pw_port_add_listener(struct pw_port *object, + struct spa_hook *listener, + const struct pw_port_events *events, + void *data) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_port, (struct spa_interface*)object, add_listener, 0, + listener, events, data); +} +static inline int pw_port_subscribe_params(struct pw_port *object, uint32_t *ids, uint32_t n_ids) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_port, (struct spa_interface*)object, subscribe_params, 0, + ids, n_ids); +} +static inline int pw_port_enum_params(struct pw_port *object, + int seq, uint32_t id, uint32_t start, uint32_t num, + const struct spa_pod *filter) +{ + return spa_api_method_r(int, -ENOTSUP, + pw_port, (struct spa_interface*)object, enum_params, 0, + seq, id, start, num, filter); +} /** * \} diff --git a/src/tools/pw-top.c b/src/tools/pw-top.c index a0e41e9c0..3f9a71729 100644 --- a/src/tools/pw-top.c +++ b/src/tools/pw-top.c @@ -8,6 +8,8 @@ #include #include +#undef clear + #include #include #include