PipeWire  0.3.19
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 
41 struct pw_filter;
42 
43 #include <spa/buffer/buffer.h>
44 #include <spa/node/io.h>
45 #include <spa/param/param.h>
46 
47 #include <pipewire/core.h>
48 #include <pipewire/stream.h>
49 
57 };
58 
59 #if 0
60 struct pw_buffer {
61  struct spa_buffer *buffer;
62  void *user_data;
63  uint64_t size;
68 };
69 #endif
70 
74 #define PW_VERSION_FILTER_EVENTS 0
75  uint32_t version;
76 
77  void (*destroy) (void *data);
79  void (*state_changed) (void *data, enum pw_filter_state old,
80  enum pw_filter_state state, const char *error);
81 
83  void (*io_changed) (void *data, void *port_data,
84  uint32_t id, void *area, uint32_t size);
86  void (*param_changed) (void *data, void *port_data,
87  uint32_t id, const struct spa_pod *param);
88 
90  void (*add_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
92  void (*remove_buffer) (void *data, void *port_data, struct pw_buffer *buffer);
93 
97  void (*process) (void *data, struct spa_io_position *position);
98 
100  void (*drained) (void *data);
101 };
102 
104 const char * pw_filter_state_as_string(enum pw_filter_state state);
105 
109  PW_FILTER_FLAG_INACTIVE = (1 << 0),
113  PW_FILTER_FLAG_RT_PROCESS = (1 << 2),
115 };
116 
123 };
124 
127 struct pw_filter *
128 pw_filter_new(struct pw_core *core,
129  const char *name,
130  struct pw_properties *props );
131 
132 struct pw_filter *
133 pw_filter_new_simple(struct pw_loop *loop,
134  const char *name,
135  struct pw_properties *props,
136  const struct pw_filter_events *events,
137  void *data );
138 
140 void pw_filter_destroy(struct pw_filter *filter);
141 
143  struct spa_hook *listener,
144  const struct pw_filter_events *events,
145  void *data);
146 
147 enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error);
148 
149 const char *pw_filter_get_name(struct pw_filter *filter);
150 
151 struct pw_core *pw_filter_get_core(struct pw_filter *filter);
152 
158 int
160  enum pw_filter_flags flags,
161  const struct spa_pod **params,
162  uint32_t n_params );
163 
166 uint32_t
168 
171 
173 void *pw_filter_add_port(struct pw_filter *filter,
174  enum pw_direction direction,
175  enum pw_filter_port_flags flags,
176  size_t port_data_size,
177  struct pw_properties *props,
178  const struct spa_pod **params,
180  uint32_t n_params );
181 
183 int pw_filter_remove_port(void *port_data );
184 
187  void *port_data);
188 
191  void *port_data, const struct spa_dict *dict);
192 
195  int res,
196  const char *error, ... ) SPA_PRINTF_FUNC(3, 4);
197 
199 int
201  void *port_data,
202  const struct spa_pod **params,
203  uint32_t n_params );
204 
205 
206 #if 0
208 struct pw_time {
209  int64_t now;
210  struct spa_fraction rate;
211  uint64_t ticks;
213 };
214 #endif
215 
217 int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time);
218 
221 struct pw_buffer *pw_filter_dequeue_buffer(void *port_data);
222 
224 int pw_filter_queue_buffer(void *port_data, struct pw_buffer *buffer);
225 
227 void *pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples);
228 
230 int pw_filter_set_active(struct pw_filter *filter, bool active);
231 
234 int pw_filter_flush(struct pw_filter *filter, bool drain);
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif /* PIPEWIRE_FILTER_H */
PipeWire filter object class.
const char * pw_filter_state_as_string(enum pw_filter_state state)
Convert a filter state to a readable string.
Definition: filter.c:1107
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:1232
uint32_t pw_filter_get_node_id(struct pw_filter *filter)
Get the node ID of the filter.
Definition: filter.c:1314
int pw_filter_disconnect(struct pw_filter *filter)
Disconnect filter.
Definition: filter.c:1320
struct pw_filter * pw_filter_new(struct pw_core *core, const char *name, struct pw_properties *props)
Create a new unconneced pw_filter.
Definition: filter.c:1039
int pw_filter_set_active(struct pw_filter *filter, bool active)
Activate or deactivate the filter.
Definition: filter.c:1549
int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time)
Query the time on the filter.
Definition: filter.c:1556
void pw_filter_destroy(struct pw_filter *filter)
Destroy a filter.
Definition: filter.c:1125
buffer[1023]
Definition: core.h:330
static uint32_t int int res
Definition: core.h:326
static uint32_t id
Definition: core.h:325
struct pw_core * pw_filter_get_core(struct pw_filter *filter)
Definition: filter.c:1181
int pw_filter_remove_port(void *port_data)
remove a port from the filter
Definition: filter.c:1480
pw_filter_flags
Extra flags that can be used in pw_filter_connect()
Definition: filter.h:107
@ PW_FILTER_FLAG_NONE
no flags
Definition: filter.h:108
@ PW_FILTER_FLAG_INACTIVE
start the filter inactive, pw_filter_set_active() needs to be called explicitly
Definition: filter.h:109
@ PW_FILTER_FLAG_RT_PROCESS
call process from the realtime thread
Definition: filter.h:113
@ PW_FILTER_FLAG_DRIVER
be a driver
Definition: filter.h:112
int pw_filter_set_error(struct pw_filter *filter, int res, const char *error,...) SPA_PRINTF_FUNC(3
Set the filter in error state.
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:1410
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:1594
void pw_filter_add_listener(struct pw_filter *filter, struct spa_hook *listener, const struct pw_filter_events *events, void *data)
Definition: filter.c:1164
enum pw_filter_state pw_filter_get_state(struct pw_filter *filter, const char **error)
Definition: filter.c:1173
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:1193
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:1613
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:1061
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:1523
pw_filter_port_flags
Definition: filter.h:117
@ PW_FILTER_PORT_FLAG_ALLOC_BUFFERS
the application will allocate buffer memory.
Definition: filter.h:120
@ PW_FILTER_PORT_FLAG_MAP_BUFFERS
mmap the buffers except DmaBuf
Definition: filter.h:119
@ PW_FILTER_PORT_FLAG_NONE
no flags
Definition: filter.h:118
pw_filter_state
The state of a filter.
Definition: filter.h:51
@ PW_FILTER_STATE_STREAMING
filter is streaming
Definition: filter.h:56
@ PW_FILTER_STATE_ERROR
the strean is in error
Definition: filter.h:52
@ PW_FILTER_STATE_UNCONNECTED
unconnected
Definition: filter.h:53
@ PW_FILTER_STATE_CONNECTING
connection is in progress
Definition: filter.h:54
@ PW_FILTER_STATE_PAUSED
filter is connected and paused
Definition: filter.h:55
const char * pw_filter_get_name(struct pw_filter *filter)
Definition: filter.c:1187
void * pw_filter_get_dsp_buffer(void *port_data, uint32_t n_samples)
Get a data pointer to the buffer data.
Definition: filter.c:1628
int pw_filter_flush(struct pw_filter *filter, bool drain)
Flush a filter.
Definition: filter.c:1683
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:1206
#define pw_direction
Definition: port.h:47
Definition: filter.c:58
Definition: filter.c:74
Definition: filter.c:116
Definition: filter.c:79
Definition: stream.h:164
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:167
struct spa_buffer * buffer
the spa buffer
Definition: stream.h:165
void * user_data
user data attached to the buffer
Definition: stream.h:166
Events for a filter.
Definition: filter.h:73
void(* process)(void *data, struct spa_io_position *position)
do processing.
Definition: filter.h:97
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:86
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:83
uint32_t version
Definition: filter.h:75
void(* drained)(void *data)
The filter is drained.
Definition: filter.h:100
void(* remove_buffer)(void *data, void *port_data, struct pw_buffer *buffer)
when a buffer was destroyed for a port
Definition: filter.h:92
void(* add_buffer)(void *data, void *port_data, struct pw_buffer *buffer)
when a new buffer was created for a port
Definition: filter.h:90
void(* destroy)(void *data)
Definition: filter.h:77
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:79
PipeWire loop object provides an implementation of the spa loop interfaces.
Definition: loop.h:41
A collection of key/value pairs.
Definition: properties.h:45
struct spa_dict dict
dictionary of key/values
Definition: properties.h:46
A time structure.
Definition: stream.h:183
struct spa_fraction rate
the rate of ticks and delay
Definition: stream.h:185
uint64_t ticks
the ticks at now.
Definition: stream.h:186
int64_t now
the monotonic time in nanoseconds
Definition: stream.h:184