PipeWire 1.7.0
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_IO_H
6#define SPA_IO_H
7
8#include <spa/utils/defs.h>
9#include <spa/pod/pod.h>
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
19
29
31enum spa_io_type {
49
74struct spa_io_buffers {
75#define SPA_STATUS_OK 0
76#define SPA_STATUS_NEED_DATA (1<<0)
77#define SPA_STATUS_HAVE_DATA (1<<1)
78#define SPA_STATUS_STOPPED (1<<2)
79#define SPA_STATUS_DRAINED (1<<3)
80 int32_t status;
81 uint32_t buffer_id;
82};
84#define SPA_IO_BUFFERS_INIT ((struct spa_io_buffers) { SPA_STATUS_OK, SPA_ID_INVALID, })
90 int32_t status;
91 uint32_t size;
92 void *data;
93};
94#define SPA_IO_MEMORY_INIT ((struct spa_io_memory) { SPA_STATUS_OK, 0, NULL, })
97struct spa_io_range {
98 uint64_t offset;
99 uint32_t min_size;
100 uint32_t max_size;
105
110 * The clock counts the elapsed time according to the clock provider
111 * since the provider was last started.
113 * Driver nodes are supposed to update the contents of \ref SPA_IO_Clock before
114 * signaling the start of a graph cycle. These updated clock values become
115 * visible to other nodes in \ref SPA_IO_Position. Non-driver nodes do
116 * not need to update the contents of their \ref SPA_IO_Clock. Also
117 * see \ref page_driver for further details.
118 *
119 * The host generally gives each node a separate \ref spa_io_clock in \ref
120 * SPA_IO_Clock, so that updates made by the driver are not visible in the
121 * contents of \ref SPA_IO_Clock of other nodes. Instead, \ref SPA_IO_Position
122 * is used to look up the current graph time.
123 *
124 * A node is a driver when \ref spa_io_clock::id and the ID in
125 * \ref spa_io_position.clock in \ref SPA_IO_Position are the same.
126 *
127 * The flags are set by the graph driver at the start of each cycle.
128 */
129struct spa_io_clock {
130#define SPA_IO_CLOCK_FLAG_FREEWHEEL (1u<<0)
135#define SPA_IO_CLOCK_FLAG_XRUN_RECOVER (1u<<1)
141 * flag is cleared again. That way, the node knows that
142 * during the last cycle it experienced an xrun. They
143 * can use this information for example to resynchronize
144 * or clear custom stale states. */
145#define SPA_IO_CLOCK_FLAG_LAZY (1u<<2)
147#define SPA_IO_CLOCK_FLAG_NO_RATE (1u<<3)
150#define SPA_IO_CLOCK_FLAG_DISCONT (1u<<4)
164 uint32_t flags;
165 uint32_t id;
166 char name[64];
169 uint64_t nsec;
173 struct spa_fraction rate;
174 uint64_t position;
175 uint64_t duration;
176 int64_t delay;
177 double rate_diff;
181 uint64_t next_nsec;
185
187 uint64_t target_duration;
188 uint32_t target_seq;
190 uint32_t cycle;
191 uint64_t xrun;
194/* the size of the video in this cycle */
195struct spa_io_video_size {
196#define SPA_IO_VIDEO_SIZE_VALID (1<<0)
197 uint32_t flags;
198 uint32_t stride;
199 struct spa_rectangle size;
200 struct spa_fraction framerate;
203 uint32_t padding[4];
210
211struct spa_io_latency {
223struct spa_io_segment_bar {
224#define SPA_IO_SEGMENT_BAR_FLAG_VALID (1<<0)
225 uint32_t flags;
226 uint32_t offset;
227 float signature_num;
228 float signature_denom;
229 double bpm;
230 double beat;
233 uint32_t padding[4];
234};
235
236/** video frame segment */
238#define SPA_IO_SEGMENT_VIDEO_FLAG_VALID (1<<0)
239#define SPA_IO_SEGMENT_VIDEO_FLAG_DROP_FRAME (1<<1)
240#define SPA_IO_SEGMENT_VIDEO_FLAG_PULL_DOWN (1<<2)
241#define SPA_IO_SEGMENT_VIDEO_FLAG_INTERLACED (1<<3)
242 uint32_t flags;
243 uint32_t offset;
245 uint32_t hours;
246 uint32_t minutes;
247 uint32_t seconds;
248 uint32_t frames;
249 uint32_t field_count;
250 uint32_t padding[11];
254
256 * The segment position is valid when the current running time is between
257 * start and start + duration. The position is then
258 * calculated as:
259 *
260 * (running time - start) * rate + position;
261 *
262 * Support for looping is done by specifying the LOOPING flags with a
263 * non-zero duration. When the running time reaches start + duration,
264 * duration is added to start and the loop repeats.
266 * Care has to be taken when the running time + clock.duration extends
267 * past the start + duration from the segment; the user should correctly
268 * wrap around and partially repeat the loop in the current cycle.
270 * Extra information can be placed in the segment by setting the valid flags
271 * and filling up the corresponding structures.
272 */
274 uint32_t version;
275#define SPA_IO_SEGMENT_FLAG_LOOPING (1<<0)
276#define SPA_IO_SEGMENT_FLAG_NO_POSITION (1<<1)
280 uint32_t flags;
281 uint64_t start;
285 uint64_t duration;
290 double rate;
292 uint64_t position;
295
324
330 int64_t offset;
335 uint32_t state;
336
337 uint32_t n_segments;
339};
340
353 * When resampling to (graph->node) direction, the number of samples produced
354 * by the resampler varies on each cycle, as the rates are not commensurate.
356 * When resampling to (node->graph) direction, the number of samples consumed by the
357 * resampler varies. Node output ports in process() should produce \a size number of
358 * samples to match what the resampler needs to produce one graph quantum of output
359 * samples.
360 *
361 * Resampling filters introduce processing delay, given by \a delay and \a delay_frac, in
362 * samples at node rate. The delay varies on each cycle e.g. when resampling between
363 * noncommensurate rates.
365 * The first sample output (graph->node) or consumed (node->graph) by the resampler is
366 * offset by \a delay + \a delay_frac / 1e9 node samples relative to the nominal graph
367 * cycle start position:
368 *
369 * \code{.unparsed}
370 * first_resampled_sample_nsec =
371 * first_original_sample_nsec
372 * - (rate_match->delay * SPA_NSEC_PER_SEC + rate_match->delay_frac) / node_rate
373 * \endcode
374 */
375struct spa_io_rate_match {
376 uint32_t delay;
378 uint32_t size;
379 double rate;
380#define SPA_IO_RATE_MATCH_FLAG_ACTIVE (1 << 0)
381 uint32_t flags;
382 int32_t delay_frac;
384 uint32_t padding[6];
385};
386
389 struct spa_io_buffers buffers[2];
391};
392
396
397#ifdef __cplusplus
398} /* extern "C" */
399#endif
400
401#endif /* SPA_IO_H */
spa/utils/defs.h
uint32_t id
Definition core.h:432
spa_io_position_state
Definition io.h:325
spa_io_type
IO areas.
Definition io.h:36
#define SPA_IO_POSITION_MAX_SEGMENTS
the maximum number of segments visible in the future
Definition io.h:333
@ SPA_IO_POSITION_STATE_RUNNING
Definition io.h:328
@ SPA_IO_POSITION_STATE_STOPPED
Definition io.h:326
@ SPA_IO_POSITION_STATE_STARTING
Definition io.h:327
@ SPA_IO_AsyncBuffers
async area to exchange buffers, struct spa_io_async_buffers
Definition io.h:47
@ SPA_IO_Notify
area for notify messages, struct spa_io_sequence
Definition io.h:43
@ SPA_IO_Memory
memory pointer, struct spa_io_memory (currently not used in PipeWire)
Definition io.h:46
@ SPA_IO_Clock
area to update clock information, struct spa_io_clock
Definition io.h:40
@ SPA_IO_Control
area for control messages, struct spa_io_sequence
Definition io.h:42
@ SPA_IO_Latency
latency reporting, struct spa_io_latency
Definition io.h:41
@ SPA_IO_Range
expected byte range, struct spa_io_range (currently not used in PipeWire)
Definition io.h:39
@ SPA_IO_Invalid
Definition io.h:37
@ SPA_IO_Position
position information in the graph, struct spa_io_position
Definition io.h:44
@ SPA_IO_Buffers
area to exchange buffers, struct spa_io_buffers
Definition io.h:38
@ SPA_IO_RateMatch
rate matching between nodes, struct spa_io_rate_match
Definition io.h:45
spa/pod/pod.h
Definition defs.h:138
async buffers
Definition io.h:415
struct spa_io_buffers buffers[2]
async buffers, writers write to current (cycle+1)&1, readers read from (cycle)&1
Definition io.h:416
IO area to exchange buffers.
Definition io.h:79
int32_t status
the status code
Definition io.h:90
uint32_t buffer_id
a buffer id
Definition io.h:91
Absolute time reporting.
Definition io.h:141
struct spa_fraction target_rate
Target rate of next cycle.
Definition io.h:203
uint64_t next_nsec
Estimated next wakeup time in nanoseconds.
Definition io.h:198
uint64_t xrun
Estimated accumulated xrun duration.
Definition io.h:208
uint64_t position
Current position, in samples @ rate.
Definition io.h:191
uint32_t cycle
incremented each time the graph is started
Definition io.h:207
uint64_t nsec
Time in nanoseconds against monotonic clock (CLOCK_MONOTONIC).
Definition io.h:186
struct spa_fraction rate
Rate for position/duration/delay/xrun.
Definition io.h:190
double rate_diff
Rate difference between clock and monotonic time, as a ratio of clock speeds.
Definition io.h:194
uint32_t flags
Clock flags.
Definition io.h:181
uint64_t target_duration
Target duration of next cycle.
Definition io.h:204
uint64_t duration
Duration of current cycle, in samples @ rate.
Definition io.h:192
int64_t delay
Delay between position and hardware, in samples @ rate.
Definition io.h:193
uint32_t target_seq
Seq counter.
Definition io.h:205
Latency reporting.
Definition io.h:229
int64_t playback_latency
playback latency
Definition io.h:232
int64_t capture_latency
capture latency
Definition io.h:231
struct spa_fraction rate
rate for latencies
Definition io.h:230
IO area to exchange a memory region.
Definition io.h:100
uint32_t size
the size of data
Definition io.h:102
The position information adds extra meaning to the raw clock times.
Definition io.h:352
struct spa_io_clock clock
clock position of driver, always valid and read only
Definition io.h:353
struct spa_io_video_size video
size of the video in the current cycle
Definition io.h:355
uint32_t state
one of enum spa_io_position_state
Definition io.h:361
uint32_t n_segments
number of segments
Definition io.h:363
struct spa_io_segment segments[SPA_IO_POSITION_MAX_SEGMENTS]
segments
Definition io.h:364
int64_t offset
an offset to subtract from the clock position to get a running time.
Definition io.h:356
A range, suitable for input ports that can suggest a range to output ports.
Definition io.h:109
uint64_t offset
offset in range
Definition io.h:110
uint32_t max_size
maximum size of data
Definition io.h:112
uint32_t min_size
minimum size of data
Definition io.h:111
Rate matching.
Definition io.h:401
int32_t delay_frac
resampling delay fractional part, in units of nanosamples (1/10^9 sample) at node rate
Definition io.h:409
uint32_t padding[6]
Definition io.h:411
uint32_t flags
extra flags (set by node)
Definition io.h:408
double rate
rate for resampler (set by node)
Definition io.h:405
uint32_t delay
resampling delay, in samples at node rate
Definition io.h:402
uint32_t size
requested input size for resampler
Definition io.h:404
bar and beat segment
Definition io.h:241
double beat
current beat in segment
Definition io.h:249
uint32_t padding[4]
Definition io.h:252
double bpm
beats per minute
Definition io.h:248
float signature_denom
time signature denominator
Definition io.h:247
double ticks_per_beat
Definition io.h:251
double bar_start_tick
Definition io.h:250
uint32_t offset
offset in segment of this beat
Definition io.h:245
float signature_num
time signature numerator
Definition io.h:246
uint32_t flags
extra flags
Definition io.h:244
video frame segment
Definition io.h:256
uint32_t seconds
Definition io.h:270
struct spa_fraction framerate
Definition io.h:267
uint32_t field_count
0 for progressive, 1 and 2 for interlaced
Definition io.h:272
uint32_t flags
flags
Definition io.h:265
uint32_t hours
Definition io.h:268
uint32_t minutes
Definition io.h:269
uint32_t frames
Definition io.h:271
uint32_t offset
offset in segment
Definition io.h:266
A segment converts a running time to a segment (stream) position.
Definition io.h:296
uint64_t duration
duration when this info becomes invalid expressed in running time.
Definition io.h:310
uint64_t position
The position when the running time == start.
Definition io.h:317
double rate
overall rate of the segment, can be negative for backwards time reporting.
Definition io.h:315
struct spa_io_segment_video video
Definition io.h:322
struct spa_io_segment_bar bar
Definition io.h:321
uint32_t version
Definition io.h:297
control stream, io area for SPA_IO_Control and SPA_IO_Notify
Definition io.h:236
struct spa_pod_sequence sequence
sequence of timed events
Definition io.h:237
Definition io.h:212
struct spa_fraction framerate
the minimum framerate, the cycle duration is always smaller to ensure there is only one video frame p...
Definition io.h:218
uint32_t padding[4]
Definition io.h:221
uint32_t stride
video stride in bytes
Definition io.h:216
uint32_t flags
optional flags
Definition io.h:215
struct spa_rectangle size
the video size
Definition io.h:217
a sequence of timed controls
Definition pod.h:271
Definition defs.h:117