PipeWire 0.3.65
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
29extern "C" {
30#endif
31
46struct pw_filter;
47
48#include <spa/buffer/buffer.h>
49#include <spa/node/io.h>
51#include <spa/pod/command.h>
52
53#include <pipewire/core.h>
54#include <pipewire/stream.h>
55
57enum pw_filter_state {
63};
65#if 0
66struct pw_buffer {
67 struct spa_buffer *buffer;
68 void *user_data;
69 uint64_t size;
74};
75#endif
76
79struct pw_filter_events {
80#define PW_VERSION_FILTER_EVENTS 1
81 uint32_t version;
82
83 void (*destroy) (void *data);
85 void (*state_changed) (void *data, enum pw_filter_state old,
86 enum pw_filter_state state, const char *error);
89 void (*io_changed) (void *data, void *port_data,
90 uint32_t id, void *area, uint32_t size);
92 void (*param_changed) (void *data, void *port_data,
93 uint32_t id, const struct spa_pod *param);
94
96 void (*add_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
98 void (*remove_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
99
103 void (*process) (void *data, struct spa_io_position *position);
106 void (*drained) (void *data);
107
109 void (*command) (void *data, const struct spa_command *command);
110};
111
113const char * pw_filter_state_as_string(enum pw_filter_state state);
114
116enum pw_filter_flags {
118 PW_FILTER_FLAG_INACTIVE = (1 << 0),
121 PW_FILTER_FLAG_DRIVER = (1 << 1),
128
139struct pw_filter *
140pw_filter_new(struct pw_core *core,
141 const char *name,
142 struct pw_properties *props );
143
144struct pw_filter *
145pw_filter_new_simple(struct pw_loop *loop,
146 const char *name,
147 struct pw_properties *props,
148 const struct pw_filter_events *events,
149 void *data );
150
152void pw_filter_destroy(struct pw_filter *filter);
153
154void pw_filter_add_listener(struct pw_filter *filter,
155 struct spa_hook *listener,
156 const struct pw_filter_events *events,
157 void *data);
158
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
171pw_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
179pw_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
214pw_filter_update_params(struct pw_filter *filter,
215 void *port_data,
216 const struct spa_pod **params,
217 uint32_t n_params );
218
219
223int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time);
224
227struct pw_buffer *pw_filter_dequeue_buffer(void *port_data);
228
230int pw_filter_queue_buffer(void *port_data, struct pw_buffer *buffer);
231
233void *pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples);
234
236int pw_filter_set_active(struct pw_filter *filter, bool active);
237
240int pw_filter_flush(struct pw_filter *filter, bool drain);
241
246#ifdef __cplusplus
247}
248#endif
249
250#endif /* PIPEWIRE_FILTER_H */
spa/buffer/buffer.h
pipewire/core.h
const char * pw_filter_get_name(struct pw_filter *filter)
Definition: filter.c:1449
int pw_filter_remove_port(void *port_data)
remove a port from the filter
Definition: filter.c:1753
pw_filter_flags
Extra flags that can be used in pw_filter_connect()
Definition: src/pipewire/filter.h:122
const char * pw_filter_state_as_string(enum pw_filter_state state)
Convert a filter state to a readable string
Definition: filter.c:1352
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:1501
struct pw_core * pw_filter_get_core(struct pw_filter *filter)
Definition: filter.c:1443
void pw_filter_add_listener(struct pw_filter *filter, struct spa_hook *listener, const struct pw_filter_events *events, void *data)
Definition: filter.c:1420
enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error)
Definition: filter.c:1435
uint32_t pw_filter_get_node_id(struct pw_filter *filter)
Get the node ID of the filter.
Definition: filter.c:1590
int pw_filter_set_error(struct pw_filter *filter, int res, const char *error,...) 1(3
Set the filter in error state.
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:1886
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:1796
pw_filter_port_flags
Definition: src/pipewire/filter.h:135
int pw_filter_disconnect(struct pw_filter *filter)
Disconnect filter
Definition: filter.c:1596
pw_filter_state
The state of a filter
Definition: src/pipewire/filter.h:62
struct pw_filter * pw_filter_new(struct pw_core *core, const char *name, struct pw_properties *props)
Create a new unconneced Filter.
Definition: filter.c:1285
int pw_filter_set_active(struct pw_filter *filter, bool active)
Activate or deactivate the filter
Definition: filter.c:1822
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:1685
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:1829
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:1867
int pw_filter_flush(struct pw_filter *filter, bool drain)
Flush a filter.
Definition: filter.c:1956
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:1455
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:1468
void pw_filter_destroy(struct pw_filter *filter)
Destroy a filter
Definition: filter.c:1370
void * pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples)
Get a data pointer to the buffer data.
Definition: filter.c:1901
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:1307
@ PW_FILTER_FLAG_NONE
no flags
Definition: src/pipewire/filter.h:123
@ PW_FILTER_FLAG_CUSTOM_LATENCY
don't call the default latency algorithm but emit the param_changed event for the ports when Latency ...
Definition: src/pipewire/filter.h:130
@ PW_FILTER_FLAG_INACTIVE
start the filter inactive, pw_filter_set_active() needs to be called explicitly
Definition: src/pipewire/filter.h:124
@ PW_FILTER_FLAG_RT_PROCESS
call process from the realtime thread
Definition: src/pipewire/filter.h:128
@ PW_FILTER_FLAG_DRIVER
be a driver
Definition: src/pipewire/filter.h:127
@ PW_FILTER_PORT_FLAG_ALLOC_BUFFERS
the application will allocate buffer memory.
Definition: src/pipewire/filter.h:138
@ PW_FILTER_PORT_FLAG_MAP_BUFFERS
mmap the buffers except DmaBuf
Definition: src/pipewire/filter.h:137
@ PW_FILTER_PORT_FLAG_NONE
no flags
Definition: src/pipewire/filter.h:136
@ PW_FILTER_STATE_STREAMING
filter is streaming
Definition: src/pipewire/filter.h:67
@ PW_FILTER_STATE_ERROR
the stream is in error
Definition: src/pipewire/filter.h:63
@ PW_FILTER_STATE_UNCONNECTED
unconnected
Definition: src/pipewire/filter.h:64
@ PW_FILTER_STATE_CONNECTING
connection is in progress
Definition: src/pipewire/filter.h:65
@ PW_FILTER_STATE_PAUSED
filter is connected and paused
Definition: src/pipewire/filter.h:66
#define pw_direction
The direction of a port.
Definition: port.h:63
#define SPA_DEPRECATED
Definition: defs.h:295
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:289
spa/node/io.h
spa/param/param.h
spa/pod/command.h
pipewire/stream.h
a buffer structure obtained from pw_stream_dequeue_buffer().
Definition: stream.h:211
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:214
struct spa_buffer * buffer
the spa buffer
Definition: stream.h:212
void * user_data
user data attached to the buffer
Definition: stream.h:213
Events for a filter.
Definition: src/pipewire/filter.h:84
void(* process)(void *data, struct spa_io_position *position)
do processing.
Definition: src/pipewire/filter.h:109
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: src/pipewire/filter.h:98
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: src/pipewire/filter.h:95
uint32_t version
Definition: src/pipewire/filter.h:87
void(* drained)(void *data)
The filter is drained.
Definition: src/pipewire/filter.h:112
void(* command)(void *data, const struct spa_command *command)
A command notify, Since 0.3.39:1.
Definition: src/pipewire/filter.h:115
void(* remove_buffer)(void *data, void *port_data, struct pw_buffer *buffer)
when a buffer was destroyed for a port
Definition: src/pipewire/filter.h:104
void(* add_buffer)(void *data, void *port_data, struct pw_buffer *buffer)
when a new buffer was created for a port
Definition: src/pipewire/filter.h:102
void(* destroy)(void *data)
Definition: src/pipewire/filter.h:89
void(* state_changed)(void *data, enum pw_filter_state old, enum pw_filter_state state, const char *error)
when the filter state changes
Definition: src/pipewire/filter.h:91
Definition: src/pipewire/loop.h:51
Definition: properties.h:53
struct spa_dict dict
dictionary of key/values
Definition: properties.h:54
A time structure.
Definition: stream.h:301
A Buffer.
Definition: buffer/buffer.h:109
Definition: pod/command.h:49
Definition: utils/dict.h:59
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:351
The position information adds extra meaning to the raw clock times.
Definition: io.h:293
Definition: pod/pod.h:63