PipeWire 1.4.1
 
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#ifdef __cplusplus
9extern "C" {
10#endif
11
16
17#include <spa/utils/defs.h>
18#include <spa/pod/pod.h>
19
29
31enum spa_io_type {
50
75struct spa_io_buffers {
76#define SPA_STATUS_OK 0
77#define SPA_STATUS_NEED_DATA (1<<0)
78#define SPA_STATUS_HAVE_DATA (1<<1)
79#define SPA_STATUS_STOPPED (1<<2)
80#define SPA_STATUS_DRAINED (1<<3)
81 int32_t status;
82 uint32_t buffer_id;
83};
85#define SPA_IO_BUFFERS_INIT ((struct spa_io_buffers) { SPA_STATUS_OK, SPA_ID_INVALID, })
91 int32_t status;
92 uint32_t size;
93 void *data;
94};
95#define SPA_IO_MEMORY_INIT ((struct spa_io_memory) { SPA_STATUS_OK, 0, NULL, })
98struct spa_io_range {
99 uint64_t offset;
100 uint32_t min_size;
101 uint32_t max_size;
106
111 * The clock counts the elapsed time according to the clock provider
112 * since the provider was last started.
114 * Driver nodes are supposed to update the contents of \ref SPA_IO_Clock before
115 * signaling the start of a graph cycle. These updated clock values become
116 * visible to other nodes in \ref SPA_IO_Position. Non-driver nodes do
117 * not need to update the contents of their \ref SPA_IO_Clock.
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 in \ref SPA_IO_Clock and
125 * \ref spa_io_position.clock.id in \ref SPA_IO_Position are the same.
126 */
127struct spa_io_clock {
128#define SPA_IO_CLOCK_FLAG_FREEWHEEL (1u<<0) /* graph is freewheeling */
129#define SPA_IO_CLOCK_FLAG_XRUN_RECOVER (1u<<1) /* recovering from xrun */
130#define SPA_IO_CLOCK_FLAG_LAZY (1u<<2) /* lazy scheduling */
131#define SPA_IO_CLOCK_FLAG_NO_RATE (1u<<3) /* the rate of the clock is only approximately.
132 * it is recommended to use the nsec as a clock source.
133 * The rate_diff contains the measured inaccuracy. */
134 uint32_t flags;
135 uint32_t id;
136 char name[64];
139 uint64_t nsec;
142 struct spa_fraction rate;
143 uint64_t position;
144 uint64_t duration;
145 int64_t delay;
146 double rate_diff;
148 uint64_t next_nsec;
152
154 uint64_t target_duration;
155 uint32_t target_seq;
157 uint32_t cycle;
158 uint64_t xrun;
161/* the size of the video in this cycle */
163#define SPA_IO_VIDEO_SIZE_VALID (1<<0)
164 uint32_t flags;
165 uint32_t stride;
166 struct spa_rectangle size;
170 uint32_t padding[4];
174
176 * Currently not used in PipeWire. Instead, \see spa_param_latency
177 */
180 uint64_t min;
181 uint64_t max;
183
187};
188
190struct spa_io_segment_bar {
191#define SPA_IO_SEGMENT_BAR_FLAG_VALID (1<<0)
192 uint32_t flags;
193 uint32_t offset;
196 double bpm;
197 double beat;
198 double bar_start_tick;
199 double ticks_per_beat;
200 uint32_t padding[4];
202
203
205#define SPA_IO_SEGMENT_VIDEO_FLAG_VALID (1<<0)
206#define SPA_IO_SEGMENT_VIDEO_FLAG_DROP_FRAME (1<<1)
207#define SPA_IO_SEGMENT_VIDEO_FLAG_PULL_DOWN (1<<2)
208#define SPA_IO_SEGMENT_VIDEO_FLAG_INTERLACED (1<<3)
209 uint32_t flags;
210 uint32_t offset;
212 uint32_t hours;
213 uint32_t minutes;
214 uint32_t seconds;
215 uint32_t frames;
216 uint32_t field_count;
217 uint32_t padding[11];
218};
219
220/**
221 * A segment converts a running time to a segment (stream) position.
223 * The segment position is valid when the current running time is between
224 * start and start + duration. The position is then
225 * calculated as:
227 * (running time - start) * rate + position;
229 * Support for looping is done by specifying the LOOPING flags with a
230 * non-zero duration. When the running time reaches start + duration,
231 * duration is added to start and the loop repeats.
233 * Care has to be taken when the running time + clock.duration extends
234 * past the start + duration from the segment; the user should correctly
235 * wrap around and partially repeat the loop in the current cycle.
237 * Extra information can be placed in the segment by setting the valid flags
238 * and filling up the corresponding structures.
239 */
240struct spa_io_segment {
241 uint32_t version;
242#define SPA_IO_SEGMENT_FLAG_LOOPING (1<<0)
243#define SPA_IO_SEGMENT_FLAG_NO_POSITION (1<<1)
247 uint32_t flags;
248 uint64_t start;
252 uint64_t duration;
257 double rate;
259 uint64_t position;
260 * can be invalid when the owner of the extra segment
261 * information has not yet made the mapping. */
262
266
271};
272
274#define SPA_IO_POSITION_MAX_SEGMENTS 8
275
288
289 * start times, and thus the order in which they will activate in
290 * the future. This makes it possible to look ahead in the scheduled
291 * segments and anticipate the changes in the timeline.
292 */
293struct spa_io_position {
294 struct spa_io_clock clock;
296 struct spa_io_video_size video;
297 int64_t offset;
302 uint32_t state;
303
304 uint32_t n_segments;
306};
307
316 * \ref SPA_IO_RATE_MATCH_ACTIVE on \a flags, and setting \a rate to the desired rate
317 * correction. Usually the rate is obtained from DLL or other adaptive mechanism that
318 * e.g. drives the node buffer fill level toward a specific value.
320 * When resampling to (graph->node) direction, the number of samples produced
321 * by the resampler varies on each cycle, as the rates are not commensurate.
322 *
323 * When resampling to (node->graph) direction, the number of samples consumed by the
324 * resampler varies. Node output ports in process() should produce \a size number of
325 * samples to match what the resampler needs to produce one graph quantum of output
326 * samples.
328 * Resampling filters introduce processing delay, given by \a delay and \a delay_frac, in
329 * samples at node rate. The delay varies on each cycle e.g. when resampling between
330 * noncommensurate rates.
331 *
332 * The first sample output (graph->node) or consumed (node->graph) by the resampler is
333 * offset by \a delay + \a delay_frac / 1e9 node samples relative to the nominal graph
334 * cycle start position:
335 *
336 * \code{.unparsed}
337 * first_resampled_sample_nsec =
338 * first_original_sample_nsec
339 * - (rate_match->delay * SPA_NSEC_PER_SEC + rate_match->delay_frac) / node_rate
340 * \endcode
341 */
342struct spa_io_rate_match {
343 uint32_t delay;
345 uint32_t size;
346 double rate;
347#define SPA_IO_RATE_MATCH_FLAG_ACTIVE (1 << 0)
348 uint32_t flags;
349 int32_t delay_frac;
351 uint32_t padding[6];
352};
353
356 struct spa_io_buffers buffers[2];
358};
359
363
364#ifdef __cplusplus
365} /* extern "C" */
366#endif
367
368#endif /* SPA_IO_H */
spa/utils/defs.h
uint32_t id
Definition core.h:432
spa_io_position_state
Definition io.h:289
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:297
@ SPA_IO_POSITION_STATE_RUNNING
Definition io.h:292
@ SPA_IO_POSITION_STATE_STOPPED
Definition io.h:290
@ SPA_IO_POSITION_STATE_STARTING
Definition io.h:291
@ SPA_IO_AsyncBuffers
async area to exchange buffers, struct spa_io_async_buffers
Definition io.h:48
@ SPA_IO_Notify
area for notify messages, struct spa_io_sequence
Definition io.h:44
@ SPA_IO_Memory
memory pointer, struct spa_io_memory (currently not used in PipeWire)
Definition io.h:47
@ 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:43
@ SPA_IO_Latency
latency reporting, struct spa_io_latency (currently not used in PipeWire).
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:45
@ 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:46
spa/pod/pod.h
Definition defs.h:137
async buffers
Definition io.h:379
struct spa_io_buffers buffers[2]
async buffers, writers write to current (cycle+1)&1, readers read from (cycle)&1
Definition io.h:380
IO area to exchange buffers.
Definition io.h:80
int32_t status
the status code
Definition io.h:91
uint32_t buffer_id
a buffer id
Definition io.h:92
Absolute time reporting.
Definition io.h:139
struct spa_fraction target_rate
Target rate of next cycle.
Definition io.h:167
uint64_t next_nsec
Estimated next wakeup time in nanoseconds.
Definition io.h:162
uint64_t xrun
Estimated accumulated xrun duration.
Definition io.h:172
uint64_t position
Current position, in samples @ rate.
Definition io.h:157
uint32_t cycle
incremented each time the graph is started
Definition io.h:171
uint64_t nsec
Time in nanoseconds against monotonic clock (CLOCK_MONOTONIC).
Definition io.h:153
struct spa_fraction rate
Rate for position/duration/delay/xrun.
Definition io.h:156
double rate_diff
Rate difference between clock and monotonic time, as a ratio of clock speeds.
Definition io.h:160
uint32_t flags
Clock flags.
Definition io.h:148
uint64_t target_duration
Target duration of next cycle.
Definition io.h:168
uint64_t duration
Duration of current cycle, in samples @ rate.
Definition io.h:158
int64_t delay
Delay between position and hardware, in samples @ rate.
Definition io.h:159
uint32_t target_seq
Seq counter.
Definition io.h:169
Latency reporting.
Definition io.h:193
uint64_t min
min latency
Definition io.h:195
uint64_t max
max latency
Definition io.h:196
struct spa_fraction rate
rate for min/max
Definition io.h:194
IO area to exchange a memory region.
Definition io.h:101
uint32_t size
the size of data
Definition io.h:103
The position information adds extra meaning to the raw clock times.
Definition io.h:316
struct spa_io_clock clock
clock position of driver, always valid and read only
Definition io.h:317
struct spa_io_video_size video
size of the video in the current cycle
Definition io.h:319
uint32_t state
one of enum spa_io_position_state
Definition io.h:325
uint32_t n_segments
number of segments
Definition io.h:327
struct spa_io_segment segments[SPA_IO_POSITION_MAX_SEGMENTS]
segments
Definition io.h:328
int64_t offset
an offset to subtract from the clock position to get a running time.
Definition io.h:320
A range, suitable for input ports that can suggest a range to output ports.
Definition io.h:110
uint64_t offset
offset in range
Definition io.h:111
uint32_t max_size
maximum size of data
Definition io.h:113
uint32_t min_size
minimum size of data
Definition io.h:112
Rate matching.
Definition io.h:365
int32_t delay_frac
resampling delay fractional part, in units of nanosamples (1/10^9 sample) at node rate
Definition io.h:373
uint32_t padding[6]
Definition io.h:375
uint32_t flags
extra flags (set by node)
Definition io.h:372
double rate
rate for resampler (set by node)
Definition io.h:369
uint32_t delay
resampling delay, in samples at node rate
Definition io.h:366
uint32_t size
requested input size for resampler
Definition io.h:368
bar and beat segment
Definition io.h:205
double beat
current beat in segment
Definition io.h:213
uint32_t padding[4]
Definition io.h:216
double bpm
beats per minute
Definition io.h:212
float signature_denom
time signature denominator
Definition io.h:211
double ticks_per_beat
Definition io.h:215
double bar_start_tick
Definition io.h:214
uint32_t offset
offset in segment of this beat
Definition io.h:209
float signature_num
time signature numerator
Definition io.h:210
uint32_t flags
extra flags
Definition io.h:208
video frame segment
Definition io.h:220
uint32_t seconds
Definition io.h:234
struct spa_fraction framerate
Definition io.h:231
uint32_t field_count
0 for progressive, 1 and 2 for interlaced
Definition io.h:236
uint32_t flags
flags
Definition io.h:229
uint32_t hours
Definition io.h:232
uint32_t minutes
Definition io.h:233
uint32_t frames
Definition io.h:235
A segment converts a running time to a segment (stream) position.
Definition io.h:260
uint64_t duration
duration when this info becomes invalid expressed in running time.
Definition io.h:274
uint64_t position
The position when the running time == start.
Definition io.h:281
double rate
overall rate of the segment, can be negative for backwards time reporting.
Definition io.h:279
struct spa_io_segment_video video
Definition io.h:286
struct spa_io_segment_bar bar
Definition io.h:285
uint32_t version
Definition io.h:261
control stream, io area for SPA_IO_Control and SPA_IO_Notify
Definition io.h:200
struct spa_pod_sequence sequence
sequence of timed events
Definition io.h:201
Definition io.h:176
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:182
uint32_t padding[4]
Definition io.h:185
uint32_t stride
video stride in bytes
Definition io.h:180
struct spa_rectangle size
the video size
Definition io.h:181
a sequence of timed controls
Definition pod.h:248
Definition defs.h:116