PipeWire: pipewire/filter.h Source File

PipeWire 1.6.5

Loading...
Searching...
No Matches
filter.h
Go to the documentation of this file.
1/* PipeWire */
2/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef PIPEWIRE_FILTER_H
6#define PIPEWIRE_FILTER_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
21
26struct pw_filter;
27
28#include <spa/buffer/buffer.h>
29#include <spa/node/io.h>
30#include <spa/param/param.h>
31#include <spa/pod/command.h>
32#include <spa/pod/event.h>
33
34#include <pipewire/core.h>
35#include <pipewire/stream.h>
36
38enum pw_filter_state {
39 PW_FILTER_STATE_ERROR = -1,
40 PW_FILTER_STATE_UNCONNECTED = 0,
41 PW_FILTER_STATE_CONNECTING = 1,
42 PW_FILTER_STATE_PAUSED = 2,
43 PW_FILTER_STATE_STREAMING = 3
44};
45
46#if 0
47 struct pw_buffer {
48 struct spa_buffer *buffer;
49 void *user_data;
50 uint64_t size;
55};
56#endif
57
60struct pw_filter_events {
61#define PW_VERSION_FILTER_EVENTS 1
62 uint32_t version;
63
64 void (*destroy) (void *data);
65 /** when the filter state changes. Since 1.4 this also sets errno when the
66 * new state is PW_FILTER_STATE_ERROR */
67 void (*state_changed) (void *data, enum pw_filter_state old,
68 enum pw_filter_state state, const char *error);
69
71 void (*io_changed) (void *data, void *port_data,
72 uint32_t id, void *area, uint32_t size);
74 void (*param_changed) (void *data, void *port_data,
75 uint32_t id, const struct spa_pod *param);
76
78 void (*add_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
80 void (*remove_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
81
87 void (*process) (void *data, struct spa_io_position *position);
88
90 void (*drained) (void *data);
91
93 void (*command) (void *data, const struct spa_command *command);
94};
95
97const char * pw_filter_state_as_string(enum pw_filter_state state);
98
100enum pw_filter_flags {
101 PW_FILTER_FLAG_NONE = 0,
102 PW_FILTER_FLAG_INACTIVE = (1 << 0),
105 PW_FILTER_FLAG_DRIVER = (1 << 1),
106 PW_FILTER_FLAG_RT_PROCESS = (1 << 2),
109 PW_FILTER_FLAG_CUSTOM_LATENCY = (1 << 3),
112 PW_FILTER_FLAG_TRIGGER = (1 << 4),
117 PW_FILTER_FLAG_ASYNC = (1 << 5),
124};
125
126enum pw_filter_port_flags {
127 PW_FILTER_PORT_FLAG_NONE = 0,
128 PW_FILTER_PORT_FLAG_MAP_BUFFERS = (1 << 0),
130 PW_FILTER_PORT_FLAG_ALLOC_BUFFERS = (1 << 1),
131
132 * data of the buffer should be set */
133};
134
137struct pw_filter *
138 pw_filter_new(struct pw_core *core,
139 const char *name,
140 struct pw_properties *props );
141
142struct pw_filter *
143 pw_filter_new_simple(struct pw_loop *loop,
144 const char *name,
145 struct pw_properties *props,
146 const struct pw_filter_events *events,
147 void *data );
148
150void pw_filter_destroy(struct pw_filter *filter);
151
152void pw_filter_add_listener(struct pw_filter *filter,
153 struct spa_hook *listener,
154 const struct pw_filter_events *events,
155 void *data);
156
159enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error);
160
161const char *pw_filter_get_name(struct pw_filter *filter);
162
163struct pw_core *pw_filter_get_core(struct pw_filter *filter);
164
170int
171 pw_filter_connect(struct pw_filter *filter,
172 enum pw_filter_flags flags,
173 const struct spa_pod **params,
174 uint32_t n_params );
175
178uint32_t
179 pw_filter_get_node_id(struct pw_filter *filter);
180
182int pw_filter_disconnect(struct pw_filter *filter);
183
185void *pw_filter_add_port(struct pw_filter *filter,
186 enum pw_direction direction,
187 enum pw_filter_port_flags flags,
188 size_t port_data_size,
189 struct pw_properties *props,
190 const struct spa_pod **params,
192 uint32_t n_params );
193
195int pw_filter_remove_port(void *port_data );
196
198const struct pw_properties *pw_filter_get_properties(struct pw_filter *filter,
199 void *port_data);
200
202int pw_filter_update_properties(struct pw_filter *filter,
203 void *port_data, const struct spa_dict *dict);
204
206int pw_filter_set_error(struct pw_filter *filter,
207 int res,
208 const char *error,
209 ...
210 ) SPA_PRINTF_FUNC(3, 4);
211
213int
214 pw_filter_update_params(struct pw_filter *filter,
215 void *port_data,
216 const struct spa_pod **params,
217 uint32_t n_params );
218
219
222 SPA_DEPRECATED
223int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time);
224
227uint64_t pw_filter_get_nsec(struct pw_filter *filter);
228
231struct pw_loop *pw_filter_get_data_loop(struct pw_filter *filter);
232
235struct pw_buffer *pw_filter_dequeue_buffer(void *port_data);
236
238int pw_filter_queue_buffer(void *port_data, struct pw_buffer *buffer);
239
241void *pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples);
242
244int pw_filter_set_active(struct pw_filter *filter, bool active);
245
252int pw_filter_flush(struct pw_filter *filter, bool drain);
253
258bool pw_filter_is_driving(struct pw_filter *filter);
259
262bool pw_filter_is_lazy(struct pw_filter *filter);
263
266int pw_filter_trigger_process(struct pw_filter *filter);
267
270int pw_filter_emit_event(struct pw_filter *filter, const struct spa_event *event);
271
275
276#ifdef __cplusplus
277}
278#endif
279
280#endif /* PIPEWIRE_FILTER_H */
buffer.h
spa/buffer/buffer.h
core.h
pipewire/core.h
id
uint32_t id
Definition core.h:432
res
uint32_t int int res
Definition core.h:433
pw_filter_get_name
const char * pw_filter_get_name(struct pw_filter *filter)
Definition filter.c:1506
pw_filter_remove_port
int pw_filter_remove_port(void *port_data)
remove a port from the filter
Definition filter.c:1898
pw_filter_flags
pw_filter_flags
Extra flags that can be used in pw_filter_connect().
Definition filter.h:106
pw_filter_state_as_string
const char * pw_filter_state_as_string(enum pw_filter_state state)
Convert a filter state to a readable string.
Definition filter.c:1340
pw_filter_connect
int pw_filter_connect(struct pw_filter *filter, enum pw_filter_flags flags, const struct spa_pod **params, uint32_t n_params)
Connect a filter for processing.
Definition filter.c:1573
pw_filter_get_core
struct pw_core * pw_filter_get_core(struct pw_filter *filter)
Definition filter.c:1500
pw_filter_add_listener
void pw_filter_add_listener(struct pw_filter *filter, struct spa_hook *listener, const struct pw_filter_events *events, void *data)
Definition filter.c:1472
pw_filter_get_state
enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error)
Get the current filter state.
Definition filter.c:1490
pw_filter_get_node_id
uint32_t pw_filter_get_node_id(struct pw_filter *filter)
Get the node ID of the filter.
Definition filter.c:1724
pw_filter_emit_event
int pw_filter_emit_event(struct pw_filter *filter, const struct spa_event *event)
Emit an event from this filter.
Definition filter.c:2147
pw_filter_queue_buffer
int pw_filter_queue_buffer(void *port_data, struct pw_buffer *buffer)
Submit a buffer for playback or recycle a buffer for capture.
Definition filter.c:2041
pw_filter_get_nsec
uint64_t pw_filter_get_nsec(struct pw_filter *filter)
Get the current time in nanoseconds.
Definition filter.c:2007
pw_filter_port_flags
pw_filter_port_flags
Definition filter.h:132
pw_filter_trigger_process
int pw_filter_trigger_process(struct pw_filter *filter)
Trigger a push/pull on the filter.
Definition filter.c:2155
pw_filter_disconnect
int pw_filter_disconnect(struct pw_filter *filter)
Disconnect filter.
Definition filter.c:1730
pw_filter_state
pw_filter_state
The state of a filter.
Definition filter.h:43
pw_filter_new
struct pw_filter * pw_filter_new(struct pw_core *core, const char *name, struct pw_properties *props)
Create a new unconnected Filter.
Definition filter.c:1273
pw_filter_set_active
int pw_filter_set_active(struct pw_filter *filter, bool active)
Activate or deactivate the filter.
Definition filter.c:1964
pw_filter_get_data_loop
struct pw_loop * pw_filter_get_data_loop(struct pw_filter *filter)
Get the data loop that is doing the processing of this filter.
Definition filter.c:2015
pw_filter_add_port
void * pw_filter_add_port(struct pw_filter *filter, enum pw_direction direction, enum pw_filter_port_flags flags, size_t port_data_size, struct pw_properties *props, const struct spa_pod **params, uint32_t n_params)
add a port to the filter, returns user data of port_data_size.
Definition filter.c:1816
pw_filter_get_time
int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time)
Query the time on the filter, deprecated, use the spa_io_position in the process() method for timing ...
Definition filter.c:1982
pw_filter_dequeue_buffer
struct pw_buffer * pw_filter_dequeue_buffer(void *port_data)
Get a buffer that can be filled for output ports or consumed for input ports.
Definition filter.c:2022
pw_filter_is_driving
bool pw_filter_is_driving(struct pw_filter *filter)
Check if the filter is driving.
Definition filter.c:2117
pw_filter_is_lazy
bool pw_filter_is_lazy(struct pw_filter *filter)
Check if the graph is using lazy scheduling.
Definition filter.c:2123
pw_filter_flush
int pw_filter_flush(struct pw_filter *filter, bool drain)
Flush a filter.
Definition filter.c:2108
pw_filter_set_error
int pw_filter_set_error(struct pw_filter *filter, int res, const char *error,...)
Set the filter in error state.
Definition filter.c:1910
pw_filter_get_properties
const struct pw_properties * pw_filter_get_properties(struct pw_filter *filter, void *port_data)
get properties, port_data of NULL will give global properties
Definition filter.c:1512
pw_filter_update_params
int pw_filter_update_params(struct pw_filter *filter, void *port_data, const struct spa_pod **params, uint32_t n_params)
Update params, use NULL port_data for global filter params.
Definition filter.c:1936
pw_filter_update_properties
int pw_filter_update_properties(struct pw_filter *filter, void *port_data, const struct spa_dict *dict)
Update properties, use NULL port_data for global filter properties.
Definition filter.c:1525
pw_filter_destroy
void pw_filter_destroy(struct pw_filter *filter)
Destroy a filter.
Definition filter.c:1421
pw_filter_get_dsp_buffer
void * pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples)
Get a data pointer to the buffer data.
Definition filter.c:2057
pw_filter_new_simple
struct pw_filter * pw_filter_new_simple(struct pw_loop *loop, const char *name, struct pw_properties *props, const struct pw_filter_events *events, void *data)
Definition filter.c:1295
PW_FILTER_FLAG_NONE
@ PW_FILTER_FLAG_NONE
no flags
Definition filter.h:107
PW_FILTER_FLAG_TRIGGER
@ PW_FILTER_FLAG_TRIGGER
the filter will not be scheduled automatically but _trigger_process() needs to be called.
Definition filter.h:118
PW_FILTER_FLAG_CUSTOM_LATENCY
@ PW_FILTER_FLAG_CUSTOM_LATENCY
don't call the default latency algorithm but emit the param_changed event for the ports when Latency ...
Definition filter.h:115
PW_FILTER_FLAG_INACTIVE
@ PW_FILTER_FLAG_INACTIVE
start the filter inactive, pw_filter_set_active() needs to be called explicitly
Definition filter.h:108
PW_FILTER_FLAG_RT_PROCESS
@ PW_FILTER_FLAG_RT_PROCESS
call process from the realtime thread.
Definition filter.h:112
PW_FILTER_FLAG_ASYNC
@ PW_FILTER_FLAG_ASYNC
Buffers will not be dequeued/queued from the realtime process() function.
Definition filter.h:123
PW_FILTER_FLAG_DRIVER
@ PW_FILTER_FLAG_DRIVER
be a driver
Definition filter.h:111
PW_FILTER_PORT_FLAG_ALLOC_BUFFERS
@ PW_FILTER_PORT_FLAG_ALLOC_BUFFERS
the application will allocate buffer memory.
Definition filter.h:136
PW_FILTER_PORT_FLAG_MAP_BUFFERS
@ PW_FILTER_PORT_FLAG_MAP_BUFFERS
mmap the buffers except DmaBuf that is not explicitly marked as mappable.
Definition filter.h:134
PW_FILTER_PORT_FLAG_NONE
@ PW_FILTER_PORT_FLAG_NONE
no flags
Definition filter.h:133
PW_FILTER_STATE_STREAMING
@ PW_FILTER_STATE_STREAMING
filter is streaming
Definition filter.h:48
PW_FILTER_STATE_ERROR
@ PW_FILTER_STATE_ERROR
the stream is in error
Definition filter.h:44
PW_FILTER_STATE_UNCONNECTED
@ PW_FILTER_STATE_UNCONNECTED
unconnected
Definition filter.h:45
PW_FILTER_STATE_CONNECTING
@ PW_FILTER_STATE_CONNECTING
connection is in progress
Definition filter.h:46
PW_FILTER_STATE_PAUSED
@ PW_FILTER_STATE_PAUSED
filter is connected and paused
Definition filter.h:47
pw_direction
#define pw_direction
The direction of a port.
Definition port.h:51
SPA_DEPRECATED
#define SPA_DEPRECATED
Definition defs.h:303
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:297
io.h
spa/node/io.h
param.h
spa/param/param.h
command.h
spa/pod/command.h
event.h
spa/pod/event.h
stream.h
pipewire/stream.h
pw_buffer
a buffer structure obtained from pw_stream_dequeue_buffer().
Definition stream.h:261
pw_buffer::size
uint64_t size
This field is set by the user and the sum of all queued buffers is returned in the time info.
Definition stream.h:269
pw_buffer::user_data
void * user_data
user data attached to the buffer.
Definition stream.h:263
pw_core
pw_filter_events
Events for a filter.
Definition filter.h:65
pw_filter_events::process
void(* process)(void *data, struct spa_io_position *position)
do processing.
Definition filter.h:93
pw_filter_events::param_changed
void(* param_changed)(void *data, void *port_data, uint32_t id, const struct spa_pod *param)
when a parameter changed on a port of the filter (when port_data is NULL).
Definition filter.h:80
pw_filter_events::io_changed
void(* io_changed)(void *data, void *port_data, uint32_t id, void *area, uint32_t size)
when io changed on a port of the filter (when port_data is NULL).
Definition filter.h:77
pw_filter_events::version
uint32_t version
Definition filter.h:68
pw_filter_events::drained
void(* drained)(void *data)
The filter is drained.
Definition filter.h:96
pw_filter_events::command
void(* command)(void *data, const struct spa_command *command)
A command notify, Since 0.3.39:1.
Definition filter.h:99
pw_filter_events::remove_buffer
void(* remove_buffer)(void *data, void *port_data, struct pw_buffer *buffer)
when a buffer was destroyed for a port
Definition filter.h:86
pw_filter_events::add_buffer
void(* add_buffer)(void *data, void *port_data, struct pw_buffer *buffer)
when a new buffer was created for a port
Definition filter.h:84
pw_filter_events::destroy
void(* destroy)(void *data)
Definition filter.h:70
pw_filter_events::state_changed
void(* state_changed)(void *data, enum pw_filter_state old, enum pw_filter_state state, const char *error)
when the filter state changes.
Definition filter.h:73
pw_filter
pw_loop
Definition loop.h:33
pw_properties
Definition properties.h:39
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition properties.h:40
pw_time
A time structure.
Definition stream.h:382
spa_buffer
A Buffer.
Definition buffer.h:110
spa_command
Definition command.h:29
spa_dict
Definition dict.h:51
spa_event
Definition event.h:28
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition hook.h:427
spa_io_position
The position information adds extra meaning to the raw clock times.
Definition io.h:353
spa_pod
Definition pod.h:57