diff --git a/pipewire-jack b/pipewire-jack index 640a50091..998263819 160000 --- a/pipewire-jack +++ b/pipewire-jack @@ -1 +1 @@ -Subproject commit 640a50091ec972ecbb121b5f0928eb015435b0df +Subproject commit 998263819ab94ca1188782b66dc26b9f518b1bc5 diff --git a/pipewire-pulseaudio b/pipewire-pulseaudio index a1a5ae1d6..2057d7955 160000 --- a/pipewire-pulseaudio +++ b/pipewire-pulseaudio @@ -1 +1 @@ -Subproject commit a1a5ae1d6859b7ef2d55678e36fa5c9d458b1c65 +Subproject commit 2057d7955ce73db0e9cd16d38bbaf8c05b06fb80 diff --git a/spa/examples/example-control.c b/spa/examples/example-control.c index 2aaa56114..0d46c2f98 100644 --- a/spa/examples/example-control.c +++ b/spa/examples/example-control.c @@ -250,9 +250,9 @@ static const struct spa_node_callbacks sink_callbacks = { .reuse_buffer = on_sink_reuse_buffer }; -static int do_add_source(struct spa_loop *loop, struct spa_source *source) +static int do_add_source(void *object, struct spa_source *source) { - struct data *data = SPA_CONTAINER_OF(loop, struct data, data_loop); + struct data *data = object; data->sources[data->n_sources] = *source; data->n_sources++; @@ -261,22 +261,19 @@ static int do_add_source(struct spa_loop *loop, struct spa_source *source) return 0; } -static int do_update_source(struct spa_source *source) -{ - return 0; -} - -static void do_remove_source(struct spa_source *source) -{ -} - static int -do_invoke(struct spa_loop *loop, +do_invoke(void *object, spa_invoke_func_t func, uint32_t seq, const void *data, size_t size, bool block, void *user_data) { - return func(loop, false, seq, data, size, user_data); + return func(object, false, seq, data, size, user_data); } +static const struct spa_loop_methods impl_loop = { + SPA_VERSION_LOOP_METHODS, + .add_source = do_add_source, + .invoke = do_invoke, +}; + static int make_nodes(struct data *data, const char *device) { int res; @@ -505,11 +502,8 @@ int main(int argc, char *argv[]) spa_graph_init(&data.graph, &data.graph_state); data.log = &default_log.log; - data.data_loop.version = SPA_VERSION_LOOP; - data.data_loop.add_source = do_add_source; - data.data_loop.update_source = do_update_source; - data.data_loop.remove_source = do_remove_source; - data.data_loop.invoke = do_invoke; + data.data_loop.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Loop, SPA_VERSION_LOOP, &impl_loop, &data); if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); diff --git a/spa/include/spa/monitor/device.h b/spa/include/spa/monitor/device.h index dbb3c4d86..615acf788 100644 --- a/spa/include/spa/monitor/device.h +++ b/spa/include/spa/monitor/device.h @@ -29,14 +29,20 @@ extern "C" { #endif -struct spa_device; - #include #include #include #include #include +/** + * spa_device: + * + * The device interface. + */ +#define SPA_VERSION_DEVICE 0 +struct spa_device { struct spa_interface iface; }; + struct spa_device_info { #define SPA_VERSION_DEVICE_INFO 0 uint32_t version; @@ -103,14 +109,12 @@ struct spa_device_events { }; /** - * spa_device: - * - * The device interface. + * spa_device_methods: */ -struct spa_device { - /* the version of this device. This can be used to expand this +struct spa_device_methods { + /* the version of the methods. This can be used to expand this * structure in the future */ -#define SPA_VERSION_DEVICE 0 +#define SPA_VERSION_DEVICE_METHODS 0 uint32_t version; /** @@ -128,7 +132,7 @@ struct spa_device { * \return 0 on success * < 0 errno on error */ - int (*add_listener) (struct spa_device *device, + int (*add_listener) (void *object, struct spa_hook *listener, const struct spa_device_events *events, void *data); @@ -157,7 +161,7 @@ struct spa_device { * -ENOTSUP when there are no parameters * implemented on \a device */ - int (*enum_params) (struct spa_device *device, int seq, + int (*enum_params) (void *object, int seq, uint32_t id, uint32_t index, uint32_t max, const struct spa_pod *filter); @@ -182,14 +186,24 @@ struct spa_device { * -ENOTSUP when there are no parameters implemented on \a device * -ENOENT the parameter is unknown */ - int (*set_param) (struct spa_device *device, + int (*set_param) (void *object, uint32_t id, uint32_t flags, const struct spa_pod *param); }; -#define spa_device_add_listener(d,...) (d)->add_listener((d),__VA_ARGS__) -#define spa_device_enum_params(d,...) (d)->enum_params((d),__VA_ARGS__) -#define spa_device_set_param(d,...) (d)->set_param((d),__VA_ARGS__) +#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_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__) #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/monitor/monitor.h b/spa/include/spa/monitor/monitor.h index bbf244c01..4d80827bb 100644 --- a/spa/include/spa/monitor/monitor.h +++ b/spa/include/spa/monitor/monitor.h @@ -29,13 +29,14 @@ extern "C" { #endif -struct spa_monitor; - #include #include #include #include +#define SPA_VERSION_MONITOR 0 +struct spa_monitor { struct spa_interface iface; }; + enum spa_monitor_event { SPA_MONITOR_EVENT_Invalid, SPA_MONITOR_EVENT_Added, @@ -87,14 +88,14 @@ struct spa_monitor_callbacks { }; /** - * spa_monitor: + * spa_monitor_methods: * - * The device monitor interface. + * The device monitor methods. */ -struct spa_monitor { +struct spa_monitor_methods { /* the version of this monitor. This can be used to expand this * structure in the future */ -#define SPA_VERSION_MONITOR 0 +#define SPA_VERSION_MONITOR_METHODS 0 uint32_t version; /** @@ -108,12 +109,21 @@ struct spa_monitor { * \return 0 on success * < 0 errno on error */ - int (*set_callbacks) (struct spa_monitor *monitor, + int (*set_callbacks) (void *object, const struct spa_monitor_callbacks *callbacks, void *data); }; -#define spa_monitor_set_callbacks(m,...) (m)->set_callbacks((m),__VA_ARGS__) +static inline int spa_monitor_set_callbacks(struct spa_monitor *m, + const struct spa_monitor_callbacks *callbacks, void *data) +{ + int res = -ENOTSUP; + spa_interface_call_res(&m->iface, + struct spa_monitor_methods, res, set_callbacks, 0, + callbacks, data); + return res; + +} #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/node/node.h b/spa/include/spa/node/node.h index 480509f18..45533d474 100644 --- a/spa/include/spa/node/node.h +++ b/spa/include/spa/node/node.h @@ -29,13 +29,18 @@ extern "C" { #endif -struct spa_node; - #include #include #include #include + +/** + * A spa_node is a component that can consume and produce buffers. + */ +#define SPA_VERSION_NODE 0 +struct spa_node { struct spa_interface iface; }; + #include #include @@ -206,14 +211,13 @@ struct spa_node_callbacks { #define SPA_NODE_PARAM_FLAG_NEAREST (1 << 2) /* allow set fields to be rounded to the * nearest allowed field value. */ - /** - * A spa_node is a component that can consume and produce buffers. + * Node methods */ -struct spa_node { - /* the version of this node. This can be used to expand this +struct spa_node_methods { + /* the version of the node methods. This can be used to expand this * structure in the future */ -#define SPA_VERSION_NODE 0 +#define SPA_VERSION_NODE_METHODS 0 uint32_t version; /** @@ -230,7 +234,7 @@ struct spa_node { * \return 0 on success * < 0 errno on error */ - int (*add_listener) (struct spa_node *node, + int (*add_listener) (void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data); @@ -247,7 +251,7 @@ struct spa_node { * \return 0 on success * -EINVAL when node is NULL */ - int (*set_callbacks) (struct spa_node *node, + int (*set_callbacks) (void *object, const struct spa_node_callbacks *callbacks, void *data); /** @@ -265,7 +269,7 @@ struct spa_node { * -EINVAL when node is NULL * an async result */ - int (*sync) (struct spa_node *node, int seq); + int (*sync) (void *object, int seq); /** * Enumerate the parameters of a node. @@ -298,7 +302,7 @@ struct spa_node { * an async return value when the result event will be * emited later. */ - int (*enum_params) (struct spa_node *node, int seq, + int (*enum_params) (void *object, int seq, uint32_t id, uint32_t start, uint32_t max, const struct spa_pod *filter); @@ -323,7 +327,7 @@ struct spa_node { * -ENOTSUP when there are no parameters implemented on \a node * -ENOENT the parameter is unknown */ - int (*set_param) (struct spa_node *node, + int (*set_param) (void *object, uint32_t id, uint32_t flags, const struct spa_pod *param); @@ -345,7 +349,7 @@ struct spa_node { * -ENOENT when \a id is unknown * -ENOSPC when \a size is too small */ - int (*set_io) (struct spa_node *node, + int (*set_io) (void *object, uint32_t id, void *data, size_t size); /** @@ -362,7 +366,7 @@ struct spa_node { * -ENOTSUP when this node can't process commands * -EINVAL \a command is an invalid command */ - int (*send_command) (struct spa_node *node, const struct spa_command *command); + int (*send_command) (void *object, const struct spa_command *command); /** * Make a new port with \a port_id. The caller should use the lowest unused @@ -380,7 +384,7 @@ struct spa_node { * \return 0 on success * -EINVAL when node is NULL */ - int (*add_port) (struct spa_node *node, + int (*add_port) (void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props); @@ -394,7 +398,7 @@ struct spa_node { * -EINVAL when node is NULL or when port_id is unknown or * when the port can't be removed. */ - int (*remove_port) (struct spa_node *node, + int (*remove_port) (void *object, enum spa_direction direction, uint32_t port_id); /** @@ -427,7 +431,7 @@ struct spa_node { * an async return value when the result event will be * emited later. */ - int (*port_enum_params) (struct spa_node *node, int seq, + int (*port_enum_params) (void *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); @@ -455,7 +459,7 @@ struct spa_node { * -ESRCH when the type or size of a property is not correct. * -ENOENT when the param id is not found */ - int (*port_set_param) (struct spa_node *node, + int (*port_set_param) (void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, @@ -493,7 +497,7 @@ struct spa_node { * \param n_buffers number of elements in \a buffers * \return 0 on success */ - int (*port_use_buffers) (struct spa_node *node, + int (*port_use_buffers) (void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, @@ -530,7 +534,7 @@ struct spa_node { * \return 0 on success * -EBUSY when the node already has allocated buffers. */ - int (*port_alloc_buffers) (struct spa_node *node, + int (*port_alloc_buffers) (void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -558,7 +562,7 @@ struct spa_node { * -ENOENT when \a id is unknown * -ENOSPC when \a size is too small */ - int (*port_set_io) (struct spa_node *node, + int (*port_set_io) (void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, @@ -575,7 +579,7 @@ struct spa_node { * \return 0 on success * -EINVAL when node is NULL */ - int (*port_reuse_buffer) (struct spa_node *node, uint32_t port_id, uint32_t buffer_id); + int (*port_reuse_buffer) (void *object, uint32_t port_id, uint32_t buffer_id); /** * Process the node @@ -592,26 +596,36 @@ struct spa_node { * When the node can accept new input in the next cycle, the * SPA_STATUS_NEED_BUFFER bit will be set. */ - int (*process) (struct spa_node *node); + int (*process) (void *object); }; -#define spa_node_add_listener(n,...) (n)->add_listener((n),__VA_ARGS__) -#define spa_node_set_callbacks(n,...) (n)->set_callbacks((n),__VA_ARGS__) -#define spa_node_sync(n,...) (n)->sync((n),__VA_ARGS__) -#define spa_node_enum_params(n,...) (n)->enum_params((n),__VA_ARGS__) -#define spa_node_set_param(n,...) (n)->set_param((n),__VA_ARGS__) -#define spa_node_set_io(n,...) (n)->set_io((n),__VA_ARGS__) -#define spa_node_send_command(n,...) (n)->send_command((n),__VA_ARGS__) -#define spa_node_add_port(n,...) (n)->add_port((n),__VA_ARGS__) -#define spa_node_remove_port(n,...) (n)->remove_port((n),__VA_ARGS__) -#define spa_node_port_enum_params(n,...) (n)->port_enum_params((n),__VA_ARGS__) -#define spa_node_port_set_param(n,...) (n)->port_set_param((n),__VA_ARGS__) -#define spa_node_port_use_buffers(n,...) (n)->port_use_buffers((n),__VA_ARGS__) -#define spa_node_port_alloc_buffers(n,...) (n)->port_alloc_buffers((n),__VA_ARGS__) -#define spa_node_port_set_io(n,...) (n)->port_set_io((n),__VA_ARGS__) +#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_port_reuse_buffer(n,...) (n)->port_reuse_buffer((n),__VA_ARGS__) -#define spa_node_process(n) (n)->process((n)) +#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_alloc_buffers(n,...) spa_node_method(n, port_alloc_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_process(n) spa_node_method(n, process, 0) #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/node/utils.h b/spa/include/spa/node/utils.h index 0069ccad3..ece8f9f28 100644 --- a/spa/include/spa/node/utils.h +++ b/spa/include/spa/node/utils.h @@ -61,11 +61,13 @@ static inline int spa_node_enum_params_sync(struct spa_node *node, SPA_VERSION_NODE_EVENTS, .result = spa_result_func_node_params, }; - int res = 0; + int res; - spa_node_add_listener(node, &listener, &node_events, &data); - res = spa_node_enum_params(node, 0, id, *index, 1, filter); - spa_hook_remove(&listener); + res = spa_node_add_listener(node, &listener, &node_events, &data); + if (res >= 0) { + res = spa_node_enum_params(node, 0, id, *index, 1, filter); + spa_hook_remove(&listener); + } if (data.data.param == NULL) { if (res > 0) @@ -93,10 +95,12 @@ static inline int spa_node_port_enum_params_sync(struct spa_node *node, }; int res; - spa_node_add_listener(node, &listener, &node_events, &data); - res = spa_node_port_enum_params(node, 0, direction, port_id, - id, *index, 1, filter); - spa_hook_remove(&listener); + res = spa_node_add_listener(node, &listener, &node_events, &data); + if (res >= 0) { + res = spa_node_port_enum_params(node, 0, direction, port_id, + id, *index, 1, filter); + spa_hook_remove(&listener); + } if (data.data.param == NULL) { if (res > 0) diff --git a/spa/include/spa/support/cpu.h b/spa/include/spa/support/cpu.h index f4afbb5f1..e36189c3c 100644 --- a/spa/include/spa/support/cpu.h +++ b/spa/include/spa/support/cpu.h @@ -32,6 +32,13 @@ extern "C" { #include #include +#include + +/** + * The CPU features interface + */ +#define SPA_VERSION_CPU 0 +struct spa_cpu { struct spa_interface iface; }; /* x86 specific */ #define SPA_CPU_FLAG_MMX (1<<0) /**< standard MMX */ @@ -72,35 +79,40 @@ extern "C" { #define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1) /** - * The CPU features interface + * methods */ -struct spa_cpu { - /** the version of this interface. This can be used to expand this +struct spa_cpu_methods { + /** the version of the methods. This can be used to expand this structure in the future */ -#define SPA_VERSION_CPU 0 +#define SPA_VERSION_CPU_METHODS 0 uint32_t version; - /** - * Extra information about the interface - */ - const struct spa_dict *info; /** get CPU flags */ - uint32_t (*get_flags) (struct spa_cpu *cpu); + uint32_t (*get_flags) (void *object); /** force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags */ - int (*force_flags) (struct spa_cpu *cpu, uint32_t flags); + int (*force_flags) (void *object, uint32_t flags); /** get number of CPU cores */ - uint32_t (*get_count) (struct spa_cpu *cpu); + uint32_t (*get_count) (void *object); /** get maximum required alignment of data */ - uint32_t (*get_max_align) (struct spa_cpu *cpu); + uint32_t (*get_max_align) (void *object); }; -#define spa_cpu_get_flags(c) (c)->get_flags((c)) -#define spa_cpu_force_flags(c,f) (c)->force_flags((c), (f)) -#define spa_cpu_get_count(c) (c)->get_count((c)) -#define spa_cpu_get_max_align(c) (c)->get_max_align((c)) +#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) #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/support/dbus.h b/spa/include/spa/support/dbus.h index 06c1cd468..d9df97b38 100644 --- a/spa/include/spa/support/dbus.h +++ b/spa/include/spa/support/dbus.h @@ -31,6 +31,9 @@ extern "C" { #include +#define SPA_VERSION_DBUS 0 +struct spa_dbus { struct spa_interface iface; }; + enum spa_dbus_type { SPA_DBUS_TYPE_SESSION, /**< The login session bus */ SPA_DBUS_TYPE_SYSTEM, /**< The systemwide bus */ @@ -58,10 +61,8 @@ struct spa_dbus_connection { #define spa_dbus_connection_get(c) (c)->get((c)) #define spa_dbus_connection_destroy(c) (c)->destroy((c)) -struct spa_dbus { - /* the version of this structure. This can be used to expand this - * structure in the future */ -#define SPA_VERSION_DBUS 0 +struct spa_dbus_methods { +#define SPA_VERSION_DBUS_METHODS 0 uint32_t version; /** @@ -76,11 +77,19 @@ struct spa_dbus { * \param error location for the DBusError * \return a new dbus connection wrapper or NULL on error */ - struct spa_dbus_connection * (*get_connection) (struct spa_dbus *dbus, + struct spa_dbus_connection * (*get_connection) (void *object, enum spa_dbus_type type); }; -#define spa_dbus_get_connection(d,...) (d)->get_connection((d),__VA_ARGS__) +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; +} #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/support/log-impl.h b/spa/include/spa/support/log-impl.h index 593ba1f9f..4bc3a45fb 100644 --- a/spa/include/spa/support/log-impl.h +++ b/spa/include/spa/support/log-impl.h @@ -33,7 +33,7 @@ extern "C" { #include -static inline void spa_log_impl_logv(struct spa_log *log, +static inline void spa_log_impl_logv(void *object, enum spa_log_level level, const char *file, int line, @@ -49,7 +49,7 @@ static inline void spa_log_impl_logv(struct spa_log *log, levels[level], strrchr(file, '/') + 1, line, func, text); fputs(location, stderr); } -static inline void spa_log_impl_log(struct spa_log *log, +static inline void spa_log_impl_log(void *object, enum spa_log_level level, const char *file, int line, @@ -58,24 +58,26 @@ static inline void spa_log_impl_log(struct spa_log *log, { va_list args; va_start(args, fmt); - spa_log_impl_logv(log, level, file, line, func, fmt, args); + spa_log_impl_logv(object, level, file, line, func, fmt, args); va_end(args); } #define SPA_LOG_IMPL_DEFINE(name) \ struct { \ struct spa_log log; \ + struct spa_log_methods methods; \ } name -#define SPA_LOG_IMPL_INIT \ - { { SPA_VERSION_LOG, \ - SPA_LOG_LEVEL_INFO, \ - NULL, \ - spa_log_impl_log, \ +#define SPA_LOG_IMPL_INIT(name) \ + { { { SPA_TYPE_INTERFACE_Log, SPA_VERSION_LOG, \ + SPA_CALLBACKS_INIT(&name.methods, &name) }, \ + SPA_LOG_LEVEL_INFO, }, \ + { SPA_VERSION_LOG_METHODS, \ + spa_log_impl_log, \ spa_log_impl_logv,} } #define SPA_LOG_IMPL(name) \ - SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT + SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT(name) #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/support/log.h b/spa/include/spa/support/log.h index d185102ef..3f424c313 100644 --- a/spa/include/spa/support/log.h +++ b/spa/include/spa/support/log.h @@ -32,6 +32,7 @@ extern "C" { #include #include +#include enum spa_log_level { SPA_LOG_LEVEL_NONE = 0, @@ -49,17 +50,16 @@ struct spa_log { /** the version of this log. This can be used to expand this * structure in the future */ #define SPA_VERSION_LOG 0 - uint32_t version; + struct spa_interface iface; /** * Logging level, everything above this level is not logged */ enum spa_log_level level; +}; - /** - * Extra information about the log - */ - const struct spa_dict *info; - +struct spa_log_methods { +#define SPA_VERSION_LOG_METHODS 0 + uint32_t version; /** * Log a message with the given log level. * @@ -71,7 +71,7 @@ struct spa_log { * \param fmt printf style format * \param ... format arguments */ - void (*log) (struct spa_log *log, + void (*log) (void *object, enum spa_log_level level, const char *file, int line, @@ -89,7 +89,7 @@ struct spa_log { * \param fmt printf style format * \param args format arguments */ - void (*logv) (struct spa_log *log, + void (*logv) (void *object, enum spa_log_level level, const char *file, int line, @@ -105,8 +105,20 @@ struct spa_log { #define spa_log_log(l,lev,...) \ ({ \ - if (SPA_UNLIKELY (spa_log_level_enabled (l, lev))) \ - (l)->log((l),lev,__VA_ARGS__); \ + struct spa_log *_l = l; \ + if (SPA_UNLIKELY (spa_log_level_enabled(_l, lev))) \ + spa_interface_call(&_l->iface, \ + struct spa_log_methods, log, 0, lev, \ + __VA_ARGS__); \ +}) + +#define spa_log_logv(l,lev,...) \ +({ \ + struct spa_log *_l = l; \ + if (SPA_UNLIKELY (spa_log_level_enabled(_l, lev))) \ + spa_interface_call(&_l->iface, \ + struct spa_log_methods, logv, 0, lev, \ + __VA_ARGS__); \ }) #define spa_log_error(l,...) spa_log_log(l,SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__) @@ -129,7 +141,9 @@ static inline void spa_log_##name (struct spa_log *l, const char *format, ...) if (SPA_UNLIKELY (spa_log_level_enabled (l, lev))) { \ va_list varargs; \ va_start (varargs, format); \ - (l)->logv((l),lev,__FILE__,__LINE__,__func__,format,varargs); \ + spa_interface_call(&l->iface, \ + struct spa_log_methods, logv, 0, lev, \ + __FILE__,__LINE__,__func__,format,varargs); \ va_end (varargs); \ } \ } diff --git a/spa/include/spa/support/loop.h b/spa/include/spa/support/loop.h index 1a1317334..e797ea6cf 100644 --- a/spa/include/spa/support/loop.h +++ b/spa/include/spa/support/loop.h @@ -29,15 +29,18 @@ extern "C" { #endif -struct spa_loop; -struct spa_loop_control; -struct spa_loop_utils; -struct spa_source; - #include #include #include +#define SPA_VERSION_LOOP 0 +struct spa_loop { struct spa_interface iface; }; +#define SPA_VERSION_LOOP_CONTROL 0 +struct spa_loop_control { struct spa_interface iface; }; +#define SPA_VERSION_LOOP_UTILS 0 +struct spa_loop_utils { struct spa_interface iface; }; +struct spa_source; + enum spa_io { SPA_IO_IN = (1 << 0), SPA_IO_OUT = (1 << 1), @@ -66,24 +69,26 @@ typedef int (*spa_invoke_func_t) (struct spa_loop *loop, /** * Register sources and work items to an event loop */ -struct spa_loop { +struct spa_loop_methods { /* the version of this structure. This can be used to expand this * structure in the future */ -#define SPA_VERSION_LOOP 0 +#define SPA_VERSION_LOOP_METHODS 0 uint32_t version; /** add a source to the loop */ - int (*add_source) (struct spa_loop *loop, + int (*add_source) (void *object, struct spa_source *source); /** update the source io mask */ - int (*update_source) (struct spa_source *source); + int (*update_source) (void *object, + struct spa_source *source); /** remove a source from the loop */ - void (*remove_source) (struct spa_source *source); + int (*remove_source) (void *object, + struct spa_source *source); /** invoke a function in the context of this loop */ - int (*invoke) (struct spa_loop *loop, + int (*invoke) (void *object, spa_invoke_func_t func, uint32_t seq, const void *data, @@ -92,10 +97,20 @@ struct spa_loop { void *user_data); }; -#define spa_loop_add_source(l,...) (l)->add_source((l),__VA_ARGS__) -#define spa_loop_update_source(l,...) (l)->update_source(__VA_ARGS__) -#define spa_loop_remove_source(l,...) (l)->remove_source(__VA_ARGS__) -#define spa_loop_invoke(l,...) (l)->invoke((l),__VA_ARGS__) +#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__) /** Control hooks */ @@ -116,13 +131,13 @@ struct spa_loop_control_hooks { /** * Control an event loop */ -struct spa_loop_control { +struct spa_loop_control_methods { /* the version of this structure. This can be used to expand this * structure in the future */ -#define SPA_VERSION_LOOP_CONTROL 0 +#define SPA_VERSION_LOOP_CONTROL_METHODS 0 uint32_t version; - int (*get_fd) (struct spa_loop_control *ctrl); + int (*get_fd) (void *object); /** Add a hook * \param ctrl the control to change @@ -130,7 +145,7 @@ struct spa_loop_control { * * Adds hooks to the loop controlled by \a ctrl. */ - void (*add_hook) (struct spa_loop_control *ctrl, + void (*add_hook) (void *object, struct spa_hook *hook, const struct spa_loop_control_hooks *hooks, void *data); @@ -142,14 +157,14 @@ struct spa_loop_control { * before calling iterate and is typically used to capture the thread * that this loop will run in. */ - void (*enter) (struct spa_loop_control *ctrl); + void (*enter) (void *object); /** Leave a loop * \param ctrl the control * * Ends the iteration of a loop. This should be called after calling * iterate. */ - void (*leave) (struct spa_loop_control *ctrl); + void (*leave) (void *object); /** Perform one iteration of the loop. * \param ctrl the control @@ -160,14 +175,32 @@ struct spa_loop_control { * up to \a timeout and then dispatch the fds with activity. * The number of dispatched fds is returned. */ - int (*iterate) (struct spa_loop_control *ctrl, int timeout); + int (*iterate) (void *object, int timeout); }; -#define spa_loop_control_get_fd(l) (l)->get_fd(l) -#define spa_loop_control_add_hook(l,...) (l)->add_hook((l),__VA_ARGS__) -#define spa_loop_control_enter(l) (l)->enter(l) -#define spa_loop_control_iterate(l,...) (l)->iterate((l),__VA_ARGS__) -#define spa_loop_control_leave(l) (l)->leave(l) +#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_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__) typedef void (*spa_source_io_func_t) (void *data, int fd, enum spa_io mask); @@ -179,55 +212,84 @@ typedef void (*spa_source_signal_func_t) (void *data, int signal_number); /** * Create sources for an event loop */ -struct spa_loop_utils { +struct spa_loop_utils_methods { /* the version of this structure. This can be used to expand this * structure in the future */ -#define SPA_VERSION_LOOP_UTILS 0 +#define SPA_VERSION_LOOP_UTILS_METHODS 0 uint32_t version; - struct spa_source *(*add_io) (struct spa_loop_utils *utils, + struct spa_source *(*add_io) (void *object, int fd, enum spa_io mask, bool close, spa_source_io_func_t func, void *data); - int (*update_io) (struct spa_source *source, enum spa_io mask); + int (*update_io) (void *object, struct spa_source *source, enum spa_io mask); - struct spa_source *(*add_idle) (struct spa_loop_utils *utils, + struct spa_source *(*add_idle) (void *object, bool enabled, spa_source_idle_func_t func, void *data); - void (*enable_idle) (struct spa_source *source, bool enabled); + void (*enable_idle) (void *object, struct spa_source *source, bool enabled); - struct spa_source *(*add_event) (struct spa_loop_utils *utils, + struct spa_source *(*add_event) (void *object, spa_source_event_func_t func, void *data); - void (*signal_event) (struct spa_source *source); + void (*signal_event) (void *object, struct spa_source *source); - struct spa_source *(*add_timer) (struct spa_loop_utils *utils, + struct spa_source *(*add_timer) (void *object, spa_source_timer_func_t func, void *data); - int (*update_timer) (struct spa_source *source, + int (*update_timer) (void *object, + struct spa_source *source, struct timespec *value, struct timespec *interval, bool absolute); - struct spa_source *(*add_signal) (struct spa_loop_utils *utils, + struct spa_source *(*add_signal) (void *object, int signal_number, spa_source_signal_func_t func, void *data); /** destroy a source allocated with this interface. This function * should only be called when the loop is not running or from the * context of the running loop */ - void (*destroy_source) (struct spa_source *source); + void (*destroy_source) (void *object, struct spa_source *source); }; -#define spa_loop_utils_add_io(l,...) (l)->add_io(l,__VA_ARGS__) -#define spa_loop_utils_update_io(l,...) (l)->update_io(__VA_ARGS__) -#define spa_loop_utils_add_idle(l,...) (l)->add_idle(l,__VA_ARGS__) -#define spa_loop_utils_enable_idle(l,...) (l)->enable_idle(__VA_ARGS__) -#define spa_loop_utils_add_event(l,...) (l)->add_event(l,__VA_ARGS__) -#define spa_loop_utils_signal_event(l,...) (l)->signal_event(__VA_ARGS__) -#define spa_loop_utils_add_timer(l,...) (l)->add_timer(l,__VA_ARGS__) -#define spa_loop_utils_update_timer(l,...) (l)->update_timer(__VA_ARGS__) -#define spa_loop_utils_add_signal(l,...) (l)->add_signal(l,__VA_ARGS__) -#define spa_loop_utils_destroy_source(l,...) (l)->destroy_source(__VA_ARGS__) +#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_v(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_v(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__) #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/support/plugin.h b/spa/include/spa/support/plugin.h index e63e84442..2bd5c2ccf 100644 --- a/spa/include/spa/support/plugin.h +++ b/spa/include/spa/support/plugin.h @@ -37,11 +37,12 @@ struct spa_handle { #define SPA_VERSION_HANDLE 0 uint32_t version; - /* user_data that can be set by the application */ - void *user_data; /** * Get the interface provided by \a handle with \a type. * + * \a interface is always a struct spa_interface but depending on + * \a type, the struct might contain other information. + * * \param handle a spa_handle * \param type the interface type * \param interface result to hold the interface. diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h index ea461de04..1f285f022 100644 --- a/spa/include/spa/utils/hook.h +++ b/spa/include/spa/utils/hook.h @@ -52,6 +52,15 @@ struct spa_callbacks { #define SPA_CALLBACKS_INIT(_funcs,_data) (struct spa_callbacks){ _funcs, _data, } +struct spa_interface { + uint32_t type; + uint32_t version; + struct spa_callbacks cb; +}; + +#define SPA_INTERFACE_INIT(_type,_version,_funcs,_data) \ + (struct spa_interface){ _type, _version, SPA_CALLBACKS_INIT(_funcs,_data), } + /** A hook, contains the structure with functions and the data passed * to the functions. */ struct spa_hook { @@ -130,6 +139,12 @@ spa_hook_list_join(struct spa_hook_list *list, res; \ }) +#define spa_interface_call(iface,type,method,vers,...) \ + spa_callbacks_call(&(iface)->cb,type,method,vers,##__VA_ARGS__) + +#define spa_interface_call_res(iface,type,res,method,vers,...) \ + spa_callbacks_call_res(&(iface)->cb,type,res,method,vers,##__VA_ARGS__) + #define spa_hook_list_call_simple(l,type,method,vers,...) \ ({ \ struct spa_hook_list *_l = l; \ diff --git a/spa/plugins/alsa/alsa-device.c b/spa/plugins/alsa/alsa-device.c index 932e92174..981f02fbb 100644 --- a/spa/plugins/alsa/alsa-device.c +++ b/spa/plugins/alsa/alsa-device.c @@ -256,18 +256,17 @@ static int emit_info(struct impl *this, bool full) return err; } -static int impl_add_listener(struct spa_device *device, +static int impl_add_listener(void *object, struct spa_hook *listener, const struct spa_device_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(device != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(events != NULL, -EINVAL); - this = SPA_CONTAINER_OF(device, struct impl, device); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); if (events->info || events->object_info) @@ -279,22 +278,20 @@ static int impl_add_listener(struct spa_device *device, } -static int impl_enum_params(struct spa_device *device, int seq, +static int impl_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_device_params result; uint32_t count = 0; - spa_return_val_if_fail(device != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(device, struct impl, device); - result.id = id; result.next = start; next: @@ -351,16 +348,14 @@ static int impl_enum_params(struct spa_device *device, int seq, return 0; } -static int impl_set_param(struct spa_device *device, +static int impl_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; int res; - spa_return_val_if_fail(device != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(device, struct impl, device); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Profile: @@ -384,11 +379,11 @@ static int impl_set_param(struct spa_device *device, return 0; } -static const struct spa_device impl_device = { - SPA_VERSION_DEVICE, - impl_add_listener, - impl_enum_params, - impl_set_param, +static const struct spa_device_methods impl_device = { + SPA_VERSION_DEVICE_METHODS, + .add_listener = impl_add_listener, + .enum_params = impl_enum_params, + .set_param = impl_set_param, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -450,7 +445,10 @@ impl_init(const struct spa_handle_factory *factory, return -EINVAL; } - this->device = impl_device; + this->device.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Device, + SPA_VERSION_DEVICE, + &impl_device, this); spa_hook_list_init(&this->hooks); reset_props(&this->props); diff --git a/spa/plugins/alsa/alsa-monitor.c b/spa/plugins/alsa/alsa-monitor.c index 9a77852b6..6fbdfc1c7 100644 --- a/spa/plugins/alsa/alsa-monitor.c +++ b/spa/plugins/alsa/alsa-monitor.c @@ -367,16 +367,14 @@ static int enum_devices(struct impl *this) } static int -impl_monitor_set_callbacks(struct spa_monitor *monitor, +impl_monitor_set_callbacks(void *object, const struct spa_monitor_callbacks *callbacks, void *data) { int res; - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(monitor != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(monitor, struct impl, monitor); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); @@ -397,9 +395,9 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor, return 0; } -static const struct spa_monitor impl_monitor = { - SPA_VERSION_MONITOR, - impl_monitor_set_callbacks, +static const struct spa_monitor_methods impl_monitor = { + SPA_VERSION_MONITOR_METHODS, + .set_callbacks = impl_monitor_set_callbacks, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -422,7 +420,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i static int impl_clear(struct spa_handle *handle) { struct impl *this = (struct impl *) handle; - impl_monitor_set_callbacks(&this->monitor, NULL, NULL); + impl_monitor_set_callbacks(this, NULL, NULL); return 0; } @@ -462,7 +460,10 @@ impl_init(const struct spa_handle_factory *factory, return -EINVAL; } - this->monitor = impl_monitor; + this->monitor.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Monitor, + SPA_VERSION_MONITOR, + &impl_monitor, this); return 0; } diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index 36ece317f..af5e2bf39 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -49,22 +49,20 @@ static void reset_props(struct props *props) props->max_latency = default_max_latency; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct state *this; + struct state *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - result.id = id; result.next = start; next: @@ -152,13 +150,11 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_IO_Clock: @@ -175,14 +171,12 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return 0; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (id == SPA_PARAM_Props) { struct props *p = &this->props; @@ -203,16 +197,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct state *this; + struct state *this = object; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: if (!this->have_format) @@ -261,17 +253,16 @@ static void emit_port_info(struct state *this, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct state *this; + struct state *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -283,51 +274,47 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } -static int impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +static int impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct state *this; + struct state *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); result.id = id; @@ -430,12 +417,12 @@ static int clear_buffers(struct state *this) return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct state *this = SPA_CONTAINER_OF(node, struct state, node); + struct state *this = object; int err; if (format == NULL) { @@ -483,33 +470,33 @@ static int port_set_format(struct spa_node *node, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - spa_return_val_if_fail(node != NULL, -EINVAL); + struct state *this = object; - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); + + spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(this, direction, port_id, flags, param); } else return -ENOENT; } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct state *this; + struct state *this = object; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -550,7 +537,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -558,13 +545,11 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(buffers != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); if (!this->have_format) @@ -574,17 +559,15 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -604,19 +587,18 @@ impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { return -ENOTSUP; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct state *this; + struct state *this = object; struct spa_io_buffers *input; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); input = this->io; spa_return_val_if_fail(input != NULL, -EIO); @@ -646,8 +628,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -725,7 +707,11 @@ impl_init(const struct spa_handle_factory *factory, return -EINVAL; } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); + spa_hook_list_init(&this->hooks); this->stream = SND_PCM_STREAM_PLAYBACK; diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c index d7720b95d..faf199197 100644 --- a/spa/plugins/alsa/alsa-source.c +++ b/spa/plugins/alsa/alsa-source.c @@ -49,11 +49,11 @@ static void reset_props(struct props *props) props->max_latency = default_max_latency; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct state *this; + struct state *this = object; struct spa_pod *param; uint8_t buffer[1024]; struct spa_pod_builder b = { 0 }; @@ -61,10 +61,9 @@ static int impl_node_enum_params(struct spa_node *node, int seq, struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); p = &this->props; result.id = id; @@ -148,13 +147,11 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_IO_Clock: @@ -170,14 +167,12 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return 0; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -202,16 +197,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct state *this; + struct state *this = object; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: if (!this->have_format) @@ -260,17 +253,16 @@ static void emit_port_info(struct state *this, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct state *this; + struct state *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -282,28 +274,26 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } -static int impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +static int impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } @@ -320,23 +310,21 @@ static void recycle_buffer(struct state *this, uint32_t buffer_id) } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct state *this; + struct state *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); result.id = id; @@ -434,11 +422,11 @@ static int clear_buffers(struct state *this) return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct state *this = SPA_CONTAINER_OF(node, struct state, node); + struct state *this = object; int err; if (format == NULL) { @@ -485,20 +473,21 @@ static int port_set_format(struct spa_node *node, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { + struct state *this = object; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); + spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); switch (id) { case SPA_PARAM_Format: - res = port_set_format(node, direction, port_id, flags, param); + res = port_set_format(this, direction, port_id, flags, param); break; default: @@ -509,17 +498,15 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct state *this; + struct state *this = object; int res; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -555,7 +542,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -563,13 +550,11 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(buffers != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); if (this->n_buffers == 0) @@ -579,17 +564,15 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -606,13 +589,11 @@ impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct state *this; + struct state *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct state, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(port_id == 0, -EINVAL); @@ -627,15 +608,14 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct state *this; + struct state *this = object; struct spa_io_buffers *io; struct buffer *b; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); io = this->io; spa_return_val_if_fail(io != NULL, -EIO); @@ -664,8 +644,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -747,7 +727,8 @@ impl_init(const struct spa_handle_factory *factory, return -EINVAL; } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT(SPA_TYPE_INTERFACE_Node, SPA_VERSION_NODE, &impl_node, this); + spa_hook_list_init(&this->hooks); this->stream = SND_PCM_STREAM_CAPTURE; diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index fa8dec976..0a6365fe3 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -393,22 +393,20 @@ static int setup_buffers(struct impl *this, enum spa_direction direction) return 0; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -455,14 +453,12 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_IO_Position: @@ -475,15 +471,13 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return res; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { int res = 0; - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Profile: @@ -547,15 +541,13 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return res; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -615,18 +607,17 @@ static struct spa_node_events node_events = { }; static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; struct spa_hook l[4]; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); spa_log_debug(this->log, "%p: add listener %p", this, listener); @@ -652,55 +643,49 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); return spa_node_add_port(this->fmt[direction], direction, port_id, props); } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); return spa_node_remove_port(this->fmt[direction], direction, port_id); } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -766,18 +751,16 @@ impl_node_port_enum_params(struct spa_node *node, int seq, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; int res; struct spa_node *target; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (this->mode == MODE_MERGE && port_id > 0 && direction == SPA_DIRECTION_OUTPUT) target = this->fmt[SPA_DIRECTION_INPUT]; @@ -801,19 +784,17 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; int res; struct spa_node *target; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (this->mode == MODE_MERGE && port_id > 0 && direction == SPA_DIRECTION_OUTPUT) target = this->fmt[SPA_DIRECTION_INPUT]; @@ -833,7 +814,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -841,12 +822,10 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct impl *this; + struct impl *this = object; struct spa_node *target; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (this->mode == MODE_MERGE && port_id > 0 && direction == SPA_DIRECTION_OUTPUT) target = this->fmt[SPA_DIRECTION_INPUT]; @@ -858,17 +837,15 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct spa_node *target; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_log_debug(this->log, "set io %d %d %d", id, direction, port_id); @@ -889,14 +866,12 @@ impl_node_port_set_io(struct spa_node *node, return res; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct spa_node *target; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (this->mode == MODE_MERGE && port_id > 0) target = this->fmt[SPA_DIRECTION_INPUT]; @@ -906,15 +881,13 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, return spa_node_port_reuse_buffer(target, port_id, buffer_id); } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; int r, i, res = SPA_STATUS_OK; int ready; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_log_trace_fp(this->log, NAME " %p: process %d", this, this->n_links); @@ -947,8 +920,8 @@ static int impl_node_process(struct spa_node *node) return res; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -1051,7 +1024,10 @@ impl_init(const struct spa_handle_factory *factory, if (support[i].type == SPA_TYPE_INTERFACE_Log) this->log = support[i].data; } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); if (info == NULL || (str = spa_dict_lookup(info, "factory.mode")) == NULL) diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index 825482fe3..de8e47a48 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -225,22 +225,20 @@ static int setup_convert(struct impl *this, return 0; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -331,7 +329,7 @@ static int apply_props(struct impl *this, const struct spa_pod *param) return changed; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } @@ -346,14 +344,12 @@ static void emit_info(struct impl *this, bool full) } } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -369,15 +365,13 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -403,17 +397,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_info(this, true); @@ -426,33 +419,33 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { return 0; } -static int impl_node_add_port(struct spa_node *node, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } -static int impl_node_remove_port(struct spa_node *node, +static int impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *other; other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), 0); @@ -484,12 +477,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port, *other; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -498,11 +491,8 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -517,7 +507,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, ¶m, &b)) <= 0) return res; break; @@ -616,13 +606,13 @@ static int clear_buffers(struct impl *this, struct port *port) return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port, *other; int res = 0; @@ -679,37 +669,34 @@ static int port_set_format(struct spa_node *node, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(object != NULL, -EINVAL); - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); + spa_return_val_if_fail(CHECK_PORT(object, direction, port_id), -EINVAL); if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i, j, size = SPA_ID_INVALID; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -765,7 +752,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -777,17 +764,14 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -832,14 +816,11 @@ static struct buffer *dequeue_buffer(struct impl *this, struct port *port) } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); recycle_buffer(this, buffer_id); @@ -863,16 +844,14 @@ static int process_control(struct impl *this, struct port *port, struct spa_pod_ return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *outport, *inport; struct spa_io_buffers *outio, *inio; struct buffer *sbuf, *dbuf; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); outport = GET_OUT_PORT(this, 0); inport = GET_IN_PORT(this, 0); @@ -945,8 +924,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER | SPA_STATUS_NEED_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -1028,7 +1007,10 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS; this->info = SPA_NODE_INFO_INIT(); diff --git a/spa/plugins/audioconvert/fmtconvert.c b/spa/plugins/audioconvert/fmtconvert.c index 599e20adf..a19840073 100644 --- a/spa/plugins/audioconvert/fmtconvert.c +++ b/spa/plugins/audioconvert/fmtconvert.c @@ -195,33 +195,31 @@ static int setup_convert(struct impl *this) return 0; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { return -ENOTSUP; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -257,17 +255,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_info(this, true); @@ -280,21 +277,21 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } @@ -304,13 +301,13 @@ static int int32_cmp(const void *v1, const void *v2) return *(int32_t*)v1 - *(int32_t*)v2; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port, *other; port = GET_PORT(this, direction, port_id); @@ -404,12 +401,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port, *other; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -418,11 +415,9 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -437,7 +432,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, ¶m, &b)) <= 0) return res; break; @@ -551,13 +546,13 @@ static int clear_buffers(struct impl *this, struct port *port) } return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port, *other; int res = 0; @@ -622,37 +617,35 @@ static int port_set_format(struct spa_node *node, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(object != NULL, -EINVAL); - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); + spa_return_val_if_fail(CHECK_PORT(object, direction, port_id), -EINVAL); switch (id) { case SPA_PARAM_Format: - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); default: return -ENOENT; } } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i, size = SPA_ID_INVALID, j; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -721,7 +714,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -733,17 +726,14 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -784,15 +774,12 @@ static inline struct buffer *dequeue_buffer(struct impl *this, struct port *port return b; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); port = GET_OUT_PORT(this, port_id); @@ -802,9 +789,9 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *inport, *outport; struct spa_io_buffers *inio, *outio; struct buffer *inbuf, *outbuf; @@ -815,9 +802,7 @@ static int impl_node_process(struct spa_node *node) int res = 0; uint32_t n_samples, size, maxsize, offs; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); outport = GET_OUT_PORT(this, 0); inport = GET_IN_PORT(this, 0); @@ -893,8 +878,8 @@ static int impl_node_process(struct spa_node *node) return res; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -995,7 +980,10 @@ impl_init(const struct spa_handle_factory *factory, break; } } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); if (this->cpu) diff --git a/spa/plugins/audioconvert/merger.c b/spa/plugins/audioconvert/merger.c index fc8ee0856..12f01a9ef 100644 --- a/spa/plugins/audioconvert/merger.c +++ b/spa/plugins/audioconvert/merger.c @@ -193,20 +193,19 @@ static int init_port(struct impl *this, enum spa_direction direction, uint32_t p return 0; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); result.id = id; result.next = start; @@ -233,20 +232,18 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Profile: @@ -310,15 +307,13 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -333,20 +328,18 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; uint32_t i; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - - spa_log_debug(this->log, NAME" %p: add listener %p", node, listener); + spa_log_debug(this->log, NAME" %p: add listener %p", this, listener); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -360,34 +353,32 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { - spa_return_val_if_fail(node != NULL, -EINVAL); return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { - spa_return_val_if_fail(node != NULL, -EINVAL); return -ENOTSUP; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port = GET_PORT(this, direction, port_id); switch (index) { @@ -428,12 +419,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -442,11 +433,9 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_log_debug(this->log, "%p: enum params %d %d %u %u", this, seq, direction, port_id, id); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -462,7 +451,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, result.index, ¶m, &b)) <= 0) + if ((res = port_enum_formats(object, direction, port_id, result.index, ¶m, &b)) <= 0) return res; break; case SPA_PARAM_Format: @@ -594,13 +583,13 @@ static int calc_width(struct spa_audio_info *info) } } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port; int res; @@ -694,22 +683,20 @@ static int port_set_format(struct spa_node *node, static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); switch (id) { case SPA_PARAM_Format: - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(this, direction, port_id, flags, param); default: return -ENOENT; } @@ -745,19 +732,17 @@ static struct buffer *dequeue_buffer(struct impl *this, struct port *port) } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i, j; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -813,7 +798,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -825,16 +810,14 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -850,14 +833,12 @@ impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); @@ -924,9 +905,9 @@ static inline int handle_monitor(struct impl *this, const void *data, int n_samp return res; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *outport; struct spa_io_buffers *outio; uint32_t i, maxsize, n_samples; @@ -937,9 +918,7 @@ static int impl_node_process(struct spa_node *node) void **dst_datas; int res = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); outport = GET_OUT_PORT(this, 0); outio = outport->io; @@ -1000,8 +979,8 @@ static int impl_node_process(struct spa_node *node) return res | SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -1085,7 +1064,10 @@ impl_init(const struct spa_handle_factory *factory, if (info != NULL && (str = spa_dict_lookup(info, "merger.monitor")) != NULL) this->monitor = atoi(str); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | diff --git a/spa/plugins/audioconvert/resample.c b/spa/plugins/audioconvert/resample.c index e4504988e..87215f7a5 100644 --- a/spa/plugins/audioconvert/resample.c +++ b/spa/plugins/audioconvert/resample.c @@ -170,7 +170,7 @@ static int setup_convert(struct impl *this, return err; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { @@ -197,15 +197,13 @@ static int apply_props(struct impl *this, const struct spa_pod *param) return 0; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; int res = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -218,13 +216,11 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return res; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_IO_Position: @@ -236,15 +232,13 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -281,17 +275,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -304,32 +297,32 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *other; struct spa_pod_frame f; @@ -369,12 +362,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port, *other; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -383,11 +376,9 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -402,7 +393,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, ¶m, &b)) <= 0) return res; break; @@ -493,13 +484,13 @@ static int clear_buffers(struct impl *this, struct port *port) return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port, *other; int res = 0; @@ -554,36 +545,34 @@ static int port_set_format(struct spa_node *node, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(object != NULL, -EINVAL); - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); + spa_return_val_if_fail(CHECK_PORT(object, direction, port_id), -EINVAL); if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i, j, size = SPA_ID_INVALID; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -635,7 +624,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -647,16 +636,14 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -706,13 +693,11 @@ static void dequeue_buffer(struct impl *this, struct buffer *b) SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT); } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); @@ -737,9 +722,9 @@ static int process_control(struct impl *this, struct port *port, struct spa_pod_ return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *outport, *inport; struct spa_io_buffers *outio, *inio; struct buffer *sbuf, *dbuf; @@ -750,9 +735,7 @@ static int impl_node_process(struct spa_node *node) void **dst_datas; bool flush_out = false; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); outport = GET_OUT_PORT(this, 0); inport = GET_IN_PORT(this, 0); @@ -853,8 +836,8 @@ static int impl_node_process(struct spa_node *node) return res; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -957,7 +940,10 @@ impl_init(const struct spa_handle_factory *factory, } spa_log_debug(this->log, "mode:%d", this->mode); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); diff --git a/spa/plugins/audioconvert/splitter.c b/spa/plugins/audioconvert/splitter.c index a0c1b6520..b55fd8dda 100644 --- a/spa/plugins/audioconvert/splitter.c +++ b/spa/plugins/audioconvert/splitter.c @@ -189,22 +189,20 @@ static int init_port(struct impl *this, enum spa_direction direction, return 0; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -228,20 +226,18 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Profile: @@ -297,15 +293,13 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -320,18 +314,17 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -345,34 +338,32 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { - spa_return_val_if_fail(node != NULL, -EINVAL); return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { - spa_return_val_if_fail(node != NULL, -EINVAL); return -ENOTSUP; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port = GET_PORT(this, direction, port_id); switch (index) { @@ -418,12 +409,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -432,11 +423,8 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -452,7 +440,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, ¶m, &b)) <= 0) return res; break; @@ -587,13 +575,13 @@ static int calc_width(struct spa_audio_info *info) } } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port; int res; @@ -666,22 +654,19 @@ static int port_set_format(struct spa_node *node, static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); switch (id) { case SPA_PARAM_Format: - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(this, direction, port_id, flags, param); default: return -ENOENT; } @@ -717,20 +702,17 @@ static struct buffer *dequeue_buffer(struct impl *this, struct port *port) } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i, j; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -777,7 +759,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -789,17 +771,14 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -814,15 +793,12 @@ impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); port = GET_OUT_PORT(this, port_id); @@ -831,9 +807,9 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *inport; struct spa_io_buffers *inio; uint32_t i, j, maxsize, n_samples; @@ -844,9 +820,7 @@ static int impl_node_process(struct spa_node *node) void **dst_datas; int res = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); inport = GET_IN_PORT(this, 0); inio = inport->io; @@ -936,8 +910,8 @@ static int impl_node_process(struct spa_node *node) return res; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -1018,7 +992,10 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS; this->info = SPA_NODE_INFO_INIT(); diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index a3225015f..d544f5b00 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -131,33 +131,31 @@ struct impl { #define GET_OUT_PORT(this,p) (&this->out_ports[p]) #define GET_PORT(this,d,p) (d == SPA_DIRECTION_INPUT ? GET_IN_PORT(this,p) : GET_OUT_PORT(this,p)) -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { return -ENOTSUP; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -192,18 +190,17 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } } -static int impl_node_add_listener(struct spa_node *node, +static int impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -219,23 +216,20 @@ static int impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_FREE_IN_PORT(this, direction, port_id), -EINVAL); port = GET_IN_PORT(this, port_id); @@ -274,15 +268,12 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_IN_PORT(this, direction, port_id), -EINVAL); port = GET_IN_PORT(this, port_id); @@ -309,13 +300,13 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3 return 0; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; switch (index) { case 0: @@ -347,12 +338,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -361,11 +352,8 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -379,7 +367,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, ¶m, &b)) <= 0) return res; break; @@ -463,13 +451,13 @@ static int clear_buffers(struct impl *this, struct port *port) return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port; int res; @@ -542,41 +530,35 @@ static int port_set_format(struct spa_node *node, static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(this, direction, port_id, flags, param); } else return -ENOENT; } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -617,7 +599,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -629,17 +611,14 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -667,14 +646,11 @@ static void recycle_buffer(struct impl *this, uint32_t id) spa_log_trace(this->log, NAME " %p: recycle buffer %d", this, id); } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); recycle_buffer(this, buffer_id); @@ -808,17 +784,15 @@ static int mix_output(struct impl *this, size_t n_bytes) return SPA_STATUS_HAVE_BUFFER; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *outport; struct spa_io_buffers *outio; uint32_t i; size_t min_queued = SIZE_MAX; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); outport = GET_OUT_PORT(this, 0); outio = outport->io; @@ -869,8 +843,8 @@ static int impl_node_process(struct spa_node *node) return outio->status; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -943,7 +917,10 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info = SPA_NODE_INFO_INIT(); this->info.max_input_ports = MAX_PORTS; this->info.max_output_ports = 1; diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index a0615aec1..b55999449 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -136,22 +136,20 @@ struct impl { #define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_PORTS) -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -241,14 +239,12 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (id == SPA_PARAM_Props) { struct props *p = &this->props; @@ -275,7 +271,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } @@ -390,15 +386,14 @@ static void on_output(struct spa_source *source) spa_node_call_ready(&this->callbacks, res); } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; switch (SPA_NODE_COMMAND_ID(command)) { @@ -472,17 +467,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -494,29 +488,27 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } @@ -550,12 +542,12 @@ port_enum_formats(struct impl *this, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -564,11 +556,9 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -737,16 +727,14 @@ port_set_format(struct impl *this, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -757,19 +745,17 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -805,7 +791,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -813,12 +799,10 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -831,18 +815,16 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); @@ -875,14 +857,12 @@ static inline void reuse_buffer(struct impl *this, struct port *port, uint32_t i set_timer(this, true); } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(port_id == 0, -EINVAL); port = &this->port; @@ -915,15 +895,14 @@ static int process_control(struct impl *this, struct spa_pod_sequence *sequence) return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_io_buffers *io; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; io = port->io; @@ -946,8 +925,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_OK; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -1032,7 +1011,11 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); + this->info_all |= SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PROPS | SPA_NODE_CHANGE_MASK_PARAMS; diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 08484efb6..d02303499 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -156,22 +156,20 @@ static void reset_props(struct props *props) props->max_latency = default_max_latency; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -272,14 +270,12 @@ static inline bool is_slaved(struct impl *this) return this->position && this->clock && this->position->clock.id != this->clock->id; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; bool slaved; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_IO_Clock: @@ -301,14 +297,12 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return 0; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -878,16 +872,15 @@ static int do_stop(struct impl *this) return res; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; struct port *port; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; switch (SPA_NODE_COMMAND_ID(command)) { @@ -938,17 +931,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -960,40 +952,38 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } -static int impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +static int impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -1001,11 +991,9 @@ impl_node_port_enum_params(struct spa_node *node, int seq, struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -1173,18 +1161,16 @@ static int port_set_format(struct impl *this, struct port *port, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; struct port *port; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); port = &this->port; @@ -1200,17 +1186,15 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -1246,7 +1230,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -1254,14 +1238,11 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(buffers != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -1272,18 +1253,16 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -1298,21 +1277,20 @@ impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { return -ENOTSUP; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_io_buffers *io; uint64_t now_time; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; io = port->io; spa_return_val_if_fail(io != NULL, -EIO); @@ -1348,8 +1326,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -1444,7 +1422,10 @@ impl_init(const struct spa_handle_factory *factory, return -EINVAL; } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); reset_props(&this->props); diff --git a/spa/plugins/bluez5/a2dp-source.c b/spa/plugins/bluez5/a2dp-source.c index e2560d29d..04f26bccd 100644 --- a/spa/plugins/bluez5/a2dp-source.c +++ b/spa/plugins/bluez5/a2dp-source.c @@ -132,22 +132,20 @@ static void reset_props(struct props *props) props->max_latency = default_max_latency; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -226,14 +224,12 @@ static inline bool is_slaved(struct impl *this) return this->position && this->clock && this->position->clock.id != this->clock->id; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; bool slaved; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_IO_Clock: @@ -255,14 +251,12 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return 0; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -531,16 +525,15 @@ static int do_stop(struct impl *this) return res; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; struct port *port; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; switch (SPA_NODE_COMMAND_ID(command)) { @@ -591,17 +584,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -613,40 +605,38 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } -static int impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +static int impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -654,11 +644,9 @@ impl_node_port_enum_params(struct spa_node *node, int seq, struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -828,17 +816,16 @@ static int port_set_format(struct impl *this, struct port *port, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; struct port *port; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); port = &this->port; @@ -855,17 +842,15 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -901,7 +886,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -909,14 +894,12 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(buffers != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -927,18 +910,16 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -964,14 +945,12 @@ static void recycle_buffer(struct impl *this, struct port *port, uint32_t buffer } } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(port_id == 0, -EINVAL); port = &this->port; @@ -987,17 +966,16 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_io_buffers *io; struct buffer *b; /* get IO */ - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; io = port->io; spa_return_val_if_fail(io != NULL, -EIO); @@ -1029,8 +1007,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -1136,7 +1114,10 @@ impl_init(const struct spa_handle_factory *factory, return -EINVAL; } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); reset_props(&this->props); diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index ee262b9ac..0976d8e1e 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -184,18 +184,17 @@ static const struct spa_dict_item info_items[] = { { "media.class", "Audio/Device" }, }; -static int impl_add_listener(struct spa_device *device, +static int impl_add_listener(void *object, struct spa_hook *listener, const struct spa_device_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(device != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(events != NULL, -EINVAL); - this = SPA_CONTAINER_OF(device, struct impl, device); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); if (events->info) { @@ -222,25 +221,25 @@ static int impl_add_listener(struct spa_device *device, } -static int impl_enum_params(struct spa_device *device, int seq, +static int impl_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { return -ENOTSUP; } -static int impl_set_param(struct spa_device *device, +static int impl_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { return -ENOTSUP; } -static const struct spa_device impl_device = { - SPA_VERSION_DEVICE, - impl_add_listener, - impl_enum_params, - impl_set_param, +static const struct spa_device_methods impl_device = { + SPA_VERSION_DEVICE_METHODS, + .add_listener = impl_add_listener, + .enum_params = impl_enum_params, + .set_param = impl_set_param, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -309,7 +308,10 @@ impl_init(const struct spa_handle_factory *factory, spa_log_error(this->log, "a device is needed"); return -EINVAL; } - this->device = impl_device; + this->device.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Device, + SPA_VERSION_DEVICE, + &impl_device, this); spa_hook_list_init(&this->hooks); diff --git a/spa/plugins/bluez5/bluez5-monitor.c b/spa/plugins/bluez5/bluez5-monitor.c index ee9071252..8b33fe7f2 100644 --- a/spa/plugins/bluez5/bluez5-monitor.c +++ b/spa/plugins/bluez5/bluez5-monitor.c @@ -2184,15 +2184,13 @@ fail: } static int -impl_monitor_set_callbacks(struct spa_monitor *monitor, +impl_monitor_set_callbacks(void *object, const struct spa_monitor_callbacks *callbacks, void *data) { - struct spa_bt_monitor *this; + struct spa_bt_monitor *this = object; - spa_return_val_if_fail(monitor != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(monitor, struct spa_bt_monitor, monitor); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); @@ -2204,9 +2202,9 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor, return 0; } -static const struct spa_monitor impl_monitor = { - SPA_VERSION_MONITOR, - impl_monitor_set_callbacks, +static const struct spa_monitor_methods impl_monitor = { + SPA_VERSION_MONITOR_METHODS, + .set_callbacks = impl_monitor_set_callbacks, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -2281,7 +2279,10 @@ impl_init(const struct spa_handle_factory *factory, } this->conn = spa_dbus_connection_get(this->dbus_connection); - this->monitor = impl_monitor; + this->monitor.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Monitor, + SPA_VERSION_MONITOR, + &impl_monitor, this); spa_list_init(&this->adapter_list); spa_list_init(&this->device_list); @@ -2312,7 +2313,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory, } const struct spa_handle_factory spa_bluez5_monitor_factory = { - SPA_VERSION_MONITOR, + SPA_VERSION_HANDLE_FACTORY, NAME, NULL, impl_get_size, diff --git a/spa/plugins/ffmpeg/ffmpeg-dec.c b/spa/plugins/ffmpeg/ffmpeg-dec.c index 164955fe8..df34c0486 100644 --- a/spa/plugins/ffmpeg/ffmpeg-dec.c +++ b/spa/plugins/ffmpeg/ffmpeg-dec.c @@ -88,34 +88,32 @@ struct impl { bool started; }; -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { return -ENOTSUP; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - if (node == NULL || command == NULL) + if (this == NULL || command == NULL) return -EINVAL; - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -151,17 +149,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -174,7 +171,7 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { @@ -182,32 +179,28 @@ impl_node_set_callbacks(struct spa_node *node, } static int -impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, const struct spa_pod *filter, struct spa_pod **param, struct spa_pod_builder *builder) { - //struct impl *this; - - //this = SPA_CONTAINER_OF (node, struct impl, node); - - if (!IS_VALID_PORT(this, direction, port_id)) + if (!IS_VALID_PORT(object, direction, port_id)) return -EINVAL; switch (index) { @@ -220,14 +213,14 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, +static int port_get_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, const struct spa_pod *filter, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port; port = GET_PORT(this, direction, port_id); @@ -244,12 +237,12 @@ static int port_get_format(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -266,13 +259,13 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, filter, ¶m, &b)) <= 0) return res; break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, + if ((res = port_get_format(this, direction, port_id, result.index, filter, ¶m, &b)) <= 0) return res; break; @@ -292,20 +285,18 @@ impl_node_port_enum_params(struct spa_node *node, int seq, return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this; + struct impl *this = object; struct port *port; int res; - if (node == NULL || format == NULL) + if (this == NULL || format == NULL) return -EINVAL; - this = SPA_CONTAINER_OF(node, struct impl, node); - if (!IS_VALID_PORT(this, direction, port_id)) return -EINVAL; @@ -335,36 +326,36 @@ static int port_set_format(struct spa_node *node, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - if (node == NULL) + if (object == NULL) return -EINVAL; - if (!IS_VALID_PORT(node, direction, port_id)) + if (!IS_VALID_PORT(object, direction, port_id)) return -EINVAL; return -ENOTSUP; } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -376,20 +367,18 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - if (node == NULL) + if (this == NULL) return -EINVAL; - this = SPA_CONTAINER_OF(node, struct impl, node); - if (!IS_VALID_PORT(this, direction, port_id)) return -EINVAL; @@ -403,17 +392,15 @@ impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_io_buffers *output; - if (node == NULL) + if (this == NULL) return -EINVAL; - this = SPA_CONTAINER_OF(node, struct impl, node); - port = &this->out_ports[0]; if ((output = port->io) == NULL) @@ -429,9 +416,9 @@ static int impl_node_process(struct spa_node *node) } static int -impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - if (node == NULL) + if (object == NULL) return -EINVAL; if (port_id != 0) @@ -440,8 +427,8 @@ impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t bu return -ENOTSUP; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -498,7 +485,10 @@ spa_ffmpeg_dec_init(struct spa_handle *handle, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS; this->info = SPA_NODE_INFO_INIT(); this->info.max_input_ports = 1; diff --git a/spa/plugins/ffmpeg/ffmpeg-enc.c b/spa/plugins/ffmpeg/ffmpeg-enc.c index 3bb5fb424..8628453d2 100644 --- a/spa/plugins/ffmpeg/ffmpeg-enc.c +++ b/spa/plugins/ffmpeg/ffmpeg-enc.c @@ -87,33 +87,31 @@ struct impl { bool started; }; -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { return -ENOTSUP; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - if (node == NULL || command == NULL) + if (this == NULL || command == NULL) return -EINVAL; - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -149,17 +147,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -172,7 +169,7 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { @@ -180,20 +177,20 @@ impl_node_set_callbacks(struct spa_node *node, } static int -impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, const struct spa_pod *filter, @@ -203,14 +200,14 @@ static int port_enum_formats(struct spa_node *node, return -ENOTSUP; } -static int port_get_format(struct spa_node *node, +static int port_get_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, const struct spa_pod *filter, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port; port = GET_PORT(this, direction, port_id); @@ -227,12 +224,12 @@ static int port_get_format(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -240,8 +237,6 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -251,13 +246,13 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, filter, ¶m, &b)) <= 0) return res; break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, + if ((res = port_get_format(this, direction, port_id, result.index, filter, ¶m, &b)) <= 0) return res; break; @@ -277,11 +272,11 @@ impl_node_port_enum_params(struct spa_node *node, int seq, return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port; int res; @@ -311,35 +306,35 @@ static int port_set_format(struct spa_node *node, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - if (node == NULL) + if (object == NULL) return -EINVAL; - if (!IS_VALID_PORT(node, direction, port_id)) + if (!IS_VALID_PORT(object, direction, port_id)) return -EINVAL; return -ENOTSUP; } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -351,20 +346,18 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - if (node == NULL) + if (this == NULL) return -EINVAL; - this = SPA_CONTAINER_OF(node, struct impl, node); - if (!IS_VALID_PORT(this, direction, port_id)) return -EINVAL; @@ -379,9 +372,9 @@ impl_node_port_set_io(struct spa_node *node, } static int -impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - if (node == NULL) + if (object == NULL) return -EINVAL; if (port_id != 0) @@ -390,17 +383,15 @@ impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t bu return -ENOTSUP; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_io_buffers *output; - if (node == NULL) + if (this == NULL) return -EINVAL; - this = SPA_CONTAINER_OF(node, struct impl, node); - if ((output = this->out_ports[0].io) == NULL) return -EIO; @@ -415,8 +406,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_OK; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -472,7 +463,10 @@ spa_ffmpeg_enc_init(struct spa_handle *handle, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS; this->info = SPA_NODE_INFO_INIT(); this->info.max_input_ports = 1; diff --git a/spa/plugins/support/cpu.c b/spa/plugins/support/cpu.c index eccebcb8a..a32179105 100644 --- a/spa/plugins/support/cpu.c +++ b/spa/plugins/support/cpu.c @@ -33,6 +33,7 @@ #include #include #include +#include #define NAME "cpu" @@ -57,18 +58,18 @@ struct impl { #endif static uint32_t -impl_cpu_get_flags(struct spa_cpu *cpu) +impl_cpu_get_flags(void *object) { - struct impl *impl = SPA_CONTAINER_OF(cpu, struct impl, cpu); + struct impl *impl = object; if (impl->force != SPA_CPU_FORCE_AUTODETECT) return impl->force; return impl->flags; } static int -impl_cpu_force_flags(struct spa_cpu *cpu, uint32_t flags) +impl_cpu_force_flags(void *object, uint32_t flags) { - struct impl *impl = SPA_CONTAINER_OF(cpu, struct impl, cpu); + struct impl *impl = object; impl->force = flags; return 0; } @@ -83,26 +84,25 @@ static uint32_t get_count(struct impl *this) } static uint32_t -impl_cpu_get_count(struct spa_cpu *cpu) +impl_cpu_get_count(void *object) { - struct impl *impl = SPA_CONTAINER_OF(cpu, struct impl, cpu); + struct impl *impl = object; return impl->count; } static uint32_t -impl_cpu_get_max_align(struct spa_cpu *cpu) +impl_cpu_get_max_align(void *object) { - struct impl *impl = SPA_CONTAINER_OF(cpu, struct impl, cpu); + struct impl *impl = object; return impl->max_align; } -static const struct spa_cpu impl_cpu = { - SPA_VERSION_CPU, - NULL, - impl_cpu_get_flags, - impl_cpu_force_flags, - impl_cpu_get_count, - impl_cpu_get_max_align, +static const struct spa_cpu_methods impl_cpu = { + SPA_VERSION_CPU_METHODS, + .get_flags = impl_cpu_get_flags, + .force_flags = impl_cpu_force_flags, + .get_count = impl_cpu_get_count, + .get_max_align = impl_cpu_get_max_align, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -152,7 +152,10 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; - this->cpu = impl_cpu; + this->cpu.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_CPU, + SPA_VERSION_CPU, + &impl_cpu, this); for (i = 0; i < n_support; i++) { if (support[i].type == SPA_TYPE_INTERFACE_Log) diff --git a/spa/plugins/support/dbus.c b/spa/plugins/support/dbus.c index 0ef8c73a8..fecd9c3ec 100644 --- a/spa/plugins/support/dbus.c +++ b/spa/plugins/support/dbus.c @@ -280,10 +280,10 @@ static const struct spa_dbus_connection impl_connection = { }; static struct spa_dbus_connection * -impl_get_connection(struct spa_dbus *dbus, +impl_get_connection(void *object, enum spa_dbus_type type) { - struct impl *impl = SPA_CONTAINER_OF(dbus, struct impl, dbus); + struct impl *impl = object; struct connection *conn; DBusError error; @@ -318,9 +318,9 @@ impl_get_connection(struct spa_dbus *dbus, return NULL; } -static const struct spa_dbus impl_dbus = { - SPA_VERSION_DBUS, - impl_get_connection, +static const struct spa_dbus_methods impl_dbus = { + SPA_VERSION_DBUS_METHODS, + .get_connection = impl_get_connection, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -372,7 +372,10 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; spa_list_init(&this->connection_list); - this->dbus = impl_dbus; + this->dbus.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_DBus, + SPA_VERSION_DBUS, + &impl_dbus, this); for (i = 0; i < n_support; i++) { if (support[i].type == SPA_TYPE_INTERFACE_Log) diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c index 87ba3c219..64dcc0a9d 100644 --- a/spa/plugins/support/logger.c +++ b/spa/plugins/support/logger.c @@ -56,7 +56,7 @@ struct impl { }; static void -impl_log_logv(struct spa_log *log, +impl_log_logv(void *object, enum spa_log_level level, const char *file, int line, @@ -64,7 +64,7 @@ impl_log_logv(struct spa_log *log, const char *fmt, va_list args) { - struct impl *impl = SPA_CONTAINER_OF(log, struct impl, log); + struct impl *impl = object; char text[512], location[1024]; static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*" }; const char *prefix = "", *suffix = ""; @@ -107,7 +107,7 @@ impl_log_logv(struct spa_log *log, static void -impl_log_log(struct spa_log *log, +impl_log_log(void *object, enum spa_log_level level, const char *file, int line, @@ -116,7 +116,7 @@ impl_log_log(struct spa_log *log, { va_list args; va_start(args, fmt); - impl_log_logv(log, level, file, line, func, fmt, args); + impl_log_logv(object, level, file, line, func, fmt, args); va_end(args); } @@ -149,12 +149,10 @@ static void on_trace_event(struct spa_source *source) } } -static const struct spa_log impl_log = { - SPA_VERSION_LOG, - DEFAULT_LOG_LEVEL, - NULL, - impl_log_log, - impl_log_logv, +static const struct spa_log_methods impl_log = { + SPA_VERSION_LOG_METHODS, + .log = impl_log_log, + .logv = impl_log_logv, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -217,7 +215,11 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; - this->log = impl_log; + this->log.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Log, + SPA_VERSION_LOG, + &impl_log, this); + this->log.level = DEFAULT_LOG_LEVEL; for (i = 0; i < n_support; i++) { if (support[i].type == SPA_TYPE_INTERFACE_MainLoop) @@ -281,7 +283,7 @@ const struct spa_handle_factory spa_support_logger_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - impl_get_size, - impl_init, - impl_enum_interface_info, + .get_size = impl_get_size, + .init = impl_init, + .enum_interface_info = impl_enum_interface_info, }; diff --git a/spa/plugins/support/loop.c b/spa/plugins/support/loop.c index c2c0ebc8d..747c10452 100644 --- a/spa/plugins/support/loop.c +++ b/spa/plugins/support/loop.c @@ -59,7 +59,7 @@ struct invoke_item { int res; }; -static void loop_signal_event(struct spa_source *source); +static void loop_signal_event(void *object, struct spa_source *source); struct impl { struct spa_handle handle; @@ -134,11 +134,11 @@ static inline enum spa_io spa_epoll_to_io(uint32_t events) return mask; } -static int loop_add_source(struct spa_loop *loop, struct spa_source *source) +static int loop_add_source(void *object, struct spa_source *source) { - struct impl *impl = SPA_CONTAINER_OF(loop, struct impl, loop); + struct impl *impl = object; - source->loop = loop; + source->loop = (struct spa_loop*) &impl->loop; if (source->fd != -1) { struct epoll_event ep; @@ -153,10 +153,9 @@ static int loop_add_source(struct spa_loop *loop, struct spa_source *source) return 0; } -static int loop_update_source(struct spa_source *source) +static int loop_update_source(void *object, struct spa_source *source) { - struct spa_loop *loop = source->loop; - struct impl *impl = SPA_CONTAINER_OF(loop, struct impl, loop); + struct impl *impl = object; if (source->fd != -1) { struct epoll_event ep; @@ -171,19 +170,19 @@ static int loop_update_source(struct spa_source *source) return 0; } -static void loop_remove_source(struct spa_source *source) +static int loop_remove_source(void *object, struct spa_source *source) { - struct spa_loop *loop = source->loop; - struct impl *impl = SPA_CONTAINER_OF(loop, struct impl, loop); + struct impl *impl = object; if (source->fd != -1) epoll_ctl(impl->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL); source->loop = NULL; + return 0; } static int -loop_invoke(struct spa_loop *loop, +loop_invoke(void *object, spa_invoke_func_t func, uint32_t seq, const void *data, @@ -191,13 +190,13 @@ loop_invoke(struct spa_loop *loop, bool block, void *user_data) { - struct impl *impl = SPA_CONTAINER_OF(loop, struct impl, loop); + struct impl *impl = object; bool in_thread = pthread_equal(impl->thread, pthread_self()); struct invoke_item *item; int res; if (in_thread) { - res = func(loop, false, seq, data, size, user_data); + res = func(object, false, seq, data, size, user_data); } else { int32_t filled; uint32_t avail, idx, offset, l0; @@ -236,7 +235,7 @@ loop_invoke(struct spa_loop *loop, spa_ringbuffer_write_update(&impl->buffer, idx + item->item_size); - spa_loop_utils_signal_event(&impl->utils, impl->wakeup); + spa_loop_utils_signal_event((struct spa_loop_utils*)&impl->utils, impl->wakeup); if (block) { uint64_t count = 1; @@ -272,7 +271,8 @@ static void wakeup_func(void *data, uint64_t count) item = SPA_MEMBER(impl->buffer_data, index & (DATAS_SIZE - 1), struct invoke_item); block = item->block; - item->res = item->func(&impl->loop, true, item->seq, item->data, item->size, + item->res = item->func((struct spa_loop *)&impl->loop, + true, item->seq, item->data, item->size, item->user_data); spa_ringbuffer_read_update(&impl->buffer, index + item->item_size); @@ -286,33 +286,31 @@ static void wakeup_func(void *data, uint64_t count) } } -static int loop_get_fd(struct spa_loop_control *ctrl) +static int loop_get_fd(void *object) { - struct impl *impl = SPA_CONTAINER_OF(ctrl, struct impl, control); - + struct impl *impl = object; return impl->epoll_fd; } static void -loop_add_hooks(struct spa_loop_control *ctrl, - struct spa_hook *hook, - const struct spa_loop_control_hooks *hooks, - void *data) +loop_add_hook(void *object, + struct spa_hook *hook, + const struct spa_loop_control_hooks *hooks, + void *data) { - struct impl *impl = SPA_CONTAINER_OF(ctrl, struct impl, control); - + struct impl *impl = object; spa_hook_list_append(&impl->hooks_list, hook, hooks, data); } -static void loop_enter(struct spa_loop_control *ctrl) +static void loop_enter(void *object) { - struct impl *impl = SPA_CONTAINER_OF(ctrl, struct impl, control); + struct impl *impl = object; impl->thread = pthread_self(); } -static void loop_leave(struct spa_loop_control *ctrl) +static void loop_leave(void *object) { - struct impl *impl = SPA_CONTAINER_OF(ctrl, struct impl, control); + struct impl *impl = object; impl->thread = 0; } @@ -324,10 +322,10 @@ static inline void process_destroy(struct impl *impl) spa_list_init(&impl->destroy_list); } -static int loop_iterate(struct spa_loop_control *ctrl, int timeout) +static int loop_iterate(void *object, int timeout) { - struct impl *impl = SPA_CONTAINER_OF(ctrl, struct impl, control); - struct spa_loop *loop = &impl->loop; + struct impl *impl = object; + struct spa_loop *loop = (struct spa_loop *)&impl->loop; struct epoll_event ep[32]; int i, nfds, save_errno = 0; @@ -364,19 +362,19 @@ static void source_io_func(struct spa_source *source) impl->func.io(source->data, source->fd, source->rmask); } -static struct spa_source *loop_add_io(struct spa_loop_utils *utils, +static struct spa_source *loop_add_io(void *object, int fd, enum spa_io mask, bool close, spa_source_io_func_t func, void *data) { - struct impl *impl = SPA_CONTAINER_OF(utils, struct impl, utils); + struct impl *impl = object; struct source_impl *source; source = calloc(1, sizeof(struct source_impl)); if (source == NULL) return NULL; - source->source.loop = &impl->loop; + source->source.loop = (struct spa_loop *) &impl->loop; source->source.func = source_io_func; source->source.data = data; source->source.fd = fd; @@ -385,14 +383,14 @@ static struct spa_source *loop_add_io(struct spa_loop_utils *utils, source->close = close; source->func.io = func; - spa_loop_add_source(&impl->loop, &source->source); + spa_loop_add_source(source->source.loop, &source->source); spa_list_insert(&impl->source_list, &source->link); return &source->source; } -static int loop_update_io(struct spa_source *source, enum spa_io mask) +static int loop_update_io(void *object, struct spa_source *source, enum spa_io mask) { source->mask = mask; return spa_loop_update_source(source->loop, source); @@ -405,17 +403,17 @@ static void source_idle_func(struct spa_source *source) impl->func.idle(source->data); } -static struct spa_source *loop_add_idle(struct spa_loop_utils *utils, +static struct spa_source *loop_add_idle(void *object, bool enabled, spa_source_idle_func_t func, void *data) { - struct impl *impl = SPA_CONTAINER_OF(utils, struct impl, utils); + struct impl *impl = object; struct source_impl *source; source = calloc(1, sizeof(struct source_impl)); if (source == NULL) return NULL; - source->source.loop = &impl->loop; + source->source.loop = (struct spa_loop *)&impl->loop; source->source.func = source_idle_func; source->source.data = data; source->source.fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); @@ -424,19 +422,20 @@ static struct spa_source *loop_add_idle(struct spa_loop_utils *utils, source->source.mask = SPA_IO_IN; source->func.idle = func; - spa_loop_add_source(&impl->loop, &source->source); + spa_loop_add_source(source->source.loop, &source->source); spa_list_insert(&impl->source_list, &source->link); if (enabled) - spa_loop_utils_enable_idle(&impl->utils, &source->source, true); + spa_loop_utils_enable_idle((struct spa_loop_utils*)&impl->utils, + &source->source, true); return &source->source; } -static void loop_enable_idle(struct spa_source *source, bool enabled) +static void loop_enable_idle(void *object, struct spa_source *source, bool enabled) { - struct source_impl *impl = SPA_CONTAINER_OF(source, struct source_impl, source); + struct source_impl *impl = object; uint64_t count; if (enabled && !impl->enabled) { @@ -464,17 +463,17 @@ static void source_event_func(struct spa_source *source) impl->func.event(source->data, count); } -static struct spa_source *loop_add_event(struct spa_loop_utils *utils, +static struct spa_source *loop_add_event(void *object, spa_source_event_func_t func, void *data) { - struct impl *impl = SPA_CONTAINER_OF(utils, struct impl, utils); + struct impl *impl = object; struct source_impl *source; source = calloc(1, sizeof(struct source_impl)); if (source == NULL) return NULL; - source->source.loop = &impl->loop; + source->source.loop = (struct spa_loop *)&impl->loop; source->source.func = source_event_func; source->source.data = data; source->source.fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); @@ -483,14 +482,14 @@ static struct spa_source *loop_add_event(struct spa_loop_utils *utils, source->close = true; source->func.event = func; - spa_loop_add_source(&impl->loop, &source->source); + spa_loop_add_source(source->source.loop, &source->source); spa_list_insert(&impl->source_list, &source->link); return &source->source; } -static void loop_signal_event(struct spa_source *source) +static void loop_signal_event(void *object, struct spa_source *source) { struct source_impl *impl = SPA_CONTAINER_OF(source, struct source_impl, source); uint64_t count = 1; @@ -512,17 +511,17 @@ static void source_timer_func(struct spa_source *source) impl->func.timer(source->data, expirations); } -static struct spa_source *loop_add_timer(struct spa_loop_utils *utils, +static struct spa_source *loop_add_timer(void *object, spa_source_timer_func_t func, void *data) { - struct impl *impl = SPA_CONTAINER_OF(utils, struct impl, utils); + struct impl *impl = object; struct source_impl *source; source = calloc(1, sizeof(struct source_impl)); if (source == NULL) return NULL; - source->source.loop = &impl->loop; + source->source.loop = (struct spa_loop*)&impl->loop; source->source.func = source_timer_func; source->source.data = data; source->source.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); @@ -531,7 +530,7 @@ static struct spa_source *loop_add_timer(struct spa_loop_utils *utils, source->close = true; source->func.timer = func; - spa_loop_add_source(&impl->loop, &source->source); + spa_loop_add_source(source->source.loop, &source->source); spa_list_insert(&impl->source_list, &source->link); @@ -539,7 +538,7 @@ static struct spa_source *loop_add_timer(struct spa_loop_utils *utils, } static int -loop_update_timer(struct spa_source *source, +loop_update_timer(void *object, struct spa_source *source, struct timespec *value, struct timespec *interval, bool absolute) { struct itimerspec its; @@ -577,11 +576,11 @@ static void source_signal_func(struct spa_source *source) impl->func.signal(source->data, impl->signal_number); } -static struct spa_source *loop_add_signal(struct spa_loop_utils *utils, +static struct spa_source *loop_add_signal(void *object, int signal_number, spa_source_signal_func_t func, void *data) { - struct impl *impl = SPA_CONTAINER_OF(utils, struct impl, utils); + struct impl *impl = object; struct source_impl *source; sigset_t mask; @@ -589,7 +588,7 @@ static struct spa_source *loop_add_signal(struct spa_loop_utils *utils, if (source == NULL) return NULL; - source->source.loop = &impl->loop; + source->source.loop = (struct spa_loop *)&impl->loop; source->source.func = source_signal_func; source->source.data = data; @@ -604,14 +603,14 @@ static struct spa_source *loop_add_signal(struct spa_loop_utils *utils, source->func.signal = func; source->signal_number = signal_number; - spa_loop_add_source(&impl->loop, &source->source); + spa_loop_add_source(source->source.loop, &source->source); spa_list_insert(&impl->source_list, &source->link); return &source->source; } -static void loop_destroy_source(struct spa_source *source) +static void loop_destroy_source(void *object, struct spa_source *source) { struct source_impl *impl = SPA_CONTAINER_OF(source, struct source_impl, source); @@ -627,35 +626,35 @@ static void loop_destroy_source(struct spa_source *source) spa_list_insert(&impl->impl->destroy_list, &impl->link); } -static const struct spa_loop impl_loop = { - SPA_VERSION_LOOP, - loop_add_source, - loop_update_source, - loop_remove_source, - loop_invoke, +static const struct spa_loop_methods impl_loop = { + SPA_VERSION_LOOP_METHODS, + .add_source = loop_add_source, + .update_source = loop_update_source, + .remove_source = loop_remove_source, + .invoke = loop_invoke, }; -static const struct spa_loop_control impl_loop_control = { - SPA_VERSION_LOOP_CONTROL, - loop_get_fd, - loop_add_hooks, - loop_enter, - loop_leave, - loop_iterate, +static const struct spa_loop_control_methods impl_loop_control = { + SPA_VERSION_LOOP_CONTROL_METHODS, + .get_fd = loop_get_fd, + .add_hook = loop_add_hook, + .enter = loop_enter, + .leave = loop_leave, + .iterate = loop_iterate, }; -static const struct spa_loop_utils impl_loop_utils = { - SPA_VERSION_LOOP_UTILS, - loop_add_io, - loop_update_io, - loop_add_idle, - loop_enable_idle, - loop_add_event, - loop_signal_event, - loop_add_timer, - loop_update_timer, - loop_add_signal, - loop_destroy_source, +static const struct spa_loop_utils_methods impl_loop_utils = { + SPA_VERSION_LOOP_UTILS_METHODS, + .add_io = loop_add_io, + .update_io = loop_update_io, + .add_idle = loop_add_idle, + .enable_idle = loop_enable_idle, + .add_event = loop_add_event, + .signal_event = loop_signal_event, + .add_timer = loop_add_timer, + .update_timer = loop_update_timer, + .add_signal = loop_add_signal, + .destroy_source = loop_destroy_source, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -693,7 +692,7 @@ static int impl_clear(struct spa_handle *handle) impl = (struct impl *) handle; spa_list_consume(source, &impl->source_list, link) - loop_destroy_source(&source->source); + loop_destroy_source(impl, &source->source); process_destroy(impl); @@ -727,9 +726,18 @@ impl_init(const struct spa_handle_factory *factory, handle->clear = impl_clear; impl = (struct impl *) handle; - impl->loop = impl_loop; - impl->control = impl_loop_control; - impl->utils = impl_loop_utils; + impl->loop.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Loop, + SPA_VERSION_LOOP, + &impl_loop, impl); + impl->control.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_LoopControl, + SPA_VERSION_LOOP_CONTROL, + &impl_loop_control, impl); + impl->utils.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_LoopUtils, + SPA_VERSION_LOOP_UTILS, + &impl_loop_utils, impl); for (i = 0; i < n_support; i++) { if (support[i].type == SPA_TYPE_INTERFACE_Log) @@ -746,7 +754,7 @@ impl_init(const struct spa_handle_factory *factory, spa_ringbuffer_init(&impl->buffer); - impl->wakeup = spa_loop_utils_add_event(&impl->utils, wakeup_func, impl); + impl->wakeup = spa_loop_utils_add_event((struct spa_loop_utils*)&impl->utils, wakeup_func, impl); impl->ack_fd = eventfd(0, EFD_SEMAPHORE | EFD_CLOEXEC); spa_log_debug(impl->log, NAME " %p: initialized", impl); diff --git a/spa/plugins/test/fakesink.c b/spa/plugins/test/fakesink.c index de693faec..9429bbbb2 100644 --- a/spa/plugins/test/fakesink.c +++ b/spa/plugins/test/fakesink.c @@ -109,22 +109,20 @@ static void reset_props(struct impl *this, struct props *props) props->live = DEFAULT_LIVE; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -156,19 +154,17 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -281,15 +277,14 @@ static void on_input(struct spa_source *source) consume_buffer(this); } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; switch (SPA_NODE_COMMAND_ID(command)) { @@ -358,17 +353,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -380,15 +374,13 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (this->data_loop == NULL && callbacks != NULL) { spa_log_error(this->log, "a data_loop is needed for async operation"); @@ -399,14 +391,14 @@ impl_node_set_callbacks(struct spa_node *node, return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } @@ -438,12 +430,12 @@ static int port_get_format(struct impl *this, struct port *port, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -452,11 +444,8 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); port = &this->port; @@ -545,17 +534,15 @@ static int port_set_format(struct impl *this, struct port *port, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); port = &this->port; @@ -567,20 +554,17 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -612,7 +596,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -620,13 +604,10 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -637,19 +618,16 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -661,20 +639,19 @@ impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { return -ENOTSUP; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_io_buffers *io; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; io = port->io; @@ -704,8 +681,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_OK; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -790,7 +767,10 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS; this->info = SPA_NODE_INFO_INIT(); diff --git a/spa/plugins/test/fakesrc.c b/spa/plugins/test/fakesrc.c index d7560cb4e..666dfa09d 100644 --- a/spa/plugins/test/fakesrc.c +++ b/spa/plugins/test/fakesrc.c @@ -113,22 +113,20 @@ static void reset_props(struct impl *this, struct props *props) props->pattern = DEFAULT_PATTERN; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -165,19 +163,17 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -296,15 +292,14 @@ static void on_output(struct spa_source *source) spa_node_call_ready(&this->callbacks, res); } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; switch (SPA_NODE_COMMAND_ID(command)) { @@ -372,17 +367,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } } -static int impl_node_add_listener(struct spa_node *node, +static int impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -394,15 +388,13 @@ static int impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (this->data_loop == NULL && callbacks != NULL) { spa_log_error(this->log, "a data_loop is needed for async operation"); @@ -413,14 +405,14 @@ impl_node_set_callbacks(struct spa_node *node, return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } @@ -451,12 +443,12 @@ static int port_get_format(struct impl *this, struct port *port, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -465,11 +457,8 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); port = &this->port; @@ -562,17 +551,15 @@ static int port_set_format(struct impl *this, struct port *port, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); port = &this->port; @@ -584,20 +571,17 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -631,7 +615,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -639,13 +623,10 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -656,19 +637,16 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -696,15 +674,12 @@ static inline void reuse_buffer(struct impl *this, struct port *port, uint32_t i } } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(port_id == 0, -EINVAL); port = &this->port; @@ -715,15 +690,14 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_io_buffers *io; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; io = port->io; spa_return_val_if_fail(io != NULL, -EIO); @@ -743,8 +717,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_OK; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -829,7 +803,10 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS; this->info = SPA_NODE_INFO_INIT(); diff --git a/spa/plugins/v4l2/v4l2-device.c b/spa/plugins/v4l2/v4l2-device.c index 96748f580..21c80520e 100644 --- a/spa/plugins/v4l2/v4l2-device.c +++ b/spa/plugins/v4l2/v4l2-device.c @@ -115,19 +115,18 @@ static int emit_info(struct impl *this, bool full) return 0; } -static int impl_add_listener(struct spa_device *device, +static int impl_add_listener(void *object, struct spa_hook *listener, const struct spa_device_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; int res = 0; - spa_return_val_if_fail(device != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(events != NULL, -EINVAL); - this = SPA_CONTAINER_OF(device, struct impl, device); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); if (events->info || events->object_info) @@ -138,25 +137,25 @@ static int impl_add_listener(struct spa_device *device, return res; } -static int impl_enum_params(struct spa_device *device, int seq, +static int impl_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { return -ENOTSUP; } -static int impl_set_param(struct spa_device *device, +static int impl_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { return -ENOTSUP; } -static const struct spa_device impl_device = { - SPA_VERSION_DEVICE, - impl_add_listener, - impl_enum_params, - impl_set_param, +static const struct spa_device_methods impl_device = { + SPA_VERSION_DEVICE_METHODS, + .add_listener = impl_add_listener, + .enum_params = impl_enum_params, + .set_param = impl_set_param, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -218,7 +217,10 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->device = impl_device; + this->device.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Device, + SPA_VERSION_DEVICE, + &impl_device, this); this->dev.log = this->log; this->dev.fd = -1; diff --git a/spa/plugins/v4l2/v4l2-monitor.c b/spa/plugins/v4l2/v4l2-monitor.c index 4a028557e..464330e9a 100644 --- a/spa/plugins/v4l2/v4l2-monitor.c +++ b/spa/plugins/v4l2/v4l2-monitor.c @@ -225,6 +225,7 @@ static int start_monitor(struct impl *this) this->source.fd = udev_monitor_get_fd(this->umonitor);; this->source.mask = SPA_IO_IN | SPA_IO_ERR; + spa_log_debug(this->log, "monitor %p", this->umonitor); spa_loop_add_source(this->main_loop, &this->source); return 0; @@ -273,16 +274,14 @@ static int enum_devices(struct impl *this) static int -impl_monitor_set_callbacks(struct spa_monitor *monitor, +impl_monitor_set_callbacks(void *object, const struct spa_monitor_callbacks *callbacks, void *data) { int res; - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(monitor != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(monitor, struct impl, monitor); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); @@ -302,9 +301,9 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor, return 0; } -static const struct spa_monitor impl_monitor = { - SPA_VERSION_MONITOR, - impl_monitor_set_callbacks, +static const struct spa_monitor_methods impl_monitor = { + SPA_VERSION_MONITOR_METHODS, + .set_callbacks = impl_monitor_set_callbacks, }; static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) @@ -327,7 +326,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i static int impl_clear(struct spa_handle *handle) { struct impl *this = (struct impl *) handle; - impl_monitor_set_callbacks(&this->monitor, NULL, NULL); + impl_monitor_set_callbacks(this, NULL, NULL); return 0; } @@ -367,7 +366,10 @@ impl_init(const struct spa_handle_factory *factory, return -EINVAL; } - this->monitor = impl_monitor; + this->monitor.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Monitor, + SPA_VERSION_MONITOR, + &impl_monitor, this); return 0; } @@ -394,7 +396,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory, } const struct spa_handle_factory spa_v4l2_monitor_factory = { - SPA_VERSION_MONITOR, + SPA_VERSION_HANDLE_FACTORY, NAME, NULL, impl_get_size, diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index a03a6147d..bc920dd26 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -149,22 +149,20 @@ struct impl { #include "v4l2-utils.c" -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -236,15 +234,13 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_param(struct spa_node *node, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -266,13 +262,11 @@ static int impl_node_set_param(struct spa_node *node, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_IO_Clock: @@ -287,16 +281,14 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: { @@ -352,17 +344,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -373,43 +364,41 @@ impl_node_add_listener(struct spa_node *node, return 0; } -static int impl_node_set_callbacks(struct spa_node *node, +static int impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } -static int impl_node_add_port(struct spa_node *node, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } -static int impl_node_remove_port(struct spa_node *node, +static int impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } -static int port_get_format(struct spa_node *node, +static int port_get_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, const struct spa_pod *filter, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port = GET_PORT(this, direction, port_id); struct spa_pod_frame f; @@ -454,14 +443,14 @@ static int port_get_format(struct spa_node *node, return 1; } -static int impl_node_port_enum_params(struct spa_node *node, int seq, +static int impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -470,11 +459,8 @@ static int impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -494,7 +480,7 @@ static int impl_node_port_enum_params(struct spa_node *node, int seq, return spa_v4l2_enum_format(this, seq, start, num, filter); case SPA_PARAM_Format: - if((res = port_get_format(node, direction, port_id, + if((res = port_get_format(this, direction, port_id, result.index, filter, ¶m, &b)) <= 0) return res; break; @@ -564,12 +550,12 @@ static int impl_node_port_enum_params(struct spa_node *node, int seq, return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct spa_video_info info; struct port *port = GET_PORT(this, direction, port_id); int res; @@ -658,36 +644,33 @@ static int port_set_format(struct spa_node *node, return 0; } -static int impl_node_port_set_param(struct spa_node *node, +static int impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(object != NULL, -EINVAL); - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); + spa_return_val_if_fail(CHECK_PORT(object, direction, port_id), -EINVAL); if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } -static int impl_node_port_use_buffers(struct spa_node *node, +static int impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -708,7 +691,7 @@ static int impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -716,15 +699,12 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(buffers != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -737,19 +717,16 @@ impl_node_port_alloc_buffers(struct spa_node *node, return res; } -static int impl_node_port_set_io(struct spa_node *node, +static int impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -767,18 +744,17 @@ static int impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_port_reuse_buffer(struct spa_node *node, +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(port_id == 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = GET_OUT_PORT(this, port_id); spa_return_val_if_fail(buffer_id < port->n_buffers, -EINVAL); @@ -854,17 +830,15 @@ static int process_control(struct impl *this, struct spa_pod_sequence *control) return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; int res; struct spa_io_buffers *io; struct port *port; struct buffer *b; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); port = GET_OUT_PORT(this, 0); io = port->io; @@ -873,7 +847,7 @@ static int impl_node_process(struct spa_node *node) if (port->control) process_control(this, &port->control->sequence); - spa_log_trace(this->log, NAME " %p; status %d", node, io->status); + spa_log_trace(this->log, NAME " %p; status %d", this, io->status); if (io->status == SPA_STATUS_HAVE_BUFFER) return SPA_STATUS_HAVE_BUFFER; @@ -891,7 +865,7 @@ static int impl_node_process(struct spa_node *node) b = spa_list_first(&port->queue, struct buffer, link); spa_list_remove(&b->link); - spa_log_trace(this->log, NAME " %p: dequeue buffer %d", node, b->id); + spa_log_trace(this->log, NAME " %p: dequeue buffer %d", this, b->id); io->buffer_id = b->id; io->status = SPA_STATUS_HAVE_BUFFER; @@ -899,8 +873,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -985,7 +959,10 @@ impl_init(const struct spa_handle_factory *factory, return -EINVAL; } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index c012c6222..d8ff7dfd1 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -122,22 +122,20 @@ struct impl { #define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_PORTS) -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - result.id = id; result.next = start; next: @@ -211,19 +209,17 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -343,15 +339,14 @@ static void on_output(struct spa_source *source) spa_node_call_ready(&this->callbacks, res); } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; switch (SPA_NODE_COMMAND_ID(command)) { @@ -424,17 +419,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -446,34 +440,32 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, const struct spa_pod *filter, @@ -506,12 +498,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -520,11 +512,9 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -537,7 +527,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, filter, ¶m, &b)) <= 0) return res; break; @@ -658,17 +648,15 @@ static int port_set_format(struct impl *this, struct port *port, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); port = &this->port; @@ -680,20 +668,17 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -727,7 +712,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -735,13 +720,10 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -752,19 +734,16 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = &this->port; @@ -790,15 +769,12 @@ static inline void reuse_buffer(struct impl *this, struct port *port, uint32_t i set_timer(this, true); } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(port_id == 0, -EINVAL); port = &this->port; spa_return_val_if_fail(buffer_id < port->n_buffers, -EINVAL); @@ -808,15 +784,14 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_io_buffers *io; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); port = &this->port; io = port->io; spa_return_val_if_fail(io != NULL, -EIO); @@ -835,8 +810,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_OK; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -921,7 +896,11 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); + this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PROPS | SPA_NODE_CHANGE_MASK_PARAMS; diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index a8ca4cdc3..20b1a3d0e 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -111,11 +111,11 @@ struct impl { #define GET_OUT_PORT(this,p) (&this->out_ports[p]) #define GET_PORT(this,d,p) (d == SPA_DIRECTION_INPUT ? GET_IN_PORT(this,p) : GET_OUT_PORT(this,p)) -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -123,10 +123,9 @@ static int impl_node_enum_params(struct spa_node *node, int seq, struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); p = &this->props; result.id = id; @@ -184,19 +183,17 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); switch (id) { case SPA_PARAM_Props: @@ -220,15 +217,13 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -264,17 +259,16 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } static int -impl_node_add_listener(struct spa_node *node, +impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -287,26 +281,26 @@ impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { return -ENOTSUP; } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { return -ENOTSUP; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, const struct spa_pod *filter, @@ -333,12 +327,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -347,11 +341,8 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -365,7 +356,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, + if ((res = port_enum_formats(this, direction, port_id, result.index, filter, ¶m, &b)) <= 0) return res; break; @@ -445,12 +436,12 @@ static int clear_buffers(struct impl *this, struct port *port) return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port; int res; @@ -491,37 +482,34 @@ static int port_set_format(struct spa_node *node, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(object != NULL, -EINVAL); - spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); + spa_return_val_if_fail(CHECK_PORT(object, direction, port_id), -EINVAL); if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -560,7 +548,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -572,19 +560,16 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -614,15 +599,12 @@ static void recycle_buffer(struct impl *this, uint32_t id) spa_log_trace(this->log, NAME " %p: recycle buffer %d", this, id); } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); @@ -696,16 +678,14 @@ static void do_volume(struct impl *this, struct spa_buffer *dbuf, struct spa_buf dd[0].chunk->stride = 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *in_port, *out_port; struct spa_io_buffers *input, *output; struct buffer *dbuf, *sbuf; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); out_port = GET_OUT_PORT(this, 0); output = out_port->io; @@ -750,8 +730,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -824,7 +804,10 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS; this->info = SPA_NODE_INFO_INIT(); diff --git a/spa/tools/spa-inspect.c b/spa/tools/spa-inspect.c index 75ff7872d..c2eeee50d 100644 --- a/spa/tools/spa-inspect.c +++ b/spa/tools/spa-inspect.c @@ -240,19 +240,9 @@ static void inspect_factory(struct data *data, const struct spa_handle_factory * } } -static int do_add_source(struct spa_loop *loop, struct spa_source *source) -{ - return 0; -} - -static int do_update_source(struct spa_source *source) -{ - return 0; -} - -static void do_remove_source(struct spa_source *source) -{ -} +static const struct spa_loop_methods impl_loop = { + SPA_VERSION_LOOP_METHODS, +}; int main(int argc, char *argv[]) { @@ -269,10 +259,10 @@ int main(int argc, char *argv[]) } data.log = &default_log.log; - data.loop.version = SPA_VERSION_LOOP; - data.loop.add_source = do_add_source; - data.loop.update_source = do_update_source; - data.loop.remove_source = do_remove_source; + data.loop.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Loop, + SPA_VERSION_LOOP, + &impl_loop, &data); if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); diff --git a/spa/tools/spa-monitor.c b/spa/tools/spa-monitor.c index ccca863d5..07444ecf9 100644 --- a/spa/tools/spa-monitor.c +++ b/spa/tools/spa-monitor.c @@ -88,9 +88,9 @@ static int on_monitor_event(void *_data, struct spa_event *event) return 0; } -static int do_add_source(struct spa_loop *loop, struct spa_source *source) +static int do_add_source(void *object, struct spa_source *source) { - struct data *data = SPA_CONTAINER_OF(loop, struct data, main_loop); + struct data *data = object; data->sources[data->n_sources] = *source; data->n_sources++; @@ -99,14 +99,10 @@ static int do_add_source(struct spa_loop *loop, struct spa_source *source) return 0; } -static int do_update_source(struct spa_source *source) -{ - return 0; -} - -static void do_remove_source(struct spa_source *source) -{ -} +static const struct spa_loop_methods impl_loop = { + SPA_VERSION_LOOP_METHODS, + .add_source = do_add_source, +}; static const struct spa_monitor_callbacks impl_callbacks = { SPA_VERSION_MONITOR_CALLBACKS, @@ -161,10 +157,10 @@ int main(int argc, char *argv[]) uint32_t fidx; data.log = &default_log.log; - data.main_loop.version = SPA_VERSION_LOOP; - data.main_loop.add_source = do_add_source; - data.main_loop.update_source = do_update_source; - data.main_loop.remove_source = do_remove_source; + data.main_loop.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Loop, + SPA_VERSION_LOOP, + &impl_loop, &data); data.support[1] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_Log, data.log); data.support[2] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_MainLoop, &data.main_loop); diff --git a/src/examples/export-sink.c b/src/examples/export-sink.c index 433691318..59c337100 100644 --- a/src/examples/export-sink.c +++ b/src/examples/export-sink.c @@ -129,17 +129,17 @@ static void update_param(struct data *data) data->param_accum -= M_PI_M2; } -static int impl_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_send_command(void *object, const struct spa_command *command) { return 0; } -static int impl_add_listener(struct spa_node *node, +static int impl_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; struct spa_hook_list save; spa_hook_list_isolate(&d->hooks, &save, listener, events, data); @@ -154,23 +154,23 @@ static int impl_add_listener(struct spa_node *node, return 0; } -static int impl_set_callbacks(struct spa_node *node, +static int impl_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { return 0; } -static int impl_set_io(struct spa_node *node, +static int impl_set_io(void *object, uint32_t id, void *data, size_t size) { return 0; } -static int impl_port_set_io(struct spa_node *node, +static int impl_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; switch (id) { case SPA_IO_Buffers: @@ -186,12 +186,12 @@ static int impl_port_set_io(struct spa_node *node, return 0; } -static int impl_port_enum_params(struct spa_node *node, int seq, +static int impl_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -288,11 +288,11 @@ static int impl_port_enum_params(struct spa_node *node, int seq, return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; Uint32 sdl_format; void *dest; @@ -327,22 +327,22 @@ static int port_set_format(struct spa_node *node, return 0; } -static int impl_port_set_param(struct spa_node *node, +static int impl_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } -static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; uint32_t i; for (i = 0; i < n_buffers; i++) @@ -417,9 +417,9 @@ static int do_render(struct spa_loop *loop, bool async, uint32_t seq, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; struct spa_buffer *buf; int res; @@ -441,8 +441,8 @@ static int impl_node_process(struct spa_node *node) return d->io->status = SPA_STATUS_NEED_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_add_listener, .set_callbacks = impl_set_callbacks, .set_io = impl_set_io, @@ -465,7 +465,10 @@ static void make_node(struct data *data) pw_properties_set(props, PW_NODE_PROP_CATEGORY, "Capture"); pw_properties_set(props, PW_NODE_PROP_ROLE, "Camera"); - data->impl_node = impl_node; + data->impl_node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, data); pw_remote_export(data->remote, SPA_TYPE_INTERFACE_Node, props, &data->impl_node); } diff --git a/src/examples/export-source.c b/src/examples/export-source.c index d01b6b3f6..98f8450b6 100644 --- a/src/examples/export-source.c +++ b/src/examples/export-source.c @@ -102,17 +102,17 @@ static void update_volume(struct data *data) data->volume_accum -= M_PI_M2; } -static int impl_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_send_command(void *object, const struct spa_command *command) { return 0; } -static int impl_add_listener(struct spa_node *node, +static int impl_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; struct spa_hook_list save; spa_hook_list_isolate(&d->hooks, &save, listener, events, data); @@ -125,22 +125,22 @@ static int impl_add_listener(struct spa_node *node, return 0; } -static int impl_set_callbacks(struct spa_node *node, +static int impl_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { return 0; } -static int impl_set_io(struct spa_node *node, +static int impl_set_io(void *object, uint32_t id, void *data, size_t size) { return 0; } -static int impl_port_set_io(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; switch (id) { case SPA_IO_Buffers: @@ -156,12 +156,12 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction, return 0; } -static int impl_port_enum_params(struct spa_node *node, int seq, +static int impl_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -260,11 +260,11 @@ static int impl_port_enum_params(struct spa_node *node, int seq, return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; d->info.change_mask = SPA_PORT_CHANGE_MASK_PARAMS; if (format == NULL) { @@ -291,22 +291,22 @@ static int port_set_format(struct spa_node *node, return 0; } -static int impl_port_set_param(struct spa_node *node, +static int impl_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } -static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; uint32_t i; for (i = 0; i < n_buffers; i++) { struct buffer *b = &d->buffers[i]; @@ -347,9 +347,9 @@ static inline void reuse_buffer(struct data *d, uint32_t id) spa_list_append(&d->empty, &d->buffers[id].link); } -static int impl_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; reuse_buffer(d, buffer_id); return 0; } @@ -396,9 +396,9 @@ static void fill_s16(struct data *d, void *dest, int avail) } } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; struct buffer *b; int avail; struct spa_io_buffers *io = d->io; @@ -446,8 +446,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_add_listener, .set_callbacks = impl_set_callbacks, .set_io = impl_set_io, @@ -473,7 +473,10 @@ static void make_node(struct data *data) if (data->path) pw_properties_set(props, PW_NODE_PROP_TARGET_NODE, data->path); - data->impl_node = impl_node; + data->impl_node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, data); pw_remote_export(data->remote, SPA_TYPE_INTERFACE_Node, props, &data->impl_node); } diff --git a/src/examples/export-spa.c b/src/examples/export-spa.c index b93496cc3..b86d956d4 100644 --- a/src/examples/export-spa.c +++ b/src/examples/export-spa.c @@ -65,7 +65,7 @@ static int make_node(struct data *data) data->node = pw_factory_create_object(factory, NULL, PW_TYPE_INTERFACE_Node, - PW_VERSION_NODE, + PW_VERSION_NODE_PROXY, props, SPA_ID_INVALID); pw_node_set_active(data->node, true); diff --git a/src/examples/local-v4l2.c b/src/examples/local-v4l2.c index c9ab820dc..f20b2b70b 100644 --- a/src/examples/local-v4l2.c +++ b/src/examples/local-v4l2.c @@ -80,22 +80,22 @@ static void handle_events(struct data *data) } } -static int impl_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_set_io(void *object, uint32_t id, void *data, size_t size) { return 0; } -static int impl_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_send_command(void *object, const struct spa_command *command) { return 0; } -static int impl_add_listener(struct spa_node *node, +static int impl_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; struct spa_port_info info; struct spa_hook_list save; @@ -112,16 +112,16 @@ static int impl_add_listener(struct spa_node *node, return 0; } -static int impl_set_callbacks(struct spa_node *node, +static int impl_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { return 0; } -static int impl_port_set_io(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; if (id == SPA_IO_Buffers) d->io = data; @@ -131,12 +131,12 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction, return 0; } -static int impl_port_enum_params(struct spa_node *node, int seq, +static int impl_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -200,10 +200,10 @@ static int impl_port_enum_params(struct spa_node *node, int seq, return 0; } -static int port_set_format(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; Uint32 sdl_format; void *dest; @@ -229,22 +229,22 @@ static int port_set_format(struct spa_node *node, enum spa_direction direction, return 0; } -static int impl_port_set_param(struct spa_node *node, +static int impl_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; } -static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; uint32_t i; for (i = 0; i < n_buffers; i++) @@ -303,9 +303,9 @@ static int do_render(struct spa_loop *loop, bool async, uint32_t seq, return 0; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); + struct data *d = object; int res; if ((res = pw_loop_invoke(pw_main_loop_get_loop(d->loop), do_render, @@ -319,9 +319,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_NEED_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, - NULL, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_add_listener, .set_callbacks = impl_set_callbacks, .set_io = impl_set_io, @@ -339,7 +338,10 @@ static void make_nodes(struct data *data) struct pw_properties *props; data->node = pw_node_new(data->core, "SDL-sink", NULL, 0); - data->impl_node = impl_node; + data->impl_node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, data); pw_node_set_implementation(data->node, &data->impl_node); pw_node_register(data->node, NULL, NULL, NULL); @@ -350,7 +352,7 @@ static void make_nodes(struct data *data) data->v4l2 = pw_factory_create_object(factory, NULL, PW_TYPE_INTERFACE_Node, - PW_VERSION_NODE, + PW_VERSION_NODE_PROXY, props, SPA_ID_INVALID); data->link = pw_link_new(data->core, diff --git a/src/examples/media-session.c b/src/examples/media-session.c index b2229c7a3..f9e56d415 100644 --- a/src/examples/media-session.c +++ b/src/examples/media-session.c @@ -308,7 +308,7 @@ static int link_session_dsp(struct impl *impl, struct session *session) session->link_proxy = pw_core_proxy_create_object(impl->core_proxy, "link-factory", PW_TYPE_INTERFACE_Link, - PW_VERSION_LINK, + PW_VERSION_LINK_PROXY, &props->dict, 0); pw_proxy_add_listener(session->link_proxy, &session->link_listener, &link_proxy_events, session); @@ -481,7 +481,7 @@ handle_node(struct impl *impl, uint32_t id, uint32_t parent_id, media_class = props ? spa_dict_lookup(props, "media.class") : NULL; p = pw_registry_proxy_bind(impl->registry_proxy, - id, type, PW_VERSION_NODE, + id, type, PW_VERSION_NODE_PROXY, sizeof(struct node)); node = pw_proxy_get_user_data(p); @@ -657,7 +657,7 @@ handle_port(struct impl *impl, uint32_t id, uint32_t parent_id, uint32_t type, return -EINVAL; p = pw_registry_proxy_bind(impl->registry_proxy, - id, type, PW_VERSION_PORT, + id, type, PW_VERSION_PORT_PROXY, sizeof(struct port)); port = pw_proxy_get_user_data(p); @@ -737,7 +737,7 @@ handle_client(struct impl *impl, uint32_t id, uint32_t parent_id, const char *str; p = pw_registry_proxy_bind(impl->registry_proxy, - id, type, PW_VERSION_CLIENT, + id, type, PW_VERSION_CLIENT_PROXY, sizeof(struct client)); client = pw_proxy_get_user_data(p); @@ -932,7 +932,7 @@ static int link_nodes(struct node *peer, enum pw_direction direction, struct nod pw_core_proxy_create_object(impl->core_proxy, "link-factory", PW_TYPE_INTERFACE_Link, - PW_VERSION_LINK, + PW_VERSION_LINK_PROXY, &props->dict, 0); @@ -1259,7 +1259,7 @@ static void rescan_session(struct impl *impl, struct session *sess) sess->dsp_proxy = pw_core_proxy_create_object(impl->core_proxy, "audio-dsp", PW_TYPE_INTERFACE_Node, - PW_VERSION_NODE, + PW_VERSION_NODE_PROXY, &props->dict, 0); pw_properties_free(props); @@ -1299,7 +1299,7 @@ static void do_rescan(struct impl *impl) static void core_done(void *data, uint32_t id, int seq) { struct impl *impl = data; - pw_log_debug("media-session %p: sync %d %d/%d", impl, id, seq, impl->seq); + pw_log_debug("media-session %p: sync %u %d/%d", impl, id, seq, impl->seq); if (impl->seq == seq) do_rescan(impl); } @@ -1326,7 +1326,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remo &impl->core_listener, &core_events, impl); impl->registry_proxy = pw_core_proxy_get_registry(impl->core_proxy, - PW_VERSION_REGISTRY, 0); + PW_VERSION_REGISTRY_PROXY, 0); pw_registry_proxy_add_listener(impl->registry_proxy, &impl->registry_listener, ®istry_events, impl); diff --git a/src/extensions/client-node.h b/src/extensions/client-node.h index eaa80e6de..b8f2c3c6f 100644 --- a/src/extensions/client-node.h +++ b/src/extensions/client-node.h @@ -32,9 +32,7 @@ extern "C" { #include #include -#include - -struct pw_client_node_proxy; +struct pw_client_node_proxy { struct spa_interface iface; }; #define PW_VERSION_CLIENT_NODE 0 @@ -48,117 +46,6 @@ struct pw_client_node_buffer { struct spa_buffer *buffer; /**< buffer describing metadata and buffer memory */ }; -#define PW_CLIENT_NODE_PROXY_METHOD_GET_NODE 0 -#define PW_CLIENT_NODE_PROXY_METHOD_UPDATE 1 -#define PW_CLIENT_NODE_PROXY_METHOD_PORT_UPDATE 2 -#define PW_CLIENT_NODE_PROXY_METHOD_SET_ACTIVE 3 -#define PW_CLIENT_NODE_PROXY_METHOD_EVENT 4 -#define PW_CLIENT_NODE_PROXY_METHOD_NUM 5 - -/** \ref pw_client_node methods */ -struct pw_client_node_proxy_methods { -#define PW_VERSION_CLIENT_NODE_PROXY_METHODS 0 - uint32_t version; - - /** get the node object - */ - int (*get_node) (void *object, uint32_t version, uint32_t new_id); - /** - * Update the node ports and properties - * - * Update the maximum number of ports and the params of the - * client node. - * \param change_mask bitfield with changed parameters - * \param max_input_ports new max input ports - * \param max_output_ports new max output ports - * \param params new params - */ - int (*update) (void *object, -#define PW_CLIENT_NODE_UPDATE_PARAMS (1 << 0) -#define PW_CLIENT_NODE_UPDATE_INFO (1 << 1) - uint32_t change_mask, - uint32_t n_params, - const struct spa_pod **params, - const struct spa_node_info *info); - - /** - * Update a node port - * - * Update the information of one port of a node. - * \param direction the direction of the port - * \param port_id the port id to update - * \param change_mask a bitfield of changed items - * \param n_params number of port parameters - * \param params array of port parameters - * \param info port information - */ - int (*port_update) (void *object, - enum spa_direction direction, - uint32_t port_id, -#define PW_CLIENT_NODE_PORT_UPDATE_PARAMS (1 << 0) -#define PW_CLIENT_NODE_PORT_UPDATE_INFO (1 << 1) - uint32_t change_mask, - uint32_t n_params, - const struct spa_pod **params, - const struct spa_port_info *info); - /** - * Activate or deactivate the node - */ - int (*set_active) (void *object, bool active); - /** - * Send an event to the node - * \param event the event to send - */ - int (*event) (void *object, struct spa_event *event); -}; - -static inline struct pw_node_proxy * -pw_client_node_proxy_get_node(struct pw_client_node_proxy *p, uint32_t version, size_t user_data_size) -{ - struct pw_proxy *np = pw_proxy_new((struct pw_proxy*)p, PW_TYPE_INTERFACE_Node, user_data_size); - pw_proxy_do((struct pw_proxy*)p, struct pw_client_node_proxy_methods, - get_node, version, pw_proxy_get_id(np)); - return (struct pw_node_proxy *) np; -} - -static inline int -pw_client_node_proxy_update(struct pw_client_node_proxy *p, - uint32_t change_mask, - uint32_t n_params, - const struct spa_pod **params, - const struct spa_node_info *info) -{ - return pw_proxy_do((struct pw_proxy*)p, struct pw_client_node_proxy_methods, - update, - change_mask, n_params, params, info); -} - -static inline int -pw_client_node_proxy_port_update(struct pw_client_node_proxy *p, - 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 pw_proxy_do((struct pw_proxy*)p, struct pw_client_node_proxy_methods, - port_update, direction, port_id, change_mask, - n_params, params, info); -} - -static inline int -pw_client_node_proxy_set_active(struct pw_client_node_proxy *p, bool active) -{ - return pw_proxy_do((struct pw_proxy*)p, struct pw_client_node_proxy_methods, set_active, active); -} - -static inline int -pw_client_node_proxy_event(struct pw_client_node_proxy *p, struct spa_event *event) -{ - return pw_proxy_do((struct pw_proxy*)p, struct pw_client_node_proxy_methods, event, event); -} - #define PW_CLIENT_NODE_PROXY_EVENT_ADD_MEM 0 #define PW_CLIENT_NODE_PROXY_EVENT_TRANSPORT 1 #define PW_CLIENT_NODE_PROXY_EVENT_SET_PARAM 2 @@ -331,39 +218,102 @@ struct pw_client_node_proxy_events { uint32_t size); }; -static inline void -pw_client_node_proxy_add_listener(struct pw_client_node_proxy *p, - struct spa_hook *listener, - const struct pw_client_node_proxy_events *events, - void *data) +#define PW_CLIENT_NODE_PROXY_METHOD_ADD_LISTENER 0 +#define PW_CLIENT_NODE_PROXY_METHOD_GET_NODE 1 +#define PW_CLIENT_NODE_PROXY_METHOD_UPDATE 2 +#define PW_CLIENT_NODE_PROXY_METHOD_PORT_UPDATE 3 +#define PW_CLIENT_NODE_PROXY_METHOD_SET_ACTIVE 4 +#define PW_CLIENT_NODE_PROXY_METHOD_EVENT 5 +#define PW_CLIENT_NODE_PROXY_METHOD_NUM 6 + +/** \ref pw_client_node methods */ +struct pw_client_node_proxy_methods { +#define PW_VERSION_CLIENT_NODE_PROXY_METHODS 0 + uint32_t version; + + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_client_node_proxy_events *events, + void *data); + /** get the node object + */ + struct pw_node_proxy * (*get_node) (void *object, uint32_t version, size_t user_data_size); + /** + * Update the node ports and properties + * + * Update the maximum number of ports and the params of the + * client node. + * \param change_mask bitfield with changed parameters + * \param max_input_ports new max input ports + * \param max_output_ports new max output ports + * \param params new params + */ + int (*update) (void *object, +#define PW_CLIENT_NODE_UPDATE_PARAMS (1 << 0) +#define PW_CLIENT_NODE_UPDATE_INFO (1 << 1) + uint32_t change_mask, + uint32_t n_params, + const struct spa_pod **params, + const struct spa_node_info *info); + + /** + * Update a node port + * + * Update the information of one port of a node. + * \param direction the direction of the port + * \param port_id the port id to update + * \param change_mask a bitfield of changed items + * \param n_params number of port parameters + * \param params array of port parameters + * \param info port information + */ + int (*port_update) (void *object, + enum spa_direction direction, + uint32_t port_id, +#define PW_CLIENT_NODE_PORT_UPDATE_PARAMS (1 << 0) +#define PW_CLIENT_NODE_PORT_UPDATE_INFO (1 << 1) + uint32_t change_mask, + uint32_t n_params, + const struct spa_pod **params, + const struct spa_port_info *info); + /** + * Activate or deactivate the node + */ + int (*set_active) (void *object, bool active); + /** + * Send an event to the node + * \param event the event to send + */ + int (*event) (void *object, struct spa_event *event); +}; + + +#define pw_client_node_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_client_node_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_client_node_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) + +#define pw_client_node_proxy_add_listener(c,...) pw_client_node_proxy_method(c,add_listener,0,__VA_ARGS__) + +static inline struct pw_node_proxy * +pw_client_node_proxy_get_node(struct pw_client_node_proxy *p, uint32_t version, size_t user_data_size) { - pw_proxy_add_proxy_listener((struct pw_proxy*)p, listener, events, data); + struct pw_node_proxy *res = NULL; + spa_interface_call_res(&p->iface, + struct pw_client_node_proxy_methods, res, + get_node, 0, version, user_data_size); + return res; } -#define pw_client_node_resource_add_mem(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,add_mem,__VA_ARGS__) -#define pw_client_node_resource_transport(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,transport,__VA_ARGS__) -#define pw_client_node_resource_set_param(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,set_param,__VA_ARGS__) -#define pw_client_node_resource_set_io(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,set_io,__VA_ARGS__) -#define pw_client_node_resource_event(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,event,__VA_ARGS__) -#define pw_client_node_resource_command(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,command,__VA_ARGS__) -#define pw_client_node_resource_add_port(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,add_port,__VA_ARGS__) -#define pw_client_node_resource_remove_port(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,remove_port,__VA_ARGS__) -#define pw_client_node_resource_port_set_param(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,port_set_param,__VA_ARGS__) -#define pw_client_node_resource_port_use_buffers(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,port_use_buffers,__VA_ARGS__) -#define pw_client_node_resource_port_set_io(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,port_set_io,__VA_ARGS__) -#define pw_client_node_resource_set_activation(r,...) \ - pw_resource_notify(r,struct pw_client_node_proxy_events,set_activation,__VA_ARGS__) +#define pw_client_node_proxy_update(c,...) pw_client_node_proxy_method(c,update,0,__VA_ARGS__) +#define pw_client_node_proxy_port_update(c,...) pw_client_node_proxy_method(c,port_update,0,__VA_ARGS__) +#define pw_client_node_proxy_set_active(c,...) pw_client_node_proxy_method(c,set_active,0,__VA_ARGS__) +#define pw_client_node_proxy_event(c,...) pw_client_node_proxy_method(c,event,0,__VA_ARGS__) #ifdef __cplusplus } /* extern "C" */ diff --git a/src/gst/gstpipewiredeviceprovider.c b/src/gst/gstpipewiredeviceprovider.c index 8dad8f6b2..513eeea54 100644 --- a/src/gst/gstpipewiredeviceprovider.c +++ b/src/gst/gstpipewiredeviceprovider.c @@ -462,7 +462,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id, u node = pw_registry_proxy_bind(rd->registry, id, PW_TYPE_INTERFACE_Node, - PW_VERSION_NODE, sizeof(*nd)); + PW_VERSION_NODE_PROXY, sizeof(*nd)); if (node == NULL) goto no_mem; @@ -486,7 +486,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id, u port = pw_registry_proxy_bind(rd->registry, id, PW_TYPE_INTERFACE_Port, - PW_VERSION_PORT, sizeof(*pd)); + PW_VERSION_PORT_PROXY, sizeof(*pd)); if (port == NULL) goto no_mem; @@ -580,8 +580,7 @@ gst_pipewire_device_provider_probe (GstDeviceProvider * provider) self->list_only = TRUE; self->devices = NULL; - data->registry = pw_core_proxy_get_registry(self->core_proxy, - PW_VERSION_REGISTRY, 0); + data->registry = pw_core_proxy_get_registry(self->core_proxy, PW_VERSION_REGISTRY_PROXY, 0); pw_registry_proxy_add_listener(data->registry, &data->registry_listener, ®istry_events, data); pw_core_proxy_sync(self->core_proxy, 0, self->seq++); @@ -666,8 +665,8 @@ gst_pipewire_device_provider_start (GstDeviceProvider * provider) } GST_DEBUG_OBJECT (self, "connected"); - self->registry = pw_core_proxy_get_registry(self->core_proxy, - PW_VERSION_REGISTRY, 0); + self->registry = pw_core_proxy_get_registry(self->core_proxy, PW_VERSION_REGISTRY_PROXY, 0); + data->registry = self->registry; pw_registry_proxy_add_listener(self->registry, &data->registry_listener, ®istry_events, data); diff --git a/src/modules/module-audio-dsp.c b/src/modules/module-audio-dsp.c index 758a28d23..2fea40845 100644 --- a/src/modules/module-audio-dsp.c +++ b/src/modules/module-audio-dsp.c @@ -136,7 +136,8 @@ static void *create_object(void *_data, pw_node_register(dsp, client, pw_module_get_global(d->module), NULL); pw_node_add_listener(dsp, &nd->dsp_listener, &node_events, nd); - res = pw_global_bind(pw_node_get_global(dsp), client, PW_PERM_RWX, PW_VERSION_NODE, new_id); + res = pw_global_bind(pw_node_get_global(dsp), client, + PW_PERM_RWX, PW_VERSION_NODE_PROXY, new_id); if (res < 0) goto no_bind; @@ -208,7 +209,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie factory = pw_factory_new(core, "audio-dsp", PW_TYPE_INTERFACE_Node, - PW_VERSION_NODE, + PW_VERSION_NODE_PROXY, NULL, sizeof(*data)); if (factory == NULL) diff --git a/src/modules/module-audio-dsp/floatmix.c b/src/modules/module-audio-dsp/floatmix.c index 3039cde97..1e1fa9e13 100644 --- a/src/modules/module-audio-dsp/floatmix.c +++ b/src/modules/module-audio-dsp/floatmix.c @@ -124,33 +124,31 @@ struct impl { #define GET_OUT_PORT(this,p) (&this->out_ports[p]) #define GET_PORT(this,d,p) (d == SPA_DIRECTION_INPUT ? GET_IN_PORT(this,p) : GET_OUT_PORT(this,p)) -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { return -ENOTSUP; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { return -ENOTSUP; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { return -ENOTSUP; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct impl *this; + struct impl *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); - switch (SPA_NODE_COMMAND_ID(command)) { case SPA_NODE_COMMAND_Start: this->started = true; @@ -185,18 +183,17 @@ static void emit_port_info(struct impl *this, struct port *port, bool full) } } -static int impl_node_add_listener(struct spa_node *node, +static int impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct impl *this; + struct impl *this = object; struct spa_hook_list save; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct impl, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); emit_node_info(this, true); @@ -212,23 +209,20 @@ static int impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *user_data) { return 0; } -static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_FREE_IN_PORT(this, direction, port_id), -EINVAL); port = GET_IN_PORT (this, port_id); @@ -266,15 +260,12 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_IN_PORT(this, direction, port_id), -EINVAL); port = GET_IN_PORT (this, port_id); @@ -303,13 +294,13 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3 return 0; } -static int port_enum_formats(struct spa_node *node, +static int port_enum_formats(void *object, enum spa_direction direction, uint32_t port_id, uint32_t index, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; switch (index) { case 0: @@ -333,12 +324,12 @@ static int port_enum_formats(struct spa_node *node, } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct impl *this; + struct impl *this = object; struct port *port; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -347,11 +338,8 @@ impl_node_port_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -365,7 +353,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq, switch (id) { case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, result.index, ¶m, &b)) <= 0) + if ((res = port_enum_formats(this, direction, port_id, result.index, ¶m, &b)) <= 0) return res; break; @@ -471,13 +459,13 @@ static struct buffer *dequeue_buffer(struct impl *this, struct port *port) return b; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; struct port *port; int res; @@ -538,41 +526,35 @@ static int port_set_format(struct spa_node *node, static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + struct impl *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(this, direction, port_id, flags, param); } else return -ENOENT; } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct impl *this; + struct impl *this = object; struct port *port; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -612,7 +594,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -624,17 +606,14 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -649,15 +628,12 @@ impl_node_port_set_io(struct spa_node *node, return 0; } -static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *this; + struct impl *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); - + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); port = GET_OUT_PORT(this, 0); @@ -721,18 +697,16 @@ static void mix_2(float * dst, const float * SPA_RESTRICT src1, #endif -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct impl *this; + struct impl *this = object; struct port *outport; struct spa_io_buffers *outio; uint32_t n_samples, n_buffers, i, maxsize; struct buffer **buffers; struct buffer *outb; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct impl, node); + spa_return_val_if_fail(this != NULL, -EINVAL); outport = GET_OUT_PORT(this, 0); outio = outport->io; @@ -825,8 +799,8 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER | SPA_STATUS_NEED_BUFFER; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .enum_params = impl_node_enum_params, @@ -899,7 +873,10 @@ impl_init(const struct spa_handle_factory *factory, spa_hook_list_init(&this->hooks); - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); this->info = SPA_NODE_INFO_INIT(); this->info.max_input_ports = MAX_PORTS; this->info.max_output_ports = 1; diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index 30430f42c..e538d9111 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -173,6 +173,33 @@ struct impl { int other_fds[2]; }; +#define pw_client_node_resource(r,m,v,...) \ + pw_resource_notify_res(r,struct pw_client_node_proxy_events,m,v,__VA_ARGS__) + +#define pw_client_node_resource_add_mem(r,...) \ + pw_client_node_resource(r,add_mem,0,__VA_ARGS__) +#define pw_client_node_resource_transport(r,...) \ + pw_client_node_resource(r,transport,0,__VA_ARGS__) +#define pw_client_node_resource_set_param(r,...) \ + pw_client_node_resource(r,set_param,0,__VA_ARGS__) +#define pw_client_node_resource_set_io(r,...) \ + pw_client_node_resource(r,set_io,0,__VA_ARGS__) +#define pw_client_node_resource_event(r,...) \ + pw_client_node_resource(r,event,0,__VA_ARGS__) +#define pw_client_node_resource_command(r,...) \ + pw_client_node_resource(r,command,0,__VA_ARGS__) +#define pw_client_node_resource_add_port(r,...) \ + pw_client_node_resource(r,add_port,0,__VA_ARGS__) +#define pw_client_node_resource_remove_port(r,...) \ + pw_client_node_resource(r,remove_port,0,__VA_ARGS__) +#define pw_client_node_resource_port_set_param(r,...) \ + pw_client_node_resource(r,port_set_param,0,__VA_ARGS__) +#define pw_client_node_resource_port_use_buffers(r,...) \ + pw_client_node_resource(r,port_use_buffers,0,__VA_ARGS__) +#define pw_client_node_resource_port_set_io(r,...) \ + pw_client_node_resource(r,port_set_io,0,__VA_ARGS__) +#define pw_client_node_resource_set_activation(r,...) \ + pw_client_node_resource(r,set_activation,0,__VA_ARGS__) static int do_port_use_buffers(struct impl *impl, enum spa_direction direction, @@ -356,21 +383,19 @@ static void mix_clear(struct node *this, struct mix *mix) mix->valid = false; } -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct node *this; + struct node *this = object; uint8_t buffer[1024]; struct spa_pod_builder b = { 0 }; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); - result.id = id; result.next = start; @@ -399,14 +424,12 @@ static int impl_node_enum_params(struct spa_node *node, int seq, return 0; } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct node *this; + struct node *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct node, node); + spa_return_val_if_fail(this != NULL, -EINVAL); if (this->resource == NULL) return -EIO; @@ -414,17 +437,16 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return pw_client_node_resource_set_param(this->resource, id, flags, param); } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct node *this; + struct node *this = object; struct impl *impl; struct pw_memblock *mem; struct mem *m; uint32_t memid, mem_offset, mem_size; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; if (impl->this.flags & 1) @@ -461,19 +483,17 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return 0; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct node *this; + struct node *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); - if (this->resource == NULL) return -EIO; - pw_log_debug("client-node %p: send command %d", node, SPA_COMMAND_TYPE(command)); + pw_log_debug("client-node %p: send command %d", this, SPA_COMMAND_TYPE(command)); return pw_client_node_resource_command(this->resource, command); } @@ -484,18 +504,17 @@ static void emit_port_info(struct node *this, struct port *port) port->direction, port->id, &port->info); } -static int impl_node_add_listener(struct spa_node *node, +static int impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct node *this; + struct node *this = object; struct spa_hook_list save; uint32_t i; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); for (i = 0; i < MAX_INPUTS; i++) { @@ -512,29 +531,30 @@ static int impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct node *this; + struct node *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } static int -impl_node_sync(struct spa_node *node, int seq) +impl_node_sync(void *object, int seq) { - struct node *this; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); - pw_log_debug("client-node %p: sync", node); + struct node *this = object; + + spa_return_val_if_fail(this != NULL, -EINVAL); + + pw_log_debug("client-node %p: sync", this); if (this->resource == NULL) return -EIO; + return pw_resource_ping(this->resource, seq); } @@ -622,50 +642,43 @@ clear_port(struct node *this, struct port *port) } static int -impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { - struct node *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); + struct node *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_FREE_PORT(this, direction, port_id), -EINVAL); return pw_client_node_resource_add_port(this->resource, direction, port_id, props); } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { - struct node *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); + struct node *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); return pw_client_node_resource_remove_port(this->resource, direction, port_id); } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct node *this; + struct node *this = object; struct port *port; uint8_t buffer[1024]; struct spa_pod_builder b = { 0 }; struct spa_result_node_params result; uint32_t count = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct node, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -702,17 +715,14 @@ impl_node_port_enum_params(struct spa_node *node, int seq, } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct node *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct node, node); + struct node *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); if (this->resource == NULL) @@ -783,7 +793,7 @@ static int do_port_set_io(struct impl *impl, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, @@ -907,18 +917,17 @@ do_port_use_buffers(struct impl *impl, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct node *this; + struct node *this = object; struct impl *impl; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; return do_port_use_buffers(impl, direction, port_id, @@ -926,7 +935,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -934,14 +943,11 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct node *this; + struct node *this = object; struct port *port; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(buffers != NULL, -EINVAL); - - this = SPA_CONTAINER_OF(node, struct node, node); - spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); port = GET_PORT(this, direction, port_id); @@ -954,13 +960,11 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct node *this; - - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); + struct node *this = object; + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(CHECK_OUT_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL); spa_log_trace_fp(this->log, "reuse buffer %d", buffer_id); @@ -968,9 +972,9 @@ impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t bu return -ENOTSUP; } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct node *this = SPA_CONTAINER_OF(node, struct node, node); + struct node *this = object; struct impl *impl = this->impl; struct pw_node *n = impl->this.node; struct timespec ts; @@ -988,18 +992,22 @@ static int impl_node_process(struct spa_node *node) return SPA_STATUS_OK; } -static int +static struct pw_node_proxy * client_node_get_node(void *data, uint32_t version, - uint32_t new_id) + size_t user_data_size) { struct impl *impl = data; struct node *this = &impl->node; + uint32_t new_id = user_data_size; + pw_log_debug("node %p: bind %u/%u", this, new_id, version); + impl->bind_node_version = version; impl->bind_node_id = new_id; pw_map_insert_at(&this->resource->client->objects, new_id, NULL); - return 0; + + return NULL; } static int @@ -1118,9 +1126,8 @@ static void node_on_data_fd_events(struct spa_source *source) } } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, - NULL, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .sync = impl_node_sync, @@ -1164,7 +1171,10 @@ node_init(struct node *this, return -EINVAL; } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); spa_list_init(&this->pending_list); @@ -1380,59 +1390,59 @@ static const struct pw_port_implementation port_impl = { }; static int -impl_mix_port_enum_params(struct spa_node *node, int seq, +impl_mix_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node); + struct port *port = object; return impl_node_port_enum_params(&port->node->node, seq, direction, port->id, id, start, num, filter); } static int -impl_mix_port_set_param(struct spa_node *node, +impl_mix_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node); + struct port *port = object; return impl_node_port_set_param(&port->node->node, direction, port->id, id, flags, param); } static int -impl_mix_add_port(struct spa_node *node, enum spa_direction direction, uint32_t mix_id, +impl_mix_add_port(void *object, enum spa_direction direction, uint32_t mix_id, const struct spa_dict *props) { - struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node); - pw_log_debug("client-node %p: add port %d:%d.%d", node, direction, port->id, mix_id); + struct port *port = object; + pw_log_debug("client-node %p: add port %d:%d.%d", object, direction, port->id, mix_id); return 0; } static int -impl_mix_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t mix_id) +impl_mix_remove_port(void *object, enum spa_direction direction, uint32_t mix_id) { - struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node); - pw_log_debug("client-node %p: remove port %d:%d.%d", node, direction, port->id, mix_id); + struct port *port = object; + pw_log_debug("client-node %p: remove port %d:%d.%d", object, direction, port->id, mix_id); return 0; } static int -impl_mix_port_use_buffers(struct spa_node *node, +impl_mix_port_use_buffers(void *object, enum spa_direction direction, uint32_t mix_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node); + struct port *port = object; struct impl *impl = port->impl; return do_port_use_buffers(impl, direction, port->id, mix_id, buffers, n_buffers); } static int -impl_mix_port_alloc_buffers(struct spa_node *node, +impl_mix_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -1443,11 +1453,11 @@ impl_mix_port_alloc_buffers(struct spa_node *node, return -ENOTSUP; } -static int impl_mix_port_set_io(struct spa_node *node, +static int impl_mix_port_set_io(void *object, enum spa_direction direction, uint32_t mix_id, uint32_t id, void *data, size_t size) { - struct port *p = SPA_CONTAINER_OF(node, struct port, mix_node); + struct port *p = object; struct pw_port *port = p->port; struct impl *impl = port->owner_data; struct pw_port_mix *mix; @@ -1469,20 +1479,19 @@ static int impl_mix_port_set_io(struct spa_node *node, } static int -impl_mix_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +impl_mix_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct port *p = SPA_CONTAINER_OF(node, struct port, mix_node); + struct port *p = object; return impl_node_port_reuse_buffer(&p->node->node, p->id, buffer_id); } -static int impl_mix_process(struct spa_node *data) +static int impl_mix_process(void *object) { return SPA_STATUS_HAVE_BUFFER; } -static const struct spa_node impl_port_mix = { - SPA_VERSION_NODE, - NULL, +static const struct spa_node_methods impl_port_mix = { + SPA_VERSION_NODE_METHODS, .port_enum_params = impl_mix_port_enum_params, .port_set_param = impl_mix_port_set_param, .add_port = impl_mix_add_port, @@ -1508,7 +1517,10 @@ static void node_port_init(void *data, struct pw_port *port) p->direction = port->direction; p->id = port->port_id; p->impl = impl; - p->mix_node = impl_port_mix; + p->mix_node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_port_mix, p); mix_init(&p->mix[MAX_MIX], p, SPA_ID_INVALID); if (p->direction == SPA_DIRECTION_INPUT) { @@ -1526,7 +1538,7 @@ static void node_port_added(void *data, struct pw_port *port) struct impl *impl = data; struct port *p = pw_port_get_user_data(port); - pw_port_set_mix(port, &p->mix_node, + pw_port_set_mix(port, (struct spa_node *)&p->mix_node, PW_PORT_MIX_FLAG_MULTI | PW_PORT_MIX_FLAG_MIX_ONLY); @@ -1613,7 +1625,7 @@ static int process_node(void *data) { struct impl *impl = data; pw_log_trace_fp("client-node %p: process", impl); - return spa_node_process(&impl->node.node); + return spa_node_process((struct spa_node*)&impl->node.node); } /** Create a new client node @@ -1670,7 +1682,7 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource, name, PW_SPA_NODE_FLAG_ASYNC | (do_register ? 0 : PW_SPA_NODE_FLAG_NO_REGISTER), - &impl->node.node, + (struct spa_node *)&impl->node.node, NULL, properties, 0); if (this->node == NULL) diff --git a/src/modules/module-client-node/client-stream.c b/src/modules/module-client-node/client-stream.c index 23fa3a06b..8516517b5 100644 --- a/src/modules/module-client-node/client-stream.c +++ b/src/modules/module-client-node/client-stream.c @@ -116,11 +116,11 @@ struct impl { /** \endcond */ -static int impl_node_enum_params(struct spa_node *node, int seq, +static int impl_node_enum_params(void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct node *this; + struct node *this = object; struct impl *impl; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -129,10 +129,9 @@ static int impl_node_enum_params(struct spa_node *node, int seq, uint32_t count = 0; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; result.id = id; @@ -224,14 +223,13 @@ static void emit_node_info(struct node *this, bool full) } } -static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, +static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { int res = 0; - struct node *this; + struct node *this = object; struct impl *impl; - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; switch (id) { @@ -263,15 +261,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return res; } -static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) { - struct node *this; + struct node *this = object; struct impl *impl; int res = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; if (impl->adapter) @@ -283,15 +280,14 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return res; } -static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_node_send_command(void *object, const struct spa_command *command) { - struct node *this; + struct node *this = object; struct impl *impl; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; switch (SPA_NODE_COMMAND_ID(command)) { @@ -343,19 +339,18 @@ static const struct spa_node_events adapter_node_events = { .result = adapter_result, }; -static int impl_node_add_listener(struct spa_node *node, +static int impl_node_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct node *this; + struct node *this = object; struct impl *impl; struct spa_hook l; struct spa_hook_list save; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; pw_log_debug("%p: add listener %p", this, listener); @@ -375,15 +370,14 @@ static int impl_node_add_listener(struct spa_node *node, } static int -impl_node_set_callbacks(struct spa_node *node, +impl_node_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct node *this; + struct node *this = object; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); @@ -391,30 +385,28 @@ impl_node_set_callbacks(struct spa_node *node, } static int -impl_node_sync(struct spa_node *node, int seq) +impl_node_sync(void *object, int seq) { - struct node *this; + struct node *this = object; struct impl *impl; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; return spa_node_sync(impl->cnode, seq); } static int -impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props) { - struct node *this; + struct node *this = object; struct impl *impl; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; if (direction != impl->direction) @@ -427,14 +419,13 @@ impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t } static int -impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) +impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) { - struct node *this; + struct node *this = object; struct impl *impl; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; if (direction != this->impl->direction) @@ -444,18 +435,17 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3 } static int -impl_node_port_enum_params(struct spa_node *node, int seq, +impl_node_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct node *this; + struct node *this = object; struct impl *impl; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(num != 0, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; if (direction != impl->direction) @@ -698,18 +688,17 @@ static int negotiate_buffers(struct impl *impl) } static int -impl_node_port_set_param(struct spa_node *node, +impl_node_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct node *this; + struct node *this = object; struct impl *impl; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; if (direction != impl->direction) @@ -737,19 +726,18 @@ impl_node_port_set_param(struct spa_node *node, } static int -impl_node_port_set_io(struct spa_node *node, +impl_node_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct node *this; + struct node *this = object; struct impl *impl; int res = 0; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; spa_log_debug(this->log, "set io %d %d %d %d", port_id, id, direction, impl->direction); @@ -769,19 +757,18 @@ impl_node_port_set_io(struct spa_node *node, } static int -impl_node_port_use_buffers(struct spa_node *node, +impl_node_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct node *this; + struct node *this = object; struct impl *impl; int res; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; if (direction != impl->direction) @@ -802,7 +789,7 @@ impl_node_port_use_buffers(struct spa_node *node, } static int -impl_node_port_alloc_buffers(struct spa_node *node, +impl_node_port_alloc_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_pod **params, @@ -810,12 +797,11 @@ impl_node_port_alloc_buffers(struct spa_node *node, struct spa_buffer **buffers, uint32_t *n_buffers) { - struct node *this; + struct node *this = object; struct impl *impl; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; if (direction != impl->direction) @@ -826,22 +812,21 @@ impl_node_port_alloc_buffers(struct spa_node *node, } static int -impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct node *this; + struct node *this = object; struct impl *impl; - spa_return_val_if_fail(node != NULL, -EINVAL); + spa_return_val_if_fail(this != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct node, node); impl = this->impl; return spa_node_port_reuse_buffer(impl->adapter, port_id, buffer_id); } -static int impl_node_process(struct spa_node *node) +static int impl_node_process(void *object) { - struct node *this = SPA_CONTAINER_OF(node, struct node, node); + struct node *this = object; struct impl *impl = this->impl; struct spa_io_position *q = impl->this.node->driver_node->rt.position; int status, trigger; @@ -890,8 +875,8 @@ static int impl_node_process(struct spa_node *node) return status; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_node_add_listener, .set_callbacks = impl_node_set_callbacks, .sync = impl_node_sync, @@ -922,7 +907,10 @@ node_init(struct node *this, if (support[i].type == SPA_TYPE_INTERFACE_Log) this->log = support[i].data; } - this->node = impl_node; + this->node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl_node, this); spa_hook_list_init(&this->hooks); this->info_all = SPA_NODE_CHANGE_MASK_PARAMS; @@ -1301,7 +1289,7 @@ struct pw_client_stream *pw_client_stream_new(struct pw_resource *resource, name, PW_SPA_NODE_FLAG_ASYNC | PW_SPA_NODE_FLAG_ACTIVATE, - &impl->node.node, + (struct spa_node *)&impl->node.node, NULL, properties, 0); if (this->node == NULL) diff --git a/src/modules/module-client-node/protocol-native.c b/src/modules/module-client-node/protocol-native.c index 81f238c65..8e55b1188 100644 --- a/src/modules/module-client-node/protocol-native.c +++ b/src/modules/module-client-node/protocol-native.c @@ -47,11 +47,29 @@ static void push_dict(struct spa_pod_builder *b, const struct spa_dict *dict) spa_pod_builder_pop(b, &f); } -static int -client_node_marshal_get_node(void *object, uint32_t version, uint32_t new_id) +static int client_node_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_client_node_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + +static struct pw_node_proxy * +client_node_marshal_get_node(void *object, uint32_t version, size_t user_data_size) { struct pw_proxy *proxy = object; struct spa_pod_builder *b; + struct pw_proxy *res; + uint32_t new_id; + + res = pw_proxy_new(object, PW_TYPE_INTERFACE_Node, user_data_size); + if (res == NULL) + return NULL; + + new_id = pw_proxy_get_id(res); b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_GET_NODE, NULL); @@ -59,7 +77,9 @@ client_node_marshal_get_node(void *object, uint32_t version, uint32_t new_id) SPA_POD_Int(version), SPA_POD_Int(new_id)); - return pw_protocol_native_end_proxy(proxy, b); + pw_protocol_native_end_proxy(proxy, b); + + return (struct pw_node_proxy *) res; } static int @@ -1000,50 +1020,56 @@ static int client_node_demarshal_event_method(void *object, const struct pw_prot static const struct pw_client_node_proxy_methods pw_protocol_native_client_node_method_marshal = { PW_VERSION_CLIENT_NODE_PROXY_METHODS, - &client_node_marshal_get_node, - &client_node_marshal_update, - &client_node_marshal_port_update, - &client_node_marshal_set_active, - &client_node_marshal_event_method + .add_listener = &client_node_marshal_add_listener, + .get_node = &client_node_marshal_get_node, + .update = &client_node_marshal_update, + .port_update = &client_node_marshal_port_update, + .set_active = &client_node_marshal_set_active, + .event = &client_node_marshal_event_method }; -static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_method_demarshal[] = { - { &client_node_demarshal_get_node, 0 }, - { &client_node_demarshal_update, 0 }, - { &client_node_demarshal_port_update, 0 }, - { &client_node_demarshal_set_active, 0 }, - { &client_node_demarshal_event_method, 0 } +static const struct pw_protocol_native_demarshal +pw_protocol_native_client_node_method_demarshal[PW_CLIENT_NODE_PROXY_METHOD_NUM] = +{ + [PW_CLIENT_NODE_PROXY_METHOD_ADD_LISTENER] = { NULL, 0 }, + [PW_CLIENT_NODE_PROXY_METHOD_GET_NODE] = { &client_node_demarshal_get_node, 0 }, + [PW_CLIENT_NODE_PROXY_METHOD_UPDATE] = { &client_node_demarshal_update, 0 }, + [PW_CLIENT_NODE_PROXY_METHOD_PORT_UPDATE] = { &client_node_demarshal_port_update, 0 }, + [PW_CLIENT_NODE_PROXY_METHOD_SET_ACTIVE] = { &client_node_demarshal_set_active, 0 }, + [PW_CLIENT_NODE_PROXY_METHOD_EVENT] = { &client_node_demarshal_event_method, 0 } }; static const struct pw_client_node_proxy_events pw_protocol_native_client_node_event_marshal = { PW_VERSION_CLIENT_NODE_PROXY_EVENTS, - &client_node_marshal_add_mem, - &client_node_marshal_transport, - &client_node_marshal_set_param, - &client_node_marshal_set_io, - &client_node_marshal_event_event, - &client_node_marshal_command, - &client_node_marshal_add_port, - &client_node_marshal_remove_port, - &client_node_marshal_port_set_param, - &client_node_marshal_port_use_buffers, - &client_node_marshal_port_set_io, - &client_node_marshal_set_activation, + .add_mem = &client_node_marshal_add_mem, + .transport = &client_node_marshal_transport, + .set_param = &client_node_marshal_set_param, + .set_io = &client_node_marshal_set_io, + .event = &client_node_marshal_event_event, + .command = &client_node_marshal_command, + .add_port = &client_node_marshal_add_port, + .remove_port = &client_node_marshal_remove_port, + .port_set_param = &client_node_marshal_port_set_param, + .port_use_buffers = &client_node_marshal_port_use_buffers, + .port_set_io = &client_node_marshal_port_set_io, + .set_activation = &client_node_marshal_set_activation, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_event_demarshal[] = { - { &client_node_demarshal_add_mem, 0 }, - { &client_node_demarshal_transport, 0 }, - { &client_node_demarshal_set_param, 0 }, - { &client_node_demarshal_set_io, 0 }, - { &client_node_demarshal_event_event, 0 }, - { &client_node_demarshal_command, 0 }, - { &client_node_demarshal_add_port, 0 }, - { &client_node_demarshal_remove_port, 0 }, - { &client_node_demarshal_port_set_param, 0 }, - { &client_node_demarshal_port_use_buffers, 0 }, - { &client_node_demarshal_port_set_io, 0 }, - { &client_node_demarshal_set_activation, 0 } +static const struct pw_protocol_native_demarshal +pw_protocol_native_client_node_event_demarshal[PW_CLIENT_NODE_PROXY_EVENT_NUM] = +{ + [PW_CLIENT_NODE_PROXY_EVENT_ADD_MEM] = { &client_node_demarshal_add_mem, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_TRANSPORT] = { &client_node_demarshal_transport, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_SET_PARAM] = { &client_node_demarshal_set_param, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_SET_IO] = { &client_node_demarshal_set_io, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_EVENT] = { &client_node_demarshal_event_event, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_COMMAND] = { &client_node_demarshal_command, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_ADD_PORT] = { &client_node_demarshal_add_port, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_REMOVE_PORT] = { &client_node_demarshal_remove_port, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_PORT_SET_PARAM] = { &client_node_demarshal_port_set_param, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_PORT_USE_BUFFERS] = { &client_node_demarshal_port_use_buffers, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_PORT_SET_IO] = { &client_node_demarshal_port_set_io, 0 }, + [PW_CLIENT_NODE_PROXY_EVENT_SET_ACTIVATION] = { &client_node_demarshal_set_activation, 0 } }; static const struct pw_protocol_marshal pw_protocol_native_client_node_marshal = { diff --git a/src/modules/module-client-node/remote-node.c b/src/modules/module-client-node/remote-node.c index 63834f8d1..85906f199 100644 --- a/src/modules/module-client-node/remote-node.c +++ b/src/modules/module-client-node/remote-node.c @@ -1218,7 +1218,7 @@ static struct pw_proxy *node_export(struct pw_remote *remote, void *object, bool do_node_init(proxy); data->proxy = (struct pw_proxy*) pw_client_node_proxy_get_node(data->node_proxy, - PW_VERSION_NODE, 0); + PW_VERSION_NODE_PROXY, 0); return data->proxy; } diff --git a/src/modules/module-link-factory.c b/src/modules/module-link-factory.c index 1498fc8ca..4992e2324 100644 --- a/src/modules/module-link-factory.c +++ b/src/modules/module-link-factory.c @@ -229,7 +229,7 @@ static void *create_object(void *_data, ld->global = pw_link_get_global(link); pw_global_add_listener(ld->global, &ld->global_listener, &global_events, ld); - res = pw_global_bind(ld->global, client, PW_PERM_RWX, PW_VERSION_LINK, new_id); + res = pw_global_bind(ld->global, client, PW_PERM_RWX, PW_VERSION_LINK_PROXY, new_id); if (res < 0) goto no_bind; @@ -312,7 +312,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie factory = pw_factory_new(core, "link-factory", PW_TYPE_INTERFACE_Link, - PW_VERSION_LINK, + PW_VERSION_LINK_PROXY, NULL, sizeof(*data)); if (factory == NULL) diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 411bad6c2..e23665b82 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -299,7 +299,7 @@ static struct pw_client *client_new(struct server *s, int fd) pw_client_add_listener(client, &this->client_listener, &client_events, this); if (pw_global_bind(pw_core_get_global(core), client, - PW_PERM_RWX, PW_VERSION_CORE, 0) < 0) + PW_PERM_RWX, PW_VERSION_CORE_PROXY, 0) < 0) goto cleanup_client; props = pw_properties_copy(pw_client_get_properties(client)); @@ -307,7 +307,7 @@ static struct pw_client *client_new(struct server *s, int fd) goto cleanup_client; if (pw_global_bind(pw_client_get_global(client), client, - PW_PERM_RWX, PW_VERSION_CLIENT, 1) < 0) + PW_PERM_RWX, PW_VERSION_CLIENT_PROXY, 1) < 0) goto cleanup_client; return client; diff --git a/src/modules/module-protocol-native/protocol-native.c b/src/modules/module-protocol-native/protocol-native.c index 59b4b3a35..da618d9dc 100644 --- a/src/modules/module-protocol-native/protocol-native.c +++ b/src/modules/module-protocol-native/protocol-native.c @@ -32,6 +32,16 @@ #include "connection.h" +static int core_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_core_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + static int core_method_marshal_hello(void *object, uint32_t version) { struct pw_proxy *proxy = object; @@ -90,10 +100,19 @@ static int core_method_marshal_error(void *object, uint32_t id, int seq, int res return pw_protocol_native_end_proxy(proxy, b); } -static int core_method_marshal_get_registry(void *object, uint32_t version, uint32_t new_id) +static struct pw_registry_proxy * core_method_marshal_get_registry(void *object, + uint32_t version, size_t user_data_size) { struct pw_proxy *proxy = object; struct spa_pod_builder *b; + struct pw_proxy *res; + uint32_t new_id; + + res = pw_proxy_new(object, PW_TYPE_INTERFACE_Registry, user_data_size); + if (res == NULL) + return NULL; + + new_id = pw_proxy_get_id(res); b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_GET_REGISTRY, NULL); @@ -101,7 +120,9 @@ static int core_method_marshal_get_registry(void *object, uint32_t version, uint SPA_POD_Int(version), SPA_POD_Int(new_id)); - return pw_protocol_native_end_proxy(proxy, b); + pw_protocol_native_end_proxy(proxy, b); + + return (struct pw_registry_proxy *) res; } static void push_dict(struct spa_pod_builder *b, const struct spa_dict *dict) @@ -135,15 +156,23 @@ static void push_params(struct spa_pod_builder *b, uint32_t n_params, spa_pod_builder_pop(b, &f); } -static int +static void * core_method_marshal_create_object(void *object, const char *factory_name, uint32_t type, uint32_t version, - const struct spa_dict *props, uint32_t new_id) + const struct spa_dict *props, size_t user_data_size) { struct pw_proxy *proxy = object; struct spa_pod_builder *b; struct spa_pod_frame f; + struct pw_proxy *res; + uint32_t new_id; + + res = pw_proxy_new(object, type, user_data_size); + if (res == NULL) + return NULL; + + new_id = pw_proxy_get_id(res); b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_CREATE_OBJECT, NULL); @@ -157,14 +186,17 @@ core_method_marshal_create_object(void *object, spa_pod_builder_int(b, new_id); spa_pod_builder_pop(b, &f); - return pw_protocol_native_end_proxy(proxy, b); + pw_protocol_native_end_proxy(proxy, b); + + return (void *)res; } static int -core_method_marshal_destroy(void *object, uint32_t id) +core_method_marshal_destroy(void *object, void *p) { struct pw_proxy *proxy = object; struct spa_pod_builder *b; + uint32_t id = pw_proxy_get_id(p); b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_DESTROY, NULL); @@ -480,6 +512,8 @@ static int core_method_demarshal_create_object(void *object, const struct pw_pro static int core_method_demarshal_destroy(void *object, const struct pw_protocol_native_message *msg) { struct pw_resource *resource = object; + struct pw_client *client = pw_resource_get_client(resource); + struct pw_resource *r; struct spa_pod_parser prs; uint32_t id; @@ -488,7 +522,27 @@ static int core_method_demarshal_destroy(void *object, const struct pw_protocol_ SPA_POD_Int(&id)) < 0) return -EINVAL; - return pw_resource_do(resource, struct pw_core_proxy_methods, destroy, 0, id); + pw_log_debug("client %p: destroy resource %d", client, id); + + if ((r = pw_client_find_resource(client, id)) == NULL) + goto no_resource; + + return pw_resource_do(resource, struct pw_core_proxy_methods, destroy, 0, r); + + no_resource: + pw_log_error("client %p: can't find resouce %d", client, id); + pw_resource_error(resource, -EINVAL, "unknown resource %d", id); + return -EINVAL; +} + +static int registry_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_registry_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; } static void registry_marshal_global(void *object, uint32_t id, uint32_t parent_id, uint32_t permissions, @@ -557,6 +611,16 @@ static int registry_demarshal_destroy(void *object, const struct pw_protocol_nat return pw_resource_do(resource, struct pw_registry_proxy_methods, destroy, 0, id); } +static int module_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_module_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + static void module_marshal_info(void *object, const struct pw_module_info *info) { struct pw_resource *resource = object; @@ -614,6 +678,16 @@ static int module_demarshal_info(void *object, const struct pw_protocol_native_m return pw_proxy_notify(proxy, struct pw_module_proxy_events, info, 0, &info); } +static int device_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_device_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + static void device_marshal_info(void *object, const struct pw_device_info *info) { struct pw_resource *resource = object; @@ -795,6 +869,16 @@ static int device_demarshal_set_param(void *object, const struct pw_protocol_nat return pw_resource_do(resource, struct pw_device_proxy_methods, set_param, 0, id, flags, param); } +static int factory_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_factory_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + static void factory_marshal_info(void *object, const struct pw_factory_info *info) { struct pw_resource *resource = object; @@ -852,6 +936,16 @@ static int factory_demarshal_info(void *object, const struct pw_protocol_native_ return pw_proxy_notify(proxy, struct pw_factory_proxy_events, info, 0, &info); } +static int node_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_node_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + static void node_marshal_info(void *object, const struct pw_node_info *info) { struct pw_resource *resource = object; @@ -1102,6 +1196,16 @@ static int node_demarshal_send_command(void *object, const struct pw_protocol_na return pw_resource_do(resource, struct pw_node_proxy_methods, send_command, 0, command); } +static int port_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_port_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + static void port_marshal_info(void *object, const struct pw_port_info *info) { struct pw_resource *resource = object; @@ -1282,6 +1386,16 @@ static int port_demarshal_enum_params(void *object, const struct pw_protocol_nat seq, id, index, num, filter); } +static int client_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_client_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + static void client_marshal_info(void *object, const struct pw_client_info *info) { struct pw_resource *resource = object; @@ -1540,6 +1654,16 @@ static int client_demarshal_update_permissions(void *object, const struct pw_pro n_permissions, permissions); } +static int link_method_marshal_add_listener(void *object, + struct spa_hook *listener, + const struct pw_link_proxy_events *events, + void *data) +{ + struct pw_proxy *proxy = object; + pw_proxy_add_proxy_listener(proxy, listener, events, data); + return 0; +} + static void link_marshal_info(void *object, const struct pw_link_info *info) { struct pw_resource *resource = object; @@ -1655,11 +1779,19 @@ static int registry_demarshal_global_remove(void *object, const struct pw_protoc return pw_proxy_notify(proxy, struct pw_registry_proxy_events, global_remove, 0, id); } -static int registry_marshal_bind(void *object, uint32_t id, - uint32_t type, uint32_t version, uint32_t new_id) +static void * registry_marshal_bind(void *object, uint32_t id, + uint32_t type, uint32_t version, size_t user_data_size) { struct pw_proxy *proxy = object; struct spa_pod_builder *b; + struct pw_proxy *res; + uint32_t new_id; + + res = pw_proxy_new(object, type, user_data_size); + if (res == NULL) + return NULL; + + new_id = pw_proxy_get_id(res); b = pw_protocol_native_begin_proxy(proxy, PW_REGISTRY_PROXY_METHOD_BIND, NULL); @@ -1669,7 +1801,9 @@ static int registry_marshal_bind(void *object, uint32_t id, SPA_POD_Int(version), SPA_POD_Int(new_id)); - return pw_protocol_native_end_proxy(proxy, b); + pw_protocol_native_end_proxy(proxy, b); + + return (void *) res; } static int registry_marshal_destroy(void *object, uint32_t id) @@ -1685,45 +1819,49 @@ static int registry_marshal_destroy(void *object, uint32_t id) static const struct pw_core_proxy_methods pw_protocol_native_core_method_marshal = { PW_VERSION_CORE_PROXY_METHODS, - &core_method_marshal_hello, - &core_method_marshal_sync, - &core_method_marshal_pong, - &core_method_marshal_error, - &core_method_marshal_get_registry, - &core_method_marshal_create_object, - &core_method_marshal_destroy, + .add_listener = &core_method_marshal_add_listener, + .hello = &core_method_marshal_hello, + .sync = &core_method_marshal_sync, + .pong = &core_method_marshal_pong, + .error = &core_method_marshal_error, + .get_registry = &core_method_marshal_get_registry, + .create_object = &core_method_marshal_create_object, + .destroy = &core_method_marshal_destroy, }; static const struct pw_protocol_native_demarshal pw_protocol_native_core_method_demarshal[PW_CORE_PROXY_METHOD_NUM] = { - { &core_method_demarshal_hello, 0, }, - { &core_method_demarshal_sync, 0, }, - { &core_method_demarshal_pong, 0, }, - { &core_method_demarshal_error, 0, }, - { &core_method_demarshal_get_registry, 0, }, - { &core_method_demarshal_create_object, 0, }, - { &core_method_demarshal_destroy, 0, } + [PW_CORE_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, + [PW_CORE_PROXY_METHOD_HELLO] = { &core_method_demarshal_hello, 0, }, + [PW_CORE_PROXY_METHOD_SYNC] = { &core_method_demarshal_sync, 0, }, + [PW_CORE_PROXY_METHOD_PONG] = { &core_method_demarshal_pong, 0, }, + [PW_CORE_PROXY_METHOD_ERROR] = { &core_method_demarshal_error, 0, }, + [PW_CORE_PROXY_METHOD_GET_REGISTRY] = { &core_method_demarshal_get_registry, 0, }, + [PW_CORE_PROXY_METHOD_CREATE_OBJECT] = { &core_method_demarshal_create_object, 0, }, + [PW_CORE_PROXY_METHOD_DESTROY] = { &core_method_demarshal_destroy, 0, } }; static const struct pw_core_proxy_events pw_protocol_native_core_event_marshal = { PW_VERSION_CORE_PROXY_EVENTS, - &core_event_marshal_info, - &core_event_marshal_done, - &core_event_marshal_ping, - &core_event_marshal_error, - &core_event_marshal_remove_id, + .info = &core_event_marshal_info, + .done = &core_event_marshal_done, + .ping = &core_event_marshal_ping, + .error = &core_event_marshal_error, + .remove_id = &core_event_marshal_remove_id, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_core_event_demarshal[PW_CORE_PROXY_EVENT_NUM] = { - { &core_event_demarshal_info, 0, }, - { &core_event_demarshal_done, 0, }, - { &core_event_demarshal_ping, 0, }, - { &core_event_demarshal_error, 0, }, - { &core_event_demarshal_remove_id, 0, }, +static const struct pw_protocol_native_demarshal +pw_protocol_native_core_event_demarshal[PW_CORE_PROXY_EVENT_NUM] = +{ + [PW_CORE_PROXY_EVENT_INFO] = { &core_event_demarshal_info, 0, }, + [PW_CORE_PROXY_EVENT_DONE] = { &core_event_demarshal_done, 0, }, + [PW_CORE_PROXY_EVENT_PING] = { &core_event_demarshal_ping, 0, }, + [PW_CORE_PROXY_EVENT_ERROR] = { &core_event_demarshal_error, 0, }, + [PW_CORE_PROXY_EVENT_REMOVE_ID] = { &core_event_demarshal_remove_id, 0, }, }; static const struct pw_protocol_marshal pw_protocol_native_core_marshal = { PW_TYPE_INTERFACE_Core, - PW_VERSION_CORE, + PW_VERSION_CORE_PROXY, PW_CORE_PROXY_METHOD_NUM, PW_CORE_PROXY_EVENT_NUM, &pw_protocol_native_core_method_marshal, @@ -1734,29 +1872,35 @@ static const struct pw_protocol_marshal pw_protocol_native_core_marshal = { static const struct pw_registry_proxy_methods pw_protocol_native_registry_method_marshal = { PW_VERSION_REGISTRY_PROXY_METHODS, - ®istry_marshal_bind, - ®istry_marshal_destroy, + .add_listener = ®istry_method_marshal_add_listener, + .bind = ®istry_marshal_bind, + .destroy = ®istry_marshal_destroy, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_registry_method_demarshal[] = { - { ®istry_demarshal_bind, 0, }, - { ®istry_demarshal_destroy, 0, }, +static const struct pw_protocol_native_demarshal +pw_protocol_native_registry_method_demarshal[PW_REGISTRY_PROXY_METHOD_NUM] = +{ + [PW_REGISTRY_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, + [PW_REGISTRY_PROXY_METHOD_BIND] = { ®istry_demarshal_bind, 0, }, + [PW_REGISTRY_PROXY_METHOD_DESTROY] = { ®istry_demarshal_destroy, 0, }, }; static const struct pw_registry_proxy_events pw_protocol_native_registry_event_marshal = { PW_VERSION_REGISTRY_PROXY_EVENTS, - ®istry_marshal_global, - ®istry_marshal_global_remove, + .global = ®istry_marshal_global, + .global_remove = ®istry_marshal_global_remove, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_registry_event_demarshal[] = { - { ®istry_demarshal_global, 0, }, - { ®istry_demarshal_global_remove, 0, } +static const struct pw_protocol_native_demarshal +pw_protocol_native_registry_event_demarshal[PW_REGISTRY_PROXY_EVENT_NUM] = +{ + [PW_REGISTRY_PROXY_EVENT_GLOBAL] = { ®istry_demarshal_global, 0, }, + [PW_REGISTRY_PROXY_EVENT_GLOBAL_REMOVE] = { ®istry_demarshal_global_remove, 0, } }; const struct pw_protocol_marshal pw_protocol_native_registry_marshal = { PW_TYPE_INTERFACE_Registry, - PW_VERSION_REGISTRY, + PW_VERSION_REGISTRY_PROXY, PW_REGISTRY_PROXY_METHOD_NUM, PW_REGISTRY_PROXY_EVENT_NUM, &pw_protocol_native_registry_method_marshal, @@ -1767,67 +1911,100 @@ const struct pw_protocol_marshal pw_protocol_native_registry_marshal = { static const struct pw_module_proxy_events pw_protocol_native_module_event_marshal = { PW_VERSION_MODULE_PROXY_EVENTS, - &module_marshal_info, + .info = &module_marshal_info, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_module_event_demarshal[] = { - { &module_demarshal_info, 0, }, +static const struct pw_protocol_native_demarshal +pw_protocol_native_module_event_demarshal[PW_MODULE_PROXY_EVENT_NUM] = +{ + [PW_MODULE_PROXY_EVENT_INFO] = { &module_demarshal_info, 0, }, +}; + + +static const struct pw_module_proxy_methods pw_protocol_native_module_method_marshal = { + PW_VERSION_MODULE_PROXY_METHODS, + .add_listener = &module_method_marshal_add_listener, +}; + +static const struct pw_protocol_native_demarshal +pw_protocol_native_module_method_demarshal[PW_MODULE_PROXY_METHOD_NUM] = +{ + [PW_MODULE_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, }; const struct pw_protocol_marshal pw_protocol_native_module_marshal = { PW_TYPE_INTERFACE_Module, - PW_VERSION_MODULE, - 0, + PW_VERSION_MODULE_PROXY, + PW_MODULE_PROXY_METHOD_NUM, PW_MODULE_PROXY_EVENT_NUM, - NULL, NULL, + &pw_protocol_native_module_method_marshal, + pw_protocol_native_module_method_demarshal, &pw_protocol_native_module_event_marshal, pw_protocol_native_module_event_demarshal, }; static const struct pw_factory_proxy_events pw_protocol_native_factory_event_marshal = { PW_VERSION_FACTORY_PROXY_EVENTS, - &factory_marshal_info, + .info = &factory_marshal_info, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_factory_event_demarshal[] = { - { &factory_demarshal_info, 0, }, +static const struct pw_protocol_native_demarshal +pw_protocol_native_factory_event_demarshal[PW_FACTORY_PROXY_EVENT_NUM] = +{ + [PW_FACTORY_PROXY_EVENT_INFO] = { &factory_demarshal_info, 0, }, +}; + +static const struct pw_factory_proxy_methods pw_protocol_native_factory_method_marshal = { + PW_VERSION_FACTORY_PROXY_METHODS, + .add_listener = &factory_method_marshal_add_listener, +}; + +static const struct pw_protocol_native_demarshal +pw_protocol_native_factory_method_demarshal[PW_FACTORY_PROXY_METHOD_NUM] = +{ + [PW_FACTORY_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, }; const struct pw_protocol_marshal pw_protocol_native_factory_marshal = { PW_TYPE_INTERFACE_Factory, - PW_VERSION_FACTORY, - 0, + PW_VERSION_FACTORY_PROXY, + PW_FACTORY_PROXY_METHOD_NUM, PW_FACTORY_PROXY_EVENT_NUM, - NULL, NULL, + &pw_protocol_native_factory_method_marshal, + pw_protocol_native_factory_method_demarshal, &pw_protocol_native_factory_event_marshal, pw_protocol_native_factory_event_demarshal, }; static const struct pw_device_proxy_methods pw_protocol_native_device_method_marshal = { PW_VERSION_DEVICE_PROXY_METHODS, - &device_marshal_enum_params, - &device_marshal_set_param, + .add_listener = &device_method_marshal_add_listener, + .enum_params = &device_marshal_enum_params, + .set_param = &device_marshal_set_param, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_device_method_demarshal[] = { - { &device_demarshal_enum_params, 0, }, - { &device_demarshal_set_param, PW_PERM_W, }, +static const struct pw_protocol_native_demarshal +pw_protocol_native_device_method_demarshal[PW_DEVICE_PROXY_METHOD_NUM] = { + [PW_DEVICE_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, + [PW_DEVICE_PROXY_METHOD_ENUM_PARAMS] = { &device_demarshal_enum_params, 0, }, + [PW_DEVICE_PROXY_METHOD_SET_PARAM] = { &device_demarshal_set_param, PW_PERM_W, }, }; static const struct pw_device_proxy_events pw_protocol_native_device_event_marshal = { PW_VERSION_DEVICE_PROXY_EVENTS, - &device_marshal_info, - &device_marshal_param, + .info = &device_marshal_info, + .param = &device_marshal_param, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_device_event_demarshal[] = { - { &device_demarshal_info, 0, }, - { &device_demarshal_param, 0, } +static const struct pw_protocol_native_demarshal +pw_protocol_native_device_event_demarshal[PW_DEVICE_PROXY_EVENT_NUM] = { + [PW_DEVICE_PROXY_EVENT_INFO] = { &device_demarshal_info, 0, }, + [PW_DEVICE_PROXY_EVENT_PARAM] = { &device_demarshal_param, 0, } }; static const struct pw_protocol_marshal pw_protocol_native_device_marshal = { PW_TYPE_INTERFACE_Device, - PW_VERSION_DEVICE, + PW_VERSION_DEVICE_PROXY, PW_DEVICE_PROXY_METHOD_NUM, PW_DEVICE_PROXY_EVENT_NUM, &pw_protocol_native_device_method_marshal, @@ -1838,33 +2015,38 @@ static const struct pw_protocol_marshal pw_protocol_native_device_marshal = { static const struct pw_node_proxy_methods pw_protocol_native_node_method_marshal = { PW_VERSION_NODE_PROXY_METHODS, - &node_marshal_subscribe_params, - &node_marshal_enum_params, - &node_marshal_set_param, - &node_marshal_send_command, + .add_listener = &node_method_marshal_add_listener, + .subscribe_params = &node_marshal_subscribe_params, + .enum_params = &node_marshal_enum_params, + .set_param = &node_marshal_set_param, + .send_command = &node_marshal_send_command, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_node_method_demarshal[] = { - { &node_demarshal_subscribe_params, 0, }, - { &node_demarshal_enum_params, 0, }, - { &node_demarshal_set_param, PW_PERM_W, }, - { &node_demarshal_send_command, PW_PERM_W, }, +static const struct pw_protocol_native_demarshal +pw_protocol_native_node_method_demarshal[PW_NODE_PROXY_METHOD_NUM] = +{ + [PW_NODE_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, + [PW_NODE_PROXY_METHOD_SUBSCRIBE_PARAMS] = { &node_demarshal_subscribe_params, 0, }, + [PW_NODE_PROXY_METHOD_ENUM_PARAMS] = { &node_demarshal_enum_params, 0, }, + [PW_NODE_PROXY_METHOD_SET_PARAM] = { &node_demarshal_set_param, PW_PERM_W, }, + [PW_NODE_PROXY_METHOD_SEND_COMMAND] = { &node_demarshal_send_command, PW_PERM_W, }, }; static const struct pw_node_proxy_events pw_protocol_native_node_event_marshal = { PW_VERSION_NODE_PROXY_EVENTS, - &node_marshal_info, - &node_marshal_param, + .info = &node_marshal_info, + .param = &node_marshal_param, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_node_event_demarshal[] = { - { &node_demarshal_info, 0, }, - { &node_demarshal_param, 0, } +static const struct pw_protocol_native_demarshal +pw_protocol_native_node_event_demarshal[PW_NODE_PROXY_EVENT_NUM] = { + [PW_NODE_PROXY_EVENT_INFO] = { &node_demarshal_info, 0, }, + [PW_NODE_PROXY_EVENT_PARAM] = { &node_demarshal_param, 0, } }; static const struct pw_protocol_marshal pw_protocol_native_node_marshal = { PW_TYPE_INTERFACE_Node, - PW_VERSION_NODE, + PW_VERSION_NODE_PROXY, PW_NODE_PROXY_METHOD_NUM, PW_NODE_PROXY_EVENT_NUM, &pw_protocol_native_node_method_marshal, @@ -1876,29 +2058,35 @@ static const struct pw_protocol_marshal pw_protocol_native_node_marshal = { static const struct pw_port_proxy_methods pw_protocol_native_port_method_marshal = { PW_VERSION_PORT_PROXY_METHODS, - &port_marshal_subscribe_params, - &port_marshal_enum_params, + .add_listener = &port_method_marshal_add_listener, + .subscribe_params = &port_marshal_subscribe_params, + .enum_params = &port_marshal_enum_params, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_port_method_demarshal[] = { - { &port_demarshal_subscribe_params, 0, }, - { &port_demarshal_enum_params, 0, }, +static const struct pw_protocol_native_demarshal +pw_protocol_native_port_method_demarshal[PW_PORT_PROXY_METHOD_NUM] = +{ + [PW_PORT_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, + [PW_PORT_PROXY_METHOD_SUBSCRIBE_PARAMS] = { &port_demarshal_subscribe_params, 0, }, + [PW_PORT_PROXY_METHOD_ENUM_PARAMS] = { &port_demarshal_enum_params, 0, }, }; static const struct pw_port_proxy_events pw_protocol_native_port_event_marshal = { PW_VERSION_PORT_PROXY_EVENTS, - &port_marshal_info, - &port_marshal_param, + .info = &port_marshal_info, + .param = &port_marshal_param, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_port_event_demarshal[] = { - { &port_demarshal_info, 0, }, - { &port_demarshal_param, 0, } +static const struct pw_protocol_native_demarshal +pw_protocol_native_port_event_demarshal[PW_PORT_PROXY_EVENT_NUM] = +{ + [PW_PORT_PROXY_EVENT_INFO] = { &port_demarshal_info, 0, }, + [PW_PORT_PROXY_EVENT_PARAM] = { &port_demarshal_param, 0, } }; static const struct pw_protocol_marshal pw_protocol_native_port_marshal = { PW_TYPE_INTERFACE_Port, - PW_VERSION_PORT, + PW_VERSION_PORT_PROXY, PW_PORT_PROXY_METHOD_NUM, PW_PORT_PROXY_EVENT_NUM, &pw_protocol_native_port_method_marshal, @@ -1909,33 +2097,39 @@ static const struct pw_protocol_marshal pw_protocol_native_port_marshal = { static const struct pw_client_proxy_methods pw_protocol_native_client_method_marshal = { PW_VERSION_CLIENT_PROXY_METHODS, - &client_marshal_error, - &client_marshal_update_properties, - &client_marshal_get_permissions, - &client_marshal_update_permissions, + .add_listener = &client_method_marshal_add_listener, + .error = &client_marshal_error, + .update_properties = &client_marshal_update_properties, + .get_permissions = &client_marshal_get_permissions, + .update_permissions = &client_marshal_update_permissions, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_client_method_demarshal[] = { - { &client_demarshal_error, PW_PERM_W, }, - { &client_demarshal_update_properties, PW_PERM_W, }, - { &client_demarshal_get_permissions, 0, }, - { &client_demarshal_update_permissions, PW_PERM_W, }, +static const struct pw_protocol_native_demarshal +pw_protocol_native_client_method_demarshal[PW_CLIENT_PROXY_METHOD_NUM] = +{ + [PW_CLIENT_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, + [PW_CLIENT_PROXY_METHOD_ERROR] = { &client_demarshal_error, PW_PERM_W, }, + [PW_CLIENT_PROXY_METHOD_UPDATE_PROPERTIES] = { &client_demarshal_update_properties, PW_PERM_W, }, + [PW_CLIENT_PROXY_METHOD_GET_PERMISSIONS] = { &client_demarshal_get_permissions, 0, }, + [PW_CLIENT_PROXY_METHOD_UPDATE_PERMISSIONS] = { &client_demarshal_update_permissions, PW_PERM_W, }, }; static const struct pw_client_proxy_events pw_protocol_native_client_event_marshal = { PW_VERSION_CLIENT_PROXY_EVENTS, - &client_marshal_info, - &client_marshal_permissions, + .info = &client_marshal_info, + .permissions = &client_marshal_permissions, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_client_event_demarshal[] = { - { &client_demarshal_info, 0, }, - { &client_demarshal_permissions, 0, } +static const struct pw_protocol_native_demarshal +pw_protocol_native_client_event_demarshal[PW_CLIENT_PROXY_EVENT_NUM] = +{ + [PW_CLIENT_PROXY_EVENT_INFO] = { &client_demarshal_info, 0, }, + [PW_CLIENT_PROXY_EVENT_PERMISSIONS] = { &client_demarshal_permissions, 0, } }; static const struct pw_protocol_marshal pw_protocol_native_client_marshal = { PW_TYPE_INTERFACE_Client, - PW_VERSION_CLIENT, + PW_VERSION_CLIENT_PROXY, PW_CLIENT_PROXY_METHOD_NUM, PW_CLIENT_PROXY_EVENT_NUM, &pw_protocol_native_client_method_marshal, @@ -1944,21 +2138,36 @@ static const struct pw_protocol_marshal pw_protocol_native_client_marshal = { pw_protocol_native_client_event_demarshal, }; -static const struct pw_link_proxy_events pw_protocol_native_link_event_marshal = { - PW_VERSION_LINK_PROXY_EVENTS, - &link_marshal_info, + +static const struct pw_link_proxy_methods pw_protocol_native_link_method_marshal = { + PW_VERSION_LINK_PROXY_METHODS, + .add_listener = &link_method_marshal_add_listener, }; -static const struct pw_protocol_native_demarshal pw_protocol_native_link_event_demarshal[] = { - { &link_demarshal_info, 0, } +static const struct pw_protocol_native_demarshal +pw_protocol_native_link_method_demarshal[PW_LINK_PROXY_METHOD_NUM] = +{ + [PW_LINK_PROXY_METHOD_ADD_LISTENER] = { NULL, 0, }, +}; + +static const struct pw_link_proxy_events pw_protocol_native_link_event_marshal = { + PW_VERSION_LINK_PROXY_EVENTS, + .info = &link_marshal_info, +}; + +static const struct pw_protocol_native_demarshal +pw_protocol_native_link_event_demarshal[PW_LINK_PROXY_EVENT_NUM] = +{ + [PW_LINK_PROXY_EVENT_INFO] = { &link_demarshal_info, 0, } }; static const struct pw_protocol_marshal pw_protocol_native_link_marshal = { PW_TYPE_INTERFACE_Link, - PW_VERSION_LINK, - 0, + PW_VERSION_LINK_PROXY, + PW_LINK_PROXY_METHOD_NUM, PW_LINK_PROXY_EVENT_NUM, - NULL, NULL, + &pw_protocol_native_link_method_marshal, + pw_protocol_native_link_method_demarshal, &pw_protocol_native_link_event_marshal, pw_protocol_native_link_event_demarshal, }; diff --git a/src/modules/spa/module-node-factory.c b/src/modules/spa/module-node-factory.c index 900a9e49b..d4b98d14a 100644 --- a/src/modules/spa/module-node-factory.c +++ b/src/modules/spa/module-node-factory.c @@ -180,7 +180,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie factory = pw_factory_new(core, "spa-node-factory", PW_TYPE_INTERFACE_Node, - PW_VERSION_NODE, + PW_VERSION_NODE_PROXY, NULL, sizeof(*data)); if (factory == NULL) diff --git a/src/pipewire/client.c b/src/pipewire/client.c index ae17d14bc..f9fb12072 100644 --- a/src/pipewire/client.c +++ b/src/pipewire/client.c @@ -38,6 +38,10 @@ struct impl { struct pw_array permissions; }; +#define pw_client_resource(r,m,v,...) pw_resource_notify(r,struct pw_client_proxy_events,m,v,__VA_ARGS__) +#define pw_client_resource_info(r,...) pw_client_resource(r,info,0,__VA_ARGS__) +#define pw_client_resource_permissions(r,...) pw_client_resource(r,permissions,0,__VA_ARGS__) + struct resource_data { struct spa_hook resource_listener; struct pw_client *client; @@ -320,7 +324,8 @@ int pw_client_register(struct pw_client *client, client->registered = true; client->global = pw_global_new(core, - PW_TYPE_INTERFACE_Client, PW_VERSION_CLIENT, + PW_TYPE_INTERFACE_Client, + PW_VERSION_CLIENT_PROXY, properties, global_bind, client); diff --git a/src/pipewire/control.c b/src/pipewire/control.c index 6235ca399..e76250ac6 100644 --- a/src/pipewire/control.c +++ b/src/pipewire/control.c @@ -145,7 +145,7 @@ static int port_set_io(struct pw_port *port, uint32_t mix, uint32_t id, void *da uint32_t p; int res; - if (port->mix && port->mix->port_set_io) { + if (port->mix) { n = port->mix; p = mix; } else { diff --git a/src/pipewire/core.c b/src/pipewire/core.c index 0d4b71590..cdf99c189 100644 --- a/src/pipewire/core.c +++ b/src/pipewire/core.c @@ -57,15 +57,14 @@ struct resource_data { }; /** \endcond */ - -static int registry_bind(void *object, uint32_t id, - uint32_t type, uint32_t version, uint32_t new_id) +static void * registry_bind(void *object, uint32_t id, + uint32_t type, uint32_t version, size_t user_data_size) { struct pw_resource *resource = object; struct pw_client *client = resource->client; struct pw_core *core = resource->core; struct pw_global *global; - uint32_t permissions; + uint32_t permissions, new_id = user_data_size; if ((global = pw_core_find_global(core, id)) == NULL) goto no_id; @@ -84,7 +83,7 @@ static int registry_bind(void *object, uint32_t id, if (pw_global_bind(global, client, permissions, version, new_id) < 0) goto exit; - return 0; + return NULL; no_id: pw_log_debug("registry %p: no global with id %u to bind to %u", resource, id, new_id); @@ -100,7 +99,7 @@ static int registry_bind(void *object, uint32_t id, * new_id as 'used and freed' */ pw_map_insert_at(&client->objects, new_id, NULL); pw_core_resource_remove_id(client->core_resource, new_id); - return -EFAULT; + return NULL; } static int registry_destroy(void *object, uint32_t id) @@ -213,7 +212,7 @@ static int core_error(void *object, uint32_t id, int seq, int res, const char *m return 0; } -static int core_get_registry(void *object, uint32_t version, uint32_t new_id) +static struct pw_registry_proxy * core_get_registry(void *object, uint32_t version, size_t user_data_size) { struct pw_resource *resource = object; struct pw_client *client = resource->client; @@ -221,6 +220,7 @@ static int core_get_registry(void *object, uint32_t version, uint32_t new_id) struct pw_global *global; struct pw_resource *registry_resource; struct resource_data *data; + uint32_t new_id = user_data_size; registry_resource = pw_resource_new(client, new_id, @@ -257,7 +257,7 @@ static int core_get_registry(void *object, uint32_t version, uint32_t new_id) } } - return 0; + return (struct pw_registry_proxy *)registry_resource; no_mem: pw_log_error("can't create registry resource"); @@ -265,22 +265,24 @@ static int core_get_registry(void *object, uint32_t version, uint32_t new_id) client->recv_seq, -ENOMEM, "no memory"); pw_map_insert_at(&client->objects, new_id, NULL); pw_core_resource_remove_id(client->core_resource, new_id); - return -ENOMEM; + errno = ENOMEM; + return NULL; } -static int +static void * core_create_object(void *object, const char *factory_name, uint32_t type, uint32_t version, const struct spa_dict *props, - uint32_t new_id) + size_t user_data_size) { struct pw_resource *resource = object; struct pw_client *client = resource->client; struct pw_factory *factory; void *obj; struct pw_properties *properties; + uint32_t new_id = user_data_size; int res; factory = pw_core_find_factory(client->core, factory_name); @@ -330,27 +332,17 @@ core_create_object(void *object, error: pw_map_insert_at(&client->objects, new_id, NULL); pw_core_resource_remove_id(client->core_resource, new_id); - return res; + return NULL; } -static int core_destroy(void *object, uint32_t id) +static int core_destroy(void *object, void *proxy) { struct pw_resource *resource = object; struct pw_client *client = resource->client; - struct pw_resource *r; - - pw_log_debug("core %p: destroy resource %d from client %p", resource->core, id, client); - - if ((r = pw_client_find_resource(client, id)) == NULL) - goto no_resource; - + struct pw_resource *r = proxy; + pw_log_debug("core %p: destroy resource %p from client %p", resource->core, r, client); pw_resource_destroy(r); return 0; - - no_resource: - pw_log_error("can't find resouce %d", id); - pw_resource_error(resource, -EINVAL, "unknown resource %d", id); - return -EINVAL; } static const struct pw_core_proxy_methods core_methods = { @@ -525,7 +517,7 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, this->global = pw_global_new(this, PW_TYPE_INTERFACE_Core, - PW_VERSION_CORE, + PW_VERSION_CORE_PROXY, pw_properties_new( PW_CORE_PROP_USER_NAME, this->info.user_name, PW_CORE_PROP_HOST_NAME, this->info.host_name, diff --git a/src/pipewire/device.c b/src/pipewire/device.c index 11907d13b..cc0f186ce 100644 --- a/src/pipewire/device.c +++ b/src/pipewire/device.c @@ -36,6 +36,10 @@ struct impl { struct pw_device this; }; +#define pw_device_resource(r,m,v,...) pw_resource_notify(r,struct pw_device_proxy_events,m,v,__VA_ARGS__) +#define pw_device_resource_info(r,...) pw_device_resource(r,info,0,__VA_ARGS__) +#define pw_device_resource_param(r,...) pw_device_resource(r,param,0,__VA_ARGS__) + struct resource_data { struct spa_hook resource_listener; struct pw_device *device; @@ -291,7 +295,7 @@ int pw_device_register(struct pw_device *device, device->registered = true; device->global = pw_global_new(core, - PW_TYPE_INTERFACE_Device, PW_VERSION_DEVICE, + PW_TYPE_INTERFACE_Device, PW_VERSION_DEVICE_PROXY, properties, global_bind, device); diff --git a/src/pipewire/factory.c b/src/pipewire/factory.c index 8d678700b..e5f1dc9c8 100644 --- a/src/pipewire/factory.c +++ b/src/pipewire/factory.c @@ -31,6 +31,8 @@ #include "pipewire/type.h" #include "pipewire/interfaces.h" +#define pw_factory_resource_info(r,...) pw_resource_notify(r,struct pw_factory_proxy_events,info,0,__VA_ARGS__) + struct resource_data { struct spa_hook resource_listener; }; @@ -163,7 +165,8 @@ int pw_factory_register(struct pw_factory *factory, factory->registered = true; factory->global = pw_global_new(core, - PW_TYPE_INTERFACE_Factory, PW_VERSION_FACTORY, + PW_TYPE_INTERFACE_Factory, + PW_VERSION_FACTORY_PROXY, properties, global_bind, factory); diff --git a/src/pipewire/global.c b/src/pipewire/global.c index 8ac7ace36..7f794b785 100644 --- a/src/pipewire/global.c +++ b/src/pipewire/global.c @@ -272,8 +272,7 @@ void pw_global_add_listener(struct pw_global *global, * * \memberof pw_global */ -SPA_EXPORT -int +SPA_EXPORT int pw_global_bind(struct pw_global *global, struct pw_client *client, uint32_t permissions, uint32_t version, uint32_t id) { diff --git a/src/pipewire/interfaces.h b/src/pipewire/interfaces.h index 8aa301d68..1a1a29344 100644 --- a/src/pipewire/interfaces.h +++ b/src/pipewire/interfaces.h @@ -30,25 +30,35 @@ extern "C" { #endif #include +#include #include +#include #include #include #include -#include #include #include -struct pw_core_proxy; -struct pw_registry_proxy; -struct pw_module_proxy; -struct pw_device_proxy; -struct pw_node_proxy; -struct pw_port_proxy; -struct pw_factory_proxy; -struct pw_client_proxy; -struct pw_link_proxy; +#define PW_VERSION_CORE_PROXY 0 +struct pw_core_proxy { struct spa_interface iface; }; +#define PW_VERSION_REGISTRY_PROXY 0 +struct pw_registry_proxy { struct spa_interface iface; }; +#define PW_VERSION_MODULE_PROXY 0 +struct pw_module_proxy { struct spa_interface iface; }; +#define PW_VERSION_DEVICE_PROXY 0 +struct pw_device_proxy { struct spa_interface iface; }; +#define PW_VERSION_NODE_PROXY 0 +struct pw_node_proxy { struct spa_interface iface; }; +#define PW_VERSION_PORT_PROXY 0 +struct pw_port_proxy { struct spa_interface iface; }; +#define PW_VERSION_FACTORY_PROXY 0 +struct pw_factory_proxy { struct spa_interface iface; }; +#define PW_VERSION_CLIENT_PROXY 0 +struct pw_client_proxy { struct spa_interface iface; }; +#define PW_VERSION_LINK_PROXY 0 +struct pw_link_proxy { struct spa_interface iface; }; /** * \page page_pipewire_protocol The PipeWire protocol @@ -68,186 +78,6 @@ struct pw_link_proxy; /** Core */ -#define PW_VERSION_CORE 0 - -#define PW_CORE_PROXY_METHOD_HELLO 0 -#define PW_CORE_PROXY_METHOD_SYNC 1 -#define PW_CORE_PROXY_METHOD_PONG 2 -#define PW_CORE_PROXY_METHOD_ERROR 3 -#define PW_CORE_PROXY_METHOD_GET_REGISTRY 4 -#define PW_CORE_PROXY_METHOD_CREATE_OBJECT 5 -#define PW_CORE_PROXY_METHOD_DESTROY 6 -#define PW_CORE_PROXY_METHOD_NUM 7 - -#define PW_LINK_OUTPUT_NODE_ID "link.output_node.id" -#define PW_LINK_OUTPUT_PORT_ID "link.output_port.id" -#define PW_LINK_INPUT_NODE_ID "link.input_node.id" -#define PW_LINK_INPUT_PORT_ID "link.input_port.id" - -/** - * \struct pw_core_proxy_methods - * \brief Core methods - * - * The core global object. This is a singleton object used for - * creating new objects in the remote PipeWire intance. It is - * also used for internal features. - */ -struct pw_core_proxy_methods { -#define PW_VERSION_CORE_PROXY_METHODS 0 - uint32_t version; - /** - * Start a conversation with the server. This will send - * the core info and will destroy all resources for the client - * (except the core and client resource). - */ - int (*hello) (void *object, uint32_t version); - /** - * Do server roundtrip - * - * Ask the server to emit the 'done' event with \a seq. - * - * Since methods are handled in-order and events are delivered - * in-order, this can be used as a barrier to ensure all previous - * methods and the resulting events have been handled. - * - * \param seq the seq number passed to the done event - */ - int (*sync) (void *object, uint32_t id, int seq); - /** - * Reply to a server ping event. - * - * Reply to the server ping event with the same seq. - * - * \param seq the seq number received in the ping event - */ - int (*pong) (void *object, uint32_t id, int seq); - /** - * Fatal error event - * - * The error method is sent out when a fatal (non-recoverable) - * error has occurred. The id argument is the proxy object where - * the error occurred, most often in response to an event on that - * object. The message is a brief description of the error, - * for (debugging) convenience. - * - * This method is usually also emited on the resource object with - * \a id. - * - * \param id object where the error occurred - * \param res error code - * \param message error description - */ - int (*error) (void *object, uint32_t id, int seq, int res, const char *message); - /** - * Get the registry object - * - * Create a registry object that allows the client to list and bind - * the global objects available from the PipeWire server - * \param version the client proxy id - * \param id the client proxy id - */ - int (*get_registry) (void *object, uint32_t version, uint32_t new_id); - /** - * Create a new object on the PipeWire server from a factory. - * - * \param factory_name the factory name to use - * \param type the interface to bind to - * \param version the version of the interface - * \param props extra properties - * \param new_id the client proxy id - */ - int (*create_object) (void *object, - const char *factory_name, - uint32_t type, - uint32_t version, - const struct spa_dict *props, - uint32_t new_id); - /** - * Destroy an resource - * - * Destroy the server resource with the given proxy id. - * - * \param id the client proxy id to destroy - */ - int (*destroy) (void *object, uint32_t id); -}; - -static inline int -pw_core_proxy_hello(struct pw_core_proxy *core, uint32_t version) -{ - return pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, hello, version); -} - -static inline int -pw_core_proxy_sync(struct pw_core_proxy *core, uint32_t id, int seq) -{ - return pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, sync, id, seq); -} - -static inline int -pw_core_proxy_pong(struct pw_core_proxy *core, uint32_t id, int seq) -{ - return pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, pong, id, seq); -} - -static inline int -pw_core_proxy_error(struct pw_core_proxy *core, uint32_t id, int seq, - int res, const char *message) -{ - return pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, error, - id, seq, res, message); -} - -static inline int -pw_core_proxy_errorv(struct pw_core_proxy *core, uint32_t id, int seq, - int res, const char *message, va_list args) -{ - char buffer[1024]; - vsnprintf(buffer, sizeof(buffer), message, args); - buffer[1023] = '\0'; - return pw_core_proxy_error(core, id, seq, res, buffer); -} - -static inline int -pw_core_proxy_errorf(struct pw_core_proxy *core, uint32_t id, int seq, - int res, const char *message, ...) -{ - va_list args; - int r; - va_start(args, message); - r = pw_core_proxy_errorv(core, id, seq, res, message, args); - va_end(args); - return r; -} - -static inline struct pw_registry_proxy * -pw_core_proxy_get_registry(struct pw_core_proxy *core, uint32_t version, size_t user_data_size) -{ - struct pw_proxy *p = pw_proxy_new((struct pw_proxy*)core, PW_TYPE_INTERFACE_Registry, user_data_size); - pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, get_registry, version, pw_proxy_get_id(p)); - return (struct pw_registry_proxy *) p; -} - -static inline void * -pw_core_proxy_create_object(struct pw_core_proxy *core, - const char *factory_name, - uint32_t type, - uint32_t version, - const struct spa_dict *props, - size_t user_data_size) -{ - struct pw_proxy *p = pw_proxy_new((struct pw_proxy*)core, type, user_data_size); - pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, create_object, factory_name, - type, version, props, pw_proxy_get_id(p)); - return p; -} - -static inline int -pw_core_proxy_destroy(struct pw_core_proxy *core, struct pw_proxy *proxy) -{ - return pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, destroy, pw_proxy_get_id(proxy)); -} - #define PW_CORE_PROXY_EVENT_INFO 0 #define PW_CORE_PROXY_EVENT_DONE 1 #define PW_CORE_PROXY_EVENT_PING 2 @@ -321,43 +151,183 @@ struct pw_core_proxy_events { void (*remove_id) (void *object, uint32_t id); }; -static inline void -pw_core_proxy_add_listener(struct pw_core_proxy *core, - struct spa_hook *listener, - const struct pw_core_proxy_events *events, - void *data) -{ - pw_proxy_add_proxy_listener((struct pw_proxy*)core, listener, events, data); -} -#define pw_core_resource_info(r,...) pw_resource_notify(r,struct pw_core_proxy_events,info,__VA_ARGS__) -#define pw_core_resource_done(r,...) pw_resource_notify(r,struct pw_core_proxy_events,done,__VA_ARGS__) -#define pw_core_resource_ping(r,...) pw_resource_notify(r,struct pw_core_proxy_events,ping,__VA_ARGS__) -#define pw_core_resource_error(r,...) pw_resource_notify(r,struct pw_core_proxy_events,error,__VA_ARGS__) -#define pw_core_resource_remove_id(r,...) pw_resource_notify(r,struct pw_core_proxy_events,remove_id,__VA_ARGS__) +#define PW_CORE_PROXY_METHOD_ADD_LISTENER 0 +#define PW_CORE_PROXY_METHOD_HELLO 1 +#define PW_CORE_PROXY_METHOD_SYNC 2 +#define PW_CORE_PROXY_METHOD_PONG 3 +#define PW_CORE_PROXY_METHOD_ERROR 4 +#define PW_CORE_PROXY_METHOD_GET_REGISTRY 5 +#define PW_CORE_PROXY_METHOD_CREATE_OBJECT 6 +#define PW_CORE_PROXY_METHOD_DESTROY 7 +#define PW_CORE_PROXY_METHOD_NUM 8 -static inline void -pw_core_resource_errorv(struct pw_resource *resource, uint32_t id, int seq, +#define PW_LINK_OUTPUT_NODE_ID "link.output_node.id" +#define PW_LINK_OUTPUT_PORT_ID "link.output_port.id" +#define PW_LINK_INPUT_NODE_ID "link.input_node.id" +#define PW_LINK_INPUT_PORT_ID "link.input_port.id" + +/** + * \struct pw_core_proxy_methods + * \brief Core methods + * + * The core global object. This is a singleton object used for + * creating new objects in the remote PipeWire intance. It is + * also used for internal features. + */ +struct pw_core_proxy_methods { +#define PW_VERSION_CORE_PROXY_METHODS 0 + uint32_t version; + + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_core_proxy_events *events, + void *data); + /** + * Start a conversation with the server. This will send + * the core info and will destroy all resources for the client + * (except the core and client resource). + */ + int (*hello) (void *object, uint32_t version); + /** + * Do server roundtrip + * + * Ask the server to emit the 'done' event with \a seq. + * + * Since methods are handled in-order and events are delivered + * in-order, this can be used as a barrier to ensure all previous + * methods and the resulting events have been handled. + * + * \param seq the seq number passed to the done event + */ + int (*sync) (void *object, uint32_t id, int seq); + /** + * Reply to a server ping event. + * + * Reply to the server ping event with the same seq. + * + * \param seq the seq number received in the ping event + */ + int (*pong) (void *object, uint32_t id, int seq); + /** + * Fatal error event + * + * The error method is sent out when a fatal (non-recoverable) + * error has occurred. The id argument is the proxy object where + * the error occurred, most often in response to an event on that + * object. The message is a brief description of the error, + * for (debugging) convenience. + * + * This method is usually also emited on the resource object with + * \a id. + * + * \param id object where the error occurred + * \param res error code + * \param message error description + */ + int (*error) (void *object, uint32_t id, int seq, int res, const char *message); + /** + * Get the registry object + * + * Create a registry object that allows the client to list and bind + * the global objects available from the PipeWire server + * \param version the client version + * \param user_data_size extra size + */ + struct pw_registry_proxy * (*get_registry) (void *object, uint32_t version, + size_t user_data_size); + + /** + * Create a new object on the PipeWire server from a factory. + * + * \param factory_name the factory name to use + * \param type the interface to bind to + * \param version the version of the interface + * \param props extra properties + * \param user_data_size extra size + */ + void * (*create_object) (void *object, + const char *factory_name, + uint32_t type, + uint32_t version, + const struct spa_dict *props, + size_t user_data_size); + /** + * Destroy an resource + * + * Destroy the server resource for the given proxy. + * + * \param obj the proxy to destroy + */ + int (*destroy) (void *object, void *proxy); +}; + +#define pw_core_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_core_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_core_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) + +#define pw_core_proxy_add_listener(c,...) pw_core_proxy_method(c,add_listener,0,__VA_ARGS__) +#define pw_core_proxy_hello(c,...) pw_core_proxy_method(c,hello,0,__VA_ARGS__) +#define pw_core_proxy_sync(c,...) pw_core_proxy_method(c,sync,0,__VA_ARGS__) +#define pw_core_proxy_pong(c,...) pw_core_proxy_method(c,pong,0,__VA_ARGS__) +#define pw_core_proxy_error(c,...) pw_core_proxy_method(c,error,0,__VA_ARGS__) + +static inline int +pw_core_proxy_errorv(struct pw_core_proxy *core, uint32_t id, int seq, int res, const char *message, va_list args) { char buffer[1024]; vsnprintf(buffer, sizeof(buffer), message, args); buffer[1023] = '\0'; - pw_core_resource_error(resource, id, seq, res, buffer); + return pw_core_proxy_error(core, id, seq, res, buffer); } -static inline void -pw_core_resource_errorf(struct pw_resource *resource, uint32_t id, int seq, +static inline int +pw_core_proxy_errorf(struct pw_core_proxy *core, uint32_t id, int seq, int res, const char *message, ...) { va_list args; + int r; va_start(args, message); - pw_core_resource_errorv(resource, id, seq, res, message, args); + r = pw_core_proxy_errorv(core, id, seq, res, message, args); va_end(args); + return r; } -#define PW_VERSION_REGISTRY 0 +static inline struct pw_registry_proxy * +pw_core_proxy_get_registry(struct pw_core_proxy *core, uint32_t version, size_t user_data_size) +{ + struct pw_registry_proxy *res = NULL; + spa_interface_call_res(&core->iface, + struct pw_core_proxy_methods, res, + get_registry, 0, version, user_data_size); + return res; +} + +static inline void * +pw_core_proxy_create_object(struct pw_core_proxy *core, + const char *factory_name, + uint32_t type, + uint32_t version, + const struct spa_dict *props, + size_t user_data_size) +{ + void *res = NULL; + spa_interface_call_res(&core->iface, + struct pw_core_proxy_methods, res, + create_object, 0, factory_name, + type, version, props, user_data_size); + return res; +} + +#define pw_core_proxy_destroy(c,...) pw_core_proxy_method(c,destroy,0,__VA_ARGS__) /** \page page_registry Registry * @@ -390,57 +360,6 @@ pw_core_resource_errorf(struct pw_resource *resource, uint32_t id, int seq, * can, for example, hide certain existing or new objects or limit * the access permissions on an object. */ -#define PW_REGISTRY_PROXY_METHOD_BIND 0 -#define PW_REGISTRY_PROXY_METHOD_DESTROY 1 -#define PW_REGISTRY_PROXY_METHOD_NUM 2 - -/** Registry methods */ -struct pw_registry_proxy_methods { -#define PW_VERSION_REGISTRY_PROXY_METHODS 0 - uint32_t version; - /** - * Bind to a global object - * - * Bind to the global object with \a id and use the client proxy - * with new_id as the proxy. After this call, methods can be - * send to the remote global object and events can be received - * - * \param id the global id to bind to - * \param type the interface type to bind to - * \param version the interface version to use - * \param new_id the client proxy to use - */ - int (*bind) (void *object, uint32_t id, uint32_t type, uint32_t version, uint32_t new_id); - - /** - * Attempt to destroy a global object - * - * Try to destroy the global object. - * - * \param id the global id to destroy - */ - int (*destroy) (void *object, uint32_t id); -}; - -/** Registry */ -static inline void * -pw_registry_proxy_bind(struct pw_registry_proxy *registry, - uint32_t id, uint32_t type, uint32_t version, - size_t user_data_size) -{ - struct pw_proxy *reg = (struct pw_proxy*)registry; - struct pw_proxy *p = pw_proxy_new(reg, type, user_data_size); - pw_proxy_do(reg, struct pw_registry_proxy_methods, bind, - id, type, version, pw_proxy_get_id(p)); - return p; -} - -static inline int -pw_registry_proxy_destroy(struct pw_registry_proxy *registry, uint32_t id) -{ - struct pw_proxy *reg = (struct pw_proxy*)registry; - return pw_proxy_do(reg, struct pw_registry_proxy_methods, destroy, id); -} #define PW_REGISTRY_PROXY_EVENT_GLOBAL 0 #define PW_REGISTRY_PROXY_EVENT_GLOBAL_REMOVE 1 @@ -478,29 +397,73 @@ struct pw_registry_proxy_events { void (*global_remove) (void *object, uint32_t id); }; -static inline void -pw_registry_proxy_add_listener(struct pw_registry_proxy *registry, - struct spa_hook *listener, - const struct pw_registry_proxy_events *events, - void *data) +#define PW_REGISTRY_PROXY_METHOD_ADD_LISTENER 0 +#define PW_REGISTRY_PROXY_METHOD_BIND 1 +#define PW_REGISTRY_PROXY_METHOD_DESTROY 2 +#define PW_REGISTRY_PROXY_METHOD_NUM 3 + +/** Registry methods */ +struct pw_registry_proxy_methods { +#define PW_VERSION_REGISTRY_PROXY_METHODS 0 + uint32_t version; + + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_registry_proxy_events *events, + void *data); + /** + * Bind to a global object + * + * Bind to the global object with \a id and use the client proxy + * with new_id as the proxy. After this call, methods can be + * send to the remote global object and events can be received + * + * \param id the global id to bind to + * \param type the interface type to bind to + * \param version the interface version to use + * \returns the new object + */ + void * (*bind) (void *object, uint32_t id, uint32_t type, uint32_t version, + size_t use_data_size); + + /** + * Attempt to destroy a global object + * + * Try to destroy the global object. + * + * \param id the global id to destroy + */ + int (*destroy) (void *object, uint32_t id); +}; + +#define pw_registry_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_registry_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_registry_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) + +/** Registry */ +#define pw_registry_proxy_add_listener(p,...) pw_registry_proxy_method(p,add_listener,0,__VA_ARGS__) + +static inline void * +pw_registry_proxy_bind(struct pw_registry_proxy *registry, + uint32_t id, uint32_t type, uint32_t version, + size_t user_data_size) { - pw_proxy_add_proxy_listener((struct pw_proxy*)registry, listener, events, data); + void *res = NULL; + spa_interface_call_res(®istry->iface, + struct pw_registry_proxy_methods, res, + bind, 0, id, type, version, user_data_size); + return res; } -#define pw_registry_resource_global(r,...) pw_resource_notify(r,struct pw_registry_proxy_events,global,__VA_ARGS__) -#define pw_registry_resource_global_remove(r,...) pw_resource_notify(r,struct pw_registry_proxy_events,global_remove,__VA_ARGS__) +#define pw_registry_proxy_destroy(p,...) pw_registry_proxy_method(p,destroy,0,__VA_ARGS__) -#define PW_VERSION_MODULE 0 - -#define PW_MODULE_PROXY_METHOD_NUM 0 - -/** Module methods */ -struct pw_module_proxy_methods { -#define PW_VERSION_MODULE_PROXY_METHODS 0 - uint32_t version; -}; - #define PW_MODULE_PROXY_EVENT_INFO 0 #define PW_MODULE_PROXY_EVENT_NUM 1 @@ -516,68 +479,31 @@ struct pw_module_proxy_events { void (*info) (void *object, const struct pw_module_info *info); }; -static inline void -pw_module_proxy_add_listener(struct pw_module_proxy *module, - struct spa_hook *listener, - const struct pw_module_proxy_events *events, - void *data) -{ - pw_proxy_add_proxy_listener((struct pw_proxy*)module, listener, events, data); -} +#define PW_MODULE_PROXY_METHOD_ADD_LISTENER 0 +#define PW_MODULE_PROXY_METHOD_NUM 1 -#define pw_module_resource_info(r,...) pw_resource_notify(r,struct pw_module_proxy_events,info,__VA_ARGS__) - - -#define PW_VERSION_DEVICE 0 - -#define PW_DEVICE_PROXY_METHOD_ENUM_PARAMS 0 -#define PW_DEVICE_PROXY_METHOD_SET_PARAM 1 -#define PW_DEVICE_PROXY_METHOD_NUM 2 - -/** Device methods */ -struct pw_device_proxy_methods { -#define PW_VERSION_DEVICE_PROXY_METHODS 0 +/** Module methods */ +struct pw_module_proxy_methods { +#define PW_VERSION_MODULE_PROXY_METHODS 0 uint32_t version; - /** - * Enumerate device parameters - * - * Start enumeration of device parameters. For each param, a - * param event will be emited. - * - * \param seq a sequence number to place in the reply - * \param id the parameter id to enum or SPA_ID_INVALID for all - * \param start the start index or 0 for the first param - * \param num the maximum number of params to retrieve - * \param filter a param filter or NULL - */ - int (*enum_params) (void *object, int seq, uint32_t id, uint32_t start, uint32_t num, - const struct spa_pod *filter); - /** - * Set a parameter on the device - * - * \param id the parameter id to set - * \param flags extra parameter flags - * \param param the parameter to set - */ - int (*set_param) (void *object, uint32_t id, uint32_t flags, - const struct spa_pod *param); + + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_module_proxy_events *events, + void *data); }; -static inline int -pw_device_proxy_enum_params(struct pw_device_proxy *device, int seq, uint32_t id, uint32_t index, - uint32_t num, const struct spa_pod *filter) -{ - return pw_proxy_do((struct pw_proxy*)device, struct pw_device_proxy_methods, enum_params, - seq, id, index, num, filter); -} +#define pw_module_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_module_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_module_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) -static inline int -pw_device_proxy_set_param(struct pw_device_proxy *device, uint32_t id, uint32_t flags, - const struct spa_pod *param) -{ - return pw_proxy_do((struct pw_proxy*)device, struct pw_device_proxy_methods, set_param, - id, flags, param); -} +#define pw_module_proxy_add_listener(c,...) pw_module_proxy_method(c,add_listener,0,__VA_ARGS__) #define PW_DEVICE_PROXY_EVENT_INFO 0 #define PW_DEVICE_PROXY_EVENT_PARAM 1 @@ -609,30 +535,107 @@ struct pw_device_proxy_events { const struct spa_pod *param); }; -static inline void -pw_device_proxy_add_listener(struct pw_device_proxy *device, - struct spa_hook *listener, - const struct pw_device_proxy_events *events, - void *data) -{ - pw_proxy_add_proxy_listener((struct pw_proxy*)device, listener, events, data); -} -#define pw_device_resource_info(r,...) pw_resource_notify(r,struct pw_device_proxy_events,info,__VA_ARGS__) -#define pw_device_resource_param(r,...) pw_resource_notify(r,struct pw_device_proxy_events,param,__VA_ARGS__) +#define PW_DEVICE_PROXY_METHOD_ADD_LISTENER 0 +#define PW_DEVICE_PROXY_METHOD_ENUM_PARAMS 1 +#define PW_DEVICE_PROXY_METHOD_SET_PARAM 2 +#define PW_DEVICE_PROXY_METHOD_NUM 3 -#define PW_VERSION_NODE 0 +/** Device methods */ +struct pw_device_proxy_methods { +#define PW_VERSION_DEVICE_PROXY_METHODS 0 + uint32_t version; -#define PW_NODE_PROXY_METHOD_SUBSCRIBE_PARAMS 0 -#define PW_NODE_PROXY_METHOD_ENUM_PARAMS 1 -#define PW_NODE_PROXY_METHOD_SET_PARAM 2 -#define PW_NODE_PROXY_METHOD_SEND_COMMAND 3 -#define PW_NODE_PROXY_METHOD_NUM 4 + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_device_proxy_events *events, + void *data); + /** + * Enumerate device parameters + * + * Start enumeration of device parameters. For each param, a + * param event will be emited. + * + * \param seq a sequence number to place in the reply + * \param id the parameter id to enum or SPA_ID_INVALID for all + * \param start the start index or 0 for the first param + * \param num the maximum number of params to retrieve + * \param filter a param filter or NULL + */ + int (*enum_params) (void *object, int seq, uint32_t id, uint32_t start, uint32_t num, + const struct spa_pod *filter); + /** + * Set a parameter on the device + * + * \param id the parameter id to set + * \param flags extra parameter flags + * \param param the parameter to set + */ + int (*set_param) (void *object, uint32_t id, uint32_t flags, + const struct spa_pod *param); +}; + +#define pw_device_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_device_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_device_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) + +#define pw_device_proxy_add_listener(c,...) pw_device_proxy_method(c,add_listener,0,__VA_ARGS__) +#define pw_device_proxy_enum_params(c,...) pw_device_proxy_method(c,enum_params,0,__VA_ARGS__) +#define pw_device_proxy_set_param(c,...) pw_device_proxy_method(c,set_param,0,__VA_ARGS__) + + +#define PW_NODE_PROXY_EVENT_INFO 0 +#define PW_NODE_PROXY_EVENT_PARAM 1 +#define PW_NODE_PROXY_EVENT_NUM 2 + +/** Node events */ +struct pw_node_proxy_events { +#define PW_VERSION_NODE_PROXY_EVENTS 0 + uint32_t version; + /** + * Notify node info + * + * \param info info about the node + */ + void (*info) (void *object, const struct pw_node_info *info); + /** + * Notify a node param + * + * Event emited as a result of the enum_params method. + * + * \param seq the sequence number of the request + * \param id the param id + * \param index the param index + * \param next the param index of the next param + * \param param the parameter + */ + void (*param) (void *object, int seq, + uint32_t id, uint32_t index, uint32_t next, + const struct spa_pod *param); +}; + +#define PW_NODE_PROXY_METHOD_ADD_LISTENER 0 +#define PW_NODE_PROXY_METHOD_SUBSCRIBE_PARAMS 1 +#define PW_NODE_PROXY_METHOD_ENUM_PARAMS 2 +#define PW_NODE_PROXY_METHOD_SET_PARAM 3 +#define PW_NODE_PROXY_METHOD_SEND_COMMAND 4 +#define PW_NODE_PROXY_METHOD_NUM 5 /** Node methods */ struct pw_node_proxy_methods { #define PW_VERSION_NODE_PROXY_METHODS 0 uint32_t version; + + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_node_proxy_events *events, + void *data); /** * Subscribe to parameter changes * @@ -678,133 +681,23 @@ struct pw_node_proxy_methods { int (*send_command) (void *object, const struct spa_command *command); }; +#define pw_node_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_node_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_node_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) + /** Node */ -static inline int -pw_node_proxy_subscribe_params(struct pw_node_proxy *node, uint32_t *ids, uint32_t n_ids) -{ - return pw_proxy_do((struct pw_proxy*)node, struct pw_node_proxy_methods, subscribe_params, - ids, n_ids); -} +#define pw_node_proxy_add_listener(c,...) pw_node_proxy_method(c,add_listener,0,__VA_ARGS__) +#define pw_node_proxy_subscribe_params(c,...) pw_node_proxy_method(c,subscribe_params,0,__VA_ARGS__) +#define pw_node_proxy_enum_params(c,...) pw_node_proxy_method(c,enum_params,0,__VA_ARGS__) +#define pw_node_proxy_set_param(c,...) pw_node_proxy_method(c,set_param,0,__VA_ARGS__) +#define pw_node_proxy_send_command(c,...) pw_node_proxy_method(c,send_command,0,__VA_ARGS__) -static inline int -pw_node_proxy_enum_params(struct pw_node_proxy *node, int seq, uint32_t id, uint32_t index, - uint32_t num, const struct spa_pod *filter) -{ - return pw_proxy_do((struct pw_proxy*)node, struct pw_node_proxy_methods, enum_params, - seq, id, index, num, filter); -} - -static inline int -pw_node_proxy_set_param(struct pw_node_proxy *node, uint32_t id, uint32_t flags, - const struct spa_pod *param) -{ - return pw_proxy_do((struct pw_proxy*)node, struct pw_node_proxy_methods, set_param, - id, flags, param); -} - -static inline int -pw_node_proxy_send_command(struct pw_node_proxy *node, const struct spa_command *command) -{ - return pw_proxy_do((struct pw_proxy*)node, struct pw_node_proxy_methods, send_command, - command); -} - -#define PW_NODE_PROXY_EVENT_INFO 0 -#define PW_NODE_PROXY_EVENT_PARAM 1 -#define PW_NODE_PROXY_EVENT_NUM 2 - -/** Node events */ -struct pw_node_proxy_events { -#define PW_VERSION_NODE_PROXY_EVENTS 0 - uint32_t version; - /** - * Notify node info - * - * \param info info about the node - */ - void (*info) (void *object, const struct pw_node_info *info); - /** - * Notify a node param - * - * Event emited as a result of the enum_params method. - * - * \param seq the sequence number of the request - * \param id the param id - * \param index the param index - * \param next the param index of the next param - * \param param the parameter - */ - void (*param) (void *object, int seq, - uint32_t id, uint32_t index, uint32_t next, - const struct spa_pod *param); -}; - -static inline void -pw_node_proxy_add_listener(struct pw_node_proxy *node, - struct spa_hook *listener, - const struct pw_node_proxy_events *events, - void *data) -{ - pw_proxy_add_proxy_listener((struct pw_proxy*)node, listener, events, data); -} - -#define pw_node_resource_info(r,...) pw_resource_notify(r,struct pw_node_proxy_events,info,__VA_ARGS__) -#define pw_node_resource_param(r,...) pw_resource_notify(r,struct pw_node_proxy_events,param,__VA_ARGS__) - - -#define PW_VERSION_PORT 0 - -#define PW_PORT_PROXY_METHOD_SUBSCRIBE_PARAMS 0 -#define PW_PORT_PROXY_METHOD_ENUM_PARAMS 1 -#define PW_PORT_PROXY_METHOD_NUM 2 - -/** Port methods */ -struct pw_port_proxy_methods { -#define PW_VERSION_PORT_PROXY_METHODS 0 - uint32_t version; - /** - * Subscribe to parameter changes - * - * Automatically emit param events for the given ids when - * they are changed. - * - * \param ids an array of param ids - * \param n_ids the number of ids in \a ids - */ - int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids); - - /** - * Enumerate port parameters - * - * Start enumeration of port parameters. For each param, a - * param event will be emited. - * - * \param seq a sequence number returned in the reply - * \param id the parameter id to enumerate - * \param start the start index or 0 for the first param - * \param num the maximum number of params to retrieve - * \param filter a param filter or NULL - */ - int (*enum_params) (void *object, int seq, - uint32_t id, uint32_t start, uint32_t num, - const struct spa_pod *filter); -}; - -/** Port params */ -static inline int -pw_port_proxy_subscribe_params(struct pw_port_proxy *port, uint32_t *ids, uint32_t n_ids) -{ - return pw_proxy_do((struct pw_proxy*)port, struct pw_port_proxy_methods, subscribe_params, - ids, n_ids); -} - -static inline int -pw_port_proxy_enum_params(struct pw_port_proxy *port, int seq, uint32_t id, uint32_t index, - uint32_t num, const struct spa_pod *filter) -{ - return pw_proxy_do((struct pw_proxy*)port, struct pw_port_proxy_methods, enum_params, - seq, id, index, num, filter); -} #define PW_PORT_PROXY_EVENT_INFO 0 #define PW_PORT_PROXY_EVENT_PARAM 1 @@ -836,28 +729,63 @@ struct pw_port_proxy_events { const struct spa_pod *param); }; -static inline void -pw_port_proxy_add_listener(struct pw_port_proxy *port, - struct spa_hook *listener, - const struct pw_port_proxy_events *events, - void *data) -{ - pw_proxy_add_proxy_listener((struct pw_proxy*)port, listener, events, data); -} +#define PW_PORT_PROXY_METHOD_ADD_LISTENER 0 +#define PW_PORT_PROXY_METHOD_SUBSCRIBE_PARAMS 1 +#define PW_PORT_PROXY_METHOD_ENUM_PARAMS 2 +#define PW_PORT_PROXY_METHOD_NUM 3 -#define pw_port_resource_info(r,...) pw_resource_notify(r,struct pw_port_proxy_events,info,__VA_ARGS__) -#define pw_port_resource_param(r,...) pw_resource_notify(r,struct pw_port_proxy_events,param,__VA_ARGS__) - -#define PW_VERSION_FACTORY 0 - -#define PW_FACTORY_PROXY_METHOD_NUM 0 - -/** Factory methods */ -struct pw_factory_proxy_methods { -#define PW_VERSION_FACTORY_PROXY_METHODS 0 +/** Port methods */ +struct pw_port_proxy_methods { +#define PW_VERSION_PORT_PROXY_METHODS 0 uint32_t version; + + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_port_proxy_events *events, + void *data); + /** + * Subscribe to parameter changes + * + * Automatically emit param events for the given ids when + * they are changed. + * + * \param ids an array of param ids + * \param n_ids the number of ids in \a ids + */ + int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids); + + /** + * Enumerate port parameters + * + * Start enumeration of port parameters. For each param, a + * param event will be emited. + * + * \param seq a sequence number returned in the reply + * \param id the parameter id to enumerate + * \param start the start index or 0 for the first param + * \param num the maximum number of params to retrieve + * \param filter a param filter or NULL + */ + int (*enum_params) (void *object, int seq, + uint32_t id, uint32_t start, uint32_t num, + const struct spa_pod *filter); }; +#define pw_port_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_port_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_port_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) + +#define pw_port_proxy_add_listener(c,...) pw_port_proxy_method(c,add_listener,0,__VA_ARGS__) +#define pw_port_proxy_subscribe_params(c,...) pw_port_proxy_method(c,subscribe_params,0,__VA_ARGS__) +#define pw_port_proxy_enum_params(c,...) pw_port_proxy_method(c,enum_params,0,__VA_ARGS__) + + #define PW_FACTORY_PROXY_EVENT_INFO 0 #define PW_FACTORY_PROXY_EVENT_NUM 1 @@ -873,31 +801,80 @@ struct pw_factory_proxy_events { void (*info) (void *object, const struct pw_factory_info *info); }; -/** Factory */ -static inline void -pw_factory_proxy_add_listener(struct pw_factory_proxy *factory, - struct spa_hook *listener, - const struct pw_factory_proxy_events *events, - void *data) -{ - pw_proxy_add_proxy_listener((struct pw_proxy*)factory, listener, events, data); -} +#define PW_FACTORY_PROXY_METHOD_ADD_LISTENER 0 +#define PW_FACTORY_PROXY_METHOD_NUM 1 -#define pw_factory_resource_info(r,...) pw_resource_notify(r,struct pw_factory_proxy_events,info,__VA_ARGS__) +/** Factory methods */ +struct pw_factory_proxy_methods { +#define PW_VERSION_FACTORY_PROXY_METHODS 0 + uint32_t version; -#define PW_VERSION_CLIENT 0 + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_factory_proxy_events *events, + void *data); +}; -#define PW_CLIENT_PROXY_METHOD_ERROR 0 -#define PW_CLIENT_PROXY_METHOD_UPDATE_PROPERTIES 1 -#define PW_CLIENT_PROXY_METHOD_GET_PERMISSIONS 2 -#define PW_CLIENT_PROXY_METHOD_UPDATE_PERMISSIONS 3 -#define PW_CLIENT_PROXY_METHOD_NUM 4 +#define pw_factory_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_factory_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_factory_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) + +#define pw_factory_proxy_add_listener(c,...) pw_factory_proxy_method(c,add_listener,0,__VA_ARGS__) + + +#define PW_CLIENT_PROXY_EVENT_INFO 0 +#define PW_CLIENT_PROXY_EVENT_PERMISSIONS 1 +#define PW_CLIENT_PROXY_EVENT_NUM 2 + +/** Client events */ +struct pw_client_proxy_events { +#define PW_VERSION_CLIENT_PROXY_EVENTS 0 + uint32_t version; + /** + * Notify client info + * + * \param info info about the client + */ + void (*info) (void *object, const struct pw_client_info *info); + /** + * Notify a client permission + * + * Event emited as a result of the get_permissions method. + * + * \param default_permissions the default permissions + * \param index the index of the first permission entry + * \param n_permissions the number of permissions + * \param permissions the permissions + */ + void (*permissions) (void *object, + uint32_t index, + uint32_t n_permissions, + const struct pw_permission *permissions); +}; + + +#define PW_CLIENT_PROXY_METHOD_ADD_LISTENER 0 +#define PW_CLIENT_PROXY_METHOD_ERROR 1 +#define PW_CLIENT_PROXY_METHOD_UPDATE_PROPERTIES 2 +#define PW_CLIENT_PROXY_METHOD_GET_PERMISSIONS 3 +#define PW_CLIENT_PROXY_METHOD_UPDATE_PERMISSIONS 4 +#define PW_CLIENT_PROXY_METHOD_NUM 5 /** Client methods */ struct pw_client_proxy_methods { #define PW_VERSION_CLIENT_PROXY_METHODS 0 uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_client_proxy_events *events, + void *data); /** * Send an error to a client * @@ -939,85 +916,22 @@ struct pw_client_proxy_methods { const struct pw_permission *permissions); }; -/** Client permissions */ -static inline int -pw_client_proxy_error(struct pw_client_proxy *client, uint32_t id, int res, const char *message) -{ - return pw_proxy_do((struct pw_proxy*)client, struct pw_client_proxy_methods, error, id, res, message); -} +#define pw_client_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_client_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_client_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) -static inline int -pw_client_proxy_update_properties(struct pw_client_proxy *client, const struct spa_dict *props) -{ - return pw_proxy_do((struct pw_proxy*)client, struct pw_client_proxy_methods, update_properties, props); -} +#define pw_client_proxy_add_listener(c,...) pw_client_proxy_method(c,add_listener,0,__VA_ARGS__) +#define pw_client_proxy_error(c,...) pw_client_proxy_method(c,error,0,__VA_ARGS__) +#define pw_client_proxy_update_properties(c,...) pw_client_proxy_method(c,update_properties,0,__VA_ARGS__) +#define pw_client_proxy_get_permissions(c,...) pw_client_proxy_method(c,get_permissions,0,__VA_ARGS__) +#define pw_client_proxy_update_permissions(c,...) pw_client_proxy_method(c,update_permissions,0,__VA_ARGS__) -static inline int -pw_client_proxy_get_permissions(struct pw_client_proxy *client, uint32_t index, uint32_t num) -{ - return pw_proxy_do((struct pw_proxy*)client, struct pw_client_proxy_methods, get_permissions, index, num); -} - -static inline int -pw_client_proxy_update_permissions(struct pw_client_proxy *client, uint32_t n_permissions, - const struct pw_permission *permissions) -{ - return pw_proxy_do((struct pw_proxy*)client, struct pw_client_proxy_methods, update_permissions, - n_permissions, permissions); -} - -#define PW_CLIENT_PROXY_EVENT_INFO 0 -#define PW_CLIENT_PROXY_EVENT_PERMISSIONS 1 -#define PW_CLIENT_PROXY_EVENT_NUM 2 - -/** Client events */ -struct pw_client_proxy_events { -#define PW_VERSION_CLIENT_PROXY_EVENTS 0 - uint32_t version; - /** - * Notify client info - * - * \param info info about the client - */ - void (*info) (void *object, const struct pw_client_info *info); - /** - * Notify a client permission - * - * Event emited as a result of the get_permissions method. - * - * \param default_permissions the default permissions - * \param index the index of the first permission entry - * \param n_permissions the number of permissions - * \param permissions the permissions - */ - void (*permissions) (void *object, - uint32_t index, - uint32_t n_permissions, - const struct pw_permission *permissions); -}; - -/** Client */ -static inline void -pw_client_proxy_add_listener(struct pw_client_proxy *client, - struct spa_hook *listener, - const struct pw_client_proxy_events *events, - void *data) -{ - pw_proxy_add_proxy_listener((struct pw_proxy*)client, listener, events, data); -} - -#define pw_client_resource_info(r,...) pw_resource_notify(r,struct pw_client_proxy_events,info,__VA_ARGS__) -#define pw_client_resource_permissions(r,...) pw_resource_notify(r,struct pw_client_proxy_events,permissions,__VA_ARGS__) - -#define PW_VERSION_LINK 0 - -#define PW_LINK_PROXY_METHOD_NUM 0 - -/** Link methods */ -struct pw_link_proxy_methods { -#define PW_VERSION_LINK_PROXY_METHODS 0 - uint32_t version; -}; #define PW_LINK_PROXY_EVENT_INFO 0 #define PW_LINK_PROXY_EVENT_NUM 1 @@ -1034,17 +948,31 @@ struct pw_link_proxy_events { void (*info) (void *object, const struct pw_link_info *info); }; -/** Link */ -static inline void -pw_link_proxy_add_listener(struct pw_link_proxy *link, - struct spa_hook *listener, - const struct pw_link_proxy_events *events, - void *data) -{ - pw_proxy_add_proxy_listener((struct pw_proxy*)link, listener, events, data); -} +#define PW_LINK_PROXY_METHOD_ADD_LISTENER 0 +#define PW_LINK_PROXY_METHOD_NUM 1 -#define pw_link_resource_info(r,...) pw_resource_notify(r,struct pw_link_proxy_events,info,__VA_ARGS__) +/** Link methods */ +struct pw_link_proxy_methods { +#define PW_VERSION_LINK_PROXY_METHODS 0 + uint32_t version; + + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_link_proxy_events *events, + void *data); +}; + +#define pw_link_proxy_method(o,method,version,...) \ +({ \ + int _res = -ENOTSUP; \ + struct pw_link_proxy *_p = o; \ + spa_interface_call_res(&_p->iface, \ + struct pw_link_proxy_methods, _res, \ + method, version, ##__VA_ARGS__); \ + _res; \ +}) + +#define pw_link_proxy_add_listener(c,...) pw_link_proxy_method(c,add_listener,0,__VA_ARGS__) #ifdef __cplusplus } /* extern "C" */ diff --git a/src/pipewire/link.c b/src/pipewire/link.c index 073c7605c..aa27608c5 100644 --- a/src/pipewire/link.c +++ b/src/pipewire/link.c @@ -47,6 +47,8 @@ #define MAX_BUFFERS 64 +#define pw_link_resource_info(r,...) pw_resource_notify(r,struct pw_link_proxy_events,info,0,__VA_ARGS__) + /** \cond */ struct impl { struct pw_link this; @@ -518,11 +520,13 @@ static int port_set_io(struct pw_link *this, struct pw_port *port, uint32_t id, pw_direction_as_string(port->direction), port, port->port_id, mix->port.port_id, id, data, size); - if (port->mix->port_set_io) { - if ((res = spa_node_port_set_io(port->mix, - mix->port.direction, - mix->port.port_id, - id, data, size)) < 0) + if ((res = spa_node_port_set_io(port->mix, + mix->port.direction, + mix->port.port_id, + id, data, size)) < 0) { + if (res == -ENOTSUP) + res = 0; + else pw_log_warn("port %p: can't set io: %s", port, spa_strerror(res)); } return res; @@ -1417,7 +1421,8 @@ int pw_link_register(struct pw_link *link, link->registered = true; link->global = pw_global_new(core, - PW_TYPE_INTERFACE_Link, PW_VERSION_LINK, + PW_TYPE_INTERFACE_Link, + PW_VERSION_LINK_PROXY, properties, global_bind, link); diff --git a/src/pipewire/log.c b/src/pipewire/log.c index 43ec6fed7..19c81c3ae 100644 --- a/src/pipewire/log.c +++ b/src/pipewire/log.c @@ -86,7 +86,9 @@ pw_log_log(enum spa_log_level level, if (SPA_UNLIKELY(pw_log_level_enabled(level) && global_log)) { va_list args; va_start(args, fmt); - global_log->logv(global_log, level, file, line, func, fmt, args); + spa_interface_call(&global_log->iface, + struct spa_log_methods, logv, 0, level, file, line, + func, fmt, args); va_end(args); } } @@ -111,7 +113,9 @@ pw_log_logv(enum spa_log_level level, va_list args) { if (SPA_UNLIKELY(pw_log_level_enabled(level) && global_log)) { - global_log->logv(global_log, level, file, line, func, fmt, args); + spa_interface_call(&global_log->iface, + struct spa_log_methods, logv, 0, level, file, line, + func, fmt, args); } } diff --git a/src/pipewire/module.c b/src/pipewire/module.c index 409e07ea1..933dd1ebd 100644 --- a/src/pipewire/module.c +++ b/src/pipewire/module.c @@ -45,6 +45,8 @@ struct impl { void *hnd; }; +#define pw_module_resource_info(r,...) pw_resource_notify(r,struct pw_module_proxy_events,info,0,__VA_ARGS__) + struct resource_data { struct spa_hook resource_listener; }; @@ -240,7 +242,8 @@ pw_module_load(struct pw_core *core, spa_list_append(&core->module_list, &this->link); this->global = pw_global_new(core, - PW_TYPE_INTERFACE_Module, PW_VERSION_MODULE, + PW_TYPE_INTERFACE_Module, + PW_VERSION_MODULE_PROXY, pw_properties_new( PW_MODULE_PROP_NAME, name, NULL), diff --git a/src/pipewire/node.c b/src/pipewire/node.c index 88de2aa32..97a0ebe70 100644 --- a/src/pipewire/node.c +++ b/src/pipewire/node.c @@ -54,6 +54,10 @@ struct impl { unsigned int pause_on_idle:1; }; +#define pw_node_resource(r,m,v,...) pw_resource_notify(r,struct pw_node_proxy_events,m,v,__VA_ARGS__) +#define pw_node_resource_info(r,...) pw_node_resource(r,info,0,__VA_ARGS__) +#define pw_node_resource_param(r,...) pw_node_resource(r,param,0,__VA_ARGS__) + struct resource_data { struct spa_hook resource_listener; struct pw_node *node; @@ -497,7 +501,8 @@ int pw_node_register(struct pw_node *this, this->registered = true; this->global = pw_global_new(core, - PW_TYPE_INTERFACE_Node, PW_VERSION_NODE, + PW_TYPE_INTERFACE_Node, + PW_VERSION_NODE_PROXY, properties, global_bind, this); diff --git a/src/pipewire/port.c b/src/pipewire/port.c index c1f676c58..782b6be42 100644 --- a/src/pipewire/port.c +++ b/src/pipewire/port.c @@ -42,6 +42,10 @@ struct impl { struct spa_node mix_node; /**< mix node implementation */ }; +#define pw_port_resource(r,m,v,...) pw_resource_notify(r,struct pw_port_proxy_events,m,v,__VA_ARGS__) +#define pw_port_resource_info(r,...) pw_port_resource(r,info,0,__VA_ARGS__) +#define pw_port_resource_param(r,...) pw_port_resource(r,param,0,__VA_ARGS__) + struct resource_data { struct spa_hook resource_listener; struct pw_port *port; @@ -81,9 +85,9 @@ void pw_port_update_state(struct pw_port *port, enum pw_port_state state) } } -static int tee_process(struct spa_node *data) +static int tee_process(void *object) { - struct impl *impl = SPA_CONTAINER_OF(data, struct impl, mix_node); + struct impl *impl = object; struct pw_port *this = &impl->this; struct pw_port_mix *mix; struct spa_io_buffers *io = &this->rt.io; @@ -99,9 +103,9 @@ static int tee_process(struct spa_node *data) return SPA_STATUS_HAVE_BUFFER | SPA_STATUS_NEED_BUFFER; } -static int tee_reuse_buffer(struct spa_node *data, uint32_t port_id, uint32_t buffer_id) +static int tee_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *impl = SPA_CONTAINER_OF(data, struct impl, mix_node); + struct impl *impl = object; struct pw_port *this = &impl->this; pw_log_trace_fp("port %p: tee reuse buffer %d %d", this, port_id, buffer_id); @@ -110,16 +114,15 @@ static int tee_reuse_buffer(struct spa_node *data, uint32_t port_id, uint32_t bu return 0; } -static const struct spa_node schedule_tee_node = { - SPA_VERSION_NODE, - NULL, +static const struct spa_node_methods schedule_tee_node = { + SPA_VERSION_NODE_METHODS, .process = tee_process, .port_reuse_buffer = tee_reuse_buffer, }; -static int schedule_mix_input(struct spa_node *data) +static int schedule_mix_input(void *object) { - struct impl *impl = SPA_CONTAINER_OF(data, struct impl, mix_node); + struct impl *impl = object; struct pw_port *this = &impl->this; struct spa_io_buffers *io = &this->rt.io; struct pw_port_mix *mix; @@ -137,9 +140,9 @@ static int schedule_mix_input(struct spa_node *data) return SPA_STATUS_HAVE_BUFFER | SPA_STATUS_NEED_BUFFER; } -static int schedule_mix_reuse_buffer(struct spa_node *data, uint32_t port_id, uint32_t buffer_id) +static int schedule_mix_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct impl *impl = SPA_CONTAINER_OF(data, struct impl, mix_node); + struct impl *impl = object; struct pw_port *this = &impl->this; struct pw_port_mix *mix; @@ -150,9 +153,8 @@ static int schedule_mix_reuse_buffer(struct spa_node *data, uint32_t port_id, ui return 0; } -static const struct spa_node schedule_mix_node = { - SPA_VERSION_NODE, - NULL, +static const struct spa_node_methods schedule_mix_node = { + SPA_VERSION_NODE_METHODS, .process = schedule_mix_input, .port_reuse_buffer = schedule_mix_reuse_buffer, }; @@ -172,13 +174,12 @@ int pw_port_init_mix(struct pw_port *port, struct pw_port_mix *mix) port->n_mix++; mix->p = port; - if (port->mix->add_port) - port->mix->add_port(port->mix, port->direction, port_id, NULL); + spa_node_add_port(port->mix, port->direction, port_id, NULL); res = pw_port_call_init_mix(port, mix); /* set the same format on the mixer as on the port if any */ - if (port->mix->enum_params && port->mix->set_param) { + if (1) { uint32_t idx = 0; uint8_t buffer[1024]; struct spa_pod_builder b; @@ -212,9 +213,7 @@ int pw_port_release_mix(struct pw_port *port, struct pw_port_mix *mix) res = pw_port_call_release_mix(port, mix); - if (port->mix->remove_port) { - port->mix->remove_port(port->mix, port->direction, port_id); - } + spa_node_remove_port(port->mix, port->direction, port_id); pw_log_debug("port %p: release mix %d.%d", port, port->port_id, mix->port.port_id); @@ -334,6 +333,7 @@ struct pw_port *pw_port_new(enum pw_direction direction, struct impl *impl; struct pw_port *this; struct pw_properties *properties; + const struct spa_node_methods *mix_methods; impl = calloc(1, sizeof(struct impl) + user_data_size); if (impl == NULL) @@ -379,10 +379,17 @@ struct pw_port *pw_port_new(enum pw_direction direction, spa_hook_list_init(&this->listener_list); - impl->mix_node = this->direction == PW_DIRECTION_INPUT ? - schedule_mix_node : - schedule_tee_node; - pw_port_set_mix(this, &impl->mix_node, 0); + if (this->direction == PW_DIRECTION_INPUT) + mix_methods = &schedule_mix_node; + else + mix_methods = &schedule_tee_node; + + impl->mix_node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + mix_methods, impl); + + pw_port_set_mix(this, NULL, 0); pw_map_init(&this->mix_port_map, 64, 64); @@ -405,7 +412,7 @@ int pw_port_set_mix(struct pw_port *port, struct spa_node *node, uint32_t flags) struct impl *impl = SPA_CONTAINER_OF(port, struct impl, this); if (node == NULL) { - node = &impl->mix_node; + node = (struct spa_node *)&impl->mix_node; flags = 0; } pw_log_debug("port %p: mix node %p->%p", port, port->mix, node); @@ -631,7 +638,8 @@ int pw_port_register(struct pw_port *port, struct pw_core *core = node->core; port->global = pw_global_new(core, - PW_TYPE_INTERFACE_Port, PW_VERSION_PORT, + PW_TYPE_INTERFACE_Port, + PW_VERSION_PORT_PROXY, properties, global_bind, port); @@ -702,12 +710,10 @@ int pw_port_add(struct pw_port *port, struct pw_node *node) SPA_IO_Buffers, &port->rt.io, sizeof(port->rt.io)); - if (port->mix->port_set_io) { - spa_node_port_set_io(port->mix, - pw_direction_reverse(port->direction), 0, - SPA_IO_Buffers, - &port->rt.io, sizeof(port->rt.io)); - } + spa_node_port_set_io(port->mix, + pw_direction_reverse(port->direction), 0, + SPA_IO_Buffers, + &port->rt.io, sizeof(port->rt.io)); } pw_log_debug("port %p: %d add to node %p", port, port_id, node); @@ -952,7 +958,7 @@ int pw_port_set_param(struct pw_port *port, uint32_t id, uint32_t flags, pw_log_debug("port %p: %d set param %d %p", port, port->state, id, param); /* set the parameters on all ports of the mixer node if possible */ - if (port->mix->port_set_param != NULL) { + if (1) { struct pw_port_mix *mix; spa_list_for_each(mix, &port->mix_list, link) { @@ -1010,7 +1016,7 @@ int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id, if ((mix = pw_map_lookup(&port->mix_port_map, mix_id)) == NULL) return -EIO; - if (port->mix->port_use_buffers != NULL) { + if (1) { res = spa_node_port_use_buffers(port->mix, mix->port.direction, mix->port.port_id, buffers, n_buffers); diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 12b161efd..2a4fb4586 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -36,6 +36,7 @@ extern "C" { #include "pipewire/remote.h" #include "pipewire/mem.h" #include "pipewire/introspect.h" +#include "pipewire/interfaces.h" #include "pipewire/stream.h" #include "pipewire/log.h" @@ -170,6 +171,38 @@ struct pw_global { #define pw_core_emit_global_added(c,g) pw_core_emit(c, global_added, 0, g) #define pw_core_emit_global_removed(c,g) pw_core_emit(c, global_removed, 0, g) +#define pw_core_resource(r,m,v,...) pw_resource_notify(r, struct pw_core_proxy_events, m, v, ##__VA_ARGS__) +#define pw_core_resource_info(r,...) pw_core_resource(r,info,0,__VA_ARGS__) +#define pw_core_resource_done(r,...) pw_core_resource(r,done,0,__VA_ARGS__) +#define pw_core_resource_ping(r,...) pw_core_resource(r,ping,0,__VA_ARGS__) +#define pw_core_resource_error(r,...) pw_core_resource(r,error,0,__VA_ARGS__) +#define pw_core_resource_remove_id(r,...) pw_core_resource(r,remove_id,0,__VA_ARGS__) + +static inline void +pw_core_resource_errorv(struct pw_resource *resource, uint32_t id, int seq, + int res, const char *message, va_list args) +{ + char buffer[1024]; + vsnprintf(buffer, sizeof(buffer), message, args); + buffer[1023] = '\0'; + pw_core_resource_error(resource, id, seq, res, buffer); +} + +static inline void +pw_core_resource_errorf(struct pw_resource *resource, uint32_t id, int seq, + int res, const char *message, ...) +{ + va_list args; + va_start(args, message); + pw_core_resource_errorv(resource, id, seq, res, message, args); + va_end(args); +} + +#define pw_registry_resource(r,m,v,...) pw_resource_notify(r, struct pw_registry_proxy_events,m,v,##__VA_ARGS__) +#define pw_registry_resource_global(r,...) pw_registry_resource(r,global,0,__VA_ARGS__) +#define pw_registry_resource_global_remove(r,...) pw_registry_resource(r,global_remove,0,__VA_ARGS__) + + struct pw_core { struct pw_global *global; /**< the global of the core */ struct spa_hook global_listener; @@ -592,6 +625,7 @@ struct pw_link { #define pw_resource_emit_error(o,s,r,m) pw_resource_emit(o, error, 0, s, r, m) struct pw_resource { + struct spa_interface impl; /**< event implementation */ struct pw_core *core; /**< the core object */ struct spa_list link; /**< link in object resource_list */ @@ -620,6 +654,7 @@ struct pw_resource { #define pw_proxy_emit_error(p,s,r,m) pw_proxy_emit(p, error, 0, s, r, m) struct pw_proxy { + struct spa_interface impl; /**< method implementation */ struct pw_remote *remote; /**< the owner remote of this proxy */ struct spa_list link; /**< link in the remote */ diff --git a/src/pipewire/proxy.c b/src/pipewire/proxy.c index a76c60e3b..40962ca5c 100644 --- a/src/pipewire/proxy.c +++ b/src/pipewire/proxy.c @@ -78,6 +78,11 @@ struct pw_proxy *pw_proxy_new(struct pw_proxy *factory, this->marshal = pw_protocol_get_marshal(remote->conn->protocol, type); + this->impl = SPA_INTERFACE_INIT( + type, + this->marshal->version, + this->marshal->method_marshal, this); + spa_list_append(&this->remote->proxy_list, &this->link); pw_log_debug("proxy %p: new %u %s remote %p, marshal %p", diff --git a/src/pipewire/proxy.h b/src/pipewire/proxy.h index 009523405..a43d860ab 100644 --- a/src/pipewire/proxy.h +++ b/src/pipewire/proxy.h @@ -164,7 +164,6 @@ struct spa_hook_list *pw_proxy_get_proxy_listeners(struct pw_proxy *proxy); const struct pw_protocol_marshal *pw_proxy_get_marshal(struct pw_proxy *proxy); #define pw_proxy_notify(p,type,event,ver,...) spa_hook_list_call(pw_proxy_get_proxy_listeners(p),type,event,ver,## __VA_ARGS__) -#define pw_proxy_do(p,type,method,...) ((type*) pw_proxy_get_marshal(p)->method_marshal)->method(p, ## __VA_ARGS__) #ifdef __cplusplus } diff --git a/src/pipewire/remote.c b/src/pipewire/remote.c index ad3219206..da53a7fbc 100644 --- a/src/pipewire/remote.c +++ b/src/pipewire/remote.c @@ -329,7 +329,7 @@ static int do_connect(struct pw_remote *remote) pw_core_proxy_add_listener(remote->core_proxy, &impl->core_listener, &core_proxy_events, remote); pw_client_proxy_update_properties(remote->client_proxy, &remote->properties->dict); - pw_core_proxy_hello(remote->core_proxy, PW_VERSION_CORE); + pw_core_proxy_hello(remote->core_proxy, PW_VERSION_CORE_PROXY); pw_remote_update_state(remote, PW_REMOTE_STATE_CONNECTED, NULL); return 0; diff --git a/src/pipewire/resource.c b/src/pipewire/resource.c index 46f170926..349553ad8 100644 --- a/src/pipewire/resource.c +++ b/src/pipewire/resource.c @@ -76,6 +76,11 @@ struct pw_resource *pw_resource_new(struct pw_client *client, this->marshal = pw_protocol_get_marshal(client->protocol, type); + this->impl = SPA_INTERFACE_INIT( + type, + this->marshal->version, + this->marshal->event_marshal, this); + pw_log_debug("resource %p: new %u %s/%d client %p marshal %p", this, id, spa_debug_type_find_name(pw_type_info(), type), version, diff --git a/src/pipewire/resource.h b/src/pipewire/resource.h index d3a7543e9..243cab87f 100644 --- a/src/pipewire/resource.h +++ b/src/pipewire/resource.h @@ -141,8 +141,17 @@ const struct pw_protocol_marshal *pw_resource_get_marshal(struct pw_resource *re #define pw_resource_do_parent(r,l,type,method,...) \ spa_hook_list_call_once_start(pw_resource_get_implementation(r),l,type,method,v,## __VA_ARGS__) -#define pw_resource_notify(r,type,event,...) \ - ((type*) pw_resource_get_marshal(r)->event_marshal)->event(r, ## __VA_ARGS__) +#define pw_resource_notify(r,type,event,version,...) \ + spa_interface_call((struct spa_interface*)r, \ + type, event, version, ##__VA_ARGS__); + +#define pw_resource_notify_res(r,type,event,version,...) \ +({ \ + int _res = -ENOTSUP; \ + spa_interface_call_res((struct spa_interface*)r, \ + type, _res, event, version, ##__VA_ARGS__); \ + _res; \ +}) #ifdef __cplusplus } diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 14bc82236..84eb86d0e 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -118,6 +118,7 @@ struct stream { struct spa_port_info port_info; struct spa_node impl_node; + struct spa_node_methods node_methods; struct spa_hook_list hooks; struct spa_callbacks callbacks; struct spa_io_buffers *io; @@ -304,9 +305,9 @@ static void call_process(struct stream *impl) } } -static int impl_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) +static int impl_set_io(void *object, uint32_t id, void *data, size_t size) { - struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *impl = object; switch(id) { case SPA_IO_Position: if (data && size >= sizeof(struct spa_io_position)) @@ -320,9 +321,9 @@ static int impl_set_io(struct spa_node *node, uint32_t id, void *data, size_t si return 0; } -static int impl_send_command(struct spa_node *node, const struct spa_command *command) +static int impl_send_command(void *object, const struct spa_command *command) { - struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *impl = object; struct pw_stream *stream = &impl->this; switch (SPA_NODE_COMMAND_ID(command)) { @@ -383,12 +384,12 @@ static void emit_port_info(struct stream *d) spa_node_emit_port_info(&d->hooks, d->direction, 0, &info); } -static int impl_add_listener(struct spa_node *node, +static int impl_add_listener(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data) { - struct stream *d = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *d = object; struct spa_hook_list save; spa_hook_list_isolate(&d->hooks, &save, listener, events, data); @@ -401,20 +402,20 @@ static int impl_add_listener(struct spa_node *node, return 0; } -static int impl_set_callbacks(struct spa_node *node, +static int impl_set_callbacks(void *object, const struct spa_node_callbacks *callbacks, void *data) { - struct stream *d = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *d = object; d->callbacks = SPA_CALLBACKS_INIT(callbacks, data); return 0; } -static int impl_port_set_io(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_port_set_io(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size) { - struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *impl = object; pw_log_debug("stream %p: set io %s %p %zd", impl, spa_debug_type_find_name(spa_type_io, id), data, size); @@ -432,12 +433,12 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction, return 0; } -static int impl_port_enum_params(struct spa_node *node, int seq, +static int impl_port_enum_params(void *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter) { - struct stream *d = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *d = object; struct spa_result_node_params result; uint8_t buffer[1024]; struct spa_pod_builder b = { 0 }; @@ -473,11 +474,11 @@ static int impl_port_enum_params(struct spa_node *node, int seq, return 0; } -static int port_set_format(struct spa_node *node, +static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, const struct spa_pod *format) { - struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *impl = object; struct pw_stream *stream = &impl->this; struct param *p; int count; @@ -520,13 +521,13 @@ static int port_set_format(struct spa_node *node, return -ENOMEM; } -static int impl_port_set_param(struct spa_node *node, +static int impl_port_set_param(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param) { if (id == SPA_PARAM_Format) { - return port_set_format(node, direction, port_id, flags, param); + return port_set_format(object, direction, port_id, flags, param); } else return -ENOENT; @@ -590,10 +591,10 @@ static void clear_buffers(struct pw_stream *stream) clear_queue(impl, &impl->queued); } -static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direction, uint32_t port_id, +static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) { - struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *impl = object; struct pw_stream *stream = &impl->this; uint32_t i, j, flags = impl->flags; int prot, res; @@ -662,9 +663,9 @@ static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direc return 0; } -static int impl_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) +static int impl_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { - struct stream *d = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *d = object; pw_log_trace("stream %p: recycle buffer %d", d, buffer_id); if (buffer_id < d->n_buffers) push_queue(d, &d->queued, &d->buffers[buffer_id]); @@ -685,9 +686,9 @@ static inline void copy_position(struct stream *impl, int64_t queued) } } -static int impl_node_process_input(struct spa_node *node) +static int impl_node_process_input(void *object) { - struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *impl = object; struct pw_stream *stream = &impl->this; struct spa_io_buffers *io = impl->io; struct buffer *b; @@ -724,9 +725,9 @@ static int impl_node_process_input(struct spa_node *node) return SPA_STATUS_HAVE_BUFFER; } -static int impl_node_process_output(struct spa_node *node) +static int impl_node_process_output(void *object) { - struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node); + struct stream *impl = object; struct pw_stream *stream = &impl->this; struct spa_io_buffers *io = impl->io; struct buffer *b; @@ -771,8 +772,8 @@ static int impl_node_process_output(struct spa_node *node) return res; } -static const struct spa_node impl_node = { - SPA_VERSION_NODE, +static const struct spa_node_methods impl_node = { + SPA_VERSION_NODE_METHODS, .add_listener = impl_add_listener, .set_callbacks = impl_set_callbacks, .set_io = impl_set_io, @@ -961,12 +962,17 @@ static int handle_connect(struct pw_stream *stream) if (impl->node == NULL) goto no_node; - impl->impl_node = impl_node; + impl->node_methods = impl_node; if (impl->direction == SPA_DIRECTION_INPUT) - impl->impl_node.process = impl_node_process_input; + impl->node_methods.process = impl_node_process_input; else - impl->impl_node.process = impl_node_process_output; + impl->node_methods.process = impl_node_process_output; + + impl->impl_node.iface = SPA_INTERFACE_INIT( + SPA_TYPE_INTERFACE_Node, + SPA_VERSION_NODE, + &impl->node_methods, impl); pw_node_set_implementation(impl->node, &impl->impl_node); diff --git a/src/tests/test-core.c b/src/tests/test-core.c index b5db02cba..cba7683c6 100644 --- a/src/tests/test-core.c +++ b/src/tests/test-core.c @@ -150,7 +150,7 @@ static void test_create(void) spa_assert(pw_global_get_owner(global) == NULL); spa_assert(pw_global_get_parent(global) == global); spa_assert(pw_global_get_type(global) == PW_TYPE_INTERFACE_Core); - spa_assert(pw_global_get_version(global) == PW_VERSION_CORE); + spa_assert(pw_global_get_version(global) == PW_VERSION_CORE_PROXY); spa_assert(pw_global_get_id(global) == 0); spa_assert(pw_global_get_object(global) == (void*)core); diff --git a/src/tests/test-interfaces.c b/src/tests/test-interfaces.c index 14492a911..c9cfcebc1 100644 --- a/src/tests/test-interfaces.c +++ b/src/tests/test-interfaces.c @@ -37,18 +37,23 @@ static void test_core_abi(void) struct pw_core_proxy_events e; struct { uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_core_proxy_events *events, + void *data); int (*hello) (void *object, uint32_t version); int (*sync) (void *object, uint32_t id, int seq); int (*pong) (void *object, uint32_t id, int seq); int (*error) (void *object, uint32_t id, int seq, int res, const char *error); - int (*get_registry) (void *object, uint32_t version, uint32_t new_id); - int (*create_object) (void *object, + struct pw_registry_proxy * (*get_registry) (void *object, + uint32_t version, size_t user_data_size); + void * (*create_object) (void *object, const char *factory_name, uint32_t type, uint32_t version, const struct spa_dict *props, - uint32_t new_id); - int (*destroy) (void *object, uint32_t id); + size_t user_data_size); + int (*destroy) (void *object, void *proxy); } methods = { PW_VERSION_CORE_PROXY_METHODS, }; struct { uint32_t version; @@ -60,6 +65,7 @@ static void test_core_abi(void) } events = { PW_VERSION_CORE_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); TEST_FUNC(m, methods, hello); TEST_FUNC(m, methods, sync); TEST_FUNC(m, methods, pong); @@ -86,7 +92,12 @@ static void test_registry_abi(void) struct pw_registry_proxy_events e; struct { uint32_t version; - int (*bind) (void *object, uint32_t id, uint32_t type, uint32_t version, uint32_t new_id); + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_registry_proxy_events *events, + void *data); + void * (*bind) (void *object, uint32_t id, uint32_t type, uint32_t version, + size_t user_data_size); int (*destroy) (void *object, uint32_t id); } methods = { PW_VERSION_REGISTRY_PROXY_METHODS, }; struct { @@ -98,6 +109,7 @@ static void test_registry_abi(void) } events = { PW_VERSION_REGISTRY_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); TEST_FUNC(m, methods, bind); TEST_FUNC(m, methods, destroy); spa_assert(PW_VERSION_REGISTRY_PROXY_METHODS == 0); @@ -116,6 +128,10 @@ static void test_module_abi(void) struct pw_module_proxy_events e; struct { uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_module_proxy_events *events, + void *data); } methods = { PW_VERSION_MODULE_PROXY_METHODS, }; struct { uint32_t version; @@ -123,6 +139,7 @@ static void test_module_abi(void) } events = { PW_VERSION_MODULE_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); spa_assert(PW_VERSION_MODULE_PROXY_METHODS == 0); spa_assert(sizeof(m) == sizeof(methods)); @@ -138,6 +155,10 @@ static void test_device_abi(void) struct pw_device_proxy_events e; struct { uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_device_proxy_events *events, + void *data); int (*enum_params) (void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter); @@ -153,6 +174,7 @@ static void test_device_abi(void) } events = { PW_VERSION_DEVICE_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); TEST_FUNC(m, methods, enum_params); TEST_FUNC(m, methods, set_param); spa_assert(PW_VERSION_DEVICE_PROXY_METHODS == 0); @@ -171,6 +193,10 @@ static void test_node_abi(void) struct pw_node_proxy_events e; struct { uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_node_proxy_events *events, + void *data); int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids); int (*enum_params) (void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter); @@ -187,6 +213,7 @@ static void test_node_abi(void) } events = { PW_VERSION_NODE_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); TEST_FUNC(m, methods, subscribe_params); TEST_FUNC(m, methods, enum_params); TEST_FUNC(m, methods, set_param); @@ -207,6 +234,10 @@ static void test_port_abi(void) struct pw_port_proxy_events e; struct { uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_port_proxy_events *events, + void *data); int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids); int (*enum_params) (void *object, int seq, uint32_t id, uint32_t start, uint32_t num, const struct spa_pod *filter); @@ -220,6 +251,7 @@ static void test_port_abi(void) } events = { PW_VERSION_PORT_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); TEST_FUNC(m, methods, enum_params); spa_assert(PW_VERSION_PORT_PROXY_METHODS == 0); spa_assert(sizeof(m) == sizeof(methods)); @@ -237,6 +269,10 @@ static void test_factory_abi(void) struct pw_factory_proxy_events e; struct { uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_factory_proxy_events *events, + void *data); } methods = { PW_VERSION_FACTORY_PROXY_METHODS, }; struct { uint32_t version; @@ -244,6 +280,7 @@ static void test_factory_abi(void) } events = { PW_VERSION_FACTORY_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); spa_assert(PW_VERSION_FACTORY_PROXY_METHODS == 0); spa_assert(sizeof(m) == sizeof(methods)); @@ -259,6 +296,10 @@ static void test_client_abi(void) struct pw_client_proxy_events e; struct { uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_client_proxy_events *events, + void *data); int (*error) (void *object, uint32_t id, int res, const char *error); int (*update_properties) (void *object, const struct spa_dict *props); int (*get_permissions) (void *object, uint32_t index, uint32_t num); @@ -273,6 +314,8 @@ static void test_client_abi(void) } events = { PW_VERSION_CLIENT_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); + TEST_FUNC(m, methods, error); TEST_FUNC(m, methods, update_properties); TEST_FUNC(m, methods, get_permissions); TEST_FUNC(m, methods, update_permissions); @@ -292,6 +335,10 @@ static void test_link_abi(void) struct pw_link_proxy_events e; struct { uint32_t version; + int (*add_listener) (void *object, + struct spa_hook *listener, + const struct pw_link_proxy_events *events, + void *data); } methods = { PW_VERSION_LINK_PROXY_METHODS, }; struct { uint32_t version; @@ -299,6 +346,7 @@ static void test_link_abi(void) } events = { PW_VERSION_LINK_PROXY_EVENTS, }; TEST_FUNC(m, methods, version); + TEST_FUNC(m, methods, add_listener); spa_assert(PW_VERSION_LINK_PROXY_METHODS == 0); spa_assert(sizeof(m) == sizeof(methods)); diff --git a/src/tools/pipewire-cli.c b/src/tools/pipewire-cli.c index a26aa469a..46487b773 100644 --- a/src/tools/pipewire-cli.c +++ b/src/tools/pipewire-cli.c @@ -400,7 +400,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old, &rd->core_listener, &remote_core_events, rd); rd->registry_proxy = pw_core_proxy_get_registry(rd->core_proxy, - PW_VERSION_REGISTRY, 0); + PW_VERSION_REGISTRY_PROXY, 0); pw_registry_proxy_add_listener(rd->registry_proxy, &rd->registry_listener, ®istry_events, rd); @@ -881,49 +881,49 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er switch (global->type) { case PW_TYPE_INTERFACE_Core: events = &core_events; - client_version = PW_VERSION_CORE; + client_version = PW_VERSION_CORE_PROXY; destroy = (pw_destroy_t) pw_core_info_free; info_func = info_core; break; case PW_TYPE_INTERFACE_Module: events = &module_events; - client_version = PW_VERSION_MODULE; + client_version = PW_VERSION_MODULE_PROXY; destroy = (pw_destroy_t) pw_module_info_free; info_func = info_module; break; case PW_TYPE_INTERFACE_Device: events = &device_events; - client_version = PW_VERSION_DEVICE; + client_version = PW_VERSION_DEVICE_PROXY; destroy = (pw_destroy_t) pw_device_info_free; info_func = info_device; break; case PW_TYPE_INTERFACE_Node: events = &node_events; - client_version = PW_VERSION_NODE; + client_version = PW_VERSION_NODE_PROXY; destroy = (pw_destroy_t) pw_node_info_free; info_func = info_node; break; case PW_TYPE_INTERFACE_Port: events = &port_events; - client_version = PW_VERSION_PORT; + client_version = PW_VERSION_PORT_PROXY; destroy = (pw_destroy_t) pw_port_info_free; info_func = info_port; break; case PW_TYPE_INTERFACE_Factory: events = &factory_events; - client_version = PW_VERSION_FACTORY; + client_version = PW_VERSION_FACTORY_PROXY; destroy = (pw_destroy_t) pw_factory_info_free; info_func = info_factory; break; case PW_TYPE_INTERFACE_Client: events = &client_events; - client_version = PW_VERSION_CLIENT; + client_version = PW_VERSION_CLIENT_PROXY; destroy = (pw_destroy_t) pw_client_info_free; info_func = info_client; break; case PW_TYPE_INTERFACE_Link: events = &link_events; - client_version = PW_VERSION_LINK; + client_version = PW_VERSION_LINK_PROXY; destroy = (pw_destroy_t) pw_link_info_free; info_func = info_link; break; @@ -1030,7 +1030,8 @@ static bool do_create_node(struct data *data, const char *cmd, char *args, char props = parse_props(a[1]); proxy = pw_core_proxy_create_object(rd->core_proxy, a[0], - PW_TYPE_INTERFACE_Node, PW_VERSION_NODE, + PW_TYPE_INTERFACE_Node, + PW_VERSION_NODE_PROXY, props ? &props->dict : NULL, sizeof(struct proxy_data)); @@ -1099,7 +1100,7 @@ static bool do_create_link(struct data *data, const char *cmd, char *args, char proxy = (struct pw_proxy*)pw_core_proxy_create_object(rd->core_proxy, "link-factory", PW_TYPE_INTERFACE_Link, - PW_VERSION_LINK, + PW_VERSION_LINK_PROXY, props ? &props->dict : NULL, sizeof(struct proxy_data)); diff --git a/src/tools/pipewire-monitor.c b/src/tools/pipewire-monitor.c index deeec1fd7..679e06d2c 100644 --- a/src/tools/pipewire-monitor.c +++ b/src/tools/pipewire-monitor.c @@ -589,40 +589,40 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id, switch (type) { case PW_TYPE_INTERFACE_Node: events = &node_events; - client_version = PW_VERSION_NODE; + client_version = PW_VERSION_NODE_PROXY; destroy = (pw_destroy_t) pw_node_info_free; print_func = print_node; break; case PW_TYPE_INTERFACE_Port: events = &port_events; - client_version = PW_VERSION_PORT; + client_version = PW_VERSION_PORT_PROXY; destroy = (pw_destroy_t) pw_port_info_free; print_func = print_port; break; case PW_TYPE_INTERFACE_Module: events = &module_events; - client_version = PW_VERSION_MODULE; + client_version = PW_VERSION_MODULE_PROXY; destroy = (pw_destroy_t) pw_module_info_free; break; case PW_TYPE_INTERFACE_Device: events = &device_events; - client_version = PW_VERSION_DEVICE; + client_version = PW_VERSION_DEVICE_PROXY; destroy = (pw_destroy_t) pw_device_info_free; print_func = print_device; break; case PW_TYPE_INTERFACE_Factory: events = &factory_events; - client_version = PW_VERSION_FACTORY; + client_version = PW_VERSION_FACTORY_PROXY; destroy = (pw_destroy_t) pw_factory_info_free; break; case PW_TYPE_INTERFACE_Client: events = &client_events; - client_version = PW_VERSION_CLIENT; + client_version = PW_VERSION_CLIENT_PROXY; destroy = (pw_destroy_t) pw_client_info_free; break; case PW_TYPE_INTERFACE_Link: events = &link_events; - client_version = PW_VERSION_LINK; + client_version = PW_VERSION_LINK_PROXY; destroy = (pw_destroy_t) pw_link_info_free; break; default: @@ -702,7 +702,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old, &data->core_listener, &core_events, data); data->registry_proxy = pw_core_proxy_get_registry(data->core_proxy, - PW_VERSION_REGISTRY, 0); + PW_VERSION_REGISTRY_PROXY, 0); pw_registry_proxy_add_listener(data->registry_proxy, &data->registry_listener, ®istry_events, data);