PipeWire: pipewire/stream.h Source File

PipeWire 0.3.51

stream.h
Go to the documentation of this file.
1/* PipeWire
2 *
3 * Copyright © 2018 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_STREAM_H
26#define PIPEWIRE_STREAM_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
161struct pw_stream;
162
163#include <spa/buffer/buffer.h>
164#include <spa/param/param.h>
165#include <spa/pod/command.h>
166
168enum pw_stream_state {
169 PW_STREAM_STATE_ERROR = -1,
170 PW_STREAM_STATE_UNCONNECTED = 0,
171 PW_STREAM_STATE_CONNECTING = 1,
172 PW_STREAM_STATE_PAUSED = 2,
173 PW_STREAM_STATE_STREAMING = 3
174};
175
178struct pw_buffer {
179 struct spa_buffer *buffer;
180 void *user_data;
181 uint64_t size;
185 uint64_t requested;
190};
191
192struct pw_stream_control {
193 const char *name;
194 uint32_t flags;
195 float def;
196 float min;
197 float max;
198 float *values;
199 uint32_t n_values;
200 uint32_t max_values;
201};
202
268struct pw_time {
269 int64_t now;
275 struct spa_fraction rate;
277 uint64_t ticks;
280 int64_t delay;
289 uint64_t queued;
292 uint64_t buffered;
295 uint32_t queued_buffers;
296 uint32_t avail_buffers;
297};
298
299#include <pipewire/port.h>
300
303struct pw_stream_events {
304#define PW_VERSION_STREAM_EVENTS 2
305 uint32_t version;
306
307 void (*destroy) (void *data);
309 void (*state_changed) (void *data, enum pw_stream_state old,
310 enum pw_stream_state state, const char *error);
311
313 void (*control_info) (void *data, uint32_t id, const struct pw_stream_control *control);
314
316 void (*io_changed) (void *data, uint32_t id, void *area, uint32_t size);
318 void (*param_changed) (void *data, uint32_t id, const struct spa_pod *param);
319
321 void (*add_buffer) (void *data, struct pw_buffer *buffer);
323 void (*remove_buffer) (void *data, struct pw_buffer *buffer);
324
329 void (*process) (void *data);
330
332 void (*drained) (void *data);
333
335 void (*command) (void *data, const struct spa_command *command);
336
338 void (*trigger_done) (void *data);
339};
340
342const char * pw_stream_state_as_string(enum pw_stream_state state);
343
345enum pw_stream_flags {
346 PW_STREAM_FLAG_NONE = 0,
347 PW_STREAM_FLAG_AUTOCONNECT = (1 << 0),
349 PW_STREAM_FLAG_INACTIVE = (1 << 1),
352 PW_STREAM_FLAG_MAP_BUFFERS = (1 << 2),
353 PW_STREAM_FLAG_DRIVER = (1 << 3),
354 PW_STREAM_FLAG_RT_PROCESS = (1 << 4),
357 PW_STREAM_FLAG_NO_CONVERT = (1 << 5),
358 PW_STREAM_FLAG_EXCLUSIVE = (1 << 6),
360 PW_STREAM_FLAG_DONT_RECONNECT = (1 << 7),
362 PW_STREAM_FLAG_ALLOC_BUFFERS = (1 << 8),
365 PW_STREAM_FLAG_TRIGGER = (1 << 9),
370};
371
374struct pw_stream *
375 pw_stream_new(struct pw_core *core,
376 const char *name,
377 struct pw_properties *props );
378
379struct pw_stream *
380 pw_stream_new_simple(struct pw_loop *loop,
381 const char *name,
382 struct pw_properties *props,
383 const struct pw_stream_events *events,
384 void *data );
385
387void pw_stream_destroy(struct pw_stream *stream);
388
389void pw_stream_add_listener(struct pw_stream *stream,
390 struct spa_hook *listener,
391 const struct pw_stream_events *events,
392 void *data);
393
394enum pw_stream_state pw_stream_get_state(struct pw_stream *stream, const char **error);
395
396const char *pw_stream_get_name(struct pw_stream *stream);
397
398struct pw_core *pw_stream_get_core(struct pw_stream *stream);
399
400const struct pw_properties *pw_stream_get_properties(struct pw_stream *stream);
401
402int pw_stream_update_properties(struct pw_stream *stream, const struct spa_dict *dict);
403
409int
410 pw_stream_connect(struct pw_stream *stream,
411 enum pw_direction direction,
412 uint32_t target_id,
415 enum pw_stream_flags flags,
416 const struct spa_pod **params,
419 uint32_t n_params );
420
423uint32_t
424 pw_stream_get_node_id(struct pw_stream *stream);
425
427int pw_stream_disconnect(struct pw_stream *stream);
428
430int pw_stream_set_error(struct pw_stream *stream,
431 int res,
432 const char *error,
433 ...) SPA_PRINTF_FUNC(3, 4);
434
441int
442 pw_stream_update_params(struct pw_stream *stream,
443 const struct spa_pod **params,
446 uint32_t n_params );
447
449const struct pw_stream_control *pw_stream_get_control(struct pw_stream *stream, uint32_t id);
450
452int pw_stream_set_control(struct pw_stream *stream, uint32_t id, uint32_t n_values, float *values, ...);
453
455int pw_stream_get_time_n(struct pw_stream *stream, struct pw_time *time, size_t size);
456
459 SPA_DEPRECATED
460int pw_stream_get_time(struct pw_stream *stream, struct pw_time *time);
461
464struct pw_buffer *pw_stream_dequeue_buffer(struct pw_stream *stream);
465
467int pw_stream_queue_buffer(struct pw_stream *stream, struct pw_buffer *buffer);
468
470int pw_stream_set_active(struct pw_stream *stream, bool active);
471
474int pw_stream_flush(struct pw_stream *stream, bool drain);
475
480bool pw_stream_is_driving(struct pw_stream *stream);
481
484int pw_stream_trigger_process(struct pw_stream *stream);
485
490#ifdef __cplusplus
491}
492#endif
493
494#endif /* PIPEWIRE_STREAM_H */
buffer.h
spa/buffer/buffer.h
pw_direction
#define pw_direction
The direction of a port.
Definition: port.h:63
pw_stream_flags
pw_stream_flags
Extra flags that can be used in pw_stream_connect()
Definition: stream.h:351
pw_stream_update_properties
int pw_stream_update_properties(struct pw_stream *stream, const struct spa_dict *dict)
Definition: stream.c:1662
pw_stream_get_state
enum pw_stream_state pw_stream_get_state(struct pw_stream *stream, const char **error)
Definition: stream.c:1642
pw_stream_update_params
int int pw_stream_update_params(struct pw_stream *stream, const struct spa_pod **params, uint32_t n_params)
Complete the negotiation process with result code res.
Definition: stream.c:2053
pw_stream_connect
int pw_stream_connect(struct pw_stream *stream, enum pw_direction direction, uint32_t target_id, enum pw_stream_flags flags, const struct spa_pod **params, uint32_t n_params)
Connect a stream for input or output on port_path.
Definition: stream.c:1764
pw_stream_dequeue_buffer
struct pw_buffer * pw_stream_dequeue_buffer(struct pw_stream *stream)
Get a buffer that can be filled for playback streams or consumed for capture streams.
Definition: stream.c:2216
pw_stream_get_node_id
uint32_t pw_stream_get_node_id(struct pw_stream *stream)
Get the node ID of the stream.
Definition: stream.c:1989
pw_stream_set_error
int pw_stream_set_error(struct pw_stream *stream, int res, const char *error,...) 1(3
Set the stream in error state.
pw_stream_set_control
int pw_stream_set_control(struct pw_stream *stream, uint32_t id, uint32_t n_values, float *values,...)
Set control values.
Definition: stream.c:2071
pw_stream_is_driving
bool pw_stream_is_driving(struct pw_stream *stream)
Check if the stream is driving.
Definition: stream.c:2309
pw_stream_flush
int pw_stream_flush(struct pw_stream *stream, bool drain)
Flush a stream.
Definition: stream.c:2297
pw_stream_new
struct pw_stream * pw_stream_new(struct pw_core *core, const char *name, struct pw_properties *props)
Create a new unconneced Stream.
Definition: stream.c:1489
pw_stream_get_time
int pw_stream_get_time(struct pw_stream *stream, struct pw_time *time)
Query the time on the stream, deprecated since 0.3.50, use pw_stream_get_time_n() to get the fields a...
Definition: stream.c:2161
pw_stream_get_control
const struct pw_stream_control * pw_stream_get_control(struct pw_stream *stream, uint32_t id)
Get control values.
Definition: stream.c:2126
pw_stream_state_as_string
const char * pw_stream_state_as_string(enum pw_stream_state state)
Convert a stream state to a readable string.
Definition: stream.c:1555
pw_stream_state
pw_stream_state
The state of a stream.
Definition: stream.h:173
pw_stream_disconnect
int pw_stream_disconnect(struct pw_stream *stream)
Disconnect stream
Definition: stream.c:1995
pw_stream_set_active
int pw_stream_set_active(struct pw_stream *stream, bool active)
Activate or deactivate the stream.
Definition: stream.c:2140
pw_stream_trigger_process
int pw_stream_trigger_process(struct pw_stream *stream)
Trigger a push/pull on the stream.
Definition: stream.c:2344
pw_stream_queue_buffer
int pw_stream_queue_buffer(struct pw_stream *stream, struct pw_buffer *buffer)
Submit a buffer for playback or recycle a buffer for capture.
Definition: stream.c:2243
pw_stream_get_name
const char * pw_stream_get_name(struct pw_stream *stream)
Definition: stream.c:1650
pw_stream_new_simple
struct pw_stream * pw_stream_new_simple(struct pw_loop *loop, const char *name, struct pw_properties *props, const struct pw_stream_events *events, void *data)
Definition: stream.c:1511
pw_stream_get_properties
const struct pw_properties * pw_stream_get_properties(struct pw_stream *stream)
Definition: stream.c:1656
pw_stream_get_time_n
int pw_stream_get_time_n(struct pw_stream *stream, struct pw_time *time, size_t size)
Query the time on the stream.
Definition: stream.c:2167
pw_stream_add_listener
void pw_stream_add_listener(struct pw_stream *stream, struct spa_hook *listener, const struct pw_stream_events *events, void *data)
Definition: stream.c:1626
pw_stream_destroy
void pw_stream_destroy(struct pw_stream *stream)
Destroy a stream.
Definition: stream.c:1573
pw_stream_get_core
struct pw_core * pw_stream_get_core(struct pw_stream *stream)
Definition: stream.c:1686
PW_STREAM_FLAG_INACTIVE
@ PW_STREAM_FLAG_INACTIVE
start the stream inactive, pw_stream_set_active() needs to be called explicitly
Definition: stream.h:355
PW_STREAM_FLAG_MAP_BUFFERS
@ PW_STREAM_FLAG_MAP_BUFFERS
mmap the buffers except DmaBuf
Definition: stream.h:358
PW_STREAM_FLAG_DRIVER
@ PW_STREAM_FLAG_DRIVER
be a driver
Definition: stream.h:359
PW_STREAM_FLAG_EXCLUSIVE
@ PW_STREAM_FLAG_EXCLUSIVE
require exclusive access to the device
Definition: stream.h:364
PW_STREAM_FLAG_NO_CONVERT
@ PW_STREAM_FLAG_NO_CONVERT
don't convert format
Definition: stream.h:363
PW_STREAM_FLAG_TRIGGER
@ PW_STREAM_FLAG_TRIGGER
the output stream will not be scheduled automatically but _trigger_process() needs to be called.
Definition: stream.h:371
PW_STREAM_FLAG_DONT_RECONNECT
@ PW_STREAM_FLAG_DONT_RECONNECT
don't try to reconnect this stream when the sink/source is removed
Definition: stream.h:366
PW_STREAM_FLAG_AUTOCONNECT
@ PW_STREAM_FLAG_AUTOCONNECT
try to automatically connect this stream
Definition: stream.h:353
PW_STREAM_FLAG_ALLOC_BUFFERS
@ PW_STREAM_FLAG_ALLOC_BUFFERS
the application will allocate buffer memory.
Definition: stream.h:368
PW_STREAM_FLAG_RT_PROCESS
@ PW_STREAM_FLAG_RT_PROCESS
call process from the realtime thread.
Definition: stream.h:360
PW_STREAM_FLAG_NONE
@ PW_STREAM_FLAG_NONE
no flags
Definition: stream.h:352
PW_STREAM_STATE_PAUSED
@ PW_STREAM_STATE_PAUSED
paused
Definition: stream.h:177
PW_STREAM_STATE_CONNECTING
@ PW_STREAM_STATE_CONNECTING
connection is in progress
Definition: stream.h:176
PW_STREAM_STATE_UNCONNECTED
@ PW_STREAM_STATE_UNCONNECTED
unconnected
Definition: stream.h:175
PW_STREAM_STATE_ERROR
@ PW_STREAM_STATE_ERROR
the stream is in error
Definition: stream.h:174
PW_STREAM_STATE_STREAMING
@ PW_STREAM_STATE_STREAMING
streaming
Definition: stream.h:178
SPA_DEPRECATED
#define SPA_DEPRECATED
Definition: defs.h:266
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:260
param.h
spa/param/param.h
command.h
spa/pod/command.h
port.h
pipewire/port.h
pw_buffer
a buffer structure obtained from pw_stream_dequeue_buffer().
Definition: stream.h:183
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:186
pw_buffer::requested
uint64_t requested
For playback streams, this field contains the suggested amount of data to provide.
Definition: stream.h:190
pw_buffer::buffer
struct spa_buffer * buffer
the spa buffer
Definition: stream.h:184
pw_buffer::user_data
void * user_data
user data attached to the buffer
Definition: stream.h:185
pw_core
pw_loop
Definition: loop.h:51
pw_properties
Definition: properties.h:53
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition: properties.h:54
pw_properties::flags
uint32_t flags
extra flags
Definition: properties.h:55
pw_stream_control
Definition: stream.h:197
pw_stream_control::max
float max
max value
Definition: stream.h:202
pw_stream_control::flags
uint32_t flags
extra flags (unused)
Definition: stream.h:199
pw_stream_control::def
float def
default value
Definition: stream.h:200
pw_stream_control::max_values
uint32_t max_values
max values that can be set on this control
Definition: stream.h:205
pw_stream_control::min
float min
min value
Definition: stream.h:201
pw_stream_control::n_values
uint32_t n_values
number of values in array
Definition: stream.h:204
pw_stream_control::values
float * values
array of values
Definition: stream.h:203
pw_stream_events
Events for a stream.
Definition: stream.h:308
pw_stream_events::remove_buffer
void(* remove_buffer)(void *data, struct pw_buffer *buffer)
when a buffer was destroyed for this stream
Definition: stream.h:329
pw_stream_events::control_info
void(* control_info)(void *data, uint32_t id, const struct pw_stream_control *control)
Notify information about a control.
Definition: stream.h:319
pw_stream_events::trigger_done
void(* trigger_done)(void *data)
a trigger_process completed.
Definition: stream.h:344
pw_stream_events::param_changed
void(* param_changed)(void *data, uint32_t id, const struct spa_pod *param)
when a parameter changed
Definition: stream.h:324
pw_stream_events::process
void(* process)(void *data)
when a buffer can be queued (for playback streams) or dequeued (for capture streams).
Definition: stream.h:335
pw_stream_events::command
void(* command)(void *data, const struct spa_command *command)
A command notify, Since 0.3.39:1.
Definition: stream.h:341
pw_stream_events::version
uint32_t version
Definition: stream.h:311
pw_stream_events::state_changed
void(* state_changed)(void *data, enum pw_stream_state old, enum pw_stream_state state, const char *error)
when the stream state changes
Definition: stream.h:315
pw_stream_events::drained
void(* drained)(void *data)
The stream is drained.
Definition: stream.h:338
pw_stream_events::destroy
void(* destroy)(void *data)
Definition: stream.h:313
pw_stream_events::add_buffer
void(* add_buffer)(void *data, struct pw_buffer *buffer)
when a new buffer was created for this stream
Definition: stream.h:327
pw_stream_events::io_changed
void(* io_changed)(void *data, uint32_t id, void *area, uint32_t size)
when io changed on the stream.
Definition: stream.h:322
pw_stream
pw_time
A time structure.
Definition: stream.h:273
pw_time::delay
int64_t delay
delay to device.
Definition: stream.h:285
pw_time::rate
struct spa_fraction rate
the rate of ticks and delay.
Definition: stream.h:280
pw_time::buffered
uint64_t buffered
for audio/raw streams, this contains the extra number of samples buffered in the resampler.
Definition: stream.h:297
pw_time::queued
uint64_t queued
data queued in the stream, this is the sum of the size fields in the pw_buffer that are currently que...
Definition: stream.h:294
pw_time::queued_buffers
uint32_t queued_buffers
The number of buffers that are queued.
Definition: stream.h:300
pw_time::ticks
uint64_t ticks
the ticks at now.
Definition: stream.h:282
pw_time::now
int64_t now
the monotonic time in nanoseconds.
Definition: stream.h:274
pw_time::avail_buffers
uint32_t avail_buffers
The number of buffers that can be dequeued.
Definition: stream.h:301
spa_buffer
A Buffer.
Definition: buffer.h:105
spa_command
Definition: command.h:49
spa_dict
Definition: dict.h:59
spa_fraction
Definition: defs.h:121
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:351
spa_pod
Definition: pod.h:63