PipeWire: spa/node/node.h Source File

PipeWire 0.3.50

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
29extern "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
54struct 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;
84 struct spa_param_info *params;
85 uint32_t n_params;
86};
87
88#define SPA_NODE_INFO_INIT() (struct spa_node_info) { 0, }
89
95struct 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;
121 struct spa_fraction rate;
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
133struct spa_result_node_error {
134 const char *message;
135};
136
138struct 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
157struct 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
208struct 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
282struct 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
636 int (*process) (void *object);
637};
638
639#define spa_node_method(o,method,version,...) \
640({ \
641 int _res = -ENOTSUP; \
642 struct spa_node *_n = o; \
643 spa_interface_call_res(&_n->iface, \
644 struct spa_node_methods, _res, \
645 method, version, ##__VA_ARGS__); \
646 _res; \
647})
648
649#define spa_node_add_listener(n,...) spa_node_method(n, add_listener, 0, __VA_ARGS__)
650#define spa_node_set_callbacks(n,...) spa_node_method(n, set_callbacks, 0, __VA_ARGS__)
651#define spa_node_sync(n,...) spa_node_method(n, sync, 0, __VA_ARGS__)
652#define spa_node_enum_params(n,...) spa_node_method(n, enum_params, 0, __VA_ARGS__)
653#define spa_node_set_param(n,...) spa_node_method(n, set_param, 0, __VA_ARGS__)
654#define spa_node_set_io(n,...) spa_node_method(n, set_io, 0, __VA_ARGS__)
655#define spa_node_send_command(n,...) spa_node_method(n, send_command, 0, __VA_ARGS__)
656#define spa_node_add_port(n,...) spa_node_method(n, add_port, 0, __VA_ARGS__)
657#define spa_node_remove_port(n,...) spa_node_method(n, remove_port, 0, __VA_ARGS__)
658#define spa_node_port_enum_params(n,...) spa_node_method(n, port_enum_params, 0, __VA_ARGS__)
659#define spa_node_port_set_param(n,...) spa_node_method(n, port_set_param, 0, __VA_ARGS__)
660#define spa_node_port_use_buffers(n,...) spa_node_method(n, port_use_buffers, 0, __VA_ARGS__)
661#define spa_node_port_set_io(n,...) spa_node_method(n, port_set_io, 0, __VA_ARGS__)
662
663#define spa_node_port_reuse_buffer(n,...) spa_node_method(n, port_reuse_buffer, 0, __VA_ARGS__)
664#define spa_node_process(n) spa_node_method(n, process, 0)
665
670#ifdef __cplusplus
671} /* extern "C" */
672#endif
673
674#endif /* SPA_NODE_H */
buffer.h
spa/buffer/buffer.h
defs.h
spa/utils/defs.h
spa_direction
spa_direction
Definition: defs.h:90
hook.h
spa/utils/hook.h
command.h
spa/node/command.h
event.h
spa/node/event.h
type.h
spa/utils/type.h
spa_buffer
A Buffer.
Definition: buffer.h:105
spa_command
Definition: command.h:49
spa_dict
Definition: dict.h:59
spa_event
Definition: event.h:48
spa_fraction
Definition: defs.h:121
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:351
spa_interface
Definition: hook.h:158
spa_node_callbacks
Node callbacks.
Definition: node.h:252
spa_node_callbacks::version
uint32_t version
Definition: node.h:255
spa_node_callbacks::ready
int(* ready)(void *data, int state)
Definition: node.h:264
spa_node_callbacks::reuse_buffer
int(* reuse_buffer)(void *data, uint32_t port_id, uint32_t buffer_id)
Definition: node.h:276
spa_node_callbacks::xrun
int(* xrun)(void *data, uint64_t trigger, uint64_t delay, struct spa_pod *info)
Definition: node.h:290
spa_node_events
events from the spa_node.
Definition: node.h:196
spa_node_events::version
uint32_t version
version of this structure
Definition: node.h:199
spa_node_events::event
void(* event)(void *data, const struct spa_event *event)
Definition: node.h:235
spa_node_events::result
void(* result)(void *data, int seq, int res, uint32_t type, const void *result)
notify a result.
Definition: node.h:225
spa_node_events::info
void(* info)(void *data, const struct spa_node_info *info)
Emitted when info changes.
Definition: node.h:202
spa_node_events::port_info
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
spa_node_info
Node information structure.
Definition: node.h:68
spa_node_info::params
struct spa_param_info * params
parameter information
Definition: node.h:101
spa_node_info::flags
uint64_t flags
Definition: node.h:99
spa_node_info::n_params
uint32_t n_params
number of items in params
Definition: node.h:102
spa_node_info::max_output_ports
uint32_t max_output_ports
Definition: node.h:70
spa_node_info::change_mask
uint64_t change_mask
Definition: node.h:77
spa_node_info::max_input_ports
uint32_t max_input_ports
Definition: node.h:69
spa_node_methods
Node methods.
Definition: node.h:347
spa_node_methods::set_param
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
spa_node_methods::port_enum_params
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
spa_node_methods::port_set_io
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
spa_node_methods::process
int(* process)(void *object)
Process the node.
Definition: node.h:702
spa_node_methods::port_use_buffers
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
spa_node_methods::add_listener
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
spa_node_methods::sync
int(* sync)(void *object, int seq)
Perform a sync operation.
Definition: node.h:403
spa_node_methods::add_port
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
spa_node_methods::enum_params
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
spa_node_methods::set_callbacks
int(* set_callbacks)(void *object, const struct spa_node_callbacks *callbacks, void *data)
Set callbacks to on node.
Definition: node.h:385
spa_node_methods::version
uint32_t version
Definition: node.h:352
spa_node_methods::set_io
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
spa_node_methods::port_reuse_buffer
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
spa_node_methods::remove_port
int(* remove_port)(void *object, enum spa_direction direction, uint32_t port_id)
Remove a port with port_id.
Definition: node.h:532
spa_node_methods::send_command
int(* send_command)(void *object, const struct spa_command *command)
Send a command to a node.
Definition: node.h:500
spa_node_methods::port_set_param
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
spa_node
Definition: node.h:61
spa_node::iface
struct spa_interface iface
Definition: node.h:61
spa_param_info
information about a parameter
Definition: param.h:70
spa_pod
Definition: pod.h:63
spa_pod::size
uint32_t size
Definition: pod.h:64
spa_port_info
Port information structure.
Definition: node.h:113
spa_port_info::flags
uint64_t flags
port flags
Definition: node.h:151
spa_port_info::rate
struct spa_fraction rate
rate of sequence numbers on port
Definition: node.h:152
spa_port_info::params
struct spa_param_info * params
parameter information
Definition: node.h:154
spa_port_info::change_mask
uint64_t change_mask
Definition: node.h:122
spa_port_info::n_params
uint32_t n_params
number of items in params
Definition: node.h:155
spa_result_node_error
an error result
Definition: node.h:167
spa_result_node_error::message
const char * message
Definition: node.h:168
spa_result_node_params
the result of enum_params or port_enum_params.
Definition: node.h:172
spa_result_node_params::param
struct spa_pod * param
the result param
Definition: node.h:176
spa_result_node_params::next
uint32_t next
next index of iteration
Definition: node.h:175
spa_result_node_params::index
uint32_t index
index of parameter
Definition: node.h:174
spa_result_node_params::id
uint32_t id
id of parameter
Definition: node.h:173