PipeWire: spa/node/utils.h Source File

PipeWire 1.0.3

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
9extern "C" {
10#endif
11
17#include <spa/pod/builder.h>
18
19#include <spa/node/node.h>
20
21struct spa_result_node_params_data {
22 struct spa_pod_builder *builder;
23 struct spa_result_node_params data;
24};
25
26 static inline void spa_result_func_node_params(void *data,
27 int seq SPA_UNUSED, int res SPA_UNUSED, uint32_t type SPA_UNUSED, const void *result)
28{
29 struct spa_result_node_params_data *d =
30 (struct spa_result_node_params_data *) data;
31 const struct spa_result_node_params *r =
32 (const struct spa_result_node_params *) result;
33 uint32_t offset = d->builder->state.offset;
34 if (spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param)) < 0)
35 return;
36 d->data.next = r->next;
37 d->data.param = spa_pod_builder_deref(d->builder, offset);
38}
39
40static inline int spa_node_enum_params_sync(struct spa_node *node,
41 uint32_t id, uint32_t *index,
42 const struct spa_pod *filter,
43 struct spa_pod **param,
44 struct spa_pod_builder *builder)
45{
46 struct spa_result_node_params_data data = { builder, {0}};
47 struct spa_hook listener = {{0}, {0}, 0, 0};
48 static const struct spa_node_events node_events = {
49 .version = SPA_VERSION_NODE_EVENTS,
50 .info = NULL,
51 .port_info = NULL,
52 .result = spa_result_func_node_params,
53 };
54 int res;
55
56 res = spa_node_add_listener(node, &listener, &node_events, &data);
57 if (res >= 0) {
58 res = spa_node_enum_params(node, 0, id, *index, 1, filter);
59 spa_hook_remove(&listener);
60 }
61
62 if (data.data.param == NULL) {
63 if (res > 0)
64 res = 0;
65 } else {
66 *index = data.data.next;
67 *param = data.data.param;
68 res = 1;
69 }
70 return res;
71}
72
73static inline int spa_node_port_enum_params_sync(struct spa_node *node,
74 enum spa_direction direction, uint32_t port_id,
75 uint32_t id, uint32_t *index,
76 const struct spa_pod *filter,
77 struct spa_pod **param,
78 struct spa_pod_builder *builder)
79{
80 struct spa_result_node_params_data data = { builder, {0}};
81 struct spa_hook listener = {{0}, {0}, 0, 0};
82 static const struct spa_node_events node_events = {
83 .version = SPA_VERSION_NODE_EVENTS,
84 .info = NULL,
85 .port_info = NULL,
86 .result = spa_result_func_node_params,
87 };
88 int res;
89
90 res = spa_node_add_listener(node, &listener, &node_events, &data);
91 if (res >= 0) {
92 res = spa_node_port_enum_params(node, 0, direction, port_id,
93 id, *index, 1, filter);
94 spa_hook_remove(&listener);
95 }
96
97 if (data.data.param == NULL) {
98 if (res > 0)
99 res = 0;
100 } else {
101 *index = data.data.next;
102 *param = data.data.param;
103 res = 1;
104 }
105 return res;
106}
107
108#define spa_node_emit(hooks,method,version,...) \
109 spa_hook_list_call_simple(hooks, struct spa_node_events, \
110 method, version, ##__VA_ARGS__)
111
112#define spa_node_emit_info(hooks,...) spa_node_emit(hooks,info, 0, __VA_ARGS__)
113#define spa_node_emit_port_info(hooks,...) spa_node_emit(hooks,port_info, 0, __VA_ARGS__)
114#define spa_node_emit_result(hooks,...) spa_node_emit(hooks,result, 0, __VA_ARGS__)
115#define spa_node_emit_event(hooks,...) spa_node_emit(hooks,event, 0, __VA_ARGS__)
116
117
118#define spa_node_call(callbacks,method,version,...) \
119({ \
120 int _res; \
121 spa_callbacks_call_fast_res(callbacks, struct spa_node_callbacks, \
122 _res, method, version, ##__VA_ARGS__); \
123 _res; \
124})
125
126#define spa_node_call_ready(hook,...) spa_node_call(hook, ready, 0, __VA_ARGS__)
127#define spa_node_call_reuse_buffer(hook,...) spa_node_call(hook, reuse_buffer, 0, __VA_ARGS__)
128#define spa_node_call_xrun(hook,...) spa_node_call(hook, xrun, 0, __VA_ARGS__)
129
134#ifdef __cplusplus
135} /* extern "C" */
136#endif
137
138#endif /* SPA_NODE_UTILS_H */
builder.h
spa/pod/builder.h
spa_hook_remove
static void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition hook.h:391
spa_result_func_node_params
static void spa_result_func_node_params(void *data, int seq 1, int res 1, uint32_t type 1, const void *result)
Definition utils.h:31
spa_node_enum_params_sync
static 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:45
spa_node_add_listener
#define spa_node_add_listener(n,...)
Adds an event listener on node.
Definition node.h:719
spa_node_port_enum_params
#define spa_node_port_enum_params(n,...)
Enumerate all possible parameters of id on port_id of node that are compatible with filter.
Definition node.h:746
spa_node_port_enum_params_sync
static 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:78
spa_node_enum_params
#define spa_node_enum_params(n,...)
Enumerate the parameters of a node.
Definition node.h:728
SPA_VERSION_NODE_EVENTS
#define SPA_VERSION_NODE_EVENTS
Definition node.h:178
spa_pod_builder_raw_padded
static int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition builder.h:160
SPA_POD_SIZE
#define SPA_POD_SIZE(pod)
Definition pod.h:30
spa_pod_builder_deref
static struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition builder.h:93
SPA_UNUSED
#define SPA_UNUSED
Definition defs.h:289
spa_direction
spa_direction
Definition defs.h:92
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:350
spa_node_events
events from the spa_node.
Definition node.h:176
spa_node_events::version
uint32_t version
version of this structure
Definition node.h:179
spa_node
Definition node.h:41
spa_pod_builder_state::offset
uint32_t offset
Definition builder.h:33
spa_pod_builder
Definition builder.h:53
spa_pod_builder::state
struct spa_pod_builder_state state
Definition builder.h:57
spa_pod
Definition pod.h:43
spa_result_node_params_data
Definition utils.h:26
spa_result_node_params_data::data
struct spa_result_node_params data
Definition utils.h:28
spa_result_node_params_data::builder
struct spa_pod_builder * builder
Definition utils.h:27
spa_result_node_params
the result of enum_params or port_enum_params.
Definition node.h:152
spa_result_node_params::param
struct spa_pod * param
the result param
Definition node.h:156
spa_result_node_params::next
uint32_t next
next index of iteration
Definition node.h:155
spa_result_node_params::index
uint32_t index
index of parameter
Definition node.h:154