2023-02-08 18:12:00 +01:00
|
|
|
/* Simple Plugin API */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2019-02-20 17:51:05 +01:00
|
|
|
|
|
|
|
|
#ifndef SPA_NODE_UTILS_H
|
|
|
|
|
#define SPA_NODE_UTILS_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-05-21 14:03:07 +10:00
|
|
|
/**
|
|
|
|
|
* \addtogroup spa_node
|
|
|
|
|
* \{
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-23 13:13:01 +02:00
|
|
|
#include <spa/pod/builder.h>
|
|
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
#include <spa/node/node.h>
|
|
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
struct spa_result_node_params_data {
|
2019-02-20 17:51:05 +01:00
|
|
|
struct spa_pod_builder *builder;
|
2019-02-25 12:29:57 +01:00
|
|
|
struct spa_result_node_params data;
|
2019-02-20 17:51:05 +01:00
|
|
|
};
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static inline void spa_result_func_node_params(void *data,
|
2023-11-21 17:18:26 +01:00
|
|
|
int seq SPA_UNUSED, int res SPA_UNUSED, uint32_t type SPA_UNUSED, const void *result)
|
2019-02-20 17:51:05 +01:00
|
|
|
{
|
2019-02-25 12:29:57 +01:00
|
|
|
struct spa_result_node_params_data *d =
|
2019-03-01 12:00:42 +01:00
|
|
|
(struct spa_result_node_params_data *) data;
|
2019-02-25 12:29:57 +01:00
|
|
|
const struct spa_result_node_params *r =
|
2019-03-01 12:00:42 +01:00
|
|
|
(const struct spa_result_node_params *) result;
|
2019-02-21 12:14:25 +01:00
|
|
|
uint32_t offset = d->builder->state.offset;
|
2021-09-06 13:57:39 +02:00
|
|
|
if (spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param)) < 0)
|
|
|
|
|
return;
|
2019-02-21 12:14:25 +01:00
|
|
|
d->data.next = r->next;
|
2021-09-06 13:57:39 +02:00
|
|
|
d->data.param = spa_pod_builder_deref(d->builder, offset);
|
2019-02-20 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int spa_node_enum_params_sync(struct spa_node *node,
|
|
|
|
|
uint32_t id, uint32_t *index,
|
|
|
|
|
const struct spa_pod *filter,
|
|
|
|
|
struct spa_pod **param,
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_pod_builder *builder)
|
2019-02-20 17:51:05 +01:00
|
|
|
{
|
2023-11-21 17:18:26 +01:00
|
|
|
struct spa_result_node_params_data data = { builder, {0}};
|
|
|
|
|
struct spa_hook listener = {{0}, {0}, 0, 0};
|
2019-03-01 12:00:42 +01:00
|
|
|
static const struct spa_node_events node_events = {
|
2021-06-10 14:49:44 +10:00
|
|
|
.version = SPA_VERSION_NODE_EVENTS,
|
|
|
|
|
.info = NULL,
|
|
|
|
|
.port_info = NULL,
|
2019-03-01 12:00:42 +01:00
|
|
|
.result = spa_result_func_node_params,
|
|
|
|
|
};
|
2019-05-20 16:11:23 +02:00
|
|
|
int res;
|
2019-02-20 17:51:05 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
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);
|
|
|
|
|
}
|
2019-02-25 20:19:33 +01:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
if (data.data.param == NULL) {
|
|
|
|
|
if (res > 0)
|
|
|
|
|
res = 0;
|
|
|
|
|
} else {
|
|
|
|
|
*index = data.data.next;
|
|
|
|
|
*param = data.data.param;
|
|
|
|
|
res = 1;
|
|
|
|
|
}
|
2019-02-20 17:51:05 +01:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int spa_node_port_enum_params_sync(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t *index,
|
|
|
|
|
const struct spa_pod *filter,
|
|
|
|
|
struct spa_pod **param,
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_pod_builder *builder)
|
2019-02-20 17:51:05 +01:00
|
|
|
{
|
2023-11-21 17:18:26 +01:00
|
|
|
struct spa_result_node_params_data data = { builder, {0}};
|
|
|
|
|
struct spa_hook listener = {{0}, {0}, 0, 0};
|
2019-03-01 12:00:42 +01:00
|
|
|
static const struct spa_node_events node_events = {
|
2021-06-10 14:49:44 +10:00
|
|
|
.version = SPA_VERSION_NODE_EVENTS,
|
|
|
|
|
.info = NULL,
|
|
|
|
|
.port_info = NULL,
|
2019-03-01 12:00:42 +01:00
|
|
|
.result = spa_result_func_node_params,
|
|
|
|
|
};
|
2019-02-20 17:51:05 +01:00
|
|
|
int res;
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
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);
|
|
|
|
|
}
|
2019-02-25 20:19:33 +01:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
if (data.data.param == NULL) {
|
|
|
|
|
if (res > 0)
|
|
|
|
|
res = 0;
|
|
|
|
|
} else {
|
|
|
|
|
*index = data.data.next;
|
|
|
|
|
*param = data.data.param;
|
|
|
|
|
res = 1;
|
|
|
|
|
}
|
2019-02-20 17:51:05 +01:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 10:14:00 +02:00
|
|
|
#define spa_node_emit(hooks,method,version,...) \
|
|
|
|
|
spa_hook_list_call_simple(hooks, struct spa_node_events, \
|
|
|
|
|
method, version, ##__VA_ARGS__)
|
|
|
|
|
|
2019-08-22 13:23:48 +02:00
|
|
|
#define spa_node_emit_info(hooks,...) spa_node_emit(hooks,info, 0, __VA_ARGS__)
|
|
|
|
|
#define spa_node_emit_port_info(hooks,...) spa_node_emit(hooks,port_info, 0, __VA_ARGS__)
|
|
|
|
|
#define spa_node_emit_result(hooks,...) spa_node_emit(hooks,result, 0, __VA_ARGS__)
|
|
|
|
|
#define spa_node_emit_event(hooks,...) spa_node_emit(hooks,event, 0, __VA_ARGS__)
|
2024-04-11 17:19:12 +02:00
|
|
|
#define spa_node_emit_peer_enum_params(hooks,...) spa_node_emit(hooks,peer_enum_params,1, __VA_ARGS__)
|
2019-05-20 10:14:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#define spa_node_call(callbacks,method,version,...) \
|
|
|
|
|
({ \
|
2023-05-06 00:47:39 +02:00
|
|
|
int _res; \
|
|
|
|
|
spa_callbacks_call_fast_res(callbacks, struct spa_node_callbacks, \
|
2019-05-20 10:14:00 +02:00
|
|
|
_res, method, version, ##__VA_ARGS__); \
|
|
|
|
|
_res; \
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-22 13:23:48 +02:00
|
|
|
#define spa_node_call_ready(hook,...) spa_node_call(hook, ready, 0, __VA_ARGS__)
|
|
|
|
|
#define spa_node_call_reuse_buffer(hook,...) spa_node_call(hook, reuse_buffer, 0, __VA_ARGS__)
|
|
|
|
|
#define spa_node_call_xrun(hook,...) spa_node_call(hook, xrun, 0, __VA_ARGS__)
|
2019-05-20 10:14:00 +02:00
|
|
|
|
2021-05-21 14:03:07 +10:00
|
|
|
/**
|
|
|
|
|
* \}
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
} /* extern "C" */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* SPA_NODE_UTILS_H */
|