+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 1 | /* Simple Plugin API */ |
| 2 | /* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */ |
| 3 | /* SPDX-License-Identifier: MIT */ |
| 4 | |
| 5 | #ifndef SPA_NODE_H |
| 6 | #define SPA_NODE_H |
| 7 | |
| 8 | #include <errno.h> |
| 9 | #include <spa/utils/defs.h> |
| 10 | #include <spa/utils/type.h> |
| 11 | #include <spa/utils/hook.h> |
| 12 | #include <spa/buffer/buffer.h> |
| 13 | #include <spa/node/event.h> |
| 14 | #include <spa/node/command.h> |
| 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
| 20 | /** \defgroup spa_node Node |
| 21 | * |
| 22 | * A spa_node is a component that can consume and produce buffers. |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * \addtogroup spa_node |
| 27 | * \{ |
| 28 | */ |
| 29 | |
| 30 | #ifndef SPA_API_NODE |
| 31 | #ifdef SPA_API_IMPL |
| 32 | #define SPA_API_NODE SPA_API_IMPL |
| 33 | #else |
| 34 | #define SPA_API_NODE static inline |
| 35 | #endif |
| 36 | #endif |
| 37 | |
| 38 | |
| 39 | #define SPA_TYPE_INTERFACE_Node SPA_TYPE_INFO_INTERFACE_BASE "Node" |
| 40 | |
| 41 | #define SPA_VERSION_NODE 0 |
| 42 | struct spa_node { struct spa_interface iface; }; |
| 43 | |
| 44 | /** |
| 45 | * Node information structure |
| 46 | * |
| 47 | * Contains the basic node information. |
| 48 | */ |
| 49 | struct spa_node_info { |
| 50 | uint32_t max_input_ports; |
| 51 | uint32_t max_output_ports; |
| 52 | #define SPA_NODE_CHANGE_MASK_FLAGS (1u<<0) |
| 53 | #define SPA_NODE_CHANGE_MASK_PROPS (1u<<1) |
| 54 | #define SPA_NODE_CHANGE_MASK_PARAMS (1u<<2) |
| 55 | uint64_t change_mask; |
| 56 | |
| 57 | #define SPA_NODE_FLAG_RT (1u<<0) /**< node can do real-time processing */ |
| 58 | #define SPA_NODE_FLAG_IN_DYNAMIC_PORTS (1u<<1) /**< input ports can be added/removed */ |
| 59 | #define SPA_NODE_FLAG_OUT_DYNAMIC_PORTS (1u<<2) /**< output ports can be added/removed */ |
| 60 | #define SPA_NODE_FLAG_IN_PORT_CONFIG (1u<<3) /**< input ports can be reconfigured with |
| 61 | * PortConfig parameter */ |
| 62 | #define SPA_NODE_FLAG_OUT_PORT_CONFIG (1u<<4) /**< output ports can be reconfigured with |
| 63 | * PortConfig parameter */ |
| 64 | #define SPA_NODE_FLAG_NEED_CONFIGURE (1u<<5) /**< node needs configuration before it can |
| 65 | * be started. */ |
| 66 | #define SPA_NODE_FLAG_ASYNC (1u<<6) /**< the process function might not |
| 67 | * immediately produce or consume data |
| 68 | * but might offload the work to a worker |
| 69 | * thread. */ |
| 70 | uint64_t flags; |
| 71 | struct spa_dict *props; /**< extra node properties */ |
| 72 | struct spa_param_info *params; /**< parameter information */ |
| 73 | uint32_t n_params; /**< number of items in \a params */ |
| 74 | }; |
| 75 | |
| 76 | #define SPA_NODE_INFO_INIT() ((struct spa_node_info) { 0, }) |
| 77 | |
| 78 | /** |
| 79 | * Port information structure |
| 80 | * |
| 81 | * Contains the basic port information. |
| 82 | */ |
| 83 | struct spa_port_info { |
| 84 | #define SPA_PORT_CHANGE_MASK_FLAGS (1u<<0) |
| 85 | #define SPA_PORT_CHANGE_MASK_RATE (1u<<1) |
| 86 | #define SPA_PORT_CHANGE_MASK_PROPS (1u<<2) |
| 87 | #define SPA_PORT_CHANGE_MASK_PARAMS (1u<<3) |
| 88 | uint64_t change_mask; |
| 89 | |
| 90 | #define SPA_PORT_FLAG_REMOVABLE (1u<<0) /**< port can be removed */ |
| 91 | #define SPA_PORT_FLAG_OPTIONAL (1u<<1) /**< processing on port is optional */ |
| 92 | #define SPA_PORT_FLAG_CAN_ALLOC_BUFFERS (1u<<2) /**< the port can allocate buffer data */ |
| 93 | #define SPA_PORT_FLAG_IN_PLACE (1u<<3) /**< the port can process data in-place and |
| 94 | * will need a writable input buffer */ |
| 95 | #define SPA_PORT_FLAG_NO_REF (1u<<4) /**< the port does not keep a ref on the buffer. |
| 96 | * This means the node will always completely |
| 97 | * consume the input buffer and it will be |
| 98 | * recycled after process. */ |
| 99 | #define SPA_PORT_FLAG_LIVE (1u<<5) /**< output buffers from this port are |
| 100 | * timestamped against a live clock. */ |
| 101 | #define SPA_PORT_FLAG_PHYSICAL (1u<<6) /**< connects to some device */ |
| 102 | #define SPA_PORT_FLAG_TERMINAL (1u<<7) /**< data was not created from this port |
| 103 | * or will not be made available on another |
| 104 | * port */ |
| 105 | #define SPA_PORT_FLAG_DYNAMIC_DATA (1u<<8) /**< data pointer on buffers can be changed. |
| 106 | * Only the buffer data marked as DYNAMIC |
| 107 | * can be changed. */ |
| 108 | uint64_t flags; /**< port flags */ |
| 109 | struct spa_fraction rate; /**< rate of sequence numbers on port */ |
| 110 | const struct spa_dict *props; /**< extra port properties */ |
| 111 | struct spa_param_info *params; /**< parameter information */ |
| 112 | uint32_t n_params; /**< number of items in \a params */ |
| 113 | }; |
| 114 | |
| 115 | #define SPA_PORT_INFO_INIT() ((struct spa_port_info) { 0, }) |
| 116 | |
| 117 | #define SPA_RESULT_TYPE_NODE_ERROR 1 |
| 118 | #define SPA_RESULT_TYPE_NODE_PARAMS 2 |
| 119 | |
| 120 | /** an error result */ |
| 121 | struct spa_result_node_error { |
| 122 | const char *message; |
| 123 | }; |
| 124 | |
| 125 | /** the result of enum_params or port_enum_params. */ |
| 126 | struct spa_result_node_params { |
| 127 | uint32_t id; /**< id of parameter */ |
| 128 | uint32_t index; /**< index of parameter */ |
| 129 | uint32_t next; /**< next index of iteration */ |
| 130 | struct spa_pod *param; /**< the result param */ |
| 131 | }; |
| 132 | |
| 133 | #define SPA_NODE_EVENT_INFO 0 |
| 134 | #define SPA_NODE_EVENT_PORT_INFO 1 |
| 135 | #define SPA_NODE_EVENT_RESULT 2 |
| 136 | #define SPA_NODE_EVENT_EVENT 3 |
| 137 | #define SPA_NODE_EVENT_NUM 4 |
| 138 | |
| 139 | /** events from the spa_node. |
| 140 | * |
| 141 | * All event are called from the main thread and multiple |
| 142 | * listeners can be registered for the events with |
| 143 | * spa_node_add_listener(). |
| 144 | */ |
| 145 | struct spa_node_events { |
| 146 | #define SPA_VERSION_NODE_EVENTS 0 |
| 147 | uint32_t version; /**< version of this structure */ |
| 148 | |
| 149 | /** Emitted when info changes */ |
| 150 | void (*info) (void *data, const struct spa_node_info *info); |
| 151 | |
| 152 | /** Emitted when port info changes, NULL when port is removed */ |
| 153 | void (*port_info) (void *data, |
| 154 | enum spa_direction direction, uint32_t port, |
| 155 | const struct spa_port_info *info); |
| 156 | |
| 157 | /** notify a result. |
| 158 | * |
| 159 | * Some methods will trigger a result event with an optional |
| 160 | * result of the given type. Look at the documentation of the |
| 161 | * method to know when to expect a result event. |
| 162 | * |
| 163 | * The result event can be called synchronously, as an event |
| 164 | * called from inside the method itself, in which case the seq |
| 165 | * number passed to the method will be passed unchanged. |
| 166 | * |
| 167 | * The result event will be called asynchronously when the |
| 168 | * method returned an async return value. In this case, the seq |
| 169 | * number in the result will match the async return value of |
| 170 | * the method call. Users should match the seq number from |
| 171 | * request to the reply. |
| 172 | */ |
| 173 | void (*result) (void *data, int seq, int res, |
| 174 | uint32_t type, const void *result); |
| 175 | |
| 176 | /** |
| 177 | * \param node a spa_node |
| 178 | * \param event the event that was emitted |
| 179 | * |
| 180 | * This will be called when an out-of-bound event is notified |
| 181 | * on \a node. |
| 182 | */ |
| 183 | void (*event) (void *data, const struct spa_event *event); |
| 184 | }; |
| 185 | |
| 186 | #define SPA_NODE_CALLBACK_READY 0 |
| 187 | #define SPA_NODE_CALLBACK_REUSE_BUFFER 1 |
| 188 | #define SPA_NODE_CALLBACK_XRUN 2 |
| 189 | #define SPA_NODE_CALLBACK_NUM 3 |
| 190 | |
| 191 | /** Node callbacks |
| 192 | * |
| 193 | * Callbacks are called from the real-time data thread. Only |
| 194 | * one callback structure can be set on an spa_node. |
| 195 | */ |
| 196 | struct spa_node_callbacks { |
| 197 | #define SPA_VERSION_NODE_CALLBACKS 0 |
| 198 | uint32_t version; |
| 199 | /** |
| 200 | * \param node a spa_node |
| 201 | * |
| 202 | * The node is ready for processing. |
| 203 | * |
| 204 | * When this function is NULL, synchronous operation is requested |
| 205 | * on the ports. |
| 206 | */ |
| 207 | int (*ready) (void *data, int state); |
| 208 | |
| 209 | /** |
| 210 | * \param node a spa_node |
| 211 | * \param port_id an input port_id |
| 212 | * \param buffer_id the buffer id to be reused |
| 213 | * |
| 214 | * The node has a buffer that can be reused. |
| 215 | * |
| 216 | * When this function is NULL, the buffers to reuse will be set in |
| 217 | * the io area of the input ports. |
| 218 | */ |
| 219 | int (*reuse_buffer) (void *data, |
| 220 | uint32_t port_id, |
| 221 | uint32_t buffer_id); |
| 222 | |
| 223 | /** |
| 224 | * \param data user data |
| 225 | * \param trigger the timestamp in microseconds when the xrun happened |
| 226 | * \param delay the amount of microseconds of xrun. |
| 227 | * \param info an object with extra info (NULL for now) |
| 228 | * |
| 229 | * The node has encountered an over or underrun |
| 230 | * |
| 231 | * The info contains an object with more information |
| 232 | */ |
| 233 | int (*xrun) (void *data, uint64_t trigger, uint64_t delay, |
| 234 | struct spa_pod *info); |
| 235 | }; |
| 236 | |
| 237 | |
| 238 | /** flags that can be passed to set_param and port_set_param functions */ |
| 239 | #define SPA_NODE_PARAM_FLAG_TEST_ONLY (1 << 0) /**< Just check if the param is accepted */ |
| 240 | #define SPA_NODE_PARAM_FLAG_FIXATE (1 << 1) /**< Fixate the non-optional unset fields */ |
| 241 | #define SPA_NODE_PARAM_FLAG_NEAREST (1 << 2) /**< Allow set fields to be rounded to the |
| 242 | * nearest allowed field value. */ |
| 243 | |
| 244 | /** flags to pass to the use_buffers functions */ |
| 245 | #define SPA_NODE_BUFFERS_FLAG_ALLOC (1 << 0) /**< Allocate memory for the buffers. This flag |
| 246 | * is ignored when the port does not have the |
| 247 | * SPA_PORT_FLAG_CAN_ALLOC_BUFFERS set. */ |
| 248 | |
| 249 | |
| 250 | #define SPA_NODE_METHOD_ADD_LISTENER 0 |
| 251 | #define SPA_NODE_METHOD_SET_CALLBACKS 1 |
| 252 | #define SPA_NODE_METHOD_SYNC 2 |
| 253 | #define SPA_NODE_METHOD_ENUM_PARAMS 3 |
| 254 | #define SPA_NODE_METHOD_SET_PARAM 4 |
| 255 | #define SPA_NODE_METHOD_SET_IO 5 |
| 256 | #define SPA_NODE_METHOD_SEND_COMMAND 6 |
| 257 | #define SPA_NODE_METHOD_ADD_PORT 7 |
| 258 | #define SPA_NODE_METHOD_REMOVE_PORT 8 |
| 259 | #define SPA_NODE_METHOD_PORT_ENUM_PARAMS 9 |
| 260 | #define SPA_NODE_METHOD_PORT_SET_PARAM 10 |
| 261 | #define SPA_NODE_METHOD_PORT_USE_BUFFERS 11 |
| 262 | #define SPA_NODE_METHOD_PORT_SET_IO 12 |
| 263 | #define SPA_NODE_METHOD_PORT_REUSE_BUFFER 13 |
| 264 | #define SPA_NODE_METHOD_PROCESS 14 |
| 265 | #define SPA_NODE_METHOD_NUM 15 |
| 266 | |
| 267 | /** |
| 268 | * Node methods |
| 269 | */ |
| 270 | struct spa_node_methods { |
| 271 | /* the version of the node methods. This can be used to expand this |
| 272 | * structure in the future */ |
| 273 | #define SPA_VERSION_NODE_METHODS 0 |
| 274 | uint32_t version; |
| 275 | |
| 276 | /** |
| 277 | * Adds an event listener on \a node. |
| 278 | * |
| 279 | * Setting the events will trigger the info event and a |
| 280 | * port_info event for each managed port on the new |
| 281 | * listener. |
| 282 | * |
| 283 | * \param node a #spa_node |
| 284 | * \param listener a listener |
| 285 | * \param events a struct \ref spa_node_events |
| 286 | * \param data data passed as first argument in functions of \a events |
| 287 | * \return 0 on success |
| 288 | * < 0 errno on error |
| 289 | */ |
| 290 | int (*add_listener) (void *object, |
| 291 | struct spa_hook *listener, |
| 292 | const struct spa_node_events *events, |
| 293 | void *data); |
| 294 | /** |
| 295 | * Set callbacks to on \a node. |
| 296 | * if \a callbacks is NULL, the current callbacks are removed. |
| 297 | * |
| 298 | * This function must be called from the main thread. |
| 299 | * |
| 300 | * All callbacks are called from the data thread. |
| 301 | * |
| 302 | * \param node a spa_node |
| 303 | * \param callbacks callbacks to set |
| 304 | * \return 0 on success |
| 305 | * -EINVAL when node is NULL |
| 306 | */ |
| 307 | int (*set_callbacks) (void *object, |
| 308 | const struct spa_node_callbacks *callbacks, |
| 309 | void *data); |
| 310 | /** |
| 311 | * Perform a sync operation. |
| 312 | * |
| 313 | * This method will emit the result event with the given sequence |
| 314 | * number synchronously or with the returned async return value |
| 315 | * asynchronously. |
| 316 | * |
| 317 | * Because all methods are serialized in the node, this can be used |
| 318 | * to wait for completion of all previous method calls. |
| 319 | * |
| 320 | * \param seq a sequence number |
| 321 | * \return 0 on success |
| 322 | * -EINVAL when node is NULL |
| 323 | * an async result |
| 324 | */ |
| 325 | int (*sync) (void *object, int seq); |
| 326 | |
| 327 | /** |
| 328 | * Enumerate the parameters of a node. |
| 329 | * |
| 330 | * Parameters are identified with an \a id. Some parameters can have |
| 331 | * multiple values, see the documentation of the parameter id. |
| 332 | * |
| 333 | * Parameters can be filtered by passing a non-NULL \a filter. |
| 334 | * |
| 335 | * The function will emit the result event up to \a max times with |
| 336 | * the result value. The seq in the result will either be the \a seq |
| 337 | * number when executed synchronously or the async return value of |
| 338 | * this function when executed asynchronously. |
| 339 | * |
| 340 | * This function must be called from the main thread. |
| 341 | * |
| 342 | * \param node a \ref spa_node |
| 343 | * \param seq a sequence number to pass to the result event when |
| 344 | * this method is executed synchronously. |
| 345 | * \param id the param id to enumerate |
| 346 | * \param start the index of enumeration, pass 0 for the first item |
| 347 | * \param max the maximum number of parameters to enumerate |
| 348 | * \param filter and optional filter to use |
| 349 | * |
| 350 | * \return 0 when no more items can be iterated. |
| 351 | * -EINVAL when invalid arguments are given |
| 352 | * -ENOENT the parameter \a id is unknown |
| 353 | * -ENOTSUP when there are no parameters |
| 354 | * implemented on \a node |
| 355 | * an async return value when the result event will be |
| 356 | * emitted later. |
| 357 | */ |
| 358 | int (*enum_params) (void *object, int seq, |
| 359 | uint32_t id, uint32_t start, uint32_t max, |
| 360 | const struct spa_pod *filter); |
| 361 | |
| 362 | /** |
| 363 | * Set the configurable parameter in \a node. |
| 364 | * |
| 365 | * Usually, \a param will be obtained from enum_params and then |
| 366 | * modified but it is also possible to set another spa_pod |
| 367 | * as long as its keys and types match a supported object. |
| 368 | * |
| 369 | * Objects with property keys that are not known are ignored. |
| 370 | * |
| 371 | * This function must be called from the main thread. |
| 372 | * |
| 373 | * \param node a \ref spa_node |
| 374 | * \param id the parameter id to configure |
| 375 | * \param flags additional flags |
| 376 | * \param param the parameter to configure |
| 377 | * |
| 378 | * \return 0 on success |
| 379 | * -EINVAL when node is NULL |
| 380 | * -ENOTSUP when there are no parameters implemented on \a node |
| 381 | * -ENOENT the parameter is unknown |
| 382 | */ |
| 383 | int (*set_param) (void *object, |
| 384 | uint32_t id, uint32_t flags, |
| 385 | const struct spa_pod *param); |
| 386 | |
| 387 | /** |
| 388 | * Configure the given memory area with \a id on \a node. This |
| 389 | * structure is allocated by the host and is used to exchange |
| 390 | * data and parameters with the node. |
| 391 | * |
| 392 | * Setting an \a io of NULL will disable the node io. |
| 393 | * |
| 394 | * This function must be called from the main thread. |
| 395 | * |
| 396 | * \param id the id of the io area, the available ids can be |
| 397 | * enumerated with the node parameters. |
| 398 | * \param data a io area memory |
| 399 | * \param size the size of \a data |
| 400 | * \return 0 on success |
| 401 | * -EINVAL when invalid input is given |
| 402 | * -ENOENT when \a id is unknown |
| 403 | * -ENOSPC when \a size is too small |
| 404 | */ |
| 405 | int (*set_io) (void *object, |
| 406 | uint32_t id, void *data, size_t size); |
| 407 | |
| 408 | /** |
| 409 | * Send a command to a node. |
| 410 | * |
| 411 | * Upon completion, a command might change the state of a node. |
| 412 | * |
| 413 | * This function must be called from the main thread. |
| 414 | * |
| 415 | * \param node a spa_node |
| 416 | * \param command a spa_command |
| 417 | * \return 0 on success |
| 418 | * -EINVAL when node or command is NULL |
| 419 | * -ENOTSUP when this node can't process commands |
| 420 | * -EINVAL \a command is an invalid command |
| 421 | */ |
| 422 | int (*send_command) (void *object, const struct spa_command *command); |
| 423 | |
| 424 | /** |
| 425 | * Make a new port with \a port_id. The caller should use the lowest unused |
| 426 | * port id for the given \a direction. |
| 427 | * |
| 428 | * Port ids should be between 0 and max_ports as obtained from the info |
| 429 | * event. |
| 430 | * |
| 431 | * This function must be called from the main thread. |
| 432 | * |
| 433 | * \param node a spa_node |
| 434 | * \param direction a enum \ref spa_direction |
| 435 | * \param port_id an unused port id |
| 436 | * \param props extra properties |
| 437 | * \return 0 on success |
| 438 | * -EINVAL when node is NULL |
| 439 | */ |
| 440 | int (*add_port) (void *object, |
| 441 | enum spa_direction direction, uint32_t port_id, |
| 442 | const struct spa_dict *props); |
| 443 | |
| 444 | /** |
| 445 | * Remove a port with \a port_id. |
| 446 | * |
| 447 | * \param node a spa_node |
| 448 | * \param direction a enum \ref spa_direction |
| 449 | * \param port_id a port id |
| 450 | * \return 0 on success |
| 451 | * -EINVAL when node is NULL or when port_id is unknown or |
| 452 | * when the port can't be removed. |
| 453 | */ |
| 454 | int (*remove_port) (void *object, |
| 455 | enum spa_direction direction, uint32_t port_id); |
| 456 | |
| 457 | /** |
| 458 | * Enumerate all possible parameters of \a id on \a port_id of \a node |
| 459 | * that are compatible with \a filter. |
| 460 | * |
| 461 | * When SPA_ID_INVALID is given as the port_id, the node will reply with |
| 462 | * the params that would be returned for a new port in the given direction. |
| 463 | * |
| 464 | * The result parameters can be queried and modified and ultimately be used |
| 465 | * to call port_set_param. |
| 466 | * |
| 467 | * The function will emit the result event up to \a max times with |
| 468 | * the result value. The seq in the result event will either be the |
| 469 | * \a seq number when executed synchronously or the async return |
| 470 | * value of this function when executed asynchronously. |
| 471 | * |
| 472 | * This function must be called from the main thread. |
| 473 | * |
| 474 | * \param node a spa_node |
| 475 | * \param seq a sequence number to pass to the result event when |
| 476 | * this method is executed synchronously. |
| 477 | * \param direction an spa_direction |
| 478 | * \param port_id the port to query or SPA_ID_INVALID |
| 479 | * \param id the parameter id to query |
| 480 | * \param start the first index to query, 0 to get the first item |
| 481 | * \param max the maximum number of params to query |
| 482 | * \param filter a parameter filter or NULL for no filter |
| 483 | * |
| 484 | * \return 0 when no more items can be iterated. |
| 485 | * -EINVAL when invalid parameters are given |
| 486 | * -ENOENT when \a id is unknown |
| 487 | * an async return value when the result event will be |
| 488 | * emitted later. |
| 489 | */ |
| 490 | int (*port_enum_params) (void *object, int seq, |
| 491 | enum spa_direction direction, uint32_t port_id, |
| 492 | uint32_t id, uint32_t start, uint32_t max, |
| 493 | const struct spa_pod *filter); |
| 494 | /** |
| 495 | * Set a parameter on \a port_id of \a node. |
| 496 | * |
| 497 | * When \a param is NULL, the parameter will be unset. |
| 498 | * |
| 499 | * This function must be called from the main thread. The node muse be paused |
| 500 | * or the port SPA_IO_Buffers area is NULL when this function is called with |
| 501 | * a param that changes the processing state (like a format change). |
| 502 | * |
| 503 | * \param node a struct \ref spa_node |
| 504 | * \param direction a enum \ref spa_direction |
| 505 | * \param port_id the port to configure |
| 506 | * \param id the parameter id to set |
| 507 | * \param flags optional flags |
| 508 | * \param param a struct \ref spa_pod with the parameter to set |
| 509 | * \return 0 on success |
| 510 | * 1 on success, the value of \a param might have been |
| 511 | * changed depending on \a flags and the final value can be found by |
| 512 | * doing port_enum_params. |
| 513 | * -EINVAL when node is NULL or invalid arguments are given |
| 514 | * -ESRCH when one of the mandatory param |
| 515 | * properties is not specified and SPA_NODE_PARAM_FLAG_FIXATE was |
| 516 | * not set in \a flags. |
| 517 | * -ESRCH when the type or size of a property is not correct. |
| 518 | * -ENOENT when the param id is not found |
| 519 | */ |
| 520 | int (*port_set_param) (void *object, |
| 521 | enum spa_direction direction, |
| 522 | uint32_t port_id, |
| 523 | uint32_t id, uint32_t flags, |
| 524 | const struct spa_pod *param); |
| 525 | |
| 526 | /** |
| 527 | * Tell the port to use the given buffers |
| 528 | * |
| 529 | * When \a flags contains SPA_NODE_BUFFERS_FLAG_ALLOC, the data |
| 530 | * in the buffers should point to an array of at least 1 data entry |
| 531 | * with the desired supported type that will be filled by this function. |
| 532 | * |
| 533 | * The port should also have a spa_io_buffers io area configured to exchange |
| 534 | * the buffers with the port. |
| 535 | * |
| 536 | * For an input port, all the buffers will remain dequeued. |
| 537 | * Once a buffer has been queued on a port in the spa_io_buffers, |
| 538 | * it should not be reused until the reuse_buffer callback is notified |
| 539 | * or when the buffer has been returned in the spa_io_buffers of |
| 540 | * the port. |
| 541 | * |
| 542 | * For output ports, all buffers will be queued in the port. When process |
| 543 | * returns SPA_STATUS_HAVE_DATA, buffers are available in one or more |
| 544 | * of the spa_io_buffers areas. |
| 545 | * |
| 546 | * When a buffer can be reused, port_reuse_buffer() should be called or the |
| 547 | * buffer_id should be placed in the spa_io_buffers area before calling |
| 548 | * process. |
| 549 | * |
| 550 | * Passing NULL as \a buffers will remove the reference that the port has |
| 551 | * on the buffers. |
| 552 | * |
| 553 | * When this function returns async, use the spa_node_sync operation to |
| 554 | * wait for completion. |
| 555 | * |
| 556 | * This function must be called from the main thread. The node muse be paused |
| 557 | * or the port SPA_IO_Buffers area is NULL when this function is called. |
| 558 | * |
| 559 | * \param object an object implementing the interface |
| 560 | * \param direction a port direction |
| 561 | * \param port_id a port id |
| 562 | * \param flags extra flags |
| 563 | * \param buffers an array of buffer pointers |
| 564 | * \param n_buffers number of elements in \a buffers |
| 565 | * \return 0 on success |
| 566 | */ |
| 567 | int (*port_use_buffers) (void *object, |
| 568 | enum spa_direction direction, |
| 569 | uint32_t port_id, |
| 570 | uint32_t flags, |
| 571 | struct spa_buffer **buffers, |
| 572 | uint32_t n_buffers); |
| 573 | |
| 574 | /** |
| 575 | * Configure the given memory area with \a id on \a port_id. This |
| 576 | * structure is allocated by the host and is used to exchange |
| 577 | * data and parameters with the port. |
| 578 | * |
| 579 | * Setting an \a io of NULL will disable the port io. |
| 580 | * |
| 581 | * This function must be called from the main thread. |
| 582 | * |
| 583 | * This function can be called when the node is running and the node |
| 584 | * must be prepared to handle changes in io areas while running. This |
| 585 | * is normally done by synchronizing the port io updates with the |
| 586 | * data processing loop. |
| 587 | * |
| 588 | * \param direction a spa_direction |
| 589 | * \param port_id a port id |
| 590 | * \param id the id of the io area, the available ids can be |
| 591 | * enumerated with the port parameters. |
| 592 | * \param data a io area memory |
| 593 | * \param size the size of \a data |
| 594 | * \return 0 on success |
| 595 | * -EINVAL when invalid input is given |
| 596 | * -ENOENT when \a id is unknown |
| 597 | * -ENOSPC when \a size is too small |
| 598 | */ |
| 599 | int (*port_set_io) (void *object, |
| 600 | enum spa_direction direction, |
| 601 | uint32_t port_id, |
| 602 | uint32_t id, |
| 603 | void *data, size_t size); |
| 604 | |
| 605 | /** |
| 606 | * Tell an output port to reuse a buffer. |
| 607 | * |
| 608 | * This function must be called from the data thread. |
| 609 | * |
| 610 | * \param node a spa_node |
| 611 | * \param port_id a port id |
| 612 | * \param buffer_id a buffer id to reuse |
| 613 | * \return 0 on success |
| 614 | * -EINVAL when node is NULL |
| 615 | */ |
| 616 | int (*port_reuse_buffer) (void *object, uint32_t port_id, uint32_t buffer_id); |
| 617 | |
| 618 | /** |
| 619 | * Process the node |
| 620 | * |
| 621 | * This function must be called from the data thread. |
| 622 | * |
| 623 | * Output io areas with SPA_STATUS_NEED_DATA will recycle the |
| 624 | * buffers if any. |
| 625 | * |
| 626 | * Input areas with SPA_STATUS_HAVE_DATA are consumed if possible |
| 627 | * and the status is set to SPA_STATUS_NEED_DATA or SPA_STATUS_OK. |
| 628 | * |
| 629 | * When the node has new output buffers, the SPA_STATUS_HAVE_DATA |
| 630 | * bit will be set. |
| 631 | * |
| 632 | * When the node can accept new input in the next cycle, the |
| 633 | * SPA_STATUS_NEED_DATA bit will be set. |
| 634 | * |
| 635 | * Note that the node might return SPA_STATUS_NEED_DATA even when |
| 636 | * no input ports have this status. This means that the amount of |
| 637 | * data still available on the input ports is likely not going to |
| 638 | * be enough for the next cycle and the host might need to prefetch |
| 639 | * data for the next cycle. |
| 640 | */ |
| 641 | int (*process) (void *object); |
| 642 | }; |
| 643 | |
| 644 | |
| 645 | SPA_API_NODE int spa_node_add_listener(struct spa_node *object, |
| 646 | struct spa_hook *listener, |
| 647 | const struct spa_node_events *events, |
| 648 | void *data) |
| 649 | { |
| 650 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, add_listener, 0, |
| 651 | listener, events, data); |
| 652 | } |
| 653 | SPA_API_NODE int spa_node_set_callbacks(struct spa_node *object, |
| 654 | const struct spa_node_callbacks *callbacks, |
| 655 | void *data) |
| 656 | { |
| 657 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_callbacks, 0, |
| 658 | callbacks, data); |
| 659 | } |
| 660 | SPA_API_NODE int spa_node_sync(struct spa_node *object, int seq) |
| 661 | { |
| 662 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, sync, 0, |
| 663 | seq); |
| 664 | } |
| 665 | SPA_API_NODE int spa_node_enum_params(struct spa_node *object, int seq, |
| 666 | uint32_t id, uint32_t start, uint32_t max, |
| 667 | const struct spa_pod *filter) |
| 668 | { |
| 669 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, enum_params, 0, |
| 670 | seq, id, start, max, filter); |
| 671 | } |
| 672 | SPA_API_NODE int spa_node_set_param(struct spa_node *object, |
| 673 | uint32_t id, uint32_t flags, |
| 674 | const struct spa_pod *param) |
| 675 | { |
| 676 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_param, 0, |
| 677 | id, flags, param); |
| 678 | } |
| 679 | SPA_API_NODE int spa_node_set_io(struct spa_node *object, |
| 680 | uint32_t id, void *data, size_t size) |
| 681 | { |
| 682 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_io, 0, |
| 683 | id, data, size); |
| 684 | } |
| 685 | SPA_API_NODE int spa_node_send_command(struct spa_node *object, |
| 686 | const struct spa_command *command) |
| 687 | { |
| 688 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, send_command, 0, |
| 689 | command); |
| 690 | } |
| 691 | SPA_API_NODE int spa_node_add_port(struct spa_node *object, |
| 692 | enum spa_direction direction, uint32_t port_id, |
| 693 | const struct spa_dict *props) |
| 694 | { |
| 695 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, add_port, 0, |
| 696 | direction, port_id, props); |
| 697 | } |
| 698 | SPA_API_NODE int spa_node_remove_port(struct spa_node *object, |
| 699 | enum spa_direction direction, uint32_t port_id) |
| 700 | { |
| 701 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, remove_port, 0, |
| 702 | direction, port_id); |
| 703 | } |
| 704 | SPA_API_NODE int spa_node_port_enum_params(struct spa_node *object, int seq, |
| 705 | enum spa_direction direction, uint32_t port_id, |
| 706 | uint32_t id, uint32_t start, uint32_t max, |
| 707 | const struct spa_pod *filter) |
| 708 | { |
| 709 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_enum_params, 0, |
| 710 | seq, direction, port_id, id, start, max, filter); |
| 711 | } |
| 712 | SPA_API_NODE int spa_node_port_set_param(struct spa_node *object, |
| 713 | enum spa_direction direction, |
| 714 | uint32_t port_id, |
| 715 | uint32_t id, uint32_t flags, |
| 716 | const struct spa_pod *param) |
| 717 | { |
| 718 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_set_param, 0, |
| 719 | direction, port_id, id, flags, param); |
| 720 | } |
| 721 | SPA_API_NODE int spa_node_port_use_buffers(struct spa_node *object, |
| 722 | enum spa_direction direction, |
| 723 | uint32_t port_id, |
| 724 | uint32_t flags, |
| 725 | struct spa_buffer **buffers, |
| 726 | uint32_t n_buffers) |
| 727 | { |
| 728 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_use_buffers, 0, |
| 729 | direction, port_id, flags, buffers, n_buffers); |
| 730 | } |
| 731 | SPA_API_NODE int spa_node_port_set_io(struct spa_node *object, |
| 732 | enum spa_direction direction, |
| 733 | uint32_t port_id, |
| 734 | uint32_t id, void *data, size_t size) |
| 735 | { |
| 736 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_set_io, 0, |
| 737 | direction, port_id, id, data, size); |
| 738 | } |
| 739 | |
| 740 | SPA_API_NODE int spa_node_port_reuse_buffer(struct spa_node *object, uint32_t port_id, uint32_t buffer_id) |
| 741 | { |
| 742 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_reuse_buffer, 0, |
| 743 | port_id, buffer_id); |
| 744 | } |
| 745 | SPA_API_NODE int spa_node_port_reuse_buffer_fast(struct spa_node *object, uint32_t port_id, uint32_t buffer_id) |
| 746 | { |
| 747 | return spa_api_method_fast_r(int, -ENOTSUP, spa_node, &object->iface, port_reuse_buffer, 0, |
| 748 | port_id, buffer_id); |
| 749 | } |
| 750 | SPA_API_NODE int spa_node_process(struct spa_node *object) |
| 751 | { |
| 752 | return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, process, 0); |
| 753 | } |
| 754 | SPA_API_NODE int spa_node_process_fast(struct spa_node *object) |
| 755 | { |
| 756 | return spa_api_method_fast_r(int, -ENOTSUP, spa_node, &object->iface, process, 0); |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * \} |
| 761 | */ |
| 762 | |
| 763 | #ifdef __cplusplus |
| 764 | } /* extern "C" */ |
| 765 | #endif |
| 766 | |
| 767 | #endif /* SPA_NODE_H */ |