PipeWire  0.3.29
output/doc/spa/node/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 
41 #include <spa/utils/defs.h>
42 #include <spa/utils/type.h>
43 #include <spa/utils/hook.h>
44 #include <spa/buffer/buffer.h>
45 #include <spa/node/event.h>
46 #include <spa/node/command.h>
47 
48 
49 #define SPA_TYPE_INTERFACE_Node SPA_TYPE_INFO_INTERFACE_BASE "Node"
50 
51 #define SPA_VERSION_NODE 0
52 struct spa_node { struct spa_interface iface; };
53 
59 struct spa_node_info {
60  uint32_t max_input_ports;
61  uint32_t max_output_ports;
62 #define SPA_NODE_CHANGE_MASK_FLAGS (1u<<0)
63 #define SPA_NODE_CHANGE_MASK_PROPS (1u<<1)
64 #define SPA_NODE_CHANGE_MASK_PARAMS (1u<<2)
65  uint64_t change_mask;
66 
67 #define SPA_NODE_FLAG_RT (1u<<0)
68 #define SPA_NODE_FLAG_IN_DYNAMIC_PORTS (1u<<1)
69 #define SPA_NODE_FLAG_OUT_DYNAMIC_PORTS (1u<<2)
70 #define SPA_NODE_FLAG_IN_PORT_CONFIG (1u<<3)
72 #define SPA_NODE_FLAG_OUT_PORT_CONFIG (1u<<4)
74 #define SPA_NODE_FLAG_NEED_CONFIGURE (1u<<5)
76 #define SPA_NODE_FLAG_ASYNC (1u<<6)
80  uint64_t flags;
81  struct spa_dict *props;
83  uint32_t n_params;
84 };
85 
86 #define SPA_NODE_INFO_INIT() (struct spa_node_info) { 0, }
87 
93 struct spa_port_info {
94 #define SPA_PORT_CHANGE_MASK_FLAGS (1u<<0)
95 #define SPA_PORT_CHANGE_MASK_RATE (1u<<1)
96 #define SPA_PORT_CHANGE_MASK_PROPS (1u<<2)
97 #define SPA_PORT_CHANGE_MASK_PARAMS (1u<<3)
98  uint64_t change_mask;
99 
100 #define SPA_PORT_FLAG_REMOVABLE (1u<<0)
101 #define SPA_PORT_FLAG_OPTIONAL (1u<<1)
102 #define SPA_PORT_FLAG_CAN_ALLOC_BUFFERS (1u<<2)
103 #define SPA_PORT_FLAG_IN_PLACE (1u<<3)
105 #define SPA_PORT_FLAG_NO_REF (1u<<4)
109 #define SPA_PORT_FLAG_LIVE (1u<<5)
111 #define SPA_PORT_FLAG_PHYSICAL (1u<<6)
112 #define SPA_PORT_FLAG_TERMINAL (1u<<7)
115 #define SPA_PORT_FLAG_DYNAMIC_DATA (1u<<8)
118  uint64_t flags;
119  struct spa_fraction rate;
120  const struct spa_dict *props;
122  uint32_t n_params;
123 };
124 
125 #define SPA_PORT_INFO_INIT() (struct spa_port_info) { 0, }
126 
127 #define SPA_RESULT_TYPE_NODE_ERROR 1
128 #define SPA_RESULT_TYPE_NODE_PARAMS 2
129 
132  const char *message;
133 };
134 
137  uint32_t id;
138  uint32_t index;
139  uint32_t next;
140  struct spa_pod *param;
141 };
142 
143 #define SPA_NODE_EVENT_INFO 0
144 #define SPA_NODE_EVENT_PORT_INFO 1
145 #define SPA_NODE_EVENT_RESULT 2
146 #define SPA_NODE_EVENT_EVENT 3
147 #define SPA_NODE_EVENT_NUM 4
148 
156 #define SPA_VERSION_NODE_EVENTS 0
157  uint32_t version;
160  void (*info) (void *data, const struct spa_node_info *info);
161 
163  void (*port_info) (void *data,
164  enum spa_direction direction, uint32_t port,
165  const struct spa_port_info *info);
166 
183  void (*result) (void *data, int seq, int res,
184  uint32_t type, const void *result);
185 
193  void (*event) (void *data, const struct spa_event *event);
194 };
195 
196 #define SPA_NODE_CALLBACK_READY 0
197 #define SPA_NODE_CALLBACK_REUSE_BUFFER 1
198 #define SPA_NODE_CALLBACK_XRUN 2
199 #define SPA_NODE_CALLBACK_NUM 3
200 
207 #define SPA_VERSION_NODE_CALLBACKS 0
208  uint32_t version;
217  int (*ready) (void *data, int state);
218 
229  int (*reuse_buffer) (void *data,
230  uint32_t port_id,
231  uint32_t buffer_id);
232 
243  int (*xrun) (void *data, uint64_t trigger, uint64_t delay,
244  struct spa_pod *info);
245 };
246 
247 
249 #define SPA_NODE_PARAM_FLAG_TEST_ONLY (1 << 0)
250 #define SPA_NODE_PARAM_FLAG_FIXATE (1 << 1)
251 #define SPA_NODE_PARAM_FLAG_NEAREST (1 << 2)
255 #define SPA_NODE_BUFFERS_FLAG_ALLOC (1 << 0)
260 #define SPA_NODE_METHOD_ADD_LISTENER 0
261 #define SPA_NODE_METHOD_SET_CALLBACKS 1
262 #define SPA_NODE_METHOD_SYNC 2
263 #define SPA_NODE_METHOD_ENUM_PARAMS 3
264 #define SPA_NODE_METHOD_SET_PARAM 4
265 #define SPA_NODE_METHOD_SET_IO 5
266 #define SPA_NODE_METHOD_SEND_COMMAND 6
267 #define SPA_NODE_METHOD_ADD_PORT 7
268 #define SPA_NODE_METHOD_REMOVE_PORT 8
269 #define SPA_NODE_METHOD_PORT_ENUM_PARAMS 9
270 #define SPA_NODE_METHOD_PORT_SET_PARAM 10
271 #define SPA_NODE_METHOD_PORT_USE_BUFFERS 11
272 #define SPA_NODE_METHOD_PORT_SET_IO 12
273 #define SPA_NODE_METHOD_PORT_REUSE_BUFFER 13
274 #define SPA_NODE_METHOD_PROCESS 14
275 #define SPA_NODE_METHOD_NUM 15
276 
281  /* the version of the node methods. This can be used to expand this
282  * structure in the future */
283 #define SPA_VERSION_NODE_METHODS 0
284  uint32_t version;
285 
300  int (*add_listener) (void *object,
301  struct spa_hook *listener,
302  const struct spa_node_events *events,
303  void *data);
317  int (*set_callbacks) (void *object,
318  const struct spa_node_callbacks *callbacks,
319  void *data);
335  int (*sync) (void *object, int seq);
336 
368  int (*enum_params) (void *object, int seq,
369  uint32_t id, uint32_t start, uint32_t max,
370  const struct spa_pod *filter);
371 
393  int (*set_param) (void *object,
394  uint32_t id, uint32_t flags,
395  const struct spa_pod *param);
396 
415  int (*set_io) (void *object,
416  uint32_t id, void *data, size_t size);
417 
432  int (*send_command) (void *object, const struct spa_command *command);
433 
450  int (*add_port) (void *object,
451  enum spa_direction direction, uint32_t port_id,
452  const struct spa_dict *props);
453 
464  int (*remove_port) (void *object,
465  enum spa_direction direction, uint32_t port_id);
466 
497  int (*port_enum_params) (void *object, int seq,
498  enum spa_direction direction, uint32_t port_id,
499  uint32_t id, uint32_t start, uint32_t max,
500  const struct spa_pod *filter);
525  int (*port_set_param) (void *object,
526  enum spa_direction direction,
527  uint32_t port_id,
528  uint32_t id, uint32_t flags,
529  const struct spa_pod *param);
530 
571  int (*port_use_buffers) (void *object,
572  enum spa_direction direction,
573  uint32_t port_id,
574  uint32_t flags,
575  struct spa_buffer **buffers,
576  uint32_t n_buffers);
577 
598  int (*port_set_io) (void *object,
599  enum spa_direction direction,
600  uint32_t port_id,
601  uint32_t id,
602  void *data, size_t size);
603 
615  int (*port_reuse_buffer) (void *object, uint32_t port_id, uint32_t buffer_id);
616 
634  int (*process) (void *object);
635 };
636 
637 #define spa_node_method(o,method,version,...) \
638 ({ \
639  int _res = -ENOTSUP; \
640  struct spa_node *_n = o; \
641  spa_interface_call_res(&_n->iface, \
642  struct spa_node_methods, _res, \
643  method, version, ##__VA_ARGS__); \
644  _res; \
645 })
646 
647 #define spa_node_add_listener(n,...) spa_node_method(n, add_listener, 0, __VA_ARGS__)
648 #define spa_node_set_callbacks(n,...) spa_node_method(n, set_callbacks, 0, __VA_ARGS__)
649 #define spa_node_sync(n,...) spa_node_method(n, sync, 0, __VA_ARGS__)
650 #define spa_node_enum_params(n,...) spa_node_method(n, enum_params, 0, __VA_ARGS__)
651 #define spa_node_set_param(n,...) spa_node_method(n, set_param, 0, __VA_ARGS__)
652 #define spa_node_set_io(n,...) spa_node_method(n, set_io, 0, __VA_ARGS__)
653 #define spa_node_send_command(n,...) spa_node_method(n, send_command, 0, __VA_ARGS__)
654 #define spa_node_add_port(n,...) spa_node_method(n, add_port, 0, __VA_ARGS__)
655 #define spa_node_remove_port(n,...) spa_node_method(n, remove_port, 0, __VA_ARGS__)
656 #define spa_node_port_enum_params(n,...) spa_node_method(n, port_enum_params, 0, __VA_ARGS__)
657 #define spa_node_port_set_param(n,...) spa_node_method(n, port_set_param, 0, __VA_ARGS__)
658 #define spa_node_port_use_buffers(n,...) spa_node_method(n, port_use_buffers, 0, __VA_ARGS__)
659 #define spa_node_port_set_io(n,...) spa_node_method(n, port_set_io, 0, __VA_ARGS__)
660 
661 #define spa_node_port_reuse_buffer(n,...) spa_node_method(n, port_reuse_buffer, 0, __VA_ARGS__)
662 #define spa_node_process(n) spa_node_method(n, process, 0)
663 
668 #ifdef __cplusplus
669 } /* extern "C" */
670 #endif
671 
672 #endif /* SPA_NODE_H */
static uint32_t int int res
Definition: core.h:329
static uint32_t int seq
Definition: core.h:328
static uint32_t id
Definition: core.h:328
spa_direction
Definition: defs.h:77
Definition: filter.c:75
Definition: filter.c:124
Definition: filter.c:80
Definition: buffers.c:44
A Buffer.
Definition: buffer/buffer.h:93
Definition: pod/command.h:44
Definition: utils/dict.h:48
Definition: pod/event.h:43
Definition: defs.h:103
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:76
Definition: hook.h:65
Node callbacks.
Definition: output/doc/spa/node/node.h:206
uint32_t version
Definition: output/doc/spa/node/node.h:208
int(* ready)(void *data, int state)
Definition: output/doc/spa/node/node.h:217
int(* reuse_buffer)(void *data, uint32_t port_id, uint32_t buffer_id)
Definition: output/doc/spa/node/node.h:229
int(* xrun)(void *data, uint64_t trigger, uint64_t delay, struct spa_pod *info)
Definition: output/doc/spa/node/node.h:243
events from the spa_node.
Definition: output/doc/spa/node/node.h:155
uint32_t version
version of this structure
Definition: output/doc/spa/node/node.h:157
void(* event)(void *data, const struct spa_event *event)
Definition: output/doc/spa/node/node.h:193
void(* result)(void *data, int seq, int res, uint32_t type, const void *result)
notify a result.
Definition: output/doc/spa/node/node.h:183
void(* info)(void *data, const struct spa_node_info *info)
Emitted when info changes.
Definition: output/doc/spa/node/node.h:160
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: output/doc/spa/node/node.h:163
Node information structure.
Definition: output/doc/spa/node/node.h:59
struct spa_param_info * params
parameter information
Definition: output/doc/spa/node/node.h:82
uint64_t flags
Definition: output/doc/spa/node/node.h:80
uint32_t n_params
number of items in params
Definition: output/doc/spa/node/node.h:83
uint32_t max_output_ports
Definition: output/doc/spa/node/node.h:61
uint64_t change_mask
Definition: output/doc/spa/node/node.h:65
struct spa_dict * props
extra node properties
Definition: output/doc/spa/node/node.h:81
uint32_t max_input_ports
Definition: output/doc/spa/node/node.h:60
Node methods.
Definition: output/doc/spa/node/node.h:280
int(* set_param)(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param)
Set the configurable parameter in node.
Definition: output/doc/spa/node/node.h:393
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: output/doc/spa/node/node.h:497
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: output/doc/spa/node/node.h:598
int(* process)(void *object)
Process the node.
Definition: output/doc/spa/node/node.h:634
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: output/doc/spa/node/node.h:571
int(* add_listener)(void *object, struct spa_hook *listener, const struct spa_node_events *events, void *data)
Adds an event listener on node.
Definition: output/doc/spa/node/node.h:300
int(* sync)(void *object, int seq)
Perform a sync operation.
Definition: output/doc/spa/node/node.h:335
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: output/doc/spa/node/node.h:450
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: output/doc/spa/node/node.h:368
int(* set_callbacks)(void *object, const struct spa_node_callbacks *callbacks, void *data)
Set callbacks to on node.
Definition: output/doc/spa/node/node.h:317
uint32_t version
Definition: output/doc/spa/node/node.h:284
int(* set_io)(void *object, uint32_t id, void *data, size_t size)
Configure the given memory area with id on node.
Definition: output/doc/spa/node/node.h:415
int(* port_reuse_buffer)(void *object, uint32_t port_id, uint32_t buffer_id)
Tell an output port to reuse a buffer.
Definition: output/doc/spa/node/node.h:615
int(* remove_port)(void *object, enum spa_direction direction, uint32_t port_id)
Remove a port with port_id.
Definition: output/doc/spa/node/node.h:464
int(* send_command)(void *object, const struct spa_command *command)
Send a command to a node.
Definition: output/doc/spa/node/node.h:432
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: output/doc/spa/node/node.h:525
Definition: output/doc/spa/node/node.h:52
struct spa_interface iface
Definition: output/doc/spa/node/node.h:52
information about a parameter
Definition: param.h:63
Definition: pod/pod.h:50
uint32_t size
Definition: pod/pod.h:51
Port information structure.
Definition: output/doc/spa/node/node.h:93
uint64_t flags
port flags
Definition: output/doc/spa/node/node.h:118
struct spa_fraction rate
rate of sequence numbers on port
Definition: output/doc/spa/node/node.h:119
struct spa_param_info * params
parameter information
Definition: output/doc/spa/node/node.h:121
uint64_t change_mask
Definition: output/doc/spa/node/node.h:98
uint32_t n_params
number of items in params
Definition: output/doc/spa/node/node.h:122
const struct spa_dict * props
extra port properties
Definition: output/doc/spa/node/node.h:120
an error result
Definition: output/doc/spa/node/node.h:131
const char * message
Definition: output/doc/spa/node/node.h:132
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
uint32_t id
id of parameter
Definition: output/doc/spa/node/node.h:137