]> code.delx.au - pulseaudio/blob - src/pulse/def.h
01ed0f6d089b893c98fa5198fb36dcd45418493f
[pulseaudio] / src / pulse / def.h
1 #ifndef foodefhfoo
2 #define foodefhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of PulseAudio.
8
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
13
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <inttypes.h>
26 #include <sys/time.h>
27 #include <time.h>
28
29 #include <pulse/cdecl.h>
30 #include <pulse/sample.h>
31
32 /** \file
33 * Global definitions */
34
35 PA_C_DECL_BEGIN
36
37 /** The state of a connection context */
38 typedef enum pa_context_state {
39 PA_CONTEXT_UNCONNECTED, /**< The context hasn't been connected yet */
40 PA_CONTEXT_CONNECTING, /**< A connection is being established */
41 PA_CONTEXT_AUTHORIZING, /**< The client is authorizing itself to the daemon */
42 PA_CONTEXT_SETTING_NAME, /**< The client is passing its application name to the daemon */
43 PA_CONTEXT_READY, /**< The connection is established, the context is ready to execute operations */
44 PA_CONTEXT_FAILED, /**< The connection failed or was disconnected */
45 PA_CONTEXT_TERMINATED /**< The connection was terminated cleanly */
46 } pa_context_state_t;
47
48 /** The state of a stream */
49 typedef enum pa_stream_state {
50 PA_STREAM_UNCONNECTED, /**< The stream is not yet connected to any sink or source */
51 PA_STREAM_CREATING, /**< The stream is being created */
52 PA_STREAM_READY, /**< The stream is established, you may pass audio data to it now */
53 PA_STREAM_FAILED, /**< An error occured that made the stream invalid */
54 PA_STREAM_TERMINATED /**< The stream has been terminated cleanly */
55 } pa_stream_state_t;
56
57 /** The state of an operation */
58 typedef enum pa_operation_state {
59 PA_OPERATION_RUNNING, /**< The operation is still running */
60 PA_OPERATION_DONE, /**< The operation has been completed */
61 PA_OPERATION_CANCELED /**< The operation has been canceled */
62 } pa_operation_state_t;
63
64 /** An invalid index */
65 #define PA_INVALID_INDEX ((uint32_t) -1)
66
67 /** Some special flags for contexts. \since 0.8 */
68 typedef enum pa_context_flags {
69 PA_CONTEXT_NOAUTOSPAWN = 1 /**< Disabled autospawning of the PulseAudio daemon if required */
70 } pa_context_flags_t;
71
72 /** The direction of a pa_stream object */
73 typedef enum pa_stream_direction {
74 PA_STREAM_NODIRECTION, /**< Invalid direction */
75 PA_STREAM_PLAYBACK, /**< Playback stream */
76 PA_STREAM_RECORD, /**< Record stream */
77 PA_STREAM_UPLOAD /**< Sample upload stream */
78 } pa_stream_direction_t;
79
80 /** Some special flags for stream connections. \since 0.6 */
81 typedef enum pa_stream_flags {
82 PA_STREAM_START_CORKED = 1, /**< Create the stream corked, requiring an explicit pa_stream_cork() call to uncork it. */
83 PA_STREAM_INTERPOLATE_TIMING = 2, /**< Interpolate the latency for
84 * this stream. When enabled,
85 * pa_stream_get_latency() and
86 * pa_stream_get_time() will try
87 * to estimate the current
88 * record/playback time based on
89 * the local time that passed
90 * since the last timing info
91 * update. Using this option
92 * has the advantage of not
93 * requiring a whole roundtrip
94 * when the current
95 * playback/recording time is
96 * needed. Consider using this
97 * option when requesting
98 * latency information
99 * frequently. This is
100 * especially useful on long
101 * latency network
102 * connections. It makes a lot
103 * of sense to combine this
104 * option with
105 * PA_STREAM_AUTO_TIMING_UPDATE. */
106 PA_STREAM_NOT_MONOTONOUS = 4, /**< Don't force the time to
107 * increase monotonically. If
108 * this option is enabled,
109 * pa_stream_get_time() will not
110 * necessarily return always
111 * monotonically increasing time
112 * values on each call. This may
113 * confuse applications which
114 * cannot deal with time going
115 * 'backwards', but has the
116 * advantage that bad transport
117 * latency estimations that
118 * caused the time to to jump
119 * ahead can be corrected
120 * quickly, without the need to
121 * wait. */
122 PA_STREAM_AUTO_TIMING_UPDATE = 8 /**< If set timing update requests
123 * are issued periodically
124 * automatically. Combined with
125 * PA_STREAM_INTERPOLATE_TIMING
126 * you will be able to query the
127 * current time and latency with
128 * pa_stream_get_time() and
129 * pa_stream_get_latency() at
130 * all times without a packet
131 * round trip.*/
132 } pa_stream_flags_t;
133
134 /** Playback and record buffer metrics */
135 typedef struct pa_buffer_attr {
136 uint32_t maxlength; /**< Maximum length of the buffer */
137 uint32_t tlength; /**< Playback only: target length of the buffer. The server tries to assure that at least tlength bytes are always available in the buffer */
138 uint32_t prebuf; /**< Playback only: pre-buffering. The server does not start with playback before at least prebug bytes are available in the buffer */
139 uint32_t minreq; /**< Playback only: minimum request. The server does not request less than minreq bytes from the client, instead waints until the buffer is free enough to request more bytes at once */
140 uint32_t fragsize; /**< Recording only: fragment size. The server sends data in blocks of fragsize bytes size. Large values deminish interactivity with other operations on the connection context but decrease control overhead. */
141 } pa_buffer_attr;
142
143 /** Error values as used by pa_context_errno(). Use pa_strerror() to convert these values to human readable strings */
144 enum {
145 PA_OK = 0, /**< No error */
146 PA_ERR_ACCESS, /**< Access failure */
147 PA_ERR_COMMAND, /**< Unknown command */
148 PA_ERR_INVALID, /**< Invalid argument */
149 PA_ERR_EXIST, /**< Entity exists */
150 PA_ERR_NOENTITY, /**< No such entity */
151 PA_ERR_CONNECTIONREFUSED, /**< Connection refused */
152 PA_ERR_PROTOCOL, /**< Protocol error */
153 PA_ERR_TIMEOUT, /**< Timeout */
154 PA_ERR_AUTHKEY, /**< No authorization key */
155 PA_ERR_INTERNAL, /**< Internal error */
156 PA_ERR_CONNECTIONTERMINATED, /**< Connection terminated */
157 PA_ERR_KILLED, /**< Entity killed */
158 PA_ERR_INVALIDSERVER, /**< Invalid server */
159 PA_ERR_MODINITFAILED, /**< Module initialization failed */
160 PA_ERR_BADSTATE, /**< Bad state */
161 PA_ERR_NODATA, /**< No data */
162 PA_ERR_VERSION, /**< Incompatible protocol version \since 0.8 */
163 PA_ERR_TOOLARGE, /**< Data too large \since 0.8.1 */
164 PA_ERR_MAX /**< Not really an error but the first invalid error code */
165 };
166
167 /** Subscription event mask, as used by pa_context_subscribe() */
168 typedef enum pa_subscription_mask {
169 PA_SUBSCRIPTION_MASK_NULL = 0, /**< No events */
170 PA_SUBSCRIPTION_MASK_SINK = 1, /**< Sink events */
171 PA_SUBSCRIPTION_MASK_SOURCE = 2, /**< Source events */
172 PA_SUBSCRIPTION_MASK_SINK_INPUT = 4, /**< Sink input events */
173 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT = 8, /**< Source output events */
174 PA_SUBSCRIPTION_MASK_MODULE = 16, /**< Module events */
175 PA_SUBSCRIPTION_MASK_CLIENT = 32, /**< Client events */
176 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE = 64, /**< Sample cache events */
177 PA_SUBSCRIPTION_MASK_SERVER = 128, /**< Other global server changes. \since 0.4 */
178 PA_SUBSCRIPTION_MASK_AUTOLOAD = 256, /**< Autoload table events. \since 0.5 */
179 PA_SUBSCRIPTION_MASK_ALL = 511 /**< Catch all events \since 0.8 */
180 } pa_subscription_mask_t;
181
182 /** Subscription event types, as used by pa_context_subscribe() */
183 typedef enum pa_subscription_event_type {
184 PA_SUBSCRIPTION_EVENT_SINK = 0, /**< Event type: Sink */
185 PA_SUBSCRIPTION_EVENT_SOURCE = 1, /**< Event type: Source */
186 PA_SUBSCRIPTION_EVENT_SINK_INPUT = 2, /**< Event type: Sink input */
187 PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT = 3, /**< Event type: Source output */
188 PA_SUBSCRIPTION_EVENT_MODULE = 4, /**< Event type: Module */
189 PA_SUBSCRIPTION_EVENT_CLIENT = 5, /**< Event type: Client */
190 PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE = 6, /**< Event type: Sample cache item */
191 PA_SUBSCRIPTION_EVENT_SERVER = 7, /**< Event type: Global server change, only occuring with PA_SUBSCRIPTION_EVENT_CHANGE. \since 0.4 */
192 PA_SUBSCRIPTION_EVENT_AUTOLOAD = 8, /**< Event type: Autoload table changes. \since 0.5 */
193 PA_SUBSCRIPTION_EVENT_FACILITY_MASK = 15, /**< A mask to extract the event type from an event value */
194
195 PA_SUBSCRIPTION_EVENT_NEW = 0, /**< A new object was created */
196 PA_SUBSCRIPTION_EVENT_CHANGE = 16, /**< A property of the object was modified */
197 PA_SUBSCRIPTION_EVENT_REMOVE = 32, /**< An object was removed */
198 PA_SUBSCRIPTION_EVENT_TYPE_MASK = 16+32 /**< A mask to extract the event operation from an event value */
199 } pa_subscription_event_type_t;
200
201 /** Return one if an event type t matches an event mask bitfield */
202 #define pa_subscription_match_flags(m, t) (!!((m) & (1 << ((t) & PA_SUBSCRIPTION_EVENT_FACILITY_MASK))))
203
204 /** A structure for all kinds of timing information of a stream. See
205 * pa_stream_update_timing_info() and pa_stream_get_timing_info(). The
206 * total output latency a sample that is written with
207 * pa_stream_write() takes to be played may be estimated by
208 * sink_usec+buffer_usec+transport_usec. (where buffer_usec is defined
209 * as pa_bytes_to_usec(write_index-read_index)) The output buffer
210 * which buffer_usec relates to may be manipulated freely (with
211 * pa_stream_write()'s seek argument, pa_stream_flush() and friends),
212 * the buffers sink_usec and source_usec relate to are first-in
213 * first-out (FIFO) buffers which cannot be flushed or manipulated in
214 * any way. The total input latency a sample that is recorded takes to
215 * be delivered to the application is:
216 * source_usec+buffer_usec+transport_usec-sink_usec. (Take care of
217 * sign issues!) When connected to a monitor source sink_usec contains
218 * the latency of the owning sink. The two latency estimations
219 * described here are implemented in pa_stream_get_latency().*/
220 typedef struct pa_timing_info {
221 struct timeval timestamp; /**< The time when this timing info structure was current */
222 int synchronized_clocks; /**< Non-zero if the local and the
223 * remote machine have synchronized
224 * clocks. If synchronized clocks are
225 * detected transport_usec becomes much
226 * more reliable. However, the code that
227 * detects synchronized clocks is very
228 * limited und unreliable itself. \since
229 * 0.5 */
230
231 pa_usec_t sink_usec; /**< Time in usecs a sample takes to be played on the sink. For playback streams and record streams connected to a monitor source. */
232 pa_usec_t source_usec; /**< Time in usecs a sample takes from being recorded to being delivered to the application. Only for record streams. \since 0.5*/
233 pa_usec_t transport_usec; /**< Estimated time in usecs a sample takes to be transferred to/from the daemon. For both playback and record streams. \since 0.5 */
234
235 int playing; /**< Non-zero when the stream is currently playing. Only for playback streams. */
236
237 int write_index_corrupt; /**< Non-zero if write_index is not
238 * up-to-date because a local write
239 * command that corrupted it has been
240 * issued in the time since this latency
241 * info was current . Only write
242 * commands with SEEK_RELATIVE_ON_READ
243 * and SEEK_RELATIVE_END can corrupt
244 * write_index. \since 0.8 */
245 int64_t write_index; /**< Current write index into the
246 * playback buffer in bytes. Think twice before
247 * using this for seeking purposes: it
248 * might be out of date a the time you
249 * want to use it. Consider using
250 * PA_SEEK_RELATIVE instead. \since
251 * 0.8 */
252
253 int read_index_corrupt; /**< Non-zero if read_index is not
254 * up-to-date because a local pause or
255 * flush request that corrupted it has
256 * been issued in the time since this
257 * latency info was current. \since 0.8 */
258
259 int64_t read_index; /**< Current read index into the
260 * playback buffer in bytes. Think twice before
261 * using this for seeking purposes: it
262 * might be out of date a the time you
263 * want to use it. Consider using
264 * PA_SEEK_RELATIVE_ON_READ
265 * instead. \since 0.8 */
266 } pa_timing_info;
267
268 /** A structure for the spawn api. This may be used to integrate auto
269 * spawned daemons into your application. For more information see
270 * pa_context_connect(). When spawning a new child process the
271 * waitpid() is used on the child's PID. The spawn routine will not
272 * block or ignore SIGCHLD signals, since this cannot be done in a
273 * thread compatible way. You might have to do this in
274 * prefork/postfork. \since 0.4 */
275 typedef struct pa_spawn_api {
276 void (*prefork)(void); /**< Is called just before the fork in the parent process. May be NULL. */
277 void (*postfork)(void); /**< Is called immediately after the fork in the parent process. May be NULL.*/
278 void (*atfork)(void); /**< Is called immediately after the
279 * fork in the child process. May be
280 * NULL. It is not safe to close all
281 * file descriptors in this function
282 * unconditionally, since a UNIX socket
283 * (created using socketpair()) is
284 * passed to the new process. */
285 } pa_spawn_api;
286
287 /** Seek type for pa_stream_write(). \since 0.8*/
288 typedef enum pa_seek_mode {
289 PA_SEEK_RELATIVE = 0, /**< Seek relatively to the write index */
290 PA_SEEK_ABSOLUTE = 1, /**< Seek relatively to the start of the buffer queue */
291 PA_SEEK_RELATIVE_ON_READ = 2, /**< Seek relatively to the read index. */
292 PA_SEEK_RELATIVE_END = 3 /**< Seek relatively to the current end of the buffer queue. */
293 } pa_seek_mode_t;
294
295 /** Special sink flags. \since 0.8 */
296 typedef enum pa_sink_flags {
297 PA_SINK_HW_VOLUME_CTRL = 1, /**< Supports hardware volume control */
298 PA_SINK_LATENCY = 2, /**< Supports latency querying */
299 PA_SINK_HARDWARE = 4 /**< Is a hardware sink of some kind, in contrast to "virtual"/software sinks \since 0.9.3 */
300 } pa_sink_flags_t;
301
302 /** Special source flags. \since 0.8 */
303 typedef enum pa_source_flags {
304 PA_SOURCE_HW_VOLUME_CTRL = 1, /**< Supports hardware volume control */
305 PA_SOURCE_LATENCY = 2, /**< Supports latency querying */
306 PA_SOURCE_HARDWARE = 4 /**< Is a hardware source of some kind, in contrast to "virtual"/software source \since 0.9.3 */
307 } pa_source_flags_t;
308
309 /** A generic free() like callback prototype */
310 typedef void (*pa_free_cb_t)(void *p);
311
312 PA_C_DECL_END
313
314 #endif