PipeWire 1.2.6

Loading...
Searching...
No Matches
Files | Data Structures | Typedefs | Macros
Loop
SPA » Support

Event loop interface More...

## Files
file | loop.h
| `spa/support/loop.h`

## Data Structures
struct | spa_loop
struct | spa_loop_control
struct | spa_loop_utils
struct | spa_source
struct | spa_loop_methods
| Register sources and work items to an event loop. More...
struct | spa_loop_control_hooks
| Control hooks. More...
struct | spa_loop_control_methods
| Control an event loop. More...
struct | spa_loop_utils_methods
| Create sources for an event loop. More...

## Typedefs
typedef void(* | spa_source_func_t) (struct spa_source *source)
typedef int(* | spa_invoke_func_t) (struct spa_loop *loop, bool async, uint32_t seq, const void *data, size_t size, void *user_data)
typedef void(* | spa_source_io_func_t) (void *data, int fd, uint32_t mask)
typedef void(* | spa_source_idle_func_t) (void *data)
typedef void(* | spa_source_event_func_t) (void *data, uint64_t count)
typedef void(* | spa_source_timer_func_t) (void *data, uint64_t expirations)
typedef void(* | spa_source_signal_func_t) (void *data, int signal_number)

## Macros
#define | SPA_TYPE_INTERFACE_Loop SPA_TYPE_INFO_INTERFACE_BASE "Loop"
#define | SPA_TYPE_INTERFACE_DataLoop SPA_TYPE_INFO_INTERFACE_BASE "DataLoop"
#define | SPA_VERSION_LOOP 0
#define | SPA_TYPE_INTERFACE_LoopControl SPA_TYPE_INFO_INTERFACE_BASE "LoopControl"
#define | SPA_VERSION_LOOP_CONTROL 1
#define | SPA_TYPE_INTERFACE_LoopUtils SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils"
#define | SPA_VERSION_LOOP_UTILS 0
#define | SPA_VERSION_LOOP_METHODS 0
#define | spa_loop_method(o, method, version, ...)
#define | spa_loop_add_source(l, ...)
| Add a source to the loop.
#define | spa_loop_update_source(l, ...)
| Update the source io mask.
#define | spa_loop_remove_source(l, ...)
| Remove a source from the loop.
#define | spa_loop_invoke(l, ...)
| Invoke a function in the context of this loop.
#define | SPA_VERSION_LOOP_CONTROL_HOOKS 0
#define | spa_loop_control_hook_before(l)
#define | spa_loop_control_hook_after(l)
#define | SPA_VERSION_LOOP_CONTROL_METHODS 1
#define | spa_loop_control_method_v(o, method, version, ...)
#define | spa_loop_control_method_r(o, method, version, ...)
#define | spa_loop_control_method_fast_r(o, method, version, ...)
#define | spa_loop_control_get_fd(l)
#define | spa_loop_control_add_hook(l, ...)
| Add a hook.
#define | spa_loop_control_enter(l)
| Enter a loop.
#define | spa_loop_control_leave(l)
| Leave a loop.
#define | spa_loop_control_iterate(l, ...)
| Perform one iteration of the loop.
#define | spa_loop_control_check(l)
| Check context of the loop.
#define | spa_loop_control_iterate_fast(l, ...)
#define | SPA_VERSION_LOOP_UTILS_METHODS 0
#define | spa_loop_utils_method_v(o, method, version, ...)
#define | spa_loop_utils_method_r(o, method, version, ...)
#define | spa_loop_utils_method_s(o, method, version, ...)
#define | spa_loop_utils_add_io(l, ...)
#define | spa_loop_utils_update_io(l, ...)
#define | spa_loop_utils_add_idle(l, ...)
#define | spa_loop_utils_enable_idle(l, ...)
#define | spa_loop_utils_add_event(l, ...)
#define | spa_loop_utils_signal_event(l, ...)
#define | spa_loop_utils_add_timer(l, ...)
#define | spa_loop_utils_update_timer(l, ...)
#define | spa_loop_utils_add_signal(l, ...)
#define | spa_loop_utils_destroy_source(l, ...)
| destroy a source allocated with this interface.

## Detailed Description

Event loop interface

## Typedef Documentation

## ◆ spa_source_func_t

typedef void(* spa_source_func_t) (struct spa_source *source)

## ◆ spa_invoke_func_t

typedef int(* spa_invoke_func_t) (struct spa_loop *loop, bool async, uint32_t seq, const void *data, size_t size, void *user_data)

## ◆ spa_source_io_func_t

typedef void(* spa_source_io_func_t) (void *data, int fd, uint32_t mask)

## ◆ spa_source_idle_func_t

typedef void(* spa_source_idle_func_t) (void *data)

## ◆ spa_source_event_func_t

typedef void(* spa_source_event_func_t) (void *data, uint64_t count)

## ◆ spa_source_timer_func_t

typedef void(* spa_source_timer_func_t) (void *data, uint64_t expirations)

## ◆ spa_source_signal_func_t

typedef void(* spa_source_signal_func_t) (void *data, int signal_number)

## Macro Definition Documentation

## ◆ SPA_TYPE_INTERFACE_Loop

#define SPA_TYPE_INTERFACE_Loop SPA_TYPE_INFO_INTERFACE_BASE "Loop"

Examples
  local-v4l2.c, spa/examples/adapter-control.c, spa/examples/example-control.c, spa/examples/local-libcamera.c, and spa/examples/local-v4l2.c.

## ◆ SPA_TYPE_INTERFACE_DataLoop

#define SPA_TYPE_INTERFACE_DataLoop SPA_TYPE_INFO_INTERFACE_BASE "DataLoop"

Examples
  local-v4l2.c, spa/examples/adapter-control.c, spa/examples/example-control.c, spa/examples/local-libcamera.c, and spa/examples/local-v4l2.c.

## ◆ SPA_VERSION_LOOP

#define SPA_VERSION_LOOP 0

## ◆ SPA_TYPE_INTERFACE_LoopControl

#define SPA_TYPE_INTERFACE_LoopControl SPA_TYPE_INFO_INTERFACE_BASE "LoopControl"

Examples
  local-v4l2.c, spa/examples/adapter-control.c, spa/examples/example-control.c, spa/examples/local-libcamera.c, and spa/examples/local-v4l2.c.

## ◆ SPA_VERSION_LOOP_CONTROL

#define SPA_VERSION_LOOP_CONTROL 1

## ◆ SPA_TYPE_INTERFACE_LoopUtils

#define SPA_TYPE_INTERFACE_LoopUtils SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils"

## ◆ SPA_VERSION_LOOP_UTILS

#define SPA_VERSION_LOOP_UTILS 0

## ◆ SPA_VERSION_LOOP_METHODS

#define SPA_VERSION_LOOP_METHODS 0

## ◆ spa_loop_method

#define spa_loop_method | ( |  | o,
|  |  | method,
|  |  | version,
|  |  | ... )

## ◆ spa_loop_add_source

#define spa_loop_add_source | ( |  | l,
|  |  | ... )

Value:
spa_loop_method(l,add_source,0,##__VA_ARGS__)
spa_loop_method
#define spa_loop_method(o, method, version,...)
Definition loop.h:142

Add a source to the loop.

Must be called from the loop's own thread.

Parameters

  [in] | object | The callbacks data.
  [in] | source | The source.

Returns
  0 on success, negative errno-style value on failure.

See also
  spa_loop_methods.add_source

## ◆ spa_loop_update_source

#define spa_loop_update_source | ( |  | l,
|  |  | ... )

Value:
spa_loop_method(l,update_source,0,##__VA_ARGS__)

Update the source io mask.

Must be called from the loop's own thread.

Parameters

  [in] | object | The callbacks data.
  [in] | source | The source.

Returns
  0 on success, negative errno-style value on failure.

See also
  spa_loop_methods.update_source

## ◆ spa_loop_remove_source

#define spa_loop_remove_source | ( |  | l,
|  |  | ... )

Value:
spa_loop_method(l,remove_source,0,##__VA_ARGS__)

Remove a source from the loop.

Must be called from the loop's own thread.

Parameters

  [in] | object | The callbacks data.
  [in] | source | The source.

Returns
  0 on success, negative errno-style value on failure.

See also
  spa_loop_methods.remove_source

## ◆ spa_loop_invoke

#define spa_loop_invoke | ( |  | l,
|  |  | ... )

Value:
spa_loop_method(l,invoke,0,##__VA_ARGS__)

Invoke a function in the context of this loop.

May be called from any thread and multiple threads at the same time. If called from the loop's thread, all callbacks previously queued with invoke() will be run synchronously, which might cause unexpected reentrancy problems.

Parameters

  [in] | object | The callbacks data.
  | func | The function to be invoked.
  | seq | An opaque sequence number. This will be made available to func.
  [in] | data | Data that will be copied into the internal ring buffer and made available to func. Because this data is copied, it is okay to pass a pointer to a local variable, but do not pass a pointer to an object that has identity.
  | size | The size of data to copy.
  | block | If \true, do not return until func has been called. Otherwise, returns immediately. Passing \true does not risk a deadlock because the data thread is never allowed to wait on any other thread.
  | user_data | An opaque pointer passed to func.

Returns
  `-EPIPE` if the internal ring buffer filled up, if block is \false, 0 if seq was SPA_ID_INVALID or seq with the ASYNC flag set or the return value of func otherwise.

See also
  spa_loop_methods.invoke

## ◆ SPA_VERSION_LOOP_CONTROL_HOOKS

#define SPA_VERSION_LOOP_CONTROL_HOOKS 0

## ◆ spa_loop_control_hook_before

#define spa_loop_control_hook_before | ( |  | l | ) |

## ◆ spa_loop_control_hook_after

#define spa_loop_control_hook_after | ( |  | l | ) |

## ◆ SPA_VERSION_LOOP_CONTROL_METHODS

#define SPA_VERSION_LOOP_CONTROL_METHODS 1

## ◆ spa_loop_control_method_v

#define spa_loop_control_method_v | ( |  | o,
|  |  | method,
|  |  | version,
|  |  | ... )

## ◆ spa_loop_control_method_r

#define spa_loop_control_method_r | ( |  | o,
|  |  | method,
|  |  | version,
|  |  | ... )

## ◆ spa_loop_control_method_fast_r

#define spa_loop_control_method_fast_r | ( |  | o,
|  |  | method,
|  |  | version,
|  |  | ... )

## ◆ spa_loop_control_get_fd

#define spa_loop_control_get_fd | ( |  | l | ) |

Value:
spa_loop_control_method_r(l,get_fd,0)
spa_loop_control_method_r
#define spa_loop_control_method_r(o, method, version,...)
Definition loop.h:266

See also
  spa_loop_control_methods.get_fd

## ◆ spa_loop_control_add_hook

#define spa_loop_control_add_hook | ( |  | l,
|  |  | ... )

Value:
spa_loop_control_method_v(l,add_hook,0,__VA_ARGS__)
spa_loop_control_method_v
#define spa_loop_control_method_v(o, method, version,...)
Definition loop.h:258

Add a hook.

Parameters

  ctrl | the control to change
  hooks | the hooks to add

Adds hooks to the loop controlled by ctrl.

See also
  spa_loop_control_methods.add_hook

## ◆ spa_loop_control_enter

#define spa_loop_control_enter | ( |  | l | ) |

Value:
spa_loop_control_method_v(l,enter,0)

Enter a loop.

Parameters

  ctrl | the control

Start an iteration of the loop. This function should be called before calling iterate and is typically used to capture the thread that this loop will run in.

See also
  spa_loop_control_methods.enter

Examples
  local-v4l2.c, spa/examples/adapter-control.c, spa/examples/example-control.c, spa/examples/local-libcamera.c, and spa/examples/local-v4l2.c.

## ◆ spa_loop_control_leave

#define spa_loop_control_leave | ( |  | l | ) |

Value:
spa_loop_control_method_v(l,leave,0)

Leave a loop.

Parameters

  ctrl | the control

Ends the iteration of a loop. This should be called after calling iterate.

See also
  spa_loop_control_methods.leave

Examples
  local-v4l2.c, spa/examples/adapter-control.c, spa/examples/example-control.c, spa/examples/local-libcamera.c, and spa/examples/local-v4l2.c.

## ◆ spa_loop_control_iterate

#define spa_loop_control_iterate | ( |  | l,
|  |  | ... )

Value:
spa_loop_control_method_r(l,iterate,0,__VA_ARGS__)

Perform one iteration of the loop.

Parameters

  ctrl | the control
  timeout | an optional timeout in milliseconds. 0 for no timeout, -1 for infinite timeout.

This function will block up to timeout milliseconds and then dispatch the fds with activity. The number of dispatched fds is returned.

See also
  spa_loop_control_methods.iterate

Examples
  local-v4l2.c, spa/examples/adapter-control.c, spa/examples/example-control.c, spa/examples/local-libcamera.c, and spa/examples/local-v4l2.c.

## ◆ spa_loop_control_check

#define spa_loop_control_check | ( |  | l | ) |

Value:
spa_loop_control_method_r(l,check,1)

Check context of the loop.

Parameters

  ctrl | the control

This function will check if the current thread is currently the one that did the enter call. Since version 1:1.

returns 1 on success, 0 or negative errno value on error.

See also
  spa_loop_control_methods.check

## ◆ spa_loop_control_iterate_fast

#define spa_loop_control_iterate_fast | ( |  | l,
|  |  | ... )

Value:
spa_loop_control_method_fast_r(l,iterate,0,__VA_ARGS__)
spa_loop_control_method_fast_r
#define spa_loop_control_method_fast_r(o, method, version,...)
Definition loop.h:276

## ◆ SPA_VERSION_LOOP_UTILS_METHODS

#define SPA_VERSION_LOOP_UTILS_METHODS 0

## ◆ spa_loop_utils_method_v

#define spa_loop_utils_method_v | ( |  | o,
|  |  | method,
|  |  | version,
|  |  | ... )

## ◆ spa_loop_utils_method_r

#define spa_loop_utils_method_r | ( |  | o,
|  |  | method,
|  |  | version,
|  |  | ... )

## ◆ spa_loop_utils_method_s

#define spa_loop_utils_method_s | ( |  | o,
|  |  | method,
|  |  | version,
|  |  | ... )

## ◆ spa_loop_utils_add_io

#define spa_loop_utils_add_io | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_s(l,add_io,0,__VA_ARGS__)
spa_loop_utils_method_s
#define spa_loop_utils_method_s(o, method, version,...)
Definition loop.h:374

See also
  spa_loop_utils_methods.add_io

## ◆ spa_loop_utils_update_io

#define spa_loop_utils_update_io | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_r(l,update_io,0,__VA_ARGS__)
spa_loop_utils_method_r
#define spa_loop_utils_method_r(o, method, version,...)
Definition loop.h:365

See also
  spa_loop_utils_methods.update_io

## ◆ spa_loop_utils_add_idle

#define spa_loop_utils_add_idle | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_s(l,add_idle,0,__VA_ARGS__)

See also
  spa_loop_utils_methods.add_idle

## ◆ spa_loop_utils_enable_idle

#define spa_loop_utils_enable_idle | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_r(l,enable_idle,0,__VA_ARGS__)

See also
  spa_loop_utils_methods.enable_idle

## ◆ spa_loop_utils_add_event

#define spa_loop_utils_add_event | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_s(l,add_event,0,__VA_ARGS__)

See also
  spa_loop_utils_methods.add_event

## ◆ spa_loop_utils_signal_event

#define spa_loop_utils_signal_event | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_r(l,signal_event,0,__VA_ARGS__)

See also
  spa_loop_utils_methods.signal_event

## ◆ spa_loop_utils_add_timer

#define spa_loop_utils_add_timer | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_s(l,add_timer,0,__VA_ARGS__)

See also
  spa_loop_utils_methods.add_timer

## ◆ spa_loop_utils_update_timer

#define spa_loop_utils_update_timer | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_r(l,update_timer,0,__VA_ARGS__)

See also
  spa_loop_utils_methods.update_timer

## ◆ spa_loop_utils_add_signal

#define spa_loop_utils_add_signal | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_s(l,add_signal,0,__VA_ARGS__)

See also
  spa_loop_utils_methods.add_signal

## ◆ spa_loop_utils_destroy_source

#define spa_loop_utils_destroy_source | ( |  | l,
|  |  | ... )

Value:
spa_loop_utils_method_v(l,destroy_source,0,__VA_ARGS__)
spa_loop_utils_method_v
#define spa_loop_utils_method_v(o, method, version,...)
Definition loop.h:357

destroy a source allocated with this interface.

This function should only be called when the loop is not running or from the context of the running loop

See also
  spa_loop_utils_methods.destroy_source