PipeWire  1.0.7
stream.h
1 /* PipeWire */
2 /* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4 
5 #ifndef PIPEWIRE_STREAM_H
6 #define PIPEWIRE_STREAM_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
174 struct pw_stream;
175 
176 #include <spa/buffer/buffer.h>
177 #include <spa/param/param.h>
178 #include <spa/pod/command.h>
179 
181 enum pw_stream_state {
182  PW_STREAM_STATE_ERROR = -1,
187 };
191 struct pw_buffer {
192  struct spa_buffer *buffer;
193  void *user_data;
199  uint64_t size;
203  uint64_t requested;
208  uint64_t time;
213 };
214 
215 struct pw_stream_control {
216  const char *name;
217  uint32_t flags;
218  float def;
219  float min;
220  float max;
221  float *values;
222  uint32_t n_values;
223  uint32_t max_values;
224 };
299 struct pw_time {
300  int64_t now;
306  struct spa_fraction rate;
308  uint64_t ticks;
311  int64_t delay;
320  uint64_t queued;
323  uint64_t buffered;
326  uint32_t queued_buffers;
327  uint32_t avail_buffers;
328  uint64_t size;
332 };
334 #include <pipewire/port.h>
335 
338 struct pw_stream_events {
339 #define PW_VERSION_STREAM_EVENTS 2
340  uint32_t version;
341 
342  void (*destroy) (void *data);
344  void (*state_changed) (void *data, enum pw_stream_state old,
345  enum pw_stream_state state, const char *error);
348  void (*control_info) (void *data, uint32_t id, const struct pw_stream_control *control);
349 
351  void (*io_changed) (void *data, uint32_t id, void *area, uint32_t size);
353  void (*param_changed) (void *data, uint32_t id, const struct spa_pod *param);
356  void (*add_buffer) (void *data, struct pw_buffer *buffer);
358  void (*remove_buffer) (void *data, struct pw_buffer *buffer);
364  void (*process) (void *data);
365 
367  void (*drained) (void *data);
368 
370  void (*command) (void *data, const struct spa_command *command);
371 
373  void (*trigger_done) (void *data);
374 };
375 
377 const char * pw_stream_state_as_string(enum pw_stream_state state);
378 
380 enum pw_stream_flags {
381  PW_STREAM_FLAG_NONE = 0,
382  PW_STREAM_FLAG_AUTOCONNECT = (1 << 0),
384  PW_STREAM_FLAG_INACTIVE = (1 << 1),
389  PW_STREAM_FLAG_DRIVER = (1 << 3),
394  PW_STREAM_FLAG_EXCLUSIVE = (1 << 6),
398  PW_STREAM_FLAG_ALLOC_BUFFERS = (1 << 8),
401  PW_STREAM_FLAG_TRIGGER = (1 << 9),
406  PW_STREAM_FLAG_ASYNC = (1 << 10),
413  PW_STREAM_FLAG_EARLY_PROCESS = (1 << 11),
418 };
422 struct pw_stream *
423 pw_stream_new(struct pw_core *core,
424  const char *name,
425  struct pw_properties *props );
426 
427 struct pw_stream *
428 pw_stream_new_simple(struct pw_loop *loop,
429  const char *name,
430  struct pw_properties *props,
431  const struct pw_stream_events *events,
432  void *data );
433 
435 void pw_stream_destroy(struct pw_stream *stream);
436 
437 void pw_stream_add_listener(struct pw_stream *stream,
438  struct spa_hook *listener,
439  const struct pw_stream_events *events,
440  void *data);
441 
442 enum pw_stream_state pw_stream_get_state(struct pw_stream *stream, const char **error);
443 
444 const char *pw_stream_get_name(struct pw_stream *stream);
445 
446 struct pw_core *pw_stream_get_core(struct pw_stream *stream);
447 
448 const struct pw_properties *pw_stream_get_properties(struct pw_stream *stream);
449 
450 int pw_stream_update_properties(struct pw_stream *stream, const struct spa_dict *dict);
451 
457 int
458 pw_stream_connect(struct pw_stream *stream,
459  enum pw_direction direction,
460  uint32_t target_id,
470  enum pw_stream_flags flags,
471  const struct spa_pod **params,
474  uint32_t n_params );
475 
478 uint32_t
479 pw_stream_get_node_id(struct pw_stream *stream);
480 
482 int pw_stream_disconnect(struct pw_stream *stream);
483 
485 int pw_stream_set_error(struct pw_stream *stream,
486  int res,
487  const char *error,
488  ...) SPA_PRINTF_FUNC(3, 4);
489 
491 int
492 pw_stream_update_params(struct pw_stream *stream,
493  const struct spa_pod **params,
494  uint32_t n_params );
495 
500 int pw_stream_set_param(struct pw_stream *stream,
501  uint32_t id,
502  const struct spa_pod *param );
503 
505 const struct pw_stream_control *pw_stream_get_control(struct pw_stream *stream, uint32_t id);
506 
508 int pw_stream_set_control(struct pw_stream *stream, uint32_t id, uint32_t n_values, float *values, ...);
509 
511 int pw_stream_get_time_n(struct pw_stream *stream, struct pw_time *time, size_t size);
512 
515 uint64_t pw_stream_get_nsec(struct pw_stream *stream);
516 
520 int pw_stream_get_time(struct pw_stream *stream, struct pw_time *time);
521 
524 struct pw_buffer *pw_stream_dequeue_buffer(struct pw_stream *stream);
525 
527 int pw_stream_queue_buffer(struct pw_stream *stream, struct pw_buffer *buffer);
528 
530 int pw_stream_set_active(struct pw_stream *stream, bool active);
531 
534 int pw_stream_flush(struct pw_stream *stream, bool drain);
535 
540 bool pw_stream_is_driving(struct pw_stream *stream);
541 
544 int pw_stream_trigger_process(struct pw_stream *stream);
545 
550 #ifdef __cplusplus
551 }
552 #endif
553 
554 #endif /* PIPEWIRE_STREAM_H */
void pw_stream_destroy(struct pw_stream *stream)
Destroy a stream.
Definition: stream.c:1697
int pw_stream_set_error(struct pw_stream *stream, int res, const char *error,...)
Set the stream in error state.
Definition: stream.c:2198
#define pw_direction
The direction of a port.
Definition: port.h:46
uint64_t ticks
the ticks at now.
Definition: stream.h:313
Definition: properties.h:33
the stream is in error
Definition: stream.h:187
uint32_t avail_buffers
the number of buffers that can be dequeued.
Definition: stream.h:332
uint32_t n_values
number of values in array
Definition: stream.h:227
the application will allocate buffer memory.
Definition: stream.h:404
float * values
array of values
Definition: stream.h:226
uint64_t time
For capture streams, this field contains the cycle time in nanoseconds when this buffer was queued in...
Definition: stream.h:213
int64_t now
the time in nanoseconds.
Definition: stream.h:305
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:350
Definition: stream.h:220
Definition: loop.h:31
A time structure.
Definition: stream.h:304
struct spa_dict dict
dictionary of key/values
Definition: properties.h:34
void(* add_buffer)(void *data, struct pw_buffer *buffer)
when a new buffer was created for this stream
Definition: stream.h:362
int pw_stream_flush(struct pw_stream *stream, bool drain)
Flush a stream.
Definition: stream.c:2531
Events for a stream.
Definition: stream.h:343
call process from the realtime thread.
Definition: stream.h:396
uint32_t queued_buffers
the number of buffers that are queued.
Definition: stream.h:331
#define SPA_DEPRECATED
Definition: defs.h:293
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:325
don't try to reconnect this stream when the sink/source is removed
Definition: stream.h:402
int pw_stream_trigger_process(struct pw_stream *stream)
Trigger a push/pull on the stream.
Definition: stream.c:2585
connection is in progress
Definition: stream.h:189
void pw_stream_add_listener(struct pw_stream *stream, struct spa_hook *listener, const struct pw_stream_events *events, void *data)
Definition: stream.c:1762
const char * pw_stream_get_name(struct pw_stream *stream)
Definition: stream.c:1789
Definition: dict.h:39
try to automatically connect this stream
Definition: stream.h:388
int pw_stream_update_params(struct pw_stream *stream, const struct spa_pod **params, uint32_t n_params)
Update the param exposed on the stream.
Definition: stream.c:2224
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:2368
void(* command)(void *data, const struct spa_command *command)
A command notify, Since 0.3.39:1.
Definition: stream.h:376
uint64_t buffered
for audio/raw streams, this contains the extra number of samples buffered in the resampler.
Definition: stream.h:328
paused
Definition: stream.h:190
int pw_stream_update_properties(struct pw_stream *stream, const struct spa_dict *dict)
Definition: stream.c:1801
the output stream will not be scheduled automatically but _trigger_process() needs to be called...
Definition: stream.h:407
Definition: defs.h:123
float def
default value
Definition: stream.h:223
start the stream inactive, pw_stream_set_active() needs to be called explicitly
Definition: stream.h:390
bool pw_stream_is_driving(struct pw_stream *stream)
Check if the stream is driving.
Definition: stream.c:2548
int pw_stream_set_active(struct pw_stream *stream, bool active)
Activate or deactivate the stream.
Definition: stream.c:2341
pw_stream_state
The state of a stream.
Definition: stream.h:186
don't convert format
Definition: stream.h:399
void(* destroy)(void *data)
Definition: stream.h:348
A Buffer.
Definition: buffer.h:98
uint64_t pw_stream_get_nsec(struct pw_stream *stream)
Get the current time in nanoseconds.
Definition: stream.c:2422
Definition: pod.h:43
uint64_t size
This field is set by the user and the sum of all queued buffers is returned in the time info...
Definition: stream.h:204
unconnected
Definition: stream.h:188
enum pw_stream_state pw_stream_get_state(struct pw_stream *stream, const char **error)
Definition: stream.c:1781
const struct pw_stream_control * pw_stream_get_control(struct pw_stream *stream, uint32_t id)
Get control values.
Definition: stream.c:2327
Buffers will not be dequeued/queued from the realtime process() function.
Definition: stream.h:412
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:350
be a driver
Definition: stream.h:395
const char * pw_stream_state_as_string(enum pw_stream_state state)
Convert a stream state to a readable string.
Definition: stream.c:1647
void(* remove_buffer)(void *data, struct pw_buffer *buffer)
when a buffer was destroyed for this stream
Definition: stream.h:364
void(* param_changed)(void *data, uint32_t id, const struct spa_pod *param)
when a parameter changed
Definition: stream.h:359
uint64_t size
for audio/raw playback streams, this contains the number of samples requested by the resampler for th...
Definition: stream.h:333
float max
max value
Definition: stream.h:225
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:1904
int pw_stream_disconnect(struct pw_stream *stream)
Disconnect stream.
Definition: stream.c:2190
void(* drained)(void *data)
The stream is drained.
Definition: stream.h:373
int64_t delay
delay to device.
Definition: stream.h:316
struct spa_buffer * buffer
the spa buffer
Definition: stream.h:197
uint64_t requested
For playback streams, this field contains the suggested amount of data to provide.
Definition: stream.h:208
void(* trigger_done)(void *data)
a trigger_process completed.
Definition: stream.h:379
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:2374
void(* control_info)(void *data, uint32_t id, const struct pw_stream_control *control)
Notify information about a control.
Definition: stream.h:354
no flags
Definition: stream.h:387
require exclusive access to the device
Definition: stream.h:400
a buffer structure obtained from pw_stream_dequeue_buffer().
Definition: stream.h:196
int pw_stream_set_param(struct pw_stream *stream, uint32_t id, const struct spa_pod *param)
Set a parameter on the stream.
Definition: stream.c:2254
void(* process)(void *data)
when a buffer can be queued (for playback streams) or dequeued (for capture streams).
Definition: stream.h:370
mmap the buffers except DmaBuf that is not explicitly marked as mappable.
Definition: stream.h:393
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:1581
uint32_t flags
extra flags (unused)
Definition: stream.h:222
uint32_t flags
extra flags
Definition: properties.h:35
const struct pw_properties * pw_stream_get_properties(struct pw_stream *stream)
Definition: stream.c:1795
uint32_t version
Definition: stream.h:346
pw_stream_flags
Extra flags that can be used in pw_stream_connect()
Definition: stream.h:386
Definition: command.h:29
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:1603
uint32_t max_values
max values that can be set on this control
Definition: stream.h:228
float min
min value
Definition: stream.h:224
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:2439
void(* io_changed)(void *data, uint32_t id, void *area, uint32_t size)
when io changed on the stream.
Definition: stream.h:357
streaming
Definition: stream.h:191
void * user_data
user data attached to the buffer.
Definition: stream.h:198
uint32_t pw_stream_get_node_id(struct pw_stream *stream)
Get the node ID of the stream.
Definition: stream.c:2184
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:287
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:2467
struct pw_core * pw_stream_get_core(struct pw_stream *stream)
Definition: stream.c:1827
int pw_stream_set_control(struct pw_stream *stream, uint32_t id, uint32_t n_values, float *values,...)
Set control values.
Definition: stream.c:2266
Call process as soon as there is a buffer to dequeue.
Definition: stream.h:419