PipeWire  0.3.66
src/pipewire/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
9 extern "C" {
10 #endif
11 
26 struct pw_filter;
27 
28 #include <spa/buffer/buffer.h>
29 #include <spa/node/io.h>
31 #include <spa/pod/command.h>
32 
33 #include <pipewire/core.h>
34 #include <pipewire/stream.h>
35 
37 enum pw_filter_state {
43 };
44 
45 #if 0
46 struct pw_buffer {
47  struct spa_buffer *buffer;
48  void *user_data;
49  uint64_t size;
54 };
55 #endif
56 
59 struct pw_filter_events {
60 #define PW_VERSION_FILTER_EVENTS 1
61  uint32_t version;
62 
63  void (*destroy) (void *data);
65  void (*state_changed) (void *data, enum pw_filter_state old,
66  enum pw_filter_state state, const char *error);
67 
69  void (*io_changed) (void *data, void *port_data,
70  uint32_t id, void *area, uint32_t size);
72  void (*param_changed) (void *data, void *port_data,
73  uint32_t id, const struct spa_pod *param);
74 
76  void (*add_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
78  void (*remove_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
79 
83  void (*process) (void *data, struct spa_io_position *position);
84 
86  void (*drained) (void *data);
87 
89  void (*command) (void *data, const struct spa_command *command);
90 };
91 
93 const char * pw_filter_state_as_string(enum pw_filter_state state);
94 
96 enum pw_filter_flags {
98  PW_FILTER_FLAG_INACTIVE = (1 << 0),
101  PW_FILTER_FLAG_DRIVER = (1 << 1),
104  PW_FILTER_FLAG_CUSTOM_LATENCY = (1 << 3),
107 };
108 
115 };
116 
119 struct pw_filter *
120 pw_filter_new(struct pw_core *core,
121  const char *name,
122  struct pw_properties *props );
123 
124 struct pw_filter *
125 pw_filter_new_simple(struct pw_loop *loop,
126  const char *name,
127  struct pw_properties *props,
128  const struct pw_filter_events *events,
129  void *data );
130 
132 void pw_filter_destroy(struct pw_filter *filter);
133 
134 void pw_filter_add_listener(struct pw_filter *filter,
135  struct spa_hook *listener,
136  const struct pw_filter_events *events,
137  void *data);
138 
139 enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error);
140 
141 const char *pw_filter_get_name(struct pw_filter *filter);
142 
143 struct pw_core *pw_filter_get_core(struct pw_filter *filter);
144 
150 int
151 pw_filter_connect(struct pw_filter *filter,
152  enum pw_filter_flags flags,
153  const struct spa_pod **params,
154  uint32_t n_params );
155 
158 uint32_t
159 pw_filter_get_node_id(struct pw_filter *filter);
160 
162 int pw_filter_disconnect(struct pw_filter *filter);
163 
165 void *pw_filter_add_port(struct pw_filter *filter,
166  enum pw_direction direction,
167  enum pw_filter_port_flags flags,
168  size_t port_data_size,
169  struct pw_properties *props,
170  const struct spa_pod **params,
172  uint32_t n_params );
173 
175 int pw_filter_remove_port(void *port_data );
176 
178 const struct pw_properties *pw_filter_get_properties(struct pw_filter *filter,
179  void *port_data);
180 
182 int pw_filter_update_properties(struct pw_filter *filter,
183  void *port_data, const struct spa_dict *dict);
184 
186 int pw_filter_set_error(struct pw_filter *filter,
187  int res,
188  const char *error,
189  ...
190  ) SPA_PRINTF_FUNC(3, 4);
191 
193 int
194 pw_filter_update_params(struct pw_filter *filter,
195  void *port_data,
196  const struct spa_pod **params,
197  uint32_t n_params );
198 
199 
203 int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time);
204 
207 struct pw_buffer *pw_filter_dequeue_buffer(void *port_data);
208 
210 int pw_filter_queue_buffer(void *port_data, struct pw_buffer *buffer);
211 
213 void *pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples);
214 
216 int pw_filter_set_active(struct pw_filter *filter, bool active);
217 
220 int pw_filter_flush(struct pw_filter *filter, bool drain);
221 
226 bool pw_filter_is_driving(struct pw_filter *filter);
227 
230 int pw_filter_trigger_process(struct pw_filter *filter);
231 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif /* PIPEWIRE_FILTER_H */
spa/buffer/buffer.h
pipewire/core.h
struct pw_core * pw_filter_get_core(struct pw_filter *filter)
Definition: filter.c:1432
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:102
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:1490
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:1274
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:1674
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:1838
void pw_filter_add_listener(struct pw_filter *filter, struct spa_hook *listener, const struct pw_filter_events *events, void *data)
Definition: filter.c:1409
enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error)
Definition: filter.c:1424
uint32_t pw_filter_get_node_id(struct pw_filter *filter)
Get the node ID of the filter.
Definition: filter.c:1579
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:1444
int pw_filter_set_error(struct pw_filter *filter, int res, const char *error,...) 1(3
Set the filter in error state.
const char * pw_filter_state_as_string(enum pw_filter_state state)
Convert a filter state to a readable string
Definition: filter.c:1341
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:1857
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:1296
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:1786
pw_filter_port_flags
Definition: src/pipewire/filter.h:115
int pw_filter_trigger_process(struct pw_filter *filter)
Trigger a push/pull on the filter.
Definition: filter.c:1964
int pw_filter_disconnect(struct pw_filter *filter)
Disconnect filter
Definition: filter.c:1585
pw_filter_state
The state of a filter
Definition: src/pipewire/filter.h:42
int pw_filter_set_active(struct pw_filter *filter, bool active)
Activate or deactivate the filter
Definition: filter.c:1812
const char * pw_filter_get_name(struct pw_filter *filter)
Definition: filter.c:1438
void * pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples)
Get a data pointer to the buffer data.
Definition: filter.c:1872
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:1819
bool pw_filter_is_driving(struct pw_filter *filter)
Check if the filter is driving.
Definition: filter.c:1936
int pw_filter_flush(struct pw_filter *filter, bool drain)
Flush a filter.
Definition: filter.c:1927
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:1457
void pw_filter_destroy(struct pw_filter *filter)
Destroy a filter
Definition: filter.c:1359
@ PW_FILTER_FLAG_NONE
no flags
Definition: src/pipewire/filter.h:103
@ 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:110
@ PW_FILTER_FLAG_INACTIVE
start the filter inactive, pw_filter_set_active() needs to be called explicitly
Definition: src/pipewire/filter.h:104
@ PW_FILTER_FLAG_RT_PROCESS
call process from the realtime thread
Definition: src/pipewire/filter.h:108
@ PW_FILTER_FLAG_DRIVER
be a driver
Definition: src/pipewire/filter.h:107
@ PW_FILTER_PORT_FLAG_ALLOC_BUFFERS
the application will allocate buffer memory.
Definition: src/pipewire/filter.h:118
@ PW_FILTER_PORT_FLAG_MAP_BUFFERS
mmap the buffers except DmaBuf
Definition: src/pipewire/filter.h:117
@ PW_FILTER_PORT_FLAG_NONE
no flags
Definition: src/pipewire/filter.h:116
@ PW_FILTER_STATE_STREAMING
filter is streaming
Definition: src/pipewire/filter.h:47
@ PW_FILTER_STATE_ERROR
the stream is in error
Definition: src/pipewire/filter.h:43
@ PW_FILTER_STATE_UNCONNECTED
unconnected
Definition: src/pipewire/filter.h:44
@ PW_FILTER_STATE_CONNECTING
connection is in progress
Definition: src/pipewire/filter.h:45
@ PW_FILTER_STATE_PAUSED
filter is connected and paused
Definition: src/pipewire/filter.h:46
#define pw_direction
The direction of a port.
Definition: port.h:43
#define SPA_DEPRECATED
Definition: defs.h:279
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:273
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:191
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:194
struct spa_buffer * buffer
the spa buffer
Definition: stream.h:192
void * user_data
user data attached to the buffer
Definition: stream.h:193
Events for a filter.
Definition: src/pipewire/filter.h:64
void(* process)(void *data, struct spa_io_position *position)
do processing.
Definition: src/pipewire/filter.h:89
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:78
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:75
uint32_t version
Definition: src/pipewire/filter.h:67
void(* drained)(void *data)
The filter is drained.
Definition: src/pipewire/filter.h:92
void(* command)(void *data, const struct spa_command *command)
A command notify, Since 0.3.39:1.
Definition: src/pipewire/filter.h:95
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:84
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:82
void(* destroy)(void *data)
Definition: src/pipewire/filter.h:69
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:71
Definition: src/pipewire/loop.h:31
Definition: properties.h:33
struct spa_dict dict
dictionary of key/values
Definition: properties.h:34
A time structure.
Definition: stream.h:281
A Buffer.
Definition: buffer/buffer.h:90
Definition: pod/command.h:29
Definition: utils/dict.h:39
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:331
The position information adds extra meaning to the raw clock times.
Definition: io.h:273
Definition: pod/pod.h:43