PipeWire 1.4.10

Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_NODE_UTILS_H
6#define SPA_NODE_UTILS_H
7
8#ifdef __cplusplus
9 extern "C" {
10#endif
11
16
17#include <spa/pod/builder.h>
18
19#include <spa/node/node.h>
20
21#ifndef SPA_API_NODE_UTILS
22 #ifdef SPA_API_IMPL
23 #define SPA_API_NODE_UTILS SPA_API_IMPL
24 #else
25 #define SPA_API_NODE_UTILS static inline
26 #endif
27#endif
28
29 struct spa_result_node_params_data {
30 struct spa_pod_builder *builder;
31 struct spa_result_node_params data;
32};
33
34 SPA_API_NODE_UTILS void spa_result_func_node_params(void *data,
35 int seq SPA_UNUSED, int res SPA_UNUSED, uint32_t type SPA_UNUSED, const void *result)
36{
37 struct spa_result_node_params_data *d =
38 (struct spa_result_node_params_data *) data;
39 const struct spa_result_node_params *r =
40 (const struct spa_result_node_params *) result;
41 uint32_t offset = d->builder->state.offset;
42 if (spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param)) < 0)
43 return;
44 d->data.next = r->next;
45 d->data.param = spa_pod_builder_deref(d->builder, offset);
46}
47
48 SPA_API_NODE_UTILS int spa_node_enum_params_sync(struct spa_node *node,
49 uint32_t id, uint32_t *index,
50 const struct spa_pod *filter,
51 struct spa_pod **param,
52 struct spa_pod_builder *builder)
53{
54 struct spa_result_node_params_data data = { builder, {0}};
55 struct spa_hook listener = {{0}, {0}, 0, 0};
56 static const struct spa_node_events node_events = {
57 .version = SPA_VERSION_NODE_EVENTS,
58 .info = NULL,
59 .port_info = NULL,
60 .result = spa_result_func_node_params,
61 };
62 int res;
63
64 res = spa_node_add_listener(node, &listener, &node_events, &data);
65 if (res >= 0) {
66 res = spa_node_enum_params(node, 0, id, *index, 1, filter);
67 spa_hook_remove(&listener);
68 }
69
70 if (data.data.param == NULL) {
71 if (res > 0)
72 res = 0;
73 } else {
74 *index = data.data.next;
75 *param = data.data.param;
76 res = 1;
77 }
78 return res;
79}
80
81 SPA_API_NODE_UTILS int spa_node_port_enum_params_sync(struct spa_node *node,
82 enum spa_direction direction, uint32_t port_id,
83 uint32_t id, uint32_t *index,
84 const struct spa_pod *filter,
85 struct spa_pod **param,
86 struct spa_pod_builder *builder)
87{
88 struct spa_result_node_params_data data = { builder, {0}};
89 struct spa_hook listener = {{0}, {0}, 0, 0};
90 static const struct spa_node_events node_events = {
91 .version = SPA_VERSION_NODE_EVENTS,
92 .info = NULL,
93 .port_info = NULL,
94 .result = spa_result_func_node_params,
95 };
96 int res;
97
98 res = spa_node_add_listener(node, &listener, &node_events, &data);
99 if (res >= 0) {
100 res = spa_node_port_enum_params(node, 0, direction, port_id,
101 id, *index, 1, filter);
102 spa_hook_remove(&listener);
103 }
104
105 if (data.data.param == NULL) {
106 if (res > 0)
107 res = 0;
108 } else {
109 *index = data.data.next;
110 *param = data.data.param;
111 res = 1;
112 }
113 return res;
114}
115
116#define spa_node_emit(hooks,method,version,...) \
117 spa_hook_list_call_simple(hooks, struct spa_node_events, \
118 method, version, ##__VA_ARGS__)
119
120#define spa_node_emit_info(hooks,...) spa_node_emit(hooks,info, 0, __VA_ARGS__)
121#define spa_node_emit_port_info(hooks,...) spa_node_emit(hooks,port_info, 0, __VA_ARGS__)
122#define spa_node_emit_result(hooks,...) spa_node_emit(hooks,result, 0, __VA_ARGS__)
123#define spa_node_emit_event(hooks,...) spa_node_emit(hooks,event, 0, __VA_ARGS__)
124
125
126#define spa_node_call(callbacks,method,version,...) \
127({ \
128 int _res; \
129 spa_callbacks_call_fast_res(callbacks, struct spa_node_callbacks, \
130 _res, method, version, ##__VA_ARGS__); \
131 _res; \
132})
133
134#define spa_node_call_ready(hook,...) spa_node_call(hook, ready, 0, __VA_ARGS__)
135#define spa_node_call_reuse_buffer(hook,...) spa_node_call(hook, reuse_buffer, 0, __VA_ARGS__)
136#define spa_node_call_xrun(hook,...) spa_node_call(hook, xrun, 0, __VA_ARGS__)
137
140
141
142#ifdef __cplusplus
143} /* extern "C" */
144#endif
145
146#endif /* SPA_NODE_UTILS_H */
builder.h
spa/pod/builder.h
seq
uint32_t int seq
Definition core.h:432
r
uint32_t int int const char int r
Definition core.h:447
res
uint32_t int int res
Definition core.h:433
spa_hook_remove
SPA_API_HOOK void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition hook.h:468
spa_node_enum_params
SPA_API_NODE int spa_node_enum_params(struct spa_node *object, int seq, uint32_t id, uint32_t start, uint32_t max, const struct spa_pod *filter)
Definition node.h:733
spa_result_func_node_params
SPA_API_NODE_UTILS void spa_result_func_node_params(void *data, int seq, int res 1, uint32_t type 1, const void *result)
Definition utils.h:41
spa_node_add_listener
SPA_API_NODE int spa_node_add_listener(struct spa_node *object, struct spa_hook *listener, const struct spa_node_events *events, void *data)
Definition node.h:713
spa_node_enum_params_sync
SPA_API_NODE_UTILS 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, struct spa_pod_builder *builder)
Definition utils.h:55
spa_node_port_enum_params_sync
SPA_API_NODE_UTILS 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, struct spa_pod_builder *builder)
Definition utils.h:88
spa_node_port_enum_params
SPA_API_NODE int spa_node_port_enum_params(struct spa_node *object, int seq, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t start, uint32_t max, const struct spa_pod *filter)
Definition node.h:772
SPA_VERSION_NODE_EVENTS
#define SPA_VERSION_NODE_EVENTS
Definition node.h:188
SPA_API_NODE_UTILS
#define SPA_API_NODE_UTILS
Definition utils.h:32
spa_pod_builder_deref
SPA_API_POD_BUILDER struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition builder.h:103
spa_pod_builder_raw_padded
SPA_API_POD_BUILDER int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition builder.h:179
SPA_POD_SIZE
#define SPA_POD_SIZE(pod)
Definition pod.h:30
SPA_UNUSED
#define SPA_UNUSED
Definition defs.h:307
spa_direction
spa_direction
Definition defs.h:106
node.h
spa/node/node.h
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition hook.h:427
spa_node_events
events from the spa_node.
Definition node.h:186
spa_node
Definition node.h:51
spa_pod_builder_state::offset
uint32_t offset
Definition builder.h:43
spa_pod_builder
Definition builder.h:63
spa_pod_builder::state
struct spa_pod_builder_state state
Definition builder.h:67
spa_pod
Definition pod.h:43
spa_result_node_params_data
Definition utils.h:36
spa_result_node_params_data::data
struct spa_result_node_params data
Definition utils.h:38
spa_result_node_params_data::builder
struct spa_pod_builder * builder
Definition utils.h:37
spa_result_node_params
the result of enum_params or port_enum_params.
Definition node.h:162
spa_result_node_params::param
struct spa_pod * param
the result param
Definition node.h:166
spa_result_node_params::next
uint32_t next
next index of iteration
Definition node.h:165
spa_result_node_params::index
uint32_t index
index of parameter
Definition node.h:164