PipeWire  0.3.29
output/doc/spa/node/utils.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2019 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef SPA_NODE_UTILS_H
26 #define SPA_NODE_UTILS_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
37 #include <spa/pod/builder.h>
38 
39 #include <spa/node/node.h>
40 
44 };
45 
46 /* static */ inline void spa_result_func_node_params(void *data,
47  int seq, int res, uint32_t type, const void *result)
48 {
49  struct spa_result_node_params_data *d =
51  const struct spa_result_node_params *r =
52  (const struct spa_result_node_params *) result;
53  uint32_t offset = d->builder->state.offset;
54  spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param));
55  d->data.next = r->next;
56  d->data.param = SPA_PTROFF(d->builder->data, offset, struct spa_pod);
57 }
58 
59 /* static */ inline int spa_node_enum_params_sync(struct spa_node *node,
60  uint32_t id, uint32_t *index,
61  const struct spa_pod *filter,
62  struct spa_pod **param,
63  struct spa_pod_builder *builder)
64 {
66  struct spa_hook listener = { 0 };
67  static const struct spa_node_events node_events = {
70  };
71  int res;
72 
73  res = spa_node_add_listener(node, &listener, &node_events, &data);
74  if (res >= 0) {
75  res = spa_node_enum_params(node, 0, id, *index, 1, filter);
76  spa_hook_remove(&listener);
77  }
78 
79  if (data.data.param == NULL) {
80  if (res > 0)
81  res = 0;
82  } else {
83  *index = data.data.next;
84  *param = data.data.param;
85  res = 1;
86  }
87  return res;
88 }
89 
90 /* static */ inline int spa_node_port_enum_params_sync(struct spa_node *node,
91  enum spa_direction direction, uint32_t port_id,
92  uint32_t id, uint32_t *index,
93  const struct spa_pod *filter,
94  struct spa_pod **param,
95  struct spa_pod_builder *builder)
96 {
98  struct spa_hook listener = { 0 };
99  static const struct spa_node_events node_events = {
101  .result = spa_result_func_node_params,
102  };
103  int res;
104 
105  res = spa_node_add_listener(node, &listener, &node_events, &data);
106  if (res >= 0) {
107  res = spa_node_port_enum_params(node, 0, direction, port_id,
108  id, *index, 1, filter);
109  spa_hook_remove(&listener);
110  }
111 
112  if (data.data.param == NULL) {
113  if (res > 0)
114  res = 0;
115  } else {
116  *index = data.data.next;
117  *param = data.data.param;
118  res = 1;
119  }
120  return res;
121 }
122 
123 #define spa_node_emit(hooks,method,version,...) \
124  spa_hook_list_call_simple(hooks, struct spa_node_events, \
125  method, version, ##__VA_ARGS__)
126 
127 #define spa_node_emit_info(hooks,...) spa_node_emit(hooks,info, 0, __VA_ARGS__)
128 #define spa_node_emit_port_info(hooks,...) spa_node_emit(hooks,port_info, 0, __VA_ARGS__)
129 #define spa_node_emit_result(hooks,...) spa_node_emit(hooks,result, 0, __VA_ARGS__)
130 #define spa_node_emit_event(hooks,...) spa_node_emit(hooks,event, 0, __VA_ARGS__)
131 
132 
133 #define spa_node_call(callbacks,method,version,...) \
134 ({ \
135  int _res = -ENOTSUP; \
136  spa_callbacks_call_res(callbacks, struct spa_node_callbacks, \
137  _res, method, version, ##__VA_ARGS__); \
138  _res; \
139 })
140 
141 #define spa_node_call_ready(hook,...) spa_node_call(hook, ready, 0, __VA_ARGS__)
142 #define spa_node_call_reuse_buffer(hook,...) spa_node_call(hook, reuse_buffer, 0, __VA_ARGS__)
143 #define spa_node_call_xrun(hook,...) spa_node_call(hook, xrun, 0, __VA_ARGS__)
144 
149 #ifdef __cplusplus
150 } /* extern "C" */
151 #endif
152 
153 #endif /* SPA_NODE_UTILS_H */
static uint32_t int int res
Definition: core.h:329
static uint32_t int int const char int r
Definition: core.h:341
static uint32_t int seq
Definition: core.h:328
void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition: hook.h:117
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: output/doc/spa/node/utils.h:59
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: output/doc/spa/node/utils.h:90
#define spa_node_add_listener(n,...)
Definition: output/doc/spa/node/node.h:647
#define spa_node_port_enum_params(n,...)
Definition: output/doc/spa/node/node.h:656
void spa_result_func_node_params(void *data, int seq, int res, uint32_t type, const void *result)
Definition: output/doc/spa/node/utils.h:46
#define spa_node_enum_params(n,...)
Definition: output/doc/spa/node/node.h:650
int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition: builder.h:167
#define SPA_POD_SIZE(pod)
Definition: pod/pod.h:42
spa_direction
Definition: defs.h:77
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition: defs.h:158
#define SPA_VERSION_NODE_EVENTS
Definition: output/doc/spa/node/node.h:156
Definition: filter.c:75
Definition: filter.c:124
Definition: filter.c:80
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:76
events from the spa_node.
Definition: output/doc/spa/node/node.h:155
Definition: output/doc/spa/node/node.h:52
uint32_t offset
Definition: builder.h:47
Definition: builder.h:63
void * data
Definition: builder.h:64
struct spa_pod_builder_state state
Definition: builder.h:67
Definition: pod/pod.h:50
Definition: output/doc/spa/node/utils.h:41
struct spa_result_node_params data
Definition: output/doc/spa/node/utils.h:43
struct spa_pod_builder * builder
Definition: output/doc/spa/node/utils.h:42
the result of enum_params or port_enum_params.
Definition: output/doc/spa/node/node.h:136
struct spa_pod * param
the result param
Definition: output/doc/spa/node/node.h:140
uint32_t next
next index of iteration
Definition: output/doc/spa/node/node.h:139
uint32_t index
index of parameter
Definition: output/doc/spa/node/node.h:138