PipeWire: filter.h Source File

PipeWire 0.3.34

pipewire/src/pipewire/filter.h
Go to the documentation of this file.
1 /* PipeWire
2 *
3 * Copyright © 2019 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 PIPEWIRE_FILTER_H
26 #define PIPEWIRE_FILTER_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
46 struct pw_filter;
47
48 #include <spa/buffer/buffer.h>
49 #include <spa/node/io.h>
50 #include <spa/param/param.h>
51
52 #include <pipewire/core.h>
53 #include <pipewire/stream.h>
54
56 enum pw_filter_state {
57 PW_FILTER_STATE_ERROR = -1,
58 PW_FILTER_STATE_UNCONNECTED = 0,
59 PW_FILTER_STATE_CONNECTING = 1,
60 PW_FILTER_STATE_PAUSED = 2,
61 PW_FILTER_STATE_STREAMING = 3
62 };
63
64 #if 0
65 struct pw_buffer {
66 struct spa_buffer *buffer;
67 void *user_data;
68 uint64_t size;
73 };
74 #endif
75
78 struct pw_filter_events {
79 #define PW_VERSION_FILTER_EVENTS 0
80 uint32_t version;
81
82 void (*destroy) (void *data);
84 void (*state_changed) (void *data, enum pw_filter_state old,
85 enum pw_filter_state state, const char *error);
86
88 void (*io_changed) (void *data, void *port_data,
89 uint32_t id, void *area, uint32_t size);
91 void (*param_changed) (void *data, void *port_data,
92 uint32_t id, const struct spa_pod *param);
93
95 void (*add_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
97 void (*remove_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
98
102 void (*process) (void *data, struct spa_io_position *position);
103
105 void (*drained) (void *data);
106 };
107
109 const char * pw_filter_state_as_string(enum pw_filter_state state);
110
112 enum pw_filter_flags {
113 PW_FILTER_FLAG_NONE = 0,
114 PW_FILTER_FLAG_INACTIVE = (1 << 0),
117 PW_FILTER_FLAG_DRIVER = (1 << 1),
118 PW_FILTER_FLAG_RT_PROCESS = (1 << 2),
120 PW_FILTER_FLAG_CUSTOM_LATENCY = (1 << 3),
123 };
124
125 enum pw_filter_port_flags {
126 PW_FILTER_PORT_FLAG_NONE = 0,
127 PW_FILTER_PORT_FLAG_MAP_BUFFERS = (1 << 0),
128 PW_FILTER_PORT_FLAG_ALLOC_BUFFERS = (1 << 1),
131 };
132
135 struct pw_filter *
136 pw_filter_new(struct pw_core *core,
137 const char *name,
138 struct pw_properties *props );
139
140 struct pw_filter *
141 pw_filter_new_simple(struct pw_loop *loop,
142 const char *name,
143 struct pw_properties *props,
144 const struct pw_filter_events *events,
145 void *data );
146
148 void pw_filter_destroy(struct pw_filter *filter);
149
150 void pw_filter_add_listener(struct pw_filter *filter,
151 struct spa_hook *listener,
152 const struct pw_filter_events *events,
153 void *data);
154
155 enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error);
156
157 const char *pw_filter_get_name(struct pw_filter *filter);
158
159 struct pw_core *pw_filter_get_core(struct pw_filter *filter);
160
166 int
167 pw_filter_connect(struct pw_filter *filter,
168 enum pw_filter_flags flags,
169 const struct spa_pod **params,
170 uint32_t n_params );
171
174 uint32_t
175 pw_filter_get_node_id(struct pw_filter *filter);
176
178 int pw_filter_disconnect(struct pw_filter *filter);
179
181 void *pw_filter_add_port(struct pw_filter *filter,
182 enum pw_direction direction,
183 enum pw_filter_port_flags flags,
184 size_t port_data_size,
185 struct pw_properties *props,
186 const struct spa_pod **params,
188 uint32_t n_params );
189
191 int pw_filter_remove_port(void *port_data );
192
194 const struct pw_properties *pw_filter_get_properties(struct pw_filter *filter,
195 void *port_data);
196
198 int pw_filter_update_properties(struct pw_filter *filter,
199 void *port_data, const struct spa_dict *dict);
200
202 int pw_filter_set_error(struct pw_filter *filter,
203 int res,
204 const char *error,
205 ...
206 ) SPA_PRINTF_FUNC(3, 4);
207
209 int
210 pw_filter_update_params(struct pw_filter *filter,
211 void *port_data,
212 const struct spa_pod **params,
213 uint32_t n_params );
214
215
216 #if 0
218 struct pw_time {
219 int64_t now;
220 struct spa_fraction rate;
221 uint64_t ticks;
223 };
224 #endif
225
227 int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time);
228
231 struct pw_buffer *pw_filter_dequeue_buffer(void *port_data);
232
234 int pw_filter_queue_buffer(void *port_data, struct pw_buffer *buffer);
235
237 void *pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples);
238
240 int pw_filter_set_active(struct pw_filter *filter, bool active);
241
244 int pw_filter_flush(struct pw_filter *filter, bool drain);
245
250 #ifdef __cplusplus
251 }
252 #endif
253
254 #endif /* PIPEWIRE_FILTER_H */
buffer.h
core.h
pw_filter_get_core
struct pw_core * pw_filter_get_core(struct pw_filter *filter)
Definition: filter.c:1400
pw_filter_remove_port
int pw_filter_remove_port(void *port_data)
remove a port from the filter
Definition: filter.c:1700
pw_filter_flags
pw_filter_flags
Extra flags that can be used in pw_filter_connect()
Definition: pipewire/src/pipewire/filter.h:112
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:1451
pw_filter_new
struct pw_filter * pw_filter_new(struct pw_core *core, const char *name, struct pw_properties *props)
Create a new unconneced PipeWire Filter.
Definition: filter.c:1245
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:1632
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:1814
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:1377
pw_filter_get_state
enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error)
Definition: filter.c:1392
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:1536
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:1412
pw_filter_set_error
int pw_filter_set_error(struct pw_filter *filter, int res, const char *error,...) 1(3
Set the filter in error state.
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:1312
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:1833
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:1267
pw_filter_update_params
int 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:1743
pw_filter_port_flags
pw_filter_port_flags
Definition: pipewire/src/pipewire/filter.h:125
pw_filter_disconnect
int pw_filter_disconnect(struct pw_filter *filter)
Disconnect filter
Definition: filter.c:1542
pw_filter_state
pw_filter_state
The state of a filter
Definition: pipewire/src/pipewire/filter.h:56
pw_filter_set_active
int pw_filter_set_active(struct pw_filter *filter, bool active)
Activate or deactivate the filter
Definition: filter.c:1769
pw_filter_get_name
const char * pw_filter_get_name(struct pw_filter *filter)
Definition: filter.c:1406
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:1848
pw_filter_get_time
int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time)
Query the time on the filter
Definition: filter.c:1776
pw_filter_flush
int pw_filter_flush(struct pw_filter *filter, bool drain)
Flush a filter.
Definition: filter.c:1903
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:1425
pw_filter_destroy
void pw_filter_destroy(struct pw_filter *filter)
Destroy a filter
Definition: filter.c:1330
PW_FILTER_FLAG_NONE
@ PW_FILTER_FLAG_NONE
no flags
Definition: pipewire/src/pipewire/filter.h:113
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: pipewire/src/pipewire/filter.h:120
PW_FILTER_FLAG_INACTIVE
@ PW_FILTER_FLAG_INACTIVE
start the filter inactive, pw_filter_set_active() needs to be called explicitly
Definition: pipewire/src/pipewire/filter.h:114
PW_FILTER_FLAG_RT_PROCESS
@ PW_FILTER_FLAG_RT_PROCESS
call process from the realtime thread
Definition: pipewire/src/pipewire/filter.h:118
PW_FILTER_FLAG_DRIVER
@ PW_FILTER_FLAG_DRIVER
be a driver
Definition: pipewire/src/pipewire/filter.h:117
PW_FILTER_PORT_FLAG_ALLOC_BUFFERS
@ PW_FILTER_PORT_FLAG_ALLOC_BUFFERS
the application will allocate buffer memory.
Definition: pipewire/src/pipewire/filter.h:128
PW_FILTER_PORT_FLAG_MAP_BUFFERS
@ PW_FILTER_PORT_FLAG_MAP_BUFFERS
mmap the buffers except DmaBuf
Definition: pipewire/src/pipewire/filter.h:127
PW_FILTER_PORT_FLAG_NONE
@ PW_FILTER_PORT_FLAG_NONE
no flags
Definition: pipewire/src/pipewire/filter.h:126
PW_FILTER_STATE_STREAMING
@ PW_FILTER_STATE_STREAMING
filter is streaming
Definition: pipewire/src/pipewire/filter.h:61
PW_FILTER_STATE_ERROR
@ PW_FILTER_STATE_ERROR
the stream is in error
Definition: pipewire/src/pipewire/filter.h:57
PW_FILTER_STATE_UNCONNECTED
@ PW_FILTER_STATE_UNCONNECTED
unconnected
Definition: pipewire/src/pipewire/filter.h:58
PW_FILTER_STATE_CONNECTING
@ PW_FILTER_STATE_CONNECTING
connection is in progress
Definition: pipewire/src/pipewire/filter.h:59
PW_FILTER_STATE_PAUSED
@ PW_FILTER_STATE_PAUSED
filter is connected and paused
Definition: pipewire/src/pipewire/filter.h:60
pw_direction
#define pw_direction
The direction of a port.
Definition: port.h:56
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:205
io.h
props
const char * props
Definition: media-session.c:2382
name
const char * name
Definition: media-session.c:2379
param.h
stream.h
buffer
Definition: filter.c:59
data
user data to add to an object
Definition: filter.c:75
filter
Definition: filter.c:126
param
Definition: filter.c:80
pw_buffer
Definition: stream.h:175
pw_buffer::size
uint64_t size
This field is set by the user and the sum of all queued buffer is returned in the time info.
Definition: stream.h:178
pw_buffer::buffer
struct spa_buffer * buffer
the spa buffer
Definition: stream.h:176
pw_buffer::user_data
void * user_data
user data attached to the buffer
Definition: stream.h:177
pw_filter_events
Events for a filter.
Definition: pipewire/src/pipewire/filter.h:78
pw_filter_events::process
void(* process)(void *data, struct spa_io_position *position)
do processing.
Definition: pipewire/src/pipewire/filter.h:102
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: pipewire/src/pipewire/filter.h:91
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: pipewire/src/pipewire/filter.h:88
pw_filter_events::version
uint32_t version
Definition: pipewire/src/pipewire/filter.h:80
pw_filter_events::drained
void(* drained)(void *data)
The filter is drained.
Definition: pipewire/src/pipewire/filter.h:105
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: pipewire/src/pipewire/filter.h:97
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: pipewire/src/pipewire/filter.h:95
pw_filter_events::destroy
void(* destroy)(void *data)
Definition: pipewire/src/pipewire/filter.h:82
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: pipewire/src/pipewire/filter.h:84
pw_loop
Definition: pipewire/src/pipewire/loop.h:47
pw_properties
Definition: properties.h:49
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition: properties.h:50
pw_time
A time structure.
Definition: stream.h:194
pw_time::rate
struct spa_fraction rate
the rate of ticks and delay
Definition: stream.h:196
pw_time::ticks
uint64_t ticks
the ticks at now.
Definition: stream.h:197
pw_time::now
int64_t now
the monotonic time in nanoseconds
Definition: stream.h:195
spa_buffer
A Buffer.
Definition: buffer/buffer.h:93
spa_dict
Definition: utils/dict.h:48
spa_fraction
Definition: defs.h:104
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:295
spa_io_position
The position information adds extra meaning to the raw clock times.
Definition: io.h:271
spa_io_position::state
uint32_t state
one of enum spa_io_position_state
Definition: io.h:280
spa_pod
Definition: pod/pod.h:50