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
29 extern "C" {
30 #endif
31 
161 struct pw_stream;
162 
163 #include <spa/buffer/buffer.h>
164 #include <spa/param/param.h>
166 
168 enum pw_stream_state {
169  PW_STREAM_STATE_ERROR = -1,
174 };
175 
178 struct pw_buffer {
179  struct spa_buffer *buffer;
180  void *user_data;
181  uint64_t size;
185  uint64_t requested;
190 };
191 
192 struct 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 
268 struct 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 
303 struct 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 
342 const char * pw_stream_state_as_string(enum pw_stream_state state);
343 
345 enum pw_stream_flags {
346  PW_STREAM_FLAG_NONE = 0,
347  PW_STREAM_FLAG_AUTOCONNECT = (1 << 0),
349  PW_STREAM_FLAG_INACTIVE = (1 << 1),
353  PW_STREAM_FLAG_DRIVER = (1 << 3),
360  PW_STREAM_FLAG_DONT_RECONNECT = (1 << 7),
370 };
371 
374 struct pw_stream *
375 pw_stream_new(struct pw_core *core,
376  const char *name,
377  struct pw_properties *props );
378 
379 struct 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 
387 void pw_stream_destroy(struct pw_stream *stream);
388 
389 void pw_stream_add_listener(struct pw_stream *stream,
390  struct spa_hook *listener,
391  const struct pw_stream_events *events,
392  void *data);
393 
394 enum pw_stream_state pw_stream_get_state(struct pw_stream *stream, const char **error);
395 
396 const char *pw_stream_get_name(struct pw_stream *stream);
397 
398 struct pw_core *pw_stream_get_core(struct pw_stream *stream);
399 
400 const struct pw_properties *pw_stream_get_properties(struct pw_stream *stream);
401 
402 int pw_stream_update_properties(struct pw_stream *stream, const struct spa_dict *dict);
403 
409 int
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 
423 uint32_t
424 pw_stream_get_node_id(struct pw_stream *stream);
425 
427 int pw_stream_disconnect(struct pw_stream *stream);
428 
430 int pw_stream_set_error(struct pw_stream *stream,
431  int res,
432  const char *error,
433  ...) SPA_PRINTF_FUNC(3, 4);
434 
441 int
442 pw_stream_update_params(struct pw_stream *stream,
443  const struct spa_pod **params,
446  uint32_t n_params );
447 
449 const struct pw_stream_control *pw_stream_get_control(struct pw_stream *stream, uint32_t id);
450 
452 int pw_stream_set_control(struct pw_stream *stream, uint32_t id, uint32_t n_values, float *values, ...);
453 
455 int pw_stream_get_time_n(struct pw_stream *stream, struct pw_time *time, size_t size);
456 
460 int pw_stream_get_time(struct pw_stream *stream, struct pw_time *time);
461 
464 struct pw_buffer *pw_stream_dequeue_buffer(struct pw_stream *stream);
465 
467 int pw_stream_queue_buffer(struct pw_stream *stream, struct pw_buffer *buffer);
468 
470 int pw_stream_set_active(struct pw_stream *stream, bool active);
471 
474 int pw_stream_flush(struct pw_stream *stream, bool drain);
475 
480 bool pw_stream_is_driving(struct pw_stream *stream);
481 
484 int pw_stream_trigger_process(struct pw_stream *stream);
485 
490 #ifdef __cplusplus
491 }
492 #endif
493 
494 #endif /* PIPEWIRE_STREAM_H */
spa/buffer/buffer.h
#define pw_direction
The direction of a port.
Definition: port.h:63
pw_stream_flags
Extra flags that can be used in pw_stream_connect()
Definition: stream.h:351
int pw_stream_update_properties(struct pw_stream *stream, const struct spa_dict *dict)
Definition: stream.c:1665
enum pw_stream_state pw_stream_get_state(struct pw_stream *stream, const char **error)
Definition: stream.c:1645
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:2052
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:1767
uint32_t pw_stream_get_node_id(struct pw_stream *stream)
Get the node ID of the stream.
Definition: stream.c:1988
int pw_stream_set_error(struct pw_stream *stream, int res, const char *error,...) 1(3
Set the stream in error state.
int pw_stream_set_control(struct pw_stream *stream, uint32_t id, uint32_t n_values, float *values,...)
Set control values.
Definition: stream.c:2070
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:1492
bool pw_stream_is_driving(struct pw_stream *stream)
Check if the stream is driving.
Definition: stream.c:2313
const struct pw_stream_control * pw_stream_get_control(struct pw_stream *stream, uint32_t id)
Get control values.
Definition: stream.c:2130
int pw_stream_flush(struct pw_stream *stream, bool drain)
Flush a stream.
Definition: stream.c:2301
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:2165
const char * pw_stream_get_name(struct pw_stream *stream)
Definition: stream.c:1653
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:1514
pw_stream_state
The state of a stream.
Definition: stream.h:173
int pw_stream_disconnect(struct pw_stream *stream)
Disconnect stream
Definition: stream.c:1994
int pw_stream_set_active(struct pw_stream *stream, bool active)
Activate or deactivate the stream.
Definition: stream.c:2144
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:2220
int pw_stream_trigger_process(struct pw_stream *stream)
Trigger a push/pull on the stream.
Definition: stream.c:2348
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:2247
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:2171
void pw_stream_add_listener(struct pw_stream *stream, struct spa_hook *listener, const struct pw_stream_events *events, void *data)
Definition: stream.c:1629
const char * pw_stream_state_as_string(enum pw_stream_state state)
Convert a stream state to a readable string.
Definition: stream.c:1558
struct pw_core * pw_stream_get_core(struct pw_stream *stream)
Definition: stream.c:1689
void pw_stream_destroy(struct pw_stream *stream)
Destroy a stream.
Definition: stream.c:1576
const struct pw_properties * pw_stream_get_properties(struct pw_stream *stream)
Definition: stream.c:1659
@ 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
mmap the buffers except DmaBuf
Definition: stream.h:358
@ PW_STREAM_FLAG_DRIVER
be a driver
Definition: stream.h:359
@ PW_STREAM_FLAG_EXCLUSIVE
require exclusive access to the device
Definition: stream.h:364
@ PW_STREAM_FLAG_NO_CONVERT
don't convert format
Definition: stream.h:363
@ 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
don't try to reconnect this stream when the sink/source is removed
Definition: stream.h:366
@ PW_STREAM_FLAG_AUTOCONNECT
try to automatically connect this stream
Definition: stream.h:353
@ PW_STREAM_FLAG_ALLOC_BUFFERS
the application will allocate buffer memory.
Definition: stream.h:368
@ PW_STREAM_FLAG_RT_PROCESS
call process from the realtime thread.
Definition: stream.h:360
@ PW_STREAM_FLAG_NONE
no flags
Definition: stream.h:352
@ PW_STREAM_STATE_PAUSED
paused
Definition: stream.h:177
@ PW_STREAM_STATE_CONNECTING
connection is in progress
Definition: stream.h:176
@ PW_STREAM_STATE_UNCONNECTED
unconnected
Definition: stream.h:175
@ PW_STREAM_STATE_ERROR
the stream is in error
Definition: stream.h:174
@ PW_STREAM_STATE_STREAMING
streaming
Definition: stream.h:178
#define SPA_DEPRECATED
Definition: defs.h:266
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:260
spa/param/param.h
spa/pod/command.h
pipewire/port.h
a buffer structure obtained from pw_stream_dequeue_buffer().
Definition: stream.h:183
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
uint64_t requested
For playback streams, this field contains the suggested amount of data to provide.
Definition: stream.h:190
struct spa_buffer * buffer
the spa buffer
Definition: stream.h:184
void * user_data
user data attached to the buffer
Definition: stream.h:185
Definition: loop.h:51
Definition: properties.h:53
struct spa_dict dict
dictionary of key/values
Definition: properties.h:54
uint32_t flags
extra flags
Definition: properties.h:55
Definition: stream.h:197
float max
max value
Definition: stream.h:202
uint32_t flags
extra flags (unused)
Definition: stream.h:199
float def
default value
Definition: stream.h:200
uint32_t max_values
max values that can be set on this control
Definition: stream.h:205
float min
min value
Definition: stream.h:201
uint32_t n_values
number of values in array
Definition: stream.h:204
float * values
array of values
Definition: stream.h:203
Events for a stream.
Definition: stream.h:308
void(* remove_buffer)(void *data, struct pw_buffer *buffer)
when a buffer was destroyed for this stream
Definition: stream.h:329
void(* control_info)(void *data, uint32_t id, const struct pw_stream_control *control)
Notify information about a control.
Definition: stream.h:319
void(* trigger_done)(void *data)
a trigger_process completed.
Definition: stream.h:344
void(* param_changed)(void *data, uint32_t id, const struct spa_pod *param)
when a parameter changed
Definition: stream.h:324
void(* process)(void *data)
when a buffer can be queued (for playback streams) or dequeued (for capture streams).
Definition: stream.h:335
void(* command)(void *data, const struct spa_command *command)
A command notify, Since 0.3.39:1.
Definition: stream.h:341
uint32_t version
Definition: stream.h:311
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
void(* drained)(void *data)
The stream is drained.
Definition: stream.h:338
void(* destroy)(void *data)
Definition: stream.h:313
void(* add_buffer)(void *data, struct pw_buffer *buffer)
when a new buffer was created for this stream
Definition: stream.h:327
void(* io_changed)(void *data, uint32_t id, void *area, uint32_t size)
when io changed on the stream.
Definition: stream.h:322
A time structure.
Definition: stream.h:273
int64_t delay
delay to device.
Definition: stream.h:285
struct spa_fraction rate
the rate of ticks and delay.
Definition: stream.h:280
uint64_t buffered
for audio/raw streams, this contains the extra number of samples buffered in the resampler.
Definition: stream.h:297
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
uint32_t queued_buffers
The number of buffers that are queued.
Definition: stream.h:300
uint64_t ticks
the ticks at now.
Definition: stream.h:282
int64_t now
the monotonic time in nanoseconds.
Definition: stream.h:274
uint32_t avail_buffers
The number of buffers that can be dequeued.
Definition: stream.h:301
A Buffer.
Definition: buffer.h:105
Definition: command.h:49
Definition: dict.h:59
Definition: defs.h:121
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:351
Definition: pod.h:63