PipeWire  0.3.59
node.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2018 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_H
26 #define SPA_NODE_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
42 #include <errno.h>
43 #include <spa/utils/defs.h>
44 #include <spa/utils/type.h>
45 #include <spa/utils/hook.h>
46 #include <spa/buffer/buffer.h>
47 #include <spa/node/event.h>
48 #include <spa/node/command.h>
49 
50 
51 #define SPA_TYPE_INTERFACE_Node SPA_TYPE_INFO_INTERFACE_BASE "Node"
52 
53 #define SPA_VERSION_NODE 0
54 struct spa_node { struct spa_interface iface; };
55 
61 struct spa_node_info {
62  uint32_t max_input_ports;
63  uint32_t max_output_ports;
64 #define SPA_NODE_CHANGE_MASK_FLAGS (1u<<0)
65 #define SPA_NODE_CHANGE_MASK_PROPS (1u<<1)
66 #define SPA_NODE_CHANGE_MASK_PARAMS (1u<<2)
67  uint64_t change_mask;
68 
69 #define SPA_NODE_FLAG_RT (1u<<0)
70 #define SPA_NODE_FLAG_IN_DYNAMIC_PORTS (1u<<1)
71 #define SPA_NODE_FLAG_OUT_DYNAMIC_PORTS (1u<<2)
72 #define SPA_NODE_FLAG_IN_PORT_CONFIG (1u<<3)
74 #define SPA_NODE_FLAG_OUT_PORT_CONFIG (1u<<4)
76 #define SPA_NODE_FLAG_NEED_CONFIGURE (1u<<5)
78 #define SPA_NODE_FLAG_ASYNC (1u<<6)
82  uint64_t flags;
83  struct spa_dict *props;
85  uint32_t n_params;
86 };
87 
88 #define SPA_NODE_INFO_INIT() ((struct spa_node_info) { 0, })
89 
95 struct spa_port_info {
96 #define SPA_PORT_CHANGE_MASK_FLAGS (1u<<0)
97 #define SPA_PORT_CHANGE_MASK_RATE (1u<<1)
98 #define SPA_PORT_CHANGE_MASK_PROPS (1u<<2)
99 #define SPA_PORT_CHANGE_MASK_PARAMS (1u<<3)
100  uint64_t change_mask;
101 
102 #define SPA_PORT_FLAG_REMOVABLE (1u<<0)
103 #define SPA_PORT_FLAG_OPTIONAL (1u<<1)
104 #define SPA_PORT_FLAG_CAN_ALLOC_BUFFERS (1u<<2)
105 #define SPA_PORT_FLAG_IN_PLACE (1u<<3)
107 #define SPA_PORT_FLAG_NO_REF (1u<<4)
111 #define SPA_PORT_FLAG_LIVE (1u<<5)
113 #define SPA_PORT_FLAG_PHYSICAL (1u<<6)
114 #define SPA_PORT_FLAG_TERMINAL (1u<<7)
117 #define SPA_PORT_FLAG_DYNAMIC_DATA (1u<<8)
120  uint64_t flags;
122  const struct spa_dict *props;
123  struct spa_param_info *params;
124  uint32_t n_params;
125 };
126 
127 #define SPA_PORT_INFO_INIT() ((struct spa_port_info) { 0, })
128 
129 #define SPA_RESULT_TYPE_NODE_ERROR 1
130 #define SPA_RESULT_TYPE_NODE_PARAMS 2
131 
133 struct spa_result_node_error {
134  const char *message;
135 };
136 
138 struct spa_result_node_params {
139  uint32_t id;
140  uint32_t index;
141  uint32_t next;
142  struct spa_pod *param;
143 };
144 
145 #define SPA_NODE_EVENT_INFO 0
146 #define SPA_NODE_EVENT_PORT_INFO 1
147 #define SPA_NODE_EVENT_RESULT 2
148 #define SPA_NODE_EVENT_EVENT 3
149 #define SPA_NODE_EVENT_NUM 4
150 
157 struct spa_node_events {
158 #define SPA_VERSION_NODE_EVENTS 0
159  uint32_t version;
162  void (*info) (void *data, const struct spa_node_info *info);
163 
165  void (*port_info) (void *data,
166  enum spa_direction direction, uint32_t port,
167  const struct spa_port_info *info);
168 
185  void (*result) (void *data, int seq, int res,
186  uint32_t type, const void *result);
187 
195  void (*event) (void *data, const struct spa_event *event);
196 };
197 
198 #define SPA_NODE_CALLBACK_READY 0
199 #define SPA_NODE_CALLBACK_REUSE_BUFFER 1
200 #define SPA_NODE_CALLBACK_XRUN 2
201 #define SPA_NODE_CALLBACK_NUM 3
202 
208 struct spa_node_callbacks {
209 #define SPA_VERSION_NODE_CALLBACKS 0
210  uint32_t version;
219  int (*ready) (void *data, int state);
220 
231  int (*reuse_buffer) (void *data,
232  uint32_t port_id,
233  uint32_t buffer_id);
234 
245  int (*xrun) (void *data, uint64_t trigger, uint64_t delay,
246  struct spa_pod *info);
247 };
248 
249 
251 #define SPA_NODE_PARAM_FLAG_TEST_ONLY (1 << 0)
252 #define SPA_NODE_PARAM_FLAG_FIXATE (1 << 1)
253 #define SPA_NODE_PARAM_FLAG_NEAREST (1 << 2)
257 #define SPA_NODE_BUFFERS_FLAG_ALLOC (1 << 0)
262 #define SPA_NODE_METHOD_ADD_LISTENER 0
263 #define SPA_NODE_METHOD_SET_CALLBACKS 1
264 #define SPA_NODE_METHOD_SYNC 2
265 #define SPA_NODE_METHOD_ENUM_PARAMS 3
266 #define SPA_NODE_METHOD_SET_PARAM 4
267 #define SPA_NODE_METHOD_SET_IO 5
268 #define SPA_NODE_METHOD_SEND_COMMAND 6
269 #define SPA_NODE_METHOD_ADD_PORT 7
270 #define SPA_NODE_METHOD_REMOVE_PORT 8
271 #define SPA_NODE_METHOD_PORT_ENUM_PARAMS 9
272 #define SPA_NODE_METHOD_PORT_SET_PARAM 10
273 #define SPA_NODE_METHOD_PORT_USE_BUFFERS 11
274 #define SPA_NODE_METHOD_PORT_SET_IO 12
275 #define SPA_NODE_METHOD_PORT_REUSE_BUFFER 13
276 #define SPA_NODE_METHOD_PROCESS 14
277 #define SPA_NODE_METHOD_NUM 15
278 
282 struct spa_node_methods {
283  /* the version of the node methods. This can be used to expand this
284  * structure in the future */
285 #define SPA_VERSION_NODE_METHODS 0
286  uint32_t version;
287 
302  int (*add_listener) (void *object,
303  struct spa_hook *listener,
304  const struct spa_node_events *events,
305  void *data);
319  int (*set_callbacks) (void *object,
320  const struct spa_node_callbacks *callbacks,
321  void *data);
337  int (*sync) (void *object, int seq);
338 
370  int (*enum_params) (void *object, int seq,
371  uint32_t id, uint32_t start, uint32_t max,
372  const struct spa_pod *filter);
373 
395  int (*set_param) (void *object,
396  uint32_t id, uint32_t flags,
397  const struct spa_pod *param);
398 
417  int (*set_io) (void *object,
418  uint32_t id, void *data, size_t size);
419 
434  int (*send_command) (void *object, const struct spa_command *command);
435 
452  int (*add_port) (void *object,
453  enum spa_direction direction, uint32_t port_id,
454  const struct spa_dict *props);
455 
466  int (*remove_port) (void *object,
467  enum spa_direction direction, uint32_t port_id);
468 
499  int (*port_enum_params) (void *object, int seq,
500  enum spa_direction direction, uint32_t port_id,
501  uint32_t id, uint32_t start, uint32_t max,
502  const struct spa_pod *filter);
527  int (*port_set_param) (void *object,
528  enum spa_direction direction,
529  uint32_t port_id,
530  uint32_t id, uint32_t flags,
531  const struct spa_pod *param);
532 
573  int (*port_use_buffers) (void *object,
574  enum spa_direction direction,
575  uint32_t port_id,
576  uint32_t flags,
577  struct spa_buffer **buffers,
578  uint32_t n_buffers);
579 
600  int (*port_set_io) (void *object,
601  enum spa_direction direction,
602  uint32_t port_id,
603  uint32_t id,
604  void *data, size_t size);
605 
617  int (*port_reuse_buffer) (void *object, uint32_t port_id, uint32_t buffer_id);
618 
642  int (*process) (void *object);
643 };
644 
645 #define spa_node_method(o,method,version,...) \
646 ({ \
647  int _res = -ENOTSUP; \
648  struct spa_node *_n = o; \
649  spa_interface_call_res(&_n->iface, \
650  struct spa_node_methods, _res, \
651  method, version, ##__VA_ARGS__); \
652  _res; \
653 })
654 
655 #define spa_node_add_listener(n,...) spa_node_method(n, add_listener, 0, __VA_ARGS__)
656 #define spa_node_set_callbacks(n,...) spa_node_method(n, set_callbacks, 0, __VA_ARGS__)
657 #define spa_node_sync(n,...) spa_node_method(n, sync, 0, __VA_ARGS__)
658 #define spa_node_enum_params(n,...) spa_node_method(n, enum_params, 0, __VA_ARGS__)
659 #define spa_node_set_param(n,...) spa_node_method(n, set_param, 0, __VA_ARGS__)
660 #define spa_node_set_io(n,...) spa_node_method(n, set_io, 0, __VA_ARGS__)
661 #define spa_node_send_command(n,...) spa_node_method(n, send_command, 0, __VA_ARGS__)
662 #define spa_node_add_port(n,...) spa_node_method(n, add_port, 0, __VA_ARGS__)
663 #define spa_node_remove_port(n,...) spa_node_method(n, remove_port, 0, __VA_ARGS__)
664 #define spa_node_port_enum_params(n,...) spa_node_method(n, port_enum_params, 0, __VA_ARGS__)
665 #define spa_node_port_set_param(n,...) spa_node_method(n, port_set_param, 0, __VA_ARGS__)
666 #define spa_node_port_use_buffers(n,...) spa_node_method(n, port_use_buffers, 0, __VA_ARGS__)
667 #define spa_node_port_set_io(n,...) spa_node_method(n, port_set_io, 0, __VA_ARGS__)
668 
669 #define spa_node_port_reuse_buffer(n,...) spa_node_method(n, port_reuse_buffer, 0, __VA_ARGS__)
670 #define spa_node_process(n) spa_node_method(n, process, 0)
671 
676 #ifdef __cplusplus
677 } /* extern "C" */
678 #endif
679 
680 #endif /* SPA_NODE_H */
spa/buffer/buffer.h
spa/utils/defs.h
spa_direction
Definition: defs.h:108
spa/utils/hook.h
spa/node/command.h
spa/node/event.h
spa/utils/type.h
A Buffer.
Definition: buffer.h:109
Definition: command.h:49
Definition: dict.h:59
Definition: event.h:48
Definition: defs.h:139
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:351
Definition: hook.h:158
Node callbacks.
Definition: node.h:252
uint32_t version
Definition: node.h:255
int(* ready)(void *data, int state)
Definition: node.h:264
int(* reuse_buffer)(void *data, uint32_t port_id, uint32_t buffer_id)
Definition: node.h:276
int(* xrun)(void *data, uint64_t trigger, uint64_t delay, struct spa_pod *info)
Definition: node.h:290
events from the spa_node.
Definition: node.h:196
uint32_t version
version of this structure
Definition: node.h:199
void(* event)(void *data, const struct spa_event *event)
Definition: node.h:235
void(* result)(void *data, int seq, int res, uint32_t type, const void *result)
notify a result.
Definition: node.h:225
void(* info)(void *data, const struct spa_node_info *info)
Emitted when info changes.
Definition: node.h:202
void(* port_info)(void *data, enum spa_direction direction, uint32_t port, const struct spa_port_info *info)
Emitted when port info changes, NULL when port is removed.
Definition: node.h:205
Node information structure.
Definition: node.h:68
struct spa_param_info * params
parameter information
Definition: node.h:101
uint64_t flags
Definition: node.h:99
uint32_t n_params
number of items in params
Definition: node.h:102
uint32_t max_output_ports
Definition: node.h:70
uint64_t change_mask
Definition: node.h:77
uint32_t max_input_ports
Definition: node.h:69
Node methods.
Definition: node.h:347
int(* set_param)(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param)
Set the configurable parameter in node.
Definition: node.h:461
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)
Enumerate all possible parameters of id on port_id of node that are compatible with filter.
Definition: node.h:565
int(* port_set_io)(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, void *data, size_t size)
Configure the given memory area with id on port_id.
Definition: node.h:666
int(* process)(void *object)
Process the node.
Definition: node.h:708
int(* port_use_buffers)(void *object, enum spa_direction direction, uint32_t port_id, uint32_t flags, struct spa_buffer **buffers, uint32_t n_buffers)
Tell the port to use the given buffers.
Definition: node.h:639
int(* add_listener)(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data)
Adds an event listener on node.
Definition: node.h:368
int(* sync)(void *object, int seq)
Perform a sync operation.
Definition: node.h:403
int(* add_port)(void *object, enum spa_direction direction, uint32_t port_id, const struct spa_dict *props)
Make a new port with port_id.
Definition: node.h:518
int(* enum_params)(void *object, int seq, uint32_t id, uint32_t start, uint32_t max, const struct spa_pod *filter)
Enumerate the parameters of a node.
Definition: node.h:436
int(* set_callbacks)(void *object, const struct spa_node_callbacks *callbacks, void *data)
Set callbacks to on node.
Definition: node.h:385
uint32_t version
Definition: node.h:352
int(* set_io)(void *object, uint32_t id, void *data, size_t size)
Configure the given memory area with id on node.
Definition: node.h:483
int(* port_reuse_buffer)(void *object, uint32_t port_id, uint32_t buffer_id)
Tell an output port to reuse a buffer.
Definition: node.h:683
int(* remove_port)(void *object, enum spa_direction direction, uint32_t port_id)
Remove a port with port_id.
Definition: node.h:532
int(* send_command)(void *object, const struct spa_command *command)
Send a command to a node.
Definition: node.h:500
int(* port_set_param)(void *object, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t flags, const struct spa_pod *param)
Set a parameter on port_id of node.
Definition: node.h:593
Definition: node.h:61
struct spa_interface iface
Definition: node.h:61
information about a parameter
Definition: param.h:70
Definition: pod.h:63
uint32_t size
Definition: pod.h:64
Port information structure.
Definition: node.h:113
uint64_t flags
port flags
Definition: node.h:151
struct spa_fraction rate
rate of sequence numbers on port
Definition: node.h:152
struct spa_param_info * params
parameter information
Definition: node.h:154
uint64_t change_mask
Definition: node.h:122
uint32_t n_params
number of items in params
Definition: node.h:155
an error result
Definition: node.h:167
const char * message
Definition: node.h:168
the result of enum_params or port_enum_params.
Definition: node.h:172
struct spa_pod * param
the result param
Definition: node.h:176
uint32_t next
next index of iteration
Definition: node.h:175
uint32_t index
index of parameter
Definition: node.h:174
uint32_t id
id of parameter
Definition: node.h:173